/** * 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) { $mimetype = $file->get_mimetype(); $output[] = html_writer::tag('p', html_writer::link($qa->get_response_file_url($file), $this->output->pix_icon(file_mimetype_icon($mimetype), $mimetype, 'moodle', array('class' => 'icon')) . ' ' . s($file->get_filename()))); } return implode($output); }
function print_student_answer($userid, $return = false) { global $CFG, $USER, $OUTPUT; $fs = get_file_storage(); $browser = get_file_browser(); $output = ''; if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "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 . '/assignment_submission/' . $userid . '/' . $filename); $output .= '<a href="' . $path . '" ><img class="icon" src="' . $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)) . '" alt="' . $mimetype . '" />' . s($filename) . '</a><br />'; } } $output = '<div class="files">' . $output . '</div>'; return $output; }
function displaydir($file_info) { global $CFG, $OUTPUT; $children = $file_info->get_children(); $parent_info = $file_info->get_parent(); $strname = get_string('name'); $strsize = get_string('size'); $strmodified = get_string('modified'); $strfolder = get_string('folder'); $strfile = get_string('file'); $strdownload = get_string('download'); $strdelete = get_string('delete'); $straction = get_string('action'); $path = array(); $params = $file_info->get_params_rawencoded(); $params = implode('&', $params); $path[] = $file_info->get_visible_name(); $level = $parent_info; while ($level) { $params = $level->get_params_rawencoded(); $params = implode('&', $params); $path[] = '<a href="index.php?' . $params . '">' . $level->get_visible_name() . '</a>'; $level = $level->get_parent(); } $path = array_reverse($path); $path = implode(' / ', $path); echo $path . ' /'; echo "<div>"; echo "<hr/>"; echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"740\" class=\"files\">"; echo "<tr>"; echo "<th class=\"header\" scope=\"col\"></th>"; echo "<th class=\"header name\" scope=\"col\">{$strname}</th>"; echo "<th class=\"header size\" scope=\"col\">{$strsize}</th>"; echo "<th class=\"header date\" scope=\"col\">{$strmodified}</th>"; echo "<th class=\"header commands\" scope=\"col\">{$straction}</th>"; echo "</tr>\n"; $parentwritable = $file_info->is_writable(); if ($parent_info) { $params = $parent_info->get_params_rawencoded(); $params = implode('&', $params); echo "<tr class=\"folder\">"; print_cell(); print_cell('left', '<a href="index.php?' . $params . '"><img src="' . $OUTPUT->old_icon_url('f/parent') . '" class="icon" alt="" /> ' . get_string('parentfolder') . '</a>', 'name'); print_cell(); print_cell(); print_cell(); echo "</tr>"; } if ($children) { foreach ($children as $child_info) { $filename = $child_info->get_visible_name(); $filesize = $child_info->get_filesize(); $filesize = $filesize ? display_size($filesize) : ''; $filedate = $child_info->get_timemodified(); $filedate = $filedate ? userdate($filedate) : ''; $mimetype = $child_info->get_mimetype(); $params = $child_info->get_params_rawencoded(); $params = implode('&', $params); if ($child_info->is_directory()) { echo "<tr class=\"folder\">"; print_cell(); print_cell("left", "<a href=\"index.php?{$params}\"><img src=\"" . $OUTPUT->old_icon_url('f/folder') . "\" class=\"icon\" alt=\"{$strfolder}\" /> " . s($filename) . "</a>", 'name'); print_cell("right", $filesize, 'size'); print_cell("right", $filedate, 'date'); if ($parentwritable) { print_cell("right", "<a href=\"index.php?{$params}&sesskey=" . sesskey() . "&delete=1\"><img src=\"" . $OUTPUT->old_icon_url('t/delete') . "\" class=\"iconsmall\" alt=\"{$strdelete}\" /></a>", 'command'); } else { print_cell(); } echo "</tr>"; } else { if ($downloadurl = $child_info->get_url(true)) { $downloadurl = " <a href=\"{$downloadurl}\" title=\"" . get_string('downloadfile') . "\"><img src=\"" . $OUTPUT->old_icon_url('t/down') . "\" class=\"iconsmall\" alt=\"{$strdownload}\" /></a>"; } else { $downloadurl = ''; } if ($viewurl = $child_info->get_url()) { $link = html_link::make($viewurl, "display", "<img src=\"" . $OUTPUT->old_icon_url('t/preview') . "\" class=\"iconsmall\" alt=\"{$strfile}\" /> "); $link->add_action(new popup_action('click', $link->url, 'display', array('height' => 480, 'width' => 640))); $viewurl = " " . $OUTPUT->link($link); } else { $viewurl = ''; } echo "<tr class=\"file\">"; print_cell(); print_cell("left", "<img src=\"" . $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)) . "\" class=\"icon\" alt=\"{$strfile}\" /> " . s($filename) . $downloadurl . $viewurl, 'name'); print_cell("right", $filesize, 'size'); print_cell("right", $filedate, 'date'); if ($parentwritable) { print_cell("right", "<a href=\"index.php?{$params}&sesskey=" . sesskey() . "&delete=1\"><img src=\"" . $OUTPUT->old_icon_url('t/delete') . "\" class=\"iconsmall\" alt=\"{$strdelete}\" /></a>", 'command'); } else { print_cell(); } echo "</tr>"; } } } echo "</table>"; echo "</div>"; echo "<hr/>"; }
/** * 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 = get_context_instance(CONTEXT_MODULE, $cm->id)) { return $type !== 'separateimages' ? '' : array('', ''); } $strattachment = get_string('attachment', 'forum'); $fs = get_file_storage(); $imagereturn = ''; $output = ''; $canexport = (has_capability('mod/forum:exportpost', $context) || ($post->userid == $USER->id && has_capability('mod/forum:exportownpost', $context))); require_once($CFG->libdir.'/portfoliolib.php'); if ($files = $fs->get_area_files($context->id, 'mod_forum', 'attachment', $post->id, "timemodified", false)) { $button = new portfolio_add_button(); foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'; $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/locallib.php'); $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/locallib.php'); $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/locallib.php'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= '<br />'; } } } } if ($type !== 'separateimages') { return $output; } else { return array($output, $imagereturn); } }
/** * 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 = ''; $fs = get_file_storage(); $browser = get_file_browser(); $found = false; if ($files = $fs->get_area_files($this->context->id, 'assignment_submission', $userid, "timemodified", false)) { $button = new portfolio_add_button(); 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 . '/assignment_submission/' . $userid . '/' . $filename); $output .= '<a href="' . $path . '" ><img src="' . $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)) . '" class="icon" alt="' . $mimetype . '" />' . s($filename) . '</a>'; if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) { $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id())); $button->set_formats(portfolio_format_from_file($file)); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= '<br />'; } if (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)); $button->set_formats(PORTFOLIO_PORMAT_FILE); $output .= '<br />' . $button->to_html(); } } $output = '<div class="files">' . $output . '</div>'; if ($return) { return $output; } echo $output; }
/** * 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(); $type = mimeinfo_from_type('type', $type); $image = html_writer::empty_tag('img', array('src' => $this->output->pix_url(file_mimetype_icon($type)), 'alt' => $type, 'class' => 'icon')); $linkhtml = html_writer::link($fileurl, $image) . substr($filepath, 1) . html_writer::link($fileurl, $filename); $linktxt = "{$filename} [{$fileurl}]"; if ($format == 'html') { if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) { $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; } }
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 = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())).'" class="icon" alt="'.$file->get_mimetype().'" />'. '<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('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; }
function extend_settings_navigation($node) { global $CFG, $USER, $OUTPUT; // get users submission if there is one $submission = $this->get_submission(); if (is_enrolled($this->context, $USER, 'mod/assignment:submit')) { $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked); } else { $editable = false; } // If the user has submitted something add some related links and data if (isset($submission->data2) AND $submission->data2 == 'submitted') { // Add a view link to the settings nav $link = new moodle_url('/mod/assignment/view.php', array('id'=>$this->cm->id)); $node->add(get_string('viewmysubmission', 'assignment'), $link, navigation_node::TYPE_SETTING); if (!empty($submission->timemodified)) { $submittednode = $node->add(get_string('submitted', 'assignment') . ' ' . userdate($submission->timemodified)); $submittednode->text = preg_replace('#([^,])\s#', '$1 ', $submittednode->text); $submittednode->add_class('note'); if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) { $submittednode->add_class('early'); } else { $submittednode->add_class('late'); } } } // Check if the user has uploaded any files, if so we can add some more stuff to the settings nav if ($submission && is_enrolled($this->context, $USER, 'mod/assignment:submit') && $this->count_user_files($submission->id)) { $fs = get_file_storage(); if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) { if (!$this->drafts_tracked() or !$this->isopen() or $this->is_finalized($submission)) { $filenode = $node->add(get_string('submission', 'assignment')); } else { $filenode = $node->add(get_string('submissiondraft', 'assignment')); } foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $link = file_encode_url($CFG->wwwroot.'/pluginfile.php', '/'.$this->context->id.'/mod_assignment/submission/'.$submission->id.'/'.$filename); $filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_mimetype_icon($mimetype),'')); } } } // Show a notes link if they are enabled if ($this->notes_allowed()) { $link = new moodle_url('/mod/assignment/upload.php', array('id'=>$this->cm->id, 'action'=>'editnotes', 'sesskey'=>sesskey())); $node->add(get_string('notes', 'assignment'), $link); } }
/** * Print the podcast attachment and the media player if appropriate * * @global stdClass $CFG * @global stdClass $DB * @global stdClass $OUTPUT * @param object $episode * @param object $cm * @return string image string or nothing depending on $type param */ function pcast_display_mediafile_link($episode, $cm, $audioonly = false) { global $CFG, $DB, $OUTPUT; if (!($context = get_context_instance(CONTEXT_MODULE, $cm->id))) { return ''; } $fs = get_file_storage(); $imagereturn = ''; if ($files = $fs->get_area_files($context->id, 'mod_pcast', 'episode', $episode->id, "timemodified", false)) { foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url(file_mimetype_icon($mimetype)), 'class' => 'icon', 'alt' => $mimetype)); $path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $context->id . '/mod_pcast/episode/' . $episode->id . '/' . $filename); } } $templink = get_string('nopcastmediafile', 'pcast'); // Make sure there is actually an attachment before trying to render the file link and player if (!empty($filename)) { $out = html_writer::start_tag('div'); $out .= html_writer::tag('a', $iconimage, array('href' => $path)); //Icon $out .= html_writer::tag('a', s($filename), array('href' => $path)); //File $out .= html_writer::end_tag('div'); //Add Media player if enabled if ($CFG->pcast_usemediafilter) { $templink = $out; } else { //Add nolink tags to prevent autolinking. $templink = html_writer::start_tag('div', array('class' => 'nolink')); $templink .= $out; $templink .= html_writer::end_tag('div'); } $templink = format_text($templink, FORMAT_HTML, array('context' => $context)); } return $templink; }
function referentiel_get_manage_archives($contextid, $titre, $appli, $userid_filtre = 0, $instanceid = 0, $ok_portfolio = false, $report = false, $export_format = '') { // retourne la liste des liens vers des fichiers stockes dans le filearea // propose la suppression global $CFG; global $OUTPUT; // Archives older than REFERENTIEL_ARCHIVE_OBSOLETE days will be deleted. $delai_destruction = REFERENTIEL_ARCHIVE_OBSOLETE * 24 * 3600; $date_obsolete = time() - $delai_destruction; $msg = get_string('archive_deleted', 'referentiel', date("Y-m-d H:i:s.", $date_obsolete)); $s = ''; $total_size = 0; $nfile = 0; // fileareas autorisees $filearea = 'archive'; $strauthor = get_string('auteur', 'referentiel'); $strfilename = get_string('filename', 'referentiel'); $strfilesize = get_string('filesize', 'referentiel'); $strtimecreated = get_string('timecreated', 'referentiel'); $strtimemodified = get_string('timemodified', 'referentiel'); $strmimetype = get_string('mimetype', 'referentiel'); $strmenu = get_string('delete'); $strportfolio = get_string('publishporttfolio', 'referentiel'); $strurl = get_string('url'); // publication via potfolio if ($ok_portfolio) { require_once $CFG->libdir . '/portfoliolib.php'; } $fs = get_file_storage(); if ($files = $fs->get_area_files($contextid, 'mod_referentiel', $filearea, 0, "timemodified", false)) { $table = new html_table(); if ($ok_portfolio) { $table->head = array($strauthor, $strfilename, $strfilesize, $strtimecreated, $strtimemodified, $strmimetype, $strmenu, $strportfolio); $table->align = array("right", "center", "left", "left", "left", "center", "center", "center"); } else { $table->head = array($strauthor, $strfilename, $strfilesize, $strtimecreated, $strtimemodified, $strmimetype, $strmenu); $table->align = array("right", "center", "left", "left", "left", "center", "center"); } $ok = false; //drapeau d'affichage foreach ($files as $file) { // print_object($file); $filesize = $file->get_filesize(); $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $filepath = $file->get_filepath(); $iconimage = '<img src="' . $OUTPUT->pix_url(file_mimetype_icon($mimetype)) . '" class="icon" alt="' . $mimetype . '" />'; $userid = 0; $author = ''; $parts = explode('/', $filepath); if (is_array($parts)) { $refrefid = $parts[1]; if (isset($parts[2])) { $userid = trim($parts[2]); // echo "<br />USER:$userid\n"; $author = '#' . $userid . ' ' . referentiel_get_user_info($userid); } } $fullpath = '/' . $contextid . '/mod_referentiel/' . $filearea . '/' . '0' . $filepath . $filename; // echo "<br />FULPATH :: $fullpath \n"; $timecreated = userdate($file->get_timecreated(), "%Y/%m/%d-%H:%M", 99, false); $timemodified = userdate($file->get_timemodified(), "%Y/%m/%d-%H:%M", 99, false); $link = new moodle_url($CFG->wwwroot . '/pluginfile.php' . $fullpath); $url = ' <a href="' . $link . '" target="_blank">' . $iconimage . $filename . '</a><br />' . "\n"; $delete_link = '<input type="checkbox" name="deletefile[]" value="' . $fullpath . '" />' . "\n"; if ($userid && ($userid_filtre == 0 || $userid == $userid_filtre)) { // afficher ce fichier $ok = true; $output_button = ''; // Publish button if ($ok_portfolio) { $params = array('instanceid' => $instanceid, 'attachment' => $file->get_id(), 'report' => $report, 'export_format' => $export_format); // DEBUG /* echo "<br />DEBUG :: lib_archive.php :: 585 :: PARAM PORTFOLIO<br />\n"; print_object($params); echo "<br />\n"; // exit; */ $button = new portfolio_add_button(); // Version anterieure à Moodle 2.4 // $button->set_callback_options('referentiel_portfolio_caller', // $params, '/mod/referentiel/portfolio/mahara/locallib_portfolio.php'); // Version Moodle 2.4 $button->set_callback_options('referentiel_portfolio_caller', $params, 'mod_referentiel'); $button->set_format_by_file($file); // $button->set_formats(array(PORTFOLIO_FORMAT_FILE)); // $output_button = "<a href=\"$path\">$iconimage</a> "; $output_button .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); $table->data[] = array($author, $url, display_size($filesize), $timecreated, $timemodified, $mimetype, $delete_link, $output_button); } else { $table->data[] = array($author, $url, display_size($filesize), $timecreated, $timemodified, $mimetype, $delete_link); } $total_size += $filesize; $nfile++; } } if ($ok) { if ($ok_portfolio) { $table->data[] = array('', get_string('nbfile', 'referentiel', $nfile), get_string('totalsize', 'referentiel', display_size($total_size)), '', '', '', ''); } else { $table->data[] = array('', get_string('nbfile', 'referentiel', $nfile), get_string('totalsize', 'referentiel', display_size($total_size)), '', ''); } echo $OUTPUT->box_start('generalbox boxaligncenter'); echo '<div align="center">' . "\n"; echo '<h3>' . $titre . '</h3>' . "\n"; // message d'information echo '<p><i>' . $msg . '</i></p>' . "\n"; echo '<form method="post" action="' . $appli . '">' . "\n"; echo "\n" . '<input type="hidden" name="sesskey" value="' . sesskey() . '" />' . "\n"; echo '<div align="center">' . "\n"; echo '<input type="button" name="select_all_archive" id="select_tous_enseignants" value="' . get_string('select_all', 'referentiel') . '" onClick="return checkall()" />' . "\n"; // echo ' <input type="button" name="select_not_any_archive" id="select_aucun_enseignant" value="'.get_string('select_not_any', 'referentiel').'" onClick="return uncheckall()" />'."\n"; // echo '<input type="reset" value="'.get_string('corriger', 'referentiel').'" />'."\n"; echo ' <input type="reset" value="' . get_string('select_not_any', 'referentiel') . '" />' . "\n"; echo ' '; echo '<input type="submit" name="save" value="' . get_string('deletefile', 'referentiel') . '" />' . "\n"; echo '<input type="submit" name="cancel" value="' . get_string('quit', 'referentiel') . '" />' . "\n"; echo '</div>' . "\n"; echo html_writer::table($table); echo '<div align="center">' . "\n"; echo '<input type="button" name="select_all_archive" id="select_tous_enseignants" value="' . get_string('select_all', 'referentiel') . '" onClick="return checkall()" />' . "\n"; // echo ' <input type="button" name="select_not_any_archive" id="select_aucun_enseignant" value="'.get_string('select_not_any', 'referentiel').'" onClick="return uncheckall()" />'."\n"; // echo '<input type="reset" value="'.get_string('corriger', 'referentiel').'" />'."\n"; echo ' <input type="reset" value="' . get_string('select_not_any', 'referentiel') . '" />' . "\n"; echo ' '; echo '<input type="submit" name="save" value="' . get_string('deletefile', 'referentiel') . '" />' . "\n"; echo '<input type="submit" name="cancel" value="' . get_string('quit', 'referentiel') . '" />' . "\n"; echo '</div>' . "\n"; echo '</form>' . "\n"; echo '</div>' . "\n"; echo $OUTPUT->box_end(); } } }
public function icon() { global $OUTPUT; return $OUTPUT->pix_icon(file_mimetype_icon($this->row->mimetype), ''); }
/** * Return full message * @return object Message */ public function full() { global $DB, $USER, $OUTPUT, $CFG; require_once $CFG->libdir . '/filelib.php'; $user = $DB->get_record('user', array('id' => $this->sender, 'deleted' => 0)); $message = new stdClass(); $message->id = $this->id; $message->from = fullname($user); $message->sender = $this->sender; $message->subject = format_string($this->subject); if ($this->timesent) { $message->date = userdate($this->timesent); } else { $message->date = userdate($this->timecreated); } $message->body = $this->body; $message->approved = $this->approved; $message->deleted = $this->deleted; $message->destinataries = array(); $message->attachments = array(); $message->labels = array(); if (isset($SESSION->jmailcache->courses[$this->courseid])) { $course = $SESSION->jmailcache->courses[$this->courseid]; } else { $course = $DB->get_record('course', array('id' => $this->courseid), 'id, fullname, shortname', MUST_EXIST); $SESSION->jmailcache->courses[$this->courseid] = $course; } $message->courseid = $course->id; $message->courseshortname = $course->shortname; // Destinataries if ($destinataries = $DB->get_records('block_jmail_sent', array('messageid' => $this->id))) { foreach ($destinataries as $dest) { if ($dest->type == 'bcc' and $this->sender != $USER->id) { continue; } if ($user = $DB->get_record('user', array('id' => $dest->userid, 'deleted' => 0))) { $dest->fullname = fullname($user); $message->destinataries[$dest->type][] = $dest; } } } // Attachments $context = block_jmail_get_context(CONTEXT_COURSE, $this->courseid); // We need the block instance for getting the attachments if ($instance = $DB->get_record('block_instances', array('blockname' => 'jmail', 'parentcontextid' => $context->id))) { $context = block_jmail_get_context(CONTEXT_BLOCK, $instance->id); $fs = get_file_storage(); if ($files = $fs->get_area_files($context->id, 'block_jmail', 'attachment', $this->id, "timemodified", false)) { foreach ($files as $file) { $mimetype = $file->get_mimetype(); $attachment = new stdClass(); $attachment->filename = $file->get_filename(); $attachment->iconimage = '<img src="' . $OUTPUT->pix_url(file_mimetype_icon($mimetype)) . '" class="icon" alt="' . $mimetype . '" />'; $attachment->path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $context->id . '/block_jmail/attachment/' . $this->id . '/' . $attachment->filename); $message->attachments[] = $attachment; } } $message->body = file_rewrite_pluginfile_urls($message->body, 'pluginfile.php', $context->id, 'block_jmail', 'body', $this->id); $message->body = format_text($message->body); } // Labels $sql = "SELECT l.id, l.name\n FROM\n {block_jmail_label} l\n JOIN {block_jmail_m_label} m\n ON l.id = m.labelid\n WHERE\n m.messagesentid = ?\n "; if ($labels = $DB->get_records_sql($sql, array($this->sentid))) { foreach ($labels as $label) { $message->labels[] = $label; } } if ($this->timesent and $this->sender == $USER->id) { $message->labels[] = 'sent'; } if (!$this->timesent and $this->sender == $USER->id) { $message->labels[] = 'draft'; } if ($message->deleted) { $message->labels[] = 'trash'; } if (!$message->approved) { $message->labels[] = 'toapprove'; } if (empty($message->labels)) { $message->labels[] = 'inbox'; } return $message; }
// Print blog posts. ?> <div id="middle-column"> <div class="oublog-post"> <h3><?php print format_string($edit->oldtitle); ?> </h3> <?php $fs = get_file_storage(); if ($files = $fs->get_area_files($context->id, 'mod_oublog', 'edit', $edit->id, "timemodified", false)) { echo '<div class="oublog-post-attachments">'; foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = '<img src="' . $OUTPUT->pix_url(file_mimetype_icon($mimetype)) . '" class="icon" alt="' . $mimetype . '" />'; $path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $context->id . '/mod_oublog/edit/' . $edit->id . '/' . $filename); echo "<a href=\"{$path}\">{$iconimage}</a> "; echo "<a href=\"{$path}\">" . s($filename) . "</a><br />"; } echo '</div>'; } ?> <div class="oublog-post-date"> <?php print oublog_date($edit->timeupdated); ?> </div> <p> <?php $text = file_rewrite_pluginfile_urls($edit->oldmessage, 'pluginfile.php', $context->id, 'mod_oublog', 'message', $edit->postid);
/** * Return the relative icon path for a given file * * Usage: * <code> * // $file - instance of stored_file or file_info * $icon = $OUTPUT->pix_url(file_file_icon($file))->out(); * echo html_writer::empty_tag('img', array('src' => $icon, 'alt' => get_mimetype_description($file))); * </code> * or * <code> * echo $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file)); * </code> * * @param stored_file|file_info|stdClass|array $file (in case of object attributes $file->filename * and $file->mimetype are expected) * @param int $size The size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256 * @return string */ function file_file_icon($file, $size = null) { if (!is_object($file)) { $file = (object) $file; } if (isset($file->filename)) { $filename = $file->filename; } else { if (method_exists($file, 'get_filename')) { $filename = $file->get_filename(); } else { if (method_exists($file, 'get_visible_name')) { $filename = $file->get_visible_name(); } else { $filename = ''; } } } if (isset($file->mimetype)) { $mimetype = $file->mimetype; } else { if (method_exists($file, 'get_mimetype')) { $mimetype = $file->get_mimetype(); } else { $mimetype = ''; } } if ($filename && pathinfo($filename, PATHINFO_EXTENSION) && (!$mimetype || mimeinfo('type', $filename) === $mimetype)) { // files with different extensions sharing the same mimetype (i.e. 'text/plain') may have different icons return file_extension_icon($filename, $size); } else { // if mimetype and extension do not match we assume that mimetype is more correct return file_mimetype_icon($mimetype, $size); } }
/** * Optimised mimetype detection from general URL. * Copied from /mod/url/locallib.php * * @param $equella stdclass * @param $size int * @return string */ function equella_guess_icon($equella, $size = 24) { global $CFG; $icon = null; if (!empty($equella->filename)) { if ('document/unknown' != mimeinfo('type', $equella->filename)) { $icon = 'f/' . mimeinfo('icon' . $size, $equella->filename); } } if (empty($icon)) { $mimetype = $equella->mimetype; $icon = file_mimetype_icon($mimetype, $size); } return $icon; //if (substr_count($fullurl, '/') < 3 or substr($fullurl, -1) === '/') { //// Most probably default directory - index.php, index.html, etc. Return null because //// we want to use the default module icon instead of the HTML file icon. //return null; //} //$icon = file_extension_icon($fullurl, $size); //$htmlicon = file_extension_icon('.htm', $size); //$unknownicon = file_extension_icon('', $size); //// We do not want to return those icon types, the module icon is more appropriate. //if ($icon === $unknownicon || $icon === $htmlicon) { //return null; //} //return $icon; }
/** * Format the compared file for rendering as part of the diff * * @param file object * @param action string * @return output */ public function ouwiki_print_attachment_diff($file, $action = 'none') { global $OUTPUT, $CFG; $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url(file_mimetype_icon($mimetype)), 'alt' => $mimetype, 'class' => 'icon')); if ($action === 'add') { $addedstart = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('diff_added_begins', 'ouwiki'), 'alt' => get_string('addedbegins', 'ouwiki'), 'class' => 'icon')); $addedend = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('diff_added_ends', 'ouwiki'), 'alt' => get_string('addedends', 'ouwiki'), 'class' => 'icon')); $output = html_writer::start_tag('li'); $output .= $addedstart; $output .= html_writer::tag('span', " {$iconimage} {$filename} ", array('class' => 'ouw_added')); $output .= $addedend; $output .= html_writer::end_tag('li'); } else { if ($action === 'delete') { $deletedstart = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('diff_deleted_begins', 'ouwiki'), 'alt' => get_string('deletedbegins', 'ouwiki'), 'class' => 'icon')); $deletedend = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url('diff_deleted_ends', 'ouwiki'), 'alt' => get_string('deletedends', 'ouwiki'), 'class' => 'icon')); $output = html_writer::start_tag('li'); $output .= $deletedstart; $output .= html_writer::tag('span', " {$iconimage} {$filename} ", array('class' => 'ouw_deleted')); $output .= $deletedend; $output .= html_writer::end_tag('li'); } else { // default case; no change in file $output = html_writer::tag('li', "{$iconimage} {$filename}"); } } return $output; }
/** * 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, $PAGE; $mode = optional_param('mode', '', PARAM_ALPHA); $offset = optional_param('offset', 0, PARAM_INT); if (!$userid) { if (!isloggedin()) { return ''; } $userid = $USER->id; } $output = $OUTPUT->box_start('files'); $submission = $this->get_submission($userid); $candelete = $this->can_delete_files($submission); $strdelete = get_string('delete'); if (!$this->is_finalized($submission) and !empty($mode)) { // only during grading $output .= '<strong>' . get_string('draft', 'assignment') . ':</strong><br />'; } if ($this->notes_allowed() and !empty($submission->data1) and !empty($mode)) { // only during grading $npurl = new moodle_url('/mod/assignment/type/uploadpdf/notes.php', array('id' => $this->cm->id, 'userid' => $userid, 'offset' => $offset, 'mode' => 'single')); $output .= '<a href="' . $npurl . '">' . get_string('notes', 'assignment') . '</a><br />'; } if ($this->is_finalized($submission)) { $fs = get_file_storage(); if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submissionfinal', $submission->id, 'timemodified', false)) { foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); if ($mimetype == 'application/pdf' && has_capability('mod/assignment:grade', $this->context)) { $editurl = new moodle_url('/mod/assignment/type/uploadpdf/editcomment.php', array('id' => $this->cm->id, 'userid' => $userid)); $img = '<img class="icon" src="' . $OUTPUT->pix_url(file_mimetype_icon($mimetype)) . '" alt="' . $mimetype . '" />'; $filename = get_string('annotatesubmission', 'assignment_uploadpdf'); $output .= $OUTPUT->action_link($editurl, $img . s($filename), new popup_action('click', $editurl, 'editcomment' . $userid, array('width' => 1000, 'height' => 700))) . ' '; } else { $path = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $this->context->id . '/mod_assignment/submissionfinal/' . $submission->id . '/' . $filename); if ($mimetype == 'application/pdf') { $filename = get_string('yourcompletedsubmission', 'assignment_uploadpdf'); } $output .= '<a href="' . $path . '" ><img src="' . $OUTPUT->pix_url(file_mimetype_icon($mimetype)) . '" class="icon" alt="' . $mimetype . '" />' . s($filename) . '</a>'; $output .= '<br />'; } } } } else { if ($submission) { $renderer = $PAGE->get_renderer('mod_assignment', null); $output .= $renderer->assignment_files($this->context, $submission->id); } } if (has_capability('mod/assignment:grade', $this->context) and $mode != 'grade' and $mode != '') { // we do not want it on view.php page if ($this->can_unfinalize($submission)) { $output .= '<br /><input type="submit" name="unfinalize" value="' . get_string('unfinalize', 'assignment') . '" />'; } } $output .= $OUTPUT->box_end(); if ($return) { return $output; } echo $output; }
/** * 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 $contribution * @param object $cm * @param string $type html, txt, empty * @param string $align left or right * @return string image string or nothing depending on $type param */ function giportfolio_print_attachments($contribution, $cm, $type = null, $align = "right") { global $CFG, $OUTPUT; if (!($context = context_module::instance($cm->id))) { return ''; } $filecontext = $context; $strattachment = get_string('attachment', 'giportfolio'); $fs = get_file_storage(); $output = ''; if ($files = $fs->get_area_files($filecontext->id, 'mod_giportfolio', 'attachment', $contribution->id, "timemodified", false)) { foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = '<img src="' . $OUTPUT->pix_url(file_mimetype_icon($mimetype)) . '" class="icon" alt="' . $mimetype . '" />'; $path = moodle_url::make_pluginfile_url($context->id, 'mod_giportfolio', 'attachment', $contribution->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/jpg'))) { // Image attachments don't get printed as links. $output .= "<a href=\"{$path}\">{$iconimage}</a> "; $output .= format_text("<a href=\"{$path}\">" . s($filename) . "</a>", FORMAT_HTML, array('context' => $context)); $output .= '<br />'; } else { $output .= "<a href=\"{$path}\">{$iconimage}</a> "; $output .= format_text("<a href=\"{$path}\">" . s($filename) . "</a>", FORMAT_HTML, array('context' => $context)); $output .= '<br />'; } } } } } return $output; }
/** * Print issed file certificate link * * @param stdClass $issuecert The issued certificate object * @return string file link url */ function simplecertificate_print_issue_certificate_file(stdClass $issuecert) { global $CFG, $OUTPUT; require_once dirname(__FILE__) . '/locallib.php'; // Trying to cath course module context try { $fs = get_file_storage(); if (!$fs->file_exists_by_hash($issuecert->pathnamehash)) { throw new Exception(); } $file = $fs->get_file_by_hash($issuecert->pathnamehash); $output = '<img src="' . $OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())) . '" height="16" width="16" alt="' . $file->get_mimetype() . '" /> '; $url = new moodle_url('wmsendfile.php'); $url->param('id', $issuecert->id); $url->param('sk', sesskey()); $output .= '<a href="' . $url->out(true) . '" target="_blank" >' . s($file->get_filename()) . '</a>'; } catch (Exception $e) { $output = get_string('filenotfound', 'simplecertificate', ''); } return '<div class="files">' . $output . '<br /> </div>'; }
$filesize = $file->get_filesize(); $filesize = $filesize ? display_size($filesize) : ''; $mimetype = $file->get_mimetype(); if ($file->is_directory()) { if ($subdirs) { $dirname = explode('/', trim($filepath, '/')); $dirname = array_pop($dirname); echo '<div class="folder">'; echo "<a href=\"draftfiles.php?itemid={$itemid}&filepath={$filepath}&subdirs={$subdirs}&maxbytes={$maxbytes}\"><img src=\"" . $OUTPUT->old_icon_url('f/folder') . "\" class=\"icon\" alt=\"{$strfolder}\" /> " . s($dirname) . "</a> "; echo "<a href=\"draftfiles.php?itemid={$itemid}&filepath={$filepath}&delete={$filenameurl}&subdirs={$subdirs}&maxbytes={$maxbytes}\"><img src=\"" . $OUTPUT->old_icon_url('t/delete') . "\" class=\"iconsmall\" alt=\"{$strdelete}\" /></a>"; echo '</div>'; } } else { $viewurl = file_encode_url("{$CFG->wwwroot}/draftfile.php", "/{$contextid}/user_draft/{$itemid}" . $filepath . $filename, false, false); echo '<div class="file">'; echo "<a href=\"{$viewurl}\"><img src=\"" . $OUTPUT->old_icon_url(file_mimetype_icon($mimetype)) . "\" class=\"icon\" alt=\"{$strfile}\" /> " . s($filename) . " ({$filesize})</a> "; echo "<a href=\"draftfiles.php?itemid={$itemid}&filepath={$filepath}&delete={$filenameurl}&subdirs={$subdirs}&maxbytes={$maxbytes}\"><img src=\"" . $OUTPUT->old_icon_url('t/delete') . "\" class=\"iconsmall\" alt=\"{$strdelete}\" /></a>"; echo '</div>'; } } echo '</div>'; if ($maxbytes == 0 or $maxbytes > $totalbytes) { echo '<form enctype="multipart/form-data" method="post" action="draftfiles.php"><div>'; if ($maxbytes) { echo '<input type="hidden" name="MAX_FILE_SIZE" value="' . ($maxbytes - $totalbytes) . '" />'; } echo '<input type="hidden" name="itemid" value="' . $itemid . '" />'; echo '<input type="hidden" name="filepath" value="' . s($filepath) . '" />'; echo '<input type="hidden" name="subdirs" value="' . $subdirs . '" />'; echo '<input type="hidden" name="maxbytes" value="' . $maxbytes . '" />'; echo '<input type="hidden" name="sesskey" value="' . sesskey() . '" />';
function display_browse_field($recordid, $template) { global $CFG, $DB; if (!($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid)))) { return ''; } if (empty($content->content)) { return ''; } $browser = get_file_browser(); 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 . '/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 = '<img src="' . $OUTPUT->old_icon_url(file_mimetype_icon($file->get_mimetype())) . '" height="16" width="16" alt="' . $file->get_mimetype() . '" /> ' . '<a href="' . $src . '" >' . s($name) . '</a>'; return $str; }
/** * Print single user participation for display * * @param object $cm current course module object * @param object $course current course object * @param object $oublog current oublog object * @param int $userid user id of user to view participation for * @param int $groupid optional group id, no group = 0 * @param string $download download type (csv only, default '') * @param int $page flexible_table pagination page * @param array $participation mixed array of user participation values * @param object $context current context * @param bool $viewfullnames flag for global users fullnames capability * @param string groupname group name for display, default '' */ public function render_user_participation_list($cm, $course, $oublog, $participation, $groupid, $download, $page, $context, $viewfullnames, $groupname, $start, $end) { global $DB, $CFG; $user = $participation->user; $fullname = fullname($user, $viewfullnames); // Setup the table. require_once $CFG->dirroot . '/mod/oublog/participation_table.php'; $filename = "{$course->shortname}-" . format_string($oublog->name, true); if ($groupname !== '') { $filename .= '-' . format_string($groupname, true); } $filename .= '-' . format_string($fullname, true); $table = new oublog_user_participation_table($cm->id, $course, $oublog, $user->id, $fullname, $groupname, $groupid, $start, $end); $table->setup($download); $table->is_downloading($download, $filename, get_string('participation', 'oublog')); // Print standard output. $output = ''; $modcontext = context_module::instance($cm->id); if (!$table->is_downloading()) { $output .= html_writer::tag('h2', get_string('postsby', 'oublog', $fullname)); if (!$participation->posts) { $output .= html_writer::tag('p', get_string('nouserposts', 'oublog')); } else { $counter = 0; foreach ($participation->posts as $post) { $row = $counter % 2 ? 'oublog-odd' : 'oublog-even'; $counter++; $output .= html_writer::start_tag('div', array('class' => 'oublog-post ' . $row)); $output .= html_writer::start_tag('div', array('class' => 'oublog-post-top')); // Post attachments. $fs = get_file_storage(); if ($files = $fs->get_area_files($modcontext->id, 'mod_oublog', 'attachment', $post->id, 'timemodified', false)) { $output .= html_writer::start_tag('div', array('class' => 'oublog-post-attachments')); foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $iconimage = html_writer::empty_tag('img', array('src' => $this->output->pix_url(file_mimetype_icon($mimetype)), 'alt' => $mimetype, 'class' => 'icon')); $fileurlbase = $CFG->wwwroot . '/pluginfile.php'; $filepath = '/' . $modcontext->id . '/mod_oublog/attachment/' . $post->id . '/' . $filename; $path = moodle_url::make_file_url($fileurlbase, $filepath); $output .= html_writer::tag('a', $iconimage, array('href' => $path)); $output .= html_writer::tag('a', s($filename), array('href' => $path)); } $output .= html_writer::end_tag('div'); } // Post title and date. if (isset($post->title) && !empty($post->title)) { $viewposturl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id)); $viewpost = html_writer::link($viewposturl, s($post->title)); $output .= html_writer::tag('h3', $viewpost, array('class' => 'oublog-post-title')); $output .= html_writer::start_tag('div', array('class' => 'oublog-post-date')); $output .= oublog_date($post->timeposted); $output .= html_writer::end_tag('div'); } else { $viewposturl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $post->id)); $viewpost = html_writer::link($viewposturl, oublog_date($post->timeposted)); $output .= html_writer::tag('h3', $viewpost, array('class' => 'oublog-post-title')); } $output .= html_writer::end_tag('div'); // Post content. $output .= html_writer::start_tag('div', array('class' => 'oublog-post-content')); $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_oublog', 'message', $post->id); $output .= format_text($post->message, FORMAT_HTML); $output .= html_writer::end_tag('div'); // End display box. $output .= html_writer::end_tag('div'); } } $output .= html_writer::tag('h2', get_string('commentsby', 'oublog', $fullname)); if (!$participation->comments) { $output .= html_writer::tag('p', get_string('nousercomments', 'oublog')); } else { $output .= html_writer::start_tag('div', array('id' => 'oublogcomments', 'class' => 'oublog-post-comments oublogpartcomments')); foreach ($participation->comments as $comment) { $output .= html_writer::start_tag('div', array('class' => 'oublog-comment')); $author = new StdClass(); $author->id = $comment->authorid; $userfields = get_all_user_name_fields(); foreach ($userfields as $field) { $author->{$field} = $comment->{$field}; } $authorurl = new moodle_url('/user/view.php', array('id' => $author->id)); $authorlink = html_writer::link($authorurl, fullname($author, $viewfullnames)); if (isset($comment->posttitle) && !empty($comment->posttitle)) { $viewposturl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $comment->postid)); $viewpostlink = html_writer::link($viewposturl, s($comment->posttitle)); $strparams = array('title' => $viewpostlink, 'author' => $authorlink); $output .= html_writer::tag('h3', get_string('commentonby', 'oublog', $strparams)); } else { $viewposturl = new moodle_url('/mod/oublog/viewpost.php', array('post' => $comment->postid)); $viewpostlink = html_writer::link($viewposturl, oublog_date($comment->postdate)); $strparams = array('title' => $viewpostlink, 'author' => $authorlink); $output .= html_writer::tag('h3', get_string('commentonby', 'oublog', $strparams)); } // Comment title. if (isset($comment->title) && !empty($comment->title)) { $output .= html_writer::tag('h3', s($comment->title), array('class' => 'oublog-comment-title')); } // Comment content and date. $output .= html_writer::start_tag('div', array('class' => 'oublog-comment-date')); $output .= oublog_date($comment->timeposted); $output .= html_writer::end_tag('div'); $output .= html_writer::start_tag('div', array('class' => 'oublog-comment-content')); $comment->message = file_rewrite_pluginfile_urls($comment->message, 'pluginfile.php', $modcontext->id, 'mod_oublog', 'messagecomment', $comment->id); $output .= format_text($comment->message, FORMAT_HTML); $output .= html_writer::end_tag('div'); // End display box. $output .= html_writer::end_tag('div'); } $output .= html_writer::end_tag('div'); } // Only printing the download buttons. echo $table->download_buttons(); // Print the actual output. echo $output; // Grade. if (isset($participation->gradeobj)) { $this->render_user_grade($course, $cm, $oublog, $participation, $groupid); } } else { // Posts. if ($participation->posts) { $table->add_data($table->posts); $table->add_data($table->postsheader); foreach ($participation->posts as $post) { $row = array(); $row[] = userdate($post->timeposted, get_string('strftimedate')); $row[] = userdate($post->timeposted, get_string('strftimetime')); $row[] = isset($post->title) && !empty($post->title) ? $post->title : ''; $post->message = file_rewrite_pluginfile_urls($post->message, 'pluginfile.php', $modcontext->id, 'mod_oublog', 'message', $post->id); $row[] = format_text($post->message, FORMAT_HTML); $fs = get_file_storage(); if ($files = $fs->get_area_files($modcontext->id, 'mod_oublog', 'attachment', $post->id, 'timemodified', false)) { $attachmentstring = ''; foreach ($files as $file) { $filename = $file->get_filename(); $attachmentstring .= ' ' . $filename . ', '; } $attachmentstring = substr($attachmentstring, 0, -2); $row[] = $attachmentstring; } else { $row[] = ''; } $table->add_data($row); } } // Comments. if ($participation->comments) { $table->add_data($table->comments); $table->add_data($table->commentsheader); foreach ($participation->comments as $comment) { $author = new StdClass(); $author->id = $comment->authorid; $userfields = get_all_user_name_fields(); foreach ($userfields as $field) { $author->{$field} = $comment->{$field}; } $authorfullname = fullname($author, $viewfullnames); $row = array(); $row[] = userdate($comment->timeposted, get_string('strftimedate')); $row[] = userdate($comment->timeposted, get_string('strftimetime')); $row[] = isset($comment->title) ? $comment->title : ''; $comment->message = file_rewrite_pluginfile_urls($comment->message, 'pluginfile.php', $modcontext->id, 'mod_oublog', 'messagecomment', $comment->id); $row[] = format_text($comment->message, FORMAT_HTML); $row[] = $authorfullname; $row[] = userdate($comment->postdate, get_string('strftimedate')); $row[] = userdate($comment->postdate, get_string('strftimetime')); $row[] = isset($comment->posttitle) ? $comment->posttitle : ''; $table->add_data($row); } } if (!$participation->posts && !$participation->comments) { $table->add_data(array('')); } $table->finish_output(); } }
/** * 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 $align left or right * @return string image string or nothing depending on $type param */ function glossary_print_attachments($entry, $cm, $type=NULL, $align="left") { global $CFG, $DB, $OUTPUT; if (!$context = get_context_instance(CONTEXT_MODULE, $cm->id)) { return ''; } if ($entry->sourceglossaryid == $cm->instance) { if (!$maincm = get_coursemodule_from_instance('glossary', $entry->glossaryid)) { return ''; } $filecontext = get_context_instance(CONTEXT_MODULE, $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 = '<img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'; $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; } }
/** * Render attachments associated with a message - conversation or reply. * * @global type $OUTPUT * @param array $attachments * @return string */ public function render_attachments(array $attachments) { global $OUTPUT; $html = ''; if ($attachments) { $numattachments = count($attachments); $attachmentheader = $numattachments > 1 ? get_string('numberattachments', 'dialogue', $numattachments) : get_string('attachment', 'dialogue'); $html .= html_writer::start_div('attachments'); $html .= html_writer::tag('h5', $attachmentheader); foreach ($attachments as $file) { $contextid = $file->get_contextid(); $itemid = $file->get_itemid(); $filename = $file->get_filename(); $filesize = $file->get_filesize(); $mimetype = $file->get_mimetype(); $viewurl = new moodle_url('/pluginfile.php/' . $contextid . '/mod_dialogue/attachment/' . $itemid . '/' . $filename); $previewurl = clone $viewurl; $previewurl->param('preview', 'thumb'); $downloadurl = clone $viewurl; $downloadurl->param('forcedownload', 'true'); if ($file->is_valid_image()) { $html .= html_writer::start_tag('table'); $html .= html_writer::start_tag('tbody'); $html .= html_writer::start_tag('tr'); $html .= html_writer::start_tag('td'); $html .= html_writer::link($viewurl, html_writer::empty_tag('img', array('src' => $previewurl->out(), 'class' => 'thumbnail', 'alt' => $mimetype))); $html .= html_writer::end_tag('td'); $html .= html_writer::start_tag('td'); $html .= html_writer::tag('b', $filename); $html .= html_writer::empty_tag('br'); $html .= html_writer::tag('span', display_size($filesize), array('class' => 'meta-filesize')); $html .= html_writer::link($viewurl, html_writer::tag('span', get_string('view'))); $html .= html_writer::link($downloadurl, html_writer::tag('span', get_string('download'))); $html .= html_writer::end_tag('td'); $html .= html_writer::end_tag('tr'); $html .= html_writer::end_tag('tbody'); $html .= html_writer::end_tag('table'); } else { $html .= html_writer::start_tag('table'); $html .= html_writer::start_tag('tbody'); $html .= html_writer::start_tag('tr'); $html .= html_writer::start_tag('td'); $html .= html_writer::link($downloadurl, html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url(file_mimetype_icon($mimetype)), 'class' => 'icon', 'alt' => $mimetype))); $html .= html_writer::end_tag('td'); $html .= html_writer::start_tag('td'); $html .= html_writer::tag('i', $filename); $html .= html_writer::empty_tag('br'); $html .= html_writer::tag('span', display_size($filesize), array('class' => 'meta-filesize')); $html .= html_writer::link($downloadurl, html_writer::tag('span', get_string('download'))); $html .= html_writer::end_tag('td'); $html .= html_writer::end_tag('tr'); $html .= html_writer::end_tag('tbody'); $html .= html_writer::end_tag('table'); } $html .= html_writer::empty_tag('br'); // break up attachments spacing } $html .= html_writer::end_div(); } return $html; }
/** * Return the relative icon path for a given file * * Usage: * <code> * // $file - instance of stored_file or file_info * $icon = $OUTPUT->pix_url(file_file_icon($file))->out(); * echo html_writer::empty_tag('img', array('src' => $icon, 'alt' => get_mimetype_description($file))); * </code> * or * <code> * echo $OUTPUT->pix_icon(file_file_icon($file), get_mimetype_description($file)); * </code> * * @param stored_file|file_info|stdClass|array $file (in case of object attributes $file->filename * and $file->mimetype are expected) * @param int $size The size of the icon. Defaults to 16 can also be 24, 32, 64, 128, 256 * @return string */ function file_file_icon($file, $size = null) { if (!is_object($file)) { $file = (object) $file; } if (isset($file->filename)) { $filename = $file->filename; } else { if (method_exists($file, 'get_filename')) { $filename = $file->get_filename(); } else { if (method_exists($file, 'get_visible_name')) { $filename = $file->get_visible_name(); } else { $filename = ''; } } } if (isset($file->mimetype)) { $mimetype = $file->mimetype; } else { if (method_exists($file, 'get_mimetype')) { $mimetype = $file->get_mimetype(); } else { $mimetype = ''; } } $mimetypes =& get_mimetypes_array(); if ($filename) { $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); if ($extension && !empty($mimetypes[$extension])) { // if file name has known extension, return icon for this extension return file_extension_icon($filename, $size); } } return file_mimetype_icon($mimetype, $size); }
/** * */ protected function display_link($file, $path, $altname, $params = null) { global $OUTPUT; $filename = $file->get_filename(); $displayname = $altname ? $altname : $filename; $fileicon = html_writer::empty_tag('img', array('src' => $OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())), 'alt' => $file->get_mimetype(), 'height' => 16, 'width' => 16)); if (!empty($params['download'])) { list(, $context, , , $contentid) = explode('/', $path); $url = new moodle_url("/mod/dataform/field/file/download.php", array('cid' => $contentid, 'context' => $context, 'file' => $filename)); } else { $url = moodle_url::make_file_url('/pluginfile.php', "{$path}/{$filename}"); } return html_writer::link($url, "{$fileicon} {$displayname}"); }
/** * Produces a list of links to the issued certificates. Used for report. * * @param stdClass $certificate * @param int $userid * @param stdClass $context * @return boolean, true if success printing */ function certificate_print_user_files($certificate, $userid, $context) { global $CFG, $DB, $OUTPUT; $output = ''; $certrecord = certificate_get_latest_issue($certificate->id, $userid); $fs = get_file_storage(); $browser = get_file_browser(); $component = 'mod_certificate'; $filearea = 'issue'; $files = $fs->get_area_files($context, $component, $filearea, $certrecord->id); foreach ($files as $file) { $filename = $file->get_filename(); $mimetype = $file->get_mimetype(); $link = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . $context . '/mod_certificate/issue/' . $certrecord->id . '/' . $filename); $output = '<img src="' . $OUTPUT->pix_url(file_mimetype_icon($file->get_mimetype())) . '" height="16" width="16" alt="' . $file->get_mimetype() . '" /> ' . '<a href="' . $link . '" >' . s($filename) . '</a>'; } $output .= '<br />'; $output = '<div class="files">' . $output . '</div>'; return $output; }
public function file_icon() { if ($file = $this->get_file()) { return file_file_icon($file); } else { if (!empty($this->record->externalurl)) { if ($this->get_youtube_videoid()) { return file_mimetype_icon('video/mpeg'); } return file_mimetype_icon('image/jpeg'); } } return null; }
/** * 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 = ''; $fs = get_file_storage(); $found = false; $submission = $this->get_submission($userid); if (($submission) && $files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) { require_once($CFG->libdir.'/portfoliolib.php'); require_once($CFG->dirroot . '/mod/assignment/locallib.php'); $button = new portfolio_add_button(); 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.'" ><img src="'.$OUTPUT->pix_url(file_mimetype_icon($mimetype)).'" class="icon" alt="'.$mimetype.'" />'.s($filename).'</a>'; if ($this->portfolio_exportable() && has_capability('mod/assignment:exportownsubmission', $this->context)) { $button->set_callback_options('assignment_portfolio_caller', array('id' => $this->cm->id, 'fileid' => $file->get_id()), '/mod/assignment/locallib.php'); $button->set_format_by_file($file); $output .= $button->to_html(PORTFOLIO_ADD_ICON_LINK); } $output .= plagiarism_get_links(array('userid'=>$userid, 'file'=>$file, 'cmid'=>$this->cm->id, 'course'=>$this->course, 'assignment'=>$this->assignment)); $output .= '<br />'; } if (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), '/mod/assignment/locallib.php'); $output .= '<br />' . $button->to_html(); } } $output = '<div class="files">'.$output.'</div>'; if ($return) { return $output; } echo $output; }
/** * 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 */ function blog_print_attachments($blogentry, $return = NULL) { global $CFG; require_once $CFG->libdir . '/filelib.php'; $fs = get_file_storage(); $browser = get_file_browser(); $files = $fs->get_area_files(SYSCONTEXTID, 'blog', $blogentry->id); $imagereturn = ""; $output = ""; $strattachment = get_string("attachment", "forum"); foreach ($files as $file) { if ($file->is_directory()) { continue; } $filename = $file->get_filename(); $ffurl = file_encode_url($CFG->wwwroot . '/pluginfile.php', '/' . SYSCONTEXTID . '/blog/' . $blogentry->id . '/' . $filename); $type = $file->get_mimetype(); $type = mimeinfo_from_type("type", $type); $image = "<img src=\"" . $OUTPUT->old_icon_url(file_mimetype_icon($type)) . "\" class=\"icon\" alt=\"\" />"; if ($return == "html") { $output .= "<a href=\"{$ffurl}\">{$image}</a> "; $output .= "<a href=\"{$ffurl}\">{$filename}</a><br />"; } else { if ($return == "text") { $output .= "{$strattachment} {$filename}:\n{$ffurl}\n"; } else { if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) { // Image attachments don't get printed as links $imagereturn .= "<br /><img src=\"{$ffurl}\" alt=\"\" />"; } else { echo "<a href=\"{$ffurl}\">{$image}</a> "; echo filter_text("<a href=\"{$ffurl}\">{$filename}</a><br />"); } } } } if ($return) { return $output; } return $imagereturn; }