From f7c338b4101e33b99004a8e996ef2d24d2fe47e8 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Mon, 18 Dec 2006 07:45:41 +0000 Subject: [PATCH] Adding a bunch of new Printer stuff that I'm not sure works quite yet --- PrinterBaseElement.php | 168 +++++++++++++++++++++++++++++++ PrinterElement.php | 107 ++++++++++++++++++++ PrinterRootElement.php | 85 ++++++++++++++++ PrinterRootElementPage.php | 193 ++++++++++++++++++++++++++++++++++++ PrinterRootElementTable.php | 137 +++++++++++++++++++++++++ PrinterTableElement.php | 146 +++++++++++++++++++++++++++ 6 files changed, 836 insertions(+) create mode 100644 PrinterBaseElement.php create mode 100644 PrinterElement.php create mode 100644 PrinterRootElement.php create mode 100644 PrinterRootElementPage.php create mode 100644 PrinterRootElementTable.php create mode 100644 PrinterTableElement.php diff --git a/PrinterBaseElement.php b/PrinterBaseElement.php new file mode 100644 index 0000000..61ace8a --- /dev/null +++ b/PrinterBaseElement.php @@ -0,0 +1,168 @@ +setParent($parent); + $this->type = $type; + $this->name = $name; + $this->value = $value; + } + + // ################################################################### + /** + * Sets the parent element + * + * @param BSPrinterElement The parent + */ + public function setParent(BSPrinterElement $parent) + { + $this->parent = $parent; + $this->parent->addChild($this); + } + + // ################################################################### + /** + * Returns the parent element + * + * @return BSPrinterElement The parent element + */ + public function getParent() + { + return $this->parent; + } + + // ################################################################### + /** + * If the type is either checkbox, radio, or option then this will + * set the selected/checked attribute + * + * @param boolean Active? + */ + public function setActive($active) + { + if (!in_array($this->type, array('checkbox', 'radio', 'option'))) + { + trigger_error('PrinterBaseElement::setActive() can only be used on elements of type checkbox, radio, or option'); + } + $this->active = $active; + } + + // ################################################################### + /** + * Returns the output HTML + * + * @return string Output HTML + */ + public function paint() + { + $name = ' name="' . $this->name . '"'; + $style = ($this->_prepareStyle() ? ' style="' . $this->_prepareStyle() . '"' : ''); + $value = ($this->value ? ' value="' . $this->value . '"' : ''); + switch ($this->type) + { + case 'text': + case 'password': + case 'button': + case 'submit': + case 'reset': + return ''; + break; + + case 'checkbox': + case 'radio': + return 'active ? ' checked="checked"' : '') . $style . ' />'; + break; + + case 'option': + return 'active ? ' selected="selected"' : '') . $style . '>' . $this->name . ''; + break; + + default: + trigger_error('Invalid PrinterBaseElement type "' . $this->type . '"'); + break; + } + } +} + +/*=====================================================================* +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/PrinterElement.php b/PrinterElement.php new file mode 100644 index 0000000..ad1a5e1 --- /dev/null +++ b/PrinterElement.php @@ -0,0 +1,107 @@ +style = $attributes; + } + + // ################################################################### + /** + * Returns a string of CSS style attributes + * + * @return string CSS attributes + */ + protected function _prepareStyle() + { + if (empty($this->style)) + { + return; + } + + $attrs = array(); + + foreach ($this->style AS $prop => $value) + { + $attrs[] = $prop . ': ' . $value; + } + + return explode('; ', $attrs); + } +} + +/*=====================================================================* +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/PrinterRootElement.php b/PrinterRootElement.php new file mode 100644 index 0000000..f143f68 --- /dev/null +++ b/PrinterRootElement.php @@ -0,0 +1,85 @@ +printer = $printer; + } + + /** + * Returns all of the children painted in the right order + */ + protected abstract function _paintChildren(); + + // ################################################################### + /** + * Adds a child node to the element + * + * @param BSPrinterElement A child element + */ + public function addChild(BSPrinterElement $child) + { + $this->children[] = $child; + } +} + +/*=====================================================================* +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/PrinterRootElementPage.php b/PrinterRootElementPage.php new file mode 100644 index 0000000..ef89541 --- /dev/null +++ b/PrinterRootElementPage.php @@ -0,0 +1,193 @@ +, 'direction' =>, 'charset' =>) + * @var array + */ + private $language = array('langcode' => 'en_US', 'direction' => 'ltr', 'charset' => 'utf-8'); + + /** + * The CSS stylesheet + * @var string + */ + private $stylesheet; + + /** + * Constructor + * + * @param BSPrinter Printer object + * @param string Page title + */ + function __construct($printer, $title) + { + $this->title = $title; + parent::__construct($printer); + } + + // ################################################################### + /** + * Sets the language array information + * + * @param array Language array + */ + public function setLanguageInformation($lang) + { + $this->language = $lang; + } + + // ################################################################### + /** + * Sets the path to the CSS style sheet + * + * @param string Path + */ + public function setStylesheet($stylesheet) + { + $this->stylesheet = $stylesheet; + } + + // ################################################################### + /** + * Sets the parent element + */ + public function setParent(BSPrinterElement $parent) + { + trigger_error('Cannot set the parent element on a BSPrinterRootElement'); + } + + // ################################################################### + /** + * Gets the parent element (none exist as this is the root element) + */ + public function getParent() + { + return null; + } + + // ################################################################### + /** + * Returns the HTML for all printed children elements + * + * @return string Printed HTML + */ + protected function _paintChildren() + { + $builder = ''; + + foreach ($this->children AS $child) + { + $this->builder .= "\n" . $child->paint() . "\n"; + } + + return $this->builder; + } + + // ################################################################### + /** + * Tells the element to paint itself (and any children) + */ + public function paint() + { + $this->printer->paint("\n"); + $this->printer->paint("language['langcode'] . "\" lang=\"" . $this->language['langcode'] . "\" dir=\"" . $this->language['direction'] . "\">\n"); + $this->printer->paint("\n\t" . sprintf(_('%1$s - %2$s'), BSRegister::GetApplication(), $this->title) . ""); + $this->printer->paint("\n\t"); + $this->printer->paint("\n\tstylesheet . "\" />"); + // echo $this->code; + $this->printer->paint("\n\n\n"); + + if (BSRegister::GetType('PrinterNavigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR (defined('ISSO_PRINTER_NO_NAVIGATION') AND constant('ISSO_PRINTER_NO_NAVIGATION') != true))) + { + echo BSRegister::GetType('PrinterNavigation')->generate_header_html(); + } + + $this->printer->paint($this->_paintChildren()); + + if (BSRegister::GetDebug() AND isset($_GET['query'])) + { + ob_clean(); + ob_end_clean(); + + if (is_array($this->registry->modules[ISSO_DB_LAYER]->history)) + { + foreach ($this->registry->modules[ISSO_DB_LAYER]->history AS $query) + { + echo $this->registry->modules[ISSO_DB_LAYER]->construct_query_debug($query); + } + } + exit; + } + + if (BSRegister::GetType('PrinterNavigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR (defined('ISSO_PRINTER_NO_NAVIGATION') AND constant('ISSO_PRINTER_NO_NAVIGATION') != true))) + { + echo BSRegister::GetType('PrinterNavigation')->generate_footer_html(); + } + + $copyright = "\n
\n

\n\t" . BSRegister::GetApplication() . ' ' . BSRegister::GetAppVersion() . ", ©2002 - " . gmdate('Y') . " Blue Static\n

"; + + if (!defined('ISSO_PRINTER_HIDE_SETUP')) + { + $this->printer->paint("\n$copyright"); + //echo $this->registry->construct_debug_block(false); + } + + $this->printer->paint("\n\n\n"); + + exit; + } +} + +/*=====================================================================* +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/PrinterRootElementTable.php b/PrinterRootElementTable.php new file mode 100644 index 0000000..270fe1c --- /dev/null +++ b/PrinterRootElementTable.php @@ -0,0 +1,137 @@ + object. This can have a parent or not: if it does, +* then it will be painted as a child, otherwise it will act as a root. +* +* @author Blue Static +* @copyright Copyright (c)2002 - [#]year[#], Blue Static +* @version $Revision$ +* @package ISSO +* +*/ +class BSPrinterRootElementTable extends BSPrinterRootElement +{ + /** + * Maximum number of columns + * @var integer + */ + private $colspan = 0; + + // ################################################################### + /** + * Adds a table row into the child list + * + * @param BSPrinterTableElement Table element + */ + public function addChild(BSPrinterElement $tr) + { + $this->children[] = $tr; + } + + // ################################################################### + /** + * Calculates the number of columns to display based on the colspan + * of children elements + */ + private function _calculateColumnCount() + { + foreach ($this->children AS $child) + { + if ($child->numberOfColumns() > $this->colspan) + { + $this->colspan = $child->numberOfColumns(); + } + } + } + + // ################################################################### + /** + * Returns the HTML for all printed children elements + * + * @return string Printed HTML + */ + protected function _paintChildren() + { + $builder = ''; + + $this->_calculateColumnCount(); + + foreach ($this->children AS $child) + { + $this->builder .= "\n" . $child->paint() . "\n"; + } + + return $this->builder; + } + + // ################################################################### + /** + * Sets the parent element + * + * @param BSPrinterElement Parent + */ + public function setParent(BSPrinterElement $parent) + { + $this->parent = $parent; + } + + // ################################################################### + /** + * Gets the parent element + * + * @return BSPrinterElement Parent + */ + public function getParent() + { + return $this->parent; + } + + // ################################################################### + /** + * Paints the + * + * @return string Table HTML code + */ + public function paint() + { + $this->printer->paint("
" . $this->_paintChildren() . "
"); + } +} + +/*=====================================================================* +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file diff --git a/PrinterTableElement.php b/PrinterTableElement.php new file mode 100644 index 0000000..9c230e8 --- /dev/null +++ b/PrinterTableElement.php @@ -0,0 +1,146 @@ +parent = $table; + } + + // ################################################################### + /** + * Sets the CSS class to use. Use ":swap:" to alternate + * + * @param string CSS class + */ + public function setCssClass($class) + { + $this->cssClass = $class; + } + + // ################################################################### + /** + * Sets the parent element + */ + public function setParent(BSPrinterElement $parent) + { + trigger_error('Cannot set the parent element on a BSPrinterRootElement'); + } + + // ################################################################### + /** + * Gets the parent element (none exist as this is the root element) + */ + public function getParent() + { + return null; + } + + // ################################################################### + /** + * Returns the number of columns in this element + * + * @return integer Column count + */ + public function numberOfColumns() + { + return sizeof($this->children); + } + + // ################################################################### + /** + * Returns the HTML for all printed children elements + * + * @return string Printed HTML + */ + protected function _paintChildren() + { + $builder = ''; + + foreach ($this->children AS $child) + { + $builder .= "\n" . $child->paint() . "\n"; + } + + return $builder; + } + + // ################################################################### + /** + * Paints the entire table row + * + * @return string Table row HTML + */ + public function paint() + { + return "" . $this->_paintChildren() . ""; + } +} + +/*=====================================================================* +|| ################################################################### +|| # $HeadURL$ +|| # $Id$ +|| ################################################################### +\*=====================================================================*/ +?> \ No newline at end of file -- 2.22.5