public function print_badges_list($badges, $userid, $profile = false, $external = false) { global $USER, $CFG; foreach ($badges as $badge) { if (!$external) { $context = ($badge->type == BADGE_TYPE_SITE) ? context_system::instance() : context_course::instance($badge->courseid); $bname = $badge->name; $imageurl = moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', 'f1', false); } else { $bname = $badge->assertion->badge->name; $imageurl = $badge->imageUrl; } $name = html_writer::tag('span', $bname, array('class' => 'badge-name')); $image = html_writer::empty_tag('img', array('src' => $imageurl, 'class' => 'badge-image')); if (!empty($badge->dateexpire) && $badge->dateexpire < time()) { $image .= $this->output->pix_icon('i/expired', get_string('expireddate', 'badges', userdate($badge->dateexpire)), 'moodle', array('class' => 'expireimage')); $name .= '(' . get_string('expired', 'badges') . ')'; } $download = $status = $push = ''; if (($userid == $USER->id) && !$profile) { $url = new moodle_url('mybadges.php', array('download' => $badge->id, 'hash' => $badge->uniquehash, 'sesskey' => sesskey())); $notexpiredbadge = (empty($badge->dateexpire) || $badge->dateexpire > time()); $backpackexists = badges_user_has_backpack($USER->id); if (!empty($CFG->badges_allowexternalbackpack) && $notexpiredbadge && $backpackexists) { $assertion = new moodle_url('/badges/assertion.php', array('b' => $badge->uniquehash)); $action = new component_action('click', 'addtobackpack', array('assertion' => $assertion->out(false))); $push = $this->output->action_icon(new moodle_url('#'), new pix_icon('t/backpack', get_string('addtobackpack', 'badges')), $action); } $download = $this->output->action_icon($url, new pix_icon('t/download', get_string('download'))); if ($badge->visible) { $url = new moodle_url('mybadges.php', array('hide' => $badge->issuedid, 'sesskey' => sesskey())); $status = $this->output->action_icon($url, new pix_icon('t/hide', get_string('makeprivate', 'badges'))); } else { $url = new moodle_url('mybadges.php', array('show' => $badge->issuedid, 'sesskey' => sesskey())); $status = $this->output->action_icon($url, new pix_icon('t/show', get_string('makepublic', 'badges'))); } } if (!$profile) { $url = new moodle_url('badge.php', array('hash' => $badge->uniquehash)); } else { if (!$external) { $url = new moodle_url('/badges/badge.php', array('hash' => $badge->uniquehash)); } else { $hash = hash('md5', $badge->hostedUrl); $url = new moodle_url('/badges/external.php', array('hash' => $hash, 'user' => $userid)); } } $actions = html_writer::tag('div', $push . $download . $status, array('class' => 'badge-actions')); $items[] = html_writer::link($url, $image . $actions . $name, array('title' => $bname)); } return html_writer::alist($items, array('class' => 'badges')); }
/** * Construct contents of testimonials block * * @param array $products The list of products to be output * @return string html to be displayed in testimonials block */ public function output_testimonials($config, $context) { $html = ''; $html = sprintf('<ul class="testimonial__list %s">', (int) $config->enable_rotation === 1 ? 'autoplay' : ''); for ($i = 1; $i <= (int) $config->testimonials_shown; $i++) { $quote = 'testimonial_quote_' . $i; $image = 'testimonial_photo_' . $i; $name = 'testimonial_name_' . $i; $position = 'testimonial_position_' . $i; $html .= sprintf('<li class="testimonial__item %s" data-id="%d">', $i === 1 ? 'active' : '', $i); // Output quote if (0 < strlen($config->{$quote})) { $html .= sprintf('<div class="testimonial__quote">%s</div>', $config->{$quote}); } $html .= '<div class="testimonial__person">'; // Output image if ((bool) $config->show_image) { $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'block_testimonials', 'photo', $config->{$image}); foreach ($files as $file) { $filename = $file->get_filename(); if ($filename !== '.') { $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $filename); if (!!$url) { $html .= sprintf('<img class="testimonial__photo" src="%s" alt="%s">', $url, $config->{$name}); } } } } $html .= '<div class="testimonial__info">'; // Output title if ((bool) $config->show_name) { $html .= sprintf('<h3 class="testimonial__name">%s</h3>', $config->{$name}); } // Output description if ((bool) $config->show_position) { $html .= sprintf('<h4 class="testimonial__position">%s</h4>', $config->{$position}); } $html .= '</div>'; $html .= '</div>'; $html .= '</li>'; } $html .= '</ul>'; // output pagination if ((bool) $config->show_pagination) { $html .= '<ul class="pagination">'; for ($i = 1; $i <= (int) $config->testimonials_shown; $i++) { $html .= sprintf('<li class="pagination__item %1$s"><a class="pagination__link" data-id="%2$d">%2$d</a></li>', $i === 1 ? 'active' : '', $i); } $html .= '</ul>'; } return $html; }
/** * 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); }
public function setInitilizationFile($CFG, $DB, $context, $fromform, $incremental, $maxbytes, $folderpath) { $this->setSimulationFilePath(""); file_save_draft_area_files($fromform->recordingfile, $context->id, 'atto_ejsapp', 'recordingfiles', $incremental, array('subdirs' => 0, 'maxbytes' => $maxbytes, 'maxfiles' => 1, 'accepted_types' => '.rec')); $fs = get_file_storage(); if ($files = $fs->get_area_files($context->id, 'atto_ejsapp', 'recordingfiles', $incremental, 'sortorder', false)) { foreach ($files as $file) { $fileurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); $this->setSimulationFilePath($fileurl); } } /*$file_records = $DB->get_records('files', array('contextid'=>$context->id, 'component'=>'atto_ejsapp', 'filearea'=>'recordingfiles', 'itemid'=>$incremental), 'filesize DESC'); $file_record = reset($file_records); if($file_record) { $fs = get_file_storage(); $file_state = $fs->get_file_by_id($file_record->id); $file_state->copy_content_to($folderpath . "simfiles/".$file_record->filename); $this->setSimulationFilePath($CFG->wwwroot . '/lib/editor/atto/plugins/ejsapp/jarfiles/' . $incremental . "/simfiles/".$file_record->filename); }*/ }
$speakerimg = $whiteboardpath . "images/speakerpressingactive.png"; $audio_tooltip = get_string('disableAudio','virtualclass'); } else { $dap = "false"; $classes = "audioTool deactive"; //$isplay = false; $speakermsg = get_string('enablespeaker', 'virtualclass'); $pressingimg = $whiteboardpath . "images/speakerpressing.png"; $audio_tooltip = get_string('enableAudio','virtualclass'); } // Output starts here. echo $OUTPUT->header(); // Default image if webcam disable. if ($USER->id) { $userpicture = moodle_url::make_pluginfile_url(context_user::instance($USER->id)->id, 'user', 'icon', null, '/', 'f2'); $src = $userpicture->out(false); } else { $src = 'bundle/virtualclass/images/quality-support.png'; } // Javascript variables. ?> <script type="text/javascript"> wbUser.virtualclassPlay = '<?php echo $isplay; ?>'; wbUser.vcSid = '<?php echo $vcSid; ?>'; wbUser.imageurl = '<?php echo $src; ?>'; wbUser.id = '<?php echo $USER->id; ?>'; wbUser.socketOn = '<?php echo $info; ?>'; wbUser.dataInfo = 0; //layout and all inofrmation is not validated since long time wbUser.room = '<?php echo $course->id . "_" . $cm->id; ?>'; wbUser.sid = '<?php echo $sid; ?>';
/** * Get list of course participants. * * @param int $courseid * @param text $withcapability * @param int $groupid * @param bool $onlyactive * @return array of course participants * @since Moodle 2.0 * @deprecated Moodle 2.2 MDL-29106 - Please do not call this function any more. * @todo MDL-31194 This will be deleted in Moodle 2.5. * @see core_enrol_external::get_enrolled_users() */ public static function get_enrolled_users($courseid, $withcapability = null, $groupid = null, $onlyactive = false) { global $DB, $CFG, $USER; // Do basic automatic PARAM checks on incoming data, using params description // If any problems are found then exceptions are thrown with helpful error messages $params = self::validate_parameters(self::get_enrolled_users_parameters(), array('courseid' => $courseid, 'withcapability' => $withcapability, 'groupid' => $groupid, 'onlyactive' => $onlyactive)); $coursecontext = context_course::instance($params['courseid'], IGNORE_MISSING); if ($courseid == SITEID) { $context = context_system::instance(); } else { $context = $coursecontext; } try { self::validate_context($context); } catch (Exception $e) { $exceptionparam = new stdClass(); $exceptionparam->message = $e->getMessage(); $exceptionparam->courseid = $params['courseid']; throw new moodle_exception('errorcoursecontextnotvalid', 'webservice', '', $exceptionparam); } if ($courseid == SITEID) { require_capability('moodle/site:viewparticipants', $context); } else { require_capability('moodle/course:viewparticipants', $context); } if ($withcapability) { require_capability('moodle/role:review', $coursecontext); } if ($groupid && groups_is_member($groupid)) { require_capability('moodle/site:accessallgroups', $coursecontext); } if ($onlyactive) { require_capability('moodle/course:enrolreview', $coursecontext); } list($sqlparams, $params) = get_enrolled_sql($coursecontext, $withcapability, $groupid, $onlyactive); $sql = "SELECT ue.userid, e.courseid, u.firstname, u.lastname, u.username, c.id as usercontextid\n FROM {user_enrolments} ue\n JOIN {enrol} e ON (e.id = ue.enrolid)\n JOIN {user} u ON (ue.userid = u.id)\n JOIN {context} c ON (u.id = c.instanceid AND contextlevel = " . CONTEXT_USER . ")\n WHERE e.courseid = :courseid AND ue.userid IN ({$sqlparams})\n GROUP BY ue.userid, e.courseid, u.firstname, u.lastname, u.username, c.id"; $params['courseid'] = $courseid; $enrolledusers = $DB->get_records_sql($sql, $params); $result = array(); $isadmin = is_siteadmin($USER); $canviewfullnames = has_capability('moodle/site:viewfullnames', $context); foreach ($enrolledusers as $enrolleduser) { $profilimgurl = moodle_url::make_pluginfile_url($enrolleduser->usercontextid, 'user', 'icon', NULL, '/', 'f1'); $profilimgurlsmall = moodle_url::make_pluginfile_url($enrolleduser->usercontextid, 'user', 'icon', NULL, '/', 'f2'); $resultuser = array('courseid' => $enrolleduser->courseid, 'userid' => $enrolleduser->userid, 'fullname' => fullname($enrolleduser), 'profileimgurl' => $profilimgurl->out(false), 'profileimgurlsmall' => $profilimgurlsmall->out(false)); // check if we can return username if ($isadmin) { $resultuser['username'] = $enrolleduser->username; } // check if we can return first and last name if ($isadmin or $canviewfullnames) { $resultuser['firstname'] = $enrolleduser->firstname; $resultuser['lastname'] = $enrolleduser->lastname; } $result[] = $resultuser; } return $result; }
function extend_settings_navigation($node) { global $CFG, $USER, $OUTPUT; // get users submission if there is one $submission = $this->get_submission(); if (is_enrolled($this->context, $USER, 'mod/assignment:submit')) { $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked); } else { $editable = false; } // If the user has submitted something add some related links and data if (isset($submission->numfiles) and $submission->numfiles) { // Add a view link to the settings nav $link = new moodle_url('/mod/assignment/view.php', array('id' => $this->cm->id)); $node->add(get_string('viewmysubmission', 'assignment'), $link, navigation_node::TYPE_SETTING); if (!empty($submission->timemodified)) { $submissionnode = $node->add(get_string('submitted', 'assignment') . ' ' . userdate($submission->timemodified)); $submissionnode->text = preg_replace('#([^,])\\s#', '$1 ', $submissionnode->text); $submissionnode->add_class('note'); if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) { $submissionnode->add_class('early'); } else { $submissionnode->add_class('late'); } } } // Check if the user has uploaded any files, if so we can add some more stuff to the settings nav if ($submission && is_enrolled($this->context, $USER, 'mod/assignment:submit') && $this->count_user_files($submission->id)) { $fs = get_file_storage(); if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) { $filenode = $node->add(get_string('submission', 'assignment')); foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $link = moodle_url::make_pluginfile_url($this->context->id, 'mod_assignment', 'submission', $submission->id, $file->get_filepath(), $filename); $filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_file_icon($file), '')); } } } }
// // You should have received a copy of the GNU General Public License // along with Moodle. If not, see <http://www.gnu.org/licenses/>. /** * BC user image location * * @package core * @subpackage file * @copyright 2010 Petr Skoda (http://skodak.org) * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ define('NO_DEBUG_DISPLAY', true); define('NOMOODLECOOKIE', 1); require '../config.php'; $PAGE->set_url('/user/pix.php'); $PAGE->set_context(null); $relativepath = get_file_argument('pix.php'); $args = explode('/', trim($relativepath, '/')); if (count($args) == 2) { $userid = (int) $args[0]; if ($args[1] === 'f1.jpg') { $image = 'f1'; } else { $image = 'f2'; } if ($usercontext = get_context_instance(CONTEXT_USER, $userid)) { $url = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', $image); redirect($url); } } redirect($OUTPUT->pix_url('u/f1'));
admin_externalpage_setup('toolgeneratortestplan'); // Start page. echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('maketestplan', 'tool_generator')); // Information message. $context = context_system::instance(); $markdownlink = '[' . tool_generator_testplan_backend::get_repourl() . '](' . tool_generator_testplan_backend::get_repourl() . ')'; echo $OUTPUT->box(format_text(get_string('testplanexplanation', 'tool_generator', $markdownlink), FORMAT_MARKDOWN, array('context' => $context))); // Check debugging is set to DEVELOPER. if (!debugging('', DEBUG_DEVELOPER)) { echo $OUTPUT->notification(get_string('error_notdebugging', 'tool_generator')); echo $OUTPUT->footer(); exit; } // Set up the form. $mform = new tool_generator_make_testplan_form('maketestplan.php'); if ($data = $mform->get_data()) { // Creating both test plan and users files. $testplanfile = tool_generator_testplan_backend::create_testplan_file($data->courseid, $data->size); $usersfile = tool_generator_testplan_backend::create_users_file($data->courseid, $data->updateuserspassword); // Test plan link. $testplanurl = moodle_url::make_pluginfile_url($testplanfile->get_contextid(), $testplanfile->get_component(), $testplanfile->get_filearea(), $testplanfile->get_itemid(), $testplanfile->get_filepath(), $testplanfile->get_filename()); echo html_writer::div(html_writer::link($testplanurl, get_string('downloadtestplan', 'tool_generator'))); // Users file link. $usersfileurl = moodle_url::make_pluginfile_url($usersfile->get_contextid(), $usersfile->get_component(), $usersfile->get_filearea(), $usersfile->get_itemid(), $usersfile->get_filepath(), $usersfile->get_filename()); echo html_writer::div(html_writer::link($usersfileurl, get_string('downloadusersfile', 'tool_generator'))); } else { // Display form. $mform->display(); } echo $OUTPUT->footer();
/** * 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; }
function my_badges($username, $n = 10) { global $CFG; require_once $CFG->libdir . "/badgeslib.php"; $username = utf8_decode($username); $username = strtolower($username); $user = get_complete_user_data('username', $username); if (!$user) { return array(); } $badges = badges_get_user_badges($user->id, NULL, 0, $n); $bs = array(); foreach ($badges as $badge) { $b = array(); $b['name'] = $badge->name; $b['hash'] = $badge->uniquehash; $context = $badge->type == BADGE_TYPE_SITE ? context_system::instance() : context_course::instance($badge->courseid); $image_url = moodle_url::make_pluginfile_url($context->id, 'badges', 'badgeimage', $badge->id, '/', 'f1', false); $b['image_url'] = (string) $image_url; $bs[] = $b; } return $bs; }
function block_referentiel_get_manage_block_files($contextid, $filearea, $docid, $titre, $appli) { // retourne la liste des liens vers des fichiers stockes dans le filearea // propose la suppression global $CFG; global $OUTPUT; $total_size = 0; $nfile = 0; // fileareas autorisees $fileareas = array('referentiel'); if (!in_array($filearea, $fileareas)) { return false; } $strfilepath = 'filepath'; $strfilename = get_string('filename', 'referentiel'); $strfilesize = get_string('filesize', 'referentiel'); $strtimecreated = get_string('timecreated', 'referentiel'); $strtimemodified = get_string('timemodified', 'referentiel'); $strmimetype = get_string('mimetype', 'referentiel'); $strmenu = get_string('delete'); $strurl = get_string('url'); $fs = get_file_storage(); if ($files = $fs->get_area_files($contextid, 'block_referentiel', $filearea, $docid, "timemodified", false)) { // DEBUG //print_object($files); //exit; $table = new html_table(); $table->head = array($strfilename, $strfilesize, $strtimecreated, $strtimemodified, $strmimetype, $strmenu); $table->align = array("center", "left", "left", "left", "center"); foreach ($files as $file) { // print_object($file); $filesize = $file->get_filesize(); $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $filepath = $file->get_filepath(); $timecreated = userdate($file->get_timecreated(), "%Y/%m/%d-%H:%M", 99, false); $timemodified = userdate($file->get_timemodified(), "%Y/%m/%d-%H:%M", 99, false); $fullpath = '/' . $contextid . '/block_referentiel/' . $filearea . '/' . $docid . $filepath . $filename; //echo "<br />FULLPATH : ".$fullpath."\n"; //$link1 = new moodle_url($CFG->wwwroot.'/pluginfile.php'.$fullpath); //echo "<br />LINK1 : ".$link1."\n"; $link = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename()); // echo "<br />LINK : ".$link."\n"; $url = '<a href="' . $link . '">' . $filename . '</a><br />' . "\n"; $delete_link = '<input type="checkbox" name="deletefile[]" value="' . $fullpath . '" />' . "\n"; $table->data[] = array($url, display_size($filesize), $timecreated, $timemodified, $mimetype, $delete_link); $total_size += $filesize; $nfile++; } $table->data[] = array(get_string('nbfile', 'referentiel', $nfile), get_string('totalsize', 'referentiel', display_size($total_size)), '', '', '', ''); echo $OUTPUT->box_start('generalbox boxaligncenter'); echo '<div align="center">' . "\n"; echo '<h3>' . $titre . '</h3>' . "\n"; echo '<form method="post" action="' . $appli . '">' . "\n"; echo html_writer::table($table); echo "\n" . '<input type="hidden" name="sesskey" value="' . sesskey() . '" />' . "\n"; echo '<input type="submit" value="' . get_string('delete') . '" />' . "\n"; echo '</form>' . "\n"; echo '</div>' . "\n"; echo $OUTPUT->box_end(); } }
$shown++; if (floor($shown / $perpage) != $page) { continue; } $actions = array(); $deleteurl = new moodle_url('/mod/emarking/print/orphanpages.php', array('id' => $cm->id, 'delete' => $file->get_id())); $rotateurl = new moodle_url('/mod/emarking/print/orphanpages.php', array('id' => $cm->id, 'file' => $file->get_id(), 'rotate' => true)); if ($usercanupload) { $actions[] = $OUTPUT->action_icon($rotateurl, new pix_icon('i/return', get_string('rotatepage', 'mod_emarking'))); $actions[] = $OUTPUT->pix_icon('i/edit', get_string('rotatepage', 'mod_emarking'), '', array('style' => 'cursor:pointer;', 'onclick' => 'showfixform(' . $file->get_id() . ')')); } if (isset($file->anonymous)) { $actions[] = $OUTPUT->action_icon(moodle_url::make_pluginfile_url($context->id, 'mod_emarking', 'orphanpages', $emarking->id, '/', $file->anonymous->get_filename()), new pix_icon('i/show', get_string('anonymousfile', 'mod_emarking'))); } $actions[] = html_writer::div(html_writer::div(get_string('student', 'grades'), NULL, array('id' => 'error-student-' . $file->get_id())) . html_writer::tag('input', NULL, array('name' => 'student-' . $file->get_id(), 'type' => 'text', 'class' => 'studentname', 'tabindex' => $shown * 2, 'fileid' => $file->get_id())) . '<br/>' . html_writer::div(get_string('page', 'mod_emarking'), NULL, array('id' => 'error-pagenumber-' . $file->get_id())) . html_writer::select($options, 'page-' . $file->get_id(), '', false, array('tabindex' => $shown * 2 + 1, 'id' => 'page-' . $file->get_id())) . '<br/>' . html_writer::tag('button', get_string('cancel'), array('class' => 'btn', 'onclick' => 'return cancelchanges(' . $file->get_id() . ');')) . html_writer::tag('button', get_string('submit'), array('class' => 'btn', 'onclick' => 'return savechanges(' . $file->get_id() . ');')) . html_writer::tag('input', NULL, array('type' => 'hidden', 'name' => 'studentid-' . $file->get_id(), 'id' => 's' . $file->get_id())), 'fixorphanpage', array('id' => 'fix-' . $file->get_id())) . html_writer::div('', '', array('id' => 'content-' . $file->get_id())); $imgurl = moodle_url::make_pluginfile_url($context->id, 'mod_emarking', 'orphanpages', $emarking->id, '/', $file->get_filename()); $imgurl .= '?r=' . random_string(); $data = array($OUTPUT->action_link($imgurl, html_writer::div(html_writer::img($imgurl, $file->get_filename()), '', array('style' => 'height:100px; overflow:hidden; max-width:600px;'))), implode(' ', $actions)); if ($usercanupload) { $data[] = html_writer::checkbox('d[]', $file->get_id(), false, ''); } $table->data[] = $data; } echo html_writer::table($table); echo $OUTPUT->paging_bar($numorphanpages, $page, $perpage, $url); if ($usercanupload) { echo html_writer::start_tag('input', array('type' => 'submit', 'value' => get_string('deleteselectedpages', 'mod_emarking'), 'style' => 'float:right;')); echo "</form>"; } } $students = get_enrolled_users($context, 'mod/emarking:submit');
/** * Constructor. * * @param array $params The fields to initialise the renderable. */ public function __construct(array $params) { global $OUTPUT; $diff = array_diff_key($params, array_flip(self::$required)); if (count($diff) > 0) { throw new coding_exception('Missing, or unexpected, properties'); } // Assigning the properties. foreach ($params as $key => $value) { if (in_array($key, self::$required)) { $this->{$key} = $value; } } // Has next level. if (!empty($this->nextlevelxp) && $this->nextlevelxp > $this->xp) { $this->hasnextlevel = true; $this->nextlevel = $this->level + 1; // Percentage. $this->xpinlevel = $this->xp - $this->levelxp; $this->xpforlevel = $this->nextlevelxp - $this->levelxp; $this->percentage = round($this->xpinlevel / $this->xpforlevel * 100); } else { $this->nextlevel = null; $this->hasnextlevel = true; $this->xpforlevel = $this->xp; $this->xpinlevel = $this->xp; $this->percentage = 100; } // Image URL. $this->levelimgsrc = moodle_url::make_pluginfile_url(context_course::instance($this->courseid)->id, 'block_xp', 'badges', 0, '/', $this->level); }
/** * 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; }
/** * Print a specified group's avatar. * * @global object * @uses CONTEXT_COURSE * @param array|stdClass $group A single {@link group} object OR array of groups. * @param int $courseid The course ID. * @param boolean $large Default small picture, or large. * @param boolean $return If false print picture, otherwise return the output as string * @param boolean $link Enclose image in a link to view specified course? * @return string|void Depending on the setting of $return */ function print_group_picture($group, $courseid, $large = false, $return = false, $link = true) { global $CFG; if (is_array($group)) { $output = ''; foreach ($group as $g) { $output .= print_group_picture($g, $courseid, $large, true, $link); } if ($return) { return $output; } else { echo $output; return; } } $context = get_context_instance(CONTEXT_COURSE, $courseid); // If there is no picture, do nothing if (!$group->picture) { return ''; } // If picture is hidden, only show to those with course:managegroups if ($group->hidepicture and !has_capability('moodle/course:managegroups', $context)) { return ''; } if ($link or has_capability('moodle/site:accessallgroups', $context)) { $output = '<a href="' . $CFG->wwwroot . '/user/index.php?id=' . $courseid . '&group=' . $group->id . '">'; } else { $output = ''; } if ($large) { $file = 'f1'; } else { $file = 'f2'; } $grouppictureurl = moodle_url::make_pluginfile_url($context->id, 'group', 'icon', $group->id, '/', $file); $output .= '<img class="grouppicture" src="' . $grouppictureurl . '"' . ' alt="' . s(get_string('group') . ' ' . $group->name) . '" title="' . s($group->name) . '"/>'; if ($link or has_capability('moodle/site:accessallgroups', $context)) { $output .= '</a>'; } if ($return) { return $output; } else { echo $output; } }
/** * Make url based on file for theme_snap components only. * * @param stored_file $file * @return \moodle_url | bool */ private static function snap_pluginfile_url($file) { if (!$file) { return false; } else { return \moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_timemodified(), $file->get_filepath(), $file->get_filename()); } }
/** * This is a function used to detect media types and generate html code. * * @global object $CFG * @global object $PAGE * @param object $lesson * @param object $context * @return string $code the html code of media */ function lesson_get_media_html($lesson, $context) { global $CFG, $PAGE, $OUTPUT; require_once "{$CFG->libdir}/resourcelib.php"; // get the media file link if (strpos($lesson->mediafile, '://') !== false) { $url = new moodle_url($lesson->mediafile); } else { // the timemodified is used to prevent caching problems, instead of '/' we should better read from files table and use sortorder $url = moodle_url::make_pluginfile_url($context->id, 'mod_lesson', 'mediafile', $lesson->timemodified, '/', ltrim($lesson->mediafile, '/')); } $title = $lesson->mediafile; $clicktoopen = html_writer::link($url, get_string('download')); $mimetype = resourcelib_guess_url_mimetype($url); $extension = resourcelib_get_extension($url->out(false)); $mediarenderer = $PAGE->get_renderer('core', 'media'); $embedoptions = array(core_media::OPTION_TRUSTED => true, core_media::OPTION_BLOCK => true); // find the correct type and print it out if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // It's an image $code = resourcelib_embed_image($url, $title); } else { if ($mediarenderer->can_embed_url($url, $embedoptions)) { // Media (audio/video) file. $code = $mediarenderer->embed_url($url, $title, 0, 0, $embedoptions); } else { // anything else - just try object tag enlarged as much as possible $code = resourcelib_embed_general($url, $title, $clicktoopen, $mimetype); } } return $code; }
} $added = page_editor::set_annotations($grade->id, $index, $page->annotations); if ($added != count($page->annotations)) { array_push($response->errors, get_string('couldnotsavepage', 'assignfeedback_editpdf', $index + 1)); } echo json_encode($response); die; } else { if ($action == 'generatepdf') { require_capability('mod/assign:grade', $context); $response = new stdClass(); $grade = $assignment->get_user_grade($userid, true, $attemptnumber); $file = document_services::generate_feedback_document($assignment, $userid, $attemptnumber); $response->url = ''; if ($file) { $url = moodle_url::make_pluginfile_url($assignment->get_context()->id, 'assignfeedback_editpdf', document_services::FINAL_PDF_FILEAREA, $grade->id, '/', $file->get_filename(), false); $response->url = $url->out(true); $response->filename = $file->get_filename(); } echo json_encode($response); die; } else { if ($action == 'loadquicklist') { require_capability('mod/assign:grade', $context); $result = comments_quick_list::get_comments(); echo json_encode($result); die; } else { if ($action == 'addtoquicklist') { require_capability('mod/assign:grade', $context); $comment = required_param('commenttext', PARAM_RAW);
/** * Displays a backup files viewer * * @global stdClass $USER * @param backup_files_viewer $tree * @return string */ public function render_backup_files_viewer(backup_files_viewer $viewer) { global $CFG; $files = $viewer->files; $table = new html_table(); $table->attributes['class'] = 'backup-files-table generaltable'; $table->head = array(get_string('filename', 'backup'), get_string('time'), get_string('size'), get_string('download'), get_string('restore')); $table->width = '100%'; $table->data = array(); foreach ($files as $file) { if ($file->is_directory()) { continue; } $fileurl = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename(), true); $params = array(); $params['action'] = 'choosebackupfile'; $params['filename'] = $file->get_filename(); $params['filepath'] = $file->get_filepath(); $params['component'] = $file->get_component(); $params['filearea'] = $file->get_filearea(); $params['filecontextid'] = $file->get_contextid(); $params['contextid'] = $viewer->currentcontext->id; $params['itemid'] = $file->get_itemid(); $restoreurl = new moodle_url('/backup/restorefile.php', $params); $table->data[] = array($file->get_filename(), userdate($file->get_timemodified()), display_size($file->get_filesize()), html_writer::link($fileurl, get_string('download')), html_writer::link($restoreurl, get_string('restore'))); } $html = html_writer::table($table); $html .= $this->output->single_button(new moodle_url('/backup/backupfilesedit.php', array('currentcontext' => $viewer->currentcontext->id, 'contextid' => $viewer->filecontext->id, 'filearea' => $viewer->filearea, 'component' => $viewer->component, 'returnurl' => $this->page->url->out())), get_string('managefiles', 'backup'), 'post'); return $html; }
/** * * Give user record from mdl_user, build an array conntains * all user details * * Warning: description file urls are 'webservice/pluginfile.php' is use. * it can be changed with $CFG->moodlewstextformatlinkstoimagesfile * * @param stdClass $user user record from mdl_user * @param stdClass $context context object * @param stdClass $course moodle course * @param array $userfields required fields * @return array|null */ function user_get_user_details($user, $course = null, array $userfields = array()) { global $USER, $DB, $CFG; require_once $CFG->dirroot . "/user/profile/lib.php"; //custom field library require_once $CFG->dirroot . "/lib/filelib.php"; // file handling on description and friends $defaultfields = user_get_default_fields(); if (empty($userfields)) { $userfields = $defaultfields; } foreach ($userfields as $thefield) { if (!in_array($thefield, $defaultfields)) { throw new moodle_exception('invaliduserfield', 'error', '', $thefield); } } // Make sure id and fullname are included if (!in_array('id', $userfields)) { $userfields[] = 'id'; } if (!in_array('fullname', $userfields)) { $userfields[] = 'fullname'; } if (!empty($course)) { $context = context_course::instance($course->id); $usercontext = context_user::instance($user->id); $canviewdetailscap = has_capability('moodle/user:viewdetails', $context) || has_capability('moodle/user:viewdetails', $usercontext); } else { $context = context_user::instance($user->id); $usercontext = $context; $canviewdetailscap = has_capability('moodle/user:viewdetails', $usercontext); } $currentuser = $user->id == $USER->id; $isadmin = is_siteadmin($USER); $showuseridentityfields = get_extra_user_fields($context); if (!empty($course)) { $canviewhiddenuserfields = has_capability('moodle/course:viewhiddenuserfields', $context); } else { $canviewhiddenuserfields = has_capability('moodle/user:viewhiddendetails', $context); } $canviewfullnames = has_capability('moodle/site:viewfullnames', $context); if (!empty($course)) { $canviewuseremail = has_capability('moodle/course:useremail', $context); } else { $canviewuseremail = false; } $cannotviewdescription = !empty($CFG->profilesforenrolledusersonly) && !$currentuser && !$DB->record_exists('role_assignments', array('userid' => $user->id)); if (!empty($course)) { $canaccessallgroups = has_capability('moodle/site:accessallgroups', $context); } else { $canaccessallgroups = false; } if (!$currentuser && !$canviewdetailscap && !has_coursecontact_role($user->id)) { // skip this user details return null; } $userdetails = array(); $userdetails['id'] = $user->id; if (($isadmin or $currentuser) and in_array('username', $userfields)) { $userdetails['username'] = $user->username; } if ($isadmin or $canviewfullnames) { if (in_array('firstname', $userfields)) { $userdetails['firstname'] = $user->firstname; } if (in_array('lastname', $userfields)) { $userdetails['lastname'] = $user->lastname; } } $userdetails['fullname'] = fullname($user); if (in_array('customfields', $userfields)) { $fields = $DB->get_recordset_sql("SELECT f.*\n FROM {user_info_field} f\n JOIN {user_info_category} c\n ON f.categoryid=c.id\n ORDER BY c.sortorder ASC, f.sortorder ASC"); $userdetails['customfields'] = array(); foreach ($fields as $field) { require_once $CFG->dirroot . '/user/profile/field/' . $field->datatype . '/field.class.php'; $newfield = 'profile_field_' . $field->datatype; $formfield = new $newfield($field->id, $user->id); if ($formfield->is_visible() and !$formfield->is_empty()) { $userdetails['customfields'][] = array('name' => $formfield->field->name, 'value' => $formfield->data, 'type' => $field->datatype, 'shortname' => $formfield->field->shortname); } } $fields->close(); // unset customfields if it's empty if (empty($userdetails['customfields'])) { unset($userdetails['customfields']); } } // profile image if (in_array('profileimageurl', $userfields)) { $profileimageurl = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', 'f1'); $userdetails['profileimageurl'] = $profileimageurl->out(false); } if (in_array('profileimageurlsmall', $userfields)) { $profileimageurlsmall = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', 'f2'); $userdetails['profileimageurlsmall'] = $profileimageurlsmall->out(false); } //hidden user field if ($canviewhiddenuserfields) { $hiddenfields = array(); // address, phone1 and phone2 not appears in hidden fields list // but require viewhiddenfields capability // according to user/profile.php if ($user->address && in_array('address', $userfields)) { $userdetails['address'] = $user->address; } } else { $hiddenfields = array_flip(explode(',', $CFG->hiddenuserfields)); } if ($user->phone1 && in_array('phone1', $userfields) && (in_array('phone1', $showuseridentityfields) or $canviewhiddenuserfields)) { $userdetails['phone1'] = $user->phone1; } if ($user->phone2 && in_array('phone2', $userfields) && (in_array('phone2', $showuseridentityfields) or $canviewhiddenuserfields)) { $userdetails['phone2'] = $user->phone2; } if (isset($user->description) && (!isset($hiddenfields['description']) && !$cannotviewdescription or $isadmin)) { if (in_array('description', $userfields)) { // Always return the descriptionformat if description is requested. list($userdetails['description'], $userdetails['descriptionformat']) = external_format_text($user->description, $user->descriptionformat, $usercontext->id, 'user', 'profile', null); } } if (in_array('country', $userfields) && (!isset($hiddenfields['country']) or $isadmin) && $user->country) { $userdetails['country'] = $user->country; } if (in_array('city', $userfields) && (!isset($hiddenfields['city']) or $isadmin) && $user->city) { $userdetails['city'] = $user->city; } if (in_array('url', $userfields) && $user->url && (!isset($hiddenfields['webpage']) or $isadmin)) { $url = $user->url; if (strpos($user->url, '://') === false) { $url = 'http://' . $url; } $user->url = clean_param($user->url, PARAM_URL); $userdetails['url'] = $user->url; } if (in_array('icq', $userfields) && $user->icq && (!isset($hiddenfields['icqnumber']) or $isadmin)) { $userdetails['icq'] = $user->icq; } if (in_array('skype', $userfields) && $user->skype && (!isset($hiddenfields['skypeid']) or $isadmin)) { $userdetails['skype'] = $user->skype; } if (in_array('yahoo', $userfields) && $user->yahoo && (!isset($hiddenfields['yahooid']) or $isadmin)) { $userdetails['yahoo'] = $user->yahoo; } if (in_array('aim', $userfields) && $user->aim && (!isset($hiddenfields['aimid']) or $isadmin)) { $userdetails['aim'] = $user->aim; } if (in_array('msn', $userfields) && $user->msn && (!isset($hiddenfields['msnid']) or $isadmin)) { $userdetails['msn'] = $user->msn; } if (in_array('firstaccess', $userfields) && (!isset($hiddenfields['firstaccess']) or $isadmin)) { if ($user->firstaccess) { $userdetails['firstaccess'] = $user->firstaccess; } else { $userdetails['firstaccess'] = 0; } } if (in_array('lastaccess', $userfields) && (!isset($hiddenfields['lastaccess']) or $isadmin)) { if ($user->lastaccess) { $userdetails['lastaccess'] = $user->lastaccess; } else { $userdetails['lastaccess'] = 0; } } if (in_array('email', $userfields) && ($isadmin or $currentuser or $canviewuseremail or in_array('email', $showuseridentityfields) or $user->maildisplay == 1 or $user->maildisplay == 2 and enrol_sharing_course($user, $USER))) { $userdetails['email'] = $user->email; } if (in_array('interests', $userfields) && !empty($CFG->usetags)) { require_once $CFG->dirroot . '/tag/lib.php'; if ($interests = tag_get_tags_csv('user', $user->id, TAG_RETURN_TEXT)) { $userdetails['interests'] = $interests; } } //Departement/Institution/Idnumber are not displayed on any profile, however you can get them from editing profile. if ($isadmin or $currentuser or in_array('idnumber', $showuseridentityfields)) { if (in_array('idnumber', $userfields) && $user->idnumber) { $userdetails['idnumber'] = $user->idnumber; } } if ($isadmin or $currentuser or in_array('institution', $showuseridentityfields)) { if (in_array('institution', $userfields) && $user->institution) { $userdetails['institution'] = $user->institution; } } if ($isadmin or $currentuser or in_array('department', $showuseridentityfields)) { if (in_array('department', $userfields) && isset($user->department)) { //isset because it's ok to have department 0 $userdetails['department'] = $user->department; } } if (in_array('roles', $userfields) && !empty($course)) { // not a big secret $roles = get_user_roles($context, $user->id, false); $userdetails['roles'] = array(); foreach ($roles as $role) { $userdetails['roles'][] = array('roleid' => $role->roleid, 'name' => $role->name, 'shortname' => $role->shortname, 'sortorder' => $role->sortorder); } } // If groups are in use and enforced throughout the course, then make sure we can meet in at least one course level group if (in_array('groups', $userfields) && !empty($course) && $canaccessallgroups) { $usergroups = groups_get_all_groups($course->id, $user->id, $course->defaultgroupingid, 'g.id, g.name,g.description,g.descriptionformat'); $userdetails['groups'] = array(); foreach ($usergroups as $group) { list($group->description, $group->descriptionformat) = external_format_text($group->description, $group->descriptionformat, $context->id, 'group', 'description', $group->id); $userdetails['groups'][] = array('id' => $group->id, 'name' => $group->name, 'description' => $group->description, 'descriptionformat' => $group->descriptionformat); } } //list of courses where the user is enrolled if (in_array('enrolledcourses', $userfields) && !isset($hiddenfields['mycourses'])) { $enrolledcourses = array(); if ($mycourses = enrol_get_users_courses($user->id, true)) { foreach ($mycourses as $mycourse) { if ($mycourse->category) { $coursecontext = context_course::instance($mycourse->id); $enrolledcourse = array(); $enrolledcourse['id'] = $mycourse->id; $enrolledcourse['fullname'] = format_string($mycourse->fullname, true, array('context' => $coursecontext)); $enrolledcourse['shortname'] = format_string($mycourse->shortname, true, array('context' => $coursecontext)); $enrolledcourses[] = $enrolledcourse; } } $userdetails['enrolledcourses'] = $enrolledcourses; } } //user preferences if (in_array('preferences', $userfields) && $currentuser) { $preferences = array(); $userpreferences = get_user_preferences(); foreach ($userpreferences as $prefname => $prefvalue) { $preferences[] = array('name' => $prefname, 'value' => $prefvalue); } $userdetails['preferences'] = $preferences; } return $userdetails; }
function get_content() { global $CFG, $PAGE, $OUTPUT; require_once $CFG->libdir . '/filelib.php'; if ($this->content !== NULL) { return $this->content; } $this->title = ''; $this->content = new stdClass(); $this->content->text = ''; $this->content->footer = ''; if (!isset($this->config)) { $this->config = new stdClass(); } if (!isset($this->config->showslides)) { $this->config->showslides = 'always'; } if (!isset($this->config->interval)) { $this->config->interval = 5; } if (!isset($this->config->firstslide)) { $this->config->firstslide = 1; } if (!isset($this->config->transition)) { $this->config->transition = 'fade'; } if (!isset($this->config->transitionduration)) { $this->config->transitionduration = 0.5; } if ($this->config->showslides == 'beforelogin' && isloggedin()) { return $this->content; } if ($this->config->showslides == 'afterlogin' && !isloggedin()) { return $this->content; } if (isset($this->config->slides)) { $ssid = $this->instance->id; $slidesactive = 0; $slidestext = ''; $fs = get_file_storage(); for ($i = 0; $i < $this->config->slides; $i++) { if (isset($this->config->enabled[$i]) && !empty($this->config->enabled[$i])) { $imagefiles = $fs->get_area_files($this->context->id, 'block_slideshow', 'slides', $i); // Get file which was uploaded in draft area. $imagefile = null; foreach ($imagefiles as $file) { if (!$file->is_directory()) { $imagefile = clone $file; break; } } if (!empty($this->config->title[$i]) || !empty($this->config->caption[$i]) || !empty($imagefile)) { $slidestyle = $i == $this->config->firstslide ? 'display: block; position:static; width: 100%' : 'width: 100%'; $slidestext .= html_writer::start_tag('div', array('class' => 'block_slideshow_slide', 'style' => $slidestyle)); if (!empty($imagefile)) { $imagestyle = 'width: 100%'; if (isset($this->config->imageposition[$i])) { switch ($this->config->imageposition[$i]) { case 'fullsize': $imagestyle = 'width: 100%'; break; case 'left': $imagestyle = 'width: 50%; margin-left: 0px'; break; case 'center': $imagestyle = 'width: 50%; margin-left: 25%'; break; case 'right': $imagestyle = 'width: 50%; margin-left: 50%'; break; } } $imageurl = moodle_url::make_pluginfile_url($this->context->id, 'block_slideshow', 'slides', $i, $imagefile->get_filepath(), $imagefile->get_filename()); $imagetext = html_writer::empty_tag('img', array('src' => $imageurl)); if (!empty($this->config->link[$i])) { $imagetext = html_writer::link(new moodle_url($this->config->link[$i]), $imagetext); } $slidestext .= html_writer::tag('div', $imagetext, array('class' => 'block_slideshow_image', 'style' => $imagestyle)); } if (!empty($this->config->title[$i]) || !empty($this->config->caption[$i])) { $captionstyle = 'bottom: 1em; right: 1em'; if (isset($this->config->captionposition[$i])) { switch ($this->config->captionposition[$i]) { case 'topleft': $captionstyle = 'top: 1em; left: 1em'; break; case 'top': $captionstyle = 'top: 0px; left: 0px; right: 0px'; break; case 'topright': $captionstyle = 'top: 1em; right: 1em'; break; case 'left': $captionstyle = 'left: 0px; top: 0px; bottom: 0px; max-width: 33%'; break; case 'center': $captionstyle = 'top: 0px; bottom: 0px; left: 33%; right: 33%; max-width: 33%'; break; case 'right': $captionstyle = 'right: 0px; top: 0px; bottom: 0px; max-width: 33%'; break; case 'bottomleft': $captionstyle = 'bottom: 1em; left: 1em'; break; case 'bottom': $captionstyle = 'bottom: 0px; left: 0px; right: 0px'; break; case 'bottomright': $captionstyle = 'bottom: 1em; right: 1em;'; break; case 'fullsize': $captionstyle = 'top: 0px; bottom: 0px; left: 0px; right: 0px'; break; } } $slidestext .= html_writer::start_tag('div', array('class' => 'block_slideshow_caption', 'style' => $captionstyle)); if (!empty($this->config->title[$i])) { $titletext = $this->config->title[$i]; if (!empty($this->config->link[$i])) { $titletext = html_writer::link(new moodle_url($this->config->link[$i]), $titletext); } $slidestext .= html_writer::tag('h1', $titletext, array('class' => 'block_slideshow_captiontitle')); } if (!empty($this->config->caption[$i])) { $captiontext = $this->config->caption[$i]; if (!empty($this->config->link[$i])) { $captiontext = html_writer::link(new moodle_url($this->config->link[$i]), $captiontext); } $slidestext .= html_writer::tag('p', $captiontext, array('class' => 'block_slideshow_captiontext')); } $slidestext .= html_writer::end_tag('div'); } $slidestext .= html_writer::end_tag('div'); $slidesactive++; } } } if ($slidesactive) { $this->content->text .= html_writer::start_tag('div', array('class' => 'block_slideshow_slideshow')); $this->content->text .= html_writer::start_tag('div', array('id' => 'block_slideshow_' . $ssid, 'class' => 'block_slideshow_slides')); $this->content->text .= $slidestext; $this->content->text .= html_writer::end_tag('div'); if ($slidesactive > 1) { $transition = 'fade'; if (isset($this->config->transition)) { $transition = $this->config->transition; } $strprev = get_string('enablejavascriptformore', 'block_slideshow'); $strnext = get_string('enablejavascriptformore', 'block_slideshow'); switch ($transition) { case 'fade': case 'slideLeft': $this->content->text .= html_writer::tag('div', $OUTPUT->pix_icon('t/left', $strprev), array('id' => 'block_slideshow_prev_' . $ssid, 'class' => 'block_slideshow_left')); $this->content->text .= html_writer::tag('div', $OUTPUT->pix_icon('t/right', $strnext), array('id' => 'block_slideshow_next_' . $ssid, 'class' => 'block_slideshow_right')); break; case 'slideRight': $this->content->text .= html_writer::tag('div', $OUTPUT->pix_icon('t/left', $strnext), array('id' => 'block_slideshow_next_' . $ssid, 'class' => 'block_slideshow_left')); $this->content->text .= html_writer::tag('div', $OUTPUT->pix_icon('t/right', $strprev), array('id' => 'block_slideshow_prev_' . $ssid, 'class' => 'block_slideshow_right')); break; case 'slideUp': $this->content->text .= html_writer::tag('div', $OUTPUT->pix_icon('t/up', $strprev), array('id' => 'block_slideshow_prev_' . $ssid, 'class' => 'block_slideshow_up')); $this->content->text .= html_writer::tag('div', $OUTPUT->pix_icon('t/down', $strnext), array('id' => 'block_slideshow_next_' . $ssid, 'class' => 'block_slideshow_down')); break; case 'slideDown': $this->content->text .= html_writer::tag('div', $OUTPUT->pix_icon('t/up', $strnext), array('id' => 'block_slideshow_next_' . $ssid, 'class' => 'block_slideshow_up')); $this->content->text .= html_writer::tag('div', $OUTPUT->pix_icon('t/down', $strprev), array('id' => 'block_slideshow_prev_' . $ssid, 'class' => 'block_slideshow_down')); break; } $pagerstyle = 'bottom: .5em; right: .5em'; if (isset($this->config->pagerposition)) { switch ($this->config->pagerposition) { case 'topleft': $pagerstyle = 'top: .5em; left: .5em'; break; case 'top': $pagerstyle = 'top: .5em; left: 45%; right: 45%; min-width: 10%'; break; case 'topright': $pagerstyle = 'top: .5em; right: .5em'; break; case 'left': $pagerstyle = 'left: .5em; top: 40%; width: 1em'; break; case 'right': $pagerstyle = 'right: .5em; top: 40%; width: 1em'; break; case 'bottomleft': $pagerstyle = 'bottom: .5em; left: .5em'; break; case 'bottom': $pagerstyle = 'bottom: .5em; left: 45%; right: 45%; min-width: 10%'; break; case 'bottomright': $pagerstyle = 'bottom: .5em; right: .5em'; break; } } $this->content->text .= html_writer::start_tag('ul', array('class' => 'block_slideshow_pages', 'id' => 'block_slideshow_pages_' . $ssid, 'style' => $pagerstyle)); for ($i = 0; $i < $slidesactive; $i++) { $firstslide = $i == $this->config->firstslide ? ' yui3-slideshow-active' : ''; $this->content->text .= html_writer::empty_tag('li', array('class' => 'block_slideshow_page block_slideshow_page_' . $ssid . $firstslide . ' ' . $transition)); } $this->content->text .= '</ul>'; $this->content->text .= html_writer::start_tag('noscript'); $this->content->text .= html_writer::tag('span', get_string('enablejavascriptformore', 'block_slideshow')); $this->content->text .= html_writer::end_tag('noscript'); $script = 'Y.use(\'moodle-block_slideshow-slideshow\', function(Y){'; $script .= 'var slideshow' . $ssid . ' = new Y.Slideshow({ srcNode: \'#block_slideshow_' . $ssid . '\', previousButton:\'#block_slideshow_prev_' . $ssid . '\', nextButton:\'#block_slideshow_next_' . $ssid . '\', pages:\'.block_slideshow_page_' . $ssid . '\', currentIndex:' . $this->config->firstslide . ', pauseOnChange: false, duration:' . $this->config->transitionduration . ', interval:' . $this->config->interval . ', transition: Y.Slideshow.PRESETS.' . $transition . '}); slideshow' . $this->instance->id . '.render(); '; $script .= 'if (Y.one(\'#block_slideshow_prev_' . $ssid . ' img\') != null) { Y.one(\'#block_slideshow_prev_' . $ssid . ' img\').setAttribute(\'title\',\'' . get_string('prev') . '\');}'; $script .= 'if (Y.one(\'#block_slideshow_next_' . $ssid . ' img\') != null) { Y.one(\'#block_slideshow_next_' . $ssid . ' img\').setAttribute(\'title\',\'' . get_string('next') . '\');}'; $script .= ' });'; $PAGE->requires->js_init_code($script); } $this->content->text .= html_writer::end_tag('div'); } } else { $this->content->text = ''; } return $this->content; }
/** * Create a widget for rendering the editor. * * @param int $userid * @param stdClass $grade * @param bool $readonly * @return setaskfeedback_editpdf_widget */ public function get_widget($userid, $grade, $readonly) { $attempt = -1; if ($grade && $grade->attemptnumber) { $attempt = $grade->attemptnumber; } else { $grade = $this->setaskment->get_user_grade($userid, true); } $feedbackfile = document_services::get_feedback_document($this->setaskment->get_instance()->id, $userid, $attempt); $stampfiles = array(); $fs = get_file_storage(); $syscontext = context_system::instance(); // Copy any new stamps to this instance. if ($files = $fs->get_area_files($syscontext->id, 'setaskfeedback_editpdf', 'stamps', 0, "filename", false)) { foreach ($files as $file) { $filename = $file->get_filename(); if ($filename !== '.') { $existingfile = $fs->get_file($this->setaskment->get_context()->id, 'setaskfeedback_editpdf', 'stamps', $grade->id, '/', $file->get_filename()); if (!$existingfile) { $newrecord = new stdClass(); $newrecord->contextid = $this->setaskment->get_context()->id; $newrecord->itemid = $grade->id; $fs->create_file_from_storedfile($newrecord, $file); } } } } // Now get the full list of stamp files for this instance. if ($files = $fs->get_area_files($this->setaskment->get_context()->id, 'setaskfeedback_editpdf', 'stamps', $grade->id, "filename", false)) { foreach ($files as $file) { $filename = $file->get_filename(); if ($filename !== '.') { $url = moodle_url::make_pluginfile_url($this->setaskment->get_context()->id, 'setaskfeedback_editpdf', 'stamps', $grade->id, '/', $file->get_filename(), false); array_push($stampfiles, $url->out()); } } } $url = false; $filename = ''; if ($feedbackfile) { $url = moodle_url::make_pluginfile_url($this->setaskment->get_context()->id, 'setaskfeedback_editpdf', document_services::FINAL_PDF_FILEAREA, $grade->id, '/', $feedbackfile->get_filename(), false); $filename = $feedbackfile->get_filename(); } // Retrieve total number of pages. $pagetotal = document_services::page_number_for_attempt($this->setaskment->get_instance()->id, $userid, $attempt, $readonly); $widget = new setaskfeedback_editpdf_widget($this->setaskment->get_instance()->id, $userid, $attempt, $url, $filename, $stampfiles, $readonly, $pagetotal); return $widget; }
/** * Return the site's compact logo URL, if any. * * @param int $maxwidth The maximum width, or null when the maximum width does not matter. * @param int $maxheight The maximum height, or null when the maximum height does not matter. * @return moodle_url|false */ public function get_compact_logo_url($maxwidth = 100, $maxheight = 100) { global $CFG; $logo = get_config('core_admin', 'logocompact'); if (empty($logo)) { return false; } // Hide the requested size in the file path. $filepath = (int) $maxwidth . 'x' . (int) $maxheight . '/'; // Use $CFG->themerev to prevent browser caching when the file changes. return moodle_url::make_pluginfile_url(context_system::instance()->id, 'core_admin', 'logocompact', $filepath, theme_get_revision(), $logo); }
/** * Prepares the list of overall feedback attachments * * Returns false if overall feedback attachments are not allowed. Otherwise returns * list of attachments (may be empty). * * @return bool|array of stdClass */ public function get_overall_feedback_attachments() { if ($this->workshop->overallfeedbackmode == 0) { return false; } if ($this->workshop->overallfeedbackfiles == 0) { return false; } if (empty($this->feedbackauthorattachment)) { return array(); } $attachments = array(); $fs = get_file_storage(); $files = $fs->get_area_files($this->workshop->context->id, 'mod_workshop', 'overallfeedback_attachment', $this->id); foreach ($files as $file) { if ($file->is_directory()) { continue; } $filepath = $file->get_filepath(); $filename = $file->get_filename(); $fileurl = moodle_url::make_pluginfile_url($this->workshop->context->id, 'mod_workshop', 'overallfeedback_attachment', $this->id, $filepath, $filename, true); $previewurl = new moodle_url(moodle_url::make_pluginfile_url($this->workshop->context->id, 'mod_workshop', 'overallfeedback_attachment', $this->id, $filepath, $filename, false), array('preview' => 'bigthumb')); $attachments[] = (object) array('filepath' => $filepath, 'filename' => $filename, 'fileurl' => $fileurl, 'previewurl' => $previewurl, 'mimetype' => $file->get_mimetype()); } return $attachments; }
/** * Internal implementation of user image rendering. * @param user_picture $userpicture * @return string */ protected function render_user_picture(user_picture $userpicture) { global $CFG, $DB; $user = $userpicture->user; if ($userpicture->alttext) { if (!empty($user->imagealt)) { $alt = $user->imagealt; } else { $alt = get_string('pictureof', '', fullname($user)); } } else { $alt = ''; } if (empty($userpicture->size)) { $file = 'f2'; $size = 35; } else { if ($userpicture->size === true or $userpicture->size == 1) { $file = 'f1'; $size = 100; } else { if ($userpicture->size >= 50) { $file = 'f1'; $size = $userpicture->size; } else { $file = 'f2'; $size = $userpicture->size; } } } $class = $userpicture->class; if ($user->picture == 1) { $usercontext = get_context_instance(CONTEXT_USER, $user->id); $src = moodle_url::make_pluginfile_url($usercontext->id, 'user', 'icon', NULL, '/', $file); } else { if ($user->picture == 2) { //TODO: gravatar user icon support } else { // Print default user pictures (use theme version if available) $class .= ' defaultuserpic'; $src = $this->pix_url('u/' . $file); } } $attributes = array('src' => $src, 'alt' => $alt, 'title' => $alt, 'class' => $class, 'width' => $size, 'height' => $size); // get the image html output fisrt $output = html_writer::empty_tag('img', $attributes); // then wrap it in link if needed if (!$userpicture->link) { return $output; } if (empty($userpicture->courseid)) { $courseid = $this->page->course->id; } else { $courseid = $userpicture->courseid; } if ($courseid == SITEID) { $url = new moodle_url('/user/profile.php', array('id' => $user->id)); } else { $url = new moodle_url('/user/view.php', array('id' => $user->id, 'course' => $courseid)); } $attributes = array('href' => $url); if ($userpicture->popup) { $id = html_writer::random_id('userpicture'); $attributes['id'] = $id; $this->add_action_handler(new popup_action('click', $url), $id); } return html_writer::tag('a', $output, $attributes); }
/** * 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; }
/** * 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; }
/** * Renders a list of files attached to the submission * * If format==html, then format a html string. If format==text, then format a text-only string. * Otherwise, returns html for non-images and html to display the image inline. * * @param int $submissionid submission identifier * @param string format the format of the returned string - html|text * @return string formatted text to be echoed */ protected function helper_submission_attachments($submissionid, $format = 'html') { global $CFG; require_once $CFG->libdir . '/filelib.php'; $fs = get_file_storage(); $ctx = $this->page->context; $files = $fs->get_area_files($ctx->id, 'mod_workshop', 'submission_attachment', $submissionid); $outputimgs = ''; // images to be displayed inline $outputfiles = ''; // list of attachment files foreach ($files as $file) { if ($file->is_directory()) { continue; } $filepath = $file->get_filepath(); $filename = $file->get_filename(); $fileurl = moodle_url::make_pluginfile_url($ctx->id, 'mod_workshop', 'submission_attachment', $submissionid, $filepath, $filename, true); $embedurl = moodle_url::make_pluginfile_url($ctx->id, 'mod_workshop', 'submission_attachment', $submissionid, $filepath, $filename, false); $embedurl = new moodle_url($embedurl, array('preview' => 'bigthumb')); $type = $file->get_mimetype(); $image = $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')); $linkhtml = html_writer::link($fileurl, $image . substr($filepath, 1) . $filename); $linktxt = "{$filename} [{$fileurl}]"; if ($format == 'html') { if (file_mimetype_in_typegroup($type, 'web_image')) { $preview = html_writer::empty_tag('img', array('src' => $embedurl, 'alt' => '', 'class' => 'preview')); $preview = html_writer::tag('a', $preview, array('href' => $fileurl)); $outputimgs .= $this->output->container($preview); } else { $outputfiles .= html_writer::tag('li', $linkhtml, array('class' => $type)); } } else { if ($format == 'text') { $outputfiles .= $linktxt . PHP_EOL; } } if (!empty($CFG->enableplagiarism)) { require_once $CFG->libdir . '/plagiarismlib.php'; $outputfiles .= plagiarism_get_links(array('userid' => $file->get_userid(), 'file' => $file, 'cmid' => $this->page->cm->id, 'course' => $this->page->course->id)); } } if ($format == 'html') { if ($outputimgs) { $outputimgs = $this->output->container($outputimgs, 'images'); } if ($outputfiles) { $outputfiles = html_writer::tag('ul', $outputfiles, array('class' => 'files')); } return $this->output->container($outputimgs . $outputfiles, 'attachments'); } else { return $outputfiles; } }
/** * Internal function - creates htmls structure suitable for YUI tree. */ protected function htmllize_tree($tree, $dir) { global $CFG; if (empty($dir['subdirs']) and empty($dir['files'])) { return ''; } $result = '<ul>'; foreach ($dir['subdirs'] as $subdir) { $image = $this->output->pix_icon(file_folder_icon(24), $subdir['dirname'], 'moodle'); $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', s($subdir['dirname']), array('class' => 'fp-filename')); $filename = html_writer::tag('div', $filename, array('class' => 'fp-filename-icon')); $result .= html_writer::tag('li', $filename. $this->htmllize_tree($tree, $subdir)); } foreach ($dir['files'] as $file) { $filename = $file->get_filename(); $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $filename, false); if (file_extension_in_typegroup($filename, 'web_image')) { $image = $url->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified())); $image = html_writer::empty_tag('img', array('src' => $image)); } else { $image = $this->output->pix_icon(file_file_icon($file, 24), $filename, 'moodle'); } $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', $filename, array('class' => 'fp-filename')); $filename = html_writer::tag('span', html_writer::link($url->out(false, array('forcedownload' => 1)), $filename), array('class' => 'fp-filename-icon')); $result .= html_writer::tag('li', $filename); } $result .= '</ul>'; return $result; }