Exemplo n.º 1
0
 // Check that this action request is not a CSRF hacked request:
 $Session->assert_received_crumb('plugin');
 // Check permission:
 $current_User->check_perm('options', 'edit', true);
 param('plugin_ID', 'integer', 0);
 if ($plugin_ID) {
     // second step:
     $edit_Plugin =& $admin_Plugins->get_by_ID($plugin_ID);
     if (!is_a($edit_Plugin, 'Plugin')) {
         $Messages->add(sprintf(T_('The plugin with ID %d could not be instantiated.'), $plugin_ID), 'error');
         $action = 'list';
         break;
     }
 }
 load_funcs('plugins/_plugin.funcs.php');
 if (!install_plugin_db_schema_action($edit_Plugin)) {
     $next_action = 'install_db_schema';
     break;
 }
 $msg = sprintf(T_('Installed plugin «%s».'), $edit_Plugin->classname);
 if ($edit_settings_url = $edit_Plugin->get_edit_settings_url()) {
     $msg .= ' <a href="' . $edit_settings_url . '">' . T_('Click here to configure') . '</a>.';
 }
 $Messages->add($msg, 'success');
 // Install completed:
 $r = $admin_Plugins->call_method($edit_Plugin->ID, 'AfterInstall', $params = array());
 // invalidate all PageCaches
 invalidate_pagecaches();
 // Try to enable plugin:
 $enable_return = $edit_Plugin->BeforeEnable();
 if ($enable_return === true) {
Exemplo n.º 2
0
     // Redisplay so user can fix errors:
     $action = 'edit_settings';
     break;
 case 'edit_settings':
     // Check permission:
     $current_User->check_perm('options', 'view', true);
     // Edit plugin settings:
     param('plugin_ID', 'integer', true);
     $edit_Plugin =& $admin_Plugins->get_by_ID($plugin_ID);
     if (!$edit_Plugin) {
         $Debuglog->add('The plugin with ID ' . $plugin_ID . ' was not found.', array('plugins', 'error'));
         $action = 'list';
         break;
     }
     load_funcs('plugins/_plugin.funcs.php');
     if ($edit_Plugin->status == 'broken' && !install_plugin_db_schema_action($edit_Plugin)) {
         // If the plugin is in broken status and has some required db changes then display the db changes
         $action = 'install_db_schema';
         $next_action = 'install_db_schema';
         break;
     }
     // Detect new events, so they get displayed correctly in the "Edit events" fieldset:
     $admin_Plugins->save_events($edit_Plugin, array());
     // Inform Plugin that it gets edited:
     $admin_Plugins->call_method($edit_Plugin->ID, 'PluginSettingsEditAction', $tmp_params = array());
     // Params for form:
     $edited_plugin_name = $edit_Plugin->name;
     $edited_plugin_shortdesc = $edit_Plugin->short_desc;
     $edited_plugin_code = $edit_Plugin->code;
     $edited_plugin_priority = $edit_Plugin->priority;
     break;
Exemplo n.º 3
0
/**
 * Install plugin
 *
 * @param string Plugin name
 * @param boolean TRUE - to activate plugin
 * @param array Plugin settings
 * @return true on success
 */
function install_plugin($plugin, $activate = true, $settings = array())
{
    /**
     * @var Plugins_admin
     */
    global $Plugins_admin;
    task_begin('Installing plugin: ' . $plugin . '... ');
    $edit_Plugin =& $Plugins_admin->install($plugin, 'broken');
    // "broken" by default, gets adjusted later
    if (!is_a($edit_Plugin, 'Plugin')) {
        // Broken plugin
        echo '<span class="text-danger"><evo:error>' . $edit_Plugin . '</evo:error></span><br />' . "\n";
        return false;
    }
    load_funcs('plugins/_plugin.funcs.php');
    install_plugin_db_schema_action($edit_Plugin, true);
    if (!empty($settings)) {
        // Set plugin settings
        foreach ($settings as $setting_name => $setting_value) {
            $edit_Plugin->Settings->set($setting_name, $setting_value);
        }
        $edit_Plugin->Settings->dbupdate();
    }
    if ($activate) {
        // Try to enable plugin:
        $enable_return = $edit_Plugin->BeforeEnable();
        if ($enable_return !== true) {
            // Warning on enable a plugin
            echo '<span class="text-warning"><evo:warning>' . $enable_return . '</evo:warning></span><br />' . "\n";
            // Set plugin status to "needs_config" to mark the plugin as incomplete for using:
            $Plugins_admin->set_Plugin_status($edit_Plugin, 'needs_config');
            return false;
        }
        $Plugins_admin->set_Plugin_status($edit_Plugin, 'enabled');
    } else {
        // Set plugin status as disable
        $Plugins_admin->set_Plugin_status($edit_Plugin, 'disabled');
    }
    task_end();
    return true;
}