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