class ExtensionFilter extends FilterIterator {
private $ext = array();
private $it;
public function __construct(DirectoryIterator $it, $ext) {
parent::__construct($it);
$this->it = $it;
$this->ext = $ext;
}
public function accept() {
$cur = $this->current();
$ext = array_pop(explode('.', $cur->getFilename()));
if ($this->it->isDir()==false && in_array($ext,$this->ext)) {
return true;
} else {
return false;
}
}
}
class Image {
public static function process($file,$images,$xml) {
$info = pathinfo($file);
if(!array_key_exists($info["basename"],$images)) {
$child = $xml->addChild("image");
$child->addChild("filename",$info["basename"]);
}
return $xml;
}
}
class Pictet2 {
static private $_instance = null;
private $_xml,
$_path,
$_images = array(),
$_dir;
private function __construct($path) {
$this->_path = $path;
chdir($path);
}
static public function initialize($path) {
if(null==self::$_instance) {
self::$_instance = new Pictet2($path);
}
return self::$_instance;
}
public function buildPage() {
if(file_exists(".xml/files.xml")) {
$xml = simplexml_load_file(".xml/files.xml");
foreach($xml->image as $image) {
$this->_images["$image->filename"] = $image;
}
} else {
if(!file_exists(".xml")) {
mkdir(".xml");
}
$xml = new simpleXMLElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><images></images>");
}
$this->_dir = new ExtensionFilter(new DirectoryIterator("."), array("jpg"));
foreach($this->_dir as $file) {
$name = $file->getFilename();
if(!array_key_exists($file->getFilename(), $this->_images)) {
$image = $xml->addChild("image");
$image->addChild("filename",$name);
$this->_images[$name] = $image;
}
if(!$this->_images[$name]->hash) {
$image->hash = md5_file($name);
}
}
file_put_contents(".xml/files.xml", $xml->asXML());
}
}
$pictet2 = Pictet2::initialize(".");
$pictet2->buildPage();
<?
/*
PictetBeta v2.5.1
Filename: index.php
Description: does everything pretty much.
SVN: Revision $WCREV$ on $WCDATE$
License (MIT License)
Copyright (c) 2005 ----------
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
// CONFIG VARIABLES
$_CONFIG["GALLERY_TITLE"] = "Pictet"; // gallery name
$_CONFIG["MOD_ALIAS"] = true; // try turning this off if you are experiencing problems
$_CONFIG["FILE_TYPES"] = "jpg,png,gif,JPG"; // types of files that are listed, dont change these for now!
$_CONFIG["THUMB_WIDTH"] = 120; // width in pixels of the thumbnails, note these values affect the layout, don't modify unless you know how to edit the css file
$_CONFIG["THUMB_HEIGHT"] = 120; // see above
$_CONFIG["IMAGES_PER_PAGE"] = 45; // number of images on a page, please don't change unless you know how to make changes to the css
$_CONFIG["IMAGES_PER_ROW"] = 5; // make this a multiple of the above value for best effect
$_CONFIG["ALLOW_COMMENTS"] = true; // allow or don't allow comments
$_CONFIG["METHOD"] = 1; // sort method, 1 is by file name, 2 is by modify date
$_CONFIG["DIRECTION"] = 2; // sort ascending (2) or descending (1)
$_CONFIG["LOGIN_TIME"] = 24; // how long someone will stay logged in for in hours...
$_CONFIG["NO_GALLERY"] = false; // go straight to the viewing mode
$_CONFIG["TEXT_LINKS"] = false; // use text navigation links for the image gallery
$_CONFIG["RENAME_ERRORS"] = true;
// Advice: Look but don't touch.... ^__- (unless your very very very brave!)
ini_set("safe_mode", false);
ini_set("safe_mode_gid", false);
$script_info = pathinfo($_SERVER["SCRIPT_FILENAME"]);
$SCRIPT_NAME = $script_info["basename"];
if(!function_exists(hash_file)) {
function hash_file($algo, $file) {
if(is_string($file)) {
return md5_file($file);
}
}
}
if($_CONFIG["MOD_ALIAS"] && (!$_SERVER["SCRIPT_NAME"] || !$_SERVER["SCRIPT_FILENAME"])) {
$path = $_SERVER["REQUEST_URI"];
$path = preg_replace("/(.*)?.*/", "$1", $path);
//print $path;
$parts = explode("/", $path);
$parts = array_unique($parts);
$file_info = pathinfo($path);
if(preg_match("/^d+/", $parts[1])) {
$_REQUEST["off"] = $parts[1];
$off_set = true;
if($parts[2] === "comments") {
if(!$_REQUEST["image"]) $_REQUEST["image"] = $parts[2];
if(!$_REQUEST["action"]) $_REQUEST["action"] = "comments";
$modded = true;
} elseif($parts[2] === "cast") {
if(!$_REQUEST["image"]) $_REQUEST["image"] = $parts[2];
if(!$_REQUEST["action"]) $_REQUEST["action"] = "cast";
$modded = true;
} elseif($parts[2] === "_thumbs") {
$extn = $file_info['extension'];
$path = $parts[2]."/".$parts[3];
if(is_file(".".$path) && $file_info["basename"]) {
header('Content-Type: image/'.$extn);
$open = fopen($gal."_thumbs/".$file_info["basename"], "r");
fpassthru($open);
fclose($open);
exit();
} else {
header('HTTP/1.0 404 Not Found');
die;
}
exit();
} else {
$accept = split(",",$_CONFIG["FILE_TYPES"]);
$file_info = pathinfo($path);
if($file_info['extension'] === "css") {
$path = $parts[2]."/".$parts[3];
if(is_file(".".$path) && $file_info["basename"]) {
header('Content-Type: text/css');
$open = fopen($gal."_css/".$file_info["basename"], "r");
fpassthru($open);
fclose($open);
exit();
} else {
header('HTTP/1.0 404 Not Found');
die;
}
} elseif(in_array(strtolower($file_info['extension']), $accept)) {
$extn = $file_info['extension'];
$path = $parts[2]."/".$parts[3];
if(is_file(".".$path) && $file_info["basename"]) {
header('Content-Type: image/'.$extn);
$open = fopen($gal.$file_info["basename"], "r");
fpassthru($open);
fclose($open);
exit();
} else {
header('HTTP/1.0 404 Not Found');
die;
}
}
}
} elseif(preg_match("/^d+/", $parts[2])) {
$_REQUEST["off"] = $parts[2];
$_REQUEST["gallery"] = $parts[1];
if($parts[3] === "comments") {
if(!$_REQUEST["image"]) $_REQUEST["image"] = $parts[4];
if(!$_REQUEST["action"]) $_REQUEST["action"] = "comments";
$modded = true;
} elseif($parts[3] === "cast") {
if(!$_REQUEST["image"]) $_REQUEST["image"] = $parts[4];
if(!$_REQUEST["action"]) $_REQUEST["action"] = "cast";
$modded = true;
} elseif($parts[3] === "_thumbs") {
$extn = $file_info['extension'];
$path = $parts[3]."/".$parts[4];
if(is_file(".".$path) && $file_info["basename"]) {
header('Content-Type: image/'.$extn);
$open = fopen($gal."_thumbs/".$file_info["basename"], "r");
fpassthru($open);
fclose($open);
exit();
} else {
header('HTTP/1.0 404 Not Found');
die;
}
exit();
} else {
$accept = split(",",$_CONFIG["FILE_TYPES"]);
$file_info = pathinfo($path);
if($file_info['extension'] === "css") {
$path = $parts[3]."/".$parts[4];
if(is_file(".".$path) && $file_info["basename"]) {
header('Content-Type: text/css');
$open = fopen($gal."_css/".$file_info["basename"], "r");
fpassthru($open);
fclose($open);
exit();
} else {
header('HTTP/1.0 404 Not Found');
die;
}
} elseif(in_array(strtolower($file_info['extension']), $accept)) {
$extn = $file_info['extension'];
$path = $parts[3]."/".$parts[4];
if(is_file(".".$path) && $file_info["basename"]) {
header('Content-Type: image/'.$extn);
$open = fopen($gal.$file_info["basename"], "r");
fpassthru($open);
fclose($open);
exit();
} else {
header('HTTP/1.0 404 Not Found');
die;
}
}
}
} else {
if($parts[1] === "comments") {
if(!$_REQUEST["image"]) $_REQUEST["image"] = $parts[2];
if(!$_REQUEST["action"]) $_REQUEST["action"] = "comments";
$modded = true;
} elseif($parts[1] === "cast") {
if(!$_REQUEST["image"]) $_REQUEST["image"] = $parts[2];
if(!$_REQUEST["action"]) $_REQUEST["action"] = "cast";
$modded = true;
} elseif($parts[1] && !$file_info['extension']) {
if(!$_REQUEST["gallery"]) $_REQUEST["gallery"] = $parts[1];
$modded = true;
} elseif($parts[2] === "comments") {
if(!$_REQUEST["gallery"]) $_REQUEST["gallery"] = $parts[1];
if(!$_REQUEST["image"]) $_REQUEST["image"] = $parts[3];
if(!$_REQUEST["action"]) $_REQUEST["action"] = "comments";
$modded = true;
} elseif($parts[2] === "cast") {
if(!$_REQUEST["gallery"]) $_REQUEST["gallery"] = $parts[1];
if(!$_REQUEST["image"]) $_REQUEST["image"] = $parts[3];
if(!$_REQUEST["action"]) $_REQUEST["action"] = "cast";
$modded = true;
} elseif($parts[1] === "_thumbs" || $parts[2] === "_thumbs") {
$extn = $file_info['extension'];
if($parts[2] === "_thumbs") {
$gal = $parts[1] . "/";
}
if(is_file(".".$path) && $file_info["basename"]) {
header('Content-Type: image/'.$extn);
$open = fopen($gal."_thumbs/".$file_info["basename"], "r");
fpassthru($open);
fclose($open);
exit();
} else {
header('HTTP/1.0 404 Not Found');
die;
}
exit();
} else {
$accept = split(",",$_CONFIG["FILE_TYPES"]);
$file_info = pathinfo($path);
if($file_info['extension'] === "css") {
if($parts[2] === "_css") {
$gal = $parts[1] . "/";
}
if(is_file(".".$path) && $file_info["basename"]) {
header('Content-Type: text/css');
$open = fopen($gal."_css/".$file_info["basename"], "r");
fpassthru($open);
fclose($open);
exit();
} else {
header('HTTP/1.0 404 Not Found');
die;
}
} elseif(in_array(strtolower($file_info['extension']), $accept)) {
$extn = $file_info['extension'];
if($parts[2]) {
$gal = $parts[1] . "/";
}
if(is_file(".".$path) && $file_info["basename"]) {
header('Content-Type: image/'.$extn);
$open = fopen($gal.$file_info["basename"], "r");
fpassthru($open);
fclose($open);
exit();
} else {
header('HTTP/1.0 404 Not Found');
die;
}
}
}
}
}
if($_REQUEST["gallery"] && !$off_set) {
if(!chdir("./".$_REQUEST["gallery"])) {
die();
}
}
if(file_exists("_xml/config.xml")) {
load_config();
}
if(!function_exists("scandir")) {
function scandir($dir = './', $sort = 0) {
$dir_open = @ opendir($dir);
if (! $dir_open)
return false;
while (($dir_content = readdir($dir_open)) !== false)
$files[] = $dir_content;
if ($sort == 1)
rsort($files, SORT_STRING);
else
sort($files, SORT_STRING);
return $files;
}
}
if($_REQUEST["off"]) {
$off = $_REQUEST["off"];
$start_off = ($off-1)*$_CONFIG["IMAGES_PER_PAGE"];
$end = $_CONFIG["IMAGES_PER_PAGE"]*$off;
$gal_off_set = true;
} else {
$start_off = 0;
$end = $_CONFIG["IMAGES_PER_PAGE"];
}
if(!$_SERVER["SCRIPT_NAME"] || !$_SERVER["SCRIPT_FILENAME"]) {
$modded = true;
}
if($_REQUEST["gallery"]) {
$gal = $_REQUEST["gallery"] . "/";
} else {
if(!file_exists("_css/css.css")) {
if(!is_dir("_css")) {
mkdir("_css");
}
$open = fopen("_css/css.css", "w");
fwrite($open, print_css());
fclose($open);
}
$gal = null;
}
$gd2=checkgd();
if($_REQUEST["debug"]) {
header("Content-type: text/plain");
print_r($_SERVER);
die;
}
$action = $_REQUEST["action"];
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////
if(!$action) {
$files = directory(".",$_CONFIG["FILE_TYPES"]);
$files = sort_images($files);
if($_CONFIG["NO_GALLERY"]) {
if($modded) {
if($gal) {
header("Location: ".$gal."comments/".$files[0]);
} else {
header("Location: /comments/".$files[0]);
}
} else {
if($gal) {
header("Location: $SCRIPT_NAME?gallery=".$_REQUEST["gallery"]."&action=comments&image=".$files[0]);
} else {
header("Location: $SCRIPT_NAME&action=comments&image=".$files[0]);
}
}
die;
}
if(!is_dir("_xml")) {
mkdir("_xml");
}
if(!file_exists("_xml/images.xml")) {
if(!is_dir("_thumbs")) {
mkdir("_thumbs");
}
$start = microtime(true);
$x = $start_off;
while($x <= $end-1 && $files[$x]) {
$file = $files[$x];
if(microtime(true)-$start < 25) {
if(!file_exists("_thumbs/tn_".$file) || filesize("_thumbs/tn_".$file) < 1024) {
if(!createthumb($file, "_thumbs/tn_".$file, $_CONFIG["THUMB_WIDTH"], $_CONFIG["THUMB_HEIGHT"])) {
$files[$x] = "";
if($_CONFIG["RENAME_ERRORS"]) {
if(!file_exists($file.".CORRUPT")) {
rename($file, $file.".CORRUPT");
} else {
$rand = rand(0,9999);
while(file_exists($file.".$rand.CORRUPT")) {
$rand = rand(0,9999);
}
rename($file, $file.".$rand.CORRUPT");
}
}
} else {
$hash = "<hash>".hash_file('md5',$file)."</hash>\n";
$filename = "<filename>".$file."</filename>\n";
$filexml .= " <file>\n"." $filename $hash </file>\n";
$xml = "<?xml version=\"1.0\"?>\n<files>\n".$filexml."</files>";
$fp = fopen("_xml/images.xml","w");
fwrite($fp, $xml);
fclose($fp);
}
}
} else {
$xml = "<?xml version=\"1.0\"?>\n<files>\n".$filexml."</files>";
$fp = fopen("_xml/images.xml","w");
fwrite($fp, $xml);
fclose($fp);
header("Location: " . $_SERVER["REQUEST_URI"]);
}
++$x;
}
$xml = "<?xml version=\"1.0\"?>\n<files>\n".$filexml."</files>";
$open = fopen("_xml/images.xml", "w");
fwrite($open, $xml);
fclose($open);
} else {
$x = $start_off;
while($x <= $end-1 && $files[$x]) {
$file = $files[$x];
if(is_array($file)) {
$file = $file[0];
$files[$x] = $file;
}
$hashes[$file]["hash"] = hash_file('md5',$file);
++$x;
}
$xml = new XML('_xml/images.xml');
$i = 0;
foreach($xml->nodes as $node) {
if(is_array($node)) {
$node = $node[0];
}
if($node->name == "filename") {
$data[$i]["filename"] = trim($node->data);
} elseif($node->name == "hash") {
$data[$i]["hash"] = trim($node->data);
++$i;
}
}
for($i = 0; $i <= count($data)-1; ++$i) {
$fname = $data[$i]["filename"];
$fname = trim($fname);
if($hashes[$fname]) {
$hash = $data[$i]["hash"];
$hash = trim($hash);
if(file_exists($fname)) {
if($hashes[$fname]["hash"] == $hash) {
$hashes["$fname"]["ok"] = true;
if(!file_exists("_thumbs/tn_".$fname)) {
$make[] = $fname;
$changed = true;
}
} else {
$hashes["$fname"]["ok"] = false;
$changed = true;
}
} else {
if(file_exists("_thumbs/tn_".$fname)) {
unlink("_thumbs/tn_".$fname);
}
$changed = true;
unset($data[$i]);
}
}
}
if($hashes) {
foreach ($hashes as $key=>$val) {
if(!$hashes[$key]["ok"]) {
$make[] = $key;
$changed = true;
if(file_exists("_thumbs/tn_".$key)) {
unlink("_thumbs/tn_".$key);
}
}
}
}
if($changed) {
if($data) {
foreach($data as $f) {
if(is_array($f[0])) {
$f = $f[0];
}
$hash = "<hash>".$f["hash"]."</hash>\n";
$filename = "<filename>".$f["filename"]."</filename>\n";
$filexml .= " <file>\n"." $filename $hash </file>\n";
}
}
//var_dump($make);
if($make) {
$start = microtime(true);
foreach($make as $new) {
if(is_array($new)) {
$new = $new[0];
}
if(microtime(true)-$start < 25) {
if(!file_exists("_thumbs/tn_".$new) || filesize("_thumbs/tn_".$new) < 1024) {
if(createthumb($new, "_thumbs/tn_".$new, $_CONFIG["THUMB_WIDTH"], $_CONFIG["THUMB_HEIGHT"])) {
$hash = "<hash>".hash_file('md5',$new)."</hash>\n";
$filename = "<filename>".$new."</filename>\n";
$filexml .= " <file>\n"." $filename $hash </file>\n";
$xml = "<?xml version=\"1.0\"?>\n<files>\n".$filexml."</files>";
$fp = fopen("_xml/images.xml","w");
fwrite($fp, $xml);
fclose($fp);
} else {
$files[array_search($new, $files)] = "";
if(!file_exists($new.".CORRUPT")) {
rename($new, $new.".CORRUPT");
} else {
$rand = rand(0,9999);
while(file_exists($new.".$rand.CORRUPT")) {
$rand = rand(0,9999);
}
rename($new, $new.".$rand.CORRUPT");
}
}
}
} else {
$xml = "<?xml version=\"1.0\"?>\n<files>\n".$filexml."</files>";
$fp = fopen("_xml/images.xml","w");
fwrite($fp, $xml);
fclose($fp);
header("Location: " . $_SERVER["REQUEST_URI"]);
}
}
}
$xml = "<?xml version=\"1.0\"?>\n<files>\n".$filexml."</files>";
$fp = fopen("_xml/images.xml","w");
fwrite($fp, $xml);
fclose($fp);
//header("Location: " . $_SERVER["REQUEST_URI"]);
}
}
if($modded) {
$check = $path;
$check = strrev($check);
//print $slash;
if($check[0] != "/" && !$gal_off_set) {
$slash = $_REQUEST["gallery"]."/";
}
}
if($gal && file_exists("_css/css.css")) {
if(!$modded) {
$css = "@import \"_css/css.css\";\n@import \"" . $gal . "_css/css.css\";\n";
} else {
$css = "@import \"/_css/css.css\";\n@import \"$slash"."_css/css.css\";\n";
}
} elseif(!file_exists("_css/css.css") && !$modded) {
$css = "@import \"_css/css.css\";\n";
} else {
if(!$gal) {
$css = "@import \"_css/css.css\";\n";
} else {
$css = "@import \"/_css/css.css\";\n";
}
}
if($gal) {
$dirs = scandir("..");
} else {
$dirs = scandir(".");
}
foreach ($dirs as $potential) {
if(is_array($potential)) {
$potential = $potential[0];
}
if(is_dir($potential) || is_dir("../$potential")) {
if(!preg_match("/^[_|.].*/", $potential)) {
if($num = directory($potential, $_CONFIG["FILE_TYPES"])) {
$num = count($num);
$list[] = array("dir" => $potential, "num" => $num);
} elseif($num = directory("../".$potential, $_CONFIG["FILE_TYPES"])) {
$num = count($num);
$list[] = array("dir" => $potential, "num" => $num);
}
}
}
}
if($gal) {
$root_num = directory("../", $_CONFIG["FILE_TYPES"]);
$root_num = count($root_num);
} else {
$root_num = count($files);
}
$off = $_REQUEST["off"];
$max = $_CONFIG["IMAGES_PER_PAGE"];
if($max < count($files)) {
if($off) {
if($max*($off) < count($files)) {
$next = $off+1;
} else {
$next = null;
}
} else {
$next = 2;
}
} else {
$next = null;
}
if($off) {
if($off > 2) {
$back = $off - 1;
} else {
if($modded) {
$back = ".";
} else {
$back = "1";
}
}
}
$t = 0;
while($max*$t <= count($files)) {
++$t;
}
if($t > 1) {
$last = $t;
} else {
$last = null;
}
$image_container = $_CONFIG["IMAGES_PER_ROW"]*($_CONFIG["THUMB_WIDTH"]+7)+35;
//print $image_container;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><? print $_CONFIG["GALLERY_TITLE"]; if($gal) print "/" . $gal; ?></title>
******* type="text/css">
<? print $css; ?>
dl.images {
width: <? print $_CONFIG["THUMB_WIDTH"]+5; ?>px;
height: <? print $_CONFIG["THUMB_HEIGHT"]+5; ?>px;
}
#images {
width: <? print $image_container; ?>px;
}
#container {
width: <? print $image_container+250; ?>px;
</style>
</head>
****** id="gallery">
<div id="container">
<div id="images">
<div id="galNavTop">
<?
if($back && $off != 1) {
if($modded) {
?><a href="<? print $back; ?>"><<</a></li>
<a href=".">|<<</a></li>
<?
} else {
?><a href="?gallery=<? print $_REQUEST["gallery"]; ?>&off=<? print $back; ?>"><<</a> <a href="?gallery=<? print $_REQUEST["gallery"]; ?>">|<<</a>
<?
}
}
if($next) {
if($modded) {
?><a href="<? print $slash.$last; ?>">>>|</a> <a href="<? print $slash.$next; ?>">>></a><?
} else {
?><a href="?gallery=<? print $_REQUEST["gallery"]; ?>&off=<? print $last; ?>">>>|</a> <a href="?gallery=<? print $_REQUEST["gallery"]; ?>&off=<? print $next; ?>">>></a><?
}
}
?>
</div>
<?
$x = $start_off;
while($x <= $end-1 && $files[$x]) {
$i = 0;
print "<div class=\"imageRow\">\n";
while($i <= ($_CONFIG["IMAGES_PER_ROW"]-1) && $files[$x] && $x <= $end-1) {
?>
<dl class="images">
<dt><?
if($modded) {
print "<a href=\"$slash"."comments/".$files[$x]."\"><img src=\"$slash"."_thumbs/tn_".$files[$x]."\" alt=\"".$files[$x]."\" /></a>";
} else {
print "<a href=\"?gallery=".$_REQUEST["gallery"]."&action=comments&image=".$files[$x]."\"><img src=\"$gal"."_thumbs/tn_".$files[$x]."\" alt=\"".$files[$x]."\" /></a>";
}
?></dt>
<? if($_CONFIG["ALLOW_COMMENTS"]) { ?>
<dt><?
if($modded) {
if($comments = check_comments($files[$x])) { print "<a class=\"comments\" href=\"$slash"."comments/".$files[$x]."\">".$comments; if($comments > 1) print " comments</a>"; else print " comment</a>"; } else { print "<a href=\"$slash"."comments/".$files[$x]."\">Add Comment</a>"; }
} else {
if($comments = check_comments($files[$x])) { print "<a class=\"comments\" href=\"?gallery=".$_REQUEST["gallery"]."&action=comments&image=".$files[$x]."\">".$comments; if($comments > 1) print " comments</a>"; else print " comment</a>"; } else { print "<a href=\"?gallery=".$_REQUEST["gallery"]."&action=comments&image=".$files[$x]."\">Add Comment</a>"; }
}
?></dt>
<? } ?>
</dl>
<?
++$x;
++$i;
}
print "</div>\n";
}
?>
<div id="galNavBottom">
<?
if($back && $off != 1) {
if($modded) {
?><a href="<? print $back; ?>"><<</a> <a href=".">|<<</a>
<?
} else {
?><a href="?gallery=<? print $_REQUEST["gallery"]; ?>&off=<? print $back; ?>"><<</a> <a href="?gallery<? print $_REQUEST["gallery"]; ?>">|<<</a>
<?
}
}
if($next) {
if($modded) {
?><a href="<? print $slash.$last; ?>">>>|</a> <a href="<? print $slash.$next; ?>">>></a><?
} else {
?><a href="?gallery=<? print $_REQUEST["gallery"]; ?>&off=<? print $last; ?>">>>|</a> <a href="?gallery=<? print $_REQUEST["gallery"]; ?>&off=<? print $next; ?>">>></a><?
}
}
?>
</div>
</div>
<? if($list) { ?>
<div id="galleryList">
<ul>
<?
if($gal) {
if($modded) {
print "<li class=\"root\"><a class=\"top\" href=\"/\">".$_CONFIG["GALLERY_TITLE"]." Root ($root_num)</a></li>\n";
} else {
print "<li class=\"root\"><a class=\"top\" href=\".\">".$_CONFIG["GALLERY_TITLE"]." Root ($root_num)</a></li>\n";
}
} else {
print "<li class=\"root\"><a class=\"topSelected\" href=\".\">".$_CONFIG["GALLERY_TITLE"]." Root ($root_num)</a></li>\n";
}
foreach ($list as $dir) {
if(is_array($dir) && !$dir['dir']) {
$dir = $dir[0];
}
if($dir['dir'] == $_REQUEST["gallery"]) {
$class = " class=\"current\"";
} else {
$class = "";
}
if($modded) {
if($gal) {
print "<li><a$class href=\"/".$dir['dir']."\">".preg_replace("/_/", " ", $dir['dir'])." (".$dir['num'].")</a></li>\n";
} else {
print "<li><a$class href=\"".$dir['dir']."\">".preg_replace("/_/", " ", $dir['dir'])." (".$dir['num'].")</a></li>\n";
}
} else {
print "<li><a$class href=\"?gallery=".$dir['dir']."\">".preg_replace("/_/", " ", $dir['dir'])." (".$dir['num'].")</a></li>\n";
}
}
?>
</ul>
</div>
<? } ?>
</div>
</body>
</html>
<?
} elseif($action == "comments") {
$files = directory(".",$_CONFIG["FILE_TYPES"]);
$files = sort_images($files);
if(!file_exists($_REQUEST["image"])) {
print "Error: Image does not exist!";
die;
}
$key = array_search($_REQUEST["image"], $files);
//print $key;
if($key) {
$current_off = $key/$_CONFIG["IMAGES_PER_PAGE"];
}
//print $key;
$current_off = floor($current_off)+1;
if($key > 0) {
$last = $files[$key-1];
} else {
$last = null;
}
if($files[$key+1]) {
$next = $files[$key+1];
} else {
$next = null;
}
$text = $_CONFIG["TEXT_LINKS"];
if(!$text) {
if(!file_exists("_thumbs/tn_".$next) && $next) {
createthumb($file, "_thumbs/tn_".$file, $_CONFIG["THUMB_WIDTH"], $_CONFIG["THUMB_HEIGHT"]);
$hash = "<hash>".hash_file('md5',$file)."</hash>\n";
$filename = "<filename>".$file."</filename>\n";
$filexml .= " <file>\n"." $filename $hash </file>\n";
$xml = $filexml."</files>";
$fp = fopen("_xml/_comments/".$image.".xml", "r+");
fseek($fp, -8, SEEK_END);
fwrite($fp, $xml);
fclose($fp);
}
}
if($gal && file_exists("_css/css.css")) {
if(!$modded) {
$css = "@import \"_css/css.css\";\n@import \"" . $gal . "_css/css.css\";\n";
} else {
$css = "@import \"/../_css/css.css\";\n@import \"../$slash"."_css/css.css\";\n";
}
} elseif(!$modded) {
$css = "@import \"_css/css.css\";\n";
} else {
if(!$gal) {
$css = "@import \"../_css/css.css\";\n";
} else {
$css = "@import \"/_css/css.css\";\n";
}
}
$file = explode(".", $_REQUEST["image"]);
$image = $file[0];
//print "THIS IS $image";
if(file_exists("_xml/_comments/$image".".xml")) {
$xml = new XML("_xml/_comments/$image".'.xml');
$i = 0;
foreach($xml->nodes as $node) {
if(is_array($node)) {
$node = $node[0];
}
if($node->name == "name") {
$data[$i]["name"] = stripslashes(trim($node->data));
} elseif($node->name == "tripcode") {
$data[$i]["tripcode"] = trim($node->data);
} elseif($node->name == "title") {
$data[$i]["title"] = stripslashes(trim($node->data));
} elseif($node->name == "commentText") {
$data[$i]["comment"] = stripslashes(trim($node->data));
} elseif($node->name == "time") {
$data[$i]["time"] = trim($node->data);
++$i;
}
}
}
if($_COOKIE["pictetName"] && $_COOKIE["pictetTrip"]) {
$value = $_COOKIE["pictetName"]."#".$_COOKIE["pictetTrip"];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title><? print $_CONFIG["GALLERY_TITLE"]; if($gal) print "/" . $gal; ?></title>
******* type="text/css">
<? print $css; ?>
.nav {
width: <? print 3*$_CONFIG["THUMB_WIDTH"]; ?>px;
}
.nav a {
height: <? print $_CONFIG["THUMB_HEIGHT"]; ?>px;
width: <? print $_CONFIG["THUMB_WIDTH"]; ?>px;
}
</style>
</head>
****** id="commentPage">
<div class="container">
<div class="<? if($text) print "textnav"; else print "nav";?>">
<?
if($last) {
if($modded) {
if($text) {
print "<a class=\"textlink\" rel=\"Prev\" href=\"$last\">Last</a>\n";
} else {
print "<a rel=\"Prev\" style=\"background: url('../_thumbs/tn_$last') center center no-repeat;\" href=\"$last\">Previous Image</a>\n";
}
} else {
if($text) {
print "<a class=\"textlink\" rel=\"Prev\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$last."\">Last</a>\n";
} else {
if($gal) {
print "<a rel=\"Prev\" style=\"background: url('".$_REQUEST["gallery"]."/_thumbs/tn_$last') center center no-repeat;\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$last."\">Previous Image</a>\n";
} else {
print "<a rel=\"Prev\" style=\"background: url('_thumbs/tn_$last') center center no-repeat;\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$last."\">Previous Image</a>\n";
}
}
}
}
if(!$_CONFIG["NO_GALLERY"]) {
if($modded) {
print "<a class=\"up\" href=\"../$current_off\">Gallery</a>\n";
} else {
print "<a class=\"up\" href=\"?gallery=".$_REQUEST["gallery"]."&off=$current_off\">Gallery</a>";
}
} else {
if($text) print " | ";
}
if($next) {
if($modded) {
if($text) {
print "<a class=\"textlink\" rel=\"Next\" href=\"$next\">Next</a>\n";
} else {
print "<a rel=\"Next\" style=\"background: url('../_thumbs/tn_$next') center center no-repeat;\" href=\"$next\">Next Image</a>\n";
}
} else {
if($text) {
print "<a class=\"textlink\" rel=\"Next\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$next."\">Next</a>\n";
} else {
if($gal) {
print "<a rel=\"Next\" style=\"background: url('".$_REQUEST["gallery"]."/_thumbs/tn_$next') center center no-repeat;\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$next."\">Next Image</a>\n";
} else {
print "<a rel=\"Next\" style=\"background: url('_thumbs/tn_$next') center center no-repeat;\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$next."\">Next Image</a>\n";
}
}
}
}
?>
</div>
</div>
<div id="image">
<?
if($modded) {
print "<img src=\"../".$_REQUEST["image"]."\" alt=\"".$_REQUEST["image"]."\"/>";
} else {
if($gal) {
print "<img src=\"$gal".$_REQUEST["image"]."\" alt=\"".$_REQUEST["image"]."\" />";
} else {
print "<img src=\"".$_REQUEST["image"]."\" alt=\"".$_REQUEST["image"]."\" />";
}
}
?>
</div>
<div class="container">
<div class="<? if($text) print "textnav"; else print "nav";?>">
<?
if($last) {
if($modded) {
if($text) {
print "<a class=\"textlink\" rel=\"Prev\" href=\"$last\">Last</a>\n";
} else {
print "<a rel=\"Prev\" style=\"background: url('../_thumbs/tn_$last') center center no-repeat;\" href=\"$last\">Previous Image</a>\n";
}
} else {
if($text) {
print "<a class=\"textlink\" rel=\"Prev\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$last."\">Last</a>\n";
} else {
if($gal) {
print "<a rel=\"Prev\" style=\"background: url('".$_REQUEST["gallery"]."/_thumbs/tn_$last') center center no-repeat;\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$last."\">Previous Image</a>\n";
} else {
print "<a rel=\"Prev\" style=\"background: url('_thumbs/tn_$last') center center no-repeat;\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$last."\">Previous Image</a>\n";
}
}
}
}
if(!$_CONFIG["NO_GALLERY"]) {
if($modded) {
print "<a class=\"up\" href=\"../$current_off\">Gallery</a>\n";
} else {
print "<a class=\"up\" href=\"?gallery=".$_REQUEST["gallery"]."&off=$current_off\">Gallery</a>";
}
} else {
if($text) print " | ";
}
if($next) {
if($modded) {
if($text) {
print "<a class=\"textlink\" rel=\"Next\" href=\"$next\">Next</a>\n";
} else {
print "<a rel=\"Next\" style=\"background: url('../_thumbs/tn_$next') center center no-repeat;\" href=\"$next\">Next Image</a>\n";
}
} else {
if($text) {
print "<a class=\"textlink\" rel=\"Next\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$next."\">Next</a>\n";
} else {
if($gal) {
print "<a rel=\"Next\" style=\"background: url('".$_REQUEST["gallery"]."/_thumbs/tn_$next') center center no-repeat;\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$next."\">Next Image</a>\n";
} else {
print "<a rel=\"Next\" style=\"background: url('_thumbs/tn_$next') center center no-repeat;\" href=\"?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$next."\">Next Image</a>\n";
}
}
}
}
?>
</div>
<? if($_CONFIG["ALLOW_COMMENTS"]) { ?>
<div id="comments">
<?
if($data) {
print "<span class=\"commentTitle\">Comments</span>\n";
foreach ($data as $comment) {
if(is_array($comment[0])) {
$comment = $comment[0];
}
if($comment['name']) {
if($comment['tripcode']) {
$name = $comment['name']." <span class=\"tripcode\">".$comment['tripcode']."</span>";
} else {
$name = $name = $comment['name'];
}
} else {
$name = "Anonymous";
}
print "<a name=\"".$comment['time']."\"></a><div class=\"commentEntry\"><div class=\"title\">".$comment['title']."</div><div class=\"name\">From ".$name."</div>\n<div class=\"date\">" . date('r',$comment['time']) . "</div>\n<div class=\"comment\">\n";
print nl2br($comment['comment']);
print "</div>";
print "</div>";
}
}
?>
</div>
<div id="addComment">
<form action="<? print $SCRIPT_NAME; ?>" method="post">
Name:
<? if($_COOKIE["pictetName"]) { print $_COOKIE["pictetName"]; ?> [<a href="?logout=1" />Logout</a>]<? } else { ?><input value="<? print $value; ?>" name="name" /><? } ?>
Title:
<input name="title" />
Comment:
<textarea name="commentText" cols="40" rows="10"></textarea>
<input type="hidden" name="action" value="add_comment" />
<input type="hidden" name="image" value="<? print $_REQUEST["image"]; ?>" />
<input type="hidden" name="gallery" value="<? print $_REQUEST["gallery"]; ?>" />
<input class="button" type="submit" value="Add Comment" />
</form>
</div>
<? } ?>
</div>
</body>
</html>
<?
} elseif($action == "add_comment") {
foreach($_REQUEST as $key=>$val) {
$_REQUEST[$key] = strip_tags($val);
}
$file = explode(".", $_REQUEST["image"]);
$image = $file[0];
$comment = strip_tags($_REQUEST["commentText"]);
$subject = strip_tags($_REQUEST["title"]);
$name = strip_tags($_REQUEST["name"]);
if(!$_COOKIE["pictetName"]) {
$nm = split("#", $name);
$name = $nm[0];
if($nm[1]) {
$trip = make_trip($nm[1], $nm[0]);
setcookie("pictetTrip", $trip, time()+3600*$_CONFIG["LOGIN_TIME"]);
setcookie("pictetName", $name, time()+3600*$_CONFIG["LOGIN_TIME"]);
}
} else {
$name = $_COOKIE["pictetName"];
$trip = $_COOKIE["pictetTrip"];
}
$time = time();
if(!is_dir("_xml/_comments")) {
mkdir("_xml/_comments");
}
if(!file_exists("_xml/_comments/".$image.".xml")) {
$xml = "<"."?xml version=\"1.0\""."?>\n<comments>";
$first = true;
}
$xml .= " <comment>\n <name>$name</name>\n <tripcode>$trip</tripcode>\n <title>$subject</title>\n <commentText>$comment</commentText>\n <time>$time</time>\n </comment>\n</comments>";
if(!$first) {
$fp = fopen("_xml/_comments/".$image.".xml", "r+");
fseek($fp, -11, SEEK_END);
} else {
$fp = fopen("_xml/_comments/".$image.".xml", "w");
}
fwrite($fp, $xml);
fclose($fp);
if($modded) {
$string = $_REQUEST["image"];
header("Location: $string");
} else {
$string = "?action=comments&gallery=".$_REQUEST["gallery"]."&image=".$_REQUEST["image"];
header("Location: $string");
}
} elseif($action=="cast") {
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false);
header("Content-type: text/xml");
$files = directory(".",$_CONFIG["FILE_TYPES"]);
$files = sort_images($files, 1);
$path = $_SERVER["REQUEST_URI"];
$path = preg_replace("/(.*)?.*/", "$1", $path);
//print $path;
$parts = explode("/", $path);
$parts = array_unique($parts);
if($modded) {
$parts = array_reverse($parts);
$parts[0] = "";
$parts = array_reverse($parts);
}
if($parts) $url = implode("/", $parts);
$url = "http://".$_SERVER["SERVER_NAME"].$url;
if(!$modded) $url .= "/";
if(!is_dir("_xml")) {
mkdir("_xml");
}
if($gal) {
$title = $_CONFIG["GALLERY_TITLE"]."/".$gal;
} else {
$title = $_CONFIG["GALLERY_TITLE"];
}
$rss = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n<rss version=\"2.0\">\n <channel>\n <title>$title</title>\n <description>Pictet Cast</description>\n <link>".$url."</link>\n\n";
$x = 0;
$gal = $_REQUEST["gallery"];
$org_url = $url;
while($files[$x]) {
$file = $files[$x];
if(is_array($file)) {
$file = $file[0];
}
if(file_exists("_thumbs/tn_".$file)) {
if($modded) {
if($gal) {
$url .= $gal."/comments/".$file;
} else {
$url .= "comments/".$file;
}
} else {
if($gal) {
$url .= "$SCRIPT_NAME?action=comments&gallery=$gal&image=$file";
} else {
$url .= "$SCRIPT_NAME?action=comments&image=$file";
}
}
$comment = $url;
$url = $org_url;
if($gal) {
$thumb = $url . $gal . "/_thumbs/tn_".$file;
} else {
$thumb = $url . "_thumbs/tn_".$file;
}
$url = $org_url;
if($gal) {
$link = $url . $gal . "/" .$file;
} else {
$link = $url . $file;
}
$title = "<title>$file</title>\n";
$link = "<link>$link</link>\n";
$hash = "<comments>".htmlspecialchars($comment)."</comments>\n";
$filename = "<description>".$thumb."</description>\n";
$filexml .= " <item>\n"." $title $link $filename $hash </item>\n";
}
++$x;
$url = $org_url;
}
$rss .= $filexml."\n </channel>\n</rss>";
print $rss;
}
function make_trip($pass, $name) {
$c = sha1($pass . $name . MY_SALT);
$c = crypt($c,MY_SALT);
$exp = strsplit($c);
$exp[0] = "!";
$exp[1] = "";
$c = implode("", $exp);
return $c;
}
function strsplit($str)
{
if (!preg_match_all("/./", $str, $split))
{
return false;
}
return $split[0];
}
/*
Next three functions were originally from: <a href="http://icant.co.uk/articles/phpthumbnails/index.html" target="_blank" rel="nofollow">http://icant.co.uk/articles/phpthumbnails/index.html</a>
I modified some of the code to do other things, but over all most of the work is theirs.
I don't think any of its under license, but if it is let me know.
Thanks for the code though!
*/
function checkgd() {
$gd2="";
ob_start();
phpinfo(8);
$phpinfo=ob_get_contents();
ob_end_clean();
$phpinfo=strip_tags($phpinfo);
$phpinfo=stristr($phpinfo,"gd version");
$phpinfo=stristr($phpinfo,"version");
preg_match('/d/',$phpinfo,$gd);
if ($gd[0]=='2'){$gd2="yes";}
return $gd2;
}
function createthumb($name,$filename,$new_w,$new_h) {
global $gd2;
$gd_info = gd_info();
if(file_exists($name)) {
$system=explode(".",$name);
$system=array_reverse($system);
if (preg_match("/jpg|jpeg|JPG/",$system[0])){$src_img=imagecreatefromjpeg($name); if(!$src_img) return false;}
if (preg_match("/png/",$system[0])){$src_img=imagecreatefrompng($name); if(!$src_img) return false;}
if (preg_match("/gif/",$system[0]) && $gd_info["GIF Create Support"]){$src_img=imagecreatefromgif($name); if(!$src_img) return false;}
$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);
}
if ($old_x < $old_y) {
$thumb_w=$old_x*($new_w/$old_y);
$thumb_h=$new_h;
}
if ($old_x == $old_y) {
$thumb_w=$new_w;
$thumb_h=$new_h;
}
if ($gd2==""){
$dst_img=ImageCreate($thumb_w,$thumb_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
}else{
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
}
if (preg_match("/png|PNG/",$system[0])){
imagepng($dst_img,$filename);
} elseif(preg_match("/jpg|jpeg|JPG/",$system[0])) {
imagejpeg($dst_img,$filename);
} else {
if($gd_info["GIF Create Support"]) imagegif($dst_img,$filename);
}
imagedestroy($dst_img);
imagedestroy($src_img);
}
return true;
}
// gets a list of files from the directory specified, and of the type specified.
function directory($dir=".",$filters="all") {
if(is_dir($dir)) {
$handle=opendir($dir);
$files=array();
if ($filters == "all"){while(($file = readdir($handle))!==false){$files[] = $file;}}
if ($filters != "all"){
$filters=explode(",",$filters);
while (($file = readdir($handle))!==false) {
for ($f=0;$f<sizeof($filters);$f++):
$system=explode(".",$file);
$system=array_reverse($system);
if ($system[0] == $filters[$f]){$files[] = $file;}
endfor;
}
}
closedir($handle);
return $files;
} else {
return false;
}
}
/*
I grabbed these xml parsing classes from: <a href="http://www.zend.com/codex.php?id=276&single=1" target="_blank" rel="nofollow">http://www.zend.com/codex.php?id=276&single=1</a>
I don't know if its under any license or not, if it is please let me know which one and I will comply with it.
It was pretty old (from 1999-2000) and I had to fix it up a bit, but it does the job really pretty simply. Nothing to advanced needed.
*/
class Node {
var $name;
var $attributes;
var $ancestors = "/";
var $data;
var $type;
function Node($tree) {
$this->name = array_pop($tree);
$this->ancestors .= implode("/", $tree);
}
function add_data($value) {
$this->data .= ' '.$value;
}
function get_type() {
if (strlen($this->data) > 0) {
return "with CDATA";
} else {
return "without CDATA";
}
}
function level() {
if ($this->ancestors == "/") return 0;
if (preg_match_all("/(/{1})/", $this->ancestors, $result,PREG_PATTERN_ORDER)) {
return (count($result[0]));
} else {
return 0;
}
}
function has_attributes() {
return (is_array($this->attributes));
}
function print_name() {
return "$this->name";
}
function is_child($node) {
$result = preg_match("/^$ancestors/", $node->ancestors, $match);
if ($node->ancestors == $this->ancestors) $result = false;
return $result;
}
}
class XML {
var $file;
var $tree = array();
var $nodes = array();
var $PIs;
function XML($filename) {
$this->file = $filename;
$xml_parser = xml_parser_create();
xml_set_object($xml_parser,$this);
xml_set_element_handler($xml_parser, "startElement", "endElement");
xml_set_character_data_handler($xml_parser, "characterData");
xml_set_processing_instruction_handler ($xml_parser, "process_instruction");
# Why should one want to use case-folding with XML? XML is case-sensitiv, I think this is nonsense
xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
if (!($fp = @fopen($this->file, "r"))) {
die(print("Couldn't open file: $this->filen"));
}
while ($data = fread($fp, 4096)) {
if (!xml_parse($xml_parser, $data, feof($fp))) {
die(sprintf("XML error: %s at line %dn",
xml_error_string(xml_get_error_code($xml_parser)),
xml_get_current_line_number($xml_parser)));
}
}
}
function startElement($parser, $name, $attribs) {
# Adding the additional element to the tree, including attributes
$this->tree[] = $name;
$node = new Node($this->tree);
while (list($k, $v) = each($attribs)) {
$node->attributes[$k] = $v;
}
$this->nodes[] = $node;
}
function endElement($parser, $name) {
# Adding a new element, describing the end of the tag
# But only, if the Tag has CDATA in it!
# Check
if (count($this->nodes) >= 1) {
$prev_node = $this->nodes[count($this->nodes)-1];
if (strlen($prev_node->data) > 0 || $prev_node->name != $name) {
$this->tree[count($this->tree)-1] = "/".$this->tree[count($this->tree)-1];
$this->nodes[] = new Node($this->tree, NULL);
} else {
# Adding a slash to the end of the prev_node
$prev_node->name = $prev_node->name."/";
$this->nodes[count($this->nodes)-1]->name = $this->nodes[count($this->nodes)-1]->name."/";
}
}
# Removing the element from the tree
array_pop($this->tree);
}
function characterData($parser, $data) {
$data = ltrim($data);
if ($data != "") $this->nodes[count($this->nodes)-1]->add_data($data);
}
function process_instruction($parser, $target, $data) {
if (preg_match("/xml:stylesheet/", $target, $match) && preg_match("/type=\"text/xsl\"/", $data, $match)) {
preg_match("/href=\"(.+)\"/i", $data, $this->PIs);
# print "<b>found xls pi: $PIs[1]</b>n"
}
}
}
function check_comments($image) {
$file = explode(".", $image);
$image = $file[0];
//print "THIS IS $image";
if(file_exists("_xml/_comments/$image".".xml")) {
$xml = new XML("_xml/_comments/$image".'.xml');
$i = 0;
foreach($xml->nodes as $node) {
if(is_array($node)) {
$node = $node[0];
}
if($node->name == "time") {
$data[$i] = $node->data;
++$i;
}
}
unset($xml);
return $i;
} else {
return false;
}
}
function sort_images($pics, $method_overide = NULL) {
global $_CONFIG;
if($method_overide) {
$_CONFIG["METHOD"] = 2;
$_CONFIG["DIRECTION"] = 1;
}
if($pics) {
if($_CONFIG["METHOD"] == 1) {
if($_CONFIG["DIRECTION"] == 1) {
rsort($pics);
} else {
sort($pics);
}
$x = 0; // for some reason I have to set this as 0 here or all hell breaks loose, I'm still trying to figure out why.
} elseif($_CONFIG["METHOD"] == 2) {
$x = 0;
foreach ($pics as $file) {
if(is_array($file)) $file = $file[0];
$t = filemtime($file);
if(!$k[$t]) {
$k[$t] = $file;
} else {
while($k[$t]) {
$t+=1;
}
$k[$t] = $file;
}
}
unset($pics);
$pics = $k;
if($_CONFIG["DIRECTION"] == 1) {
krsort($pics);
} else {
ksort($pics);
}
$x = 0;
foreach($pics as $pic) {
if(is_array($pic)) {
$pic = $pic[0];
}
if($pic) {
$o[$x] = $pic;
++$x;
}
}
unset($pics);
$pics = $o;
}
return $pics;
}
}
function load_config() {
global $_CONFIG;
if(file_exists("_xml/config.xml")) {
$xml = new XML("_xml/config.xml");
foreach($xml->nodes as $node) {
if(is_array($node)) {
$node = $node[0];
}
if($node->name == "GALLERY_TITLE") {
$_CONFIG["GALLERY_TITLE"] = trim($node->data);
} elseif($node->name == "THUMB_WIDTH") {
$_CONFIG["THUMB_WIDTH"] = trim($node->data);
} elseif($node->name == "THUMB_HEIGHT") {
$_CONFIG["THUMB_HEIGHT"] = trim($node->data);
} elseif($node->name == "IMAGES_PER_PAGE") {
$_CONFIG["IMAGES_PER_PAGE"] = trim($node->data);
} elseif($node->name == "IMAGES_PER_ROW") {
$_CONFIG["IMAGES_PER_ROW"] = trim($node->data);
} elseif($node->name == "ALLOW_COMMENTS") {
$_CONFIG["ALLOW_COMMENTS"] = trim($node->data);
} elseif($node->name == "METHOD") {
$_CONFIG["METHOD"] = trim($node->data);
} elseif($node->name == "DIRECTION") {
$_CONFIG["DIRECTION"] = trim($node->data);
} elseif($node->name == "NO_GALLERY") {
$_CONFIG["NO_GALLERY"] = trim($node->data);
} elseif($node->name == "TEXT_LINKS") {
$_CONFIG["TEXT_LINKS"] = trim($node->data);
}
}
} else {
return false;
}
return true;
}
function print_css() {
$default_css = "body {
background-color: #fff;
font-family: Arial, san-serif;
margin: 10px;
padding: 0px;
text-size: 12px;
}
a, a:visited, a:hover {
color: #000;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
a.comments {
color: red;
}
dl.images {
margin: 0px;
border: 1px solid #000;
background-color: #ddd;
text-align: center;
padding: 1px;
padding-bottom: 12px;
float: left;
margin-right: 5px;
margin-bottom: 5px;
}
.images dt {
font-size: 10px;
}
.images dt img {
border: 1px solid #000;
}
.imageRow {
clear: left;
}
#galNavTop {
font-weight: bold;
width: auto;
text-align: center;
height: 30px;
}
#galNavTop a {
padding-left: 10px;
padding-right: 10px;
}
#galNavBottom {
font-weight: bold;
text-align: center;
height: 30px;
}
#galNavBottom a {
padding-left: 10px;
padding-right: 10px;
}
#images {
margin-top: 20px;
float: left;
}
#galleryList {
margin-top: 50px;
margin-left: 20px;
border: 1px solid black;
width: 200px;
padding: 2px;
background-color: #888;
float: left;
}
#galleryList li, #galleryList ul {
margin: 0px;
padding: 0px;
list-style-type: none;
}
#galleryList a, #galleryList a:visited, #galleryList a:hover {
display: block;
height: 18px;
width: auto;
border: 1px solid black;
border-top: 0px;
font-size: 12px;
padding-left: 4px;
padding-top: 2px;
background-color: #bbb;
color: #000;
}
#galleryList a.current, #galleryList a.current:visited, #galleryList a.current:hover {
background-color: #ccc;
border-right: 4px solid black;
text-decoration: none;
}
#galleryList a:hover {
background-color: #ccc;
}
#galleryList a.top, #galleryList a.top:visited, #galleryList a.top:hover {
border: 1px solid black;
}
#galleryList a.topSelected, #galleryList a.topSelected:visited, #galleryList a.topSelected:hover {
border: 1px solid black;
background-color: #ccc;
border-right: 4px solid black;
}
#galNavTop ul, #galNavTop li {
list-style-type: none;
margin: 0px;
padding: 0px;
}
#galNavTop li {
display: block;
float: left;
margin-right: 20px;
}
#commentPage .container {
margin-left: auto;
margin-right: auto;
margin-top: 10px;
}
#commentPage #image {
margin-bottom: 20px;
}
#commentPage .nav {
margin-left: auto;
margin-right: auto;
margin-bottom: 10px;
}
#commentPage .up {
font-size: 18px;
font-weight: bold;
}
#commentPage #comments {
text-align: center;
width: auto;
}
#commentPage .commentEntry {
text-align: left;
margin-left: auto;
margin-right: auto;
margin-bottom: 10px;
width: 500px;
border: 1px dashed black;
padding: 5px;
}
#commentPage .name {
font-size: 12px;
}
#commentPage .date {
font-size: 10px;
border-bottom: 1px solid #999;
}
#commentPage .comment {
margin-top: 5px;
font-size: 12px;
}
#commentPage #comments span.commentTitle {
font-size: 20px;
font-weight: bold;
}
.title {
font-weight: bold;
}
span.tripcode {
color: green;
font-weight: bold;
font-size: 12px;
}
#commentPage #addComment {
margin-left: auto;
margin-right: auto;
width: 420px;
}
#commentPage form {
text-size: 12px;
font-weight: bold;
}
#commentPage input {
border: 1px solid black;
width: 200px;
}
#commentPage textarea {
border: 1px solid black;
width: 410px;
}
#image {
width: auto;
text-align: center;
clear: both;
}
#comments {
clear: both;
}
div.textnav {
width: auto;
text-align: center;
}
.nav a {
text-indent: -49000px;
display: block;
float: left;
}
a.textlink {
text-indent: 0px;
display: inline;
float: none;
}
.nav a.up {
text-indent: 0px;
text-align: center;
}
";
return $default_css;
}
?>
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||