]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PhotoAlbum.php
function run: @return mixed
[SourceForge/phpwiki.git] / lib / plugin / PhotoAlbum.php
1 <?php
2
3 /*
4  * Copyright 2003,2004,2005,2007 $ThePhpWikiProgrammingTeam
5  * Copyright 2009 Marc-Etienne Vargenau, Alcatel-Lucent
6  *
7  * This file is part of PhpWiki.
8  *
9  * PhpWiki is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * PhpWiki is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with PhpWiki; if not, write to the Free Software Foundation, Inc.,
21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 /**
25  * Display an album of a set of photos with optional descriptions.
26  *
27  * @author: Ted Vinke <teddy@jouwfeestje.com>
28  *          Reini Urban (local fs)
29  *          Thomas Harding (slides mode, real thumbnails)
30  *
31  * Usage:
32  * <<PhotoAlbum
33  *          src="http://server/textfile" or localfile or localdir
34  *          mode=[normal|column|row|thumbs|tiles|list|slide]
35  *          desc=true
36  *          numcols=3
37  *          height=50%
38  *          width=50%
39  *          thumbswidth=80
40  *          align=[center|left|right]
41  *          duration=6
42  * >>
43  *
44  * "src": textfile of images or directory of images or a single image (local or remote)
45  *      Local or remote e.g. http://myserver/images/MyPhotos.txt or http://myserver/images/
46  *      or /images/ or Upload:photos/
47  *      Possible content of a valid textfile:
48  *     photo-01.jpg; Me and my girlfriend
49  *     photo-02.jpg
50  *     christmas.gif; Merry Christmas!
51  *
52  *     Inside textfile, filenames and optional descriptions are separated by
53  *     semi-colon on each line. Listed files must be in same directory as textfile
54  *     itself, so don't use relative paths inside textfile.
55  *
56  * "url": defines the the webpath to the srcdir directory (formerly called weblocation)
57  */
58
59 /**
60  * TODO:
61  * - specify picture(s) as parameter(s)
62  * - limit amount of pictures on one page
63  * - use PHP to really resize or greyscale images (only where GD library supports it)
64  *   (quite done for resize with "ImageTile.php")
65  *
66  * KNOWN ISSUES:
67  * - reading height and width from images with spaces in their names fails.
68  *
69  * Fixed album location idea by Philip J. Hollenback. Thanks!
70  */
71
72 class ImageTile extends HtmlElement
73 {
74     // go away, hack!
75     function image_tile( /*...*/)
76     {
77         $el = new HTML ('img');
78         $tag = func_get_args();
79         $path = DATA_PATH . "/ImageTile.php";
80         $params = "<img src=\"$path?url=" . $tag[0]['src'];
81         if (!@empty($tag[0]['width']))
82             $params .= "&width=" . $tag[0]['width'];
83         if (!@empty($tag[0]['height']))
84             $params .= "&height=" . $tag[0]['height'];
85         if (!@empty($tag[0]['width']))
86             $params .= '" width="' . $tag[0]['width'];
87         if (!@empty($tag[0]['height']))
88             $params .= '" height="' . $tag[0]['height'];
89
90         $params .= '" alt="' . $tag[0]['alt'] . '" />';
91         return $el->raw($params);
92     }
93 }
94
95 class WikiPlugin_PhotoAlbum
96     extends WikiPlugin
97 {
98     function getDescription()
99     {
100         return _("Display a set of photos listed in a text file with optional descriptions.");
101     }
102
103 // Avoid nameclash, so it's disabled. We allow any url.
104 // define('allow_album_location', true);
105 // define('album_location', 'http://kw.jouwfeestje.com/foto/redactie');
106 // define('album_default_extension', '.jpg');
107 // define('desc_separator', ';');
108
109     function getDefaultArguments()
110     {
111         return array('src' => '', // textfile of image list, or local dir.
112             'url' => '', // if src=localfs, url prefix (webroot for the links)
113             'mode' => 'normal', // normal|thumbs|tiles|list
114             // "normal" - Normal table which shows photos full-size
115             // "thumbs" - WinXP thumbnail style
116             // "tiles"  - WinXP tiles style
117             // "list"   - WinXP list style
118             // "row"    - inline thumbnails
119             // "column" - photos full-size, displayed in 1 column
120             // "slide"  - slideshow mode, needs javascript on client
121             'numcols' => 3, // photos per row, columns
122             'showdesc' => 'both', // none|name|desc|both
123             // "none"   - No descriptions next to photos
124             // "name"   - Only filename shown
125             // "desc"   - Only description (from textfile) shown
126             // "both"     - If no description found, then filename will be used
127             'link' => true, // show link to original sized photo
128             // If true, each image will be hyperlinked to a page where the single
129             // photo will be shown full-size. Only works when mode != 'normal'
130             'attrib' => '', // 'sort, nowrap, alt'
131             // attrib arg allows multiple attributes: attrib=sort,nowrap,alt
132             // 'sort' sorts alphabetically, 'nowrap' for cells, 'alt' to use
133             // descs instead of filenames in image ALT-tags
134             'bgcolor' => '#eae8e8', // cell bgcolor (lightgrey)
135             'hlcolor' => '#c0c0ff', // highlight color (lightblue)
136             'align' => 'center', // alignment of table
137             'height' => 'auto', // image height (auto|75|100%)
138             'width' => 'auto', // image width (auto|75|100%)
139             // Size of shown photos. Either absolute value (e.g. "50") or
140             // HTML style percentage (e.g. "75%") or "auto" for no special
141             // action.
142             'cellwidth' => 'image', // cell (auto|equal|image|75|100%)
143             // Width of cells in table. Either absolute value in pixels, HTML
144             // style percentage, "auto" (no special action), "equal" (where
145             // all columns are equally sized) or "image" (take height and
146             // width of the photo in that cell).
147             'tablewidth' => false, // table (75|100%)
148             'p' => false, // "displaythissinglephoto.jpg"
149             'h' => false, // "highlightcolorofthisphoto.jpg"
150             'duration' => 6, // in slide mode, in seconds
151             'thumbswidth' => 80 //width of thumbnails
152         );
153     }
154
155     // descriptions (instead of filenames) for image alt-tags
156
157     /**
158      * @param WikiDB $dbi
159      * @param string $argstr
160      * @param WikiRequest $request
161      * @param string $basepage
162      * @return mixed
163      */
164     function run($dbi, $argstr, &$request, $basepage)
165     {
166
167         extract($this->getArgs($argstr, $request));
168
169         $attributes = $attrib ? explode(",", $attrib) : array();
170         $photos = array();
171         $html = HTML();
172         $count = 0;
173         // check all parameters
174         // what type do we have?
175         if (!$src) {
176             $showdesc = 'none';
177             $src = $request->getArg('pagename');
178             $error = $this->fromLocation($src, $photos);
179         } else {
180             $error = $this->fromFile($src, $photos, $url);
181         }
182         if ($error) {
183             return $this->error($error);
184         }
185
186         if ($numcols < 1) $numcols = 1;
187         if ($align != 'left' && $align != 'center' && $align != 'right') {
188             $align = 'center';
189         }
190         if (count($photos) == 0) {
191             return HTML::raw('');
192         }
193
194         if (in_array("sort", $attributes))
195             sort($photos);
196
197         if ($p) {
198             $mode = "normal";
199         }
200
201         if ($mode == "column") {
202             $mode = "normal";
203             $numcols = "1";
204         }
205
206         // set some fixed properties for each $mode
207         if ($mode == 'thumbs' || $mode == 'tiles') {
208             $attributes = array_merge($attributes, "alt");
209             $attributes = array_merge($attributes, "nowrap");
210             $cellwidth = 'auto'; // else cell won't nowrap
211             if ($width == 'auto') $width = 70;
212         } elseif ($mode == 'list') {
213             $numcols = 1;
214             $cellwidth = "auto";
215             if ($width == 'auto') $width = 50;
216         } elseif ($mode == 'slide') {
217             $tableheight = 0;
218             $cell_width = 0;
219             $numcols = count($photos);
220             $keep = $photos;
221             while (list($key, $value) = each($photos)) {
222                 list($x, $y, $s, $t) = @getimagesize($value['src']);
223                 if ($height != 'auto') $y = $this->newSize($y, $height);
224                 if ($width != 'auto') $y = round($y * $this->newSize($x, $width) / $x);
225                 if ($x > $cell_width) $cell_width = $x;
226                 if ($y > $tableheight) $tableheight = $y;
227             }
228             $tableheight += 50;
229             $photos = $keep;
230             unset ($x, $y, $s, $t, $key, $value, $keep);
231         }
232
233         $row = HTML();
234         $duration = 1000 * $duration;
235         if ($mode == 'slide')
236             $row->pushContent(JavaScript("
237 i = 0;
238 function display_slides() {
239   j = i - 1;
240   cell0 = document.getElementsByName('wikislide' + j);
241   cell = document.getElementsByName('wikislide' + i);
242   if (cell0.item(0) != null)
243     cell0.item(0).style.display='none';
244   if (cell.item(0) != null)
245     cell.item(0).style.display='block';
246   i += 1;
247   if (cell.item(0) == null) i = 0;
248   setTimeout('display_slides()',$duration);
249 }
250 display_slides();"));
251
252         while (list($key, $value) = each($photos)) {
253             if ($p && basename($value["name"]) != "$p") {
254                 continue;
255             }
256             if ($h && basename($value["name"]) == "$h") {
257                 $color = $hlcolor ? $hlcolor : $bgcolor;
258             } else {
259                 $color = $bgcolor;
260             }
261             // $params will be used for each <img > tag
262             $params = array('src' => $value["name"],
263                 'src_tile' => $value["name_tile"],
264                 'alt' => ($value["desc"] != "" and in_array("alt", $attributes))
265                     ? $value["desc"]
266                     : basename($value["name"]));
267             if (!@empty($value['location']))
268                 $params = array_merge($params, array("location" => $value['location']));
269             // check description
270             switch ($showdesc) {
271                 case 'none':
272                     $value["desc"] = '';
273                     break;
274                 case 'name':
275                     $value["desc"] = basename($value["name"]);
276                     break;
277                 case 'desc':
278                     break;
279                 default: // 'both'
280                     if (!$value["desc"]) $value["desc"] = basename($value["name"]);
281                     break;
282             }
283
284             // FIXME: get getimagesize to work with names with spaces in it.
285             // convert $value["name"] from webpath to local path
286             $size = @getimagesize($value["name"]); // try " " => "\\ "
287             if (!$size and !empty($value["src"])) {
288                 $size = @getimagesize($value["src"]);
289                 if (!$size) {
290                     trigger_error("Unable to getimagesize(" . $value["name"] . ")",
291                         E_USER_NOTICE);
292                 }
293             }
294             $newwidth = $this->newSize($size[0], $width);
295             if ($width != 'auto' && $newwidth > 0) {
296                 $params = array_merge($params, array("width" => $newwidth));
297             }
298             if (($mode == 'thumbs' || $mode == 'tiles' || $mode == 'list')) {
299                 if (!empty($size[0])) {
300                     $newheight = round($newwidth * $size[1] / $size[0]);
301                     $params['width'] = $newwidth;
302                     $params['height'] = $newheight;
303                 } else  $newheight = '';
304                 if ($height == 'auto') $height = 150;
305             } else {
306                 $newheight = $this->newSize($size[1], $height);
307                 if ($height != 'auto' && $newheight > 0) {
308                     $params = array_merge($params, array("height" => $newheight));
309                 }
310             }
311
312             // cell operations
313             $cell = array(
314                 'class' => 'photoalbum cell align-center top',
315                 'bgcolor' => "$color");
316             if ($cellwidth != 'auto') {
317                 if ($cellwidth == 'equal') {
318                     $newcellwidth = round(100 / $numcols) . "%";
319                 } elseif ($cellwidth == 'image') {
320                     $newcellwidth = $newwidth;
321                 } else {
322                     $newcellwidth = $cellwidth;
323                 }
324                 $cell = array_merge($cell, array("width" => $newcellwidth));
325             }
326             if (in_array("nowrap", $attributes)) {
327                 $cell = array_merge($cell, array("nowrap" => "nowrap"));
328             }
329             //create url to display single larger version of image on page
330             $url = WikiURL($request->getPage(),
331                 array("p" => basename($value["name"])))
332                 . "#"
333                 . basename($value["name"]);
334
335             $b_url = WikiURL($request->getPage(),
336                 array("h" => basename($value["name"])))
337                 . "#"
338                 . basename($value["name"]);
339             $url_text = $link
340                 ? HTML::a(array("href" => "$url"), basename($value["desc"]))
341                 : basename($value["name"]);
342             if (!$p) {
343                 if ($mode == 'normal' || $mode == 'slide') {
344                     if (!@empty($params['location'])) $params['src'] = $params['location'];
345                     unset ($params['location'], $params['src_tile']);
346                     $url_image = $link ? HTML::a(array("id" => basename($value["name"]),
347                         "href" => "$url"), HTML::img($params))
348                         : HTML::img($params);
349                 } else {
350                     $keep = $params;
351                     if (!@empty ($params['src_tile']))
352                         $params['src'] = $params['src_tile'];
353                     unset ($params['location'], $params['src_tile']);
354                     $url_image = $link ? HTML::a(array("id" => basename($value["name"]),
355                             "href" => "$url"),
356                         ImageTile::image_tile($params))
357                         : HTML::img($params);
358                     $params = $keep;
359                     unset ($keep);
360                 }
361             } else {
362                 if (!@empty($params['location'])) $params['src'] = $params['location'];
363                 unset ($params['location'], $params['src_tile']);
364                 $url_image = $link ? HTML::a(array("id" => basename($value["name"]),
365                     "href" => "$b_url"), HTML::img($params))
366                     : HTML::img($params);
367             }
368             if ($mode == 'list')
369                 $url_text = HTML::a(array("id" => basename($value["name"])),
370                     $url_text);
371             // here we use different modes
372             if ($mode == 'tiles') {
373                 $row->pushContent(
374                     HTML::td($cell,
375                         HTML::div(array('class' => 'top'), $url_image),
376                         HTML::div(array('class' => 'bottom'),
377                             HTML::div(array('class' => 'boldsmall'),
378                                 ($url_text)),
379                             HTML::br(),
380                             HTML::div(array('class' => 'gensmall'),
381                                 ($size[0] .
382                                     " x " .
383                                     $size[1] .
384                                     " pixels"))))
385                 );
386             } elseif ($mode == 'list') {
387                 $desc = ($showdesc != 'none') ? $value["desc"] : '';
388                 $row->pushContent(
389                     HTML::td(array("class" => "top",
390                             "nowrap" => 0,
391                             "bgcolor" => $color),
392                         HTML::div(array('class' => 'boldsmall'), ($url_text))));
393                 $row->pushContent(
394                     HTML::td(array("class" => "top",
395                             "nowrap" => 0,
396                             "bgcolor" => $color),
397                         HTML::div(array('class' => 'gensmall'),
398                             ($size[0] .
399                                 " x " .
400                                 $size[1] .
401                                 " pixels"))));
402
403                 if ($desc != '')
404                     $row->pushContent(
405                         HTML::td(array("class" => "top",
406                                 "nowrap" => 0,
407                                 "bgcolor" => $color),
408                             HTML::div(array('class' => 'gensmall'), $desc)));
409
410             } elseif ($mode == 'thumbs') {
411                 $desc = ($showdesc != 'none') ?
412                     HTML::p(HTML::a(array("href" => "$url"),
413                         $url_text)) : '';
414                 $row->pushContent(
415                     (HTML::td($cell,
416                         $url_image,
417                         // FIXME: no HtmlElement for fontsizes?
418                         // rurban: use ->setAttr("style","font-size:small;")
419                         //         but better use a css class
420                         HTML::div(array('class' => 'gensmall'), $desc)
421                     )));
422             } elseif ($mode == 'normal') {
423                 $desc = ($showdesc != 'none') ? HTML::p($value["desc"]) : '';
424                 $row->pushContent(
425                     (HTML::td($cell,
426                         $url_image,
427                         // FIXME: no HtmlElement for fontsizes?
428                         HTML::div(array('class' => 'gensmall'), $desc)
429                     )));
430             } elseif ($mode == 'slide') {
431                 if ($newwidth == 'auto' || !$newwidth)
432                     $newwidth = $this->newSize($size[0], $width);
433                 if ($newwidth == 'auto' || !$newwidth)
434                     $newwidth = $size[0];
435                 if ($newheight != 'auto') $newwidth = round($size[0] * $newheight / $size[1]);
436                 $desc = ($showdesc != 'none') ? HTML::p($value["desc"]) : '';
437                 if ($count == 0)
438                     $cell = array('style' => 'display: block; '
439                         . 'position: absolute; '
440                         . 'left: 50% ; '
441                         . 'margin-left: -' . round($newwidth / 2) . 'px;'
442                         . 'text-align: center; '
443                         . 'vertical-align: top',
444                         'name' => "wikislide" . $count);
445                 else
446                     $cell = array('style' => 'display: none; '
447                         . 'position: absolute ;'
448                         . 'left: 50% ;'
449                         . 'margin-left: -' . round($newwidth / 2) . 'px;'
450                         . 'text-align: center; '
451                         . 'vertical-align: top',
452                         'name' => "wikislide" . $count);
453                 if ($align == 'left' || $align == 'right') {
454                     if ($count == 0)
455                         $cell = array('style' => 'display: block; '
456                             . 'position: absolute; '
457                             . $align . ': 50px; '
458                             . 'vertical-align: top',
459                             'name' => "wikislide" . $count);
460                     else
461                         $cell = array('style' => 'display: none; '
462                             . 'position: absolute; '
463                             . $align . ': 50px; '
464                             . 'vertical-align: top',
465                             'name' => "wikislide" . $count);
466                 }
467                 $row->pushContent(
468                     (HTML::td($cell,
469                         $url_image,
470                         HTML::div(array('class' => 'gensmall'), $desc)
471                     )));
472                 $count++;
473             } elseif ($mode == 'row') {
474                 $desc = ($showdesc != 'none') ? HTML::p($value["desc"]) : '';
475                 $row->pushContent(
476                     HTML::table(array("style" => "display: inline",
477                             'class' > "photoalbum row"),
478                         HTML::tr(HTML::td($url_image)),
479                         HTML::tr(HTML::td(array("class" => "gensmall",
480                                 "style" => "text-align: center; "
481                                     . "background-color: $color"),
482                             $desc))
483                     ));
484             } else {
485                 return $this->error(fmt("Invalid argument: %s=%s", 'mode', $mode));
486             }
487
488             // no more images in one row as defined by $numcols
489             if (($key + 1) % $numcols == 0 ||
490                 ($key + 1) == count($photos) ||
491                 $p
492             ) {
493                 if ($mode == 'row')
494                     $html->pushcontent(HTML::div($row));
495                 else
496                     $html->pushcontent(HTML::tr($row));
497                 $row->setContent('');
498             }
499         }
500
501         //create main table
502         $table_attributes = array(
503             "class" => "photoalbum",
504             "width" => $tablewidth ? $tablewidth : "100%");
505
506         if (!empty($tableheight))
507             $table_attributes = array_merge($table_attributes,
508                 array("height" => $tableheight));
509         if ($mode != 'row')
510             $html = HTML::table($table_attributes, $html);
511         // align all
512         return HTML::div(array("align" => $align), $html);
513     }
514
515     /**
516      * Calculate the new size in pixels when the original size
517      * with a value is given.
518      *
519      * @param  integer $oldSize Absolute no. of pixels
520      * @param  mixed   $value   Either absolute no. or HTML percentage e.g. '50%'
521      * @return integer New size in pixels
522      */
523     function newSize($oldSize, $value)
524     {
525         if (trim(substr($value, strlen($value) - 1)) != "%") {
526             return $value;
527         }
528         $value = str_replace("%", "", $value);
529         return round(($oldSize * $value) / 100);
530     }
531
532     /**
533      * fromLocation - read only one picture from fixed album_location
534      * and return it in array $photos
535      *
536      * @param string $src Name of page
537      * @param array $photos
538      * @return string Error if fixed location is not allowed
539      */
540     function fromLocation($src, &$photos)
541     {
542         /*if (!allow_album_location) {
543             return $this->error(_("Fixed album location is not allowed. Please specify parameter src."));
544     }*/
545         //FIXME!
546         if (!IsSafeURL($src)) {
547             return $this->error(_("Bad url in src: remove all of <, >, \""));
548         }
549         $photos[] = array("name" => $src, //album_location."/$src".album_default_extension,
550             "desc" => "");
551         return '';
552     }
553
554     /**
555      * fromFile - read pictures & descriptions (separated by ;)
556      *            from $src and return it in array $photos
557      *
558      * @param  string $src    path to dir or textfile (local or remote)
559      * @param  array  $photos
560      * @param string $webpath
561      * @return string Error when bad url or file couldn't be opened
562      */
563     function fromFile($src, &$photos, $webpath = '')
564     {
565         $src_bak = $src;
566         if (preg_match("/^Upload:(.*)$/", $src, $m)) {
567             $src = getUploadFilePath() . $m[1];
568             $webpath = getUploadDataPath() . $m[1];
569         }
570         //there has a big security hole... as loading config/config.ini !
571         if (!preg_match('/(\.csv|\.jpg|\.jpeg|\.png|\.gif|\/)$/', $src)) {
572             return $this->error(_("File extension for csv file has to be '.csv'"));
573         }
574         if (!IsSafeURL($src)) {
575             return $this->error(_("Bad url in src: remove all of <, >, \""));
576         }
577         if (preg_match('/^(http|ftp|https):\/\//i', $src)) {
578             $contents = url_get_contents($src);
579             $web_location = 1;
580         } else {
581             $web_location = 0;
582             if (string_ends_with($src, "/"))
583                 $src = substr($src, 0, -1);
584         }
585         if (!file_exists($src) and @file_exists(PHPWIKI_DIR . "/$src")) {
586             $src = PHPWIKI_DIR . "/$src";
587         }
588         // check if src is a directory
589         if (file_exists($src) and filetype($src) == 'dir') {
590             //all images
591             $list = array();
592             foreach (array('jpeg', 'jpg', 'png', 'gif') as $ext) {
593                 $fileset = new fileSet($src, "*.$ext");
594                 $list = array_merge($list, $fileset->getFiles());
595             }
596             // convert dirname($src) (local fs path) to web path
597             natcasesort($list);
598             if (!$webpath) {
599                 // assume relative src. default: "themes/Hawaiian/images/pictures"
600                 $webpath = DATA_PATH . '/' . $src_bak;
601             }
602             foreach ($list as $file) {
603                 // convert local path to webpath
604                 $photos[] = array("src" => $file,
605                     "name" => $webpath . "/$file",
606                     "name_tile" => $src . "/$file",
607                     "src" => $src . "/$file",
608                     "desc" => "");
609             }
610             return '';
611         }
612         // check if $src is an image
613         foreach (array('jpeg', 'jpg', 'png', 'gif') as $ext) {
614             if (preg_match("/\.$ext$/", $src)) {
615                 if (!file_exists($src) and @file_exists(PHPWIKI_DIR . "/$src"))
616                     $src = PHPWIKI_DIR . "/$src";
617                 if ($web_location == 1 and !empty($contents)) {
618                     $photos[] = array("src" => $src,
619                         "name" => $src,
620                         "name_tile" => $src,
621                         "src" => $src,
622                         "desc" => "");
623                     return '';
624                 }
625                 if (!file_exists($src))
626                     return $this->error(fmt("Unable to find src=ā€œ%sā€", $src));
627                 $photos[] = array("src" => $src,
628                     "name" => "../" . $src,
629                     "name_tile" => $src,
630                     "src" => $src,
631                     "desc" => "");
632                 return '';
633             }
634         }
635         if ($web_location == 0) {
636             $fp = @fopen($src, "r");
637             if (!$fp) {
638                 return $this->error(fmt("Unable to read src=ā€œ%sā€", $src));
639             }
640             while ($data = fgetcsv($fp, 1024, ';')) {
641                 if (count($data) == 0 || empty($data[0])
642                     || preg_match('/^#/', $data[0])
643                     || preg_match('/^[[:space:]]*$/', $data[0])
644                 )
645                     continue;
646                 if (empty($data[1])) $data[1] = '';
647                 $photos[] = array("name" => dirname($src) . "/" . trim($data[0]),
648                     "location" => "../" . dirname($src) . "/" . trim($data[0]),
649                     "desc" => trim($data[1]),
650                     "name_tile" => dirname($src) . "/" . trim($data[0]));
651             }
652             fclose($fp);
653
654         } elseif ($web_location == 1) {
655             //TODO: check if the file is an image
656             $contents = preg_split('/\n/', $contents);
657             while (list($key, $value) = each($contents)) {
658                 $data = preg_split('/\;/', $value);
659                 if (count($data) == 0 || empty($data[0])
660                     || preg_match('/^#/', $data[0])
661                     || preg_match('/^[[:space:]]*$/', $data[0])
662                 )
663                     continue;
664                 if (empty($data[1])) $data[1] = '';
665                 $photos[] = array("name" => dirname($src) . "/" . trim($data[0]),
666                     "src" => dirname($src) . "/" . trim($data[0]),
667                     "desc" => trim($data[1]),
668                     "name_tile" => dirname($src) . "/" . trim($data[0]));
669             }
670         }
671         return '';
672     }
673 }
674
675 // Local Variables:
676 // mode: php
677 // tab-width: 8
678 // c-basic-offset: 4
679 // c-hanging-comment-ender-p: nil
680 // indent-tabs-mode: nil
681 // End: