From 657b191f6b4ae00d714fffe6911d8999d0a99873 Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 27 Jan 2010 15:11:09 +0000 Subject: Major update of gallery module. Now we actually use span tags for the css layout engine to use. --- utils/modules/gallery.php | 142 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 108 insertions(+), 34 deletions(-) diff --git a/utils/modules/gallery.php b/utils/modules/gallery.php index 74a0ba0..308f10a 100644 --- a/utils/modules/gallery.php +++ b/utils/modules/gallery.php @@ -2,8 +2,6 @@ /* -*- Mode: php; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ include_once($UTIL_DIR . "/convert.php"); -include_once($UTIL_DIR . "/markdown.php"); -include_once($UTIL_DIR . "/modules.php"); function isJpeg($file) { @@ -35,22 +33,27 @@ class Photo { public function write($fp) { fwrite($fp, " id, ENT_QUOTES, "UTF-8") . "\"\n"); + htmlspecialchars($this->id, ENT_QUOTES, "UTF-8") . "\"\n"); fwrite($fp, " title=\"" . - htmlspecialchars($this->title, ENT_QUOTES, "UTF-8") . "\"\n"); + htmlspecialchars($this->title, ENT_QUOTES, "UTF-8") . "\"\n"); fwrite($fp, " image=\"" . - htmlspecialchars($this->image, ENT_QUOTES, "UTF-8") . "\"/>\n"); + htmlspecialchars($this->image, ENT_QUOTES, "UTF-8") . "\"/>\n"); } - public function show($maxwidth = 100, $maxheight = 100, $showbig = false) + public function show($indent, $maxwidth = 100, $maxheight = 100, $showbig = false) { - $str = "

\n"; - if($showbig) $str .= " path . "/" . $this->image . "\">\n"; - - $str .= " path . "/" . $this->image . "&mw=".$maxwidth."&mh=".$maxheight."\"\"/>
\n"; - if($showbig) $str .= "
\n"; - $str .= " " . $this->title . "\n"; - $str .= "

\n"; + $str = ""; + $str .= $indent."\n"; + if($showbig) $str .= $indent." path . "/" . $this->image . "\">\n"; + + $str .= $indent." \n"; + $str .= $indent." \"".$this-title."\"\n"; + $str .= $indent." src=\"?mode=imagecache&uri=" + . $this->path . "/" . $this->image . "&mw=".$maxwidth."&mh=".$maxheight."\"/>\n"; + $str .= $indent." \n"; + if($showbig) $str .= $indent." \n"; + $str .= $indent." " . $this->title . "\n"; + $str .= $indent."\n"; return $str; } @@ -95,24 +98,76 @@ class Album { fwrite($fp, " \n"); } - public function show($maxwidth, $maxheight) + public function show($indent, $maxwidth, $maxheight) { global $page; - $str = "

\n"; - //$str .= " getPath() . "/" . $this->photos[$this->icon]->image . "&mw=".($maxwidth/2)."&mh=".($maxheight/2)."\"\"/>
\n"; - //$str .= "getPath() . "/" . $this->photos[$this->icon]->image . "\" width=\"64\"/>\n"; - $str .= "" . $this->title . "\n"; - $str .= "

\n"; + + $str = ""; + $str .= $indent."\n"; + $str .= $indent." " . $this->title . "\n"; foreach($this->photos as $photo) { - $str .= "id."&p=".$photo->id."\">".$photo->show($maxwidth, $maxheight).""; + $str .= $indent." id."&p=".$photo->id."\">\n"; + $str .= $photo->show($indent." ", $maxwidth, $maxheight); + $str .= $indent." \n"; } + $str .= $indent."\n"; + return $str; } - public function showIcon($maxwidth, $maxheight) + public function showIcon($indent, $maxwidth, $maxheight) { global $page; - return "id."\">".$this->title . $this->photos[$this->icon]->show($maxwidth, $maxheight)."\n"; + + $str = ""; + + $str .= $indent."id."\">\n"; + $str .= $indent." ".$this->title."\n"; + $str .= $indent." \n"; + $str .= $this->photos[$this->icon]->show($indent." ", $maxwidth, $maxheight); + $str .= $indent." \n"; + $str .= $indent."\n"; + + return $str; + } + + public function showPhoto($indent, $photo, $maxwidth, $maxheight, $maxwidth_icon, $maxheight_icon) + { + global $GLOBALS; + + $album = $this->id; + + $str = ""; + + $str = $this->photos[$photo]->show($indent, $maxwidth, $maxheight, true); + + $str .= $indent."\n"; + if($this->photos[$photo - 1]) { + $str .= $indent." \n"; + $str .= $this->photos[$photo - 1]->show($indent." ", $maxwidth_icon, $maxheight_icon); + $str .= $indent." \n"; + } else { + $str .= $indent." \n"; + $str .= $indent." \n"; + $str .= $indent." \n"; + } + + $str .= $indent." \n"; + $str .= $indent." \n"; + $str .= $indent." \n"; + + if($this->photos[$photo + 1]) { + $str .= $indent." \n"; + $str .= $this->photos[$photo + 1]->show($indent." ", $maxwidth_icon, $maxheight_icon); + $str .= $indent." \n"; + } else { + $str .= $indent." \n"; + $str .= $indent." \n"; + $str .= $indent." \n"; + } + $str .= $indent."\n"; + + return $str; } public function getPath() @@ -212,7 +267,7 @@ class Gallery { unpackImages($_FILES['images'], $album); $this->add($album); $this->write(); - echo $album->show($this->maxwidth_icon, $this->maxheight_icon); + echo $album->show("", $this->maxwidth_icon, $this->maxheight_icon); break; case "select": @@ -273,31 +328,44 @@ class Gallery { public function showRandomPhoto() { + $str = ""; + srand((float) microtime() * 10000000); if(sizeof($this->albums) == 0) return ""; $album = array_rand($this->albums); if(sizeof($this->albums[$album]->photos) == 0) return ""; $photo = array_rand($this->albums[$album]->photos); - return "".$this->albums[$album]->photos[$photo]->show($this->maxwidth_rand, $this->maxheight_rand).""; + + $str .= " \n"; + $str .= $this->albums[$album]->photos[$photo]->show(" ", $this->maxwidth_rand, $this->maxheight_rand); + $str .= " \n"; + + return $str; } public function showAlbums() { $str = ""; + + $str .= "\n\n"; foreach($this->albums as $album) { - $str .= $album->showIcon($this->maxwidth_icon, $this->maxheight_icon); + $str .= $album->showIcon(" ", $this->maxwidth_icon, $this->maxheight_icon); } + $str .= "\n"; + return $str; } public function showPhoto($album, $photo) { - $str = $this->albums[$album]->photos[$photo]->show($this->maxwidth, $this->maxheight, true); - if($this->albums[$album]->photos[$photo - 1]) - $str .= "". $this->albums[$album]->photos[$photo - 1]->show($this->maxwidth_icon, $this->maxheight_icon) . ""; - $str .= ""; - if($this->albums[$album]->photos[$photo + 1]) - $str .= "".$this->albums[$album]->photos[$photo + 1]->show($this->maxwidth_icon, $this->maxheight_icon).""; + $str = ""; + + if($this->albums[$album]) { + $str .= $this->albums[$album]->showPhoto(" ", $photo, + $this->maxwidth, $this->maxheight, + $this->maxwidth_icon, $this->maxheight_icon); + } + return $str; } @@ -306,18 +374,24 @@ class Gallery { global $a, $p; $str = ""; + + $str .= "\n\n"; foreach($params as $param) { switch($param) { default: - if($p != "" && $a != "") return $this->showPhoto($a, $p); - if($a != "") return $this->albums[$a]->show($this->maxwidth_icon, $this->maxheight_icon); - return $this->showAlbums(); + if($p != "" && $a != "") $str .= $this->showPhoto($a, $p); + else if($a != "" && $this->albums[$a] && $p == "") + $str .= $this->albums[$a]->show(" ", $this->maxwidth_icon, $this->maxheight_icon); + else $str .= $this->showAlbums(); + break; case "random": $str .= $this->showRandomPhoto(); break; } } + $str .= "\n"; + return $str; } -- cgit v1.2.3