diff --git a/e107_admin/plugin.php b/e107_admin/plugin.php index bf7639c33..e3523ad31 100644 --- a/e107_admin/plugin.php +++ b/e107_admin/plugin.php @@ -11,8 +11,8 @@ | GNU General Public License (http://gnu.org). | | $Source: /cvs_backup/e107_0.8/e107_admin/plugin.php,v $ -| $Revision: 1.9 $ -| $Date: 2008-01-26 05:19:58 $ +| $Revision: 1.10 $ +| $Date: 2008-01-27 01:34:59 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -501,8 +501,11 @@ function render_plugs($pluginList) foreach($pluginList as $plug) { $_path = e_PLUGIN.$plug['plugin_path'].'/'; - $plug_vars = $plugin->parse_plugin($_path); - + $plug_vars = false; + if($plugin->parse_plugin($_path)) + { + $plug_vars = $plugin->plug_vars; + } if($plug_vars) { @@ -616,10 +619,14 @@ function show_uninstall_confirm() global $plugin, $tp, $id, $ns; $id = intval($id); $plug = $plugin->getinfo($id); + $_path = e_PLUGIN.$plug['plugin_path']; if ($plug['plugin_installflag'] == true ) { - $plug_vars = $plugin->parse_plugin($_path); + if($plugin->parse_plugin($_path)) + { + $plug_vars = $plugin->plug_vars; + } } if(is_writable(e_PLUGIN.$plug['plugin_path'])) diff --git a/e107_handlers/plugin_class.php b/e107_handlers/plugin_class.php index 2be24120b..3e6bc8608 100644 --- a/e107_handlers/plugin_class.php +++ b/e107_handlers/plugin_class.php @@ -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.17 $ -| $Date: 2008-01-26 05:19:59 $ +| $Revision: 1.18 $ +| $Date: 2008-01-27 01:34:59 $ | $Author: mcfly_e107 $ +----------------------------------------------------------------------------+ */ @@ -66,6 +66,8 @@ class e107plugin 'plugin_addons' // List of any extras associated with plugin - bbcodes, e_XXX files... ); + var $plug_vars; + /** * Returns an array containing details of all plugins in the plugin table - should normally use e107plugin::update_plugins_table() first to * make sure the table is up to date. (Primarily called from plugin manager to get lists of installed and uninstalled plugins. @@ -280,9 +282,22 @@ class e107plugin } } - function manage_link($action, $link_url, $link_name,$link_class=0) + function manage_link($action, $link_url, $link_name, $link_class=0) { global $sql, $tp; + + if(!ctype_digit($link_class)) + { + $link_class = strtolower($link_class); + $plug_perm['everyone'] = e_UC_PUBLIC; + $plug_perm['guest'] = e_UC_GUEST; + $plug_perm['member'] = e_UC_MEMBER; + $plug_perm['mainadmin'] = e_UC_MAINADMIN; + $plug_perm['admin'] = e_UC_ADMIN; + $plug_perm['nobody'] = e_UC_NOBODY; + $link_class = ($plug_perm[$link_class]) ? $plug_perm[$link_class] : e_UC_PUBLIC; + } + $link_url = $tp -> toDB($link_url, true); $link_name = $tp -> toDB($link_name, true); $path = str_replace("../", "", $link_url); // This should clean up 'non-standard' links @@ -563,21 +578,156 @@ class e107plugin $sql -> db_Update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs'"); } - function install_plugin_xml($path) + function manage_plugin_xml($path, $function='') { - $plug_vars = $this->parse_plugin_xml($path); - - //Still working on this, let's install via plugin.php still + //Will just install using plugin.php file for now. return $this->install_plugin_php($path); + + //New code to install using plugin.xml below. + if(!file_exists($path.'plugin.xml') || $function == '') + { + return false; + } + + $error = array(); + + if($this->parse_plugin_xml($path)) + { + $plug_vars = $this->plug_vars; + } + else + { + return false; + } + + //tables + if(($function == 'install' || $function == 'uninstall') || isset($plug_vars['sqlFile'])) + { + if($sql_data = file_get_contents($path.$plug_vars['sqlFile'])) + { + 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
"; +// $this->manage_tables('remove', array($tablename)); + } + if($function == 'install') + { + $sql_table = preg_replace("/create table\s+/si", "CREATE TABLE #", $sql_table); + echo "Adding table:
{$sql_table}

"; +// $this->manage_tables('add', array($sql_table)); + } + } + } + } + + //main menu items + if(isset($plug_vars['menuLink'])) + { + //Ensure it is an array for use with foreach() + if(!is_array($plug_vars['menuLink'])) + { + $plug_vars['menuLink'] = array($plug_vars['menuLink']); + } + foreach($plug_vars['menuLink'] as $link) + { + $attrib = $link['@attributes']; + switch($function) + { + case 'upgrade': + case 'install': + // Add any active link + 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}
"; +// 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']}]
"; +// manage_link('remove', $attrib['url'], $attrib['name']); + } + break; + + case 'uninstall': + //remove all links + echo "Removing link {$attrib['name']} with url [{$attrib['url']}]
"; +// manage_link('remove', $attrib['url'], $attrib['name']); + break; + } + } + } + + //main pref items + if(isset($plug_vars['mainPrefs'])) + { + if(isset($plug_vars['mainPrefs']['pref'])) + { + if(!is_array($plug_vars['mainPrefs']['pref'])) + { + $pref_list = array($plug_vars['mainPrefs']['pref']); + } + else + { + $pref_list = $plug_vars['mainPrefs']['pref']; + } + + $list = array(); + foreach($pref_list as $pref) + { + $attrib = $pref['@attributes']; + $list['all'][$attrib['name']] = $attrib['value']; + if(!isset($attrib['active']) || $attrib['active'] == 'true') + { + $list['active'][$attrib['name']] = $attrib['value']; + } + if(isset($attrib['active']) && $attrib['active'] == 'false') + { + $list['inactive'][$attrib['name']] = $attrib['value']; + } + } + switch($function) + { + case 'install': + case 'upgrade': + if(!isset($attrib['active']) || $attrib['active'] == true) + { + echo "Adding prefs ".print_a($list['active'], true)."
"; +// manage_prefs('add', $list['active']); + } + + //If upgrading, removing any inactive pref + if($function == 'upgrade') + { + echo "Removing prefs ".print_a($list['inactive'], true)."
"; +// manage_prefs('remove', $list['inactive']); + } + break; + + //If uninstalling, remove all prefs (active or inactive) + case 'uninstall': + echo "Removing prefs ".print_a($list['all'], true)."
"; +// manage_prefs('remove', $list['all']); + break; + } + } + } } function install_plugin_php($path) { + global $sql; $plug = array(); $plug['plug_action'] = 'install'; -// $plug_vars = $this->parse_plugin_php($path); + // $plug_vars = $this->parse_plugin_php($path); include_once($path.'plugin.php'); $func = $eplug_folder.'_install'; @@ -650,15 +800,8 @@ class e107plugin if ($eplug_link === TRUE && $eplug_link_url != '' && $eplug_link_name != '') { - $plug_perm['everyone'] = e_UC_PUBLIC; - $plug_perm['guest'] = e_UC_GUEST; - $plug_perm['member'] = e_UC_MEMBER; - $plug_perm['mainadmin'] = e_UC_MAINADMIN; - $plug_perm['admin'] = e_UC_ADMIN; - $plug_perm['nobody'] = e_UC_NOBODY; - $eplug_link_perms = strtolower($eplug_link_perms); - $linkperm = ($plug_perm[$eplug_link_perms]) ? $plug_perm[$eplug_link_perms] : e_UC_PUBLIC; - $this->manage_link('add', $eplug_link_url, $eplug_link_name,$linkperm); + $linkperm = (isset($eplug_link_perms) ? $eplug_link_perms : e_UC_PUBLIC); + $this->manage_link('add', $eplug_link_url, $eplug_link_name, $linkperm); } if ($eplug_userclass) @@ -702,14 +845,14 @@ class e107plugin if ($plug['plugin_installflag'] == FALSE) { $_path = e_PLUGIN.$plug['plugin_path'].'/'; - if(file_exists($path.'plugin.php')) + if(file_exists($_path.'plugin.xml')) + { + $text = $this->manage_plugin_xml($_path, 'install'); + } + elseif(file_exists($_path.'plugin.php')) { $text = $this->install_plugin_php($_path); } - elseif(file_exists($path.'plugin.xml')) - { - $text = $this->install_plugin_xml($_path); - } } else { @@ -905,11 +1048,11 @@ class e107plugin function parse_plugin($path) { - if(file_exists($_path.'plugin.xml')) + if(file_exists($path.'plugin.xml')) { return $this->parse_plugin_xml($path); } - elseif(file_exists($_path.'plugin.php')) + elseif(file_exists($path.'plugin.php')) { return $this->parse_plugin_php($path); } @@ -942,10 +1085,10 @@ class e107plugin // Set this key so we know the vars came from a plugin.php file $ret['plugin_php'] = true; - return $ret; + $this->plug_vars = $ret; + return true; } - function parse_plugin_xml($path) { global $tp; @@ -955,9 +1098,10 @@ class e107plugin $xml = new xmlClass; $xml->loadXMLfile($path.'plugin.xml', true, true); $xml->xmlFileContents = $tp->replaceConstants($xml->xmlFileContents, '', true); - return $xml->parseXml(); + $this->plug_vars = $xml->parseXml(); + return true; } } -?> +?> \ No newline at end of file diff --git a/e107_plugins/forum/forum_sql.php b/e107_plugins/forum/forum_sql.php index 702477c5d..375213db3 100644 --- a/e107_plugins/forum/forum_sql.php +++ b/e107_plugins/forum/forum_sql.php @@ -1,4 +1,4 @@ -CREATE TABLE forum ( +CREATE TABLE forum ( forum_id int(10) unsigned NOT NULL auto_increment, forum_name varchar(250) NOT NULL default '', forum_description text NOT NULL, @@ -14,7 +14,7 @@ CREATE TABLE forum ( forum_order int(10) unsigned NOT NULL default '0', forum_postclass tinyint(3) unsigned NOT NULL default '0', PRIMARY KEY (forum_id) - ) TYPE=MyISAM AUTO_INCREMENT=1 + ) TYPE=MyISAM; CREATE TABLE forum_t ( thread_id int(10) unsigned NOT NULL auto_increment, @@ -35,5 +35,5 @@ CREATE TABLE forum_t ( KEY thread_parent (thread_parent), KEY thread_datestamp (thread_datestamp), KEY thread_forum_id (thread_forum_id) - ) TYPE=MyISAM AUTO_INCREMENT=1; + ) TYPE=MyISAM; diff --git a/e107_plugins/forum/plugin.xml b/e107_plugins/forum/plugin.xml index f9061b5df..88bb103af 100755 --- a/e107_plugins/forum/plugin.xml +++ b/e107_plugins/forum/plugin.xml @@ -16,7 +16,8 @@ true true - + +