⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 resource.class.php

📁 很棒的在线教学系统
💻 PHP
📖 第 1 页 / 共 3 页
字号:
        return parent::delete_instance($resource);    }    /**     * Display the file resource     *     * Displays a file resource embedded, in a frame, or in a popup.     * Output depends on type of file resource.     *     * @param    CFG     global object     */    function display() {        global $CFG, $THEME, $USER;        require_once($CFG->libdir.'/filelib.php');    /// Set up generic stuff first, including checking for access        parent::display();    /// Set up some shorthand variables        $cm = $this->cm;        $course = $this->course;        $resource = $this->resource;    /// Fetch parameters        $inpopup = optional_param('inpopup', 0, PARAM_BOOL);        $page    = optional_param('page', 0, PARAM_INT);        $frameset= optional_param('frameset', '', PARAM_ALPHA);    /// Init some variables        $errorcode = 0;        $buttontext = 0;        $querystring = '';        $resourcetype = '';        $mimetype = mimeinfo("type", $resource->reference);        $pagetitle = strip_tags($course->shortname.': '.format_string($resource->name));        $formatoptions = new object();        $formatoptions->noclean = true;    /// Cache this per request        static $items;    /// Check for errors        $errorcode = $this->check4errors($resource->reference, $course, $resource);    /// If there are any error, show it instead of the resource page        if ($errorcode) {            if (!has_capability('moodle/course:activityvisibility', get_context_instance(CONTEXT_COURSE, $course->id))) {            /// Resource not available page                $errortext = get_string('resourcenotavailable','resource');            } else {            /// Depending of the error, show different messages and pages                if ($errorcode ==1) {                    $errortext = get_string('invalidfiletype','error', $resource->reference);                } else if ($errorcode == 2) {                    $errortext = get_string('filenotfound','error', $resource->reference);                } else if ($errorcode == 3) {                    $errortext = get_string('packagenotdeplyed','resource');                } else if ($errorcode == 4) {                    $errortext = get_string('packagechanged','resource');                } else if ($errorcode == 5) {                    $errortext = get_string('packagenotdeplyed','resource'); // no button though since from repository.                }            }        /// Display the error and exit            if ($inpopup) {                print_header($pagetitle, $course->fullname.' : '.$resource->name);            } else {                $navigation = build_navigation($this->navlinks, $cm);                print_header($pagetitle, $course->fullname, $navigation, "", "", true,                        update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm));            }            print_simple_box_start('center', '60%');            echo '<p align="center">'.$errortext.'</p>';        /// If errors were 3 or 4 and isteacheredit(), show the deploy button            if (has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $course->id)) && ($errorcode == 3 || $errorcode == 4)) {                $link = 'type/ims/deploy.php';                $options['courseid'] = $course->id;                $options['cmid'] = $cm->id;                $options['file'] = $resource->reference;                $options['sesskey'] = $USER->sesskey;                $options['inpopup'] = $inpopup;                if ($errorcode == 3) {                    $label = get_string ('deploy', 'resource');                } else if ($errorcode == 4) {                     $label = get_string ('redeploy', 'resource');                }                $method='post';            /// Let's go with the button                echo '<center>';                print_single_button($link, $options, $label, $method);                echo '</center>';            }            print_simple_box_end();        /// Close button if inpopup            if ($inpopup) {                close_window_button();            }            print_footer();            exit;        }    /// Load serialized IMS CP index to memory only once.        if (empty($items)) {            if (!$this->isrepository) {                $resourcedir = $CFG->dataroot.'/'.$course->id.'/'.$CFG->moddata.'/resource/'.$resource->id;            }            else {                $resourcedir = $CFG->repository . $resource->reference;            }            if (!$items = ims_load_serialized_file($resourcedir.'/moodle_inx.ser')) {                error (get_string('errorreadingfile', 'error', 'moodle_inx.ser'));            }        }    /// Check whether this is supposed to be a popup, but was called directly        if (empty($frameset) && $resource->popup && !$inpopup) {    /// Make a page and a pop-up window            $navigation = build_navigation($this->navlinks, $cm);            print_header($pagetitle, $course->fullname, $navigation, "", "", true,                    update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm));            echo "\n<script type=\"text/javascript\">";            echo "\n<!--\n";            echo "openpopup('/mod/resource/view.php?inpopup=true&id={$cm->id}','resource{$resource->id}','{$resource->popup}');\n";            echo "\n-->\n";            echo '</script>';            if (trim(strip_tags($resource->summary))) {                print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions), "center");            }            $link = "<a href=\"$CFG->wwwroot/mod/resource/view.php?inpopup=true&amp;id={$cm->id}\" target=\"resource{$resource->id}\" onclick=\"return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', 'resource{$resource->id}','{$resource->popup}');\">".format_string($resource->name,true)."</a>";            echo "<p>&nbsp;</p>";            echo '<p align="center">';            print_string('popupresource', 'resource');            echo '<br />';            print_string('popupresourcelink', 'resource', $link);            echo "</p>";            print_footer($course);            exit;        }    /// No frames or framesets anymore, except iframe. in print_ims, iframe filled.    /// needs callback to this file to display table of contents in the iframe so    /// $frameset = 'toc' leads to output of toc and blank or 'ims' produces the    /// iframe.        if (empty($frameset) || $frameset=='ims') {        /// Conditional argument to pass to IMS JavaScript. Need to be global to retrieve it from our custom javascript! :-(            global $jsarg;            $jsarg = 'false';            if (!empty($this->parameters->navigationmenu)) {                $jsarg = 'true';            }        /// Define $CFG->javascript to use our custom javascript. Save the original one to add it from ours. Global too! :-(            global $standard_javascript;            $standard_javascript = $CFG->javascript;  // Save original javascript file            $CFG->javascript = $CFG->dirroot.'/mod/resource/type/ims/javascript.php';  //Use our custom IMS javascript code        /// moodle header            if ($resource->popup) {                //print_header($pagetitle, $course->fullname.' : '.$resource->name);                print_header();            } else {                $navigation = build_navigation($this->navlinks, $cm);                print_header($pagetitle, $course->fullname, $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "parent"));            }        /// content - this produces everything else            $this->print_ims($cm, $course, $items, $resource, $page);            print_footer('empty');        /// log it.            add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);            exit;        }        if ($frameset == 'toc') {            print_header();            $this->print_toc($items, $resource, $page);            echo '</div></div></body></html>';            exit;        }    }/// Function print_ims prints nearly the whole page. Stupid name subject to change :-)    function print_ims($cm, $course, $items, $resource, $page) {        global $CFG;    /// Set the correct contentframe id based on $this->parameters->navigationmenu        if (!empty($this->parameters->navigationmenu)) {            $contentframe = 'ims-contentframe';        } else {            $contentframe = 'ims-contentframe-no-nav';        }    /// Calculate the file.php correct url        if (!$this->isrepository) {            require_once($CFG->libdir.'/filelib.php');            $fileurl = get_file_url($course->id.'/'.$CFG->moddata.'/resource/'.$resource->id);        }        else {            $fileurl = $CFG->repositorywebroot . $resource->reference;        }    /// Calculate the view.php correct url        $viewurl = "view.php?id={$cm->id}&amp;type={$resource->type}&amp;frameset=toc&amp;page=";    /// Decide what to show (full toc, partial toc or package file)        $fullurl = '';        if (empty($page) && !empty($this->parameters->tableofcontents)) {        /// Full toc contents            $fullurl = $viewurl.$page;        } else {            if (empty($page)) {            /// If no page and no toc, set page 1 unless skipping submenus, in which case fast forward:                $page = 1;                if (!empty($this->parameters->skipsubmenus)) {                    while (empty($items[$page]->href) && !empty($items[$page])) {                        $page++;                    }                }            }            if (empty($items[$page]->href)) {            /// The page hasn't href, then partial toc contents                $fullurl = $viewurl.$page;            } else {            /// The page has href, then its own file contents            /// but considering if it seems to be an external url or a internal one                if (strpos($items[$page]->href, '//') !== false) {                /// External URL                    $fullurl = $items[$page]->href;                } else {                /// Internal URL, use file.php                    $fullurl = $fileurl.'/'.$items[$page]->href;                }            }        }    /// print navigation buttons if needed        if (!empty($this->parameters->navigationbuttons)) {            $this->print_nav($items, $resource, $page);        }        echo '<div id="ims-containerdiv">';    /// adds side navigation bar if needed. must also adjust width of iframe to accomodate        if (!empty($this->parameters->navigationmenu)) {            echo "<div id=\"ims-menudiv\">"; $this->print_navmenu($items, $resource, $page); echo "</div>";        }    /// prints iframe filled with $fullurl        echo "<iframe id=\"".$contentframe."\" name=\"".$contentframe."\" src=\"{$fullurl}\" title=\"".get_string('modulename','resource')."\">Your browser does not support inline frames or is currently configured not to display inline frames. Content can be viewed at {$fullurl}</iframe>"; //Content frame        echo '</div>';    }/// Prints TOC    function print_toc($items, $resource, $page) {        $table = new stdClass;        if (empty($page)) {            $table->head[] = '<b>'.$resource->name.'</b>';        } else {            $table->head[] = '<b>'.$items[$page]->title.'</b>';        }        $table->data[] = array(ims_generate_toc ($items, $resource, $page));        $table->width = '60%';        print_table($table);    }/// Prints side navigation menu. This is just the full TOC with no surround.    function print_navmenu($items, $resource, $page=0) {        echo ims_generate_toc ($items, $resource, 0, $page);    }/// Prints navigation bar at the top of the page.    function print_nav($items, $resource, $page) {        echo '<div class="ims-nav-bar" id="ims-nav-bar">';    /// Prev button        echo ims_get_prev_nav_button ($items, $this, $page);    /// Up button        echo ims_get_up_nav_button ($items, $this, $page);    /// Next button        echo ims_get_next_nav_button ($items, $this, $page);    /// Main TOC button        echo ims_get_toc_nav_button ($items, $this, $page);    /// Footer        echo '</div>';    }    function setup_preprocessing(&$defaults){        if (!isset($defaults['popup'])) {            // use form defaults

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -