[Picfinity-commit] SF.net SVN: picfinity: [3]
Status: Beta
Brought to you by:
espadav8
From: <esp...@us...> - 2007-07-18 10:34:09
|
Revision: 3 http://picfinity.svn.sourceforge.net/picfinity/?rev=3&view=rev Author: espadav8 Date: 2007-07-18 03:34:06 -0700 (Wed, 18 Jul 2007) Log Message: ----------- - Initial import Added Paths: ----------- .project .projectOptions index.php Added: .project =================================================================== --- .project (rev 0) +++ .project 2007-07-18 10:34:06 UTC (rev 3) @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>Egallery</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.php.core.PhpIncrementalProjectBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.wst.validation.validationbuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.php.core.PHPNature</nature> + </natures> +</projectDescription> Added: .projectOptions =================================================================== --- .projectOptions (rev 0) +++ .projectOptions 2007-07-18 10:34:06 UTC (rev 3) @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<phpProjectOptions> + <projectOption name="org.eclipse.php.core.contextRoot"> + </projectOption> + <projectOption name="org.eclipse.php.core.defaultEncoding"> + </projectOption> + <includepath> + </includepath> +</phpProjectOptions> Added: index.php =================================================================== --- index.php (rev 0) +++ index.php 2007-07-18 10:34:06 UTC (rev 3) @@ -0,0 +1,215 @@ +<?php + + // site options + $site_name = "Andrew's Gallery"; + $theme = ($_GET['theme'] != '') ? $_GET['theme'] : "ajax" ; + + // not implemented yet + $max_folders = 0; // 0 = unlimited + + $create_thumbnails = true; + $create_html = true; + $create_xml = true; + + // 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('.'); + + $xml = array_to_xml($site_layout); + + if ($create_xml) + { + file_put_contents("gallery.xml", $xml); + } + + $html = xml_to_xhtml($xml, ".themes/$theme/$theme.xsl", array('title' => $site_name)); + + if ($create_html) + { + file_put_contents("index.html", $html); + } + + echo $html; + + // echo "<div style=\"display:none;\">$xml</div>"; + + + function create_folder_layout($folder) + { + global $valid_image_formats; + global $create_thumbnails; + + // get a listing of the files/folder + $folder_contents = scandir($folder); + $name = substr($folder, strrpos($folder, '/') + 1); + $id = uniqid('id'); + $layout = array('name' => $name, 'id' => $id); + + // for each entry + while (list(,$folder_entry) = each($folder_contents)) + { + if (strpos($folder_entry, '.') === 0) + { + // this is a hidden file/folder, ignore + } + // if it's a directory and doesn't start with a . + 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[] = array($folder_entry => $sub_layout); + $layout['folder'][] = $sub_layout; + } + 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)) + { + if ($create_thumbnails) + { + // create a thumbnail + create_thumbnail($folder, $folder_entry, $ext); + } + $layout['image'][] = array('id' => uniqid('id'), 'file' => $folder_entry); + } + } + } + + return $layout; + } + + function create_thumbnail($folder, $image, $ext) + { + if (!is_dir('.thumbs/'.$folder)) + { + mkdir('.thumbs/'.$folder, 0777, TRUE); + chmod('.thumbs/'.$folder, 0777); + } + if (file_exists('.thumbs/'.$folder.'/'.$image)) + { + // if it already exists, do nothing + return; + } + else + { + $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; + } + + $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); + } + else if ($old_x < $old_y) { + $thumb_w = $old_x * ($new_w/$old_y); + $thumb_h = $new_h; + } + else if ($old_x == $old_y) { + $thumb_w = $new_w; + $thumb_h = $new_h; + } + + $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); + } + } + + 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, + 'encoding' => 'ISO-8859-1', + 'indent' => ' ', + 'indentAttributes' => '_auto', + 'rootName' => 'layout', + 'defaultTagName' => $tag_name, + 'mode' => 'simplexml', + 'scalarAsAttributes' => true + + ); + + // 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()); + } + + // print_r($Serializer->options); + + // return the XML document + return $Serializer->getSerializedData(); + } + + function xml_to_xhtml($xml, $xsl_file, $params = array()) + { + $doc = new DOMDocument(); + $xsl = new XSLTProcessor(); + + $doc->load($xsl_file); + $xsl->importStyleSheet($doc); + + $doc->loadXML($xml); + + $xsl->setParameter('', $params); + + $html = $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. |