本文整理汇总了PHP中get_component_directory函数的典型用法代码示例。如果您正苦于以下问题:PHP get_component_directory函数的具体用法?PHP get_component_directory怎么用?PHP get_component_directory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_component_directory函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: external_function_info
/**
* Returns detailed function information
* @param string|object $function name of external function or record from external_function
* @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found;
* MUST_EXIST means throw exception if no record or multiple records found
* @return object description or false if not found or exception thrown
*/
function external_function_info($function, $strictness=MUST_EXIST) {
global $DB, $CFG;
if (!is_object($function)) {
if (!$function = $DB->get_record('external_functions', array('name'=>$function), '*', $strictness)) {
return false;
}
}
//first find and include the ext implementation class
$function->classpath = empty($function->classpath) ? get_component_directory($function->component).'/externallib.php' : $CFG->dirroot.'/'.$function->classpath;
if (!file_exists($function->classpath)) {
throw new coding_exception('Can not find file with external function implementation');
}
require_once($function->classpath);
$function->parameters_method = $function->methodname.'_parameters';
$function->returns_method = $function->methodname.'_returns';
// make sure the implementaion class is ok
if (!method_exists($function->classname, $function->methodname)) {
throw new coding_exception('Missing implementation method of '.$function->classname.'::'.$function->methodname);
}
if (!method_exists($function->classname, $function->parameters_method)) {
throw new coding_exception('Missing parameters description');
}
if (!method_exists($function->classname, $function->returns_method)) {
throw new coding_exception('Missing returned values description');
}
// fetch the parameters description
$function->parameters_desc = call_user_func(array($function->classname, $function->parameters_method));
if (!($function->parameters_desc instanceof external_function_parameters)) {
throw new coding_exception('Invalid parameters description');
}
// fetch the return values description
$function->returns_desc = call_user_func(array($function->classname, $function->returns_method));
// null means void result or result is ignored
if (!is_null($function->returns_desc) and !($function->returns_desc instanceof external_description)) {
throw new coding_exception('Invalid return description');
}
//now get the function description
//TODO: use localised lang pack descriptions, it would be nice to have
// easy to understand descriptions in admin UI,
// on the other hand this is still a bit in a flux and we need to find some new naming
// conventions for these descriptions in lang packs
$function->description = null;
$servicesfile = get_component_directory($function->component).'/db/services.php';
if (file_exists($servicesfile)) {
$functions = null;
include($servicesfile);
if (isset($functions[$function->name]['description'])) {
$function->description = $functions[$function->name]['description'];
}
}
return $function;
}
示例2: groups_add_member
/**
* Adds a specified user to a group
*
* @param mixed $grouporid The group id or group object
* @param mixed $userorid The user id or user object
* @param string $component Optional component name e.g. 'enrol_imsenterprise'
* @param int $itemid Optional itemid associated with component
* @return bool True if user added successfully or the user is already a
* member of the group, false otherwise.
*/
function groups_add_member($grouporid, $userorid, $component = null, $itemid = 0)
{
global $DB;
if (is_object($userorid)) {
$userid = $userorid->id;
$user = $userorid;
} else {
$userid = $userorid;
$user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
}
if (is_object($grouporid)) {
$groupid = $grouporid->id;
$group = $grouporid;
} else {
$groupid = $grouporid;
$group = $DB->get_record('groups', array('id' => $groupid), '*', MUST_EXIST);
}
//check if the user a participant of the group course
if (!is_enrolled(context_course::instance($group->courseid), $userid)) {
return false;
}
if (groups_is_member($groupid, $userid)) {
return true;
}
$member = new stdClass();
$member->groupid = $groupid;
$member->userid = $userid;
$member->timeadded = time();
$member->component = '';
$member->itemid = 0;
// Check the component exists if specified
if (!empty($component)) {
$dir = get_component_directory($component);
if ($dir && is_dir($dir)) {
// Component exists and can be used
$member->component = $component;
$member->itemid = $itemid;
} else {
throw new coding_exception('Invalid call to groups_add_member(). An invalid component was specified');
}
}
if ($itemid !== 0 && empty($member->component)) {
// An itemid can only be specified if a valid component was found
throw new coding_exception('Invalid call to groups_add_member(). A component must be specified if an itemid is given');
}
$DB->insert_record('groups_members', $member);
//update group info
$DB->set_field('groups', 'timemodified', $member->timeadded, array('id' => $groupid));
//trigger groups events
$eventdata = new stdClass();
$eventdata->groupid = $groupid;
$eventdata->userid = $userid;
$eventdata->component = $member->component;
$eventdata->itemid = $member->itemid;
events_trigger('groups_member_added', $eventdata);
return true;
}
示例3: events_load_def
/**
* Loads the events definitions for the component (from file). If no
* events are defined for the component, we simply return an empty array.
*
* INTERNAL - to be used from eventslib only
*
* @global object
* @param string $component examples: 'moodle', 'mod/forum', 'block/quiz_results'
* @return array of capabilities or empty array if not exists
*/
function events_load_def($component)
{
$defpath = get_component_directory($component) . '/db/events.php';
$handlers = array();
if (file_exists($defpath)) {
require $defpath;
}
return $handlers;
}
示例4: events_load_def
/**
* Loads the events definitions for the component (from file). If no
* events are defined for the component, we simply return an empty array.
*
* INTERNAL - to be used from eventslib only
*
* @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
* @return array of capabilities or empty array if not exists
*/
function events_load_def($component)
{
global $CFG;
if ($component === 'unittest') {
$defpath = $CFG->dirroot . '/lib/simpletest/fixtures/events.php';
} else {
$defpath = get_component_directory($component) . '/db/events.php';
}
$handlers = array();
if (file_exists($defpath)) {
require $defpath;
}
// make sure the definitions are valid and complete; tell devs what is wrong
foreach ($handlers as $eventname => $handler) {
if ($eventname === 'reset') {
debugging("'reset' can not be used as event name.");
unset($handlers['reset']);
continue;
}
if (!is_array($handler)) {
debugging("Handler of '{$eventname}' must be specified as array'");
unset($handlers[$eventname]);
continue;
}
if (!isset($handler['handlerfile'])) {
debugging("Handler of '{$eventname}' must include 'handlerfile' key'");
unset($handlers[$eventname]);
continue;
}
if (!isset($handler['handlerfunction'])) {
debugging("Handler of '{$eventname}' must include 'handlerfunction' key'");
unset($handlers[$eventname]);
continue;
}
if (!isset($handler['schedule'])) {
$handler['schedule'] = 'instant';
}
if ($handler['schedule'] !== 'instant' and $handler['schedule'] !== 'cron') {
debugging("Handler of '{$eventname}' must include valid 'schedule' type (instant or cron)'");
unset($handlers[$eventname]);
continue;
}
if (!isset($handler['internal'])) {
$handler['internal'] = 1;
}
$handlers[$eventname] = $handler;
}
return $handlers;
}
示例5: get_site_info
/**
* Return user information including profile picture + basic site information
* Note:
* - no capability checking because we return just known information by logged user
* @param array $serviceshortnames of service shortnames - the functions of these services will be returned
* @return array
*/
public function get_site_info($serviceshortnames = array())
{
global $USER, $SITE, $CFG;
$params = self::validate_parameters(self::get_site_info_parameters(), array('serviceshortnames' => $serviceshortnames));
$profileimageurl = moodle_url::make_pluginfile_url(get_context_instance(CONTEXT_USER, $USER->id)->id, 'user', 'icon', NULL, '/', 'f1');
require_once $CFG->dirroot . "/webservice/lib.php";
$webservice = new webservice();
//If no service listed always return the mobile one by default
if (empty($params['serviceshortnames']) and $CFG->enablewebservices) {
$mobileservice = $webservice->get_external_service_by_shortname(MOODLE_OFFICIAL_MOBILE_SERVICE);
if ($mobileservice->enabled) {
$params['serviceshortnames'] = array(MOODLE_OFFICIAL_MOBILE_SERVICE);
//return mobile service by default
}
}
//retrieve the functions related to the services
$functions = $webservice->get_external_functions_by_enabled_services($params['serviceshortnames']);
//built up the returned values of the list of functions
$componentversions = array();
$avalaiblefunctions = array();
foreach ($functions as $function) {
$functioninfo = array();
$functioninfo['name'] = $function->name;
if ($function->component == 'moodle') {
$version = $CFG->version;
//moodle version
} else {
$versionpath = get_component_directory($function->component) . '/version.php';
if (is_readable($versionpath)) {
//we store the component version once retrieved (so we don't load twice the version.php)
if (!isset($componentversions[$function->component])) {
include $versionpath;
$componentversions[$function->component] = $plugin->version;
$version = $plugin->version;
} else {
$version = $componentversions[$function->component];
}
} else {
//function component should always have a version.php,
//otherwise the function should have been described with component => 'moodle'
throw new moodle_exception('missingversionfile', 'webservice', '', $function->component);
}
}
$functioninfo['version'] = $version;
$avalaiblefunctions[] = $functioninfo;
}
return array('sitename' => $SITE->fullname, 'siteurl' => $CFG->wwwroot, 'username' => $USER->username, 'firstname' => $USER->firstname, 'lastname' => $USER->lastname, 'fullname' => fullname($USER), 'userid' => $USER->id, 'userpictureurl' => $profileimageurl->out(false), 'functions' => $avalaiblefunctions);
}
示例6: elis_tasks_load_def
/**
* Loads the task definitions for the component (from file). If no
* tasks are defined for the component, we simply return an empty array.
* @param $component - examples: 'moodle', 'mod_forum', 'block_quiz_results'
* @return array of tasks or empty array if not exists
*
* INTERNAL - to be used from cronlib only
*/
function elis_tasks_load_def($component)
{
global $CFG;
if ($component == 'moodle') {
$defpath = $CFG->libdir . '/db/tasks.php';
//} else if ($component == 'unittest') {
// $defpath = $CFG->libdir.'/simpletest/fixtures/tasks.php';
} else {
$defpath = get_component_directory($component) . '/db/tasks.php';
//error_log("/local/eliscore/lib/tasklib.php::elis_tasks_load_def('{$component}') looking for: {$defpath}");
}
$tasks = array();
if (file_exists($defpath)) {
require $defpath;
}
return $tasks;
}
示例7: get_moodle_metadata
/**
* Determine the module metadata for all moodle YUI modules.
*
* This works through all modules capable of serving YUI modules, and attempts to get
* metadata for each of those modules.
*
* @return Array of module metadata
*/
private function get_moodle_metadata()
{
$moodlemodules = array();
// Core isn't a plugin type or subsystem - handle it seperately.
if ($module = $this->get_moodle_path_metadata(get_component_directory('core'))) {
$moodlemodules = array_merge($moodlemodules, $module);
}
// Handle other core subsystems.
$subsystems = get_core_subsystems();
foreach ($subsystems as $subsystem => $path) {
if (is_null($path)) {
continue;
}
$path = get_component_directory($subsystem);
if ($module = $this->get_moodle_path_metadata($path)) {
$moodlemodules = array_merge($moodlemodules, $module);
}
}
// And finally the plugins.
$plugintypes = get_plugin_types();
foreach ($plugintypes as $plugintype => $pathroot) {
$pluginlist = get_plugin_list($plugintype);
foreach ($pluginlist as $plugin => $path) {
if ($module = $this->get_moodle_path_metadata($path)) {
$moodlemodules = array_merge($moodlemodules, $module);
}
}
}
return $moodlemodules;
}
示例8: find_module
/**
* Find out if JS module present and return details.
* @param string $component name of component in frankenstyle, ex: core_group, mod_forum
* @return array description of module or null if not found
*/
protected function find_module($component)
{
global $CFG;
$module = null;
if (strpos($component, 'core_') === 0) {
// must be some core stuff - list here is not complete, this is just the stuff used from multiple places
// so that we do nto have to repeat the definition of these modules over and over again
switch ($component) {
case 'core_filepicker':
$module = array('name' => 'core_filepicker', 'fullpath' => '/repository/filepicker.js', 'requires' => array('base', 'node', 'node-event-simulate', 'json', 'async-queue', 'io', 'yui2-button', 'yui2-container', 'yui2-layout', 'yui2-menu', 'yui2-treeview', 'yui2-dragdrop', 'yui2-cookie'), 'strings' => array(array('add', 'repository'), array('back', 'repository'), array('cancel', 'moodle'), array('close', 'repository'), array('cleancache', 'repository'), array('copying', 'repository'), array('date', 'repository'), array('downloadsucc', 'repository'), array('emptylist', 'repository'), array('error', 'repository'), array('federatedsearch', 'repository'), array('filenotnull', 'repository'), array('getfile', 'repository'), array('help', 'moodle'), array('iconview', 'repository'), array('invalidjson', 'repository'), array('linkexternal', 'repository'), array('listview', 'repository'), array('loading', 'repository'), array('login', 'repository'), array('logout', 'repository'), array('noenter', 'repository'), array('noresult', 'repository'), array('manageurl', 'repository'), array('popup', 'repository'), array('preview', 'repository'), array('refresh', 'repository'), array('save', 'repository'), array('saveas', 'repository'), array('saved', 'repository'), array('saving', 'repository'), array('search', 'repository'), array('searching', 'repository'), array('size', 'repository'), array('submit', 'repository'), array('sync', 'repository'), array('title', 'repository'), array('upload', 'repository'), array('uploading', 'repository'), array('xhtmlerror', 'repository'), array('cancel'), array('chooselicense', 'repository'), array('author', 'repository'), array('ok', 'moodle'), array('error', 'moodle'), array('info', 'moodle'), array('norepositoriesavailable', 'repository'), array('norepositoriesexternalavailable', 'repository'), array('nofilesattached', 'repository'), array('filepicker', 'repository'), array('nofilesavailable', 'repository'), array('overwrite', 'repository'), array('renameto', 'repository'), array('fileexists', 'repository'), array('fileexistsdialogheader', 'repository'), array('fileexistsdialog_editor', 'repository'), array('fileexistsdialog_filemanager', 'repository')));
break;
case 'core_comment':
$module = array('name' => 'core_comment', 'fullpath' => '/comment/comment.js', 'requires' => array('base', 'io', 'node', 'json', 'yui2-animation', 'overlay'), 'strings' => array(array('confirmdeletecomments', 'admin'), array('yes', 'moodle'), array('no', 'moodle')));
break;
case 'core_role':
$module = array('name' => 'core_role', 'fullpath' => '/admin/roles/module.js', 'requires' => array('node', 'cookie'));
break;
case 'core_completion':
$module = array('name' => 'core_completion', 'fullpath' => '/course/completion.js');
break;
case 'core_dock':
$module = array('name' => 'core_dock', 'fullpath' => '/blocks/dock.js', 'requires' => array('base', 'node', 'event-custom', 'event-mouseenter', 'event-resize'), 'strings' => array(array('addtodock', 'block'), array('undockitem', 'block'), array('undockall', 'block'), array('thisdirectionvertical', 'langconfig')));
break;
case 'core_message':
$module = array('name' => 'core_message', 'requires' => array('base', 'node', 'event', 'node-event-simulate'), 'fullpath' => '/message/module.js');
break;
case 'core_group':
$module = array('name' => 'core_group', 'fullpath' => '/group/module.js', 'requires' => array('node', 'overlay', 'event-mouseenter'));
break;
case 'core_question_engine':
$module = array('name' => 'core_question_engine', 'fullpath' => '/question/qengine.js', 'requires' => array('node', 'event'));
break;
case 'core_rating':
$module = array('name' => 'core_rating', 'fullpath' => '/rating/module.js', 'requires' => array('node', 'event', 'overlay', 'io', 'json'));
break;
case 'core_filetree':
$module = array('name' => 'core_filetree', 'fullpath' => '/files/module.js', 'requires' => array('node', 'event', 'overlay', 'io', 'json', 'yui2-treeview'));
break;
}
} else {
if ($dir = get_component_directory($component)) {
if (file_exists("{$dir}/module.js")) {
if (strpos($dir, $CFG->dirroot . '/') === 0) {
$dir = substr($dir, strlen($CFG->dirroot));
$module = array('name' => $component, 'fullpath' => "{$dir}/module.js", 'requires' => array());
}
}
}
}
return $module;
}
示例9: message_get_providers_from_file
/**
* Loads the messages definitions for a component from file
*
* If no messages are defined for the component, return an empty array.
* This is an internal function used within messagelib.php
*
* @see message_update_providers()
* @see message_update_processors()
* @param string $component A moodle component like 'moodle', 'mod_forum', 'block_quiz_results'
* @return array An array of message providers or empty array if not exists
*/
function message_get_providers_from_file($component) {
$defpath = get_component_directory($component).'/db/messages.php';
$messageproviders = array();
if (file_exists($defpath)) {
require($defpath);
}
foreach ($messageproviders as $name => $messageprovider) { // Fix up missing values if required
if (empty($messageprovider['capability'])) {
$messageproviders[$name]['capability'] = NULL;
}
if (empty($messageprovider['defaults'])) {
$messageproviders[$name]['defaults'] = array();
}
}
return $messageproviders;
}
示例10: send_file_not_found
} else {
$birecord = null;
}
$filefunction = $component . '_pluginfile';
if (function_exists($filefunction)) {
// if the function exists, it must send the file and terminate. Whatever it returns leads to "not found"
$filefunction($course, $birecord, $context, $filearea, $args, $forcedownload);
}
send_file_not_found();
} else {
if (strpos($component, '_') === false) {
// all core subsystems have to be specified above, no more guessing here!
send_file_not_found();
} else {
// try to serve general plugin file in arbitrary context
$dir = get_component_directory($component);
if (!file_exists("{$dir}/lib.php")) {
send_file_not_found();
}
include_once "{$dir}/lib.php";
$filefunction = $component . '_pluginfile';
if (function_exists($filefunction)) {
// if the function exists, it must send the file and terminate. Whatever it returns leads to "not found"
$filefunction($course, $cm, $context, $filearea, $args, $forcedownload);
}
send_file_not_found();
}
}
}
}
}
示例11: get_site_info
/**
* Return user information including profile picture + basic site information
* Note:
* - no capability checking because we return only known information about logged user
*
* @param array $serviceshortnames - DEPRECATED PARAMETER - values will be ignored -
* it was an original design error, we keep for backward compatibility.
* @return array site info
* @since Moodle 2.2
*/
public static function get_site_info($serviceshortnames = array()) {
global $USER, $SITE, $CFG, $DB;
$params = self::validate_parameters(self::get_site_info_parameters(),
array('serviceshortnames'=>$serviceshortnames));
$profileimageurl = moodle_url::make_pluginfile_url(
context_user::instance($USER->id)->id, 'user', 'icon', null, '/', 'f1');
// Site information.
$siteinfo = array(
'sitename' => $SITE->fullname,
'siteurl' => $CFG->wwwroot,
'username' => $USER->username,
'firstname' => $USER->firstname,
'lastname' => $USER->lastname,
'fullname' => fullname($USER),
'userid' => $USER->id,
'userpictureurl' => $profileimageurl->out(false)
);
// Retrieve the service and functions from the web service linked to the token
// If you call this function directly from external (not a web service call),
// then it will still return site info without information about a service
// Note: wsusername/wspassword ws authentication is not supported.
$functions = array();
if ($CFG->enablewebservices) { // No need to check token if web service are disabled and not a ws call.
$token = optional_param('wstoken', '', PARAM_ALPHANUM);
if (!empty($token)) { // No need to run if not a ws call.
// Retrieve service shortname.
$servicesql = 'SELECT s.*
FROM {external_services} s, {external_tokens} t
WHERE t.externalserviceid = s.id AND token = ? AND t.userid = ? AND s.enabled = 1';
$service = $DB->get_record_sql($servicesql, array($token, $USER->id));
$siteinfo['downloadfiles'] = $service->downloadfiles;
if (!empty($service)) {
// Return the release and version number for web service users only.
$siteinfo['release'] = $CFG->release;
$siteinfo['version'] = $CFG->version;
// Retrieve the functions.
$functionssql = "SELECT f.*
FROM {external_functions} f, {external_services_functions} sf
WHERE f.name = sf.functionname AND sf.externalserviceid = ?";
$functions = $DB->get_records_sql($functionssql, array($service->id));
} else {
throw new coding_exception('No service found in get_site_info: something is buggy, \
it should have fail at the ws server authentication layer.');
}
}
}
// Build up the returned values of the list of functions.
$componentversions = array();
$availablefunctions = array();
foreach ($functions as $function) {
$functioninfo = array();
$functioninfo['name'] = $function->name;
if ($function->component == 'moodle' || $function->component == 'core') {
$version = $CFG->version; // Moodle version.
} else {
$versionpath = get_component_directory($function->component).'/version.php';
if (is_readable($versionpath)) {
// We store the component version once retrieved (so we don't load twice the version.php).
if (!isset($componentversions[$function->component])) {
include($versionpath);
$componentversions[$function->component] = $plugin->version;
$version = $plugin->version;
} else {
$version = $componentversions[$function->component];
}
} else {
// Function component should always have a version.php,
// otherwise the function should have been described with component => 'moodle'.
throw new moodle_exception('missingversionfile', 'webservice', '', $function->component);
}
}
$functioninfo['version'] = $version;
$availablefunctions[] = $functioninfo;
}
$siteinfo['functions'] = $availablefunctions;
return $siteinfo;
}
示例12: require_login
try {
$autologinguest = true;
$setwantsurltome = true;
$preventredirect = true;
require_login($course, $autologinguest, $cm, $setwantsurltome, $preventredirect);
} catch (Exception $e) {
if (isguestuser()) {
rss_error('rsserrorguest');
} else {
rss_error('rsserrorauth');
}
}
// Work out which component in Moodle we want (from the frankenstyle name)
$componentdir = get_component_directory($componentname);
list($type, $plugin) = normalize_component($componentname);
// Call the component to check/update the feed and tell us the path to the cached file
$pathname = null;
if (file_exists($componentdir)) {
require_once("$componentdir/rsslib.php");
$functionname = $plugin.'_rss_get_feed';
if (function_exists($functionname)) {
// $pathname will be null if there was a problem (eg user doesn't have the necessary capabilities)
// NOTE:the component providing the feed must do its own capability checks and security
$pathname = $functionname($context, $args);
}
示例13: portfolio_include_callback_file
/**
* Function to require any potential callback files, throwing exceptions
* if an issue occurs.
*
* @param string $callbackfile This is the location of the callback file '/mod/forum/locallib.php'
* @param string $class Name of the class containing the callback functions
* activity components should ALWAYS use their name_portfolio_caller
* other locations must use something unique
*/
function portfolio_include_callback_file($callbackfile, $class = null) {
global $CFG;
require_once($CFG->libdir . '/adminlib.php');
// Get the last occurrence of '/' in the file path.
$pos = strrpos($callbackfile, '/');
// Get rid of the first slash (if it exists).
$callbackfile = ltrim($callbackfile, '/');
// Get a list of valid plugin types.
$plugintypes = get_plugin_types(false);
// Assume it is not valid for now.
$isvalid = false;
// Go through the plugin types.
foreach ($plugintypes as $type => $path) {
if (strrpos($callbackfile, $path) === 0) {
// Found the plugin type.
$isvalid = true;
$plugintype = $type;
$pluginpath = $path;
}
}
// Throw exception if not a valid component.
if (!$isvalid) {
throw new coding_exception('Somehow a non-valid plugin path was passed, could be a hackz0r attempt, exiting.');
}
// Keep record of the filename.
$filename = substr($callbackfile, $pos);
// Remove the file name.
$component = trim(substr($callbackfile, 0, $pos), '/');
// Replace the path with the type.
$component = str_replace($pluginpath, $plugintype, $component);
// Ok, replace '/' with '_'.
$component = str_replace('/', '_', $component);
// Check that it is a valid component.
if (!get_component_version($component)) {
throw new portfolio_button_exception('nocallbackcomponent', 'portfolio', '', $component);
}
// Obtain the component's location.
if (!$componentloc = get_component_directory($component)) {
throw new portfolio_button_exception('nocallbackcomponent', 'portfolio', '', $component);
}
// Check if the filename does not meet any of the expected names.
if (($filename != 'locallib.php') && ($filename != 'portfoliolib.php') && ($filename != 'portfolio_callback.php')) {
debugging('Please standardise your plugin by keeping your portfolio callback functionality in the file locallib.php.', DEBUG_DEVELOPER);
}
// Throw error if file does not exist.
if (!file_exists($componentloc . '/' . $filename)) {
throw new portfolio_button_exception('nocallbackfile', 'portfolio', '', $callbackfile);
}
require_once($componentloc . '/' . $filename);
if (!is_null($class) && !class_exists($class)) {
throw new portfolio_button_exception('nocallbackclass', 'portfolio', '', $class);
}
}
示例14: question_pluginfile
/**
* Called by pluginfile.php to serve files related to the 'question' core
* component and for files belonging to qtypes.
*
* For files that relate to questions in a question_attempt, then we delegate to
* a function in the component that owns the attempt (for example in the quiz,
* or in core question preview) to get necessary inforation.
*
* (Note that, at the moment, all question file areas relate to questions in
* attempts, so the If at the start of the last paragraph is always true.)
*
* Does not return, either calls send_file_not_found(); or serves the file.
*
* @package core_question
* @category files
* @param stdClass $course course settings object
* @param stdClass $context context object
* @param string $component the name of the component we are serving files for.
* @param string $filearea the name of the file area.
* @param array $args the remaining bits of the file path.
* @param bool $forcedownload whether the user must be forced to download the file.
* @param array $options additional options affecting the file serving
*/
function question_pluginfile($course, $context, $component, $filearea, $args, $forcedownload, array $options = array())
{
global $DB, $CFG;
if ($filearea === 'questiontext_preview') {
$component = array_shift($args);
$questionid = array_shift($args);
component_callback($component, 'questiontext_preview_pluginfile', array($context, $questionid, $args, $forcedownload, $options));
send_file_not_found();
}
if ($filearea === 'export') {
list($context, $course, $cm) = get_context_info_array($context->id);
require_login($course, false, $cm);
require_once $CFG->dirroot . '/question/editlib.php';
$contexts = new question_edit_contexts($context);
// check export capability
$contexts->require_one_edit_tab_cap('export');
$category_id = (int) array_shift($args);
$format = array_shift($args);
$cattofile = array_shift($args);
$contexttofile = array_shift($args);
$filename = array_shift($args);
// load parent class for import/export
require_once $CFG->dirroot . '/question/format.php';
require_once $CFG->dirroot . '/question/editlib.php';
require_once $CFG->dirroot . '/question/format/' . $format . '/format.php';
$classname = 'qformat_' . $format;
if (!class_exists($classname)) {
send_file_not_found();
}
$qformat = new $classname();
if (!($category = $DB->get_record('question_categories', array('id' => $category_id)))) {
send_file_not_found();
}
$qformat->setCategory($category);
$qformat->setContexts($contexts->having_one_edit_tab_cap('export'));
$qformat->setCourse($course);
if ($cattofile == 'withcategories') {
$qformat->setCattofile(true);
} else {
$qformat->setCattofile(false);
}
if ($contexttofile == 'withcontexts') {
$qformat->setContexttofile(true);
} else {
$qformat->setContexttofile(false);
}
if (!$qformat->exportpreprocess()) {
send_file_not_found();
print_error('exporterror', 'question', $thispageurl->out());
}
// export data to moodle file pool
if (!($content = $qformat->exportprocess(true))) {
send_file_not_found();
}
send_file($content, $filename, 0, 0, true, true, $qformat->mime_type());
}
$qubaid = (int) array_shift($args);
$slot = (int) array_shift($args);
$module = $DB->get_field('question_usages', 'component', array('id' => $qubaid));
if ($module === 'core_question_preview') {
require_once $CFG->dirroot . '/question/previewlib.php';
return question_preview_question_pluginfile($course, $context, $component, $filearea, $qubaid, $slot, $args, $forcedownload, $options);
} else {
$dir = get_component_directory($module);
if (!file_exists("{$dir}/lib.php")) {
send_file_not_found();
}
include_once "{$dir}/lib.php";
$filefunction = $module . '_question_pluginfile';
if (function_exists($filefunction)) {
$filefunction($course, $context, $component, $filearea, $qubaid, $slot, $args, $forcedownload, $options);
}
// Okay, we're here so lets check for function without 'mod_'.
if (strpos($module, 'mod_') === 0) {
$filefunctionold = substr($module, 4) . '_question_pluginfile';
if (function_exists($filefunctionold)) {
$filefunctionold($course, $context, $component, $filearea, $qubaid, $slot, $args, $forcedownload, $options);
//.........这里部分代码省略.........
示例15: external_update_descriptions
/**
* Web service discovery function used during install and upgrade.
* @param string $component name of component (moodle, mod_assignment, etc.)
* @return void
*/
function external_update_descriptions($component)
{
global $DB;
$defpath = get_component_directory($component) . '/db/services.php';
if (!file_exists($defpath)) {
external_delete_descriptions($component);
return;
}
// load new info
$functions = array();
$services = array();
include $defpath;
// update all function fist
$dbfunctions = $DB->get_records('external_functions', array('component' => $component));
foreach ($dbfunctions as $dbfunction) {
if (empty($functions[$dbfunction->name])) {
$DB->delete_records('external_functions', array('id' => $dbfunction->id));
// do not delete functions from external_services_functions, beacuse
// we want to notify admins when functions used in custom services disappear
//TODO: this looks wrong, we have to delete it eventually (skodak)
continue;
}
$function = $functions[$dbfunction->name];
unset($functions[$dbfunction->name]);
$function['classpath'] = empty($function['classpath']) ? null : $function['classpath'];
$update = false;
if ($dbfunction->classname != $function['classname']) {
$dbfunction->classname = $function['classname'];
$update = true;
}
if ($dbfunction->methodname != $function['methodname']) {
$dbfunction->methodname = $function['methodname'];
$update = true;
}
if ($dbfunction->classpath != $function['classpath']) {
$dbfunction->classpath = $function['classpath'];
$update = true;
}
$functioncapabilities = key_exists('capabilities', $function) ? $function['capabilities'] : '';
if ($dbfunction->capabilities != $functioncapabilities) {
$dbfunction->capabilities = $functioncapabilities;
$update = true;
}
if ($update) {
$DB->update_record('external_functions', $dbfunction);
}
}
foreach ($functions as $fname => $function) {
$dbfunction = new stdClass();
$dbfunction->name = $fname;
$dbfunction->classname = $function['classname'];
$dbfunction->methodname = $function['methodname'];
$dbfunction->classpath = empty($function['classpath']) ? null : $function['classpath'];
$dbfunction->component = $component;
$dbfunction->capabilities = key_exists('capabilities', $function) ? $function['capabilities'] : '';
$dbfunction->id = $DB->insert_record('external_functions', $dbfunction);
}
unset($functions);
// now deal with services
$dbservices = $DB->get_records('external_services', array('component' => $component));
foreach ($dbservices as $dbservice) {
if (empty($services[$dbservice->name])) {
$DB->delete_records('external_services_functions', array('externalserviceid' => $dbservice->id));
$DB->delete_records('external_services_users', array('externalserviceid' => $dbservice->id));
$DB->delete_records('external_services', array('id' => $dbservice->id));
continue;
}
$service = $services[$dbservice->name];
unset($services[$dbservice->name]);
$service['enabled'] = empty($service['enabled']) ? 0 : $service['enabled'];
$service['requiredcapability'] = empty($service['requiredcapability']) ? null : $service['requiredcapability'];
$service['restrictedusers'] = !isset($service['restrictedusers']) ? 1 : $service['restrictedusers'];
$update = false;
if ($dbservice->enabled != $service['enabled']) {
$dbservice->enabled = $service['enabled'];
$update = true;
}
if ($dbservice->requiredcapability != $service['requiredcapability']) {
$dbservice->requiredcapability = $service['requiredcapability'];
$update = true;
}
if ($dbservice->restrictedusers != $service['restrictedusers']) {
$dbservice->restrictedusers = $service['restrictedusers'];
$update = true;
}
if ($update) {
$DB->update_record('external_services', $dbservice);
}
$functions = $DB->get_records('external_services_functions', array('externalserviceid' => $dbservice->id));
foreach ($functions as $function) {
$key = array_search($function->functionname, $service['functions']);
if ($key === false) {
$DB->delete_records('external_services_functions', array('id' => $function->id));
} else {
unset($service['functions'][$key]);
//.........这里部分代码省略.........