1
0
mirror of https://github.com/e107inc/e107.git synced 2025-07-31 20:00:37 +02:00

plugin.xml support completed (I hope)

This commit is contained in:
mcfly
2008-02-02 22:04:18 +00:00
parent 39f7ced05a
commit 114ea53cf0
3 changed files with 273 additions and 343 deletions

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_admin/plugin.php,v $
| $Revision: 1.11 $
| $Date: 2008-02-01 14:11:27 $
| $Revision: 1.12 $
| $Date: 2008-02-02 22:04:18 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -144,8 +144,16 @@ if ($action == 'uninstall')
$id = intval($id);
$plug = $plugin->getinfo($id);
$text = '';
//Uninstall Plugin
if ($plug['plugin_installflag'] == TRUE )
{
$_path = e_PLUGIN.$plug['plugin_path'].'/';
if(file_exists($_path.'plugin.xml'))
{
$text .= $plugin->manage_plugin_xml($id, 'uninstall');
}
else
{
include(e_PLUGIN.$plug['plugin_path'].'/plugin.php');
@@ -186,7 +194,6 @@ if ($action == 'uninstall')
$text .= ($plugin->manage_comments('remove', $eplug_comment_ids)) ? EPL_ADLAN_50."<br />" : "";
}
if ($eplug_module)
{
$plugin->manage_plugin_prefs('remove', 'modules', $eplug_folder);
@@ -202,8 +209,6 @@ if ($action == 'uninstall')
$plugin->manage_plugin_prefs('remove', 'plug_latest', $eplug_folder);
}
if (is_array($eplug_array_pref))
{
foreach($eplug_array_pref as $key => $val)
@@ -222,29 +227,6 @@ if ($action == 'uninstall')
$plugin->manage_plugin_prefs('remove', 'plug_bb', $eplug_folder, $eplug_bb);
}
if (is_array($eplug_user_prefs))
{
if (!is_object($sql)){ $sql = new db; }
$sql->db_Select("core", " e107_value", " e107_name='user_entended'");
$row = $sql->db_Fetch();
$user_entended = unserialize($row[0]);
$user_entended = array_values(array_diff($user_entended, array_keys($eplug_user_prefs)));
if ($user_entended == NULL)
{
$sql->db_Delete("core", "e107_name='user_entended'");
}
else
{
$tmp = addslashes(serialize($user_entended));
$sql->db_Update("core", "e107_value='$tmp' WHERE e107_name='user_entended' ");
}
while (list($key, $e_user_pref) = each($eplug_user_prefs))
{
unset($user_pref[$key]);
}
save_prefs("user");
}
if ($eplug_menu_name)
{
$sql->db_Delete('menus', "menu_name='$eplug_menu_name' ");
@@ -259,10 +241,11 @@ if ($action == 'uninstall')
{
$plugin->manage_userclass('remove', $eplug_userclass);
}
}
$plugin -> manage_search('remove', $eplug_folder);
$plugin->manage_search('remove', $eplug_folder);
$plugin -> manage_notify('remove', $eplug_folder);
$plugin->manage_notify('remove', $eplug_folder);
$sql->db_Update('plugin', "plugin_installflag=0, plugin_version='{$eplug_version}' WHERE plugin_id='{$id}' ");
if (isset($pref['plug_installed'][$plug['plugin_path']]))
@@ -270,7 +253,7 @@ if ($action == 'uninstall')
unset($pref['plug_installed'][$plug['plugin_path']]);
save_prefs();
}
}
if($_POST['delete_files'])
{
@@ -283,21 +266,31 @@ if ($action == 'uninstall')
{
$text .= '<br />'.EPL_ADLAN_31.' <b>'.e_PLUGIN.$eplug_folder.'</b> '.EPL_ADLAN_32;
}
$ns->tablerender(EPL_ADLAN_1.' '.$tp->toHtml($eplug_name,"","defs,emotes_off, no_make_clickable"), $text);
$text = "";
$plugin -> save_addon_prefs();
}
$plugin->save_addon_prefs();
$ns->tablerender(EPL_ADLAN_1.' '.$tp->toHtml($plug['plugin_name'], "", "defs,emotes_off,no_make_clickable"), $text);
$text = '';
}
if ($action == 'install')
{
$plugin->install_plugin(intval($id));
$text = $plugin->install_plugin($id);
$plugin ->save_addon_prefs();
// if($eplug_conffile){ $text .= "&nbsp;<a href='".e_PLUGIN."$eplug_folder/$eplug_conffile'>[".LAN_CONFIGURE."]</a>"; }
$ns->tablerender(EPL_ADLAN_33, $text);
}
if ($action == 'upgrade')
{
$plug = $plugin->getinfo($id);
$_path = e_PLUGIN.$plug['plugin_path'].'/';
if(file_exists($_path.'plugin.xml'))
{
$text .= $plugin->manage_plugin_xml($id, 'upgrade');
}
else
{
include(e_PLUGIN.$plug['plugin_path'].'/plugin.php');
$func = $eplug_folder.'_upgrade';
@@ -393,48 +386,8 @@ if ($action == 'upgrade')
}
}
if (is_array($upgrade_add_user_prefs))
{
if (!is_object($sql)){ $sql = new db; }
$sql->db_Select("core", " e107_value", " e107_name='user_entended'");
$row = $sql->db_Fetch();
$user_entended = unserialize($row[0]);
while (list($key, $e_user_pref) = each($eplug_user_prefs))
{
$user_entended[] = $e_user_pref;
}
$tmp = addslashes(serialize($user_entended));
if ($sql->db_Select("core", " e107_value", " e107_name='user_entended'"))
{
$sql->db_Update("core", "e107_value='$tmp' WHERE e107_name='user_entended' ");
}
else
{
$sql->db_Insert("core", "'user_entended', '$tmp' ");
}
$text .= EPL_ADLAN_8."<br />";
}
if (is_array($upgrade_remove_user_prefs))
{
if (!is_object($sql)){ $sql = new db; }
$sql->db_Select("core", " e107_value", " e107_name='user_entended'");
$row = $sql->db_Fetch();
$user_entended = unserialize($row[0]);
$user_entended = array_values(array_diff($user_entended, $eplug_user_prefs));
if ($user_entended == NULL)
{
$sql->db_Delete("core", "e107_name='user_entended'");
}
else
{
$tmp = addslashes(serialize($user_entended));
$sql->db_Update("core", "e107_value='$tmp' WHERE e107_name='user_entended' ");
}
}
$plugin -> manage_search('upgrade', $eplug_folder);
$plugin -> manage_notify('upgrade', $eplug_folder);
$plugin->manage_search('upgrade', $eplug_folder);
$plugin->manage_notify('upgrade', $eplug_folder);
$eplug_addons = $plugin -> getAddons($eplug_folder);
@@ -442,9 +395,10 @@ if ($action == 'upgrade')
$sql->db_Update('plugin', "plugin_version ='{$eplug_version}', plugin_addons='{$eplug_addons}' WHERE plugin_id='$id' ");
$pref['plug_installed'][$plug['plugin_path']] = $eplug_version; // Update the version
save_prefs();
}
$ns->tablerender(EPL_ADLAN_34, $text);
$plugin -> save_addon_prefs();
$plugin->save_addon_prefs();
}

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $
| $Revision: 1.26 $
| $Date: 2008-02-02 03:23:47 $
| $Revision: 1.27 $
| $Date: 2008-02-02 22:04:18 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -30,16 +30,15 @@ class e107plugin
'eplug_prefs',
'eplug_array_pref', // missing previously
'eplug_table_names',
'eplug_user_prefs',
'eplug_sc',
'eplug_userclass',
'eplug_module',
'eplug_bb',
'eplug_latest',
'eplug_status' //,
// 'eplug_comment_ids', // Not sure about this one
// 'eplug_menu_name', // ...or this one
// 'eplug_conffile' // ...or this one
'eplug_status',
'eplug_comment_ids',
'eplug_conffile',
'eplug_menu_name'
);
// List of all plugin variables involved in an update (not used ATM, but worth 'documenting')
@@ -51,8 +50,6 @@ class e107plugin
'upgrade_remove_eplug_bb',
'upgrade_add_prefs',
'upgrade_remove_prefs',
'upgrade_add_user_prefs',
'upgrade_remove_user_prefs',
'upgrade_add_array_pref',
'upgrade_remove_array_pref'
);
@@ -385,10 +382,10 @@ class e107plugin
}
}
function manage_comments($action,$comment_id)
function manage_comments($action, $comment_id)
{
global $sql, $tp;
$tmp = array();
if($action == 'remove')
{
foreach($comment_id as $com)
@@ -396,11 +393,11 @@ class e107plugin
$tmp[] = "comment_type='".$tp -> toDB($com, true)."'";
}
$qry = implode(" OR ",$tmp);
return $sql->db_Delete('comments',$qry);
echo $qry."<br />";
return $sql->db_Delete('comments', $qry);
}
}
function manage_tables($action, $var)
{
global $sql;
@@ -604,10 +601,11 @@ class e107plugin
$id = (int)$id;
$plug = $this->getinfo($id);
$this->current_plug = $plug;
$txt = '';
$path = e_PLUGIN.$plug['plugin_path'].'/';
//We'll just install using plugin.php file for now.
return $this->install_plugin_php($path);
//return $this->install_plugin_php($path);
//New code to install using plugin.xml below.
$addons = explode(',', $plug['plugin_addons']);
@@ -637,7 +635,7 @@ class e107plugin
}
// Let's call any custom pre functions defined in <management> section
$this->execute_function($path, $function, 'pre');
$txt .= $this->execute_function($path, $function, 'pre');
// tables
// This will load each _sql.php file found in the plugin directory and parse it.
@@ -649,19 +647,21 @@ class e107plugin
{
preg_match_all("/create(.*?)myisam.*?;/si", $sql_data, $result );
foreach ($result[0] as $sql_table)
{
if($function == 'uninstall')
{
preg_match("/CREATE TABLE(.*?)\(/si", $sql_table, $match);
$tablename = trim($match[1]);
echo "Removing table $tablename <br />";
if($function == 'uninstall' && isset($_POST['delete_tables']) && $_POST['delete_tables'])
{
$txt .= "Removing table $tablename <br />";
$this->manage_tables('remove', array($tablename));
}
if($function == 'install')
{
$sql_table = preg_replace("/create table\s+/si", "CREATE TABLE #", $sql_table);
echo "Adding table: <pre>{$sql_table}</pre><br />";
$this->manage_tables('add', array($sql_table));
$sql_table = preg_replace("/create table\s+/si", "CREATE TABLE ".MPREFIX, $sql_table);
$txt .= "Adding table: {$tablename} ... ";
$result = $this->manage_tables('add', array($sql_table));
$txt .= ($result ? "Success" : "Failed!")."<br />";
}
}
}
@@ -687,20 +687,20 @@ class e107plugin
if(!isset($attrib['active']) || $attrib['active'] == 'true')
{
$perm = (isset($attrib['perm']) ? $attrib['perm'] : 0);
echo "Adding link {$attrib['name']} with url [{$attrib['url']}] and perm {$perm} <br />";
$txt .= "Adding link {$attrib['name']} with url [{$attrib['url']}] and perm {$perm} <br />";
$this->manage_link('add', $attrib['url'], $attrib['name'], $perm);
}
//remove inactive links on upgrade
if($function == 'upgrade' && isset($attrib['active']) && $attrib['active'] == 'false')
{
echo "Removing link {$attrib['name']} with url [{$attrib['url']}] <br />";
$txt .= "Removing link {$attrib['name']} with url [{$attrib['url']}] <br />";
$this->manage_link('remove', $attrib['url'], $attrib['name']);
}
break;
case 'uninstall':
//remove all links
echo "Removing link {$attrib['name']} with url [{$attrib['url']}] <br />";
$txt .= "Removing link {$attrib['name']} with url [{$attrib['url']}] <br />";
$this->manage_link('remove', $attrib['url'], $attrib['name']);
break;
}
@@ -719,14 +719,14 @@ class e107plugin
case 'upgrade':
if(is_array($list['active']))
{
echo "Adding prefs ".print_a($list['active'], true)."<br />";
$txt .= "Adding prefs ".print_a($list['active'], true)."<br />";
$this->manage_prefs('add', $list['active']);
}
//If upgrading, removing any inactive pref
if($function == 'upgrade' && is_array($list['inactive']))
{
echo "Removing prefs ".print_a($list['inactive'], true)."<br />";
$txt .= "Removing prefs ".print_a($list['inactive'], true)."<br />";
$this->manage_prefs('remove', $list['inactive']);
}
break;
@@ -735,7 +735,7 @@ class e107plugin
case 'uninstall':
if(is_array($list['all']))
{
echo "Removing prefs ".print_a($list['all'], true)."<br />";
$txt .= "Removing prefs ".print_a($list['all'], true)."<br />";
$this->manage_prefs('remove', $list['all']);
}
break;
@@ -745,18 +745,9 @@ class e107plugin
//Userclasses
//$this->manage_userclass('add', $eplug_userclass, $eplug_userclass_description);
if(isset($plug_vars['userclasses']))
if(isset($plug_vars['userclass']))
{
if(isset($plug_vars['userclasses']['userclass']))
{
if(!isset($plug_vars['userclasses']['userclass'][0]))
{
$uclass_list = array($plug_vars['userclasses']['userclass']);
}
else
{
$uclass_list = $plug_vars['userclasses']['userclass'];
}
$uclass_list = (isset($plug_vars['userclass'][0]) ? $plug_vars['userclass'] : array($plug_vars['userclass']));
foreach($uclass_list as $uclass)
{
$attrib = $uclass['@attributes'];
@@ -767,33 +758,40 @@ class e107plugin
// Add all active userclasses
if(!isset($attrib['active']) || $attrib['active'] == 'true')
{
echo "Adding userclass ".$attrib['name']."<br />";
$txt .= "Adding userclass ".$attrib['name']."<br />";
$this->manage_userclass('add', $attrib['name'], $attrib['description']);
}
//If upgrading, removing any inactive userclass
if($function == 'upgrade' && isset($attrib['active']) && $attrib['active'] == 'false')
{
echo "Removing userclass ".$attrib['name']."<br />";
$txt .= "Removing userclass ".$attrib['name']."<br />";
$this->manage_userclass('remove', $attrib['name'], $attrib['description']);
}
break;
//If uninstalling, remove all userclasses (active or inactive)
case 'uninstall':
echo "Removing prefs ".$attrib['name']."<br />";
$txt .= "Removing userclass ".$attrib['name']."<br />";
$this->manage_userclass('remove', $attrib['name'], $attrib['description']);
break;
}
}
}
//If and commentIDs are configured, we need to remove all comments on uninstall
if($function == 'uninstall' && isset($plug_vars['commentID']))
{
$commentArray = (is_array($plug_vars['commentID']) ? $plug_vars['commentID'] : array($plug_vars['commentID']));
$txt .= "Removing all plugin comments: (".implode(', ', $commentArray).")<br />";
$this->manage_comments('remove', $commentArray);
}
$this -> manage_search($function, $plug_vars['folder']);
$this -> manage_notify($function, $plug_vars['folder']);
$this->manage_search($function, $plug_vars['folder']);
$this->manage_notify($function, $plug_vars['folder']);
// Let's call any custom post functions defined in <management> section
$this->execute_function($path, $function, 'post');
$txt .= $this->execute_function($path, $function, 'post');
if($function == 'install' || $functon = 'upgrade')
@@ -806,12 +804,13 @@ class e107plugin
if($function == 'install')
{
$text .= LAN_INSTALL_SUCCESSFUL."<br />";
$txt .= LAN_INSTALL_SUCCESSFUL."<br />";
if(isset($plug_vars['installDone']))
{
$text .= $plug_vars['installDone'];
$txt .= $plug_vars['installDone'];
}
}
return $txt;
}
function execute_function($path = '', $what='', $when='')
@@ -935,29 +934,6 @@ class e107plugin
$this->manage_plugin_prefs('add', 'plug_bb', $eplug_folder, $eplug_bb);
}
if (is_array($eplug_user_prefs))
{
$sql->db_Select("core", " e107_value", " e107_name = 'user_entended'");
$row = $sql->db_Fetch();
$user_entended = unserialize($row[0]);
while (list($e_user_pref, $default_value) = each($eplug_user_prefs))
{
$user_entended[] = $e_user_pref;
$user_pref['$e_user_pref'] = $default_value;
}
save_prefs("user");
$tmp = addslashes(serialize($user_entended));
if ($sql->db_Select("core", "e107_value", " e107_name = 'user_entended'"))
{
$sql->db_Update("core", "e107_value = '{$tmp}' WHERE e107_name = 'user_entended' ");
}
else
{
$sql->db_Insert("core", "'user_entended', '{$tmp}' ");
}
$text .= EPL_ADLAN_8."<br />";
}
if ($eplug_link === TRUE && $eplug_link_url != '' && $eplug_link_name != '')
{
$linkperm = (isset($eplug_link_perms) ? $eplug_link_perms : e_UC_PUBLIC);
@@ -1019,8 +995,7 @@ class e107plugin
{
$text = EPL_ADLAN_21;
}
if($eplug_conffile){ $text .= "&nbsp;<a href='".e_PLUGIN."$eplug_folder/$eplug_conffile'>[".LAN_CONFIGURE."]</a>"; }
$ns->tablerender(EPL_ADLAN_33, $text);
return $text;
}
function save_addon_prefs()
@@ -1234,7 +1209,7 @@ class e107plugin
include($path.'plugin.php');
$ret = array();
$ret['installRequired'] = ($eplug_conffile || is_array($eplug_table_names) || is_array($eplug_prefs) || is_array($eplug_user_prefs) || is_array($eplug_sc) || is_array($eplug_bb) || $eplug_module || $eplug_userclass || $eplug_status || $eplug_latest);
$ret['installRequired'] = ($eplug_conffile || is_array($eplug_table_names) || is_array($eplug_prefs) || is_array($eplug_sc) || is_array($eplug_bb) || $eplug_module || $eplug_userclass || $eplug_status || $eplug_latest);
$ret['version'] = varset($eplug_version);
$ret['name'] = varset($eplug_name);

View File

@@ -8,6 +8,8 @@
<compatibility>0.8</compatibility>
<installRequired>true</installRequired>
<folder>forum</folder>
<commentID>forum1</commentID>
<commentID>forum2</commentID>
<administration>
<configFile>forum_admin.php</configFile>
<icon>images/forums_32.png</icon>
@@ -35,9 +37,8 @@
<key name="pref3" value="val3" />
</pref>
</mainPrefs>
<userclasses>
<userclass name="forum_moderator" description="Moderator of all forums" />
</userclasses>
<userclass name="forum_moderator2" description="Moderator of all forums" />
<management>
<install when="post" type="classFunction" file="forum_management.php" class="forum_management" function="forum_install_post" />
<uninstall type="classFunction" file="forum_management.php" class="forum_management" function="forum_uninstall" />