/** * @param moodle_page the page we are outputting to. * @return qtype_poodllrecording_format_renderer_base the response-format-specific renderer. */ public function get_format_renderer(moodle_page $page) { //Nadav reported a possible problem here, I can't reproduce it, but hope this fixes it. //https://github.com/justinhunt/moodle-qtype_poodllrecording/issues/1 if ($this->responseformat == 'editor') { $this->responseformat = 'picture'; } return $page->get_renderer('qtype_poodllrecording', 'format_' . $this->responseformat); }
/** * Test the update user profile image function. */ public function test_update_user_profile_image() { global $DB, $CFG; // Set the profile image. \enrol_lti\helper::update_user_profile_image($this->user1->id, $this->getExternalTestFileUrl('/test.jpg')); // Get the new user record. $this->user1 = $DB->get_record('user', array('id' => $this->user1->id)); // Set the page details. $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $usercontext = context_user::instance($this->user1->id); // Get the user's profile picture and make sure it is correct. $userpicture = new user_picture($this->user1); $this->assertSame($CFG->wwwroot . '/pluginfile.php/' . $usercontext->id . '/user/icon/clean/f2?rev=' . $this->user1->picture, $userpicture->get_url($page, $renderer)->out(false)); }
/** * Constructor * * The constructor takes two arguments. The first is the page that the renderer * has been created to assist with, and the second is the target. * The target is an additional identifier that can be used to load different * renderers for different options. * * In order to create and initialize the appropriate arrays for resources, activities, assignments and icons, * we must update the declared constructor of the parent class, and since we can't just update it, we declare it again * adding the appropriate commands that suit our purpose. * * @param moodle_page $page the page we are doing output for. * @param string $target one of rendering target constants * @see core:renderer::__construct() */ public function __construct(moodle_page $page, $target) { // Find and update course modules ids. global $DB; $this->chatmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="chat"', null); $this->forummoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="forum"', null); $this->oldassignmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="assignment"', null); $this->newassignmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="assign"', null); $this->labelmoduleid = $DB->get_field_sql('SELECT id FROM {modules} WHERE name="label"', null); // Use the Label module id, to exclude it from course resources. $this->output = $page->get_renderer('core', null, $target); parent::__construct($page, $target); // These are needed for the enriched rubric renderer construction. $this->resources = $this->get_modules_array('resources', $this->moduleicon); $this->assignments = $this->get_modules_array('assignments', $this->moduleicon); $this->activities = $this->get_modules_array('activities', $this->moduleicon); }
/** * Returns the rubric plugin renderer * * @param moodle_page $page the target page * @return gradingform_rubric_renderer */ public function get_renderer(moodle_page $page) { return $page->get_renderer('gradingform_' . $this->get_method_name()); }
/** * Constructor method, calls the parent constructor * * @param moodle_page $page * @param string $target one of rendering target constants */ public function __construct(moodle_page $page, $target) { if (empty($target) && $page->pagelayout === 'maintenance') { // If the page is using the maintenance layout then we're going to force the target to maintenance. // This way we'll get a special maintenance renderer that is designed to block access to API's that are likely // unavailable for this page layout. $target = RENDERER_TARGET_MAINTENANCE; } $this->output = $page->get_renderer('core', null, $target); parent::__construct($page, $target); }
/** * Constructor method, calls the parent constructor * * @param moodle_page $page * @param string $target one of rendering target constants */ public function __construct(moodle_page $page, $target) { $this->output = $page->get_renderer('core', null, $target); parent::__construct($page, $target); }
/** * @param moodle_page $page the page to render for. * @return qbehaviour_renderer get the appropriate renderer to use for this model. */ public function get_renderer(moodle_page $page) { return $page->get_renderer(get_class($this)); }
/** * Works out the URL for the users picture. * * This method is recommended as it avoids costly redirects of user pictures * if requests are made for non-existent files etc. * * @param moodle_page $page * @param renderer_base $renderer * @return moodle_url */ public function get_url(moodle_page $page, renderer_base $renderer = null) { global $CFG, $DB; if (is_null($renderer)) { $renderer = $page->get_renderer('core'); } // Sort out the filename and size. Size is only required for the gravatar // implementation presently. if (empty($this->size)) { $filename = 'f2'; $size = 35; } else { if ($this->size === true or $this->size == 1) { $filename = 'f1'; $size = 100; } else { if ($this->size > 100) { $filename = 'f3'; $size = (int) $this->size; } else { if ($this->size >= 50) { $filename = 'f1'; $size = (int) $this->size; } else { $filename = 'f2'; $size = (int) $this->size; } } } } $defaulturl = $renderer->pix_url('u/' . $filename); // default image if ((!empty($CFG->forcelogin) and !isloggedin()) || !empty($CFG->forceloginforprofileimage) && (!isloggedin() || isguestuser())) { // Protect images if login required and not logged in; // also if login is required for profile images and is not logged in or guest // do not use require_login() because it is expensive and not suitable here anyway. return $defaulturl; } // First try to detect deleted users - but do not read from database for performance reasons! if (!empty($this->user->deleted) or strpos($this->user->email, '@') === false) { // All deleted users should have email replaced by md5 hash, // all active users are expected to have valid email. return $defaulturl; } // Did the user upload a picture? if ($this->user->picture > 0) { if (!empty($this->user->contextid)) { $contextid = $this->user->contextid; } else { $context = context_user::instance($this->user->id, IGNORE_MISSING); if (!$context) { // This must be an incorrectly deleted user, all other users have context. return $defaulturl; } $contextid = $context->id; } $path = '/'; if (clean_param($page->theme->name, PARAM_THEME) == $page->theme->name) { // We append the theme name to the file path if we have it so that // in the circumstance that the profile picture is not available // when the user actually requests it they still get the profile // picture for the correct theme. $path .= $page->theme->name . '/'; } // Set the image URL to the URL for the uploaded file and return. $url = moodle_url::make_pluginfile_url($contextid, 'user', 'icon', NULL, $path, $filename); $url->param('rev', $this->user->picture); return $url; } // Is the user a member of staff // need the next two lines to obtain some fields which are not present by default in the $user variable $ID = $this->user->id; $user = $DB->get_record('user', array('id' => "{$ID}")); if (strpos(strtolower($user->phone2), 'staff') !== false) { return $defaulturl; // It is a member of staff; we return the default URL } if (empty($user->idnumber)) { return $defaulturl; // University ID is empty; we return the default URL } if ($this->user->picture == 0) { // Normalise the size variable to acceptable bounds if ($size < 1 || $size > 512) { $size = 35; } // Find the best default image URL we can (MDL-35669) $absoluteimagepath = $page->theme->resolve_image_location('u/' . $filename, 'core'); if (strpos($absoluteimagepath, $CFG->dirroot) === 0) { $gravatardefault = $CFG->wwwroot . substr($absoluteimagepath, strlen($CFG->dirroot)); } else { $gravatardefault = $CFG->wwwroot . '/pix/u/' . $filename . '.png'; } // Build a gravatar URL with what we know. $applicationId = 'itsmoodle'; $applicationkey = '9J*#xAOsJWhms_CV0sUoG(p7Bd_oLCKx$WCr4(YU'; $universityId = $user->idnumber; // Remove department code if any if (preg_match('/([a-zA-Z]{2}\\d+)/', $universityId, $matches)) { $universityId = substr($universityId, 2); } // Hash the application key and user id $hashstring = $applicationkey . $universityId; $md5 = md5($hashstring); $image_url = "https://photos.warwick.ac.uk/{$applicationId}/photo/{$md5}/{$universityId}"; return new moodle_url("{$image_url}", array('s' => $size, 'd' => $gravatardefault)); } return $defaulturl; }
/** * Works out the URL for the users picture. * * This method is recommended as it avoids costly redirects of user pictures * if requests are made for non-existent files etc. * * @param moodle_page $page * @param renderer_base $renderer * @return moodle_url */ public function get_url(moodle_page $page, renderer_base $renderer = null) { global $CFG; if (is_null($renderer)) { $renderer = $page->get_renderer('core'); } // Sort out the filename and size. Size is only required for the gravatar // implementation presently. if (empty($this->size)) { $filename = 'f2'; $size = 35; } else { if ($this->size === true or $this->size == 1) { $filename = 'f1'; $size = 100; } else { if ($this->size > 100) { $filename = 'f3'; $size = (int) $this->size; } else { if ($this->size >= 50) { $filename = 'f1'; $size = (int) $this->size; } else { $filename = 'f2'; $size = (int) $this->size; } } } } $defaulturl = $renderer->pix_url('u/' . $filename); // default image if ((!empty($CFG->forcelogin) and !isloggedin()) || !empty($CFG->forceloginforprofileimage) && (!isloggedin() || isguestuser())) { // Protect images if login required and not logged in; // also if login is required for profile images and is not logged in or guest // do not use require_login() because it is expensive and not suitable here anyway. return $defaulturl; } // First try to detect deleted users - but do not read from database for performance reasons! if (!empty($this->user->deleted) or strpos($this->user->email, '@') === false) { // All deleted users should have email replaced by md5 hash, // all active users are expected to have valid email. return $defaulturl; } // Did the user upload a picture? if ($this->user->picture > 0) { if (!empty($this->user->contextid)) { $contextid = $this->user->contextid; } else { $context = context_user::instance($this->user->id, IGNORE_MISSING); if (!$context) { // This must be an incorrectly deleted user, all other users have context. return $defaulturl; } $contextid = $context->id; } $path = '/'; if (clean_param($page->theme->name, PARAM_THEME) == $page->theme->name) { // We append the theme name to the file path if we have it so that // in the circumstance that the profile picture is not available // when the user actually requests it they still get the profile // picture for the correct theme. $path .= $page->theme->name . '/'; } // Set the image URL to the URL for the uploaded file and return. $url = moodle_url::make_pluginfile_url($contextid, 'user', 'icon', NULL, $path, $filename); $url->param('rev', $this->user->picture); return $url; } if ($this->user->picture == 0 and !empty($CFG->enablegravatar)) { // Normalise the size variable to acceptable bounds if ($size < 1 || $size > 512) { $size = 35; } // Hash the users email address $md5 = md5(strtolower(trim($this->user->email))); // Build a gravatar URL with what we know. // Find the best default image URL we can (MDL-35669) if (empty($CFG->gravatardefaulturl)) { $absoluteimagepath = $page->theme->resolve_image_location('u/' . $filename, 'core'); if (strpos($absoluteimagepath, $CFG->dirroot) === 0) { $gravatardefault = $CFG->wwwroot . substr($absoluteimagepath, strlen($CFG->dirroot)); } else { $gravatardefault = $CFG->wwwroot . '/pix/u/' . $filename . '.png'; } } else { $gravatardefault = $CFG->gravatardefaulturl; } // If the currently requested page is https then we'll return an // https gravatar page. if (is_https()) { $gravatardefault = str_replace($CFG->wwwroot, $CFG->httpswwwroot, $gravatardefault); // Replace by secure url. return new moodle_url("https://secure.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $gravatardefault)); } else { return new moodle_url("http://www.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $gravatardefault)); } } return $defaulturl; }
public function get_renderer(moodle_page $page) { return $page->get_renderer('qtype_multichoice', 'multi'); }
/** * @param moodle_page the page we are outputting to. * @return qtype_poodllrecording_format_renderer_base the response-format-specific renderer. */ public function get_format_renderer(moodle_page $page) { return $page->get_renderer('qtype_poodllrecording', 'format_' . $this->responseformat); // return $page->get_renderer('qtype_poodllrecording', 'format_video'); }
?> <li id="student_<?php echo $student->id; ?> " data-prof="<?php echo $student->roleid == 5 ? 'b' : 'a'; ?> " data-order="<?php echo $studentNum++; ?> "> <?php $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $up3 = new user_picture($student); $up3->size = 100; $image = $up3->get_url($page, $renderer)->out(false); ?> <img src="<?php echo $image; ?> " alt="<?php echo $student->firstname; ?> "> <span class="user-name no-text"><?php echo fullname($student); ?> </span>
/** * Return the proper renderer for this class * * @param moodle_page $page * @return renderer_base */ public function get_renderer(moodle_page $page) { return $page->get_renderer('qtype_omerointeractive', 'multi'); }
/** * Works out the URL for the users picture. * * This method is recommended as it avoids costly redirects of user pictures * if requests are made for non-existent files etc. * * @param renderer_base $renderer * @return moodle_url */ public function get_url(moodle_page $page, renderer_base $renderer = null) { global $CFG; if (is_null($renderer)) { $renderer = $page->get_renderer('core'); } if ((!empty($CFG->forcelogin) and !isloggedin()) || !empty($CFG->forceloginforprofileimage) && (!isloggedin() || isguestuser())) { // protect images if login required and not logged in; // also if login is required for profile images and is not logged in or guest // do not use require_login() because it is expensive and not suitable here anyway return $renderer->pix_url('u/f1'); } // Sort out the filename and size. Size is only required for the gravatar // implementation presently. if (empty($this->size)) { $filename = 'f2'; $size = 35; } else { if ($this->size === true or $this->size == 1) { $filename = 'f1'; $size = 100; } else { if ($this->size >= 50) { $filename = 'f1'; $size = (int) $this->size; } else { $filename = 'f2'; $size = (int) $this->size; } } } if ($this->user->picture == 1) { // The user has uploaded their own profile pic. In this case we will // check that a profile pic file does actually exist $fs = get_file_storage(); $context = get_context_instance(CONTEXT_USER, $this->user->id); if (!$fs->file_exists($context->id, 'user', 'icon', 0, '/', $filename . '/.png')) { if (!$fs->file_exists($context->id, 'user', 'icon', 0, '/', $filename . '/.jpg')) { return $renderer->pix_url('u/' . $filename); } } $path = '/'; if (clean_param($page->theme->name, PARAM_THEME) == $page->theme->name) { // We append the theme name to the file path if we have it so that // in the circumstance that the profile picture is not available // when the user actually requests it they still get the profile // picture for the correct theme. $path .= $page->theme->name . '/'; } return moodle_url::make_pluginfile_url($context->id, 'user', 'icon', NULL, $path, $filename); } else { if ($this->user->picture == 2) { // This is just VERY basic support for gravatar to give the actual // implementor a headstart in what to do. if ($size < 1 || $size > 500) { $size = 35; } $md5 = md5(strtolower(trim($this->user->email))); $default = urlencode($this->pix_url('u/' . $filename)->out(false)); return "http://www.gravatar.com/avatar/{$md5}?s={$size}&d={$default}"; } } return $renderer->pix_url('u/' . $filename); }
/** * Handle showing/processing the submission from the block editing form. * @return boolean true if the form was submitted and the new config saved. Does not * return if the editing form was displayed. False otherwise. */ public function process_url_edit() { global $CFG, $DB, $PAGE, $OUTPUT; $blockid = optional_param('bui_editid', null, PARAM_INT); if (!$blockid) { return false; } require_sesskey(); require_once $CFG->dirroot . '/blocks/edit_form.php'; $block = $this->find_instance($blockid); if (!$block->user_can_edit() && !$this->page->user_can_edit_blocks()) { throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock')); } $editpage = new moodle_page(); $editpage->set_pagelayout('admin'); $editpage->set_course($this->page->course); //$editpage->set_context($block->context); $editpage->set_context($this->page->context); if ($this->page->cm) { $editpage->set_cm($this->page->cm); } $editurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring()); $editurlparams = $this->page->url->params(); $editurlparams['bui_editid'] = $blockid; $editpage->set_url($editurlbase, $editurlparams); $editpage->set_block_actions_done(); // At this point we are either going to redirect, or display the form, so // overwrite global $PAGE ready for this. (Formslib refers to it.) $PAGE = $editpage; //some functions like MoodleQuickForm::addHelpButton use $OUTPUT so we need to replace that to $output = $editpage->get_renderer('core'); $OUTPUT = $output; $formfile = $CFG->dirroot . '/blocks/' . $block->name() . '/edit_form.php'; if (is_readable($formfile)) { require_once $formfile; $classname = 'block_' . $block->name() . '_edit_form'; if (!class_exists($classname)) { $classname = 'block_edit_form'; } } else { $classname = 'block_edit_form'; } $mform = new $classname($editpage->url, $block, $this->page); $mform->set_data($block->instance); if ($mform->is_cancelled()) { redirect($this->page->url); } else { if ($data = $mform->get_data()) { $bi = new stdClass(); $bi->id = $block->instance->id; // This may get overwritten by the special case handling below. $bi->pagetypepattern = $data->bui_pagetypepattern; $bi->showinsubcontexts = (bool) $data->bui_contexts; if (empty($data->bui_subpagepattern) || $data->bui_subpagepattern == '%@NULL@%') { $bi->subpagepattern = null; } else { $bi->subpagepattern = $data->bui_subpagepattern; } $systemcontext = context_system::instance(); $frontpagecontext = context_course::instance(SITEID); $parentcontext = context::instance_by_id($data->bui_parentcontextid); // Updating stickiness and contexts. See MDL-21375 for details. if (has_capability('moodle/site:manageblocks', $parentcontext)) { // Check permissions in destination // Explicitly set the default context $bi->parentcontextid = $parentcontext->id; if ($data->bui_editingatfrontpage) { // The block is being edited on the front page // The interface here is a special case because the pagetype pattern is // totally derived from the context menu. Here are the excpetions. MDL-30340 switch ($data->bui_contexts) { case BUI_CONTEXTS_ENTIRE_SITE: // The user wants to show the block across the entire site $bi->parentcontextid = $systemcontext->id; $bi->showinsubcontexts = true; $bi->pagetypepattern = '*'; break; case BUI_CONTEXTS_FRONTPAGE_SUBS: // The user wants the block shown on the front page and all subcontexts $bi->parentcontextid = $frontpagecontext->id; $bi->showinsubcontexts = true; $bi->pagetypepattern = '*'; break; case BUI_CONTEXTS_FRONTPAGE_ONLY: // The user want to show the front page on the frontpage only $bi->parentcontextid = $frontpagecontext->id; $bi->showinsubcontexts = false; $bi->pagetypepattern = 'site-index'; // This is the only relevant page type anyway but we'll set it explicitly just // in case the front page grows site-index-* subpages of its own later break; } } } $bits = explode('-', $bi->pagetypepattern); // hacks for some contexts if ($parentcontext->contextlevel == CONTEXT_COURSE && $parentcontext->instanceid != SITEID) { // For course context // is page type pattern is mod-*, change showinsubcontext to 1 if ($bits[0] == 'mod' || $bi->pagetypepattern == '*') { $bi->showinsubcontexts = 1; } else { $bi->showinsubcontexts = 0; } } else { if ($parentcontext->contextlevel == CONTEXT_USER) { // for user context // subpagepattern should be null if ($bits[0] == 'user' or $bits[0] == 'my') { // we don't need subpagepattern in usercontext $bi->subpagepattern = null; } } } $bi->defaultregion = $data->bui_defaultregion; $bi->defaultweight = $data->bui_defaultweight; $DB->update_record('block_instances', $bi); if (!empty($block->config)) { $config = clone $block->config; } else { $config = new stdClass(); } foreach ($data as $configfield => $value) { if (strpos($configfield, 'config_') !== 0) { continue; } $field = substr($configfield, 7); $config->{$field} = $value; } $block->instance_config_save($config); $bp = new stdClass(); $bp->visible = $data->bui_visible; $bp->region = $data->bui_region; $bp->weight = $data->bui_weight; $needbprecord = !$data->bui_visible || $data->bui_region != $data->bui_defaultregion || $data->bui_weight != $data->bui_defaultweight; if ($block->instance->blockpositionid && !$needbprecord) { $DB->delete_records('block_positions', array('id' => $block->instance->blockpositionid)); } else { if ($block->instance->blockpositionid && $needbprecord) { $bp->id = $block->instance->blockpositionid; $DB->update_record('block_positions', $bp); } else { if ($needbprecord) { $bp->blockinstanceid = $block->instance->id; $bp->contextid = $this->page->context->id; $bp->pagetype = $this->page->pagetype; if ($this->page->subpage) { $bp->subpage = $this->page->subpage; } else { $bp->subpage = ''; } $DB->insert_record('block_positions', $bp); } } } redirect($this->page->url); } else { $strheading = get_string('blockconfiga', 'moodle', $block->get_title()); $editpage->set_title($strheading); $editpage->set_heading($strheading); $bits = explode('-', $this->page->pagetype); if ($bits[0] == 'tag' && !empty($this->page->subpage)) { // better navbar for tag pages $editpage->navbar->add(get_string('tags'), new moodle_url('/tag/')); $tag = tag_get('id', $this->page->subpage, '*'); // tag search page doesn't have subpageid if ($tag) { $editpage->navbar->add($tag->name, new moodle_url('/tag/index.php', array('id' => $tag->id))); } } $editpage->navbar->add($block->get_title()); $editpage->navbar->add(get_string('configuration')); echo $output->header(); echo $output->heading($strheading, 2); $mform->display(); echo $output->footer(); exit; } } }
/** * Works out the URL for the users picture. * * This method is recommended as it avoids costly redirects of user pictures * if requests are made for non-existent files etc. * * @param renderer_base $renderer * @return moodle_url */ public function get_url(moodle_page $page, renderer_base $renderer = null) { global $CFG, $FULLME; if (is_null($renderer)) { $renderer = $page->get_renderer('core'); } if (!empty($CFG->forcelogin) and !isloggedin()) { // protect images if login required and not logged in; // do not use require_login() because it is expensive and not suitable here anyway return $renderer->pix_url('u/f1'); } // Sort out the filename and size. Size is only required for the gravatar // implementation presently. if (empty($this->size)) { $filename = 'f2'; $size = 35; } else { if ($this->size === true or $this->size == 1) { $filename = 'f1'; $size = 100; } else { if ($this->size >= 50) { $filename = 'f1'; $size = (int) $this->size; } else { $filename = 'f2'; $size = (int) $this->size; } } } // First we need to determine whether the user has uploaded a profile // picture of not. $fs = get_file_storage(); $context = get_context_instance(CONTEXT_USER, $this->user->id); $hasuploadedfile = $fs->file_exists($context->id, 'user', 'icon', 0, '/', $filename . '/.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', $filename . '/.jpg'); $imageurl = $renderer->pix_url('u/' . $filename); if ($hasuploadedfile && $this->user->picture == 1) { $path = '/'; if (clean_param($page->theme->name, PARAM_THEME) == $page->theme->name) { // We append the theme name to the file path if we have it so that // in the circumstance that the profile picture is not available // when the user actually requests it they still get the profile // picture for the correct theme. $path .= $page->theme->name . '/'; } // Set the image URL to the URL for the uploaded file. $imageurl = moodle_url::make_pluginfile_url($context->id, 'user', 'icon', NULL, $path, $filename); } else { if (!empty($CFG->enablegravatar)) { // Normalise the size variable to acceptable bounds if ($size < 1 || $size > 512) { $size = 35; } // Hash the users email address $md5 = md5(strtolower(trim($this->user->email))); // Build a gravatar URL with what we know. // If the currently requested page is https then we'll return an // https gravatar page. if (strpos($FULLME, 'https://') === 0) { $imageurl = new moodle_url("https://secure.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $imageurl->out(false))); } else { $imageurl = new moodle_url("http://www.gravatar.com/avatar/{$md5}", array('s' => $size, 'd' => $imageurl->out(false))); } } } // Return the URL that has been generated. return $imageurl; }
// Get the config argument for the chosen device. $themename = get_device_cfg_var_name($device); set_config($themename, $theme->name); // Create a new page for the display of the themes readme. // This ensures that the readme page is shown using the new theme. $confirmpage = new moodle_page(); $confirmpage->set_context($PAGE->context); $confirmpage->set_url($PAGE->url); $confirmpage->set_pagelayout($PAGE->pagelayout); $confirmpage->set_pagetype($PAGE->pagetype); $confirmpage->set_title($PAGE->title); $confirmpage->set_heading($PAGE->heading); // Get the core renderer for the new theme. $output = $confirmpage->get_renderer('core'); echo $output->header(); echo $output->heading(get_string('themesaved')); echo $output->box_start(); echo format_text(get_string('choosereadme', 'theme_'.$theme->name), FORMAT_MOODLE); echo $output->box_end(); echo $output->continue_button($CFG->wwwroot . '/theme/index.php'); echo $output->footer(); exit; } else if ($device && $unsettheme && confirm_sesskey() && ($device != 'default')) { //Unset the theme and continue. unset_config(get_device_cfg_var_name($device)); $device = ''; }
/** * @param moodle_page the page we are outputting to. * @return qtype_renderer the renderer to use for outputting this question. */ public function get_renderer(moodle_page $page) { return $page->get_renderer($this->qtype->plugin_name()); }
/** * @param moodle_page the page we are outputting to. * @return qtype_essay_format_renderer_base the response-format-specific renderer. */ public function get_format_renderer(moodle_page $page) { return $page->get_renderer('qtype_essay', 'format_' . $this->responseformat); }
public function test_get_url() { global $DB, $CFG; $this->resetAfterTest(); // Force SVG on so that we have predictable URL's. $CFG->svgicons = true; // verify new install contains expected defaults $this->assertEquals('standard', $CFG->theme); $this->assertEquals(1, $CFG->slasharguments); $this->assertEquals(1, $CFG->themerev); $this->assertEquals(0, $CFG->themedesignermode); $this->assertEquals('http://www.example.com/moodle', $CFG->wwwroot); $this->assertEquals($CFG->wwwroot, $CFG->httpswwwroot); $this->assertEquals(0, $CFG->enablegravatar); $this->assertEquals('mm', $CFG->gravatardefaulturl); // create some users $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $user1 = $this->getDataGenerator()->create_user(array('picture' => 11, 'email' => '*****@*****.**')); $context1 = context_user::instance($user1->id); $user2 = $this->getDataGenerator()->create_user(array('picture' => 0, 'email' => '*****@*****.**')); $context2 = context_user::instance($user2->id); $user3 = $this->getDataGenerator()->create_user(array('picture' => 1, 'deleted' => 1, 'email' => '*****@*****.**')); $context3 = context_user::instance($user3->id, IGNORE_MISSING); $this->assertEquals($user3->picture, 0); $this->assertNotEquals($user3->email, '*****@*****.**'); $this->assertFalse($context3); // try legacy picture == 1 $user1->picture = 1; $up1 = new user_picture($user1); $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=1', $up1->get_url($page, $renderer)->out(false)); $user1->picture = 11; // try valid user with picture when user context is not cached - 1 query expected context_helper::reset_caches(); $reads = $DB->perf_get_reads(); $up1 = new user_picture($user1); $this->assertEquals($reads, $DB->perf_get_reads()); $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false)); $this->assertEquals($reads + 1, $DB->perf_get_reads()); // try valid user with contextid hint - no queries expected $user1->contextid = $context1->id; context_helper::reset_caches(); $reads = $DB->perf_get_reads(); $up1 = new user_picture($user1); $this->assertEquals($reads, $DB->perf_get_reads()); $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false)); $this->assertEquals($reads, $DB->perf_get_reads()); // try valid user without image - no queries expected context_helper::reset_caches(); $reads = $DB->perf_get_reads(); $up2 = new user_picture($user2); $this->assertEquals($reads, $DB->perf_get_reads()); $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up2->get_url($page, $renderer)->out(false)); $this->assertEquals($reads, $DB->perf_get_reads()); // try guessing of deleted users - no queries expected unset($user3->deleted); context_helper::reset_caches(); $reads = $DB->perf_get_reads(); $up3 = new user_picture($user3); $this->assertEquals($reads, $DB->perf_get_reads()); $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false)); $this->assertEquals($reads, $DB->perf_get_reads()); // try incorrectly deleted users (with valid email and pciture flag) - some DB reads expected $user3->email = '*****@*****.**'; $user3->picture = 1; $reads = $DB->perf_get_reads(); $up3 = new user_picture($user3); $this->assertEquals($reads, $DB->perf_get_reads()); $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false)); $this->assertTrue($reads < $DB->perf_get_reads()); // test gravatar set_config('enablegravatar', 1); // deleted user can not have gravatar $user3->email = 'deleted'; $user3->picture = 0; $up3 = new user_picture($user3); $this->assertEquals($CFG->wwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false)); // verify defaults to misteryman (mm) $up2 = new user_picture($user2); $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=mm', $up2->get_url($page, $renderer)->out(false)); // without gravatardefaulturl, verify we pick own file set_config('gravatardefaulturl', ''); $up2 = new user_picture($user2); $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false)); // uploaded image takes precedence before gravatar $up1 = new user_picture($user1); $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false)); // https version $CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot); $up1 = new user_picture($user1); $this->assertEquals($CFG->httpswwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/standard/f2?rev=11', $up1->get_url($page, $renderer)->out(false)); $up3 = new user_picture($user3); $this->assertEquals($CFG->httpswwwroot . '/theme/image.php/standard/core/1/u/f2', $up3->get_url($page, $renderer)->out(false)); $up2 = new user_picture($user2); $this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Fpix%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false)); // now test gravatar with one theme having own images (afterburner) $CFG->httpswwwroot = $CFG->wwwroot; $this->assertTrue(file_exists("{$CFG->dirroot}/theme/afterburner/config.php")); set_config('theme', 'afterburner'); $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $up2 = new user_picture($user2); $this->assertEquals('http://www.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=http%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false)); // https version $CFG->httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot); $up2 = new user_picture($user2); $this->assertEquals('https://secure.gravatar.com/avatar/ab53a2911ddf9b4817ac01ddcd3d975f?s=35&d=https%3A%2F%2Fwww.example.com%2Fmoodle%2Ftheme%2Fafterburner%2Fpix_core%2Fu%2Ff2.png', $up2->get_url($page, $renderer)->out(false)); // end of gravatar tests // test themed images set_config('enablegravatar', 0); $this->assertTrue(file_exists("{$CFG->dirroot}/theme/formal_white/config.php")); // use any other theme set_config('theme', 'formal_white'); $CFG->httpswwwroot = $CFG->wwwroot; $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $up1 = new user_picture($user1); $this->assertEquals($CFG->wwwroot . '/pluginfile.php/' . $context1->id . '/user/icon/formal_white/f2?rev=11', $up1->get_url($page, $renderer)->out(false)); $up2 = new user_picture($user2); $this->assertEquals($CFG->wwwroot . '/theme/image.php/formal_white/core/1/u/f2', $up2->get_url($page, $renderer)->out(false)); // test non-slashargument images set_config('theme', 'standard'); $CFG->httpswwwroot = $CFG->wwwroot; $CFG->slasharguments = 0; $page = new moodle_page(); $page->set_url('/user/profile.php'); $page->set_context(context_system::instance()); $renderer = $page->get_renderer('core'); $up3 = new user_picture($user3); $this->assertEquals($CFG->wwwroot . '/theme/image.php?theme=standard&component=core&rev=1&image=u%2Ff2', $up3->get_url($page, $renderer)->out(false)); }
/** * Returns instance of page renderer used by this plugin * * @param moodle_page $page * @return renderer_base */ public function get_renderer(moodle_page $page) { return $page->get_renderer('format_' . $this->get_format()); }
/** * Handle showing/processing the submission from the block editing form. * @return boolean true if the form was submitted and the new config saved. Does not * return if the editing form was displayed. False otherwise. */ public function process_url_edit() { global $CFG, $DB, $PAGE; $blockid = optional_param('bui_editid', null, PARAM_INTEGER); if (!$blockid) { return false; } require_sesskey(); require_once $CFG->dirroot . '/blocks/edit_form.php'; $block = $this->find_instance($blockid); if (!$block->user_can_edit() && !$this->page->user_can_edit_blocks()) { throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('editblock')); } $editpage = new moodle_page(); $editpage->set_pagelayout('admin'); $editpage->set_course($this->page->course); $editpage->set_context($block->context); if ($this->page->cm) { $editpage->set_cm($this->page->cm); } $editurlbase = str_replace($CFG->wwwroot . '/', '/', $this->page->url->out_omit_querystring()); $editurlparams = $this->page->url->params(); $editurlparams['bui_editid'] = $blockid; $editpage->set_url($editurlbase, $editurlparams); $editpage->set_block_actions_done(); // At this point we are either going to redirect, or display the form, so // overwrite global $PAGE ready for this. (Formslib refers to it.) $PAGE = $editpage; $formfile = $CFG->dirroot . '/blocks/' . $block->name() . '/edit_form.php'; if (is_readable($formfile)) { require_once $formfile; $classname = 'block_' . $block->name() . '_edit_form'; if (!class_exists($classname)) { $classname = 'block_edit_form'; } } else { $classname = 'block_edit_form'; } $mform = new $classname($editpage->url, $block, $this->page); $mform->set_data($block->instance); if ($mform->is_cancelled()) { redirect($this->page->url); } else { if ($data = $mform->get_data()) { $bi = new stdClass(); $bi->id = $block->instance->id; $bi->pagetypepattern = $data->bui_pagetypepattern; if (empty($data->bui_subpagepattern) || $data->bui_subpagepattern == '%@NULL@%') { $bi->subpagepattern = null; } else { $bi->subpagepattern = $data->bui_subpagepattern; } $parentcontext = get_context_instance_by_id($data->bui_parentcontextid); $systemcontext = get_context_instance(CONTEXT_SYSTEM); // Updating stickiness and contexts. See MDL-21375 for details. if (has_capability('moodle/site:manageblocks', $parentcontext)) { // Check permissions in destination // Explicitly set the context $bi->parentcontextid = $parentcontext->id; // If the context type is > 0 then we'll explicitly set the block as sticky, otherwise not $bi->showinsubcontexts = (int) (!empty($data->bui_contexts)); // If the block wants to be system-wide, then explicitly set that if ($data->bui_contexts == 2) { // Only possible on a frontpage or system page $bi->parentcontextid = $systemcontext->id; } else { // The block doesn't want to be system-wide, so let's ensure that if ($parentcontext->id == $systemcontext->id) { // We need to move it to the front page $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID); $bi->parentcontextid = $frontpagecontext->id; $bi->pagetypepattern = '*'; // Just in case } } } $bi->defaultregion = $data->bui_defaultregion; $bi->defaultweight = $data->bui_defaultweight; $DB->update_record('block_instances', $bi); if (!empty($block->config)) { $config = clone $block->config; } else { $config = new stdClass(); } foreach ($data as $configfield => $value) { if (strpos($configfield, 'config_') !== 0) { continue; } $field = substr($configfield, 7); $config->{$field} = $value; } $block->instance_config_save($config); $bp = new stdClass(); $bp->visible = $data->bui_visible; $bp->region = $data->bui_region; $bp->weight = $data->bui_weight; $needbprecord = !$data->bui_visible || $data->bui_region != $data->bui_defaultregion || $data->bui_weight != $data->bui_defaultweight; if ($block->instance->blockpositionid && !$needbprecord) { $DB->delete_records('block_positions', array('id' => $block->instance->blockpositionid)); } else { if ($block->instance->blockpositionid && $needbprecord) { $bp->id = $block->instance->blockpositionid; $DB->update_record('block_positions', $bp); } else { if ($needbprecord) { $bp->blockinstanceid = $block->instance->id; $bp->contextid = $this->page->context->id; $bp->pagetype = $this->page->pagetype; if ($this->page->subpage) { $bp->subpage = $this->page->subpage; } else { $bp->subpage = ''; } $DB->insert_record('block_positions', $bp); } } } redirect($this->page->url); } else { $strheading = get_string('blockconfiga', 'moodle', $block->get_title()); $editpage->set_title($strheading); $editpage->set_heading($strheading); $editpage->navbar->add($strheading); $output = $editpage->get_renderer('core'); echo $output->header(); echo $output->heading($strheading, 2); $mform->display(); echo $output->footer(); exit; } } }