2 // BIFE: Build It FastEr - draft 2
4 require_once 'HTML/Template/Sigma.php';
5 require_once 'Album.php';
9 $template =& new HTML_Template_Sigma('.');
10 $template->setErrorHandling(PEAR_ERROR_PRINT);
15 function startElement($parser, $name, $attrs) {
17 $class = "BIFE_$name";
18 if (class_exists($class)) {
19 $obj =& new $class($attrs);
20 if (!is_a($obj, 'bife_base')) {
21 trigger_error("Class '$class' is not a BIFE_Base.", E_USER_WARNING);
25 trigger_error("Class not found '$class'.", E_USER_ERROR);
29 function endElement($parser, $name) {
30 global $stack, $template, $output;
32 $current =& $stack[key($stack)];
35 $parent =& $stack[key($stack)];
37 $parent->addContents($current->process($template));
39 $output = $current->process($template);
43 function characterData($parser, $data) {
46 $current =& $stack[key($stack)];
47 $current->addContents($data);
50 $xml_parser = xml_parser_create();
51 xml_set_element_handler($xml_parser, "startElement", "endElement");
52 xml_set_character_data_handler($xml_parser, "characterData");
53 if (!($fp = @fopen($file, "r"))) {
54 die("could not open XML input\n");
57 while ($data = fread($fp, 4096)) {
58 if (!xml_parse($xml_parser, $data, feof($fp))) {
59 die(sprintf("XML error: %s at line %d\n",
60 xml_error_string(xml_get_error_code($xml_parser)),
61 xml_get_current_line_number($xml_parser)));
64 xml_parser_free($xml_parser);
68 function BIFE_Base() {
69 trigger_error('Can\'t instanciate abstract class BIFE_Base.',
73 function addContents($contents) {
74 trigger_error('Method not implemented '.get_class($this).
75 '::addContents().', E_USER_ERROR);
78 function process(&$template) {
79 trigger_error('Method not implemented '.get_class($this).
80 '::addContents().', E_USER_ERROR);
85 class BIFE_Common extends BIFE_Base {
90 function BIFE_Common($attrs) {
91 $this->attrs = $attrs;
95 function addContents($contents) {
96 $this->contents .= trim($contents);
99 function process(&$template) {
100 $template->loadTemplateFile(get_class($this).'.html');
101 $template->setVariable($this->attrs);
102 $template->setVariable('CONTENTS', $this->contents);
103 return $template->get();
108 class BIFE_Page extends BIFE_Common {
109 function BIFE_Page($attrs) {
110 $this->BIFE_Common($attrs);
114 class BIFE_Title extends BIFE_Common {
115 function BIFE_Title($attrs) {
116 $this->BIFE_Common($attrs);
120 class BIFE_Album extends BIFE_Base {
122 function BIFE_Album($attrs) {
126 'THUMBSFORMAT' => 'jpeg',
127 'THUMBSDIR' => '.thumbs',
128 'EXTENSIONS' => 'png,jpg,jpeg,gif',
133 $this->attrs = array_merge($defaults, $attrs);
135 function addContents($contents) {
136 trigger_error('BIFE_Album is not a container, you can\'t add contents.',
139 function process(&$template) {
140 extract($this->attrs, EXTR_SKIP);
141 $album =& new Hook_Album($DIR, $RECURSIVE, $THUMBSFORMAT, $THUMBSDIR, $EXTENSIONS);
142 return $album->album($template, $SELECTED, $MAXROWS, $COLUMNS);