1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-05 22:27:34 +02:00

No longer a need for a hardcoded list of e_xxx.php files, will not search for any matching the pattern and add them to the addons field. Should make adding new types less painful

This commit is contained in:
mcfly
2008-01-20 15:01:19 +00:00
parent 09fec54db4
commit 0bf29c6219

View File

@@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org).
|
| $Source: /cvs_backup/e107_0.8/e107_handlers/plugin_class.php,v $
| $Revision: 1.14 $
| $Date: 2007-12-03 20:43:07 $
| $Author: e107steved $
| $Revision: 1.15 $
| $Date: 2008-01-20 15:01:19 $
| $Author: mcfly_e107 $
+----------------------------------------------------------------------------+
*/
@@ -37,9 +37,9 @@ class e107plugin
'eplug_bb',
'eplug_latest',
'eplug_status' //,
// 'eplug_comment_ids', // Not sure about this one
// 'eplug_menu_name', // ...or this one
// 'eplug_conffile' // ...or this one
// 'eplug_comment_ids', // Not sure about this one
// 'eplug_menu_name', // ...or this one
// 'eplug_conffile' // ...or this one
);
// List of all plugin variables involved in an update (not used ATM, but worth 'documenting')
@@ -75,11 +75,12 @@ class e107plugin
{
global $sql;
if ($sql->db_Select("plugin","*","plugin_installflag = '".intval($flag)."' ORDER BY plugin_path ASC"))
if ($sql->db_Select("plugin","*","plugin_installflag = ".(int)$flag." ORDER BY plugin_path ASC"))
{
$ret = $sql->db_getList();
return $ret;
}
return ($ret) ? $ret : FALSE;
return false;
}
@@ -96,7 +97,7 @@ class e107plugin
$pluginList = $fl->get_files(e_PLUGIN, "^plugin\.php$", "standard", 1);
$sp = FALSE;
// Read all the plugin DB info into an array to save lots of accesses
// Read all the plugin DB info into an array to save lots of accesses
$pluginDBList = array();
if ($sql->db_Select('plugin',"*"))
{
@@ -104,7 +105,7 @@ class e107plugin
{
$pluginDBList[$row['plugin_path']] = $row;
$pluginDBList[$row['plugin_path']]['status'] = 'read';
// echo "Found plugin: ".$row['plugin_path']." in DB<br />";
// echo "Found plugin: ".$row['plugin_path']." in DB<br />";
}
}
@@ -128,7 +129,7 @@ class e107plugin
// 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
// $eplug_addons = $this->getAddons($plugin_path,'check'); // Checks opening/closing tags on addon files
// See whether the plugin needs installation - it does if one or more variables defined
$no_install_needed = 1;
@@ -159,7 +160,7 @@ class e107plugin
if (isset($pref['plug_installed'][$plugin_path]))
{
unset($pref['plug_installed'][$plugin_path]);
// echo "Remove: ".$plugin_path."->".$ep_row['plugin_version']."<br />";
// echo "Remove: ".$plugin_path."->".$ep_row['plugin_version']."<br />";
$sp = TRUE;
}
}
@@ -168,7 +169,7 @@ class e107plugin
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 />";
// echo "Add: ".$plugin_path."->".$ep_row['plugin_version']."<br />";
$sp = TRUE;
}
}
@@ -178,14 +179,14 @@ class e107plugin
if ($eplug_name)
{
// Can just add to DB - shouldn''t matter that its not in our current table
// echo "Trying to insert: ".$eplug_folder."<br />";
// echo "Trying to insert: ".$eplug_folder."<br />";
$sql->db_Insert("plugin", "0, '".$tp -> toDB($eplug_name, true)."', '".$tp -> toDB($eplug_version, true)."', '".$tp -> toDB($eplug_folder, true)."', {$no_install_needed}, '{$eplug_addons}' ");
}
}
}
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: {$eplug_folder}<br /><br />";
// echo "Plugin copied to wrong directory. Is in: {$plugin_path} Should be: {$eplug_folder}<br /><br />";
}
}
@@ -194,8 +195,8 @@ class e107plugin
{
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 />";
$sql->db_Delete('plugin', "`plugin_id`={$plug_info['plugin_id']}");
// echo "Deleted: ".$plug_path."<br />";
}
if ($plug_info['status'] == 'update')
{
@@ -204,8 +205,8 @@ class e107plugin
{
$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 />";
$sql->db_Update('plugin', implode(", ",$temp)." WHERE `plugin_id`={$plug_info['plugin_id']}");
// echo "Updated: ".$plug_path."<br />";
}
}
if ($sp) save_prefs();
@@ -227,38 +228,51 @@ class e107plugin
}
}
function manage_userclass($action, $class_name, $class_description) {
function manage_userclass($action, $class_name, $class_description)
{
global $sql, $tp;
$class_name = $tp -> toDB($class_name, true);
$class_description = $tp -> toDB($class_description, true);
if ($action == 'add') {
if ($action == 'add')
{
$i = 1;
while ($sql->db_Select('userclass_classes', '*', "userclass_id='{$i}' ") && $i < e_UC_READONLY) {
while ($sql->db_Select('userclass_classes', '*', "userclass_id={$i} ") && $i < e_UC_READONLY)
{
$i++;
}
if ($i < e_UC_READONLY) {
if ($i < e_UC_READONLY)
{
return $sql->db_Insert('userclass_classes', "{$i},'".strip_tags(strtoupper($class_name))."', '{$class_description}' ,".e_UC_PUBLIC);
} else {
}
else
{
return FALSE;
}
}
if ($action == 'remove') {
if ($sql->db_Select('userclass_classes', 'userclass_id', "userclass_name = '{$class_name}'")) {
if ($action == 'remove')
{
if ($sql->db_Select('userclass_classes', 'userclass_id', "userclass_name = '{$class_name}'"))
{
$row = $sql->db_Fetch();
$class_id = $row['userclass_id'];
if ($sql->db_Delete('userclass_classes', "userclass_id = '{$class_id}'")) {
if ($sql->db_Select('user', 'user_id, user_class', "user_class REGEXP('^{$class_id}\.') OR user_class REGEXP('\.{$class_id}\.') OR user_class REGEXP('\.{$class_id}$')")) {
if ($sql->db_Delete('userclass_classes', "userclass_id = {$class_id}"))
{
if ($sql->db_Select('user', 'user_id, user_class', "user_class REGEXP('^{$class_id}\.') OR user_class REGEXP('\.{$class_id}\.') OR user_class REGEXP('\.{$class_id}$')"))
{
$sql2 = new db;
while ($row = $sql->db_Fetch()) {
while ($row = $sql->db_Fetch())
{
$classes = explode(".", $row['user_class']);
unset($classes[$class_id]);
foreach($classes as $k => $v) {
if ($v = '') {
foreach($classes as $k => $v)
{
if ($v = '')
{
unset($classes[$k]);
}
}
$newclass = '.'.implode('.', $classes).'.';
$sql2->db_Update('user', "user_class = '{$newclass}' WHERE user_id = '{$row['user_id']}");
$sql2->db_Update('user', "user_class = '{$newclass}' WHERE user_id = {$row['user_id']}");
}
}
}
@@ -266,7 +280,8 @@ class e107plugin
}
}
function manage_link($action, $link_url, $link_name,$link_class=0) {
function manage_link($action, $link_url, $link_name,$link_class=0)
{
global $sql, $tp;
$link_url = $tp -> toDB($link_url, true);
$link_name = $tp -> toDB($link_name, true);
@@ -291,14 +306,16 @@ class e107plugin
{
$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']}'");
return $sql->db_Delete('links', "link_id = {$row['link_id']}");
}
}
}
function manage_prefs($action, $var) {
function manage_prefs($action, $var)
{
global $pref;
if (is_array($var)) {
if (is_array($var))
{
switch ($action)
{
case 'add' :
@@ -334,10 +351,13 @@ class e107plugin
}
function manage_comments($action,$comment_id){
function manage_comments($action,$comment_id)
{
global $sql, $tp;
if($action == 'remove'){
foreach($comment_id as $com){
if($action == 'remove')
{
foreach($comment_id as $com)
{
$tmp[] = "comment_type='".$tp -> toDB($com, true)."'";
}
$qry = implode(" OR ",$tmp);
@@ -346,12 +366,17 @@ class e107plugin
}
function manage_tables($action, $var) {
function manage_tables($action, $var)
{
global $sql;
if ($action == 'add') {
if (is_array($var)) {
foreach($var as $tab) {
if (!$sql->db_Query($tab)) {
if ($action == 'add')
{
if (is_array($var))
{
foreach($var as $tab)
{
if (!$sql->db_Query($tab))
{
return FALSE;
}
}
@@ -359,10 +384,14 @@ class e107plugin
}
return TRUE;
}
if ($action == 'upgrade') {
if (is_array($var)) {
foreach($var as $tab) {
if (!$sql->db_Query_all($tab)) {
if ($action == 'upgrade')
{
if (is_array($var))
{
foreach($var as $tab)
{
if (!$sql->db_Query_all($tab))
{
return FALSE;
}
}
@@ -370,11 +399,15 @@ class e107plugin
}
return TRUE;
}
if ($action == 'remove') {
if (is_array($var)) {
foreach($var as $tab) {
if ($action == 'remove')
{
if (is_array($var))
{
foreach($var as $tab)
{
$qry = 'DROP TABLE '.MPREFIX.$tab;
if (!$sql->db_Query_all($qry)) {
if (!$sql->db_Query_all($qry))
{
return $tab;
}
}
@@ -389,12 +422,15 @@ class e107plugin
global $pref;
if ($prefname == 'plug_sc' || $prefname == 'plug_bb')
{ // Special cases - shortcodes and bbcodes - each plugin may contribute several elements
foreach($varArray as $code) {
foreach($varArray as $code)
{
$prefvals[] = "$code:$plugin_folder";
}
} else {
}
else
{
$prefvals[] = $varArray;
// $prefvals[] = $plugin_folder;
// $prefvals[] = $plugin_folder;
}
$curvals = explode(',', $pref[$prefname]);
@@ -423,75 +459,102 @@ class e107plugin
save_prefs();
}
function manage_search($action, $eplug_folder) {
function manage_search($action, $eplug_folder)
{
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'){
if ($action == 'add')
{
$install_default = $default ? TRUE : FALSE;
$install_comments = $comments ? TRUE : FALSE;
} else if ($action == 'remove'){
}
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])) {
}
else if ($action == 'upgrade')
{
if (isset($search_prefs['plug_handlers'][$eplug_folder]))
{
$uninstall_default = $default ? FALSE : TRUE;
} else {
}
else
{
$install_default = $default ? TRUE : FALSE;
}
if (isset($search_prefs['comments_handlers'][$eplug_folder])) {
if (isset($search_prefs['comments_handlers'][$eplug_folder]))
{
$uninstall_comments = $comments ? FALSE : TRUE;
} else {
}
else
{
$install_comments = $comments ? TRUE : FALSE;
}
}
if ($install_default) {
if ($install_default)
{
$search_prefs['plug_handlers'][$eplug_folder] = array('class' => 0, 'pre_title' => 1, 'pre_title_alt' => '', 'chars' => 150, 'results' => 10);
} else if ($uninstall_default) {
}
else if ($uninstall_default)
{
unset($search_prefs['plug_handlers'][$eplug_folder]);
}
if ($install_comments) {
if ($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 ($uninstall_comments) {
}
else if ($uninstall_comments)
{
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) {
function manage_notify($action, $eplug_folder)
{
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'){
if ($action == 'add')
{
$install_notify = $e_notify ? TRUE : FALSE;
} else if ($action == 'remove'){
}
else if ($action == 'remove')
{
$uninstall_notify = isset($notify_prefs['plugins'][$eplug_folder]) ? TRUE : FALSE;
} else if ($action == 'upgrade'){
if (isset($notify_prefs['plugins'][$eplug_folder])) {
}
else if ($action == 'upgrade')
{
if (isset($notify_prefs['plugins'][$eplug_folder]))
{
$uninstall_notify = $e_notify ? FALSE : TRUE;
} else {
}
else
{
$install_notify = $e_notify ? TRUE : FALSE;
}
}
if ($install_notify) {
if ($install_notify)
{
$notify_prefs['plugins'][$eplug_folder] = TRUE;
require_once(e_PLUGIN.$eplug_folder.'/e_notify.php');
foreach ($config_events as $event_id => $event_text) {
foreach ($config_events as $event_id => $event_text)
{
$notify_prefs['event'][$event_id] = array('type' => 'off', 'class' => '254', 'email' => '');
}
} else if ($uninstall_notify) {
}
else if ($uninstall_notify)
{
unset($notify_prefs['plugins'][$eplug_folder]);
require_once(e_PLUGIN.$eplug_folder.'/e_notify.php');
foreach ($config_events as $event_id => $event_text) {
foreach ($config_events as $event_id => $event_text)
{
unset($notify_prefs['event'][$event_id]);
}
}
@@ -513,20 +576,26 @@ class e107plugin
$plug = $this->getinfo($id);
$plug['plug_action'] = 'install';
if ($plug['plugin_installflag'] == FALSE) {
if ($plug['plugin_installflag'] == FALSE)
{
include_once(e_PLUGIN.$plug['plugin_path'].'/plugin.php');
$func = $eplug_folder.'_install';
if (function_exists($func)) {
if (function_exists($func))
{
$text .= call_user_func($func);
}
if (is_array($eplug_tables)) {
if (is_array($eplug_tables))
{
$result = $this->manage_tables('add', $eplug_tables);
if ($result === TRUE) {
if ($result === TRUE)
{
$text .= EPL_ADLAN_19.'<br />';
//success
} else {
}
else
{
$text .= EPL_ADLAN_18.'<br />';
//fail
}
@@ -534,46 +603,57 @@ class e107plugin
if (is_array($eplug_prefs)) {
if (is_array($eplug_prefs))
{
$this->manage_prefs('add', $eplug_prefs);
$text .= EPL_ADLAN_8.'<br />';
}
if (is_array($eplug_array_pref)){
foreach($eplug_array_pref as $key => $val){
if (is_array($eplug_array_pref))
{
foreach($eplug_array_pref as $key => $val)
{
$this->manage_plugin_prefs('add', $key, $eplug_folder, $val);
}
}
if (is_array($eplug_sc)) {
if (is_array($eplug_sc))
{
$this->manage_plugin_prefs('add', 'plug_sc', $eplug_folder, $eplug_sc);
}
if (is_array($eplug_bb)) {
if (is_array($eplug_bb))
{
$this->manage_plugin_prefs('add', 'plug_bb', $eplug_folder, $eplug_bb);
}
if (is_array($eplug_user_prefs)) {
if (is_array($eplug_user_prefs))
{
$sql->db_Select("core", " e107_value", " e107_name = 'user_entended'");
$row = $sql->db_Fetch();
$user_entended = unserialize($row[0]);
while (list($e_user_pref, $default_value) = each($eplug_user_prefs)) {
while (list($e_user_pref, $default_value) = each($eplug_user_prefs))
{
$user_entended[] = $e_user_pref;
$user_pref['$e_user_pref'] = $default_value;
}
save_prefs("user");
$tmp = addslashes(serialize($user_entended));
if ($sql->db_Select("core", "e107_value", " e107_name = 'user_entended'")) {
if ($sql->db_Select("core", "e107_value", " e107_name = 'user_entended'"))
{
$sql->db_Update("core", "e107_value = '{$tmp}' WHERE e107_name = 'user_entended' ");
} else {
}
else
{
$sql->db_Insert("core", "'user_entended', '{$tmp}' ");
}
$text .= EPL_ADLAN_8."<br />";
}
if ($eplug_link === TRUE && $eplug_link_url != '' && $eplug_link_name != '') {
if ($eplug_link === TRUE && $eplug_link_url != '' && $eplug_link_name != '')
{
$plug_perm['everyone'] = e_UC_PUBLIC;
$plug_perm['guest'] = e_UC_GUEST;
$plug_perm['member'] = e_UC_MEMBER;
@@ -585,7 +665,8 @@ class e107plugin
$this->manage_link('add', $eplug_link_url, $eplug_link_name,$linkperm);
}
if ($eplug_userclass) {
if ($eplug_userclass)
{
$this->manage_userclass('add', $eplug_userclass, $eplug_userclass_description);
}
@@ -595,24 +676,27 @@ class e107plugin
$eplug_addons = $this->getAddons($eplug_folder);
$sql->db_Update('plugin', "plugin_installflag = 1, plugin_addons = '{$eplug_addons}' WHERE plugin_id = '".intval($id)."'");
$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();
if($rssmess) { $text .= $rssmess; }
if($rssmess)
{ $text .= $rssmess;
}
$text .= (isset($eplug_done) ? "<br />{$eplug_done}" : "<br />".LAN_INSTALL_SUCCESSFUL);
} else {
}
else
{
$text = EPL_ADLAN_21;
}
if($eplug_conffile){ $text .= "&nbsp;<a href='".e_PLUGIN."$eplug_folder/$eplug_conffile'>[".LAN_CONFIGURE."]</a>"; }
$ns->tablerender(EPL_ADLAN_33, $text);
}
function save_addon_prefs(){ // scan the plugin table and create path-array-prefs for each addon.
function save_addon_prefs()
{ // scan the plugin table and create path-array-prefs for each addon.
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_installflag = 1 AND plugin_addons !='' ORDER BY plugin_path ASC";
$query = "SELECT * FROM #plugin WHERE plugin_addons !='' ORDER BY plugin_path ASC";
// clear all addon prefs before re-creation.
@@ -700,35 +784,46 @@ class e107plugin
save_prefs();
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)
function getAddons($plugin_path, $debug=FALSE)
{
global $fl;
$p_addons = array();
foreach($this->plugin_addons as $e_xxx)
{
if(is_readable(e_PLUGIN.$plugin_path."/".$e_xxx.".php"))
{
$passfail = '';
if ($debug == 'check')
{
$file_text = file_get_contents(e_PLUGIN.$plugin_path."/".$e_xxx.".php");
if ((substr($file_text,0,5) != '<'.'?php') || (substr($file_text,-2,2) !='?>')) $passfail = '<b>fail</b>'; else $passfail = 'pass';
echo $plugin_path."/".$e_xxx.".php - ".$passfail."<br />";
}
$p_addons[] = $e_xxx;
}
}
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;
}
}
}
// Grab List of Shortcodes & BBcodes
$shortcodeList = $fl->get_files(e_PLUGIN.$plugin_path, ".sc$", "standard", 1);
@@ -762,8 +857,7 @@ class e107plugin
}
}
if($debug==TRUE)
if($debug == true)
{
echo $plugin_path." = ".implode(",",$p_addons)."<br />";
}