]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/plugin/PhotoAlbum.php
Add return argument
[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) {
189             return HTML::raw();
190         }
191
192         if (in_array("sort", $attributes))
193             sort($photos);
194
195         if ($p) {
196             $mode = "normal";
197         }
198
199         if ($mode == "column") {
200             $mode = "normal";
201             $numcols = "1";
202         }
203
204         // set some fixed properties for each $mode
205         if ($mode == 'thumbs' || $mode == 'tiles') {
206             $attributes = array_merge($attributes, "alt");
207             $attributes = array_merge($attributes, "nowrap");
208             $cellwidth = 'auto'; // else cell won't nowrap
209             if ($width == 'auto') $width = 70;
210         } elseif ($mode == 'list') {
211             $numcols = 1;
212             $cellwidth = "auto";
213             if ($width == 'auto') $width = 50;
214         } elseif ($mode == 'slide') {
215             $tableheight = 0;
216             $cell_width = 0;
217             $numcols = count($photos);
218             $keep = $photos;
219             while (list($key, $value) = each($photos)) {
220                 list($x, $y, $s, $t) = @getimagesize($value['src']);
221                 if ($height != 'auto') $y = $this->newSize($y, $height);
222                 if ($width != 'auto') $y = round($y * $this->newSize($x, $width) / $x);
223                 if ($x > $cell_width) $cell_width = $x;
224                 if ($y > $tableheight) $tableheight = $y;
225             }
226             $tableheight += 50;
227             $photos = $keep;
228             unset ($x, $y, $s, $t, $key, $value, $keep);
229         }
230
231         $row = HTML();
232         $duration = 1000 * $duration;
233         if ($mode == 'slide')
234             $row->pushContent(JavaScript("
235 i = 0;
236 function display_slides() {
237   j = i - 1;
238   cell0 = document.getElementsByName('wikislide' + j);
239   cell = document.getElementsByName('wikislide' + i);
240   if (cell0.item(0) != null)
241     cell0.item(0).style.display='none';
242   if (cell.item(0) != null)
243     cell.item(0).style.display='block';
244   i += 1;
245   if (cell.item(0) == null) i = 0;
246   setTimeout('display_slides()',$duration);
247 }
248 display_slides();"));
249
250         while (list($key, $value) = each($photos)) {
251             if ($p && basename($value["name"]) != "$p") {
252                 continue;
253             }
254             if ($h && basename($value["name"]) == "$h") {
255                 $color = $hlcolor ? $hlcolor : $bgcolor;
256             } else {
257                 $color = $bgcolor;
258             }
259             // $params will be used for each <img > tag
260             $params = array('src' => $value["name"],
261                 'src_tile' => $value["name_tile"],
262                 'alt' => ($value["desc"] != "" and in_array("alt", $attributes))
263                     ? $value["desc"]
264                     : basename($value["name"]));
265             if (!@empty($value['location']))
266                 $params = array_merge($params, array("location" => $value['location']));
267             // check description
268             switch ($showdesc) {
269                 case 'none':
270                     $value["desc"] = '';
271                     break;
272                 case 'name':
273                     $value["desc"] = basename($value["name"]);
274                     break;
275                 case 'desc':
276                     break;
277                 default: // 'both'
278                     if (!$value["desc"]) $value["desc"] = basename($value["name"]);
279                     break;
280             }
281
282             // FIXME: get getimagesize to work with names with spaces in it.
283             // convert $value["name"] from webpath to local path
284             $size = @getimagesize($value["name"]); // try " " => "\\ "
285             if (!$size and !empty($value["src"])) {
286                 $size = @getimagesize($value["src"]);
287                 if (!$size) {
288                     trigger_error("Unable to getimagesize(" . $value["name"] . ")",
289                         E_USER_NOTICE);
290                 }
291             }
292             $newwidth = $this->newSize($size[0], $width);
293             if ($width != 'auto' && $newwidth > 0) {
294                 $params = array_merge($params, array("width" => $newwidth));
295             }
296             if (($mode == 'thumbs' || $mode == 'tiles' || $mode == 'list')) {
297                 if (!empty($size[0])) {
298                     $newheight = round($newwidth * $size[1] / $size[0]);
299                     $params['width'] = $newwidth;
300                     $params['height'] = $newheight;
301                 } else  $newheight = '';
302                 if ($height == 'auto') $height = 150;
303             } else {
304                 $newheight = $this->newSize($size[1], $height);
305                 if ($height != 'auto' && $newheight > 0) {
306                     $params = array_merge($params, array("height" => $newheight));
307                 }
308             }
309
310             // cell operations
311             $cell = array('align' => "center",
312                 'valign' => "top",
313                 'class' => 'photoalbum cell',
314                 'bgcolor' => "$color");
315             if ($cellwidth != 'auto') {
316                 if ($cellwidth == 'equal') {
317                     $newcellwidth = round(100 / $numcols) . "%";
318                 } elseif ($cellwidth == 'image') {
319                     $newcellwidth = $newwidth;
320                 } else {
321                     $newcellwidth = $cellwidth;
322                 }
323                 $cell = array_merge($cell, array("width" => $newcellwidth));
324             }
325             if (in_array("nowrap", $attributes)) {
326                 $cell = array_merge($cell, array("nowrap" => "nowrap"));
327             }
328             //create url to display single larger version of image on page
329             $url = WikiURL($request->getPage(),
330                 array("p" => basename($value["name"])))
331                 . "#"
332                 . basename($value["name"]);
333
334             $b_url = WikiURL($request->getPage(),
335                 array("h" => basename($value["name"])))
336                 . "#"
337                 . basename($value["name"]);
338             $url_text = $link
339                 ? HTML::a(array("href" => "$url"), basename($value["desc"]))
340                 : basename($value["name"]);
341             if (!$p) {
342                 if ($mode == 'normal' || $mode == 'slide') {
343                     if (!@empty($params['location'])) $params['src'] = $params['location'];
344                     unset ($params['location'], $params['src_tile']);
345                     $url_image = $link ? HTML::a(array("id" => basename($value["name"]),
346                         "href" => "$url"), HTML::img($params))
347                         : HTML::img($params);
348                 } else {
349                     $keep = $params;
350                     if (!@empty ($params['src_tile']))
351                         $params['src'] = $params['src_tile'];
352                     unset ($params['location'], $params['src_tile']);
353                     $url_image = $link ? HTML::a(array("id" => basename($value["name"]),
354                             "href" => "$url"),
355                         ImageTile::image_tile($params))
356                         : HTML::img($params);
357                     $params = $keep;
358                     unset ($keep);
359                 }
360             } else {
361                 if (!@empty($params['location'])) $params['src'] = $params['location'];
362                 unset ($params['location'], $params['src_tile']);
363                 $url_image = $link ? HTML::a(array("id" => basename($value["name"]),
364                     "href" => "$b_url"), HTML::img($params))
365                     : HTML::img($params);
366             }
367             if ($mode == 'list')
368                 $url_text = HTML::a(array("id" => basename($value["name"])),
369                     $url_text);
370             // here we use different modes
371             if ($mode == 'tiles') {
372                 $row->pushContent(
373                     HTML::td($cell,
374                         HTML::div(array('valign' => 'top'), $url_image),
375                         HTML::div(array('valign' => 'bottom'),
376                             HTML::div(array('class' => 'boldsmall'),
377                                 ($url_text)),
378                             HTML::br(),
379                             HTML::div(array('class' => 'gensmall'),
380                                 ($size[0] .
381                                     " x " .
382                                     $size[1] .
383                                     " pixels"))))
384                 );
385             } elseif ($mode == 'list') {
386                 $desc = ($showdesc != 'none') ? $value["desc"] : '';
387                 $row->pushContent(
388                     HTML::td(array("valign" => "top",
389                             "nowrap" => 0,
390                             "bgcolor" => $color),
391                         HTML::div(array('class' => 'boldsmall'), ($url_text))));
392                 $row->pushContent(
393                     HTML::td(array("valign" => "top",
394                             "nowrap" => 0,
395                             "bgcolor" => $color),
396                         HTML::div(array('class' => 'gensmall'),
397                             ($size[0] .
398                                 " x " .
399                                 $size[1] .
400                                 " pixels"))));
401
402                 if ($desc != '')
403                     $row->pushContent(
404                         HTML::td(array("valign" => "top",
405                                 "nowrap" => 0,
406                                 "bgcolor" => $color),
407                             HTML::div(array('class' => 'gensmall'), $desc)));
408
409             } elseif ($mode == 'thumbs') {
410                 $desc = ($showdesc != 'none') ?
411                     HTML::p(HTML::a(array("href" => "$url"),
412                         $url_text)) : '';
413                 $row->pushContent(
414                     (HTML::td($cell,
415                         $url_image,
416                         // FIXME: no HtmlElement for fontsizes?
417                         // rurban: use ->setAttr("style","font-size:small;")
418                         //         but better use a css class
419                         HTML::div(array('class' => 'gensmall'), $desc)
420                     )));
421             } elseif ($mode == 'normal') {
422                 $desc = ($showdesc != 'none') ? HTML::p($value["desc"]) : '';
423                 $row->pushContent(
424                     (HTML::td($cell,
425                         $url_image,
426                         // FIXME: no HtmlElement for fontsizes?
427                         HTML::div(array('class' => 'gensmall'), $desc)
428                     )));
429             } elseif ($mode == 'slide') {
430                 if ($newwidth == 'auto' || !$newwidth)
431                     $newwidth = $this->newSize($size[0], $width);
432                 if ($newwidth == 'auto' || !$newwidth)
433                     $newwidth = $size[0];
434                 if ($newheight != 'auto') $newwidth = round($size[0] * $newheight / $size[1]);
435                 $desc = ($showdesc != 'none') ? HTML::p($value["desc"]) : '';
436                 if ($count == 0)
437                     $cell = array('style' => 'display: block; '
438                         . 'position: absolute; '
439                         . 'left: 50% ; '
440                         . 'margin-left: -' . round($newwidth / 2) . 'px;'
441                         . 'text-align: center; '
442                         . 'vertical-align: top',
443                         'name' => "wikislide" . $count);
444                 else
445                     $cell = array('style' => 'display: none; '
446                         . 'position: absolute ;'
447                         . 'left: 50% ;'
448                         . 'margin-left: -' . round($newwidth / 2) . 'px;'
449                         . 'text-align: center; '
450                         . 'vertical-align: top',
451                         'name' => "wikislide" . $count);
452                 if ($align == 'left' || $align == 'right') {
453                     if ($count == 0)
454                         $cell = array('style' => 'display: block; '
455                             . 'position: absolute; '
456                             . $align . ': 50px; '
457                             . 'vertical-align: top',
458                             'name' => "wikislide" . $count);
459                     else
460                         $cell = array('style' => 'display: none; '
461                             . 'position: absolute; '
462                             . $align . ': 50px; '
463                             . 'vertical-align: top',
464                             'name' => "wikislide" . $count);
465                 }
466                 $row->pushContent(
467                     (HTML::td($cell,
468                         $url_image,
469                         HTML::div(array('class' => 'gensmall'), $desc)
470                     )));
471                 $count++;
472             } elseif ($mode == 'row') {
473                 $desc = ($showdesc != 'none') ? HTML::p($value["desc"]) : '';
474                 $row->pushContent(
475                     HTML::table(array("style" => "display: inline",
476                             'class' > "photoalbum row"),
477                         HTML::tr(HTML::td($url_image)),
478                         HTML::tr(HTML::td(array("class" => "gensmall",
479                                 "style" => "text-align: center; "
480                                     . "background-color: $color"),
481                             $desc))
482                     ));
483             } else {
484                 return $this->error(fmt("Invalid argument: %s=%s", 'mode', $mode));
485             }
486
487             // no more images in one row as defined by $numcols
488             if (($key + 1) % $numcols == 0 ||
489                 ($key + 1) == count($photos) ||
490                 $p
491             ) {
492                 if ($mode == 'row')
493                     $html->pushcontent(HTML::div($row));
494                 else
495                     $html->pushcontent(HTML::tr($row));
496                 $row->setContent('');
497             }
498         }
499
500         //create main table
501         $table_attributes = array("border" => 0,
502             "cellpadding" => 5,
503             "cellspacing" => 2,
504             "class" => "photoalbum",
505             "width" => $tablewidth ? $tablewidth : "100%");
506
507         if (!empty($tableheight))
508             $table_attributes = array_merge($table_attributes,
509                 array("height" => $tableheight));
510         if ($mode != 'row')
511             $html = HTML::table($table_attributes, $html);
512         // align all
513         return HTML::div(array("align" => $align), $html);
514     }
515
516     /**
517      * Calculate the new size in pixels when the original size
518      * with a value is given.
519      *
520      * @param  integer $oldSize Absolute no. of pixels
521      * @param  mixed   $value   Either absolute no. or HTML percentage e.g. '50%'
522      * @return integer New size in pixels
523      */
524     function newSize($oldSize, $value)
525     {
526         if (trim(substr($value, strlen($value) - 1)) != "%") {
527             return $value;
528         }
529         $value = str_replace("%", "", $value);
530         return round(($oldSize * $value) / 100);
531     }
532
533     /**
534      * fromLocation - read only one picture from fixed album_location
535      * and return it in array $photos
536      *
537      * @param string $src Name of page
538      * @param array $photos
539      * @return string Error if fixed location is not allowed
540      */
541     function fromLocation($src, &$photos)
542     {
543         /*if (!allow_album_location) {
544             return $this->error(_("Fixed album location is not allowed. Please specify parameter src."));
545     }*/
546         //FIXME!
547         if (!IsSafeURL($src)) {
548             return $this->error(_("Bad url in src: remove all of <, >, \""));
549         }
550         $photos[] = array("name" => $src, //album_location."/$src".album_default_extension,
551             "desc" => "");
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     }
672 }
673
674 // Local Variables:
675 // mode: php
676 // tab-width: 8
677 // c-basic-offset: 4
678 // c-hanging-comment-ender-p: nil
679 // indent-tabs-mode: nil
680 // End: