]> git.llucax.com Git - software/bife/album.git/blobdiff - src/BIFE/Album/Thumbs.php
Removed \n at the end of the file and added a VIM option to keep it as is.
[software/bife/album.git] / src / BIFE / Album / Thumbs.php
index 293b0922d07cb30275263786950851a31f528495..53b0b508ca12b41bbccabde303825079d4c5bd1e 100644 (file)
@@ -1,5 +1,5 @@
 <?php
 <?php
-// vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
+// vim: set expandtab tabstop=4 shiftwidth=4 binary:
 // +--------------------------------------------------------------------+
 // |                       BIFE - Buil It FastEr                        |
 // +--------------------------------------------------------------------+
 // +--------------------------------------------------------------------+
 // |                       BIFE - Buil It FastEr                        |
 // +--------------------------------------------------------------------+
@@ -78,8 +78,7 @@ class BIFE_Album_Thumbs extends BIFE_Widget {
             'EXTENSIONS'    => 'png,jpg,jpeg,PNG,JPG,JPEG',
             'MAXROWS'       => 0,
             'COLUMNS'       => 4,
             'EXTENSIONS'    => 'png,jpg,jpeg,PNG,JPG,JPEG',
             'MAXROWS'       => 0,
             'COLUMNS'       => 4,
-            'LINK-BIFE'     => 'photo.xbf',
-            'LINK-URL'      => '',
+            'LINK'          => 'photo.xbf',
         );
         $attrs = array_merge($defaults, $attrs);
         $attrs['EXTENSIONS'] = explode(',', $attrs['EXTENSIONS']);
         );
         $attrs = array_merge($defaults, $attrs);
         $attrs['EXTENSIONS'] = explode(',', $attrs['EXTENSIONS']);
@@ -99,7 +98,9 @@ class BIFE_Album_Thumbs extends BIFE_Widget {
     function render(&$template) // ~X2C
     {
         $template->pushGroup('album');
     function render(&$template) // ~X2C
     {
         $template->pushGroup('album');
-        $list = $this->getList();
+        $list = $this->getList(BIFE_Link::getFsPath() . $this->attrs['DIR'],
+                $this->attrs['EXTENSIONS'], $this->attrs['THUMBSFORMAT'],
+                $this->attrs['THUMBSDIR']);
         $tot  = count($list);
         $rows = ceil($tot / $this->attrs['COLUMNS']);
         for ($row = 0; $row < $rows; $row++) {
         $tot  = count($list);
         $rows = ceil($tot / $this->attrs['COLUMNS']);
         for ($row = 0; $row < $rows; $row++) {
@@ -107,13 +108,18 @@ class BIFE_Album_Thumbs extends BIFE_Widget {
                 $cur = $row * $this->attrs['COLUMNS'] + $col;
                 if ($photo = @$list[$cur]) {
                     if (is_null($photo['THUMB'])) {
                 $cur = $row * $this->attrs['COLUMNS'] + $col;
                 if ($photo = @$list[$cur]) {
                     if (is_null($photo['THUMB'])) {
-                        $photo['THUMB'] = $this->makeThumb($photo['FILE']);
+                        $photo['THUMB'] = $this->makeThumb($photo['FILE'],
+                            $this->attrs['THUMBSFORMAT'],
+                            $this->attrs['THUMBSDIR'],
+                            BIFE_Link::getFsPath() . $this->attrs['DIR']);
                     }
                     }
+                    $photo['THUMB'] = BIFE_Link::getWebPath()
+                        . $this->attrs['DIR'] . '/' . $photo['THUMB'];
                     $photo['URL'] = BIFE_Link::getURL(
                         array(
                     $photo['URL'] = BIFE_Link::getURL(
                         array(
-                            'BIFE'                  => $this->attrs['LINK-BIFE'],
-                            'URL'                   => $this->attrs['LINK-URL'],
-                            'DATA-BIFE_ALBUM_FILE'  => $photo['FILE'],
+                            'URL'                   => $this->attrs['LINK'],
+                            'DATA-BIFE_ALBUM_FILE'  => BIFE_Link::getWebPath()
+                                 . $this->attrs['DIR'] . '/' . $photo['FILE'],
                         )
                     );
                     $cell = $template->parse('item', $photo);
                         )
                     );
                     $cell = $template->parse('item', $photo);
@@ -142,26 +148,29 @@ Returns an array of associative arrays with this keys:
 <li><b>desc:</b> Photo Description.</li>
 <li><b>thumb:</b> Photo thumbnail filename.</li>
 </ul>
 <li><b>desc:</b> Photo Description.</li>
 <li><b>thumb:</b> Photo thumbnail filename.</li>
 </ul>
+     *
+     * @param  string $root Directory where images are.
+     * @param  array $exts Images extensions to accept.
+     * @param  string $format Format to use to save the thumbs.
+     * @param  string $thumbsdir Directory where the thumbs are.
      *
      * @return array
      * @access protected
      */
      *
      * @return array
      * @access protected
      */
-    function getList() // ~X2C
+    function getList($root, $exts, $format, $thumbsdir) // ~X2C
     {
     {
-        $root = $this->attrs['DIR'];
-        $exts = $this->attrs['EXTENSIONS'];
-        $format = $this->attrs['THUMBSFORMAT'];
         $return = array();
         $d = dir($root);
         if ($d) {
             while (($file = $d->read()) !== false) {
                 list($path, $name, $ext) = $this->splitFilename("$root/$file");
                 if (is_readable("$root/$file") and in_array($ext, $exts)) {
         $return = array();
         $d = dir($root);
         if ($d) {
             while (($file = $d->read()) !== false) {
                 list($path, $name, $ext) = $this->splitFilename("$root/$file");
                 if (is_readable("$root/$file") and in_array($ext, $exts)) {
-                    $thumb = $this->getThumbFilename("$root/$file");
+                    $thumb = $this->getThumbFilename($file, $format,
+                        $thumbsdir, $root);
                     $return[] = array(
                     $return[] = array(
-                        'FILE'  => "$root/$file",
+                        'FILE'  => $file,
                         'DESC'  => $name,
                         'DESC'  => $name,
-                        'THUMB' => is_readable($thumb) ? $thumb : null,
+                        'THUMB' => $thumb,
                     );
                 }              
             }
                     );
                 }              
             }
@@ -176,21 +185,23 @@ Returns an array of associative arrays with this keys:
      * Creates an image thumbnail, returning his filename.
      *
      * @param  string $filename Filename of the image to create the thumb.
      * Creates an image thumbnail, returning his filename.
      *
      * @param  string $filename Filename of the image to create the thumb.
+     * @param  string $format Thumbs format.
+     * @param  string $thumbsdir Directory where to put the thumbs.
+     * @param  string $root Root directory.
      * @param  int $size Maximum thumbnail size.
      *
      * @return string
      * @access protected
      * @param  int $size Maximum thumbnail size.
      *
      * @return string
      * @access protected
+     * @static
      */
      */
-    function makeThumb($filename, $size = 100) // ~X2C
+    function makeThumb($filename, $format, $thumbsdir, $root, $size = 100) // ~X2C
     {
     {
-        $format = $this->attrs['THUMBSFORMAT'];
-        $thumb = $this->getThumbFilename($filename);
-        list($path, $name, $ext) = $this->splitFilename($thumb);
+        list($path, $name, $ext) = $this->splitFilename($filename);
         $img =& Image_Transform::factory('GD');
         $img =& Image_Transform::factory('GD');
-        $img->load($filename);
+        $img->load("$root/$filename");
         // If image is larger than the maximum size, we resize it.
         if ($img->img_x > $size or $img->img_y > $size ) {
         // If image is larger than the maximum size, we resize it.
         if ($img->img_x > $size or $img->img_y > $size ) {
-            if (!@is_dir($path) and !@mkdir($path)) {
+            if (!@is_dir("$root/$thumbsdir") and !@mkdir("$root/$thumbsdir")) {
                 return null;
             }
             if (PEAR::isError($img)) {
                 return null;
             }
             if (PEAR::isError($img)) {
@@ -200,10 +211,9 @@ Returns an array of associative arrays with this keys:
                 return null;
             }
         }
                 return null;
             }
         }
-        $img->save("$path/$name.$format", $format);
+        $img->save("$root/$thumbsdir/$name.$format", $format);
         $img->free();
         $img->free();
-
-        return $thumb;
+        return "$thumbsdir/$name.$format";
     }
     // -X2C
 
     }
     // -X2C
 
@@ -212,19 +222,21 @@ Returns an array of associative arrays with this keys:
      * Returns the filename of an image thumb.
      *
      * @param  string $filename Filename of the image to get the thumb name.
      * Returns the filename of an image thumb.
      *
      * @param  string $filename Filename of the image to get the thumb name.
+     * @param  string $format Thumbs format.
+     * @param  string $thumbsdir Directory where the thumbs are.
+     * @param  string $root Root directory.
      *
      * @return string
      * @access protected
      */
      *
      * @return string
      * @access protected
      */
-    function getThumbFilename($filename) // ~X2C
+    function getThumbFilename($filename, $format, $thumbsdir, $root) // ~X2C
     {
     {
-        $root = $this->attrs['DIR'];
-        $format = $this->attrs['THUMBSFORMAT'];
-        $thumbsdir = $this->attrs['THUMBSDIR'];
-
         list($path, $name, $ext) = $this->splitFilename($filename);
         list($path, $name, $ext) = $this->splitFilename($filename);
-
-        return "$root/$thumbsdir/$name.$format";
+        if (is_readable("$root/$thumbsdir/$name.$format")) {
+            return "$thumbsdir/$name.$format";
+        } else {
+            return null;
+        }
     }
     // -X2C
 
     }
     // -X2C