Esempio n. 1
0
/**
 * This function returns the URL for the RSS XML file.
 *
 * @param int    $contextid      the course id
 * @param int    $userid         the current user id
 * @param string $componentname  the name of the current component. For example "forum"
 * @param string $additionalargs For modules, module instance id
 * @return string the url of the RSS feed
 */
function rss_get_url($contextid, $userid, $componentname, $additionalargs)
{
    global $CFG;
    require_once $CFG->libdir . '/filelib.php';
    $usertoken = rss_get_token($userid);
    return get_file_url($contextid . '/' . $usertoken . '/' . $componentname . '/' . $additionalargs . '/rss.xml', null, 'rssfile');
}
Esempio n. 2
0
function picture_header()
{
    if (project() && project()->type() == 'picture') {
        echo theme()->js(array('src' => get_file_url('ex/plugin/picture/jquery.colorbox-min.js'))), "\n";
        echo theme()->css(array('href' => get_file_url('ex/plugin/picture/colorbox.css'))), "\n";
    }
}
Esempio n. 3
0
/**
 * 增加后台编辑器所需的引用文件
 */
function page_edit_header_out()
{
    theme()->header_add(theme()->css(array('href' => get_file_url("ex/kindeditor/themes/default/default.css"))));
    theme()->header_add(theme()->js(array('src' => get_file_url("ex/kindeditor/kindeditor-min.js"))));
    theme()->header_add(theme()->js(array('src' => get_file_url("ex/kindeditor/lang/zh_CN.js"))));
    theme()->header_add(theme()->js(array('src' => get_file_url("js/jquery.form.js"))));
}
Esempio n. 4
0
function blog_rss_print_link($filtertype, $filterselect, $tagid = 0, $tooltiptext = '')
{
    global $CFG, $USER;
    if (empty($USER->id)) {
        $userid = 1;
    } else {
        $userid = $USER->id;
    }
    switch ($filtertype) {
        case 'site':
            $path = SITEID . '/' . $userid . '/blog/site/' . SITEID;
            break;
        case 'course':
            $path = $filterselect . '/' . $userid . '/blog/course/' . $filterselect;
            break;
        case 'group':
            $path = SITEID . '/' . $userid . '/blog/group/' . $filterselect;
            break;
        case 'user':
            $path = SITEID . '/' . $userid . '/blog/user/' . $filterselect;
            break;
    }
    if ($tagid) {
        $path .= '/' . $tagid;
    }
    $path .= '/rss.xml';
    $rsspix = $CFG->pixpath . '/i/rss.gif';
    require_once $CFG->libdir . '/filelib.php';
    $path = get_file_url($path, null, 'rssfile');
    print '<div class="mdl-right"><a href="' . $path . '"><img src="' . $rsspix . '" title="' . strip_tags($tooltiptext) . '" alt="' . get_string('rss') . '" /></a></div>';
}
Esempio n. 5
0
/**
 * 生成网站地图信息
 */
function sitemap_create($out_message = false)
{
    require_once __DIR__ . "/sitemap.php";
    $sitemap = new \Plugin\SiteMap($out_message);
    $sitemap->msg("准备生成网站地图,最大10M,最多5000条<br />当前内存消耗:<span class='text-danger'>" . sitemap_size(memory_get_usage()) . "</span>");
    $sitemap->create();
    $file = _BasePath_ . "/sitemap.xml";
    $sitemap->write_file($file);
    $sitemap->msg("生成文件大小: <span class='text-danger'>" . sitemap_size(filesize($file))) . "</span>";
    $sitemap->msg("生成记录: <span class='text-danger'>" . $sitemap->count() . "</span> 条");
    $sitemap->msg("地图地址: <a rel='external' class='text-warning' href='" . get_file_url('sitemap.xml') . "'>" . get_file_url('sitemap.xml') . "</a>");
    $sitemap->msg("生成地图成功<br />当前内存消耗:<span class='text-danger'>" . sitemap_size(memory_get_usage()) . "</span>");
}
Esempio n. 6
0
 function print_student_answer($userid, $return = false)
 {
     global $CFG, $USER;
     $filearea = $this->file_area_name($userid);
     $output = '';
     if ($basedir = $this->file_area($userid)) {
         if ($files = get_directory_list($basedir)) {
             require_once $CFG->libdir . '/filelib.php';
             foreach ($files as $key => $file) {
                 $icon = mimeinfo('icon', $file);
                 $ffurl = get_file_url("{$filearea}/{$file}");
                 //died right here
                 //require_once($ffurl);
                 $output = '<img align="middle" src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" />' . '<a href="' . $ffurl . '" >' . $file . '</a><br />';
             }
         }
     }
     $output = '<div class="files">' . $output . '</div>';
     return $output;
 }
 /**
  * Provide NULL and legacy file.php uses decoding
  */
 public function process_cdata($cdata)
 {
     global $CFG;
     if ($cdata === '$@NULL@$') {
         // Some cases we know we can skip complete processing
         return null;
     } else {
         if ($cdata === '') {
             return '';
         } else {
             if (is_numeric($cdata)) {
                 return $cdata;
             } else {
                 if (strlen($cdata) < 32) {
                     // Impossible to have one link in 32cc
                     return $cdata;
                     // (http://10.0.0.1/file.php/1/1.jpg, http://10.0.0.1/mod/url/view.php?id=)
                 } else {
                     if (strpos($cdata, '$@FILEPHP@$') === false) {
                         // No $@FILEPHP@$, nothing to convert
                         return $cdata;
                     }
                 }
             }
         }
     }
     // Decode file.php calls
     $search = array("\$@FILEPHP@\$");
     $replace = array(get_file_url($this->courseid));
     $result = str_replace($search, $replace, $cdata);
     // Now $@SLASH@$ and $@FORCEDOWNLOAD@$ MDL-18799
     $search = array('$@SLASH@$', '$@FORCEDOWNLOAD@$');
     if ($CFG->slasharguments) {
         $replace = array('/', '?forcedownload=1');
     } else {
         $replace = array('%2F', '&amp;forcedownload=1');
     }
     return str_replace($search, $replace, $result);
 }
Esempio n. 8
0
function get_rss_enclosure($file_name, $image_type, $cat_id)
{
    if (!get_file_path($file_name, $image_type, $cat_id, 0, 0)) {
        return array();
    }
    $file = get_file_path($file_name, $image_type, $cat_id, 0, 1);
    $url = get_file_url($file_name, $image_type, $cat_id);
    return array('url' => $url, 'length' => @filesize($file), 'type' => get_mime_content_type($file));
}
Esempio n. 9
0
<?php

include '../config.php';
//require_login();
/// Remove the following three lines if you want everyone to access it
//require_capability('moodle/site:config', get_context_instance(CONTEXT_SYSTEM));
if (!($users = get_records("user", "picture", "1", "lastaccess DESC", "id,firstname,lastname"))) {
    error("no users!");
}
$title = get_string("users");
print_header($title, $title, build_navigation(array(array('name' => $title, 'link' => null, 'type' => 'misc'))));
foreach ($users as $user) {
    $fullname = fullname($user);
    echo "<a href=\"{$CFG->wwwroot}/user/view.php?id={$user->id}&amp;course=1\" " . "title=\"{$fullname}\">";
    require_once $CFG->libdir . '/filelib.php';
    $userpictureurl = get_file_url($user->id . '/f1.jpg', null, 'user');
    echo '<img src="' . $userpictureurl . '"' . ' style="border:0px; width:100px; height:100px" alt="' . $fullname . '" />';
    echo "</a> \n";
}
print_footer();
Esempio n. 10
0
function blog_print_attachments($blogentry, $return = NULL)
{
    // 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
    global $CFG;
    $filearea = blog_file_area_name($blogentry);
    $imagereturn = "";
    $output = "";
    if ($basedir = blog_file_area($blogentry)) {
        if ($files = get_directory_list($basedir)) {
            $strattachment = get_string("attachment", "forum");
            foreach ($files as $file) {
                include_once $CFG->libdir . '/filelib.php';
                $icon = mimeinfo("icon", $file);
                $type = mimeinfo("type", $file);
                $ffurl = get_file_url("{$filearea}/{$file}");
                $image = "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"\" />";
                if ($return == "html") {
                    $output .= "<a href=\"{$ffurl}\">{$image}</a> ";
                    $output .= "<a href=\"{$ffurl}\">{$file}</a><br />";
                } else {
                    if ($return == "text") {
                        $output .= "{$strattachment} {$file}:\n{$ffurl}\n";
                    } else {
                        if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
                            // Image attachments don't get printed as links
                            $imagereturn .= "<br /><img src=\"{$ffurl}\" alt=\"\" />";
                        } else {
                            echo "<a href=\"{$ffurl}\">{$image}</a> ";
                            echo filter_text("<a href=\"{$ffurl}\">{$file}</a><br />");
                        }
                    }
                }
            }
        }
    }
    if ($return) {
        return $output;
    }
    return $imagereturn;
}
Esempio n. 11
0
 /**
  * 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;
     /// 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;
     $this->set_parameters();
     // set the parameters array
     ///////////////////////////////////////////////
     /// Possible display modes are:
     /// File displayed embedded in a normal page
     /// File displayed in a popup window
     /// File displayed embedded in a popup window
     /// File not displayed at all, but downloaded
     /// First, find out what sort of file we are dealing with.
     require_once $CFG->libdir . '/filelib.php';
     $querystring = '';
     $resourcetype = '';
     $embedded = false;
     $mimetype = mimeinfo("type", $resource->reference);
     $pagetitle = strip_tags($course->shortname . ': ' . format_string($resource->name));
     $formatoptions = new object();
     $formatoptions->noclean = true;
     if ($resource->options != "forcedownload") {
         // TODO nicolasconnault 14-03-07: This option should be renamed "embed"
         if (in_array($mimetype, array('image/gif', 'image/jpeg', 'image/png'))) {
             // It's an image
             $resourcetype = "image";
             $embedded = true;
         } else {
             if ($mimetype == "audio/mp3") {
                 // It's an MP3 audio file
                 $resourcetype = "mp3";
                 $embedded = true;
             } else {
                 if ($mimetype == "video/x-flv") {
                     // It's a Flash video file
                     $resourcetype = "flv";
                     $embedded = true;
                 } else {
                     if (substr($mimetype, 0, 10) == "video/x-ms") {
                         // It's a Media Player file
                         $resourcetype = "mediaplayer";
                         $embedded = true;
                     } else {
                         if ($mimetype == "video/quicktime") {
                             // It's a Quicktime file
                             $resourcetype = "quicktime";
                             $embedded = true;
                         } else {
                             if ($mimetype == "application/x-shockwave-flash") {
                                 // It's a Flash file
                                 $resourcetype = "flash";
                                 $embedded = true;
                             } else {
                                 if ($mimetype == "video/mpeg") {
                                     // It's a Mpeg file
                                     $resourcetype = "mpeg";
                                     $embedded = true;
                                 } else {
                                     if ($mimetype == "text/html") {
                                         // It's a web page
                                         $resourcetype = "html";
                                     } else {
                                         if ($mimetype == "application/zip") {
                                             // It's a zip archive
                                             $resourcetype = "zip";
                                             $embedded = true;
                                         } else {
                                             if ($mimetype == 'application/pdf' || $mimetype == 'application/x-pdf') {
                                                 $resourcetype = "pdf";
                                                 //no need embedded, html file types behave like unknown file type
                                             } else {
                                                 if ($mimetype == "audio/x-pn-realaudio-plugin") {
                                                     // It's a realmedia file
                                                     $resourcetype = "rm";
                                                     $embedded = true;
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     $isteamspeak = stripos($resource->reference, 'teamspeak://') === 0;
     /// Form the parse string
     $querys = array();
     if (!empty($resource->alltext)) {
         $parray = explode(',', $resource->alltext);
         foreach ($parray as $fieldstring) {
             list($moodleparam, $urlname) = explode('=', $fieldstring);
             $value = urlencode($this->parameters[$moodleparam]['value']);
             $querys[urlencode($urlname)] = $value;
             $querysbits[] = urlencode($urlname) . '=' . $value;
         }
         if ($isteamspeak) {
             $querystring = implode('?', $querysbits);
         } else {
             $querystring = implode('&amp;', $querysbits);
         }
     }
     /// Set up some variables
     $inpopup = optional_param('inpopup', 0, PARAM_BOOL);
     if (resource_is_url($resource->reference)) {
         $fullurl = $resource->reference;
         if (!empty($querystring)) {
             $urlpieces = parse_url($resource->reference);
             if (empty($urlpieces['query']) or $isteamspeak) {
                 $fullurl .= '?' . $querystring;
             } else {
                 $fullurl .= '&amp;' . $querystring;
             }
         }
     } else {
         if ($CFG->resource_allowlocalfiles and strpos($resource->reference, RESOURCE_LOCALPATH) === 0) {
             // Localpath
             $localpath = get_user_preferences('resource_localpath', 'D:');
             $relativeurl = str_replace(RESOURCE_LOCALPATH, $localpath, $resource->reference);
             if ($querystring) {
                 $relativeurl .= '?' . $querystring;
             }
             $relativeurl = str_replace('\\', '/', $relativeurl);
             $relativeurl = str_replace(' ', '%20', $relativeurl);
             $fullurl = 'file:///' . htmlentities($relativeurl);
             $localpath = true;
         } else {
             // Normal uploaded file
             $forcedownloadsep = '?';
             if ($resource->options == 'forcedownload') {
                 $querys['forcedownload'] = '1';
             }
             $fullurl = get_file_url($course->id . '/' . $resource->reference, $querys);
         }
     }
     /// Print a notice and redirect if we are trying to access a file on a local file system
     /// and the config setting has been disabled
     if (!$CFG->resource_allowlocalfiles and strpos($resource->reference, RESOURCE_LOCALPATH) === 0) {
         if ($inpopup) {
             print_header($pagetitle, $course->fullname);
         } 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));
         }
         notify(get_string('notallowedlocalfileaccess', 'resource', ''));
         if ($inpopup) {
             close_window_button();
         }
         print_footer('none');
         die;
     }
     /// Check whether this is supposed to be a popup, but was called directly
     if ($resource->popup and !$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}\" " . "onclick=\"this.target='resource{$resource->id}'; return openpopup('/mod/resource/view.php?inpopup=true&amp;id={$cm->id}', " . "'resource{$resource->id}','{$resource->popup}');\">" . format_string($resource->name, true) . "</a>";
         echo '<div class="popupnotice">';
         print_string('popupresource', 'resource');
         echo '<br />';
         print_string('popupresourcelink', 'resource', $link);
         echo '</div>';
         print_footer($course);
         exit;
     }
     /// Now check whether we need to display a frameset
     $frameset = optional_param('frameset', '', PARAM_ALPHA);
     if (empty($frameset) and !$embedded and !$inpopup and $resource->options == "frame" || $resource->options == "objectframe" and empty($USER->screenreader)) {
         /// display the resource into a object tag
         if ($resource->options == "objectframe") {
             /// Yahoo javascript libaries for updating embedded object size
             require_js(array('yui_utilities'));
             require_js(array('yui_container'));
             require_js(array('yui_dom-event'));
             require_js(array('yui_dom'));
             /// Moodle Header and navigation bar
             $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"));
             $options = new object();
             $options->para = false;
             if (!empty($localpath)) {
                 // Show some help
                 echo '<div class="mdl-right helplink">';
                 link_to_popup_window('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp', 'resource'), 400, 500, get_string('localfilehelp', 'resource'));
                 echo '</div>';
             }
             echo '</div></div>';
             /// embedded file into iframe if the resource is on another domain
             ///
             /// This case is not XHTML strict but there is no alternative
             /// The object tag alternative is XHTML strict, however IE6-7 displays a blank object on accross domain by default,
             /// so we decided to use iframe for accross domain MDL-10021
             if (!stristr($fullurl, $CFG->wwwroot)) {
                 echo '<p><iframe id="embeddedhtml" src ="' . $fullurl . '" width="100%" height="600"></iframe></p>';
             } else {
                 /// embedded HTML file into an object tag
                 echo '<p><object id="embeddedhtml" data="' . $fullurl . '" type="' . $mimetype . '" width="800" height="600">
                         alt : <a href="' . $fullurl . '">' . $fullurl . '</a>
                       </object></p>';
             }
             /// add some javascript in order to fit this object tag into the browser window
             echo '<script type="text/javascript">
                          //<![CDATA[
                          function resizeEmbeddedHtml() {
                          //calculate new embedded html height size
                  ';
             if (!empty($resource->summary)) {
                 echo '    objectheight =  YAHOO.util.Dom.getViewportHeight() - 230;
                     ';
             } else {
                 echo '    objectheight =  YAHOO.util.Dom.getViewportHeight() - 120;
                      ';
             }
             echo '       //the object tag cannot be smaller than a human readable size
                          if (objectheight < 200) {
                              objectheight = 200;
                          }
                          //resize the embedded html object
                          YAHOO.util.Dom.setStyle("embeddedhtml", "height", objectheight+"px");
                          YAHOO.util.Dom.setStyle("embeddedhtml", "width", "100%");
                       }
                       resizeEmbeddedHtml();
                       YAHOO.widget.Overlay.windowResizeEvent.subscribe(resizeEmbeddedHtml);
                       //]]>
                    </script>
                 ';
             /// print the summary
             if (!empty($resource->summary)) {
                 print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center");
             }
             echo "</body></html>";
             exit;
         } else {
             @header('Content-Type: text/html; charset=utf-8');
             echo "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Frameset//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd\">\n";
             echo "<html dir=\"ltr\">\n";
             echo '<head>';
             echo '<meta http-equiv="content-type" content="text/html; charset=utf-8" />';
             echo "<title>" . format_string($course->shortname) . ": " . strip_tags(format_string($resource->name, true)) . "</title></head>\n";
             echo "<frameset rows=\"{$CFG->resource_framesize},*\">";
             echo "<frame src=\"view.php?id={$cm->id}&amp;type={$resource->type}&amp;frameset=top\" title=\"" . get_string('modulename', 'resource') . "\"/>";
             if (!empty($localpath)) {
                 // Show it like this so we interpose some HTML
                 echo "<frame src=\"view.php?id={$cm->id}&amp;type={$resource->type}&amp;inpopup=true\" title=\"" . get_string('modulename', 'resource') . "\"/>";
             } else {
                 echo "<frame src=\"{$fullurl}\" title=\"" . get_string('modulename', 'resource') . "\"/>";
             }
             echo "</frameset>";
             echo "</html>";
             exit;
         }
     }
     /// We can only get here once per resource, so add an entry to the log
     add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);
     /// If we are in a frameset, just print the top of it
     if (!empty($frameset) and $frameset == "top") {
         // Force target atttributes on links.  Not Strict but we are already using frames anyway! MDL-20327
         $CFG->frametarget = ' target="' . $CFG->framename . '" ';
         $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"));
         $options = new object();
         $options->para = false;
         echo '<div class="summary">' . format_text($resource->summary, FORMAT_HTML, $options) . '</div>';
         if (!empty($localpath)) {
             // Show some help
             echo '<div class="mdl-right helplink">';
             link_to_popup_window('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp', 'resource'), 400, 500, get_string('localfilehelp', 'resource'));
             echo '</div>';
         }
         print_footer('empty');
         exit;
     }
     /// Display the actual resource
     if ($embedded) {
         // Display resource embedded in page
         $strdirectlink = get_string("directlink", "resource");
         if ($inpopup) {
             print_header($pagetitle);
         } else {
             $navigation = build_navigation($this->navlinks, $cm);
             print_header_simple($pagetitle, '', $navigation, "", "", true, update_module_button($cm->id, $course->id, $this->strresource), navmenu($course, $cm, "self"));
         }
         if ($resourcetype == "image") {
             echo '<div class="resourcecontent resourceimg">';
             echo "<img title=\"" . strip_tags(format_string($resource->name, true)) . "\" class=\"resourceimage\" src=\"{$fullurl}\" alt=\"\" />";
             echo '</div>';
         } else {
             if ($resourcetype == "mp3") {
                 if (!empty($THEME->resource_mp3player_colors)) {
                     $c = $THEME->resource_mp3player_colors;
                     // You can set this up in your theme/xxx/config.php
                 } else {
                     $c = 'bgColour=000000&btnColour=ffffff&btnBorderColour=cccccc&iconColour=000000&' . 'iconOverColour=00cc00&trackColour=cccccc&handleColour=ffffff&loaderColour=ffffff&' . 'font=Arial&fontColour=FF33FF&buffer=10&waitForPlay=no&autoPlay=yes';
                 }
                 $c .= '&volText=' . get_string('vol', 'resource') . '&panText=' . get_string('pan', 'resource');
                 $c = htmlentities($c);
                 $id = 'filter_mp3_' . time();
                 //we need something unique because it might be stored in text cache
                 $cleanurl = addslashes_js($fullurl);
                 // If we have Javascript, use UFO to embed the MP3 player, otherwise depend on plugins
                 echo '<div class="resourcecontent resourcemp3">';
                 echo '<span class="mediaplugin mediaplugin_mp3" id="' . $id . '"></span>' . '<script type="text/javascript">' . "\n" . '//<![CDATA[' . "\n" . 'var FO = { movie:"' . $CFG->wwwroot . '/lib/mp3player/mp3player.swf?src=' . $cleanurl . '",' . "\n" . 'width:"600", height:"70", majorversion:"6", build:"40", flashvars:"' . $c . '", quality: "high" };' . "\n" . 'UFO.create(FO, "' . $id . '");' . "\n" . '//]]>' . "\n" . '</script>' . "\n";
                 echo '<noscript>';
                 echo "<object type=\"audio/mpeg\" data=\"{$fullurl}\" width=\"600\" height=\"70\">";
                 echo "<param name=\"src\" value=\"{$fullurl}\" />";
                 echo '<param name="quality" value="high" />';
                 echo '<param name="autoplay" value="true" />';
                 echo '<param name="autostart" value="true" />';
                 echo '</object>';
                 echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>';
                 echo '</noscript>';
                 echo '</div>';
             } else {
                 if ($resourcetype == "flv") {
                     $id = 'filter_flv_' . time();
                     //we need something unique because it might be stored in text cache
                     $cleanurl = addslashes_js($fullurl);
                     // If we have Javascript, use UFO to embed the FLV player, otherwise depend on plugins
                     echo '<div class="resourcecontent resourceflv">';
                     echo '<span class="mediaplugin mediaplugin_flv" id="' . $id . '"></span>' . '<script type="text/javascript">' . "\n" . '//<![CDATA[' . "\n" . 'var FO = { movie:"' . $CFG->wwwroot . '/filter/mediaplugin/flvplayer.swf?file=' . $cleanurl . '",' . "\n" . 'width:"600", height:"400", majorversion:"6", build:"40", allowscriptaccess:"never", allowfullscreen:"true", quality: "high" };' . "\n" . 'UFO.create(FO, "' . $id . '");' . "\n" . '//]]>' . "\n" . '</script>' . "\n";
                     echo '<noscript>';
                     echo "<object type=\"video/x-flv\" data=\"{$fullurl}\" width=\"600\" height=\"400\">";
                     echo "<param name=\"src\" value=\"{$fullurl}\" />";
                     echo '<param name="quality" value="high" />';
                     echo '<param name="autoplay" value="true" />';
                     echo '<param name="autostart" value="true" />';
                     echo '</object>';
                     echo '<p><a href="' . $fullurl . '">' . $fullurl . '</a></p>';
                     echo '</noscript>';
                     echo '</div>';
                 } else {
                     if ($resourcetype == "mediaplayer") {
                         echo '<div class="resourcecontent resourcewmv">';
                         echo '<object type="video/x-ms-wmv" data="' . $fullurl . '">';
                         echo '<param name="controller" value="true" />';
                         echo '<param name="autostart" value="true" />';
                         echo "<param name=\"src\" value=\"{$fullurl}\" />";
                         echo '<param name="scale" value="noScale" />';
                         echo "<a href=\"{$fullurl}\">{$fullurl}</a>";
                         echo '</object>';
                         echo '</div>';
                     } else {
                         if ($resourcetype == "mpeg") {
                             echo '<div class="resourcecontent resourcempeg">';
                             echo '<object classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
                           codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsm p2inf.cab#Version=5,1,52,701"
                           type="application/x-oleobject">';
                             echo "<param name=\"fileName\" value=\"{$fullurl}\" />";
                             echo '<param name="autoStart" value="true" />';
                             echo '<param name="animationatStart" value="true" />';
                             echo '<param name="transparentatStart" value="true" />';
                             echo '<param name="showControls" value="true" />';
                             echo '<param name="Volume" value="-450" />';
                             echo '<!--[if !IE]>-->';
                             echo '<object type="video/mpeg" data="' . $fullurl . '">';
                             echo '<param name="controller" value="true" />';
                             echo '<param name="autostart" value="true" />';
                             echo "<param name=\"src\" value=\"{$fullurl}\" />";
                             echo "<a href=\"{$fullurl}\">{$fullurl}</a>";
                             echo '<!--<![endif]-->';
                             echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
                             echo '<!--[if !IE]>-->';
                             echo '</object>';
                             echo '<!--<![endif]-->';
                             echo '</object>';
                             echo '</div>';
                         } else {
                             if ($resourcetype == "rm") {
                                 echo '<div class="resourcecontent resourcerm">';
                                 echo '<object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="320" height="240">';
                                 echo '<param name="src" value="' . $fullurl . '" />';
                                 echo '<param name="controls" value="All" />';
                                 echo '<!--[if !IE]>-->';
                                 echo '<object type="audio/x-pn-realaudio-plugin" data="' . $fullurl . '" width="320" height="240">';
                                 echo '<param name="controls" value="All" />';
                                 echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
                                 echo '</object>';
                                 echo '<!--<![endif]-->';
                                 echo '</object>';
                                 echo '</div>';
                             } else {
                                 if ($resourcetype == "quicktime") {
                                     echo '<div class="resourcecontent resourceqt">';
                                     echo '<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"';
                                     echo '        codebase="http://www.apple.com/qtactivex/qtplugin.cab">';
                                     echo "<param name=\"src\" value=\"{$fullurl}\" />";
                                     echo '<param name="autoplay" value="true" />';
                                     echo '<param name="loop" value="true" />';
                                     echo '<param name="controller" value="true" />';
                                     echo '<param name="scale" value="aspect" />';
                                     echo '<!--[if !IE]>-->';
                                     echo "<object type=\"video/quicktime\" data=\"{$fullurl}\">";
                                     echo '<param name="controller" value="true" />';
                                     echo '<param name="autoplay" value="true" />';
                                     echo '<param name="loop" value="true" />';
                                     echo '<param name="scale" value="aspect" />';
                                     echo '<!--<![endif]-->';
                                     echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
                                     echo '<!--[if !IE]>-->';
                                     echo '</object>';
                                     echo '<!--<![endif]-->';
                                     echo '</object>';
                                     echo '</div>';
                                 } else {
                                     if ($resourcetype == "flash") {
                                         echo '<div class="resourcecontent resourceswf">';
                                         echo '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">';
                                         echo "<param name=\"movie\" value=\"{$fullurl}\" />";
                                         echo '<param name="autoplay" value="true" />';
                                         echo '<param name="loop" value="true" />';
                                         echo '<param name="controller" value="true" />';
                                         echo '<param name="scale" value="aspect" />';
                                         echo '<param name="base" value="." />';
                                         echo '<!--[if !IE]>-->';
                                         echo "<object type=\"application/x-shockwave-flash\" data=\"{$fullurl}\">";
                                         echo '<param name="controller" value="true" />';
                                         echo '<param name="autoplay" value="true" />';
                                         echo '<param name="loop" value="true" />';
                                         echo '<param name="scale" value="aspect" />';
                                         echo '<param name="base" value="." />';
                                         echo '<!--<![endif]-->';
                                         echo '<a href="' . $fullurl . '">' . $fullurl . '</a>';
                                         echo '<!--[if !IE]>-->';
                                         echo '</object>';
                                         echo '<!--<![endif]-->';
                                         echo '</object>';
                                         echo '</div>';
                                     } elseif ($resourcetype == 'zip') {
                                         echo '<div class="resourcepdf">';
                                         echo get_string('clicktoopen', 'resource') . '<a href="' . $fullurl . '">' . format_string($resource->name) . '</a>';
                                         echo '</div>';
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if (trim($resource->summary)) {
             print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center");
         }
         if ($inpopup) {
             echo "<div class=\"popupnotice\">(<a href=\"{$fullurl}\">{$strdirectlink}</a>)</div>";
             print_footer($course);
             // MDL-12098
         } else {
             print_spacer(20, 20);
             print_footer($course);
         }
     } else {
         // Display the resource on it's own
         if (!empty($localpath)) {
             // Show a link to help work around browser security
             echo '<div class="mdl-right helplink">';
             link_to_popup_window('/mod/resource/type/file/localpath.php', get_string('localfile', 'resource'), get_string('localfilehelp', 'resource'), 400, 500, get_string('localfilehelp', 'resource'));
             echo '</div>';
             echo "<div class=\"popupnotice\">(<a href=\"{$fullurl}\">{$fullurl}</a>)</div>";
         }
         redirect($fullurl);
     }
 }
Esempio n. 12
0
 function display()
 {
     global $CFG;
     /// 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;
     require_once $CFG->libdir . '/filelib.php';
     $subdir = optional_param('subdir', '', PARAM_PATH);
     $resource->reference = clean_param($resource->reference, PARAM_PATH);
     $formatoptions = new object();
     $formatoptions->noclean = true;
     $formatoptions->para = false;
     // MDL-12061, <p> in html editor breaks xhtml strict
     add_to_log($course->id, "resource", "view", "view.php?id={$cm->id}", $resource->id, $cm->id);
     if ($resource->reference) {
         $relativepath = "{$course->id}/{$resource->reference}";
     } else {
         $relativepath = "{$course->id}";
     }
     if ($subdir) {
         $relativepath = "{$relativepath}{$subdir}";
         if (stripos($relativepath, 'backupdata') !== FALSE or stripos($relativepath, $CFG->moddata) !== FALSE) {
             error("Access not allowed!");
         }
         $subs = explode('/', $subdir);
         array_shift($subs);
         $countsubs = count($subs);
         $count = 0;
         $backsub = '';
         foreach ($subs as $sub) {
             $count++;
             if ($count < $countsubs) {
                 $backsub .= "/{$sub}";
                 $this->navlinks[] = array('name' => $sub, 'link' => "view.php?id={$cm->id}", 'type' => 'title');
             } else {
                 $this->navlinks[] = array('name' => $sub, 'link' => '', 'type' => 'title');
             }
         }
     }
     $pagetitle = strip_tags($course->shortname . ': ' . format_string($resource->name));
     $update = update_module_button($cm->id, $course->id, $this->strresource);
     if (has_capability('moodle/course:managefiles', get_context_instance(CONTEXT_COURSE, $course->id))) {
         $options = array('id' => $course->id, 'wdir' => '/' . $resource->reference . $subdir);
         $editfiles = print_single_button("{$CFG->wwwroot}/files/index.php", $options, get_string("editfiles"), 'get', '', true);
         $update = $editfiles . $update;
     }
     $navigation = build_navigation($this->navlinks, $cm);
     print_header($pagetitle, $course->fullname, $navigation, "", "", true, $update, navmenu($course, $cm));
     if (trim(strip_tags($resource->summary))) {
         print_simple_box(format_text($resource->summary, FORMAT_MOODLE, $formatoptions, $course->id), "center");
         print_spacer(10, 10);
     }
     $files = get_directory_list("{$CFG->dataroot}/{$relativepath}", array($CFG->moddata, 'backupdata'), false, true, true);
     if (!$files) {
         print_heading(get_string("nofilesyet"));
         print_footer($course);
         exit;
     }
     print_simple_box_start("center", "", "", '0');
     $strftime = get_string('strftimedatetime');
     $strname = get_string("name");
     $strsize = get_string("size");
     $strmodified = get_string("modified");
     $strfolder = get_string("folder");
     $strfile = get_string("file");
     echo '<table cellpadding="4" cellspacing="1" class="files" summary="">';
     echo "<tr><th class=\"header name\" scope=\"col\">{$strname}</th>" . "<th align=\"right\" colspan=\"2\" class=\"header size\" scope=\"col\">{$strsize}</th>" . "<th align=\"right\" class=\"header date\" scope=\"col\">{$strmodified}</th>" . "</tr>";
     foreach ($files as $file) {
         if (is_dir("{$CFG->dataroot}/{$relativepath}/{$file}")) {
             // Must be a directory
             $icon = "folder.gif";
             $relativeurl = "/view.php?blah";
             $filesize = display_size(get_directory_size("{$CFG->dataroot}/{$relativepath}/{$file}"));
         } else {
             $icon = mimeinfo("icon", $file);
             $relativeurl = get_file_url("{$relativepath}/{$file}");
             $filesize = display_size(filesize("{$CFG->dataroot}/{$relativepath}/{$file}"));
         }
         if ($icon == 'folder.gif') {
             echo '<tr class="folder">';
             echo '<td class="name">';
             echo "<a href=\"view.php?id={$cm->id}&amp;subdir={$subdir}/{$file}\">";
             echo "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfolder}\" />&nbsp;{$file}</a>";
         } else {
             echo '<tr class="file">';
             echo '<td class="name">';
             link_to_popup_window($relativeurl, "resourcedirectory{$resource->id}", "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" />&nbsp;{$file}", 450, 600, '');
         }
         echo '</td>';
         echo '<td>&nbsp;</td>';
         echo '<td align="right" class="size">';
         echo $filesize;
         echo '</td>';
         echo '<td align="right" class="date">';
         echo userdate(filemtime("{$CFG->dataroot}/{$relativepath}/{$file}"), $strftime);
         echo '</td>';
         echo '</tr>';
     }
     echo '</table>';
     print_simple_box_end();
     print_footer($course);
 }
Esempio n. 13
0
 function get_baseurl()
 {
     // set the url base (first time only)
     if (!isset($this->baseurl)) {
         global $CFG;
         require_once $CFG->libdir . '/filelib.php';
         $this->baseurl = get_file_url($this->filedir) . '/';
     }
     return $this->baseurl;
 }
Esempio n. 14
0
File: lib.php Progetto: r007/PMoodle
/**
 * if return=html, then return a html string.
 * if return=text, then return a text-only string.
 * otherwise, print HTML for non-images, and return image HTML
 */
function forum_print_attachments($post, $return = NULL)
{
    global $CFG;
    $filearea = forum_file_area_name($post);
    $imagereturn = "";
    $output = "";
    if ($basedir = forum_file_area($post)) {
        if ($files = get_directory_list($basedir)) {
            $strattachment = get_string("attachment", "forum");
            foreach ($files as $file) {
                $icon = mimeinfo("icon", $file);
                $type = mimeinfo("type", $file);
                $ffurl = get_file_url("{$filearea}/{$file}");
                $image = "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"\" />";
                if ($return == "html") {
                    $output .= "<a href=\"{$ffurl}\">{$image}</a> ";
                    $output .= "<a href=\"{$ffurl}\">{$file}</a><br />";
                } else {
                    if ($return == "text") {
                        $output .= "{$strattachment} {$file}:\n{$ffurl}\n";
                    } else {
                        if (in_array($type, array('image/gif', 'image/jpeg', 'image/png'))) {
                            // Image attachments don't get printed as links
                            $imagereturn .= "<br /><img src=\"{$ffurl}\" alt=\"\" />";
                        } else {
                            echo "<a href=\"{$ffurl}\">{$image}</a> ";
                            echo filter_text("<a href=\"{$ffurl}\">{$file}</a><br />");
                        }
                    }
                }
            }
        }
    }
    if ($return) {
        return $output;
    }
    return $imagereturn;
}
Esempio n. 15
0
function rss_get_url($courseid, $userid, $modulename, $id)
{
    global $CFG;
    require_once $CFG->libdir . '/filelib.php';
    return get_file_url($courseid . '/' . $userid . '/' . $modulename . '/' . $id . '/rss.xml', null, 'rssfile');
}
Esempio n. 16
0
 function readquestions($lines)
 {
     /// Parses an array of lines into an array of questions,
     /// where each item is a question object as defined by
     /// readquestion().
     // set courseid and baseurl
     global $CFG, $COURSE, $course;
     switch (true) {
         case isset($this->course->id):
             // import to quiz module
             $courseid = $this->course->id;
             break;
         case isset($course->id):
             // import to lesson module
             $courseid = $course->id;
             break;
         case isset($COURSE->id):
             // last resort
             $courseid = $COURSE->id;
             break;
         default:
             // shouldn't happen !!
             $courseid = 0;
     }
     require_once $CFG->libdir . '/filelib.php';
     $baseurl = get_file_url($courseid) . '/';
     // get import file name
     global $params;
     if (!empty($this->realfilename)) {
         $filename = $this->realfilename;
     } else {
         if (isset($params) && !empty($params->choosefile)) {
             // course file (Moodle >=1.6+)
             $filename = $params->choosefile;
         } else {
             // uploaded file (all Moodles)
             $filename = basename($_FILES['newfile']['tmp_name']);
         }
     }
     // get hotpot file source
     $source = implode($lines, " ");
     $source = hotpot_convert_relative_urls($source, $baseurl, $filename);
     // create xml tree for this hotpot
     $xml = new hotpot_xml_tree($source);
     // determine the quiz type
     $xml->quiztype = '';
     $keys = array_keys($xml->xml);
     foreach ($keys as $key) {
         if (preg_match('/^(hotpot|textoys)-(\\w+)-file$/i', $key, $matches)) {
             $xml->quiztype = strtolower($matches[2]);
             $xml->xml_root = "['{$key}']['#']";
             break;
         }
     }
     // convert xml to questions array
     $questions = array();
     switch ($xml->quiztype) {
         case 'jcloze':
             $this->process_jcloze($xml, $questions);
             break;
         case 'jcross':
             $this->process_jcross($xml, $questions);
             break;
         case 'jmatch':
             $this->process_jmatch($xml, $questions);
             break;
         case 'jmix':
             $this->process_jmix($xml, $questions);
             break;
         case 'jbc':
         case 'jquiz':
             $this->process_jquiz($xml, $questions);
             break;
         default:
             if (empty($xml->quiztype)) {
                 notice("Input file not recognized as a Hot Potatoes XML file");
             } else {
                 notice("Unknown quiz type '{$xml->quiztype}'");
             }
     }
     // end switch
     if (count($questions)) {
         return $questions;
     } else {
         if (method_exists($this, 'error')) {
             // Moodle >= 1.8
             $this->error(get_string('giftnovalidquestion', 'quiz'));
         }
         return false;
     }
 }
Esempio n. 17
0
		<input type="text" class="form-control" name="s[desc]" value="曾记否我们一切安好" id="I_desc">
	</div>

	<div class="form-group">
		<label class="control-label" for="I_url">网站地址</label>
		<input type="text" class="form-control" name="s[url]" value="<?php 
echo get_file_url();
?>
" id="I_url">
		<p class="help-block">注意:如果网站使用PATH_INFO的形式请在结尾处添加<code>index.php/</code>,如若修正指定文件请手动修改。</p>
	</div>

	<div class="form-group">
		<label class="control-label" for="I_static_url">网站静态地址</label>
		<input type="text" class="form-control" name="s[static_url]" value="<?php 
echo get_file_url();
?>
" id="I_static_url">
	</div>

	<div class="form-group">
		<label class="control-label" for="I_email">管理员邮箱</label>
		<input type="text" class="form-control" name="s[email]" placeholder="你必须提交你的管理员邮箱" value="" id="I_email">
	</div>

	<hr>


	<div class="form-group">
		<label class="control-label" for="I_user">管理员账户</label>
		<input type="text" class="form-control" name="u[name]" placeholder="你的用户名,最低6位" value="" id="I_user">
Esempio n. 18
0
function extract_data($pages, $courseid, $lessonname, $modname)
{
    // this function attempts to extract the content out of the slides
    // the slides are ugly broken xml.  and the xml is broken... yeah...
    global $CFG;
    global $matches;
    $extratedpages = array();
    // directory for images
    make_mod_upload_directory($courseid);
    // make sure moddata is made
    make_upload_directory($courseid . '/moddata/' . $modname, false);
    // we store our images in a subfolder in here
    $imagedir = $CFG->dataroot . '/' . $courseid . '/moddata/' . $modname;
    require_once $CFG->libdir . '/filelib.php';
    $imagelink = get_file_url($courseid . '/moddata/' . $modname);
    // try to make a unique subfolder to store the images
    $lessonname = str_replace(' ', '_', $lessonname);
    // get rid of spaces
    $i = 0;
    while (true) {
        if (!file_exists($imagedir . '/' . $lessonname . $i)) {
            // ok doesnt exist so make the directory and update our paths
            mkdir($imagedir . '/' . $lessonname . $i);
            $imagedir = $imagedir . '/' . $lessonname . $i;
            $imagelink = $imagelink . '/' . $lessonname . $i;
            break;
        }
        $i++;
    }
    foreach ($pages as $file => $content) {
        // to make life easier on our preg_match_alls, we strip out all tags except
        // for div and img (where our content is).  We want div because sometimes we
        // can identify the content in the div based on the div's class
        $tags = '<div><img>';
        // should also allow <b><i>
        $string = strip_tags($content, $tags);
        //echo s($string);
        $matches = array();
        // this will look for a non nested tag that is closed
        // want to allow <b><i>(maybe more) tags but when we do that
        // the preg_match messes up.
        preg_match_all("/(<([\\w]+)[^>]*>)([^<\\2>]*)(<\\/\\2>)/", $string, $matches);
        //(<([\w]+)[^>]*>)([^<\\2>]*)(<\/\\2>)  original pattern
        //(<(div+)[^>]*>)[^(<div*)](<\/div>) work in progress
        $path_parts = pathinfo($file);
        $file = substr($path_parts['basename'], 0, strpos($path_parts['basename'], '.'));
        // get rid of the extension
        $imgs = array();
        // this preg matches all images
        preg_match_all("/<img[^>]*(src\\=\"(" . $file . "\\_image[^>^\"]*)\"[^>]*)>/i", $string, $imgs);
        // start building our page
        $page = new stdClass();
        $page->title = '';
        $page->contents = array();
        $page->images = array();
        $page->source = $path_parts['basename'];
        // need for book only
        // this foreach keeps the style intact.  Found it doesn't help much.  But if you want back uncomment
        // this foreach and uncomment the line with the comment imgstyle in it.  Also need to comment out
        // the $page->images[]... line in the next foreach
        /*foreach ($imgs[1] as $img) { 
              $page->images[] = '<img '.str_replace('src="', "src=\"$imagelink/", $img).' />';
          }*/
        foreach ($imgs[2] as $img) {
            copy($path_parts['dirname'] . '/' . $img, $imagedir . '/' . $img);
            $page->images[] = "<img src=\"{$imagelink}/{$img}\" title=\"{$img}\" />";
            // comment out this line if you are using the above foreach loop
        }
        for ($i = 0; $i < count($matches[1]); $i++) {
            // go through all of our div matches
            $class = isolate_class($matches[1][$i]);
            // first step in isolating the class
            // check for any static classes
            switch ($class) {
                case 'T':
                    // class T is used for Titles
                    $page->title = $matches[3][$i];
                    break;
                case 'B':
                    // I would guess that all bullet lists would start with B then go to B1, B2, etc
                // I would guess that all bullet lists would start with B then go to B1, B2, etc
                case 'B1':
                    // B1-B4 are just insurance, should just hit B and all be taken care of
                // B1-B4 are just insurance, should just hit B and all be taken care of
                case 'B2':
                case 'B3':
                case 'B4':
                    $page->contents[] = build_list('<ul>', $i, 0);
                    // this is a recursive function that will grab all the bullets and rebuild the list in html
                    break;
                default:
                    if ($matches[3][$i] != '&#13;') {
                        // odd crap generated... sigh
                        if (substr($matches[3][$i], 0, 1) == ':') {
                            // check for leading :    ... hate MS ...
                            $page->contents[] = substr($matches[3][$i], 1);
                            // get rid of :
                        } else {
                            $page->contents[] = $matches[3][$i];
                        }
                    }
                    break;
            }
        }
        /*if (count($page->contents) == 0) {  // didnt find anything, grab everything
                                              // potential to pull in a lot of crap
              for($i = 0; $i < count($matches[1]); $i++) {        
                  //if($class = isolate_class($matches[1][$i])) { 
                      //if ($class == 'O') {
                          if ($matches[3][$i] != '&#13;') {  // odd crap generated... sigh
                              if (substr($matches[3][$i], 0, 1) == ':') {  // check for leading :    ... hate MS ...
                                  $page->contents[] = substr($matches[3][$i], 1);  // get rid of :
                              } else {
                                  $page->contents[] = $matches[3][$i];
                              }
                          }
                      //}
                  //}
              }
          }*/
        // add the page to the array;
        $extratedpages[] = $page;
    }
    // end $pages foreach loop
    return $extratedpages;
}
Esempio n. 19
0
function question_replace_file_links_in_html($html, $fromcourseid, $tocourseid, $url, $destination, &$changed)
{
    global $CFG;
    require_once $CFG->libdir . '/filelib.php';
    $tourl = get_file_url("{$tocourseid}/{$destination}");
    $fromurl = question_file_links_base_url($fromcourseid) . preg_quote($url, '!');
    $searchfor = array('!(<\\s*(a|img)\\s[^>]*(href|src)\\s*=\\s*")' . $fromurl . '(")!i', '!(<\\s*(a|img)\\s[^>]*(href|src)\\s*=\\s*\')' . $fromurl . '(\')!i');
    $newhtml = preg_replace($searchfor, '\\1' . $tourl . '\\5', $html);
    if ($newhtml != $html) {
        $changed = true;
    }
    return $newhtml;
}
Esempio n. 20
0
File: trdl.php Progetto: happyj/qcn
function qcn_trigger_detail(&$res, $bg_color, $auth, $user, $bDownloadAll)
{
    global $unixtimeArchive;
    if ($auth || $user->id == $res->hostid) {
        $loc_res = 4;
    } else {
        $loc_res = 2;
    }
    // CMC took out hostnamebyid below
    $sensor_type = $res->sensor_description;
    $archpre = $res->is_archive ? "a" : "r";
    // prefix to signify if it's an archive record or not
    $file_url = get_file_url($res);
    if ($auth) {
        if ($bDownloadAll) {
            echo "<input type=\"hidden\" name=\"cb_" . $archpre . "_dlfile[]\" id=\"cb_" . $archpre . "_dlfile[]\" value=\"{$res->triggerid}\"" . ">\n";
            //echo "<tr><td><input type=\"hidden\" name=\"cb_" . $archpre . "_dlfile[]\" id=\"cb_" . $archpre . "_dlfile[]\" value=\"$res->triggerid\"" .
            //     "></font size></td></tr>\n";
            return;
        } else {
            echo "\n        <tr bgcolor=\"" . $bg_color . "\">\n";
            echo "\n        <td><font size=\"1\"><input type=\"checkbox\" name=\"cb_" . $archpre . "_reqfile[]\" id=\"cb_" . $archpre . "_reqfile[]\" value=\"{$res->triggerid}\"" . ($res->varietyid != 0 || $res->received_file == 100 || $res->trigger_timereq > 0 || $res->trigger_time < $unixtimeArchive ? " disabled " : " ") . "></font size></td>\n        <td><font size=\"1\"><input type=\"checkbox\" name=\"cb_" . $archpre . "_dlfile[]\" id=\"cb_" . $archpre . "_dlfile[]\" value=\"{$res->triggerid}\"" . ($res->received_file != 100 || file_url == "N/A" ? " disabled " : ($bDownloadAll ? " checked " : " ")) . "></font size></td>";
        }
    }
    echo "\n        <td><font size=\"1\">{$res->triggerid}</font size></td>";
    echo "<td><font size=\"1\"><a href=\"show_host_detail.php?hostid={$res->hostid}\">" . $res->hostid . "</a></font size></td>";
    if ($auth) {
        echo "   <td><font size=\"1\">{$res->ipaddr}<br>{$res->hostname}</font size></td>";
    }
    //    echo "<td><font size=\"1\">$res->result_name</font size></td>";
    echo "\n        <td><font size=\"1\">" . time_str($res->trigger_time) . "</font size></td>\n        <td><font size=\"1\">" . round($res->delay_time, 2) . "</font size></td>\n        <td><font size=\"1\">" . time_str($res->trigger_sync) . "</font size></td>\n        <td><font size=\"1\">" . round($res->sync_offset, 2) . "</font size></td>\n        <td><font size=\"1\">" . round($res->trigger_mag, 2) . "</font size></td>\n        <td><font size=\"1\">" . round($res->significance, 2) . "</font size></td>\n        <td><font size=\"1\">" . round($res->trigger_lat, $loc_res) . "</font size></td>\n        <td><font size=\"1\">" . round($res->trigger_lon, $loc_res) . "</font size></td>\n        <td><font size=\"1\">" . ($res->numreset ? $res->numreset : 0) . "</font size></td>\n        <td><font size=\"1\">{$res->delta_t}</font size></td>\n        <td><font size=\"1\">{$sensor_type}</font size></td>\n        <td><font size=\"1\">{$res->sw_version}</font size></td>\n        <td><font size=\"1\">{$res->is_geoip}<font size></td>";
    echo "\n        <td><font size=\"1\">" . time_str($res->trigger_timereq) . "</font size></td>";
    //      echo"  <td><font size=\"1\">" . ($res->received_file == 100 ? " Yes " : " No " ) . "</font size></td>";
    if ($file_url != "N/A") {
        echo "<td><font size=\"1\"><a href=\"" . $file_url . "\">Download</a></font size></td>";
        echo "<td><font size=\"1\"><a href=\"javascript:void(0)\"onclick=\"window.open('" . BASEURL . "/earthquakes/view/view_data.php?dat=" . basename($file_url) . "&fthumb=340','linkname','height=550,width=400,scrollbars=no')\">View</a></font size></td>";
    } else {
        echo "<td><font size=\"1\">N/A</font size></td>";
        echo "<td><font size=\"1\">N/A</font size></td>";
    }
    if ($res->qcn_quakeid) {
        echo "<td><font size=\"1\"><A HREF=\"{$res->quake_url}\">{$res->qcn_quakeid}</A></font size></td>";
        echo "<td><font size=\"1\">" . round($res->quake_distance_km, 2) . "</font size></td>";
        echo "<td><font size=\"1\">" . round($res->quake_magnitude, 2) . "</font size></td>";
        echo "<td><font size=\"1\">" . time_str($res->quake_time) . "</font size></td>";
        echo "<td><font size=\"1\">" . round($res->quake_lat, $loc_res) . "</font size></td>";
        echo "<td><font size=\"1\">" . round($res->quake_lon, $loc_res) . "</font size></td>";
        echo "<td><font size=\"1\">{$res->description}</font size></td>";
        //           echo "<td><font size=\"1\">$res->guid</font size></td>";
        echo "<td><font size=\"1\">" . ($res->is_archive ? "Y" : "N") . "</font size></td>";
    } else {
        echo "<td><font size=\"1\">N/A</font size></td>";
        echo "<td><font size=\"1\">&nbsp</font size></td>";
        echo "<td><font size=\"1\">&nbsp</font size></td>";
        echo "<td><font size=\"1\">&nbsp</font size></td>";
        echo "<td><font size=\"1\">&nbsp</font size></td>";
        echo "<td><font size=\"1\">&nbsp</font size></td>";
        echo "<td><font size=\"1\">&nbsp</font size></td>";
        //           echo "<td><font size=\"1\">&nbsp</font size></td>";
        echo "<td><font size=\"1\">" . ($res->is_archive ? "Y" : "N") . "</font size></td>";
    }
    echo "</tr>\n    ";
}
Esempio n. 21
0
function restore_decode_absolute_links($content)
{
    global $CFG, $restore;
    require_once $CFG->libdir . '/filelib.php';
    /// MDL-14072: Prevent NULLs, empties and numbers to be processed by the
    /// heavy interlinking. Just a few cpu cycles saved.
    if ($content === NULL) {
        return NULL;
    } else {
        if ($content === '') {
            return '';
        } else {
            if (is_numeric($content)) {
                return $content;
            }
        }
    }
    //Now decode wwwroot and file.php calls
    $search = array("\$@FILEPHP@\$");
    $replace = array(get_file_url($restore->course_id));
    $result = str_replace($search, $replace, $content);
    //Now $@SLASH@$ and $@FORCEDOWNLOAD@$ MDL-18799
    $search = array('$@SLASH@$', '$@FORCEDOWNLOAD@$');
    if ($CFG->slasharguments) {
        $replace = array('/', '?forcedownload=1');
    } else {
        $replace = array('%2F', '&amp;forcedownload=1');
    }
    $result = str_replace($search, $replace, $result);
    if ($result != $content && debugging()) {
        //Debug
        if (!defined('RESTORE_SILENTLY')) {
            echo '<br /><hr />' . s($content) . '<br />changed to<br />' . s($result) . '<hr /><br />';
            //Debug
        }
    }
    //Debug
    return $result;
}
Esempio n. 22
0
 public function test_get_file_url()
 {
     global $CFG, $HTTPSPAGEREQUIRED;
     // Slasharguments off
     $CFG->slasharguments = false;
     $path = '/path/to/file/file.txt';
     $this->assertEqual($CFG->wwwroot . '/file.php?file=%2Fpath%2Fto%2Ffile%2Ffile.txt', get_file_url($path));
     $options = array('var1' => 'value1', 'var2' => 'value2');
     $this->assertEqual($CFG->wwwroot . '/file.php?file=%2Fpath%2Fto%2Ffile%2Ffile.txt&amp;var1=value1&amp;var2=value2', get_file_url($path, $options));
     $this->assertEqual($CFG->httpswwwroot . '/file.php?file=%2Fpath%2Fto%2Ffile%2Ffile.txt&amp;var1=value1&amp;var2=value2', get_file_url($path, $options, 'httpscoursefile'));
     $path = 'C:\\path\\to\\file.txt';
     $this->assertEqual($CFG->wwwroot . '/file.php?file=%2FC%3A%5Cpath%5Cto%5Cfile.txt&amp;var1=value1&amp;var2=value2', get_file_url($path, $options));
     // With slasharguments on
     $CFG->slasharguments = true;
     $path = '/path/to/file/file.txt';
     $this->assertEqual($CFG->wwwroot . '/file.php' . $path, get_file_url($path));
     $options = array('var1' => 'value1', 'var2' => 'value2');
     $this->assertEqual($CFG->wwwroot . '/file.php' . $path . '?var1=value1&amp;var2=value2', get_file_url($path, $options));
     $this->assertEqual($CFG->httpswwwroot . '/file.php' . $path . '?var1=value1&amp;var2=value2', get_file_url($path, $options, 'httpscoursefile'));
     $path = 'C:\\path\\to\\file.txt';
     $this->assertEqual($CFG->wwwroot . '/file.php/C%3A%5Cpath%5Cto%5Cfile.txt?var1=value1&amp;var2=value2', get_file_url($path, $options));
     $path = '/path/to/file/file.txt';
     $HTTPSPAGEREQUIRED = true;
     $this->assertEqual($CFG->httpswwwroot . '/user/pix.php' . $path, get_file_url($path, null, 'user'));
     $HTTPSPAGEREQUIRED = false;
     $this->assertEqual($CFG->wwwroot . '/user/pix.php' . $path, get_file_url($path, null, 'user'));
     $this->assertEqual($CFG->wwwroot . '/question/exportfile.php' . $path, get_file_url($path, null, 'questionfile'));
     $this->assertEqual($CFG->wwwroot . '/rss/file.php' . $path, get_file_url($path, null, 'rssfile'));
     // Test relative path
     $path = 'relative/path/to/file.txt';
     $this->assertEqual($CFG->wwwroot . '/file.php/' . $path, get_file_url($path));
     // Test with anchor in path
     $path = 'relative/path/to/index.html#anchor1';
     $this->assertEqual($CFG->wwwroot . '/file.php/' . $path, get_file_url($path));
     // Test with anchor and funny characters in path
     $path = 'rela89èà7(##&$tive/path/to /indéx.html#anchor1';
     $this->assertEqual($CFG->wwwroot . '/file.php/rela89%C3%A8%C3%A07%28##%26%24tive/path/to%20/ind%C3%A9x.html#anchor1', get_file_url($path));
 }
Esempio n. 23
0
function displaydir($wdir)
{
    //  $wdir == / or /a or /a/b/c/d  etc
    global $basedir;
    global $id;
    global $USER, $CFG;
    global $choose;
    $fullpath = $basedir . $wdir;
    $dirlist = array();
    $directory = opendir($fullpath);
    // Find all files
    while (false !== ($file = readdir($directory))) {
        if ($file == "." || $file == "..") {
            continue;
        }
        if (is_dir($fullpath . "/" . $file)) {
            $dirlist[] = $file;
        } else {
            $filelist[] = $file;
        }
    }
    closedir($directory);
    $strname = get_string("name");
    $strsize = get_string("size");
    $strmodified = get_string("modified");
    $straction = get_string("action");
    $strmakeafolder = get_string("makeafolder");
    $struploadafile = get_string("uploadafile");
    $strselectall = get_string("selectall");
    $strselectnone = get_string("deselectall");
    $strwithchosenfiles = get_string("withchosenfiles");
    $strmovetoanotherfolder = get_string("movetoanotherfolder");
    $strmovefilestohere = get_string("movefilestohere");
    $strdeletecompletely = get_string("deletecompletely");
    $strcreateziparchive = get_string("createziparchive");
    $strrename = get_string("rename");
    $stredit = get_string("edit");
    $strunzip = get_string("unzip");
    $strlist = get_string("list");
    $strrestore = get_string("restore");
    $strchoose = get_string("choose");
    $strfolder = get_string("folder");
    $strfile = get_string("file");
    echo "<form action=\"index.php\" method=\"post\" id=\"dirform\">";
    echo "<div>";
    echo '<input type="hidden" name="choose" value="' . $choose . '" />';
    // echo "<hr align=\"center\" noshade=\"noshade\" size=\"1\" />";
    echo "<hr/>";
    echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\" class=\"files\">";
    echo "<tr>";
    echo "<th class=\"header\" scope=\"col\"></th>";
    echo "<th class=\"header name\" scope=\"col\">{$strname}</th>";
    echo "<th class=\"header size\" scope=\"col\">{$strsize}</th>";
    echo "<th class=\"header date\" scope=\"col\">{$strmodified}</th>";
    echo "<th class=\"header commands\" scope=\"col\">{$straction}</th>";
    echo "</tr>\n";
    if ($wdir != "/") {
        $dirlist[] = '..';
    }
    $count = 0;
    if (!empty($dirlist)) {
        asort($dirlist);
        foreach ($dirlist as $dir) {
            echo "<tr class=\"folder\">";
            if ($dir == '..') {
                $fileurl = rawurlencode(dirname($wdir));
                print_cell();
                // alt attribute intentionally empty to prevent repetition in screen reader
                print_cell('left', '<a href="index.php?id=' . $id . '&amp;wdir=' . $fileurl . '&amp;choose=' . $choose . '"><img src="' . $CFG->pixpath . '/f/parent.gif" class="icon" alt="" />&nbsp;' . get_string('parentfolder') . '</a>', 'name');
                print_cell();
                print_cell();
                print_cell();
            } else {
                $count++;
                $filename = $fullpath . "/" . $dir;
                $fileurl = rawurlencode($wdir . "/" . $dir);
                $filesafe = rawurlencode($dir);
                $filesize = display_size(get_directory_size("{$fullpath}/{$dir}"));
                $filedate = userdate(filemtime($filename), get_string("strftimedatetime"));
                if ($wdir . $dir === '/moddata') {
                    print_cell();
                } else {
                    print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox');
                }
                print_cell("left", "<a href=\"index.php?id={$id}&amp;wdir={$fileurl}&amp;choose={$choose}\"><img src=\"{$CFG->pixpath}/f/folder.gif\" class=\"icon\" alt=\"{$strfolder}\" />&nbsp;" . htmlspecialchars($dir) . "</a>", 'name');
                print_cell("right", $filesize, 'size');
                print_cell("right", $filedate, 'date');
                if ($wdir . $dir === '/moddata') {
                    print_cell();
                } else {
                    print_cell("right", "<a href=\"index.php?id={$id}&amp;wdir={$wdir}&amp;file={$filesafe}&amp;action=rename&amp;choose={$choose}\">{$strrename}</a>", 'commands');
                }
            }
            echo "</tr>";
        }
    }
    if (!empty($filelist)) {
        asort($filelist);
        foreach ($filelist as $file) {
            $icon = mimeinfo("icon", $file);
            $count++;
            $filename = $fullpath . "/" . $file;
            $fileurl = trim($wdir, "/") . "/{$file}";
            $filesafe = rawurlencode($file);
            $fileurlsafe = rawurlencode($fileurl);
            $filedate = userdate(filemtime($filename), get_string("strftimedatetime"));
            $selectfile = trim($fileurl, "/");
            echo "<tr class=\"file\">";
            print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox');
            echo "<td align=\"left\" style=\"white-space:nowrap\" class=\"name\">";
            $ffurl = get_file_url($id . '/' . $fileurl);
            link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" />&nbsp;" . htmlspecialchars($file), 480, 640);
            echo "</td>";
            $file_size = filesize($filename);
            print_cell("right", display_size($file_size), 'size');
            print_cell("right", $filedate, 'date');
            if ($choose) {
                $edittext = "<strong><a onclick=\"return set_value('{$selectfile}')\" href=\"#\">{$strchoose}</a></strong>&nbsp;";
            } else {
                $edittext = '';
            }
            if ($icon == "text.gif" || $icon == "html.gif") {
                $edittext .= "<a href=\"index.php?id={$id}&amp;wdir={$wdir}&amp;file={$fileurl}&amp;action=edit&amp;choose={$choose}\">{$stredit}</a>";
            } else {
                if ($icon == "zip.gif") {
                    $edittext .= "<a href=\"index.php?id={$id}&amp;wdir={$wdir}&amp;file={$fileurl}&amp;action=unzip&amp;sesskey={$USER->sesskey}&amp;choose={$choose}\">{$strunzip}</a>&nbsp;";
                    $edittext .= "<a href=\"index.php?id={$id}&amp;wdir={$wdir}&amp;file={$fileurl}&amp;action=listzip&amp;sesskey={$USER->sesskey}&amp;choose={$choose}\">{$strlist}</a> ";
                    if (!empty($CFG->backup_version) and has_capability('moodle/site:restore', get_context_instance(CONTEXT_COURSE, $id))) {
                        $edittext .= "<a href=\"index.php?id={$id}&amp;wdir={$wdir}&amp;file={$filesafe}&amp;action=restore&amp;sesskey={$USER->sesskey}&amp;choose={$choose}\">{$strrestore}</a> ";
                    }
                }
            }
            print_cell("right", "{$edittext} <a href=\"index.php?id={$id}&amp;wdir={$wdir}&amp;file={$filesafe}&amp;action=rename&amp;choose={$choose}\">{$strrename}</a>", 'commands');
            echo "</tr>";
        }
    }
    echo "</table>";
    echo "<hr />";
    //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
    echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">";
    echo "<tr><td>";
    echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />";
    echo '<input type="hidden" name="choose" value="' . $choose . '" />';
    echo "<input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" /> ";
    echo "<input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />";
    $options = array("move" => "{$strmovetoanotherfolder}", "delete" => "{$strdeletecompletely}", "zip" => "{$strcreateziparchive}");
    if (!empty($count)) {
        choose_from_menu($options, "action", "", "{$strwithchosenfiles}...", "javascript:getElementById('dirform').submit()");
        echo '<div id="noscriptgo" style="display: inline;">';
        echo '<input type="submit" value="' . get_string('go') . '" />';
        echo '<script type="text/javascript">' . "\n//<![CDATA[\n" . 'document.getElementById("noscriptgo").style.display = "none";' . "\n//]]>\n" . '</script>';
        echo '</div>';
    }
    echo "</td></tr></table>";
    echo "</div>";
    echo "</form>";
    echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\"><tr>";
    echo "<td align=\"center\">";
    if (!empty($USER->fileop) and $USER->fileop == "move" and $USER->filesource != $wdir) {
        echo "<form action=\"index.php\" method=\"get\">";
        echo "<div>";
        echo ' <input type="hidden" name="choose" value="' . $choose . '" />';
        echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />";
        echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />";
        echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />";
        echo " <input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />";
        echo " <input type=\"submit\" value=\"{$strmovefilestohere}\" />";
        echo "</div>";
        echo "</form>";
    }
    echo "</td>";
    echo "<td align=\"right\">";
    echo "<form action=\"index.php\" method=\"get\">";
    echo "<div>";
    echo ' <input type="hidden" name="choose" value="' . $choose . '" />';
    echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />";
    echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />";
    echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />";
    echo " <input type=\"submit\" value=\"{$strmakeafolder}\" />";
    echo "</div>";
    echo "</form>";
    echo "</td>";
    echo "<td align=\"right\">";
    echo "<form action=\"index.php\" method=\"get\">";
    //dummy form - alignment only
    echo "<fieldset class=\"invisiblefieldset\">";
    echo " <input type=\"button\" value=\"{$strselectall}\" onclick=\"checkall();\" />";
    echo " <input type=\"button\" value=\"{$strselectnone}\" onclick=\"uncheckall();\" />";
    echo "</fieldset>";
    echo "</form>";
    echo "</td>";
    echo "<td align=\"right\">";
    echo "<form action=\"index.php\" method=\"get\">";
    echo "<div>";
    echo ' <input type="hidden" name="choose" value="' . $choose . '" />';
    echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />";
    echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />";
    echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
    echo " <input type=\"submit\" value=\"{$struploadafile}\" />";
    echo "</div>";
    echo "</form>";
    echo "</td></tr>";
    echo "</table>";
    echo "<hr/>";
    //echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
}
Esempio n. 24
0
 /**
  * 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;
     if (!$userid) {
         if (!isloggedin()) {
             return '';
         }
         $userid = $USER->id;
     }
     $filearea = $this->file_area_name($userid);
     $output = '';
     if ($basedir = $this->file_area($userid)) {
         if ($files = get_directory_list($basedir)) {
             require_once $CFG->libdir . '/filelib.php';
             foreach ($files as $key => $file) {
                 $icon = mimeinfo('icon', $file);
                 $ffurl = get_file_url("{$filearea}/{$file}", array('forcedownload' => 1));
                 // Syntax Highlighert source code
                 $viewlink = link_to_popup_window('/mod/assignment/type/onlinejudge/source.php?id=' . $this->cm->id . '&amp;userid=' . $userid . '&amp;file=' . $file, $file . 'sourcecode', get_string('preview'), 500, 740, $file, 'none', true, 'button' . $userid);
                 $output .= '<img src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" />' . '<a href="' . $ffurl . '" >' . $file . '</a> (' . $viewlink . ')<br />';
             }
         }
     }
     $output = '<div class="files">' . $output . '</div>';
     if ($return) {
         return $output;
     }
     echo $output;
 }
Esempio n. 25
0
		</div>
		<button type="button" class="btn btn-danger col-sm-1 pull-right" onclick="upload_all()">上传<span
				class="glyphicon glyphicon-cloud-upload"></span></button>
		<button type="button" class="btn btn-warning col-sm-1 upload_clear pull-right" onclick="image_clear()">清除</button>
	</div>
	<div class="well well-sm">
		<p class="help-block">已上传的图片:<a href="#" onclick="return uploaded_img_edit();">编辑</a>,
			<a href="#" onclick="return create_gallery();">创建图集</a></p>

		<div id="Uploaded"></div>
	</div>
	<div id="ImageList">
	</div>
</div>
<script src="<?php 
echo get_file_url("js/md5_sha1.js");
?>
" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
	if (!html5_file_upload()) {
		alert_error("当前浏览器不支持HTML5的图片上传!");
	}
});
var API_URL = '<?php 
echo get_url("UserApi", "picture_upload");
?>
';
var files_info = {files: {},//文件存储信息,是对象,非数组
	uid: {},//文件唯一ID
	count: 0, //当前队列计数
Esempio n. 26
0
/**
 * creates a media tag to use for choice media
 *
 * @param string $file the filename
 * @param string $courseid the course id
 * @param string $alt to specify the alt tag
 * @return string either an image tag, or html for an embedded object 
 */
function get_media_tag($file, $courseid = 0, $alt = 'media file', $width = 0, $height = 0)
{
    global $CFG;
    // if it's a moodle library file, it will be served through file.php
    if (substr(strtolower($file), 0, 7) == 'http://') {
        $media = $file;
    } else {
        require_once $CFG->libdir . '/filelib.php';
        $media = get_file_url("{$courseid}/{$file}");
    }
    $ismultimedia = false;
    if (!($isimage = is_image_by_extension($file))) {
        $ismultimedia = is_multimedia_by_extension($file);
    }
    // if there is no known width and height, try to get one
    if ($width == 0) {
        if ($isimage || is_sizable_multimedia($file)) {
        }
    }
    // create either an image link or a generic link.
    // if the moodle multimedia filter is turned on, it'll catch multimedia content in the generic link
    if (is_image_by_extension($file)) {
        return "<img src=\"{$media}\" alt=\"{$alt}\" width=\"{$width}\" height=\"{$height}\" />";
    } else {
        require_once "{$CFG->dirroot}/mod/quiz/format/qti/custommediafilter.php";
        return custom_mediaplugin_filter('<a href="' . $media . '"></a>', $courseid, $width, $height);
    }
}
Esempio n. 27
0
 /**
  * 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;
     if (!$userid) {
         if (!isloggedin()) {
             return '';
         }
         $userid = $USER->id;
     }
     $filearea = $this->file_area_name($userid);
     $output = '';
     if ($basedir = $this->file_area($userid)) {
         if ($files = get_directory_list($basedir)) {
             require_once $CFG->libdir . '/filelib.php';
             foreach ($files as $key => $file) {
                 $icon = mimeinfo('icon', $file);
                 $ffurl = get_file_url("{$filearea}/{$file}", array('forcedownload' => 1));
                 $output .= '<img src="' . $CFG->pixpath . '/f/' . $icon . '" class="icon" alt="' . $icon . '" />' . '<a href="' . $ffurl . '" >' . $file . '</a><br />';
             }
         }
     }
     $output = '<div class="files">' . $output . '</div>';
     if ($return) {
         return $output;
     }
     echo $output;
 }
Esempio n. 28
0
 function print_responsefiles($userid, $return = false)
 {
     global $CFG, $USER;
     $mode = optional_param('mode', '', PARAM_ALPHA);
     $offset = optional_param('offset', 0, PARAM_INT);
     $filearea = $this->file_area_name($userid) . '/responses';
     $output = '';
     $candelete = $this->can_manage_responsefiles();
     $strdelete = get_string('delete');
     if ($basedir = $this->file_area($userid)) {
         $basedir .= '/responses';
         if ($files = get_directory_list($basedir)) {
             require_once $CFG->libdir . '/filelib.php';
             foreach ($files as $key => $file) {
                 $icon = mimeinfo('icon', $file);
                 $ffurl = get_file_url("{$filearea}/{$file}");
                 $output .= '<a href="' . $ffurl . '" ><img src="' . $CFG->pixpath . '/f/' . $icon . '" alt="' . $icon . '" />' . $file . '</a>';
                 if ($candelete) {
                     $delurl = "{$CFG->wwwroot}/mod/assignment/delete.php?id={$this->cm->id}&amp;file={$file}&amp;userid={$userid}&amp;mode={$mode}&amp;offset={$offset}&amp;action=response";
                     $output .= '<a href="' . $delurl . '">&nbsp;' . '<img title="' . $strdelete . '" src="' . $CFG->pixpath . '/t/delete.gif" class="iconsmall" alt=""/></a> ';
                 }
                 $output .= '&nbsp;';
             }
         }
         $output = '<div class="responsefiles">' . $output . '</div>';
     }
     if ($return) {
         return $output;
     }
     echo $output;
 }
Esempio n. 29
0
function displaydir($wdir)
{
    //  $wdir == / or /a or /a/b/c/d  etc
    global $basedir;
    global $usecheckboxes;
    global $id;
    global $USER, $CFG;
    $fullpath = $basedir . $wdir;
    $directory = opendir($fullpath);
    // Find all files
    while (false !== ($file = readdir($directory))) {
        if ($file == "." || $file == "..") {
            continue;
        }
        if (is_dir($fullpath . "/" . $file)) {
            $dirlist[] = $file;
        } else {
            $filelist[] = $file;
        }
    }
    closedir($directory);
    $strfile = get_string("file");
    $strname = get_string("name");
    $strsize = get_string("size");
    $strmodified = get_string("modified");
    $straction = get_string("action");
    $strmakeafolder = get_string("makeafolder");
    $struploadafile = get_string("uploadafile");
    $strwithchosenfiles = get_string("withchosenfiles");
    $strmovetoanotherfolder = get_string("movetoanotherfolder");
    $strmovefilestohere = get_string("movefilestohere");
    $strdeletecompletely = get_string("deletecompletely");
    $strcreateziparchive = get_string("createziparchive");
    $strrename = get_string("rename");
    $stredit = get_string("edit");
    $strunzip = get_string("unzip");
    $strlist = get_string("list");
    $strchoose = get_string("choose");
    echo "<form action=\"coursefiles.php\" method=\"post\" name=\"dirform\">\n";
    echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"100%\">\n";
    if ($wdir == "/") {
        $wdir = "";
    } else {
        $bdir = str_replace("/" . basename($wdir), "", $wdir);
        if ($bdir == "/") {
            $bdir = "";
        }
        print "<tr>\n<td colspan=\"5\">";
        print "<a href=\"coursefiles.php?id={$id}&amp;wdir={$bdir}&amp;usecheckboxes={$usecheckboxes}\" onclick=\"return reset_value();\">";
        print "<img src=\"{$CFG->wwwroot}/lib/editor/htmlarea/images/folderup.gif\" height=\"14\" width=\"24\" border=\"0\" alt=\"" . get_string('parentfolder') . "\" />";
        print "</a></td>\n</tr>\n";
    }
    $count = 0;
    if (!empty($dirlist)) {
        asort($dirlist);
        foreach ($dirlist as $dir) {
            $count++;
            $filename = $fullpath . "/" . $dir;
            $fileurl = $wdir . "/" . $dir;
            $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
            echo "<tr>";
            if ($usecheckboxes) {
                print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" onclick=\"return set_rename('{$dir}');\" />");
            }
            print_cell("left", "<a href=\"coursefiles.php?id={$id}&amp;wdir={$fileurl}\" onclick=\"return reset_value();\"><img src=\"{$CFG->pixpath}/f/folder.gif\" class=\"icon\" alt=\"" . get_string('folder') . "\" /></a> <a href=\"coursefiles.php?id={$id}&amp;wdir={$fileurl}&amp;usecheckboxes={$usecheckboxes}\" onclick=\"return reset_value();\">" . htmlspecialchars($dir) . "</a>");
            print_cell("right", "&nbsp;");
            print_cell("right", $filedate);
            echo "</tr>";
        }
    }
    if (!empty($filelist)) {
        asort($filelist);
        foreach ($filelist as $file) {
            $icon = mimeinfo("icon", $file);
            $imgtype = mimeinfo("type", $file);
            $count++;
            $filename = $fullpath . "/" . $file;
            $fileurl = "{$wdir}/{$file}";
            $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
            $dimensions = get_image_size($filename);
            if ($dimensions) {
                $imgwidth = $dimensions[0];
                $imgheight = $dimensions[1];
            } else {
                $imgwidth = "Unknown";
                $imgheight = "Unknown";
            }
            unset($dimensions);
            echo "<tr>\n";
            if ($usecheckboxes) {
                print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" onclick=\";return set_rename('{$file}');\" />");
            }
            echo "<td align=\"left\" nowrap=\"nowrap\">";
            $ffurl = get_file_url($id . $fileurl);
            link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" />", 480, 640);
            $file_size = filesize($filename);
            echo "<a onclick=\"return set_value(info = {url: '" . $ffurl . "',";
            echo " isize: '" . $file_size . "', itype: '" . $imgtype . "', iwidth: '" . $imgwidth . "',";
            echo " iheight: '" . $imgheight . "', imodified: '" . $filedate . "' })\" href=\"#\">{$file}</a>";
            echo "</td>\n";
            if ($icon == "zip.gif") {
                $edittext = "<a href=\"coursefiles.php?id={$id}&amp;wdir={$wdir}&amp;file={$fileurl}&amp;action=unzip&amp;sesskey={$USER->sesskey}\">{$strunzip}</a>&nbsp;";
                $edittext .= "<a href=\"coursefiles.php?id={$id}&amp;wdir={$wdir}&amp;file={$fileurl}&amp;action=listzip&amp;sesskey={$USER->sesskey}\">{$strlist}</a> ";
            } else {
                $edittext = "&nbsp;";
            }
            print_cell("right", "{$edittext} ");
            print_cell("right", $filedate);
            echo "</tr>\n";
        }
    }
    echo "</table>\n";
    if (empty($wdir)) {
        $wdir = "/";
    }
    echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\">\n";
    echo "<tr>\n<td>";
    echo "<input type=\"hidden\" name=\"id\" value=\"{$id}\" />\n";
    echo "<input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />\n";
    echo "<input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />\n";
    $options = array("move" => "{$strmovetoanotherfolder}", "delete" => "{$strdeletecompletely}", "zip" => "{$strcreateziparchive}");
    if (!empty($count)) {
        choose_from_menu($options, "action", "", "{$strwithchosenfiles}...", "javascript:getElementById('dirform').submit()");
    }
    if (!empty($USER->fileop) and $USER->fileop == "move" and $USER->filesource != $wdir) {
        echo "<form action=\"coursefiles.php\" method=\"get\">\n";
        echo " <input type=\"hidden\" name=\"id\" value=\"{$id}\" />\n";
        echo " <input type=\"hidden\" name=\"wdir\" value=\"{$wdir}\" />\n";
        echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />\n";
        echo " <input type=\"hidden\" name=\"sesskey\" value=\"{$USER->sesskey}\" />\n";
        echo " <input type=\"submit\" value=\"{$strmovefilestohere}\" />\n";
        echo "</form>";
    }
    echo "</td></tr>\n";
    echo "</table>\n";
    echo "</form>\n";
}
Esempio n. 30
0
/**
 * Print a specified group's avatar.
 *
 * @param group $group A single {@link group} object OR array of groups.
 * @param int $courseid The course ID.
 * @param boolean $large Default small picture, or large.
 * @param boolean $return If false print picture, otherwise return the output as string
 * @param boolean $link Enclose image in a link to view specified course?
 * @return string
 * @todo Finish documenting this function
 */
function print_group_picture($group, $courseid, $large = false, $return = false, $link = true)
{
    global $CFG;
    if (is_array($group)) {
        $output = '';
        foreach ($group as $g) {
            $output .= print_group_picture($g, $courseid, $large, true, $link);
        }
        if ($return) {
            return $output;
        } else {
            echo $output;
            return;
        }
    }
    $context = get_context_instance(CONTEXT_COURSE, $courseid);
    if ($group->hidepicture and !has_capability('moodle/course:managegroups', $context)) {
        return '';
    }
    if ($link or has_capability('moodle/site:accessallgroups', $context)) {
        $output = '<a href="' . $CFG->wwwroot . '/user/index.php?id=' . $courseid . '&amp;group=' . $group->id . '">';
    } else {
        $output = '';
    }
    if ($large) {
        $file = 'f1';
    } else {
        $file = 'f2';
    }
    if ($group->picture) {
        // Print custom group picture
        require_once $CFG->libdir . '/filelib.php';
        $grouppictureurl = get_file_url($group->id . '/' . $file . '.jpg', null, 'usergroup');
        $output .= '<img class="grouppicture" src="' . $grouppictureurl . '"' . ' alt="' . s(get_string('group') . ' ' . $group->name) . '" title="' . s($group->name) . '"/>';
    }
    if ($link or has_capability('moodle/site:accessallgroups', $context)) {
        $output .= '</a>';
    }
    if ($return) {
        return $output;
    } else {
        echo $output;
    }
}