Ejemplo n.º 1
0
function file_folder_view($folder)
{
    global $CFG;
    /*
     *    View a specific folder
     *    (Access rights are presumed)
     */
    // Find out who's the owner
    global $page_owner;
    $owner_username = user_info('username', $page_owner);
    // If we're not in the parent folder, provide a link to return to the parent
    /*
    if ($folder->ident != -1) {
        $folder->name = stripslashes($folder->name);
    }
    */
    $body = "<h2>" . $folder->name . "</h2>";
    // Firstly, get a list of folders
    // Display folders we actually have access to
    if ($folder->idents = get_records_select('file_folders', "parent = {$folder->ident} AND (" . run("users:access_level_sql_where") . ") and files_owner = {$page_owner}")) {
        $subFolders = __gettext("Subfolders");
        // gettext variable
        $body .= <<<END

                            <h3>
                                {$subFolders}
                            </h3>

END;
        foreach ($folder->idents as $folder->ident_details) {
            if (run("users:access_level_check", $folder->ident_details->access) == true) {
                $username = $owner_username;
                $ident = (int) $folder->ident_details->ident;
                $name = get_access_description($folder->ident_details->access);
                $name .= stripslashes($folder->ident_details->name);
                $folder->identmenu = file_folder_edit_links($folder->ident_details);
                $keywords = display_output_field(array("", "keywords", "folder", "folder", $ident, $folder->ident_details->owner));
                if ($keywords) {
                    $keywords = __gettext("Keywords: ") . $keywords;
                }
                $body .= templates_draw(array('context' => 'folder', 'username' => $username, 'url' => $CFG->wwwroot . "{$username}/files/{$ident}", 'ident' => $ident, 'name' => $name, 'menu' => $folder->identmenu, 'icon' => $CFG->wwwroot . "mod/file/folder.png", 'keywords' => $keywords));
            }
        }
    }
    // Then get a list of files
    // View files we actually have access to
    if ($files = get_records_select('files', "folder = ? AND files_owner = ?", array($folder->ident, $page_owner))) {
        foreach ($files as $file) {
            if (run("users:access_level_check", $file->access) == true || $file->owner == $_SESSION['userid']) {
                $username = $owner_username;
                $ident = (int) $file->ident;
                $folder->ident = $file->folder;
                $title = get_access_description($file->access);
                $title .= stripslashes($file->title);
                $description = nl2br(stripslashes($file->description));
                $filetitle = urlencode($title);
                $originalname = stripslashes($file->originalname);
                $filemenu = round($file->size / 1048576, 4) . "MB ";
                $icon = $CFG->wwwroot . "_icon/file/" . $file->ident;
                $filepath = $CFG->wwwroot . "{$username}/files/{$folder->ident}/{$ident}/" . urlencode($originalname);
                $mimetype = mimeinfo('type', $file->originalname);
                if ($mimetype == "audio/mpeg" || $mimetype == "audio/mp3") {
                    $filemenu .= " <object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\"\n        codebase=\"http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0\"\n        width=\"17\" height=\"17\" >\n            <param name=\"allowScriptAccess\" value=\"sameDomain\" />\n            <param name=\"movie\" value=\"" . $CFG->wwwroot . "mod/file/mp3player/musicplayer.swf?song_url={$filepath}&amp;song_title={$filetitle}\" />\n            <param name=\"quality\" value=\"high\" />\n            <embed src=\"" . $CFG->wwwroot . "mod/file/mp3player/musicplayer.swf?song_url={$filepath}&amp;song_title={$filetitle}\"\n            quality=\"high\" bgcolor=\"#E6E6E6\" name=\"xspf_player\" allowscriptaccess=\"sameDomain\"\n            type=\"application/x-shockwave-flash\"\n            pluginspage=\"http://www.macromedia.com/go/getflashplayer\"\n            align=\"center\" height=\"17\" width=\"17\" />\n        </object>";
                }
                $filemenu = file_edit_links($file);
                $keywords = display_output_field(array("", "keywords", "file", "file", $ident, $file->owner));
                if ($keywords) {
                    $keywords = __gettext("Keywords: ") . $keywords;
                }
                $body .= templates_draw(array('context' => 'file', 'username' => $username, 'title' => $title, 'ident' => $ident, 'folder' => $folder->ident, 'description' => $description, 'originalname' => $originalname, 'url' => $filepath, 'menu' => $filemenu, 'icon' => $icon, 'keywords' => $keywords));
                $body .= display_run_displayobjectannotations($file, "file::file");
            }
        }
    }
    // Deliver an apologetic message if there aren't any files or folders
    if (empty($files) && empty($folder->idents)) {
        $body .= "<p>" . __gettext("This folder is currently empty.") . "</p>";
    }
    return $body;
}
Ejemplo n.º 2
0
function photogallery_folder_view($folder)
{
    global $CFG, $metatags, $messages;
    require_once $CFG->dirroot . 'lib/filelib.php';
    $metatags .= file_get_contents($CFG->dirroot . "mod/photogallery/css");
    $metatags .= <<<END
        <script type="text/javascript">
            var elggWwwRoot = "{$CFG->wwwroot}";
        </script>
        <script type="text/javascript" src="{$CFG->wwwroot}mod/photogallery/lightbox/js/prototype.js"></script>
        <script type="text/javascript" src="{$CFG->wwwroot}mod/photogallery/lightbox/js/scriptaculous.js?load=effects"></script>
        <script type="text/javascript" src="{$CFG->wwwroot}mod/photogallery/lightbox/js/lightbox.js"></script>
        <link rel="stylesheet" href="{$CFG->wwwroot}mod/photogallery/lightbox/css/lightbox.css" type="text/css" media="screen" />

END;
    $file_html = "";
    $photo_html = "";
    $folder_html = "";
    // Get all the files in this folder
    if ($files = get_records_select('files', "folder = ? AND files_owner = ? ORDER BY time_uploaded desc", array($folder->ident, $folder->files_owner))) {
        foreach ($files as $file) {
            if (run("users:access_level_check", $file->access) == true) {
                $image = $CFG->wwwroot . "_files/icon.php?id=" . $file->ident . "&amp;w=200&amp;h=200";
                $filepath = $CFG->wwwroot . user_info("username", $file->files_owner) . "/files/{$folder->ident}/{$file->ident}/" . urlencode($file->originalname);
                $image = "<a href=\"{$CFG->wwwroot}_files/icon.php?id={$file->ident}&w=500&h=500\" rel=\"lightbox[folder]\"><img src=\"{$image}\" /></a>";
                $fileinfo = round($file->size / 1048576, 4) . "Mb";
                $filelinks = file_edit_links($file);
                $uploaded = sprintf(__gettext("Uploaded on %s"), strftime("%A, %d %B %Y", $file->time_uploaded));
                $keywords = display_output_field(array("", "keywords", "file", "file", $file->ident, $file->owner));
                $mimetype = mimeinfo('type', $file->originalname);
                if (empty($file->title)) {
                    $file->title = __gettext("No title");
                }
                if (substr_count($mimetype, "image") > 0) {
                    $photo_html .= <<<END

                            <div class="photogallery-photo-container">
                                <div class="photogallery-photo-image">
                                    {$image}
                                </div>
                                <div class="photogallery-photo-info">
                                    <h2 class="photogallery-photo-title"><a href="{$filepath}" >{$file->title}</a></h2>
                                    <p class="photogallery-photo-description">
                                        {$file->description}
                                    </p>
                                    <p class="photogallery-photo-keywords">
                                        {$keywords}
                                    </p>
                                    <p class="photogallery-photo-infobar">
                                        {$uploaded}<br />
                                        {$fileinfo} {$mimetype} {$filelinks}
                                    </p>
                                </div>
                            </div>

END;
                } else {
                    $file_html .= <<<END

                            <div class="photogallery-file-container">
                                <div class="photogallery-file-image">
                                    <a href="{$filepath}">{$image}</a>
                                </div>
                                <div class="photogallery-file-info">
                                    <h2 class="photogallery-file-title"><a href="{$filepath}">{$file->title}</a></h2>
                                    <p>{$file->description}</p>
                                    <p class="photogallery-file-keywords">
                                        {$keywords}
                                    </p>
                                    <p class="photogallery-file-infobar">
                                        {$uploaded}<br />
                                        {$fileinfo} {$mimetype} {$filelinks}
                                    </p>
                                </div>
                            </div>

END;
                }
            }
        }
    }
    if ($subfolders = get_records_select('file_folders', "parent = ? AND files_owner = ? ORDER BY name desc", array($folder->ident, $folder->owner))) {
        foreach ($subfolders as $subfolder) {
            $folderlinks = file_folder_edit_links($subfolder);
            $keywords = display_output_field(array("", "keywords", "folder", "folder", $subfolder->ident, $subfolder->owner));
            $filepath = $CFG->wwwroot . user_info("username", $folder->files_owner) . "/files/" . $subfolder->ident;
            $folder_html .= <<<END

                        <div class="photogallery-file-container">
                            <div class="photogallery-file-image">
                                <a href="{$filepath}"><img src="{$CFG->wwwroot}_files/folder.png" /></a>
                            </div>
                            <div class="photogallery-file-info">
                                <h2 class="photogallery-file-title"><a href="{$filepath}">{$subfolder->name}</a></h2>
                                <p class="photogallery-file-keywords">
                                    {$keywords}
                                </p>
                                <p class="photogallery-file-infobar">
                                    {$folderlinks}
                                </p>
                            </div>
                        </div>

END;
        }
    }
    if (!empty($file_html)) {
        $file_html = "<h2>" . __gettext("Non-photo files") . "</h2>" . $file_html;
    }
    if (!empty($folder_html)) {
        $folder_html = "<h2>" . __gettext("Subfolders") . "</h2>" . $folder_html;
    }
    $body = $photo_html . $file_html . $folder_html;
    if (empty($body)) {
        $body = "<p>" . __gettext("This folder is currently empty.") . "</p>";
    }
    return $body;
}