2006-12-02 04:36:16 +00:00
< ? php
/*
+ ----------------------------------------------------------------------------+
| e107 website system
|
2009-08-31 02:00:51 +00:00
| <EFBFBD> Steve Dunstan 2001 - 2002
2006-12-02 04:36:16 +00:00
| 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 $
2009-10-29 13:36:27 +00:00
| $Revision : 1.107 $
| $Date : 2009 - 10 - 29 13 : 35 : 54 $
| $Author : marj_nl_fr $
2006-12-02 04:36:16 +00:00
+----------------------------------------------------------------------------+
*/
if ( ! defined ( 'e107_INIT' )) { exit ; }
2009-09-03 22:27:32 +00:00
include_lan ( e_LANGUAGEDIR . e_LANGUAGE . " /admin/lan_plugin.php " );
2006-12-02 04:36:16 +00:00
class e107plugin
{
2009-09-21 23:02:47 +00:00
// Reserved Addon names.
2008-08-09 16:49:58 +00:00
var $plugin_addons = array (
2009-09-25 20:14:29 +00:00
'e_rss' ,
'e_notify' ,
'e_linkgen' ,
'e_list' ,
'e_bb' ,
'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' ,
2009-10-09 18:58:12 +00:00
'e_tagwords' ,
2009-10-23 09:08:15 +00:00
'e_url' ,
'e_cron'
2008-08-09 16:49:58 +00:00
);
2006-12-02 04:36:16 +00:00
2007-02-01 22:00:41 +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
2007-02-01 22:00:41 +00:00
var $all_eplug_install_variables = array (
2009-09-21 21:53:38 +00:00
'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'
2007-02-01 22:00:41 +00:00
);
// 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
2007-02-01 22:00:41 +00:00
var $all_eplug_update_variables = array (
2009-09-21 21:53:38 +00:00
'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'
2007-02-01 22:00:41 +00:00
);
2008-01-20 15:01:19 +00:00
2007-06-05 19:51:36 +00:00
// List of all 'editable' DB fields ('plugin_id' is an arbitrary reference which is never edited)
var $all_editable_db_fields = array (
2009-09-21 21:53:38 +00:00
'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
2007-06-05 19:51:36 +00:00
);
2008-01-20 15:01:19 +00:00
2009-09-19 17:43:19 +00:00
var $accepted_categories = array ( 'settings' , 'users' , 'content' , 'tools' , 'manage' , 'misc' , 'menu' , 'about' );
2009-09-14 11:27:45 +00:00
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 ;
2009-09-23 23:18:18 +00:00
var $plugFolder ;
2009-10-20 03:49:28 +00:00
var $plugConfigFile ;
2009-09-23 23:18:18 +00:00
var $unInstallOpts ;
2008-11-24 00:36:50 +00:00
var $module = array ();
2009-10-20 03:49:28 +00:00
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
/**
2008-01-20 15:01:19 +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 )
{
2009-09-03 22:27:32 +00:00
$sql = e107 :: getDb ();
2008-01-20 15:01:19 +00:00
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 ();
2008-01-20 15:01:19 +00:00
return $ret ;
}
return false ;
2006-12-02 04:36:16 +00:00
}
2007-02-01 22:00:41 +00:00
2006-12-02 04:36:16 +00:00
/**
2008-01-20 15:01:19 +00:00
* Check for new plugins , create entry in plugin table and remove deleted plugins
*/
function update_plugins_table ()
2007-02-01 22:00:41 +00:00
{
2009-09-03 22:27:32 +00:00
2009-08-31 02:00:51 +00:00
$sql = e107 :: getDb ();
$sql2 = e107 :: getDb ( 'sql2' );
2009-09-03 22:27:32 +00:00
$tp = e107 :: getParser ();
2009-09-06 20:04:04 +00:00
$fl = e107 :: getFile ();
2009-08-31 02:00:51 +00:00
2009-09-03 22:27:32 +00:00
global $mySQLprefix , $menu_pref , $pref ;
2006-12-02 04:36:16 +00:00
2007-05-07 13:38:34 +00:00
$sp = FALSE ;
2009-09-21 21:53:38 +00:00
2007-06-05 19:51:36 +00:00
$pluginDBList = array ();
2009-09-21 21:53:38 +00:00
if ( $sql -> db_Select ( 'plugin' , " * " )) // Read all the plugin DB info into an array to save lots of accesses
2007-06-05 19:51:36 +00:00
{
2008-02-13 00:46:05 +00:00
while ( $row = $sql -> db_Fetch ( MYSQL_ASSOC ))
2009-09-21 21:53:38 +00:00
{
2008-01-20 15:01:19 +00:00
$pluginDBList [ $row [ 'plugin_path' ]] = $row ;
$pluginDBList [ $row [ 'plugin_path' ]][ 'status' ] = 'read' ;
2009-08-31 02:00:51 +00:00
// echo "Found plugin: ".$row['plugin_path']." in DB<br />";
2008-01-20 15:01:19 +00:00
}
2007-06-05 19:51:36 +00:00
}
2009-09-21 21:53:38 +00:00
$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.
2008-12-02 21:51:22 +00:00
{
2009-09-21 21:53:38 +00:00
$key = basename ( $val [ 'path' ]);
$pluginList [ $key ] = $val ;
2008-12-02 21:51:22 +00:00
}
2009-09-03 22:27:32 +00:00
$p_installed = e107 :: getPref ( 'plug_installed' , array ()); // load preference;
2009-09-10 15:24:57 +00:00
require_once ( e_HANDLER . " message_handler.php " );
2009-10-23 09:08:15 +00:00
$mes = eMessage :: getInstance ();
2009-08-31 02:00:51 +00:00
2006-12-02 04:36:16 +00:00
foreach ( $pluginList as $p )
{
2009-09-10 15:24:57 +00:00
$p [ 'path' ] = substr ( str_replace ( e_PLUGIN , " " , $p [ 'path' ]), 0 , - 1 );
$plugin_path = $p [ 'path' ];
if ( strpos ( $plugin_path , 'e107_' ) !== FALSE )
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Folder error: <i> { $p [ 'path' ] } </i>. 'e107_' is not permitted within plugin folder names. " , E_MESSAGE_WARNING );
2009-09-10 15:24:57 +00:00
continue ;
}
2008-02-13 00:46:05 +00:00
$plug [ 'plug_action' ] = 'scan' ; // Make sure plugin.php knows what we're up to
2009-09-03 22:27:32 +00:00
2009-09-10 15:24:57 +00:00
2009-09-03 22:27:32 +00:00
2008-02-13 00:46:05 +00:00
if ( ! $this -> parse_plugin ( $p [ 'path' ]))
2008-01-20 15:01:19 +00:00
{
2009-09-21 21:53:38 +00:00
//parsing of plugin.php/plugin.xml failed.
2009-10-23 09:08:15 +00:00
$mes -> add ( " Parsing failed - file format error: { $p [ 'path' ] } " , E_MESSAGE_ERROR );
2009-09-21 21:53:38 +00:00
continue ; // Carry on and do any others that are OK
2008-01-20 15:01:19 +00:00
}
2009-09-21 21:53:38 +00:00
2008-02-13 00:46:05 +00:00
$plug_info = $this -> plug_vars ;
2009-10-26 01:04:36 +00:00
$eplug_addons = $this -> getAddons ( $plugin_path );
2008-01-20 15:01:19 +00:00
2008-03-11 01:47:05 +00:00
//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-01-20 15:01:19 +00:00
{
2008-02-13 00:46:05 +00:00
if ( array_key_exists ( $plugin_path , $pluginDBList ))
2008-01-20 15:01:19 +00:00
{ // Update the addons needed by the plugin
$pluginDBList [ $plugin_path ][ 'status' ] = 'exists' ;
2009-07-09 02:47:17 +00:00
// 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 " ;
2009-07-09 02:47:17 +00:00
}
2008-01-20 15:01:19 +00:00
// If plugin not installed, and version number of files changed, update version as well
2008-12-03 22:29:58 +00:00
if (( $pluginDBList [ $plugin_path ][ 'plugin_installflag' ] == 0 ) && ( $pluginDBList [ $plugin_path ][ 'plugin_version' ] != $plug_info [ '@attributes' ][ 'version' ]))
2008-01-20 15:01:19 +00:00
{ // Update stored version
2008-12-03 22:29:58 +00:00
$pluginDBList [ $plugin_path ][ 'plugin_version' ] = $plug_info [ '@attributes' ][ 'version' ];
2008-01-20 15:01:19 +00:00
$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' ;
}
2009-09-03 22:27:32 +00:00
if ( $pluginDBList [ $plugin_path ][ 'plugin_installflag' ] == 0 ) // Plugin not installed - make sure $pref not set
{
if ( isset ( $p_installed [ $plugin_path ]))
2008-01-20 15:01:19 +00:00
{
2009-09-03 22:27:32 +00:00
unset ( $p_installed [ $plugin_path ]);
2008-01-20 15:01:19 +00:00
$sp = TRUE ;
}
}
else
{ // Plugin installed - make sure $pref is set
2009-09-03 22:27:32 +00:00
if ( ! isset ( $p_installed [ $plugin_path ]) || ( $p_installed [ $plugin_path ] != $pluginDBList [ $plugin_path ][ 'plugin_version' ]))
2008-01-20 15:01:19 +00:00
{ // Update prefs array of installed plugins
2009-09-03 22:27:32 +00:00
$p_installed [ $plugin_path ] = $pluginDBList [ $plugin_path ][ 'plugin_version' ];
2008-01-20 15:01:19 +00:00
// echo "Add: ".$plugin_path."->".$ep_row['plugin_version']."<br />";
$sp = TRUE ;
}
}
2007-06-05 19:51:36 +00:00
}
2009-10-23 09:08:15 +00:00
else // New plugin - not in table yet, so add it. If no install needed, mark it as 'installed'
{
2008-12-05 14:18:51 +00:00
if ( $plug_info [ '@attributes' ][ 'name' ])
2008-01-20 15:01:19 +00:00
{
2009-10-26 01:04:36 +00:00
2009-10-23 09:08:15 +00:00
2008-12-05 19:56:51 +00:00
$_installed = ( $plug_info [ '@attributes' ][ 'installRequired' ] == 'true' || $plug_info [ '@attributes' ][ 'installRequired' ] == 1 ? 0 : 1 );
2009-10-09 18:58:12 +00:00
if ( e107 :: getDb () -> 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 } ', ' " . $this -> manage_category ( $plug_info [ 'category' ]) . " ', ' " . varset ( $plug_info [ '@attributes' ][ 'releaseUrl' ]) . " ' " ))
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Added <b> " . $plug_info [ '@attributes' ][ 'name' ] . " </b> to the plugin table. " , E_MESSAGE_DEBUG );
2009-10-09 18:58:12 +00:00
}
else
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Failed to add " . $plug_info [ '@attributes' ][ 'name' ] . " to the plugin table. " , E_MESSAGE_DEBUG );
}
2008-01-20 15:01:19 +00:00
}
2007-06-05 19:51:36 +00:00
}
2007-02-01 22:00:41 +00:00
}
2007-06-05 19:51:36 +00:00
else
2008-01-20 15:01:19 +00:00
{ // 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 />";
2007-02-01 22:00:41 +00:00
}
2009-07-09 02:47:17 +00:00
2009-09-03 22:27:32 +00:00
// print_a($plug_info);
2006-12-02 04:36:16 +00:00
}
2007-06-05 19:51:36 +00:00
// Now scan the table, updating the DB where needed
foreach ( $pluginDBList as $plug_path => $plug_info )
{
2008-01-20 15:01:19 +00:00
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' )
2007-06-05 19:51:36 +00:00
{
2008-01-20 15:01:19 +00:00
$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 />";
2007-06-05 19:51:36 +00:00
}
2006-12-02 04:36:16 +00:00
}
2009-09-03 22:27:32 +00:00
if ( $sp && vartrue ( $p_installed ))
{
e107 :: getConfig ( 'core' ) -> setPref ( 'plug_installed' , $p_installed );
e107 :: getConfig ( 'core' ) -> save ();
}
2006-12-02 04:36:16 +00:00
}
2009-09-14 11:27:45 +00:00
function manage_category ( $cat )
{
if ( vartrue ( $cat ) && in_array ( $cat , $this -> accepted_categories ))
{
return $cat ;
}
else
{
return 'misc' ;
}
}
2006-12-02 04:36:16 +00:00
2009-09-28 07:17:52 +00:00
function manage_icons ( $plugin = '' , $function = '' )
2009-07-16 02:55:19 +00:00
{
2009-09-03 22:27:32 +00:00
global $iconpool , $pref ;
2009-09-28 07:17:52 +00:00
2009-10-23 09:08:15 +00:00
$mes = eMessage :: getInstance ();
2009-09-03 22:27:32 +00:00
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
2009-09-06 20:04:04 +00:00
$fl = e107 :: getFile ();
2009-09-28 07:17:52 +00:00
if ( $plugin && ( $function == 'uninstall' ) )
{
if ( vartrue ( $this -> unInstallOpts [ 'del_ipool' ], FALSE ))
{
$ipool_entry = 'plugin-' . $plugin ;
e107 :: getConfig ( 'ipool' ) -> remove ( $ipool_entry ); // FIXME - ipool removal issue.
$status = ( e107 :: getConfig ( 'ipool' ) -> save ( FALSE )) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2009-10-23 09:08:15 +00:00
$mes -> add ( 'Removing Icon-Pool entry: ' . $ipool_entry , $status );
2009-09-28 07:17:52 +00:00
}
return ;
}
2009-07-16 02:55:19 +00:00
$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 " ;
}
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 " ));
2009-07-16 02:55:19 +00:00
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 );
}
2009-07-16 08:15:35 +00:00
if ( $theme_icons = $fl -> get_files ( e_THEME . $pref [ 'sitetheme' ] . " /images/ " , $filesrch , $reject_core , 2 ))
{
sort ( $theme_icons );
}
2009-07-16 02:55:19 +00:00
$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' ];
}
2009-09-02 02:05:51 +00:00
$srch = array ( e_PLUGIN , " /images/ " , " /icons/ " , " /icon/ " );
2009-07-16 08:15:35 +00:00
$repl = array ( " " , " " , " " );
2009-07-16 02:55:19 +00:00
foreach ( $plugin_icons as $file )
{
$path = str_replace ( $srch , $repl , $file [ 'path' ]);
$key = " plugin- " . $path ;
$iconpool [ $key ][] = $tp -> createConstants ( $file [ 'path' ], 1 ) . $file [ 'fname' ];
}
2009-09-02 02:05:51 +00:00
$srch = array ( e_THEME , " /images/ " , " /icons/ " , " /demo/ " );
$repl = array ( " " , " " , " " );
2009-07-16 08:15:35 +00:00
foreach ( $theme_icons as $file )
{
$path = str_replace ( $srch , $repl , $file [ 'path' ]);
$key = " theme- " . $path ;
$iconpool [ $key ][] = $tp -> createConstants ( $file [ 'path' ], 1 ) . $file [ 'fname' ];
}
2009-09-06 20:04:04 +00:00
e107 :: getConfig ( 'ipool' ) -> setPref ( $iconpool );
2009-09-03 22:27:32 +00:00
return ( e107 :: getConfig ( 'ipool' ) -> save ( FALSE )) ? TRUE : FALSE ;
2007-05-07 13:38:34 +00:00
2009-07-16 02:55:19 +00:00
}
2007-05-07 13:38:34 +00:00
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
2008-01-20 15:01:19 +00:00
*
* @ param int $id
* @ return array plugin info
*/
2008-01-28 02:49:50 +00:00
function getinfo ( $id , $force = false )
{
2009-08-31 02:00:51 +00:00
$sql = e107 :: getDb ();
2008-02-01 14:11:27 +00:00
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
}
2009-09-21 21:53:38 +00:00
function manage_extended_field ( $action , $field_name , $field_type , $field_default = '' , $field_source = '' )
2008-11-24 00:36:50 +00:00
{
if ( ! isset ( $this -> module [ 'ue' ]))
{
include_once ( e_HANDLER . 'user_extended_class.php' );
$this -> module [ 'ue' ] = new e107_user_extended ;
}
2009-09-21 21:53:38 +00:00
$type = defined ( $field_type ) ? constant ( $field_type ) : $field_type ;
2008-12-05 14:18:51 +00:00
2008-11-24 00:36:50 +00:00
if ( $action == 'add' )
{
return $this -> module [ 'ue' ] -> user_extended_add_system ( $field_name , $type , $field_default , $field_source );
}
2008-12-05 14:18:51 +00:00
2008-11-24 00:36:50 +00:00
if ( $action == 'remove' )
{
return $this -> module [ 'ue' ] -> user_extended_remove ( $field_name , $field_name );
}
}
2008-08-09 16:49:58 +00:00
2009-09-23 23:18:18 +00:00
2008-01-20 15:01:19 +00:00
function manage_userclass ( $action , $class_name , $class_description )
{
2009-09-03 22:27:32 +00:00
global $e107 ;
$tp = e107 :: getParser ();
$sql = e107 :: getDb ();
2008-12-29 22:30:16 +00:00
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 ));
2008-01-20 15:01:19 +00:00
if ( $action == 'add' )
{
2008-12-29 20:55:27 +00:00
if ( $e107 -> user_class -> ucGetClassIDFromName ( $class_name ) !== FALSE )
{ // Class already exists.
return TRUE ; // That's probably OK
}
2008-12-29 22:30:16 +00:00
$i = $e107 -> user_class -> findNewClassID ();
if ( $i !== FALSE )
2008-01-20 15:01:19 +00:00
{
2008-12-10 13:27:09 +00:00
$tmp = array ();
$tmp [ 'userclass_id' ] = $i ;
2008-12-29 20:55:27 +00:00
$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 ;
2008-12-29 20:55:27 +00:00
$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' ;
2008-12-29 22:30:16 +00:00
return $e107 -> user_class -> add_new_class ( $tmp );
2008-01-20 15:01:19 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
return FALSE ;
}
}
2008-01-20 15:01:19 +00:00
if ( $action == 'remove' )
{
2008-12-29 22:30:16 +00:00
$classID = $e107 -> user_class -> ucGetClassIDFromName ( $class_name );
if (( $classID !== FALSE )
&& ( $e107 -> user_class -> deleteClassAndUsers ( $classID ) === TRUE ))
2008-01-20 15:01:19 +00:00
{
2008-12-29 22:30:16 +00:00
return TRUE ;
}
else
{
return FALSE ;
2006-12-02 04:36:16 +00:00
}
}
}
2008-08-09 16:49:58 +00:00
2009-08-08 23:09:08 +00:00
function manage_link ( $action , $link_url , $link_name , $link_class = 0 )
2008-01-20 15:01:19 +00:00
{
2009-09-03 22:27:32 +00:00
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
2009-08-08 23:09:08 +00:00
2009-09-23 23:18:18 +00:00
if ( ! is_numeric ( $link_class ))
2008-01-27 01:34:59 +00:00
{
$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
2008-01-20 15:01:19 +00:00
if ( $action == 'add' )
2007-05-30 20:35:44 +00:00
{
2006-12-02 04:36:16 +00:00
$link_t = $sql -> db_Count ( 'links' );
2008-01-20 15:01:19 +00:00
if ( ! $sql -> db_Count ( 'links' , '(*)' , " WHERE link_url = ' { $path } ' OR link_name = ' { $link_name } ' " ))
2007-09-28 20:00:37 +00:00
{
2008-01-20 15:01:19 +00:00
return $sql -> db_Insert ( 'links' , " 0, ' { $link_name } ', ' { $path } ', '', '', '1', ' " . ( $link_t + 1 ) . " ', '0', '0', ' { $link_class } ' " );
}
else
2007-09-28 20:00:37 +00:00
{
2008-01-20 15:01:19 +00:00
return FALSE ;
2006-12-02 04:36:16 +00:00
}
}
2008-01-20 15:01:19 +00:00
if ( $action == 'remove' )
2007-05-30 20:35:44 +00:00
{ // Look up by URL if we can - should be more reliable. Otherwise try looking up by name (as previously)
2008-01-20 15:01:19 +00:00
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
2009-09-23 23:18:18 +00:00
// DEPRECATED in 0.8 - See XmlPrefs(); Left for BC.
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'
2008-08-11 20:21:17 +00:00
function manage_prefs ( $action , $var , $prefType = 'pref' , $path = '' , $unEscape = FALSE )
2008-01-20 15:01:19 +00:00
{
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 )
{
2008-08-11 20:21:17 +00:00
if ( $unEscape )
{
$v = str_replace ( array ( '\{' , '\}' ), array ( '{' , '}' ), $v );
}
2008-08-09 16:49:58 +00:00
switch ( $prefType )
2008-01-20 15:01:19 +00:00
{
2008-08-09 16:49:58 +00:00
case 'pref' :
2008-01-20 15:01:19 +00:00
switch ( $action )
{
2008-08-09 16:49:58 +00:00
case 'add' :
$pref [ $k ] = $v ;
2008-01-20 15:01:19 +00:00
break ;
2008-08-09 16:49:58 +00:00
case 'update' :
2008-12-10 22:39:43 +00:00
case 'refresh' :
2008-08-09 16:49:58 +00:00
// Only update if $pref doesn't exist
if ( ! isset ( $pref [ $k ])) $pref [ $k ] = $v ;
2008-01-20 15:01:19 +00:00
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 ]);
2008-01-20 15:01:19 +00:00
}
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' :
2008-12-10 22:39:43 +00:00
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' :
2008-12-10 22:39:43 +00:00
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
}
2009-09-03 22:27:32 +00:00
2009-09-06 20:04:04 +00:00
e107 :: getConfig ( 'core' ) -> setPref ( $pref ) -> save ();
// e107::getConfig()->loadData($pref, false)->save(false, true);
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 )
2008-01-20 15:01:19 +00:00
{
2009-09-03 22:27:32 +00:00
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
2008-02-02 22:04:18 +00:00
$tmp = array ();
2008-01-20 15:01:19 +00:00
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 );
2008-01-20 15:01:19 +00:00
}
2006-12-02 04:36:16 +00:00
}
2008-08-12 20:26:53 +00:00
// Handle table updates - passed an array of actions.
// $var array:
// For 'add' - its a query to create the table
2008-12-10 22:39:43 +00:00
// For 'upgrade' - its a query to modify the table (not called from the plugin.xml handler)
2008-08-12 20:26:53 +00:00
// For 'remove' - its a table name
// 'upgrade' and 'remove' operate on all language variants of the same table
2008-01-20 15:01:19 +00:00
function manage_tables ( $action , $var )
{
2009-09-03 22:27:32 +00:00
$sql = e107 :: getDB ();
2008-08-12 20:26:53 +00:00
if ( ! is_array ( $var )) return FALSE ; // Return if nothing to do
2008-07-25 19:26:46 +00:00
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 ;
2008-07-25 19:26:46 +00:00
break ;
case 'upgrade' :
2008-01-20 15:01:19 +00:00
foreach ( $var as $tab )
{
if ( ! $sql -> db_Query_all ( $tab ))
{
2006-12-02 04:36:16 +00:00
return FALSE ;
}
}
return TRUE ;
2008-07-25 19:26:46 +00:00
break ;
case 'remove' :
2008-01-20 15:01:19 +00:00
foreach ( $var as $tab )
{
2006-12-02 04:36:16 +00:00
$qry = 'DROP TABLE ' . MPREFIX . $tab ;
2008-01-20 15:01:19 +00:00
if ( ! $sql -> db_Query_all ( $qry ))
{
2006-12-02 04:36:16 +00:00
return $tab ;
}
}
return TRUE ;
2008-07-25 19:26:46 +00:00
break ;
}
2008-08-12 20:26:53 +00:00
return FALSE ;
2006-12-02 04:36:16 +00:00
}
2008-08-09 16:49:58 +00:00
2009-09-23 23:18:18 +00:00
// DEPRECATED for 0.8 xml files - See XmlPrefs();
2008-08-09 16:49:58 +00:00
// Handle prefs from arrays (mostly 0.7 stuff, possibly apart from the special cases)
2008-01-20 15:01:19 +00:00
function manage_plugin_prefs ( $action , $prefname , $plugin_folder , $varArray = '' )
2007-06-05 19:51:36 +00:00
{ // These prefs are 'cumulative' - several plugins may contribute an array element
2009-09-06 20:04:04 +00:00
// global $pref;
2008-08-24 09:57:08 +00:00
/*
2008-01-20 15:01:19 +00:00
if ( $prefname == 'plug_sc' || $prefname == 'plug_bb' )
2007-06-05 19:51:36 +00:00
{ // Special cases - shortcodes and bbcodes - each plugin may contribute several elements
2008-01-20 15:01:19 +00:00
foreach ( $varArray as $code )
{
2006-12-02 04:36:16 +00:00
$prefvals [] = " $code : $plugin_folder " ;
}
2008-01-20 15:01:19 +00:00
}
else
{
2008-08-24 09:57:08 +00:00
*/
2007-02-01 22:00:41 +00:00
$prefvals [] = $varArray ;
2008-01-20 15:01:19 +00:00
// $prefvals[] = $plugin_folder;
2008-08-24 09:57:08 +00:00
// }
2006-12-02 04:36:16 +00:00
$curvals = explode ( ',' , $pref [ $prefname ]);
2008-01-20 15:01:19 +00:00
if ( $action == 'add' )
2007-02-01 22:00:41 +00:00
{
2006-12-02 04:36:16 +00:00
$newvals = array_merge ( $curvals , $prefvals );
}
2008-01-20 15:01:19 +00:00
if ( $action == 'remove' )
2007-02-01 22:00:41 +00:00
{
2008-01-20 15:01:19 +00:00
foreach ( $prefvals as $v )
2007-02-01 22:00:41 +00:00
{
2008-01-20 15:01:19 +00:00
if (( $i = array_search ( $v , $curvals )) !== FALSE )
{
unset ( $curvals [ $i ]);
}
2006-12-02 04:36:16 +00:00
}
2008-01-20 15:01:19 +00:00
$newvals = $curvals ;
2006-12-02 04:36:16 +00:00
}
$newvals = array_unique ( $newvals );
2007-02-01 22:00:41 +00:00
$pref [ $prefname ] = implode ( ',' , $newvals );
2006-12-02 04:36:16 +00:00
if ( substr ( $pref [ $prefname ], 0 , 1 ) == " , " )
{
2008-01-20 15:01:19 +00:00
$pref [ $prefname ] = substr ( $pref [ $prefname ], 1 );
2006-12-02 04:36:16 +00:00
}
2009-09-06 20:04:04 +00:00
e107 :: getConfig ( 'core' ) -> setPref ( $pref );
e107 :: getConfig ( 'core' ) -> save ();
2009-09-26 16:54:21 +00:00
2006-12-02 04:36:16 +00:00
}
2008-08-09 16:49:58 +00:00
2008-01-20 15:01:19 +00:00
function manage_search ( $action , $eplug_folder )
{
2009-09-03 22:27:32 +00:00
global $sysprefs ;
$sql = e107 :: getDb ();
2009-09-14 11:27:45 +00:00
$search_prefs = e107 :: getConfig ( 'search' ) -> getPref ();
2009-09-03 22:27:32 +00:00
// $search_prefs = $sysprefs -> getArray('search_prefs');
2006-12-02 04:36:16 +00:00
$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 ;
2008-01-20 15:01:19 +00:00
if ( $action == 'add' )
{
2006-12-02 04:36:16 +00:00
$install_default = $default ? TRUE : FALSE ;
$install_comments = $comments ? TRUE : FALSE ;
2008-01-20 15:01:19 +00:00
}
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 ;
2008-01-20 15:01:19 +00:00
}
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 ;
2008-01-20 15:01:19 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
$install_default = $default ? TRUE : FALSE ;
}
2008-01-20 15:01:19 +00:00
if ( isset ( $search_prefs [ 'comments_handlers' ][ $eplug_folder ]))
{
2006-12-02 04:36:16 +00:00
$uninstall_comments = $comments ? FALSE : TRUE ;
2008-01-20 15:01:19 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
$install_comments = $comments ? TRUE : FALSE ;
}
}
2009-09-03 22:27:32 +00:00
if ( vartrue ( $install_default ))
2008-01-20 15:01:19 +00:00
{
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 );
2008-01-20 15:01:19 +00:00
}
2009-09-03 22:27:32 +00:00
else if ( vartrue ( $uninstall_default ))
2008-01-20 15:01:19 +00:00
{
2006-12-02 04:36:16 +00:00
unset ( $search_prefs [ 'plug_handlers' ][ $eplug_folder ]);
}
2009-09-03 22:27:32 +00:00
if ( vartrue ( $install_comments ))
2008-01-20 15:01:19 +00:00
{
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 );
2008-01-20 15:01:19 +00:00
}
2009-09-03 22:27:32 +00:00
else if ( vartrue ( $uninstall_comments ))
2008-01-20 15:01:19 +00:00
{
2006-12-02 04:36:16 +00:00
unset ( $search_prefs [ 'comments_handlers' ][ $eplug_folder ]);
}
2009-09-06 20:04:04 +00:00
e107 :: getConfig ( 'search' ) -> setPref ( $search_prefs ) -> save ();
2006-12-02 04:36:16 +00:00
}
2008-01-20 15:01:19 +00:00
function manage_notify ( $action , $eplug_folder )
{
2009-09-03 22:27:32 +00:00
$tp = e107 :: getParser ();
// $notify_prefs = $sysprefs -> get('notify_prefs');
// $notify_prefs = $eArrayStorage -> ReadArray($notify_prefs);
$notify_prefs = e107 :: getConfig ( 'notify' );
2006-12-02 04:36:16 +00:00
$e_notify = file_exists ( e_PLUGIN . $eplug_folder . '/e_notify.php' ) ? TRUE : FALSE ;
2008-01-20 15:01:19 +00:00
if ( $action == 'add' )
{
2006-12-02 04:36:16 +00:00
$install_notify = $e_notify ? TRUE : FALSE ;
2008-01-20 15:01:19 +00:00
}
else if ( $action == 'remove' )
{
2009-09-15 16:10:32 +00:00
$uninstall_notify = $notify_prefs -> isData ( 'plugins/' . $eplug_folder ); //isset($notify_prefs['plugins'][$eplug_folder]) ? TRUE : FALSE;
2008-01-20 15:01:19 +00:00
}
else if ( $action == 'upgrade' )
{
2009-09-15 16:10:32 +00:00
if ( $notify_prefs -> isData ( 'plugins/' . $eplug_folder ))
2008-01-20 15:01:19 +00:00
{
2006-12-02 04:36:16 +00:00
$uninstall_notify = $e_notify ? FALSE : TRUE ;
2008-01-20 15:01:19 +00:00
}
else
{
2006-12-02 04:36:16 +00:00
$install_notify = $e_notify ? TRUE : FALSE ;
}
}
2009-09-03 22:27:32 +00:00
if ( vartrue ( $install_notify ))
2008-01-20 15:01:19 +00:00
{
2009-09-15 16:10:32 +00:00
$notify_prefs -> setPref ( 'plugins/' . $eplug_folder , 1 ); //$notify_prefs['plugins'][$eplug_folder] = TRUE;
2006-12-02 04:36:16 +00:00
require_once ( e_PLUGIN . $eplug_folder . '/e_notify.php' );
2008-01-20 15:01:19 +00:00
foreach ( $config_events as $event_id => $event_text )
{
2009-09-15 16:10:32 +00:00
$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' => '');
2006-12-02 04:36:16 +00:00
}
2008-01-20 15:01:19 +00:00
}
2009-09-03 22:27:32 +00:00
else if ( vartrue ( $uninstall_notify ))
2008-01-20 15:01:19 +00:00
{
2009-09-15 16:10:32 +00:00
$notify_prefs -> removePref ( 'plugins/' . $eplug_folder );
//unset($notify_prefs['plugins'][$eplug_folder]);
2006-12-02 04:36:16 +00:00
require_once ( e_PLUGIN . $eplug_folder . '/e_notify.php' );
2008-01-20 15:01:19 +00:00
foreach ( $config_events as $event_id => $event_text )
{
2009-09-15 16:10:32 +00:00
$notify_prefs -> removePref ( 'event/' . $event_id );
//unset($notify_prefs['event'][$event_id]);
2006-12-02 04:36:16 +00:00
}
}
2009-09-15 16:10:32 +00:00
//$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 );
2006-12-02 04:36:16 +00:00
}
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
//----------------------------------------------------------
2008-12-10 22:39:43 +00:00
// $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
2008-12-30 19:01:17 +00:00
// $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
2009-10-23 09:08:15 +00:00
function install_plugin_xml ( $id , $function = '' , $options = FALSE )
2007-05-30 20:35:44 +00:00
{
2009-09-03 22:27:32 +00:00
global $pref ;
2008-08-09 16:49:58 +00:00
2009-09-03 22:27:32 +00:00
$sql = e107 :: getDb ();
2009-10-23 09:08:15 +00:00
$mes = eMessage :: getInstance ();
2009-09-23 23:18:18 +00:00
2008-08-09 16:49:58 +00:00
$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' ] . '/' ;
2009-09-23 23:18:18 +00:00
$this -> plugFolder = $plug [ 'plugin_path' ];
$this -> unInstallOpts = $options ;
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 == '' )
{
2008-12-30 09:44:23 +00:00
$error [] = EPL_ADLAN_77 ;
$canContinue = FALSE ;
2008-01-27 01:34:59 +00:00
}
2008-12-10 22:39:43 +00:00
if ( $canContinue && $this -> parse_plugin_xml ( $plug [ 'plugin_path' ]))
2008-01-27 01:34:59 +00:00
{
2008-12-30 09:44:23 +00:00
$plug_vars = $this -> plug_vars ;
2008-01-27 01:34:59 +00:00
}
else
{
2008-12-30 09:44:23 +00:00
$error [] = EPL_ADLAN_76 ;
$canContinue = FALSE ;
2008-08-09 16:49:58 +00:00
}
2009-10-20 03:49:28 +00:00
if ( varset ( $plug_vars [ 'languageFiles' ]))
{
$this -> XmlLanguageFiles ( $function , $plug_vars [ 'languageFiles' ], 'pre' ); // First of all, see if there's a language file specific to install
}
2008-08-10 11:41:13 +00:00
// Next most important, if installing or upgrading, check that any dependencies are met
2009-09-23 23:18:18 +00:00
if ( $canContinue && ( $function != 'uninstall' ) && isset ( $plug_vars [ 'dependencies' ]))
2008-08-09 16:49:58 +00:00
{
2009-09-23 23:18:18 +00:00
$canContinue = $this -> XmlDependencies ( $plug_vars [ 'dependencies' ]);
2008-08-09 16:49:58 +00:00
}
if ( ! $canContinue )
{
2009-09-23 23:18:18 +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
2008-08-12 20:26:53 +00:00
if ( $canContinue )
2009-09-23 23:18:18 +00:00
{
2008-08-17 12:02:14 +00:00
$ret = $this -> execute_function ( $path , $function , 'pre' );
if ( ! is_bool ( $ret )) $txt .= $ret ;
2008-08-12 20:26:53 +00:00
}
2008-02-02 00:48:58 +00:00
2009-09-23 23:18:18 +00:00
if ( $canContinue && count ( $sql_list )) // TODO - move to it's own function.
2008-08-12 20:26:53 +00:00
{ // Handle tables
2009-09-23 23:18:18 +00:00
2008-08-12 20:26:53 +00:00
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
{
2008-08-12 20:26:53 +00:00
$tableList = $dbHandler -> get_table_def ( '' , $path . $sqlFile );
if ( ! is_array ( $tableList ))
2008-01-27 01:34:59 +00:00
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Can't read SQL definition: " . $path . $sqlFile , E_MESSAGE_ERROR );
2008-08-12 20:26:53 +00:00
break ;
}
// Got the required definition here
2009-10-20 03:49:28 +00:00
2008-08-12 20:26:53 +00:00
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
{
2008-08-12 20:26:53 +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 ]));
2009-09-28 07:17:52 +00:00
$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
2009-10-23 09:08:15 +00:00
$mes -> add ( $txt , $status );
2008-08-12 20:26:53 +00:00
break ;
case 'upgrade' :
$tmp = $dbHandler -> update_table_structure ( $ct , FALSE , TRUE , $pref [ 'multilanguage' ]);
if ( $tmp === FALSE )
{
2008-12-10 22:39:43 +00:00
$error [] = 'Error updating table: ' . $ct [ 1 ];
2008-08-12 20:26:53 +00:00
}
elseif ( $tmp !== TRUE )
{
$error [] = $tmp ;
}
break ;
2008-12-10 22:39:43 +00:00
case 'refresh' : // Leave things alone
break ;
2008-08-12 20:26:53 +00:00
case 'uninstall' :
2008-12-30 19:01:17 +00:00
if ( varsettrue ( $options [ 'del_tables' ], FALSE ))
{
2009-09-28 07:17:52 +00:00
$txt = " Removing table { $ct [ 1 ] } <br /> " ;
$status = $this -> manage_tables ( 'remove' , array ( $ct [ 1 ])) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ; // Delete the table
2009-10-23 09:08:15 +00:00
$mes -> add ( $txt , $status );
2008-12-30 19:01:17 +00:00
}
else
2009-09-28 07:17:52 +00:00
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Table { $ct [ 1 ] } left in place. " , E_MESSAGE_SUCCESS );
2008-12-30 19:01:17 +00:00
}
2008-08-12 20:26:53 +00:00
break ;
2008-01-27 01:34:59 +00:00
}
}
}
2009-10-20 03:49:28 +00:00
}
if ( varset ( $plug_vars [ 'adminLinks' ]))
{
$this -> XmlAdminLinks ( $function , $plug_vars [ 'adminLinks' ]);
}
2009-09-23 23:18:18 +00:00
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' ]);
}
2009-10-20 03:49:28 +00:00
if ( varset ( $plug_vars [ 'languageFiles' ]))
2009-09-23 23:18:18 +00:00
{
2009-10-20 03:49:28 +00:00
$this -> XmlLanguageFiles ( $function , $plug_vars [ 'languageFiles' ]);
2009-09-23 23:18:18 +00:00
}
2009-09-28 07:17:52 +00:00
$this -> manage_icons ( $this -> plugFolder , $function );
2009-09-23 23:18:18 +00:00
//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' ]);
2009-10-26 01:04:36 +00:00
2009-09-23 23:18:18 +00:00
$p_installed = e107 :: getPref ( 'plug_installed' , array ()); // load preference;
if ( $function == 'install' || $function == 'upgrade' )
{
$sql -> db_Update ( 'plugin' , " plugin_installflag = 1, plugin_addons = ' { $eplug_addons } ', plugin_version = ' { $plug_vars [ '@attributes' ][ 'version' ] } ', plugin_category =' " . $this -> manage_category ( $plug_vars [ 'category' ]) . " ', plugin_releaseUrl= ' " . varset ( $plug_vars [ '@attributes' ][ 'releaseUrl' ]) . " ' 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 ();
}
if ( $function == 'uninstall' )
{
$sql -> db_Update ( 'plugin' , " plugin_installflag = 0, plugin_addons = ' { $eplug_addons } ', plugin_version = ' { $plug_vars [ '@attributes' ][ 'version' ] } ', plugin_category =' " . $this -> manage_category ( $plug_vars [ 'category' ]) . " ', plugin_releaseUrl= ' " . varset ( $plug_vars [ '@attributes' ][ 'releaseUrl' ]) . " ' WHERE plugin_id = " . $id );
unset ( $p_installed [ $plug [ 'plugin_path' ]]);
e107 :: getConfig ( 'core' ) -> setPref ( 'plug_installed' , $p_installed );
}
e107 :: getConfig ( 'core' ) -> save ();
2009-10-20 03:49:28 +00:00
/* if ( $function == 'install' )
2009-09-23 23:18:18 +00:00
{
if ( isset ( $plug_vars [ 'management' ][ 'installDone' ][ 0 ]))
{
2009-10-23 09:08:15 +00:00
$mes -> add ( $plug_vars [ 'management' ][ 'installDone' ][ 0 ], E_MESSAGE_SUCCESS );
2009-09-23 23:18:18 +00:00
}
2009-10-20 03:49:28 +00:00
} */
if ( ! $this -> execute_function ( $path , $function , 'post' )) // Call any custom post functions defined in <plugin>_setup.php or the deprecated <management> section
{
if ( $function == 'install' )
{
$text = " Installation Complete. " ;
if ( $this -> plugConfigFile )
{
$text .= " <a href=' " . $this -> plugConfigFile . " '>[ " . LAN_CONFIGURE . " ]</a> " ;
}
2009-09-23 23:18:18 +00:00
2009-10-23 09:08:15 +00:00
$mes -> add ( $text , E_MESSAGE_SUCCESS );
2009-10-20 03:49:28 +00:00
}
}
2009-09-23 23:18:18 +00:00
}
2009-10-20 03:49:28 +00:00
2009-09-23 23:18:18 +00:00
/**
* Process XML Tag < dependencies > ( deprecated 'depend' which is a brand of adult diapers )
* @ param array $tag
* @ return boolean
*/
function XmlDependencies ( $tag )
{
$canContinue = TRUE ;
2009-10-23 09:08:15 +00:00
$mes = eMessage :: getInstance ();
2009-09-23 23:18:18 +00:00
$error = array ();
2009-09-17 00:13:40 +00:00
2009-09-23 23:18:18 +00:00
foreach ( $tag as $dt => $dv )
2008-01-27 01:34:59 +00:00
{
2009-09-23 23:18:18 +00:00
if ( isset ( $dv [ '@attributes' ]) && isset ( $dv [ '@attributes' ][ 'name' ]))
2008-01-27 01:34:59 +00:00
{
2009-09-23 23:18:18 +00:00
// 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 );
2009-10-23 09:08:15 +00:00
$mes -> add ( $text , E_MESSAGE_ERROR );
2009-09-23 23:18:18 +00:00
}
return $canContinue ;
}
2009-10-20 03:49:28 +00:00
2009-09-23 23:18:18 +00:00
/**
2009-10-20 03:49:28 +00:00
* Process XML Tag < LanguageFiles >
2009-09-23 23:18:18 +00:00
* @ param object $function
* @ param object $tag
* @ return
*/
2009-10-20 03:49:28 +00:00
function XmlLanguageFiles ( $function , $tag , $when = '' )
2009-09-23 23:18:18 +00:00
{
$core = e107 :: getConfig ( 'core' );
2009-10-20 03:49:28 +00:00
foreach ( $tag [ 'file' ] as $val )
{
$att = $val [ '@attributes' ];
if ( $when == 'pre' ) // just check for install language file BEFORE install.
{
if ( $att [ 'type' ] == 'install' )
{
$file = str_replace ( '--LAN--' , e_LANGUAGE , $att [ 'path' ]);
$fullpath_file = e_PLUGIN . $this -> plugFolder . " / " . $file ;
include_lan ( $fullpath_file );
return ;
}
}
elseif ( $att [ 'type' ] == 'log' )
{
switch ( $function )
{
case 'install' :
case 'upgrade' :
case 'refresh' :
$core -> setPref ( 'logLanguageFile/' . $this -> plugFolder , $att [ 'path' ]);
break ;
case 'uninstall' :
$core -> removePref ( 'logLanguageFile/' . $this -> plugFolder );
break ;
}
}
}
2009-09-23 23:18:18 +00:00
}
2009-10-20 03:49:28 +00:00
2009-09-23 23:18:18 +00:00
/**
* Process XML Tag < siteLinks >
* @ param string $function install | upgrade | refresh | uninstall
* @ param array $array
* @ return
*/
function XmlSiteLinks ( $function , $array )
{
2009-10-23 09:08:15 +00:00
$mes = e107 :: getMessage ();
2009-09-23 23:18:18 +00:00
foreach ( $array [ 'link' ] as $link )
{
2008-08-10 16:06:15 +00:00
$attrib = $link [ '@attributes' ];
2009-09-23 23:18:18 +00:00
$linkName = ( defset ( $link [ '@value' ])) ? constant ( $link [ '@value' ]) : $link [ '@value' ];
$remove = ( varset ( $attrib [ 'deprecate' ]) == 'true' ) ? TRUE : FALSE ;
2009-10-22 04:14:45 +00:00
$url = $attrib [ 'url' ];
2009-09-23 23:18:18 +00:00
$perm = ( isset ( $attrib [ 'perm' ]) ? $attrib [ 'perm' ] : 0 );
2008-01-27 01:34:59 +00:00
switch ( $function )
{
2008-12-10 22:39:43 +00:00
case 'upgrade' :
case 'install' :
2009-09-23 23:18:18 +00:00
if ( ! $remove ) // Add any non-deprecated link
{
$status = ( $this -> manage_link ( 'add' , $url , $linkName , $perm )) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2009-10-23 09:08:15 +00:00
$mes -> add ( " Adding Link: { $linkName } with url [ { $url } ] and perm { $perm } " , $status );
2008-12-10 22:39:43 +00:00
}
2009-09-23 23:18:18 +00:00
if ( $function == 'upgrade' && $remove ) //remove inactive links on upgrade
2008-12-10 22:39:43 +00:00
{
2009-09-23 23:18:18 +00:00
$status = ( $this -> manage_link ( 'remove' , $url , $linkName )) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2009-10-23 09:08:15 +00:00
$mes -> add ( " Removing Link: { $linkName } with url [ { $url } ] " , $status );
2008-12-10 22:39:43 +00:00
}
break ;
2009-09-23 23:18:18 +00:00
case 'refresh' : // Probably best to leave well alone
2008-12-10 22:39:43 +00:00
break ;
2009-09-23 23:18:18 +00:00
case 'uninstall' : //remove all links
$status = ( $this -> manage_link ( 'remove' , $url , $linkName )) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2009-10-23 09:08:15 +00:00
$mes -> add ( " Removing Link: { $linkName } with url [ { $url } ] " , $status );
2008-12-10 22:39:43 +00:00
break ;
2008-01-27 01:34:59 +00:00
}
2009-09-23 23:18:18 +00:00
}
}
2009-09-21 21:53:38 +00:00
2009-09-23 23:18:18 +00:00
/**
* Process XML Tag < adminLinks >
* @ return
*/
2009-10-20 03:49:28 +00:00
function XmlAdminLinks ( $function , $tag )
2009-09-23 23:18:18 +00:00
{
2009-10-20 03:49:28 +00:00
foreach ( $tag [ 'link' ] as $link )
{
$attrib = $link [ '@attributes' ];
$linkName = ( defset ( $link [ '@value' ])) ? constant ( $link [ '@value' ]) : $link [ '@value' ];
$url = e_PLUGIN_ABS . $this -> plugFolder . " / " . $attrib [ 'url' ];
if ( $attrib [ 'primary' ] == 'true' )
{
$this -> plugConfigFile = $url ;
}
}
2009-09-23 23:18:18 +00:00
}
2008-02-01 14:11:27 +00:00
2009-09-21 21:53:38 +00:00
2009-09-23 23:18:18 +00:00
/**
* Process XML Tag < userClasses >
* @ param string $function install | upgrade | refresh | uninstall
* @ param array $array
* @ return
*/
function XmlUserClasses ( $function , $array )
{
2009-10-23 09:08:15 +00:00
$mes = e107 :: getMessage ();
2009-09-17 00:13:40 +00:00
2009-09-23 23:18:18 +00:00
foreach ( $array [ 'class' ] as $uclass )
2008-01-27 05:16:03 +00:00
{
2008-02-02 22:04:18 +00:00
$attrib = $uclass [ '@attributes' ];
2009-09-23 23:18:18 +00:00
$name = $attrib [ 'name' ];
$description = $attrib [ 'description' ];
$remove = ( varset ( $attrib [ 'deprecate' ]) == 'true' ) ? TRUE : FALSE ;
2008-02-02 22:04:18 +00:00
switch ( $function )
2008-01-27 05:16:03 +00:00
{
2008-12-29 22:30:16 +00:00
case 'install' :
case 'upgrade' :
case 'refresh' :
2009-09-23 23:18:18 +00:00
if ( ! $remove ) // Add all active userclasses (code checks for already installed)
{
$status = $this -> manage_userclass ( 'add' , $name , $description ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2009-10-23 09:08:15 +00:00
$mes -> add ( 'Adding Userclass: ' . $name , $status );
2009-09-23 23:18:18 +00:00
}
if ( $function == 'upgrade' && $remove ) //If upgrading, removing any inactive userclass
{
$status = $this -> manage_userclass ( 'remove' , $name , $description ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2009-10-23 09:08:15 +00:00
$mes -> add ( 'Removing Userclass: ' . $name , $status );
2009-09-23 23:18:18 +00:00
}
2008-02-02 22:04:18 +00:00
break ;
2009-09-23 23:18:18 +00:00
case 'uninstall' : //If uninstalling, remove all userclasses (active or inactive)
if ( varsettrue ( $this -> unInstallOpts [ 'del_userclasses' ], FALSE ))
2008-12-30 19:01:17 +00:00
{
2009-09-23 23:18:18 +00:00
$status = $this -> manage_userclass ( 'remove' , $name , $description ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2009-10-23 09:08:15 +00:00
$mes -> add ( 'Removing Userclass: ' . $name , $status );
2008-12-30 19:01:17 +00:00
}
else
{
2009-10-23 09:08:15 +00:00
$mes -> add ( 'Userclass: ' . $name . ' left in place' . $name , $status );
2008-12-30 19:01:17 +00:00
}
2009-09-23 23:18:18 +00:00
2008-02-02 22:04:18 +00:00
break ;
2008-01-27 05:16:03 +00:00
}
}
2009-09-23 23:18:18 +00:00
}
2008-11-24 00:36:50 +00:00
2009-09-23 23:18:18 +00:00
/**
* Process XML Tag < extendedFields >
* @ param string $function install | upgrade | refresh | uninstall
* @ param array $array
* @ return
*/
function XmlExtendedFields ( $function , $array )
{
2009-10-23 09:08:15 +00:00
$mes = e107 :: getMessage ();
2009-09-23 23:18:18 +00:00
foreach ( $array [ 'field' ] as $efield )
2008-11-24 00:36:50 +00:00
{
$attrib = $efield [ '@attributes' ];
$attrib [ 'default' ] = varset ( $attrib [ 'default' ]);
2009-09-23 23:18:18 +00:00
$name = 'plugin_' . $this -> plugFolder . '_' . $attrib [ 'name' ];
$source = 'plugin_' . $this -> plugFolder ;
$remove = ( varset ( $attrib [ 'deprecate' ]) == 'true' ) ? TRUE : FALSE ;
$type = $attrib [ 'type' ];
2008-12-05 14:18:51 +00:00
2008-11-24 00:36:50 +00:00
switch ( $function )
{
2009-09-23 23:18:18 +00:00
case 'install' : // Add all active extended fields
2008-11-24 00:36:50 +00:00
case 'upgrade' :
2009-09-23 23:18:18 +00:00
if ( ! $remove )
2008-11-24 00:36:50 +00:00
{
2009-09-23 23:18:18 +00:00
$status = $this -> manage_extended_field ( 'add' , $name , $type , $attrib [ 'default' ], $source ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2009-10-23 09:08:15 +00:00
$mes -> add ( 'Adding Extended Field: ' . $name . ' ... ' , $status );
2008-11-24 00:36:50 +00:00
}
2009-09-23 23:18:18 +00:00
if ( $function == 'upgrade' && $remove ) //If upgrading, removing any inactive extended fields
{
$status = $this -> manage_extended_field ( 'remove' , $name , $source ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2009-10-23 09:08:15 +00:00
$mes -> add ( 'Removing Extended Field: ' . $name . ' ... ' , $status );
2008-11-24 00:36:50 +00:00
}
break ;
2009-09-23 23:18:18 +00:00
case 'uninstall' : //If uninstalling, remove all extended fields (active or inactive)
if ( varsettrue ( $this -> unInstallOpts [ 'del_extended' ], FALSE ))
2008-12-30 19:01:17 +00:00
{
2009-09-23 23:18:18 +00:00
$status = ( $this -> manage_extended_field ( 'remove' , $name , $source )) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2009-10-23 09:08:15 +00:00
$mes -> add ( 'Removing Extended Field: ' . $name . ' ... ' , $status );
2008-12-30 19:01:17 +00:00
}
else
{
2009-10-23 09:08:15 +00:00
$mes -> add ( 'Extended Field: ' . $name . ' left in place' . $name , E_MESSAGE_SUCCESS );
2008-12-30 19:01:17 +00:00
}
break ;
2008-11-24 00:36:50 +00:00
}
}
2008-02-02 00:48:58 +00:00
}
2006-12-02 04:36:16 +00:00
2009-09-23 23:18:18 +00:00
2009-09-21 21:53:38 +00:00
/**
2009-09-23 23:18:18 +00:00
* Process XML tags < mainPrefs > and < pluginPrefs >
2009-09-21 21:53:38 +00:00
* @ param object $mode 'core' or the folder name of the plugin .
* @ param object $function install | uninstall | upgrade | refresh
* @ param object $prefArray XML array of prefs . eg . mainPref () or pluginPref ();
* @ return
*/
2009-09-23 23:18:18 +00:00
function XmlPrefs ( $mode = 'core' , $function , $prefArray )
2009-09-21 21:53:38 +00:00
{
//XXX Could also be used for theme prefs.. perhaps this function should be moved elsewhere?
2009-09-22 21:12:12 +00:00
//TODO array support for prefs. <key>? or array() as used in xml site export?
2009-10-23 09:08:15 +00:00
$mes = e107 :: getMessage ();
2009-09-21 21:53:38 +00:00
if ( ! varset ( $prefArray ) || ! varset ( $prefArray ))
{
return ;
}
$config = ( $mode == 'core' ) ? e107 :: getConfig ( 'core' ) : e107 :: getPlugConfig ( $mode );
foreach ( $prefArray [ 'pref' ] as $tag )
{
$key = varset ( $tag [ '@attributes' ][ 'name' ]);
2009-09-22 21:12:12 +00:00
$value = vartrue ( $tag [ '@value' ]);
2009-09-23 23:18:18 +00:00
$remove = ( varset ( $tag [ '@attributes' ][ 'deprecate' ]) == 'true' ) ? TRUE : FALSE ;
2009-09-21 21:53:38 +00:00
if ( varset ( $tag [ '@attributes' ][ 'value' ]))
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Deprecated plugin.xml spec. found. Use the following format: " . htmlentities ( " <pref name='name'>value</pref> " ), E_MESSAGE_ERROR );
2009-09-21 21:53:38 +00:00
}
switch ( $function )
{
case 'install' :
$config -> add ( $key , $value );
2009-10-23 09:08:15 +00:00
$mes -> add ( " Adding Pref: " . $key , E_MESSAGE_SUCCESS );
2009-09-21 21:53:38 +00:00
break ;
case 'upgrade' :
case 'refresh' :
2009-09-22 21:12:12 +00:00
if ( $remove ) // remove active='false' prefs.
{
$config -> remove ( $key , $value );
2009-10-23 09:08:15 +00:00
$mes -> add ( " Removing Pref: " . $key , E_MESSAGE_SUCCESS );
2009-09-22 21:12:12 +00:00
}
else
{
$config -> update ( $key , $value );
2009-10-23 09:08:15 +00:00
$mes -> add ( " Updating Pref: " . $key , E_MESSAGE_SUCCESS );
2009-09-22 21:12:12 +00:00
}
2009-09-21 21:53:38 +00:00
break ;
case 'uninstall' :
$config -> remove ( $key , $value );
2009-10-23 09:08:15 +00:00
$mes -> add ( " Removing Pref: " . $key , E_MESSAGE_SUCCESS );
2009-09-21 21:53:38 +00:00
break ;
}
}
2009-09-23 23:18:18 +00:00
if ( $mode != " core " ) // Do only one core pref save during install/uninstall etc.
2009-09-21 21:53:38 +00:00
{
2009-09-23 23:18:18 +00:00
$config -> save ();
}
return ;
2009-09-21 21:53:38 +00:00
}
2009-10-21 12:53:00 +00:00
/**
*
* @ param object $path [ unused ]
* @ param object $what install | uninstall | upgrade
* @ param object $when pre | post
* @ return
*/
2008-02-02 00:48:58 +00:00
function execute_function ( $path = '' , $what = '' , $when = '' )
2009-10-20 03:49:28 +00:00
{
2009-10-23 09:08:15 +00:00
$mes = eMessage :: getInstance ();
2009-10-20 03:49:28 +00:00
$class_name = $this -> plugFolder . " _setup " ;
2009-10-21 12:53:00 +00:00
$method_name = $what . " _ " . $when ;
2009-10-20 03:49:28 +00:00
if ( varset ( $this -> plug_vars [ '@attributes' ][ 'setupFile' ]))
{
$setup_file = e_PLUGIN . $this -> plugFolder . '/' . $this -> plug_vars [ '@attributes' ][ 'setupFile' ];
}
else
{
$setup_file = e_PLUGIN . $this -> plugFolder . '/' . $this -> plugFolder . '_setup.php' ;
}
if ( is_readable ( $setup_file ))
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Found setup file <b> " . $setup_file . " </b> " , E_MESSAGE_DEBUG );
2009-10-20 03:49:28 +00:00
include_once ( $setup_file );
if ( class_exists ( $class_name ))
{
$obj = new $class_name ;
if ( method_exists ( $obj , $method_name ))
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Executing setup function <b> " . $method_name . " ()</b> " , E_MESSAGE_DEBUG );
2009-10-20 03:49:28 +00:00
return call_user_func ( array ( $obj , $method_name ), $this );
}
else
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Setup function <b> " . $method_name . " ()</b> NOT found. " , E_MESSAGE_DEBUG );
2009-10-20 03:49:28 +00:00
return FALSE ;
}
}
else
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Setup function <b> " . $method_name . " ()</b> NOT found. " , E_MESSAGE_DEBUG );
2009-10-20 03:49:28 +00:00
return FALSE ;
}
}
else
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Optional Setup File NOT Found <b> " . $setup_file . " </b> " , E_MESSAGE_DEBUG );
2009-10-20 03:49:28 +00:00
}
2009-10-23 09:08:15 +00:00
$mes -> add ( " Setup function <b> " . $method_name . " ()</b> NOT found. " , E_MESSAGE_DEBUG );
2009-10-20 03:49:28 +00:00
return FALSE ; // IMPORTANT.
2008-02-01 14:11:27 +00:00
}
2009-10-20 03:49:28 +00:00
2008-01-26 05:19:59 +00:00
2009-09-23 23:18:18 +00:00
// DEPRECATED - See XMLPrefs();
2009-09-21 21:53:38 +00:00
function parse_prefs ( $pref_array , $mode = 'simple' )
2008-02-01 18:09:02 +00:00
{
$ret = array ();
if ( ! isset ( $pref_array [ 0 ]))
{
$pref_array = array ( $pref_array );
}
2009-07-14 03:18:17 +00:00
if ( is_array ( $pref_array ))
2008-02-01 18:09:02 +00:00
{
2009-07-14 03:18:17 +00:00
foreach ( $pref_array as $k => $p )
2008-02-01 18:09:02 +00:00
{
2009-07-14 03:18:17 +00:00
$attrib = $p [ '@attributes' ];
if ( isset ( $attrib [ 'type' ]) && $attrib [ 'type' ] == 'array' )
2008-02-01 18:09:02 +00:00
{
2009-07-14 03:18:17 +00:00
$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' ];
2008-02-01 18:09:02 +00:00
}
else
{
2009-07-14 03:18:17 +00:00
$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' ];
}
2008-02-01 18:09:02 +00:00
}
}
}
return $ret ;
}
2008-12-05 14:18:51 +00:00
2008-01-28 02:49:50 +00:00
function install_plugin_php ( $id )
2008-01-26 05:19:59 +00:00
{
2009-10-22 04:14:45 +00:00
$function = 'install' ;
2009-09-03 22:27:32 +00:00
$sql = e107 :: getDb ();
2009-10-22 04:14:45 +00:00
$mes = e107 :: getMessage ();
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
2007-05-07 13:38:34 +00:00
$plug [ 'plug_action' ] = 'install' ;
2006-12-02 04:36:16 +00:00
2009-10-22 04:14:45 +00:00
$this -> parse_plugin_php ( $plug [ 'plugin_path' ]);
$plug_vars = $this -> plug_vars ;
2009-07-14 03:18:17 +00:00
include ( $_path . 'plugin.php' );
2008-01-26 05:19:59 +00:00
$func = $eplug_folder . '_install' ;
if ( function_exists ( $func ))
2008-01-20 15:01:19 +00:00
{
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-20 15:01:19 +00:00
{
2008-01-26 05:19:59 +00:00
$text .= EPL_ADLAN_19 . '<br />' ;
2009-10-22 04:14:45 +00:00
$mes -> add ( EPL_ADLAN_19 , E_MESSAGE_SUCCESS );
2008-01-26 05:19:59 +00:00
//success
2006-12-02 04:36:16 +00:00
}
2008-01-26 05:19:59 +00:00
else
2008-01-20 15:01:19 +00:00
{
2009-10-22 04:14:45 +00:00
$mes -> add ( EPL_ADLAN_18 , E_MESSAGE_ERROR );
2008-01-26 05:19:59 +00:00
//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
2009-10-22 04:14:45 +00:00
/* if ( is_array ( $eplug_prefs ))
2008-01-26 05:19:59 +00:00
{
$this -> manage_prefs ( 'add' , $eplug_prefs );
$text .= EPL_ADLAN_8 . '<br />' ;
2009-10-22 04:14:45 +00:00
} */
if ( varset ( $plug_vars [ 'mainPrefs' ])) //Core pref items <mainPrefs>
{
$this -> XmlPrefs ( 'core' , $function , $plug_vars [ 'mainPrefs' ]);
$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-20 15:01:19 +00:00
{
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
}
2006-12-02 04:36:16 +00:00
2009-10-22 04:14:45 +00:00
if ( varset ( $plug_vars [ 'siteLinks' ]))
2008-01-26 05:19:59 +00:00
{
2009-10-22 04:14:45 +00:00
$this -> XmlSiteLinks ( $function , $plug_vars [ 'siteLinks' ]);
2008-01-26 05:19:59 +00:00
}
2009-10-22 04:14:45 +00:00
if ( varset ( $plug_vars [ 'userClasses' ]))
{
$this -> XmlUserClasses ( $function , $plug_vars [ 'userClasses' ]);
}
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 );
2009-09-03 22:27:32 +00:00
$p_installed = e107 :: getPref ( 'plug_installed' , array ()); // load preference;
$p_installed [ $plug [ 'plugin_path' ]] = $plug [ 'plugin_version' ];
e107 :: getConfig ( 'core' ) -> setPref ( 'plug_installed' , $p_installed ) -> save ();
2008-01-26 05:19:59 +00:00
$text .= ( isset ( $eplug_done ) ? " <br /> { $eplug_done } " : " <br /> " . LAN_INSTALL_SUCCESSFUL );
2009-10-20 03:49:28 +00:00
if ( $eplug_conffile )
{
$text .= " <a href=' " . e_PLUGIN . $eplug_folder . " / " . $eplug_conffile . " '>[ " . LAN_CONFIGURE . " ]</a> " ;
}
2006-12-02 04:36:16 +00:00
2008-01-26 05:19:59 +00:00
return $text ;
}
2008-01-20 15:01:19 +00:00
2008-01-26 05:19:59 +00:00
/**
* Installs a plugin by ID
*
* @ param int $id
*/
function install_plugin ( $id )
{
2009-09-03 22:27:32 +00:00
global $ns , $sysprefs , $mySQLprefix ;
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
2008-01-26 05:19:59 +00:00
// 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 );
2009-07-14 03:18:17 +00:00
2008-01-26 05:19:59 +00:00
$plug [ 'plug_action' ] = 'install' ;
2008-12-05 14:18:51 +00:00
2009-09-17 01:47:20 +00:00
if ( ! vartrue ( $plug [ 'plugin_installflag' ]))
2008-01-26 05:19:59 +00:00
{
$_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
{
2009-10-23 09:08:15 +00:00
$text = $this -> install_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 );
2008-01-20 15:01:19 +00:00
}
}
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
}
2009-09-03 22:27:32 +00:00
function save_addon_prefs () // scan the plugin table and create path-array-prefs for each addon.
{
$sql = e107 :: getDb ();
2009-09-06 20:04:04 +00:00
$core = e107 :: getConfig ( 'core' );
2009-09-03 22:27:32 +00:00
2009-09-21 23:02:47 +00:00
foreach ( $this -> plugin_addons as $var ) // clear all existing prefs.
2009-09-12 13:16:56 +00:00
{
2009-09-21 23:02:47 +00:00
$core -> update ( $var . '_list' , " " );
2009-09-12 13:16:56 +00:00
}
$query = " SELECT * FROM #plugin WHERE plugin_addons !='' ORDER BY plugin_path ASC " ;
2009-09-13 12:12:23 +00:00
if ( $sql -> db_Select_gen ( $query ))
2006-12-02 04:36:16 +00:00
{
while ( $row = $sql -> db_Fetch ())
{
2008-01-20 15:01:19 +00:00
$is_installed = ( $row [ 'plugin_installflag' ] == 1 );
$tmp = explode ( " , " , $row [ 'plugin_addons' ]);
2006-12-02 04:36:16 +00:00
$path = $row [ 'plugin_path' ];
2009-09-25 20:14:29 +00:00
2008-01-20 15:01:19 +00:00
if ( $is_installed )
2006-12-02 04:36:16 +00:00
{
2008-02-01 18:09:02 +00:00
foreach ( $tmp as $val )
2006-12-02 04:36:16 +00:00
{
2008-02-01 18:09:02 +00:00
if ( strpos ( $val , 'e_' ) === 0 )
2008-01-20 15:01:19 +00:00
{
2009-09-06 20:04:04 +00:00
// $addpref[$val."_list"][$path] = $path;
$core -> setPref ( $val . '_list/' . $path , $path );
2008-01-20 15:01:19 +00:00
}
2006-12-02 04:36:16 +00:00
}
}
2009-09-25 20:14:29 +00:00
2008-01-20 15:01:19 +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 ();
2008-01-20 15:01:19 +00:00
foreach ( $tmp as $adds )
2006-12-02 04:36:16 +00:00
{
2008-01-20 15:01:19 +00:00
if ( substr ( $adds , - 3 ) == " .sc " )
2006-12-02 04:36:16 +00:00
{
$sc_name = substr ( $adds , 0 , - 3 ); // remove the .sc
2007-07-18 20:46:42 +00:00
if ( $is_installed )
{
2008-01-20 15:01:19 +00:00
$sc_array [ $sc_name ] = " 0 " ; // default userclass = e_UC_PUBLIC
2007-07-18 20:46:42 +00:00
}
else
{
2008-01-20 15:01:19 +00:00
$sc_array [ $sc_name ] = e_UC_NOBODY ; // register shortcode, but disable it
2007-07-18 20:46:42 +00:00
}
2006-12-02 04:36:16 +00:00
}
2007-07-18 20:46:42 +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
2008-01-20 15:01:19 +00:00
$bb_array [ $bb_name ] = " 0 " ; // default userclass.
2009-09-06 20:04:04 +00:00
2006-12-02 04:36:16 +00:00
}
2007-07-18 20:46:42 +00:00
if ( $is_installed && ( substr ( $adds , - 4 ) == " _sql " ))
2006-12-02 04:36:16 +00:00
{
2009-09-06 20:04:04 +00:00
$core -> setPref ( 'e_sql_list/' . $path , $adds );
2006-12-02 04:36:16 +00:00
}
}
2008-01-20 15:01:19 +00:00
// 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 );
2009-10-08 14:47:54 +00:00
$core -> setPref ( 'bbcode_list/' . $path , $bb_array );
2006-12-02 04:36:16 +00:00
}
2008-01-20 15:01:19 +00:00
// Build shortcode list - do if uninstalled as well
2007-05-07 13:38:34 +00:00
if ( count ( $sc_array ) > 0 )
{
2008-01-20 15:01:19 +00:00
ksort ( $sc_array );
2009-09-06 20:04:04 +00:00
$core -> setPref ( 'shortcode_list/' . $path , $sc_array );
2006-12-02 04:36:16 +00:00
}
}
}
2009-09-25 20:14:29 +00:00
$core -> save ( FALSE );
2009-07-16 02:55:19 +00:00
if ( $this -> manage_icons ())
{
// echo 'IT WORKED';
}
else
{
// echo "didn't work!";
}
2006-12-02 04:36:16 +00:00
return ;
}
2008-01-20 15:01:19 +00:00
// return a list of available plugin addons for the specified plugin. e_xxx etc.
2007-02-11 20:16:25 +00:00
// $debug = TRUE - prints diagnostics
// $debug = 'check' - checks each file found for php tags - prints 'pass' or 'fail'
2008-01-20 15:01:19 +00:00
function getAddons ( $plugin_path , $debug = FALSE )
2007-02-11 20:16:25 +00:00
{
2009-09-06 20:04:04 +00:00
$fl = e107 :: getFile ();
2008-01-20 15:01:19 +00:00
$p_addons = array ();
2009-09-21 21:53:38 +00:00
foreach ( $this -> plugin_addons as $addon ) //Find exact matches only.
{
// if(preg_match("#^(e_.*)\.php$#", $f['fname'], $matches))
$addonPHP = $addon . " .php " ;
if ( is_readable ( e_PLUGIN . $plugin_path . " / " . $addonPHP ))
2008-01-20 15:01:19 +00:00
{
if ( $debug === 'check' )
{
$passfail = '' ;
2009-09-21 21:53:38 +00:00
$file_text = file_get_contents ( e_PLUGIN . $plugin_path . " / " . $addonPHP );
2009-10-29 13:36:27 +00:00
if (( substr ( $file_text , 0 , 5 ) != '<' . '?php' )
|| ( ( substr ( $file_text , - 2 , 2 ) != '?' . '>' ) && ( strrpos ( $file_text , '?' . '>' ) !== FALSE ) )
)
2008-01-20 15:01:19 +00:00
{
$passfail = '<b>fail</b>' ;
}
else
{
$passfail = 'pass' ;
}
echo $plugin_path . " / " . $addon . " .php - " . $passfail . " <br /> " ;
}
2009-10-23 09:08:15 +00:00
$mes = e107 :: getMessage ();
$mes -> add ( 'Detected addon: <b>' . $addon . '</b>' , E_MESSAGE_DEBUG );
2008-01-20 15:01:19 +00:00
$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 );
2008-01-20 15:01:19 +00:00
$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' ];
}
}
2008-01-20 15:01:19 +00:00
// 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' ];
}
}
2008-01-20 15:01:19 +00:00
// Search _sql files.
foreach ( $sqlList as $esql )
2006-12-02 04:36:16 +00:00
{
if ( is_readable ( e_PLUGIN . $plugin_path . " / " . $esql [ 'fname' ]))
{
2008-08-09 17:23:26 +00:00
$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
}
}
2008-01-20 15:01:19 +00:00
if ( $debug == true )
2006-12-02 04:36:16 +00:00
{
echo $plugin_path . " = " . implode ( " , " , $p_addons ) . " <br /> " ;
}
return implode ( " , " , $p_addons );
}
2007-02-14 21:17:42 +00:00
function checkAddon ( $plugin_path , $e_xxx )
{ // Return 0 = OK, 1 = Fail, 2 = inaccessible
2009-10-29 13:36:27 +00:00
/*** debug
if ( $plugin_path == 'chatbox_menu' && $e_xxx == 'e_rss' )
{
$file_text = file_get_contents ( e_PLUGIN . $plugin_path . " / " . $e_xxx . " .php " );
if ( substr ( $file_text , 0 , 5 ) != '<' . '?php' )
echo '<' . '?php' ;
if ( substr ( $file_text , - 2 , 2 ) != '?' . '>' )
echo '?' . '>' ;
if ( strrpos ( $file_text , '?' . '>' ) !== FALSE )
echo 'no ?' . '>' ;
if ( ( substr ( $file_text , - 2 , 2 ) != '?' . '>' ) AND ( strrpos ( $file_text , '?' . '>' ) !== FALSE ) )
echo " ( (substr( \$ file_text, -2, 2) != '?'.'>') OR (strrpos( \$ file_text, '?'.'>') === FALSE) ) " ;
exit ;
}
*/
2008-01-20 15:01:19 +00:00
if ( is_readable ( e_PLUGIN . $plugin_path . " / " . $e_xxx . " .php " ))
{
$file_text = file_get_contents ( e_PLUGIN . $plugin_path . " / " . $e_xxx . " .php " );
2009-10-29 13:36:27 +00:00
if (( substr ( $file_text , 0 , 5 ) != '<' . '?php' )
|| ( ( substr ( $file_text , - 2 , 2 ) != '?' . '>' ) && ( strrpos ( $file_text , '?' . '>' ) !== FALSE ) )
)
{
return 1 ;
}
2008-01-20 15:01:19 +00:00
return 0 ;
2007-02-14 21:17:42 +00:00
}
2008-01-20 15:01:19 +00:00
return 2 ;
2007-02-14 21:17:42 +00:00
}
2008-01-26 05:19:59 +00:00
2008-01-26 04:47:27 +00:00
2008-08-09 16:49:58 +00:00
// Entry point to read plugin configuration data
2008-12-10 22:39:43 +00:00
function parse_plugin ( $plugName , $force = false )
2008-01-26 04:47:27 +00:00
{
2009-08-31 02:00:51 +00:00
$ret = " " ;
2009-09-03 22:27:32 +00:00
2008-12-10 22:39:43 +00:00
if ( isset ( $this -> parsed_plugin [ $plugName ]) && $force != true )
2008-01-28 02:49:50 +00:00
{
2008-12-10 22:39:43 +00:00
$this -> plug_vars = $this -> parsed_plugin [ $plugName ];
2008-01-28 02:49:50 +00:00
return true ;
}
2008-12-10 22:39:43 +00:00
unset ( $this -> parsed_plugin [ $plugName ]); // In case forced parsing which fails
if ( file_exists ( e_PLUGIN . $plugName . '/plugin.xml' ))
2008-01-26 04:47:27 +00:00
{
2008-12-10 22:39:43 +00:00
$ret = $this -> parse_plugin_xml ( $plugName );
2008-01-26 04:47:27 +00:00
}
2008-12-10 22:39:43 +00:00
elseif ( file_exists ( e_PLUGIN . $plugName . '/plugin.php' ))
2008-01-26 04:47:27 +00:00
{
2008-12-10 22:39:43 +00:00
$ret = $this -> parse_plugin_php ( $plugName );
2008-01-26 04:47:27 +00:00
}
2008-01-28 02:49:50 +00:00
if ( $ret == true )
{
2008-12-10 22:39:43 +00:00
$this -> parsed_plugin [ $plugName ] = $this -> plug_vars ;
2008-01-28 02:49:50 +00:00
}
2009-09-14 11:27:45 +00:00
2008-01-28 02:49:50 +00:00
return $ret ;
2008-01-26 04:47:27 +00:00
}
2008-08-09 16:49:58 +00:00
// Called to parse the (deprecated) plugin.php file
2008-12-10 22:39:43 +00:00
function parse_plugin_php ( $plugName )
2008-01-26 04:47:27 +00:00
{
2009-10-22 04:14:45 +00:00
$mes = e107 :: getMessage ();
$tp = e107 :: getParser ();
if ( include ( e_PLUGIN . $plugName . '/plugin.php' ))
{
//$mes->add("Loading ".e_PLUGIN.$plugName.'/plugin.php', E_MESSAGE_DEBUG);
}
2008-01-26 04:47:27 +00:00
$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);
2009-10-22 04:14:45 +00:00
2008-12-03 22:29:58 +00:00
$ret [ '@attributes' ][ 'name' ] = varset ( $eplug_name );
2009-10-22 04:14:45 +00:00
$ret [ '@attributes' ][ 'version' ] = varset ( $eplug_version );
2008-12-03 22:29:58 +00:00
$ret [ '@attributes' ][ 'compatibility' ] = varset ( $eplug_compatible );
2009-10-22 04:14:45 +00:00
$ret [ '@attributes' ][ 'installRequired' ] = ( $eplug_conffile || is_array ( $eplug_table_names ) || is_array ( $eplug_prefs ) || $eplug_module || $eplug_userclass || $eplug_status || $eplug_latest ) ? 'true' : '' ;
$ret [ '@attributes' ][ 'xhtmlcompliant' ] = vartrue ( $eplug_compliant ) ? 'true' : '' ;
2009-09-21 21:53:38 +00:00
$ret [ 'folder' ] = ( varset ( $eplug_folder )) ? $eplug_folder : $plugName ;
2009-10-22 04:14:45 +00:00
2008-12-03 22:29:58 +00:00
$ret [ 'author' ][ '@attributes' ][ 'name' ] = varset ( $eplug_author );
$ret [ 'author' ][ '@attributes' ][ 'url' ] = varset ( $eplug_url );
$ret [ 'author' ][ '@attributes' ][ 'email' ] = varset ( $eplug_email );
2009-10-22 04:14:45 +00:00
$ret [ 'description' ] = varset ( $eplug_description );
$ret [ 'category' ] = varset ( $eplug_category ) ? $this -> manage_category ( $eplug_category ) : " misc " ;
2008-01-26 04:47:27 +00:00
$ret [ 'readme' ] = varset ( $eplug_readme );
2009-10-22 04:14:45 +00:00
$ret [ 'menuName' ] = varset ( $eplug_menu_name );
if ( varset ( $eplug_prefs ))
{
$c = 0 ;
foreach ( $eplug_prefs as $name => $value )
{
$ret [ 'mainPrefs' ][ 'pref' ][ $c ][ '@attributes' ][ 'name' ] = $name ;
$ret [ 'mainPrefs' ][ 'pref' ][ $c ][ '@value' ] = $value ;
$c ++ ;
}
}
2009-07-09 02:47:17 +00:00
2009-10-22 04:14:45 +00:00
// For BC.
2008-01-26 04:47:27 +00:00
$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
2009-10-22 04:14:45 +00:00
if ( varset ( $eplug_conffile ))
{
$ret [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'url' ] = varset ( $eplug_conffile );
$ret [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'description' ] = LAN_CONFIGURE ;
$ret [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'icon' ] = varset ( $eplug_icon );
$ret [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'iconSmall' ] = varset ( $eplug_icon_small );
$ret [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'primary' ] = 'true' ;
}
if ( vartrue ( $eplug_link ) && varset ( $eplug_link_name ) && varset ( $eplug_link_url ))
{
$ret [ 'siteLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'url' ] = $tp -> createConstants ( $eplug_link_url , 1 );
$ret [ 'siteLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'perm' ] = $eplug_link_perms ;
$ret [ 'siteLinks' ][ 'link' ][ 0 ][ '@value' ] = $eplug_link_name ;
}
if ( vartrue ( $eplug_userclass ) && vartrue ( $eplug_userclass_description ))
{
$ret [ 'userClasses' ][ 'class' ][ 0 ][ '@attributes' ][ 'name' ] = $eplug_userclass ;
$ret [ 'userClasses' ][ 'class' ][ 0 ][ '@attributes' ][ 'description' ] = $eplug_userclass_description ;
}
2008-01-26 04:47:27 +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 ;
2009-10-22 04:14:45 +00:00
2008-01-27 01:34:59 +00:00
return true ;
2008-01-26 04:47:27 +00:00
}
2008-08-09 16:49:58 +00:00
// Called to parse the plugin.xml file if it exists
2008-12-10 22:39:43 +00:00
function parse_plugin_xml ( $plugName )
2008-01-26 04:47:27 +00:00
{
2009-09-23 23:18:18 +00:00
2009-09-03 22:27:32 +00:00
$tp = e107 :: getParser ();
// loadLanFiles($plugName, 'admin'); // Look for LAN files on default paths
2008-01-26 04:47:27 +00:00
require_once ( e_HANDLER . 'xml_class.php' );
$xml = new xmlClass ;
2009-09-23 23:18:18 +00:00
// $xml->setOptArrayTags('extendedField,userclass,menuLink,commentID'); // always arrays for these tags.
// $xml->setOptStringTags('install,uninstall,upgrade');
2009-09-16 13:01:19 +00:00
2009-10-22 04:14:45 +00:00
2009-09-21 21:53:38 +00:00
$this -> plug_vars = $xml -> loadXMLfile ( e_PLUGIN . $plugName . '/plugin.xml' , 'advanced' );
2008-12-10 13:27:09 +00:00
if ( $this -> plug_vars === FALSE )
2008-12-05 19:56:51 +00:00
{
2009-07-20 15:24:34 +00:00
require_once ( e_HANDLER . " message_handler.php " );
2009-10-23 09:08:15 +00:00
$mes = e107 :: getMessage ();
$mes -> add ( " Error reading { $plugName } /plugin.xml " , E_MESSAGE_ERROR );
2009-07-20 15:24:34 +00:00
return FALSE ;
2008-12-05 19:56:51 +00:00
}
2009-09-14 11:27:45 +00:00
2009-09-17 00:13:40 +00:00
$this -> plug_vars [ 'category' ] = ( isset ( $this -> plug_vars [ 'category' ])) ? $this -> manage_category ( $this -> plug_vars [ 'category' ]) : " misc " ;
2009-09-21 21:53:38 +00:00
$this -> plug_vars [ 'folder' ] = $plugName ; // remove the need for <folder> tag in plugin.xml.
2009-10-22 04:14:45 +00:00
/*
// Very useful debug code.to compare plugin.php vs plugin.xml
$testplug = 'forum' ;
if ( $plugName == $testplug )
{
$plug_vars1 = $this -> plug_vars ;
$this -> parse_plugin_php ( $testplug );
$plug_vars2 = $this -> plug_vars ;
ksort ( $plug_vars2 );
ksort ( $plug_vars1 );
echo " <table>
< tr >< td >< h1 > PHP </ h1 ></ td >< td >< h1 > XML </ h1 ></ td ></ tr >
< tr >< td style = 'border-right:1px solid black' > " ;
print_a ( $plug_vars2 );
2009-09-21 21:53:38 +00:00
echo " </td><td> " ;
2009-10-22 04:14:45 +00:00
print_a ( $plug_vars1 );
2009-09-21 21:53:38 +00:00
echo " </table> " ;
2009-10-22 04:14:45 +00:00
}
*/
2009-09-23 23:18:18 +00:00
// TODO search for $this->plug_vars['adminLinks']['link'][0]['@attributes']['primary']==true.
$this -> plug_vars [ 'administration' ][ 'icon' ] = varset ( $this -> plug_vars [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'icon' ]);
$this -> plug_vars [ 'administration' ][ 'caption' ] = varset ( $this -> plug_vars [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'description' ]);
$this -> plug_vars [ 'administration' ][ 'iconSmall' ] = varset ( $this -> plug_vars [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'iconSmall' ]);
$this -> plug_vars [ 'administration' ][ 'configFile' ] = varset ( $this -> plug_vars [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'url' ]);
2009-10-22 04:14:45 +00:00
2009-09-14 11:27:45 +00:00
return TRUE ;
}
2009-09-16 13:01:19 +00:00
2008-01-26 04:47:27 +00:00
2006-12-02 04:36:16 +00:00
}
2008-01-27 01:34:59 +00:00
?>