1

Topic: [1.3] Extension developpment?

Does anyone started an extension?

I couldn' t found a better way to test my extension (localy) than delete and recache the hooks in the db on each page.

Do you know a better way to "develop" an extension?

If it can help someone, there is the patch ^^ :

Index: admin/extensions.php
===================================================================
--- admin/extensions.php    (revision 928)
+++ admin/extensions.php    (working copy)
@@ -26,7 +26,8 @@
 define('PUN_ROOT', '../');
 require PUN_ROOT.'include/common.php';
 require PUN_ROOT.'include/common_admin.php';
-require PUN_ROOT.'include/xml.php';
+if(!PUN_EXTDEV)
+    require PUN_ROOT.'include/xml.php';
 
 
 if ($pun_user['g_id'] != PUN_ADMIN)
Index: include/common.php
===================================================================
--- include/common.php    (revision 928)
+++ include/common.php    (working copy)
@@ -24,6 +24,7 @@
 
 // Enable DEBUG mode by removing // from the following line
 define('PUN_DEBUG', 1);
+define('PUN_EXTDEV', 0);
 
 // This displays all executed queries in the page footer.
 // DO NOT enable this in a production environment!
@@ -114,6 +115,8 @@
 
 
 // Load hooks
+if(!PUN_EXTDEV)
+{
 if (file_exists(PUN_ROOT.'cache/cache_hooks.php'))
     include PUN_ROOT.'cache/cache_hooks.php';
 
@@ -123,8 +126,44 @@
     generate_hooks_cache();
     require PUN_ROOT.'cache/cache_hooks.php';
 }
+}
+else
+{
+    include PUN_ROOT.'include/xml.php';
+    $result = $db->query('SELECT id FROM '.$db->prefix.'extensions') or error('Unable to fetch extension', __FILE__, __LINE__, $db->error());
+    while($row = $db->fetch_row($result))
+    {
+        $id = $row[0];
+        $ext_data = xml_to_array(file_get_contents(PUN_ROOT.'extensions/'.$id.'/manifest.xml'));
+        $errors = validate_manifest($ext_data, $id);
+        if (!empty($errors))
+        {
+            echo "\t\t\t\t\t".'<p class="field"><strong class="alabel error">'.$lang_admin['Extension error'].'<span>: </span></strong> <span class="input">'.sprintf($lang_admin['Extension loading error'], htmlspecialchars($id)).' '.implode(' ', $errors).'</span></p>'."\n";
+        }
+        else
+        {
+            $db->query('DELETE FROM '.$db->prefix.'extension_hooks WHERE extension_id=\''.$db->escape($id).'\'') or error('Unable to delete extension hooks', __FILE__, __LINE__, $db->error());
+            $hooks = $ext_data['extension']['hooks']['hook'];
+            if (!is_array(current($hooks)))
+                $hooks = array($hooks);
+            foreach ($hooks as $hook)
+                $db->query('INSERT INTO '.$db->prefix.'extension_hooks (id, extension_id, code, installed) VALUES(\''.$db->escape(trim($hook['attributes']['id'])).'\', \''.$db->escape($id).'\', \''.$db->escape(trim($hook['content'])).'\', '.time().')') or error('Unable to create extension hook', __FILE__, __LINE__, $db->error());
+        }
+    }
+    $d = dir(PUN_ROOT.'cache');
+    while (($entry = $d->read()) !== false)
+    {
+        if (substr($entry, strlen($entry)-4) == '.php')
+        @unlink(PUN_ROOT.'cache/'.$entry);
+    }
+    $d->close();
+    require_once PUN_ROOT.'include/cache.php';
+    generate_hooks_cache();
+    require PUN_ROOT.'cache/cache_hooks.php';
+}
 
 
+
 // A good place to add common functions for your extension
 ($hook = get_hook('co_common')) ? eval($hook) : null;

Re: [1.3] Extension developpment?

Why noy install and uninstall via the regular methods?

Actually, what I will be doing is writing code in the PunBB files, and then putting it into a manifest file once it's finished.

3 (edited by Jiboo 2007-03-30 19:06)

Re: [1.3] Extension developpment?

Why noy install and uninstall via the regular methods?

Because it' s the method that i don' t wan' t to use wink

Actually, what I will be doing is writing code in the PunBB files, and then putting it into a manifest file once it's finished.

So simple that i haven' t think about that ^^.
Thx.

Re: [1.3] Extension developpment?

PunXS should fix most of this smile

5

Re: [1.3] Extension developpment?

Yes the "preview" seems to be so cool. smile
Can' t wait.