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