From: Leandro Lucarella Date: Sat, 31 May 2003 00:55:47 +0000 (+0000) Subject: - Added experimental phing build file. X-Git-Tag: svn_import~49 X-Git-Url: https://git.llucax.com/software/bife/bife-all.git/commitdiff_plain/f36ac20c1ad9e4d0987240a7fd2e0438f492be9b?ds=sidebyside - Added experimental phing build file. - Added experimental PEAR package.xml. - Added AlbumPhoto widget. - Added AlbumPhoto to the example. - Fixed some bugs. --- diff --git a/build.xml b/build.xml new file mode 100644 index 0000000..5a6d0a5 --- /dev/null +++ b/build.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/doc/bife.xmi b/doc/bife.xmi index a21c9de..cd94d32 100644 --- a/doc/bife.xmi +++ b/doc/bife.xmi @@ -9,7 +9,7 @@ - + @@ -166,70 +166,88 @@ Returns an array of associative arrays with this keys: + + + + + + + + + + + + + - + - - - - - - - - - + + + + + + + + + + - - + + - - - + + - - + + - - - + + - - + + - - + + - - + + - - + + + + + + + + @@ -286,7 +304,7 @@ Returns an array of associative arrays with this keys: - + @@ -311,6 +329,13 @@ Returns an array of associative arrays with this keys: + + + + + + + diff --git a/examples/photo.php b/examples/photo.php new file mode 100644 index 0000000..ca803c7 --- /dev/null +++ b/examples/photo.php @@ -0,0 +1,51 @@ + | +// +--------------------------------------------------------------------+ +// +// $Id$ +// + +$tmp = ini_get('include_path'); +ini_set('include_path', "../src:$tmp"); +unset($tmp); + +require_once 'HTML/Template/Sigma.php'; +require_once 'BIFE/Parser.php'; +require_once 'BIFE/Copy.php'; +require_once 'BIFE/Page.php'; +require_once 'BIFE/Title.php'; +#require_once 'BIFE/Album.php'; +#require_once 'BIFE.php'; + +$file = 'photo.xbf'; + +$template =& new HTML_Template_Sigma('templates'); +$template->setErrorHandling(PEAR_ERROR_PRINT); + +$parser =& new BIFE_Parser('BIFE_Copy'); +$page =& $parser->parseFile($file); +$parser->__destruct(); +echo $page->render($template); + +?> diff --git a/examples/photo.xbf b/examples/photo.xbf new file mode 100644 index 0000000..5ead3ee --- /dev/null +++ b/examples/photo.xbf @@ -0,0 +1,4 @@ + + + + diff --git a/examples/templates/bife_album_item.html b/examples/templates/bife_album_item.html index 1e828f9..5d20d8c 100644 --- a/examples/templates/bife_album_item.html +++ b/examples/templates/bife_album_item.html @@ -1,3 +1,3 @@ - {DESC} + {DESC} diff --git a/examples/templates/bife_albumphoto.html b/examples/templates/bife_albumphoto.html new file mode 100644 index 0000000..34c901f --- /dev/null +++ b/examples/templates/bife_albumphoto.html @@ -0,0 +1,2 @@ +{DESC} +
{DESC}
diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..0c54d1b --- /dev/null +++ b/package.xml @@ -0,0 +1,55 @@ + + + + BIFE + Build It FastEr + BIFE - Build It FastEr: +BIFE is a framwork to separate the logic, contents and looks of a PHP +application, inspired on BIF (Buil It Fast) but with speed in mind. +One of the main goals of BIFE is to be fast. + + GPL + + + luca + Leandro Lucarella + luca@lugmen.org.ar + lead + + + + + 0.8 + 2003-05-23 + alpha + + - Added a root blah... + + + + src/BIFE/Parser.php + src/BIFE/Widget.php + src/BIFE/Container.php + src/BIFE/Root.php + src/BIFE/Fallback.php + src/BIFE/Page.php + src/BIFE/Copy.php + src/BIFE/Generic.php + src/BIFE/Title.php + src/BIFE/Album.php + + doc/bife.xmi + examples/index.php + examples/simple.xbf + examples/templates/bife_page.html + examples/templates/bife_title.html + examples/templates/bife_album.html + examples/templates/bife_album_item.html + examples/templates/bife_album_emptyitem.html + + + + 4.2.3 + HTML_Template_Sigma + + diff --git a/src/Album.php b/src/Album.php deleted file mode 100644 index 7ec9ca0..0000000 --- a/src/Album.php +++ /dev/null @@ -1,299 +0,0 @@ - | -// | Groucho Marx | -// | Leandro Lucarella | -// +--------------------------------------------------------------------+ -// -// $Id$ -// - -require_once 'Image/Transform.php'; -require_once 'HTML/Template/Sigma.php'; - -/** - * Generates a photo album. - * - * This library generates a photo album dinamically. - * - * @package Hooks - * @subpackage Album - * @author Leandro Lucarella - * @author Harpo Maxx - * @author Groucho Marx - * @version $Rev$ - * @since rev 130 - * @access public - */ -class Hook_Album { - - var $root; - var $recursive; - var $thumbsdir; - var $thumbsformat; - var $exts; - - /** - * Constructor. - * - * @param string $root Root directory. - * same row. - * @param bool $recursive True if subdirectories must be - * proccessed. - * @param string $thumbsdir Directory where the thumbnails are (or - * will be generated). - * @param array $exts Comma separated extensions of photo files. - * - * @access public - */ - function Hook_Album($root = '.', $recursive = true, $thumbsformat = 'jpeg', $thumbsdir = '.thumbs', $exts = 'png,jpg,jpeg,gif') { - $this->root = $root ? $root : '.'; - $this->recursive = $recursive; - $this->thumbsdir = $thumbsdir; - $this->thumbsformat = $thumbsformat; - $this->exts = preg_split('/\s*,\s*/', $exts); - } - - /** - * Shows the photo album. - * - * Shows the photo album. - * - * @param string $photo Selected photo. - * @param int $max Maximum quantity of thumbnails to show. 0 for - * unlimited. - * @param int $cols How many thumbnails are shown in the - * - * @access public - * @todo Implement the 'max' feature! - * @todo Make the thumbs cache before showing the images so the - * browser can find the with having to refresh. - */ - function album(&$tpl, $photo = '', $max = 0, $cols = 4) { - $tpl->loadTemplateFile('bife_album.html'); - $tpl->addBlockFile('ITEMS', 'ITEM', 'bife_album_item.html'); - - $root = $this->root; - $list = $this->getList(); - $tot = count($list); - $rows = ceil($tot / $cols); - - for ($row = 0; $row < $rows; $row++) { - for ($col = 0; $col < $cols; $col++) { - $cur = $row*$cols+$col; - if ($photo = @$list[$cur]) { - $selected = ($photo['file'] === $photo); - if (is_null($photo['thumb'])) { - $photo['thumb'] = $this->makeThumb($photo['file']); - } - $tpl->setVariable( - array( - 'PHOTO' => $photo['file'], - 'DESC' => $photo['desc'], - 'THUMB' => $photo['thumb'], - ) - ); - $tpl->parse('ITEM'); - } else { - if (!@$empty) { - $tpl->replaceBlockFile('ITEM', - 'bife_album_emptyitem.html', true); - $empty = true; - } - $tpl->touchBlock('ITEM'); - $tpl->parse('ITEM'); - } - } - $tpl->parse('FILA'); - } - $tpl->setVariable('DESC', $this->getDescription()); - return $tpl->get(); - } - - /** - * Shows a photo. - * - * Shows a photo. - * - * @param string $photo Photo to show. - * - * @access public - * @since rev 131 - */ - function photo($photo) { - list($path, $name, $ext) = File_Util::splitFilename($photo); - $tpl =& new HTML_Template_Sigma('.'); - $tpl->loadTemplateFile('bife_album_photo.html'); - $tpl->setVariable( - array( - 'DESC' => $name, - 'PHOTO' => $photo, - ) - ); - $tpl->show(); - } - - /** - * Makes a photo thumbnail. - * - * @param string $photo Source photo to create the thumbnail. - * @param int $size Maximum thumbnail size. - * - * @return bool True on success, false on failure. - * - * @access public - * @since rev 131 - */ - function makeThumb($photo, $size = 100) { - $format = $this->thumbsformat; - $thumb = $this->getThumbName($photo); - list($path, $name, $ext) = File_Util::splitFilename($thumb); - - $img =& Image_Transform::factory('GD'); - - $img->load($photo); - // 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)) { - return false; - } - if (PEAR::isError($img)) { - return false; - } - if (!$img->scale($size)) { - return false; - } - } - $img->save("$path/$name.$format", $format); - $img->free(); - - return true; - } - - /** - * Gets a list of photos with their descriptions and thumbnails. - * - * Returns an array of associative arrays with this keys: - *
    - *
  • file: Photo filename.
  • - *
  • desc: Photo Description.
  • - *
  • thumb: Photo thumbnail filename.
  • - *
- * - * @return array Array of associative arrays with file, desc and - * thumb. - * - * @access public - */ - function getList() { - $root = $this->root; - $exts = $this->exts; - $format = $this->thumbsformat; - $return = array(); - - $d = dir($root); - while (($file = $d->read()) !== false) { - list($path, $name, $ext) = File_Util::splitFilename("$root/$file"); - if (is_readable("$root/$file") and in_array($ext, $exts)) { - $thumb = $this->getThumbName("$root/$file"); - $return[] = array( - 'file' => "$root/$file", - 'desc' => $name, - 'thumb' => is_readable($thumb) ? $thumb : null, - ); - } - } - $d->close(); - - return $return; - } - - /** - * Gets a photo thumbnail name. - * - * @param string $photo Source photo to create the thumbnail. - * - * @return string Thumbnail name. - * - * @access public - * @since rev 131 - */ - function getThumbName($photo) { - $root = $this->root; - $format = $this->thumbsformat; - $thumbsdir = $this->thumbsdir; - - list($path, $name, $ext) = File_Util::splitFilename($photo); - - return "$root/$thumbsdir/$name.$format"; - } - - /** - * Creates album thumbnails. - * - * @since rev 147 - * @access public - */ - function createThumbs() { - foreach ($this->getList() as $photo) { - if (is_null($photo['thumb'])) { - $photo['thumb'] = $this->makeThumb($photo['file']); - } - } - } - - /** - * Sets the album description. - * - * @param string $desc New album description. - * - * @returns bool True on success, false on failure. - * - * @since rev 147 - * @access public - */ - function setDescription($desc) { - $root = $this->root; - $out = fopen("$root/.album", 'w'); - $ret = fputs($out, $desc); - fclose($out); - return $ret ? true : false; - } - - /** - * Gets the album description. - * - * @returns string Album description. - * - * @since rev 149 - * @access public - */ - function getDescription() { - $root = $this->root; - return file_get_contents("$root/.album"); - } - -} - -// $Id$ -?> diff --git a/src/BIFE/Album.php b/src/BIFE/Album.php index 1788ee8..977949c 100644 --- a/src/BIFE/Album.php +++ b/src/BIFE/Album.php @@ -30,6 +30,8 @@ require_once 'BIFE/Widget.php'; // ~X2C +require_once 'Image/Transform.php'; + // +X2C Class 20 :Album /** * Photo album widget. [TODO: Make a better explanation] @@ -83,6 +85,8 @@ class BIFE_Album extends BIFE_Widget { 'SELECTED' => '', 'MAXROWS' => 0, 'COLUMNS' => 4, + // TODO - agregar atributo para el LINK, ver de hacer el + // widget de un link. ); $this->attrs = array_merge($defaults, $attrs); $this->attrs['EXTENSIONS'] = explode(',', $this->attrs['EXTENSIONS']); @@ -161,21 +165,21 @@ Returns an array of associative arrays with this keys: $exts = $this->attrs['EXTENSIONS']; $format = $this->attrs['THUMBSFORMAT']; $return = array(); - $d = dir($root); - 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"); - $return[] = array( - 'file' => "$root/$file", - 'desc' => $name, - 'thumb' => is_readable($thumb) ? $thumb : null, - ); - } + 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"); + $return[] = array( + 'file' => "$root/$name", + 'desc' => $name, + 'thumb' => is_readable($thumb) ? $thumb : null, + ); + } + } + $d->close(); } - $d->close(); - return $return; } // -X2C diff --git a/src/BIFE/AlbumPhoto.php b/src/BIFE/AlbumPhoto.php new file mode 100644 index 0000000..7d7548d --- /dev/null +++ b/src/BIFE/AlbumPhoto.php @@ -0,0 +1,113 @@ + | +// +--------------------------------------------------------------------+ +// +// $Id$ +// + +// +X2C includes +require_once 'BIFE/Widget.php'; +// ~X2C + +// +X2C Class 103 :AlbumPhoto +/** + * Photo widget. + * + * @access public + */ +class BIFE_AlbumPhoto extends BIFE_Widget { + /** + * Photo filename. + * + * @var string $file + * @access protected + */ + var $file; + + /** + * Photo Description. + * + * @var string $desc + * @access protected + */ + var $desc; + + // ~X2C + + // +X2C Operation 106 + /** + * Constructor. + * + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function BIFE_AlbumPhoto($attrs) // ~X2C + { + $this->__construct($attrs); + } + // -X2C + + // +X2C Operation 107 + /** + * Constructor. + * + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function __construct($attrs) // ~X2C + { + $this->file = @$attrs['FILE'] ? $attrs['FILE'] : @$_REQUEST['BIFE_AlbumPhoto_FILE']; + $this->desc = @$attrs['DESC'] ? $attrs['DESC'] : basename($this->file); + } + // -X2C + + // +X2C Operation 108 + /** + * Renders the widget using a template returning a string with the results. + * + * @param HTML_Template_Sigma &$template Template to use to render the widget. + * + * @return string + * @access public + */ + function render(&$template) // ~X2C + { + $template->loadTemplateFile('bife_albumphoto.html'); + $template->setVariable( + array( + 'FILE' => $this->file, + 'DESC' => $this->desc, + ) + ); + return $template->get(); + } + // -X2C + +} // -X2C Class :AlbumPhoto + +?> diff --git a/src/Util.php b/src/Util.php deleted file mode 100644 index 7fee82a..0000000 --- a/src/Util.php +++ /dev/null @@ -1,128 +0,0 @@ - | -// +--------------------------------------------------------------------+ -// -// $Id$ -// - -/** - * General file utilities functions. - * - * This is a group of static functions for getting file info and other - * stuff. - * - * @package Hooks - * @author Leandro Lucarella - * @version $Rev$ - * @since rev 122 - * @access public - */ -class File_Util { - - /** - * Splits a filename into path, filename and extension. - * - * @param string $file Filename to split. - * - * @return array Array where the first element (index 0) is the - * path, the second is the name and the third is the - * extension. - * - * @access public - * @since rev 122 - */ - function splitFilename($file) - { - $path = preg_split('|/|', $file); - $file = array_pop($path); - $ext = ''; - if (strstr($file, '.')) { - preg_match('|([^/]+?)(\.([^\.]*))?$|', $file, $m); - $file = @$m[1] . ((@$m[2] == '.' ) ? '.' : ''); - $ext = @$m[3]; - } - $dir = count($path) ? join('/', $path) : ''; - return array($dir, $file, $ext); - } - - /** - * Tells if a file is readable looking in the include path. - * - * @param string $file Name of the file to look for. - * - * @return bool True if file is readable, false if not. - * - * @access public - * @since rev 122 - */ - function isReadableInclude($file) - { - list($dir, $page, $ext) = File_Util::splitFilename($file); - if (is_readable($file)) { - return true; - } - $include_path = array_unique(preg_split('/:/', ini_get('include_path'))); - foreach ($include_path as $path) { - if (is_readable("$path/$file")) { - return true; - } - } - return false; - } - - /** - * Gets the last modification date/time for a file. - * - * @param string $file Name of the file to get the last modification - * date/time. - * @param string $format Format (see strftime). - * - * @return string Formated string with the last modification - * date/time. - * - * @see strftime() - * @access public - * @since rev 142 - */ - function lastModified($file, $format = '%c') - { - return strftime($format, filemtime($file)); - } - -} - -// This is a workarround to live until PHP 4.3 is out and we can use the -// native get_file_contents() function. We don't care about -// $use_include_file option. -function file_get_contents($file, $use_include_file = false) -{ - if (@is_readable($file)) { - $var = join('', file($file)); - } else { - $var = ''; - } - return $var; -} - -?>