[Picfinity-commit] SF.net SVN: picfinity: [15] index.php
Status: Beta
Brought to you by:
espadav8
From: <esp...@us...> - 2007-07-29 10:56:41
|
Revision: 15 http://picfinity.svn.sourceforge.net/picfinity/?rev=15&view=rev Author: espadav8 Date: 2007-07-29 03:54:19 -0700 (Sun, 29 Jul 2007) Log Message: ----------- Add lots of comments to the file Add the option of using the XML_Seralizer PEAR module or not Make thumbnail_width, _height set with the other options Modified Paths: -------------- index.php Modified: index.php =================================================================== --- index.php 2007-07-29 10:50:51 UTC (rev 14) +++ index.php 2007-07-29 10:54:19 UTC (rev 15) @@ -2,14 +2,28 @@ // site options $site_name = "Picfinity"; + + // use the default theme or get the one passed in $theme = ($_GET['theme'] != '') ? $_GET['theme'] : "ajax" ; // not implemented yet $max_folders = 0; // 0 = unlimited - + + // create thumbnails for images that don't have one already $create_thumbnails = true; + + // create a flat HTML version of the page $create_html = true; + + // create the gallery.xml file (for use by themes $create_xml = true; + + // use the PEAR module to create the XML + $use_pear = false; + + // thumbnail sizes + $thumbnail_width = 100; + $thumbnail_height = 100; // valid images to be shown $valid_image_formats = array('png', 'gif', 'jpg', 'jpeg', 'bmp'); @@ -17,99 +31,154 @@ // get the layout of the current dir $site_layout = create_folder_layout('.'); - $xml = array_to_xml($site_layout); + // create the XML of the layout + // if we're not using the PEAR module then the XML will have already been returned + if ($use_pear) + $xml = array_to_xml($site_layout); + else + $xml = $site_layout; + // create the XML file if we've been told to 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)); - if ($create_html) - { - file_put_contents("index.html", $html); - } + // create the flat version if we need to + if ($create_html) file_put_contents("index.html", $html); + // echo the HTML to the screen echo $html; - echo "<div style=\"display:none;\">$xml</div>"; - - + // this function takes a folder path and creates a layout of the folder and sub folders function create_folder_layout($folder) { global $valid_image_formats; global $create_thumbnails; + global $use_pear; + // 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'); + + // add the folder to the Array (for use by the PEAR route) + $layout = array('name' => $name, 'id' => $folder_id); + + // create the non-PEAR XML + if ($name == "") + $folder_layout_xml = "<?xml version=\"1.0\"?>" + . "\n" + . "<!DOCTYPE layout PUBLIC \"-//picfinity//Gallery Layout//EN\" \"http://www.sunset-cigarette.co.uk/gallery/gallery.dtd\">" + . "\n" + . "<layout id=\"$folder_id\" name=\"\">\n"; + else + $folder_layout_xml = "<folder id=\"$folder_id\" name=\"$name\">\n"; + // get a listing of the files/folder $folder_contents = scandir($folder); - $name = substr($folder, strrpos($folder, '/') + 1); - $layout = array('name' => $name, 'id' => uniqid('id')); // 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")) { - $layout['themes'] = create_themes_layout(); + if ($use_pear) + $layout['themes'] = create_themes_layout(); + else + $folder_layout_xml .= create_themes_layout(); } + + // else if it starts with a . ignore it else if (strpos($folder_entry, '.') === 0) { - // this is a hidden file/folder, ignore continue; } - // if it's a directory and doesn't start with a . + + // if it's a directory and doesn't start with a . then create a folder layout for it else if (is_dir($folder . '/' . $folder_entry)) { // get a list of it's files and check/create thumbnail(s) - $sub_layout = create_folder_layout($folder . '/' . $folder_entry); - $layout['folder'][] = $sub_layout; + if ($use_pear) + $layout['folder'][] = create_folder_layout($folder . '/' . $folder_entry); + else + $folder_layout_xml .= create_folder_layout($folder . '/' . $folder_entry); } + + // otherwise check to see if it's an image else { - // otherwise, check if it's an image to process $ext = substr($folder_entry, strrpos($folder_entry, '.') + 1); - // check if it's a valid image format if (in_array($ext, $valid_image_formats)) { + // create a thumbnail if we've been told to if ($create_thumbnails) { - // create a thumbnail create_thumbnail($folder, $folder_entry, $ext); } - $layout['image'][] = array('id' => uniqid('id'), 'file' => $folder_entry); + $image_id = uniqid('id'); + $layout['image'][] = array('id' => $image_id, 'file' => $folder_entry); + $folder_layout_xml .= "\t<image id=\"$image_id\" file=\"$folder_entry\" />\n"; } } } - return $layout; + // close up the hand-coded XML + if ($name == "") $folder_layout_xml .= "</layout>\n"; + else $folder_layout_xml .= "</folder>\n"; + + // return the correct layout (XML or Array) + if ($use_pear) return $layout; + else return $folder_layout_xml; } function create_themes_layout() { + global $use_pear; + + $themes_id = uniqid('id'); + + // create the themes node + $theme_xml = "<themes id=\"$themes_id\" name=\".themes\">\n"; + $layout = array('name' => '.themes', 'id' => $themes_id); + + // get the themes $folder_contents = scandir(".themes"); - $layout = array('name' => '.themes', 'id' => uniqid('id')); // for each entry while (list(,$folder_entry) = each($folder_contents)) { + // if it's hidden ignore it if (strpos($folder_entry, '.') === 0) { continue; } + // otherwise if it's a dir assume it's a theme and add it to the list else if (is_dir(".themes/" . $folder_entry)) { - $layout['theme'][] = array('name' => $folder_entry, 'id' => uniqid('id')); + $theme_id = uniqid('id'); + $layout['theme'][] = array('name' => $folder_entry, 'id' => $theme_id); + $theme_xml .= "\t<theme id=\"$theme_id\" name=\"$folder_entry\" />\n"; } } - return $layout; + $theme_xml .= "</themes>\n"; + echo $theme_xml; + + if ($use_pear) return $layout; + else return $theme_xml; } function create_thumbnail($folder, $image, $ext) { + global $thumbnail_width; + global $thumbnail_height; + if (!is_dir('.thumbs/'.$folder)) { mkdir('.thumbs/'.$folder, 0777, TRUE); @@ -138,25 +207,25 @@ case 'bmp': $src_img = imagecreatefrombmp($folder.'/'.$image); break; + default: + return; + break; } - $new_w = 100; - $new_h = 100; - $old_x = imageSX($src_img); $old_y = imageSY($src_img); if ($old_x > $old_y) { - $thumb_w = $new_w; - $thumb_h = $old_y * ($new_h/$old_x); + $thumb_w = $thumbnail_width; + $thumb_h = $old_y * ($thumbnail_height/$old_x); } else if ($old_x < $old_y) { - $thumb_w = $old_x * ($new_w/$old_y); - $thumb_h = $new_h; + $thumb_w = $old_x * ($thumbnail_width/$old_y); + $thumb_h = $thumbnail_height; } else if ($old_x == $old_y) { - $thumb_w = $new_w; - $thumb_h = $new_h; + $thumb_w = $thumbnail_width; + $thumb_h = $thumbnail_height; } $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h); @@ -235,8 +304,7 @@ $xsl->setParameter('', $params); - $html = $xsl->transformToXML($doc); + return $xsl->transformToXML($doc); + } +?> - return $html; - } -?> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |