1. Import
This commit is contained in:
351
html/illt/HTML/Common.php
Normal file
351
html/illt/HTML/Common.php
Normal file
@@ -0,0 +1,351 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Common.php,v 1.14.2.1 2002/04/09 19:04:19 ssb Exp $
|
||||
|
||||
/**
|
||||
* Base class for all HTML classes
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @version 1.6
|
||||
* @since PHP 4.0.3pl1
|
||||
* @abstract
|
||||
*/
|
||||
class HTML_Common {
|
||||
|
||||
/**
|
||||
* Associative array of table attributes
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_attributes = array();
|
||||
|
||||
/**
|
||||
* Tab offset of the table
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $_tabOffset = 0;
|
||||
|
||||
/**
|
||||
* HTML comment on the object
|
||||
* @var string
|
||||
* @since 1.5
|
||||
* @access private
|
||||
*/
|
||||
var $_comment = "";
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
* @param mixed $attributes Associative array of table tag attributes
|
||||
* or HTML attributes name="value" pairs
|
||||
* @access public
|
||||
*/
|
||||
function HTML_Common($attributes=null, $tabOffset=0)
|
||||
{
|
||||
$this->setTabOffset($tabOffset);
|
||||
$this->setAttributes($attributes);
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Returns the current API version
|
||||
* @access public
|
||||
* @returns double
|
||||
*/
|
||||
function apiVersion()
|
||||
{
|
||||
return 1.6;
|
||||
} // end func apiVersion
|
||||
|
||||
/**
|
||||
* Returns a string of \t for the tabOffset property
|
||||
* @access private
|
||||
*/
|
||||
function _getTabs()
|
||||
{
|
||||
return $this->_tabOffset > 0 ? str_repeat("\t", $this->_tabOffset) : "";
|
||||
} // end func _getTabs
|
||||
|
||||
/**
|
||||
* Returns an HTML formatted attribute string
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
* @access private
|
||||
*/
|
||||
function _getAttrString($attributes)
|
||||
{
|
||||
$strAttr = '';
|
||||
if (is_array($attributes)) {
|
||||
while (list($key, $value) = each($attributes)) {
|
||||
if (is_int($key)) {
|
||||
$strAttr .= ' ' . strtolower($value) . '="' . strtolower($value) . '"';
|
||||
} else {
|
||||
$strAttr .= ' ' . strtolower($key) . '="' . htmlspecialchars($value) . '"';
|
||||
}
|
||||
}
|
||||
}
|
||||
return $strAttr;
|
||||
} // end func _getAttrString
|
||||
|
||||
/**
|
||||
* Returns a valid atrributes array from either a string or array
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access private
|
||||
*/
|
||||
function _parseAttributes($attributes)
|
||||
{
|
||||
if (is_array($attributes)) {
|
||||
return $attributes;
|
||||
} elseif (is_string($attributes)) {
|
||||
$preg = "/(([A-Za-z_:]|[^\\x00-\\x7F])([A-Za-z0-9_:.-]|[^\\x00-\\x7F])*)" .
|
||||
"([ \\n\\t\\r]+)?(=([ \\n\\t\\r]+)?(\"[^\"]*\"|'[^']*'|[^ \\n\\t\\r]*))?/";
|
||||
if (preg_match_all($preg, $attributes, $regs)) {
|
||||
$valCounter = 0;
|
||||
for ($counter=0; $counter<count($regs[1]); $counter++) {
|
||||
$name = $regs[1][$counter];
|
||||
$check = $regs[0][$counter];
|
||||
$value = $regs[7][$valCounter];
|
||||
if (trim($name) == trim($check)) {
|
||||
$arrAttr[] = strtoupper(trim($name));
|
||||
} else {
|
||||
if (substr($value, 0, 1) == "\"" || substr($value, 0, 1) == "'") {
|
||||
$value = substr($value, 1, -1);
|
||||
}
|
||||
$arrAttr[strtolower(trim($name))] = trim($value);
|
||||
$valCounter++;
|
||||
}
|
||||
}
|
||||
return $arrAttr;
|
||||
}
|
||||
}
|
||||
} // end func _parseAttributes
|
||||
|
||||
/**
|
||||
* Returns the array key for the given non-name-value pair attribute
|
||||
*
|
||||
* @param string $attr Attribute
|
||||
* @param array $attributes Array of attribute
|
||||
* @since 1.0
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function _getAttrKey($attr, $attributes)
|
||||
{
|
||||
if (is_array($attributes)) {
|
||||
$keys = array_keys($attributes);
|
||||
for ($counter=0; $counter < count($keys); $counter++) {
|
||||
$key = $keys[$counter];
|
||||
$value = $attributes[$key];
|
||||
if (strtoupper($value) == strtoupper($attr) && is_int($key)) {
|
||||
return $key;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} //end func _getAttrKey
|
||||
|
||||
/**
|
||||
* Updates the attributes in $attr1 with the values in $attr2 without changing the other existing attributes
|
||||
* @param array $attr1 Original attributes array
|
||||
* @param array $attr2 New attributes array
|
||||
* @access private
|
||||
* @return array
|
||||
*/
|
||||
function _updateAttrArray(&$attr1, $attr2)
|
||||
{
|
||||
if (!is_array($attr2)) {
|
||||
return false;
|
||||
}
|
||||
while (list($key, $value) = each($attr2)) {
|
||||
if (!is_int($key)) {
|
||||
$attr1[$key] = $value;
|
||||
} else {
|
||||
$key = $this->_getAttrKey($value, $attr1);
|
||||
if (isset($key)) {
|
||||
$attr1[$key] = $value;
|
||||
} else {
|
||||
if (is_array($attr1)) {
|
||||
array_unshift($attr1, $value);
|
||||
} else {
|
||||
$attr1[] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end func _updateAtrrArray
|
||||
|
||||
/**
|
||||
* Removes the given attribute from the given array
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @param array $attributes Attribute array
|
||||
* @since 1.4
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function _removeAttr($attr, &$attributes)
|
||||
{
|
||||
if (in_array(strtolower($attr), array_keys($attributes))) {
|
||||
unset($attributes[$attr]);
|
||||
} else {
|
||||
unset($attributes[$this->_getAttrKey($attr, $attributes)]);
|
||||
}
|
||||
} //end func _removeAttr
|
||||
|
||||
/**
|
||||
* Returns the value of the given attribute
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function getAttribute($attr)
|
||||
{
|
||||
$attr = strtolower($attr);
|
||||
if (is_array($this->_attributes) && isset($this->_attributes[$attr])) {
|
||||
return $this->_attributes[$attr];
|
||||
}
|
||||
return;
|
||||
} //end func getAttribute
|
||||
|
||||
/**
|
||||
* Sets the HTML attributes
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
function setAttributes($attributes)
|
||||
{
|
||||
$this->_attributes = $this->_parseAttributes($attributes);
|
||||
} // end func _setAttributes
|
||||
|
||||
/**
|
||||
* Returns an assoc array of attributes
|
||||
*
|
||||
* @since 1.6
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function getAttributes()
|
||||
{
|
||||
return $this->_attributes;
|
||||
} //end func getAttributes
|
||||
|
||||
/**
|
||||
* Updates the passed attributes without changing the other existing attributes
|
||||
* @param mixed $attributes Either a typical HTML attribute string or an associative array
|
||||
* @access public
|
||||
*/
|
||||
function updateAttributes($attributes)
|
||||
{
|
||||
$attributes = $this->_parseAttributes($attributes);
|
||||
$this->_updateAttrArray($this->_attributes, $attributes);
|
||||
} // end func updateAttributes
|
||||
|
||||
/**
|
||||
* Removes an attribute from
|
||||
*
|
||||
* @param string $attr Attribute name
|
||||
* @since 1.4
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function removeAttribute($attr)
|
||||
{
|
||||
$this->_removeAttr($attr, $this->_attributes);
|
||||
} //end func removeAttribute
|
||||
|
||||
/**
|
||||
* Sets the tab offset
|
||||
* @param int $offset
|
||||
* @access public
|
||||
*/
|
||||
function setTabOffset($offset)
|
||||
{
|
||||
$this->_tabOffset = $offset;
|
||||
} // end func setTabOffset
|
||||
|
||||
/**
|
||||
* Returns the tabOffset
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function getTabOffset()
|
||||
{
|
||||
return $this->_tabOffset;
|
||||
} //end func getTabOffset
|
||||
|
||||
/**
|
||||
* Sets the HTML comment to be displayed at the beginning of the HTML string
|
||||
*
|
||||
* @param string
|
||||
* @since 1.4
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function setComment($comment)
|
||||
{
|
||||
$this->_comment = $comment;
|
||||
} // end func setHtmlComment
|
||||
|
||||
/**
|
||||
* Returns the HTML comment
|
||||
*
|
||||
* @since 1.5
|
||||
* @access public
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
function getComment()
|
||||
{
|
||||
return $this->_comment;
|
||||
} //end func getComment
|
||||
|
||||
/**
|
||||
* Abstract method. Must be extended to return the objects HTML
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
* @abstract
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
return "";
|
||||
} // end func toHtml
|
||||
|
||||
/**
|
||||
* Displays the HTML to the screen
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
function display()
|
||||
{
|
||||
print $this->toHtml();
|
||||
} // end func display
|
||||
|
||||
} // end class HTML_Common
|
||||
?>
|
||||
792
html/illt/HTML/IT.php
Normal file
792
html/illt/HTML/IT.php
Normal file
@@ -0,0 +1,792 @@
|
||||
<?php
|
||||
//
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997-2002 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.02 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Ulf Wendel <ulf.wendel@phpdoc.de> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: IT.php,v 1.13 2002/02/28 08:27:13 sebastian Exp $
|
||||
//
|
||||
|
||||
require_once('HTML/IT_Error.php');
|
||||
|
||||
/**
|
||||
* Integrated Template - IT
|
||||
*
|
||||
* Well there's not much to say about it. I needed a template class that
|
||||
* supports a single template file with multiple (nested) blocks inside and
|
||||
* a simple block API.
|
||||
*
|
||||
* The Isotemplate API is somewhat tricky for a beginner although it is the best
|
||||
* one you can build. template::parse() [phplib template = Isotemplate] requests
|
||||
* you to name a source and a target where the current block gets parsed into.
|
||||
* Source and target can be block names or even handler names. This API gives you
|
||||
* a maximum of fexibility but you always have to know what you do which is
|
||||
* quite unusual for php skripter like me.
|
||||
*
|
||||
* I noticed that I do not any control on which block gets parsed into which one.
|
||||
* If all blocks are within one file, the script knows how they are nested and in
|
||||
* which way you have to parse them. IT knows that inner1 is a child of block2, there's
|
||||
* no need to tell him about this.
|
||||
*
|
||||
* <table border>
|
||||
* <tr>
|
||||
* <td colspan=2>
|
||||
* __global__
|
||||
* <p>
|
||||
* (hidden and automatically added)
|
||||
* </td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>block1</td>
|
||||
* <td>
|
||||
* <table border>
|
||||
* <tr>
|
||||
* <td colspan=2>block2</td>
|
||||
* </tr>
|
||||
* <tr>
|
||||
* <td>inner1</td>
|
||||
* <td>inner2</td>
|
||||
* </tr>
|
||||
* </table>
|
||||
* </td>
|
||||
* </tr>
|
||||
* </table>
|
||||
*
|
||||
* To add content to block1 you simply type:
|
||||
* <code>$tpl->setCurrentBlock("block1");</code>
|
||||
* and repeat this as often as needed:
|
||||
* <code>
|
||||
* $tpl->setVariable(...);
|
||||
* $tpl->parseCurrentBlock();
|
||||
* </code>
|
||||
*
|
||||
* To add content to block2 you would type something like:
|
||||
* <code>
|
||||
* $tpl->setCurrentBlock("inner1");
|
||||
* $tpl->setVariable(...);
|
||||
* $tpl->parseCurrentBlock();
|
||||
*
|
||||
* $tpl->setVariable(...);
|
||||
* $tpl->parseCurrentBlock();
|
||||
*
|
||||
* $tpl->parse("block1");
|
||||
* </code>
|
||||
*
|
||||
* This will result in one repition of block1 which contains two repitions
|
||||
* of inner1. inner2 will be removed if $removeEmptyBlock is set to true which is the default.
|
||||
*
|
||||
* Usage:
|
||||
* <code>
|
||||
* $tpl = new IntegratedTemplate( [string filerootdir] );
|
||||
*
|
||||
* // load a template or set it with setTemplate()
|
||||
* $tpl->loadTemplatefile( string filename [, boolean removeUnknownVariables, boolean removeEmptyBlocks] )
|
||||
*
|
||||
* // set "global" Variables meaning variables not beeing within a (inner) block
|
||||
* $tpl->setVariable( string variablename, mixed value );
|
||||
*
|
||||
* // like with the Isotemplates there's a second way to use setVariable()
|
||||
* $tpl->setVariable( array ( string varname => mixed value ) );
|
||||
*
|
||||
* // Let's use any block, even a deeply nested one
|
||||
* $tpl->setCurrentBlock( string blockname );
|
||||
*
|
||||
* // repeat this as often as you need it.
|
||||
* $tpl->setVariable( array ( string varname => mixed value ) );
|
||||
* $tpl->parseCurrentBlock();
|
||||
*
|
||||
* // get the parsed template or print it: $tpl->show()
|
||||
* $tpl->get();
|
||||
* </code>
|
||||
*
|
||||
* @author Ulf Wendel <uw@netuse.de>
|
||||
* @version $Id: IT.php,v 1.13 2002/02/28 08:27:13 sebastian Exp $
|
||||
* @access public
|
||||
* @package IX[X]
|
||||
*/
|
||||
class IntegratedTemplate {
|
||||
|
||||
/**
|
||||
* Contains the error objects
|
||||
* @var array
|
||||
* @access public
|
||||
* @see halt(), $printError, $haltOnError
|
||||
*/
|
||||
var $err = array();
|
||||
|
||||
/**
|
||||
* Clear cache on get()?
|
||||
* @var boolean
|
||||
*/
|
||||
var $clearCache = false;
|
||||
|
||||
/**
|
||||
* First character of a variable placeholder ( _{_VARIABLE} ).
|
||||
* @var string
|
||||
* @access public
|
||||
* @see $closingDelimiter, $blocknameRegExp, $variablenameRegExp
|
||||
*/
|
||||
var $openingDelimiter = "{";
|
||||
|
||||
/**
|
||||
* Last character of a variable placeholder ( {VARIABLE_}_ ).
|
||||
* @var string
|
||||
* @access public
|
||||
* @see $openingDelimiter, $blocknameRegExp, $variablenameRegExp
|
||||
*/
|
||||
var $closingDelimiter = "}";
|
||||
|
||||
/**
|
||||
* RegExp matching a block in the template.
|
||||
* Per default "sm" is used as the regexp modifier, "i" is missing.
|
||||
* That means a case sensitive search is done.
|
||||
* @var string
|
||||
* @access public
|
||||
* @see $variablenameRegExp, $openingDelimiter, $closingDelimiter
|
||||
*/
|
||||
var $blocknameRegExp = "[0-9A-Za-z_-]+";
|
||||
|
||||
/**
|
||||
* RegExp matching a variable placeholder in the template.
|
||||
* Per default "sm" is used as the regexp modifier, "i" is missing.
|
||||
* That means a case sensitive search is done.
|
||||
* @var string
|
||||
* @access public
|
||||
* @see $blocknameRegExp, $openingDelimiter, $closingDelimiter
|
||||
*/
|
||||
var $variablenameRegExp = "[0-9A-Za-z_-]+";
|
||||
|
||||
/**
|
||||
* RegExp used to find variable placeholder, filled by the constructor.
|
||||
* @var string Looks somewhat like @(delimiter varname delimiter)@
|
||||
* @access public
|
||||
* @see IntegratedTemplate()
|
||||
*/
|
||||
var $variablesRegExp = "";
|
||||
|
||||
/**
|
||||
* RegExp used to strip unused variable placeholder.
|
||||
* @brother $variablesRegExp
|
||||
*/
|
||||
var $removeVariablesRegExp = "";
|
||||
|
||||
/**
|
||||
* Controls the handling of unknown variables, default is remove.
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $removeUnknownVariables = true;
|
||||
|
||||
/**
|
||||
* Controls the handling of empty blocks, default is remove.
|
||||
* @var boolean
|
||||
* @access public
|
||||
*/
|
||||
var $removeEmptyBlocks = true;
|
||||
|
||||
/**
|
||||
* RegExp used to find blocks an their content, filled by the constructor.
|
||||
* @var string
|
||||
* @see IntegratedTemplate()
|
||||
*/
|
||||
var $blockRegExp = "";
|
||||
|
||||
/**
|
||||
* Name of the current block.
|
||||
* @var string
|
||||
*/
|
||||
var $currentBlock = "__global__";
|
||||
|
||||
/**
|
||||
* Content of the template.
|
||||
* @var string
|
||||
*/
|
||||
var $template = "";
|
||||
|
||||
/**
|
||||
* Array of all blocks and their content.
|
||||
*
|
||||
* @var array
|
||||
* @see findBlocks()
|
||||
*/
|
||||
var $blocklist = array();
|
||||
|
||||
/**
|
||||
* Array with the parsed content of a block.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
var $blockdata = array();
|
||||
|
||||
/**
|
||||
* Array of variables in a block.
|
||||
* @var array
|
||||
*/
|
||||
var $blockvariables = array();
|
||||
|
||||
/**
|
||||
* Array of inner blocks of a block.
|
||||
* @var array
|
||||
*/
|
||||
var $blockinner = array();
|
||||
|
||||
/**
|
||||
* List of blocks to preverse even if they are "empty".
|
||||
*
|
||||
* This is something special. Sometimes you have blocks that
|
||||
* should be preserved although they are empty (no placeholder replaced).
|
||||
* Think of a shopping basket. If it's empty you have to drop a message to
|
||||
* the user. If it's filled you have to show the contents of the shopping baseket.
|
||||
* Now where do you place the message that the basket is empty? It's no good
|
||||
* idea to place it in you applications as customers tend to like unecessary minor
|
||||
* text changes. Having another template file for an empty basket means that it's
|
||||
* very likely that one fine day the filled and empty basket templates have different
|
||||
* layout. I decided to introduce blocks that to not contain any placeholder but only
|
||||
* text such as the message "Your shopping basked is empty".
|
||||
*
|
||||
* Now if there is no replacement done in such a block the block will be recognized
|
||||
* as "empty" and by default ($removeEmptyBlocks = true) be stripped off. To avoid this
|
||||
* you can now call touchBlock() to avoid this.
|
||||
*
|
||||
* The array $touchedBlocks stores a list of touched block which must not be removed even
|
||||
* if they are empty.
|
||||
*
|
||||
* @var array $touchedBlocks
|
||||
* @see touchBlock(), $removeEmptyBlocks
|
||||
*/
|
||||
var $touchedBlocks = array();
|
||||
|
||||
/**
|
||||
* Variable cache.
|
||||
*
|
||||
* Variables get cached before any replacement is done.
|
||||
* Advantage: empty blocks can be removed automatically.
|
||||
* Disadvantage: might take some more memory
|
||||
*
|
||||
* @var array
|
||||
* @see setVariable(), $clearCacheOnParse
|
||||
*/
|
||||
var $variableCache = array();
|
||||
|
||||
/**
|
||||
* Clear the variable cache on parse?
|
||||
*
|
||||
* If you're not an expert just leave the default false.
|
||||
* True reduces memory consumption somewhat if you tend to
|
||||
* add lots of values for unknown placeholder.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
var $clearCacheOnParse = false;
|
||||
|
||||
/**
|
||||
* Root directory for all file operations.
|
||||
* The string gets prefixed to all filenames given.
|
||||
* @var string
|
||||
* @see IntegratedTemplate(), setRoot()
|
||||
*/
|
||||
var $fileRoot = "";
|
||||
|
||||
/**
|
||||
* Internal flag indicating that a blockname was used multiple times.
|
||||
* @var boolean
|
||||
*/
|
||||
var $flagBlocktrouble = false;
|
||||
|
||||
/**
|
||||
* Flag indicating that the global block was parsed.
|
||||
* @var boolean
|
||||
*/
|
||||
var $flagGlobalParsed = false;
|
||||
|
||||
/**
|
||||
* EXPERIMENTAL! FIXME!
|
||||
* Flag indication that a template gets cached.
|
||||
*
|
||||
* Complex templates require some times to be preparsed
|
||||
* before the replacement can take place. Often I use
|
||||
* one template file over and over again but I don't know
|
||||
* before that I will use the same template file again.
|
||||
* Now IT could notice this and skip the preparse.
|
||||
*
|
||||
* @var boolean
|
||||
*/
|
||||
var $flagCacheTemplatefile = true;
|
||||
|
||||
/**
|
||||
* EXPERIMENTAL! FIXME!
|
||||
*/
|
||||
var $lastTemplatefile = "";
|
||||
|
||||
/**
|
||||
* Builds some complex regular expressions and optinally sets the file root directory.
|
||||
*
|
||||
* Make sure that you call this constructor if you derive your template
|
||||
* class from this one.
|
||||
*
|
||||
* @param string File root directory, prefix for all filenames given to the object.
|
||||
* @see setRoot()
|
||||
*/
|
||||
function IntegratedTemplate($root = "") {
|
||||
|
||||
$this->variablesRegExp = "@" . $this->openingDelimiter . "(" . $this->variablenameRegExp . ")" . $this->closingDelimiter . "@sm";
|
||||
$this->removeVariablesRegExp = "@" . $this->openingDelimiter . "\s*(" . $this->variablenameRegExp . ")\s*" . $this->closingDelimiter . "@sm";
|
||||
|
||||
$this->blockRegExp = '@<!--\s+BEGIN\s+(' . $this->blocknameRegExp . ')\s+-->(.*)<!--\s+END\s+\1\s+-->@sm';
|
||||
|
||||
$this->setRoot($root);
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Print a certain block with all replacements done.
|
||||
* @brother get()
|
||||
*/
|
||||
function show($block = "__global__") {
|
||||
print $this->get($block);
|
||||
} // end func show
|
||||
|
||||
/**
|
||||
* Returns a block with all replacements done.
|
||||
*
|
||||
* @param string name of the block
|
||||
* @return string
|
||||
* @throws IT_Error
|
||||
* @access public
|
||||
* @see show()
|
||||
*/
|
||||
function get($block = "__global__") {
|
||||
|
||||
if ("__global__" == $block && !$this->flagGlobalParsed)
|
||||
$this->parse("__global__");
|
||||
|
||||
if (!isset($this->blocklist[$block])) {
|
||||
new IT_Error("The block '$block' was not found in the template.", __FILE__, __LINE__);
|
||||
return "";
|
||||
}
|
||||
|
||||
if ($this->clearCache) {
|
||||
|
||||
$data = (isset($this->blockdata[$block])) ? $this->blockdata[$block] : "";
|
||||
unset($this->blockdata[$block]);
|
||||
return $data;
|
||||
|
||||
} else {
|
||||
|
||||
return (isset($this->blockdata[$block])) ? $this->blockdata[$block] : "";
|
||||
|
||||
}
|
||||
|
||||
} // end func get()
|
||||
|
||||
/**
|
||||
* Parses the given block.
|
||||
*
|
||||
* @param string name of the block to be parsed
|
||||
* @access public
|
||||
* @see parseCurrentBlock()
|
||||
* @throws IT_Error
|
||||
*/
|
||||
function parse($block = "__global__", $flag_recursion = false) {
|
||||
|
||||
if (!isset($this->blocklist[$block])) {
|
||||
return new IT_Error("The block '$block' was not found in the template.", __FILE__, __LINE__);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("__global__" == $block)
|
||||
$this->flagGlobalParsed = true;
|
||||
|
||||
$regs = array();
|
||||
$values = array();
|
||||
|
||||
if ($this->clearCacheOnParse) {
|
||||
|
||||
foreach ($this->variableCache as $name => $value) {
|
||||
$regs[] = "@" . $this->openingDelimiter . $name . $this->closingDelimiter . "@";
|
||||
$values[] = $value;
|
||||
}
|
||||
$this->variableCache = array();
|
||||
|
||||
} else {
|
||||
|
||||
foreach ($this->blockvariables[$block] as $allowedvar => $v) {
|
||||
|
||||
if (isset($this->variableCache[$allowedvar])) {
|
||||
$regs[] = "@".$this->openingDelimiter . $allowedvar . $this->closingDelimiter . "@";
|
||||
$values[] = $this->variableCache[$allowedvar];
|
||||
unset($this->variableCache[$allowedvar]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$outer = (0 == count($regs)) ? $this->blocklist[$block] : preg_replace($regs, $values, $this->blocklist[$block]);
|
||||
$empty = (0 == count($values)) ? true : false;
|
||||
|
||||
if (isset($this->blockinner[$block])) {
|
||||
|
||||
foreach ($this->blockinner[$block] as $k => $innerblock) {
|
||||
|
||||
$this->parse($innerblock, true);
|
||||
if ("" != $this->blockdata[$innerblock])
|
||||
$empty = false;
|
||||
|
||||
$placeholder = $this->openingDelimiter . "__" . $innerblock . "__" . $this->closingDelimiter;
|
||||
$outer = str_replace($placeholder, $this->blockdata[$innerblock], $outer);
|
||||
$this->blockdata[$innerblock] = "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($this->removeUnknownVariables)
|
||||
$outer = preg_replace($this->removeVariablesRegExp, "", $outer);
|
||||
|
||||
if ($empty) {
|
||||
|
||||
if (!$this->removeEmptyBlocks) {
|
||||
|
||||
$this->blockdata[$block ].= $outer;
|
||||
|
||||
} else {
|
||||
|
||||
if (isset($this->touchedBlocks[$block])) {
|
||||
$this->blockdata[$block] .= $outer;
|
||||
unset($this->touchedBlocks[$block]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
$this->blockdata[$block] .= $outer;
|
||||
|
||||
}
|
||||
|
||||
return $empty;
|
||||
} // end func parse
|
||||
|
||||
/**
|
||||
* Parses the current block
|
||||
* @see parse(), setCurrentBlock(), $currentBlock
|
||||
* @access public
|
||||
*/
|
||||
function parseCurrentBlock() {
|
||||
return $this->parse($this->currentBlock);
|
||||
} // end func parseCurrentBlock
|
||||
|
||||
/**
|
||||
* Sets a variable value.
|
||||
*
|
||||
* The function can be used eighter like setVariable( "varname", "value")
|
||||
* or with one array $variables["varname"] = "value" given setVariable($variables)
|
||||
* quite like phplib templates set_var().
|
||||
*
|
||||
* @param mixed string with the variable name or an array %variables["varname"] = "value"
|
||||
* @param string value of the variable or empty if $variable is an array.
|
||||
* @param string prefix for variable names
|
||||
* @access public
|
||||
*/
|
||||
function setVariable($variable, $value = "") {
|
||||
|
||||
if (is_array($variable)) {
|
||||
|
||||
$this->variableCache = array_merge($this->variableCache, $variable);
|
||||
|
||||
} else {
|
||||
|
||||
$this->variableCache[$variable] = $value;
|
||||
|
||||
}
|
||||
|
||||
} // end func setVariable
|
||||
|
||||
/**
|
||||
* Sets the name of the current block that is the block where variables are added.
|
||||
*
|
||||
* @param string name of the block
|
||||
* @return boolean false on failure, otherwise true
|
||||
* @throws IT_Error
|
||||
* @access public
|
||||
*/
|
||||
function setCurrentBlock($block = "__global__") {
|
||||
|
||||
if (!isset($this->blocklist[$block]))
|
||||
return new IT_Error("Can't find the block '$block' in the template.", __FILE__, __LINE__);
|
||||
|
||||
$this->currentBlock = $block;
|
||||
|
||||
return true;
|
||||
} // end func setCurrentBlock
|
||||
|
||||
/**
|
||||
* Preserves an empty block even if removeEmptyBlocks is true.
|
||||
*
|
||||
* @param string name of the block
|
||||
* @return boolean false on false, otherwise true
|
||||
* @throws IT_Error
|
||||
* @access public
|
||||
* @see $removeEmptyBlocks
|
||||
*/
|
||||
function touchBlock($block) {
|
||||
|
||||
if (!isset($this->blocklist[$block]))
|
||||
return new IT_Error("Can't find the block '$block' in the template.", __FILE__, __LINE__);
|
||||
|
||||
$this->touchedBlocks[$block] = true;
|
||||
|
||||
return true;
|
||||
} // end func touchBlock
|
||||
|
||||
/**
|
||||
* Clears all datafields of the object and rebuild the internal blocklist
|
||||
*
|
||||
* LoadTemplatefile() and setTemplate() automatically call this function
|
||||
* when a new template is given. Don't use this function
|
||||
* unless you know what you're doing.
|
||||
*
|
||||
* @access public
|
||||
* @see free()
|
||||
*/
|
||||
function init() {
|
||||
|
||||
$this->free();
|
||||
$this->findBlocks($this->template);
|
||||
// we don't need it any more
|
||||
$this->template = '';
|
||||
$this->buildBlockvariablelist();
|
||||
|
||||
} // end func init
|
||||
|
||||
/**
|
||||
* Clears all datafields of the object.
|
||||
*
|
||||
* Don't use this function unless you know what you're doing.
|
||||
*
|
||||
* @access public
|
||||
* @see init()
|
||||
*/
|
||||
function free() {
|
||||
|
||||
$this->err = array();
|
||||
|
||||
$this->currentBlock = "__global__";
|
||||
|
||||
$this->variableCache = array();
|
||||
$this->blocklookup = array();
|
||||
$this->touchedBlocks = array();
|
||||
|
||||
$this->flagBlocktrouble = false;
|
||||
$this->flagGlobalParsed = false;
|
||||
|
||||
} // end func free
|
||||
|
||||
/**
|
||||
* Sets the template.
|
||||
*
|
||||
* You can eighter load a template file from disk with LoadTemplatefile() or set the
|
||||
* template manually using this function.
|
||||
*
|
||||
* @param string template content
|
||||
* @param boolean remove unknown/unused variables?
|
||||
* @param boolean remove empty blocks?
|
||||
* @see LoadTemplatefile(), $template
|
||||
* @access public
|
||||
*/
|
||||
function setTemplate($template, $removeUnknownVariables = true, $removeEmptyBlocks = true) {
|
||||
|
||||
$this->removeUnknownVariables = $removeUnknownVariables;
|
||||
$this->removeEmptyBlocks = $removeEmptyBlocks;
|
||||
|
||||
if ("" == $template && $this->flagCacheTemplatefile) {
|
||||
|
||||
$this->variableCache = array();
|
||||
$this->blockdata = array();
|
||||
$this->touchedBlocks = array();
|
||||
$this->currentBlock = "__global__";
|
||||
|
||||
} else {
|
||||
|
||||
$this->template = '<!-- BEGIN __global__ -->' . $template . '<!-- END __global__ -->';
|
||||
$this->init();
|
||||
|
||||
}
|
||||
|
||||
if ($this->flagBlocktrouble)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
} // end func setTemplate
|
||||
|
||||
/**
|
||||
* Reads a template file from the disk.
|
||||
*
|
||||
* @param string name of the template file
|
||||
* @param bool how to handle unknown variables.
|
||||
* @param bool how to handle empty blocks.
|
||||
* @access public
|
||||
* @return boolean false on failure, otherwise true
|
||||
* @see $template, setTemplate(), $removeUnknownVariables, $removeEmptyBlocks
|
||||
*/
|
||||
function loadTemplatefile($filename, $removeUnknownVariables = true, $removeEmptyBlocks = true) {
|
||||
|
||||
$template = "";
|
||||
if (!$this->flagCacheTemplatefile || $this->lastTemplatefile != $filename)
|
||||
$template = $this->getfile($filename);
|
||||
|
||||
$this->lastTemplatefile = $filename;
|
||||
|
||||
return $this->setTemplate($template, $removeUnknownVariables, $removeEmptyBlocks);
|
||||
} // end func LoadTemplatefile
|
||||
|
||||
/**
|
||||
* Sets the file root. The file root gets prefixed to all filenames passed to the object.
|
||||
*
|
||||
* Make sure that you override this function when using the class
|
||||
* on windows.
|
||||
*
|
||||
* @param string
|
||||
* @see IntegratedTemplate()
|
||||
* @access public
|
||||
*/
|
||||
function setRoot($root) {
|
||||
|
||||
if ("" != $root && "/" != substr($root, -1))
|
||||
$root .= "/";
|
||||
|
||||
$this->fileRoot = $root;
|
||||
|
||||
} // end func setRoot
|
||||
|
||||
/**
|
||||
* Build a list of all variables within of a block
|
||||
*/
|
||||
function buildBlockvariablelist() {
|
||||
|
||||
foreach ($this->blocklist as $name => $content) {
|
||||
preg_match_all( $this->variablesRegExp, $content, $regs );
|
||||
|
||||
if (0 != count($regs[1])) {
|
||||
|
||||
foreach ($regs[1] as $k => $var)
|
||||
$this->blockvariables[$name][$var] = true;
|
||||
|
||||
} else {
|
||||
|
||||
$this->blockvariables[$name] = array();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
} // end func buildBlockvariablelist
|
||||
|
||||
/**
|
||||
* Returns a list of all
|
||||
*/
|
||||
function getGlobalvariables() {
|
||||
|
||||
$regs = array();
|
||||
$values = array();
|
||||
|
||||
foreach ($this->blockvariables["__global__"] as $allowedvar => $v) {
|
||||
|
||||
if (isset($this->variableCache[$allowedvar])) {
|
||||
$regs[] = "@" . $this->openingDelimiter . $allowedvar . $this->closingDelimiter."@";
|
||||
$values[] = $this->variableCache[$allowedvar];
|
||||
unset($this->variableCache[$allowedvar]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return array($regs, $values);
|
||||
} // end func getGlobalvariables
|
||||
|
||||
/**
|
||||
* Recusively builds a list of all blocks within the template.
|
||||
*
|
||||
* @param string string that gets scanned
|
||||
* @see $blocklist
|
||||
*/
|
||||
function findBlocks($string) {
|
||||
|
||||
$blocklist = array();
|
||||
|
||||
if (preg_match_all($this->blockRegExp, $string, $regs, PREG_SET_ORDER)) {
|
||||
|
||||
foreach ($regs as $k => $match) {
|
||||
|
||||
$blockname = $match[1];
|
||||
$blockcontent = $match[2];
|
||||
|
||||
if (isset($this->blocklist[$blockname])) {
|
||||
new IT_Error("The name of a block must be unique within a template. Found '$blockname' twice. Unpredictable results may appear.", __FILE__, __LINE__);
|
||||
$this->flagBlocktrouble = true;
|
||||
}
|
||||
|
||||
$this->blocklist[$blockname] = $blockcontent;
|
||||
$this->blockdata[$blockname] = "";
|
||||
|
||||
$blocklist[] = $blockname;
|
||||
|
||||
$inner = $this->findBlocks($blockcontent);
|
||||
foreach ($inner as $k => $name) {
|
||||
|
||||
$pattern = sprintf('@<!--\s+BEGIN\s+%s\s+-->(.*)<!--\s+END\s+%s\s+-->@sm',
|
||||
$name,
|
||||
$name
|
||||
);
|
||||
|
||||
$this->blocklist[$blockname] = preg_replace( $pattern,
|
||||
$this->openingDelimiter . "__" . $name . "__" . $this->closingDelimiter,
|
||||
$this->blocklist[$blockname]
|
||||
);
|
||||
$this->blockinner[$blockname][] = $name;
|
||||
$this->blockparents[$name] = $blockname;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return $blocklist;
|
||||
} // end func findBlocks
|
||||
|
||||
/**
|
||||
* Reads a file from disk and returns its content.
|
||||
* @param string Filename
|
||||
* @return string Filecontent
|
||||
*/
|
||||
function getFile($filename) {
|
||||
|
||||
if ("/" == $filename{0} && "/" == substr($this->fileRoot, -1))
|
||||
$filename = substr($filename, 1);
|
||||
|
||||
$filename = $this->fileRoot . $filename;
|
||||
|
||||
if (!($fh = @fopen($filename, "r"))) {
|
||||
new IT_Error("Can't read '$filename'.", __FILE__, __LINE__);
|
||||
return "";
|
||||
}
|
||||
|
||||
$content = fread($fh, filesize($filename));
|
||||
fclose($fh);
|
||||
|
||||
return preg_replace("#<!-- INCLUDE (.*) -->#ime", "\$this->getFile('\\1')", $content);
|
||||
} // end func getFile
|
||||
|
||||
} // end class IntegratedTemplate
|
||||
?>
|
||||
51
html/illt/HTML/IT_Error.php
Normal file
51
html/illt/HTML/IT_Error.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Author: Ulf Wendel <ulf.wendel@phpdoc.de> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: IT_Error.php,v 1.4 2002/02/28 08:27:13 sebastian Exp $
|
||||
|
||||
require_once "PEAR.php";
|
||||
|
||||
/**
|
||||
* IT[X] Error class
|
||||
*
|
||||
* @package IT[X]
|
||||
*/
|
||||
class IT_Error extends PEAR_Error {
|
||||
|
||||
|
||||
/**
|
||||
* Prefix of all error messages.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
var $error_message_prefix = "IntegratedTemplate Error: ";
|
||||
|
||||
/**
|
||||
* Creates an cache error object.
|
||||
*
|
||||
* @param string error message
|
||||
* @param string file where the error occured
|
||||
* @param string linenumber where the error occured
|
||||
*/
|
||||
function IT_Error($msg, $file = __FILE__, $line = __LINE__) {
|
||||
|
||||
$this->PEAR_Error(sprintf("%s [%s on line %d].", $msg, $file, $line));
|
||||
|
||||
} // end func IT_Error
|
||||
|
||||
} // end class IT_Error
|
||||
?>
|
||||
631
html/illt/HTML/Table.php
Normal file
631
html/illt/HTML/Table.php
Normal file
@@ -0,0 +1,631 @@
|
||||
<?php
|
||||
/* vim: set expandtab tabstop=4 shiftwidth=4: */
|
||||
// +----------------------------------------------------------------------+
|
||||
// | PHP Version 4 |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | This source file is subject to version 2.0 of the PHP license, |
|
||||
// | that is bundled with this package in the file LICENSE, and is |
|
||||
// | available at through the world-wide-web at |
|
||||
// | http://www.php.net/license/2_02.txt. |
|
||||
// | If you did not receive a copy of the PHP license and are unable to |
|
||||
// | obtain it through the world-wide-web, please send a note to |
|
||||
// | license@php.net so we can mail you a copy immediately. |
|
||||
// +----------------------------------------------------------------------+
|
||||
// | Authors: Adam Daniel <adaniel1@eesus.jnj.com> |
|
||||
// | Bertrand Mansion <bmansion@mamasam.com> |
|
||||
// +----------------------------------------------------------------------+
|
||||
//
|
||||
// $Id: Table.php,v 1.14 2002/01/31 13:01:52 mansion Exp $
|
||||
|
||||
require_once "PEAR.php";
|
||||
require_once "HTML/Common.php";
|
||||
|
||||
/**
|
||||
* Builds an HTML table
|
||||
*
|
||||
* @author Adam Daniel <adaniel1@eesus.jnj.com>
|
||||
* @author Bertrand Mansion <bmansion@mamasam.com>
|
||||
* @version 1.6
|
||||
* @since PHP 4.0.3pl1
|
||||
*/
|
||||
class HTML_Table extends HTML_Common {
|
||||
|
||||
/**
|
||||
* Automatically adds a new row or column if a given row or column index does not exist
|
||||
*
|
||||
* @var bool
|
||||
* @access private
|
||||
*/
|
||||
var $_autoGrow = true;
|
||||
|
||||
/**
|
||||
* Value to insert into empty cells
|
||||
*
|
||||
* @var string
|
||||
* @access private
|
||||
*/
|
||||
var $_autoFill = " ";
|
||||
|
||||
/**
|
||||
* Array containing the table structure
|
||||
*
|
||||
* @var array
|
||||
* @access private
|
||||
*/
|
||||
var $_structure = array();
|
||||
|
||||
/**
|
||||
* Number of rows composing in the table
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $_rows = 0;
|
||||
|
||||
/**
|
||||
* Number of column composing the table
|
||||
*
|
||||
* @var int
|
||||
* @access private
|
||||
*/
|
||||
var $_cols = 0;
|
||||
|
||||
/**
|
||||
* Tracks the level of nested tables
|
||||
*
|
||||
* @var int
|
||||
* @since 1.5
|
||||
* @access private
|
||||
*/
|
||||
var $_nestLevel = 0;
|
||||
|
||||
/**
|
||||
* Class constructor
|
||||
*
|
||||
* @param array $attributes Associative array of table tag attributes
|
||||
* @param int $tabOffset
|
||||
* @access public
|
||||
*/
|
||||
function HTML_Table($attributes = null, $tabOffset = 0)
|
||||
{
|
||||
$commonVersion = 1.3;
|
||||
if (HTML_Common::apiVersion() < $commonVersion) {
|
||||
return new PEAR_Error("HTML_Table version " . $this->apiVersion() . " requires " .
|
||||
"HTML_Common version $commonVersion or greater.", 0, PEAR_ERROR_TRIGGER);
|
||||
}
|
||||
HTML_Common::HTML_Common($attributes, $tabOffset);
|
||||
} // end constructor
|
||||
|
||||
/**
|
||||
* Returns the API version
|
||||
*
|
||||
* @access public
|
||||
* @return double
|
||||
*/
|
||||
function apiVersion()
|
||||
{
|
||||
return 1.6;
|
||||
} // end func apiVersion
|
||||
|
||||
/**
|
||||
* Sets the table caption
|
||||
*
|
||||
* @param string $caption
|
||||
* @param mixed $attributes Associative array or string of table row attributes
|
||||
* @access public
|
||||
*/
|
||||
function setCaption($caption, $attributes = null)
|
||||
{
|
||||
$attributes = $this->_parseAttributes($attributes);
|
||||
$this->_structure["caption"] = array("attr" => $attributes, "contents" => $caption);
|
||||
} // end func setCaption
|
||||
|
||||
/**
|
||||
* Sets the autoFill value
|
||||
*
|
||||
* @param mixed $fill
|
||||
* @access public
|
||||
*/
|
||||
function setAutoFill($fill)
|
||||
{
|
||||
$this->_autoFill = $fill;
|
||||
} // end func setAutoFill
|
||||
|
||||
/**
|
||||
* Returns the autoFill value
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function getAutoFill()
|
||||
{
|
||||
return $this->_autoFill;
|
||||
} // end func getAutoFill
|
||||
|
||||
/**
|
||||
* Sets the autoGrow value
|
||||
*
|
||||
* @param bool $fill
|
||||
* @access public
|
||||
*/
|
||||
function setAutoGrow($grow)
|
||||
{
|
||||
$this->_autoGrow = $grow;
|
||||
} // end func setAutoGrow
|
||||
|
||||
/**
|
||||
* Returns the autoGrow value
|
||||
*
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function getAutoGrow()
|
||||
{
|
||||
return $this->_autoGrow;
|
||||
} // end func getAutoGrow
|
||||
|
||||
/**
|
||||
* Sets the number of rows in the table
|
||||
*
|
||||
* @param int $rows
|
||||
* @access public
|
||||
*/
|
||||
function setRowCount($rows)
|
||||
{
|
||||
$this->_rows = $rows;
|
||||
} // end func setRowCount
|
||||
|
||||
/**
|
||||
* Sets the number of columns in the table
|
||||
*
|
||||
* @param int $cols
|
||||
* @access public
|
||||
*/
|
||||
function setColCount($cols)
|
||||
{
|
||||
$this->_cols = $cols;
|
||||
} // end func setColCount
|
||||
|
||||
/**
|
||||
* Returns the number of rows in the table
|
||||
*
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getRowCount()
|
||||
{
|
||||
return $this->_rows;
|
||||
} // end func getRowCount
|
||||
|
||||
/**
|
||||
* Sets the number of columns in the table
|
||||
*
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
function getColCount()
|
||||
{
|
||||
return $this->_cols;
|
||||
} // end func getColCount
|
||||
|
||||
/**
|
||||
* Sets a rows type 'TH' or 'TD'
|
||||
*
|
||||
* @param int $row Row index
|
||||
* @param string $type 'TH' or 'TD'
|
||||
* @access public
|
||||
*/
|
||||
|
||||
function setRowType($row, $type)
|
||||
{
|
||||
for ($counter = 0; $counter < $this->_cols; $counter++) {
|
||||
$this->_structure[$row][$counter]["type"] = $type;
|
||||
}
|
||||
} // end func setRowType
|
||||
|
||||
/**
|
||||
* Sets a columns type 'TH' or 'TD'
|
||||
*
|
||||
* @param int $col Column index
|
||||
* @param string $type 'TH' or 'TD'
|
||||
* @access public
|
||||
*/
|
||||
function setColType($col, $type)
|
||||
{
|
||||
for ($counter = 0; $counter < $this->_rows; $counter++) {
|
||||
$this->_structure[$counter][$col]["type"] = $type;
|
||||
}
|
||||
} // end func setColType
|
||||
|
||||
/**
|
||||
* Sets the cell attributes for an existing cell.
|
||||
*
|
||||
* If the given indices do not exist and autoGrow is true then the given
|
||||
* row and/or col is automatically added. If autoGrow is false then an
|
||||
* error is returned.
|
||||
*
|
||||
* @param int $row Row index
|
||||
* @param int $col Column index
|
||||
* @param mixed $attributes Associative array or string of table row attributes
|
||||
* @access public
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function setCellAttributes($row, $col, $attributes)
|
||||
{
|
||||
if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == "__SPANNED__") return;
|
||||
$attributes = $this->_parseAttributes($attributes);
|
||||
$err = $this->_adjustEnds($row, $col, 'setCellAttributes', $attributes);
|
||||
if (PEAR::isError($err)) {
|
||||
return $err;
|
||||
}
|
||||
$this->_structure[$row][$col]["attr"] = $attributes;
|
||||
$this->_updateSpanGrid($row, $col);
|
||||
} // end func setCellAttributes
|
||||
|
||||
/**
|
||||
* Updates the cell attributes passed but leaves other existing attributes in tact
|
||||
*
|
||||
* @param int $row Row index
|
||||
* @param int $col Column index
|
||||
* @param mixed $attributes Associative array or string of table row attributes
|
||||
* @access public
|
||||
*/
|
||||
function updateCellAttributes($row, $col, $attributes)
|
||||
{
|
||||
if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == "__SPANNED__") return;
|
||||
$attributes = $this->_parseAttributes($attributes);
|
||||
$err = $this->_adjustEnds($row, $col, 'updateCellAttributes', $attributes);
|
||||
if (PEAR::isError($err)) {
|
||||
return $err;
|
||||
}
|
||||
$this->_updateAttrArray($this->_structure[$row][$col]["attr"], $attributes);
|
||||
$this->_updateSpanGrid($row, $col);
|
||||
} // end func updateCellAttributes
|
||||
|
||||
/**
|
||||
* Sets the cell contents for an existing cell
|
||||
*
|
||||
* If the given indices do not exist and autoGrow is true then the given
|
||||
* row and/or col is automatically added. If autoGrow is false then an
|
||||
* error is returned.
|
||||
*
|
||||
* @param int $row Row index
|
||||
* @param int $col Column index
|
||||
* @param mixed $contents May contain html or any object with a toHTML method
|
||||
* @param string $type (optional) Cell type either 'TH' or 'TD'
|
||||
* @access public
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function setCellContents($row, $col, $contents, $type = 'TD')
|
||||
{
|
||||
if(isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == "__SPANNED__") return;
|
||||
$err = $this->_adjustEnds($row, $col, 'setCellContents');
|
||||
if (PEAR::isError($err)) {
|
||||
return $err;
|
||||
}
|
||||
$this->_structure[$row][$col]["contents"] = $contents;
|
||||
$this->_structure[$row][$col]["type"] = $type;
|
||||
} // end func setCellContents
|
||||
|
||||
/**
|
||||
* Returns the cell contents for an existing cell
|
||||
*
|
||||
* @param int $row Row index
|
||||
* @param int $col Column index
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
function getCellContents($row, $col)
|
||||
{
|
||||
if (isset($this->_structure[$row][$col]) && $this->_structure[$row][$col] == "__SPANNED__") return;
|
||||
return $this->_structure[$row][$col]["contents"];
|
||||
} // end func getCellContents
|
||||
|
||||
/**
|
||||
* Sets the contents of a header cell
|
||||
*
|
||||
* @param int $row
|
||||
* @param int $col
|
||||
* @param mixed $contents
|
||||
* @access public
|
||||
*/
|
||||
function setHeaderContents($row, $col, $contents)
|
||||
{
|
||||
$this->setCellContents($row, $col, $contents, 'TH');
|
||||
} // end func setHeaderContents
|
||||
|
||||
/**
|
||||
* Adds a table row and returns the row identifier
|
||||
*
|
||||
* @param array $contents (optional) Must be a indexed array of valid cell contents
|
||||
* @param mixed $attributes (optional) Associative array or string of table row attributes
|
||||
* @param string $type (optional) Cell type either 'TH' or 'TD'
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
function addRow($contents = null, $attributes = null, $type = 'TD')
|
||||
{
|
||||
if (isset($contents) && !is_array($contents)) {
|
||||
return new PEAR_Error("First parameter to HTML_Table::addRow must be an array");
|
||||
}
|
||||
$row = $this->_rows++;
|
||||
for ($counter = 0; $counter < count($contents); $counter++) {
|
||||
if ($type == 'TD') {
|
||||
$this->setCellContents($row, $counter, $contents[$counter]);
|
||||
} elseif ($type == 'TH') {
|
||||
$this->setHeaderContents($row, $counter, $contents[$counter]);
|
||||
}
|
||||
}
|
||||
$this->setRowAttributes($row, $attributes);
|
||||
return $row;
|
||||
} // end func addRow
|
||||
|
||||
/**
|
||||
* Sets the row attributes for an existing row
|
||||
*
|
||||
* @param int $row Row index
|
||||
* @param mixed $attributes Associative array or string of table row attributes
|
||||
* @access public
|
||||
*/
|
||||
function setRowAttributes($row, $attributes)
|
||||
{
|
||||
for ($i = 0; $i < $this->_cols; $i++) {
|
||||
$this->setCellAttributes($row, $i, $attributes);
|
||||
}
|
||||
} // end func setRowAttributes
|
||||
|
||||
/**
|
||||
* Updates the row attributes for an existing row
|
||||
*
|
||||
* @param int $row Row index
|
||||
* @param mixed $attributes Associative array or string of table row attributes
|
||||
* @access public
|
||||
*/
|
||||
function updateRowAttributes($row, $attributes = null)
|
||||
{
|
||||
for ($i = 0; $i < $this->_cols; $i++) {
|
||||
$this->updateCellAttributes($row, $i, $attributes);
|
||||
}
|
||||
} // end func updateRowAttributes
|
||||
|
||||
/**
|
||||
* Alternates the row attributes starting at $start
|
||||
*
|
||||
* @param int $start Row index of row in which alternating begins
|
||||
* @param mixed $attributes1 Associative array or string of table row attributes
|
||||
* @param mixed $attribute2 Associative array or string of table row attributes
|
||||
* @access public
|
||||
*/
|
||||
function altRowAttributes($start, $attributes1, $attributes2)
|
||||
{
|
||||
for ($row = $start ; $row < $this->_rows ; $row++) {
|
||||
$attributes = ( ($row+$start)%2 == 0 ) ? $attributes1 : $attributes2;
|
||||
$this->updateRowAttributes($row, $attributes);
|
||||
}
|
||||
} // end func altRowAttributes
|
||||
|
||||
/**
|
||||
* Adds a table column and returns the column identifier
|
||||
*
|
||||
* @param array $contents (optional) Must be a indexed array of valid cell contents
|
||||
* @param mixed $attributes (optional) Associative array or string of table row attributes
|
||||
* @param string $type (optional) Cell type either 'TH' or 'TD'
|
||||
* @return int
|
||||
* @access public
|
||||
*/
|
||||
function addCol($contents = null, $attributes = null, $type = 'TD')
|
||||
{
|
||||
if (isset($contents) && !is_array($contents)) {
|
||||
return new PEAR_Error("First parameter to HTML_Table::addCol must be an array");
|
||||
}
|
||||
$col = $this->_cols++;
|
||||
for ($counter = 0; $counter < count($contents); $counter++) {
|
||||
$this->setCellContents($counter, $col, $contents[$counter], $type);
|
||||
}
|
||||
$this->setColAttributes($col, $attributes);
|
||||
return $col;
|
||||
} // end func addCol
|
||||
|
||||
/**
|
||||
* Sets the column attributes for an existing column
|
||||
*
|
||||
* @param int $col Column index
|
||||
* @param mixed $attributes (optional) Associative array or string of table row attributes
|
||||
* @access public
|
||||
*/
|
||||
function setColAttributes($col, $attributes = null)
|
||||
{
|
||||
for ($i = 0; $i < $this->_rows; $i++) {
|
||||
$this->setCellAttributes($i,$col,$attributes);
|
||||
}
|
||||
} // end func setColAttributes
|
||||
|
||||
/**
|
||||
* Updates the column attributes for an existing column
|
||||
*
|
||||
* @param int $col Column index
|
||||
* @param mixed $attributes (optional) Associative array or string of table row attributes
|
||||
* @access public
|
||||
*/
|
||||
function updateColAttributes($col, $attributes = null)
|
||||
{
|
||||
for ($i = 0; $i < $this->_rows; $i++) {
|
||||
$this->updateCellAttributes($i, $col, $attributes);
|
||||
}
|
||||
} // end func updateColAttributes
|
||||
|
||||
/**
|
||||
* Sets the attributes for all cells
|
||||
*
|
||||
* @param mixed $attributes (optional) Associative array or string of table row attributes
|
||||
* @since 1.6
|
||||
* @access public
|
||||
*/
|
||||
function setAllAttributes($attributes = null)
|
||||
{
|
||||
for ($i = 0; $i < $this->_rows; $i++) {
|
||||
$this->setRowAttributes($i, $attributes);
|
||||
}
|
||||
} // end func setAllAttributes
|
||||
|
||||
/**
|
||||
* Updates the attributes for all cells
|
||||
*
|
||||
* @param mixed $attributes (optional) Associative array or string of table row attributes
|
||||
* @since 1.6
|
||||
* @access public
|
||||
*/
|
||||
function updateAllAttributes($attributes = null)
|
||||
{
|
||||
for ($i = 0; $i < $this->_rows; $i++) {
|
||||
$this->updateRowAttributes($i, $attributes);
|
||||
}
|
||||
} // end func updateAllAttributes
|
||||
|
||||
/**
|
||||
* Returns the table structure as HTML
|
||||
*
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
function toHtml()
|
||||
{
|
||||
$tabs = $this->_getTabs();
|
||||
$strHtml =
|
||||
"\n" . $tabs . "<!-- BEGIN TABLE LEVEL: $this->_nestLevel -->\n";
|
||||
if ($this->_comment) {
|
||||
$strHtml .= $tabs . "<!-- $this->_comment -->\n";
|
||||
}
|
||||
$strHtml .=
|
||||
$tabs . "<table" . $this->_getAttrString($this->_attributes) . ">\n";
|
||||
if (!empty($this->_structure["caption"])) {
|
||||
$attr = $this->_structure["caption"]["attr"];
|
||||
$contents = $this->_structure["caption"]["contents"];
|
||||
$strHtml .= $tabs . "\t<caption" . $this->_getAttrString($attr) . ">";
|
||||
if (is_array($contents)) $contents = implode(", ", $contents);
|
||||
$strHtml .= $contents;
|
||||
$strHtml .= "</caption>\n";
|
||||
}
|
||||
for ($i = 0 ; $i < $this->_rows ; $i++) {
|
||||
$strHtml .= $tabs ."\t<tr>\n";
|
||||
for ($j = 0 ; $j < $this->_cols ; $j++) {
|
||||
if (isset($this -> _structure[$i][$j]) && $this->_structure[$i][$j] == "__SPANNED__") {
|
||||
$strHtml .= $tabs ."\t\t<!-- span -->\n";
|
||||
continue;
|
||||
}
|
||||
if (isset($this->_structure[$i][$j]["type"])) {
|
||||
$type = (strtoupper($this->_structure[$i][$j]["type"]) == "TH" ? "th" : "td");
|
||||
} else {
|
||||
$type = "td";
|
||||
}
|
||||
if (isset($this->_structure[$i][$j]["attr"])) {
|
||||
$attr = $this->_structure[$i][$j]["attr"];
|
||||
} else {
|
||||
$attr = "";
|
||||
}
|
||||
if (isset($this->_structure[$i][$j]["contents"])) {
|
||||
$contents = $this->_structure[$i][$j]["contents"];
|
||||
} else {
|
||||
$contents = "";
|
||||
}
|
||||
$flagCloseTable = false;
|
||||
$strHtml .= $tabs . "\t\t<$type" . $this->_getAttrString($attr) . ">";
|
||||
if (is_object($contents)) {
|
||||
if (is_subclass_of($contents, "html_common")) {
|
||||
$contents->setTabOffset($this->_tabOffset + 3);
|
||||
$contents->_nestLevel = $this->_nestLevel + 1;
|
||||
$flagCloseTable = true;
|
||||
}
|
||||
if (method_exists($contents, "toHtml")) {
|
||||
$contents = $contents->toHtml();
|
||||
} elseif (method_exists($contents, "toString")) {
|
||||
$contents = $contents->toString();
|
||||
}
|
||||
}
|
||||
if (is_array($contents))
|
||||
$contents = implode(", ",$contents);
|
||||
if (isset($this->_autoFill) && $contents == "")
|
||||
$contents = $this->_autoFill;
|
||||
$strHtml .= $contents;
|
||||
$strHtml .= (isset($flagCloseTable)) ? "\t\t" : '';
|
||||
$strHtml .= "</$type>\n";
|
||||
}
|
||||
$strHtml .= $tabs ."\t</tr>\n";
|
||||
}
|
||||
$strHtml .=
|
||||
$tabs . "</table>\n". $tabs . "<!-- END TABLE LEVEL: $this->_nestLevel -->\n";
|
||||
return $strHtml;
|
||||
} // end func toHtml
|
||||
|
||||
/**
|
||||
* Checks if rows or columns are spanned
|
||||
*
|
||||
* @param int $row Row index
|
||||
* @param int $col Column index
|
||||
* @access private
|
||||
*/
|
||||
function _updateSpanGrid($row, $col)
|
||||
{
|
||||
if (isset($this->_structure[$row][$col]["attr"]["colspan"])) {
|
||||
$colspan = $this->_structure[$row][$col]["attr"]["colspan"];
|
||||
}
|
||||
if (isset($this->_structure[$row][$col]["attr"]["rowspan"])) {
|
||||
$rowspan = $this->_structure[$row][$col]["attr"]["rowspan"];
|
||||
}
|
||||
if (isset($colspan)) {
|
||||
for ($j = $col+1; (($j < $this->_cols) && ($j <= ($col + $colspan - 1))); $j++) {
|
||||
$this->_structure[$row][$j] = "__SPANNED__";
|
||||
}
|
||||
}
|
||||
if (isset($rowspan)) {
|
||||
for ($i = $row+1; (($i < $this->_rows) && ($i <= ($row + $rowspan - 1))); $i++) {
|
||||
$this->_structure[$i][$col] = "__SPANNED__";
|
||||
}
|
||||
}
|
||||
if (isset($colspan) && isset($rowspan)) {
|
||||
for ($i = $row+1; (($i < $this->_rows) && ($i <= ($row + $rowspan - 1))); $i++) {
|
||||
for ($j = $col+1; (($j <= $this->_cols) && ($j <= ($col + $colspan - 1))); $j++) {
|
||||
$this->_structure[$i][$j] = "__SPANNED__";
|
||||
}
|
||||
}
|
||||
}
|
||||
} // end func _updateSpanGrid
|
||||
|
||||
/**
|
||||
* Adjusts ends (total number of rows and columns)
|
||||
*
|
||||
* @param int $row Row index
|
||||
* @param int $col Column index
|
||||
* @param string $method Method name of caller
|
||||
* Used to populate PEAR_Error if thrown.
|
||||
* @param array $attributes Assoc array of attributes
|
||||
* Default is an empty array.
|
||||
* @access private
|
||||
* @throws PEAR_Error
|
||||
*/
|
||||
function _adjustEnds($row, $col, $method, $attributes = array())
|
||||
{
|
||||
$colspan = isset($attributes['colspan']) ? $attributes['colspan'] : 1;
|
||||
$rowspan = isset($attributes['rowspan']) ? $attributes['rowspan'] : 1;
|
||||
if (($row + $rowspan - 1) >= $this->_rows) {
|
||||
if ($this->_autoGrow) {
|
||||
$this->_rows = $row + $rowspan;
|
||||
} else {
|
||||
return new PEAR_Error('Invalid table row reference[' .
|
||||
$row . '] in HTML_Table::' . $method);
|
||||
}
|
||||
}
|
||||
if (($col + $colspan - 1) >= $this->_cols) {
|
||||
if ($this->_autoGrow) {
|
||||
$this->_cols = $col + $colspan;
|
||||
} else {
|
||||
return new PEAR_Error('Invalid table column reference[' .
|
||||
$col . '] in HTML_Table::' . $method);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // end class HTML_Table
|
||||
?>
|
||||
Reference in New Issue
Block a user