basedir)) {
echo '
LightPress configuration not found
please
check the folder where you have installed LightPress, then set (and save) required options';
} else if (!@include_once "$basedir/classes/Frontend.php") {
echo '
classes/Frontend.php not found in the LightPress installation directory
please
check the folder where you have install LightPress';
} else if (!@is_dir("$basedir/plugins") || !@is_readable("$basedir/plugins")) {
echo '
plugin folder not found in the LightPress installation directory
please
check the folder where you have install LightPress';
} else {
// get plugin configuration
if (!($plugins_config = get_option('lp_opt_plugins')))
$plugins_config =& $lp_opts->plugins; // use default plugins
// retrieve plugin files
$dummy_obj = array();
$plugins = array();
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . $basedir);
foreach ($lp_opts->getPluginList() as $plugin_file) {
if (!include_once("$basedir/plugins/$plugin_file"))
continue;
$plugin_name = substr($plugin_file, 0, -4);
$plugin =& new $plugin_name($dummy_obj, $dummy_obj, true);
$plugins[$plugin_name] =& $plugin;
}
// retrieve contexts and their constants
$contexts = array();
foreach (explode(' ', LP_CONTEXTS) as $c) {
$context = strtoupper("LP_CONTEXT_$c");
if (defined($context))
$contexts[$c] = constant($context);
}
// retrieve the action, if there is one
$action = (isset($_POST['action']) ? $_POST['action'] : '');
// check and retrieve the plugin name, if we have an action
// hairy code following, it must be the effect of running inside WP :)
if (!empty($action) // we have an action
&& // and
(
!isset($_POST['lp_plugin']) // the plugin name is not set
|| // or
!isset($plugins[($plugin_name=$_POST['lp_plugin'])]) // the plugin name is invalid
)
) {
// display an error message and stop processing
echo '
LightPress Plugins
';
echo '
No plugin to manage
';
} else {
// either we have no action, or we have both an action and a plugin name
// define the message variable we will use as a flag to signal if we have
// to display the plugin list after processing the actions
$message = '';
// prepare accessory variables
if ($action) {
// retrieve plugin information
if (isset($plugins_config[$plugin_name])) {
list($plugin_context, $plugin_args) = $plugins_config[$plugin_name];
} else {
$plugin_context = 0;
$plugin_args = array();
}
$plugin =& $plugins[$plugin_name];
// fill in missing plugin args with defaults
foreach ($plugin->constructor_args as $k=>$v) {
if (!isset($plugin_args[$k]))
$plugin_args[$k] = $plugin->$k;
}
// kill old args
foreach($plugin_args as $k=>$v) {
if (!isset($plugin->constructor_args[$k]))
unset($plugin_args[$k]);
}
}
switch ($action) {
case 'Manage':
// deal with the manage request
// show form
echo "
$plugin_name
";
echo '
' . $plugin->description . "
\n";
echo '
';
break;
case 'Activate':
// update plugin args
if (!isset($plugins_config[$plugin_name])) {
$plugin_args = array();
foreach ($plugin->constructor_args as $k=>$v)
$plugin_args[$k] = $plugin->$k;
$plugins_config[$plugin_name] = array(0, $plugin_args);
}
$err = $plugin->install();
if ($err) {
$message = "Error activating $plugin_name: $err";
} else {
$message = "Plugin $plugin_name activated";
// update plugin context
$plugins_config[$plugin_name][0] = $plugin->default_context;
}
// store plugins configuration
$lp_opts->updateOption('lp_opt_plugins', $plugins_config);
break;
case 'Deactivate':
if (isset($plugins_config[$plugin_name])) {
$plugins_config[$plugin_name][0] = 0;
}
$lp_opts->updateOption('lp_opt_plugins', $plugins_config);
$message = "Plugin $plugin_name deactivated";
break;
case 'Save':
// deal with the save request
// retrieve plugin args
foreach ($_POST as $k=>$v) {
// PHP on some systems has the nasty habit of adding slashes
// to POST variable values with magic_quotes_gpc turned off
// while the same values in _REQUEST have no slashes
if (substr($k, 0, 7) == 'lp_arg_') {
$arg_name = substr($k, 7);
// check that it's a valid arg
if (isset($plugin_args[$arg_name])) {
// check and optionally convert its type
if (is_bool($plugin->$arg_name))
$plugin_args[$arg_name] = (bool)$v;
else if (is_float($plugin->$arg_name))
$plugin_args[$arg_name] = (float)$v;
else if (is_int($plugin->$arg_name))
$plugin_args[$arg_name] = (int)$v;
else
$plugin_args[$arg_name] = stripslashes($v);
}
}
}
if (!isset($plugins_config[$plugin_name]))
$plugins_config[$plugin_name] = array(0, $plugin_args);
else
$plugins_config[$plugin_name][1] = $plugin_args;
// deal with contexts
$plugin_context = 0; // if it's not in POST it means we have to clear all contexts
if (isset($_POST['lp_context']) && is_array($_POST['lp_context'])) {
foreach ($_POST['lp_context'] as $c)
$plugin_context |= (int)$c;
}
$message = "Configuration for plugin $plugin_name updated";
// check if the context has been modified
if ($plugin_context > 0 && $plugin_context != $plugins_config[$plugin_name][0]) {
// run plugin installation routine
$err = $plugin->install();
if ($err)
$message = "Error activating $plugin_name: $err";
else
$plugins_config[$plugin_name][0] = $plugin_context;
} else {
$plugins_config[$plugin_name][0] = $plugin_context;
}
$lp_opts->updateOption('lp_opt_plugins', $plugins_config);
break;
default:
break;
}
if (!empty($message) || empty($action)) {
// display the plugin list if we have no action, or if we have successfully
// completed one of the 'transparent' actions (save, activate, deactivate)
if (!empty($message))
echo '
';
echo '
LightPress Plugins
';
?>