[Picfinity-commit] SF.net SVN: picfinity: [29] trunk
Status: Beta
Brought to you by:
espadav8
From: <esp...@us...> - 2007-08-12 20:06:29
|
Revision: 29 http://picfinity.svn.sourceforge.net/picfinity/?rev=29&view=rev Author: espadav8 Date: 2007-08-12 13:06:30 -0700 (Sun, 12 Aug 2007) Log Message: ----------- Hopefully create the folders in the correct places so it can be tagged and branched Added Paths: ----------- branches/ tags/ trunk/ trunk/.themes/ trunk/.themes/ajax/ trunk/.themes/gallery/ trunk/gallery.dtd trunk/index.php Removed Paths: ------------- .themes/ gallery.dtd index.php trunk/.themes/ajax/ trunk/.themes/gallery/ Deleted: gallery.dtd =================================================================== --- gallery.dtd 2007-08-12 19:43:08 UTC (rev 28) +++ gallery.dtd 2007-08-12 20:06:30 UTC (rev 29) @@ -1,20 +0,0 @@ -<!ELEMENT layout (themes,folder*)> -<!ELEMENT folder (folder*,image*)> -<!ELEMENT themes (theme*)> -<!ELEMENT image EMPTY> -<!ELEMENT theme EMPTY> - -<!ATTLIST layout id ID #IMPLIED> -<!ATTLIST layout name CDATA #REQUIRED> - -<!ATTLIST folder id ID #IMPLIED> -<!ATTLIST folder name CDATA #REQUIRED> - -<!ATTLIST themes id ID #IMPLIED> -<!ATTLIST themes name CDATA #REQUIRED> - -<!ATTLIST theme id ID #IMPLIED> -<!ATTLIST theme name CDATA #REQUIRED> - -<!ATTLIST image id ID #IMPLIED> -<!ATTLIST image file CDATA #REQUIRED> \ No newline at end of file Deleted: index.php =================================================================== --- index.php 2007-08-12 19:43:08 UTC (rev 28) +++ index.php 2007-08-12 20:06:30 UTC (rev 29) @@ -1,378 +0,0 @@ -<?php - // site options - $site_name = "Picfinity"; - - // 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; - } - - // create thumbnails for images that don't have one already - $create_thumbnails = true; - - // create a flat HTML version of the page - $create_html = false; - - // create the gallery.xml file (for use by themes - $create_xml = true; - - // 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; - - // valid images to be shown - $valid_image_formats = array('png', 'gif', 'jpg', 'jpeg', 'bmp'); - - // get the layout of the current dir - $site_layout = create_folder_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) - { - $fh = fopen("gallery.xml", "w"); - fwrite($fh, $xml); - fclose($fh); - } - - // pass the XML to the theme and get the HTML back - $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) - { - $fh = fopen("index.html", "w"); - fwrite($fh, $html); - fclose($fh); - } - - // echo the HTML to the screen - echo $html; - - // 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; - 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 = "id" . md5($folder); - - // 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 - $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") && - $enable_themes) - { - 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) - { - continue; - } - - // 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) - 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 - { - $ext = strtolower(substr($folder_entry, strrpos($folder_entry, '.') + 1)); - - if (in_array($ext, $valid_image_formats)) - { - // create a thumbnail if we've been told to - if ($create_thumbnails) - { - create_thumbnail($folder, $folder_entry, $ext); - } - $image_id = "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"; - } - } - } - - // 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 = "id" . md5(".themes"); - - // create the themes node - $layout = array('name' => '.themes', 'id' => $themes_id); - $theme_xml = "<themes id=\"$themes_id\" name=\".themes\">\n"; - - // get the 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)) - { - // 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)) - { - $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"; - - if ($use_pear) return $layout; - else return $theme_xml; - } - - function create_thumbnail($folder, $image, $ext) - { - global $thumbnail_width; - global $thumbnail_height; - - if (file_exists('.thumbs/'.$folder.'/'.$image)) - { - // if it already exists, do nothing - return; - } - if (!is_dir('.thumbs/'.$folder)) - { - MakeDirectory('.thumbs/'.$folder, 0777); - chmod('.thumbs/'.$folder, 0777); - } - - $src_img; - switch ($ext) - { - case 'png': - $src_img = imagecreatefrompng($folder.'/'.$image); - break; - case 'jpg': - case 'jpeg': - $src_img = imagecreatefromjpeg($folder.'/'.$image); - break; - case 'gif': - $src_img = imagecreatefromgif($folder.'/'.$image); - break; - case 'bmp': - $src_img = imagecreatefrombmp($folder.'/'.$image); - break; - default: - return; - break; - } - - $old_x = imageSX($src_img); - $old_y = imageSY($src_img); - - if ($old_x > $old_y) { - $thumb_w = $thumbnail_width; - $thumb_h = $old_y * ($thumbnail_height/$old_x); - } - else if ($old_x < $old_y) { - $thumb_w = $old_x * ($thumbnail_width/$old_y); - $thumb_h = $thumbnail_height; - } - else if ($old_x == $old_y) { - $thumb_w = $thumbnail_width; - $thumb_h = $thumbnail_height; - } - - $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h); - imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); - - switch ($ext) - { - case 'png': - imagepg($dst_img, '.thumbs/'.$folder.'/'.$image); - break; - case 'jpg': - case 'jpeg': - imagejpeg($dst_img, '.thumbs/'.$folder.'/'.$image); - break; - case 'gif': - imagegif($dst_img, '.thumbs/'.$folder.'/'.$image); - break; - case 'bmp': - imagebmp($dst_img, '.thumbs/'.$folder.'/'.$image); - break; - } - - imagedestroy($dst_img); - imagedestroy($src_img); - - return; - } - - function array_to_xml(&$array, $tag_name = 'image', $headless = false) - { - error_reporting(E_ALL ^ E_NOTICE); - - // Include XML_Serializer - require_once 'XML/Serializer.php'; - - // An array of serializer options - $serializer_options = array ( - 'addDecl' => !$headless, - 'addDoctype' => true, - 'encoding' => 'ISO-8859-1', - 'indent' => ' ', - 'indentAttributes' => '_auto', - 'rootName' => 'layout', - 'defaultTagName' => $tag_name, - 'mode' => 'simplexml', - 'scalarAsAttributes' => true, - 'doctype' => array ( - 'id' => '-//picfinity//Gallery Layout//EN', - 'uri' => 'http://www.sunset-cigarette.co.uk/gallery/gallery.dtd' - ) - ); - - // Instantiate the serializer with the options - $Serializer = &new XML_Serializer($serializer_options); - - // Serialize the data structure - $status = $Serializer->serialize($array); - - // Check whether serialization worked - if (PEAR::isError($status)) { - die($status->getMessage()); - } - - // return the XML document - return $Serializer->getSerializedData(); - } - - function xml_to_xhtml($xml, $xsl_file, $params = array()) - { - $ver = explode( '.', PHP_VERSION ); - $ver_num = $ver[0] . $ver[1] . $ver[2]; - - if ( $ver_num < 500 ) - { - $arguments = array('/_xml' => $xml); - $xsltproc = xslt_create(); - $html = xslt_process($xsltproc, 'arg:/_xml', $xsl_file, NULL, $arguments); - - if (empty($html)) { - die('XSLT processing error: '. xslt_error($xsltproc)); - } - xslt_free($xsltproc); - return $html; - } - else - { - $doc = new DOMDocument(); - $xsl = new XSLTProcessor(); - - $doc->load($xsl_file); - $xsl->importStyleSheet($doc); - - $doc->loadXML($xml); - $xsl->setParameter('', $params); - - 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); - } -?> - Copied: trunk/.themes (from rev 27, .themes) Copied: trunk/.themes/ajax (from rev 28, .themes/ajax) Copied: trunk/.themes/gallery (from rev 28, .themes/gallery) Copied: trunk/gallery.dtd (from rev 27, gallery.dtd) =================================================================== --- trunk/gallery.dtd (rev 0) +++ trunk/gallery.dtd 2007-08-12 20:06:30 UTC (rev 29) @@ -0,0 +1,20 @@ +<!ELEMENT layout (themes,folder*)> +<!ELEMENT folder (folder*,image*)> +<!ELEMENT themes (theme*)> +<!ELEMENT image EMPTY> +<!ELEMENT theme EMPTY> + +<!ATTLIST layout id ID #IMPLIED> +<!ATTLIST layout name CDATA #REQUIRED> + +<!ATTLIST folder id ID #IMPLIED> +<!ATTLIST folder name CDATA #REQUIRED> + +<!ATTLIST themes id ID #IMPLIED> +<!ATTLIST themes name CDATA #REQUIRED> + +<!ATTLIST theme id ID #IMPLIED> +<!ATTLIST theme name CDATA #REQUIRED> + +<!ATTLIST image id ID #IMPLIED> +<!ATTLIST image file CDATA #REQUIRED> \ No newline at end of file Copied: trunk/index.php (from rev 27, index.php) =================================================================== --- trunk/index.php (rev 0) +++ trunk/index.php 2007-08-12 20:06:30 UTC (rev 29) @@ -0,0 +1,378 @@ +<?php + // site options + $site_name = "Picfinity"; + + // 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; + } + + // create thumbnails for images that don't have one already + $create_thumbnails = true; + + // create a flat HTML version of the page + $create_html = false; + + // create the gallery.xml file (for use by themes + $create_xml = true; + + // 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; + + // valid images to be shown + $valid_image_formats = array('png', 'gif', 'jpg', 'jpeg', 'bmp'); + + // get the layout of the current dir + $site_layout = create_folder_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) + { + $fh = fopen("gallery.xml", "w"); + fwrite($fh, $xml); + fclose($fh); + } + + // pass the XML to the theme and get the HTML back + $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) + { + $fh = fopen("index.html", "w"); + fwrite($fh, $html); + fclose($fh); + } + + // echo the HTML to the screen + echo $html; + + // 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; + 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 = "id" . md5($folder); + + // 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 + $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") && + $enable_themes) + { + 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) + { + continue; + } + + // 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) + 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 + { + $ext = strtolower(substr($folder_entry, strrpos($folder_entry, '.') + 1)); + + if (in_array($ext, $valid_image_formats)) + { + // create a thumbnail if we've been told to + if ($create_thumbnails) + { + create_thumbnail($folder, $folder_entry, $ext); + } + $image_id = "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"; + } + } + } + + // 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 = "id" . md5(".themes"); + + // create the themes node + $layout = array('name' => '.themes', 'id' => $themes_id); + $theme_xml = "<themes id=\"$themes_id\" name=\".themes\">\n"; + + // get the 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)) + { + // 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)) + { + $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"; + + if ($use_pear) return $layout; + else return $theme_xml; + } + + function create_thumbnail($folder, $image, $ext) + { + global $thumbnail_width; + global $thumbnail_height; + + if (file_exists('.thumbs/'.$folder.'/'.$image)) + { + // if it already exists, do nothing + return; + } + if (!is_dir('.thumbs/'.$folder)) + { + MakeDirectory('.thumbs/'.$folder, 0777); + chmod('.thumbs/'.$folder, 0777); + } + + $src_img; + switch ($ext) + { + case 'png': + $src_img = imagecreatefrompng($folder.'/'.$image); + break; + case 'jpg': + case 'jpeg': + $src_img = imagecreatefromjpeg($folder.'/'.$image); + break; + case 'gif': + $src_img = imagecreatefromgif($folder.'/'.$image); + break; + case 'bmp': + $src_img = imagecreatefrombmp($folder.'/'.$image); + break; + default: + return; + break; + } + + $old_x = imageSX($src_img); + $old_y = imageSY($src_img); + + if ($old_x > $old_y) { + $thumb_w = $thumbnail_width; + $thumb_h = $old_y * ($thumbnail_height/$old_x); + } + else if ($old_x < $old_y) { + $thumb_w = $old_x * ($thumbnail_width/$old_y); + $thumb_h = $thumbnail_height; + } + else if ($old_x == $old_y) { + $thumb_w = $thumbnail_width; + $thumb_h = $thumbnail_height; + } + + $dst_img = ImageCreateTrueColor($thumb_w, $thumb_h); + imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $thumb_w, $thumb_h, $old_x, $old_y); + + switch ($ext) + { + case 'png': + imagepg($dst_img, '.thumbs/'.$folder.'/'.$image); + break; + case 'jpg': + case 'jpeg': + imagejpeg($dst_img, '.thumbs/'.$folder.'/'.$image); + break; + case 'gif': + imagegif($dst_img, '.thumbs/'.$folder.'/'.$image); + break; + case 'bmp': + imagebmp($dst_img, '.thumbs/'.$folder.'/'.$image); + break; + } + + imagedestroy($dst_img); + imagedestroy($src_img); + + return; + } + + function array_to_xml(&$array, $tag_name = 'image', $headless = false) + { + error_reporting(E_ALL ^ E_NOTICE); + + // Include XML_Serializer + require_once 'XML/Serializer.php'; + + // An array of serializer options + $serializer_options = array ( + 'addDecl' => !$headless, + 'addDoctype' => true, + 'encoding' => 'ISO-8859-1', + 'indent' => ' ', + 'indentAttributes' => '_auto', + 'rootName' => 'layout', + 'defaultTagName' => $tag_name, + 'mode' => 'simplexml', + 'scalarAsAttributes' => true, + 'doctype' => array ( + 'id' => '-//picfinity//Gallery Layout//EN', + 'uri' => 'http://www.sunset-cigarette.co.uk/gallery/gallery.dtd' + ) + ); + + // Instantiate the serializer with the options + $Serializer = &new XML_Serializer($serializer_options); + + // Serialize the data structure + $status = $Serializer->serialize($array); + + // Check whether serialization worked + if (PEAR::isError($status)) { + die($status->getMessage()); + } + + // return the XML document + return $Serializer->getSerializedData(); + } + + function xml_to_xhtml($xml, $xsl_file, $params = array()) + { + $ver = explode( '.', PHP_VERSION ); + $ver_num = $ver[0] . $ver[1] . $ver[2]; + + if ( $ver_num < 500 ) + { + $arguments = array('/_xml' => $xml); + $xsltproc = xslt_create(); + $html = xslt_process($xsltproc, 'arg:/_xml', $xsl_file, NULL, $arguments); + + if (empty($html)) { + die('XSLT processing error: '. xslt_error($xsltproc)); + } + xslt_free($xsltproc); + return $html; + } + else + { + $doc = new DOMDocument(); + $xsl = new XSLTProcessor(); + + $doc->load($xsl_file); + $xsl->importStyleSheet($doc); + + $doc->loadXML($xml); + $xsl->setParameter('', $params); + + 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. |