X-Git-Url: https://git.llucax.com/software/bife/bife-all.git/blobdiff_plain/a4ee5812869c45aeec7bed6bbfeaf60a981209a8..f42d10f67726bb642ff6a9adbd04f4aeb0af5121:/index.php?ds=sidebyside 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(); ?>