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