<?php
-// vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4:
+// vim: set expandtab tabstop=4 shiftwidth=4 binary:
// +--------------------------------------------------------------------+
// | BIFE - Buil It FastEr |
// +--------------------------------------------------------------------+
'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']);
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++) {
$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(
- '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);
<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
*/
- 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)) {
- $thumb = $this->getThumbFilename("$root/$file");
+ $thumb = $this->getThumbFilename($file, $format,
+ $thumbsdir, $root);
$return[] = array(
- 'FILE' => "$root/$file",
+ 'FILE' => $file,
'DESC' => $name,
- 'THUMB' => is_readable($thumb) ? $thumb : null,
+ 'THUMB' => $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
+ * @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->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 (!@is_dir($path) and !@mkdir($path)) {
+ if (!@is_dir("$root/$thumbsdir") and !@mkdir("$root/$thumbsdir")) {
return null;
}
if (PEAR::isError($img)) {
return null;
}
}
- $img->save("$path/$name.$format", $format);
+ $img->save("$root/$thumbsdir/$name.$format", $format);
$img->free();
-
- return $thumb;
+ return "$thumbsdir/$name.$format";
}
// -X2C
* 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
*/
- 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);
-
- return "$root/$thumbsdir/$name.$format";
+ if (is_readable("$root/$thumbsdir/$name.$format")) {
+ return "$thumbsdir/$name.$format";
+ } else {
+ return null;
+ }
}
// -X2C