-$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;