function print_student_answer($userid, $return=false){ global $CFG, $USER, $OUTPUT; $fs = get_file_storage(); $browser = get_file_browser(); $output = ''; if ($submission = $this->get_submission($userid)) { if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) { foreach ($files as $file) { $filename = $file->get_filename(); $found = true; $mimetype = $file->get_mimetype(); $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename); $output .= '<a href="'.$path.'" >'.$OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')).s($filename).'</a><br />'; $output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment)); $output .='<br/>'; } } } $output = '<div class="files">'.$output.'</div>'; return $output; }
/** * Displays any attached files when the question is in read-only mode. * @param question_attempt $qa the question attempt to display. * @param question_display_options $options controls what should and should * not be displayed. Used to get the context. */ public function files_read_only(question_attempt $qa, question_display_options $options) { $files = $qa->get_last_qt_files('attachments', $options->context->id); $output = array(); foreach ($files as $file) { $output[] = html_writer::tag('p', html_writer::link($qa->get_response_file_url($file), $this->output->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename()))); } return implode($output); }
public function render_files_tree_viewer(files_tree_viewer $tree) { $html = $this->output->heading_with_help(get_string('coursefiles'), 'courselegacyfiles', 'moodle'); $html .= $this->output->container_start('coursefilesbreadcrumb'); foreach($tree->path as $path) { $html .= $path; $html .= ' / '; } $html .= $this->output->container_end(); $html .= $this->output->box_start(); $table = new html_table(); $table->head = array(get_string('name'), get_string('lastmodified'), get_string('size', 'repository'), get_string('type', 'repository')); $table->align = array('left', 'left', 'left', 'left'); $table->width = '100%'; $table->data = array(); foreach ($tree->tree as $file) { $filedate = $filesize = $filetype = ''; if ($file['filedate']) { $filedate = userdate($file['filedate'], get_string('strftimedatetimeshort', 'langconfig')); } if (empty($file['isdir'])) { if ($file['filesize']) { $filesize = display_size($file['filesize']); } $fileicon = file_file_icon($file, 24); $filetype = get_mimetype_description($file); } else { $fileicon = file_folder_icon(24); } $table->data[] = array( html_writer::link($file['url'], $this->output->pix_icon($fileicon, get_string('icon')) . ' ' . $file['filename']), $filedate, $filesize, $filetype ); } $html .= html_writer::table($table); $html .= $this->output->single_button(new moodle_url('/files/coursefilesedit.php', array('contextid'=>$tree->context->id)), get_string('coursefilesedit'), 'get'); $html .= $this->output->box_end(); return $html; }
/** * 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; } }
public function mail($message, $reply = false, $offset = 0) { global $CFG, $USER; $totalusers = 0; $output = ''; if (!$reply) { $output .= html_writer::empty_tag('input', array( 'type' => 'hidden', 'name' => 'm', 'value' => $message->id(), )); $output .= html_writer::empty_tag('input', array( 'type' => 'hidden', 'name' => 'offset', 'value' => $offset, )); } $output .= $this->output->container_start('mail_header'); $output .= $this->output->container_start('left'); $output .= $this->output->user_picture($message->sender()); $output .= $this->output->container_end(); $output .= $this->output->container_start('mail_info'); $output .= html_writer::link(new moodle_url('/user/view.php', array( 'id' => $message->sender()->id, 'course' => $message->course()->id )), fullname($message->sender()), array('class' => 'user_from')); $output .= $this->date($message, true); if (!$reply) { $output .= $this->output->container_start('mail_recipients'); foreach (array('to', 'cc', 'bcc') as $role) { $recipients = $message->recipients($role); if (!empty($recipients)) { if ($role == 'bcc' and $message->sender()->id !== $USER->id) { continue; } $output .= html_writer::start_tag('div'); $output .= html_writer::tag('span', get_string($role, 'local_mail'), array('class' => 'mail_role')); $numusers = count($recipients); $totalusers += $numusers; $cont = 1; foreach ($recipients as $user) { $output .= html_writer::link(new moodle_url('/user/view.php', array( 'id' => $user->id, 'course' => $message->course()->id )), fullname($user)); if ($cont < $numusers) { $output .= ', '; } $cont += 1; } $output .= ' '; $output .= html_writer::end_tag('div'); } } $output .= $this->output->container_end(); } else { $output .= html_writer::tag('div', '', array('class' => 'mail_recipients')); } $output .= $this->output->container_end(); $output .= $this->output->container_end(); $output .= $this->output->container_start('mail_body'); $output .= $this->output->container_start('mail_content'); $output .= local_mail_format_content($message); $attachments = local_mail_attachments($message); if ($attachments) { $output .= $this->output->container_start('mail_attachments'); if (count($attachments) > 1) { $text = get_string('attachnumber', 'local_mail', count($attachments)); $output .= html_writer::tag('span', $text, array('class' => 'mail_attachment_text')); $downloadurl = new moodle_url($this->page->url, array('downloadall' => '1')); $iconimage = $this->output->pix_icon('a/download_all', get_string('downloadall', 'local_mail'), 'moodle', array('class' => 'icon')); $output .= html_writer::start_div('mail_attachment_downloadall'); $output .= html_writer::link($downloadurl, $iconimage); $output .= html_writer::link($downloadurl, get_string('downloadall', 'local_mail'), array('class' => 'mail_downloadall_text')); $output .= html_writer::end_div(); } foreach ($attachments as $attach) { $filename = $attach->get_filename(); $filepath = $attach->get_filepath(); $mimetype = $attach->get_mimetype(); $iconimage = $this->output->pix_icon(file_file_icon($attach), get_mimetype_description($attach), 'moodle', array('class' => 'icon')); $path = '/'.$attach->get_contextid().'/local_mail/message/'.$attach->get_itemid().$filepath.$filename; $fullurl = moodle_url::make_file_url('/pluginfile.php', $path, true); $output .= html_writer::start_tag('div', array('class' => 'mail_attachment')); $output .= html_writer::link($fullurl, $iconimage); $output .= html_writer::link($fullurl, s($filename)); $output .= html_writer::tag('span', display_size($attach->get_filesize()), array('class' => 'mail_attachment_size')); $output .= html_writer::end_tag('div'); } $output .= $this->output->container_end(); } $output .= $this->output->container_end(); $output .= $this->newlabelform(); if (!$reply) { if ($message->sender()->id !== $USER->id) { $output .= $this->toolbar('reply', $message->course()->id, array('replyall' => ($totalusers > 1))); } else { $output .= $this->toolbar('forward', $message->course()->id); } } $output .= $this->output->container_end(); return $output; }
/** * Gets optional details for a resource, depending on resource settings. * * Result may include the file size and type if those settings are chosen, * or blank if none. * * @param object $resource Resource table row * @param object $cm Course-module table row * @return string Size and type or empty string if show options are not enabled */ function resource_get_optional_details($resource, $cm) { global $DB; $details = ''; $options = empty($resource->displayoptions) ? array() : unserialize($resource->displayoptions); if (!empty($options['showsize']) || !empty($options['showtype']) || !empty($options['showdate'])) { $context = context_module::instance($cm->id); $size = ''; $type = ''; $date = ''; $langstring = ''; $infodisplayed = 0; $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false); if (!empty($options['showsize']) && count($files)) { $sizebytes = 0; foreach ($files as $file) { // this will also synchronize the file size for external files if needed $sizebytes += $file->get_filesize(); } if ($sizebytes) { $size = display_size($sizebytes); } $langstring .= 'size'; $infodisplayed += 1; } if (!empty($options['showtype']) && count($files)) { // For a typical file resource, the sortorder is 1 for the main file // and 0 for all other files. This sort approach is used just in case // there are situations where the file has a different sort order $mainfile = reset($files); $type = get_mimetype_description($mainfile); // Only show type if it is not unknown if ($type === get_mimetype_description('document/unknown')) { $type = ''; } $langstring .= 'type'; $infodisplayed += 1; } if (!empty($options['showdate'])) { $mainfile = reset($files); $uploaddate = $mainfile->get_timecreated(); $modifieddate = $mainfile->get_timemodified(); if ($modifieddate > $uploaddate) { $date = get_string('modifieddate', 'mod_resource', userdate($modifieddate)); } else { $date = get_string('uploadeddate', 'mod_resource', userdate($uploaddate)); } $langstring .= 'date'; $infodisplayed += 1; } if ($infodisplayed > 1) { $details = get_string("resourcedetails_{$langstring}", 'resource', (object)array('size' => $size, 'type' => $type, 'date' => $date)); } else { // Only one of size, type and date is set, so just append. $details = $size . $type . $date; } } return $details; }
/** * Gets details of the file to cache in course cache to be displayed using {@link resource_get_optional_details()} * * @param object $resource Resource table row (only property 'displayoptions' is used here) * @param object $cm Course-module table row * @return string Size and type or empty string if show options are not enabled */ function resource_get_file_details($resource, $cm) { $options = empty($resource->displayoptions) ? array() : @unserialize($resource->displayoptions); $filedetails = array(); if (!empty($options['showsize']) || !empty($options['showtype']) || !empty($options['showdate'])) { $context = context_module::instance($cm->id); $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false); // For a typical file resource, the sortorder is 1 for the main file // and 0 for all other files. This sort approach is used just in case // there are situations where the file has a different sort order. $mainfile = $files ? reset($files) : null; if (!empty($options['showsize'])) { $filedetails['size'] = 0; foreach ($files as $file) { // This will also synchronize the file size for external files if needed. $filedetails['size'] += $file->get_filesize(); if ($file->get_repository_id()) { // If file is a reference the 'size' attribute can not be cached. $filedetails['isref'] = true; } } } if (!empty($options['showtype'])) { if ($mainfile) { $filedetails['type'] = get_mimetype_description($mainfile); // Only show type if it is not unknown. if ($filedetails['type'] === get_mimetype_description('document/unknown')) { $filedetails['type'] = ''; } } else { $filedetails['type'] = ''; } } if (!empty($options['showdate'])) { if ($mainfile) { // Modified date may be up to several minutes later than uploaded date just because // teacher did not submit the form promptly. Give teacher up to 5 minutes to do it. if ($mainfile->get_timemodified() > $mainfile->get_timecreated() + 5 * MINSECS) { $filedetails['modifieddate'] = $mainfile->get_timemodified(); } else { $filedetails['uploadeddate'] = $mainfile->get_timecreated(); } if ($mainfile->get_repository_id()) { // If main file is a reference the 'date' attribute can not be cached. $filedetails['isref'] = true; } } else { $filedetails['uploadeddate'] = ''; } } } return $filedetails; }
/** * Listing all files (including folders) in current path (draft area) * used by file manager * @param int $draftitemid * @param string $filepath * @return stdClass */ function file_get_drafarea_files($draftitemid, $filepath = '/') { global $USER, $OUTPUT, $CFG; $context = context_user::instance($USER->id); $fs = get_file_storage(); $data = new stdClass(); $data->path = array(); $data->path[] = array('name' => get_string('files'), 'path' => '/'); // will be used to build breadcrumb $trail = '/'; if ($filepath !== '/') { $filepath = file_correct_filepath($filepath); $parts = explode('/', $filepath); foreach ($parts as $part) { if ($part != '' && $part != null) { $trail .= $part . '/'; $data->path[] = array('name' => $part, 'path' => $trail); } } } $list = array(); $maxlength = 12; if ($files = $fs->get_directory_files($context->id, 'user', 'draft', $draftitemid, $filepath, false)) { foreach ($files as $file) { $item = new stdClass(); $item->filename = $file->get_filename(); $item->filepath = $file->get_filepath(); $item->fullname = trim($item->filename, '/'); $filesize = $file->get_filesize(); $item->size = $filesize ? $filesize : null; $item->filesize = $filesize ? display_size($filesize) : ''; $item->sortorder = $file->get_sortorder(); $item->author = $file->get_author(); $item->license = $file->get_license(); $item->datemodified = $file->get_timemodified(); $item->datecreated = $file->get_timecreated(); $item->isref = $file->is_external_file(); if ($item->isref && $file->get_status() == 666) { $item->originalmissing = true; } // find the file this draft file was created from and count all references in local // system pointing to that file $source = @unserialize($file->get_source()); if (isset($source->original)) { $item->refcount = $fs->search_references_count($source->original); } if ($file->is_directory()) { $item->filesize = 0; $item->icon = $OUTPUT->pix_url(file_folder_icon(24))->out(false); $item->type = 'folder'; $foldername = explode('/', trim($item->filepath, '/')); $item->fullname = trim(array_pop($foldername), '/'); $item->thumbnail = $OUTPUT->pix_url(file_folder_icon(90))->out(false); } else { // do NOT use file browser here! $item->mimetype = get_mimetype_description($file); if (file_extension_in_typegroup($file->get_filename(), 'archive')) { $item->type = 'zip'; } else { $item->type = 'file'; } $itemurl = moodle_url::make_draftfile_url($draftitemid, $item->filepath, $item->filename); $item->url = $itemurl->out(); $item->icon = $OUTPUT->pix_url(file_file_icon($file, 24))->out(false); $item->thumbnail = $OUTPUT->pix_url(file_file_icon($file, 90))->out(false); if ($imageinfo = $file->get_imageinfo()) { $item->realthumbnail = $itemurl->out(false, array('preview' => 'thumb', 'oid' => $file->get_timemodified())); $item->realicon = $itemurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified())); $item->image_width = $imageinfo['width']; $item->image_height = $imageinfo['height']; } } $list[] = $item; } } $data->itemid = $draftitemid; $data->list = $list; return $data; }
/** * Prints a section full of activity modules * @Overrides course/lib.php=>print_section */ function ss_print_section($course, $section, $mods, $modnamesused, $absolute=false, $width="100%", $hidecompletion=false) { #print_r($mods); global $CFG, $USER, $DB, $PAGE, $OUTPUT; static $initialised; static $groupbuttons; static $groupbuttonslink; static $isediting; static $ismoving; static $strmovehere; static $strmovefull; static $strunreadpostsone; static $usetracking; static $groupings; if (!isset($initialised)) { $groupbuttons = ($course->groupmode or (!$course->groupmodeforce)); $groupbuttonslink = (!$course->groupmodeforce); $isediting = $PAGE->user_is_editing(); $ismoving = $isediting && ismoving($course->id); if ($ismoving) { $strmovehere = get_string("movehere"); $strmovefull = strip_tags(get_string("movefull", "", "'$USER->activitycopyname'")); } include_once($CFG->dirroot.'/mod/forum/lib.php'); if ($usetracking = forum_tp_can_track_forums()) { $strunreadpostsone = get_string('unreadpostsone', 'forum'); } $initialised = true; } $labelformatoptions = new stdClass(); $labelformatoptions->noclean = true; $labelformatoptions->overflowdiv = true; /// Casting $course->modinfo to string prevents one notice when the field is null $modinfo = get_fast_modinfo($course); $completioninfo = new completion_info($course); //Accessibility: replace table with list <ul>, but don't output empty list. if (!empty($section->sequence)) { // Fix bug #5027, don't want style=\"width:$width\". echo "<ul class=\"section img-text\">\n"; $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if ($ismoving and $mod->id == $USER->activitycopy) { // do not display moving mod continue; } if (isset($modinfo->cms[$modnumber])) { // We can continue (because it will not be displayed at all) // if: // 1) The activity is not visible to users // and // 2a) The 'showavailability' option is not set (if that is set, // we need to display the activity so we can show // availability info) // or // 2b) The 'availableinfo' is empty, i.e. the activity was // hidden in a way that leaves no info, such as using the // eye icon. if (!$modinfo->cms[$modnumber]->uservisible && (empty($modinfo->cms[$modnumber]->showavailability) || empty($modinfo->cms[$modnumber]->availableinfo))) { // visibility shortcut continue; } } else { if (!file_exists("$CFG->dirroot/mod/$mod->modname/lib.php")) { // module not installed continue; } if (!coursemodule_visible_for_user($mod) && empty($mod->showavailability)) { // full visibility check continue; } } // In some cases the activity is visible to user, but it is // dimmed. This is done if viewhiddenactivities is true and if: // 1. the activity is not visible, or // 2. the activity has dates set which do not include current, or // 3. the activity has any other conditions set (regardless of whether // current user meets them) $canviewhidden = has_capability( 'moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->id)); $accessiblebutdim = false; if ($canviewhidden) { $accessiblebutdim = !$mod->visible; if (!empty($CFG->enableavailability)) { $accessiblebutdim = $accessiblebutdim || $mod->availablefrom > time() || ($mod->availableuntil && $mod->availableuntil < time()) || count($mod->conditionsgrade) > 0 || count($mod->conditionscompletion) > 0; } } $liclasses = array(); $liclasses[] = 'activity'; $liclasses[] = $mod->modname; $liclasses[] = 'modtype_'.$mod->modname; echo html_writer::start_tag('li', array('class'=>join(' ', $liclasses), 'id'=>'module-'.$modnumber)); if ($ismoving) { echo '<a title="'.$strmovefull.'"'. ' href="'.$CFG->wwwroot.'/course/mod.php?moveto='.$mod->id.'&sesskey='.sesskey().'">'. '<img class="movetarget" src="'.$OUTPUT->pix_url('movehere') . '" '. ' alt="'.$strmovehere.'" /></a><br /> '; } $classes = array('mod-indent'); if (!empty($mod->indent)) { $classes[] = 'mod-indent-'.$mod->indent; if ($mod->indent > 15) { $classes[] = 'mod-indent-huge'; } } echo html_writer::start_tag('div', array('class'=>join(' ', $classes))); $extra = ''; if (!empty($modinfo->cms[$modnumber]->extra)) { $extra = $modinfo->cms[$modnumber]->extra; } if ($mod->modname == "label") { if ($accessiblebutdim || !$mod->uservisible) { echo '<div class="dimmed_text"><span class="accesshide">'. get_string('hiddenfromstudents').'</span>'; } else { echo '<div>'; } echo format_text($extra, FORMAT_HTML, $labelformatoptions); echo "</div>"; if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(".format_string($groupings[$mod->groupingid]->name).')</span>'; } } else { // Normal activity $instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id); # echo format_string($modinfo->cms[$modnumber]->intro, true, $course->id); # echo format_string($modinfo->cms[$modnumber]->name, true, $course->id); # print_r($modinfo->cms[$modnumber]); $customicon = $modinfo->cms[$modnumber]->icon; if (!empty($customicon)) { if (substr($customicon, 0, 4) === 'mod/') { list($modname, $iconname) = explode('/', substr($customicon, 4), 2); $icon = $OUTPUT->pix_url($iconname, $modname); } else { $icon = $OUTPUT->pix_url($customicon); } } else { $icon = $OUTPUT->pix_url('icon', $mod->modname); } //Accessibility: for files get description via icon, this is very ugly hack! $altname = ''; $altname = $mod->modfullname; if (!empty($customicon)) { $archetype = plugin_supports('mod', $mod->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER); if ($archetype == MOD_ARCHETYPE_RESOURCE) { $mimetype = mimeinfo_from_icon('type', $customicon); $altname = get_mimetype_description($mimetype); } } // Avoid unnecessary duplication. if (false !== stripos($instancename, $altname)) { $altname = ''; } // File type after name, for alphabetic lists (screen reader). if ($altname) { $altname = get_accesshide(' '.$altname); } // We may be displaying this just in order to show information // about visibility, without the actual link if ($mod->uservisible) { // Display normal module link if (!$accessiblebutdim) { $linkcss = ''; $accesstext =''; } else { $linkcss = ' class="dimmed" '; $accesstext = '<span class="accesshide">'. get_string('hiddenfromstudents').': </span>'; } echo '<a '.$linkcss.' '.$extra. ' href="'.$CFG->wwwroot.'/mod/'.$mod->modname.'/view.php?id='.$mod->id.'">'. '<img src="'.$icon.'" class="activityicon" alt="'.get_string('modulename',$mod->modname).'" /> '. $accesstext.'<span class="instancename">'.$instancename.$altname.'</span></a>'; if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(".format_string($groupings[$mod->groupingid]->name).')</span>'; } } else { // Display greyed-out text of link echo '<span class="dimmed_text" '.$extra.' ><span class="accesshide">'. get_string('notavailableyet','condition').': </span>'. '<img src="'.$icon.'" class="activityicon" alt="'.get_string('modulename', $mod->modname).'" /> <span>'. $instancename.$altname.'</span></span>'; } } if ($usetracking && $mod->modname == 'forum') { if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) { echo '<span class="unread"> <a href="'.$CFG->wwwroot.'/mod/forum/view.php?id='.$mod->id.'">'; if ($unread == 1) { echo $strunreadpostsone; } else { print_string('unreadpostsnumber', 'forum', $unread); } echo '</a></span>'; } } if ($isediting) { if ($groupbuttons and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) { if (! $mod->groupmodelink = $groupbuttonslink) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } echo ' '; echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section); hook_make_edit_icon_button($mod, $OUTPUT); } // Completion $completion = $hidecompletion ? COMPLETION_TRACKING_NONE : $completioninfo->is_enabled($mod); if ($completion!=COMPLETION_TRACKING_NONE && isloggedin() && !isguestuser() && $mod->uservisible) { $completiondata = $completioninfo->get_data($mod,true); $completionicon = ''; if ($isediting) { switch ($completion) { case COMPLETION_TRACKING_MANUAL : $completionicon = 'manual-enabled'; break; case COMPLETION_TRACKING_AUTOMATIC : $completionicon = 'auto-enabled'; break; default: // wtf } } else if ($completion==COMPLETION_TRACKING_MANUAL) { switch($completiondata->completionstate) { case COMPLETION_INCOMPLETE: $completionicon = 'manual-n'; break; case COMPLETION_COMPLETE: $completionicon = 'manual-y'; break; } } else { // Automatic switch($completiondata->completionstate) { case COMPLETION_INCOMPLETE: $completionicon = 'auto-n'; break; case COMPLETION_COMPLETE: $completionicon = 'auto-y'; break; case COMPLETION_COMPLETE_PASS: $completionicon = 'auto-pass'; break; case COMPLETION_COMPLETE_FAIL: $completionicon = 'auto-fail'; break; } } if ($completionicon) { $imgsrc = $OUTPUT->pix_url('i/completion-'.$completionicon); $imgalt = s(get_string('completion-alt-'.$completionicon, 'completion')); if ($completion == COMPLETION_TRACKING_MANUAL && !$isediting) { $imgtitle = s(get_string('completion-title-'.$completionicon, 'completion')); $newstate = $completiondata->completionstate==COMPLETION_COMPLETE ? COMPLETION_INCOMPLETE : COMPLETION_COMPLETE; // In manual mode the icon is a toggle form... // If this completion state is used by the // conditional activities system, we need to turn // off the JS. if (!empty($CFG->enableavailability) && condition_info::completion_value_used_as_condition($course, $mod)) { $extraclass = ' preventjs'; } else { $extraclass = ''; } echo " <form class='togglecompletion$extraclass' method='post' action='togglecompletion.php'><div> <input type='hidden' name='id' value='{$mod->id}' /> <input type='hidden' name='sesskey' value='".sesskey()."' /> <input type='hidden' name='completionstate' value='$newstate' /> <input type='image' src='$imgsrc' alt='$imgalt' title='$imgtitle' /> </div></form>"; } else { // In auto mode, or when editing, the icon is just an image echo "<span class='autocompletion'>"; echo "<img src='$imgsrc' alt='$imgalt' title='$imgalt' /></span>"; } } } // Show availability information (for someone who isn't allowed to // see the activity itself, or for staff) if (!$mod->uservisible) { echo '<div class="availabilityinfo">'.$mod->availableinfo.'</div>'; } else if ($canviewhidden && !empty($CFG->enableavailability)) { $ci = new condition_info($mod); $fullinfo = $ci->get_full_information(); if($fullinfo) { echo '<div class="availabilityinfo">'.get_string($mod->showavailability ? 'userrestriction_visible' : 'userrestriction_hidden','condition', $fullinfo).'</div>'; } } echo hook_show_activity_intro($mod); echo html_writer::end_tag('div'); echo html_writer::end_tag('li')."\n"; } } elseif ($ismoving) { echo "<ul class=\"section\">\n"; } if ($ismoving) { echo '<li><a title="'.$strmovefull.'"'. ' href="'.$CFG->wwwroot.'/course/mod.php?movetosection='.$section->id.'&sesskey='.sesskey().'">'. '<img class="movetarget" src="'.$OUTPUT->pix_url('movehere') . '" '. ' alt="'.$strmovehere.'" /></a></li> '; } if (!empty($section->sequence) || $ismoving) { echo "</ul><!--class='section'-->\n\n"; } }
/** * Own function to print one section in a tree way */ function print_topicstree_section($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%") { /// Prints a section full of activity modules global $CFG, $USER; static $initialised; static $groupbuttons; static $groupbuttonslink; static $strmovehere; static $strmovefull; static $strunreadpostsone; static $usetracking; static $groupings; $spacer = ' '; if (!isset($initialised)) { $groupbuttons = ($course->groupmode or !$course->groupmodeforce); $groupbuttonslink = !$course->groupmodeforce; include_once $CFG->dirroot . '/mod/forum/lib.php'; if ($usetracking = forum_tp_can_track_forums()) { $strunreadpostsone = get_string('unreadpostsone', 'forum'); } $initialised = true; } $labelformatoptions = new object(); $labelformatoptions->noclean = true; /// Casting $course->modinfo to string prevents one notice when the field is null $modinfo = get_fast_modinfo($course); //Acccessibility: replace table with list <ul>, but don't output empty list. if (!empty($section->sequence)) { $collapsablename = "collapsable-{$course->id}-{$section->id}"; echo '<script type="text/javascript">'; echo "//<![CDATA[\n"; /** * Can use both: * call a function: addLoadEvent(nameOfSomeFunctionToRunOnPageLoad); * execute code: addLoadEvent(function() { * // more code to run on page load * }); */ echo "addLoadEvent(function() {"; echo " compactMenu('{$collapsablename}',false,'{$spacer}± ');"; echo " stateToFromStr('{$collapsablename}', retrieveCookie('{$collapsablename}'));"; echo '});'; echo "addUnloadEvent(function() {"; echo " setCookie('{$collapsablename}',stateToFromStr('{$collapsablename}'));"; echo '});'; echo "//]]>\n"; echo '</script>'; // Fix bug #5027, don't want style=\"width:$width\". echo "<ul id=\"{$collapsablename}\" class=\"section img-text treesection\">\n"; $sectionmods = explode(",", $section->sequence); /// Preprocess all the mods, adding the necessary stuff to be able to /// output nested lists later preprocessmods4topicstree($sectionmods, $mods, $modinfo); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if (isset($modinfo->cms[$modnumber])) { if (!$modinfo->cms[$modnumber]->uservisible) { // visibility shortcut continue; } } else { if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) { // module not installed continue; } if (!coursemodule_visible_for_user($mod)) { // full visibility check continue; } } $lastcss = ''; /// Close levels if necessary if (!empty($mod->closelevel)) { for ($n = 0; $n < $mod->closelevel; $n++) { echo '</ul></li>' . "\n"; } } if (!empty($mod->islast)) { $lastcss = 'last '; } echo '<li class="activity treeactivity ' . $lastcss . $mod->modname . '" id="module-' . $modnumber . '">'; // Unique ID /// Add spacer for activities without collapse/expand button if (empty($mod->openlevel)) { echo $spacer; } $extra = ''; if (!empty($modinfo->cms[$modnumber]->extra)) { $extra = $modinfo->cms[$modnumber]->extra; } if ($mod->modname == "label") { if (!$mod->visible) { echo "<span class=\"dimmed_text\">"; } echo format_text($extra, FORMAT_HTML, $labelformatoptions); if (!$mod->visible) { echo "</span>"; } if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>'; } } else { // Normal activity $instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id); if (!empty($modinfo->cms[$modnumber]->icon)) { $icon = "{$CFG->pixpath}/" . $modinfo->cms[$modnumber]->icon; } else { $icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif"; } //Accessibility: for files get description via icon. $altname = ''; if ('resource' == $mod->modname) { if (!empty($modinfo->cms[$modnumber]->icon)) { $possaltname = $modinfo->cms[$modnumber]->icon; $mimetype = mimeinfo_from_icon('type', $possaltname); $altname = get_mimetype_description($mimetype); } else { $altname = $mod->modfullname; } } else { $altname = $mod->modfullname; } // Avoid unnecessary duplication. if (false !== stripos($instancename, $altname)) { $altname = ''; } // File type after name, for alphabetic lists (screen reader). if ($altname) { $altname = get_accesshide(' ' . $altname); } $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>'; if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>'; } } if ($usetracking && $mod->modname == 'forum') { if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) { echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">'; if ($unread == 1) { echo $strunreadpostsone; } else { print_string('unreadpostsnumber', 'forum', $unread); } echo '</a></span>'; } } /// Open new level if necessary, else print end of li if (isset($mod->openlevel)) { echo '<ul class="treelevel-' . ($mod->openlevel + 1) . '">' . "\n"; } else { echo "</li>\n"; } } /// End modules iterator /// Close remaining levels if necessary if (!empty($mod->indent)) { for ($n = 0; $n < $mod->indent; $n++) { echo '</ul></li>' . "\n"; } } } if (!empty($section->sequence)) { echo "</ul><!--class='section'-->\n\n"; } }
/** * Produces a list of links to the files uploaded by a user * * @param $userid int optional id of the user. If 0 then $USER->id is used. * @param $return boolean optional defaults to false. If true the list is returned rather than printed * @return string optional */ function print_user_files($userid = 0, $return = false) { global $CFG, $USER, $OUTPUT; if (!$userid) { if (!isloggedin()) { return ''; } $userid = $USER->id; } $output = ''; $submission = $this->get_submission($userid); if (!$submission) { return $output; } $fs = get_file_storage(); $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false); if (!empty($files)) { require_once $CFG->dirroot . '/mod/assignment/locallib.php'; if ($CFG->enableportfolios) { require_once $CFG->libdir . '/portfoliolib.php'; $button = new portfolio_add_button(); } foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/mod_assignment/submission/' . $submission->id . '/' . $filename); $output .= '<a href="' . $path . '" >' . $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . s($filename) . '</a>'; if ($CFG->enableportfolios && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) { $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'submissionid' => $submission->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } if ($CFG->enableplagiarism) { require_once $CFG->libdir . '/plagiarismlib.php'; $output .= plagiarism_get_links(array('userid' => $userid, 'file' => $file, 'cmid' => $this->cm->id, 'course' => $this->course, 'assignment' => $this->assignment)); $output .= '<br />'; } } if ($CFG->enableportfolios && count($files) > 1 && $this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) { $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'submissionid' => $submission->id), '/mod/assignment/locallib.php'); $output .= '<br />' . $button->to_html(PORTFOLIO_ADD_TEXT_LINK); } } $output = '<div class="files">' . $output . '</div>'; if ($return) { return $output; } echo $output; }
function bigbluebuttonbn_get_presentation_array($context, $presentation, $id = null) { $presentation_name = null; $presentation_url = null; $presentation_icon = null; $presentation_mimetype_description = null; if (!empty($presentation)) { $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'mod_bigbluebuttonbn', 'presentation', 0, 'itemid, filepath, filename', false); if (count($files) < 1) { //resource_print_filenotfound($resource, $cm, $course); //die; //exit; } else { $file = reset($files); unset($files); $presentation_name = $file->get_filename(); $presentation_icon = file_file_icon($file, 24); $presentation_mimetype_description = get_mimetype_description($file); if (!is_null($id)) { //Create the nonce component for granting a temporary public access $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'mod_bigbluebuttonbn', 'presentation_cache'); $presentation_nonce_key = sha1($id); $presentation_nonce_value = bigbluebuttonbn_generate_nonce(); $cache->set($presentation_nonce_key, array("value" => $presentation_nonce_value, "counter" => 0)); //The item id was adapted for granting public access to the presentation once in order to allow BigBlueButton to gather the file $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), $presentation_nonce_value, $file->get_filepath(), $file->get_filename()); } else { $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(), $file->get_filearea(), null, $file->get_filepath(), $file->get_filename()); } $presentation_url = $url->out(false); } } $presentation_array = array("url" => $presentation_url, "name" => $presentation_name, "icon" => $presentation_icon, "mimetype_description" => $presentation_mimetype_description); return $presentation_array; }
/** * Do the actual processing of the uploaded file * @param string $saveas_filename name to give to the file * @param int $maxbytes maximum file size * @param mixed $types optional array of file extensions that are allowed or '*' for all * @param string $savepath optional path to save the file to * @param int $itemid optional the ID for this item within the file area * @param string $license optional the license to use for this file * @param string $author optional the name of the author of this file * @return object containing details of the file uploaded */ public function process_upload($saveas_filename, $maxbytes, $types = '*', $savepath = '/', $itemid = 0, $license = null, $author = '') { global $USER, $CFG; if (is_array($types) and in_array('*', $types) or $types == '*') { $this->mimetypes = '*'; } else { foreach ($types as $type) { $this->mimetypes[] = mimeinfo('type', $type); } } if ($license == null) { $license = $CFG->sitedefaultlicense; } $record = new stdClass(); $record->filearea = 'draft'; $record->component = 'user'; $record->filepath = $savepath; $record->itemid = $itemid; $record->license = $license; $record->author = $author; $context = get_context_instance(CONTEXT_USER, $USER->id); $elname = 'repo_upload_file'; $fs = get_file_storage(); $sm = get_string_manager(); if ($record->filepath !== '/') { $record->filepath = file_correct_filepath($record->filepath); } if (!isset($_FILES[$elname])) { throw new moodle_exception('nofile'); } if (!empty($_FILES[$elname]['error'])) { switch ($_FILES[$elname]['error']) { case UPLOAD_ERR_INI_SIZE: throw new moodle_exception('upload_error_ini_size', 'repository_upload'); break; case UPLOAD_ERR_FORM_SIZE: throw new moodle_exception('upload_error_form_size', 'repository_upload'); break; case UPLOAD_ERR_PARTIAL: throw new moodle_exception('upload_error_partial', 'repository_upload'); break; case UPLOAD_ERR_NO_FILE: throw new moodle_exception('upload_error_no_file', 'repository_upload'); break; case UPLOAD_ERR_NO_TMP_DIR: throw new moodle_exception('upload_error_no_tmp_dir', 'repository_upload'); break; case UPLOAD_ERR_CANT_WRITE: throw new moodle_exception('upload_error_cant_write', 'repository_upload'); break; case UPLOAD_ERR_EXTENSION: throw new moodle_exception('upload_error_extension', 'repository_upload'); break; default: throw new moodle_exception('nofile'); } } // scan the files, throws exception and deletes if virus found // this is tricky because clamdscan daemon might not be able to access the files $permissions = fileperms($_FILES[$elname]['tmp_name']); @chmod($_FILES[$elname]['tmp_name'], $CFG->filepermissions); self::antivir_scan_file($_FILES[$elname]['tmp_name'], $_FILES[$elname]['name'], true); @chmod($_FILES[$elname]['tmp_name'], $permissions); if (empty($saveas_filename)) { $record->filename = clean_param($_FILES[$elname]['name'], PARAM_FILE); } else { $ext = ''; $match = array(); $filename = clean_param($_FILES[$elname]['name'], PARAM_FILE); if (preg_match('/\\.([a-z0-9]+)$/i', $filename, $match)) { if (isset($match[1])) { $ext = $match[1]; } } $ext = !empty($ext) ? $ext : ''; if (preg_match('#\\.(' . $ext . ')$#i', $saveas_filename)) { // saveas filename contains file extension already $record->filename = $saveas_filename; } else { $record->filename = $saveas_filename . '.' . $ext; } } // Check the file has some non-null contents - usually an indication that a user has // tried to upload a folder by mistake if (!$this->check_valid_contents($_FILES[$elname]['tmp_name'])) { throw new moodle_exception('upload_error_invalid_file', 'repository_upload', '', $record->filename); } if ($this->mimetypes != '*') { // check filetype $filemimetype = mimeinfo('type', $_FILES[$elname]['name']); if (!in_array($filemimetype, $this->mimetypes)) { throw new moodle_exception('invalidfiletype', 'repository', '', get_mimetype_description(array('filename' => $_FILES[$elname]['name']))); } } if (empty($record->itemid)) { $record->itemid = 0; } if ($maxbytes !== -1 && filesize($_FILES[$elname]['tmp_name']) > $maxbytes) { throw new file_exception('maxbytes'); } $record->contextid = $context->id; $record->userid = $USER->id; $record->source = ''; if (repository::draftfile_exists($record->itemid, $record->filepath, $record->filename)) { $existingfilename = $record->filename; $unused_filename = repository::get_unused_filename($record->itemid, $record->filepath, $record->filename); $record->filename = $unused_filename; $stored_file = $fs->create_file_from_pathname($record, $_FILES[$elname]['tmp_name']); $event = array(); $event['event'] = 'fileexists'; $event['newfile'] = new stdClass(); $event['newfile']->filepath = $record->filepath; $event['newfile']->filename = $unused_filename; $event['newfile']->url = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $unused_filename)->out(false); $event['existingfile'] = new stdClass(); $event['existingfile']->filepath = $record->filepath; $event['existingfile']->filename = $existingfilename; $event['existingfile']->url = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $existingfilename)->out(false); return $event; } else { $stored_file = $fs->create_file_from_pathname($record, $_FILES[$elname]['tmp_name']); return array('url' => moodle_url::make_draftfile_url($record->itemid, $record->filepath, $record->filename)->out(false), 'id' => $record->itemid, 'file' => $record->filename); } }
/** * Prepares list of files before passing it to AJAX, makes sure data is in the correct * format and stores formatted values. * * @param array|stdClass $listing result of get_listing() or search() or file_get_drafarea_files() * @return array */ public static function prepare_listing($listing) { global $OUTPUT; $defaultfoldericon = $OUTPUT->pix_url(file_folder_icon(24))->out(false); // prepare $listing['path'] or $listing->path if (is_array($listing) && isset($listing['path']) && is_array($listing['path'])) { $path = &$listing['path']; } else if (is_object($listing) && isset($listing->path) && is_array($listing->path)) { $path = &$listing->path; } if (isset($path)) { $len = count($path); for ($i=0; $i<$len; $i++) { if (is_array($path[$i]) && !isset($path[$i]['icon'])) { $path[$i]['icon'] = $defaultfoldericon; } else if (is_object($path[$i]) && !isset($path[$i]->icon)) { $path[$i]->icon = $defaultfoldericon; } } } // prepare $listing['list'] or $listing->list if (is_array($listing) && isset($listing['list']) && is_array($listing['list'])) { $listing['list'] = array_values($listing['list']); // convert to array $files = &$listing['list']; } else if (is_object($listing) && isset($listing->list) && is_array($listing->list)) { $listing->list = array_values($listing->list); // convert to array $files = &$listing->list; } else { return $listing; } $len = count($files); for ($i=0; $i<$len; $i++) { if (is_object($files[$i])) { $file = (array)$files[$i]; $converttoobject = true; } else { $file = & $files[$i]; $converttoobject = false; } if (isset($file['size'])) { $file['size'] = (int)$file['size']; $file['size_f'] = display_size($file['size']); } if (isset($file['license']) && get_string_manager()->string_exists($file['license'], 'license')) { $file['license_f'] = get_string($file['license'], 'license'); } if (isset($file['image_width']) && isset($file['image_height'])) { $a = array('width' => $file['image_width'], 'height' => $file['image_height']); $file['dimensions'] = get_string('imagesize', 'repository', (object)$a); } foreach (array('date', 'datemodified', 'datecreated') as $key) { if (!isset($file[$key]) && isset($file['date'])) { $file[$key] = $file['date']; } if (isset($file[$key])) { // must be UNIX timestamp $file[$key] = (int)$file[$key]; if (!$file[$key]) { unset($file[$key]); } else { $file[$key.'_f'] = userdate($file[$key], get_string('strftimedatetime', 'langconfig')); $file[$key.'_f_s'] = userdate($file[$key], get_string('strftimedatetimeshort', 'langconfig')); } } } $isfolder = (array_key_exists('children', $file) || (isset($file['type']) && $file['type'] == 'folder')); $filename = null; if (isset($file['title'])) { $filename = $file['title']; } else if (isset($file['fullname'])) { $filename = $file['fullname']; } if (!isset($file['mimetype']) && !$isfolder && $filename) { $file['mimetype'] = get_mimetype_description(array('filename' => $filename)); } if (!isset($file['icon'])) { if ($isfolder) { $file['icon'] = $defaultfoldericon; } else if ($filename) { $file['icon'] = $OUTPUT->pix_url(file_extension_icon($filename, 24))->out(false); } } if ($converttoobject) { $files[$i] = (object)$file; } } return $listing; }
/** * Display a post. This method is used for: * - The normal HTML display of a post * - HTML email of a post * - Text-only email of a post * These are all combined in one method since ordinarily they change at * the same time (i.e. if adding/hiding information it is usually added to * or hidden from all views). * * $options is an associative array from a mod_forumng_post::OPTION_xx constant. * All available options are always set - if they were not set by * the user, they will have been set to false before this call happens, * so there is no need to use empty() or isset(). * * Options are as follows. These are available in email mode: * * OPTION_TIME_ZONE (int) - Moodle time zone * OPTION_VIEW_FULL_NAMES (bool) - If user is allowed to see full names * OPTION_EMAIL (bool) - True if this is an email (false = standard view) * OPTION_DIGEST (bool) - True if this is part of an email digest * OPTION_COMMAND_REPLY (bool) - True if 'Reply' link should be displayed * (available in email too) * * These options only apply in non-email usage: * * OPTION_SUMMARY (bool) - True if the entire post should not be displayed, * only a short summary * OPTION_NO_COMMANDS (bool) - True if this post is being printed on its own * OPTION_COMMAND_EDIT (bool) - Display 'Edit' command * OPTION_COMMAND_DELETE (bool) - Display 'Edit' command * OPTION_COMMAND_SPLIT (bool) - Display 'Split' command * OPTION_RATINGS_VIEW (bool) - True to display current ratings * OPTION_RATINGS_EDIT (bool) - True to display ratings edit combo * OPTION_LEAVE_DIV_OPEN (bool) - True to not close post div (means that * child posts can be added within). * OPTION_EXPANDED (bool) - True to show full post, otherwise abbreviate * OPTION_DISCUSSION_SUBJECT (bool) - If true, and only IF post is a * discussion root, includes subject (HTML, shortened as it would be for * header display) as a hidden field. * * @param mod_forumng_post $post Post object * @param bool $html True if using HTML, false to output in plain text * @param array $options Associative array of name=>option, as above * @return string HTML or text of post */ public function render_post($post, $html, $options) { global $CFG, $USER, $THEME, $OUTPUT; $discussion = $post->get_discussion(); $expanded = $options[mod_forumng_post::OPTION_EXPANDED]; $export = $options[mod_forumng_post::OPTION_EXPORT]; $email = $options[mod_forumng_post::OPTION_EMAIL]; // When posts are deleted we hide a lot of info - except when the person // viewing it has the ability to view deleted posts. $deletedhide = $post->get_deleted() && !$options[mod_forumng_post::OPTION_VIEW_DELETED_INFO]; // Hide deleted messages if they have no replies if ($deletedhide && ($export || !$email) && !$post->has_children()) { // note: !email check is to deal with posts that are deleted // between when the mail list finds them, and when it sends out // mail. It would be confusing to send out a blank email so let's // not do that. Also, ->has_children() is not safe to call during // email processing because it doesn't load the whole discussion. return ''; } // Save some bandwidth by not sending link full paths except in emails if ($options[mod_forumng_post::OPTION_FULL_ADDRESSES]) { $linkprefix = $CFG->wwwroot . '/mod/forumng/'; } else { $linkprefix = ''; } $postnumber = ($options[mod_forumng_post::OPTION_NO_COMMANDS] || $email) && !$options[mod_forumng_post::OPTION_VISIBLE_POST_NUMBERS] ? '' : $post->get_number(); $lf = "\n"; // Initialise result $out = ''; if ($html) { if ($export) { $out .= '<hr />'; } // Basic intro $classes = $expanded ? ' forumng-full' : ' forumng-short'; $classes .= $post->is_important() ? ' forumng-important' : ''; $classes .= !$email && !$options[mod_forumng_post::OPTION_UNREAD_NOT_HIGHLIGHTED] && $post->is_unread() ? ' forumng-unread' : ' forumng-read'; $classes .= $post->get_deleted() ? ' forumng-deleted' : ''; $classes .= ' forumng-p' . $postnumber; if ($options[mod_forumng_post::OPTION_INDICATE_MODERATOR] == true) { $classes .= ' forumng-imoderator'; } $out .= $lf . '<div class="forumng-post' . $classes . '">' . '<div class="post-deco"><div class="post-deco-bar"></div></div><a id="p' . $post->get_id() . '"></a>'; if ($options[mod_forumng_post::OPTION_FIRST_UNREAD]) { $out .= '<a id="firstunread"></a>'; } // Theme hooks if (!empty($THEME->forumng_post_hooks)) { for ($i = 1; $i <= $THEME->forumng_post_hooks; $i++) { $out .= '<div class="forumng-' . $i . '"></div>'; } } } if ($html || $options[mod_forumng_post::OPTION_VISIBLE_POST_NUMBERS]) { // Accessible text giving post a number so we can make links unique // etc. if ($postnumber) { $data = new stdClass(); $data->num = $postnumber; if ($post->get_parent()) { if ($html) { $data->parent = '<a class="forumng-parentlink" href="#p' . $post->get_parent()->get_id() . '">' . $post->get_parent()->get_number() . '</a>'; } else { $data->parent = $post->get_parent()->get_number(); } $data->info = ''; if ($post->is_unread()) { $data->info = get_string('postinfo_unread', 'forumng'); } if (!$expanded) { $data->info .= ' ' . get_string('postinfo_short', 'forumng'); } if ($post->get_deleted()) { $data->info .= ' ' . get_string('postinfo_deleted', 'forumng'); } $data->info = trim($data->info); if ($data->info) { $data->info = ' (' . $data->info . ')'; } $info = get_string('postnumreply', 'forumng', $data); } else { $info = get_string('postnum', 'forumng', $data); } if ($options[mod_forumng_post::OPTION_VISIBLE_POST_NUMBERS]) { if (!$html) { $out .= "## " . $info . "\n"; } } } } // Discussion subject (root only) if ($options[mod_forumng_post::OPTION_DISCUSSION_SUBJECT] && $post->is_root_post()) { $out .= '<input type="hidden" name="discussion_subject" value="' . shorten_text(htmlspecialchars($post->get_subject())) . '" />'; } // Pictures (HTML version only) if ($html) { $out .= $lf . html_writer::start_tag('div', array('class' => 'forumng-pic-info')); } if ($html && !$export && $options[mod_forumng_post::OPTION_USER_IMAGE]) { $out .= $lf . html_writer::start_tag('div', array('class' => 'forumng-pic')); // User picture. if (!$options[mod_forumng_post::OPTION_IS_ANON]) { $out .= $deletedhide ? '' : $post->display_user_picture(); } else { if ($options[mod_forumng_post::OPTION_VIEW_ANON_INFO]) { $out .= $deletedhide ? '' : $post->display_user_picture(); } } // Group pictures if any - only for expanded version if ($expanded) { $grouppics = $post->display_group_pictures(); if ($grouppics) { $out .= '<div class="forumng-grouppicss">' . $grouppics . '</div>'; } } $out .= html_writer::end_tag('div'); } // Link used to expand post $expandlink = ''; if (!$expanded && !$deletedhide) { $expandlink = $this->render_expand_link($linkprefix, $discussion, $post); } // Byline $by = new stdClass(); $by->name = $deletedhide ? '' : fullname($post->get_user(), $options[mod_forumng_post::OPTION_VIEW_FULL_NAMES]); $by->date = $deletedhide ? '' : userdate($post->get_created(), get_string('strftimedatetime', 'langconfig'), $options[mod_forumng_post::OPTION_TIME_ZONE]); if ($html) { $out .= $lf . '<div class="forumng-info"><h2 class="forumng-author">'; $out .= $post->is_important() ? '<img src="' . $this->pix_url('exclamation_mark', 'mod_forumng') . '" alt="' . get_string('important', 'forumng') . '" ' . 'title = "' . get_string('important', 'forumng') . '"/>' : ''; if ($export) { if (!$options[mod_forumng_post::OPTION_IS_ANON]) { $out .= $by->name . ' '; } } else { if (!$options[mod_forumng_post::OPTION_IS_ANON]) { $out .= '<a href="' . $CFG->wwwroot . '/user/view.php?id=' . $post->get_user()->id . ($post->get_forum()->is_shared() ? '' : '&course=' . $post->get_forum()->get_course_id()) . '">' . $by->name . '</a>'; } } if ($options[mod_forumng_post::OPTION_IS_ANON] || $options[mod_forumng_post::OPTION_INDICATE_MODERATOR]) { $moderator = get_string('moderator', 'forumng'); $out .= html_writer::tag('div', get_string('moderator', 'forumng'), array('class' => 'forumng-moderator-flag')); } if ($postnumber) { if ($options[mod_forumng_post::OPTION_VISIBLE_POST_NUMBERS]) { $out .= html_writer::tag('small', ' ' . $info, array('class' => 'accesshide', 'style' => 'position:static')); } else { $out .= '<span class="accesshide"> ' . $info . ' </span>'; } } $out .= $deletedhide ? '' : '</h2> <span class="forumng-separator">•</span> '; $out .= '<span class="forumng-date">' . $by->date . '</span>'; // Should not show editing user info, if poster is anonymous and // current user can�t view anonymous info . if ($options[mod_forumng_post::OPTION_IS_ANON] && $discussion->get_forum()->can_post_anonymously() || $options[mod_forumng_post::OPTION_INDICATE_MODERATOR] || !$options[mod_forumng_post::OPTION_IS_ANON] && !$email) { if ($edituser = $post->get_edit_user()) { $out .= ' <span class="forumng-separator">•</span> ' . '<span class="forumng-edit">'; $edit = new stdClass(); $edit->date = userdate($post->get_modified(), get_string('strftimedatetime', 'langconfig'), $options[mod_forumng_post::OPTION_TIME_ZONE]); $edit->name = fullname($edituser, $options[mod_forumng_post::OPTION_VIEW_FULL_NAMES]); if ($edituser->id == $post->get_user()->id) { $out .= get_string('editbyself', 'forumng', $edit->date); } else { $out .= get_string('editbyother', 'forumng', $edit); } if ($options[mod_forumng_post::OPTION_COMMAND_HISTORY]) { $out .= ' (<a href="history.php?' . $post->get_link_params(mod_forumng::PARAM_HTML) . '">' . get_string('history', 'forumng') . '</a>)'; } $out .= '</span>'; } } if ($options[mod_forumng_post::OPTION_SELECTABLE]) { $out .= '<span class="forumng-separator"> • </span>' . '<input type="checkbox" name="selectp' . $post->get_id() . '" id="id_selectp' . $post->get_id() . '" /><label class="accesshide" for="id_selectp' . $post->get_id() . '">' . get_string('selectlabel', 'forumng', $postnumber) . '</label>'; } // End: forumng-info. $out .= html_writer::end_tag('div'); // End: forumng-pic-info. $out .= html_writer::end_tag('div'); } else { require_once dirname(__FILE__) . '/mod_forumng_cron.php'; $out .= $by->name . ' - ' . $by->date . $lf; $out .= mod_forumng_cron::EMAIL_DIVIDER; } // Add a outer div to main contents if ($html) { $out .= '<div class="forumng-post-outerbox">'; } if ($html && $post->get_deleted()) { $out .= '<p class="forumng-deleted-info"><strong>' . get_string('deletedpost', 'forumng') . '</strong> '; if ($deletedhide) { $out .= get_string($post->get_delete_user()->id == $post->get_user()->id ? 'deletedbyauthor' : 'deletedbymoderator', 'forumng', userdate($post->get_deleted())); } else { $a = new stdClass(); $a->date = userdate($post->get_deleted()); $a->user = '******' . $CFG->wwwroot . '/user/view.php?id=' . $post->get_delete_user()->id . '&course=' . $post->get_forum()->get_course_id() . '">' . fullname($post->get_delete_user(), $options[mod_forumng_post::OPTION_VIEW_FULL_NAMES]) . '</a>'; $out .= get_string('deletedbyuser', 'forumng', $a); } $out .= '</p>'; } if ($options[mod_forumng_post::OPTION_IS_ANON] && $options[mod_forumng_post::OPTION_VIEW_ANON_INFO] && !$email) { $a = html_writer::link(new moodle_url('/user/view.php', array('id' => $post->get_user()->id, 'course' => $post->get_forum()->get_course_id())), fullname($post->get_user(), $options[mod_forumng_post::OPTION_VIEW_FULL_NAMES])); $out .= get_string('createdbymoderator', 'forumng', $a); } // Get subject. This may make a db query when showing a single post // (which includes parent subject). if ($options[mod_forumng_post::OPTION_EMAIL] || $options[mod_forumng_post::OPTION_NO_COMMANDS]) { $subject = $post->get_effective_subject(true); } else { $subject = $post->get_subject(); } // Otherwise, subject is only displayed if it has changed if ($subject !== null && $expanded && !$deletedhide) { if ($html) { $out .= $lf . '<h3 class="forumng-subject">'; if ($options[mod_forumng_post::OPTION_DIGEST]) { // Digest contains link to original post $out .= '<a href="' . $linkprefix . 'discuss.php?' . $discussion->get_link_params(mod_forumng::PARAM_HTML) . '#p' . $post->get_id() . '">' . format_string($subject) . '</a>'; } else { $out .= format_string($subject); } $out .= '</h3>'; } else { $out .= format_string($subject, true); if ($options[mod_forumng_post::OPTION_DIGEST]) { // Link to original post $out .= " <{$linkprefix}discuss.php?" . $discussion->get_link_params(mod_forumng::PARAM_HTML) . $discussion->get_id() . '#p' . $post->get_id() . '>'; } $out .= $lf; } } // Get content of actual message in HTML if ($html) { $message = $post->get_formatted_message(); if (!$expanded && !$deletedhide) { // When not expanded and no subject, we include a summary of the // message $stripped = strip_tags(preg_replace('~<script.*?</script>~s', '', $message)); $messagetosummarise = $subject !== null ? '<h3>' . $subject . '</h3> ' . $stripped : $stripped; $summary = self::nice_shorten_text($messagetosummarise, 50); $out .= $lf . '<div class="forumng-summary"><div class="forumng-text">' . $summary . '</div> ' . $expandlink . '</div>'; } } // Start of post main section if ($expanded && !$deletedhide) { if ($html) { $out .= '<div class="forumng-postmain">'; } // Attachments $attachments = $post->get_attachment_names(); if (count($attachments)) { if ($html) { $out .= $lf; if (count($attachments) == 1) { $attachmentlabel = get_string('attachment', 'forumng'); } else { $attachmentlabel = get_string('attachments', 'forumng'); } $out .= '<span class="accesshide">' . $attachmentlabel . '</span><ul class="forumng-attachments">'; } foreach ($attachments as $attachment) { if ($html) { require_once $CFG->libdir . '/filelib.php'; $iconsrc = $this->pix_url('/f/' . mimeinfo('icon', $attachment)); $alt = get_mimetype_description(mimeinfo('type', $attachment)); $out .= '<li><a href="' . $post->get_attachment_url($attachment) . '">' . '<img src="' . $iconsrc . '" alt="' . $alt . '" /> <span>' . htmlspecialchars($attachment) . '</span></a> </li>'; } else { // Right-align the entry to 70 characters $padding = 70 - strlen($attachment); if ($padding > 0) { $out .= str_repeat(' ', $padding); } // Add filename $out .= $attachment . $lf; } } if ($html) { $out .= '</ul>' . $lf; } else { $out .= $lf; // Extra line break after attachments } } // Display actual content if ($html) { if ($options[mod_forumng_post::OPTION_PRINTABLE_VERSION]) { $message = preg_replace('~<a[^>]*\\shref\\s*=\\s*[\'"](http:.*?)[\'"][^>]*>' . '(?!(http:|www\\.)).*?</a>~', "\$0 [\$1]", $message); } $out .= $lf . '<div class="forumng-message">' . $message . '</div>'; } else { $out .= $post->get_email_message(); $out .= "\n\n"; } if ($html) { $out .= $lf . '<div class="clear forumng-postfooter">'; } // Ratings. $ratings = ''; $ratingclasses = ''; if ($options[mod_forumng_post::OPTION_RATINGS_VIEW]) { $ratingclasses .= ' forumng-canview'; if ($post->get_num_ratings() >= $post->get_forum()->get_rating_threshold()) { if ($html) { $ratings .= '<div class="forumng-rating">'; $a = new stdClass(); $a->avg = '<strong id="rating_for_' . $post->get_id() . '">' . $post->get_average_rating(true) . '</strong>'; $a->num = '<span class="forumng-count">' . $post->get_num_ratings() . '</span>'; $ratings .= get_string('averagerating', 'forumng', $a); $ratings .= '</div>'; } else { $ratings .= strip_tags($post->get_average_rating(true)); } } } if ($options[mod_forumng_post::OPTION_RATINGS_EDIT] && $html) { $ratingclasses .= ' forumng-canedit'; $ratings .= '<div class="forumng-editrating">' . get_string('yourrating', 'forumng') . ' '; $ratings .= html_writer::select($post->get_forum()->get_rating_options(), 'rating' . $post->get_id(), $post->get_own_rating(), array(mod_forumng_post::NO_RATING => '-')); $ratings .= '</div>'; } if ($post->get_forum()->get_enableratings() == mod_forumng::FORUMNG_STANDARD_RATING && $post->get_ratings()) { $out .= html_writer::div($OUTPUT->render($post->get_ratings()), 'forumng-ratings-standard'); } else { if ($ratings) { $out .= '<div class="forumng-ratings' . $ratingclasses . '">' . $ratings . '</div>'; } } // Commands at bottom of mail $mobileclass = ''; if ($html) { $commandsarray = array(); $expires = $post->can_ignore_edit_time_limit() ? '' : '&expires=' . ($post->get_edit_time_limit() - time()); $expandparam = !empty($options[mod_forumng_post::OPTION_CHILDREN_EXPANDED]) ? '&expand=1' : ''; // Jump box if ($options[mod_forumng_post::OPTION_JUMP_PREVIOUS] || $options[mod_forumng_post::OPTION_JUMP_NEXT] || $options[mod_forumng_post::OPTION_JUMP_PARENT]) { $nextid = $options[mod_forumng_post::OPTION_JUMP_NEXT]; $pid = $options[mod_forumng_post::OPTION_JUMP_PREVIOUS]; $parentid = $options[mod_forumng_post::OPTION_JUMP_PARENT]; if ($jumptotext = $this->render_commands_jumpto($nextid, $pid, $parentid)) { $thiscommand = '<span class="forumng-jumpto-label">' . get_string('jumpto', 'forumng') . '</span>' . $jumptotext; $commandsarray['forumng-jumpto'] = $thiscommand; } } // Mark post read. if ($CFG->forumng_trackreadposts && !isguestuser() && $post->is_unread() && !mod_forumng::mark_read_automatically()) { $commandsarray['forumng-markread'] = html_writer::link(new moodle_url('/mod/forumng/markread.php', array('p' => $post->get_id())), get_string('markpostread', 'forumng')); } // Flag link. if ($options[mod_forumng_post::OPTION_FLAG_CONTROL]) { $flagurl = new moodle_url('flagpost.php?', array('p' => $post->get_id(), 'timeread' => $options[mod_forumng_post::OPTION_READ_TIME], 'flag' => $post->is_flagged() ? 0 : 1)); $icon = "flag." . ($post->is_flagged() ? 'on' : 'off'); $iconalt = get_string($post->is_flagged() ? 'clearflag' : 'setflag', 'forumng'); $bnstr = get_string($post->is_flagged() ? 'clearflag' : 'flagpost', 'forumng'); $iconhtml = $OUTPUT->pix_icon($icon, '', 'forumng'); $iconhtml .= html_writer::span($bnstr, 'flagtext'); $link = html_writer::link($flagurl, $iconhtml, array('title' => $iconalt)); $commandsarray['forumng-flagpost'] = html_writer::div($link, 'forumng-flagpost'); } // Direct link. if ($options[mod_forumng_post::OPTION_COMMAND_DIRECTLINK]) { $commandsarray['forumng-permalink'] = '<a href="discuss.php?' . $discussion->get_link_params(mod_forumng::PARAM_HTML) . '#p' . $post->get_id() . '" title="' . get_string('directlinktitle', 'forumng') . '">' . get_string('directlink', 'forumng', $postnumber) . '</a>'; } // Alert link. $forum = $discussion->get_forum(); if ($options[mod_forumng_post::OPTION_COMMAND_REPORT] && !($options[mod_forumng_post::OPTION_IS_ANON] || $options[mod_forumng_post::OPTION_INDICATE_MODERATOR])) { $reportabuselink = ''; if ($forum->oualerts_enabled()) { $itmurl = $CFG->wwwroot . '/mod/forumng/discuss.php'; $itmurl .= '?' . $discussion->get_link_params(mod_forumng::PARAM_PLAIN); $itemurl = $itmurl . '#p' . $post->get_id(); $context = $post->get_forum()->get_context(false); $reportabuselink = oualerts_generate_alert_form_url('forumng', $context->id, 'post', $post->get_id(), $itemurl, $itemurl, $USER->id, false, true); } else { $reportabuselink = $linkprefix . 'alert.php?' . $post->get_link_params(mod_forumng::PARAM_HTML) . $expandparam; } $commandsarray['forumng-alert'] = '<a href="' . $reportabuselink . '" title="' . get_string('alert_linktitle', 'forumng') . '">' . get_string('alert_link', 'forumng', $postnumber) . '</a>'; } // Split link if ($options[mod_forumng_post::OPTION_COMMAND_SPLIT]) { $commandsarray['forumng-split'] = '<a href="' . $linkprefix . 'splitpost.php?' . $post->get_link_params(mod_forumng::PARAM_HTML) . $expandparam . '">' . get_string('split', 'forumng', $postnumber) . '</a>'; } // Delete link if ($options[mod_forumng_post::OPTION_COMMAND_DELETE]) { $commandsarray['forumng-delete'] = '<a' . $mobileclass . ' href="' . $linkprefix . 'deletepost.php?' . $post->get_link_params(mod_forumng::PARAM_HTML, true) . $expandparam . $expires . '">' . get_string('delete', 'forumng', $postnumber) . '</a>'; } // Undelete link if ($options[mod_forumng_post::OPTION_COMMAND_UNDELETE]) { $commandsarray['forumng-undelete'] = '<a href="' . $linkprefix . 'deletepost.php?' . $post->get_link_params(mod_forumng::PARAM_HTML) . $expandparam . '&delete=0">' . get_string('undelete', 'forumng', $postnumber) . '</a>'; } // Edit link if ($options[mod_forumng_post::OPTION_COMMAND_EDIT]) { $commandsarray['forumng-edit'] = '<a' . $mobileclass . ' href="' . $linkprefix . 'editpost.php?' . $post->get_link_params(mod_forumng::PARAM_HTML) . $expandparam . $expires . '">' . get_string('edit', 'forumng', $postnumber) . '</a>'; } // Reply link if ($options[mod_forumng_post::OPTION_COMMAND_REPLY]) { $commandsarray['forumng-replylink'] = '<a' . $mobileclass . ' href="' . $linkprefix . 'editpost.php?replyto=' . $post->get_id() . $post->get_forum()->get_clone_param(mod_forumng::PARAM_HTML) . $expandparam . '">' . get_string('reply', 'forumng', $postnumber) . '</a>'; } if (count($commandsarray)) { $out .= $lf . $this->render_commands($commandsarray); } } else { // Reply link if ($options[mod_forumng_post::OPTION_COMMAND_REPLY]) { $out .= mod_forumng_cron::EMAIL_DIVIDER; if ($options[mod_forumng_post::OPTION_EMAIL]) { $course = $post->get_forum()->get_course(); $out .= get_string("postmailinfo", "forumng", $course->shortname) . $lf; } $out .= "{$linkprefix}editpost.php?replyto=" . $post->get_id() . $post->get_forum()->get_clone_param(mod_forumng::PARAM_PLAIN) . $lf; } // Only the reply command is available in text mode } // End: forumng-postfooter and forumng-postmain. if ($html) { $out .= html_writer::end_tag('div') . html_writer::end_tag('div'); } } // End of post div if ($html) { // Useful empty div at end of post. $out .= html_writer::tag('div', '', array('class' => 'forumng-endpost')); // End: forumng-post-outerbox. $out .= html_writer::end_tag('div'); // Export has a couple blank lines after post (but within div, for validity). if ($export) { $out .= '<br /><br />'; } // End: forumng-post. $out .= html_writer::end_tag('div'); } return $out; }
/** * Gets optional details for a resource, depending on resource settings. * * Result may include the file size and type if those settings are chosen, * or blank if none. * * @param object $resource Resource table row * @param object $cm Course-module table row * @return string Size and type or empty string if show options are not enabled */ function resource_get_optional_details($resource, $cm) { global $DB; $details = ''; $options = empty($resource->displayoptions) ? array() : unserialize($resource->displayoptions); if (!empty($options['showsize']) || !empty($options['showtype'])) { $context = context_module::instance($cm->id); $size = ''; $type = ''; if (!empty($options['showsize'])) { $size = display_size($DB->get_field_sql('SELECT SUM(filesize) FROM {files} WHERE contextid=?', array($context->id))); } if (!empty($options['showtype'])) { // For a typical file resource, the sortorder is 1 for the main file // and 0 for all other files. This sort approach is used just in case // there are situations where the file has a different sort order $record = $DB->get_record_sql('SELECT filename, mimetype FROM {files} WHERE contextid=? ORDER BY sortorder DESC', array($context->id), IGNORE_MULTIPLE); // Only show type if it is not unknown if ($record) { $type = get_mimetype_description($record); if ($type === get_mimetype_description('document/unknown')) { $type = ''; } } } if ($size && $type) { // Depending on language it may be necessary to show both options in // different order, so use a lang string $details = get_string('resourcedetails_sizetype', 'resource', (object) array('size' => $size, 'type' => $type)); } else { // Either size or type is set, but not both, so just append $details = $size . $type; } } return $details; }
function display_add_field($recordid = 0, $formdata = null) { global $CFG, $DB, $OUTPUT, $USER, $PAGE; $file = false; $content = false; $displayname = ''; $alttext = ''; $itemid = null; $fs = get_file_storage(); if ($formdata) { $fieldname = 'field_' . $this->field->id . '_file'; $itemid = $formdata->{$fieldname}; $fieldname = 'field_' . $this->field->id . '_alttext'; if (isset($formdata->{$fieldname})) { $alttext = $formdata->{$fieldname}; } } else { if ($recordid) { if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) { file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id); if (!empty($content->content)) { if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) { $usercontext = context_user::instance($USER->id); if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false))) { return false; } if ($thumbfile = $fs->get_file($usercontext->id, 'user', 'draft', $itemid, '/', 'thumb_' . $content->content)) { $thumbfile->delete(); } if (empty($content->content1)) { // Print icon if file already exists $src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename()); $displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . '<a href="' . $src . '" >' . s($file->get_filename()) . '</a>'; } else { $displayname = get_string('nofilesattached', 'repository'); } } } $alttext = $content->content1; } } else { $itemid = file_get_unused_draft_itemid(); } } $str = '<div title="' . s($this->field->description) . '">'; $str .= '<fieldset><legend><span class="accesshide">' . $this->field->name; if ($this->field->required) { $str .= ' ' . get_string('requiredelement', 'form') . '</span></legend>'; $image = html_writer::img($OUTPUT->pix_url('req'), get_string('requiredelement', 'form'), array('class' => 'req', 'title' => get_string('requiredelement', 'form'))); $str .= html_writer::div($image, 'inline-req'); } else { $str .= '</span></legend>'; } $str .= '<noscript>'; if ($file) { $src = file_encode_url($CFG->wwwroot . '/pluginfile.php/', $this->context->id . '/mod_data/content/' . $content->id . '/' . $file->get_filename()); $str .= '<img width="' . s($this->previewwidth) . '" height="' . s($this->previewheight) . '" src="' . $src . '" alt="" />'; } $str .= '</noscript>'; $options = new stdClass(); $options->maxbytes = $this->field->param3; $options->maxfiles = 1; // Only one picture permitted. $options->itemid = $itemid; $options->accepted_types = array('web_image'); $options->return_types = FILE_INTERNAL; $options->context = $PAGE->context; if (!empty($file)) { $options->filename = $file->get_filename(); $options->filepath = '/'; } $fm = new form_filemanager($options); // Print out file manager. $output = $PAGE->get_renderer('core', 'files'); $str .= '<div class="mod-data-input">'; $str .= $output->render($fm); $str .= '<div class="mdl-left">'; $str .= '<input type="hidden" name="field_' . $this->field->id . '_file" value="' . $itemid . '" />'; $str .= '<label for="field_' . $this->field->id . '_alttext">' . get_string('alttext', 'data') . '</label> <input type="text" name="field_' . $this->field->id . '_alttext" id="field_' . $this->field->id . '_alttext" value="' . s($alttext) . '" />'; $str .= '</div>'; $str .= '</div>'; $str .= '</fieldset>'; $str .= '</div>'; return $str; }
function print_section_newsroom($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%") { /// Prints a section full of activity modules global $CFG, $USER; static $initialised; static $groupbuttons; static $groupbuttonslink; static $isediting; static $ismoving; static $strmovehere; static $strmovefull; static $strunreadpostsone; static $usetracking; static $groupings; if (!isset($initialised)) { $groupbuttons = ($course->groupmode or !$course->groupmodeforce); $groupbuttonslink = !$course->groupmodeforce; $isediting = isediting($course->id); $ismoving = $isediting && ismoving($course->id); if ($ismoving) { $strmovehere = get_string("movehere"); $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'")); } include_once $CFG->dirroot . '/mod/forum/lib.php'; if ($usetracking = forum_tp_can_track_forums()) { $strunreadpostsone = get_string('unreadpostsone', 'forum'); } $initialised = true; } $labelformatoptions = new object(); $labelformatoptions->noclean = true; /// Casting $course->modinfo to string prevents one notice when the field is null $modinfo = get_fast_modinfo($course); //Acccessibility: replace table with list <ul>, but don't output empty list. if (!empty($section->sequence)) { // Fix bug #5027, don't want style=\"width:$width\". echo "<ul class=\"section img-text\">\n"; $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } $mod = $mods[$modnumber]; if ($ismoving and $mod->id == $USER->activitycopy) { // do not display moving mod continue; } if (isset($modinfo->cms[$modnumber])) { if (!$modinfo->cms[$modnumber]->uservisible) { // visibility shortcut continue; } } else { if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) { // module not installed continue; } if (!coursemodule_visible_for_user($mod)) { // full visibility check continue; } } // The magic! ... if indent == 1 then ... hide module if ($mod->indent == 1) { $hiddemodule = 'hidden'; } else { $hiddemodule = ''; } echo '<li class="activity ' . $mod->modname . ' ' . $hiddemodule . '" id="module-' . $modnumber . '">'; // Unique ID if ($ismoving) { echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a><br /> '; } if ($mod->indent) { print_spacer(12, 20 * $mod->indent, false); } $extra = ''; if (!empty($modinfo->cms[$modnumber]->extra)) { $extra = $modinfo->cms[$modnumber]->extra; } if ($mod->modname == "label") { echo "<span class=\""; if (!$mod->visible) { echo 'dimmed_text'; } else { echo 'label'; } echo '">'; echo format_text($extra, FORMAT_HTML, $labelformatoptions); echo "</span>"; if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>'; } } else { // Normal activity $instancename = format_string($modinfo->cms[$modnumber]->name, true, $course->id); if (!empty($modinfo->cms[$modnumber]->icon)) { $icon = "{$CFG->pixpath}/" . $modinfo->cms[$modnumber]->icon; } else { $icon = "{$CFG->modpixpath}/{$mod->modname}/icon.gif"; } //Accessibility: for files get description via icon. $altname = ''; if ('resource' == $mod->modname) { if (!empty($modinfo->cms[$modnumber]->icon)) { $possaltname = $modinfo->cms[$modnumber]->icon; $mimetype = mimeinfo_from_icon('type', $possaltname); $altname = get_mimetype_description($mimetype); } else { $altname = $mod->modfullname; } } else { $altname = $mod->modfullname; } // Avoid unnecessary duplication. if (false !== stripos($instancename, $altname)) { $altname = ''; } // File type after name, for alphabetic lists (screen reader). if ($altname) { $altname = get_accesshide(' ' . $altname); } $linkcss = $mod->visible ? "" : " class=\"dimmed\" "; echo '<a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . $instancename . $altname . '</span></a>'; //echo " $mod->modname "; // Special NEWSPAPER magic ... show summry from resource and blog's 200 chars from each post OUBlog (nadavkav) if ($mod->modname == 'resource') { $article = get_record('resource', 'id', $mod->instance); //print_r($article ); echo "{$article->summary}"; } if ($mod->modname == 'oublog') { require_once $CFG->dirroot . '/mod/oublog/locallib.php'; $oublog = get_record('oublog', 'id', $mod->instance); if (!($oublogcm = get_coursemodule_from_instance('oublog', $oublog->id))) { //error("Course module ID was incorrect"); } $oublogcontext = get_context_instance(CONTEXT_MODULE, $oublogcm->id); //oublog_check_view_permissions($oublog, $oublogcontext, $oublogcm); $currentgroup = oublog_get_activity_group($oublogcm, true); echo '<br/>'; /// Get Posts list($posts, $recordcount) = oublog_get_posts($oublog, $oublogcontext, 0, $oublogcm, $currentgroup); //, -1, $oubloguser->id, $tag, $canaudit); $i = 0; foreach ($posts as $post) { if ($i < 3) { echo '<a href="' . $CFG->wwwroot . '/mod/oublog/viewpost.php?blog=' . $oublog->id . '&post=' . $post->id . '">' . $post->title . '</a><br/>'; $summaryformatoptions->noclean = false; echo mb_substr(format_text($post->message, FORMAT_HTML, $summaryformatoptions), 1, 600) . "<hr/>"; } if ($i > 2 and $i < 6) { echo '<a href="' . $CFG->wwwroot . '/mod/oublog/viewpost.php?blog=' . $oublog->id . '&post=' . $post->id . '">' . $post->title . '</a><br/>'; } $i++; } //print_r($article ); //echo "$article->summary"; echo '<br/><a ' . $linkcss . ' ' . $extra . ' href="' . $CFG->wwwroot . '/mod/' . $mod->modname . '/view.php?id=' . $mod->id . '">' . '<img src="' . $icon . '" class="activityicon" alt="" /> <span>' . get_string('more', 'format_newsroom') . '</span></a>'; } if (!empty($CFG->enablegroupings) && !empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>'; } } if ($usetracking && $mod->modname == 'forum') { if ($unread = forum_tp_count_forum_unread_posts($mod, $course)) { echo '<span class="unread"> <a href="' . $CFG->wwwroot . '/mod/forum/view.php?id=' . $mod->id . '">'; if ($unread == 1) { echo $strunreadpostsone; } else { print_string('unreadpostsnumber', 'forum', $unread); } echo '</a></span>'; } } if ($isediting) { // TODO: we must define this as mod property! if ($groupbuttons and $mod->modname != 'label' and $mod->modname != 'resource' and $mod->modname != 'glossary') { if (!($mod->groupmodelink = $groupbuttonslink)) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } echo ' '; echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section); } echo "</li>\n"; } } elseif ($ismoving) { echo "<ul class=\"section\">\n"; } if ($ismoving) { echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . $USER->sesskey . '">' . '<img class="movetarget" src="' . $CFG->pixpath . '/movehere.gif" ' . ' alt="' . $strmovehere . '" /></a></li> '; } if (!empty($section->sequence) || $ismoving) { echo "</ul><!--class='section'-->\n\n"; } }
/** * Tests the get_mimetype_description function. */ public function test_get_mimetype_description() { $this->resetAfterTest(); // Test example type (.doc). $this->assertEquals(get_string('application/msword', 'mimetypes'), get_mimetype_description(array('filename' => 'test.doc'))); // Test an unknown file type. $this->assertEquals(get_string('document/unknown', 'mimetypes'), get_mimetype_description(array('filename' => 'test.frog'))); // Test a custom filetype with no lang string specified. core_filetypes::add_type('frog', 'application/x-frog', 'document'); $this->assertEquals('application/x-frog', get_mimetype_description(array('filename' => 'test.frog'))); // Test custom description. core_filetypes::update_type('frog', 'frog', 'application/x-frog', 'document', array(), '', 'Froggy file'); $this->assertEquals('Froggy file', get_mimetype_description(array('filename' => 'test.frog'))); // Test custom description using multilang filter. filter_set_global_state('multilang', TEXTFILTER_ON); filter_set_applies_to_strings('multilang', true); core_filetypes::update_type('frog', 'frog', 'application/x-frog', 'document', array(), '', '<span lang="en" class="multilang">Green amphibian</span>' . '<span lang="fr" class="multilang">Amphibian vert</span>'); $this->assertEquals('Green amphibian', get_mimetype_description(array('filename' => 'test.frog'))); }
/** * 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 = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $ctx->id . '/mod_workshop/submission_attachment/' . $submissionid . $filepath . $filename, true); $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) . html_writer::link($fileurl, $filename); $linktxt = "$filename [$fileurl]"; if ($format == 'html') { if (file_mimetype_in_typegroup($type, 'web_image')) { $preview = html_writer::empty_tag('img', array('src' => $fileurl, '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 ($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; } }
$search_result = repository::prepare_listing($repo->search($search_text, (int) $page)); $search_result['repo_id'] = $repo_id; $search_result['issearchresult'] = true; echo json_encode($search_result); break; case 'download': // validate mimetype $mimetypes = array(); if (is_array($accepted_types) and in_array('*', $accepted_types) or $accepted_types == '*') { $mimetypes = '*'; } else { foreach ($accepted_types as $type) { $mimetypes[] = mimeinfo('type', $type); } if (!in_array(mimeinfo('type', $saveas_filename), $mimetypes)) { throw new moodle_exception('invalidfiletype', 'repository', '', get_mimetype_description(array('filename' => $saveas_filename))); } } // We have two special repository type need to deal with // local and recent plugins don't added new files to moodle, just add new records to database // so we don't check user quota and maxbytes here $allowexternallink = (int) get_config(null, 'repositoryallowexternallinks'); if (!empty($allowexternallink)) { $allowexternallink = true; } else { $allowexternallink = false; } // allow external links in url element all the time $allowexternallink = $allowexternallink || $env == 'url'; $reference = $repo->get_file_reference($source); // Use link of the files
/** * Prints a section full of activity modules */ function print_section($course, $section, $mods, $modnamesused, $absolute = false, $width = "100%", $hidecompletion = false) { global $CFG, $USER, $DB, $PAGE, $OUTPUT; static $initialised; static $groupbuttons; static $groupbuttonslink; static $isediting; static $ismoving; static $strmovehere; static $strmovefull; static $strunreadpostsone; static $groupings; static $modulenames; if (!isset($initialised)) { $groupbuttons = ($course->groupmode or !$course->groupmodeforce); $groupbuttonslink = !$course->groupmodeforce; $isediting = $PAGE->user_is_editing(); $ismoving = $isediting && ismoving($course->id); if ($ismoving) { $strmovehere = get_string("movehere"); $strmovefull = strip_tags(get_string("movefull", "", "'{$USER->activitycopyname}'")); } $modulenames = array(); $initialised = true; } $modinfo = get_fast_modinfo($course); $completioninfo = new completion_info($course); //Accessibility: replace table with list <ul>, but don't output empty list. if (!empty($section->sequence)) { // Fix bug #5027, don't want style=\"width:$width\". echo "<ul class=\"section img-text\">\n"; $sectionmods = explode(",", $section->sequence); foreach ($sectionmods as $modnumber) { if (empty($mods[$modnumber])) { continue; } /** * @var cm_info */ $mod = $mods[$modnumber]; if ($ismoving and $mod->id == $USER->activitycopy) { // do not display moving mod continue; } if (isset($modinfo->cms[$modnumber])) { // We can continue (because it will not be displayed at all) // if: // 1) The activity is not visible to users // and // 2a) The 'showavailability' option is not set (if that is set, // we need to display the activity so we can show // availability info) // or // 2b) The 'availableinfo' is empty, i.e. the activity was // hidden in a way that leaves no info, such as using the // eye icon. if (!$modinfo->cms[$modnumber]->uservisible && (empty($modinfo->cms[$modnumber]->showavailability) || empty($modinfo->cms[$modnumber]->availableinfo))) { // visibility shortcut continue; } } else { if (!file_exists("{$CFG->dirroot}/mod/{$mod->modname}/lib.php")) { // module not installed continue; } if (!coursemodule_visible_for_user($mod) && empty($mod->showavailability)) { // full visibility check continue; } } if (!isset($modulenames[$mod->modname])) { $modulenames[$mod->modname] = get_string('modulename', $mod->modname); } $modulename = $modulenames[$mod->modname]; // In some cases the activity is visible to user, but it is // dimmed. This is done if viewhiddenactivities is true and if: // 1. the activity is not visible, or // 2. the activity has dates set which do not include current, or // 3. the activity has any other conditions set (regardless of whether // current user meets them) $canviewhidden = has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_MODULE, $mod->id)); $accessiblebutdim = false; if ($canviewhidden) { $accessiblebutdim = !$mod->visible; if (!empty($CFG->enableavailability)) { $accessiblebutdim = $accessiblebutdim || $mod->availablefrom > time() || $mod->availableuntil && $mod->availableuntil < time() || count($mod->conditionsgrade) > 0 || count($mod->conditionscompletion) > 0; } } $liclasses = array(); $liclasses[] = 'activity'; $liclasses[] = $mod->modname; $liclasses[] = 'modtype_' . $mod->modname; $extraclasses = $mod->get_extra_classes(); if ($extraclasses) { $liclasses = array_merge($liclasses, explode(' ', $extraclasses)); } echo html_writer::start_tag('li', array('class' => join(' ', $liclasses), 'id' => 'module-' . $modnumber)); if ($ismoving) { echo '<a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?moveto=' . $mod->id . '&sesskey=' . sesskey() . '">' . '<img class="movetarget" src="' . $OUTPUT->pix_url('movehere') . '" ' . ' alt="' . $strmovehere . '" /></a><br /> '; } $classes = array('mod-indent'); if (!empty($mod->indent)) { $classes[] = 'mod-indent-' . $mod->indent; if ($mod->indent > 15) { $classes[] = 'mod-indent-huge'; } } echo html_writer::start_tag('div', array('class' => join(' ', $classes))); // Get data about this course-module list($content, $instancename) = get_print_section_cm_text($modinfo->cms[$modnumber], $course); //Accessibility: for files get description via icon, this is very ugly hack! $altname = ''; $altname = $mod->modfullname; if (!empty($customicon)) { $archetype = plugin_supports('mod', $mod->modname, FEATURE_MOD_ARCHETYPE, MOD_ARCHETYPE_OTHER); if ($archetype == MOD_ARCHETYPE_RESOURCE) { $mimetype = mimeinfo_from_icon('type', $customicon); $altname = get_mimetype_description($mimetype); } } // Avoid unnecessary duplication: if e.g. a forum name already // includes the word forum (or Forum, etc) then it is unhelpful // to include that in the accessible description that is added. if (false !== strpos(textlib::strtolower($instancename), textlib::strtolower($altname))) { $altname = ''; } // File type after name, for alphabetic lists (screen reader). if ($altname) { $altname = get_accesshide(' ' . $altname); } // We may be displaying this just in order to show information // about visibility, without the actual link $contentpart = ''; if ($mod->uservisible) { // Nope - in this case the link is fully working for user $linkclasses = ''; $textclasses = ''; if ($accessiblebutdim) { $linkclasses .= ' dimmed'; $textclasses .= ' dimmed_text'; $accesstext = '<span class="accesshide">' . get_string('hiddenfromstudents') . ': </span>'; } else { $accesstext = ''; } if ($linkclasses) { $linkcss = 'class="' . trim($linkclasses) . '" '; } else { $linkcss = ''; } if ($textclasses) { $textcss = 'class="' . trim($textclasses) . '" '; } else { $textcss = ''; } // Get on-click attribute value if specified $onclick = $mod->get_on_click(); if ($onclick) { $onclick = ' onclick="' . $onclick . '"'; } if ($url = $mod->get_url()) { // Display link itself echo '<a ' . $linkcss . $mod->extra . $onclick . ' href="' . $url . '"><img src="' . $mod->get_icon_url() . '" class="activityicon" alt="' . $modulename . '" /> ' . $accesstext . '<span class="instancename">' . $instancename . $altname . '</span></a>'; // If specified, display extra content after link if ($content) { $contentpart = '<div class="' . trim('contentafterlink' . $textclasses) . '">' . $content . '</div>'; } } else { // No link, so display only content $contentpart = '<div ' . $textcss . $mod->extra . '>' . $accesstext . $content . '</div>'; } if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', get_context_instance(CONTEXT_COURSE, $course->id))) { if (!isset($groupings)) { $groupings = groups_get_all_groupings($course->id); } echo " <span class=\"groupinglabel\">(" . format_string($groupings[$mod->groupingid]->name) . ')</span>'; } } else { $textclasses = $extraclasses; $textclasses .= ' dimmed_text'; if ($textclasses) { $textcss = 'class="' . trim($textclasses) . '" '; } else { $textcss = ''; } $accesstext = '<span class="accesshide">' . get_string('notavailableyet', 'condition') . ': </span>'; if ($url = $mod->get_url()) { // Display greyed-out text of link echo '<div ' . $textcss . $mod->extra . ' >' . '<img src="' . $mod->get_icon_url() . '" class="activityicon" alt="' . $modulename . '" /> <span>' . $instancename . $altname . '</span></div>'; // Do not display content after link when it is greyed out like this. } else { // No link, so display only content (also greyed) $contentpart = '<div ' . $textcss . $mod->extra . '>' . $accesstext . $content . '</div>'; } } // Module can put text after the link (e.g. forum unread) echo $mod->get_after_link(); // If there is content but NO link (eg label), then display the // content here (BEFORE any icons). In this case cons must be // displayed after the content so that it makes more sense visually // and for accessibility reasons, e.g. if you have a one-line label // it should work similarly (at least in terms of ordering) to an // activity. if (empty($url)) { echo $contentpart; } if ($isediting) { if ($groupbuttons and plugin_supports('mod', $mod->modname, FEATURE_GROUPS, 0)) { if (!($mod->groupmodelink = $groupbuttonslink)) { $mod->groupmode = $course->groupmode; } } else { $mod->groupmode = false; } echo ' '; echo make_editing_buttons($mod, $absolute, true, $mod->indent, $section->section); echo $mod->get_after_edit_icons(); } // Completion $completion = $hidecompletion ? COMPLETION_TRACKING_NONE : $completioninfo->is_enabled($mod); if ($completion != COMPLETION_TRACKING_NONE && isloggedin() && !isguestuser() && $mod->uservisible) { $completiondata = $completioninfo->get_data($mod, true); $completionicon = ''; if ($isediting) { switch ($completion) { case COMPLETION_TRACKING_MANUAL: $completionicon = 'manual-enabled'; break; case COMPLETION_TRACKING_AUTOMATIC: $completionicon = 'auto-enabled'; break; default: // wtf } } else { if ($completion == COMPLETION_TRACKING_MANUAL) { switch ($completiondata->completionstate) { case COMPLETION_INCOMPLETE: $completionicon = 'manual-n'; break; case COMPLETION_COMPLETE: $completionicon = 'manual-y'; break; } } else { // Automatic switch ($completiondata->completionstate) { case COMPLETION_INCOMPLETE: $completionicon = 'auto-n'; break; case COMPLETION_COMPLETE: $completionicon = 'auto-y'; break; case COMPLETION_COMPLETE_PASS: $completionicon = 'auto-pass'; break; case COMPLETION_COMPLETE_FAIL: $completionicon = 'auto-fail'; break; } } } if ($completionicon) { $imgsrc = $OUTPUT->pix_url('i/completion-' . $completionicon); $imgalt = s(get_string('completion-alt-' . $completionicon, 'completion', $mod->name)); if ($completion == COMPLETION_TRACKING_MANUAL && !$isediting) { $imgtitle = s(get_string('completion-title-' . $completionicon, 'completion', $mod->name)); $newstate = $completiondata->completionstate == COMPLETION_COMPLETE ? COMPLETION_INCOMPLETE : COMPLETION_COMPLETE; // In manual mode the icon is a toggle form... // If this completion state is used by the // conditional activities system, we need to turn // off the JS. if (!empty($CFG->enableavailability) && condition_info::completion_value_used_as_condition($course, $mod)) { $extraclass = ' preventjs'; } else { $extraclass = ''; } echo "\n<form class='togglecompletion{$extraclass}' method='post' action='" . $CFG->wwwroot . "/course/togglecompletion.php'><div>\n<input type='hidden' name='id' value='{$mod->id}' />\n<input type='hidden' name='modulename' value='" . s($mod->name) . "' />\n<input type='hidden' name='sesskey' value='" . sesskey() . "' />\n<input type='hidden' name='completionstate' value='{$newstate}' />\n<input type='image' src='{$imgsrc}' alt='{$imgalt}' title='{$imgtitle}' />\n</div></form>"; } else { // In auto mode, or when editing, the icon is just an image echo "<span class='autocompletion'>"; echo "<img src='{$imgsrc}' alt='{$imgalt}' title='{$imgalt}' /></span>"; } } } // If there is content AND a link, then display the content here // (AFTER any icons). Otherwise it was displayed before if (!empty($url)) { echo $contentpart; } // Show availability information (for someone who isn't allowed to // see the activity itself, or for staff) if (!$mod->uservisible) { echo '<div class="availabilityinfo">' . $mod->availableinfo . '</div>'; } else { if ($canviewhidden && !empty($CFG->enableavailability)) { $ci = new condition_info($mod); $fullinfo = $ci->get_full_information(); if ($fullinfo) { echo '<div class="availabilityinfo">' . get_string($mod->showavailability ? 'userrestriction_visible' : 'userrestriction_hidden', 'condition', $fullinfo) . '</div>'; } } } echo html_writer::end_tag('div'); echo html_writer::end_tag('li') . "\n"; } } elseif ($ismoving) { echo "<ul class=\"section\">\n"; } if ($ismoving) { echo '<li><a title="' . $strmovefull . '"' . ' href="' . $CFG->wwwroot . '/course/mod.php?movetosection=' . $section->id . '&sesskey=' . sesskey() . '">' . '<img class="movetarget" src="' . $OUTPUT->pix_url('movehere') . '" ' . ' alt="' . $strmovehere . '" /></a></li> '; } if (!empty($section->sequence) || $ismoving) { echo "</ul><!--class='section'-->\n\n"; } }
function display_add_field($recordid = 0) { global $CFG, $DB, $OUTPUT, $USER, $PAGE; $file = false; $content = false; $displayname = ''; $alttext = ''; $itemid = null; $fs = get_file_storage(); if ($recordid) { if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) { file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id); if (!empty($content->content)) { if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) { $usercontext = get_context_instance(CONTEXT_USER, $USER->id); if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false))) { return false; } if ($thumbfile = $fs->get_file($usercontext->id, 'user', 'draft', $itemid, '/', 'thumb_' . $content->content)) { $thumbfile->delete(); } if (empty($content->content1)) { // Print icon if file already exists $src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename()); $displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . '<a href="' . $src . '" >' . s($file->get_filename()) . '</a>'; } else { $displayname = get_string('nofilesattached', 'repository'); } } } $alttext = $content->content1; } } else { $itemid = file_get_unused_draft_itemid(); } $str = '<div title="' . s($this->field->description) . '">'; $str .= '<fieldset><legend><span class="accesshide">' . $this->field->name . '</span></legend>'; if ($file) { $src = file_encode_url($CFG->wwwroot . '/pluginfile.php/', $this->context->id . '/mod_data/content/' . $content->id . '/' . $file->get_filename()); $str .= '<img width="' . s($this->previewwidth) . '" height="' . s($this->previewheight) . '" src="' . $src . '" alt="" />'; } $options = new stdClass(); $options->maxbytes = $this->field->param3; $options->itemid = $itemid; $options->accepted_types = array('web_image'); $options->return_types = FILE_INTERNAL; $options->context = $PAGE->context; if (!empty($file)) { $options->filename = $file->get_filename(); $options->filepath = '/'; } $fp = new file_picker($options); $str .= $OUTPUT->render($fp); $str .= '<div class="mdl-left">'; $str .= '<input type="hidden" name="field_' . $this->field->id . '_file" value="' . $itemid . '" />'; $str .= '<label for="field_' . $this->field->id . '_alttext">' . get_string('alttext', 'data') . '</label> <input type="text" name="field_' . $this->field->id . '_alttext" id="field_' . $this->field->id . '_alttext" value="' . s($alttext) . '" />'; $str .= '</div>'; $str .= '</fieldset>'; $str .= '</div>'; $module = array('name' => 'data_imagepicker', 'fullpath' => '/mod/data/data.js', 'requires' => array('core_filepicker')); $PAGE->requires->js_init_call('M.data_imagepicker.init', array($fp->options), true, $module); return $str; }
/** * Returns attachments as formated text/html optionally with separate images * * @global object * @global object * @global object * @param object $post * @param object $cm * @param string $type html/text/separateimages * @return mixed string or array of (html text withouth images and image HTML) */ function forum_print_attachments($post, $cm, $type) { global $CFG, $DB, $USER, $OUTPUT; if (empty($post->attachment)) { return $type !== 'separateimages' ? '' : array('', ''); } if (!in_array($type, array('separateimages', 'html', 'text'))) { return $type !== 'separateimages' ? '' : array('', ''); } if (!$context = context_module::instance($cm->id)) { return $type !== 'separateimages' ? '' : array('', ''); } $strattachment = get_string('attachment', 'forum'); $fs = get_file_storage(); $imagereturn = ''; $output = ''; $canexport = !empty($CFG->enableportfolios) && (has_capability('mod/forum:exportpost', $context) || ($post->userid == $USER->id && has_capability('mod/forum:exportownpost', $context))); if ($canexport) { require_once($CFG->libdir.'/portfoliolib.php'); } $files = $fs->get_area_files($context->id, 'mod_forum', 'attachment', $post->id, "timemodified", false); if ($files) { if ($canexport) { $button = new portfolio_add_button(); } foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')); $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_forum/attachment/'.$post->id.'/'.$filename); if ($type == 'html') { $output .= "<a href=\"$path\">$iconimage</a> "; $output .= "<a href=\"$path\">".s($filename)."</a>"; if ($canexport) { $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), 'mod_forum'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= "<br />"; } else if ($type == 'text') { $output .= "$strattachment ".s($filename).":\n$path\n"; } else { //'returnimages' if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // Image attachments don't get printed as links $imagereturn .= "<br /><img src=\"$path\" alt=\"\" />"; if ($canexport) { $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), 'mod_forum'); $button->set_format_by_file($file); $imagereturn .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } } else { $output .= "<a href=\"$path\">$iconimage</a> "; $output .= format_text("<a href=\"$path\">".s($filename)."</a>", FORMAT_HTML, array('context'=>$context)); if ($canexport) { $button->set_callback_options('forum_portfolio_caller', array('postid' => $post->id, 'attachment' => $file->get_id()), 'mod_forum'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= '<br />'; } } if (!empty($CFG->enableplagiarism)) { require_once($CFG->libdir.'/plagiarismlib.php'); $output .= plagiarism_get_links(array('userid' => $post->userid, 'file' => $file, 'cmid' => $cm->id, 'course' => $post->course, 'forum' => $post->forum)); $output .= '<br />'; } } } if ($type !== 'separateimages') { return $output; } else { return array($output, $imagereturn); } }
/** * Gets optional details for a resource, depending on resource settings. * * Result may include the file size and type if those settings are chosen, * or blank if none. * * @param object $resource Resource table row * @param object $cm Course-module table row * @return string Size and type or empty string if show options are not enabled */ function resource_get_optional_details($resource, $cm) { global $DB; $details = ''; $options = empty($resource->displayoptions) ? array() : unserialize($resource->displayoptions); if (!empty($options['showsize']) || !empty($options['showtype'])) { $context = context_module::instance($cm->id); $size = ''; $type = ''; $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'mod_resource', 'content', 0, 'sortorder DESC, id ASC', false); if (!empty($options['showsize']) && count($files)) { $sizebytes = 0; foreach ($files as $file) { // this will also synchronize the file size for external files if needed $sizebytes += $file->get_filesize(); } if ($sizebytes) { $size = display_size($sizebytes); } } if (!empty($options['showtype']) && count($files)) { // For a typical file resource, the sortorder is 1 for the main file // and 0 for all other files. This sort approach is used just in case // there are situations where the file has a different sort order $mainfile = reset($files); $type = get_mimetype_description($mainfile); // Only show type if it is not unknown if ($type === get_mimetype_description('document/unknown')) { $type = ''; } } if ($size && $type) { // Depending on language it may be necessary to show both options in // different order, so use a lang string $details = get_string('resourcedetails_sizetype', 'resource', (object) array('size' => $size, 'type' => $type)); } else { // Either size or type is set, but not both, so just append $details = $size . $type; } } return $details; }
function display_add_field($recordid = 0) { global $CFG, $DB, $OUTPUT, $USER, $PAGE; $file = false; $content = false; $displayname = ''; $alttext = ''; $itemid = null; $fs = get_file_storage(); if ($recordid) { if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) { file_prepare_draft_area($itemid, $this->context->id, 'mod_data', 'content', $content->id); if (!empty($content->content)) { if ($file = $fs->get_file($this->context->id, 'mod_data', 'content', $content->id, '/', $content->content)) { $usercontext = context_user::instance($USER->id); if (!($files = $fs->get_area_files($usercontext->id, 'user', 'draft', $itemid, 'id DESC', false))) { return false; } if ($thumbfile = $fs->get_file($usercontext->id, 'user', 'draft', $itemid, '/', 'thumb_' . $content->content)) { $thumbfile->delete(); } if (empty($content->content1)) { // Print icon if file already exists $src = moodle_url::make_draftfile_url($itemid, '/', $file->get_filename()); $displayname = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')) . '<a href="' . $src . '" >' . s($file->get_filename()) . '</a>'; } else { $displayname = get_string('nofilesattached', 'repository'); } } } $alttext = $content->content1; } } else { $itemid = file_get_unused_draft_itemid(); } $str = '<div title="' . s($this->field->description) . '">'; $str .= '<fieldset><legend><span class="accesshide">' . $this->field->name . '</span></legend>'; $str .= '<noscript>'; if ($file) { $src = file_encode_url($CFG->wwwroot . '/pluginfile.php/', $this->context->id . '/mod_data/content/' . $content->id . '/' . $file->get_filename()); $str .= '<img width="' . s($this->previewwidth) . '" height="' . s($this->previewheight) . '" src="' . $src . '" alt="" />'; } $str .= '</noscript>'; $options = new stdClass(); $options->maxbytes = $this->field->param3; $options->maxfiles = 1; // Only one picture permitted. $options->itemid = $itemid; $options->accepted_types = array('web_image'); $options->return_types = FILE_INTERNAL; $options->context = $PAGE->context; if (!empty($file)) { $options->filename = $file->get_filename(); $options->filepath = '/'; } $fm = new form_filemanager($options); // Print out file manager. $output = $PAGE->get_renderer('core', 'files'); $str .= $output->render($fm); $str .= '<div class="mdl-left">'; $str .= '<input type="hidden" name="field_' . $this->field->id . '_file" value="' . $itemid . '" />'; $str .= '<label for="field_' . $this->field->id . '_alttext">' . get_string('alttext', 'data') . '</label> <input type="text" name="field_' . $this->field->id . '_alttext" id="field_' . $this->field->id . '_alttext" value="' . s($alttext) . '" />'; $str .= '</div>'; $str .= '</fieldset>'; $str .= '</div>'; $module = array('name' => 'form_filemanager', 'fullpath' => '/lib/form/filemanager.js', 'requires' => array('core_filepicker', 'base', 'io-base', 'node', 'json', 'core_dndupload', 'panel', 'resize-plugin', 'dd-plugin'), 'strings' => array(array('error', 'moodle'), array('info', 'moodle'), array('confirmdeletefile', 'repository'), array('draftareanofiles', 'repository'), array('entername', 'repository'), array('enternewname', 'repository'), array('invalidjson', 'repository'), array('popupblockeddownload', 'repository'), array('unknownoriginal', 'repository'), array('confirmdeletefolder', 'repository'), array('confirmdeletefilewithhref', 'repository'), array('confirmrenamefolder', 'repository'), array('confirmrenamefile', 'repository'), array('edit', 'moodle'))); $PAGE->requires->js_init_call('M.form_filemanager.init', array($fm->options), true, $module); return $str; }
/** * Prepare the file/folder listing. * * @param array $list of files and folders. * @return array of files and folders. * @since Moodle 2.3.3 */ protected static function prepare_list($list) { global $OUTPUT; $foldericon = $OUTPUT->pix_url(file_folder_icon(24))->out(false); // Reset the array keys because non-numeric keys will create an object when converted to JSON. $list = array_values($list); $len = count($list); for ($i = 0; $i < $len; $i++) { if (is_object($list[$i])) { $file = (array) $list[$i]; $converttoobject = true; } else { $file =& $list[$i]; $converttoobject = false; } if (isset($file['size'])) { $file['size'] = (int) $file['size']; $file['size_f'] = display_size($file['size']); } if (isset($file['license']) && get_string_manager()->string_exists($file['license'], 'license')) { $file['license_f'] = get_string($file['license'], 'license'); } if (isset($file['image_width']) && isset($file['image_height'])) { $a = array('width' => $file['image_width'], 'height' => $file['image_height']); $file['dimensions'] = get_string('imagesize', 'repository', (object) $a); } foreach (array('date', 'datemodified', 'datecreated') as $key) { if (!isset($file[$key]) && isset($file['date'])) { $file[$key] = $file['date']; } if (isset($file[$key])) { // must be UNIX timestamp $file[$key] = (int) $file[$key]; if (!$file[$key]) { unset($file[$key]); } else { $file[$key . '_f'] = userdate($file[$key], get_string('strftimedatetime', 'langconfig')); $file[$key . '_f_s'] = userdate($file[$key], get_string('strftimedatetimeshort', 'langconfig')); } } } $isfolder = array_key_exists('children', $file) || isset($file['type']) && $file['type'] == 'folder'; $filename = null; if (isset($file['title'])) { $filename = $file['title']; } else { if (isset($file['fullname'])) { $filename = $file['fullname']; } } if (!isset($file['mimetype']) && !$isfolder && $filename) { $file['mimetype'] = get_mimetype_description(array('filename' => $filename)); } if (!isset($file['icon'])) { if ($isfolder) { $file['icon'] = $foldericon; } else { if ($filename) { $file['icon'] = $OUTPUT->pix_url(file_extension_icon($filename, 24))->out(false); } } } // Recursively loop over children. if (isset($file['children'])) { $file['children'] = self::prepare_list($file['children']); } // Convert the array back to an object. if ($converttoobject) { $list[$i] = (object) $file; } } return $list; }
/** * if return=html, then return a html string. * if return=text, then return a text-only string. * otherwise, print HTML for non-images, and return image HTML * if attachment is an image, $align set its aligment. * * @global object * @global object * @param object $entry * @param object $cm * @param string $type html, txt, empty * @param string $unused This parameter is no longer used * @return string image string or nothing depending on $type param */ function glossary_print_attachments($entry, $cm, $type=NULL, $unused = null) { global $CFG, $DB, $OUTPUT; if (!$context = context_module::instance($cm->id, IGNORE_MISSING)) { return ''; } if ($entry->sourceglossaryid == $cm->instance) { if (!$maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) { return ''; } $filecontext = context_module::instance($maincm->id); } else { $filecontext = $context; } $strattachment = get_string('attachment', 'glossary'); $fs = get_file_storage(); $imagereturn = ''; $output = ''; if ($files = $fs->get_area_files($filecontext->id, 'mod_glossary', 'attachment', $entry->id, "timemodified", false)) { foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('class' => 'icon')); $path = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$context->id.'/mod_glossary/attachment/'.$entry->id.'/'.$filename); if ($type == 'html') { $output .= "<a href=\"$path\">$iconimage</a> "; $output .= "<a href=\"$path\">".s($filename)."</a>"; $output .= "<br />"; } else if ($type == 'text') { $output .= "$strattachment ".s($filename).":\n$path\n"; } else { if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) { // Image attachments don't get printed as links $imagereturn .= "<br /><img src=\"$path\" alt=\"\" />"; } else { $output .= "<a href=\"$path\">$iconimage</a> "; $output .= format_text("<a href=\"$path\">".s($filename)."</a>", FORMAT_HTML, array('context'=>$context)); $output .= '<br />'; } } } } if ($type) { return $output; } else { echo $output; return $imagereturn; } }
/** * Do the actual processing of the uploaded file * @param string $saveas_filename name to give to the file * @param int $maxbytes maximum file size * @param mixed $types optional array of file extensions that are allowed or '*' for all * @param string $savepath optional path to save the file to * @param int $itemid optional the ID for this item within the file area * @param string $license optional the license to use for this file * @param string $author optional the name of the author of this file * @param bool $overwriteexisting optional user has asked to overwrite the existing file * @param int $areamaxbytes maximum size of the file area. * @return object containing details of the file uploaded */ public function process_upload($saveas_filename, $maxbytes, $types = '*', $savepath = '/', $itemid = 0, $license = null, $author = '', $overwriteexisting = false, $areamaxbytes = FILE_AREA_MAX_BYTES_UNLIMITED) { global $USER, $CFG; if (is_array($types) and in_array('*', $types) or $types == '*') { $this->mimetypes = '*'; } else { foreach ($types as $type) { $this->mimetypes[] = mimeinfo('type', $type); } } if ($license == null) { $license = $CFG->sitedefaultlicense; } $record = new stdClass(); $record->filearea = 'draft'; $record->component = 'user'; $record->filepath = $savepath; $record->itemid = $itemid; $record->license = $license; $record->author = $author; $context = context_user::instance($USER->id); $elname = 'repo_upload_file'; $fs = get_file_storage(); $sm = get_string_manager(); if ($record->filepath !== '/') { $record->filepath = file_correct_filepath($record->filepath); } if (!isset($_FILES[$elname])) { throw new moodle_exception('nofile'); } if (!empty($_FILES[$elname]['error'])) { switch ($_FILES[$elname]['error']) { case UPLOAD_ERR_INI_SIZE: throw new moodle_exception('upload_error_ini_size', 'repository_upload'); break; case UPLOAD_ERR_FORM_SIZE: throw new moodle_exception('upload_error_form_size', 'repository_upload'); break; case UPLOAD_ERR_PARTIAL: throw new moodle_exception('upload_error_partial', 'repository_upload'); break; case UPLOAD_ERR_NO_FILE: throw new moodle_exception('upload_error_no_file', 'repository_upload'); break; case UPLOAD_ERR_NO_TMP_DIR: throw new moodle_exception('upload_error_no_tmp_dir', 'repository_upload'); break; case UPLOAD_ERR_CANT_WRITE: throw new moodle_exception('upload_error_cant_write', 'repository_upload'); break; case UPLOAD_ERR_EXTENSION: throw new moodle_exception('upload_error_extension', 'repository_upload'); break; default: throw new moodle_exception('nofile'); } } \core\antivirus\manager::scan_file($_FILES[$elname]['tmp_name'], $_FILES[$elname]['name'], true); // {@link repository::build_source_field()} $sourcefield = $this->get_file_source_info($_FILES[$elname]['name']); $record->source = self::build_source_field($sourcefield); if (empty($saveas_filename)) { $record->filename = clean_param($_FILES[$elname]['name'], PARAM_FILE); } else { $ext = ''; $match = array(); $filename = clean_param($_FILES[$elname]['name'], PARAM_FILE); if (strpos($filename, '.') === false) { // File has no extension at all - do not add a dot. $record->filename = $saveas_filename; } else { if (preg_match('/\\.([a-z0-9]+)$/i', $filename, $match)) { if (isset($match[1])) { $ext = $match[1]; } } $ext = !empty($ext) ? $ext : ''; if (preg_match('#\\.(' . $ext . ')$#i', $saveas_filename)) { // saveas filename contains file extension already $record->filename = $saveas_filename; } else { $record->filename = $saveas_filename . '.' . $ext; } } } // Check the file has some non-null contents - usually an indication that a user has // tried to upload a folder by mistake if (!$this->check_valid_contents($_FILES[$elname]['tmp_name'])) { throw new moodle_exception('upload_error_invalid_file', 'repository_upload', '', $record->filename); } if ($this->mimetypes != '*') { // check filetype $filemimetype = file_storage::mimetype($_FILES[$elname]['tmp_name'], $record->filename); if (!in_array($filemimetype, $this->mimetypes)) { throw new moodle_exception('invalidfiletype', 'repository', '', get_mimetype_description(array('filename' => $_FILES[$elname]['name']))); } } if (empty($record->itemid)) { $record->itemid = 0; } if ($maxbytes !== -1 && filesize($_FILES[$elname]['tmp_name']) > $maxbytes) { $maxbytesdisplay = display_size($maxbytes); throw new file_exception('maxbytesfile', (object) array('file' => $record->filename, 'size' => $maxbytesdisplay)); } if (file_is_draft_area_limit_reached($record->itemid, $areamaxbytes, filesize($_FILES[$elname]['tmp_name']))) { throw new file_exception('maxareabytes'); } $record->contextid = $context->id; $record->userid = $USER->id; if (repository::draftfile_exists($record->itemid, $record->filepath, $record->filename)) { $existingfilename = $record->filename; $unused_filename = repository::get_unused_filename($record->itemid, $record->filepath, $record->filename); $record->filename = $unused_filename; $stored_file = $fs->create_file_from_pathname($record, $_FILES[$elname]['tmp_name']); if ($overwriteexisting) { repository::overwrite_existing_draftfile($record->itemid, $record->filepath, $existingfilename, $record->filepath, $record->filename); $record->filename = $existingfilename; } else { $event = array(); $event['event'] = 'fileexists'; $event['newfile'] = new stdClass(); $event['newfile']->filepath = $record->filepath; $event['newfile']->filename = $unused_filename; $event['newfile']->url = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $unused_filename)->out(false); $event['existingfile'] = new stdClass(); $event['existingfile']->filepath = $record->filepath; $event['existingfile']->filename = $existingfilename; $event['existingfile']->url = moodle_url::make_draftfile_url($record->itemid, $record->filepath, $existingfilename)->out(false); return $event; } } else { $stored_file = $fs->create_file_from_pathname($record, $_FILES[$elname]['tmp_name']); } return array('url' => moodle_url::make_draftfile_url($record->itemid, $record->filepath, $record->filename)->out(false), 'id' => $record->itemid, 'file' => $record->filename); }
function display_browse_field($recordid, $template) { global $CFG, $DB, $OUTPUT; if (!($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid)))) { return ''; } if (empty($content->content)) { return ''; } if (!($file = $this->get_file($recordid, $content))) { return ''; } $name = empty($content->content1) ? $file->get_filename() : $content->content1; $src = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/mod_data/content/' . $content->id . '/' . $file->get_filename()); $width = $this->field->param1 ? ' width = "' . s($this->field->param1) . '" ' : ' '; $height = $this->field->param2 ? ' height = "' . s($this->field->param2) . '" ' : ' '; $str = $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file), 'moodle', array('width' => 16, 'height' => 16)) . ' ' . '<a href="' . $src . '" >' . s($name) . '</a>'; return $str; }