ObjectFactory->NewObject($Context, "Error"); } else { $Error = new Error2(); } $Error->AffectedElement = $AffectedElement; $Error->AffectedFunction = $AffectedFunction; $Error->Message = $Message; $Error->Code = $Code; $this->Errors[] = $Error; $this->ErrorCount += 1; if ($WriteAndKill == 1) $this->Write($Context); } function Clear() { $this->ErrorCount = 0; $this->Errors = array(); } function ErrorManager() { $this->Clear(); } function Iif($True = "1", $False = "0") { if ($this->ErrorCount == 0) { return $True; } else { return $False; } } function Write(&$Context) { echo(" The page could not be displayed "); if ($this->StyleSheet == "") { echo(" "); } else { echo("StyleSheet."\" />\r\n"); } echo("

A fatal, non-recoverable error has occurred

Technical information (for support personel):

"); for ($i = 0; $i < count($this->Errors); $i++) { echo("

Error Message: ".ForceString($this->Errors[$i]->Message, "No error message supplied")."

Affected Elements: ".ForceString($this->Errors[$i]->AffectedElement, "undefined").".".ForceString($this->Errors[$i]->AffectedFunction, "undefined")."();

"); $Code = ForceString($this->Errors[$i]->Code, ""); if ($Code != "") { echo("

The error occurred on or near:

".$Code." "); } } if ($Context) { if ($Context->Mode == agMODE_DEBUG && $Context->SqlCollector) { echo("

Database queries run prior to error

"); $Context->SqlCollector->Write(); } } echo("
For additional support documentation, visit the Lussumo Software support website at: lussumo.com/support
"); // Cleanup if ($Context) $Context->Unload(); die(); } function GetSimple() { $sReturn = ""; for ($i = 0; $i < count($this->Errors); $i++) { $sReturn .= ForceString($this->Errors[$i]->Message, "No error message supplied\r\n"); } return $sReturn; } } class Parameters { var $aParameters = array(); // Add an element to the collection function Add($Name, $Value, $EncodeValue = 1) { if ($EncodeValue && !is_array($Value)) $Value = urlencode($Value); $this->aParameters[$Name] = $Value; } // Completely clear the collection function Clear() { $this->aParameters = array(); } // Return a count of how many elements are in the collection function Count() { return count($this->aParameters); } // Retrieves all get and post variables function DefineCollection($Collection, $ParameterPrefix = "", $IncludeByPrefix = "0", $ExcludeByPrefix = "0") { $ParameterPrefix = ForceString($ParameterPrefix, ""); $IncludeByPrefix = ForceBool($IncludeByPrefix, 0); $ExcludeByPrefix = ForceBool($ExcludeByPrefix, 0); $Add = 1; while (list($key, $value) = each($Collection)) { $Add = 1; if ($ParameterPrefix != "") { $PrefixMatchLocation = strstr($key, $ParameterPrefix); // If the prefix isn't found or the location is anywhere other than 0 (the start of the variable name) if ($PrefixMatchLocation === false || $PrefixMatchLocation != 0) { if ($IncludeByPrefix) $Add = 0; } else { if ($ExcludeByPrefix) $Add = 0; } } if ($Add) $this->Add($key, $value); } } function GetHiddenInputs() { $sReturn = ""; while (list($key, $val) = each($this->aParameters)) { if(is_array($val)) { $nmrows = count($val); for ($i = 0; $i < $nmrows; ++$i) { $sReturn .= "\r\n"; } } else { $sReturn .= "\r\n"; } } reset($this->aParameters); return $sReturn; } // Return the collection as a string in querystring name/value pair format function GetQueryString() { $sReturn = ""; while (list($key, $val) = each($this->aParameters)) { if(is_array($val)) { $nmrows = count($val); for ($i = 0; $i < $nmrows; ++$i) { $sReturn .= $key ."[]=" . $val[$i] . "&"; } } else { $sReturn .= $key . "=" . $val . "&"; } } // remove trailing ampersand $sReturn = substr($sReturn,0,strlen($sReturn) - 5); if ($sReturn != "") $sReturn = "?".$sReturn; reset($this->aParameters); return $sReturn; } // Remove an element from the collection function Remove($Name) { $key_index = array_keys(array_keys($this->aParameters), $Name); if (count($key_index) > 0) array_splice($this->aParameters, $key_index[0], 1); } // Set a value. If it already exists, overwrite it. function Set($Name, $Value, $EncodeValue = 1) { $this->Remove($Name); $this->Add($Name, $Value, $EncodeValue); } } class XmlNode { var $Name; // The name of this element as defined by it's xml tag var $Type; // Type of node (1. contains other nodes, 2. contains data) var $Attributes; // Attributes in the current tag element var $Value; // value of the current element var $Child; // Array of child elements } class XmlManager { var $ErrorManager; // Error message collector var $Name; // The name of this class // Searches through the given node to search for a child node with the supplied name // returns the node if found, returns false otherwise function GetNodeByName($NodeToSearch, $NodeName) { $Node = false; for ($i = 0; $i < count($NodeToSearch->Child); $i++) { if ($NodeToSearch->Child[$i]->Name == $NodeName) $Node = $NodeToSearch->Child[$i]; } return $Node; } function GetNodeValueByName($NodeToSearch, $NodeName) { $Node = $this->GetNodeByName($NodeToSearch, $NodeName); if ($Node) { return $Node->Value; } else { false; } } // Takes a string of xml and parses it recursively returning a fully descript root node function ParseNode($XmlString) { // Retrieve the first xml tag in the file $XmlString = trim($XmlString); $RootNodeStartTag = strpos($XmlString, "<"); $RootNodeEndTag = strpos($XmlString, ">"); $RootNodeName = ""; $RootNodeAttributes = array(); $FauxContext = "0"; // If the opening tag exists, parse it out if ($RootNodeStartTag === false || $RootNodeEndTag === false) { $this->ErrorManager->AddError($FauxContext,$this->Name, "ParseNode", "A fatal error occurred while attempting to parse xml nodes. Syntax Error: xml not properly defined."); } else { $RootNodeName = trim(substr($XmlString, $RootNodeStartTag+1, $RootNodeEndTag-1)); // Evaluate the tag for attributes $SpacePosition = strpos($RootNodeName, " "); if ($SpacePosition !== false) { $sAttributes = trim(substr($RootNodeName,$SpacePosition,strlen($RootNodeName)-$SpacePosition)); $RootNodeName = trim(substr($RootNodeName,0,$SpacePosition)); $tmpArray = explode("=",$sAttributes); $i = 0; $ArrayKeys = count($tmpArray)-1; $Name = ""; while($i < $ArrayKeys) { if ($i+1 <= $ArrayKeys) { if ($Name == "") $Name = ForceString($tmpArray[$i],""); $Value = ForceString($tmpArray[$i+1],""); if (strpos($Value,"\"") === 0) $Value = substr($Value,1); $NextQuotePosition = strpos($Value,"\""); $NextName = ""; if ($NextQuotePosition !== false) { $NextName = trim(substr($Value,$NextQuotePosition)); $Value = substr($Value,0,$NextQuotePosition); } $RootNodeAttributes[$Name] = $Value; $Name = $NextName; } $i += 2; } } } // Double check to see that the root tag name has been properly defined if ($RootNodeName == "") $this->ErrorManager->AddError($FauxContext,$this->Name, "ParseNode", "Node name not defined."); $Node = new XmlNode(); $Node->Name = $RootNodeName; $Node->Attributes = $RootNodeAttributes; // Get content from within the root tag $RootNodeStartCloseTag = strpos($XmlString,""); $XmlString = substr($XmlString, $RootNodeEndTag+1, $RootNodeStartCloseTag-$RootNodeEndTag-1); // Check the inner content to define the current node type if (strpos($XmlString, "<") !== false && strpos($XmlString, ">") !== false) { $Node->Type = XmlNodeTypeContainer; } else { $Node->Type = XmlNodeTypeContent; } if ($Node->Type == XmlNodeTypeContent) { // If the current node holds content, return it $Node->Value = $XmlString; } else { // If the current node contains more nodes, parse it // Define nodes until entire xmlstring has been handled at this level $HandlerComplete = false; while(!$HandlerComplete) { // Defind the node name $NodeStartOpenTag = strpos($XmlString, "<"); $NodeEndOpenTag = strpos($XmlString, ">"); $NodeName = trim(substr($XmlString, $NodeStartOpenTag+1, $NodeEndOpenTag-1-$NodeStartOpenTag)); // Check the Node Name for any spaces and remove anything if it exists $SpacePosition = strpos($NodeName," "); if ($SpacePosition !== false) $NodeName = substr($NodeName, 0, $SpacePosition); // Find the position of the closing tag for this node $NodeStartCloseTag = strpos($XmlString,""); $NodeEndCloseTag = $NodeStartCloseTag+strlen($NodeName)+3; // If it wasn't found, throw an error and break the loop if ($NodeStartCloseTag === false) { $this->ErrorManager->AddError($FauxContext,$this->Name, "ParseNode", "Closing tag for \"$NodeName\" node not defined."); break; // If the tag was found, return everything from the beginning to the end and parse it into a child } else { $NewXmlNodeString = substr($XmlString,$NodeStartOpenTag,$NodeEndCloseTag); $Node->Child[] = $this->ParseNode($NewXmlNodeString); } if (strlen($XmlString) > $NodeEndCloseTag) { $XmlString = trim(substr($XmlString, $NodeEndCloseTag, strlen($XmlString))); } else { $XmlString = ""; } if ($XmlString == "") $HandlerComplete = true; } } return $Node; } function XmlManager() { $this->Name = "XmlManager"; } } class File { var $Name; var $Extension; var $Path; // Directory path to the file var $Body; var $Size; } class FileManager { var $ErrorManager; var $Name; function FileExtension($File) { if (strstr($File->Name, '.')) { return substr(strrchr($File->Name, '.'), 1, strlen($File->Name)); } else { return ""; } } function FileManager() { $this->Name = "FileManager"; } function FilePath($File) { if (substr($File->Path, strlen($File->Path) - 1, strlen($File->Path)) != "/") $File->Path .= "/"; return $File->Path.$File->Name; } function Get($File) { // Ensure required properties are set $FauxContext = 0; if ($File->Name == "") $this->ErrorManager->AddError($FauxContext, $this->Name, "Get", "You must supply a file name.", "", 0); if ($File->Path == "") $this->ErrorManager->AddError($FauxContext, $this->Name, "Get", "You must supply a file path.", "", 0); if ($this->ErrorManager->ErrorCount == 0) { $File->Extension = $this->FileExtension($File); $FilePath = $this->FilePath($File); $FileHandle = @fopen($FilePath, "r"); if (!$FileHandle) { $this->ErrorManager->AddError($FauxContext, $this->Name, "Get", "The file could not be opened.", $FilePath, 0); } else { $File->Size = filesize($FilePath); $File->Body = @fread($FileHandle, $File->Size); if (!$File->Body) $this->ErrorManager->AddError($FauxContext, $this->Name, "Get", "The file could not be read.", "", 0); @fclose($FileHandle); } } return $this->ErrorManager->Iif($File, false); } } function CurrentUrl() { return basename(ForceString(@$_SERVER["PHP_SELF"], "")); } function CurrentWebPath() { $SelfWebPath = ForceString(@$_SERVER["HTTP_HOST"], "").ForceString(@$_SERVER["PHP_SELF"], ""); // Strip filename from webpath if exists if (strpos($SelfWebPath, CurrentUrl()) !== false) $SelfWebPath = substr($SelfWebPath,0,strpos($SelfWebPath, CurrentUrl())); if ($SelfWebPath != "") $SelfWebPath = "http://".$SelfWebPath; return $SelfWebPath; } function FilePath($Path, $File) { if (substr($Path, strlen($Path) - 1, strlen($Path)) != "/") $Path .= "/"; return $Path.$File; } 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 = "

$FileName

"; if ($Config->FitImagesToPage) { $ImageSize = @getimagesize($FolderPath); if ($ImageSize) { $Return .= ""; } else { $Return .= "\"\""; } } else { $Return .= "\"\""; } $Return .= "
\r\n"; break; case "IFrame": $Handled = true; $Return .= "
  • Copy anchor tag
  • ".CurrentWebPath().$FolderPath."\" />
  • View
  • \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 "" tag doesn't kill my textarea $FileContents = str_replace("<", "<", $File->Body); } $Return .= "
  • Copy anchor tag
  • View
  • \r\n"; break; case "EmbedFlash": $Handled = true; $EmbedString = "PluginHeight > 0 && $Config->PluginWidth > 0) $EmbedString .= " height=\"".$Config->PluginHeight."\" width=\"".$Config->PluginWidth."\""; $EmbedString .= ">You do not appear to have the latest flash plugin installed"; $Return .= "
  • Copy embed tag
  • ".$EmbedString."
    \r\n"; break; case "Embed": $Handled = true; $EmbedString = ""; $Return .= "
  • Copy embed tag
  • ".$EmbedString."
    \r\n"; break; case "EmbedQuicktime": $Handled = true; $EmbedString = "PluginHeight > 0 && $Config->PluginWidth > 0) $EmbedString .= " height='".$Config->PluginHeight."' width='".$Config->PluginWidth."'"; $EmbedString .= ">"; $Return .= "
  • Copy embed tag
  • ".$EmbedString."
    \r\n"; break; default: // HyperLink handler method $Return .= "
    \r\n"; $Handled = true; break; } if (!$Handled) { $Return = ""; } else { $Return .= "
    \r\n"; } return $Return; } function FormatListItem($ID, $Name, $Path, $Size, $Date, $Highlighted, &$Params, $CurrentFileHasThumbnail, $Config) { $Return = "
  • UseThumbnails?" Thumbed":"")."\">
  • \r\n"; return $Return; } function FormatMenuItem($CssClass, $Params, $Link, $Alt, $Active) { $Return = "
  • "; if ($Active !== false) $Return .= "GetQueryString()."\" title=\"$Alt\">"; $Return .= $Link; if ($Active !== false) $Return .= ""; $Return .= "
  • \r\n"; return $Return; } // Append a folder name to the current browsing directory function AppendFolder($RootPath, $FolderToAppend) { if (substr($RootPath, strlen($RootPath)-1, strlen($RootPath)) == "/") $RootPath = substr($RootPath, 0, strlen($RootPath) - 1); if (substr($FolderToAppend,0,1) == "/") $FolderToAppend = substr($FolderToAppend,1,strlen($FolderToAppend)); return $RootPath."/".$FolderToAppend; } // Build the navigation path to the current browsing directory function BuildPath($FolderNavigator, $FilesPerPage = "10") { $s = ""; for ($i = 0; $i < count($FolderNavigator); $i++) { $s .= "/".$FolderNavigator[$i][0].""; } return $s; } function BuildLiteralPath($FolderNavigator) { $s = ""; for ($i = 0; $i < count($FolderNavigator); $i++) { $s .= "/".$FolderNavigator[$i][0]; } return $s; } // returns the complete path to the folder or false if not found function CheckForFolder($Path, $FolderKey, &$Config) { $FolderHandle = opendir($Path); $aCurrentSubFolders = array(); // Only look at folders while (false !== ($Item = readdir($FolderHandle))) { if ($Item != '.' && $Item != '..' && is_dir($Path."/".$Item) && !in_array($Path."/".$Item, $Config->FullyQualifiedHideFiles)) $aCurrentSubFolders[] = $Item; } closedir($FolderHandle); // Sort the folders according to the config setting usort($aCurrentSubFolders, "strcasecmp"); reset($aCurrentSubFolders); if ($Config->SortDirection == "desc") $aCurrentSubFolders = array_reverse($aCurrentSubFolders); // If the key supplied is less than the total count of folders found, append the folder name to the path if ($FolderKey < count($aCurrentSubFolders)) { $Config->FolderNavigatorLocation = FormatDelimitedString($Config->FolderNavigatorLocation, $FolderKey, $Config->FolderDelimiter); $Config->FolderNavigator[] = array($aCurrentSubFolders[$FolderKey], $Config->FolderNavigatorLocation); return AppendFolder($Path, $aCurrentSubFolders[$FolderKey]); } else { return false; } } function EncodeLinkUrl($Url) { return str_replace("'", "%27", $Url); } function FormatDelimitedString($String, $Addition, $Delimiter) { $String = $String.""; $Addition = $Addition.""; $String = trim($String); $StringLength = strlen($String); if ($String != "") { if (substr($String,0,1) == $Delimiter) $String = substr($String, 1, $StringLength-1); if (substr($String,$StringLength-1,$StringLength) == $Delimiter) $String = substr($String, 0, $StringLength-1); } $Addition = ForceString($Addition, ""); $AdditionLength = strlen($Addition); if ($Addition != "") { if (substr($Addition,0,1) == $Delimiter) $Addition = substr($Addition, 1, $AdditionLength-1); if (substr($Addition,$AdditionLength-1,$AdditionLength) == $Delimiter) $Addition = substr($Addition, 0, $AdditionLength-1); } $sReturn = ""; if ($String != "" && $Addition != "") { $sReturn = $String.$Delimiter.$Addition; } elseif ($String != "" && $Addition == "") { $sReturn = $String; } elseif ($String == "" && $Addition != "") { $sReturn = $Addition; } return $sReturn; } function FormatFileSize($FileSize) { if ($FileSize > 1048576) { return intval((($FileSize / 1048576) * 100) + 0.5) / 100 ."mb"; } elseif ($FileSize > 1024) { return ceil($FileSize / 1024)."kb"; } else { return $FileSize."b"; } } // strip the file extension from a file name function GetExtension($FileName) { if (strstr($FileName, '.')) { return strtolower(substr(strrchr($FileName, '.'), 1, strlen($FileName))); } else { return ""; } } class FileCollection { var $Name; // Name of the current collection var $FileNames; // Array of file names var $LowerFileNames;// Array of file names in lowercase (for sorting) var $FileSizes; // Array of file sizes var $FileDates; // Array of file dates var $HandlerMethods;// Array of handler methods function AddFile($Name, $Size, $Date, $HandlerMethod) { $this->FileNames[] = $Name; $this->LowerFileNames[] = strtolower($Name); $this->FileSizes[] = $Size; $this->FileDates[] = $Date; $this->HandlerMethods[] = $HandlerMethod; } function BuildAssociativeFileArray($OrderedArray, $ThumbnailArray) { reset($OrderedArray); $AssociativeArray = array(); while (list($key, $val) = each($OrderedArray)) { $AssociativeArray[] = array("Name" => $this->FileNames[$key], "Size" => FormatFileSize($this->FileSizes[$key]), "Date" => $this->FileDates[$key], "HandlerMethod" => $this->HandlerMethods[$key], "ThumbnailPresent" => $this->FindThumbnail($this->FileNames[$key], $ThumbnailArray)); } return $AssociativeArray; } function FileCollection($Name = "") { $this->Name = $Name; $this->FileNames = array(); $this->LowerFileNames = array(); $this->FileDates = array(); $this->FileSizes = array(); $this->HandlerMethods = array(); } function FindThumbnail($FileName, $ThumbnailArray) { // Take the given filename and look for a thumbnail (thumbnails are prefixed with ".thumb.") return in_array("_thumb.".$FileName, $ThumbnailArray); } // Get all items in this file collection as an associative array in the specified order & direction function GetFiles($OrderBy = "Size", $Direction = "asc", $ThumbnailArray = "") { if (!is_array($ThumbnailArray)) $ThumbnailArray = array(); if ($Direction != "asc") $Direction = "desc"; if ($OrderBy != "Size" && $OrderBy != "Name" && $OrderBy != "Date") $OrderBy = "Size"; $SortFunction = "asort"; if ($Direction == "desc") $SortFunction = "arsort"; $ReturnArray = false; if ($OrderBy == "Date") { $SortFunction($this->FileDates); $ReturnArray = $this->BuildAssociativeFileArray($this->FileDates, $ThumbnailArray); } elseif ($OrderBy == "Name") { $SortFunction($this->LowerFileNames); $ReturnArray = $this->BuildAssociativeFileArray($this->LowerFileNames, $ThumbnailArray); } else { $SortFunction($this->FileSizes); $ReturnArray = $this->BuildAssociativeFileArray($this->FileSizes, $ThumbnailArray); } return $ReturnArray; } } class Configuration { // Configuration Settings var $ConfigFile; // Location of the configuration file var $FileTypesFile; // Location of the filetypes file var $ErrorManager; // Handles error messages var $Version; // FB Version var $Developer; // FB Developer's name var $DeveloperEmail; // FB Developer's email address var $Date; // Date of FB development completion var $StyleUrl; // URL to the stylesheet var $PageTitle; // To appear on the page var $PageIntroduction; // To appear before any images are viewed var $UsePageIntroductionInSubFolders; var $DisplayHiddenFiles; // Boolean value indicating if files beginning with underscore should be visible var $BrowseSubFolders; // Boolean value indicating if subfolders should be browsable/visible var $SortBy; // Value to sort the files by var $SortDirection; // Direction to sort the files var $DateFormat; // The format string that will be used to configure the display format of the date for a file var $PluginHeight; var $PluginWidth; var $DefaultFilesPerPage; // The default number of files to show when someone clicks the >> or << buttons var $FitImagesToPage; // Boolean value indicating if large images should be shrunk to fit on the page var $UseThumbnails; // Use thumbnails (if they exist) // Browsing Properties var $FileID; // ID of file currently being viewed var $FolderIDs; // String of comma delimited folder ids var $aFolderID; // Array of folder id's currently being viewed var $FilesPerPage; // Number of files to display per page (as defined by the querystring) var $CurrentWorkingDirectory; var $CurrentBrowsingDirectory; var $SelfUrl; // Name of this file var $SelfWebPath; // path to the filebrowser execution file (ie. http://mydomain.com/images/) var $FolderDelimiter; // Querystring delimiter to be used between folder ids var $FolderNavigator; // A holder variable containing a folder navigation array var $FolderNavigatorLocation; // Another holder variable containing the querystring values for the folder navigator var $ShowMultipleFiles; // Boolean value indicating if multiple file should be displayed or not var $GetFileID; // ID of a file to "save as" var $HideFiles; // An array of files that should remain hidden var $FullyQualifiedHideFiles; // Same as above, but fully qualified to root var $Name; // The name of this class // Default constructor - define default values for class properties function Configuration() { // Configuration Settings $this->ConfigFile = "_config.xml"; $this->FileTypesFile = "_filetypes.xml"; $this->CurrentWorkingDirectory = getcwd(); // Configuration Properties $this->Version = "1.3.3"; $this->Developer = "Mark O'Sullivan"; $this->Date = "2002-2005"; $this->StyleUrl = "_default.css"; $this->PageTitle = "Lussumo Filebrowser"; $this->PageIntroduction = ""; $this->UsePageIntroductionInSubFolders = false; $this->DisplayHiddenFiles = false; $this->BrowseSubFolders = true; $this->SortBy = "Name"; $this->SortDirection = "asc"; $this->DateFormat = "m-d-y"; $this->PluginHeight = 400; $this->PluginWidth = 400; $this->DefaultFilesPerPage = 5; $this->MaxFilesPerPage = 50; $this->FitImagesToPage = 1; $this->UseThumbnails = 0; $this->HideFiles = array(); $this->FullyQualifiedHideFiles = array(); // Browsing Properties $this->FolderDelimiter = "-"; $this->FileID = ForceIncomingInt("fid", 0); $this->FolderIDs = ForceIncomingString("did", ""); if ($this->FolderIDs == "") { $this->aFolderID = array(); } else { $this->aFolderID = explode($this->FolderDelimiter, $this->FolderIDs); } $this->CurrentBrowsingDirectory = $this->CurrentWorkingDirectory; $this->FolderNavigator = array(); $this->FolderNavigatorLocation = ""; $this->ShowMultipleFiles = ForceIncomingBool("smf", false); $this->GetFileID = ForceIncomingInt("gid", 0); $this->Name = "FileBrowser"; } function RetrieveConfigurationPropertiesFromXml($Path) { $FauxContext = "0"; if ($this->ConfigFile == "") $this->ErrorManager->AddError($FauxContext,$this->Name, "RetrieveConfigurationPropertiesFromXml", "You must supply a path to the configuration file"); // Retrieve config file contents $File = new File(); $File->Name = $this->ConfigFile; $File->Path = $Path; $FileManager = new FileManager(); $FileManager->ErrorManager = &$this->ErrorManager; $File = $FileManager->Get($File); // If there were errors retrieving the config file and we're in the CWD, report an error if ($this->ErrorManager->ErrorCount > 0 && $Path == $this->CurrentWorkingDirectory) { $this->ErrorManager->Clear(); $this->ErrorManager->AddError($FauxContext,$this->Name, "RetrieveConfigurationPropertiesFromXml", "The root configuration file could not be found/read (_config.xml)."); // If failed to retrieve the file from a non-root directory, // just accept the root file } elseif ($this->ErrorManager->ErrorCount > 0) { $this->ErrorManager->Clear(); // If no errors occurred, continue to retrieve new configuration settings } else { // Create an XML Parser to retrieve configuration settings $XMan = new XmlManager(); $XMan->ErrorManager = &$this->ErrorManager; $MyConfig = $XMan->ParseNode($File->Body); if ($MyConfig && $this->ErrorManager->ErrorCount == 0) { $this->StyleUrl = $XMan->GetNodeValueByName($MyConfig, "StyleUrl"); $this->PageTitle = $XMan->GetNodeValueByName($MyConfig, "PageTitle"); $this->PageIntroduction = $XMan->GetNodeValueByName($MyConfig, "PageIntroduction"); $this->PageIntroduction = str_replace("[","<", $this->PageIntroduction); $this->PageIntroduction = str_replace("]",">", $this->PageIntroduction); $this->PageIntroduction = str_replace("\n","
    ", $this->PageIntroduction); $this->DisplayHiddenFiles = $XMan->GetNodeValueByName($MyConfig, "DisplayHiddenFiles"); $this->BrowseSubFolders = $XMan->GetNodeValueByName($MyConfig, "BrowseSubFolders"); $this->SortBy = $XMan->GetNodeValueByName($MyConfig, "SortBy"); $this->SortDirection = $XMan->GetNodeValueByName($MyConfig, "SortDirection"); $this->DateFormat = $XMan->GetNodeValueByName($MyConfig, "DateFormat"); $this->UsePageIntroductionInSubFolders = ForceBool($XMan->GetNodeValueByName($MyConfig, "UsePageIntroductionInSubFolders"), false); $this->PluginHeight = ForceInt($XMan->GetNodeValueByName($MyConfig, "PluginHeight"), $this->PluginHeight); $this->PluginWidth = ForceInt($XMan->GetNodeValueByName($MyConfig, "PluginWidth"), $this->PluginWidth); $this->FilesPerPage = ForceIncomingInt("fpp", ForceInt($XMan->GetNodeValueByName($MyConfig, "FilesPerPage"), $this->FilesPerPage)); $this->MaxFilesPerPage = ForceInt($XMan->GetNodeValueByName($MyConfig, "MaxFilesPerPage"), $this->MaxFilesPerPage); $this->FitImagesToPage = ForceBool($XMan->GetNodeValueByName($MyConfig, "FitImagesToPage"), $this->FitImagesToPage); $this->UseThumbnails = ForceBool($XMan->GetNodeValueByName($MyConfig, "UseThumbnails"), $this->UseThumbnails); $this->HideFiles = explode(",", $XMan->GetNodeValueByName($MyConfig, "HideFiles")); for ($i = 0; $i < count($this->HideFiles); $i++) { $this->FullyQualifiedHideFiles[] = $this->CurrentBrowsingDirectory."/".$this->HideFiles[$i]; } } } return $this->ErrorManager->Iif(); } } // Define required variables for the application $ErrorManager = new ErrorManager(); $Config = new Configuration(); $Config->ErrorManager = &$ErrorManager; // ------------------------------------ // 1. RETRIEVE CONFIGURATION PROPERTIES // ------------------------------------ $Config->RetrieveConfigurationPropertiesFromXml($Config->CurrentWorkingDirectory); // Check for subfolder ids if directory browsing is allowed and some folder ids were supplied if ($Config->BrowseSubFolders && count($Config->aFolderID) > 0) { for ($i = 0; $i < count($Config->aFolderID); $i++) { $CurrentFolderKey = ForceInt($Config->aFolderID[$i], 0); $Config->CurrentBrowsingDirectory = CheckForFolder($Config->CurrentBrowsingDirectory, $CurrentFolderKey, $Config); if (!$Config->CurrentBrowsingDirectory) { // IF the current browsing directory wasn't found, wipe out all directory settings and start from the root $Config->CurrentBrowsingDirectory = $Config->CurrentWorkingDirectory; $Config->FolderIDs = ""; $Config->aFolderID = array(); break; } } } // If the folder exists, and there is a _config.xml file in the folder, reconfigure the filebrowser if ($Config->CurrentWorkingDirectory != $Config->CurrentBrowsingDirectory) $Config->RetrieveConfigurationPropertiesFromXml($Config->CurrentBrowsingDirectory); // ----------------------------------- // 2. RETRIEVE FILE EXTENSION SETTINGS // ----------------------------------- $File = new File(); $File->Name = $Config->FileTypesFile; $File->Path = $Config->CurrentWorkingDirectory; $FileManager = new FileManager(); $FileManager->ErrorManager = &$Config->ErrorManager; $File = $FileManager->Get($File); // Create an XML Parser to retrieve configuration settings $XmlManager = new XmlManager(); $XmlManager->ErrorManager = &$ErrorManager; $FileTypes = $XmlManager->ParseNode($File->Body); // Create an array of all defined file types $FileCollections = array(); $FolderCollection = array(); $ExtensionLibrary = array(); for ($i = 0; $i < count($FileTypes->Child); $i++) { if ($FileTypes->Child[$i]->Name == "FileGroup") { $FileCollections[$i] = new FileCollection($FileTypes->Child[$i]->Attributes["Name"]); for ($j = 0; $j < count($FileTypes->Child[$i]->Child); $j++) { $Node = $FileTypes->Child[$i]->Child[$j]; if ($Node->Name == "Extensions") { // Ignore all items with a handler method of none if (@$Node->Attributes["HandlerMethod"] != "None") { $CurrentExtensionArray = explode(",",$Node->Value); for ($k = 0; $k < count($CurrentExtensionArray); $k++) { $ExtensionLibrary[strtolower($CurrentExtensionArray[$k])] = array($i,$Node->Attributes["HandlerMethod"]); } } } } } } // ----------------- // 3. RETRIEVE FILES // ----------------- // Loop through files in the current browsing directory $FolderKey = 0; $FolderHandle = opendir($Config->CurrentBrowsingDirectory); $CurrentExtension = ""; $RecordItem = true; $ThumbnailCollection = array(); while (false !== ($Item = readdir($FolderHandle))) { $RecordItem = true; if ($Item == "." || $Item == ".." || in_array($Config->CurrentBrowsingDirectory."/".$Item, $Config->FullyQualifiedHideFiles) ) $RecordItem = false; if ($Config->DisplayHiddenFiles == "false" && $Item == $Config->SelfUrl) $RecordItem = false; if ($Config->DisplayHiddenFiles == "false" && substr($Item,0,1) == "_") $RecordItem = false; if ($Config->UseThumbnails && substr($Item,0,7) == "_thumb.") { // Don't record the current item in the regular file collections, dump it into a thumbnail collection $RecordItem = false; $ThumbnailCollection[] = $Item; } if ($RecordItem) { // If dealing with a folder, add it to the folder collection if (is_dir($Config->CurrentBrowsingDirectory."/".$Item)) { $FolderCollection[] = $Item; // If not dealing with a folder, add it to the proper file collection } else { // Match the current file extension with an item in the extension library $CurrentExtension = GetExtension($Item); $KeyMatch = @$ExtensionLibrary[$CurrentExtension]; // If the match came back positive, add the file to the collection if ($KeyMatch) { $FileCollections[$ExtensionLibrary[$CurrentExtension][0]]->AddFile($Item, filesize($Config->CurrentBrowsingDirectory."/".$Item), filemtime($Config->CurrentBrowsingDirectory."/".$Item), $ExtensionLibrary[$CurrentExtension][1]); // If the match came back false, attempt to add this file to the wildcard group } elseif (array_key_exists("*", $ExtensionLibrary)) { $FileCollections[$ExtensionLibrary["*"][0]]->AddFile($Item, filesize($Config->CurrentBrowsingDirectory."/".$Item), filemtime($Config->CurrentBrowsingDirectory."/".$Item), $ExtensionLibrary["*"][1], $ExtensionLibrary["*"]); } // Ignore all other files } } } // -------------------------- // 4. BUILD THE PAGE ELEMENTS // -------------------------- // If in a subfolder, // and there is no file currently selected, // and we're not supposed to display the root introduction // and there is no config file for this folder // Display the first file if ($Config->FileID == 0 && $Config->CurrentWorkingDirectory != $Config->CurrentBrowsingDirectory && !$Config->UsePageIntroductionInSubFolders) $Config->FileID = 1; $FilesToDisplay = $Config->FilesPerPage; if (!$Config->ShowMultipleFiles) $FilesToDisplay = 1; $aItemHistory = array(); $FileDisplay = ""; $FileList = ""; // Create a parameters class to manage querystring values $Params = new Parameters(); $Params->DefineCollection($_GET); $Params->Add("fpp", $Config->FilesPerPage); $Params->Remove("smf"); if ($Config->FolderIDs == "") $Params->Remove("did"); $FileCounter = 0; // Build the file listing while (list(, $CurrentFileCollection) = each ($FileCollections)) { // Get the sorted files $Files = $CurrentFileCollection->GetFiles($Config->SortBy, $Config->SortDirection, $ThumbnailCollection); if (count($Files) > 0) { $FileList .= "

    ".$CurrentFileCollection->Name."

    \r\n"; } } if ($FileDisplay == "" && $Config->FileID != 0) $FileDisplay = "
    The requested file could not be found.
    \r\n"; $FileDisplay = "
    ".$FileDisplay."
    \r\n"; // Build the folder listing if ($Config->BrowseSubFolders && ((count($FolderCollection) > 0) || count($Config->aFolderID) > 0)) { $Params->Remove("fid"); $FileList .= "

    Folders

    \r\n"; } // ------------------ // 5. WRITE PAGE HEAD // ------------------ // Define the current folder path $RootPath = substr(CurrentWebPath(),0,strlen(CurrentWebPath())-1); $CurrentPath = "FilesPerPage."\">".str_replace("http://","",$RootPath).""; echo(" ".$Config->PageTitle." StyleUrl."\" />

    ".$Config->PageTitle."

    ".$CurrentPath.BuildPath($Config->FolderNavigator, $Config->FilesPerPage)."
    "); // ------------------------------------ // 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 if ($TotalItemCount > 0) { $FileKey = false; if ($Config->FileID > 0) $FileKey = array_search($Config->FileID,$aItemHistory); if ($FileKey !== false) { // Don't go past the end if ($Config->ShowMultipleFiles) { if ($FileKey + $Config->FilesPerPage <= $TotalItemCount) { $NextItem = $aItemHistory[$FileKey+$Config->FilesPerPage]; } else { $NextItem = false; } } else { if ($FileKey + 1 <= $TotalItemCount) { $NextItem = $aItemHistory[$FileKey+1]; } else { $NextItem = false; } } // Don't go before the beginning if ($FileKey < $Config->FilesPerPage) { $PreviousItemGroup = $aItemHistory[0]; } else { $PreviousItemGroup = $aItemHistory[$FileKey-$Config->FilesPerPage]; } if ($FileKey == 0) { $FirstItem = $aItemHistory[0]; $PreviousItem = false; $PreviousItemGroup = false; } else { $PreviousItem = $aItemHistory[$FileKey-1]; } } else { $NextItem = $aItemHistory[0]; $PreviousItemGroup = false; $PreviousItem = false; } } $Params->Remove("fid"); $Params->Set("did", $Config->FolderIDs); $Params->Set("fid", $FirstItem); $Menu = FormatMenuItem("NavFirstItem", $Params, "|<", "First", $FirstItem); $Params->Set("fid",$PreviousItemGroup); $Params->Add("smf",1); $Menu .= FormatMenuItem("NavPreviousItemGroup", $Params, "<<", "Previous ".$Config->FilesPerPage, $PreviousItemGroup); $Params->Remove("smf"); $Params->Set("fid",$PreviousItem); $Menu .= FormatMenuItem("NavPreviousItem", $Params, "Previous", "Previous", $PreviousItem); $Params->Set("fid",$NextItem); $Menu .= FormatMenuItem("NavNextItem", $Params, "Next", "Next", $NextItem); $Params->Add("smf",1); $Params->Set("fid",$NextItem); $Menu .= FormatMenuItem("NavNextItemGroup", $Params, ">>", "Next ".$Config->FilesPerPage, $NextItem); $Params->Remove("smf"); $Params->Set("fid",$LastItem); $Menu .= FormatMenuItem("NavLastItem", $Params, ">|", "Last", $LastItem); // ---------------------------------- // 7. WRITE THE REMAINDER OF THE PAGE // ---------------------------------- echo("\r\n"); echo("
    \r\n"); // If a file has not been requested, write out the introductory paragraph (if there is one) if ( $Config->FileID == 0 && $Config->PageIntroduction != "" && ($Config->CurrentWorkingDirectory == $Config->CurrentBrowsingDirectory || ($Config->CurrentWorkingDirectory != $Config->CurrentBrowsingDirectory && $Config->UsePageIntroductionInSubFolders))) echo("
    ".$Config->PageIntroduction."
    \r\n"); // Write out the selected files echo($FileDisplay); echo("
    \r\n" // End DisplayContainer ."\r\n" ."
    \r\n"); // Write out the file/folder listing if (trim($FileList) == "") { echo("
    No files or folders could be found.
    \r\n"); } else { echo($FileList); } // Write out the page footer echo("
    \r\n" // End ListContainer ."
    "); $p = new Parameters(); $p->DefineCollection($_GET); $p->Remove("fpp"); echo($p->GetHiddenInputs() ."
    Files/Page:
    FilesPerPage."\" onchange=\"document.frmPager.submit();\" />
    Lussumo Filebrowser ".$Config->Version." © ".$Config->Date."
    Developed by ".$Config->Developer."
    "); ?>