From: Leandro Lucarella Date: Thu, 22 May 2003 04:31:40 +0000 (+0000) Subject: - Implemented Fallback class in the Parser. X-Git-Tag: svn_import~52 X-Git-Url: https://git.llucax.com/software/bife/bife-all.git/commitdiff_plain/537561c5709c3f574c5d406cb4cb28b3522f2566 - Implemented Fallback class in the Parser. - Added a simple Fallback class implementation, Copy, that copy the XML structure to the rendered output. - Minor bugfixes. - Updated example to use Copy Fallback class. --- diff --git a/Makefile b/Makefile index f9c68d3..808da6b 100644 --- a/Makefile +++ b/Makefile @@ -42,3 +42,6 @@ clean-doc: rm -fvR doc/api/html doc/api/rtf doc/api/latex clean: clean-doc clean-backup + +tarball: + tar --exclude bife/doxygen.warn --exclude .svn --exclude .bak --exclude .swp --exclude 'bife/doc/api/*' -C .. -cvzf ../bife.tar.gz bife diff --git a/doc/bife.xmi b/doc/bife.xmi index d2bb8fd..ece1275 100644 --- a/doc/bife.xmi +++ b/doc/bife.xmi @@ -5,11 +5,11 @@ umbrello uml modeller http://uml.sf.net 1.1 - + - + @@ -73,8 +73,12 @@ - - + + + + + + @@ -101,8 +105,8 @@ - + @@ -114,62 +118,84 @@ + + + + + + + + + + + + + + + - + - - - - - - - + + + + + + + + - - + + - - + + - - + + - - + + - - + + - - + + + + + + + + - - + + @@ -188,14 +214,14 @@ - + + - @@ -213,6 +239,13 @@ + + + + + + + diff --git a/examples/index.php b/examples/index.php index 18f9ce3..cd198be 100644 --- a/examples/index.php +++ b/examples/index.php @@ -32,6 +32,7 @@ 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'; @@ -42,7 +43,7 @@ $file = 'simple.xbf'; $template =& new HTML_Template_Sigma('templates'); $template->setErrorHandling(PEAR_ERROR_PRINT); -$parser =& new BIFE_Parser($template); +$parser =& new BIFE_Parser('BIFE_Copy'); $page =& $parser->parseFile($file); $parser->__destruct(); echo $page->render($template); diff --git a/examples/simple.xbf b/examples/simple.xbf index fe44fa3..e3dcd89 100644 --- a/examples/simple.xbf +++ b/examples/simple.xbf @@ -1,5 +1,7 @@ Datos! +

Photo album

+
diff --git a/src/Album.php b/src/Album.php index 5cb8c8d..24c0826 100644 --- a/src/Album.php +++ b/src/Album.php @@ -176,7 +176,7 @@ class Hook_Album { $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)) { + if (!@is_dir($path) and !@mkdir($path)) { return false; } if (PEAR::isError($img)) { diff --git a/src/BIFE/Copy.php b/src/BIFE/Copy.php new file mode 100644 index 0000000..1d39031 --- /dev/null +++ b/src/BIFE/Copy.php @@ -0,0 +1,119 @@ + | +// +--------------------------------------------------------------------+ +// +// $Id$ +// + +// +X2C includes +require_once 'BIFE/Fallback.php'; +// ~X2C + +// +X2C Class 76 :Copy +/** + * Fallback widget that copies the XML. + * + * @access public + */ +class BIFE_Copy extends BIFE_Fallback { + /** + * Widget name. + * + * @var string $name + * @access public + */ + var $name; + + /** + * Attributes. + * + * @var array $attrs + * @access public + */ + var $attrs; + + // ~X2C + + // +X2C Operation 79 + /** + * Constructor. + * + * @param string $name Widget name. + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function BIFE_Copy($name, $attrs) // ~X2C + { + $this->__construct($name, $attrs); + } + // -X2C + + // +X2C Operation 80 + /** + * Constructor. + * + * @param string $name Widget name. + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function __construct($name, $attrs) // ~X2C + { + $this->name = $name; + $this->attrs = $attrs; + } + // -X2C + + // +X2C Operation 82 + /** + * Renders the widget returning a string with the results. + * + * @param HTML_Template_Sigma &$template Template to use to render the widget. + * + * @return void + * @access public + */ + function render(&$template) // ~X2C + { + $name = $this->name; + $ret = "<$name"; + foreach ($this->attrs as $attr => $val) { + $ret .= sprintf(' %s="%s"', $attr, $val); + } + $contents = parent::render($template); + if ($contents) { + $ret .= ">$contents"; + } else { + $ret .= "/>"; + } + return $ret; + } + // -X2C + +} // -X2C Class :Copy + +?> diff --git a/src/BIFE/Parser.php b/src/BIFE/Parser.php index 78ab5b0..bf96326 100644 --- a/src/BIFE/Parser.php +++ b/src/BIFE/Parser.php @@ -50,20 +50,18 @@ class BIFE_Parser { var $parser; /** - * Template to use to render the parsed file. + * BIFE widgets stack. * - * @var HTML_Template_Sigma $template + * @var array $stack * @access public */ - var $template; + var $stack; /** - * BIFE widgets stack. - * - * @var array $stack + * @var string $fallback * @access public */ - var $stack; + var $fallback; // ~X2C @@ -71,12 +69,14 @@ class BIFE_Parser { /** * Constructor. * + * @param string $fallback Fallback class name (none if empty). + * * @return void * @access public */ - function BIFE_Parser() // ~X2C + function BIFE_Parser($fallback = '') // ~X2C { - $this->__construct($template); + $this->__construct($fallback); } // -X2C @@ -84,15 +84,17 @@ class BIFE_Parser { /** * Constructor. * + * @param string $fallback Fallback class name (none if empty). + * * @return void * @access public */ - function __construct() // ~X2C + function __construct($fallback = '') // ~X2C { $this->stack = array(); $this->root = null; $this->parser = xml_parser_create(); - $this->template =& $template; + $this->fallback = $fallback; xml_set_object($this->parser, $this); xml_set_element_handler($this->parser, 'startElement', 'endElement'); xml_set_character_data_handler($this->parser, 'characterData'); @@ -127,7 +129,7 @@ class BIFE_Parser { { $class = "BIFE_$name"; if (!class_exists($class)) { - include_once 'BIFE/' . ucfirst(strtolower($name)) . '.php'; + @include_once 'BIFE/' . ucfirst(strtolower($name)) . '.php'; } if (class_exists($class)) { $obj =& new $class($attrs); @@ -136,7 +138,16 @@ class BIFE_Parser { } $this->stack[] =& $obj; } else { - trigger_error("Class not found '$class'.", E_USER_ERROR); + if ($this->fallback) { + $class = $this->fallback; + $obj =& new $class($name, $attrs); + if (!is_a($obj, 'bife_fallback')) { + trigger_error("Class '$class' is not a BIFE_Fallback.", E_USER_WARNING); + } + $this->stack[] =& $obj; + } else { + trigger_error("Class not found '$class'.", E_USER_ERROR); + } } } // -X2C