2 rcs_id('$Id: PhotoAlbum.php,v 1.1 2003-01-05 04:21:06 carstenklapp Exp $');
5 * WikiPlugin which makes an 'album' of a set of photos with optional
8 * @author: Ted Vinke <teddy@jouwfeestje.com>
12 * src=http://server/textfile
20 * 'src' is a CSV textfile which separates filename and description of
21 * each photo. Photos listed in textfile have to be in same directory
22 * as the file. Descriptions are optional. The 'mode' specifies how
23 * it's displayed, 'column' means vertically, 'row' means
26 * E.g. possible content of a valid textfile:
28 * photo-01.jpg; Me and my girlfriend
30 * christmas.gif; Merry Christmas!
32 * Only 'src' parameter is mandatory. Height and width are calculated
33 * compared to original metrics retrieved by php function
34 * getimagesize() and can be absolute or a percentage (e.g. "50%)
38 * - parse any local directory for pictures
39 * - specify picture(s) as parameter(s)
40 * - 'advanced' options such as limit pictures on one page, use more
41 * pages, thumbnail function which enlarges pictures on same page...
42 * - implement more layout options, such as usage of tables. Currently
43 * row mode with descriptions isn't very nice. :(
47 define('DESC_SEP', ";");
49 class WikiPlugin_PhotoAlbum
53 return _("PhotoAlbum");
56 function getDescription () {
57 return _("Displays a set of photos listed in a text file with optional descriptions");
60 function getVersion() {
61 return preg_replace("/[Revision: $]/", '',
65 function getDefaultArguments() {
66 return array('src' => '', // textfile
67 'mode' => 'row', // 'column' or 'row'
68 'desc' => true, // show descriptions
69 'sort' => false, // sorted alphabetically
70 'align' => 'center', // only for column mode
76 function run($dbi, $argstr, $request) {
77 extract($this->getArgs($argstr, $request));
80 return $this->error(fmt("%s parameter missing", "'src'"));
83 if (! IsSafeURL($src)) {
84 return $this->error(_("Bad url in src: remove all of <, >, \""));
87 @$fp = fopen($src, "r");
90 return $this->error(fmt("Unable to read %s ", $src));
94 while ($data = fgetcsv ($fp, 1024, DESC_SEP)) {
95 if (count($data) == 0 || empty($data[0]))
98 // otherwise when empty 'undefined index 1' PHP warning appears
102 $photos[count($photos)] = array ("name" => dirname($src) . "/"
104 "desc" => trim("$data[1]"),
110 if (count($photos) == 0) {
118 $bundle = HTML("\n "); // nicer html ouput
120 while (list($key, $value) = each($photos)) {
122 if (!$desc) { // no desciptions
125 $params = array('alt' => $value["desc"],
126 'src' => $value["name"],
130 $size = @getimagesize($value["name"]);
132 // only if width or height are given, we add it to the
134 if (!empty($width)) {
135 $newwidth = $this->newSize($size[0], $width);
136 $params = array_merge($params, array("width" => $newwidth));
139 if (!empty($height)) {
140 $newheight = $this->newSize($size[1], $height);
141 $params = array_merge($params, array("height" => $newheight));
144 $bundle->pushcontent(HTML::img($params), "\n"); // wrap html ouput
146 if ($mode == 'column') {
147 $bundle->pushcontent(HTML::p($value["desc"]));
149 else if ($mode == 'row') {
150 $bundle->pushcontent(" ".$value["desc"]." ");
154 if ($mode == 'column') {
155 return HTML::div(array("align" => $align), $bundle);
163 * Calculate the new size in pixels when the original size with a
166 * Value is either absolute value or HTML percentage e.g. "50%".
168 function newSize($oldSize, $value) {
170 if (substr($value, strlen($value) - 1) != "%") {
173 substr_replace($value, "%", "");
174 return ($oldSize*$value)/100;
179 // $Log: not supported by cvs2svn $
186 // c-hanging-comment-ender-p: nil
187 // indent-tabs-mode: nil