protected function definition()
 {
     global $CFG, $OUTPUT;
     $mform =& $this->_form;
     $indicators = $this->_customdata['indicators'];
     $mform->addElement('hidden', 'id', $this->_customdata['id']);
     // TODO: general course-level report settings.
     $mform->addElement('header', 'general', get_string('pluginname', 'coursereport_engagement'));
     $mform->addElement('header', 'weightings', get_string('weighting', 'coursereport_engagement'));
     $mform->addElement('static', 'weightings_desc', get_string('indicator', 'coursereport_engagement'));
     foreach ($indicators as $name => $path) {
         $grouparray = array();
         $grouparray[] =& $mform->createElement('text', "weighting_{$name}", '', array('size' => 3));
         $grouparray[] =& $mform->createElement('static', '', '', '%');
         $mform->addGroup($grouparray, "weight_group_{$name}", get_string('pluginname', "engagementindicator_{$name}"), ' ', false);
     }
     $pluginman = plugin_manager::instance();
     $instances = get_plugin_list('engagementindicator');
     foreach ($indicators as $name => $path) {
         $plugin = coursereport_engagement_get_plugin_info($pluginman, 'engagementindicator_' . $name);
         $file = "{$CFG->dirroot}/mod/engagement/indicator/{$name}/thresholds_form.php";
         if (file_exists($file) && $plugin->is_enabled()) {
             require_once $file;
             $class = "engagementindicator_{$name}_thresholds_form";
             $subform = new $class();
             $mform->addElement('header', 'general', get_string('pluginname', "engagementindicator_{$name}"));
             $subform->definition_inner($mform);
         }
     }
     $this->add_action_buttons();
 }
/**
 * Get role capabilities of a virtual platform.
 * @param mixed $user The calling user.
 * @param string $role The role to read capabilities.
 * @param mixed $capabilities The capabilities to read (optional / may be string or array).
 */
function mnetadmin_rpc_get_plugins_info($user, $plugintype, $json_response = true)
{
    global $CFG, $USER, $DB;
    // Invoke local user and check his rights
    if ($auth_response = invoke_local_user((array) $user, 'local/vmoodle:execute')) {
        if ($json_response) {
            return $auth_response;
        } else {
            return json_decode($auth_response);
        }
    }
    $response = new StdClass();
    $response->errors = array();
    $response->error = '';
    // Creating response.
    $response->status = RPC_SUCCESS;
    // Getting role.
    $pm = plugin_manager::instance();
    $allplugins = $pm->get_plugins();
    if (!array_key_exists($plugintype, $allplugins)) {
        $response->status = RPC_FAILURE_RECORD;
        $response->errors[] = "Non existant plugin type {$plugintype}.";
        $response->error = "Non existant plugin type {$plugintype}.";
        if ($json_response) {
            return json_encode($response);
        } else {
            return $response;
        }
    }
    // Setting result value.
    $response->value = (array) $allplugins[$plugintype];
    $actionclass = $plugintype . '_remote_control';
    // Get activation status.
    foreach ($response->value as $pluginname => $foobar) {
        // Ignore non implemented.
        if (!class_exists($actionclass)) {
            debug_trace("failing running remote action on {$actionclass}. Class not found");
            continue;
        }
        $control = new $actionclass($pluginname);
        $response->value[$pluginname]->enabled = $control->is_enabled();
    }
    // Returning response.
    if ($json_response) {
        return json_encode($response);
    } else {
        return $response;
    }
}
function coursereport_engagement_get_course_summary($courseid)
{
    global $CFG, $DB;
    $risks = array();
    // TODO: We want this to rely on enabled indicators in the course...
    require_once $CFG->libdir . '/pluginlib.php';
    require_once $CFG->dirroot . '/course/report/engagement/locallib.php';
    $pluginman = plugin_manager::instance();
    $instances = get_plugin_list('engagementindicator');
    if (!($weightings = $DB->get_records_menu('coursereport_engagement', array('course' => $courseid), '', 'indicator, weight'))) {
        // Setup default weightings, all equal.
        $weight = sprintf('%.2f', 1 / count($instances));
        foreach ($instances as $name => $path) {
            $record = new stdClass();
            $record->course = $courseid;
            $record->indicator = $name;
            $record->weight = $weight;
            $record->configdata = null;
            $wid = $DB->insert_record('coursereport_engagement', $record);
            $weightings[$name] = $weight;
        }
    }
    foreach ($instances as $name => $path) {
        $plugin = coursereport_engagement_get_plugin_info($pluginman, 'engagementindicator_' . $name);
        if ($plugin->is_enabled() && file_exists("{$path}/indicator.class.php")) {
            require_once "{$path}/indicator.class.php";
            $classname = "indicator_{$name}";
            $indicator = new $classname($courseid);
            $indicatorrisks = $indicator->get_course_risks();
            $weight = isset($weightings[$name]) ? $weightings[$name] : 0;
            foreach ($indicatorrisks as $userid => $risk) {
                if (!isset($risks[$userid])) {
                    $risks[$userid] = 0;
                }
                $risks[$userid] += $risk->risk * $weight;
            }
        }
    }
    return $risks;
}
示例#4
0
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/pluginlib.php';
$action = required_param('action', PARAM_ALPHANUMEXT);
$formatname = required_param('format', PARAM_PLUGIN);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
$syscontext = context_system::instance();
$PAGE->set_url('/admin/courseformats.php');
$PAGE->set_context($syscontext);
require_login();
require_capability('moodle/site:config', $syscontext);
require_sesskey();
$return = new moodle_url('/admin/settings.php', array('section' => 'manageformats'));
$allplugins = plugin_manager::instance()->get_plugins();
$formatplugins = $allplugins['format'];
$sortorder = array_flip(array_keys($formatplugins));
if (!isset($formatplugins[$formatname])) {
    print_error('courseformatnotfound', 'error', $return, $formatname);
}
switch ($action) {
    case 'disable':
        if ($formatplugins[$formatname]->is_enabled()) {
            if (get_config('moodlecourse', 'format') === $formatname) {
                print_error('cannotdisableformat', 'error', $return);
            }
            set_config('disabled', 1, 'format_' . $formatname);
        }
        break;
    case 'enable':
 /**
  * Adds and upgrades the selected plugins
  *
  * @param array $ingredients
  * @param string $path Path to the ingredient type file system
  * @param SimpleXMLElement $xml
  * @return array Problems during the ingredients deployment
  */
 public function deploy_ingredients($ingredients, $path, SimpleXMLElement $xml)
 {
     // Using the $ingredients array keys to maintain coherence with the main deployment method
     $problems = array();
     $pluginman = plugin_manager::instance();
     $plugintypespaths = get_plugin_types();
     $this->get_flavour_info($xml);
     foreach ($ingredients as $selection) {
         // [0] => ingredienttype, [1] => ingredientname
         $ingredientdata = explode('/', $selection);
         $type = $ingredientdata[0];
         $ingredient = $ingredientdata[1];
         if (empty($this->branches[$type]->branches[$ingredient])) {
             $problems[$selection]['pluginnotfound'] = $selection;
             continue;
         }
         $ingredientdata = $this->branches[$type]->branches[$ingredient];
         // Adapter to the restrictions array
         if (!empty($ingredientdata->restrictions)) {
             $problems[$selection] = $ingredientdata->restrictions;
             continue;
         }
         if (empty($xml->{$type}) || empty($xml->{$type}->{$ingredient})) {
             $problems[$selection]['pluginnotfound'] = $selection;
             continue;
         }
         // Deploy then
         $ingredientpath = $plugintypespaths[$type] . '/' . $ingredient;
         // Remove old dir if present
         if (file_exists($ingredientpath)) {
             // Report if the old plugin directory can't be removed
             if (!$this->unlink($ingredientpath)) {
                 $problems[$selection]['plugincantremove'] = $selection;
                 continue;
             }
         }
         // Copy the new contents where the flavour says
         $tmppath = $path . '/' . $xml->{$type}->{$ingredient}->path;
         if (!$this->copy($tmppath, $ingredientpath)) {
             debugging('From : ' . $tmppath . ' To: ' . $ingredientpath);
             $problems[$selection]['plugincopyerror'] = $selection;
         }
     }
     // Execute the moodle upgrade process
     try {
         foreach ($plugintypespaths as $type => $location) {
             upgrade_plugins($type, 'flavours_print_upgrade_void', 'flavours_print_upgrade_void', false);
         }
     } catch (Exception $ex) {
         abort_all_db_transactions();
         $info = get_exception_info($ex);
         upgrade_log(UPGRADE_LOG_ERROR, $ex->module, 'Exception: ' . get_class($ex), $info->message, $info->backtrace);
     }
     return $problems;
 }
示例#6
0
 /**
  * Return XHTML to display control
  *
  * @param mixed $data Unused
  * @param string $query
  * @return string highlight
  */
 public function output_html($data, $query = '')
 {
     global $CFG, $OUTPUT;
     $return = '';
     $return = $OUTPUT->heading(new lang_string('courseformats'), 3, 'main');
     $return .= $OUTPUT->box_start('generalbox formatsui');
     $formats = plugin_manager::instance()->get_plugins_of_type('format');
     // display strings
     $txt = get_strings(array('settings', 'name', 'enable', 'disable', 'up', 'down', 'default', 'delete'));
     $txt->updown = "{$txt->up}/{$txt->down}";
     $table = new html_table();
     $table->head = array($txt->name, $txt->enable, $txt->updown, $txt->delete, $txt->settings);
     $table->align = array('left', 'center', 'center', 'center', 'center');
     $table->width = '90%';
     $table->attributes['class'] = 'manageformattable generaltable';
     $table->data = array();
     $cnt = 0;
     $defaultformat = get_config('moodlecourse', 'format');
     $spacer = $OUTPUT->pix_icon('spacer', '', 'moodle', array('class' => 'iconsmall'));
     foreach ($formats as $format) {
         $url = new moodle_url('/admin/courseformats.php', array('sesskey' => sesskey(), 'format' => $format->name));
         $isdefault = '';
         if ($format->is_enabled()) {
             $strformatname = html_writer::tag('span', $format->displayname);
             if ($defaultformat === $format->name) {
                 $hideshow = $txt->default;
             } else {
                 $hideshow = html_writer::link($url->out(false, array('action' => 'disable')), $OUTPUT->pix_icon('t/hide', $txt->disable, 'moodle', array('class' => 'iconsmall')));
             }
         } else {
             $strformatname = html_writer::tag('span', $format->displayname, array('class' => 'dimmed_text'));
             $hideshow = html_writer::link($url->out(false, array('action' => 'enable')), $OUTPUT->pix_icon('t/show', $txt->enable, 'moodle', array('class' => 'iconsmall')));
         }
         $updown = '';
         if ($cnt) {
             $updown .= html_writer::link($url->out(false, array('action' => 'up')), $OUTPUT->pix_icon('t/up', $txt->up, 'moodle', array('class' => 'iconsmall'))) . '';
         } else {
             $updown .= $spacer;
         }
         if ($cnt < count($formats) - 1) {
             $updown .= '&nbsp;' . html_writer::link($url->out(false, array('action' => 'down')), $OUTPUT->pix_icon('t/down', $txt->down, 'moodle', array('class' => 'iconsmall')));
         } else {
             $updown .= $spacer;
         }
         $cnt++;
         $settings = '';
         if ($format->get_settings_url()) {
             $settings = html_writer::link($format->get_settings_url(), $txt->settings);
         }
         $uninstall = '';
         if ($defaultformat !== $format->name) {
             $uninstall = html_writer::link($format->get_uninstall_url(), $txt->delete);
         }
         $table->data[] = array($strformatname, $hideshow, $updown, $uninstall, $settings);
     }
     $return .= html_writer::table($table);
     $link = html_writer::link(new moodle_url('/admin/settings.php', array('section' => 'coursesettings')), new lang_string('coursesettings'));
     $return .= html_writer::tag('p', get_string('manageformatsgotosettings', 'admin', $link));
     $return .= $OUTPUT->box_end();
     return highlight($query, $return);
 }
示例#7
0
    /**
     * Returns the status of the plugin
     *
     * @return string one of plugin_manager::PLUGIN_STATUS_xxx constants
     */
    public function get_status() {

        if (is_null($this->versiondb) and is_null($this->versiondisk)) {
            return plugin_manager::PLUGIN_STATUS_NODB;

        } else if (is_null($this->versiondb) and !is_null($this->versiondisk)) {
            return plugin_manager::PLUGIN_STATUS_NEW;

        } else if (!is_null($this->versiondb) and is_null($this->versiondisk)) {
            if (plugin_manager::is_deleted_standard_plugin($this->type, $this->name)) {
                return plugin_manager::PLUGIN_STATUS_DELETE;
            } else {
                return plugin_manager::PLUGIN_STATUS_MISSING;
            }

        } else if ((string)$this->versiondb === (string)$this->versiondisk) {
            return plugin_manager::PLUGIN_STATUS_UPTODATE;

        } else if ($this->versiondb < $this->versiondisk) {
            return plugin_manager::PLUGIN_STATUS_UPGRADE;

        } else if ($this->versiondb > $this->versiondisk) {
            return plugin_manager::PLUGIN_STATUS_DOWNGRADE;

        } else {
            // $version = pi(); and similar funny jokes - hopefully Donald E. Knuth will never contribute to Moodle ;-)
            throw new coding_exception('Unable to determine plugin state, check the plugin versions');
        }
    }
示例#8
0
    /**
     * Adds support for mock plugin types.
     */
    protected function normalize_component($component) {

        // List of mock plugin types used in these unit tests.
        $faketypes = array('foolish', 'bazmeg', 'quxcat');

        foreach ($faketypes as $faketype) {
            if (strpos($component, $faketype.'_') === 0) {
                return explode('_', $component, 2);
            }
        }

        return parent::normalize_component($component);
    }
示例#9
0
 /**
  * Displays all known plugins and links to manage them
  *
  * This default implementation renders all plugins into one big table.
  *
  * @param plugin_manager $pluginman provides information about the plugins.
  * @return string HTML code
  */
 public function plugins_control_panel(plugin_manager $pluginman)
 {
     global $CFG;
     $plugininfo = $pluginman->get_plugins();
     if (empty($plugininfo)) {
         return '';
     }
     $table = new html_table();
     $table->id = 'plugins-control-panel';
     $table->head = array(get_string('displayname', 'core_plugin'), get_string('source', 'core_plugin'), get_string('version', 'core_plugin'), get_string('availability', 'core_plugin'), get_string('actions', 'core_plugin'), get_string('notes', 'core_plugin'));
     $table->colclasses = array('pluginname', 'source', 'version', 'availability', 'actions', 'notes');
     foreach ($plugininfo as $type => $plugins) {
         $header = new html_table_cell($pluginman->plugintype_name_plural($type));
         $header->header = true;
         $header->colspan = count($table->head);
         $header = new html_table_row(array($header));
         $header->attributes['class'] = 'plugintypeheader type-' . $type;
         $table->data[] = $header;
         if (empty($plugins)) {
             $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
             $msg->colspan = count($table->head);
             $row = new html_table_row(array($msg));
             $row->attributes['class'] .= 'msg msg-noneinstalled';
             $table->data[] = $row;
             continue;
         }
         foreach ($plugins as $name => $plugin) {
             $row = new html_table_row();
             $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
             if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
                 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
             } else {
                 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
             }
             if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
                 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
                 $row->attributes['class'] .= ' missingfromdisk';
             } else {
                 $msg = '';
             }
             $pluginname = html_writer::tag('div', $icon . ' ' . $plugin->displayname . ' ' . $msg, array('class' => 'displayname')) . html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
             $pluginname = new html_table_cell($pluginname);
             if ($plugin->is_standard()) {
                 $row->attributes['class'] .= ' standard';
                 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
             } else {
                 $row->attributes['class'] .= ' extension';
                 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
             }
             $version = new html_table_cell($plugin->versiondb);
             $isenabled = $plugin->is_enabled();
             if (is_null($isenabled)) {
                 $availability = new html_table_cell('');
             } else {
                 if ($isenabled) {
                     $row->attributes['class'] .= ' enabled';
                     $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
                     $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
                 } else {
                     $row->attributes['class'] .= ' disabled';
                     $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
                     $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
                 }
             }
             $actions = array();
             $settingsurl = $plugin->get_settings_url();
             if (!is_null($settingsurl)) {
                 $actions[] = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
             }
             $uninstallurl = $plugin->get_uninstall_url();
             if (!is_null($uninstallurl)) {
                 $actions[] = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'), array('class' => 'uninstall'));
             }
             $actions = new html_table_cell(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $actions));
             $requriedby = $pluginman->other_plugins_that_require($plugin->component);
             if ($requriedby) {
                 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)), array('class' => 'requiredby'));
             } else {
                 $requiredby = '';
             }
             $updateinfo = '';
             if (empty($CFG->disableupdatenotifications) and is_array($plugin->available_updates())) {
                 foreach ($plugin->available_updates() as $availableupdate) {
                     $updateinfo .= $this->plugin_available_update_info($availableupdate);
                 }
             }
             $notes = new html_table_cell($requiredby . $updateinfo);
             $row->cells = array($pluginname, $source, $version, $availability, $actions, $notes);
             $table->data[] = $row;
         }
     }
     return html_writer::table($table);
 }
示例#10
0
文件: lib.php 项目: neogic/moodle
/**
 * Get all message providers, validate their plugin existance and
 * system configuration
 *
 * @return mixed $processors array of objects containing information on message processors
 */
function get_message_providers() {
    global $CFG, $DB;
    require_once($CFG->libdir . '/pluginlib.php');
    $pluginman = plugin_manager::instance();

    $providers = $DB->get_records('message_providers', null, 'name');

    // Remove all the providers whose plugins are disabled or don't exist
    foreach ($providers as $providerid => $provider) {
        $plugin = $pluginman->get_plugin_info($provider->component);
        if ($plugin) {
            if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
                unset($providers[$providerid]);   // Plugins does not exist
                continue;
            }
            if ($plugin->is_enabled() === false) {
                unset($providers[$providerid]);   // Plugin disabled
                continue;
            }
        }
    }
    return $providers;
}
 function action($action)
 {
     $allplugins = plugin_manager::instance()->get_plugins();
     $formatplugins = $allplugins['format'];
     if (!isset($formatplugins[$this->plugin])) {
         return get_string('courseformatnotfound', 'error', $this->plugin);
     }
     switch ($action) {
         case 'enable':
             if (!$formatplugins[$this->plugin]->is_enabled()) {
                 unset_config('disabled', 'format_' . $this->plugin);
             }
             break;
         case 'disable':
             if ($formatplugins[$this->plugin]->is_enabled()) {
                 if (get_config('moodlecourse', 'format') === $this->plugin) {
                     return get_string('cannotdisableformat', 'error');
                 }
                 set_config('disabled', 1, 'format_' . $formatname);
             }
             break;
     }
     return 0;
 }
function mnetadmin_rpc_upgrade($user, $json_response = true)
{
    global $CFG, $USER;
    // Invoke local user and check his rights
    if ($auth_response = invoke_local_user((array) $user)) {
        if ($json_response) {
            return $auth_response;
        } else {
            return json_decode($auth_response);
        }
    }
    // Creating response
    $response = new stdclass();
    $response->status = RPC_SUCCESS;
    require "{$CFG->dirroot}/version.php";
    // defines $version, $release, $branch and $maturity
    $CFG->target_release = $release;
    // used during installation and upgrades
    if ($version < $CFG->version) {
        $response->status = RPC_FAILURE_RUN;
        $response->error = get_string('downgradedcore', 'error');
        $response->errors[] = get_string('downgradedcore', 'error');
        if ($json_response) {
            return json_encode($response);
        } else {
            return $response;
        }
    }
    $oldversion = "{$CFG->release} ({$CFG->version})";
    $newversion = "{$release} ({$version})";
    if (!moodle_needs_upgrading()) {
        $response->message = get_string('cliupgradenoneed', 'core_admin', $newversion);
        if ($json_response) {
            return json_encode($response);
        } else {
            return $response;
        }
    }
    // debug_trace('Remote Upgrade : Environment check');
    list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_NEWER);
    if (!$envstatus) {
        $response->status = RPC_FAILURE_RUN;
        $response->error = vmoodle_get_string('environmentissues', 'vmoodleadminset_upgrade');
        $response->errors[] = vmoodle_get_string('environmentissues', 'vmoodleadminset_upgrade');
        $response->detail = $environment_results;
        if ($json_response) {
            return json_encode($response);
        } else {
            return $response;
        }
    }
    // Test plugin dependencies.
    // debug_trace('Remote Upgrade : Plugins check');
    $failed = array();
    if (!plugin_manager::instance()->all_plugins_ok($version, $failed)) {
        $response->status = RPC_FAILURE_RUN;
        $response->error = get_string('pluginschecktodo', 'admin');
        $response->errors[] = get_string('pluginschecktodo', 'admin');
        if ($json_response) {
            return json_encode($response);
        } else {
            return $response;
        }
    }
    ob_start();
    // debug_trace('Remote Upgrade : Upgrade core');
    if ($version > $CFG->version) {
        upgrade_core($version, false);
    }
    set_config('release', $release);
    set_config('branch', $branch);
    // unconditionally upgrade
    // debug_trace('Remote Upgrade : Upgrade other');
    upgrade_noncore(false);
    // log in as admin - we need doanything permission when applying defaults
    // debug_trace('Remote Upgrade : Turning ADMIN ');
    session_set_user(get_admin());
    // apply all default settings, just in case do it twice to fill all defaults
    // debug_trace('Remote Upgrade : Applying settings ');
    admin_apply_default_settings(NULL, false);
    admin_apply_default_settings(NULL, false);
    ob_end_clean();
    $response->message = vmoodle_get_string('upgradecomplete', 'vmoodleadminset_upgrade', $newversion);
    if ($json_response) {
        return json_encode($response);
    } else {
        return $response;
    }
}
示例#13
0
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * TinyMCE admin settings
 *
 * @package    editor_tinymce
 * @copyright  2009 Petr Skoda (http://skodak.org)
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
defined('MOODLE_INTERNAL') || die;
$ADMIN->add('editorsettings', new admin_category('editortinymce', $editor->displayname, $editor->is_enabled() === false));
$settings = new admin_settingpage('editorsettingstinymce', new lang_string('settings', 'editor_tinymce'));
if ($ADMIN->fulltree) {
    require_once __DIR__ . '/adminlib.php';
    $settings->add(new tiynce_subplugins_settings());
    $settings->add(new admin_setting_heading('tinymcegeneralheader', new lang_string('settings'), ''));
    $default = "fontselect,fontsizeselect,formatselect,|,undo,redo,|,search,replace,|,fullscreen\n\nbold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,|,cleanup,removeformat,pastetext,pasteword,|,forecolor,backcolor,|,ltr,rtl\n\nbullist,numlist,outdent,indent,|,link,unlink,|,image,nonbreaking,charmap,table,|,code";
    $settings->add(new admin_setting_configtextarea('editor_tinymce/customtoolbar', get_string('customtoolbar', 'editor_tinymce'), get_string('customtoolbar_desc', 'editor_tinymce', 'http://www.tinymce.com/wiki.php/Buttons/controls'), $default, PARAM_RAW, 100, 8));
    $settings->add(new admin_setting_configtextarea('editor_tinymce/fontselectlist', get_string('fontselectlist', 'editor_tinymce'), '', 'Trebuchet=Trebuchet MS,Verdana,Arial,Helvetica,sans-serif;Arial=arial,helvetica,sans-serif;Courier New=courier new,courier,monospace;Georgia=georgia,times new roman,times,serif;Tahoma=tahoma,arial,helvetica,sans-serif;Times New Roman=times new roman,times,serif;Verdana=verdana,arial,helvetica,sans-serif;Impact=impact;Wingdings=wingdings', PARAM_RAW, 100, 8));
    $settings->add(new editor_tinymce_json_setting_textarea('editor_tinymce/customconfig', get_string('customconfig', 'editor_tinymce'), get_string('customconfig_desc', 'editor_tinymce'), '', PARAM_RAW, 100, 8));
}
$ADMIN->add('editortinymce', $settings);
unset($settings);
require_once "{$CFG->libdir}/pluginlib.php";
foreach (plugin_manager::instance()->get_plugins_of_type('tinymce') as $plugin) {
    $plugin->load_settings($ADMIN, 'editortinymce', $hassiteconfig);
}
// TinyMCE does not have standard settings page.
$settings = null;
 /**
  * Execute the command.
  * @param    $hosts        mixed            The host where run the command (may be wwwroot or an array).
  * @throws                Command_Exception.
  */
 public function run($hosts)
 {
     global $CFG, $USER;
     // Adding constants.
     require_once $CFG->dirroot . '/local/vmoodle/rpclib.php';
     // Checking capability to run.
     if (!has_capability('local/vmoodle:execute', \context_system::instance())) {
         throw new Command_Exception('insuffisantcapabilities');
     }
     // Getting plugin.
     list($type, $plugin) = explode('/', $this->getParameter('plugin')->getValue());
     // Getting the state.
     $state = $this->getParameter('state')->getValue();
     $pm = \plugin_manager::instance();
     $plugininfo = $pm->get_plugin_info($plugin);
     if (empty($plugininfo->type)) {
         if (empty($plugininfo)) {
             $plugininfo = new \StdClass();
         }
         $plugininfo->type = $type;
     }
     $plugininfo->action = $state;
     $plugininfos[$plugin] = (array) $plugininfo;
     // Creating XMLRPC client to change remote configuration.
     $rpc_client = new \local_vmoodle\XmlRpc_Client();
     $rpc_client->set_method('local/vmoodle/plugins/plugins/rpclib.php/mnetadmin_rpc_set_plugins_states');
     $rpc_client->add_param($plugininfos, 'array');
     // Initializing responses.
     $responses = array();
     // Creating peers.
     $mnet_hosts = array();
     if (!empty($hosts)) {
         foreach ($hosts as $host => $name) {
             $mnet_host = new \mnet_peer();
             if ($mnet_host->bootstrap($host, null, 'moodle')) {
                 $mnet_hosts[] = $mnet_host;
             } else {
                 $responses[$host] = (object) array('status' => MNET_FAILURE, 'error' => get_string('couldnotcreateclient', 'local_vmoodle', $host));
             }
         }
     }
     // Sending requests.
     foreach ($mnet_hosts as $mnet_host) {
         // Sending request.
         if (!$rpc_client->send($mnet_host)) {
             $response = new \StdClass();
             $response->status = MNET_FAILURE;
             $response->errors[] = implode('<br/>', $rpc_client->getErrors($mnet_host));
             if (debugging()) {
                 echo '<pre>';
                 var_dump($rpc_client);
                 echo '</pre>';
             }
         } else {
             $response = json_decode($rpc_client->response);
         }
         // Recording response.
         $responses[$mnet_host->wwwroot] = $response;
         // Recording plugin descriptors.
         if ($response->status == RPC_SUCCESS) {
             $this->plugins[$mnet_host->wwwroot] = @$response->value;
         }
     }
     // Saving results
     $this->results = $responses + $this->results;
 }
示例#15
0
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once '../config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/pluginlib.php';
$action = required_param('action', PARAM_ALPHANUMEXT);
$formatname = required_param('format', PARAM_PLUGIN);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
$syscontext = context_system::instance();
$PAGE->set_url('/admin/courseformats.php');
$PAGE->set_context($syscontext);
require_login();
require_capability('moodle/site:config', $syscontext);
require_sesskey();
$return = new moodle_url('/admin/settings.php', array('section' => 'manageformats'));
$formatplugins = plugin_manager::instance()->get_plugins_of_type('format');
$sortorder = array_flip(array_keys($formatplugins));
if (!isset($formatplugins[$formatname])) {
    print_error('courseformatnotfound', 'error', $return, $formatname);
}
switch ($action) {
    case 'disable':
        if ($formatplugins[$formatname]->is_enabled()) {
            if (get_config('moodlecourse', 'format') === $formatname) {
                print_error('cannotdisableformat', 'error', $return);
            }
            set_config('disabled', 1, 'format_' . $formatname);
        }
        break;
    case 'enable':
        if (!$formatplugins[$formatname]->is_enabled()) {
示例#16
0
 /**
  * Builds the XHTML to display the control.
  *
  * @param string $data Unused
  * @param string $query
  * @return string
  */
 public function output_html($data, $query = '')
 {
     global $CFG, $OUTPUT, $PAGE;
     require_once "{$CFG->libdir}/editorlib.php";
     require_once "{$CFG->libdir}/pluginlib.php";
     require_once __DIR__ . '/lib.php';
     $tinymce = new tinymce_texteditor();
     $pluginmanager = plugin_manager::instance();
     // display strings
     $strbuttons = get_string('availablebuttons', 'editor_tinymce');
     $strdisable = get_string('disable');
     $strenable = get_string('enable');
     $strname = get_string('name');
     $strsettings = get_string('settings');
     $struninstall = get_string('uninstallplugin', 'admin');
     $strversion = get_string('version');
     $subplugins = get_plugin_list('tinymce');
     $return = $OUTPUT->heading(get_string('subplugintype_tinymce_plural', 'editor_tinymce'), 3, 'main', true);
     $return .= $OUTPUT->box_start('generalbox tinymcesubplugins');
     $table = new html_table();
     $table->head = array($strname, $strbuttons, $strversion, $strenable, $strsettings, $struninstall);
     $table->align = array('left', 'left', 'center', 'center', 'center', 'center');
     $table->data = array();
     $table->width = '100%';
     // Iterate through subplugins.
     foreach ($subplugins as $name => $dir) {
         $namestr = get_string('pluginname', 'tinymce_' . $name);
         $version = get_config('tinymce_' . $name, 'version');
         if ($version === false) {
             $version = '';
         }
         $plugin = $tinymce->get_plugin($name);
         $plugininfo = $pluginmanager->get_plugin_info('tinymce_' . $name);
         // Add hide/show link.
         if (!$version) {
             $hideshow = '';
             $displayname = html_writer::tag('span', $name, array('class' => 'error'));
         } else {
             if ($plugininfo->is_enabled()) {
                 $url = new moodle_url('/lib/editor/tinymce/subplugins.php', array('sesskey' => sesskey(), 'return' => 'settings', 'disable' => $name));
                 $hideshow = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/hide'), 'class' => 'icon', 'alt' => $strdisable));
                 $hideshow = html_writer::link($url, $hideshow);
                 $displayname = html_writer::tag('span', $namestr);
             } else {
                 $url = new moodle_url('/lib/editor/tinymce/subplugins.php', array('sesskey' => sesskey(), 'return' => 'settings', 'enable' => $name));
                 $hideshow = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('i/show'), 'class' => 'icon', 'alt' => $strenable));
                 $hideshow = html_writer::link($url, $hideshow);
                 $displayname = html_writer::tag('span', $namestr, array('class' => 'dimmed_text'));
             }
         }
         if ($PAGE->theme->resolve_image_location('icon', 'tinymce_' . $name)) {
             $icon = $OUTPUT->pix_icon('icon', '', 'tinymce_' . $name, array('class' => 'smallicon pluginicon'));
         } else {
             $icon = $OUTPUT->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
         }
         $displayname = $icon . ' ' . $displayname;
         // Add available buttons.
         $buttons = implode(', ', $plugin->get_buttons());
         $buttons = html_writer::tag('span', $buttons, array('class' => 'tinymcebuttons'));
         // Add settings link.
         if (!$version) {
             $settings = '';
         } else {
             if ($url = $plugininfo->get_settings_url()) {
                 $settings = html_writer::link($url, $strsettings);
             } else {
                 $settings = '';
             }
         }
         // Add uninstall info.
         if ($version) {
             $url = new moodle_url($plugininfo->get_uninstall_url(), array('return' => 'settings'));
             $uninstall = html_writer::link($url, $struninstall);
         } else {
             $uninstall = '';
         }
         // Add a row to the table.
         $table->data[] = array($displayname, $buttons, $version, $hideshow, $settings, $uninstall);
     }
     $return .= html_writer::table($table);
     $return .= html_writer::tag('p', get_string('tablenosave', 'admin'));
     $return .= $OUTPUT->box_end();
     return highlight($query, $return);
 }
 /**
  * Renders indicator manager
  *
  * @return string HTML
  */
 public function display_indicator_list(plugin_manager $pluginman, $instances)
 {
     if (empty($instances)) {
         return '';
     }
     $table = new html_table();
     $table->id = 'plugins-control-panel';
     $table->attributes['class'] = 'generaltable generalbox boxaligncenter boxwidthwide';
     $table->head = array(get_string('displayname', 'core_plugin'), get_string('source', 'core_plugin'), get_string('version', 'core_plugin'), get_string('availability', 'core_plugin'), get_string('settings', 'core_plugin'));
     $table->colclasses = array('displayname', 'source', 'version', 'availability', 'settings');
     foreach ($instances as $name => $path) {
         $plugin = $pluginman->get_plugin_info('engagementindicator_' . $name);
         $row = new html_table_row();
         $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
         if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
             $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
         } else {
             $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
         }
         if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
             $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
             $row->attributes['class'] .= ' missingfromdisk';
         } else {
             $msg = '';
         }
         $displayname = $icon . ' ' . $plugin->displayname . ' ' . $msg;
         $displayname = new html_table_cell($displayname);
         if (coursereport_engagement_is_core_indicator($name)) {
             $row->attributes['class'] .= ' standard';
             $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
         } else {
             $row->attributes['class'] .= ' extension';
             $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
         }
         $version = new html_table_cell($plugin->versiondb);
         $isenabled = $plugin->is_enabled();
         if (is_null($isenabled)) {
             $availability = new html_table_cell('');
         } else {
             if ($isenabled) {
                 $row->attributes['class'] .= ' enabled';
                 $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
                 $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
             } else {
                 $row->attributes['class'] .= ' disabled';
                 $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
                 $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
             }
         }
         $settingsurl = $plugin->get_settings_url();
         if (is_null($settingsurl)) {
             $settings = new html_table_cell('');
         } else {
             $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'));
             $settings = new html_table_cell($settings);
         }
         $row->cells = array($displayname, $source, $version, $availability, $settings);
         $table->data[] = $row;
     }
     return html_writer::table($table);
 }
示例#18
0
 /**
  * Returns localised list of available plugin types
  *
  * @return array (string)plugintype => (string)plugin name
  */
 public function get_plugin_types_menu()
 {
     global $CFG;
     require_once $CFG->libdir . '/pluginlib.php';
     $pluginman = plugin_manager::instance();
     $menu = array('' => get_string('choosedots'));
     foreach (array_keys($pluginman->get_plugin_types()) as $plugintype) {
         $menu[$plugintype] = $pluginman->plugintype_name($plugintype) . ' (' . $plugintype . ')';
     }
     return $menu;
 }
示例#19
0
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
/**
 * UI for general plugins management
 *
 * @package    core
 * @subpackage admin
 * @copyright  2011 David Mudrak <*****@*****.**>
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(dirname(__FILE__)) . '/config.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/pluginlib.php';
require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
admin_externalpage_setup('pluginsoverview');
$output = $PAGE->get_renderer('core', 'admin');
echo $output->plugin_management_page(plugin_manager::instance());
示例#20
0
文件: util.php 项目: Burick/moodle
 /**
  * Reset contents of all database tables to initial values, reset caches, etc.
  *
  * Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!
  *
  * @static
  * @param bool $logchanges log changes in global state and database in error log
  * @return void
  */
 public static function reset_all_data($logchanges = false)
 {
     global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION;
     // Stop any message redirection.
     phpunit_util::stop_message_redirection();
     // Release memory and indirectly call destroy() methods to release resource handles, etc.
     gc_collect_cycles();
     // Show any unhandled debugging messages, the runbare() could already reset it.
     self::display_debugging_messages();
     self::reset_debugging();
     // reset global $DB in case somebody mocked it
     $DB = self::get_global_backup('DB');
     if ($DB->is_transaction_started()) {
         // we can not reset inside transaction
         $DB->force_transaction_rollback();
     }
     $resetdb = self::reset_database();
     $warnings = array();
     if ($logchanges) {
         if ($resetdb) {
             $warnings[] = 'Warning: unexpected database modification, resetting DB state';
         }
         $oldcfg = self::get_global_backup('CFG');
         $oldsite = self::get_global_backup('SITE');
         foreach ($CFG as $k => $v) {
             if (!property_exists($oldcfg, $k)) {
                 $warnings[] = 'Warning: unexpected new $CFG->' . $k . ' value';
             } else {
                 if ($oldcfg->{$k} !== $CFG->{$k}) {
                     $warnings[] = 'Warning: unexpected change of $CFG->' . $k . ' value';
                 }
             }
             unset($oldcfg->{$k});
         }
         if ($oldcfg) {
             foreach ($oldcfg as $k => $v) {
                 $warnings[] = 'Warning: unexpected removal of $CFG->' . $k;
             }
         }
         if ($USER->id != 0) {
             $warnings[] = 'Warning: unexpected change of $USER';
         }
         if ($COURSE->id != $oldsite->id) {
             $warnings[] = 'Warning: unexpected change of $COURSE';
         }
     }
     // restore original globals
     $_SERVER = self::get_global_backup('_SERVER');
     $CFG = self::get_global_backup('CFG');
     $SITE = self::get_global_backup('SITE');
     $COURSE = $SITE;
     // reinitialise following globals
     $OUTPUT = new bootstrap_renderer();
     $PAGE = new moodle_page();
     $FULLME = null;
     $ME = null;
     $SCRIPT = null;
     $SESSION = new stdClass();
     $_SESSION['SESSION'] =& $SESSION;
     // set fresh new not-logged-in user
     $user = new stdClass();
     $user->id = 0;
     $user->mnethostid = $CFG->mnet_localhost_id;
     session_set_user($user);
     // reset all static caches
     accesslib_clear_all_caches(true);
     get_string_manager()->reset_caches(true);
     reset_text_filters_cache(true);
     events_get_handlers('reset');
     textlib::reset_caches();
     if (class_exists('repository')) {
         repository::reset_caches();
     }
     filter_manager::reset_caches();
     //TODO MDL-25290: add more resets here and probably refactor them to new core function
     // Reset course and module caches.
     if (class_exists('format_base')) {
         // If file containing class is not loaded, there is no cache there anyway.
         format_base::reset_course_cache(0);
     }
     get_fast_modinfo(0, 0, true);
     // Reset other singletons.
     if (class_exists('plugin_manager')) {
         plugin_manager::reset_caches(true);
     }
     if (class_exists('available_update_checker')) {
         available_update_checker::reset_caches(true);
     }
     if (class_exists('available_update_deployer')) {
         available_update_deployer::reset_caches(true);
     }
     // purge dataroot directory
     self::reset_dataroot();
     // restore original config once more in case resetting of caches changed CFG
     $CFG = self::get_global_backup('CFG');
     // inform data generator
     self::get_data_generator()->reset();
     // fix PHP settings
     error_reporting($CFG->debug);
     // verify db writes just in case something goes wrong in reset
     if (self::$lastdbwrites != $DB->perf_get_writes()) {
         error_log('Unexpected DB writes in phpunit_util::reset_all_data()');
         self::$lastdbwrites = $DB->perf_get_writes();
     }
     if ($warnings) {
         $warnings = implode("\n", $warnings);
         trigger_error($warnings, E_USER_WARNING);
     }
 }
示例#21
0
 * @copyright  2011 The Open University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(__FILE__) . '/../config.php';
require_once $CFG->libdir . '/questionlib.php';
require_once $CFG->libdir . '/adminlib.php';
require_once $CFG->libdir . '/pluginlib.php';
require_once $CFG->libdir . '/tablelib.php';
// Check permissions.
require_login();
$systemcontext = context_system::instance();
require_capability('moodle/question:config', $systemcontext);
admin_externalpage_setup('manageqbehaviours');
$thispageurl = new moodle_url('/admin/qbehaviours.php');
$behaviours = get_plugin_list('qbehaviour');
$pluginmanager = plugin_manager::instance();
// Get some data we will need - question counts and which types are needed.
$counts = $DB->get_records_sql_menu("\n        SELECT behaviour, COUNT(1)\n        FROM {question_attempts} GROUP BY behaviour");
$needed = array();
$archetypal = array();
foreach ($behaviours as $behaviour => $notused) {
    if (!array_key_exists($behaviour, $counts)) {
        $counts[$behaviour] = 0;
    }
    $needed[$behaviour] = $counts[$behaviour] > 0 || $pluginmanager->other_plugins_that_require('qbehaviour_' . $behaviour);
    $archetypal[$behaviour] = question_engine::is_behaviour_archetypal($behaviour);
}
foreach ($counts as $behaviour => $count) {
    if (!array_key_exists($behaviour, $behaviours)) {
        $counts['missing'] += $count;
    }
示例#22
0
文件: upgrade.php 项目: nmicha/moodle
if (!moodle_needs_upgrading()) {
    cli_error(get_string('cliupgradenoneed', 'core_admin', $newversion), 0);
}
// Test environment first.
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
if (!$envstatus) {
    $errors = environment_get_errors($environment_results);
    cli_heading(get_string('environment', 'admin'));
    foreach ($errors as $error) {
        list($info, $report) = $error;
        echo "!! {$info} !!\n{$report}\n\n";
    }
    exit(1);
}
// Test plugin dependencies.
if (!plugin_manager::instance()->all_plugins_ok($version)) {
    cli_error(get_string('pluginschecktodo', 'admin'));
}
if ($interactive) {
    $a = new stdClass();
    $a->oldversion = $oldversion;
    $a->newversion = $newversion;
    echo cli_heading(get_string('databasechecking', '', $a)) . PHP_EOL;
}
// make sure we are upgrading to a stable release or display a warning
if (isset($maturity)) {
    if ($maturity < MATURITY_STABLE and !$options['allow-unstable']) {
        $maturitylevel = get_string('maturity' . $maturity, 'admin');
        if ($interactive) {
            cli_separator();
            cli_heading(get_string('notice'));
示例#23
0
 /**
  * Displays all known plugins and links to manage them
  *
  * This default implementation renders all plugins into one big table.
  *
  * @param plugin_manager $pluginman provides information about the plugins.
  * @param array $options filtering options
  * @return string HTML code
  */
 public function plugins_control_panel(plugin_manager $pluginman, array $options = array())
 {
     global $CFG;
     $plugininfo = $pluginman->get_plugins();
     // Filter the list of plugins according the options.
     if (!empty($options['updatesonly'])) {
         $updateable = array();
         foreach ($plugininfo as $plugintype => $pluginnames) {
             foreach ($pluginnames as $pluginname => $pluginfo) {
                 if (!empty($pluginfo->availableupdates)) {
                     foreach ($pluginfo->availableupdates as $pluginavailableupdate) {
                         if ($pluginavailableupdate->version > $pluginfo->versiondisk) {
                             $updateable[$plugintype][$pluginname] = $pluginfo;
                         }
                     }
                 }
             }
         }
         $plugininfo = $updateable;
     }
     if (!empty($options['contribonly'])) {
         $contribs = array();
         foreach ($plugininfo as $plugintype => $pluginnames) {
             foreach ($pluginnames as $pluginname => $pluginfo) {
                 if (!$pluginfo->is_standard()) {
                     $contribs[$plugintype][$pluginname] = $pluginfo;
                 }
             }
         }
         $plugininfo = $contribs;
     }
     if (empty($plugininfo)) {
         return '';
     }
     $table = new html_table();
     $table->id = 'plugins-control-panel';
     $table->head = array(get_string('displayname', 'core_plugin'), get_string('source', 'core_plugin'), get_string('version', 'core_plugin'), get_string('availability', 'core_plugin'), get_string('actions', 'core_plugin'), get_string('notes', 'core_plugin'));
     $table->headspan = array(1, 1, 1, 1, 2, 1);
     $table->colclasses = array('pluginname', 'source', 'version', 'availability', 'settings', 'uninstall', 'notes');
     foreach ($plugininfo as $type => $plugins) {
         $header = new html_table_cell($pluginman->plugintype_name_plural($type));
         $header->header = true;
         $header->colspan = array_sum($table->headspan);
         $header = new html_table_row(array($header));
         $header->attributes['class'] = 'plugintypeheader type-' . $type;
         $table->data[] = $header;
         if (empty($plugins)) {
             $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
             $msg->colspan = array_sum($table->headspan);
             $row = new html_table_row(array($msg));
             $row->attributes['class'] .= 'msg msg-noneinstalled';
             $table->data[] = $row;
             continue;
         }
         foreach ($plugins as $name => $plugin) {
             $row = new html_table_row();
             $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
             if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
                 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'icon pluginicon'));
             } else {
                 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'icon pluginicon noicon'));
             }
             $status = $plugin->get_status();
             $row->attributes['class'] .= ' status-' . $status;
             if ($status === plugin_manager::PLUGIN_STATUS_MISSING) {
                 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'statusmsg'));
             } else {
                 if ($status === plugin_manager::PLUGIN_STATUS_NEW) {
                     $msg = html_writer::tag('span', get_string('status_new', 'core_plugin'), array('class' => 'statusmsg'));
                 } else {
                     $msg = '';
                 }
             }
             $pluginname = html_writer::tag('div', $icon . '' . $plugin->displayname . ' ' . $msg, array('class' => 'displayname')) . html_writer::tag('div', $plugin->component, array('class' => 'componentname'));
             $pluginname = new html_table_cell($pluginname);
             if ($plugin->is_standard()) {
                 $row->attributes['class'] .= ' standard';
                 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
             } else {
                 $row->attributes['class'] .= ' extension';
                 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
             }
             $version = new html_table_cell($plugin->versiondb);
             $isenabled = $plugin->is_enabled();
             if (is_null($isenabled)) {
                 $availability = new html_table_cell('');
             } else {
                 if ($isenabled) {
                     $row->attributes['class'] .= ' enabled';
                     $availability = new html_table_cell(get_string('pluginenabled', 'core_plugin'));
                 } else {
                     $row->attributes['class'] .= ' disabled';
                     $availability = new html_table_cell(get_string('plugindisabled', 'core_plugin'));
                 }
             }
             $settingsurl = $plugin->get_settings_url();
             if (!is_null($settingsurl)) {
                 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'), array('class' => 'settings'));
             } else {
                 $settings = '';
             }
             $settings = new html_table_cell($settings);
             if ($pluginman->can_uninstall_plugin($plugin->component)) {
                 $uninstallurl = $plugin->get_uninstall_url();
                 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
             } else {
                 $uninstall = '';
             }
             $uninstall = new html_table_cell($uninstall);
             $requriedby = $pluginman->other_plugins_that_require($plugin->component);
             if ($requriedby) {
                 $requiredby = html_writer::tag('div', get_string('requiredby', 'core_plugin', implode(', ', $requriedby)), array('class' => 'requiredby'));
             } else {
                 $requiredby = '';
             }
             $updateinfo = '';
             if (empty($CFG->disableupdatenotifications) and is_array($plugin->available_updates())) {
                 foreach ($plugin->available_updates() as $availableupdate) {
                     $updateinfo .= $this->plugin_available_update_info($availableupdate);
                 }
             }
             $notes = new html_table_cell($requiredby . $updateinfo);
             $row->cells = array($pluginname, $source, $version, $availability, $settings, $uninstall, $notes);
             $table->data[] = $row;
         }
     }
     return html_writer::table($table);
 }
示例#24
0
 /**
  * @see plugintype_interface::set_source()
  */
 public function set_source()
 {
     $standard = plugin_manager::standard_plugins_list($this->type);
     if ($standard !== false) {
         $standard = array_flip($standard);
         if (isset($standard[$this->name])) {
             $this->source = plugin_manager::PLUGIN_SOURCE_STANDARD;
         } else {
             $this->source = plugin_manager::PLUGIN_SOURCE_EXTENSION;
         }
     }
 }
 /**
  * Displays all known plugins and links to manage them
  *
  * This default implementation renders all plugins into one big table.
  *
  * @param array $plugininfo as returned by {@see plugin_manager::get_plugins()}
  * @return string HTML code
  */
 public function plugins_control_panel(array $plugininfo)
 {
     if (empty($plugininfo)) {
         return '';
     }
     $pluginman = plugin_manager::instance();
     $table = new html_table();
     $table->id = 'plugins-control-panel';
     $table->head = array(get_string('displayname', 'core_plugin'), get_string('systemname', 'core_plugin'), get_string('source', 'core_plugin'), get_string('version', 'core_plugin'), get_string('availability', 'core_plugin'), get_string('settings', 'core_plugin'), get_string('uninstall', 'core_plugin'));
     $table->colclasses = array('displayname', 'systemname', 'source', 'version', 'availability', 'settings', 'uninstall');
     foreach ($plugininfo as $type => $plugins) {
         $header = new html_table_cell($pluginman->plugintype_name_plural($type));
         $header->header = true;
         $header->colspan = count($table->head);
         $header = new html_table_row(array($header));
         $header->attributes['class'] = 'plugintypeheader type-' . $type;
         $table->data[] = $header;
         if (empty($plugins)) {
             $msg = new html_table_cell(get_string('noneinstalled', 'core_plugin'));
             $msg->colspan = count($table->head);
             $row = new html_table_row(array($msg));
             $row->attributes['class'] .= 'msg msg-noneinstalled';
             $table->data[] = $row;
             continue;
         }
         foreach ($plugins as $name => $plugin) {
             $row = new html_table_row();
             $row->attributes['class'] = 'type-' . $plugin->type . ' name-' . $plugin->type . '_' . $plugin->name;
             if ($this->page->theme->resolve_image_location('icon', $plugin->type . '_' . $plugin->name)) {
                 $icon = $this->output->pix_icon('icon', '', $plugin->type . '_' . $plugin->name, array('class' => 'smallicon pluginicon'));
             } else {
                 $icon = $this->output->pix_icon('spacer', '', 'moodle', array('class' => 'smallicon pluginicon noicon'));
             }
             if ($plugin->get_status() === plugin_manager::PLUGIN_STATUS_MISSING) {
                 $msg = html_writer::tag('span', get_string('status_missing', 'core_plugin'), array('class' => 'notifyproblem'));
                 $row->attributes['class'] .= ' missingfromdisk';
             } else {
                 $msg = '';
             }
             $displayname = $icon . ' ' . $plugin->displayname . ' ' . $msg;
             $displayname = new html_table_cell($displayname);
             $systemname = new html_table_cell($plugin->type . '_' . $plugin->name);
             if ($plugin->is_standard()) {
                 $row->attributes['class'] .= ' standard';
                 $source = new html_table_cell(get_string('sourcestd', 'core_plugin'));
             } else {
                 $row->attributes['class'] .= ' extension';
                 $source = new html_table_cell(get_string('sourceext', 'core_plugin'));
             }
             $version = new html_table_cell($plugin->versiondb);
             $isenabled = $plugin->is_enabled();
             if (is_null($isenabled)) {
                 $availability = new html_table_cell('');
             } else {
                 if ($isenabled) {
                     $row->attributes['class'] .= ' enabled';
                     $icon = $this->output->pix_icon('i/hide', get_string('pluginenabled', 'core_plugin'));
                     $availability = new html_table_cell($icon . ' ' . get_string('pluginenabled', 'core_plugin'));
                 } else {
                     $row->attributes['class'] .= ' disabled';
                     $icon = $this->output->pix_icon('i/show', get_string('plugindisabled', 'core_plugin'));
                     $availability = new html_table_cell($icon . ' ' . get_string('plugindisabled', 'core_plugin'));
                 }
             }
             $settingsurl = $plugin->get_settings_url();
             if (is_null($settingsurl)) {
                 $settings = new html_table_cell('');
             } else {
                 $settings = html_writer::link($settingsurl, get_string('settings', 'core_plugin'));
                 $settings = new html_table_cell($settings);
             }
             $uninstallurl = $plugin->get_uninstall_url();
             if (is_null($uninstallurl)) {
                 $uninstall = new html_table_cell('');
             } else {
                 $uninstall = html_writer::link($uninstallurl, get_string('uninstall', 'core_plugin'));
                 $uninstall = new html_table_cell($uninstall);
             }
             $row->cells = array($displayname, $systemname, $source, $version, $availability, $settings, $uninstall);
             $table->data[] = $row;
         }
     }
     return html_writer::table($table);
 }
示例#26
0
 /**
  * Provides access to the plugin_manager singleton.
  *
  * @return plugin_manmager
  */
 protected function get_plugin_manager()
 {
     return plugin_manager::instance();
 }
示例#27
0
    /**
     * Reset contents of all database tables to initial values, reset caches, etc.
     *
     * Note: this is relatively slow (cca 2 seconds for pg and 7 for mysql) - please use with care!
     *
     * @static
     * @param bool $logchanges log changes in global state and database in error log
     * @return void
     */
    public static function reset_all_data($logchanges = false) {
        global $DB, $CFG, $USER, $SITE, $COURSE, $PAGE, $OUTPUT, $SESSION, $GROUPLIB_CACHE;

        // Release memory and indirectly call destroy() methods to release resource handles, etc.
        gc_collect_cycles();

        // reset global $DB in case somebody mocked it
        $DB = self::get_global_backup('DB');

        if ($DB->is_transaction_started()) {
            // we can not reset inside transaction
            $DB->force_transaction_rollback();
        }

        $resetdb = self::reset_database();
        $warnings = array();

        if ($logchanges) {
            if ($resetdb) {
                $warnings[] = 'Warning: unexpected database modification, resetting DB state';
            }

            $oldcfg = self::get_global_backup('CFG');
            $oldsite = self::get_global_backup('SITE');
            foreach($CFG as $k=>$v) {
                if (!property_exists($oldcfg, $k)) {
                    $warnings[] = 'Warning: unexpected new $CFG->'.$k.' value';
                } else if ($oldcfg->$k !== $CFG->$k) {
                    $warnings[] = 'Warning: unexpected change of $CFG->'.$k.' value';
                }
                unset($oldcfg->$k);

            }
            if ($oldcfg) {
                foreach($oldcfg as $k=>$v) {
                    $warnings[] = 'Warning: unexpected removal of $CFG->'.$k;
                }
            }

            if ($USER->id != 0) {
                $warnings[] = 'Warning: unexpected change of $USER';
            }

            if ($COURSE->id != $oldsite->id) {
                $warnings[] = 'Warning: unexpected change of $COURSE';
            }

        }

        if (ini_get('max_execution_time') != 0) {
            // This is special warning for all resets because we do not want any
            // libraries to mess with timeouts unintentionally.
            // Our PHPUnit integration is not supposed to change it either.

            // TODO: MDL-38912 uncomment and fix all + somehow resolve timeouts in failed tests.
            //$warnings[] = 'Warning: max_execution_time was changed.';
            set_time_limit(0);
        }

        // restore original globals
        $_SERVER = self::get_global_backup('_SERVER');
        $CFG = self::get_global_backup('CFG');
        $SITE = self::get_global_backup('SITE');
        $COURSE = $SITE;

        // reinitialise following globals
        $OUTPUT = new bootstrap_renderer();
        $PAGE = new moodle_page();
        $FULLME = null;
        $ME = null;
        $SCRIPT = null;
        $SESSION = new stdClass();
        $_SESSION['SESSION'] =& $SESSION;

        // set fresh new not-logged-in user
        $user = new stdClass();
        $user->id = 0;
        $user->mnethostid = $CFG->mnet_localhost_id;
        session_set_user($user);

        // reset all static caches
        accesslib_clear_all_caches(true);
        get_string_manager()->reset_caches();
        events_get_handlers('reset');
        textlib::reset_caches();
        if (class_exists('repository')) {
            repository::reset_caches();
        }
        $GROUPLIB_CACHE = null;
        //TODO MDL-25290: add more resets here and probably refactor them to new core function

        // Reset course and module caches.
        $reset = 'reset';
        get_fast_modinfo($reset);

        // Reset other singletons.
        if (class_exists('plugin_manager')) {
            plugin_manager::reset_caches(true);
        }
        if (class_exists('available_update_checker')) {
            available_update_checker::reset_caches(true);
        }

        // purge dataroot directory
        self::reset_dataroot();

        // restore original config once more in case resetting of caches changed CFG
        $CFG = self::get_global_backup('CFG');

        // inform data generator
        self::get_data_generator()->reset();

        // fix PHP settings
        error_reporting($CFG->debug);

        // verify db writes just in case something goes wrong in reset
        if (self::$lastdbwrites != $DB->perf_get_writes()) {
            error_log('Unexpected DB writes in phpunit_util::reset_all_data()');
            self::$lastdbwrites = $DB->perf_get_writes();
        }

        if ($warnings) {
            $warnings = implode("\n", $warnings);
            trigger_error($warnings, E_USER_WARNING);
        }
    }
示例#28
0
文件: index.php 项目: numbas/moodle
        // means core upgrade or installation was not already done
        if (!$confirmplugins) {
            $strplugincheck = get_string('plugincheck');
            $PAGE->set_pagelayout('maintenance');
            $PAGE->set_popup_notification_allowed(false);
            $PAGE->navbar->add($strplugincheck);
            $PAGE->set_title($strplugincheck);
            $PAGE->set_heading($strplugincheck);
            $PAGE->set_cacheable(false);
            if ($fetchupdates) {
                // no sesskey support guaranteed here
                available_update_checker::instance()->fetch();
                redirect($PAGE->url);
            }
            $output = $PAGE->get_renderer('core', 'admin');
            echo $output->upgrade_plugin_check_page(plugin_manager::instance(), available_update_checker::instance(), $version, $showallplugins, new moodle_url($PAGE->url), new moodle_url('/admin/index.php', array('confirmplugincheck' => 1)));
            die;
        }
    }
    // install/upgrade all plugins and other parts
    upgrade_noncore(true);
}
// If this is the first install, indicate that this site is fully configured
// except the admin password
if (during_initial_install()) {
    set_config('rolesactive', 1);
    // after this, during_initial_install will return false.
    set_config('adminsetuppending', 1);
    // we need this redirect to setup proper session
    upgrade_finished("index.php?sessionstarted=1&amp;lang={$CFG->lang}");
}
 /**
  * Process the plugin comparison.
  * @throws Commmand_Exception.
  */
 private function _process()
 {
     global $CFG, $DB, $OUTPUT, $STANDARD_PLUGIN_TYPES, $PAGE;
     $renderer = $PAGE->get_renderer('local_vmoodle');
     // Checking if command has been runned.
     if (!$this->isRunned()) {
         throw new Command_Exception('commandnotrun');
     }
     // Getting examined plugintype.
     $plugintype = $this->getParameter('plugintype')->getValue();
     // Getting hosts.
     $hosts = array_keys($this->plugins);
     $host_labels = get_available_platforms();
     // Getting local plugin info.
     $pm = \plugin_manager::instance();
     $localplugins = $pm->get_plugins();
     $localtypeplugins = $localplugins[$plugintype];
     /*
      * Creating html report.
      */
     // Creating header.
     $this->report = '<link href="' . $CFG->wwwroot . '/local/vmoodle/plugins/plugins/theme/styles.css" rel="stylesheet" type="text/css">';
     $this->report .= '<h3>' . vmoodle_get_string('compareplugins', 'vmoodleadminset_plugins', $STANDARD_PLUGIN_TYPES[$plugintype]) . '</h3>';
     // Adding link to plugin management
     /* $this->report.= '<center><p>'.$OUTPUT->single_button(new moodle_url($CFG->wwwroot.'/admin/roles/define.php', array('roleid' => $role->id, 'action' => 'edit')), get_string('editrole', 'vmoodleadminset_roles'), 'get').'</p></center>'; */
     // Creation form
     $this->report .= '<form action="' . $CFG->wwwroot . '/local/vmoodle/plugins/plugins/controller.pluginlib.sadmin.php?what=syncplugins" method="post" onsubmit="return validate_syncplugins()">';
     $this->report .= '<input id="id_plugin" type="hidden" name="plugin" value=""/>';
     $this->report .= '<input id="source_platform" type="hidden" name="source_platform" value=""/>';
     // Creating table.
     $this->report .= '<table id="plugincompare" cellspacing="1" cellpadding="5" class="generaltable boxaligncenter" style="min-width: 75%;">';
     $this->report .= '<tbody>';
     // Creating header.
     $this->report .= '<tr><th scope="col" class="header c0" style="vertical-align: bottom; text-align: left;">&nbsp</th>';
     $col = 1;
     foreach ($hosts as $host) {
         $this->report .= '<th id="plug_' . $col . '" scope="col" class="header c' . $col . '" style="vertical-align: bottom; text-align: center;">';
         $this->report .= '<label for="platform_' . $col . '"><img src="' . $CFG->wwwroot . '/local/vmoodle/plugins/plugins/draw_platformname.php?caption=' . urlencode($host_labels[$host]) . '" alt="' . $host_labels[$host] . '"/></label><br/>';
         $this->report .= '<input id="platform_' . $col . '" type="checkbox" name="platforms[]" value="' . $host . '" disabled="disabled"/></th>';
         $col++;
     }
     $this->report .= '</tr>';
     // Initializing variables.
     $row = 0;
     // Creating table data.
     foreach ($localtypeplugins as $plugin) {
         $col = 1;
         $this->report .= '<tr class="r' . $row % 2 . '">';
         $this->report .= '<td id="plug_0_' . $row . '" class="cell c0" style="vertical-align: middle; text-align: left;" onClic="setPLugin(' . $col . ',' . $row . ',\'' . $plugin->name . '\',\'' . $host . '\')">';
         $this->report .= $plugin->displayname;
         $this->report .= '</td>';
         foreach ($hosts as $host) {
             $extra_class = false;
             $title = $plugin->displayname . ' | ' . $host_labels[$host];
             if (array_key_exists($host, $this->plugins) && property_exists($this->plugins[$host], $plugin->name)) {
                 $remote_plugin = $this->plugins[$host]->{$plugin->name};
                 if (is_null($remote_plugin)) {
                     $cell = '<img src="' . $renderer->pix_url('notinstalled', 'vmoodleadminset_plugins') . ' alt="Not installed" title="' . $title . '" />';
                 } else {
                     if ($remote_plugin->enabled) {
                         $cell = '<img src="' . $renderer->pix_url('enabled', 'vmoodleadminset_plugins') . '" title="' . $title . '" />';
                     } else {
                         $cell = '<img src="' . $renderer->pix_url('disabled', 'vmoodleadminset_plugins') . '" title="' . $title . '" />';
                     }
                     if ($localtypeplugins[$plugin->name]->versiondb > $remote_plugin->versiondb) {
                         $cell .= '&nbsp;<img src="' . $renderer->pix_url('needsupgrade', 'vmoodleadminset_plugins') . '" title="' . $title . '" />';
                     }
                     if ($remote_plugin->versiondisk > $remote_plugin->versiondb) {
                         $cell .= '&nbsp;<img src="' . $renderer->pix_url('needslocalupgrade', 'vmoodleadminset_plugins') . '" title="' . $title . '" />';
                     }
                 }
             } else {
                 $cell = '<img src="' . $renderer->pix_url('notinstalled', 'vmoodleadminset_plugins') . '" alt="Not installed" title="' . $title . '"/>';
             }
             $this->report .= '<td id="plug_' . $col . '_' . $row . '" class="cell c' . $col . ($extra_class ? ' ' . $extra_class : '') . '" style="vertical-align: middle; text-align: center;" onmouseout="cellOut(' . $col . ',' . $row . ');" onmouseover="cellOver(' . $col . ',' . $row . ');">' . $cell . '</td>';
             $col++;
         }
         $this->report .= '</tr>';
         $row++;
     }
     // Closing table
     $this->report .= '</tboby></table><br/><center><input type="submit" value="' . get_string('synchronize', 'vmoodleadminset_plugins') . '"/><div id="plugincompare_validation_message"></div></center></form><br/><br/>';
 }