当前位置: 首页>>代码示例>>PHP>>正文


PHP core_component::get_component_directory方法代码示例

本文整理汇总了PHP中core_component::get_component_directory方法的典型用法代码示例。如果您正苦于以下问题:PHP core_component::get_component_directory方法的具体用法?PHP core_component::get_component_directory怎么用?PHP core_component::get_component_directory使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在core_component的用法示例。


在下文中一共展示了core_component::get_component_directory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load_default_handlers_for_component

 /**
  * Load handler instances for all of the handlers defined in db/messageinbound_handlers.php for the specified component.
  *
  * @param string $componentname - The name of the component to fetch the handlers for.
  * @return \core\message\inbound\handler[] - List of handlers for this component.
  */
 public static function load_default_handlers_for_component($componentname)
 {
     $componentname = \core_component::normalize_componentname($componentname);
     $dir = \core_component::get_component_directory($componentname);
     if (!$dir) {
         return array();
     }
     $file = $dir . '/db/messageinbound_handlers.php';
     if (!file_exists($file)) {
         return array();
     }
     $handlers = null;
     require_once $file;
     if (!isset($handlers)) {
         return array();
     }
     $handlerinstances = array();
     foreach ($handlers as $handler) {
         $record = (object) $handler;
         $record->component = $componentname;
         if ($handlerinstance = self::handler_from_record($record)) {
             $handlerinstances[] = $handlerinstance;
         } else {
             throw new \coding_exception("Inbound Message Handler not found for '{$componentname}'.");
         }
     }
     return $handlerinstances;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:34,代码来源:manager.php

示例2: load_default_scheduled_tasks_for_component

 /**
  * Given a component name, will load the list of tasks in the db/tasks.php file for that component.
  *
  * @param string $componentname - The name of the component to fetch the tasks for.
  * @return \core\task\scheduled_task[] - List of scheduled tasks for this component.
  */
 public static function load_default_scheduled_tasks_for_component($componentname)
 {
     $dir = \core_component::get_component_directory($componentname);
     if (!$dir) {
         return array();
     }
     $file = $dir . '/' . CORE_TASK_TASKS_FILENAME;
     if (!file_exists($file)) {
         return array();
     }
     $tasks = null;
     include $file;
     if (!isset($tasks)) {
         return array();
     }
     $scheduledtasks = array();
     foreach ($tasks as $task) {
         $record = (object) $task;
         $scheduledtask = self::scheduled_task_from_record($record);
         // Safety check in case the task in the DB does not match a real class (maybe something was uninstalled).
         if ($scheduledtask) {
             $scheduledtask->set_component($componentname);
             $scheduledtasks[] = $scheduledtask;
         }
     }
     return $scheduledtasks;
 }
开发者ID:educakanchay,项目名称:campus,代码行数:33,代码来源:manager.php

示例3: 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 stdClass description or false if not found or exception thrown
 * @since Moodle 2.0
 */
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) ? core_component::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 MDL-31115 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 = core_component::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'];
        }
        if (isset($functions[$function->name]['testclientpath'])) {
            $function->testclientpath = $functions[$function->name]['testclientpath'];
        }
    }
    return $function;
}
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:65,代码来源:externallib.php

示例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.
 *
 * @access protected To be used from eventslib only
 *
 * @param string $component examples: 'moodle', 'mod_forum', 'block_quiz_results'
 * @return array Array of capabilities or empty array if not exists
 */
function events_load_def($component)
{
    global $CFG;
    if ($component === 'unittest') {
        $defpath = $CFG->dirroot . '/lib/tests/fixtures/events.php';
    } else {
        $defpath = core_component::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;
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:58,代码来源:eventslib.php

示例5: test_requirejs

 /**
  * Test requirejs loader
  */
 public function test_requirejs()
 {
     global $CFG;
     // Find a core module.
     $result = core_requirejs::find_one_amd_module('core', 'templates', false);
     $expected = ['core/templates' => $CFG->dirroot . '/lib/amd/build/templates.min.js'];
     $this->assertEquals($expected, $result);
     $result = core_requirejs::find_one_amd_module('core', 'templates', true);
     $expected = ['core/templates' => $CFG->dirroot . '/lib/amd/src/templates.js'];
     $this->assertEquals($expected, $result);
     // Find a subsystem module (none exist yet).
     $result = core_requirejs::find_one_amd_module('core_group', 'doesnotexist', false);
     $expected = [];
     $this->assertEquals($expected, $result);
     // Find a plugin module.
     $result = core_requirejs::find_one_amd_module('mod_assign', 'grading_panel', true);
     $expected = ['mod_assign/grading_panel' => $CFG->dirroot . '/mod/assign/amd/src/grading_panel.js'];
     $this->assertEquals($expected, $result);
     // Find all modules - no debugging.
     $result = core_requirejs::find_all_amd_modules(true);
     foreach ($result as $key => $path) {
         // Lets verify the first part of the key is a valid component name and the second part correctly contains "min" or not.
         list($component, $template) = explode('/', $key, 2);
         // Can we resolve it to a valid dir?
         $dir = core_component::get_component_directory($component);
         $this->assertNotEmpty($dir);
         // Only "core" is allowed to have no _ in component names.
         if (strpos($component, '_') === false) {
             $this->assertEquals('core', $component);
         }
         $this->assertNotContains('.min', $path);
     }
     // Find all modules - debugging.
     $result = core_requirejs::find_all_amd_modules(false);
     foreach ($result as $key => $path) {
         // Lets verify the first part of the key is a valid component name and the second part correctly contains "min" or not.
         list($component, $template) = explode('/', $key, 2);
         $dir = core_component::get_component_directory($component);
         $this->assertNotEmpty($dir);
         // Only "core" is allowed to have no _ in component names.
         if (strpos($component, '_') === false) {
             $this->assertEquals('core', $component);
         }
         $this->assertContains('.min', $path);
     }
 }
开发者ID:evltuma,项目名称:moodle,代码行数:49,代码来源:requirejs_test.php

示例6: validate

 /**
  * Validate data.
  *
  * This ensures that:
  * - Plugins are only used once,
  * - Group names are unique,
  * - Lines match: group = plugin[, plugin[, plugin ...]],
  * - There are some groups and plugins defined,
  * - The plugins used are installed.
  *
  * @param string $data
  * @return mixed True on success, else error message.
  */
 public function validate($data)
 {
     $result = parent::validate($data);
     if ($result !== true) {
         return $result;
     }
     $lines = explode("\n", $data);
     $groups = array();
     $plugins = array();
     foreach ($lines as $line) {
         if (!trim($line)) {
             continue;
         }
         $matches = array();
         if (!preg_match('/^\\s*([a-z0-9]+)\\s*=\\s*([a-z0-9]+(\\s*,\\s*[a-z0-9]+)*)+\\s*$/', $line, $matches)) {
             $result = get_string('errorcannotparseline', 'editor_atto', $line);
             break;
         }
         $group = $matches[1];
         if (isset($groups[$group])) {
             $result = get_string('errorgroupisusedtwice', 'editor_atto', $group);
             break;
         }
         $groups[$group] = true;
         $lineplugins = array_map('trim', explode(',', $matches[2]));
         foreach ($lineplugins as $plugin) {
             if (isset($plugins[$plugin])) {
                 $result = get_string('errorpluginisusedtwice', 'editor_atto', $plugin);
                 break 2;
             } else {
                 if (!core_component::get_component_directory('atto_' . $plugin)) {
                     $result = get_string('errorpluginnotfound', 'editor_atto', $plugin);
                     break 2;
                 }
             }
             $plugins[$plugin] = true;
         }
     }
     // We did not find any groups or plugins.
     if (empty($groups) || empty($plugins)) {
         $result = get_string('errornopluginsorgroupsfound', 'editor_atto');
     }
     return $result;
 }
开发者ID:evltuma,项目名称:moodle,代码行数:57,代码来源:adminlib.php

示例7: find_one_amd_module

 /**
  * Check a single module exists and return the full path to it.
  *
  * The expected location for amd modules is:
  *  <componentdir>/amd/src/modulename.js
  *
  * @param string $component The component determines the folder the js file should be in.
  * @param string $jsfilename The filename for the module (with the js extension).
  * @param boolean $debug If true, returns the paths to the original (unminified) source files.
  * @return array $files An array of mappings from module names to file paths.
  *                      Empty array if the file does not exist.
  */
 public static function find_one_amd_module($component, $jsfilename, $debug = false)
 {
     $jsfileroot = core_component::get_component_directory($component);
     if (!$jsfileroot) {
         return array();
     }
     $module = str_replace('.js', '', $jsfilename);
     $srcdir = $jsfileroot . '/amd/build';
     $minpart = '.min';
     if ($debug) {
         $srcdir = $jsfileroot . '/amd/src';
         $minpart = '';
     }
     $filename = $srcdir . '/' . $module . $minpart . '.js';
     if (!file_exists($filename)) {
         return array();
     }
     $fullmodulename = $component . '/' . $module;
     return array($fullmodulename => $filename);
 }
开发者ID:gabrielrosset,项目名称:moodle,代码行数:32,代码来源:requirejs.php

示例8: load_default_scheduled_tasks_for_component

 /**
  * Given a component name, will load the list of tasks in the db/tasks.php file for that component.
  *
  * @param string $componentname - The name of the component to fetch the tasks for.
  * @return \core\task\scheduled_task[] - List of scheduled tasks for this component.
  */
 public static function load_default_scheduled_tasks_for_component($componentname)
 {
     $dir = \core_component::get_component_directory($componentname);
     if (!$dir) {
         return array();
     }
     $file = $dir . '/' . CORE_TASK_TASKS_FILENAME;
     if (!file_exists($file)) {
         return array();
     }
     $tasks = null;
     require_once $file;
     if (!isset($tasks)) {
         return array();
     }
     $scheduledtasks = array();
     foreach ($tasks as $task) {
         $record = (object) $task;
         $scheduledtask = self::scheduled_task_from_record($record);
         $scheduledtask->set_component($componentname);
         $scheduledtasks[] = $scheduledtask;
     }
     return $scheduledtasks;
 }
开发者ID:ruddj,项目名称:moodle,代码行数:30,代码来源:manager.php

示例9: upgrade_log

/**
 * Adds log entry into upgrade_log table
 *
 * @param int $type UPGRADE_LOG_NORMAL, UPGRADE_LOG_NOTICE or UPGRADE_LOG_ERROR
 * @param string $plugin frankenstyle component name
 * @param string $info short description text of log entry
 * @param string $details long problem description
 * @param string $backtrace string used for errors only
 * @return void
 */
function upgrade_log($type, $plugin, $info, $details=null, $backtrace=null) {
    global $DB, $USER, $CFG;

    if (empty($plugin)) {
        $plugin = 'core';
    }

    list($plugintype, $pluginname) = core_component::normalize_component($plugin);
    $component = is_null($pluginname) ? $plugintype : $plugintype . '_' . $pluginname;

    $backtrace = format_backtrace($backtrace, true);

    $currentversion = null;
    $targetversion  = null;

    //first try to find out current version number
    if ($plugintype === 'core') {
        //main
        $currentversion = $CFG->version;

        $version = null;
        include("$CFG->dirroot/version.php");
        $targetversion = $version;

    } else {
        $pluginversion = get_config($component, 'version');
        if (!empty($pluginversion)) {
            $currentversion = $pluginversion;
        }
        $cd = core_component::get_component_directory($component);
        if (file_exists("$cd/version.php")) {
            $plugin = new stdClass();
            $plugin->version = null;
            $module = $plugin;
            include("$cd/version.php");
            $targetversion = $plugin->version;
        }
    }

    $log = new stdClass();
    $log->type          = $type;
    $log->plugin        = $component;
    $log->version       = $currentversion;
    $log->targetversion = $targetversion;
    $log->info          = $info;
    $log->details       = $details;
    $log->backtrace     = $backtrace;
    $log->userid        = $USER->id;
    $log->timemodified  = time();
    try {
        $DB->insert_record('upgrade_log', $log);
    } catch (Exception $ignored) {
        // possible during install or 2.0 upgrade
    }
}
开发者ID:jtibbetts,项目名称:moodle,代码行数:65,代码来源:upgradelib.php

示例10: 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));
     $context = context_user::instance($USER->id);
     $profileimageurl = moodle_url::make_pluginfile_url($context->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), 'lang' => current_language(), '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;
             $siteinfo['uploadfiles'] = $service->uploadfiles;
             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.*\n                            FROM {external_functions} f, {external_services_functions} sf\n                            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 = core_component::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])) {
                     $plugin = new stdClass();
                     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;
     // Mobile CSS theme and alternative login url.
     $siteinfo['mobilecssurl'] = $CFG->mobilecssurl;
     // Retrieve some advanced features. Only enable/disable ones (bool).
     $advancedfeatures = array("usecomments", "usetags", "enablenotes", "messaging", "enableblogs", "enablecompletion", "enablebadges");
     foreach ($advancedfeatures as $feature) {
         if (isset($CFG->{$feature})) {
             $siteinfo['advancedfeatures'][] = array('name' => $feature, 'value' => (int) $CFG->{$feature});
         }
     }
     // Special case mnet_dispatcher_mode.
     $siteinfo['advancedfeatures'][] = array('name' => 'mnet_dispatcher_mode', 'value' => $CFG->mnet_dispatcher_mode == 'strict' ? 1 : 0);
     // User can manage own files.
     $siteinfo['usercanmanageownfiles'] = has_capability('moodle/user:manageownfiles', $context);
     // User quota. 0 means user can ignore the quota.
     $siteinfo['userquota'] = 0;
     if (!has_capability('moodle/user:ignoreuserquota', $context)) {
         $siteinfo['userquota'] = $CFG->userquota;
     }
     // User max upload file size. -1 means the user can ignore the upload file size.
     $siteinfo['usermaxuploadfilesize'] = get_user_max_upload_file_size($context, $CFG->maxbytes);
     return $siteinfo;
//.........这里部分代码省略.........
开发者ID:educakanchay,项目名称:campus,代码行数:101,代码来源:externallib.php

示例11: 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;
    // Special case, sending a question bank export.
    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());
    }
    // Normal case, a file belonging to a question.
    $qubaidorpreview = array_shift($args);
    // Two sub-cases: 1. A question being previewed outside an attempt/usage.
    if ($qubaidorpreview === 'preview') {
        $previewcontextid = (int) array_shift($args);
        $previewcomponent = array_shift($args);
        $questionid = (int) array_shift($args);
        $previewcontext = context_helper::instance_by_id($previewcontextid);
        $result = component_callback($previewcomponent, 'question_preview_pluginfile', array($previewcontext, $questionid, $context, $component, $filearea, $args, $forcedownload, $options), 'newcallbackmissing');
        if ($result === 'newcallbackmissing' && ($filearea = 'questiontext')) {
            // Fall back to the legacy callback for backwards compatibility.
            debugging("Component {$previewcomponent} does not define the expected " . "{$previewcomponent}_question_preview_pluginfile callback. Falling back to the deprecated " . "{$previewcomponent}_questiontext_preview_pluginfile callback.", DEBUG_DEVELOPER);
            component_callback($previewcomponent, 'questiontext_preview_pluginfile', array($previewcontext, $questionid, $args, $forcedownload, $options));
        }
        send_file_not_found();
    }
    // 2. A question being attempted in the normal way.
    $qubaid = (int) $qubaidorpreview;
    $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 = core_component::get_component_directory($module);
        if (!file_exists("{$dir}/lib.php")) {
//.........这里部分代码省略.........
开发者ID:tyleung,项目名称:CMPUT401MoodleExams,代码行数:101,代码来源:questionlib.php

示例12: process_assignment

 /**
  * Assign roles
  *
  * This has to be called after enrolments processing.
  *
  * @param mixed $data
  * @return void
  */
 public function process_assignment($data)
 {
     global $DB;
     $data = (object) $data;
     // Check roleid, userid are one of the mapped ones
     if (!($newroleid = $this->get_mappingid('role', $data->roleid))) {
         return;
     }
     if (!($newuserid = $this->get_mappingid('user', $data->userid))) {
         return;
     }
     if (!$DB->record_exists('user', array('id' => $newuserid, 'deleted' => 0))) {
         // Only assign roles to not deleted users
         return;
     }
     if (!($contextid = $this->task->get_contextid())) {
         return;
     }
     if (empty($data->component)) {
         // assign standard manual roles
         // TODO: role_assign() needs one userid param to be able to specify our restore userid
         role_assign($newroleid, $newuserid, $contextid);
     } else {
         if (strpos($data->component, 'enrol_') === 0) {
             // Deal with enrolment roles - ignore the component and just find out the instance via new id,
             // it is possible that enrolment was restored using different plugin type.
             if (!isset($this->plugins)) {
                 $this->plugins = enrol_get_plugins(true);
             }
             if ($enrolid = $this->get_mappingid('enrol', $data->itemid)) {
                 if ($instance = $DB->get_record('enrol', array('id' => $enrolid))) {
                     if (isset($this->plugins[$instance->enrol])) {
                         $this->plugins[$instance->enrol]->restore_role_assignment($instance, $newroleid, $newuserid, $contextid);
                     }
                 }
             }
         } else {
             $data->roleid = $newroleid;
             $data->userid = $newuserid;
             $data->contextid = $contextid;
             $dir = core_component::get_component_directory($data->component);
             if ($dir and is_dir($dir)) {
                 if (component_callback($data->component, 'restore_role_assignment', array($this, $data), true)) {
                     return;
                 }
             }
             // Bad luck, plugin could not restore the data, let's add normal membership.
             role_assign($data->roleid, $data->userid, $data->contextid);
             $message = "Restore of '{$data->component}/{$data->itemid}' role assignments is not supported, using manual role assignments instead.";
             $this->log($message, backup::LOG_WARNING);
         }
     }
 }
开发者ID:Jinelle,项目名称:moodle,代码行数:61,代码来源:restore_stepslib.php

示例13: array_shift

    }
    if ($version === 'moodle') {
        if (count($bits) <= 3) {
            // This is an invalid module load attempt.
            $content .= "\n// Incorrect moodle module inclusion. Not enough component information in {$part}.\n";
            continue;
        }
        $revision = (int)array_shift($bits);
        if ($revision === -1) {
            // Revision -1 says please don't cache the JS
            $cache = false;
        }
        $frankenstyle = array_shift($bits);
        $filename = array_pop($bits);
        $modulename = $bits[0];
        $dir = core_component::get_component_directory($frankenstyle);

        // For shifted YUI modules, we need the YUI module name in frankenstyle format.
        $frankenstylemodulename = join('-', array($version, $frankenstyle, $modulename));
        $frankenstylefilename = preg_replace('/' . $modulename . '/', $frankenstylemodulename, $filename);

        // Submodules are stored in a directory with the full submodule name.
        // We need to remove the -debug.js, -min.js, and .js from the file name to calculate that directory name.
        $frankenstyledirectoryname = str_replace(array('-min.js', '-debug.js', '.js', '.css'), '', $frankenstylefilename);

        // By default, try and use the /yui/build directory.
        $contentfile = $dir . '/yui/build/' . $frankenstyledirectoryname;
        if ($mimetype == 'text/css') {
            // CSS assets are in a slightly different place to the JS.
            $contentfile = $contentfile . '/assets/skins/sam/' . $frankenstylefilename;
开发者ID:rwijaya,项目名称:moodle,代码行数:30,代码来源:yui_combo.php

示例14: 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 = core_component::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;
}
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:31,代码来源:messagelib.php

示例15: file_pluginfile


//.........这里部分代码省略.........
                                                                if ($filearea === 'intro') {
                                                                    if (!plugin_supports('mod', $modname, FEATURE_MOD_INTRO, true)) {
                                                                        send_file_not_found();
                                                                    }
                                                                    require_course_login($course, true, $cm);
                                                                    // all users may access it
                                                                    $filename = array_pop($args);
                                                                    $filepath = $args ? '/' . implode('/', $args) . '/' : '/';
                                                                    if (!($file = $fs->get_file($context->id, 'mod_' . $modname, 'intro', 0, $filepath, $filename)) or $file->is_directory()) {
                                                                        send_file_not_found();
                                                                    }
                                                                    // finally send the file
                                                                    send_stored_file($file, null, 0, false, array('preview' => $preview));
                                                                }
                                                                $filefunction = $component . '_pluginfile';
                                                                $filefunctionold = $modname . '_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, array('preview' => $preview));
                                                                } else {
                                                                    if (function_exists($filefunctionold)) {
                                                                        // if the function exists, it must send the file and terminate. Whatever it returns leads to "not found"
                                                                        $filefunctionold($course, $cm, $context, $filearea, $args, $forcedownload, array('preview' => $preview));
                                                                    }
                                                                }
                                                                send_file_not_found();
                                                                // ========================================================================================================================
                                                            } else {
                                                                if (strpos($component, 'block_') === 0) {
                                                                    $blockname = substr($component, 6);
                                                                    // note: no more class methods in blocks please, that is ....
                                                                    if (!file_exists("{$CFG->dirroot}/blocks/{$blockname}/lib.php")) {
                                                                        send_file_not_found();
                                                                    }
                                                                    require_once "{$CFG->dirroot}/blocks/{$blockname}/lib.php";
                                                                    if ($context->contextlevel == CONTEXT_BLOCK) {
                                                                        $birecord = $DB->get_record('block_instances', array('id' => $context->instanceid), '*', MUST_EXIST);
                                                                        if ($birecord->blockname !== $blockname) {
                                                                            // somebody tries to gain illegal access, cm type must match the component!
                                                                            send_file_not_found();
                                                                        }
                                                                        if ($context->get_course_context(false)) {
                                                                            // If block is in course context, then check if user has capability to access course.
                                                                            require_course_login($course);
                                                                        } else {
                                                                            if ($CFG->forcelogin) {
                                                                                // If user is logged out, bp record will not be visible, even if the user would have access if logged in.
                                                                                require_login();
                                                                            }
                                                                        }
                                                                        $bprecord = $DB->get_record('block_positions', array('contextid' => $context->id, 'blockinstanceid' => $context->instanceid));
                                                                        // User can't access file, if block is hidden or doesn't have block:view capability
                                                                        if ($bprecord && !$bprecord->visible || !has_capability('moodle/block:view', $context)) {
                                                                            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, array('preview' => $preview));
                                                                    }
                                                                    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 = core_component::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, array('preview' => $preview));
                                                                        }
                                                                        send_file_not_found();
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
开发者ID:IFPBMoodle,项目名称:moodle,代码行数:101,代码来源:filelib.php


注:本文中的core_component::get_component_directory方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。