2006-12-02 04:36:16 +00:00
< ? php
/*
2009-11-15 17:38:05 +00:00
* e107 website system
*
2012-01-11 14:54:47 +00:00
* Copyright ( C ) 2008 - 2012 e107 Inc ( e107 . org )
2009-11-15 17:38:05 +00:00
* Released under the terms and conditions of the
* GNU General Public License ( http :// www . gnu . org / licenses / gpl . txt )
*
2011-11-25 17:35:12 +00:00
* $URL $
* $Id $
2009-11-15 17:38:05 +00:00
*
2010-06-23 10:21:21 +00:00
*/
2006-12-02 04:36:16 +00:00
2012-01-11 14:54:47 +00:00
if ( ! defined ( 'e107_INIT' )) { exit ; }
/**
*
* @ package e107
* @ category e107_handlers
* @ version $Id $
* @ author e107inc
*
* Plugin administration handler
*/
2006-12-02 04:36:16 +00:00
2012-01-11 14:54:47 +00:00
e107 :: coreLan ( 'plugin' , true );
2009-09-03 22:27:32 +00:00
2006-12-02 04:36:16 +00:00
class e107plugin
{
2009-12-09 22:38:18 +00:00
// Reserved Addon names.
2010-06-23 10:21:21 +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' ,
2009-11-15 17:38:05 +00:00
'e_cron' ,
2009-11-20 05:01:51 +00:00
'e_mailout' ,
2011-05-04 09:19:50 +00:00
'e_sitelink' ,
2012-08-19 02:33:43 +00:00
'e_tohtml' ,
'e_featurebox'
2010-06-23 10:21:21 +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' ,
2010-06-23 10:21:21 +00:00
// 'eplug_sc', // Not used in 0.8 (or later 0.7)
2009-09-21 21:53:38 +00:00
'eplug_userclass' ,
'eplug_module' ,
2010-06-23 10:21:21 +00:00
// 'eplug_bb', // Not used in 0.8 (or later 0.7)
2009-09-21 21:53:38 +00:00
'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
2010-06-23 10:21:21 +00:00
var $all_eplug_update_variables = array (
2009-09-21 21:53:38 +00:00
'upgrade_alter_tables' ,
2010-06-23 10:21:21 +00:00
// 'upgrade_add_eplug_sc', // Not used in 0.8 (or later 0.7)
// 'upgrade_remove_eplug_sc', // Not used in 0.8 (or later 0.7)
// 'upgrade_add_eplug_bb', // Not used in 0.8 (or later 0.7)
// 'upgrade_remove_eplug_bb', // Not used in 0.8 (or later 0.7)
2009-09-21 21:53:38 +00:00
'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)
2010-06-23 10:21:21 +00:00
var $all_editable_db_fields = array (
'plugin_name' , // Name of the plugin - language dependent
'plugin_version' , // Version - arbitrary text field
'plugin_path' , // Name of the directory off e_PLUGIN - unique
'plugin_installflag' , // '0' = not installed, '1' = installed
'plugin_addons' , // List of any extras associated with plugin - bbcodes, e_XXX files...
'plugin_category' // Plugin Category: settings, users, content, management, tools, misc, about
);
2008-01-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-12-09 22:38: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
/**
2010-06-23 10:21:21 +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 ();
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +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
}
/**
2010-06-23 10:21:21 +00:00
* Check for new plugins , create entry in plugin table and remove deleted plugins
*/
2008-01-20 15:01:19 +00:00
function update_plugins_table ()
2007-02-01 22:00:41 +00:00
{
2009-12-09 22:38:18 +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-12-09 22:38:18 +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-12-09 22:38:18 +00:00
2007-06-05 19:51:36 +00:00
$pluginDBList = array ();
2010-06-23 10:21:21 +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-12-09 22:38:18 +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 />";
2010-06-23 10:21:21 +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 );
2010-06-23 10:21:21 +00:00
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' ]);
2010-06-23 10:21:21 +00:00
$pluginList [ $key ] = $val ;
2008-12-02 21:51:22 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +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
2010-06-23 10:21:21 +00:00
foreach ( $pluginList as $p )
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +00:00
$p [ 'path' ] = substr ( str_replace ( e_PLUGIN , " " , $p [ 'path' ]), 0 , - 1 );
2009-12-09 22:38:18 +00:00
$plugin_path = $p [ 'path' ];
2009-09-10 15:24:57 +00:00
2010-06-23 10:21:21 +00:00
if ( strpos ( $plugin_path , 'e107_' ) !== FALSE )
2009-09-10 15:24:57 +00:00
{
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 ;
}
2010-06-23 10:21:21 +00:00
$plug [ 'plug_action' ] = 'scan' ; // Make sure plugin.php knows what we're up to
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( ! $this -> parse_plugin ( $p [ 'path' ]))
2008-01-20 15:01:19 +00:00
{
2009-12-09 22:38:18 +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 );
2010-06-23 10:21:21 +00:00
continue ; // Carry on and do any others that are OK
2012-08-22 02:45:32 +00:00
}
2009-12-09 22:38:18 +00:00
2008-02-13 00:46:05 +00:00
$plug_info = $this -> plug_vars ;
2009-12-09 22:38:18 +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
{
2010-06-23 10:21:21 +00:00
if ( array_key_exists ( $plugin_path , $pluginDBList ))
{ // Update the addons needed by the plugin
2008-01-20 15:01:19 +00:00
$pluginDBList [ $plugin_path ][ 'status' ] = 'exists' ;
2009-07-09 02:47:17 +00:00
2010-06-23 10:21:21 +00:00
// Check for missing plugin_category in plugin table.
if ( $pluginDBList [ $plugin_path ][ 'plugin_category' ] == '' || $pluginDBList [ $plugin_path ][ 'plugin_category' ] != $plug_info [ 'category' ])
2009-07-09 02:47:17 +00:00
{
2009-12-09 22:38:18 +00:00
// print_a($plug_info);
2010-06-23 10:21:21 +00:00
$pluginDBList [ $plugin_path ][ 'status' ] = 'update' ;
$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' ]))
2010-06-23 10:21:21 +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 )
2010-06-23 10:21:21 +00:00
{ // Update stored addons list
2008-01-20 15:01:19 +00:00
$pluginDBList [ $plugin_path ][ 'plugin_addons' ] = $eplug_addons ;
$pluginDBList [ $plugin_path ][ 'status' ] = 'update' ;
}
2010-06-23 10:21:21 +00:00
if ( $pluginDBList [ $plugin_path ][ 'plugin_installflag' ] == 0 ) // Plugin not installed - make sure $pref not set
2009-12-09 22:38:18 +00:00
{
2010-06-23 10:21:21 +00:00
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
2010-06-23 10:21:21 +00:00
{ // 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' ]))
2010-06-23 10:21:21 +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'
2009-12-09 22:38:18 +00:00
{
2008-12-05 14:18:51 +00:00
if ( $plug_info [ '@attributes' ][ 'name' ])
2012-08-22 02:45:32 +00:00
{
$pName = vartrue ( $plug_info [ '@attributes' ][ 'lang' ]) ? $plug_info [ '@attributes' ][ 'lang' ] : $plug_info [ '@attributes' ][ 'name' ] ;
2010-06-23 10:21:21 +00:00
$_installed = ( $plug_info [ '@attributes' ][ 'installRequired' ] == 'true' || $plug_info [ '@attributes' ][ 'installRequired' ] == 1 ? 0 : 1 );
2012-08-22 02:45:32 +00:00
if ( e107 :: getDb () -> db_Insert ( " plugin " , " 0, ' " . $tp -> toDB ( $pName , true ) . " ', ' " . $tp -> toDB ( $plug_info [ '@attributes' ][ 'version' ], true ) . " ', ' " . $tp -> toDB ( $plugin_path , true ) . " ', { $_installed } , ' { $eplug_addons } ', ' " . $this -> manage_category ( $plug_info [ 'category' ]) . " ', ' " . varset ( $plug_info [ '@attributes' ][ 'releaseUrl' ]) . " ' " ))
2009-10-09 18:58:12 +00:00
{
2012-08-22 02:45:32 +00:00
$mes -> add ( " Added <b> " . $tp -> toHTML ( $pName , false , " defs " ) . " </b> to the plugin table. " , E_MESSAGE_DEBUG );
2010-06-23 10:21:21 +00:00
}
else
{
2012-08-22 02:45:32 +00:00
$mes -> add ( " Failed to add " . $tp -> toHTML ( $pName , false , " defs " ) . " to the plugin table. " , E_MESSAGE_DEBUG );
2010-06-23 10:21:21 +00:00
}
2009-12-09 22:38:18 +00:00
}
2008-01-20 15:01:19 +00:00
}
2007-02-01 22:00:41 +00:00
}
2007-06-05 19:51:36 +00:00
else
2010-06-23 10:21:21 +00:00
{ // May be useful that we ignore what will usually be copies/backups of plugins - but don't normally say anything
// echo "Plugin copied to wrong directory. Is in: {$plugin_path} Should be: {$plug_info['folder']}<br /><br />";
2007-02-01 22:00:41 +00:00
}
2009-07-09 02:47:17 +00:00
2010-06-23 10:21:21 +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' )
2010-06-23 10:21:21 +00:00
{ // In table, not on server - delete it
2008-01-20 15:01:19 +00:00
$sql -> db_Delete ( 'plugin' , " `plugin_id`= { $plug_info [ 'plugin_id' ] } " );
// echo "Deleted: ".$plug_path."<br />";
2010-06-23 10:21:21 +00:00
}
2008-01-20 15:01:19 +00:00
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 )
{
2010-06-23 10:21:21 +00:00
$temp [] = " ` { $p_f } ` = ' { $plug_info [ $p_f ] } ' " ;
2008-01-20 15:01:19 +00:00
}
2010-06-23 10:21:21 +00:00
$sql -> db_Update ( 'plugin' , implode ( " , " , $temp ) . " WHERE `plugin_id`= { $plug_info [ 'plugin_id' ] } " );
2008-01-20 15:01:19 +00:00
// echo "Updated: ".$plug_path."<br />";
2010-06-23 10:21:21 +00:00
}
2006-12-02 04:36:16 +00:00
}
2012-01-06 09:49:08 +00:00
if ( $sp /* && vartrue($p_installed)*/ )
2009-09-03 22:27:32 +00:00
{
2010-06-23 10:21:21 +00:00
e107 :: getConfig ( 'core' ) -> setPref ( 'plug_installed' , $p_installed );
2012-01-06 09:49:08 +00:00
$this -> rebuildUrlConfig ();
2009-09-03 22:27:32 +00:00
e107 :: getConfig ( 'core' ) -> save ();
}
2006-12-02 04:36:16 +00:00
}
2009-12-09 22:38:18 +00:00
2009-09-14 11:27:45 +00:00
function manage_category ( $cat )
{
2010-06-23 10:21:21 +00:00
if ( vartrue ( $cat ) && in_array ( $cat , $this -> accepted_categories ))
2009-09-14 11:27:45 +00:00
{
return $cat ;
}
else
{
return 'misc' ;
}
}
2006-12-02 04:36:16 +00:00
2010-06-23 10:21:21 +00:00
function manage_icons ( $plugin = '' , $function = '' )
2009-07-16 02:55:19 +00:00
{
2010-03-17 23:59:52 +00:00
2010-06-23 10:21:21 +00:00
if ( $plugin == '' )
2010-03-14 02:11:23 +00:00
{
return ;
}
2009-12-09 22:38:18 +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 ();
2010-03-14 02:11:23 +00:00
$med = e107 :: getMedia ();
2010-03-17 23:59:52 +00:00
2010-06-23 10:21:21 +00:00
if ( $function == 'install' || $function == 'upgrade' )
2009-09-28 07:17:52 +00:00
{
2010-06-23 10:21:21 +00:00
$med -> importIcons ( e_PLUGIN . $plugin );
2009-09-28 07:17:52 +00:00
return ;
}
2010-03-17 23:59:52 +00:00
2010-06-23 10:21:21 +00:00
if ( $function == 'uninstall' )
2009-07-16 02:55:19 +00:00
{
2010-06-23 10:21:21 +00:00
if ( vartrue ( $this -> unInstallOpts [ 'delete_ipool' ], FALSE ))
2010-03-17 23:59:52 +00:00
{
2010-06-23 10:21:21 +00:00
$status = ( $med -> removePath ( e_PLUGIN . $plugin , 'icon' )) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2010-03-14 02:11:23 +00:00
$mes -> add ( 'Removing Icons from Media-Manager' , $status );
}
return ;
2010-03-17 23:59:52 +00:00
}
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
/**
2010-06-23 10:21:21 +00:00
* Returns details of a plugin from the plugin table from it ' s ID
*
* @ param int $id
* @ return array plugin info
*/
function getinfo ( $id , $force = false )
2008-01-28 02:49:50 +00:00
{
2009-08-31 02:00:51 +00:00
$sql = e107 :: getDb ();
2008-02-01 14:11:27 +00:00
static $getinfo_results ;
2010-06-23 10:21:21 +00:00
if ( ! is_array ( $getinfo_results ))
{
$getinfo_results = array ();
}
2008-02-01 14:11:27 +00:00
2010-06-23 10:21:21 +00:00
$id = ( int ) $id ;
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
}
2011-11-25 17:35:12 +00:00
public function setUe ()
2008-11-24 00:36:50 +00:00
{
2010-06-23 10:21:21 +00:00
if ( ! isset ( $this -> module [ 'ue' ]))
2008-11-24 00:36:50 +00:00
{
include_once ( e_HANDLER . 'user_extended_class.php' );
$this -> module [ 'ue' ] = new e107_user_extended ;
}
2011-11-25 17:35:12 +00:00
}
/**
* User field name , based on its type
* @ param string $folder plugin folder
* @ param int $type normalized field type
* @ param string $name field name
* @ return string field name
*/
public function ue_field_name ( $folder , $type , $name )
{
if ( $type == EUF_PREFIELD || $type == EUF_CATEGORY )
{
return $name ; // no plugin_plugname_ prefix
}
return 'plugin_' . $folder . '_' . $name ;
}
/**
* Normalize type
* @ param array $attrib parsed from XML user field definitions
* @ return integer type ID
*/
public function ue_field_type ( $attrib )
{
$field_type = $attrib [ 'type' ];
2009-09-21 21:53:38 +00:00
$type = defined ( $field_type ) ? constant ( $field_type ) : $field_type ;
2011-11-25 17:35:12 +00:00
if ( ! is_numeric ( $type ))
{
// normalize further
$this -> setUe ();
$type = $this -> module [ 'ue' ] -> typeArray [ $type ];
}
return $type ;
}
/**
* Type number to type name
* @ param integer $typeId
* @ return string type name
*/
public function ue_field_type_name ( $typeId )
{
if ( is_numeric ( $typeId ))
{
$this -> setUe ();
return array_search ( $typeId , $this -> module [ 'ue' ] -> typeArray );
}
return $typeId ;
}
/**
* Field atributes ( $field_attrib array ) as they have to be defined in plugin . xml :
* name - REQUIRED string
* text - ( string | constant name ) field label
* type - REQUIRED ( constant name ) see EUF_ * constants in e107_user_extended class
* regex - regex validation string
* required - 0 - not requried , don ' t show on signup ; 1 - required , show on signup ; 2 - not required , show on signup
* allow_hide ( 0 | 1 ) - allow user to hide this field on profile page
* read , write , applicable - classes , see e_UC_ * defines
* values - comma separated values ( if required )
* default - default value
* order - ( number )
* parent - ( string ) category name for this field
* system - ( 0 | 1 ) - field wont be shown if it ' s system , NOTE - default value if system is not set is 1 !
*
* @ param string $action - add | remove
* @ param string $field_name normalized field name ( see self :: ue_field_name ())
* @ param array $field_attrib
* @ param string $field_source used for system user fields
* @ return boolean success
*/
function manage_extended_field ( $action , $field_name , $field_attrib , $field_source = '' )
{
$mes = e107 :: getMessage ();
$this -> setUe ();
$type = $this -> ue_field_type ( $field_attrib );
$type_name = $this -> ue_field_type_name ( $type );
$mes -> add ( " Extended Field: " . $action . " : " . $field_name . " : " . $type_name , E_MESSAGE_DEBUG );
// predefined
if ( $type == EUF_PREFIELD )
{
$preList = $this -> module [ 'ue' ] -> parse_extended_xml ( '' ); // passed value currently not used at all, could be file path in the near future
if ( $preList && isset ( $preList [ $field_name ]))
{
$preField = $preList [ $field_name ];
if ( $preField )
{
$field_attrib = array_merge ( $preField , $field_attrib ); // merge
// predefined type - numeric value, constant or as defined in user_extended_class::typeArray
$field_attrib [ 'type' ] = $type = $this -> ue_field_type ( $preField ); // override type
}
else
{
return false ;
}
}
}
// not allowed for categories
elseif ( $type == EUF_CATEGORY )
{
$field_attrib [ 'parent' ] = 0 ;
}
2008-12-05 14:18:51 +00:00
2010-06-23 10:21:21 +00:00
if ( $action == 'add' )
2008-11-24 00:36:50 +00:00
{
2011-11-25 17:35:12 +00:00
// system field
if ( $field_attrib [ 'system' ])
{
return $this -> module [ 'ue' ] -> user_extended_add_system ( $field_name , $type , varset ( $field_attrib [ 'default' ], '' ), $field_source );
}
// new - add non-system extended field
// classes
$field_attrib [ 'read' ] = varset ( $field_attrib [ 'read' ], 'e_UC_MEMBER' );
$field_attrib [ 'write' ] = varset ( $field_attrib [ 'read' ], 'e_UC_MEMBER' );
$field_attrib [ 'applicable' ] = varset ( $field_attrib [ 'applicable' ], 'e_UC_MEMBER' );
// manage parent
if ( vartrue ( $field_attrib [ 'parent' ]))
{
foreach ( $this -> module [ 'ue' ] -> catDefinitions as $key => $value )
{
if ( $value [ 'user_extended_struct_name' ] == $field_attrib [ 'parent' ])
{
$field_attrib [ 'parent' ] = $key ;
break ;
}
}
if ( ! is_numeric ( $field_attrib [ 'parent' ])) $field_attrib [ 'parent' ] = 0 ;
}
else $field_attrib [ 'parent' ] = 0 ;
// manage required (0, 1, 2)
if ( ! isset ( $field_attrib [ 'required' ]))
{
$field_attrib [ 'required' ] = 0 ;
}
// manage params
$field_attrib [ 'parms' ] = '' ;
// validation and parms
$include = varset ( $field_attrib [ 'include_text' ]);
$regex = varset ( $field_attrib [ 'regex' ]);
$hide = vartrue ( $field_attrib [ 'allow_hide' ]) ? 1 : 0 ;
$failmsg = '' ;
2012-01-11 16:12:01 +00:00
if ( $regex || $hide )
2011-11-25 17:35:12 +00:00
{
// failmsg only when required
if ( $field_attrib [ 'required' ] == 1 || $regex )
$failmsg = vartrue ( $field_attrib [ 'error' ]) ? $field_attrib [ 'error' ] : 'LAN_UE_FAIL_' . strtoupper ( $field_name );
$field_attrib [ 'parms' ] = $include . " ^,^ " . $regex . " ^,^ " . $failmsg . '^,^' . $hide ;
}
//var_dump($field_attrib, $field_name, $type);
$status = $this -> module [ 'ue' ] -> user_extended_add (
$field_name ,
varset ( $field_attrib [ 'text' ], " LAN_UE_ " . strtoupper ( $field_name )),
$type ,
$field_attrib [ 'parms' ],
varset ( $field_attrib [ 'values' ], '' ),
varset ( $field_attrib [ 'default' ], '' ),
$field_attrib [ 'required' ],
defset ( $field_attrib [ 'read' ], e_UC_MEMBER ),
defset ( $field_attrib [ 'write' ], e_UC_MEMBER ),
defset ( $field_attrib [ 'applicable' ], e_UC_MEMBER ),
varset ( $field_attrib [ 'order' ], '' ),
$field_attrib [ 'parent' ]
);
// db fields handling
if ( $status && $type == EUF_DB_FIELD )
{
// handle DB, use original non-modified name value
$status = ! $this -> manage_extended_field_sql ( 'add' , $field_attrib [ 'name' ]); // reverse logic - sql method do a error check
}
// refresh categories - sadly the best way so far... need improvement (inside ue class)
if ( $status && $type == EUF_CATEGORY )
{
$cats = $this -> module [ 'ue' ] -> user_extended_get_categories ( false );
foreach ( $cats as $cat )
{
$this -> module [ 'ue' ] -> catDefinitions [ $cat [ 'user_extended_struct_id' ]] = $cat ;
}
}
return $status ;
2008-11-24 00:36:50 +00:00
}
2008-12-05 14:18:51 +00:00
2008-11-24 00:36:50 +00:00
if ( $action == 'remove' )
{
2011-11-25 17:35:12 +00:00
//var_dump($field_attrib, $field_name, $type);
$status = $this -> module [ 'ue' ] -> user_extended_remove ( $field_name , $field_name );
if ( $status && $type == EUF_DB_FIELD )
{
$status = $this -> manage_extended_field_sql ( 'remove' , $field_attrib [ 'name' ]);
}
return $status ;
}
return false ;
}
function manage_extended_field_sql ( $action , $field_name )
{
$f = e_ADMIN . 'sql/extended_' . preg_replace ( '/[^\w]/' , '' , $field_name ) . '.php' ; // quick security, always good idea
if ( ! is_readable ( $f )) return false ;
// TODO - taken from user_extended Administration, need to be refined :/
// FIXME - use sql parse handler
$error = FALSE ;
$count = 0 ;
if ( $action == 'add' )
{
$sql_data = file_get_contents ( $f );
$search [ 0 ] = " CREATE TABLE " ; $replace [ 0 ] = " CREATE TABLE " . MPREFIX ;
$search [ 1 ] = " INSERT INTO " ; $replace [ 1 ] = " INSERT INTO " . MPREFIX ;
preg_match_all ( " /create(.*?)myisam;/si " , $sql_data , $creation );
foreach ( $creation [ 0 ] as $tab )
{
$query = str_replace ( $search , $replace , $tab );
if ( ! mysql_query ( $query ))
{
$error = TRUE ;
}
$count ++ ;
}
preg_match_all ( " /insert(.*?);/si " , $sql_data , $inserts );
foreach ( $inserts [ 0 ] as $ins )
{
$qry = str_replace ( $search , $replace , $ins );
if ( ! mysql_query ( $qry ))
{
$error = TRUE ;
}
$count ++ ;
}
if ( ! $count ) $error = TRUE ;
return $error ;
}
//remove
if ( $action == 'remove' )
{
// executed only if the sql file exists!
return mysql_query ( " DROP TABLE " . MPREFIX . " user_extended_ " . $field_name ) ? true : false ;
2008-11-24 00:36:50 +00:00
}
}
2008-08-09 16:49:58 +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 ();
2010-06-23 10:21:21 +00:00
$sql = e107 :: getDb ();
2009-11-07 02:28:59 +00:00
$mes = e107 :: getMessage ();
$mes -> add ( " Userclass: " . $action . " : " . $class_name . " : " . $class_description , E_MESSAGE_DEBUG );
2009-12-09 22:38:18 +00:00
2010-03-17 23:59:52 +00:00
if ( ! $e107 -> user_class -> isAdmin ())
2008-12-29 22:30:16 +00:00
{
2010-06-23 10:21:21 +00:00
$e107 -> user_class = new user_class_admin ; // We need the extra methods of the admin extension
}
2008-12-29 22:30:16 +00:00
$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 )
2010-06-23 10:21:21 +00:00
{ // 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
{
2012-11-07 20:27:41 +00:00
return NULL ;
2006-12-02 04:36:16 +00:00
}
}
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 );
2010-06-23 10:21:21 +00:00
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
}
}
}
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-12-09 22:38:18 +00:00
2009-09-03 22:27:32 +00:00
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +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 ;
}
2010-06-23 10:21:21 +00:00
$link_url = $tp -> toDB ( $link_url , true );
$link_name = $tp -> toDB ( $link_name , true );
$path = str_replace ( " ../ " , " " , $link_url ); // This should clean up 'non-standard' links
$path = $tp -> createConstants ( $path ); // Add in standard {e_XXXX} directory constants if we can
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
{
2010-06-23 10:21:21 +00:00
$linkData = array (
'link_name' => $link_name ,
'link_url' => $path ,
'link_description' => '' ,
'link_button' => '' ,
'link_category' => '1' ,
'link_order' => $link_t + 1 ,
'link_parent' => '0' ,
'link_open' => '0' ,
'link_class' => $link_class ,
'link_function' => ''
2009-12-11 21:17:09 +00:00
);
2010-06-23 10:21:21 +00:00
return $sql -> db_Insert ( 'links' , $linkData ); // TODO: Add the _FIELD_DEFS array
2008-01-20 15:01:19 +00:00
}
else
2007-09-28 20:00:37 +00:00
{
2012-11-07 20:27:41 +00:00
return ;
2006-12-02 04:36:16 +00:00
}
}
2008-01-20 15:01:19 +00:00
if ( $action == 'remove' )
2010-06-23 10:21:21 +00:00
{ // Look up by URL if we can - should be more reliable. Otherwise try looking up by name (as previously)
if (( $path && $sql -> db_Select ( 'links' , 'link_id,link_order' , " link_url = ' { $path } ' " )) || $sql -> db_Select ( 'links' , 'link_id,link_order' , " link_name = ' { $link_name } ' " ))
2008-01-20 15:01:19 +00:00
{
2010-06-23 10:21:21 +00:00
$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' ] } " );
2008-01-20 15:01:19 +00:00
}
2006-12-02 04:36:16 +00:00
}
}
2009-12-09 22:38: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
{
2010-06-23 10:21:21 +00:00
global $pref ;
if ( ! is_array ( $var ))
return ;
if (( $prefType == 'arrayPref' ) && ( $path == '' ))
return ;
foreach ( $var as $k => $v )
2008-01-20 15:01:19 +00:00
{
2010-06-23 10:21:21 +00:00
if ( $unEscape )
2008-08-09 16:49:58 +00:00
{
2010-06-23 10:21:21 +00:00
$v = str_replace ( array ( '\{' , '\}' ), array ( '{' , '}' ), $v );
2008-08-09 16:49:58 +00:00
}
2010-06-23 10:21:21 +00:00
switch ( $prefType )
2008-08-09 16:49:58 +00:00
{
2010-06-23 10:21:21 +00:00
case 'pref' :
switch ( $action )
{
case 'add' :
$pref [ $k ] = $v ;
break ;
case 'update' :
case 'refresh' :
// Only update if $pref doesn't exist
if ( ! isset ( $pref [ $k ]))
$pref [ $k ] = $v ;
break ;
case 'remove' :
if ( is_numeric ( $k ))
{ // Sometimes arrays specified with value being the name of the key to delete
unset ( $pref [ $var [ $k ]]);
}
else
{ // This is how the array should be specified - key is the name of the pref
unset ( $pref [ $k ]);
}
break ;
}
break ;
case 'listPref' :
$tmp = array ();
if ( isset ( $pref [ $k ]))
$tmp = explode ( ',' , $pref [ $k ]);
switch ( $action )
{
case 'add' :
case 'update' :
case 'refresh' :
if ( ! in_array ( $v , $tmp ))
$tmp [] = $v ;
break ;
case 'remove' :
if (( $tkey = array_search ( $v , $tmp )) !== FALSE )
unset ( $tmp [ $tkey ]);
break ;
}
$pref [ $k ] = implode ( ',' , $tmp ); // Leaves an empty element if no values - probably acceptable or even preferable
break ;
case 'arrayPref' :
switch ( $action )
{
case 'add' :
$pref [ $k ][ $path ] = $v ;
break ;
case 'update' :
case 'refresh' :
if ( ! isset ( $pref [ $k ][ $path ]))
$pref [ $k ][ $path ] = $v ;
break ;
case 'remove' :
if ( isset ( $pref [ $k ][ $path ]))
unset ( $pref [ $k ][ $path ]); // Leaves an empty element if no values - probably acceptable or even preferable
break ;
}
break ;
2008-08-09 16:49:58 +00:00
}
2006-12-02 04:36:16 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
e107 :: getConfig ( 'core' ) -> setPref ( $pref ) -> save ();
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
// e107::getConfig()->loadData($pref, false)->save(false, true);
2006-12-02 04:36:16 +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 ();
2009-12-09 22:38:18 +00:00
2008-02-02 22:04:18 +00:00
$tmp = array ();
2010-06-23 10:21:21 +00:00
if ( $action == 'remove' )
2008-01-20 15:01:19 +00:00
{
2010-06-23 10:21:21 +00:00
foreach ( $comment_id as $com )
2008-01-20 15:01:19 +00:00
{
2010-06-23 10:21:21 +00:00
$tmp [] = " comment_type=' " . $tp -> toDB ( $com , true ) . " ' " ;
2006-12-02 04:36:16 +00:00
}
2010-06-23 10:21:21 +00:00
$qry = implode ( " OR " , $tmp );
// 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 )
{
2010-06-23 10:21:21 +00:00
$sql = e107 :: getDB ();
if ( ! is_array ( $var ))
return FALSE ; // Return if nothing to do
$error = false ;
$error_data = array ();
switch ( $action )
{
case 'add' :
foreach ( $var as $tab )
2008-01-20 15:01:19 +00:00
{
2010-06-23 10:21:21 +00:00
if ( false === $sql -> db_Query ( $tab ))
2008-01-20 15:01:19 +00:00
{
2010-06-23 10:21:21 +00:00
$error = true ;
$error_data [] = $tab ;
2006-12-02 04:36:16 +00:00
}
}
2010-06-23 10:21:21 +00:00
break ;
case 'upgrade' :
foreach ( $var as $tab )
{
if ( false === $sql -> db_Query_all ( $tab ))
{
$error = true ;
$error_data [] = $tab ;
}
}
break ;
case 'remove' :
foreach ( $var as $tab )
2008-01-20 15:01:19 +00:00
{
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 ))
{
2010-06-23 10:21:21 +00:00
$error = true ;
$error_data [] = $tab ;
2006-12-02 04:36:16 +00:00
}
}
2010-06-23 10:21:21 +00:00
break ;
}
// doesn't exit the loop now, returns true on success
// or error queries (string)
return ( ! $error ? true : ( ! empty ( $$error_data ) ? implode ( '<br />' , $error_data ) : false ));
2006-12-02 04:36:16 +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 = '' )
2010-06-23 10:21:21 +00:00
{ // These prefs are 'cumulative' - several plugins may contribute an array element
// global $pref;
/*
if ( $prefname == 'plug_sc' || $prefname == 'plug_bb' )
{ // Special cases - shortcodes and bbcodes - each plugin may contribute several elements
foreach ( $varArray as $code )
{
$prefvals [] = " $code : $plugin_folder " ;
}
}
else
{
*/
$prefvals [] = $varArray ;
// $prefvals[] = $plugin_folder;
// }
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
{
2010-06-23 10:21:21 +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 );
2010-06-23 10:21:21 +00:00
if ( substr ( $pref [ $prefname ], 0 , 1 ) == " , " )
2006-12-02 04:36:16 +00:00
{
2008-01-20 15:01:19 +00:00
$pref [ $prefname ] = substr ( $pref [ $prefname ], 1 );
2006-12-02 04:36:16 +00:00
}
2009-12-09 22:38:18 +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-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-12-09 22:38:18 +00:00
2009-09-14 11:27:45 +00:00
$search_prefs = e107 :: getConfig ( 'search' ) -> getPref ();
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +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
}
2010-06-23 10:21:21 +00:00
else
if ( $action == 'remove' )
2008-01-20 15:01:19 +00:00
{
2010-06-23 10:21:21 +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
2010-06-23 10:21:21 +00:00
if ( $action == 'upgrade' )
{
if ( isset ( $search_prefs [ 'plug_handlers' ][ $eplug_folder ]))
{
$uninstall_default = $default ? FALSE : TRUE ;
}
else
{
$install_default = $default ? TRUE : FALSE ;
}
if ( isset ( $search_prefs [ 'comments_handlers' ][ $eplug_folder ]))
{
$uninstall_comments = $comments ? FALSE : TRUE ;
}
else
{
$install_comments = $comments ? TRUE : FALSE ;
}
}
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
}
2010-06-23 10:21:21 +00:00
else
if ( vartrue ( $uninstall_default ))
{
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
}
2010-06-23 10:21:21 +00:00
else
if ( vartrue ( $uninstall_comments ))
{
unset ( $search_prefs [ 'comments_handlers' ][ $eplug_folder ]);
}
2009-12-09 22:38:18 +00:00
2009-09-06 20:04:04 +00:00
e107 :: getConfig ( 'search' ) -> setPref ( $search_prefs ) -> save ();
2009-12-09 22:38:18 +00:00
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 ();
2010-06-23 10:21:21 +00:00
// $notify_prefs = $sysprefs -> get('notify_prefs');
// $notify_prefs = $eArrayStorage -> ReadArray($notify_prefs);
2009-12-09 22:38:18 +00:00
2009-09-03 22:27:32 +00:00
$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
}
2010-06-23 10:21:21 +00:00
else
if ( $action == 'remove' )
2008-01-20 15:01:19 +00:00
{
2010-06-23 10:21:21 +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
2010-06-23 10:21:21 +00:00
if ( $action == 'upgrade' )
{
if ( $notify_prefs -> isData ( 'plugins/' . $eplug_folder ))
{
$uninstall_notify = $e_notify ? FALSE : TRUE ;
}
else
{
$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' => '');
2010-06-23 10:21:21 +00:00
}
2008-01-20 15:01:19 +00:00
}
2010-06-23 10:21:21 +00:00
else
if ( vartrue ( $uninstall_notify ))
2008-01-20 15:01:19 +00:00
{
2010-06-23 10:21:21 +00:00
$notify_prefs -> removePref ( 'plugins/' . $eplug_folder );
//unset($notify_prefs['plugins'][$eplug_folder]);
require_once ( e_PLUGIN . $eplug_folder . '/e_notify.php' );
foreach ( $config_events as $event_id => $event_text )
{
$notify_prefs -> removePref ( 'event/' . $event_id );
//unset($notify_prefs['event'][$event_id]);
}
2006-12-02 04:36:16 +00:00
}
2009-09-15 16:10:32 +00:00
//$s_prefs = $tp -> toDB($notify_prefs);
2009-12-09 22:38:18 +00:00
//$s_prefs = e107::getArrayStorage()->WriteArray($s_prefs);
2009-09-15 16:10:32 +00:00
//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
}
2012-01-06 09:49:08 +00:00
/**
* Rebuild URL configuration values
* Note - new core system pref values will be set , but not saved
* e107 :: getConfig () -> save () is required outside after execution of this method
* @ return void
*/
public function rebuildUrlConfig ()
{
$modules = eRouter :: adminReadModules (); // get all available locations, non installed plugins will be ignored
$config = eRouter :: adminBuildConfig ( e107 :: getPref ( 'url_config' ), $modules ); // merge with current config
$locations = eRouter :: adminBuildLocations ( $modules ); // rebuild locations pref
$aliases = eRouter :: adminSyncAliases ( e107 :: getPref ( 'url_aliases' ), $config ); // rebuild aliases
// set new values, changes should be saved outside this methods
e107 :: getConfig ()
-> set ( 'url_aliases' , $aliases )
-> set ( 'url_config' , $config )
-> set ( 'url_modules' , $modules )
-> set ( 'url_locations' , $locations );
eRouter :: clearCache ();
}
2010-06-23 10:21:21 +00:00
function displayArray ( & $array , $msg = '' )
2008-12-13 18:43:46 +00:00
{
$txt = ( $msg ? $msg . '<br />' : '' );
2010-06-23 10:21:21 +00:00
foreach ( $array as $_k => $_v )
2008-12-13 18:43:46 +00:00
{
$txt .= " { $_k } -> { $_v } <br /> " ;
}
2010-06-23 10:21:21 +00:00
$txt .= '<br />' ;
2008-12-13 18:43:46 +00:00
return $txt ;
}
2009-12-09 22:38:18 +00:00
2009-10-30 09:13:37 +00:00
/**
* Install routine for XML file
* @ param object $id ( the number of the plugin in the DB )
* @ param object $function install | upgrade | uninstall | refresh ( adds things that are missing , but doesn ' t change any existing settings )
* @ param object $options [ optional ] an array of possible options - ATM used only for uninstall :
* 'delete_userclasses' - to delete userclasses created
* 'delete_tables' - to delete DB tables
* 'delete_xfields' - to delete extended fields
* 'delete_ipool' - to delete icon pool entry
2009-12-09 22:38:18 +00:00
* + any defined in < pluginname > _setup . php in the uninstall_options () method .
2009-12-13 21:52:32 +00:00
* @ return TBD
2009-10-30 09:13:37 +00:00
*/
2010-06-23 10:21:21 +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 ;
2009-12-09 22:38:18 +00:00
2009-09-03 22:27:32 +00:00
$sql = e107 :: getDb ();
2012-11-06 11:07:47 +00:00
$mes = e107 :: getMessage ();
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
$error = array (); // Array of error messages
$canContinue = TRUE ; // Clear flag if must abort part way through
2008-08-09 16:49:58 +00:00
2010-06-23 10:21:21 +00:00
$id = ( int ) $id ;
$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-12-09 22:38:18 +00:00
2009-09-23 23:18:18 +00:00
$this -> plugFolder = $plug [ 'plugin_path' ];
$this -> unInstallOpts = $options ;
2009-12-09 22:38:18 +00:00
2008-02-01 14:11:27 +00:00
$addons = explode ( ',' , $plug [ 'plugin_addons' ]);
$sql_list = array ();
2010-06-23 10:21:21 +00:00
foreach ( $addons as $addon )
2008-02-01 14:11:27 +00:00
{
2010-06-23 10:21:21 +00:00
if ( substr ( $addon , - 4 ) == '_sql' )
2008-02-01 14:11:27 +00:00
{
$sql_list [] = $addon . '.php' ;
}
}
2008-01-28 02:49:50 +00:00
2010-06-23 10:21:21 +00:00
if ( ! file_exists ( $path . 'plugin.xml' ) || $function == '' )
2008-01-27 01:34:59 +00:00
{
2008-12-30 09:44:23 +00:00
$error [] = EPL_ADLAN_77 ;
$canContinue = FALSE ;
2008-01-27 01:34:59 +00:00
}
2010-06-23 10:21:21 +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
}
2012-11-06 11:07:47 +00:00
/*
2012-11-07 20:27:41 +00:00
* NEW upgrade XML - Not required .
2012-11-06 11:07:47 +00:00
* higher priority -> from - to version upgrade XML - e . g . upgrade / upgrade_1 . 0 - 1.1 . xml ( v1 . 0 to v1 . 1 only )
* when above not present -> generic version upgrade XML - e . g . upgrade / upgrade_1 . 1. xml ( all prior versions to v1 . 1 )
* last checked -> generic upgrade file - plugName / plugin_upgrade . xml ( all version )
* All upgrade XMLs are optional BUT recommended ( at least plugin_upgrade . xml )
* The reason is plugin prefs will be reset to default values , user classes will be duplicated etx if plugin . xml is used
* To avoid this , put upgrade XML with basic data nodes ( version , description , category , author etc )
*/
2012-11-07 20:27:41 +00:00
/*
2012-11-06 11:07:47 +00:00
if ( $canContinue && $function === 'upgrade' )
{
$found = false ;
$search = array (
'upgrade/upgrade_' . $this -> current_plug [ 'plugin_version' ] . '-' . $this -> plug_vars [ '@attributes' ][ 'version' ] . '.xml' ,
'upgrade/upgrade_' . $this -> plug_vars [ '@attributes' ][ 'version' ] . '.xml' ,
'plugin_upgrade.xml' ,
);
foreach ( $search as $case )
{
if ( file_exists ( $path . $case ) && is_readable ( $path . $case ) && $this -> parse_plugin_xml ( $plug [ 'plugin_path' ], $case ))
{
// TODO - lan
$mes -> addSuccess ( 'Upgrade using ' . $case );
$plug_vars = $this -> plug_vars ;
break ;
}
}
}
2012-11-07 20:27:41 +00:00
* */
2012-11-06 11:07:47 +00:00
// END upgrade XML
2008-08-09 16:49:58 +00:00
2010-06-23 10:21:21 +00:00
if ( varset ( $plug_vars [ 'languageFiles' ]))
2009-10-20 03:49:28 +00:00
{
2010-06-23 10:21:21 +00:00
$this -> XmlLanguageFiles ( $function , $plug_vars [ 'languageFiles' ], 'pre' ); // First of all, see if there's a language file specific to install
}
2009-10-20 03:49:28 +00:00
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-12-09 22:38:18 +00:00
{
2008-08-17 12:02:14 +00:00
$ret = $this -> execute_function ( $path , $function , 'pre' );
2010-06-23 10:21:21 +00:00
if ( ! is_bool ( $ret ))
$txt .= $ret ;
2008-08-12 20:26:53 +00:00
}
2012-11-06 11:07:47 +00:00
/*
2012-11-07 03:40:07 +00:00
* XXX - sql upgrade draft - we need better 'parse sql' support , INSERTs , ALTERs , etc
* NEW upgrade SQL - ALREADY EXISTS - use upgrade_pre ( $var ) OR upgrade_post () methods in the { plugin } _setup . php file .
2012-11-06 11:07:47 +00:00
* All upgrade sql scripts are optional , if not found system is using the auto detection mode ( diff against main sql file )
2012-11-07 03:40:07 +00:00
* ONLY table CONTENT should be changed with this .
2012-11-06 11:07:47 +00:00
*/
2012-11-07 03:40:07 +00:00
/*
2012-11-06 11:07:47 +00:00
$doSql = true ;
if ( $canContinue && $function === 'upgrade' )
{
$search = array (
'upgrade/sql_' . $this -> current_plug [ 'plugin_version' ] . '-' . $this -> plug_vars [ '@attributes' ][ 'version' ] . '.php' ,
'upgrade/sql_' . $this -> plug_vars [ '@attributes' ][ 'version' ] . '.php' ,
);
foreach ( $search as $case )
{
if ( file_exists ( $path . $case ) && is_readable ( $path . $case ) && $this -> parse_plugin_xml ( $plug [ 'plugin_path' ], $case ))
{
// TODO - lan
$mes -> addSuccess ( '(draft) Upgrade using ' . $case );
$doSql = false ;
break ;
}
}
}
2012-11-07 03:40:07 +00:00
*/
2008-02-02 00:48:58 +00:00
2012-11-06 11:07:47 +00:00
if ( $canContinue && $doSql && count ( $sql_list )) // TODO - move to it's own function.
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
{ // Handle tables
2009-12-09 22:38: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 ;
2010-06-23 10:21:21 +00:00
foreach ( $sql_list as $sqlFile )
2008-01-27 01:34:59 +00:00
{
2010-06-23 10:21:21 +00:00
$tableList = $dbHandler -> get_table_def ( '' , $path . $sqlFile );
2008-08-12 20:26:53 +00:00
if ( ! is_array ( $tableList ))
2008-01-27 01:34:59 +00:00
{
2010-06-23 10:21:21 +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-12-09 22:38:18 +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)
2010-06-23 10:21:21 +00:00
switch ( $function )
2008-01-27 01:34:59 +00:00
{
2010-06-23 10:21:21 +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 ] } ... " ;
2010-06-23 10:21:21 +00:00
$status = $this -> manage_tables ( 'add' , array ( $sqlTable )) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ; // Pass the statement to create the table
$mes -> add ( $txt , $status );
2008-08-12 20:26:53 +00:00
break ;
2010-06-23 10:21:21 +00:00
case 'upgrade' :
$tmp = $dbHandler -> update_table_structure ( $ct , FALSE , TRUE , $pref [ 'multilanguage' ]);
2008-08-12 20:26:53 +00:00
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 ;
2010-06-23 10:21:21 +00:00
case 'refresh' : // Leave things alone
2008-12-10 22:39:43 +00:00
break ;
2010-06-23 10:21:21 +00:00
case 'uninstall' :
2009-10-30 09:13:37 +00:00
if ( vartrue ( $options [ 'delete_tables' ], FALSE ))
2008-12-30 19:01:17 +00:00
{
2009-09-28 07:17:52 +00:00
$txt = " Removing table { $ct [ 1 ] } <br /> " ;
2010-06-23 10:21:21 +00:00
$status = $this -> manage_tables ( 'remove' , array ( $ct [ 1 ])) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ; // Delete the table
$mes -> add ( $txt , $status );
2008-12-30 19:01:17 +00:00
}
else
2009-12-09 22:38:18 +00:00
{
2010-06-23 10:21:21 +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
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( varset ( $plug_vars [ 'adminLinks' ]))
2009-10-20 03:49:28 +00:00
{
2010-06-23 10:21:21 +00:00
$this -> XmlAdminLinks ( $function , $plug_vars [ 'adminLinks' ]);
2009-10-20 03:49:28 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( varset ( $plug_vars [ 'siteLinks' ]))
2009-09-23 23:18:18 +00:00
{
2010-06-23 10:21:21 +00:00
$this -> XmlSiteLinks ( $function , $plug_vars [ 'siteLinks' ]);
2009-09-23 23:18:18 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( varset ( $plug_vars [ 'mainPrefs' ])) //Core pref items <mainPrefs>
2009-09-23 23:18:18 +00:00
{
2010-06-23 10:21:21 +00:00
$this -> XmlPrefs ( 'core' , $function , $plug_vars [ 'mainPrefs' ]);
2009-12-09 22:38:18 +00:00
}
2010-06-23 10:21:21 +00:00
if ( varset ( $plug_vars [ 'pluginPrefs' ])) //Plugin pref items <pluginPrefs>
2009-09-23 23:18:18 +00:00
{
2010-06-23 10:21:21 +00:00
$this -> XmlPrefs ( $plug [ 'plugin_path' ], $function , $plug_vars [ 'pluginPrefs' ]);
2009-09-23 23:18:18 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( varset ( $plug_vars [ 'userClasses' ]))
2009-09-23 23:18:18 +00:00
{
2010-06-23 10:21:21 +00:00
$this -> XmlUserClasses ( $function , $plug_vars [ 'userClasses' ]);
2009-09-23 23:18:18 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( varset ( $plug_vars [ 'extendedFields' ]))
2009-09-23 23:18:18 +00:00
{
2010-06-23 10:21:21 +00:00
$this -> XmlExtendedFields ( $function , $plug_vars [ 'extendedFields' ]);
2009-09-23 23:18:18 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( varset ( $plug_vars [ 'languageFiles' ]))
2009-09-23 23:18:18 +00:00
{
2010-06-23 10:21:21 +00:00
$this -> XmlLanguageFiles ( $function , $plug_vars [ 'languageFiles' ]);
2009-09-23 23:18:18 +00:00
}
2012-07-18 06:34:26 +00:00
if ( varset ( $plug_vars [ 'bbcodes' ]))
{
$this -> XmlBBcodes ( $function , $plug_vars );
}
2012-08-19 02:33:43 +00:00
if ( varset ( $plug_vars [ 'mediaCategories' ]))
{
$this -> XmlMediaCategories ( $function , $plug_vars );
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
$this -> manage_icons ( $this -> plugFolder , $function );
2009-12-09 22:38:18 +00:00
//FIXME
2009-09-23 23:18:18 +00:00
//If any commentIDs are configured, we need to remove all comments on uninstall
2010-06-23 10:21:21 +00:00
if ( $function == 'uninstall' && isset ( $plug_vars [ 'commentID' ]))
2009-09-23 23:18:18 +00:00
{
$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-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
$p_installed = e107 :: getPref ( 'plug_installed' , array ()); // load preference;
2009-09-23 23:18:18 +00:00
2010-06-23 10:21:21 +00:00
if ( $function == 'install' || $function == 'upgrade' )
2009-12-09 22:38:18 +00:00
{
2009-09-23 23:18:18 +00:00
$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' ];
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
e107 :: getConfig ( 'core' ) -> setPref ( 'plug_installed' , $p_installed );
2012-01-06 09:49:08 +00:00
//e107::getConfig('core')->save(); - save triggered below
2009-09-23 23:18:18 +00:00
}
2010-06-23 10:21:21 +00:00
if ( $function == 'uninstall' )
2009-09-23 23:18:18 +00:00
{
$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' ]]);
2010-06-23 10:21:21 +00:00
e107 :: getConfig ( 'core' ) -> setPref ( 'plug_installed' , $p_installed );
2009-12-09 22:38:18 +00:00
2009-09-23 23:18:18 +00:00
}
2012-01-06 09:49:08 +00:00
$this -> rebuildUrlConfig ();
2009-12-09 22:38:18 +00:00
e107 :: getConfig ( 'core' ) -> save ();
2009-09-23 23:18:18 +00:00
2010-06-23 10:21:21 +00:00
/* if ( $function == 'install' )
{
if ( isset ( $plug_vars [ 'management' ][ 'installDone' ][ 0 ]))
{
$mes -> add ( $plug_vars [ 'management' ][ 'installDone' ][ 0 ], E_MESSAGE_SUCCESS );
}
} */
if ( ! $this -> execute_function ( $path , $function , 'post' )) // Call any custom post functions defined in <plugin>_setup.php or the deprecated <management> section
2009-12-09 22:38:18 +00:00
2009-10-20 03:49:28 +00:00
{
2010-06-23 10:21:21 +00:00
if ( $function == 'install' )
2009-10-20 03:49:28 +00:00
{
2009-12-09 22:38:18 +00:00
$text = " Installation Complete. " ;
2009-10-20 03:49:28 +00:00
2010-06-23 10:21:21 +00:00
if ( $this -> plugConfigFile )
2009-10-20 03:49:28 +00:00
{
2009-12-09 22:38:18 +00:00
$text .= " <a href=' " . $this -> plugConfigFile . " '>[ " . LAN_CONFIGURE . " ]</a> " ;
2009-10-20 03:49:28 +00:00
}
2009-12-09 22:38:18 +00:00
2009-10-23 09:08:15 +00:00
$mes -> add ( $text , E_MESSAGE_SUCCESS );
2009-12-09 22:38:18 +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-12-09 22:38:18 +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
{
2010-06-23 10:21:21 +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 /> " ;
}
2009-09-23 23:18:18 +00:00
}
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( count ( $error ))
2009-09-23 23:18:18 +00:00
{
2010-06-23 10:21:21 +00:00
$text = '<b>' . LAN_INSTALL_FAIL . '</b><br />' . implode ( '<br />' , $error );
2009-12-09 22:38:18 +00:00
$mes -> add ( $text , E_MESSAGE_ERROR );
2009-09-23 23:18:18 +00:00
}
2009-12-09 22:38:18 +00:00
2009-09-23 23:18:18 +00:00
return $canContinue ;
}
2009-12-09 22:38:18 +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
2009-12-13 21:52:32 +00:00
* @ return none
2009-09-23 23:18:18 +00:00
*/
2010-06-23 10:21:21 +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
2010-06-23 10:21:21 +00:00
foreach ( $tag [ 'file' ] as $val )
2009-12-09 22:38:18 +00:00
{
2009-10-20 03:49:28 +00:00
$att = $val [ '@attributes' ];
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( $when == 'pre' ) // just check for install language file BEFORE install.
2009-10-20 03:49:28 +00:00
{
2010-06-23 10:21:21 +00:00
if ( $att [ 'type' ] == 'install' )
2009-10-20 03:49:28 +00:00
{
2010-06-23 10:21:21 +00:00
$file = str_replace ( '--LAN--' , e_LANGUAGE , $att [ 'path' ]);
2009-10-20 03:49:28 +00:00
$fullpath_file = e_PLUGIN . $this -> plugFolder . " / " . $file ;
include_lan ( $fullpath_file );
return ;
}
}
2010-06-23 10:21:21 +00:00
elseif ( $att [ 'type' ] == 'log' )
2009-10-20 03:49:28 +00:00
{
switch ( $function )
{
2010-06-23 10:21:21 +00:00
case 'install' :
case 'upgrade' :
case 'refresh' :
$core -> setPref ( 'logLanguageFile/' . $this -> plugFolder , $att [ 'path' ]);
break ;
case 'uninstall' :
2009-10-20 03:49:28 +00:00
$core -> removePref ( 'logLanguageFile/' . $this -> plugFolder );
2010-06-23 10:21:21 +00:00
break ;
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 < siteLinks >
* @ param string $function install | upgrade | refresh | uninstall
* @ param array $array
2009-12-13 21:52:32 +00:00
* @ return none
2009-09-23 23:18:18 +00:00
*/
2010-06-23 10:21:21 +00:00
function XmlSiteLinks ( $function , $array )
2009-09-23 23:18:18 +00:00
{
2009-10-23 09:08:15 +00:00
$mes = e107 :: getMessage ();
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
foreach ( $array [ 'link' ] as $link )
2009-09-23 23:18:18 +00:00
{
2010-06-23 10:21:21 +00:00
$attrib = $link [ '@attributes' ];
$linkName = ( defset ( $link [ '@value' ])) ? constant ( $link [ '@value' ]) : $link [ '@value' ];
$remove = ( varset ( $attrib [ 'deprecate' ]) == 'true' ) ? TRUE : FALSE ;
$url = $attrib [ 'url' ];
$perm = ( isset ( $attrib [ 'perm' ]) ? $attrib [ 'perm' ] : 0 );
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
switch ( $function )
{
case 'upgrade' :
case 'install' :
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( ! $remove ) // Add any non-deprecated link
{
2012-11-07 20:27:41 +00:00
$result = $this -> manage_link ( 'add' , $url , $linkName , $perm );
if ( $result !== NULL )
{
$status = ( $result ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
$mes -> add ( " Adding Link: { $linkName } with url [ { $url } ] and perm { $perm } " , $status ); //TODO LAN
}
2010-06-23 10:21:21 +00:00
}
2008-12-10 22:39:43 +00:00
2010-06-23 10:21:21 +00:00
if ( $function == 'upgrade' && $remove ) //remove inactive links on upgrade
{
2009-09-23 23:18:18 +00:00
$status = ( $this -> manage_link ( 'remove' , $url , $linkName )) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2009-12-09 22:38:18 +00:00
$mes -> add ( " Removing Link: { $linkName } with url [ { $url } ] " , $status );
2010-06-23 10:21:21 +00:00
}
break ;
case 'refresh' : // Probably best to leave well alone
break ;
case 'uninstall' : //remove all links
$status = ( $this -> manage_link ( 'remove' , $url , $linkName )) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
$mes -> add ( " Removing Link: { $linkName } with url [ { $url } ] " , $status );
break ;
2009-12-09 22:38:18 +00:00
}
2010-06-23 10:21:21 +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
/**
2009-12-09 22:38:18 +00:00
* Process XML Tag < adminLinks >
2009-12-13 21:52:32 +00:00
* @ return none
2009-09-23 23:18:18 +00:00
*/
2010-06-23 10:21:21 +00:00
function XmlAdminLinks ( $function , $tag )
2009-09-23 23:18:18 +00:00
{
2010-06-23 10:21:21 +00:00
foreach ( $tag [ 'link' ] as $link )
2009-10-20 03:49:28 +00:00
{
$attrib = $link [ '@attributes' ];
$linkName = ( defset ( $link [ '@value' ])) ? constant ( $link [ '@value' ]) : $link [ '@value' ];
$url = e_PLUGIN_ABS . $this -> plugFolder . " / " . $attrib [ 'url' ];
2012-01-11 14:54:47 +00:00
if ( isset ( $attrib [ 'primary' ]) && $attrib [ 'primary' ] == 'true' )
2009-10-20 03:49:28 +00:00
{
2009-12-09 22:38:18 +00:00
$this -> plugConfigFile = $url ;
2009-10-20 03:49:28 +00:00
}
}
2009-09-23 23:18:18 +00:00
}
2012-08-19 02:33:43 +00:00
// Only 1 category per file-type allowed. ie. 1 for images, 1 for files.
function XmlMediaCategories ( $function , $tag )
{
$mes = e107 :: getMessage ();
// print_a($tag);
$folder = $tag [ 'folder' ];
$prevType = " " ;
//print_a($tag);
switch ( $function )
{
case 'install' :
$c = 1 ;
foreach ( $tag [ 'mediaCategories' ][ 'category' ] as $v )
{
$type = $v [ '@attributes' ][ 'type' ];
2012-10-31 21:28:20 +00:00
if ( strpos ( $type , 'image' ) !== 0 && strpos ( $type , 'file' ) !== 0 && strpos ( $type , 'video' ) !== 0 )
2012-08-19 02:33:43 +00:00
{
continue ;
}
2012-10-31 21:28:20 +00:00
if ( $c == 4 || ( $prevType == $type ))
2012-08-19 02:33:43 +00:00
{
2012-10-31 21:28:20 +00:00
$mes -> addDebug ( " Only 3 Media Categories are permitted during install. One for images and one for files. " );
2012-08-19 02:33:43 +00:00
break ;
}
$prevType = $type ;
$data [ 'owner' ] = $folder ;
2012-10-31 21:28:20 +00:00
$data [ 'category' ] = $folder . " _ " . $type ;
2012-08-19 02:33:43 +00:00
$data [ 'title' ] = $v [ '@value' ];
// $data['type'] = $v['@attributes']['type']; //TODO
$data [ 'class' ] = 253 ;
$status = e107 :: getMedia () -> createCategory ( $data ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
$mes -> add ( " Adding Media Category: { $data [ 'category' ] } " , $status );
$c ++ ;
}
break ;
case 'uninstall' : // Probably best to leave well alone
$status = e107 :: getMedia () -> deleteAllCategories ( $folder ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
$mes -> add ( " Deleting All Media Categories owned by : { $folder } " , $status );
break ;
}
}
2012-07-18 06:34:26 +00:00
/**
* Process XML Tag < bbcodes >
* @ return none
*/
function XmlBBcodes ( $function , $tag )
{
$mes = e107 :: getMessage ();
//print_a($tag);
switch ( $function )
{
case 'install' : // Probably best to leave well alone
if ( vartrue ( $tag [ 'bbcodes' ][ '@attributes' ][ 'imgResize' ]))
{
e107 :: getConfig ( 'core' ) -> add ( " e_imageresize " , $tag [ 'folder' ]); //FIXME - should be saved as an array;
$mes -> debug ( 'Adding imageResize for: ' . $tag [ 'folder' ]);
}
break ;
case 'uninstall' : // Probably best to leave well alone
if ( vartrue ( $tag [ 'bbcodes' ][ '@attributes' ][ 'imgResize' ]))
{
// e107::getConfig('core')->add("e_imageresize",$tag['folder']);
}
break ;
}
return ;
}
2008-02-01 14:11:27 +00:00
2009-09-23 23:18:18 +00:00
/**
2009-12-09 22:38:18 +00:00
* Process XML Tag < userClasses >
2009-09-23 23:18:18 +00:00
* @ param string $function install | upgrade | refresh | uninstall
* @ param array $array
2009-12-13 21:52:32 +00:00
* @ return none
2009-09-23 23:18:18 +00:00
*/
2010-06-23 10:21:21 +00:00
function XmlUserClasses ( $function , $array )
2009-09-23 23:18:18 +00:00
{
2009-10-23 09:08:15 +00:00
$mes = e107 :: getMessage ();
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
foreach ( $array [ 'class' ] as $uclass )
2008-01-27 05:16:03 +00:00
{
2010-06-23 10:21:21 +00:00
$attrib = $uclass [ '@attributes' ];
$name = $attrib [ 'name' ];
$description = $attrib [ 'description' ];
$remove = ( varset ( $attrib [ 'deprecate' ]) == 'true' ) ? TRUE : FALSE ;
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
switch ( $function )
{
case 'install' :
case 'upgrade' :
case 'refresh' :
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( ! $remove ) // Add all active userclasses (code checks for already installed)
{
2012-11-07 20:27:41 +00:00
$result = $this -> manage_userclass ( 'add' , $name , $description );
if ( $result !== NULL )
{
$status = ( $result ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
$mes -> add ( 'Adding Userclass: ' . $name , $status );
}
2010-06-23 10:21:21 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( $function == 'upgrade' && $remove ) //If upgrading, removing any inactive userclass
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
{
$status = $this -> manage_userclass ( 'remove' , $name , $description ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
$mes -> add ( 'Removing Userclass: ' . $name , $status );
}
2008-02-02 22:04:18 +00:00
2010-06-23 10:21:21 +00:00
break ;
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
case 'uninstall' : //If uninstalling, remove all userclasses (active or inactive)
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( varsettrue ( $this -> unInstallOpts [ 'delete_userclasses' ], FALSE ))
{
$status = $this -> manage_userclass ( 'remove' , $name , $description ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
$mes -> add ( 'Removing Userclass: ' . $name , $status );
}
else
{
$mes -> add ( 'Userclass: ' . $name . ' left in place' . $name , $status );
}
2009-12-09 22:38:18 +00:00
2008-02-02 22:04:18 +00:00
break ;
2010-06-23 10:21:21 +00:00
}
2008-01-27 05:16:03 +00:00
}
2009-09-23 23:18:18 +00:00
}
/**
2009-12-09 22:38:18 +00:00
* Process XML Tag < extendedFields >
2009-09-23 23:18:18 +00:00
* @ param string $function install | upgrade | refresh | uninstall
* @ param array $array
2009-12-13 21:52:32 +00:00
* @ return none
2009-09-23 23:18:18 +00:00
*/
2010-06-23 10:21:21 +00:00
function XmlExtendedFields ( $function , $array )
2009-09-23 23:18:18 +00:00
{
2009-10-23 09:08:15 +00:00
$mes = e107 :: getMessage ();
2011-11-25 17:35:12 +00:00
$this -> setUe ();
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
foreach ( $array [ 'field' ] as $efield )
2008-11-24 00:36:50 +00:00
{
2010-06-23 10:21:21 +00:00
$attrib = $efield [ '@attributes' ];
$attrib [ 'default' ] = varset ( $attrib [ 'default' ]);
2011-11-25 17:35:12 +00:00
$type = $this -> ue_field_type ( $attrib );
$name = $this -> ue_field_name ( $this -> plugFolder , $type , $attrib [ 'name' ]);
//$name = 'plugin_'.$this->plugFolder.'_'.$attrib['name'];
2010-06-23 10:21:21 +00:00
$source = 'plugin_' . $this -> plugFolder ;
$remove = ( varset ( $attrib [ 'deprecate' ]) == 'true' ) ? TRUE : FALSE ;
2011-11-25 17:35:12 +00:00
if ( ! isset ( $attrib [ 'system' ])) $attrib [ 'system' ] = true ; // default true
else $attrib [ 'system' ] = $attrib [ 'system' ] === 'true' ? true : false ;
2008-12-05 14:18:51 +00:00
2010-06-23 10:21:21 +00:00
switch ( $function )
{
case 'install' : // Add all active extended fields
2008-11-24 00:36:50 +00:00
case 'upgrade' :
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( ! $remove )
{
2011-11-25 17:35:12 +00:00
//$status = $this->manage_extended_field('add', $name, $type, $attrib['default'], $source) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR;
$status = $this -> manage_extended_field ( 'add' , $name , $attrib , $source ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2010-06-23 10:21:21 +00:00
$mes -> add ( 'Adding Extended Field: ' . $name . ' ... ' , $status );
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( $function == 'upgrade' && $remove ) //If upgrading, removing any inactive extended fields
2008-11-24 00:36:50 +00:00
2010-06-23 10:21:21 +00:00
{
2011-11-25 17:35:12 +00:00
$status = $this -> manage_extended_field ( 'remove' , $name , $attrib , $source ) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2010-06-23 10:21:21 +00:00
$mes -> add ( 'Removing Extended Field: ' . $name . ' ... ' , $status );
}
break ;
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
case 'uninstall' : //If uninstalling, remove all extended fields (active or inactive)
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( varsettrue ( $this -> unInstallOpts [ 'delete_xfields' ], FALSE ))
{
2011-11-25 17:35:12 +00:00
$status = ( $this -> manage_extended_field ( 'remove' , $name , $attrib , $source )) ? E_MESSAGE_SUCCESS : E_MESSAGE_ERROR ;
2010-06-23 10:21:21 +00:00
$mes -> add ( 'Removing Extended Field: ' . $name . ' ... ' , $status );
}
else
{
$mes -> add ( 'Extended Field: ' . $name . ' left in place' . $name , E_MESSAGE_SUCCESS );
}
break ;
2008-11-24 00:36:50 +00:00
}
2010-06-23 10:21:21 +00:00
}
2008-02-02 00:48:58 +00:00
}
2006-12-02 04:36:16 +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 ();
2009-12-13 21:52:32 +00:00
* @ return none
2009-09-21 21:53:38 +00:00
*/
2010-06-23 10:21:21 +00:00
function XmlPrefs ( $mode = 'core' , $function , $prefArray )
2009-09-21 21:53:38 +00:00
{
2009-12-09 22:38:18 +00:00
2009-09-21 21:53:38 +00:00
//XXX Could also be used for theme prefs.. perhaps this function should be moved elsewhere?
2009-12-09 22:38:18 +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-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( ! varset ( $prefArray ) || ! varset ( $prefArray ))
2009-09-21 21:53:38 +00:00
{
2009-12-09 22:38:18 +00:00
return ;
2009-09-21 21:53:38 +00:00
}
2009-12-09 22:38:18 +00:00
2009-09-21 21:53:38 +00:00
$config = ( $mode == 'core' ) ? e107 :: getConfig ( 'core' ) : e107 :: getPlugConfig ( $mode );
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
foreach ( $prefArray [ 'pref' ] as $tag )
2009-09-21 21:53:38 +00:00
{
$key = varset ( $tag [ '@attributes' ][ 'name' ]);
2009-09-22 21:12:12 +00:00
$value = vartrue ( $tag [ '@value' ]);
2010-06-23 10:21:21 +00:00
$remove = ( varset ( $tag [ '@attributes' ][ 'deprecate' ]) == 'true' ) ? TRUE : FALSE ;
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( varset ( $tag [ '@attributes' ][ 'value' ]))
2009-09-21 21:53:38 +00:00
{
2009-12-09 22:38:18 +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
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
switch ( $function )
2009-09-21 21:53:38 +00:00
{
case 'install' :
2012-11-07 20:27:41 +00:00
case 'upgrade' :
$ret = $config -> add ( $key , $value );
if ( $ret -> data_has_changed == TRUE )
{
$mes -> add ( " Adding Pref: " . $key , E_MESSAGE_SUCCESS );
}
2010-06-23 10:21:21 +00:00
break ;
2012-11-07 20:27:41 +00:00
2010-06-23 10:21:21 +00:00
case 'refresh' :
if ( $remove ) // remove active='false' prefs.
2009-12-09 22:38:18 +00:00
2009-09-22 21:12:12 +00:00
{
2010-06-23 10:21:21 +00:00
$config -> remove ( $key , $value );
2009-12-09 22:38:18 +00:00
$mes -> add ( " Removing Pref: " . $key , E_MESSAGE_SUCCESS );
2009-09-22 21:12:12 +00:00
}
else
{
2010-06-23 10:21:21 +00:00
$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-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
break ;
2009-12-09 22:38:18 +00:00
2009-09-21 21:53:38 +00:00
case 'uninstall' :
2010-06-23 10:21:21 +00:00
$config -> remove ( $key , $value );
2009-12-09 22:38:18 +00:00
$mes -> add ( " Removing Pref: " . $key , E_MESSAGE_SUCCESS );
2010-06-23 10:21:21 +00:00
break ;
2009-12-09 22:38:18 +00:00
}
2009-09-21 21:53:38 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( $mode != " core " ) // Do only one core pref save during install/uninstall etc.
2009-09-21 21:53:38 +00:00
{
2009-12-09 22:38:18 +00:00
$config -> save ();
}
2009-09-23 23:18:18 +00:00
return ;
2009-09-21 21:53:38 +00:00
}
2009-10-21 12:53:00 +00:00
/**
2009-12-09 22:38:18 +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
2009-12-13 21:52:32 +00:00
* @ return boolean FALSE
2009-10-21 12:53:00 +00:00
*/
2010-06-23 10:21:21 +00:00
function execute_function ( $path = '' , $what = '' , $when = '' )
2009-12-09 22:38:18 +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-12-09 22:38:18 +00:00
$method_name = $what . " _ " . $when ;
2010-06-23 10:21:21 +00:00
if ( varset ( $this -> plug_vars [ '@attributes' ][ 'setupFile' ]))
2009-10-20 03:49:28 +00:00
{
2009-12-09 22:38:18 +00:00
$setup_file = e_PLUGIN . $this -> plugFolder . '/' . $this -> plug_vars [ '@attributes' ][ 'setupFile' ];
2009-10-20 03:49:28 +00:00
}
else
{
$setup_file = e_PLUGIN . $this -> plugFolder . '/' . $this -> plugFolder . '_setup.php' ;
2009-12-09 22:38:18 +00:00
}
2010-06-23 10:21:21 +00:00
if ( is_readable ( $setup_file ))
2009-10-20 03:49:28 +00:00
{
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 );
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( class_exists ( $class_name ))
2009-10-20 03:49:28 +00:00
{
$obj = new $class_name ;
2012-11-07 03:40:07 +00:00
$obj -> version_from = $this ;
2010-06-23 10:21:21 +00:00
if ( method_exists ( $obj , $method_name ))
2009-10-20 03:49:28 +00:00
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Executing setup function <b> " . $method_name . " ()</b> " , E_MESSAGE_DEBUG );
2010-06-23 10:21:21 +00:00
return call_user_func ( array ( $obj , $method_name ), $this );
2009-10-20 03:49:28 +00:00
}
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 ;
2009-12-09 22:38:18 +00:00
}
2009-10-20 03:49:28 +00:00
}
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 ;
2009-12-09 22:38:18 +00:00
}
2009-10-20 03:49:28 +00:00
}
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-12-09 22:38:18 +00:00
return FALSE ; // IMPORTANT.
2008-02-01 14:11:27 +00:00
}
2009-12-09 22:38:18 +00:00
2009-09-23 23:18:18 +00:00
// DEPRECATED - See XMLPrefs();
2010-06-23 10:21:21 +00:00
function parse_prefs ( $pref_array , $mode = 'simple' )
2008-02-01 18:09:02 +00:00
{
$ret = array ();
2010-06-23 10:21:21 +00:00
if ( ! isset ( $pref_array [ 0 ]))
2008-02-01 18:09:02 +00:00
{
$pref_array = array ( $pref_array );
}
2010-06-23 10:21:21 +00:00
if ( is_array ( $pref_array ))
2008-02-01 18:09:02 +00:00
{
2010-06-23 10:21:21 +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' ];
2010-06-23 10:21:21 +00:00
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' ];
2010-06-23 10:21:21 +00:00
if ( ! isset ( $attrib [ 'active' ]) || $attrib [ 'active' ] == 'true' )
2009-07-14 03:18:17 +00:00
{
$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 ();
2009-12-09 22:38:18 +00:00
$mySQLprefix = MPREFIX ; // Fix for some plugin.php files.
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-12-09 22:38:18 +00:00
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
2010-06-23 10:21:21 +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
2010-06-23 10:21:21 +00:00
}
2008-01-26 05:19:59 +00:00
}
2006-12-02 04:36:16 +00:00
2010-06-23 10:21:21 +00:00
/* if ( is_array ( $eplug_prefs ))
{
$this -> manage_prefs ( 'add' , $eplug_prefs );
$text .= EPL_ADLAN_8 . '<br />' ;
} */
if ( varset ( $plug_vars [ 'mainPrefs' ])) //Core pref items <mainPrefs>
2009-12-09 22:38:18 +00:00
2009-10-22 04:14:45 +00:00
{
2010-06-23 10:21:21 +00:00
$this -> XmlPrefs ( 'core' , $function , $plug_vars [ 'mainPrefs' ]);
2009-10-22 04:14:45 +00:00
$text .= EPL_ADLAN_8 . '<br />' ;
2009-12-09 22:38:18 +00:00
}
2008-01-26 05:19:59 +00:00
if ( is_array ( $eplug_array_pref ))
{
2010-06-23 10:21:21 +00:00
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
2010-06-23 10:21:21 +00:00
if ( varset ( $plug_vars [ 'siteLinks' ]))
2008-01-26 05:19:59 +00:00
{
2010-06-23 10:21:21 +00:00
$this -> XmlSiteLinks ( $function , $plug_vars [ 'siteLinks' ]);
2008-01-26 05:19:59 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( varset ( $plug_vars [ 'userClasses' ]))
2009-10-22 04:14:45 +00:00
{
2010-06-23 10:21:21 +00:00
$this -> XmlUserClasses ( $function , $plug_vars [ 'userClasses' ]);
2009-12-09 22:38:18 +00:00
}
2006-12-02 04:36:16 +00:00
2010-06-23 10:21:21 +00:00
$this -> manage_search ( 'add' , $eplug_folder );
2008-01-26 05:19:59 +00:00
2010-06-23 10:21:21 +00:00
$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
2010-06-23 10:21:21 +00:00
$sql -> db_Update ( 'plugin' , " plugin_installflag = 1, plugin_addons = ' { $eplug_addons } ' WHERE plugin_id = " . ( int ) $id );
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
$p_installed = e107 :: getPref ( 'plug_installed' , array ()); // load preference;
2009-09-03 22:27:32 +00:00
$p_installed [ $plug [ 'plugin_path' ]] = $plug [ 'plugin_version' ];
2009-12-09 22:38:18 +00:00
2012-01-06 09:49:08 +00:00
e107 :: getConfig ( 'core' ) -> setPref ( 'plug_installed' , $p_installed );
$this -> rebuildUrlConfig ();
e107 :: getConfig ( 'core' ) -> save ();
2009-12-09 22:38:18 +00:00
2008-01-26 05:19:59 +00:00
$text .= ( isset ( $eplug_done ) ? " <br /> { $eplug_done } " : " <br /> " . LAN_INSTALL_SUCCESSFUL );
2010-06-23 10:21:21 +00:00
if ( $eplug_conffile )
2009-10-20 03:49:28 +00:00
{
2010-06-23 10:21:21 +00:00
$text .= " <a href=' " . e_PLUGIN . $eplug_folder . " / " . $eplug_conffile . " '>[ " . LAN_CONFIGURE . " ]</a> " ;
2009-10-20 03:49:28 +00:00
}
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
/**
2010-06-23 10:21:21 +00:00
* Installs a plugin by ID
*
* @ param int $id
*/
2008-01-26 05:19:59 +00:00
function install_plugin ( $id )
{
2009-09-03 22:27:32 +00:00
global $ns , $sysprefs , $mySQLprefix ;
2009-12-09 22:38:18 +00:00
2009-09-03 22:27:32 +00:00
$sql = e107 :: getDb ();
$tp = e107 :: getParser ();
2008-01-26 05:19:59 +00:00
2012-01-01 10:51:05 +00:00
$text = '' ;
2008-01-26 05:19:59 +00:00
// install plugin ...
2010-06-23 10:21:21 +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' ] . '/' ;
2010-06-23 10:21:21 +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
}
2010-06-23 10:21:21 +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.
2009-12-09 22:38:18 +00:00
{
2009-09-03 22:27:32 +00:00
$sql = e107 :: getDb ();
2009-09-06 20:04:04 +00:00
$core = e107 :: getConfig ( 'core' );
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
foreach ( $this -> plugin_addons as $var ) // clear all existing prefs.
2009-12-09 22:38:18 +00:00
2009-09-12 13:16:56 +00:00
{
2010-06-23 10:21:21 +00:00
$core -> update ( $var . '_list' , " " );
2009-09-12 13:16:56 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
$query = " SELECT * FROM #plugin WHERE plugin_addons !='' ORDER BY plugin_path ASC " ;
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( $sql -> db_Select_gen ( $query ))
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +00:00
while ( $row = $sql -> db_Fetch ())
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +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-12-09 22:38:18 +00:00
2008-01-20 15:01:19 +00:00
if ( $is_installed )
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +00:00
foreach ( $tmp as $val )
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +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;
2010-06-23 10:21:21 +00:00
$core -> setPref ( $val . '_list/' . $path , $path );
2008-01-20 15:01:19 +00:00
}
2006-12-02 04:36:16 +00:00
}
}
2009-12-09 22:38:18 +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 ();
2010-06-23 10:21:21 +00:00
foreach ( $tmp as $adds )
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +00:00
if ( substr ( $adds , - 3 ) == " .sc " )
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +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
2010-06-23 10:21:21 +00:00
}
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
2011-12-10 19:34:08 +00:00
}
2006-12-02 04:36:16 +00:00
}
2011-12-10 19:34:08 +00:00
if ( $is_installed )
{
// simple bbcode
2011-12-10 19:06:19 +00:00
if ( substr ( $adds , - 3 ) == " .bb " )
{
$bb_name = substr ( $adds , 0 , - 3 ); // remove the .bb
$bb_array [ $bb_name ] = " 0 " ; // default userclass.
}
// bbcode class
2011-12-10 19:34:08 +00:00
elseif ( substr ( $adds , 0 , 3 ) == " bb_ " && substr ( $adds , - 4 ) == " .php " )
2011-12-10 19:06:19 +00:00
{
2011-12-10 19:34:08 +00:00
$bb_name = substr ( $adds , 0 , - 4 ); // remove the .php
$bb_name = substr ( $bb_name , 3 );
$bb_array [ $bb_name ] = " 0 " ; // TODO - instance and getPermissions() method
2011-12-10 19:06:19 +00:00
}
2011-12-10 19:34:08 +00:00
}
2006-12-02 04:36:16 +00:00
2010-06-23 10:21:21 +00:00
if ( $is_installed && ( substr ( $adds , - 4 ) == " _sql " ))
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +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)
2010-06-23 10:21:21 +00:00
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
2010-06-23 10:21:21 +00:00
if ( count ( $sc_array ) > 0 )
2007-05-07 13:38:34 +00:00
{
2008-01-20 15:01:19 +00:00
ksort ( $sc_array );
2010-06-23 10:21:21 +00:00
$core -> setPref ( 'shortcode_list/' . $path , $sc_array );
2006-12-02 04:36:16 +00:00
}
}
}
2009-12-09 22:38:18 +00:00
$core -> save ( FALSE );
2009-07-16 02:55:19 +00:00
2010-06-23 10:21:21 +00:00
if ( $this -> manage_icons ())
2009-07-16 02:55:19 +00:00
{
2010-06-23 10:21:21 +00:00
// echo 'IT WORKED';
}
2009-07-16 02:55:19 +00:00
else
{
2010-06-23 10:21:21 +00:00
// 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'
2010-06-23 10:21:21 +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 ();
2009-12-09 22:38:18 +00:00
2008-01-20 15:01:19 +00:00
$p_addons = array ();
2009-09-21 21:53:38 +00:00
2010-06-23 10:21:21 +00:00
foreach ( $this -> plugin_addons as $addon ) //Find exact matches only.
2009-12-09 22:38:18 +00:00
{
// if(preg_match("#^(e_.*)\.php$#", $f['fname'], $matches))
2009-09-21 21:53:38 +00:00
2010-06-23 10:21:21 +00:00
$addonPHP = $addon . " .php " ;
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( is_readable ( e_PLUGIN . $plugin_path . " / " . $addonPHP ))
{
if ( $debug === 'check' )
2008-01-20 15:01:19 +00:00
{
2010-06-23 10:21:21 +00:00
$passfail = '' ;
$file_text = file_get_contents ( e_PLUGIN . $plugin_path . " / " . $addonPHP );
if (( substr ( $file_text , 0 , 5 ) != '<' . '?php' ) || (( substr ( $file_text , - 2 , 2 ) != '?' . '>' ) && ( strrpos ( $file_text , '?' . '>' ) !== FALSE )))
2008-01-20 15:01:19 +00:00
{
2010-06-23 10:21:21 +00:00
$passfail = '<b>fail</b>' ;
2008-01-20 15:01:19 +00:00
}
2010-06-23 10:21:21 +00:00
else
{
$passfail = 'pass' ;
}
echo $plugin_path . " / " . $addon . " .php - " . $passfail . " <br /> " ;
2008-01-20 15:01:19 +00:00
}
2010-06-23 10:21:21 +00:00
$mes = e107 :: getMessage ();
// $mes->add('Detected addon: <b>'.$addon.'</b>', E_MESSAGE_DEBUG);
$p_addons [] = $addon ;
}
2006-12-02 04:36:16 +00:00
}
// Grab List of Shortcodes & BBcodes
2011-12-10 19:06:19 +00:00
$shortcodeList = $fl -> get_files ( e_PLUGIN . $plugin_path , '\.sc$' , " standard " , 1 );
$bbcodeList = $fl -> get_files ( e_PLUGIN . $plugin_path , '\.bb$' , " standard " , 1 );
$bbcodeClassList = $fl -> get_files ( e_PLUGIN . $plugin_path , '^bb_(.*)\.php$' , " standard " , 1 );
$bbcodeList = array_merge ( $bbcodeList , $bbcodeClassList );
$sqlList = $fl -> get_files ( e_PLUGIN . $plugin_path , '_sql\.php$' , " standard " , 1 );
2006-12-02 04:36:16 +00:00
// Search Shortcodes
2010-06-23 10:21:21 +00:00
foreach ( $shortcodeList as $sc )
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +00:00
if ( is_readable ( e_PLUGIN . $plugin_path . " / " . $sc [ 'fname' ]))
2006-12-02 04:36:16 +00:00
{
$p_addons [] = $sc [ 'fname' ];
}
}
2008-01-20 15:01:19 +00:00
// Search Bbcodes.
2010-06-23 10:21:21 +00:00
foreach ( $bbcodeList as $bb )
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +00:00
if ( is_readable ( e_PLUGIN . $plugin_path . " / " . $bb [ 'fname' ]))
2006-12-02 04:36:16 +00:00
{
$p_addons [] = $bb [ 'fname' ];
}
}
2008-01-20 15:01:19 +00:00
// Search _sql files.
2010-06-23 10:21:21 +00:00
foreach ( $sqlList as $esql )
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +00:00
if ( is_readable ( e_PLUGIN . $plugin_path . " / " . $esql [ 'fname' ]))
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +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
}
2010-06-23 10:21:21 +00:00
if ( $debug == true )
2006-12-02 04:36:16 +00:00
{
2010-06-23 10:21:21 +00:00
echo $plugin_path . " = " . implode ( " , " , $p_addons ) . " <br /> " ;
2006-12-02 04:36:16 +00:00
}
2010-06-23 10:21:21 +00:00
return implode ( " , " , $p_addons );
2006-12-02 04:36:16 +00:00
}
2009-10-29 13:55:08 +00:00
function checkAddon ( $plugin_path , $e_xxx )
2007-02-14 21:17:42 +00:00
{ // Return 0 = OK, 1 = Fail, 2 = inaccessible
2010-06-23 10:21:21 +00:00
if ( is_readable ( e_PLUGIN . $plugin_path . " / " . $e_xxx . " .php " ))
2008-01-20 15:01:19 +00:00
{
$file_text = file_get_contents ( e_PLUGIN . $plugin_path . " / " . $e_xxx . " .php " );
2010-06-23 10:21:21 +00:00
if (( substr ( $file_text , 0 , 5 ) != '<' . '?php' ) || (( substr ( $file_text , - 2 , 2 ) != '?' . '>' ) && ( strrpos ( $file_text , '?' . '>' ) !== FALSE )))
2009-10-29 13:36:27 +00:00
{
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-08-09 16:49:58 +00:00
// Entry point to read plugin configuration data
2010-06-23 10:21:21 +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-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +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 ;
}
2010-06-23 10:21:21 +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
}
2010-06-23 10:21:21 +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
}
2010-06-23 10:21:21 +00:00
if ( $ret == true )
2008-01-28 02:49:50 +00:00
{
2008-12-10 22:39:43 +00:00
$this -> parsed_plugin [ $plugName ] = $this -> plug_vars ;
2008-01-28 02:49:50 +00:00
}
2009-12-09 22:38:18 +00:00
2008-01-28 02:49:50 +00:00
return $ret ;
2008-01-26 04:47:27 +00:00
}
2011-05-18 08:58:35 +00:00
// return the Icon of the
function getIcon ( $plugName = '' , $size = 32 )
{
if ( ! $plugName ) return ;
if ( ! isset ( $this -> parsed_plugin [ $plugName ]))
{
$plug_vars = $this -> parse_plugin ( $plugName );
}
else
{
$plug_vars = $this -> parsed_plugin [ $plugName ];
}
//return print_r($plug_vars,TRUE);
$sizeArray = array ( 32 => 'icon' , 16 => 'iconSmall' );
$default = ( $size == 32 ) ? E_32_CAT_PLUG : " <img class='icon S16' src=' " . E_16_CAT_PLUG . " ' alt='' /> " ;
$sz = $sizeArray [ $size ];
2011-08-17 00:49:39 +00:00
$icon_src = e_PLUGIN . $plugName . " / " . $plug_vars [ 'administration' ][ $sz ];
2011-05-18 08:58:35 +00:00
$plugin_icon = $plug_vars [ 'administration' ][ $sz ] ? " <img src=' { $icon_src } ' alt='' class='icon S " . intval ( $size ) . " ' /> " : $default ;
if ( ! $plugin_icon )
{
//
}
return $plugin_icon ;
}
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 ();
2009-12-09 22:38:18 +00:00
$tp = e107 :: getParser ();
2010-06-23 10:21:21 +00:00
if ( include ( e_PLUGIN . $plugName . '/plugin.php' ))
2009-10-22 04:14:45 +00:00
{
2009-12-09 22:38:18 +00:00
//$mes->add("Loading ".e_PLUGIN.$plugName.'/plugin.php', E_MESSAGE_DEBUG);
2010-06-23 10:21:21 +00:00
}
2009-12-09 22:38:18 +00:00
2008-01-26 04:47:27 +00:00
$ret = array ();
2010-06-23 10:21:21 +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-12-09 22:38:18 +00:00
2008-12-03 22:29:58 +00:00
$ret [ '@attributes' ][ 'name' ] = varset ( $eplug_name );
2012-08-22 02:45:32 +00:00
$ret [ '@attributes' ][ 'lang' ] = varset ( $eplug_name );
2009-10-22 04:14:45 +00:00
$ret [ '@attributes' ][ 'version' ] = varset ( $eplug_version );
2012-07-24 00:42:17 +00:00
$ret [ '@attributes' ][ 'date' ] = varset ( $eplug_date );
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-12-09 22:38:18 +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 );
2012-08-22 02:45:32 +00:00
$ret [ 'description' ][ '@value' ] = varset ( $eplug_description );
$ret [ 'description' ][ '@attributes' ][ 'lang' ] = varset ( $eplug_description );
2009-12-09 22:38:18 +00:00
2009-10-22 04:14:45 +00:00
$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 );
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( varset ( $eplug_prefs ))
2009-10-22 04:14:45 +00:00
{
$c = 0 ;
2010-06-23 10:21:21 +00:00
foreach ( $eplug_prefs as $name => $value )
2009-10-22 04:14:45 +00:00
{
$ret [ 'mainPrefs' ][ 'pref' ][ $c ][ '@attributes' ][ 'name' ] = $name ;
$ret [ 'mainPrefs' ][ 'pref' ][ $c ][ '@value' ] = $value ;
$c ++ ;
}
}
2009-07-09 02:47:17 +00:00
2009-12-09 22:38:18 +00:00
// For BC.
2011-08-17 00:49:39 +00:00
$ret [ 'administration' ][ 'icon' ] = varset ( str_replace ( $plugName . " / " , " " , $eplug_icon ));
2008-01-26 04:47:27 +00:00
$ret [ 'administration' ][ 'caption' ] = varset ( $eplug_caption );
2011-08-17 00:49:39 +00:00
$ret [ 'administration' ][ 'iconSmall' ] = varset ( str_replace ( $plugName . " / " , " " , $eplug_icon_small ));
2008-01-26 04:47:27 +00:00
$ret [ 'administration' ][ 'configFile' ] = varset ( $eplug_conffile );
2008-01-26 05:19:59 +00:00
2010-06-23 10:21:21 +00:00
if ( varset ( $eplug_conffile ))
2009-10-22 04:14:45 +00:00
{
2010-06-23 10:21:21 +00:00
$ret [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'url' ] = varset ( $eplug_conffile );
$ret [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'description' ] = LAN_CONFIGURE ;
2011-08-17 00:49:39 +00:00
$ret [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'icon' ] = varset ( str_replace ( $plugName . " / " , " " , $eplug_icon ));
$ret [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'iconSmall' ] = varset ( str_replace ( $plugName . " / " , " " , $eplug_icon_small ));
2010-06-23 10:21:21 +00:00
$ret [ 'adminLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'primary' ] = 'true' ;
2009-10-22 04:14:45 +00:00
}
2010-06-23 10:21:21 +00:00
if ( vartrue ( $eplug_link ) && varset ( $eplug_link_name ) && varset ( $eplug_link_url ))
2009-10-22 04:14:45 +00:00
{
2010-06-23 10:21:21 +00:00
$ret [ 'siteLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'url' ] = $tp -> createConstants ( $eplug_link_url , 1 );
2009-12-09 22:38:18 +00:00
$ret [ 'siteLinks' ][ 'link' ][ 0 ][ '@attributes' ][ 'perm' ] = varset ( $eplug_link_perms );
2010-06-23 10:21:21 +00:00
$ret [ 'siteLinks' ][ 'link' ][ 0 ][ '@value' ] = varset ( $eplug_link_name );
2009-10-22 04:14:45 +00:00
}
2009-12-09 22:38:18 +00:00
2010-06-23 10:21:21 +00:00
if ( vartrue ( $eplug_userclass ) && vartrue ( $eplug_userclass_description ))
2009-10-22 04:14:45 +00:00
{
$ret [ 'userClasses' ][ 'class' ][ 0 ][ '@attributes' ][ 'name' ] = $eplug_userclass ;
2010-06-23 10:21:21 +00:00
$ret [ 'userClasses' ][ 'class' ][ 0 ][ '@attributes' ][ 'description' ] = $eplug_userclass_description ;
2009-10-22 04:14:45 +00:00
}
2008-01-26 04:47:27 +00:00
// Set this key so we know the vars came from a plugin.php file
2011-08-17 00:49:39 +00:00
// $ret['plugin_php'] = true; // Should no longer be needed.
2008-01-27 01:34:59 +00:00
$this -> plug_vars = $ret ;
2009-12-09 22:38:18 +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
2012-11-06 11:07:47 +00:00
function parse_plugin_xml ( $plugName , $where = null )
2008-01-26 04:47:27 +00:00
{
2009-12-09 22:38:18 +00:00
2009-09-03 22:27:32 +00:00
$tp = e107 :: getParser ();
2010-06-23 10:21:21 +00:00
// loadLanFiles($plugName, 'admin'); // Look for LAN files on default paths
2009-11-05 09:15:19 +00:00
$xml = e107 :: getXml ();
2012-08-22 02:45:32 +00:00
$mes = e107 :: getMessage ();
2012-11-06 11:07:47 +00:00
2010-06-23 10:21:21 +00:00
// $xml->setOptArrayTags('extendedField,userclass,menuLink,commentID'); // always arrays for these tags.
// $xml->setOptStringTags('install,uninstall,upgrade');
2012-11-06 11:07:47 +00:00
if ( null === $where ) $where = 'plugin.xml' ;
2009-10-22 04:14:45 +00:00
2012-11-06 11:07:47 +00:00
$this -> plug_vars = $xml -> loadXMLfile ( e_PLUGIN . $plugName . '/' . $where , 'advanced' );
2012-08-22 02:45:32 +00:00
2008-12-10 13:27:09 +00:00
if ( $this -> plug_vars === FALSE )
2008-12-05 19:56:51 +00:00
{
2009-10-23 09:08:15 +00:00
$mes -> add ( " Error reading { $plugName } /plugin.xml " , E_MESSAGE_ERROR );
2010-06-23 10:21:21 +00:00
return FALSE ;
2008-12-05 19:56:51 +00:00
}
2009-12-09 22:38:18 +00:00
$this -> plug_vars [ 'category' ] = ( isset ( $this -> plug_vars [ 'category' ])) ? $this -> manage_category ( $this -> plug_vars [ 'category' ]) : " misc " ;
$this -> plug_vars [ 'folder' ] = $plugName ; // remove the need for <folder> tag in plugin.xml.
2012-08-22 02:45:32 +00:00
if ( ! is_array ( $this -> plug_vars [ 'description' ]))
{
$diz = $this -> plug_vars [ 'description' ];
unset ( $this -> plug_vars [ 'description' ]);
$this -> plug_vars [ 'description' ][ '@value' ] = $diz ;
}
2010-06-23 10:21:21 +00:00
// Very useful debug code.to compare plugin.php vs plugin.xml
2012-08-22 02:45:32 +00:00
/*
2010-06-23 10:21:21 +00:00
$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 );
echo " </td><td> " ;
print_a ( $plug_vars1 );
echo " </table> " ;
}
2012-08-22 02:45:32 +00:00
*/
2009-12-09 22:38:18 +00:00
// TODO search for $this->plug_vars['adminLinks']['link'][0]['@attributes']['primary']==true.
2009-09-23 23:18:18 +00:00
$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-12-09 22:38:18 +00:00
2009-09-14 11:27:45 +00:00
return TRUE ;
}
2010-06-23 10:21:21 +00:00
}