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