php-html-common-1.2.5/0000755000175000017500000000000011315712033013234 5ustar zigozigophp-html-common-1.2.5/HTML_Common-1.2.5/0000755000175000017500000000000011315712013015747 5ustar zigozigophp-html-common-1.2.5/HTML_Common-1.2.5/Common.php0000644000175000017500000003141511165425310017720 0ustar zigozigo * @copyright 2001-2009 The PHP Group * @license http://www.php.net/license/3_01.txt PHP License 3.01 * @version CVS: $Id: Common.php,v 1.15 2009/04/03 15:26:22 avb Exp $ * @link http://pear.php.net/package/HTML_Common/ */ /** * Base class for all HTML classes * * @category HTML * @package HTML_Common * @author Adam Daniel * @version Release: 1.2.5 * @abstract */ class HTML_Common { /** * Associative array of attributes * @var array * @access private */ var $_attributes = array(); /** * Tab offset of the tag * @var int * @access private */ var $_tabOffset = 0; /** * Tab string * @var string * @since 1.7 * @access private */ var $_tab = "\11"; /** * Contains the line end string * @var string * @since 1.7 * @access private */ var $_lineEnd = "\12"; /** * 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 * @param int $tabOffset Indent offset in tabs * @access public */ function HTML_Common($attributes = null, $tabOffset = 0) { $this->setAttributes($attributes); $this->setTabOffset($tabOffset); } // end constructor /** * Returns the current API version * @access public * @returns double */ function apiVersion() { return 1.7; } // end func apiVersion /** * Returns the lineEnd * * @since 1.7 * @access private * @return string */ function _getLineEnd() { return $this->_lineEnd; } // end func getLineEnd /** * Returns a string containing the unit for indenting HTML * * @since 1.7 * @access private * @return string */ function _getTab() { return $this->_tab; } // end func _getTab /** * Returns a string containing the offset for the whole HTML code * * @return string * @access private */ function _getTabs() { return str_repeat($this->_getTab(), $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)) { $charset = HTML_Common::charset(); foreach ($attributes as $key => $value) { $strAttr .= ' ' . $key . '="' . htmlspecialchars($value, ENT_COMPAT, $charset) . '"'; } } 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 * @return array */ function _parseAttributes($attributes) { if (is_array($attributes)) { $ret = array(); foreach ($attributes as $key => $value) { if (is_int($key)) { $key = $value = strtolower($value); } else { $key = strtolower($key); } $ret[$key] = $value; } return $ret; } 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)) { for ($counter=0; $counter $value) { $attr1[$key] = $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 private * @return void */ function _removeAttr($attr, &$attributes) { $attr = strtolower($attr); if (isset($attributes[$attr])) { unset($attributes[$attr]); } } //end func _removeAttr /** * Returns the value of the given attribute * * @param string $attr Attribute name * @since 1.5 * @access public * @return string|null returns null if an attribute does not exist */ function getAttribute($attr) { $attr = strtolower($attr); if (isset($this->_attributes[$attr])) { return $this->_attributes[$attr]; } return null; } //end func getAttribute /** * Sets the value of the attribute * * @param string Attribute name * @param string Attribute value (will be set to $name if omitted) * @access public */ function setAttribute($name, $value = null) { $name = strtolower($name); if (is_null($value)) { $value = $name; } $this->_attributes[$name] = $value; } // end func setAttribute /** * 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 the assoc array (default) or string of attributes * * @param bool Whether to return the attributes as string * @since 1.6 * @access public * @return mixed attributes */ function getAttributes($asString = false) { if ($asString) { return $this->_getAttrString($this->_attributes); } else { 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) { $this->_updateAttrArray($this->_attributes, $this->_parseAttributes($attributes)); } // end func updateAttributes /** * Removes an attribute * * @param string $attr Attribute name * @since 1.4 * @access public * @return void */ function removeAttribute($attr) { $this->_removeAttr($attr, $this->_attributes); } //end func removeAttribute /** * Sets the line end style to Windows, Mac, Unix or a custom string. * * @param string $style "win", "mac", "unix" or custom string. * @since 1.7 * @access public * @return void */ function setLineEnd($style) { switch ($style) { case 'win': $this->_lineEnd = "\15\12"; break; case 'unix': $this->_lineEnd = "\12"; break; case 'mac': $this->_lineEnd = "\15"; break; default: $this->_lineEnd = $style; } } // end func setLineEnd /** * 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 int */ function getTabOffset() { return $this->_tabOffset; } //end func getTabOffset /** * Sets the string used to indent HTML * * @since 1.7 * @param string $string String used to indent ("\11", "\t", ' ', etc.). * @access public * @return void */ function setTab($string) { $this->_tab = $string; } // end func setTab /** * Sets the HTML comment to be displayed at the beginning of the HTML string * * @param string * @since 1.4 * @access public * @return void */ function setComment($comment) { $this->_comment = $comment; } // end func setHtmlComment /** * Returns the HTML comment * * @since 1.5 * @access public * @return string */ 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 /** * Sets the charset to use by htmlspecialchars() function * * Since this parameter is expected to be global, the function is designed * to be called statically: * * HTML_Common::charset('utf-8'); * * or * * $charset = HTML_Common::charset(); * * * @param string New charset to use. Omit if just getting the * current value. Consult the htmlspecialchars() docs * for a list of supported character sets. * @return string Current charset * @access public * @static */ function charset($newCharset = null) { static $charset = 'ISO-8859-1'; if (!is_null($newCharset)) { $charset = $newCharset; } return $charset; } // end func charset } // end class HTML_Common ?> php-html-common-1.2.5/package.xml0000644000175000017500000001253611165425310015362 0ustar zigozigo HTML_Common pear.php.net PEAR::HTML_Common is a base class for other HTML classes. The PEAR::HTML_Common package provides methods for html code display and attributes handling. * Methods to set, remove, update html attributes. * Handles comments in HTML code. * Handles layout, tabs, line endings for nicer HTML code. Klaus Guenther thesaur thesaur@php.net no Alexey Borzov avb avb@php.net yes Bertrand Mansion mansion bmansion@mamasam.com yes Adam Daniel adaniel adaniel1@eesus.jnj.com no 2009-04-03 1.2.5 1.2.3 stable stable PHP License Whitespace is no longer trimmed from quoted attribute values in _parseAttribute() method (bug #15787) 4.0.4 1.4.3 1.2.4 1.2.3 stable stable 2007-05-16 PHP License Migrate to package.xml version 2.0, use proper header comment block. No code changes since previous release. 1.2.3 1.2.3 stable stable 2006-10-08 PHP License * Added setAttribute() method (backport from HTML_Common2) * Added possibility to set the charset parameter for htmlspecialchars() via static HTML_Common::charset() method (see bug #2410) * Properly document getAttribute() method (bug #5704), fix PHPDoc comments for several other methods 1.2.2 1.2.2 stable stable 2005-09-01 PHP License Bugfix release - fixed bug #3948 (semicolon after case in switch) - fixed bug #3953 (outdated inline docs for a private function) - updated some other inline docs for private functions 1.2.1 1.2.1 stable stable 2003-06-19 PHP License * Method getAttributes() can now return the attributes in a string (Alexey Borzov) 1.2 1.2 stable stable 2003-05-20 PHP License Applied patch by Klaus Guenther: * setTab(): Allows the indent string (default: \t) to be set * setLineEnd(): Allows the line end string (default: \n) to be set * Allows the indent and line ending settings to be propagated to content objects 1.1 1.1 stable stable 2003-04-15 PHP License This new release optimizes HTML_Common's way to deal with attributes. * Fix a bug in _parseAttributes when a string was passed to it (Alexey Borzov) * Only key-value associative arrays are now used, XHTML compliant (Alexey Borzov) * Fix a bug related to getAttribute case sensitivity detected by Ian Harder #22628 (Alexey Borzov) 1.0 1.0 stable stable 2002-05-28 PHP License First release.