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