/** * Toggle plugin status from enabled to disabled and back * * @param array $plugin_name name of the plugin to be toggled * @return void * */ function changePluginStatus($plugin_name) { global $_TABLES, $_DB_table_prefix; if (!empty($plugin_name)) { // First find out the current state of the plugin $plugin_is_enabled = ''; $sql = "SELECT pi_enabled FROM {$_TABLES['plugins']} WHERE pi_name = ('{$plugin_name}')"; $result = DB_query($sql); if (DB_numRows($result) > 0) { list($plugin_is_enabled) = DB_fetchArray($result); } // Then toggle the state of the plugin if ($plugin_is_enabled == '1') { // Disable plugin PLG_enableStateChange($plugin_name, false); DB_change($_TABLES['plugins'], 'pi_enabled', 0, 'pi_name', $plugin_name); PLG_pluginStateChange($plugin_name, 'disabled'); } else { if ($plugin_is_enabled === '0') { // Enable plugin PLG_enableStateChange($plugin_name, true); DB_change($_TABLES['plugins'], 'pi_enabled', 1, 'pi_name', $plugin_name); PLG_pluginStateChange($plugin_name, 'enabled'); } } } }
/** * Toggle status of a plugin from enabled to disabled and back * * @param string $pi_name name of the plugin * @return void * */ function PLUGINS_toggleStatus($plugin_name_arr, $pluginarray) { global $_TABLES, $_PLUGIN_INFO, $_DB_table_prefix; if (isset($pluginarray) && is_array($pluginarray)) { foreach ($pluginarray as $plugin => $junk) { $plugin = COM_applyFilter($plugin); if (isset($plugin_name_arr[$plugin])) { DB_query("UPDATE {$_TABLES['plugins']} SET pi_enabled = '1' WHERE pi_name = '" . DB_escapeString($plugin) . "'"); $_PLUGIN_INFO[$plugin] = DB_getItem($_TABLES['plugins'], 'pi_version', "pi_name='" . DB_escapeString($plugin) . "'"); PLG_enableStateChange($plugin, true); } else { $rc = PLG_enableStateChange($plugin, false); if ($rc != 99) { DB_query("UPDATE {$_TABLES['plugins']} SET pi_enabled = '0' WHERE pi_name = '" . DB_escapeString($plugin) . "'"); } } } } CTL_clearCache(); return; }
/** * Disables all plugins with unresolved dependencies * and resolves the load order for all enabled plugins. * * @return bool True or False, depending on whether it was * necessary to alter the load order of a plugin * @since Geeklog 1.8.0 */ function PLG_resolveDependencies() { global $_PLUGINS, $_TABLES; $retval = ''; $flag = true; // false means that all dependencies are resolved while ($flag) { // loop until ALL dependencies are satisfied $flag = false; // set this if any plugin has been disabled during the loop foreach ($_PLUGINS as $key => $pi_name) { if (!PLG_checkDependencies($pi_name)) { // plugin has unresolved dependencies // disable plugin; $flag = true; // disabling a plugin can break the dependencies of a plugin that has already been checked, remember to loop again PLG_enableStateChange($pi_name, false); DB_change($_TABLES['plugins'], 'pi_enabled', 0, 'pi_name', $pi_name); PLG_pluginStateChange($pi_name, 'disabled'); unset($_PLUGINS[$key]); } } } // automatically resolve load order for enabled plugins $index = 2000; // how far through the load order to push back plugins $maxqueries = 50; // just in case... $globalflag = false; // remember if we change the load order of any plugin $flag = true; // set true if we need another pass in the while loop while ($flag && $maxqueries) { // Now check if the load order is correct $flag = false; // get the load orders of all enabled plugins $q = DB_query("SELECT pi_name, pi_load FROM {$_TABLES['plugins']} WHERE pi_enabled='1'"); $plo = array(); // Plugins Load Order while ($a = DB_fetchArray($q)) { $plo[] = $a; } $params = array(); foreach ($plo as $key => $value) { // for each available plugin $maxqueries--; $params = PLG_getParams($value['pi_name']); // get dependencies if (isset($params['requires']) && is_array($params['requires'])) { // if any foreach ($params['requires'] as $rkey => $rvalue) { // process each dependency if (isset($rvalue['plugin'])) { // get the load order of the required plugin foreach ($plo as $new_key => $new_value) { if ($new_value['pi_name'] == $rvalue['plugin']) { $dep_load = $new_value['pi_load']; break; } } if ($dep_load > $value['pi_load']) { // incorrect load order // move down the order DB_query("UPDATE {$_TABLES['plugins']} SET pi_load = '{$index}' WHERE pi_name = '{$value['pi_name']}'"); $index++; $flag = true; $globalflag = true; } } } } } } reorderplugins(); if ($globalflag == false) { return true; // no change } else { return false; // something changed } }
/** * Saves a plugin * * @param string $pi_name Plugin name * @param string $pi_version Plugin version number * @param string $pi_gl_version Geeklog version plugin is compatible with * @param int $enabled Flag that indicates if plugin is enabled * @param string $pi_homepage URL to homepage for plugin * @return string HTML redirect or error message * */ function saveplugin($pi_name, $pi_version, $pi_gl_version, $enabled, $pi_homepage) { global $_CONF, $_TABLES, $LANG32; $retval = ''; if (!empty($pi_name)) { if ($enabled == 'on') { $enabled = 1; } else { $enabled = 0; } $pi_name = addslashes($pi_name); $pi_version = addslashes($pi_version); $pi_gl_version = addslashes($pi_gl_version); $pi_homepage = addslashes($pi_homepage); $currentState = DB_getItem($_TABLES['plugins'], 'pi_enabled', "pi_name= '{$pi_name}' LIMIT 1"); if ($currentState != $enabled) { PLG_enableStateChange($pi_name, $enabled == 1 ? true : false); } DB_save($_TABLES['plugins'], 'pi_name, pi_version, pi_gl_version, pi_enabled, pi_homepage', "'{$pi_name}', '{$pi_version}', '{$pi_gl_version}', {$enabled}, '{$pi_homepage}'"); if ($currentState != $enabled) { PLG_pluginStateChange($pi_name, $enabled == 1 ? 'enabled' : 'disabled'); } $retval = COM_refresh($_CONF['site_admin_url'] . '/plugins.php?msg=28'); } else { $retval .= COM_siteHeader('menu', $LANG32[13]); $retval .= COM_startBlock($LANG32[13], '', COM_getBlockTemplate('_msg_block', 'header')); $retval .= COM_errorLog('error saving plugin, no pi_name provided', 1); $retval .= COM_endBlock(COM_getBlockTemplate('_msg_block', 'footer')); $retval .= plugineditor($pi_name); $retval .= COM_siteFooter(); } return $retval; }