コード例 #1
2
 protected function coursecat_coursebox_content(coursecat_helper $chelper, $course)
 {
     global $CFG;
     if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
         return '';
     }
     if ($course instanceof stdClass) {
         require_once $CFG->libdir . '/coursecatlib.php';
         $course = new course_in_list($course);
     }
     $content = '';
     // Display course overview files.
     $contentimages = $contentfiles = '';
     foreach ($course->get_course_overviewfiles() as $file) {
         $isimage = $file->is_valid_image();
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
         if ($isimage) {
             $contentimages .= html_writer::start_tag('div', array('class' => 'imagebox'));
             $images = html_writer::empty_tag('img', array('src' => $url, 'alt' => 'Course Image ' . $course->fullname, 'class' => 'courseimage'));
             $contentimages .= html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $images);
             $contentimages .= html_writer::end_tag('div');
         } else {
             $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
             $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
             $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
         }
     }
     $content .= $contentimages . $contentfiles;
     // Display course summary.
     if ($course->has_summary()) {
         $content .= $chelper->get_course_formatted_summary($course);
     }
     // Display course contacts. See course_in_list::get_course_contacts().
     if ($course->has_course_contacts()) {
         $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
         foreach ($course->get_course_contacts() as $userid => $coursecontact) {
             $name = $coursecontact['rolename'] . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $userid, 'course' => SITEID)), $coursecontact['username']);
             $content .= html_writer::tag('li', $name);
         }
         $content .= html_writer::end_tag('ul');
         // ...Teachers!.
     }
     return $content;
 }
コード例 #2
0
ファイル: renderer.php プロジェクト: nigeli/moodle
    /**
     * Internal function - creates htmls structure suitable for YUI tree.
     */
    protected function htmllize_tree($tree, $dir) {
        global $CFG;

        if (empty($dir['subdirs']) and empty($dir['files'])) {
            return '';
        }
        $browser = get_file_browser();
        $result = '<ul>';
        foreach ($dir['subdirs'] as $subdir) {
            $image = $this->output->pix_icon(file_folder_icon(24), $subdir['dirname'], 'moodle');
            $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', s($subdir['dirname']), array('class' => 'fp-filename'));
            $filename = html_writer::tag('div', $filename, array('class' => 'fp-filename-icon'));
            $result .= html_writer::tag('li', $filename. $this->htmllize_tree($tree, $subdir));
        }
        foreach ($dir['files'] as $file) {
            $fileinfo = $browser->get_file_info($tree->context, $file->get_component(),
                    $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
            $url = $fileinfo->get_url(true);
            $filename = $file->get_filename();
            if ($imageinfo = $fileinfo->get_imageinfo()) {
                $fileurl = new moodle_url($fileinfo->get_url());
                $image = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $fileinfo->get_timemodified()));
                $image = html_writer::empty_tag('img', array('src' => $image));
            } else {
                $image = $this->output->pix_icon(file_file_icon($file, 24), $filename, 'moodle');
            }
            $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')). html_writer::tag('span', $filename, array('class' => 'fp-filename'));
            $filename = html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'fp-filename-icon'));
            $result .= html_writer::tag('li', $filename);
        }
        $result .= '</ul>';

        return $result;
    }
コード例 #3
0
ファイル: renderer.php プロジェクト: JP-Git/moodle
    /**
     * Internal function - creates htmls structure suitable for YUI tree.
     */
    protected function htmllize_tree($tree, $dir) {
        global $CFG;
        $yuiconfig = array();
        $yuiconfig['type'] = 'html';

        if (empty($dir['subdirs']) and empty($dir['files'])) {
            return '';
        }

        $result = '<ul>';
        foreach ($dir['subdirs'] as $subdir) {
            $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class'=>'icon'));
            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.s($subdir['dirname']).'</div> '.$this->htmllize_tree($tree, $subdir).'</li>';
        }

        foreach ($dir['files'] as $file) {
            $filename = $file->get_filename();
            if ($CFG->enableplagiarism) {
                require_once($CFG->libdir.'/plagiarismlib.php');
                $plagiarsmlinks = plagiarism_get_links(array('userid'=>$file->get_userid(), 'file'=>$file, 'cmid'=>$tree->cm->id, 'course'=>$tree->course));
            } else {
                $plagiarsmlinks = '';
            }
            $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class'=>'icon'));
            $result .= '<li yuiConfig=\''.json_encode($yuiconfig).'\'><div>'.$image.' '.$file->fileurl.' '.$plagiarsmlinks.$file->portfoliobutton.'</div></li>';
        }

        $result .= '</ul>';

        return $result;
    }
コード例 #4
0
ファイル: renderer.php プロジェクト: rama1712/moodle
 /**
  * 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 get_content()
 {
     global $CFG;
     if ($this->content !== null) {
         return $this->content;
     }
     if (empty($this->instance)) {
         $this->content = '';
         return $this->content;
     }
     $this->content = new stdClass();
     $this->content->items = array();
     $this->content->icons = array();
     $this->content->footer = '';
     $this->content->text = '';
     // The user/index.php expect course context, so get one if page has module context.
     $currentcontext = $this->page->context->get_course_context(false);
     if (empty($currentcontext)) {
         return $this->content;
     }
     if ($this->page->course->id == SITEID) {
         $courses = self::get_featured_courses();
         require_once $CFG->libdir . '/coursecatlib.php';
         $chelper = new coursecat_helper();
         foreach ($courses as $course) {
             $course = new course_in_list($course);
             $this->content->text .= '<div class="container-fluid coursebox">';
             $content = '';
             $coursename = $chelper->get_course_formatted_name($course);
             $coursenamelink = html_writer::link(new moodle_url('/course/view.php', array('id' => $course->id)), $coursename, array('class' => $course->visible ? '' : 'dimmed'));
             $content .= html_writer::tag('div', $coursenamelink, array('class' => 'coursename'));
             if ($course->has_summary()) {
                 $content .= html_writer::start_tag('div', array('class' => 'summary'));
                 $content .= $chelper->get_course_formatted_summary($course, array('overflowdiv' => true, 'noclean' => true, 'para' => false));
                 $content .= html_writer::end_tag('div');
             }
             // Display course overview files.
             $contentimages = $contentfiles = '';
             foreach ($course->get_course_overviewfiles() as $file) {
                 $isimage = $file->is_valid_image();
                 $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
                 if ($isimage) {
                     $contentimages .= html_writer::tag('div', html_writer::empty_tag('img', array('src' => $url, 'style' => 'max-height: 150px')), array('class' => 'courseimage'));
                 } else {
                     $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
                     $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
                     $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
                 }
             }
             $content .= $contentimages . $contentfiles;
             $this->content->text .= $content . '</div>';
         }
     }
     return $this->content;
 }
コード例 #6
0
 protected function get_other_values(renderer_base $output)
 {
     $filename = $this->file->get_filename();
     $filenameshort = $filename;
     if (core_text::strlen($filename) > 25) {
         $filenameshort = shorten_text(substr($filename, 0, -4), 21, true, '..');
         $filenameshort .= substr($filename, -4);
     }
     $icon = $this->file->is_directory() ? file_folder_icon() : file_file_icon($this->file);
     $iconurl = $output->pix_url($icon, 'core');
     $url = moodle_url::make_pluginfile_url($this->file->get_contextid(), $this->file->get_component(), $this->file->get_filearea(), $this->file->get_itemid(), $this->file->get_filepath(), $this->file->get_filename(), true);
     return array('filenameshort' => $filenameshort, 'filesizeformatted' => display_size((int) $this->file->get_filesize()), 'icon' => $icon, 'iconurl' => $iconurl->out(false), 'url' => $url->out(false), 'timecreatedformatted' => userdate($this->file->get_timecreated()), 'timemodifiedformatted' => userdate($this->file->get_timemodified()));
 }
コード例 #7
0
ファイル: lib.php プロジェクト: evltuma/moodle
 /**
  * Get file listing
  *
  * @param string $path
  * @param string $path not used by this plugin
  * @return mixed
  */
 public function get_listing($path = '', $page = '')
 {
     global $USER, $OUTPUT;
     $itemid = optional_param('itemid', 0, PARAM_INT);
     $env = optional_param('env', 'filepicker', PARAM_ALPHA);
     $ret = array('dynload' => true, 'nosearch' => true, 'nologin' => true, 'list' => array());
     if (empty($itemid) || $env !== 'editor') {
         return $ret;
     }
     // In the most cases files embedded in textarea do not have subfolders. Do not show path by default.
     $retpath = array(array('name' => get_string('files'), 'path' => ''));
     if (!empty($path)) {
         $pathchunks = preg_split('|/|', trim($path, '/'));
         foreach ($pathchunks as $i => $chunk) {
             $retpath[] = array('name' => $chunk, 'path' => '/' . join('/', array_slice($pathchunks, 0, $i + 1)) . '/');
         }
         $ret['path'] = $retpath;
         // Show path if already inside subfolder.
     }
     $context = context_user::instance($USER->id);
     $fs = get_file_storage();
     $files = $fs->get_directory_files($context->id, 'user', 'draft', $itemid, empty($path) ? '/' : $path, false, true);
     foreach ($files as $file) {
         if ($file->is_directory()) {
             $node = array('title' => basename($file->get_filepath()), 'path' => $file->get_filepath(), 'children' => array(), 'datemodified' => $file->get_timemodified(), 'datecreated' => $file->get_timecreated(), 'icon' => $OUTPUT->pix_url(file_folder_icon(24))->out(false), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false));
             $ret['list'][] = $node;
             $ret['path'] = $retpath;
             // Show path if subfolders exist.
             continue;
         }
         $fileurl = moodle_url::make_draftfile_url($itemid, $file->get_filepath(), $file->get_filename());
         $node = array('title' => $file->get_filename(), 'size' => $file->get_filesize(), 'source' => $fileurl->out(), 'datemodified' => $file->get_timemodified(), 'datecreated' => $file->get_timecreated(), 'author' => $file->get_author(), 'license' => $file->get_license(), 'isref' => $file->is_external_file(), 'icon' => $OUTPUT->pix_url(file_file_icon($file, 24))->out(false), 'thumbnail' => $OUTPUT->pix_url(file_file_icon($file, 90))->out(false));
         if ($file->get_status() == 666) {
             $node['originalmissing'] = true;
         }
         if ($imageinfo = $file->get_imageinfo()) {
             $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $file->get_timemodified()));
             $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified()));
             $node['image_width'] = $imageinfo['width'];
             $node['image_height'] = $imageinfo['height'];
         }
         $ret['list'][] = $node;
     }
     $ret['list'] = array_filter($ret['list'], array($this, 'filter'));
     return $ret;
 }
コード例 #8
0
    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;
    }
コード例 #9
0
ファイル: renderer.php プロジェクト: alanaipe2015/moodle
 /**
  * Internal function - creates htmls structure suitable for YUI tree.
  * @param user_files_tree $tree
  * @param array $dir
  * @return string HTML
  */
 protected function htmllize_tree($tree, $dir)
 {
     global $CFG;
     $yuiconfig = array();
     $yuiconfig['type'] = 'html';
     if (empty($dir['subdirs']) and empty($dir['files'])) {
         return '';
     }
     $result = '<ul>';
     foreach ($dir['subdirs'] as $subdir) {
         $image = $this->output->pix_icon(file_folder_icon(), $subdir['dirname'], 'moodle', array('class' => 'icon'));
         $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'><div>' . $image . ' ' . s($subdir['dirname']) . '</div> ' . $this->htmllize_tree($tree, $subdir) . '</li>';
     }
     foreach ($dir['files'] as $file) {
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $tree->context->id . '/user/private' . $file->get_filepath() . $file->get_filename(), true);
         $filename = $file->get_filename();
         $image = $this->output->pix_icon(file_file_icon($file), $filename, 'moodle', array('class' => 'icon'));
         $result .= '<li yuiConfig=\'' . json_encode($yuiconfig) . '\'><div>' . $image . ' ' . html_writer::link($url, $filename) . '</div></li>';
     }
     $result .= '</ul>';
     return $result;
 }
コード例 #10
0
ファイル: lib.php プロジェクト: saurabh947/MoodleLearning
 /**
  * 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;
 }
コード例 #11
0
ファイル: field.class.php プロジェクト: alanaipe2015/moodle
 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 .= '&nbsp;' . 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>&nbsp;<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;
 }
コード例 #12
0
ファイル: filelib.php プロジェクト: ruddj/moodle
/**
 * Handles the sending of file data to the user's browser, including support for
 * byteranges etc.
 *
 * The $options parameter supports the following keys:
 *  (string|null) preview - send the preview of the file (e.g. "thumb" for a thumbnail)
 *  (string|null) filename - overrides the implicit filename
 *  (bool) dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks.
 *      if this is passed as true, ignore_user_abort is called.  if you don't want your processing to continue on cancel,
 *      you must detect this case when control is returned using connection_aborted. Please not that session is closed
 *      and should not be reopened.
 *
 * @category files
 * @param stored_file $stored_file local file object
 * @param int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime)
 * @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
 * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
 * @param array $options additional options affecting the file serving
 * @return null script execution stopped unless $options['dontdie'] is true
 */
function send_stored_file($stored_file, $lifetime = null, $filter = 0, $forcedownload = false, array $options = array())
{
    global $CFG, $COURSE;
    if (empty($options['filename'])) {
        $filename = null;
    } else {
        $filename = $options['filename'];
    }
    if (empty($options['dontdie'])) {
        $dontdie = false;
    } else {
        $dontdie = true;
    }
    if ($lifetime === 'default' or is_null($lifetime)) {
        $lifetime = $CFG->filelifetime;
    }
    if (!empty($options['preview'])) {
        // replace the file with its preview
        $fs = get_file_storage();
        $preview_file = $fs->get_file_preview($stored_file, $options['preview']);
        if (!$preview_file) {
            // unable to create a preview of the file, send its default mime icon instead
            if ($options['preview'] === 'tinyicon') {
                $size = 24;
            } else {
                if ($options['preview'] === 'thumb') {
                    $size = 90;
                } else {
                    $size = 256;
                }
            }
            $fileicon = file_file_icon($stored_file, $size);
            send_file($CFG->dirroot . '/pix/' . $fileicon . '.png', basename($fileicon) . '.png');
        } else {
            // preview images have fixed cache lifetime and they ignore forced download
            // (they are generated by GD and therefore they are considered reasonably safe).
            $stored_file = $preview_file;
            $lifetime = DAYSECS;
            $filter = 0;
            $forcedownload = false;
        }
    }
    // handle external resource
    if ($stored_file && $stored_file->is_external_file() && !isset($options['sendcachedexternalfile'])) {
        $stored_file->send_file($lifetime, $filter, $forcedownload, $options);
        die;
    }
    if (!$stored_file or $stored_file->is_directory()) {
        // nothing to serve
        if ($dontdie) {
            return;
        }
        die;
    }
    if ($dontdie) {
        ignore_user_abort(true);
    }
    \core\session\manager::write_close();
    // Unlock session during file serving.
    // Use given MIME type if specified, otherwise guess it using mimeinfo.
    // IE, Konqueror and Opera open html file directly in browser from web even when directed to save it to disk :-O
    // only Firefox saves all files locally before opening when content-disposition: attachment stated
    $filename = is_null($filename) ? $stored_file->get_filename() : $filename;
    $isFF = core_useragent::is_firefox();
    // only FF properly tested
    $mimetype = ($forcedownload and !$isFF) ? 'application/x-forcedownload' : ($stored_file->get_mimetype() ? $stored_file->get_mimetype() : mimeinfo('type', $filename));
    // if user is using IE, urlencode the filename so that multibyte file name will show up correctly on popup
    if (core_useragent::is_ie()) {
        $filename = rawurlencode($filename);
    }
    if ($forcedownload) {
        header('Content-Disposition: attachment; filename="' . $filename . '"');
    } else {
        header('Content-Disposition: inline; filename="' . $filename . '"');
    }
    if ($lifetime > 0) {
        $private = '';
        if (isloggedin() and !isguestuser()) {
            $private = ' private,';
        }
        header('Cache-Control:' . $private . ' max-age=' . $lifetime . ', no-transform');
        header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $lifetime) . ' GMT');
        header('Pragma: ');
    } else {
        // Do not cache files in proxies and browsers
        if (strpos($CFG->wwwroot, 'https://') === 0) {
            //https sites - watch out for IE! KB812935 and KB316431
            header('Cache-Control: private, max-age=10, no-transform');
            header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . ' GMT');
            header('Pragma: ');
        } else {
            //normal http - prevent caching at all cost
            header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0, no-transform');
            header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . ' GMT');
            header('Pragma: no-cache');
        }
    }
    if (empty($filter)) {
        // send the contents
        readfile_accel($stored_file, $mimetype, !$dontdie);
    } else {
        // Try to put the file through filters
        if ($mimetype == 'text/html') {
            $options = new stdClass();
            $options->noclean = true;
            $options->nocache = true;
            // temporary workaround for MDL-5136
            $text = $stored_file->get_content();
            $text = file_modify_html_header($text);
            $output = format_text($text, FORMAT_HTML, $options, $COURSE->id);
            readstring_accel($output, $mimetype, false);
        } else {
            if ($mimetype == 'text/plain' and $filter == 1) {
                // only filter text if filter all files is selected
                $options = new stdClass();
                $options->newlines = false;
                $options->noclean = true;
                $text = $stored_file->get_content();
                $output = '<pre>' . format_text($text, FORMAT_MOODLE, $options, $COURSE->id) . '</pre>';
                readstring_accel($output, $mimetype, false);
            } else {
                // Just send it out raw
                readfile_accel($stored_file, $mimetype, !$dontdie);
            }
        }
    }
    if ($dontdie) {
        return;
    }
    die;
    //no more chars to output!!!
}
コード例 #13
0
ファイル: renderer.php プロジェクト: rushi963/moodle
 /**
  * Returns HTML to display course content (summary, course contacts and optionally category name)
  *
  * This method is called from coursecat_coursebox() and may be re-used in AJAX
  *
  * @param coursecat_helper $chelper various display options
  * @param stdClass|course_in_list $course
  * @return string
  */
 protected function coursecat_coursebox_content(coursecat_helper $chelper, $course)
 {
     global $CFG;
     if ($chelper->get_show_courses() < self::COURSECAT_SHOW_COURSES_EXPANDED) {
         return '';
     }
     if ($course instanceof stdClass) {
         require_once $CFG->libdir . '/coursecatlib.php';
         $course = new course_in_list($course);
     }
     $content = '';
     // display course summary
     if ($course->has_summary()) {
         $content .= html_writer::start_tag('div', array('class' => 'summary'));
         $content .= $chelper->get_course_formatted_summary($course, array('overflowdiv' => true, 'noclean' => true, 'para' => false));
         $content .= html_writer::end_tag('div');
         // .summary
     }
     // display course overview files
     $contentimages = $contentfiles = '';
     foreach ($course->get_course_overviewfiles() as $file) {
         $isimage = $file->is_valid_image();
         $url = file_encode_url("{$CFG->wwwroot}/pluginfile.php", '/' . $file->get_contextid() . '/' . $file->get_component() . '/' . $file->get_filearea() . $file->get_filepath() . $file->get_filename(), !$isimage);
         if ($isimage) {
             $contentimages .= html_writer::tag('div', html_writer::empty_tag('img', array('src' => $url)), array('class' => 'courseimage'));
         } else {
             $image = $this->output->pix_icon(file_file_icon($file, 24), $file->get_filename(), 'moodle');
             $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')) . html_writer::tag('span', $file->get_filename(), array('class' => 'fp-filename'));
             $contentfiles .= html_writer::tag('span', html_writer::link($url, $filename), array('class' => 'coursefile fp-filename-icon'));
         }
     }
     $content .= $contentimages . $contentfiles;
     // display course contacts. See course_in_list::get_course_contacts()
     if ($course->has_course_contacts()) {
         $content .= html_writer::start_tag('ul', array('class' => 'teachers'));
         foreach ($course->get_course_contacts() as $userid => $coursecontact) {
             $name = $coursecontact['rolename'] . ': ' . html_writer::link(new moodle_url('/user/view.php', array('id' => $userid, 'course' => SITEID)), $coursecontact['username']);
             $content .= html_writer::tag('li', $name);
         }
         $content .= html_writer::end_tag('ul');
         // .teachers
     }
     // display course category if necessary (for example in search results)
     if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
         require_once $CFG->libdir . '/coursecatlib.php';
         if ($cat = coursecat::get($course->category, IGNORE_MISSING)) {
             $content .= html_writer::start_tag('div', array('class' => 'coursecat'));
             $content .= get_string('category') . ': ' . html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)), $cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
             $content .= html_writer::end_tag('div');
             // .coursecat
         }
     }
     return $content;
 }
コード例 #14
0
    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;
    }
コード例 #15
0
ファイル: repository_ajax.php プロジェクト: nigeli/moodle
                    $event['newfile']->filepath = $saveas_path;
                    $event['newfile']->filename = $unused_filename;
                    $event['newfile']->url = moodle_url::make_draftfile_url($itemid, $saveas_path, $unused_filename)->out();

                    $event['existingfile'] = new stdClass;
                    $event['existingfile']->filepath = $saveas_path;
                    $event['existingfile']->filename = $saveas_filename;
                    $event['existingfile']->url      = moodle_url::make_draftfile_url($itemid, $saveas_path, $saveas_filename)->out();;
                } else {

                    $storedfile = $fs->create_file_from_reference($record, $repo_id, $reference);
                    $event = array(
                        'url'=>moodle_url::make_draftfile_url($storedfile->get_itemid(), $storedfile->get_filepath(), $storedfile->get_filename())->out(),
                        'id'=>$storedfile->get_itemid(),
                        'file'=>$storedfile->get_filename(),
                        'icon' => $OUTPUT->pix_url(file_file_icon($storedfile, 32))->out(),
                    );
                }
                // Repository plugin callback
                // You can cache reository file in this callback
                // or complete other tasks.
                $repo->cache_file_by_reference($reference, $storedfile);
                echo json_encode($event);
                die;
            } else if ($repo->has_moodle_files()) {
                // Some repository plugins (local, user, coursefiles, recent) are hosting moodle
                // internal files, we cannot use get_file method, so we use copy_to_area method

                // If the moodle file is an alias we copy this alias, otherwise we copy the file
                // {@link repository::copy_to_area()}.
                $fileinfo = $repo->copy_to_area($source, $record, $maxbytes);
コード例 #16
0
ファイル: lib.php プロジェクト: EmmanuelYupit/educursos
 /**
  * Converts file_info object to element of repository return list
  *
  * @param file_info $fileinfo
  * @return array
  */
 private function get_node(file_info $fileinfo)
 {
     global $OUTPUT;
     $encodedpath = base64_encode(json_encode($fileinfo->get_params()));
     $node = array('title' => $fileinfo->get_visible_name(), 'datemodified' => $fileinfo->get_timemodified(), 'datecreated' => $fileinfo->get_timecreated());
     if ($fileinfo->is_directory()) {
         $node['path'] = $encodedpath;
         $node['thumbnail'] = $OUTPUT->pix_url(file_folder_icon(90))->out(false);
         $node['children'] = array();
     } else {
         $node['size'] = $fileinfo->get_filesize();
         $node['author'] = $fileinfo->get_author();
         $node['license'] = $fileinfo->get_license();
         $node['isref'] = $fileinfo->is_external_file();
         if ($fileinfo->get_status() == 666) {
             $node['originalmissing'] = true;
         }
         $node['source'] = $encodedpath;
         $node['thumbnail'] = $OUTPUT->pix_url(file_file_icon($fileinfo, 90))->out(false);
         $node['icon'] = $OUTPUT->pix_url(file_file_icon($fileinfo, 24))->out(false);
         if ($imageinfo = $fileinfo->get_imageinfo()) {
             // what a beautiful picture, isn't it
             $fileurl = new moodle_url($fileinfo->get_url());
             $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $fileinfo->get_timemodified()));
             $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $fileinfo->get_timemodified()));
             $node['image_width'] = $imageinfo['width'];
             $node['image_height'] = $imageinfo['height'];
         }
     }
     return $node;
 }
コード例 #17
0
ファイル: lib.php プロジェクト: evltuma/moodle
 /**
  * Get file listing
  *
  * @param string $encodedpath
  * @return mixed
  */
 public function get_listing($encodedpath = '', $page = '')
 {
     global $CFG, $USER, $OUTPUT;
     $ret = array();
     $ret['dynload'] = true;
     $ret['nosearch'] = true;
     $ret['nologin'] = true;
     $list = array();
     $component = 'course';
     $filearea = 'legacy';
     $itemid = 0;
     $browser = get_file_browser();
     if (!empty($encodedpath)) {
         $params = json_decode(base64_decode($encodedpath), true);
         if (is_array($params)) {
             $filepath = is_null($params['filepath']) ? NULL : clean_param($params['filepath'], PARAM_PATH);
             $filename = is_null($params['filename']) ? NULL : clean_param($params['filename'], PARAM_FILE);
             $context = context::instance_by_id(clean_param($params['contextid'], PARAM_INT));
         }
     } else {
         $filename = null;
         $filepath = null;
         list($context, $course, $cm) = get_context_info_array($this->context->id);
         $courseid = is_object($course) ? $course->id : SITEID;
         $context = context_course::instance($courseid);
     }
     if ($fileinfo = $browser->get_file_info($context, $component, $filearea, $itemid, $filepath, $filename)) {
         // build path navigation
         $pathnodes = array();
         $encodedpath = base64_encode(json_encode($fileinfo->get_params()));
         $pathnodes[] = array('name' => $fileinfo->get_visible_name(), 'path' => $encodedpath);
         $level = $fileinfo->get_parent();
         while ($level) {
             $params = $level->get_params();
             $encodedpath = base64_encode(json_encode($params));
             if ($params['contextid'] != $context->id) {
                 break;
             }
             $pathnodes[] = array('name' => $level->get_visible_name(), 'path' => $encodedpath);
             $level = $level->get_parent();
         }
         if (!empty($pathnodes) && is_array($pathnodes)) {
             $pathnodes = array_reverse($pathnodes);
             $ret['path'] = $pathnodes;
         }
         // build file tree
         $children = $fileinfo->get_children();
         foreach ($children as $child) {
             if ($child->is_directory()) {
                 $params = $child->get_params();
                 $subdir_children = $child->get_children();
                 $encodedpath = base64_encode(json_encode($params));
                 $node = array('title' => $child->get_visible_name(), 'datemodified' => $child->get_timemodified(), 'datecreated' => $child->get_timecreated(), 'path' => $encodedpath, 'children' => array(), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false));
                 $list[] = $node;
             } else {
                 $encodedpath = base64_encode(json_encode($child->get_params()));
                 $node = array('title' => $child->get_visible_name(), 'size' => $child->get_filesize(), 'author' => $child->get_author(), 'license' => $child->get_license(), 'datemodified' => $child->get_timemodified(), 'datecreated' => $child->get_timecreated(), 'source' => $encodedpath, 'isref' => $child->is_external_file(), 'thumbnail' => $OUTPUT->pix_url(file_file_icon($child, 90))->out(false));
                 if ($child->get_status() == 666) {
                     $node['originalmissing'] = true;
                 }
                 if ($imageinfo = $child->get_imageinfo()) {
                     $fileurl = new moodle_url($child->get_url());
                     $node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $child->get_timemodified()));
                     $node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $child->get_timemodified()));
                     $node['image_width'] = $imageinfo['width'];
                     $node['image_height'] = $imageinfo['height'];
                 }
                 $list[] = $node;
             }
         }
     } else {
         $list = array();
     }
     $ret['list'] = array_filter($list, array($this, 'filter'));
     return $ret;
 }
コード例 #18
0
ファイル: renderer.php プロジェクト: ncsu-delta/moodle
    /**
     * 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;
        }
    }
コード例 #19
0
ファイル: repository_ajax.php プロジェクト: covex-nn/moodle
         $record->filename = $unused_filename;
         // Create a file copy using unused filename.
         $storedfile = $fs->create_file_from_reference($record, $repo_id, $reference);
         $event = array();
         $event['event'] = 'fileexists';
         $event['newfile'] = new stdClass();
         $event['newfile']->filepath = $saveas_path;
         $event['newfile']->filename = $unused_filename;
         $event['newfile']->url = moodle_url::make_draftfile_url($itemid, $saveas_path, $unused_filename)->out();
         $event['existingfile'] = new stdClass();
         $event['existingfile']->filepath = $saveas_path;
         $event['existingfile']->filename = $saveas_filename;
         $event['existingfile']->url = moodle_url::make_draftfile_url($itemid, $saveas_path, $saveas_filename)->out();
     } else {
         $storedfile = $fs->create_file_from_reference($record, $repo_id, $reference);
         $event = array('url' => moodle_url::make_draftfile_url($storedfile->get_itemid(), $storedfile->get_filepath(), $storedfile->get_filename())->out(), 'id' => $storedfile->get_itemid(), 'file' => $storedfile->get_filename(), 'icon' => $OUTPUT->pix_url(file_file_icon($storedfile, 32))->out());
     }
     // Repository plugin callback
     // You can cache reository file in this callback
     // or complete other tasks.
     $repo->cache_file_by_reference($reference, $storedfile);
     echo json_encode($event);
     die;
 } else {
     if ($repo->has_moodle_files()) {
         // Some repository plugins (local, user, coursefiles, recent) are hosting moodle
         // internal files, we cannot use get_file method, so we use copy_to_area method
         // If the moodle file is an alias we copy this alias, otherwise we copy the file
         // {@link repository::copy_to_area()}.
         $fileinfo = $repo->copy_to_area($reference, $record, $maxbytes, $areamaxbytes);
         echo json_encode($fileinfo);
コード例 #20
0
 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>&nbsp;<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;
 }
コード例 #21
0
ファイル: assignment.class.php プロジェクト: JP-Git/moodle
    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&nbsp;', $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_file_icon($file),''));
                }
            }
        }

        // 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);
        }
    }
コード例 #22
0
 function extend_settings_navigation($node)
 {
     global $CFG, $USER, $OUTPUT;
     // get users submission if there is one
     $submission = $this->get_submission();
     if (is_enrolled($this->context, $USER, 'mod/assignment:submit')) {
         $editable = $this->isopen() && (!$submission || $this->assignment->resubmit || !$submission->timemarked);
     } else {
         $editable = false;
     }
     // If the user has submitted something add some related links and data
     if (isset($submission->numfiles) and $submission->numfiles) {
         // Add a view link to the settings nav
         $link = new moodle_url('/mod/assignment/view.php', array('id' => $this->cm->id));
         $node->add(get_string('viewmysubmission', 'assignment'), $link, navigation_node::TYPE_SETTING);
         if (!empty($submission->timemodified)) {
             $submissionnode = $node->add(get_string('submitted', 'assignment') . ' ' . userdate($submission->timemodified));
             $submissionnode->text = preg_replace('#([^,])\\s#', '$1&nbsp;', $submissionnode->text);
             $submissionnode->add_class('note');
             if ($submission->timemodified <= $this->assignment->timedue || empty($this->assignment->timedue)) {
                 $submissionnode->add_class('early');
             } else {
                 $submissionnode->add_class('late');
             }
         }
     }
     // Check if the user has uploaded any files, if so we can add some more stuff to the settings nav
     if ($submission && is_enrolled($this->context, $USER, 'mod/assignment:submit') && $this->count_user_files($submission->id)) {
         $fs = get_file_storage();
         if ($files = $fs->get_area_files($this->context->id, 'mod_assignment', 'submission', $submission->id, "timemodified", false)) {
             $filenode = $node->add(get_string('submission', 'assignment'));
             foreach ($files as $file) {
                 $filename = $file->get_filename();
                 $mimetype = $file->get_mimetype();
                 $link = moodle_url::make_pluginfile_url($this->context->id, 'mod_assignment', 'submission', $submission->id, $file->get_filepath(), $filename);
                 $filenode->add($filename, $link, navigation_node::TYPE_SETTING, null, null, new pix_icon(file_file_icon($file), ''));
             }
         }
     }
 }
コード例 #23
0
ファイル: lib.php プロジェクト: ruddj/moodle
/**
 * 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;
    }
}
コード例 #24
0
ファイル: filelib.php プロジェクト: IFPBMoodle/moodle
/**
 * Handles the sending of file data to the user's browser, including support for
 * byteranges etc.
 *
 * The $options parameter supports the following keys:
 *  (string|null) preview - send the preview of the file (e.g. "thumb" for a thumbnail)
 *  (string|null) filename - overrides the implicit filename
 *  (bool) dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks.
 *      if this is passed as true, ignore_user_abort is called.  if you don't want your processing to continue on cancel,
 *      you must detect this case when control is returned using connection_aborted. Please not that session is closed
 *      and should not be reopened
 *  (string|null) cacheability - force the cacheability setting of the HTTP response, "private" or "public",
 *      when $lifetime is greater than 0. Cacheability defaults to "private" when logged in as other than guest; otherwise,
 *      defaults to "public".
 *
 * @category files
 * @param stored_file $stored_file local file object
 * @param int $lifetime Number of seconds before the file should expire from caches (null means $CFG->filelifetime)
 * @param int $filter 0 (default)=no filtering, 1=all files, 2=html files only
 * @param bool $forcedownload If true (default false), forces download of file rather than view in browser/plugin
 * @param array $options additional options affecting the file serving
 * @return null script execution stopped unless $options['dontdie'] is true
 */
function send_stored_file($stored_file, $lifetime = null, $filter = 0, $forcedownload = false, array $options = array())
{
    global $CFG, $COURSE;
    if (empty($options['filename'])) {
        $filename = null;
    } else {
        $filename = $options['filename'];
    }
    if (empty($options['dontdie'])) {
        $dontdie = false;
    } else {
        $dontdie = true;
    }
    if ($lifetime === 'default' or is_null($lifetime)) {
        $lifetime = $CFG->filelifetime;
    }
    if (!empty($options['preview'])) {
        // replace the file with its preview
        $fs = get_file_storage();
        $preview_file = $fs->get_file_preview($stored_file, $options['preview']);
        if (!$preview_file) {
            // unable to create a preview of the file, send its default mime icon instead
            if ($options['preview'] === 'tinyicon') {
                $size = 24;
            } else {
                if ($options['preview'] === 'thumb') {
                    $size = 90;
                } else {
                    $size = 256;
                }
            }
            $fileicon = file_file_icon($stored_file, $size);
            send_file($CFG->dirroot . '/pix/' . $fileicon . '.png', basename($fileicon) . '.png');
        } else {
            // preview images have fixed cache lifetime and they ignore forced download
            // (they are generated by GD and therefore they are considered reasonably safe).
            $stored_file = $preview_file;
            $lifetime = DAYSECS;
            $filter = 0;
            $forcedownload = false;
        }
    }
    // handle external resource
    if ($stored_file && $stored_file->is_external_file() && !isset($options['sendcachedexternalfile'])) {
        $stored_file->send_file($lifetime, $filter, $forcedownload, $options);
        die;
    }
    if (!$stored_file or $stored_file->is_directory()) {
        // nothing to serve
        if ($dontdie) {
            return;
        }
        die;
    }
    if ($dontdie) {
        ignore_user_abort(true);
    }
    \core\session\manager::write_close();
    // Unlock session during file serving.
    $filename = is_null($filename) ? $stored_file->get_filename() : $filename;
    // Use given MIME type if specified.
    $mimetype = $stored_file->get_mimetype();
    // Otherwise guess it.
    if (!$mimetype || $mimetype === 'document/unknown') {
        $mimetype = get_mimetype_for_sending($filename);
    }
    // if user is using IE, urlencode the filename so that multibyte file name will show up correctly on popup
    if (core_useragent::is_ie()) {
        $filename = rawurlencode($filename);
    }
    if ($forcedownload) {
        header('Content-Disposition: attachment; filename="' . $filename . '"');
    } else {
        if ($mimetype !== 'application/x-shockwave-flash') {
            // If this is an swf don't pass content-disposition with filename as this makes the flash player treat the file
            // as an upload and enforces security that may prevent the file from being loaded.
            header('Content-Disposition: inline; filename="' . $filename . '"');
        }
    }
    if ($lifetime > 0) {
        $cacheability = ' public,';
        if (!empty($options['cacheability']) && $options['cacheability'] === 'public') {
            // This file must be cache-able by both browsers and proxies.
            $cacheability = ' public,';
        } else {
            if (!empty($options['cacheability']) && $options['cacheability'] === 'private') {
                // This file must be cache-able only by browsers.
                $cacheability = ' private,';
            } else {
                if (isloggedin() and !isguestuser()) {
                    $cacheability = ' private,';
                }
            }
        }
        header('Cache-Control:' . $cacheability . ' max-age=' . $lifetime . ', no-transform');
        header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $lifetime) . ' GMT');
        header('Pragma: ');
    } else {
        // Do not cache files in proxies and browsers
        if (is_https()) {
            // HTTPS sites - watch out for IE! KB812935 and KB316431.
            header('Cache-Control: private, max-age=10, no-transform');
            header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . ' GMT');
            header('Pragma: ');
        } else {
            //normal http - prevent caching at all cost
            header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0, no-transform');
            header('Expires: ' . gmdate('D, d M Y H:i:s', 0) . ' GMT');
            header('Pragma: no-cache');
        }
    }
    // Allow cross-origin requests only for Web Services.
    // This allow to receive requests done by Web Workers or webapps in different domains.
    if (WS_SERVER) {
        header('Access-Control-Allow-Origin: *');
    }
    if (empty($filter)) {
        // send the contents
        readfile_accel($stored_file, $mimetype, !$dontdie);
    } else {
        // Try to put the file through filters
        if ($mimetype == 'text/html' || $mimetype == 'application/xhtml+xml') {
            $options = new stdClass();
            $options->noclean = true;
            $options->nocache = true;
            // temporary workaround for MDL-5136
            $text = $stored_file->get_content();
            $text = file_modify_html_header($text);
            $output = format_text($text, FORMAT_HTML, $options, $COURSE->id);
            readstring_accel($output, $mimetype, false);
        } else {
            if ($mimetype == 'text/plain' and $filter == 1) {
                // only filter text if filter all files is selected
                $options = new stdClass();
                $options->newlines = false;
                $options->noclean = true;
                $text = $stored_file->get_content();
                $output = '<pre>' . format_text($text, FORMAT_MOODLE, $options, $COURSE->id) . '</pre>';
                readstring_accel($output, $mimetype, false);
            } else {
                // Just send it out raw
                readfile_accel($stored_file, $mimetype, !$dontdie);
            }
        }
    }
    if ($dontdie) {
        return;
    }
    die;
    //no more chars to output!!!
}
コード例 #25
0
ファイル: field.class.php プロジェクト: nmicha/moodle
 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)) . '&nbsp;' . '<a href="' . $src . '" >' . s($name) . '</a>';
     return $str;
 }
コード例 #26
0
ファイル: lib.php プロジェクト: Jtgadbois/Pedadida
/**
 * 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);
    }
}
コード例 #27
0
ファイル: renderer.php プロジェクト: dg711/moodle
 /**
  * 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;
     }
 }
コード例 #28
0
         echo ' <a href="' . $home_url->out() . '">' . get_string('makeafolder', 'moodle') . '</a>';
     }
     if (!empty($files->list)) {
         $home_url->param('action', 'downloaddir');
         echo ' ' . html_writer::link($home_url, get_string('downloadfolder', 'repository'), array('target' => '_blank'));
     }
 }
 echo '</div>';
 if (!empty($files->list)) {
     echo '<ul>';
     foreach ($files->list as $file) {
         if ($file->type != 'folder') {
             $drafturl = $file->url;
             // a file
             echo '<li>';
             echo $OUTPUT->pix_icon(file_file_icon($file), '', 'moodle', array('class' => 'iconsmall'));
             echo html_writer::link($drafturl, $file->filename);
             $home_url->param('filename', $file->filename);
             $home_url->param('draftpath', $file->filepath);
             $home_url->param('action', 'deletedraft');
             echo ' [<a href="' . $home_url->out() . '" class="fm-operation">' . get_string('delete') . '</a>]';
             $home_url->param('action', 'movefile');
             echo ' [<a href="' . $home_url->out() . '" class="fm-operation">' . get_string('move') . '</a>]';
             $home_url->param('action', 'renameform');
             echo ' [<a href="' . $home_url->out() . '" class="fm-operation">' . get_string('rename') . '</a>]';
             if (file_extension_in_typegroup($file->filename, 'archive', true)) {
                 $home_url->param('action', 'unzip');
                 $home_url->param('draftpath', $file->filepath);
                 echo ' [<a href="' . $home_url->out() . '" class="fm-operation">' . get_string('unzip') . '</a>]';
             }
             echo '</li>';
コード例 #29
0
ファイル: lib.php プロジェクト: isuruAb/moodle
 /**
  * Builds a tree of files This function is then called recursively.
  *
  * @static
  * @todo take $search into account, and respect a threshold for dynamic loading
  * @param file_info $fileinfo an object returned by file_browser::get_file_info()
  * @param string $search searched string
  * @param bool $dynamicmode no recursive call is done when in dynamic mode
  * @param array $list the array containing the files under the passed $fileinfo
  * @return int the number of files found
  */
 public static function build_tree($fileinfo, $search, $dynamicmode, &$list)
 {
     global $CFG, $OUTPUT;
     $filecount = 0;
     $children = $fileinfo->get_children();
     foreach ($children as $child) {
         $filename = $child->get_visible_name();
         $filesize = $child->get_filesize();
         $filesize = $filesize ? display_size($filesize) : '';
         $filedate = $child->get_timemodified();
         $filedate = $filedate ? userdate($filedate) : '';
         $filetype = $child->get_mimetype();
         if ($child->is_directory()) {
             $path = array();
             $level = $child->get_parent();
             while ($level) {
                 $params = $level->get_params();
                 $path[] = array($params['filepath'], $level->get_visible_name());
                 $level = $level->get_parent();
             }
             $tmp = array('title' => $child->get_visible_name(), 'size' => 0, 'date' => $filedate, 'path' => array_reverse($path), 'thumbnail' => $OUTPUT->pix_url(file_folder_icon(90))->out(false));
             //if ($dynamicmode && $child->is_writable()) {
             //    $tmp['children'] = array();
             //} else {
             // if folder name matches search, we send back all files contained.
             $_search = $search;
             if ($search && stristr($tmp['title'], $search) !== false) {
                 $_search = false;
             }
             $tmp['children'] = array();
             $_filecount = repository::build_tree($child, $_search, $dynamicmode, $tmp['children']);
             if ($search && $_filecount) {
                 $tmp['expanded'] = 1;
             }
             //}
             if (!$search || $_filecount || stristr($tmp['title'], $search) !== false) {
                 $filecount += $_filecount;
                 $list[] = $tmp;
             }
         } else {
             // not a directory
             // skip the file, if we're in search mode and it's not a match
             if ($search && stristr($filename, $search) === false) {
                 continue;
             }
             $params = $child->get_params();
             $source = serialize(array($params['contextid'], $params['component'], $params['filearea'], $params['itemid'], $params['filepath'], $params['filename']));
             $list[] = array('title' => $filename, 'size' => $filesize, 'date' => $filedate, 'source' => base64_encode($source), 'icon' => $OUTPUT->pix_url(file_file_icon($child, 24))->out(false), 'thumbnail' => $OUTPUT->pix_url(file_file_icon($child, 90))->out(false));
             $filecount++;
         }
     }
     return $filecount;
 }
コード例 #30
-1
ファイル: renderer.php プロジェクト: JP-Git/moodle
    /**
     * Internal function - creates htmls structure suitable for YUI tree.
     */
    protected function htmllize_tree($tree, $dir) {
        global $CFG;

        if (empty($dir['subdirs']) and empty($dir['files'])) {
            return '';
        }
        $result = '<ul>';
        foreach ($dir['subdirs'] as $subdir) {
            $image = $this->output->pix_icon(file_folder_icon(24), $subdir['dirname'], 'moodle');
            $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')).
                    html_writer::tag('span', s($subdir['dirname']), array('class' => 'fp-filename'));
            $filename = html_writer::tag('div', $filename, array('class' => 'fp-filename-icon'));
            $result .= html_writer::tag('li', $filename. $this->htmllize_tree($tree, $subdir));
        }
        foreach ($dir['files'] as $file) {
            $filename = $file->get_filename();
            $url = moodle_url::make_pluginfile_url($file->get_contextid(), $file->get_component(),
                    $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $filename, false);
            if (file_extension_in_typegroup($filename, 'web_image')) {
                $image = $url->out(false, array('preview' => 'tinyicon', 'oid' => $file->get_timemodified()));
                $image = html_writer::empty_tag('img', array('src' => $image));
            } else {
                $image = $this->output->pix_icon(file_file_icon($file, 24), $filename, 'moodle');
            }
            $filename = html_writer::tag('span', $image, array('class' => 'fp-icon')).
                    html_writer::tag('span', $filename, array('class' => 'fp-filename'));
            $filename = html_writer::tag('span',
                    html_writer::link($url->out(false, array('forcedownload' => 1)), $filename),
                    array('class' => 'fp-filename-icon'));
            $result .= html_writer::tag('li', $filename);
        }
        $result .= '</ul>';

        return $result;
    }