/** * Get the question type class for a particular question type. * @param string $qtypename the question type name. For example 'multichoice' or 'shortanswer'. * @param bool $mustexist if false, the missing question type is returned when * the requested question type is not installed. * @return question_type the corresponding question type class. */ public static function get_qtype($qtypename, $mustexist = true) { global $CFG; if (isset(self::$questiontypes[$qtypename])) { return self::$questiontypes[$qtypename]; } $file = core_component::get_plugin_directory('qtype', $qtypename) . '/questiontype.php'; if (!is_readable($file)) { if ($mustexist || $qtypename == 'missingtype') { throw new coding_exception('Unknown question type ' . $qtypename); } else { return self::get_qtype('missingtype'); } } include_once $file; $class = 'qtype_' . $qtypename; if (!class_exists($class)) { throw new coding_exception("Class {$class} must be defined in {$file}."); } self::$questiontypes[$qtypename] = new $class(); return self::$questiontypes[$qtypename]; }
/** * This gets the mod/block/course/core etc strings. * * @param string $component * @param int $contextlevel * @return string|bool String is success, false if failed */ function get_component_string($component, $contextlevel) { if ($component === 'moodle' or $component === 'core') { switch ($contextlevel) { // TODO: this should probably use context level names instead case CONTEXT_SYSTEM: return get_string('coresystem'); case CONTEXT_USER: return get_string('users'); case CONTEXT_COURSECAT: return get_string('categories'); case CONTEXT_COURSE: return get_string('course'); case CONTEXT_MODULE: return get_string('activities'); case CONTEXT_BLOCK: return get_string('block'); default: print_error('unknowncontext'); } } list($type, $name) = core_component::normalize_component($component); $dir = core_component::get_plugin_directory($type, $name); if (!file_exists($dir)) { // plugin not installed, bad luck, there is no way to find the name return $component.' ???'; } switch ($type) { // TODO: this is really hacky, anyway it should be probably moved to lib/pluginlib.php case 'quiz': return get_string($name.':componentname', $component);// insane hack!!! case 'repository': return get_string('repository', 'repository').': '.get_string('pluginname', $component); case 'gradeimport': return get_string('gradeimport', 'grades').': '.get_string('pluginname', $component); case 'gradeexport': return get_string('gradeexport', 'grades').': '.get_string('pluginname', $component); case 'gradereport': return get_string('gradereport', 'grades').': '.get_string('pluginname', $component); case 'webservice': return get_string('webservice', 'webservice').': '.get_string('pluginname', $component); case 'block': return get_string('block').': '.get_string('pluginname', basename($component)); case 'mod': if (get_string_manager()->string_exists('pluginname', $component)) { return get_string('activity').': '.get_string('pluginname', $component); } else { return get_string('activity').': '.get_string('modulename', $component); } default: return get_string('pluginname', $component); } }
/** * Checks whether a plugin supports a specified feature. * * @param string $type Plugin type e.g. 'mod' * @param string $name Plugin name e.g. 'forum' * @param string $feature Feature code (FEATURE_xx constant) * @param mixed $default default value if feature support unknown * @return mixed Feature result (false if not supported, null if feature is unknown, * otherwise usually true but may have other feature-specific value such as array) * @throws coding_exception */ function plugin_supports($type, $name, $feature, $default = null) { global $CFG; if ($type === 'mod' and $name === 'NEWMODULE') { // Somebody forgot to rename the module template. return false; } $component = clean_param($type . '_' . $name, PARAM_COMPONENT); if (empty($component)) { throw new coding_exception('Invalid component used in plugin_supports():' . $type . '_' . $name); } $function = null; if ($type === 'mod') { // We need this special case because we support subplugins in modules, // otherwise it would end up in infinite loop. if (file_exists("{$CFG->dirroot}/mod/{$name}/lib.php")) { include_once "{$CFG->dirroot}/mod/{$name}/lib.php"; $function = $component . '_supports'; if (!function_exists($function)) { // Legacy non-frankenstyle function name. $function = $name . '_supports'; } } } else { if (!($path = core_component::get_plugin_directory($type, $name))) { // Non existent plugin type. return false; } if (file_exists("{$path}/lib.php")) { include_once "{$path}/lib.php"; $function = $component . '_supports'; } } if ($function and function_exists($function)) { $supports = $function($feature); if (is_null($supports)) { // Plugin does not know - use default. return $default; } else { return $supports; } } // Plugin does not care, so use default. return $default; }
/** * upgrades the mnet rpc definitions for the given component. * this method doesn't return status, an exception will be thrown in the case of an error * * @param string $component the plugin to upgrade, eg auth_mnet */ function upgrade_plugin_mnet_functions($component) { global $DB, $CFG; list($type, $plugin) = core_component::normalize_component($component); $path = core_component::get_plugin_directory($type, $plugin); $publishes = array(); $subscribes = array(); if (file_exists($path . '/db/mnet.php')) { require_once($path . '/db/mnet.php'); // $publishes comes from this file } if (empty($publishes)) { $publishes = array(); // still need this to be able to disable stuff later } if (empty($subscribes)) { $subscribes = array(); // still need this to be able to disable stuff later } static $servicecache = array(); // rekey an array based on the rpc method for easy lookups later $publishmethodservices = array(); $subscribemethodservices = array(); foreach($publishes as $servicename => $service) { if (is_array($service['methods'])) { foreach($service['methods'] as $methodname) { $service['servicename'] = $servicename; $publishmethodservices[$methodname][] = $service; } } } // Disable functions that don't exist (any more) in the source // Should these be deleted? What about their permissions records? foreach ($DB->get_records('mnet_rpc', array('pluginname'=>$plugin, 'plugintype'=>$type), 'functionname ASC ') as $rpc) { if (!array_key_exists($rpc->functionname, $publishmethodservices) && $rpc->enabled) { $DB->set_field('mnet_rpc', 'enabled', 0, array('id' => $rpc->id)); } else if (array_key_exists($rpc->functionname, $publishmethodservices) && !$rpc->enabled) { $DB->set_field('mnet_rpc', 'enabled', 1, array('id' => $rpc->id)); } } // reflect all the services we're publishing and save them require_once($CFG->dirroot . '/lib/zend/Zend/Server/Reflection.php'); static $cachedclasses = array(); // to store reflection information in foreach ($publishes as $service => $data) { $f = $data['filename']; $c = $data['classname']; foreach ($data['methods'] as $method) { $dataobject = new stdClass(); $dataobject->plugintype = $type; $dataobject->pluginname = $plugin; $dataobject->enabled = 1; $dataobject->classname = $c; $dataobject->filename = $f; if (is_string($method)) { $dataobject->functionname = $method; } else if (is_array($method)) { // wants to override file or class $dataobject->functionname = $method['method']; $dataobject->classname = $method['classname']; $dataobject->filename = $method['filename']; } $dataobject->xmlrpcpath = $type.'/'.$plugin.'/'.$dataobject->filename.'/'.$method; $dataobject->static = false; require_once($path . '/' . $dataobject->filename); $functionreflect = null; // slightly different ways to get this depending on whether it's a class method or a function if (!empty($dataobject->classname)) { if (!class_exists($dataobject->classname)) { throw new moodle_exception('installnosuchmethod', 'mnet', '', (object)array('method' => $dataobject->functionname, 'class' => $dataobject->classname)); } $key = $dataobject->filename . '|' . $dataobject->classname; if (!array_key_exists($key, $cachedclasses)) { // look to see if we've already got a reflection object try { $cachedclasses[$key] = Zend_Server_Reflection::reflectClass($dataobject->classname); } catch (Zend_Server_Reflection_Exception $e) { // catch these and rethrow them to something more helpful throw new moodle_exception('installreflectionclasserror', 'mnet', '', (object)array('method' => $dataobject->functionname, 'class' => $dataobject->classname, 'error' => $e->getMessage())); } } $r =& $cachedclasses[$key]; if (!$r->hasMethod($dataobject->functionname)) { throw new moodle_exception('installnosuchmethod', 'mnet', '', (object)array('method' => $dataobject->functionname, 'class' => $dataobject->classname)); } // stupid workaround for zend not having a getMethod($name) function $ms = $r->getMethods(); foreach ($ms as $m) { if ($m->getName() == $dataobject->functionname) { $functionreflect = $m; break; } } $dataobject->static = (int)$functionreflect->isStatic(); } else { if (!function_exists($dataobject->functionname)) { throw new moodle_exception('installnosuchfunction', 'mnet', '', (object)array('method' => $dataobject->functionname, 'file' => $dataobject->filename)); } try { $functionreflect = Zend_Server_Reflection::reflectFunction($dataobject->functionname); } catch (Zend_Server_Reflection_Exception $e) { // catch these and rethrow them to something more helpful throw new moodle_exception('installreflectionfunctionerror', 'mnet', '', (object)array('method' => $dataobject->functionname, '' => $dataobject->filename, 'error' => $e->getMessage())); } } $dataobject->profile = serialize(admin_mnet_method_profile($functionreflect)); $dataobject->help = $functionreflect->getDescription(); if ($record_exists = $DB->get_record('mnet_rpc', array('xmlrpcpath'=>$dataobject->xmlrpcpath))) { $dataobject->id = $record_exists->id; $dataobject->enabled = $record_exists->enabled; $DB->update_record('mnet_rpc', $dataobject); } else { $dataobject->id = $DB->insert_record('mnet_rpc', $dataobject, true); } // TODO this API versioning must be reworked, here the recently processed method // sets the service API which may not be correct foreach ($publishmethodservices[$dataobject->functionname] as $service) { if ($serviceobj = $DB->get_record('mnet_service', array('name'=>$service['servicename']))) { $serviceobj->apiversion = $service['apiversion']; $DB->update_record('mnet_service', $serviceobj); } else { $serviceobj = new stdClass(); $serviceobj->name = $service['servicename']; $serviceobj->description = empty($service['description']) ? '' : $service['description']; $serviceobj->apiversion = $service['apiversion']; $serviceobj->offer = 1; $serviceobj->id = $DB->insert_record('mnet_service', $serviceobj); } $servicecache[$service['servicename']] = $serviceobj; if (!$DB->record_exists('mnet_service2rpc', array('rpcid'=>$dataobject->id, 'serviceid'=>$serviceobj->id))) { $obj = new stdClass(); $obj->rpcid = $dataobject->id; $obj->serviceid = $serviceobj->id; $DB->insert_record('mnet_service2rpc', $obj, true); } } } } // finished with methods we publish, now do subscribable methods foreach($subscribes as $service => $methods) { if (!array_key_exists($service, $servicecache)) { if (!$serviceobj = $DB->get_record('mnet_service', array('name' => $service))) { debugging("TODO: skipping unknown service $service - somebody needs to fix MDL-21993"); continue; } $servicecache[$service] = $serviceobj; } else { $serviceobj = $servicecache[$service]; } foreach ($methods as $method => $xmlrpcpath) { if (!$rpcid = $DB->get_field('mnet_remote_rpc', 'id', array('xmlrpcpath'=>$xmlrpcpath))) { $remoterpc = (object)array( 'functionname' => $method, 'xmlrpcpath' => $xmlrpcpath, 'plugintype' => $type, 'pluginname' => $plugin, 'enabled' => 1, ); $rpcid = $remoterpc->id = $DB->insert_record('mnet_remote_rpc', $remoterpc, true); } if (!$DB->record_exists('mnet_remote_service2rpc', array('rpcid'=>$rpcid, 'serviceid'=>$serviceobj->id))) { $obj = new stdClass(); $obj->rpcid = $rpcid; $obj->serviceid = $serviceobj->id; $DB->insert_record('mnet_remote_service2rpc', $obj, true); } $subscribemethodservices[$method][] = $service; } } foreach ($DB->get_records('mnet_remote_rpc', array('pluginname'=>$plugin, 'plugintype'=>$type), 'functionname ASC ') as $rpc) { if (!array_key_exists($rpc->functionname, $subscribemethodservices) && $rpc->enabled) { $DB->set_field('mnet_remote_rpc', 'enabled', 0, array('id' => $rpc->id)); } else if (array_key_exists($rpc->functionname, $subscribemethodservices) && !$rpc->enabled) { $DB->set_field('mnet_remote_rpc', 'enabled', 1, array('id' => $rpc->id)); } } return true; }
/** * Get the test helper class for a particular question type. * @param $qtype the question type name, e.g. 'multichoice'. * @return question_test_helper the test helper class. */ public static function get_test_helper($qtype) { global $CFG; if (array_key_exists($qtype, self::$testhelpers)) { return self::$testhelpers[$qtype]; } $file = core_component::get_plugin_directory('qtype', $qtype) . '/tests/helper.php'; if (!is_readable($file)) { throw new coding_exception('Question type ' . $qtype . ' does not have test helper code.'); } include_once $file; $class = 'qtype_' . $qtype . '_test_helper'; if (!class_exists($class)) { throw new coding_exception('Class ' . $class . ' is not defined in ' . $file); } self::$testhelpers[$qtype] = new $class(); return self::$testhelpers[$qtype]; }
/** * Returns the exact absolute path to plugin directory. * * @deprecated since 2.6, use core_component::get_plugin_directory() * * @param string $plugintype type of plugin * @param string $name name of the plugin * @return string full path to plugin directory; NULL if not found */ function get_plugin_directory($plugintype, $name) { // NOTE: do not add any other debugging here, keep forever. if ($plugintype === '') { $plugintype = 'mod'; } return core_component::get_plugin_directory($plugintype, $name); }
/** * Resolves the real font location. * * @param string $font name of font file * @param string $component * @return string full file path */ public function resolve_font_location($font, $component) { global $CFG; if ($component === 'moodle' or $component === 'core' or empty($component)) { if (file_exists("{$this->dir}/fonts_core/{$font}")) { return "{$this->dir}/fonts_core/{$font}"; } foreach (array_reverse($this->parent_configs) as $parent_config) { // Base first, the immediate parent last. if (file_exists("{$parent_config->dir}/fonts_core/{$font}")) { return "{$parent_config->dir}/fonts_core/{$font}"; } } if (file_exists("{$CFG->dataroot}/fonts/{$font}")) { return "{$CFG->dataroot}/fonts/{$font}"; } if (file_exists("{$CFG->dirroot}/lib/fonts/{$font}")) { return "{$CFG->dirroot}/lib/fonts/{$font}"; } return null; } else { if ($component === 'theme') { // Exception. if (file_exists("{$this->dir}/fonts/{$font}")) { return "{$this->dir}/fonts/{$font}"; } foreach (array_reverse($this->parent_configs) as $parent_config) { // Base first, the immediate parent last. if (file_exists("{$parent_config->dir}/fonts/{$font}")) { return "{$parent_config->dir}/fonts/{$font}"; } } return null; } else { if (strpos($component, '_') === false) { $component = 'mod_' . $component; } list($type, $plugin) = explode('_', $component, 2); if (file_exists("{$this->dir}/fonts_plugins/{$type}/{$plugin}/{$font}")) { return "{$this->dir}/fonts_plugins/{$type}/{$plugin}/{$font}"; } foreach (array_reverse($this->parent_configs) as $parent_config) { // Base first, the immediate parent last. if (file_exists("{$parent_config->dir}/fonts_plugins/{$type}/{$plugin}/{$font}")) { return "{$parent_config->dir}/fonts_plugins/{$type}/{$plugin}/{$font}"; } } if (file_exists("{$CFG->dataroot}/fonts_plugins/{$type}/{$plugin}/{$font}")) { return "{$CFG->dataroot}/fonts_plugins/{$type}/{$plugin}/{$font}"; } $dir = core_component::get_plugin_directory($type, $plugin); if (file_exists("{$dir}/fonts/{$font}")) { return "{$dir}/fonts/{$font}"; } return null; } } }
/** * Checks if the given component's directory is writable * * For the purpose of the deployment, the web server process has to have * write access to all files in the component's directory (recursively) and for the * directory itself. * * @see worker::move_directory_source_precheck() * @param string $component normalized component name * @return boolean */ protected function component_writable($component) { list($plugintype, $pluginname) = core_component::normalize_component($component); $directory = core_component::get_plugin_directory($plugintype, $pluginname); if (is_null($directory)) { throw new coding_exception('Unknown component location', $component); } return $this->directory_writable($directory); }
/** * Returns whether the grade item can control the visibility of the grades * * @return bool */ public function can_control_visibility() { if (core_component::get_plugin_directory($this->itemtype, $this->itemmodule)) { return !plugin_supports($this->itemtype, $this->itemmodule, FEATURE_CONTROLS_GRADE_VISIBILITY, false); } return parent::can_control_visibility(); }
public function test_deprecated_get_plugin_directory() { $plugintypes = core_component::get_plugin_types(); foreach ($plugintypes as $plugintype => $fulldir) { $plugins = core_component::get_plugin_list($plugintype); foreach ($plugins as $pluginname => $plugindir) { $this->assertSame(core_component::get_plugin_directory($plugintype, $pluginname), get_plugin_directory($plugintype, $pluginname)); } } }
/** * elis_versions method to get all ELIS PM and component version info * @return string */ protected function elis_versions() { global $CFG; $ret = html_writer::script("function toggle_elis_component_versions() {\n var compdiv;\n if (compdiv = document.getElementById('eliscomponentversions')) {\n if (compdiv.className.indexOf('accesshide') != -1) {\n compdiv.className = '';\n } else {\n compdiv.className = 'accesshide';\n }\n }\n }"); $ret .= html_writer::tag('p', get_string('elispmversion', 'local_elisprogram', elispm::$release) . ' ' . html_writer::empty_tag('input', array('type' => 'button', 'value' => get_string('alleliscomponents', 'local_elisprogram'), 'onclick' => 'toggle_elis_component_versions();'))); $eliscomponents = array('block_elisadmin' => null, 'block_courserequest' => null, 'block_enrolsurvey' => null, 'block_repository' => null, 'enrol_elis' => null, 'local_eliscore' => null, 'local_elisprogram' => null, 'local_elisreports' => null, 'local_datahub' => null, 'auth_elisfilessso' => null, 'repository_elisfiles' => null, 'lib_tcpdf' => array($this, 'get_tcpdf_info'), 'lib_pChart' => array($this, 'get_pchart_info'), 'lib_jquery1' => array($this, 'get_re_jquery_info'), 'lib_jquery_ui1' => array($this, 'get_re_jquery_ui_info'), 'lib_jquery2' => array($this, 'get_ds_jquery_info'), 'lib_jquery_ui2' => array($this, 'get_ds_jquery_ui_info')); $componenttable = new html_table(); $componenttable->attributes = array('width' => '70%', 'border' => '0'); $componenttable->head = array(get_string('eliscomponent', 'local_elisprogram'), get_string('eliscomponentrelease', 'local_elisprogram'), get_string('eliscomponentversion', 'local_elisprogram')); $componenttable->data = array(); foreach ($eliscomponents as $eliscomponent => $getinfocallback) { list($plugintype, $pluginname) = explode('_', $eliscomponent); if (!empty($getinfocallback)) { list($componentname, $release, $version) = call_user_func($getinfocallback); // error_log("elis_versions(): {$componentname}, {$release}, {$version}"); if (!empty($componentname)) { $thirdpartylib = get_string('thirdpartylib', 'local_elisprogram'); $componenttable->data[] = array("{$componentname} {$thirdpartylib}", $release, $version); } } else { if (($compdir = core_component::get_plugin_directory($plugintype, $pluginname)) && file_exists($compdir . '/version.php')) { $plugin = new stdClass(); require $compdir . '/version.php'; if (!empty($plugin->version)) { $version = $plugin->version; $release = !empty($plugin->release) ? $plugin->release : ''; $componenttable->data[] = array($eliscomponent, $release, $version); } } } } $ret .= html_writer::tag('div', html_writer::table($componenttable), array('id' => 'eliscomponentversions', 'class' => 'accesshide')); return $ret; }
/** * Get String returns a requested string * * @param string $identifier The identifier of the string to search for * @param string $component The module the string is associated with * @param string|object|array $a An object, string or number that can be used * within translation strings * @param string $lang moodle translation language, null means use current * @return string The String ! */ public function get_string($identifier, $component = '', $a = null, $lang = null) { global $CFG; $this->countgetstring++; // There are very many uses of these time formatting strings without the 'langconfig' component, // it would not be reasonable to expect that all of them would be converted during 2.0 migration. static $langconfigstrs = array('strftimedate' => 1, 'strftimedatefullshort' => 1, 'strftimedateshort' => 1, 'strftimedatetime' => 1, 'strftimedatetimeshort' => 1, 'strftimedaydate' => 1, 'strftimedaydatetime' => 1, 'strftimedayshort' => 1, 'strftimedaytime' => 1, 'strftimemonthyear' => 1, 'strftimerecent' => 1, 'strftimerecentfull' => 1, 'strftimetime' => 1); if (empty($component)) { if (isset($langconfigstrs[$identifier])) { $component = 'langconfig'; } else { $component = 'moodle'; } } if ($lang === null) { $lang = current_language(); } $string = $this->load_component_strings($component, $lang); if (!isset($string[$identifier])) { if ($component === 'pix' or $component === 'core_pix') { // This component contains only alt tags for emoticons, not all of them are supposed to be defined. return ''; } if ($identifier === 'parentlanguage' and ($component === 'langconfig' or $component === 'core_langconfig')) { // Identifier parentlanguage is a special string, undefined means use English if not defined. return 'en'; } // Do not rebuild caches here! // Devs need to learn to purge all caches after any change or disable $CFG->langstringcache. if (!isset($string[$identifier])) { // The string is still missing - should be fixed by developer. if ($CFG->debugdeveloper) { list($plugintype, $pluginname) = core_component::normalize_component($component); if ($plugintype === 'core') { $file = "lang/en/{$component}.php"; } else { if ($plugintype == 'mod') { $file = "mod/{$pluginname}/lang/en/{$pluginname}.php"; } else { $path = core_component::get_plugin_directory($plugintype, $pluginname); $file = "{$path}/lang/en/{$plugintype}_{$pluginname}.php"; } } debugging("Invalid get_string() identifier: '{$identifier}' or component '{$component}'. " . "Perhaps you are missing \$string['{$identifier}'] = ''; in {$file}?", DEBUG_DEVELOPER); } return "[[{$identifier}]]"; } } $string = $string[$identifier]; if ($a !== null) { // Process array's and objects (except lang_strings). if (is_array($a) or is_object($a) && !$a instanceof lang_string) { $a = (array) $a; $search = array(); $replace = array(); foreach ($a as $key => $value) { if (is_int($key)) { // We do not support numeric keys - sorry! continue; } if (is_array($value) or is_object($value) && !$value instanceof lang_string) { // We support just string or lang_string as value. continue; } $search[] = '{$a->' . $key . '}'; $replace[] = (string) $value; } if ($search) { $string = str_replace($search, $replace, $string); } } else { $string = str_replace('{$a}', (string) $a, $string); } } if ($CFG->debugdeveloper) { // Display a debugging message if sting exists but was deprecated. if ($this->string_deprecated($identifier, $component)) { list($plugintype, $pluginname) = core_component::normalize_component($component); $normcomponent = $pluginname ? $plugintype . '_' . $pluginname : $plugintype; debugging("String [{$identifier},{$normcomponent}] is deprecated. " . 'Either you should no longer be using that string, or the string has been incorrectly deprecated, in which case you should report this as a bug. ' . 'Please refer to https://docs.moodle.org/dev/String_deprecation', DEBUG_DEVELOPER); } } return $string; }
/** * @param stdClass $comment * @param stdClass $options * @throws comment_exception */ function mod_hsuforum_comment_message(stdClass $comment, stdClass $options) { global $DB; if ($options->commentarea != 'userposts_comments') { throw new comment_exception('invalidcommentarea'); } if (!($user = $DB->get_record('user', array('id' => $options->itemid)))) { throw new comment_exception('invalidcommentitemid'); } /** @var context $context */ $context = $options->context; if (!($cm = get_coursemodule_from_id('hsuforum', $context->instanceid))) { throw new comment_exception('invalidcontext'); } // Get all the users with the ability to rate. $recipients = get_users_by_capability($context, 'mod/hsuforum:rate'); // Add the item user if they are different from commenter. if ($comment->userid != $user->id and has_capability('mod/hsuforum:replypost', $context, $user)) { $recipients[$user->id] = $user; } // Sender is the author of the comment. $sender = $DB->get_record('user', array('id' => $comment->userid)); // Make sure that the commenter is not getting the message. unset($recipients[$comment->userid]); if (\core_component::get_plugin_directory('local', 'joulegrader') !== null) { // Joule Grader is installed and control panel enabled. $gareaid = component_callback('local_joulegrader', 'area_from_context', array($context, 'hsuforum')); $contexturl = new moodle_url('/local/joulegrader/view.php', array('courseid' => $cm->course, 'garea' => $gareaid, 'guser' => $user->id)); } else { $contexturl = $context->get_url(); } $params = array($comment, $recipients, $sender, $cm->name, $contexturl); component_callback('local_mrooms', 'comment_send_messages', $params); }
/** * Figure out exactly what needs to be called and stashes it in $remoteclient * Does some further verification that the method is callable * * @param string $method the full xmlrpc method that was called eg auth/mnet/auth.php/user_authorise * @param array $callstack the exploded callstack * @param stdclass $rpcrecord the record from mnet_rpc * * @throws mnet_server_exception */ function mnet_setup_dummy_method($method, $callstack, $rpcrecord) { global $CFG; $remoteclient = get_mnet_remote_client(); // verify that the callpath in the stack matches our records // callstack will look like array('mod', 'forum', 'lib.php', 'forum_add_instance'); $path = core_component::get_plugin_directory($rpcrecord->plugintype, $rpcrecord->pluginname); $path = substr($path, strlen($CFG->dirroot) + 1); // this is a bit hacky and fragile, it is not guaranteed that plugins are in dirroot array_pop($callstack); $providedpath = implode('/', $callstack); if ($providedpath != $path . '/' . $rpcrecord->filename) { throw new mnet_server_exception(705, "nosuchfile"); } if (!file_exists($CFG->dirroot . '/' . $providedpath)) { throw new mnet_server_exception(705, "nosuchfile"); } require_once $CFG->dirroot . '/' . $providedpath; if (!empty($rpcrecord->classname)) { if (!class_exists($rpcrecord->classname)) { throw new mnet_server_exception(708, 'nosuchclass'); } if (!$rpcrecord->static) { try { $object = new $rpcrecord->classname(); } catch (Exception $e) { throw new mnet_server_exception(709, "classerror"); } if (!is_callable(array($object, $rpcrecord->functionname))) { throw new mnet_server_exception(706, "nosuchfunction"); } $remoteclient->object_to_call($object); } else { if (!is_callable(array($rpcrecord->classname, $rpcrecord->functionname))) { throw new mnet_server_exception(706, "nosuchfunction"); } $remoteclient->static_location($rpcrecord->classname); } } }
/** * Automatically clean-up all plugin data and remove the plugin DB tables * * NOTE: do not call directly, use new /admin/plugins.php?uninstall=component instead! * * @param string $type The plugin type, eg. 'mod', 'qtype', 'workshopgrading' etc. * @param string $name The plugin name, eg. 'forum', 'multichoice', 'accumulative' etc. * @uses global $OUTPUT to produce notices and other messages * @return void */ function uninstall_plugin($type, $name) { global $CFG, $DB, $OUTPUT; // This may take a long time. core_php_time_limit::raise(); // Recursively uninstall all subplugins first. $subplugintypes = core_component::get_plugin_types_with_subplugins(); if (isset($subplugintypes[$type])) { $base = core_component::get_plugin_directory($type, $name); if (file_exists("{$base}/db/subplugins.php")) { $subplugins = array(); include "{$base}/db/subplugins.php"; foreach ($subplugins as $subplugintype => $dir) { $instances = core_component::get_plugin_list($subplugintype); foreach ($instances as $subpluginname => $notusedpluginpath) { uninstall_plugin($subplugintype, $subpluginname); } } } } $component = $type . '_' . $name; // eg. 'qtype_multichoice' or 'workshopgrading_accumulative' or 'mod_forum' if ($type === 'mod') { $pluginname = $name; // eg. 'forum' if (get_string_manager()->string_exists('modulename', $component)) { $strpluginname = get_string('modulename', $component); } else { $strpluginname = $component; } } else { $pluginname = $component; if (get_string_manager()->string_exists('pluginname', $component)) { $strpluginname = get_string('pluginname', $component); } else { $strpluginname = $component; } } echo $OUTPUT->heading($pluginname); // Delete all tag instances associated with this plugin. require_once $CFG->dirroot . '/tag/lib.php'; tag_delete_instances($component); // Custom plugin uninstall. $plugindirectory = core_component::get_plugin_directory($type, $name); $uninstalllib = $plugindirectory . '/db/uninstall.php'; if (file_exists($uninstalllib)) { require_once $uninstalllib; $uninstallfunction = 'xmldb_' . $pluginname . '_uninstall'; // eg. 'xmldb_workshop_uninstall()' if (function_exists($uninstallfunction)) { // Do not verify result, let plugin complain if necessary. $uninstallfunction(); } } // Specific plugin type cleanup. $plugininfo = core_plugin_manager::instance()->get_plugin_info($component); if ($plugininfo) { $plugininfo->uninstall_cleanup(); core_plugin_manager::reset_caches(); } $plugininfo = null; // perform clean-up task common for all the plugin/subplugin types //delete the web service functions and pre-built services require_once $CFG->dirroot . '/lib/externallib.php'; external_delete_descriptions($component); // delete calendar events $DB->delete_records('event', array('modulename' => $pluginname)); // Delete scheduled tasks. $DB->delete_records('task_scheduled', array('component' => $pluginname)); // Delete Inbound Message datakeys. $DB->delete_records_select('messageinbound_datakeys', 'handler IN (SELECT id FROM {messageinbound_handlers} WHERE component = ?)', array($pluginname)); // Delete Inbound Message handlers. $DB->delete_records('messageinbound_handlers', array('component' => $pluginname)); // delete all the logs $DB->delete_records('log', array('module' => $pluginname)); // delete log_display information $DB->delete_records('log_display', array('component' => $component)); // delete the module configuration records unset_all_config_for_plugin($component); if ($type === 'mod') { unset_all_config_for_plugin($pluginname); } // delete message provider message_provider_uninstall($component); // delete the plugin tables $xmldbfilepath = $plugindirectory . '/db/install.xml'; drop_plugin_tables($component, $xmldbfilepath, false); if ($type === 'mod' or $type === 'block') { // non-frankenstyle table prefixes drop_plugin_tables($name, $xmldbfilepath, false); } // delete the capabilities that were defined by this module capabilities_cleanup($component); // remove event handlers and dequeue pending events events_uninstall($component); // Delete all remaining files in the filepool owned by the component. $fs = get_file_storage(); $fs->delete_component_files($component); // Finally purge all caches. purge_all_caches(); // Invalidate the hash used for upgrade detections. set_config('allversionshash', ''); echo $OUTPUT->notification(get_string('success'), 'notifysuccess'); }
/** * Given a specific page type, parent context and currect context, return all the page type patterns * that might be used by this block. * * @param string $pagetype for example 'course-view-weeks' or 'mod-quiz-view'. * @param stdClass $parentcontext Block's parent context * @param stdClass $currentcontext Current context of block * @return array an array of all the page type patterns that might match this page type. */ function generate_page_type_patterns($pagetype, $parentcontext = null, $currentcontext = null) { global $CFG; // Required for includes bellow. $bits = explode('-', $pagetype); $core = core_component::get_core_subsystems(); $plugins = core_component::get_plugin_types(); //progressively strip pieces off the page type looking for a match $componentarray = null; for ($i = count($bits); $i > 0; $i--) { $possiblecomponentarray = array_slice($bits, 0, $i); $possiblecomponent = implode('', $possiblecomponentarray); // Check to see if the component is a core component if (array_key_exists($possiblecomponent, $core) && !empty($core[$possiblecomponent])) { $libfile = $core[$possiblecomponent] . '/lib.php'; if (file_exists($libfile)) { require_once $libfile; $function = $possiblecomponent . '_page_type_list'; if (function_exists($function)) { if ($patterns = $function($pagetype, $parentcontext, $currentcontext)) { break; } } } } //check the plugin directory and look for a callback if (array_key_exists($possiblecomponent, $plugins) && !empty($plugins[$possiblecomponent])) { //We've found a plugin type. Look for a plugin name by getting the next section of page type if (count($bits) > $i) { $pluginname = $bits[$i]; $directory = core_component::get_plugin_directory($possiblecomponent, $pluginname); if (!empty($directory)) { $libfile = $directory . '/lib.php'; if (file_exists($libfile)) { require_once $libfile; $function = $possiblecomponent . '_' . $pluginname . '_page_type_list'; if (!function_exists($function)) { $function = $pluginname . '_page_type_list'; } if (function_exists($function)) { if ($patterns = $function($pagetype, $parentcontext, $currentcontext)) { break; } } } } } //we'll only get to here if we still don't have any patterns //the plugin type may have a callback $directory = $plugins[$possiblecomponent]; $libfile = $directory . '/lib.php'; if (file_exists($libfile)) { require_once $libfile; $function = $possiblecomponent . '_page_type_list'; if (function_exists($function)) { if ($patterns = $function($pagetype, $parentcontext, $currentcontext)) { break; } } } } } if (empty($patterns)) { $patterns = default_page_type_list($pagetype, $parentcontext, $currentcontext); } // Ensure that the * pattern is always available if editing block 'at distance', so // we always can 'bring back' it to the original context. MDL-30340 if ((!isset($currentcontext) or !isset($parentcontext) or $currentcontext->id != $parentcontext->id) && !isset($patterns['*'])) { // TODO: We could change the string here, showing its 'bring back' meaning $patterns['*'] = get_string('page-x', 'pagetype'); } return $patterns; }
} else { // Either a device has been selected of $CFG->enabledevicedetection is off so display a list // of themes to select. $heading = get_string('selecttheme', 'admin', $device); if (empty($device)) { // If $CFG->enabledevicedetection is off this will return 'default'. $device = core_useragent::get_device_type(); } $themelocked = theme_is_device_locked($device); $table->id = 'adminthemeselector'; $table->head = array(get_string('theme'), get_string('info')); $themes = array(); if ($themelocked) { $heading = get_string('currenttheme', 'admin'); $themename = theme_get_locked_theme_for_device($device); $themedirectory = core_component::get_plugin_directory('theme', $themename); $themes[$themename] = $themedirectory; } else { $themes = core_component::get_plugin_list('theme'); } foreach ($themes as $themename => $themedir) { // Load the theme config. try { $theme = theme_config::load($themename); } catch (Exception $e) { // Bad theme, just skip it for now. continue; } if ($themename !== $theme->name) { // Obsoleted or broken theme, just skip for now. continue;
); // then div wrapper for xhtml strictness $output = html_writer::tag('div', $output); // now the form itself around it $formattributes = array( 'method' => $select->method, 'action' => $select->url->out_omit_querystring(), 'id' => $select->formid ); $output = html_writer::tag('form', $output, $formattributes); // and finally one more wrapper with class return html_writer::tag('div', $output, array('class' => $select->class)); } } /** * Overridden choice module renderer for the mymobile theme * * @package theme_mymobile * @copyright John Stabinger * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ $choice = core_component::get_plugin_directory('mod', 'choice'); if (file_exists($choice . '/renderer.php')) { require_once($CFG->dirroot . '/theme/mymobile/renderers/mod_choice_renderer.php'); }