Exemple #1
0
function FormatDisplayedItem($ItemID, $FileName, $FileSize, $HandlerMethod, &$Params, $Config)
{
    $FolderPath = substr($Config->CurrentBrowsingDirectory, strlen($Config->CurrentWorkingDirectory) + 1, strlen($Config->CurrentBrowsingDirectory) - strlen($Config->CurrentWorkingDirectory) + 1);
    $FolderPath = $FolderPath != "" ? $FolderPath . "/" . $FileName : $FileName;
    $EncodedPath = EncodeLinkUrl(FilePath(CurrentWebPath(), $FolderPath));
    $Params->Add("gid", $ItemID);
    $Return = "<input type=\"hidden\" name=\"Item{$ItemID}\" value=\"" . $EncodedPath . "\" />\r\n      <div class=\"DisplayItem\">\r\n         <h2><a href=\"" . CurrentWebPath() . $FolderPath . "\">{$FileName}</a></h2>\r\n         <ul class=\"Options\">\r\n            <li class=\"Save\"><a href=\"" . CurrentUrl() . $Params->GetQueryString() . "\">Save</a></li>\r\n            <li class=\"Copy\"><a href=\"Javascript:copy(document.frmLinkContainer.Item{$ItemID});\">Copy url</a></li>\r\n";
    $Handled = false;
    $Params->Remove("gid");
    switch ($HandlerMethod) {
        case "Image":
            $Handled = true;
            $Return .= "<input type=\"hidden\" name=\"ImgTag{$ItemID}\" value='<img src=\"" . $EncodedPath . "\" />' />\r\n               <li class=\"CopyImg\"><a href=\"Javascript:copy(document.frmLinkContainer.ImgTag{$ItemID});\">Copy img tag</a></li>\r\n            </ul>\r\n            <div class=\"DisplayItemImage\">";
            if ($Config->FitImagesToPage) {
                $ImageSize = @getimagesize($FolderPath);
                if ($ImageSize) {
                    $Return .= "<script>writeImage('{$EncodedPath}', " . $ImageSize[0] . ", " . $ImageSize[1] . ", '" . $ItemID . "');</script>";
                } else {
                    $Return .= "<img src=\"{$EncodedPath}\" alt=\"\" />";
                }
            } else {
                $Return .= "<img src=\"{$EncodedPath}\" alt=\"\" />";
            }
            $Return .= "</div>\r\n";
            break;
        case "IFrame":
            $Handled = true;
            $Return .= "<li class=\"CopyImg\"><a href=\"Javascript:copy(document.frmLinkContainer.AnchorTag{$ItemID});\">Copy anchor tag</a></li>\r\n            <input type=\"hidden\" name=\"AnchorTag{$ItemID}\" value=\"<a href='" . $EncodedPath . "'>" . CurrentWebPath() . $FolderPath . "</a>\" />\r\n            <li class=\"View\"><a href=\"" . CurrentWebPath() . $FolderPath . "\" target=\"_blank\">View</a></li>\r\n            </ul>\r\n         <div class=\"DisplayItemIFrame\"><iframe src=\"{$FolderPath}\"></iframe></div>\r\n";
            break;
        case "TextArea":
            $Handled = true;
            // Retrieve the file contents
            $File = new File();
            $File->Name = $FolderPath;
            $File->Path = "./";
            $FileManager = new FileManager();
            $FileManager->ErrorManager =& $Config->ErrorManager;
            $File = $FileManager->Get($File);
            if (!$File) {
                $FauxContext = "0";
                $Config->ErrorManager->AddError($FauxContext, "Filebrowser", "FormatDisplayedItem", "An error occurred while retrieving the file contents.", "", 0);
                $FileContents = $Config->ErrorManager->GetSimple();
            } else {
                // Make sure that a "</textarea>" tag doesn't kill my textarea
                $FileContents = str_replace("<", "&#60;", $File->Body);
            }
            $Return .= "<li class=\"CopyImg\"><a href=\"Javascript:copy(document.frmLinkContainer.AnchorTag{$ItemID});\">Copy anchor tag</a></li>\r\n            <input type=\"hidden\" name=\"AnchorTag{$ItemID}\" value='<a href=\"" . $EncodedPath . "\">" . CurrentWebPath() . $FolderPath . "</a>' />\r\n            <li class=\"View\"><a href=\"" . CurrentWebPath() . $FolderPath . "\" target=\"_blank\">View</a></li>\r\n            </ul>\r\n         <div class=\"DisplayItemTextArea\"><textarea>{$FileContents}</textarea></div>\r\n";
            break;
        case "EmbedFlash":
            $Handled = true;
            $EmbedString = "<object type=\"application/x-shockwave-flash\" data=\"" . $EncodedPath . "\"";
            if ($Config->PluginHeight > 0 && $Config->PluginWidth > 0) {
                $EmbedString .= " height=\"" . $Config->PluginHeight . "\" width=\"" . $Config->PluginWidth . "\"";
            }
            $EmbedString .= "><param name=\"movie\" value=\"" . $EncodedPath . "\" />You do not appear to have the latest flash plugin installed</object>";
            $Return .= "<li class=\"CopyImg\"><a href=\"Javascript:copy(document.frmLinkContainer.EmbedTag{$ItemID});\">Copy embed tag</a></li>\r\n            <input type=\"hidden\" name=\"EmbedTag{$ItemID}\" value='" . $EmbedString . "' />\r\n            </ul>\r\n            <div class=\"DisplayItemFlash\">" . $EmbedString . "</div>\r\n";
            break;
        case "Embed":
            $Handled = true;
            $EmbedString = "<embed src='" . CurrentWebPath() . $FolderPath . "'></embed>";
            $Return .= "<li class=\"CopyImg\"><a href=\"Javascript:copy(document.frmLinkContainer.EmbedTag{$ItemID});\">Copy embed tag</a></li>\r\n            <input type=\"hidden\" name=\"EmbedTag{$ItemID}\" value=\"" . $EmbedString . "\" />\r\n            </ul>\r\n         <div class=\"DisplayItemEmbed\">" . $EmbedString . "</div>\r\n";
            break;
        case "EmbedQuicktime":
            $Handled = true;
            $EmbedString = "<embed src='" . $EncodedPath . "'";
            if ($Config->PluginHeight > 0 && $Config->PluginWidth > 0) {
                $EmbedString .= " height='" . $Config->PluginHeight . "' width='" . $Config->PluginWidth . "'";
            }
            $EmbedString .= "></embed>";
            $Return .= "<li class=\"CopyImg\"><a href=\"Javascript:copy(document.frmLinkContainer.EmbedTag{$ItemID});\">Copy embed tag</a></li>\r\n            <input type=\"hidden\" name=\"EmbedTag{$ItemID}\" value=\"" . $EmbedString . "\" />\r\n            </ul>\r\n         <div class=\"DisplayItemEmbed\">" . $EmbedString . "</div>\r\n";
            break;
        default:
            // HyperLink handler method
            $Return .= "</ul>\r\n         <div class=\"DisplayItemBlank\"></div>\r\n";
            $Handled = true;
            break;
    }
    if (!$Handled) {
        $Return = "";
    } else {
        $Return .= "</div>\r\n";
    }
    return $Return;
}
    reset($FolderCollection);
    if ($Config->SortDirection == "desc") {
        $FolderCollection = array_reverse($FolderCollection);
    }
    // Add actual folders
    for ($i = 0; $i < count($FolderCollection); $i++) {
        $Params->Set("did", FormatDelimitedString($Config->FolderIDs, $i, $Config->FolderDelimiter));
        $FileList .= "<li>\r\n         <a href=\"" . CurrentUrl() . $Params->GetQueryString() . "\">" . $FolderCollection[$i] . "</a>\r\n         </li>";
    }
    $FileList .= "</ul>\r\n";
}
// ------------------
// 5. WRITE PAGE HEAD
// ------------------
// Define the current folder path
$RootPath = substr(CurrentWebPath(), 0, strlen(CurrentWebPath()) - 1);
$CurrentPath = "<a href=\"{$RootPath}?fpp=" . $Config->FilesPerPage . "\">" . str_replace("http://", "", $RootPath) . "</a>";
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en-ca\">\r\n   <head>\r\n   <title>" . $Config->PageTitle . "</title>\r\n\r\n   <link rel=\"stylesheet\" type=\"text/css\" href=\"" . $Config->StyleUrl . "\" />\r\n\r\n   <script language=\"Javascript\" type=\"text/javascript\">\r\n      //<![CDATA[\r\n      var BodyLoaded = 0;\r\n      if (document.all && !document.getElementById) {\r\n          document.getElementById = function(id) {\r\n               return document.all[id];\r\n          }\r\n      }\r\n      function copy(inElement) {\r\n         if (inElement.createTextRange) {\r\n            var range = inElement.createTextRange();\r\n            if (range && BodyLoaded==1) range.execCommand('Copy');\r\n         } else {\r\n            var flashcopier = 'flashcopier';\r\n            if(!document.getElementById(flashcopier)) {\r\n               var divholder = document.createElement('div');\r\n               divholder.id = flashcopier;\r\n               document.body.appendChild(divholder);\r\n            }\r\n            document.getElementById(flashcopier).innerHTML = '';\r\n            var divinfo = '<embed src=\"_clipboard.swf\" FlashVars=\"clipboard='+escape(inElement.value)+'\" width=\"0\" height=\"0\" type=\"application/x-shockwave-flash\"></embed>';\r\n            document.getElementById(flashcopier).innerHTML = divinfo;\r\n         }\r\n      }\r\n      function writeImage(imageName, imageWidth, imageHeight, imageID) {\r\n         var windowWidth = getWindowWidth();\r\n         if (windowWidth < imageWidth) {\r\n            var newWidth = windowWidth - 40;\r\n            var newHeight = Math.round((newWidth*imageHeight)/(imageWidth+40));\r\n\r\n            document.write('<span id=\"sm'+imageID+'\">'\r\n               +'<div class=\"Notice\">Note: this image has been shrunk to fit on your screen. <a href=\"Javascript:resizeImage('+imageID+');\">Click here to view the image at actual size.</a></div>'\r\n               +'<img src=\"'+imageName+'\" height=\"'+newHeight+'\" width=\"'+newWidth+'\" />'\r\n            +'</span>'\r\n            +'<span id=\"lg'+imageID+'\" style=\"display: none;\">'\r\n               +'<div class=\"Notice\">Note: this image does not fit on your screen. <a href=\"Javascript:resizeImage('+imageID+');\">Click here to fit the image to your screen.</a></div>'\r\n               +'<img src=\"'+imageName+'\" height=\"'+imageHeight+'\" width=\"'+imageWidth+'\" />'\r\n            +'</span>');\r\n         } else {\r\n            document.write('<img src=\"'+imageName+'\" height=\"'+imageHeight+'\" width=\"'+imageWidth+'\" />');\r\n         }\r\n      }\r\n      function getWindowWidth() {\r\n         var myWidth = 0;\r\n         if( typeof( window.innerWidth ) == 'number' ) {\r\n            myWidth = window.innerWidth - 20;\r\n         } else if (document.documentElement && document.documentElement.clientWidth) {\r\n            myWidth = document.documentElement.clientWidth;\r\n         } else if (document.body && document.body.clientWidth) {\r\n            myWidth = document.body.clientWidth;\r\n         } else {\r\n            myWidth = screen.width;\r\n         }\r\n         return myWidth;\r\n      }\r\n      function resizeImage(imageID, link) {\r\n         var lg = document.getElementById('lg'+imageID);\r\n         var sm = document.getElementById('sm'+imageID);\r\n         if (lg && sm) {\r\n            switchVisibility(lg);\r\n            switchVisibility(sm);\r\n         }\r\n      }\r\n      function switchVisibility(object) {\r\n         if (object.style.display == 'none') {\r\n            object.style.display = 'block';\r\n         } else {\r\n            object.style.display = 'none';\r\n         }\r\n      }\r\n      //]]>\r\n   </script>\r\n   </head>\r\n   <body onload=\"BodyLoaded=1\">\r\n      <div class=\"SiteContainer\">\r\n      <div class=\"Head\">\r\n         <h1>" . $Config->PageTitle . "</h1>\r\n         " . $CurrentPath . BuildPath($Config->FolderNavigator, $Config->FilesPerPage) . "\r\n      </div>";
// ------------------------------------
// 6. CONFIGURE & WRITE NAVIGATION MENU
// ------------------------------------
$TotalItemCount = ForceInt(count($aItemHistory), 0);
if ($TotalItemCount > 0) {
    $TotalItemCount = $TotalItemCount - 1;
}
$FirstItem = $TotalItemCount == 0 ? false : $aItemHistory[0];
$LastItem = $TotalItemCount == 0 ? false : $aItemHistory[$TotalItemCount];
$NextItem = false;
$PreviousItemGroup = false;
$PreviousItem = false;
// If viewing a file, check to see if the file id exists in the item history