From: Leandro Lucarella Date: Sat, 17 May 2003 05:16:47 +0000 (+0000) Subject: Draft 4 (v0.4): X-Git-Tag: svn_import~58 X-Git-Url: https://git.llucax.com/software/bife/bife-all.git/commitdiff_plain/f42d10f67726bb642ff6a9adbd04f4aeb0af5121?hp=a4ee5812869c45aeec7bed6bbfeaf60a981209a8 Draft 4 (v0.4): * Updated UML diagrams. * Generated classes with xmi2code in separeted files under BIFE directory. * Changed extension of XML files to .xbf. --- diff --git a/BIFE/Album.php b/BIFE/Album.php new file mode 100644 index 0000000..b854b8f --- /dev/null +++ b/BIFE/Album.php @@ -0,0 +1,96 @@ + '.', + 'RECURSIVE' => true, + 'THUMBSFORMAT' => 'jpeg', + 'THUMBSDIR' => '.thumbs', + 'EXTENSIONS' => 'png,jpg,jpeg,gif', + 'SELECTED' => '', + 'MAXROWS' => 0, + 'COLUMNS' => 4, + ); + $this->attrs = array_merge($defaults, $attrs); + } + // -X2C + + // +X2C Operation 23 + /** + * Renders the widget. + * + * @param HTML_Template_Sigma &$template Template to use to render the widget. + * + * @return void + * @access public + */ + function render(&$template) // ~X2C + { + extract($this->attrs, EXTR_SKIP); + $album =& new Hook_Album($DIR, $RECURSIVE, $THUMBSFORMAT, $THUMBSDIR, $EXTENSIONS); + return $album->album($template, $SELECTED, $MAXROWS, $COLUMNS); + } + // -X2C + +} // -X2C Class :Album + +?> diff --git a/BIFE/Container.php b/BIFE/Container.php new file mode 100644 index 0000000..e87f813 --- /dev/null +++ b/BIFE/Container.php @@ -0,0 +1,62 @@ + \ No newline at end of file diff --git a/BIFE/Generic.php b/BIFE/Generic.php new file mode 100644 index 0000000..d10a577 --- /dev/null +++ b/BIFE/Generic.php @@ -0,0 +1,109 @@ + | +// +--------------------------------------------------------------------+ +// +// $Id$ +// + + +// +X2C includes +require_once 'BIFE/Container.php'; +// ~X2C + +// +X2C Class 7 :Generic +/** + * This is a generic and simple BIFE_Container implementation. + * + * @access public + * @abstract + */ +class BIFE_Generic extends BIFE_Container { + /** + * Attribute list. + * + * @var array $attrs + * @access public + */ + var $attrs; + + /** + * @var string $contents + * @access public + */ + var $contents; + + // ~X2C + + // +X2C Operation 10 + /** + * Constructor. + * + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function BIFE_Generic($attrs) // ~X2C + { + $this->attrs = $attrs; + $this->contents = ''; + } + // -X2C + + // +X2C Operation 11 + /** + * Add contents to the widget. + * + * @param string $contents Contents to add. + * + * @return void + * @access public + */ + function addContents($contents) // ~X2C + { + $this->contents .= trim($contents); + } + // -X2C + + // +X2C Operation 12 + /** + * Renders the widget. + * + * @param HTML_Template_Sigma &$template Template to use to render the widget. + * + * @return void + * @access public + */ + function render(&$template) // ~X2C + { + $template->loadTemplateFile(get_class($this).'.html'); + $template->setVariable($this->attrs); + $template->setVariable('CONTENTS', $this->contents); + return $template->get(); + } + // -X2C + +} // -X2C Class :Generic + +?> \ No newline at end of file diff --git a/BIFE/Page.php b/BIFE/Page.php new file mode 100644 index 0000000..d8ef88a --- /dev/null +++ b/BIFE/Page.php @@ -0,0 +1,59 @@ +BIFE_Generic($attrs); + } + // -X2C + +} // -X2C Class :Page + +?> \ No newline at end of file diff --git a/BIFE/Parser.php b/BIFE/Parser.php new file mode 100644 index 0000000..0b85636 --- /dev/null +++ b/BIFE/Parser.php @@ -0,0 +1,253 @@ +__construct($template); + } + // -X2C + + // +X2C Operation 31 + /** + * Constructor. + * + * @param HTML_Template_Sigma &$template Template to use to render the widgets. + * + * @return void + * @access public + */ + function __construct(&$template) // ~X2C + { + $this->stack = array(); + $this->output = ''; + $this->parser = xml_parser_create(); + $this->template =& $template; + xml_set_object($this->parser, $this); + xml_set_element_handler($this->parser, 'startElement', 'endElement'); + xml_set_character_data_handler($this->parser, 'characterData'); + } + // -X2C + + // +X2C Operation 32 + /** + * Destructor. + * + * @return void + * @access public + */ + function __destruct() // ~X2C + { + xml_parser_free($this->parser); + } + // -X2C + + // +X2C Operation 33 + /** + * XML parser start of element handler. + * + * @param resource $parser XML parser resource. + * @param string $name XML tag name. + * @param array $attrs XML tag attributes. + * + * @return void + * @access public + */ + function startElement($parser, $name, $attrs) // ~X2C + { + $class = "BIFE_$name"; + if (!class_exists($class)) { + include_once 'BIFE/' . ucfirst(strtolower($name)) . '.php'; + } + if (class_exists($class)) { + $obj =& new $class($attrs); + if (!is_a($obj, 'bife_widget')) { + trigger_error("Class '$class' is not a BIFE_Widget.", E_USER_WARNING); + } + $this->stack[] =& $obj; + } else { + trigger_error("Class not found '$class'.", E_USER_ERROR); + } + } + // -X2C + + // +X2C Operation 34 + /** + * XML parser end of element handler. + * + * @param resource $parser XML parser resource. + * @param string $name XML tag name. + * + * @return void + * @access public + */ + function endElement($parser, $name) // ~X2C + { + end($this->stack); + $current =& $this->stack[key($this->stack)]; + array_pop($this->stack); + end($this->stack); + $parent =& $this->stack[key($this->stack)]; + if ($parent) { + $parent->addContents($current->render($this->template)); + } else { + $this->output = $current->render($this->template); + } + } + // -X2C + + // +X2C Operation 35 + /** + * XML parser character data handler. + * + * @param resource $parser XML parser resource. + * @param string $data XML character data. + * + * @return void + * @access public + */ + function characterData($parser, $data) // ~X2C + { + end($this->stack); + $current =& $this->stack[key($this->stack)]; + $current->addContents($data); + } + // -X2C + + // +X2C Operation 36 + /** + * Parse a string with XML data. + * + * @param string $data XML string to parse. + * @param bool $final Indicates if is the last string to parse. + * + * @return void + * @access public + */ + function parse($data, $final = true) // ~X2C + { + if (!xml_parse($this->parser, $data, $final)) { + trigger_error( + sprintf('XML error: %s at line %d.', + xml_error_string(xml_get_error_code($this->parser)), + xml_get_current_line_number($this->parser) + ), + E_USER_WARNING + ); + } + } + // -X2C + + // +X2C Operation 37 + /** + * Parse a XML file returning the rendered output. + * + * @param string $filename Filename to parse. + * + * @return void + * @access public + */ + function parseFile($filename) // ~X2C + { + if ($fp = @fopen($filename, "r")) { + while ($data = fread($fp, 4096)) { + $this->parse($data, feof($fp)); + } + } else { + trigger_error("Could not open BIFE XML input file '$filename'.", + E_USER_WARNING); + } + fclose($fp); + } + // -X2C + + // +X2C Operation 38 + /** + * Get rendered output. + * + * @return string + * @access public + */ + function getOutput() // ~X2C + { + return $this->output; + } + // -X2C + +} // -X2C Class :Parser + +?> diff --git a/BIFE/Title.php b/BIFE/Title.php new file mode 100644 index 0000000..68a0538 --- /dev/null +++ b/BIFE/Title.php @@ -0,0 +1,59 @@ +BIFE_Generic($attrs); + } + // -X2C + +} // -X2C Class :Title + +?> \ No newline at end of file diff --git a/BIFE/Widget.php b/BIFE/Widget.php new file mode 100644 index 0000000..36fe7d5 --- /dev/null +++ b/BIFE/Widget.php @@ -0,0 +1,60 @@ + \ No newline at end of file diff --git a/bife.xmi b/bife.xmi index ca1e6c1..120fc01 100644 --- a/bife.xmi +++ b/bife.xmi @@ -9,7 +9,7 @@ - + - + @@ -36,8 +34,8 @@ This is a widget that can contain data (and other widgets too)." name="Container - - + + @@ -58,14 +56,48 @@ This is a widget that can contain data (and other widgets too)." name="Container - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + @@ -75,14 +107,14 @@ This is a widget that can contain data (and other widgets too)." name="Container - + - + @@ -105,35 +137,65 @@ This is a widget that can contain data (and other widgets too)." name="Container + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + - diff --git a/index.php b/index.php index aabb4e9..8451d92 100644 --- a/index.php +++ b/index.php @@ -2,156 +2,20 @@ // BIFE: Build It FastEr - draft 4 require_once 'HTML/Template/Sigma.php'; -require_once 'Album.php'; +require_once 'BIFE/Parser.php'; +require_once 'BIFE/Page.php'; +require_once 'BIFE/Title.php'; +require_once 'BIFE/Album.php'; +#require_once 'BIFE.php'; -$file = "simple.xml"; +$file = "simple.xbf"; $template =& new HTML_Template_Sigma('templates'); $template->setErrorHandling(PEAR_ERROR_PRINT); -$output = ''; -$stack = array(); - -function startElement($parser, $name, $attrs) { - global $stack; - $class = "BIFE_$name"; - if (class_exists($class)) { - $obj =& new $class($attrs); - if (!is_a($obj, 'bife_base')) { - trigger_error("Class '$class' is not a BIFE_Base.", E_USER_WARNING); - } - $stack[] =& $obj; - } else { - trigger_error("Class not found '$class'.", E_USER_ERROR); - } -} - -function endElement($parser, $name) { - global $stack, $template, $output; - end($stack); - $current =& $stack[key($stack)]; - array_pop($stack); - end($stack); - $parent =& $stack[key($stack)]; - if ($parent) { - $parent->addContents($current->process($template)); - } else { - $output = $current->process($template); - } -} - -function characterData($parser, $data) { - global $stack; - end($stack); - $current =& $stack[key($stack)]; - $current->addContents($data); -} - -$xml_parser = xml_parser_create(); -xml_set_element_handler($xml_parser, "startElement", "endElement"); -xml_set_character_data_handler($xml_parser, "characterData"); -if (!($fp = @fopen($file, "r"))) { - die("could not open XML input\n"); -} - -while ($data = fread($fp, 4096)) { - if (!xml_parse($xml_parser, $data, feof($fp))) { - die(sprintf("XML error: %s at line %d\n", - xml_error_string(xml_get_error_code($xml_parser)), - xml_get_current_line_number($xml_parser))); - } -} -xml_parser_free($xml_parser); - -class BIFE_Base { - - function BIFE_Base() { - trigger_error('Can\'t instanciate abstract class BIFE_Base.', - E_USER_ERROR); - } - - function process(&$template) { - trigger_error('Method not implemented '.get_class($this). - '::addContents().', E_USER_ERROR); - } - -} - -class BIFE_Container extends BIFE_Base { - - function BIFE_Container() { - trigger_error('Can\'t instanciate abstract class BIFE_Container.', - E_USER_ERROR); - } - - function addContents($contents) { - trigger_error('Method not implemented '.get_class($this). - '::addContents().', E_USER_ERROR); - } - -} - -class BIFE_Generic extends BIFE_Container { - - var $attrs; - var $contents; - - function BIFE_Generic($attrs) { - $this->attrs = $attrs; - $this->contents = ''; - } - - function addContents($contents) { - $this->contents .= trim($contents); - } - - function process(&$template) { - $template->loadTemplateFile(get_class($this).'.html'); - $template->setVariable($this->attrs); - $template->setVariable('CONTENTS', $this->contents); - return $template->get(); - } - -} - -class BIFE_Page extends BIFE_Generic { - function BIFE_Page($attrs) { - $this->BIFE_Generic($attrs); - } -} - -class BIFE_Title extends BIFE_Generic { - function BIFE_Title($attrs) { - $this->BIFE_Generic($attrs); - } -} - -class BIFE_Album extends BIFE_Base { - var $attrs; - function BIFE_Album($attrs) { - $defaults = array( - 'DIR' => '.', - 'RECURSIVE' => true, - 'THUMBSFORMAT' => 'jpeg', - 'THUMBSDIR' => '.thumbs', - 'EXTENSIONS' => 'png,jpg,jpeg,gif', - 'SELECTED' => '', - 'MAXROWS' => 0, - 'COLUMNS' => 4, - ); - $this->attrs = array_merge($defaults, $attrs); - } - function addContents($contents) { - trigger_error('BIFE_Album is not a container, you can\'t add contents.', - E_USER_ERROR); - } - function process(&$template) { - extract($this->attrs, EXTR_SKIP); - $album =& new Hook_Album($DIR, $RECURSIVE, $THUMBSFORMAT, $THUMBSDIR, $EXTENSIONS); - return $album->album($template, $SELECTED, $MAXROWS, $COLUMNS); - } -} - -echo $output; +$parser =& new BIFE_Parser($template); +$parser->parseFile($file); +echo $parser->getOutput(); +$parser->__destruct(); ?> diff --git a/simple.xml b/simple.xbf similarity index 53% rename from simple.xml rename to simple.xbf index 8a2fbf2..bbf267a 100644 --- a/simple.xml +++ b/simple.xbf @@ -1,4 +1,5 @@ + Datos! - + diff --git a/photo.html b/templates/photo.html similarity index 100% rename from photo.html rename to templates/photo.html