From 8e8cfb2fb27c2b217144e1efaa4137254d58ed3e Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 24 Aug 2009 13:17:40 +0000 Subject: Some gallery stuff. Change in default number of news to show, and a new Gallery module. --- utils/modules/gallery.php | 121 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 109 insertions(+), 12 deletions(-) (limited to 'utils/modules/gallery.php') diff --git a/utils/modules/gallery.php b/utils/modules/gallery.php index c6d2f86..74a0ba0 100644 --- a/utils/modules/gallery.php +++ b/utils/modules/gallery.php @@ -42,10 +42,13 @@ class Photo { htmlspecialchars($this->image, ENT_QUOTES, "UTF-8") . "\"/>\n"); } - public function show() + public function show($maxwidth = 100, $maxheight = 100, $showbig = false) { $str = "

\n"; - $str .= " path . "/" . $this->image . "\" width=\"100\"/>
\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"; return $str; @@ -66,6 +69,7 @@ class Album { public $title; public $copyright; public $enabled; + public $icon; public $photos = array(); public function add($photo) @@ -91,18 +95,26 @@ class Album { fwrite($fp, " \n"); } - public function show() + public function show($maxwidth, $maxheight) { + global $page; $str = "

\n"; - $str .= "getPath() . "/" . $this->photos[$this->icon]->image . "\" width=\"64\"/>\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"; foreach($this->photos as $photo) { - $str .= $photo->show(); + $str .= "id."&p=".$photo->id."\">".$photo->show($maxwidth, $maxheight).""; } return $str; } + public function showIcon($maxwidth, $maxheight) + { + global $page; + return "id."\">".$this->title . $this->photos[$this->icon]->show($maxwidth, $maxheight)."\n"; + } + public function getPath() { global $ALBUMS_DIR; @@ -176,9 +188,18 @@ class Gallery { private $file; private $albums = array(); + // Local attributes + private $maxwidth_icon; + private $maxheight_icon; + private $maxwidth_rand; + private $maxheight_rand; + private $maxwidth; + private $maxheight; + // Admin config public $admin_title = "Gallery"; - public $admin_submodules = array("New album" => "new", + public $admin_submodules = array("Options" => "options", + "New album" => "new", "Edit album" => "edit", "Delete album" => "delete"); @@ -191,7 +212,7 @@ class Gallery { unpackImages($_FILES['images'], $album); $this->add($album); $this->write(); - echo $album->show(); + echo $album->show($this->maxwidth_icon, $this->maxheight_icon); break; case "select": @@ -207,9 +228,37 @@ class Gallery { } } + public function admin_options($action, $vars) + { + switch($action) { + case "store": + $this->maxwidth_icon = $vars['maxwidth_icon']; + $this->maxheight_icon = $vars['maxheight_icon']; + $this->maxwidth_rand = $vars['maxwidth_rand']; + $this->maxheight_rand = $vars['maxheight_rand']; + $this->maxwidth = $vars['maxwidth']; + $this->maxheight = $vars['maxheight']; + $this->write(); + default: + $form = new Form("store"); + $form->addWidget(new LineEdit("Icon maxwidth:", "maxwidth_icon", $this->maxwidth_icon)); + $form->addWidget(new LineEdit("Icon maxheight:", "maxheight_icon", $this->maxheight_icon)); + $form->addWidget(new LineEdit("Random maxwidth:", "maxwidth_rand", $this->maxwidth_rand)); + $form->addWidget(new LineEdit("Random maxheight:", "maxheight_rand", $this->maxheight_rand)); + $form->addWidget(new LineEdit("Image maxwidth:", "maxwidth", $this->maxwidth)); + $form->addWidget(new LineEdit("Image maxheight:", "maxheight", $this->maxheight)); + $form->addWidget(new Button("Update")); + $form->render(); + break; + } + } + public function admin($sub, $action, $vars) { switch($sub) { + case "options": + $this->admin_options($action, $vars); + break; case "new": $this->admin_new($action, $vars); break; @@ -222,15 +271,50 @@ class Gallery { } } + public function showRandomPhoto() + { + 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).""; + } + + public function showAlbums() + { + $str = ""; + foreach($this->albums as $album) { + $str .= $album->showIcon($this->maxwidth_icon, $this->maxheight_icon); + } + 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).""; + return $str; + } + public function run($params) { + global $a, $p; + $str = ""; foreach($params as $param) { switch($param) { default: - foreach($this->albums as $album) { - $str .= $album->show(); - } + if($p != "" && $a != "") return $this->showPhoto($a, $p); + if($a != "") return $this->albums[$a]->show($this->maxwidth_icon, $this->maxheight_icon); + return $this->showAlbums(); + + case "random": + $str .= $this->showRandomPhoto(); break; } } @@ -255,7 +339,12 @@ class Gallery { $fp = fopen($this->file, "w"); fwrite($fp, "\n"); - fwrite($fp, "\n"); + fwrite($fp, "maxwidth_icon."\"\n"); + fwrite($fp, " maxheight_icon=\"".$this->maxheight_icon."\"\n"); + fwrite($fp, " maxwidth_rand=\"".$this->maxwidth_rand."\"\n"); + fwrite($fp, " maxheight_rand=\"".$this->maxheight_rand."\"\n"); + fwrite($fp, " maxwidth=\"".$this->maxwidth."\"\n"); + fwrite($fp, " maxheight=\"".$this->maxheight."\">\n"); foreach($this->albums as $album) { $album->write($fp); } @@ -273,7 +362,15 @@ class Gallery { $dom->load($this->file); $gallery = $dom->documentElement; - // $this->width = $gallery->getAttribute('width'); + + $this->maxwidth_icon = $gallery->getAttribute('maxwidth_icon'); + $this->maxheight_icon = $gallery->getAttribute('maxheight_icon'); + + $this->maxwidth_rand = $gallery->getAttribute('maxwidth_rand'); + $this->maxheight_rand = $gallery->getAttribute('maxheight_rand'); + + $this->maxwidth = $gallery->getAttribute('maxwidth'); + $this->maxheight = $gallery->getAttribute('maxheight'); foreach($gallery->childNodes as $albumElem) { -- cgit v1.2.3