[Picfinity-commit] SF.net SVN: picfinity: [16] index.php
Status: Beta
Brought to you by:
espadav8
From: <esp...@us...> - 2007-08-08 14:34:50
|
Revision: 16 http://picfinity.svn.sourceforge.net/picfinity/?rev=16&view=rev Author: espadav8 Date: 2007-08-08 07:34:48 -0700 (Wed, 08 Aug 2007) Log Message: ----------- Add the ability to store the selected theme in a cookie Can disable the .themes folder being scanned and thus removing the option to change the theme Allow an ID to be sent and passed to the XML, should allow 'link to image' in themes IDs for items are now the md5 of the path to the item, this way the ID will always be the same for a given file path Changed the scandir() to a PHP4 friendly version Changed mkdir() to the PHP4 version which doesn't allow recursive creation Get the ext of a file in lowercase since JPG and jpg are the same, they would've been missed before Modified Paths: -------------- index.php Modified: index.php =================================================================== --- index.php 2007-07-29 10:54:19 UTC (rev 15) +++ index.php 2007-08-08 14:34:48 UTC (rev 16) @@ -3,9 +3,33 @@ // site options $site_name = "Picfinity"; - // use the default theme or get the one passed in - $theme = ($_GET['theme'] != '') ? $_GET['theme'] : "ajax" ; + // here we either get the theme posted in + // or if there's one stored in the cookie use that one + // otherwise use the default one + if ($_POST['theme']) + { + setcookie("theme", $_POST['theme']); + $theme = $_POST['theme']; + } + else if ($_COOKIE['theme']) + { + $theme = $_COOKIE['theme']; + } + else + { + // set the name of the default theme here + $theme = "ajax" ; + } + if ($_GET['id']) + { + $post_id = $_GET['id']; + } + else + { + $post_id = 0; + } + // not implemented yet $max_folders = 0; // 0 = unlimited @@ -21,6 +45,10 @@ // use the PEAR module to create the XML $use_pear = false; + // Allow the users to change the theme + // this needs the PHP version of the page + $enable_themes = true; + // thumbnail sizes $thumbnail_width = 100; $thumbnail_height = 100; @@ -39,11 +67,10 @@ $xml = $site_layout; // create the XML file if we've been told to - if ($create_xml) - file_put_contents("gallery.xml", $xml); + if ($create_xml) file_put_contents("gallery.xml", $xml); // pass the XML to the theme and get the HTML back - $html = xml_to_xhtml($xml, ".themes/$theme/$theme.xsl", array('title' => $site_name)); + $html = xml_to_xhtml($xml, ".themes/$theme/$theme.xsl", array('title' => $site_name, 'post_id' => $post_id)); // create the flat version if we need to if ($create_html) file_put_contents("index.html", $html); @@ -57,12 +84,13 @@ global $valid_image_formats; global $create_thumbnails; global $use_pear; + global $enable_themes; // get the name of the folder or '' if it's the root $name = substr($folder, strrpos($folder, '/') + 1); // create a folder ID - $folder_id = uniqid('id'); + $folder_id = md5($folder); // add the folder to the Array (for use by the PEAR route) $layout = array('name' => $name, 'id' => $folder_id); @@ -78,14 +106,20 @@ $folder_layout_xml = "<folder id=\"$folder_id\" name=\"$name\">\n"; // get a listing of the files/folder - $folder_contents = scandir($folder); + $dh = opendir($folder); + while (false !== ($filename = readdir($dh))) { + $folder_contents[] = $filename; + } + sort($folder_contents); + // for each entry while (list(,$folder_entry) = each($folder_contents)) { // if it's a folder and the path of it is ./.themes then create the list of themes if ((is_dir($folder . '/' . $folder_entry)) && - (($folder . '/' . $folder_entry) == "./.themes")) + (($folder . '/' . $folder_entry) == "./.themes") && + $enable_themes) { if ($use_pear) $layout['themes'] = create_themes_layout(); @@ -112,7 +146,7 @@ // otherwise check to see if it's an image else { - $ext = substr($folder_entry, strrpos($folder_entry, '.') + 1); + $ext = strtolower(substr($folder_entry, strrpos($folder_entry, '.') + 1)); if (in_array($ext, $valid_image_formats)) { @@ -121,7 +155,7 @@ { create_thumbnail($folder, $folder_entry, $ext); } - $image_id = uniqid('id'); + $image_id = md5($folder . '/' . $folder_entry); $layout['image'][] = array('id' => $image_id, 'file' => $folder_entry); $folder_layout_xml .= "\t<image id=\"$image_id\" file=\"$folder_entry\" />\n"; } @@ -141,15 +175,20 @@ { global $use_pear; - $themes_id = uniqid('id'); + $themes_id = md5(".themes"); // create the themes node + $layout = array('name' => '.themes', 'id' => $themes_id); $theme_xml = "<themes id=\"$themes_id\" name=\".themes\">\n"; - $layout = array('name' => '.themes', 'id' => $themes_id); // get the themes - $folder_contents = scandir(".themes"); + $dh = opendir(".themes"); + while (false !== ($filename = readdir($dh))) { + $folder_contents[] = $filename; + } + sort($folder_contents); + // for each entry while (list(,$folder_entry) = each($folder_contents)) { @@ -161,14 +200,13 @@ // otherwise if it's a dir assume it's a theme and add it to the list else if (is_dir(".themes/" . $folder_entry)) { - $theme_id = uniqid('id'); + $theme_id = md5(".themes/" . $folder_entry); $layout['theme'][] = array('name' => $folder_entry, 'id' => $theme_id); $theme_xml .= "\t<theme id=\"$theme_id\" name=\"$folder_entry\" />\n"; } } $theme_xml .= "</themes>\n"; - echo $theme_xml; if ($use_pear) return $layout; else return $theme_xml; @@ -181,7 +219,7 @@ if (!is_dir('.thumbs/'.$folder)) { - mkdir('.thumbs/'.$folder, 0777, TRUE); + MakeDirectory('.thumbs/'.$folder, 0777); chmod('.thumbs/'.$folder, 0777); } if (file_exists('.thumbs/'.$folder.'/'.$image)) @@ -306,5 +344,12 @@ return $xsl->transformToXML($doc); } + + function MakeDirectory($dir, $mode = 0755) + { + if (is_dir($dir) || @mkdir($dir,$mode)) return TRUE; + if (!MakeDirectory(dirname($dir),$mode)) return FALSE; + return @mkdir($dir,$mode); + } ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |