1
0
mirror of https://github.com/e107inc/e107.git synced 2025-01-17 20:58:30 +01:00
php-e107/e107_handlers/plugin_class.php

1717 lines
49 KiB
PHP
Raw Normal View History

2006-12-02 04:36:16 +00:00
<?php
/*
+ ----------------------------------------------------------------------------+
| e107 website system
|
| <EFBFBD>Steve Dunstan 2001-2002
| http://e107.org
| jalist@e107.org
|
| Released under the terms and conditions of the
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $
| $Revision: 1.71 $
| $Date: 2009-07-20 15:24:34 $
| $Author: e107coders $
2006-12-02 04:36:16 +00:00
+----------------------------------------------------------------------------+
*/
if (!defined('e107_INIT')) { exit; }
class e107plugin
{
2008-08-09 16:49:58 +00:00
var $plugin_addons = array(
"e_rss",
"e_notify",
"e_linkgen",
"e_list",
"e_bb",
"e_meta",
"e_emailprint",
"e_frontpage",
"e_latest",
"e_status",
"e_search",
"e_sc",
"e_module",
"e_comment",
"e_sql",
2008-08-09 16:49:58 +00:00
"e_userprofile",
"e_header"
);
2006-12-02 04:36:16 +00:00
// List of all plugin variables which need to be checked - install required if one or more set and non-empty
2008-08-09 16:49:58 +00:00
// 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',
2008-08-09 16:49:58 +00:00
'eplug_array_pref',
'eplug_table_names',
2008-08-24 09:57:08 +00:00
// 'eplug_sc', // Not used in 0.8 (or later 0.7)
'eplug_userclass',
'eplug_module',
2008-08-24 09:57:08 +00:00
// 'eplug_bb', // Not used in 0.8 (or later 0.7)
'eplug_latest',
2008-02-02 22:04:18 +00:00
'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')
2008-08-09 16:49:58 +00:00
// Deprecated in 0.8 (used in plugin.php only). Probably delete in 0.9
var $all_eplug_update_variables = array (
'upgrade_alter_tables',
2008-08-24 09:57:08 +00:00
// '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
);
2008-01-27 01:34:59 +00:00
var $plug_vars;
2008-02-02 03:23:47 +00:00
var $current_plug;
2008-01-28 02:49:50 +00:00
var $parsed_plugin;
var $module = array();
2008-02-02 22:04:18 +00:00
2008-01-28 02:49:50 +00:00
function e107plugin()
{
2008-02-01 14:11:27 +00:00
$parsed_plugin = array();
2008-01-28 02:49:50 +00:00
}
2008-02-01 14:11:27 +00:00
2006-12-02 04:36:16 +00:00
/**
* 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
*/
2006-12-02 04:36:16 +00:00
function getall($flag)
{
2006-12-02 04:36:16 +00:00
global $sql;
if ($sql->db_Select("plugin","*","plugin_installflag = ".(int)$flag." ORDER BY plugin_path ASC"))
2006-12-02 04:36:16 +00:00
{
$ret = $sql->db_getList();
return $ret;
}
return false;
2006-12-02 04:36:16 +00:00
}
2006-12-02 04:36:16 +00:00
/**
* Check for new plugins, create entry in plugin table and remove deleted plugins
*/
function update_plugins_table()
{
global $sql, $sql2, $mySQLprefix, $menu_pref, $tp, $pref;
2006-12-02 04:36:16 +00:00
require_once(e_HANDLER.'file_class.php');
$fl = new e_file;
2008-02-13 00:46:05 +00:00
$pluginList = $fl->get_files(e_PLUGIN, "^plugin\.(php|xml)$", "standard", 1);
$sp = FALSE;
2006-12-02 04:36:16 +00:00
// Read all the plugin DB info into an array to save lots of accesses
$pluginDBList = array();
if ($sql->db_Select('plugin',"*"))
{
2008-02-13 00:46:05 +00:00
while ($row = $sql->db_Fetch(MYSQL_ASSOC))
{
$pluginDBList[$row['plugin_path']] = $row;
$pluginDBList[$row['plugin_path']]['status'] = 'read';
// echo "Found plugin: ".$row['plugin_path']." in DB<br />";
}
}
$i = 1;
while ( $i < count($pluginList))
{
if ($pluginList[$i-1]['path'] == $pluginList[$i]['path'])
{ // Must have plugin.php and plugin.xml
if (($pluginList[$i-1]['fname'] == 'plugin.php') && ($pluginList[$i]['fname'] == 'plugin.xml'))
{
// echo "deleting: {$pluginList[$i-1]['path']}<br />";
unset($pluginList[$i-1]);
$i++;
}
if (($pluginList[$i]['fname'] == 'plugin.php') && ($pluginList[$i-1]['fname'] == 'plugin.xml'))
{
// echo "deleting: {$pluginList[$i]['path']}<br />";
unset($pluginList[$i]);
$i++;
}
}
$i++;
}
2006-12-02 04:36:16 +00:00
foreach($pluginList as $p)
{
2008-02-13 00:46:05 +00:00
$plug['plug_action'] = 'scan'; // Make sure plugin.php knows what we're up to
if(!$this->parse_plugin($p['path']))
{
2008-02-13 00:46:05 +00:00
//parsing of plugin.php/plugin.xml failed.
require_once(e_HANDLER."message_handler.php");
$emessage = &eMessage::getInstance();
$emessage->add("Parsing failed - file format error: {$p['path']}", E_MESSAGE_ERROR);
// echo <br />";
2008-08-09 16:49:58 +00:00
continue; // Carry on and do any others that are OK
}
2008-02-13 00:46:05 +00:00
$plug_info = $this->plug_vars;
$plugin_path = substr(str_replace(e_PLUGIN,"",$p['path']),0,-1);
// scan for addons.
$eplug_addons = $this->getAddons($plugin_path); // Returns comma-separated list
// $eplug_addons = $this->getAddons($plugin_path,'check'); // Checks opening/closing tags on addon files
//Ensure the plugin path lives in the same folder as is configured in the plugin.php/plugin.xml
if ($plugin_path == $plug_info['folder'])
{
2008-02-13 00:46:05 +00:00
if(array_key_exists($plugin_path, $pluginDBList))
{ // Update the addons needed by the plugin
$pluginDBList[$plugin_path]['status'] = 'exists';
// Check for missing plugin_category in plugin table.
if ($pluginDBList[$plugin_path]['plugin_category'] == '')
{
// print_a($plug_info);
$pluginDBList[$plugin_path]['status'] = 'update';
2009-07-09 22:12:21 +00:00
$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($pref['plug_installed'][$plugin_path]))
{
unset($pref['plug_installed'][$plugin_path]);
// echo "Remove: ".$plugin_path."->".$ep_row['plugin_version']."<br />";
$sp = TRUE;
}
}
else
{ // Plugin installed - make sure $pref is set
if (!isset($pref['plug_installed'][$plugin_path]) || ($pref['plug_installed'][$plugin_path] != $pluginDBList[$plugin_path]['plugin_version']))
{ // Update prefs array of installed plugins
$pref['plug_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'
//SecretR - update to latest XML version
if ($plug_info['@attributes']['name'])
{
2008-08-09 16:49:58 +00:00
// echo "New plugin to add: {$plug_info['name']}<br />";
2008-02-13 00:46:05 +00:00
// Can just add to DB - shouldn't matter that its not in our current table
// echo "Trying to insert: ".$eplug_folder."<br />";
$_installed = ($plug_info['@attributes']['installRequired'] == 'true' || $plug_info['@attributes']['installRequired'] == 1 ? 0 : 1 );
$sql->db_Insert("plugin", "0, '".$tp -> toDB($plug_info['@attributes']['name'], true)."', '".$tp -> toDB($plug_info['@attributes']['version'], true)."', '".$tp -> toDB($plugin_path, true)."', {$_installed}, '{$eplug_addons}', '".$plug_info['category']."' ");
}
}
}
else
{ // May be useful that we ignore what will usually be copies/backups of plugins - but don't normally say anything
2008-08-09 16:49:58 +00:00
// echo "Plugin copied to wrong directory. Is in: {$plugin_path} Should be: {$plug_info['folder']}<br /><br />";
}
/// print_a($plug_info);
2006-12-02 04:36:16 +00:00
}
// 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->db_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->db_Update('plugin', implode(", ",$temp)." WHERE `plugin_id`={$plug_info['plugin_id']}");
// echo "Updated: ".$plug_path."<br />";
}
2006-12-02 04:36:16 +00:00
}
2008-02-13 00:46:05 +00:00
if ($sp) { save_prefs(); }
2006-12-02 04:36:16 +00:00
}
function manage_icons($plugin='')
{
global $sql,$tp, $iconpool,$pref;
$query = "SELECT * FROM #plugin WHERE plugin_installflag =0 ORDER BY plugin_path ASC";
$sql->db_Select_gen($query);
$list = $sql->db_getList();
$reject_core = array('$.','$..','/','CVS','thumbs.db','*._$', 'index', 'null*');
$reject_plugin = $reject_core;
foreach($list as $val) // reject uninstalled plugin folders.
{
$reject_plugin[] = $val['plugin_path']."/images";
}
require_once(e_HANDLER."file_class.php");
$fl = new e_file;
2009-07-16 08:46:11 +00:00
$filesrch = implode("|",array("_16.png","_16.PNG","_32.png","_32.PNG","_48.png","_48.PNG","_64.png","_64.PNG","_128.png","_128.png"));
if($plugin_icons = $fl->get_files(e_PLUGIN,$filesrch,$reject_plugin,2))
{
sort($plugin_icons);
}
if($core_icons = $fl->get_files(e_IMAGE."icons/",$filesrch,$reject_core,2))
{
sort($core_icons);
}
if($theme_icons = $fl->get_files(e_THEME.$pref['sitetheme']."/images/",$filesrch,$reject_core,2))
{
sort($theme_icons);
}
$srch = array(e_IMAGE,"/");
$repl = array("","-");
$iconpool = array();
foreach($core_icons as $file)
{
$path = str_replace($srch,$repl,$file['path']);
$key = substr("core-".$path,0,-1);
$iconpool[$key][] = $tp->createConstants($file['path'],1).$file['fname'];
}
$srch = array(e_PLUGIN,"/images/","/icons/");
$repl = array("","","");
foreach($plugin_icons as $file)
{
$path = str_replace($srch,$repl,$file['path']);
$key = "plugin-".$path;
$iconpool[$key][] = $tp->createConstants($file['path'],1).$file['fname'];
}
foreach($theme_icons as $file)
{
$path = str_replace($srch,$repl,$file['path']);
$key = "theme-".$path;
$iconpool[$key][] = $tp->createConstants($file['path'],1).$file['fname'];
}
return (save_prefs("iconpool")) ? TRUE : FALSE;
}
2006-12-02 04:36:16 +00:00
/**
2008-08-09 16:49:58 +00:00
* Returns details of a plugin from the plugin table from it's ID
*
* @param int $id
* @return array plugin info
*/
2008-01-28 02:49:50 +00:00
function getinfo($id, $force=false)
{
2008-02-01 14:11:27 +00:00
global $sql;
static $getinfo_results;
2008-01-28 02:49:50 +00:00
if(!is_array($getinfo_results)) { $getinfo_results = array(); }
2008-02-01 14:11:27 +00:00
2008-01-28 02:49:50 +00:00
$id = (int)$id;
2008-02-01 11:52:27 +00:00
if(!isset($getinfo_results[$id]) || $force == true)
2008-01-28 02:49:50 +00:00
{
if ($sql->db_Select('plugin', '*', "plugin_id = ".$id))
{
2008-02-01 14:11:27 +00:00
$getinfo_results[$id] = $sql->db_Fetch();
2008-01-28 02:49:50 +00:00
}
else
{
return false;
}
2006-12-02 04:36:16 +00:00
}
2008-01-28 02:49:50 +00:00
return $getinfo_results[$id];
2006-12-02 04:36:16 +00:00
}
function manage_extended_field($action, $field_name, $field_type, $field_default, $field_source)
{
if(!isset($this->module['ue']))
{
include_once(e_HANDLER.'user_extended_class.php');
$this->module['ue'] = new e107_user_extended;
}
$type = constant($field_type);
if($action == 'add')
{
return $this->module['ue']->user_extended_add_system($field_name, $type, $field_default, $field_source);
}
if ($action == 'remove')
{
return $this->module['ue']->user_extended_remove($field_name, $field_name);
}
}
2008-08-09 16:49:58 +00:00
function manage_userclass($action, $class_name, $class_description)
{
global $sql, $tp, $e107;
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)
{
2008-12-10 13:27:09 +00:00
$tmp = array();
$tmp['userclass_id'] = $i;
$tmp['userclass_name'] = $class_name;
2008-12-10 13:27:09 +00:00
$tmp['userclass_description'] = $class_description;
2008-12-21 01:57:19 +00:00
$tmp['userclass_editclass'] = e_UC_ADMIN;
$tmp['userclass_visibility'] = e_UC_ADMIN;
$tmp['userclass_type'] = UC_TYPE_STD;
$tmp['userclass_parent'] = e_UC_NOBODY;
2008-12-21 01:57:19 +00:00
$tmp['_FIELD_TYPES']['userclass_editclass'] = 'int';
$tmp['_FIELD_TYPES']['userclass_visibility'] = 'int';
2008-12-10 13:27:09 +00:00
$tmp['_FIELD_TYPES']['userclass_id'] = 'int';
$tmp['_FIELD_TYPES']['_DEFAULT'] = 'todb';
return $e107->user_class->add_new_class($tmp);
}
else
{
2006-12-02 04:36:16 +00:00
return FALSE;
}
}
if ($action == 'remove')
{
$classID = $e107->user_class->ucGetClassIDFromName($class_name);
if (($classID !== FALSE)
&& ($e107->user_class->deleteClassAndUsers($classID) === TRUE))
{
return TRUE;
}
else
{
return FALSE;
2006-12-02 04:36:16 +00:00
}
}
}
2008-08-09 16:49:58 +00:00
2008-01-27 01:34:59 +00:00
function manage_link($action, $link_url, $link_name, $link_class=0)
{
2006-12-02 04:36:16 +00:00
global $sql, $tp;
2008-01-27 01:34:59 +00:00
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;
}
2006-12-02 04:36:16 +00:00
$link_url = $tp -> toDB($link_url, true);
$link_name = $tp -> toDB($link_name, true);
2007-06-06 19:25:26 +00:00
$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')
{
2006-12-02 04:36:16 +00:00
$link_t = $sql->db_Count('links');
if (!$sql->db_Count('links', '(*)', "WHERE link_url = '{$path}' OR link_name = '{$link_name}'"))
{
return $sql->db_Insert('links', "0, '{$link_name}', '{$path}', '', '', '1', '".($link_t + 1)."', '0', '0', '{$link_class}' ");
}
else
{
return FALSE;
2006-12-02 04:36:16 +00:00
}
}
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->db_Select('links', 'link_id,link_order', "link_url = '{$path}'")) ||
$sql->db_Select('links', 'link_id,link_order', "link_name = '{$link_name}'"))
{
$row = $sql->db_Fetch();
$sql->db_Update('links', "link_order = link_order - 1 WHERE link_order > {$row['link_order']}");
return $sql->db_Delete('links', "link_id = {$row['link_id']}");
}
2006-12-02 04:36:16 +00:00
}
}
2008-08-09 16:49:58 +00:00
// 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)
{
2008-08-09 16:49:58 +00:00
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);
}
2008-08-09 16:49:58 +00:00
switch ($prefType)
{
2008-08-09 16:49:58 +00:00
case 'pref' :
switch ($action)
{
2008-08-09 16:49:58 +00:00
case 'add' :
$pref[$k] = $v;
break;
2008-08-09 16:49:58 +00:00
case 'update' :
case 'refresh' :
2008-08-09 16:49:58 +00:00
// Only update if $pref doesn't exist
if (!isset($pref[$k])) $pref[$k] = $v;
break;
2008-08-09 16:49:58 +00:00
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;
}
2008-08-09 16:49:58 +00:00
break;
case 'listPref' :
$tmp = array();
if (isset($pref[$k])) $tmp = explode(',',$pref[$k]);
switch ($action)
{
case 'add' :
case 'update' :
case 'refresh' :
2008-08-09 16:49:58 +00:00
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 'refresh' :
2008-08-09 16:49:58 +00:00
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;
2006-12-02 04:36:16 +00:00
}
2008-08-09 16:49:58 +00:00
}
save_prefs();
2006-12-02 04:36:16 +00:00
}
2008-08-09 16:49:58 +00:00
2008-02-02 22:04:18 +00:00
function manage_comments($action, $comment_id)
{
2006-12-02 04:36:16 +00:00
global $sql, $tp;
2008-02-02 22:04:18 +00:00
$tmp = array();
if($action == 'remove')
{
foreach($comment_id as $com)
{
$tmp[] = "comment_type='".$tp -> toDB($com, true)."'";
2006-12-02 04:36:16 +00:00
}
$qry = implode(" OR ",$tmp);
2008-08-17 12:02:14 +00:00
// echo $qry."<br />";
2008-02-02 22:04:18 +00:00
return $sql->db_Delete('comments', $qry);
}
2006-12-02 04:36:16 +00:00
}
// 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)
{
global $sql;
if (!is_array($var)) return FALSE; // Return if nothing to do
switch ($action)
{
case 'add' :
foreach($var as $tab)
{
if (!$sql->db_Query($tab))
{
return FALSE;
}
2006-12-02 04:36:16 +00:00
}
return TRUE;
break;
case 'upgrade' :
foreach($var as $tab)
{
if (!$sql->db_Query_all($tab))
{
2006-12-02 04:36:16 +00:00
return FALSE;
}
}
return TRUE;
break;
case 'remove' :
foreach($var as $tab)
{
2006-12-02 04:36:16 +00:00
$qry = 'DROP TABLE '.MPREFIX.$tab;
if (!$sql->db_Query_all($qry))
{
2006-12-02 04:36:16 +00:00
return $tab;
}
}
return TRUE;
break;
}
return FALSE;
2006-12-02 04:36:16 +00:00
}
2008-08-09 16:49:58 +00:00
// 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
2006-12-02 04:36:16 +00:00
global $pref;
2008-08-24 09:57:08 +00:00
/*
if ($prefname == 'plug_sc' || $prefname == 'plug_bb')
{ // Special cases - shortcodes and bbcodes - each plugin may contribute several elements
foreach($varArray as $code)
{
2006-12-02 04:36:16 +00:00
$prefvals[] = "$code:$plugin_folder";
}
}
else
{
2008-08-24 09:57:08 +00:00
*/
$prefvals[] = $varArray;
// $prefvals[] = $plugin_folder;
2008-08-24 09:57:08 +00:00
// }
2006-12-02 04:36:16 +00:00
$curvals = explode(',', $pref[$prefname]);
if ($action == 'add')
{
2006-12-02 04:36:16 +00:00
$newvals = array_merge($curvals, $prefvals);
}
if ($action == 'remove')
{
foreach($prefvals as $v)
{
if (($i = array_search($v, $curvals)) !== FALSE)
{
unset($curvals[$i]);
}
2006-12-02 04:36:16 +00:00
}
$newvals = $curvals;
2006-12-02 04:36:16 +00:00
}
$newvals = array_unique($newvals);
$pref[$prefname] = implode(',', $newvals);
2006-12-02 04:36:16 +00:00
if(substr($pref[$prefname], 0, 1) == ",")
{
$pref[$prefname] = substr($pref[$prefname], 1);
2006-12-02 04:36:16 +00:00
}
save_prefs();
}
2008-08-09 16:49:58 +00:00
function manage_search($action, $eplug_folder)
{
2006-12-02 04:36:16 +00:00
global $sql, $sysprefs;
$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')
{
2006-12-02 04:36:16 +00:00
$install_default = $default ? TRUE : FALSE;
$install_comments = $comments ? TRUE : FALSE;
}
else if ($action == 'remove')
{
2006-12-02 04:36:16 +00:00
$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]))
{
2006-12-02 04:36:16 +00:00
$uninstall_default = $default ? FALSE : TRUE;
}
else
{
2006-12-02 04:36:16 +00:00
$install_default = $default ? TRUE : FALSE;
}
if (isset($search_prefs['comments_handlers'][$eplug_folder]))
{
2006-12-02 04:36:16 +00:00
$uninstall_comments = $comments ? FALSE : TRUE;
}
else
{
2006-12-02 04:36:16 +00:00
$install_comments = $comments ? TRUE : FALSE;
}
}
if ($install_default)
{
2006-12-02 04:36:16 +00:00
$search_prefs['plug_handlers'][$eplug_folder] = array('class' => 0, 'pre_title' => 1, 'pre_title_alt' => '', 'chars' => 150, 'results' => 10);
}
else if ($uninstall_default)
{
2006-12-02 04:36:16 +00:00
unset($search_prefs['plug_handlers'][$eplug_folder]);
}
if ($install_comments)
{
2006-12-02 04:36:16 +00:00
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 ($uninstall_comments)
{
2006-12-02 04:36:16 +00:00
unset($search_prefs['comments_handlers'][$eplug_folder]);
}
$tmp = addslashes(serialize($search_prefs));
$sql->db_Update("core", "e107_value = '{$tmp}' WHERE e107_name = 'search_prefs' ");
}
function manage_notify($action, $eplug_folder)
{
2006-12-02 04:36:16 +00:00
global $sql, $sysprefs, $eArrayStorage, $tp;
$notify_prefs = $sysprefs -> get('notify_prefs');
$notify_prefs = $eArrayStorage -> ReadArray($notify_prefs);
$e_notify = file_exists(e_PLUGIN.$eplug_folder.'/e_notify.php') ? TRUE : FALSE;
if ($action == 'add')
{
2006-12-02 04:36:16 +00:00
$install_notify = $e_notify ? TRUE : FALSE;
}
else if ($action == 'remove')
{
2006-12-02 04:36:16 +00:00
$uninstall_notify = isset($notify_prefs['plugins'][$eplug_folder]) ? TRUE : FALSE;
}
else if ($action == 'upgrade')
{
if (isset($notify_prefs['plugins'][$eplug_folder]))
{
2006-12-02 04:36:16 +00:00
$uninstall_notify = $e_notify ? FALSE : TRUE;
}
else
{
2006-12-02 04:36:16 +00:00
$install_notify = $e_notify ? TRUE : FALSE;
}
}
if ($install_notify)
{
2006-12-02 04:36:16 +00:00
$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['event'][$event_id] = array('class' => e_UC_NOBODY, 'email' => '');
2006-12-02 04:36:16 +00:00
}
}
else if ($uninstall_notify)
{
2006-12-02 04:36:16 +00:00
unset($notify_prefs['plugins'][$eplug_folder]);
require_once(e_PLUGIN.$eplug_folder.'/e_notify.php');
foreach ($config_events as $event_id => $event_text)
{
2006-12-02 04:36:16 +00:00
unset($notify_prefs['event'][$event_id]);
}
}
$s_prefs = $tp -> toDB($notify_prefs);
2008-01-26 05:19:59 +00:00
$s_prefs = $eArrayStorage->WriteArray($s_prefs);
2006-12-02 04:36:16 +00:00
$sql -> db_Update("core", "e107_value='".$s_prefs."' WHERE e107_name='notify_prefs'");
}
2008-12-13 18:43:46 +00:00
function displayArray(&$array, $msg='')
{
$txt = ($msg ? $msg.'<br />' : '');
foreach($array as $_k => $_v)
{
$txt .= "{$_k} -> {$_v}<br />";
}
$txt .='<br />';
return $txt;
}
2008-08-09 16:49:58 +00:00
//----------------------------------------------------------
// Install routine for XML file
//----------------------------------------------------------
// $id - the number of the plugin in the DB
// Values for $function:
// 'install'
// 'upgrade'
// 'uninstall'
// 'refresh' - adds things that are missing, but doesn't change any existing settings
// $options is an array of possible options - ATM used only for uninstall:
// 'del_userclasses' - to delete userclasses created
// 'del_tables' - to delete DB tables
// 'del_extended' - to delete extended fields
function manage_plugin_xml($id, $function='', $options = FALSE)
{
2008-08-09 16:49:58 +00:00
global $sql, $pref;
$error = array(); // Array of error messages
$canContinue = TRUE; // Clear flag if must abort part way through
2008-01-28 02:49:50 +00:00
$id = (int)$id;
2008-08-09 16:49:58 +00:00
$plug = $this->getinfo($id); // Get plugin info from DB
2008-02-02 03:23:47 +00:00
$this->current_plug = $plug;
2008-02-02 22:04:18 +00:00
$txt = '';
2008-02-01 14:11:27 +00:00
$path = e_PLUGIN.$plug['plugin_path'].'/';
2008-02-02 03:23:47 +00:00
2008-08-09 16:49:58 +00:00
2008-02-01 14:11:27 +00:00
$addons = explode(',', $plug['plugin_addons']);
$sql_list = array();
foreach($addons as $addon)
{
if(substr($addon, -4) == '_sql')
{
$sql_list[] = $addon.'.php';
}
}
2008-01-28 02:49:50 +00:00
2008-01-27 01:34:59 +00:00
if(!file_exists($path.'plugin.xml') || $function == '')
{
$error[] = EPL_ADLAN_77;
$canContinue = FALSE;
2008-01-27 01:34:59 +00:00
}
if($canContinue && $this->parse_plugin_xml($plug['plugin_path']))
2008-01-27 01:34:59 +00:00
{
$plug_vars = $this->plug_vars;
2008-01-27 01:34:59 +00:00
}
else
{
$error[] = EPL_ADLAN_76;
$canContinue = FALSE;
2008-08-09 16:49:58 +00:00
}
// First of all, see if there's a language file specific to install
if (isset($plug_vars['installLanguageFile']) && isset($plug_vars['installLanguageFile']['@attributes']['filename']))
{
include_lan($path.str_replace('--LAN--',e_LANGUAGE, $plug_vars['installLanguageFile']['@attributes']['filename']));
}
// Next most important, if installing or upgrading, check that any dependencies are met
2008-08-09 16:49:58 +00:00
if ($canContinue && ($function != 'uninstall') && isset($plug_vars['depends']))
{
foreach ($plug_vars['depends'] as $dt => $dv)
{
if (isset($dv['@attributes']) && isset($dv['@attributes']['name']))
{
// echo "Check {$dt} dependency: {$dv['@attributes']['name']} version {$dv['@attributes']['min_version']}<br />";
2008-08-09 16:49:58 +00:00
switch ($dt)
{
case 'plugin' :
if (!isset($pref['plug_installed'][$dv['@attributes']['name']]))
2008-08-09 16:49:58 +00:00
{ // 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' :
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' :
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 />";
}
}
}
}
// Temporary error handling - need to do something with this
if (!$canContinue)
{
echo '<b>'.LAN_INSTALL_FAIL.'</b><br />'.implode('<br />',$error);
2008-08-09 16:49:58 +00:00
return false;
2008-01-27 01:34:59 +00:00
}
2008-02-01 14:11:27 +00:00
2008-08-09 16:49:58 +00:00
// All the dependencies are OK - can start the install now
if ($canContinue)
{ // Let's call any custom pre functions defined in <management> section
2008-08-17 12:02:14 +00:00
$ret = $this->execute_function($path, $function, 'pre');
if (!is_bool($ret)) $txt .= $ret;
}
if ($canContinue && count($sql_list))
{ // Handle tables
require_once(e_HANDLER.'db_table_admin_class.php');
$dbHandler = new db_table_admin;
foreach($sql_list as $sqlFile)
2008-01-27 01:34:59 +00:00
{
$tableList = $dbHandler->get_table_def('',$path.$sqlFile);
if (!is_array($tableList))
2008-01-27 01:34:59 +00:00
{
$error[] = '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)
2008-01-27 01:34:59 +00:00
{
case 'install' :
2008-08-15 13:15:11 +00:00
$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]} ... ";
$result = $this->manage_tables('add', array($sqlTable)); // Pass the statement to create the table
$txt .= ($result ? "Success" : "Failed!").'<br />';
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 (varsettrue($options['del_tables'], FALSE))
{
$txt .= "Removing table {$ct[1]} <br />";
$this->manage_tables('remove', array($ct[1])); // Delete the table
}
else
{
$txt .= "Table {$ct[1]} left in place<br />";
}
break;
2008-01-27 01:34:59 +00:00
}
}
}
}
//main menu items
if(isset($plug_vars['menuLink']))
{
//Ensure it is the right sort of array for use with foreach()
if(count($plug_vars['menuLink']) <= 1)
2008-01-27 01:34:59 +00:00
{
$plug_vars['menuLink'] = array($plug_vars['menuLink']);
}
foreach($plug_vars['menuLink'] as $link)
2008-01-27 01:34:59 +00:00
{
$attrib = $link['@attributes'];
$linkName = $attrib['name'];
if (defined($linkName))
{
$linkName = constant($linkName);
}
2008-01-27 01:34:59 +00:00
switch($function)
{
case 'upgrade':
case 'install':
// Add any active link
if(!isset($attrib['active']) || $attrib['active'] == 'true')
{
$addlink = e_PLUGIN.$attrib['url'];
$perm = (isset($attrib['perm']) ? $attrib['perm'] : 0);
$txt .= "Adding link {$linkName} with url [{$addlink}] and perm {$perm} <br />";
$this->manage_link('add', $addlink, $linkName, $perm);
}
//remove inactive links on upgrade
if($function == 'upgrade' && isset($attrib['active']) && $attrib['active'] == 'false')
{
$txt .= "Removing link {$linkName} with url [{$attrib['url']}] <br />";
$this->manage_link('remove', $attrib['url'], $linkName);
}
break;
case 'refresh' : // Probably best to leave well alone
break;
case 'uninstall':
//remove all links
$txt .= "Removing link {$linkName} with url [{$attrib['url']}] <br />";
$this->manage_link('remove', $attrib['url'], $linkName);
break;
2008-01-27 01:34:59 +00:00
}
}
}
2008-02-01 14:11:27 +00:00
2008-01-27 01:34:59 +00:00
//main pref items
if(isset($plug_vars['mainPrefs']))
{
2008-08-09 16:49:58 +00:00
foreach (array('pref','listPref','arrayPref') as $prefType)
{
if(isset($plug_vars['mainPrefs'][$prefType]))
2008-01-27 01:34:59 +00:00
{
2008-08-09 16:49:58 +00:00
$list = $this->parse_prefs($plug_vars['mainPrefs'][$prefType]);
switch($function)
{
case 'install':
2008-02-01 14:11:27 +00:00
if(is_array($list['active']))
{
2008-12-13 18:43:46 +00:00
$txt .= $this->displayArray($list['active'], "Adding '{$prefType}' prefs:");
$this->manage_prefs('add', $list['active'], $prefType, $plug['plugin_path'], TRUE);
2008-08-09 16:49:58 +00:00
}
break;
case 'upgrade' :
case 'refresh' : // Add any defined prefs which don't already exist
2008-08-09 16:49:58 +00:00
if(is_array($list['active']))
{
2008-12-13 18:43:46 +00:00
$txt .= $this->displayArray($list['active'], "Updating '{$prefType}' prefs:");
$this->manage_prefs('update', $list['active'], $prefType, $plug['plugin_path'], TRUE); // This only adds prefs which aren't already defined
2008-02-01 14:11:27 +00:00
}
//If upgrading, removing any inactive pref
2008-08-09 16:49:58 +00:00
if(is_array($list['inactive']))
2008-02-01 14:11:27 +00:00
{
2008-12-13 18:43:46 +00:00
$txt .= $this->displayArray($list['inactive'], "Removing '{$prefType}' prefs:");
$this->manage_prefs('remove', $list['inactive'], $prefType, $plug['plugin_path'], TRUE);
2008-02-01 14:11:27 +00:00
}
break;
2008-01-27 01:34:59 +00:00
//If uninstalling, remove all prefs (active or inactive)
2008-08-09 16:49:58 +00:00
case 'uninstall':
2008-02-01 14:11:27 +00:00
if(is_array($list['all']))
{
2008-12-13 18:43:46 +00:00
$txt .= $this->displayArray($list['all'], "Removing '{$prefType}' prefs:");
$this->manage_prefs('remove', $list['all'], $prefType, $plug['plugin_path'], TRUE);
2008-02-01 14:11:27 +00:00
}
break;
2008-08-09 16:49:58 +00:00
}
2008-01-27 01:34:59 +00:00
}
2008-08-09 16:49:58 +00:00
}
2008-01-27 01:34:59 +00:00
}
2008-02-01 14:11:27 +00:00
2008-01-27 05:16:03 +00:00
//Userclasses
//$this->manage_userclass('add', $eplug_userclass, $eplug_userclass_description);
2008-02-02 22:04:18 +00:00
if(isset($plug_vars['userclass']))
2008-01-27 05:16:03 +00:00
{
2008-02-02 22:04:18 +00:00
$uclass_list = (isset($plug_vars['userclass'][0]) ? $plug_vars['userclass'] : array($plug_vars['userclass']));
foreach($uclass_list as $uclass)
2008-01-27 05:16:03 +00:00
{
2008-02-02 22:04:18 +00:00
$attrib = $uclass['@attributes'];
switch($function)
2008-01-27 05:16:03 +00:00
{
case 'install' :
case 'upgrade' :
case 'refresh' :
// Add all active userclasses (code checks for already installed)
2008-02-02 22:04:18 +00:00
if(!isset($attrib['active']) || $attrib['active'] == 'true')
2008-01-27 05:16:03 +00:00
{
$txt .= 'Adding userclass '.$attrib['name'].'<br />';
2008-02-02 22:04:18 +00:00
$this->manage_userclass('add', $attrib['name'], $attrib['description']);
}
2008-02-01 14:11:27 +00:00
2008-02-02 22:04:18 +00:00
//If upgrading, removing any inactive userclass
if($function == 'upgrade' && isset($attrib['active']) && $attrib['active'] == 'false')
{
$txt .= 'Removing userclass '.$attrib['name'].'<br />';
2008-02-02 03:23:47 +00:00
$this->manage_userclass('remove', $attrib['name'], $attrib['description']);
2008-01-27 05:16:03 +00:00
}
2008-02-02 22:04:18 +00:00
break;
//If uninstalling, remove all userclasses (active or inactive)
case 'uninstall':
if (varsettrue($options['del_userclasses'], FALSE))
{
$txt .= 'Removing userclass '.$attrib['name'].'<br />';
$this->manage_userclass('remove', $attrib['name'], $attrib['description']);
}
else
{
$txt .= 'userclass '.$attrib['name'].' left in place<br />';
}
2008-02-02 22:04:18 +00:00
break;
2008-01-27 05:16:03 +00:00
}
}
}
//Extended user fields
if(isset($plug_vars['extendedField']))
{
$efield_list = (isset($plug_vars['extendedField'][0]) ? $plug_vars['extendedField'] : array($plug_vars['extendedFields']));
foreach($efield_list as $efield)
{
$attrib = $efield['@attributes'];
$attrib['default'] = varset($attrib['default']);
$attrib['name'] = 'plugin_'.$plug_vars['folder'].'_'.$attrib['name'];
$source = 'plugin_'.$plug_vars['folder'];
switch($function)
{
case 'install':
case 'upgrade':
// Add all active extended fields
if(!isset($attrib['active']) || $attrib['active'] == 'true')
{
$txt .= 'Adding extended field: '.$attrib['name'].' ... ';
$result = $this->manage_extended_field('add', $attrib['name'], $attrib['type'], $attrib['default'], $source);
$txt .= ($result ? LAN_CREATED : LAN_CREATED_FAILED).'<br />';
}
//If upgrading, removing any inactive extended fields
if($function == 'upgrade' && isset($attrib['active']) && $attrib['active'] == 'false')
{
$txt .= 'Removing extended field: '.$attrib['name'].' ... ';
$result = $this->manage_extended_field('remove', $attrib['name'], $source);
$txt .= ($result ? LAN_DELETED : LAN_DELETED_FAILED).'<br />';
}
break;
//If uninstalling, remove all extended fields (active or inactive)
case 'uninstall':
if (varsettrue($options['del_extended'], FALSE))
{
$txt .= 'Removing extended field: '.$attrib['name'].' ... ';
$result = $this->manage_extended_field('remove', $attrib['name'], $source);
$txt .= ($result ? LAN_DELETED : LAN_DELETED_FAILED).'<br />';
}
else
{
$txt .= 'Extended field: '.$attrib['name'].' left in place<br />';
}
break;
}
}
}
2008-08-09 16:49:58 +00:00
//If any commentIDs are configured, we need to remove all comments on uninstall
2008-02-02 22:04:18 +00:00
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 />';
2008-02-02 22:04:18 +00:00
$this->manage_comments('remove', $commentArray);
}
2008-02-01 14:11:27 +00:00
2008-02-02 22:04:18 +00:00
$this->manage_search($function, $plug_vars['folder']);
$this->manage_notify($function, $plug_vars['folder']);
2008-08-09 16:49:58 +00:00
// Now any 'custom' values for update, language file definitions etc
if (isset($plug_vars['management']['upgradeCheck']))
{
$tmp = $plug_vars['management']['upgradeCheck'];
switch ($function)
{
case 'install' :
case 'upgrade' :
case 'refresh' :
2008-08-09 16:49:58 +00:00
$pref['upgradeCheck'][$plug['plugin_path']]['url'] = $tmp['@attributes']['url'];
$pref['upgradeCheck'][$plug['plugin_path']]['method'] = varset($tmp['@attributes']['method'],'sf_news');
$pref['upgradeCheck'][$plug['plugin_path']]['id'] = varset($tmp['@attributes']['id'],$plug['plugin_path']);
2008-08-09 16:49:58 +00:00
break;
case 'uninstall' :
unset($pref['upgradeCheck'][$plug['plugin_path']]);
break;
}
unset($tmp);
}
if (isset($plug_vars['logLanguageFile']))
{
switch ($function)
{
case 'install' :
case 'upgrade' :
case 'refresh' :
2008-08-09 16:49:58 +00:00
$pref['logLanguageFile'][$plug['plugin_path']] = $plug_vars['logLanguageFile']['@attributes']['filename'];
break;
case 'uninstall' :
if (isset($pref['logLanguageFile'][$plug['plugin_path']])) unset($pref['logLanguageFile'][$plug['plugin_path']]);
2008-08-09 16:49:58 +00:00
break;
}
}
save_prefs();
2008-08-17 12:02:14 +00:00
if ($canContinue)
{ // Let's call any custom post functions defined in <management> section
$ret = $this->execute_function($path, $function, 'post');
if (!is_bool($ret)) $txt .= $ret;
}
2008-01-28 02:49:50 +00:00
2008-02-02 03:23:47 +00:00
$eplug_addons = $this->getAddons($plug['plugin_path']);
2008-02-08 20:05:43 +00:00
if($function == 'install' || $function == 'upgrade')
2008-01-28 02:49:50 +00:00
{
$sql->db_Update('plugin', "plugin_installflag = 1, plugin_addons = '{$eplug_addons}', plugin_version = '{$plug_vars['@attributes']['version']}' WHERE plugin_id = ".$id);
$pref['plug_installed'][$plug['plugin_path']] = $plug_vars['@attributes']['version'];
2008-01-28 02:49:50 +00:00
save_prefs();
}
if($function == 'uninstall')
{
$sql->db_Update('plugin', "plugin_installflag = 0, plugin_addons = '{$eplug_addons}', plugin_version = '{$plug_vars['@attributes']['version']}' WHERE plugin_id = ".$id);
2008-08-09 16:49:58 +00:00
unset($pref['plug_installed'][$plug['plugin_path']]);
save_prefs();
}
2008-01-28 02:49:50 +00:00
if($function == 'install')
{
2008-02-02 22:04:18 +00:00
$txt .= LAN_INSTALL_SUCCESSFUL."<br />";
2008-01-28 02:49:50 +00:00
if(isset($plug_vars['installDone']))
{
2008-02-02 22:04:18 +00:00
$txt .= $plug_vars['installDone'];
2008-01-28 02:49:50 +00:00
}
}
2008-02-02 22:04:18 +00:00
return $txt;
}
2006-12-02 04:36:16 +00:00
function execute_function($path = '', $what='', $when='')
{
if($what == '' || $when == '') { return true; }
if(!isset($this->plug_vars['management'][$what])) { return true; }
$vars = $this->plug_vars['management'][$what];
if(count($vars) <= 1) { $vars = array($vars); }
foreach($vars as $var)
{
$attrib = $var['@attributes'];
if(isset($attrib['when']) && $attrib['when'] == $when)
{
if(is_readable($path.$attrib['file']))
{
include_once($path.$attrib['file']);
if($attrib['type'] == 'fileFunction')
{
2008-02-02 03:23:47 +00:00
$result = call_user_func($attrib['function'], $this);
return $result;
}
elseif($attrib['type'] == 'classFunction')
{
$_tmp = new $attrib['class'];
2008-02-02 03:23:47 +00:00
$result = call_user_func(array($_tmp, $attrib['function']), $this);
return $result;
}
}
}
}
2008-02-01 14:11:27 +00:00
}
2008-01-26 05:19:59 +00:00
function parse_prefs($pref_array)
{
$ret = array();
if(!isset($pref_array[0]))
{
$pref_array = array($pref_array);
}
if(is_array($pref_array))
{
foreach($pref_array as $k => $p)
{
$attrib = $p['@attributes'];
if(isset($attrib['type']) && $attrib['type'] == 'array')
{
$name = $attrib['name'];
$tmp = $this->parse_prefs($pref_array[$k]['key']);
$ret['all'][$name] = $tmp['all'];
$ret['active'][$name] = $tmp['active'];
$ret['inactive'][$name] = $tmp['inactive'];
}
else
{
$ret['all'][$attrib['name']] = $attrib['value'];
if(!isset($attrib['active']) || $attrib['active'] == 'true')
{
$ret['active'][$attrib['name']] = $attrib['value'];
}
else
{
$ret['inactive'][$attrib['name']] = $attrib['value'];
}
}
}
}
return $ret;
}
2008-01-28 02:49:50 +00:00
function install_plugin_php($id)
2008-01-26 05:19:59 +00:00
{
2008-01-27 01:34:59 +00:00
global $sql;
2008-02-01 14:11:27 +00:00
2008-01-28 02:49:50 +00:00
$plug = $this->getinfo($id);
2008-02-01 14:11:27 +00:00
$_path = e_PLUGIN.$plug['plugin_path'].'/';
2008-01-28 02:49:50 +00:00
$plug['plug_action'] = 'install';
2006-12-02 04:36:16 +00:00
// $plug_vars = $this->parse_plugin_php($plug['plugin_path']);
include($_path.'plugin.php');
2008-01-26 05:19:59 +00:00
$func = $eplug_folder.'_install';
if (function_exists($func))
{
2008-01-26 05:19:59 +00:00
$text .= call_user_func($func);
}
2006-12-02 04:36:16 +00:00
2008-01-26 05:19:59 +00:00
if (is_array($eplug_tables))
{
$result = $this->manage_tables('add', $eplug_tables);
if ($result === TRUE)
{
2008-01-26 05:19:59 +00:00
$text .= EPL_ADLAN_19.'<br />';
//success
2006-12-02 04:36:16 +00:00
}
2008-01-26 05:19:59 +00:00
else
{
2008-01-26 05:19:59 +00:00
$text .= EPL_ADLAN_18.'<br />';
//fail
2006-12-02 04:36:16 +00:00
}
2008-01-26 05:19:59 +00:00
}
2006-12-02 04:36:16 +00:00
2008-01-26 05:19:59 +00:00
if (is_array($eplug_prefs))
{
$this->manage_prefs('add', $eplug_prefs);
$text .= EPL_ADLAN_8.'<br />';
}
2006-12-02 04:36:16 +00:00
2008-01-26 05:19:59 +00:00
if (is_array($eplug_array_pref))
{
foreach($eplug_array_pref as $key => $val)
{
2008-01-26 05:19:59 +00:00
$this->manage_plugin_prefs('add', $key, $eplug_folder, $val);
2006-12-02 04:36:16 +00:00
}
2008-01-26 05:19:59 +00:00
}
2008-08-24 09:57:08 +00:00
/*
2008-01-26 05:19:59 +00:00
if (is_array($eplug_sc))
{
$this->manage_plugin_prefs('add', 'plug_sc', $eplug_folder, $eplug_sc);
}
2006-12-02 04:36:16 +00:00
2008-01-26 05:19:59 +00:00
if (is_array($eplug_bb))
{
$this->manage_plugin_prefs('add', 'plug_bb', $eplug_folder, $eplug_bb);
}
2008-08-24 09:57:08 +00:00
*/
2008-01-26 05:19:59 +00:00
if ($eplug_link === TRUE && $eplug_link_url != '' && $eplug_link_name != '')
{
2008-01-27 01:34:59 +00:00
$linkperm = (isset($eplug_link_perms) ? $eplug_link_perms : e_UC_PUBLIC);
$this->manage_link('add', $eplug_link_url, $eplug_link_name, $linkperm);
2008-01-26 05:19:59 +00:00
}
2006-12-02 04:36:16 +00:00
2008-01-26 05:19:59 +00:00
if ($eplug_userclass)
{
$this->manage_userclass('add', $eplug_userclass, $eplug_userclass_description);
}
2006-12-02 04:36:16 +00:00
2008-01-26 05:19:59 +00:00
$this -> manage_search('add', $eplug_folder);
$this -> manage_notify('add', $eplug_folder);
2006-12-02 04:36:16 +00:00
2008-01-26 05:19:59 +00:00
$eplug_addons = $this->getAddons($eplug_folder);
2006-12-02 04:36:16 +00:00
2008-01-26 05:19:59 +00:00
$sql->db_Update('plugin', "plugin_installflag = 1, plugin_addons = '{$eplug_addons}' WHERE plugin_id = ".(int)$id);
$pref['plug_installed'][$plugin_path] = $plug['plugin_version'];
save_prefs();
2006-12-02 04:36:16 +00:00
2008-01-26 05:19:59 +00:00
$text .= (isset($eplug_done) ? "<br />{$eplug_done}" : "<br />".LAN_INSTALL_SUCCESSFUL);
2006-12-02 04:36:16 +00:00
2008-01-26 05:19:59 +00:00
return $text;
}
2008-01-26 05:19:59 +00:00
/**
* Installs a plugin by ID
*
* @param int $id
*/
function install_plugin($id)
{
global $sql, $ns, $sysprefs, $mySQLprefix, $tp;
// install plugin ...
2008-01-28 02:49:50 +00:00
$id = (int)$id;
2008-01-26 05:19:59 +00:00
$plug = $this->getinfo($id);
2008-01-26 05:19:59 +00:00
$plug['plug_action'] = 'install';
2008-01-26 05:19:59 +00:00
if ($plug['plugin_installflag'] == FALSE)
{
$_path = e_PLUGIN.$plug['plugin_path'].'/';
2008-01-27 01:34:59 +00:00
if(file_exists($_path.'plugin.xml'))
2008-01-26 05:19:59 +00:00
{
2008-02-01 14:11:27 +00:00
$text = $this->manage_plugin_xml($id, 'install');
2008-01-26 05:19:59 +00:00
}
2008-01-27 01:34:59 +00:00
elseif(file_exists($_path.'plugin.php'))
2008-01-26 05:19:59 +00:00
{
2008-01-28 02:49:50 +00:00
$text = $this->install_plugin_php($id);
}
}
else
{
2006-12-02 04:36:16 +00:00
$text = EPL_ADLAN_21;
}
2008-02-02 22:04:18 +00:00
return $text;
2006-12-02 04:36:16 +00:00
}
function save_addon_prefs()
{ // scan the plugin table and create path-array-prefs for each addon.
2006-12-02 04:36:16 +00:00
global $sql,$pref;
// $query = "SELECT * FROM #plugin WHERE plugin_installflag = 1 AND plugin_addons !='' ORDER BY plugin_path ASC";
$query = "SELECT * FROM #plugin WHERE plugin_addons !='' ORDER BY plugin_path ASC";
2006-12-02 04:36:16 +00:00
// clear all addon prefs before re-creation.
2006-12-02 04:36:16 +00:00
unset($pref['shortcode_list'],$pref['bbcode_list'],$pref['e_sql_list']);
foreach($this->plugin_addons as $plg)
2006-12-02 04:36:16 +00:00
{
unset($pref[$plg."_list"]);
2006-12-02 04:36:16 +00:00
}
if ($sql -> db_Select_gen($query))
{
while($row = $sql-> db_Fetch())
{
$is_installed = ($row['plugin_installflag'] == 1 );
$tmp = explode(",",$row['plugin_addons']);
2006-12-02 04:36:16 +00:00
$path = $row['plugin_path'];
if ($is_installed)
2006-12-02 04:36:16 +00:00
{
foreach($tmp as $val)
2006-12-02 04:36:16 +00:00
{
if(strpos($val, 'e_') === 0)
{
$pref[$val."_list"][$path] = $path;
}
2006-12-02 04:36:16 +00:00
}
}
// search for .bb and .sc files.
2006-12-02 04:36:16 +00:00
$sc_array = array();
$bb_array = array();
$sql_array = array();
foreach($tmp as $adds)
2006-12-02 04:36:16 +00:00
{
if(substr($adds,-3) == ".sc")
2006-12-02 04:36:16 +00:00
{
$sc_name = substr($adds, 0,-3); // remove the .sc
if ($is_installed)
{
$sc_array[$sc_name] = "0"; // default userclass = e_UC_PUBLIC
}
else
{
$sc_array[$sc_name] = e_UC_NOBODY; // register shortcode, but disable it
}
2006-12-02 04:36:16 +00:00
}
if($is_installed && (substr($adds,-3) == ".bb"))
2006-12-02 04:36:16 +00:00
{
$bb_name = substr($adds, 0,-3); // remove the .bb
$bb_array[$bb_name] = "0"; // default userclass.
2006-12-02 04:36:16 +00:00
}
if($is_installed && (substr($adds,-4) == "_sql"))
2006-12-02 04:36:16 +00:00
{
$pref['e_sql_list'][$path] = $adds;
}
}
// Build Bbcode list (will be empty if plugin not installed)
if(count($bb_array) > 0)
2006-12-02 04:36:16 +00:00
{
ksort($bb_array);
$pref['bbcode_list'][$path] = $bb_array;
2006-12-02 04:36:16 +00:00
}
else
{
if (isset($pref['bbcode_list'][$path])) unset($pref['bbcode_list'][$path]);
2006-12-02 04:36:16 +00:00
}
// Build shortcode list - do if uninstalled as well
if(count($sc_array) > 0)
{
ksort($sc_array);
$pref['shortcode_list'][$path] = $sc_array;
}
2006-12-02 04:36:16 +00:00
else
{
if(isset($pref['shortcode_list'][$path])) unset($pref['shortcode_list'][$path]);
2006-12-02 04:36:16 +00:00
}
}
}
save_prefs();
if($this->manage_icons())
{
// echo 'IT WORKED';
}
else
{
// echo "didn't work!";
}
2006-12-02 04:36:16 +00:00
return;
}
// return a list of available plugin addons for the specified plugin. e_xxx etc.
// $debug = TRUE - prints diagnostics
// $debug = 'check' - checks each file found for php tags - prints 'pass' or 'fail'
function getAddons($plugin_path, $debug=FALSE)
{
global $fl;
2006-12-02 04:36:16 +00:00
if(!is_object($fl)){
require_once(e_HANDLER.'file_class.php');
$fl = new e_file;
}
$p_addons = array();
$addonlist = $fl->get_files(e_PLUGIN.$plugin_path, "^e_.*\.php$", "standard", 1);
// print_a($addonlist);
foreach($addonlist as $f)
{
if(preg_match("#^(e_.*)\.php$#", $f['fname'], $matches))
{
$addon = $matches[1];
if(is_readable(e_PLUGIN.$plugin_path."/".$f['fname']))
{
if ($debug === 'check')
{
$passfail = '';
$file_text = file_get_contents(e_PLUGIN.$plugin_path."/".$f['fname']);
if ((substr($file_text,0,5) != '<'.'?php') || (substr($file_text,-2,2) !='?>'))
{
$passfail = '<b>fail</b>';
}
else
{
$passfail = 'pass';
}
echo $plugin_path."/".$addon.".php - ".$passfail."<br />";
}
$p_addons[] = $addon;
}
}
2006-12-02 04:36:16 +00:00
}
// Grab List of Shortcodes & BBcodes
$shortcodeList = $fl->get_files(e_PLUGIN.$plugin_path, ".sc$", "standard", 1);
$bbcodeList = $fl->get_files(e_PLUGIN.$plugin_path, ".bb$", "standard", 1);
$sqlList = $fl->get_files(e_PLUGIN.$plugin_path, "_sql.php$", "standard", 1);
2006-12-02 04:36:16 +00:00
// Search Shortcodes
foreach($shortcodeList as $sc)
{
if(is_readable(e_PLUGIN.$plugin_path."/".$sc['fname']))
{
$p_addons[] = $sc['fname'];
}
}
// Search Bbcodes.
foreach($bbcodeList as $bb)
2006-12-02 04:36:16 +00:00
{
if(is_readable(e_PLUGIN.$plugin_path."/".$bb['fname']))
{
$p_addons[] = $bb['fname'];
}
}
// Search _sql files.
foreach($sqlList as $esql)
2006-12-02 04:36:16 +00:00
{
if(is_readable(e_PLUGIN.$plugin_path."/".$esql['fname']))
{
$fname = str_replace(".php","",$esql['fname']);
if (!in_array($fname, $p_addons)) $p_addons[] = $fname; // Probably already found - avoid duplication
2006-12-02 04:36:16 +00:00
}
}
if($debug == true)
2006-12-02 04:36:16 +00:00
{
echo $plugin_path." = ".implode(",",$p_addons)."<br />";
}
return implode(",",$p_addons);
}
function checkAddon($plugin_path,$e_xxx)
{ // Return 0 = OK, 1 = Fail, 2 = inaccessible
if(is_readable(e_PLUGIN.$plugin_path."/".$e_xxx.".php"))
{
$file_text = file_get_contents(e_PLUGIN.$plugin_path."/".$e_xxx.".php");
if ((substr($file_text,0,5) != '<'.'?php') || (substr($file_text,-2,2) !='?>')) return 1;
return 0;
}
return 2;
}
2008-01-26 05:19:59 +00:00
2008-08-09 16:49:58 +00:00
// Entry point to read plugin configuration data
function parse_plugin($plugName, $force=false)
{
if(isset($this->parsed_plugin[$plugName]) && $force != true)
2008-01-28 02:49:50 +00:00
{
$this->plug_vars = $this->parsed_plugin[$plugName];
2008-01-28 02:49:50 +00:00
return true;
}
unset($this->parsed_plugin[$plugName]); // In case forced parsing which fails
if(file_exists(e_PLUGIN.$plugName.'/plugin.xml'))
{
$ret = $this->parse_plugin_xml($plugName);
}
elseif(file_exists(e_PLUGIN.$plugName.'/plugin.php'))
{
$ret = $this->parse_plugin_php($plugName);
}
2008-01-28 02:49:50 +00:00
if($ret == true)
{
$this->parsed_plugin[$plugName] = $this->plug_vars;
2008-01-28 02:49:50 +00:00
}
return $ret;
}
2008-08-09 16:49:58 +00:00
// Called to parse the (deprecated) plugin.php file
function parse_plugin_php($plugName)
{
include(e_PLUGIN.$plugName.'/plugin.php');
$ret = array();
2008-08-24 09:57:08 +00:00
// $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['@attributes']['installRequired'] = ($eplug_conffile || is_array($eplug_table_names) || is_array($eplug_prefs) || $eplug_module || $eplug_userclass || $eplug_status || $eplug_latest);
$ret['@attributes']['version'] = varset($eplug_version);
$ret['@attributes']['name'] = varset($eplug_name);
$ret['@attributes']['compatibility'] = varset($eplug_compatible);
$ret['folder'] = varset($eplug_folder);
$ret['category'] = varset($eplug_category);
$ret['description'] = varset($eplug_description);
$ret['author']['@attributes']['name'] = varset($eplug_author);
$ret['author']['@attributes']['url'] = varset($eplug_url);
$ret['author']['@attributes']['email'] = varset($eplug_email);
$ret['readme'] = varset($eplug_readme);
$ret['compliant'] = varset($eplug_compliant);
$ret['menuName'] = varset($eplug_menu_name);
$ret['administration']['icon'] = varset($eplug_icon);
$ret['administration']['caption'] = varset($eplug_caption);
$ret['administration']['iconSmall'] = varset($eplug_icon_small);
$ret['administration']['configFile'] = varset($eplug_conffile);
2008-01-26 05:19:59 +00:00
// Set this key so we know the vars came from a plugin.php file
$ret['plugin_php'] = true;
2008-01-27 01:34:59 +00:00
$this->plug_vars = $ret;
return true;
}
2008-08-09 16:49:58 +00:00
// Called to parse the plugin.xml file if it exists
function parse_plugin_xml($plugName)
{
global $tp;
loadLanFiles($plugName, 'admin'); // Look for LAN files on default paths
require_once(e_HANDLER.'xml_class.php');
$xml = new xmlClass;
$this->plug_vars = $xml->loadXMLfile(e_PLUGIN.$plugName.'/plugin.xml', true, true);
2008-12-10 13:27:09 +00:00
if ($this->plug_vars === FALSE)
{
require_once(e_HANDLER."message_handler.php");
$emessage = &eMessage::getInstance();
$emessage->add("Error reading {$plugName}/plugin.xml", E_MESSAGE_ERROR);
return FALSE;
}
// print_a($this->plug_vars);
2008-01-27 01:34:59 +00:00
return true;
}
2006-12-02 04:36:16 +00:00
}
2008-01-27 01:34:59 +00:00
?>