예제 #1
0
function displaydir($wdir)
{
    //  $wdir == / or /a or /a/b/c/d  etc
    # HU, CS Repository plugin support
    global $basedir, $repository, $scheme;
    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;
        }
        # HU, CS Repository plugin support
        if (repository_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
                # HU, CS Repository plugin support
                print_cell('left', '<a href="index.php?id=' . $id . '&amp;wdir=' . $fileurl . '&amp;choose=' . $choose . $repository->get_arg() . '"><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);
                # HU, CS Repository plugin support
                $filesize = display_size(repository_get_directory_size("{$fullpath}/{$dir}"));
                # HU, CS Repository plugin support
                $filedate = userdate(repository_filemtime($filename), "%d %b %Y, %I:%M %p");
                print_cell("center", "<input type=\"checkbox\" name=\"file{$count}\" value=\"{$fileurl}\" />", 'checkbox');
                # HU, CS Repository plugin support
                print_cell("left", "<a href=\"index.php?id={$id}&amp;wdir={$fileurl}&amp;choose={$choose}" . $repository->get_arg() . "\"><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');
                print_cell("right", "<a href=\"index.php?id={$id}&amp;wdir={$wdir}&amp;file={$filesafe}&amp;action=rename&amp;choose={$choose}" . $repository->get_arg() . "\">{$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);
            # HU, CS Repository plugin support
            $filedate = userdate(repository_filemtime($filename), "%d %b %Y, %I:%M %p");
            $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\">";
            # HU, CS Repository plugin support
            $ffurl = $repository->get_url($fileurl, $id);
            repository_link_to_popup_window($ffurl, "display", "<img src=\"{$CFG->pixpath}/f/{$icon}\" class=\"icon\" alt=\"{$strfile}\" />&nbsp;" . htmlspecialchars($file), 480, 640);
            echo "</td>";
            # HU, CS Repository plugin support
            $file_size = repository_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}" . $repository->get_arg() . "\">{$stredit}</a>";
            } else {
                if ($icon == "zip.gif") {
                    # HU, CS Repository plugin support
                    /* not supported 
                       $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}" . $repository->get_arg() . "\">{$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}\" />";
    # HU, CS Repository plugin support
    echo " <input type=\"hidden\" name=\"repository\" value=\"" . $scheme . "\" />";
    $options = array("move" => "{$strmovetoanotherfolder}", "delete" => "{$strdeletecompletely}");
    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') . '" /></div>';
        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}\" />";
        # HU, CS Repository plugin support
        echo " <input type=\"hidden\" name=\"repository\" value=\"" . $scheme . "\" />";
        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\" />";
    # HU, CS Repository plugin support
    echo " <input type=\"hidden\" name=\"repository\" value=\"" . $scheme . "\" />";
    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\" />";
    # HU, CS Repository Plugin support
    echo " <input type=\"hidden\" name=\"repository\" value=\"" . $scheme . "\" />";
    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\" />";
}
예제 #2
0
function repository_get_directory_size($rootdir, $excludefile = '')
{
    global $CFG;
    if (($r = repository_is_local($rootdir)) !== false) {
        return get_directory_size($r->local_path($rootdir), $excludefile);
    }
    if (!repository_is_dir($rootdir)) {
        // Must be a directory
        return 0;
    }
    if (!($dir = @opendir($rootdir))) {
        // Can't open it for some reason
        return 0;
    }
    $size = 0;
    while (false !== ($file = readdir($dir))) {
        $firstchar = substr($file, 0, 1);
        if ($firstchar == '.' or $file == 'CVS' or $file == $excludefile) {
            continue;
        }
        $fullfile = $rootdir . '/' . $file;
        if (repository_is_dir($fullfile)) {
            $size += repository_get_directory_size($fullfile, $excludefile);
        } else {
            $size += repository_filesize($fullfile);
        }
    }
    closedir($dir);
    return $size;
}
예제 #3
0
 function get_cached_enclosure()
 {
     global $CFG;
     // need to calculate mimetype and length?
     if ($this->enclosure && (!$this->enclosureurl || !$this->enclosuretype || !$this->enclosurelength) || !$this->enclosure && $this->enclosureurl) {
         @(include_once $CFG->libdir . '/filelib.php');
         $r =& $this->channelObj->get_repository();
         $updateObj = new object();
         $updateObj->id = $this->id;
         $this->enclosureurl = $updateObj->enclosureurl = '';
         $this->enclosuretype = $updateObj->enclosuretype = '';
         $this->enclosurelength = $updateObj->enclosurelength = 0;
         if ($r && ($url = $r->get_url($r->prefix . '://' . $this->enclosure, $this->channelObj->course)) !== '') {
             $this->enclosureurl = $updateObj->enclosureurl = $url;
             $this->enclosuretype = $updateObj->enclosuretype = mimeinfo('type', $this->enclosure);
             $this->enclosurelength = $updateObj->enclosurelength = repository_filesize($r->prefix . '://' . $this->channelObj->course . '/' . $this->enclosure);
         }
         update_record('podcaster_item', $updateObj);
     }
     if ($this->enclosureurl) {
         $result = new object();
         $result->name = $this->enclosure;
         $result->url = $this->enclosureurl;
         $result->type = $this->enclosuretype;
         $result->length = $this->enclosurelength;
     } else {
         $result = NULL;
     }
     return $result;
 }