2 // BIFE: Build It FastEr - draft 4
4 require_once 'HTML/Template/Sigma.php';
5 require_once 'Album.php';
9 $template =& new HTML_Template_Sigma('templates');
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 process(&$template) {
74 trigger_error('Method not implemented '.get_class($this).
75 '::addContents().', E_USER_ERROR);
80 class BIFE_Container extends BIFE_Base {
82 function BIFE_Container() {
83 trigger_error('Can\'t instanciate abstract class BIFE_Container.',
87 function addContents($contents) {
88 trigger_error('Method not implemented '.get_class($this).
89 '::addContents().', E_USER_ERROR);
94 class BIFE_Generic extends BIFE_Container {
99 function BIFE_Generic($attrs) {
100 $this->attrs = $attrs;
101 $this->contents = '';
104 function addContents($contents) {
105 $this->contents .= trim($contents);
108 function process(&$template) {
109 $template->loadTemplateFile(get_class($this).'.html');
110 $template->setVariable($this->attrs);
111 $template->setVariable('CONTENTS', $this->contents);
112 return $template->get();
117 class BIFE_Page extends BIFE_Generic {
118 function BIFE_Page($attrs) {
119 $this->BIFE_Generic($attrs);
123 class BIFE_Title extends BIFE_Generic {
124 function BIFE_Title($attrs) {
125 $this->BIFE_Generic($attrs);
129 class BIFE_Album extends BIFE_Base {
131 function BIFE_Album($attrs) {
135 'THUMBSFORMAT' => 'jpeg',
136 'THUMBSDIR' => '.thumbs',
137 'EXTENSIONS' => 'png,jpg,jpeg,gif',
142 $this->attrs = array_merge($defaults, $attrs);
144 function addContents($contents) {
145 trigger_error('BIFE_Album is not a container, you can\'t add contents.',
148 function process(&$template) {
149 extract($this->attrs, EXTR_SKIP);
150 $album =& new Hook_Album($DIR, $RECURSIVE, $THUMBSFORMAT, $THUMBSDIR, $EXTENSIONS);
151 return $album->album($template, $SELECTED, $MAXROWS, $COLUMNS);