summaryrefslogtreecommitdiff
path: root/utils/modules/gallery.php
diff options
context:
space:
mode:
authordeva <deva>2009-08-24 13:17:40 +0000
committerdeva <deva>2009-08-24 13:17:40 +0000
commit8e8cfb2fb27c2b217144e1efaa4137254d58ed3e (patch)
tree20293895d35b03fb4f95e28f027439f023da2008 /utils/modules/gallery.php
parentb98a5821862b4c5bae88be28757d60554bb7ac68 (diff)
Some gallery stuff. Change in default number of news to show, and a new Gallery module.
Diffstat (limited to 'utils/modules/gallery.php')
-rw-r--r--utils/modules/gallery.php121
1 files changed, 109 insertions, 12 deletions
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 = "<p>\n";
- $str .= " <img src=\"" . $this->path . "/" . $this->image . "\" width=\"100\"/><br/>\n";
+ if($showbig) $str .= " <a href=\"" . $this->path . "/" . $this->image . "\">\n";
+
+ $str .= " <img src=\"?mode=imagecache&amp;uri=" . $this->path . "/" . $this->image . "&amp;mw=".$maxwidth."&amp;mh=".$maxheight."\"\"/><br/>\n";
+ if($showbig) $str .= " </a>\n";
$str .= " " . $this->title . "\n";
$str .= "</p>\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, " </album>\n");
}
- public function show()
+ public function show($maxwidth, $maxheight)
{
+ global $page;
$str = "<p>\n";
- $str .= "<img src=\"" . $this->getPath() . "/" . $this->photos[$this->icon]->image . "\" width=\"64\"/>\n";
+ //$str .= " <img src=\"?mode=imagecache&amp;uri=" . $this->getPath() . "/" . $this->photos[$this->icon]->image . "&amp;mw=".($maxwidth/2)."&amp;mh=".($maxheight/2)."\"\"/><br/>\n";
+ //$str .= "<img src=\"" . $this->getPath() . "/" . $this->photos[$this->icon]->image . "\" width=\"64\"/>\n";
$str .= "<strong>" . $this->title . "</strong>\n";
$str .= "</p>\n";
foreach($this->photos as $photo) {
- $str .= $photo->show();
+ $str .= "<a href=\"?page=".$page."&amp;a=".$this->id."&amp;p=".$photo->id."\">".$photo->show($maxwidth, $maxheight)."</a>";
}
return $str;
}
+ public function showIcon($maxwidth, $maxheight)
+ {
+ global $page;
+ return "<a href=\"?page=".$page."&amp;a=".$this->id."\">".$this->title . $this->photos[$this->icon]->show($maxwidth, $maxheight)."</a>\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 "<a href=\"?page=gallery&amp;a=".$album."&amp;p=".$photo."\">".$this->albums[$album]->photos[$photo]->show($this->maxwidth_rand, $this->maxheight_rand)."</a>";
+ }
+
+ 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 .= "<a href=\"?page=gallery&amp;a=".$album."&amp;p=".($photo-1)."\">". $this->albums[$album]->photos[$photo - 1]->show($this->maxwidth_icon, $this->maxheight_icon) . "</a>";
+ $str .= "<a href=\"?page=gallery&amp;a=".$album."\"><img src=\"snot.jpg\"/></a>";
+ if($this->albums[$album]->photos[$photo + 1])
+ $str .= "<a href=\"?page=gallery&amp;a=".$album."&amp;p=".($photo+1)."\">".$this->albums[$album]->photos[$photo + 1]->show($this->maxwidth_icon, $this->maxheight_icon)."</a>";
+ 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, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
- fwrite($fp, "<gallery>\n");
+ fwrite($fp, "<gallery maxwidth_icon=\"".$this->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) {