/e107_handlers/plugin_class.php
PHP | 3036 lines | 2533 code | 248 blank | 255 comment | 274 complexity | 8e40a66ec74b29e40ff321d4d8b8aa59 MD5 | raw file
Possible License(s): GPL-2.0
Large files files are truncated, but you can click here to view the full file
- <?php
- /*
- * e107 website system
- *
- * Copyright (C) 2008-2013 e107 Inc (e107.org)
- * Released under the terms and conditions of the
- * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
- *
- */
- if (!defined('e107_INIT')) { exit; }
- /**
- *
- * @package e107
- * @category e107_handlers
- * @author e107inc
- *
- * Plugin administration handler
- */
- // TODO LAN
- e107::coreLan('plugin', true);
- class e107plugin
- {
- // Reserved Addon names.
- var $plugin_addons = array(
- 'e_bb',
- 'e_cron',
- 'e_notify',
- 'e_linkgen',
- 'e_list',
-
- 'e_meta',
- 'e_emailprint',
- 'e_frontpage',
- 'e_latest',
- 'e_status',
- 'e_search',
- 'e_shortcode',
- 'e_module',
- 'e_event',
- 'e_comment',
- 'e_sql',
- 'e_userprofile',
- 'e_header',
- 'e_userinfo',
- 'e_tagwords',
- 'e_url',
-
- 'e_mailout',
- 'e_sitelink',
- 'e_tohtml',
- 'e_featurebox',
- 'e_related',
- 'e_rss',
- );
- var $disAllowed = array(
- 'theme',
- 'core'
- );
- protected $core_plugins = array(
- "_blank","admin_menu","alt_auth","banner","blogcalendar_menu",
- "calendar_menu","chatbox_menu", "clock_menu","comment_menu",
- "contact", "download","faqs", "featurebox", "forum","gallery",
- "gsitemap","import", "linkwords", "list_new", "log", "login_menu",
- "metaweblog", "newforumposts_main", "news", "newsfeed",
- "newsletter","online", "page", "pdf", "pm", "pm","poll",
- "rss_menu","search_menu","siteinfo", "social", "tagwords", "tinymce",
- "trackback","tree_menu","user"
- );
- // List of all plugin variables which need to be checked - install required if one or more set and non-empty
- // Deprecated in 0.8 (used in plugin.php only). Probably delete in 0.9
- var $all_eplug_install_variables = array(
- 'eplug_link_url',
- 'eplug_link',
- 'eplug_prefs',
- 'eplug_array_pref',
- 'eplug_table_names',
- // 'eplug_sc', // Not used in 0.8 (or later 0.7)
- 'eplug_userclass',
- 'eplug_module',
- // 'eplug_bb', // Not used in 0.8 (or later 0.7)
- 'eplug_latest',
- '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')
- // Deprecated in 0.8 (used in plugin.php only). Probably delete in 0.9
- var $all_eplug_update_variables = array(
- 'upgrade_alter_tables',
- // 'upgrade_add_eplug_sc', // Not used in 0.8 (or later 0.7)
- // 'upgrade_remove_eplug_sc', // Not used in 0.8 (or later 0.7)
- // 'upgrade_add_eplug_bb', // Not used in 0.8 (or later 0.7)
- // 'upgrade_remove_eplug_bb', // Not used in 0.8 (or later 0.7)
- 'upgrade_add_prefs',
- 'upgrade_remove_prefs',
- 'upgrade_add_array_pref',
- 'upgrade_remove_array_pref'
- );
- // List of all 'editable' DB fields ('plugin_id' is an arbitrary reference which is never edited)
- var $all_editable_db_fields = array(
- 'plugin_name', // Name of the plugin - language dependent
- 'plugin_version', // Version - arbitrary text field
- 'plugin_path', // Name of the directory off e_PLUGIN - unique
- 'plugin_installflag', // '0' = not installed, '1' = installed
- 'plugin_addons', // List of any extras associated with plugin - bbcodes, e_XXX files...
- 'plugin_category' // Plugin Category: settings, users, content, management, tools, misc, about
- );
- var $accepted_categories = array('settings', 'users', 'content', 'tools', 'manage', 'misc', 'menu', 'about');
- var $plug_vars;
- var $current_plug;
- var $parsed_plugin = array();
- var $plugFolder;
- var $plugConfigFile;
- var $unInstallOpts;
- var $module = array();
- private $options = array();
- function __construct()
- {
- //$parsed_plugin = array();
- }
- /**
- * 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.
- * @return array plugin details
- */
- function getall($flag)
- {
- $sql = e107::getDb();
- if($flag === 'all')
- {
- $qry = "SELECT * FROM #plugin ORDER BY plugin_path ASC";
- }
- else
- {
- $qry = "SELECT * FROM #plugin WHERE plugin_installflag = ".(int) $flag." ORDER BY plugin_path ASC";
- }
- if ($sql->gen($qry))
- {
- $ret = $sql->db_getList();
- return $ret;
- }
- return false;
- }
- /**
- * Return a list of core plugins.
- */
- public function getCorePlugins()
- {
- return $this->core_plugins;
- }
- /**
- * Return a list of non-core plugins
- */
- public function getOtherPlugins()
- {
- $allplugs = e107::getFile()->get_dirs(e_PLUGIN);
-
- return array_diff($allplugs,$this->core_plugins);
- }
-
- /**
- * 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.
- * @return array plugin details
- */
- function getId($path)
- {
- $sql = e107::getDb();
- if ($sql->select("plugin", "plugin_id", "plugin_path = '".(string) $path."' LIMIT 1"))
- {
- $row = $sql->fetch(MYSQL_ASSOC);
- return intval($row['plugin_id']);
- }
-
- return false;
- }
-
- /**
- * Checks all installed plugins and returns an array of those needing an update.
- * @param string $mode 'boolean' for a quick true/false or null for full array returned.
- * @return mixed
- */
- function updateRequired($mode=null)
- {
- $xml = e107::getXml();
- $mes = e107::getMessage();
- $needed = array();
- $log = e107::getAdminLog();
-
- if(!$plugVersions = e107::getConfig('core')->get('plug_installed'))
- {
- return FALSE;
- }
-
- foreach($plugVersions as $path=>$version)
- {
- $fullPath = e_PLUGIN.$path."/plugin.xml";
- if(is_file(e_PLUGIN.$path."/plugin.xml"))
- {
- $data = $xml->loadXMLfile($fullPath, true);
- $curVal = floatval($version);
- $fileVal = floatval($data['@attributes']['version']);
-
- if($ret = $this->execute_function($path, 'upgrade', 'required', array($this, $curVal, $fileVal))) // Check {plugin}_setup.php and run a 'required' method, if true, then update is required.
- {
- if($mode == 'boolean')
- {
- $mes->addDebug("Plugin Update(s) Required");
- return TRUE;
- }
-
- $needed[$path] = $data;
- }
-
- if($curVal < $fileVal)
- {
-
- if($mode == 'boolean')
- {
- $mes->addDebug("Plugin Update(s) Required");
- return TRUE;
- }
-
- // $mes->addDebug("Plugin: <strong>{$path}</strong> requires an update.");
-
- // $log->flushMessages();
- $needed[$path] = $data;
- }
- }
- }
- // Display debug and log to file.
- foreach($needed as $path=>$tmp)
- {
- $log->addDebug("Plugin: <strong>{$path}</strong> requires an update.");
- }
-
- return count($needed) ? $needed : FALSE;
- }
- /**
- * Check for new plugins, create entry in plugin table and remove deleted plugins
- *
- * @param string $mode = install|upgrade|refresh|uninstall - defines the intent of the call
- *
- * 'upgrade' and 'refresh' are very similar in intent, and often take the same actions:
- * 'upgrade' signals a possible change to the installed list of plugins
- * 'refresh' validates the stored data for existing plugins, recreating any that has gone missing
- */
- function update_plugins_table($mode = 'upgrade')
- {
-
- $sql = e107::getDb();
- $sql2 = e107::getDb('sql2');
- $tp = e107::getParser();
- $fl = e107::getFile();
- $mes = e107::getMessage();
-
- $mes->addDebug("Updating plugins Table");
-
- $log = e107::getAdminLog();
- global $mySQLprefix, $menu_pref;
- $pref = e107::getPref();
-
- $sp = FALSE;
- $pluginDBList = array();
- if ($sql->select('plugin', "*")) // Read all the plugin DB info into an array to save lots of accesses
- {
- while ($row = $sql->fetch(MYSQL_ASSOC))
- {
- $pluginDBList[$row['plugin_path']] = $row;
- $pluginDBList[$row['plugin_path']]['status'] = 'read';
- // echo "Found plugin: ".$row['plugin_path']." in DB<br />";
- }
- }
- $sql->db_Mark_Time('Start Scanning Plugin Files');
- $plugList = $fl->get_files(e_PLUGIN, "^plugin\.(php|xml)$", "standard", 1);
- foreach ($plugList as $num => $val) // Remove Duplicates caused by having both plugin.php AND plugin.xml.
- {
- $key = basename($val['path']);
- $pluginList[$key] = $val;
- }
- $sql->db_Mark_Time('After Scanning Plugin Files');
- $p_installed = e107::getPref('plug_installed', array()); // load preference;
- $mes = e107::getMessage();
- foreach ($pluginList as $p)
- {
- $p['path'] = substr(str_replace(e_PLUGIN, "", $p['path']), 0, -1);
- $plugin_path = $p['path'];
- if (strpos($plugin_path, 'e107_') !== FALSE)
- {
- $mes->addWarning("Folder error: <i>{$p['path']}</i>. 'e107_' is not permitted within plugin folder names.");
- continue;
- }
-
- if(in_array($plugin_path, $this->disAllowed))
- {
- $mes->addWarning("Folder error: <i>{$p['path']}</i> is not permitted as an acceptable folder name.");
- continue;
- }
-
-
- $plug['plug_action'] = 'scan'; // Make sure plugin.php knows what we're up to
- if (!$this->parse_plugin($p['path']))
- {
- //parsing of plugin.php/plugin.xml failed.
- $mes->addError("Parsing failed - file format error: {$p['path']}");
- continue; // Carry on and do any others that are OK
- }
- $plug_info = $this->plug_vars;
- $eplug_addons = $this->getAddons($plugin_path);
-
- //Ensure the plugin path lives in the same folder as is configured in the plugin.php/plugin.xml - no longer relevant.
- if ($plugin_path == $plug_info['folder'])
- {
- if (array_key_exists($plugin_path, $pluginDBList))
- { // Update the addons needed by the plugin
- $pluginDBList[$plugin_path]['status'] = 'exists';
-
- // Check for name (lan) changes
- if (vartrue($plug_info['@attributes']['lan']) && $pluginDBList[$plugin_path]['plugin_name'] != $plug_info['@attributes']['lan'])
- {
- // print_a($plug_info);
- $pluginDBList[$plugin_path]['status'] = 'update';
- $pluginDBList[$plugin_path]['plugin_name'] = $plug_info['@attributes']['lan'];
- $this->plugFolder = $plugin_path;
- $this->XmlLanguageFiles('upgrade');
- }
-
- if ($mode == 'refresh')
- {
- if ($this->XmlLanguageFileCheck('_log', 'lan_log_list', 'refresh', $pluginDBList[$plugin_path]['plugin_installflag'], FALSE, $plugin_path)) $sp = TRUE;
- if ($this->XmlLanguageFileCheck('_global', 'lan_global_list', 'refresh', $pluginDBList[$plugin_path]['plugin_installflag'], TRUE, $plugin_path)) $sp = TRUE;
- }
- // Check for missing plugin_category in plugin table.
- if ($pluginDBList[$plugin_path]['plugin_category'] == '' || $pluginDBList[$plugin_path]['plugin_category'] != $plug_info['category'])
- {
- // print_a($plug_info);
- $pluginDBList[$plugin_path]['status'] = 'update';
- $pluginDBList[$plugin_path]['plugin_category'] = (varsettrue($plug_info['category'])) ? $plug_info['category'] : "misc";
- }
- // If plugin not installed, and version number of files changed, update version as well
- if (($pluginDBList[$plugin_path]['plugin_installflag'] == 0) && ($pluginDBList[$plugin_path]['plugin_version'] != $plug_info['@attributes']['version']))
- { // Update stored version
- $pluginDBList[$plugin_path]['plugin_version'] = $plug_info['@attributes']['version'];
- $pluginDBList[$plugin_path]['status'] = 'update';
- }
- if ($pluginDBList[$plugin_path]['plugin_addons'] != $eplug_addons)
- { // Update stored addons list
- $pluginDBList[$plugin_path]['plugin_addons'] = $eplug_addons;
- $pluginDBList[$plugin_path]['status'] = 'update';
- }
- if ($pluginDBList[$plugin_path]['plugin_installflag'] == 0) // Plugin not installed - make sure $pref not set
- {
- if (isset($p_installed[$plugin_path]))
- {
- unset($p_installed[$plugin_path]);
- $sp = TRUE;
- }
- }
- else
- { // Plugin installed - make sure $pref is set
- if (!isset($p_installed[$plugin_path]) || ($p_installed[$plugin_path] != $pluginDBList[$plugin_path]['plugin_version']))
- { // Update prefs array of installed plugins
- $p_installed[$plugin_path] = $pluginDBList[$plugin_path]['plugin_version'];
- // echo "Add: ".$plugin_path."->".$ep_row['plugin_version']."<br />";
- $sp = TRUE;
- }
- }
- }
- else // New plugin - not in table yet, so add it. If no install needed, mark it as 'installed'
- {
- if ($plug_info['@attributes']['name'])
- {
- $pName = vartrue($plug_info['@attributes']['lan']) ? $plug_info['@attributes']['lan'] : $plug_info['@attributes']['name'] ;
-
- $_installed = ($plug_info['@attributes']['installRequired'] == 'true' || $plug_info['@attributes']['installRequired'] == 1 ? 0 : 1);
-
-
- $pInsert = array(
- 'plugin_id' => 0,
- 'plugin_name' => $tp->toDB($pName, true),
- 'plugin_version' => $tp->toDB($plug_info['@attributes']['version'], true),
- 'plugin_path' => $tp->toDB($plugin_path, true),
- 'plugin_installflag' => $_installed,
- 'plugin_addons' => $eplug_addons,
- 'plugin_category' => $this->manage_category($plug_info['category'])
- );
-
- // if (e107::getDb()->db_Insert("plugin", "0, '".$tp->toDB($pName, true)."', '".$tp->toDB($plug_info['@attributes']['version'], true)."', '".$tp->toDB($plugin_path, true)."',{$_installed}, '{$eplug_addons}', '".$this->manage_category($plug_info['category'])."' "))
- if (e107::getDb()->insert("plugin", $pInsert))
- {
- $log->addDebug("Added <b>".$tp->toHTML($pName,false,"defs")."</b> to the plugin table.");
- }
- else
- {
- $log->addDebug("Failed to add ".$tp->toHTML($pName,false,"defs")." to the plugin table.");
- }
-
- $log->flushMessages("Updated Plugins table");
- }
- }
- }
- else
- { // May be useful that we ignore what will usually be copies/backups of plugins - but don't normally say anything
- // echo "Plugin copied to wrong directory. Is in: {$plugin_path} Should be: {$plug_info['folder']}<br /><br />";
- }
- // print_a($plug_info);
- }
- // Now scan the table, updating the DB where needed
- foreach ($pluginDBList as $plug_path => $plug_info)
- {
- if ($plug_info['status'] == 'read')
- { // In table, not on server - delete it
- $sql->delete('plugin', "`plugin_id`={$plug_info['plugin_id']}");
- // echo "Deleted: ".$plug_path."<br />";
- }
- if ($plug_info['status'] == 'update')
- {
- $temp = array();
- foreach ($this->all_editable_db_fields as $p_f)
- {
- $temp[] = "`{$p_f}` = '{$plug_info[$p_f]}'";
- }
- $sql->update('plugin', implode(", ", $temp)." WHERE `plugin_id`={$plug_info['plugin_id']}");
- // echo "Updated: ".$plug_path."<br />";
- }
- }
- if ($sp/* && vartrue($p_installed)*/)
- {
- e107::getConfig('core')->setPref('plug_installed', $p_installed);
- $this->rebuildUrlConfig();
- e107::getConfig('core')->save();
- }
- }
- function manage_category($cat)
- {
- if (vartrue($cat) && in_array($cat, $this->accepted_categories))
- {
- return $cat;
- }
- else
- {
- return 'misc';
- }
- }
- function manage_icons($plugin = '', $function = '')
- {
- if ($plugin == '')
- {
- return;
- }
- $mes = e107::getMessage();
- $sql = e107::getDb();
- $tp = e107::getParser();
- $med = e107::getMedia();
- if ($function == 'install' || $function == 'upgrade')
- {
- $med->importIcons(e_PLUGIN.$plugin);
- return;
- }
- if ($function == 'uninstall')
- {
- if (vartrue($this->unInstallOpts['delete_ipool'], FALSE))
- {
- $status = ($med->removePath(e_PLUGIN.$plugin, 'icon')) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
- $mes->add('Removing Icons from Media-Manager', $status);
- }
- return;
- }
- }
- /**
- * Returns details of a plugin from the plugin table from it's ID
- *
- * @param int $id
- * @return array plugin info
- */
- function getinfo($id, $force = false)
- {
- $sql = e107::getDb();
- static $getinfo_results;
- if (!is_array($getinfo_results))
- {
- $getinfo_results = array();
- }
- $path = (!is_numeric($id)) ? $id : false;
- $id = (int) $id;
-
- $qry = "plugin_id = ".$id;
- $qry .= ($path != false) ? " OR plugin_path = '".$path."' " : "";
-
- if (!isset($getinfo_results[$id]) || $force == true)
- {
- if ($sql->select('plugin', '*', $qry))
- {
- $getinfo_results[$id] = $sql->fetch();
- }
- else
- {
- return false;
- }
- }
- return $getinfo_results[$id];
- }
-
- public function setUe()
- {
- if (!isset($this->module['ue']))
- {
- include_once(e_HANDLER.'user_extended_class.php');
- $this->module['ue'] = new e107_user_extended;
- }
- }
-
- /**
- * User field name, based on its type
- * @param string $folder plugin folder
- * @param int $type normalized field type
- * @param string $name field name
- * @return string field name
- */
- public function ue_field_name($folder, $type, $name)
- {
- if($type == EUF_PREFIELD || $type == EUF_CATEGORY)
- {
- return $name; // no plugin_plugname_ prefix
- }
- return 'plugin_'.$folder.'_'.$name;
- }
-
- /**
- * Normalize type
- * @param array $attrib parsed from XML user field definitions
- * @return integer type ID
- */
- public function ue_field_type($attrib)
- {
- $field_type = $attrib['type'];
- $type = defined($field_type) ? constant($field_type) : $field_type;
- if(!is_numeric($type))
- {
- // normalize further
- $this->setUe();
- $type = $this->module['ue']->typeArray[$type];
- }
- return $type;
- }
-
- /**
- * Type number to type name
- * @param integer $typeId
- * @return string type name
- */
- public function ue_field_type_name($typeId)
- {
- if(is_numeric($typeId))
- {
- $this->setUe();
- return array_search($typeId, $this->module['ue']->typeArray);
- }
- return $typeId;
- }
-
- /**
- * Field attributes ($field_attrib array) as they have to be defined in plugin.xml:
- * name - REQUIRED string
- * text - (string|constant name) field label
- * type - REQUIRED (constant name) see EUF_* constants in e107_user_extended class
- * regex - regex validation string
- * required - 0-not requried, don't show on signup; 1 - required, show on signup; 2-not required, show on signup
- * allow_hide (0|1) - allow user to hide this field on profile page
- * read, write, applicable - classes, see e_UC_* defines
- * values - comma separated values (if required)
- * default - default value
- * order - (number)
- * parent - (string) category name for this field
- * system - (0|1) - field wont be shown if it's system, NOTE - default value if system is not set is 1!
- *
- * @param string $action - add|remove
- * @param string $field_name normalized field name (see self::ue_field_name())
- * @param array $field_attrib
- * @param string $field_source used for system user fields
- *
- * @return boolean success
- */
- function manage_extended_field($action, $field_name, $field_attrib, $field_source = '')
- {
- $mes = e107::getMessage();
- $this->setUe();
- $type = $this->ue_field_type($field_attrib);
- $type_name = $this->ue_field_type_name($type);
-
- $mes->addDebug("Extended Field: ".$action.": ".$field_name." : ".$type_name);
-
- // predefined
- if($type == EUF_PREFIELD)
- {
-
- $preList = $this->module['ue']->parse_extended_xml(''); // passed value currently not used at all, could be file path in the near future
- if($preList && isset($preList[$field_name]))
- {
- $preField = $preList[$field_name];
- if($preField)
- {
- $field_attrib = array_merge($preField, $field_attrib); // merge
- // predefined type - numeric value, constant or as defined in user_extended_class::typeArray
- $field_attrib['type'] = $type = $this->ue_field_type($preField); // override type
- }
- else
- {
- return false;
- }
- }
-
- }
- // not allowed for categories
- elseif($type == EUF_CATEGORY)
- {
- $field_attrib['parent'] = 0;
- }
- if ($action == 'add')
- {
- // system field
- if($field_attrib['system'])
- {
- return $this->module['ue']->user_extended_add_system($field_name, $type, varset($field_attrib['default'], ''), $field_source);
- }
-
- // new - add non-system extended field
- // classes
- $field_attrib['read'] = varset($field_attrib['read'], 'e_UC_MEMBER');
- $field_attrib['write'] = varset($field_attrib['read'], 'e_UC_MEMBER');
- $field_attrib['applicable'] = varset($field_attrib['applicable'], 'e_UC_MEMBER');
-
- // manage parent
- if(vartrue($field_attrib['parent']))
- {
- foreach ($this->module['ue']->catDefinitions as $key => $value)
- {
- if($value['user_extended_struct_name'] == $field_attrib['parent'])
- {
- $field_attrib['parent'] = $key;
- break;
- }
- }
- if(!is_numeric($field_attrib['parent'])) $field_attrib['parent'] = 0;
- }
- else $field_attrib['parent'] = 0;
-
- // manage required (0, 1, 2)
- if(!isset($field_attrib['required']))
- {
- $field_attrib['required'] = 0;
- }
-
- // manage params
- $field_attrib['parms'] = '';
-
- // validation and parms
- $include = varset($field_attrib['include_text']);
- $regex = varset($field_attrib['regex']);
- $hide = vartrue($field_attrib['allow_hide']) ? 1 : 0;
- $failmsg = '';
- if($regex || $hide)
- {
- // failmsg only when required
- if($field_attrib['required'] == 1 || $regex)
- $failmsg = vartrue($field_attrib['error']) ? $field_attrib['error'] : 'LAN_UE_FAIL_'.strtoupper($field_name);
-
- $field_attrib['parms'] = $include."^,^".$regex."^,^".$failmsg.'^,^'.$hide;
- }
-
- //var_dump($field_attrib, $field_name, $type);
-
- $status = $this->module['ue']->user_extended_add(
- $field_name,
- varset($field_attrib['text'], "LAN_UE_".strtoupper($field_name)),
- $type,
- $field_attrib['parms'],
- varset($field_attrib['values'], ''),
- varset($field_attrib['default'], ''),
- $field_attrib['required'],
- defset($field_attrib['read'], e_UC_MEMBER),
- defset($field_attrib['write'], e_UC_MEMBER),
- defset($field_attrib['applicable'], e_UC_MEMBER),
- varset($field_attrib['order'], ''),
- $field_attrib['parent']
- );
-
- // db fields handling
- if($status && $type == EUF_DB_FIELD)
- {
- // handle DB, use original non-modified name value
- $status = !$this->manage_extended_field_sql('add', $field_attrib['name']); // reverse logic - sql method do a error check
- }
-
- // refresh categories - sadly the best way so far... need improvement (inside ue class)
- if($status && $type == EUF_CATEGORY)
- {
- $cats = $this->module['ue']->user_extended_get_categories(false);
- foreach ($cats as $cat)
- {
- $this->module['ue']->catDefinitions[$cat['user_extended_struct_id']] = $cat;
- }
- }
-
- return $status;
- }
- if ($action == 'remove')
- {
- //var_dump($field_attrib, $field_name, $type);
- $status = $this->module['ue']->user_extended_remove($field_name, $field_name);
- if($status && $type == EUF_DB_FIELD)
- {
- $status = $this->manage_extended_field_sql('remove', $field_attrib['name']);
- }
-
- return $status;
- }
- return false;
- }
- function manage_extended_field_sql($action, $field_name)
- {
- $f = e_CORE.'sql/extended_'.preg_replace('/[^\w]/', '', $field_name).'.php'; // quick security, always good idea
-
- if(!is_readable($f)) return false;
-
- // TODO - taken from user_extended Administration, need to be refined :/
- // FIXME - use sql parse handler
- $error = FALSE;
- $count = 0;
- if($action == 'add')
- {
- $sql_data = file_get_contents($f);
-
- $search[0] = "CREATE TABLE "; $replace[0] = "CREATE TABLE ".MPREFIX;
- $search[1] = "INSERT INTO "; $replace[1] = "INSERT INTO ".MPREFIX;
-
- preg_match_all("/create(.*?)myisam;/si", $sql_data, $creation);
- foreach($creation[0] as $tab)
- {
- $query = str_replace($search,$replace,$tab);
- if(!mysql_query($query))
- {
- $error = TRUE;
- }
- $count++;
- }
-
- preg_match_all("/insert(.*?);/si", $sql_data, $inserts);
- foreach($inserts[0] as $ins)
- {
- $qry = str_replace($search,$replace,$ins);
- if(!mysql_query($qry))
- {
- $error = TRUE;
- }
- $count++;
- }
-
- if(!$count) $error = TRUE;
-
- return $error;
- }
-
- //remove
- if($action == 'remove')
- {
- // executed only if the sql file exists!
- return mysql_query("DROP TABLE ".MPREFIX."user_extended_".$field_name) ? true : false;
- }
- }
- function manage_userclass($action, $class_name, $class_description)
- {
- global $e107;
- $tp = e107::getParser();
- $sql = e107::getDb();
- $mes = e107::getMessage();
- $mes->addDebug("Userclass: ".$action.": ".$class_name." : ".$class_description);
- if (!$e107->user_class->isAdmin())
- {
- $e107->user_class = new user_class_admin; // We need the extra methods of the admin extension
- }
- $class_name = strip_tags(strtoupper($class_name));
- if ($action == 'add')
- {
- if ($e107->user_class->ucGetClassIDFromName($class_name) !== FALSE)
- { // Class already exists.
- return TRUE; // That's probably OK
- }
- $i = $e107->user_class->findNewClassID();
- if ($i !== FALSE)
- {
- $tmp = array();
- $tmp['userclass_id'] = $i;
- $tmp['userclass_name'] = $class_name;
- $tmp['userclass_description'] = $class_description;
- $tmp['userclass_editclass'] = e_UC_ADMIN;
- $tmp['userclass_visibility'] = e_UC_ADMIN;
- $tmp['userclass_type'] = UC_TYPE_STD;
- $tmp['userclass_parent'] = e_UC_NOBODY;
- $tmp['_FIELD_TYPES']['userclass_editclass'] = 'int';
- $tmp['_FIELD_TYPES']['userclass_visibility'] = 'int';
- $tmp['_FIELD_TYPES']['userclass_id'] = 'int';
- $tmp['_FIELD_TYPES']['_DEFAULT'] = 'todb';
- return $e107->user_class->add_new_class($tmp);
- }
- else
- {
- return NULL;
- }
- }
- if ($action == 'remove')
- {
- $classID = $e107->user_class->ucGetClassIDFromName($class_name);
- if (($classID !== FALSE) && ($e107->user_class->deleteClassAndUsers($classID) === TRUE))
- {
- return TRUE;
- }
- else
- {
- return FALSE;
- }
- }
- }
- function manage_link($action, $link_url, $link_name, $link_class = 0, $options=array())
- {
- $sql = e107::getDb();
- $tp = e107::getParser();
-
- if (!is_numeric($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]) ? intval($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
- $path = $tp->createConstants($path); // Add in standard {e_XXXX} directory constants if we can
-
- if ($action == 'add')
- {
- $link_t = $sql->count('links');
- if (!$sql->count('links', '(*)', "WHERE link_url = '{$path}' OR link_name = '{$link_name}'"))
- {
- $linkData = array(
- 'link_name' => $link_name,
- 'link_url' => $path,
- 'link_description' => '',
- 'link_button' => '',
- 'link_category' => '1',
- 'link_order' => $link_t + 1,
- 'link_parent' => '0',
- 'link_open' => '0',
- 'link_class' => vartrue($linkclass,'0'),
- 'link_function' => (vartrue($options['link_function']) ? $this->plugFolder ."::".$options['link_function'] : "")
- );
- return $sql->insert('links', $linkData); // TODO: Add the _FIELD_DEFS array
- }
- else
- {
- return ;
- }
- }
- if ($action == 'remove')
- { // Look up by URL if we can - should be more reliable. Otherwise try looking up by name (as previously)
- if (($path && $sql->select('links', 'link_id,link_order', "link_url = '{$path}'")) || $sql->select('links', 'link_id,link_order', "link_name = '{$link_name}'"))
- {
- $row = $sql->fetch();
- $sql->db_Update('links', "link_order = link_order - 1 WHERE link_order > {$row['link_order']}");
- return $sql->delete('links', "link_id = {$row['link_id']}");
- }
- }
- }
- // DEPRECATED in 0.8 - See XmlPrefs(); Left for BC.
- // Update prefs array according to $action
- // $prefType specifies the storage type - may be 'pref', 'listPref' or 'arrayPref'
- function manage_prefs($action, $var, $prefType = 'pref', $path = '', $unEscape = FALSE)
- {
- global $pref;
- if (!is_array($var))
- return;
- if (($prefType == 'arrayPref') && ($path == ''))
- return;
- foreach ($var as $k => $v)
- {
- if ($unEscape)
- {
- $v = str_replace(array('\{', '\}'), array('{', '}'), $v);
- }
- switch ($prefType)
- {
- case 'pref':
- switch ($action)
- {
- case 'add':
- $pref[$k] = $v;
- break;
- case 'update' :
- case 'upgrade' :
- case 'refresh':
- // Only update if $pref doesn't exist
- if (!isset($pref[$k]))
- $pref[$k] = $v;
- break;
- case 'remove':
- if (is_numeric($k))
- { // Sometimes arrays specified with value being the name of the key to delete
- unset($pref[$var[$k]]);
- }
- else
- { // This is how the array should be specified - key is the name of the pref
- unset($pref[$k]);
- }
- break;
- }
- break;
- case 'listPref':
- $tmp = array();
- if (isset($pref[$k]))
- $tmp = explode(',', $pref[$k]);
- switch ($action)
- {
- case 'add':
- case 'update' :
- case 'upgrade' :
- case 'refresh':
- if (!in_array($v, $tmp))
- $tmp[] = $v;
- break;
- case 'remove':
- if (($tkey = array_search($v, $tmp)) !== FALSE)
- unset($tmp[$tkey]);
- break;
- }
- $pref[$k] = implode(',', $tmp); // Leaves an empty element if no values - probably acceptable or even preferable
- break;
- case 'arrayPref':
- switch ($action)
- {
- case 'add':
- $pref[$k][$path] = $v;
- break;
- case 'update' :
- case 'upgrade' :
- case 'refresh':
- if (!isset($pref[$k][$path]))
- $pref[$k][$path] = $v;
- break;
- case 'remove':
- if (isset($pref[$k][$path]))
- unset($pref[$k][$path]); // Leaves an empty element if no values - probably acceptable or even preferable
- break;
- }
- break;
- }
- }
- e107::getConfig('core')->setPref($pref)->save();
- // e107::getConfig()->loadData($pref, false)->save(false, true);
- }
- function manage_comments($action, $comment_id)
- {
- $sql = e107::getDb();
- $tp = e107::getParser();
- $tmp = array();
- if ($action == 'remove')
- {
- foreach ($comment_id as $com)
- {
- $tmp[] = "comment_type='".$tp->toDB($com, true)."'";
- }
- $qry = implode(" OR ", $tmp);
- // echo $qry."<br />";
- return $sql->delete('comments', $qry);
- }
- }
- // Handle table updates - passed an array of actions.
- // $var array:
- // For 'add' - its a query to create the table
- // For 'upgrade' - its a query to modify the table (not called from the plugin.xml handler)
- // For 'remove' - its a table name
- // 'upgrade' and 'remove' operate on all language variants of the same table
- function manage_tables($action, $var)
- {
- $sql = e107::getDB();
- $mes = e107::getMessage();
-
- if (!is_array($var))
- return FALSE; // Return if nothing to do
- $error = false;
- $error_data = array();
- switch ($action)
- {
- case 'add':
- foreach ($var as $tab)
- {
-
- $tab = str_replace("TYPE=MyISAM","ENGINE=MyISAM",$tab);
-
- if(!preg_match("/MyISAM.*CHARSET ?= ?utf8/i",$tab))
- {
- $tab = str_replace("MyISAM", "MyISAM DEFAULT CHARSET=utf8", $tab);
- }
-
-
- $mes->addDebug($tab);
- if (false === $sql->db_Query($tab))
- {
- $error = true;
- $error_data[] = $tab;
- }
- }
- break;
- case 'upgrade':
- foreach ($var as $tab)
- {
- if (false === $sql->db_Query_all($tab))
- {
- $error = true;
- $error_data[] = $tab;
- }
- }
- break;
- case 'remove':
- foreach ($var as $tab)
- {
- $qry = 'DROP TABLE '.MPREFIX.$tab;
- if (!$sql->db_Query_all($qry))
- {
- $error = true;
- $error_data[] = $tab;
- }
- }
- break;
- }
- // doesn't exit the loop now, returns true on success
- // or error queries (string)
- return (!$error ? true : (!empty($$error_data) ? implode('<br />', $error_data) : false));
- }
- // DEPRECATED for 0.8 xml files - See XmlPrefs();
- // Handle prefs from arrays (mostly 0.7 stuff, possibly apart from the special cases)
- function manage_plugin_prefs($action, $prefname, $plugin_folder, $varArray = '')
- { // These prefs are 'cumulative' - several plugins may contribute an array element
- // global $pref;
- /*
- if ($prefname == 'plug_sc' || $prefname == 'plug_bb')
- { // Special cases - shortcodes and bbcodes - each plugin may contribute several elements
- foreach($varArray as $code)
- {
- $prefvals[] = "$code:$plugin_folder";
- }
- }
- else
- {
- */
- $prefvals[] = $varArray;
- // $prefvals[] = $plugin_folder;
- // }
- $curvals = explode(',', $pref[$prefname]);
- if ($action == 'add')
- {
- $newvals = array_merge($curvals, $prefvals);
- }
- if ($action == 'remove')
- {
- foreach ($prefvals as $v)
- {
- if (($i = array_search($v, $curvals)) !== FALSE)
- {
- unset($curvals[$i]);
- }
- }
- $newvals = $curvals;
- }
- $newvals = array_unique($newvals);
- $pref[$prefname] = implode(',', $newvals);
- if (substr($pref[$prefname], 0, 1) == ",")
- {
- $pref[$prefname] = substr($pref[$prefname], 1);
- }
- e107::getConfig('core')->setPref($pref);
- e107::getConfig('core')->save();
- }
- function manage_search($action, $eplug_folder)
- {
- global $sysprefs;
- $sql = e107::getDb();
- $search_prefs = e107::getConfig('search')->getPref();
- // $search_prefs = $sysprefs -> getArray('search_prefs');
- $default = file_exists(e_PLUGIN.$eplug_folder.'/e_search.php') ? TRUE : FALSE;
- $comments = file_exists(e_PLUGIN.$eplug_folder.'/search/search_comments.php') ? TRUE : FALSE;
- if ($action == 'add')
- {
- $install_default = $default ? TRUE : FALSE;
- $install_comments = $comments ? TRUE : FALSE;
- }
- else
- if ($action == 'remove')
- {
- $uninstall_default = isset($search_prefs['plug_handlers'][$eplug_folder]) ? TRUE : FALSE;
- $uninstall_comments = isset($search_prefs['comments_handlers'][$eplug_folder]) ? TRUE : FALSE;
- }
- else
- if ($action == 'upgrade')
- {
- if (isset($search_prefs['plug_handlers'][$eplug_folder]))
- {
- $uninstall_default = $default ? FALSE : TRUE;
- }
- else
- {
- $install_default = $default ? TRUE : FALSE;
- }
- if (isset($search_prefs['comments_handlers'][$eplug_folder]))
- {
- $uninstall_comments = $comments ? FALSE : TRUE;
- }
- else
- {
- $install_comments = $comments ? TRUE : FALSE;
- }
- }
- if (vartrue($install_default))
- {
- $search_prefs['plug_handlers'][$eplug_folder] = array('class' => 0, 'pre_title' => 1, 'pre_title_alt' => '', 'chars' => 150, 'results' => 10);
- }
- else
- if (vartrue($uninstall_default))
- {
- unset($search_prefs['plug_handlers'][$eplug_folder]);
- }
- if (vartrue($install_comments))
- {
- require_once(e_PLUGIN.$eplug_folder.'/search/search_comments.php');
- $search_prefs['comments_handlers'][$eplug_folder] = array('id' => $comments_type_id, 'class' => 0, 'dir' => $eplug_folder);
- }
- else
- if (vartrue($uninstall_comments))
- {
- unset($search_prefs['comments_handlers'][$eplug_folder]);
- }
- e107::getConfig('search')->setPref($search_prefs)->save();
- }
- function manage_notify($action, $eplug_folder)
- {
- $tp = e107::getParser();
- // $notify_prefs = $sysprefs -> get('notify_prefs');
- // $notify_prefs = $eArrayStorage -> ReadArray($notify_prefs);
- $notify_prefs = e107::getConfig('notify');
- $e_notify = file_exists(e_PLUGIN.$eplug_folder.'/e_notify.php') ? TRUE : FALSE;
- if ($action == 'add')
- {
- $install_notify = $e_notify ? TRUE : FALSE;
- }
- else
- if ($action == 'remove')
- {
- $uninstall_notify = $notify_prefs->isData('plugins/'.$eplug_folder); //isset($notify_prefs['plugins'][$eplug_folder]) ? TRUE : FALSE;
- }
- else
- if ($action == 'upgrade')
- {
- if ($notify_prefs->isData('plugins/'.$eplug_folder))
- {
- $uninstall_notify = $e_notify ? FALSE : TRUE;
- }
- else
- {
- $install_notify = $e_notify ? TRUE : FALSE;
- }
- }
- if (vartrue($install_notify))
- {
- $notify_prefs->setPref('plugins/'.$eplug_folder, 1); //$notify_prefs['plugins'][$eplug_folder] = TRUE;
- require_once(e_PLUGIN.$eplug_folder.'/e_notify.php');
- foreach ($config_events as $event_id => $event_text)
- {
- $notify_prefs->setPref('event/'.$event_id.'/class', e_UC_NOBODY)
- ->setPref('event/'.$event_id.'/email', '');
- //$notify_prefs['event'][$event_id] = array('class' => e_UC_NOBODY, 'email' => '');
- }
- }
- else
- if (vartrue($uninstall_notify))
- {
- $notify_prefs->removePref('plugins/'.$eplug_folder);
- //unset($notify_prefs['plugins'][$eplug_folder]);
- require_once(e_PLUGIN.$eplug_folder.'/e_notify.php');
- foreach ($config_events as $event_id => $event_text)
- {
- $notify_prefs->removePref('event/'.$event_id);
- //unset($notify_prefs['event'][$event_id]);
- }
- }
- //$s_prefs = $tp -> toDB($notify_prefs);
- //$s_prefs = e107::getArrayStorage()->WriteArray($s_prefs);
- //e107::getDb() -> db_Update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs'");
- $notify_prefs->save(false);
- }
- /**
- * Rebuild URL configuration values
- * Note - new core system pref values will be set, but not saved
- * e107::getConfig()->save() is required outside after execution of this method
- * @return void
- */
- public function rebuildUrlConfig()
- {
-
- $modules = eRouter::adminReadModules(); // get all available locations, non installed plugins will be ignored
- $config = eRouter::adminBuildConfig(e107::getPref('url_config'), $modules); // merge with current config
- $locations = eRouter::adminBuildLocations($modules); // rebuild locations pref
- $aliases = eRouter::adminSyncAliases(e107::getPref('url_aliases'), $config); // rebuild aliases
-
- // set new values, changes should be saved outside this methods
- e107::getConfig()
- ->set('url_aliases', $aliases)
- ->set('url_config', $config)
- ->set('url_modules', $modules)
- ->set('url_locations', $locations);
-
- eRouter::clearCache();
- }
- function displayArray(&$array, $msg = '')
- {
- $txt = ($msg ? $msg.'<br />' : '');
- foreach ($array as $_k => $_v)
- {
- $txt .= "{$_k} -> {$_v}<br />";
- }
- $txt .= '<br />';
- return $txt;
- }
- /**
- * Install routine for XML file
- * @param object $id (the number of the plugin in the DB) or the path to the plugin folder. eg. 'forum'
- * @param object $function install|upgrade|uninstall|refresh (adds things that are missing, but doesn't change any existing settings)
- * @param object $options [optional] an array of possible options - ATM used only for uninstall:
- * 'delete_userclasses' - to delete userclasses created
- * 'delete_tables' - to delete DB tables
- * 'delete_xfields' - to delete extended fields
- * 'delete_ipool' - to delete icon pool entry
- * + any defined in <pluginname>_setup.php in the uninstall_options() method.
- * @return TBD
- */
- function install_plugin_xml($id, $function = '', $options = FALSE)
- {
-
- $pref = e107::getPref();
- $sql = e107::getDb();
- $mes = e107::getMessage();
- $error = array(); // Array of error messages
- $canContinue = TRUE; // Clear flag if must abort part way through
-
- if(is_array($id))
- {
- $plug = $id;
- $id = $plug['plugin_id'];
- }
- else
- {
- $id = (int) $id;
- $plug = $this->getinfo($id); // Get plugin info from DB
- }
-
- $this->current_plug = $plug;
-
- $txt = '';
- $path = e_PLUGIN.$plug['plugin_path'].'/';
- $this->plugFolder = $plug['plugin_path'];
-
-
-
- $this->unInstallOpts = $options;
- $addons = explode(',', $plug['plugin_addons']);
- $sql_list = array();
- foreach ($addons as $addon)
- {
- if (substr($addon, -4) == '_sql')
- {
- $sql_list[] = $addon.'.php';
- }
- }
- if (!file_exists($path.'plugin.xml') || $function == '')
- {
- $error[] = EPL_ADLAN_77;
- $canContinue = FALSE;
- }
- if ($canContinue && $this->parse_plugin_xml($plug['plugin_path']))
- {
- $plug_vars = $this->plug_vars;
- }
- else
- {
- $error[] = EPL_ADLAN_76;
- $canContinue = FALSE;
- }
-
- // Load install language file and set lan_global pref.
- $this->XmlLanguageFiles($function, $plug_vars['languageFiles'], 'pre'); // First of all, see if there's a language file specific to install
- // Next most important, if installing or upgrading, check that any dependencies are met
- if ($canContinue && ($function != 'uninstall') && isset($plug_vars['dependencies']))
- {
- $canContinue = $this->XmlDependencies($plug_vars['dependencies']);
- }
- if (!$canContinue)
- {
- return FALSE;
- }
- // All the dependencies are OK - can start the install now
-
- if ($canContinue) // Run custom {plugin}_setup install/upgrade etc. for INSERT, ALTER etc. etc. etc.
- {
- $ret = $this->execute_function($plug['plugin_path'], $function, 'pre');
- if (!is_bool($ret))
- $txt .= $ret;
- }
-
-
- // Handle tables
- if ($canContinue && count($sql_list)) // TODO - move to it's own function. XmlTables().
- {
- require_once(e_HANDLER.'db_table_admin_class.php');
- $dbHandler = new db_table_admin;
- foreach ($sql_list as $sqlFile)
- {
- $tableList = $dbHandler->get_table_def('', $path.$sqlFile);
- if (!is_array($tableList))
- {
- $mes->addError("Can't read SQL definition: ".$path.$sqlFile);
- break;
- }
- // Got the required definition here
- foreach ($tableList as $ct)
- { // Process one table at a time (but they could be multi-language)
- switch ($function)
- {
- case 'install':
- $sqlTable = str_replace("CREATE TABLE ".MPREFIX.'`', "CREATE TABLE `".MPREFIX, preg_replace("/create table\s+/si", "CREATE TABLE ".MPREFIX, $ct[0]));
- $txt = "Adding Table: {$ct[1]} ... ";
- $status = $this->manage_tables('add', array($sqlTable)) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; // Pass the statement to create the table
- $mes->add($txt, $status);
- break;
- case 'upgrade':
- $tmp = $dbHandler->update_table_structure($ct, FALSE, TRUE, $pref['multilanguage']);
- if ($tmp === FALSE)
- {
- $error[] = 'Error Updating Table: '.$ct[1];
- }
- elseif ($tmp !== TRUE)
- {
- $error[] = $tmp;
- }
- break;
- case 'refresh': // Leave things alone
- break;
- case 'uninstall':
- if (vartrue($options['delete_tables'], FALSE))
- {
- $txt = "Removing Table: {$ct[1]} <br />";
- $status = $this->manage_tables('remove', array($ct[1])) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR; // Delete the table
- $mes->add($txt, $status);
- }
- else
- {
- $mes->addSuccess("Table {$ct[1]} left in place.");
- }
- break;
- }
- }
- }
- }
- if (varset($plug_vars['adminLinks']))
- {
- $this->XmlAdminLinks($function, $plug_vars['adminLinks']);
- }
- if (varset($plug_vars['siteLinks']))
- {
- $this->XmlSiteLinks($function, $plug_vars['siteLinks']);
- }
- if (varset($plug_vars['mainPrefs'])) //Core pref items <mainPrefs>
- {
- $this->XmlPrefs('core', $function, $plug_vars['mainPrefs']);
- }
- if (varset($plug_vars['pluginPrefs'])) //Plugin pref items <pluginPrefs>
- {
- $this->XmlPrefs($plug['plugin_path'], $function, $plug_vars['pluginPrefs']);
- }
- if (varset($plug_vars['userClasses']))
- {
- $this->XmlUserClasses($function, $plug_vars['userClasses']);
- }
- if (varset($plug_vars['extendedFields']))
- {
- $this->XmlExtendedFields($function, $plug_vars['extendedFields']);
- }
- if (varset($plug_vars['languageFiles']))
- {
- $this->XmlLanguageFiles($function, $plug_vars['languageFiles']);
- }
-
- if (varset($plug_vars['bbcodes']))
- {
- $this->XmlBBcodes($function, $plug_vars);
- }
-
- if (varset($plug_vars['mediaCategories']))
- {
- $this->XmlMediaCategories($function, $plug_vars);
- }
- $this->manage_icons($this->plugFolder, $function);
- //FIXME
- //If any commentIDs are configured, we need to remove all comments on uninstall
- if ($function == 'uninstall' && isset($plug_vars['commentID']))
- {
- $txt .= 'Removing all plugin comments: ('.implode(', ', $plug_vars['commentID']).')<br />';
- $this->manage_comments('remove', $commentArray);
- }
- $this->manage_search($function, $plug_vars['folder']);
- $this->manage_notify($function, $plug_vars['folder']);
- $eplug_addons = $this->getAddons($plug['plugin_path']);
- $p_installed = e107::getPref('plug_installed', array()); // load preference;
- if ($function == 'install' || $function == 'upgrade' || $function == 'refresh')
- {
- $sql->update('plugin', "plugin_installflag = 1, plugin_addons = '{$eplug_addons}', plugin_version = '{$plug_vars['@attributes']['version']}', plugin_category ='".$this->manage_category($plug_vars['category'])."' WHERE plugin_id = ".$id);
- $p_installed[$plug['plugin_path']] = $plug_vars['@attributes']['version'];
- e107::getConfig('core')->setPref('plug_installed', $p_installed);
- //e107::getConfig('core')->save(); - save triggered below
- }
- if ($function == 'uninstall')
- {
- $sql->update('plugin', "plugin_installflag = 0, plugin_addons = '{$eplug_addons}', plugin_version = '{$plug_vars['@attributes']['version']}', plugin_category ='".$this->manage_category($plug_vars['category'])."' WHERE plugin_id = ".$id);
- unset($p_installed[$plug['plugin_path']]);
-
- e107::getConfig('core')->setPref('plug_installed', $p_installed);
- }
-
- e107::getMessage()->addDebug("updated Installed plugins pref: ".print_a($p_installed,true));
-
-
- $this->rebuildUrlConfig();
- e107::getConfig('core')->save();
- /* if($function == 'install')
- {
- if(isset($plug_vars['management']['installDone'][0]))
- {
- $mes->add($plug_vars['management']['installDone'][0], E_MESSAGE_SUCCESS);
- }
- }*/
- // Run custom {plugin}_setup install/upgrade etc. for INSERT, ALTER etc. etc. etc.
- // Call any custom post functions defined in <plugin>_setup.php or the deprecated <management> section
- if (!$this->execute_function($plug['plugin_path'], $function, 'post'))
- {
- if ($function == 'install')
- {
- $text = "Installation Complete.";
- if ($this->plugConfigFile)
- {
- $text .= "<br /><a class='btn btn-primary' href='".$this->plugConfigFile."'>".LAN_CONFIGURE."</a>";
- }
- $mes->addSuccess($text);
- }
- }
- }
- // Placeholder.
- function XmlTables($data)
- {
-
- }
-
-
-
-
-
-
- /**
- * Process XML Tag <dependencies> (deprecated 'depend' which is a brand of adult diapers)
- * @param array $tag
- * @return boolean
- */
- function XmlDependencies($tag)
- {
- $canContinue = TRUE;
- $mes = e107::getMessage();
- $error = array();
- foreach ($tag as $dt => $dv)
- {
- if (isset($dv['@attributes']) && isset($dv['@attributes']['name']))
- {
- // echo "Check {$dt} dependency: {$dv['@attributes']['name']} version {$dv['@attributes']['min_version']}<br />";
- switch ($dt)
- {
- case 'plugin':
- if (!isset($pref['plug_installed'][$dv['@attributes']['name']]))
- { // Plugin not installed
- $canContinue = FALSE;
- $error[] = EPL_ADLAN_70.$dv['@attributes']['name'];
- }
- elseif (isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], $pref['plug_installed'][$dv['@attributes']['name']], '<=') === FALSE))
- {
- $error[] = EPL_ADLAN_71.$dv['@attributes']['name'].EPL_ADLAN_72.$dv['@attributes']['min_version'];
- $canContinue = FALSE;
- }
- break;
- case 'extension':
- if (!extension_loaded($dv['@attributes']['name']))
- {
- $canContinue = FALSE;
- $error[] = EPL_ADLAN_73.$dv['@attributes']['name'];
- }
- elseif (isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], phpversion($dv['@attributes']['name']), '<=') === FALSE))
- {
- $error[] = EPL_ADLAN_71.$dv['@attributes']['name'].EPL_ADLAN_72.$dv['@attributes']['min_version'];
- $canContinue = FALSE;
- }
- break;
- case 'php': // all should be lowercase
- if (isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], phpversion(), '<=') === FALSE))
- {
- $error[] = EPL_ADLAN_74.$dv['@attributes']['min_version'];
- $canContinue = FALSE;
- }
- break;
- case 'mysql': // all should be lowercase
- if (isset($dv['@attributes']['min_version']) && (version_compare($dv['@attributes']['min_version'], mysql_get_server_info(), '<=') === FALSE))
- {
- $error[] = EPL_ADLAN_75.$dv['@attributes']['min_version'];
- $canContinue = FALSE;
- }
- break;
- default:
- echo "Unknown dependency: {$dt}<br />";
- }
- }
- }
- if (count($error))
- {
- $text = '<b>'.LAN_INSTALL_FAIL.'</b><br />'.implode('<br />', $error);
- $mes->addError($text);
- }
- return $canContinue;
- }
- /**
- * Look for a language file in the two acceptable places.
- * If found, update the appropriate pref
- *
- * @param string $fileEnd - the suffix of the file name (e.g. '_global')
- * @param string $prefName - the name of the pref to be updated
- * @param string $when = install|upgrade|refresh|uninstall ('update' also supported as alias for 'upgrade')
- * @param string $isInstalled - flag indicates whether plugin installed
- * - if false, any preference is removed.
- * - if TRUE, any preference is added
- * - so set TRUE to add value to pref regardless
- * @param boolean $justPath
- * - if TRUE, plugin name is written to pref, as a generic string which requires a search to locate the file.
- * - if FALSE, a precise path within the plugin folder, which includes '--LAN--' strings to substitute for language, is written
- * @param string $plugin - name of plugin folder. If empty string, $this->plugFolder is used (may not always exist).
- *
- * @return boolean TRUE if pref changed
- */
- public function XmlLanguageFileCheck($fileEnd, $prefName, $when, $isInstalled, $justPath = FALSE, $plug…
Large files files are truncated, but you can click here to view the full file