[Picfinity-commit] SF.net SVN: picfinity: [54] trunk
Status: Beta
Brought to you by:
espadav8
From: <esp...@us...> - 2007-08-26 11:13:34
|
Revision: 54 http://picfinity.svn.sourceforge.net/picfinity/?rev=54&view=rev Author: espadav8 Date: 2007-08-25 03:04:59 -0700 (Sat, 25 Aug 2007) Log Message: ----------- Remove the use of a PEAR module to create the XML, it complicated things more than needed Add any comments to the image xml if an id was passed in Update the dtd to show this (and correct an error with the themes entry) Modified Paths: -------------- trunk/gallery.dtd trunk/index.php Modified: trunk/gallery.dtd =================================================================== --- trunk/gallery.dtd 2007-08-19 11:55:45 UTC (rev 53) +++ trunk/gallery.dtd 2007-08-25 10:04:59 UTC (rev 54) @@ -1,9 +1,17 @@ -<!ELEMENT layout (themes,folder*)> +<!ELEMENT layout (themes?,folder*)> <!ELEMENT folder (folder*,image*)> <!ELEMENT themes (theme*)> -<!ELEMENT image EMPTY> +<!ELEMENT image (comment*)> <!ELEMENT theme EMPTY> +<!ELEMENT comment (name,www,email,comment_text,rating,added)> +<!ELEMENT name (#CDATA)> +<!ELEMENT www (#CDATA)> +<!ELEMENT email (#CDATA)> +<!ELEMENT comment_text (#CDATA)> +<!ELEMENT rating (#CDATA)> +<!ELEMENT added (#CDATA)> + <!ATTLIST layout id ID #IMPLIED> <!ATTLIST layout name CDATA #REQUIRED> @@ -17,4 +25,4 @@ <!ATTLIST theme name CDATA #REQUIRED> <!ATTLIST image id ID #IMPLIED> -<!ATTLIST image file CDATA #REQUIRED> \ No newline at end of file +<!ATTLIST image file CDATA #REQUIRED> Modified: trunk/index.php =================================================================== --- trunk/index.php 2007-08-19 11:55:45 UTC (rev 53) +++ trunk/index.php 2007-08-25 10:04:59 UTC (rev 54) @@ -38,9 +38,6 @@ // 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; @@ -91,25 +88,18 @@ $valid_image_formats = array('png', 'gif', 'jpg', 'jpeg', 'bmp'); // get the layout of the current dir - $site_layout = create_folder_layout('.'); + $site_layout_xml = 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); + fwrite($fh, $site_layout_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)); + $html = xml_to_xhtml($site_layout_xml, ".themes/$theme/$theme.xsl", array('title' => $site_name, 'post_id' => $post_id)); // create the flat version if we need to if ($create_html) @@ -127,10 +117,11 @@ // 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, $create_thumbnails, $use_pear, $enable_themes, $use_db, $current_images; + global $valid_image_formats, $create_thumbnails, $enable_themes, $use_db, $current_images, $post_id; // get the name of the folder or '' if it's the root $name = substr($folder, strrpos($folder, '/') + 1); @@ -138,15 +129,10 @@ // 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 + // create the XML if ($name == "") - $folder_layout_xml = "<?xml version=\"1.0\"?>" - . "\n" - . "<!DOCTYPE layout PUBLIC \"-//picfinity//Gallery Layout//EN\" \"http://www.espadav8.co.uk/gallery/gallery.dtd\">" - . "\n" + $folder_layout_xml = "<?xml version=\"1.0\"?>\n" + . "<!DOCTYPE layout PUBLIC \"-//picfinity//Gallery Layout//EN\" \"http://www.espadav8.co.uk/gallery/gallery.dtd\">\n" . "<layout id=\"$folder_id\" name=\"\">\n"; else $folder_layout_xml = "<folder id=\"$folder_id\" name=\"$name\">\n"; @@ -162,15 +148,12 @@ // 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 it's a folder and the path of it is ./.themes then create the list of themes if ((($folder . '/' . $folder_entry) == "./.themes") && (is_dir('./themes')) && $enable_themes) { - if ($use_pear) - $layout['themes'] = create_themes_layout(); - else - $folder_layout_xml .= create_themes_layout(); + $folder_layout_xml .= create_themes_layout(); } // else if it starts with a . ignore it @@ -183,10 +166,7 @@ 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); + $folder_layout_xml .= create_folder_layout($folder . '/' . $folder_entry); } // otherwise check to see if it's an image @@ -201,45 +181,96 @@ { 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"; - if (($use_db) && (!in_array($image_id, $current_images))) + if (!in_array($image_id, $current_images)) { - $query = "INSERT INTO images (image_md5) VALUES ('$image_id')"; - $result = mysql_query($query); - if (!$result) - { - die (mysql_error()); - } + add_image_to_db($image_id); } + + if (($use_db) && ($image_id == $post_id)) + { + $folder_layout_xml .= "\t<image id=\"$image_id\" file=\"$folder_entry\">\n" + . get_comments($image_id) + . "\t</image>\n"; + } + else + { + $folder_layout_xml .= "\t<image id=\"$image_id\" file=\"$folder_entry\" />\n"; + } } } } - // close up the hand-coded XML + // close up the 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; + // return the XML + return $folder_layout_xml; } - function create_themes_layout() + function add_image_to_db($image_id) { - global $use_pear; + $query = "INSERT INTO images (image_md5) VALUES ('$image_id')"; + $result = mysql_query($query); + if (!$result) + { + // die (mysql_error()); + } + } + function get_comments($image_id) + { + $query = " + SELECT user_name + , user_www + , user_email + , user_comment + , comment_rating + , date_added + FROM comments + INNER JOIN images + WHERE images.image_id = comments.image_id + AND images.image_md5 = '$image_id' + ORDER BY date_added DESC"; + + $result = mysql_query($query); + + if (mysql_num_rows($result) > 0) + { + while ($row = mysql_fetch_assoc($result)) + { + $comments_xml .= "<comment>" + . "<name>$row[user_name]</name>" + . "<www>$row[user_www]</www>" + . "<email>$row[user_email]</email>" + . "<comment_text>$row[user_comment]</comment_text>" + . "<rating>$row[comment_rating]</rating>" + . "<added>$row[date_added]</added>" + . "</comment>"; + } + + return $comments_xml; + } + else + { + return ""; + } + } + + function create_themes_layout() + { $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))) { + while (false !== ($filename = readdir($dh))) + { $folder_contents[] = $filename; } @@ -257,15 +288,13 @@ 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; + return $theme_xml; } function create_thumbnail($folder, $image, $ext) @@ -303,15 +332,18 @@ $old_x = imageSX($src_img); $old_y = imageSY($src_img); - if ($old_x > $old_y) { + if ($old_x > $old_y) + { $thumb_w = $thumbnail_width; $thumb_h = $old_y * ($thumbnail_height/$old_x); } - else if ($old_x < $old_y) { + else if ($old_x < $old_y) + { $thumb_w = $old_x * ($thumbnail_width/$old_y); $thumb_h = $thumbnail_height; } - else if ($old_x == $old_y) { + else if ($old_x == $old_y) + { $thumb_w = $thumbnail_width; $thumb_h = $thumbnail_height; } @@ -342,45 +374,6 @@ 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.espadav8.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 ); @@ -390,7 +383,7 @@ { $arguments = array('/_xml' => $xml); $xsltproc = xslt_create(); - $html = xslt_process($xsltproc, 'arg:/_xml', $xsl_file, NULL, $arguments); + $html = xslt_process($xsltproc, 'arg:/_xml', $xsl_file, NULL, $arguments); if (empty($html)) { die('XSLT processing error: '. xslt_error($xsltproc)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |