From ae05ddb416c0914bda78e992216286848566da88 Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Wed, 2 Jul 2003 05:44:34 +0000 Subject: [PATCH] - Added @package to classes. - Added 'provides' to package.xml. - Setted svn:ignore to api directories. - Updated HIT documentation. --- BIFE/Container.php | 98 +++++++++++++++ BIFE/Fallback.php | 87 +++++++++++++ BIFE/Link.php | 126 +++++++++++++++++++ BIFE/Parser.php | 306 +++++++++++++++++++++++++++++++++++++++++++++ BIFE/Translate.php | 3 +- BIFE/Widget.php | 97 ++++++++++++++ package.xml | 54 ++++++++ 7 files changed, 770 insertions(+), 1 deletion(-) create mode 100644 BIFE/Container.php create mode 100644 BIFE/Fallback.php create mode 100644 BIFE/Link.php create mode 100644 BIFE/Parser.php create mode 100644 BIFE/Widget.php create mode 100644 package.xml diff --git a/BIFE/Container.php b/BIFE/Container.php new file mode 100644 index 0000000..8585061 --- /dev/null +++ b/BIFE/Container.php @@ -0,0 +1,98 @@ + | +// +--------------------------------------------------------------------+ +// +// $Id$ +// + +// +X2C includes +require_once 'BIFE/Widget.php'; +// ~X2C + +// +X2C Class 5 :Container +/** + * Base container widget class. + * + * @package BIFE + * @access public + * @abstract + */ +class BIFE_Container extends BIFE_Widget { + /** + * Widget contents. + * + * @var array $contents + * @access public + */ + var $contents = array(); + + // ~X2C + + // +X2C Operation 6 + /** + * Adds contents to the container. + * + * @param mixed &$contents Contents to add to the container. + * + * @return void + * @access public + */ + function addContents(&$contents) // ~X2C + { + if (is_object($contents)) { + $this->contents[] =& $contents; + } else { + $this->contents[] = $contents; + } + } + // -X2C + + // +X2C Operation 59 + /** + * Renders the widget using a template returning a string with the results. + * + * @param HTML_Template_HIT &$template Template object to render the widget. + * + * @return string + * @access public + */ + function renderContents(&$template) // ~X2C + { + $c = count($this->contents); + $o = ''; + for ($i = 0; $i < $c; $i++) { + if (is_object($this->contents[$i])) { + $o .= $this->contents[$i]->render($template); + } else { + $o .= $this->contents[$i]; + } + } + return $o; + } + // -X2C + + +} // -X2C Class :Container + +?> \ No newline at end of file diff --git a/BIFE/Fallback.php b/BIFE/Fallback.php new file mode 100644 index 0000000..f4e98b8 --- /dev/null +++ b/BIFE/Fallback.php @@ -0,0 +1,87 @@ + | +// +--------------------------------------------------------------------+ +// +// $Id$ +// + +// +X2C includes +require_once 'BIFE/Container.php'; +// ~X2C + +// +X2C Class 61 :Fallback +/** + * Fallback widget to use when no specific widget is implemented. + * + * @package BIFE + * @access public + * @abstract + */ +class BIFE_Fallback extends BIFE_Container { + /** + * Name of the widget. + * + * @var string $name + * @access private + */ + var $name = ''; + + // ~X2C + + // +X2C Operation 62 + /** + * Constructor. + * + * @param string $name Name of the widget to draw. + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function BIFE_Fallback($name, $attrs) // ~X2C + { + $this->__construct($name, $attrs); + } + // -X2C + + // +X2C Operation 63 + /** + * Constructor. + * + * @param string $name Name of the widget. + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function __construct($name, $attrs) // ~X2C + { + parent::__construct($attrs); + $this->name = strtolower(strtr($name, ':', '_')); + } + // -X2C + +} // -X2C Class :Fallback + +?> \ No newline at end of file diff --git a/BIFE/Link.php b/BIFE/Link.php new file mode 100644 index 0000000..8204db0 --- /dev/null +++ b/BIFE/Link.php @@ -0,0 +1,126 @@ + | +// +--------------------------------------------------------------------+ +// +// $Id$ +// + +// +X2C includes +require_once 'BIFE/Container.php'; +// ~X2C + +// +X2C Class 110 :Link +/** + * Link to another page. + * + * @package BIFE + * @access public + */ +class BIFE_Link extends BIFE_Container { + // ~X2C + + // +X2C Operation 111 + /** + * Constructor. + * + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function BIFE_Link($attrs) // ~X2C + { + $this->__construct($attrs); + } + // -X2C + + // +X2C Operation 112 + /** + * Constructor. + * + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function __construct($attrs) // ~X2C + { + $link_attrs['URL'] = $this->getURL($attrs); + $link_attrs['DESC'] = @$attrs['DESC']; + $link_attrs['TARGET'] = @$attrs['TARGET']; + parent::__construct($link_attrs); + } + // -X2C + + // +X2C Operation 142 + /** + * Gets a URL string based on Link attributes. + * + * @param array $attrs Link attributes. + * + * @return string + * @access public + */ + function getURL($attrs) // ~X2C + { + $url = @$attrs['URL']; + unset($attrs['URL']); + if (isset($attrs['BIFE'])) { + $attrs['DATA-BIFE'] = $attrs['BIFE']; + unset($attrs['BIFE']); + } + $query = array(); + foreach($attrs as $name => $value) { + if (substr($name, 0, 5) === 'DATA-') { + if ($name = substr($name, 5)) { + $query[] = urlencode($name) . '=' . urlencode($value); + } + } + } + if ($query) { + $url .= '?' . join('&', $query); + } + return $url; + } + // -X2C + + // +X2C Operation 157 + /** + * Renders the widget. + * + * @param HTML_Template_HIT &$template Template to use to render the widget. + * + * @return string + * @access public + */ + function render(&$template) // ~X2C + { + $this->attrs['CONTENTS'] = $this->renderContents($template); + return $template->parse('bife_link', $this->attrs, '', ''); + } + // -X2C + +} // -X2C Class :Link + +?> \ No newline at end of file diff --git a/BIFE/Parser.php b/BIFE/Parser.php new file mode 100644 index 0000000..ee35bfc --- /dev/null +++ b/BIFE/Parser.php @@ -0,0 +1,306 @@ + | +// +--------------------------------------------------------------------+ +// +// $Id$ +// + +// +X2C Class 25 :Parser +/** + * This is the XML Parser. + * + * @package BIFE + * @access public + */ +class BIFE_Parser { + /** + * Top level widget. + * + * @var BIFE_Widget $root + * @access protected + */ + var $root = null; + + /** + * XML parser resource. + * + * @var resource $parser + * @access protected + */ + var $parser = null; + + /** + * BIFE widgets stack. + * + * @var array $stack + * @access protected + */ + var $stack = array(); + + /** + * Fallback class to use in case that a widget class is not found. + * + * @var string $fallback + * @access protected + */ + var $fallback = ''; + + /** + * XML cache directory. Empty if no cahching must be done (for current dir use '.'). + * + * @var string $cache + * @access protected + */ + var $cache = '/tmp'; + + /** + * Files required by the parsed XML file. + * + * @var array $requires + * @access protected + */ + var $requires = array(); + + // ~X2C + + // +X2C Operation 30 + /** + * Constructor. + * + * @param string $fallback Fallback class name (none if empty). + * @param string $cache XML cache directory. Empty is no caching will be done. + * + * @return void + * @access public + */ + function BIFE_Parser($fallback = '', $cache = '/tmp') // ~X2C + { + $this->__construct($fallback, $cache); + } + // -X2C + + // +X2C Operation 31 + /** + * Constructor. + * + * @param string $fallback Fallback class name (none if empty). + * @param string $cache XML cache directory. Empty is no caching will be done. + * + * @return void + * @access public + */ + function __construct($fallback = '', $cache = '/tmp') // ~X2C + { + $this->parser = xml_parser_create(); + $this->fallback = $fallback; + $this->cache = $cache; + 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_' . strtolower(strtr($name, ':', '_')); + if (!class_exists($class)) { + $inc = 'BIFE/' . + strtr(ucwords(strtr(strtolower($name), ':', ' ')), ' ', '/') . + '.php'; + if (@include_once $inc) { + $this->includes[] = $inc; + } + } + if (class_exists($class)) { + $obj =& new $class($attrs); + // XXX - Does this check make sense? + if (!is_a($obj, 'bife_widget')) { + trigger_error("Class '$class' is not a BIFE_Widget.", E_USER_WARNING); + } + $this->stack[] =& $obj; + } else { + if ($this->fallback) { + $class = $this->fallback; + $obj =& new $class($name, $attrs); + if (!is_a($obj, 'bife_fallback')) { + trigger_error("Class '$class' is not a BIFE_Fallback.", 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); + } else { + $this->root =& $current; + } + } + // -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 with a complete and valid XML document. + * + * @param string $filename Filename to parse. + * + * @return &BIFE_Widget + * @access public + */ + function &parseFile($filename) // ~X2C + { + if ($this->cache) { + $cache = $this->cache . '/' . 'bife_parser_cache' . strtr(realpath($filename), '/', '_'); + if (@filemtime($cache) > @filemtime($filename)) { + $file = file($cache); + foreach(unserialize(trim(array_shift($file))) as $required) { + include_once $required; + } + return unserialize(join('', $file)); + } + } + 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); + if ($this->cache) { + $fp = fopen($cache, 'w'); + fputs($fp, serialize($this->includes) . "\n"); + fputs($fp, serialize($this->root)); + fclose($fp); + } + return $this->root; + } + // -X2C + + // +X2C Operation 74 + /** + * Parse a XML string with a complete and valid XML document. + * + * @param string $data XML data to parse. + * + * @return &BIFE_Widget + * @access public + */ + function &parseString($data) // ~X2C + { + $this->parse($data, true); + return $this->root; + } + // -X2C + +} // -X2C Class :Parser + +?> \ No newline at end of file diff --git a/BIFE/Translate.php b/BIFE/Translate.php index 83cd535..4c1fe05 100644 --- a/BIFE/Translate.php +++ b/BIFE/Translate.php @@ -34,6 +34,7 @@ require_once 'BIFE/Fallback.php'; /** * This is a generic and simple (but very usefull) BIFE_Fallback implementation. Translate widgets using a template with it's name, prepended with 'bife_'. If not template is found, it copy the XML to the output. * + * @package BIFE * @access public */ class BIFE_Translate extends BIFE_Fallback { @@ -73,4 +74,4 @@ class BIFE_Translate extends BIFE_Fallback { } // -X2C Class :Translate -?> +?> \ No newline at end of file diff --git a/BIFE/Widget.php b/BIFE/Widget.php new file mode 100644 index 0000000..57860cd --- /dev/null +++ b/BIFE/Widget.php @@ -0,0 +1,97 @@ + | +// +--------------------------------------------------------------------+ +// +// $Id$ +// + +// +X2C Class 3 :Widget +/** + * Base widget class. + * + * @package BIFE + * @access public + * @abstract + */ +class BIFE_Widget { + /** + * Attribute list. + * + * @var array $attrs + * @access protected + */ + var $attrs = array(); + + // ~X2C + + // +X2C Operation 126 + /** + * Constructor. + * + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function BIFE_Widget($attrs) // ~X2C + { + $this->__construct($attrs); + } + // -X2C + + // +X2C Operation 127 + /** + * Constructor. + * + * @param array $attrs Attributes. + * + * @return void + * @access public + */ + function __construct($attrs) // ~X2C + { + $this->attrs = $attrs; + } + // -X2C + + // +X2C Operation 4 + /** + * Renders the widget using a template returning a string with the results. + * + * @param HTML_Template_HIT &$template Template object to render the widget. + * + * @return string + * @access public + * @abstract + */ + function render(&$template) // ~X2C + { + trigger_error('Method not implemented '.get_class($this). + '::render().', E_USER_ERROR); + } + // -X2C + +} // -X2C Class :Widget + +?> \ No newline at end of file diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..1f9f3e5 --- /dev/null +++ b/package.xml @@ -0,0 +1,54 @@ + + + + BIFE + Build It FastEr + BIFE - Build It FastEr: +BIFE is a framwork to separate the logic, contents and looks of a PHP +application, inspired on BIF (Buil It Fast) but with speed and simplicity +in mind. One of the main goals of BIFE is to be fast. + + GPL + + + luca + Leandro Lucarella + luca@lugmen.org.ar + lead + + + + + 0.11 + 2003-06-29 + alpha + Check http://www.llucax.hn.org/desarrollo/bife/ for details. + + + + + + + + + BIFE/Parser.php + BIFE/Widget.php + BIFE/Container.php + BIFE/Fallback.php + BIFE/Link.php + BIFE/Translate.php + + README + ROADMAP + examples/index.php + examples/index.xbf + examples/templates/bife_page.tpl.html + examples/templates/bife_title.tpl.html + examples/templates/bife_link.tpl.html + + + + 4.2.3 + HTML_Template_HIT + + -- 2.43.0