diff --git a/HtmlTag.inc b/HtmlTag.inc index 3b4305e..d7e3e8d 100644 --- a/HtmlTag.inc +++ b/HtmlTag.inc @@ -11,12 +11,12 @@ * Racine du dossier contenant les classes HtmlTag * Root folder constant of HtmlTag classes package */ -define('ROOT_PATH',realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR); +define('HTML_TAG_ROOT_PATH',realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR); /** * Chemin d'accès au dossier du module HTML * Path to HtmlTag folder */ -define('HTML_TAG_PATH',ROOT_PATH . 'htmltag' . DIRECTORY_SEPARATOR); +define('HTML_TAG_PATH',HTML_TAG_ROOT_PATH . 'HtmlTag' . DIRECTORY_SEPARATOR); /** * Chemin d'accès au dossier PHP du module HTML * Path to Htmltag PHP classes @@ -26,10 +26,12 @@ define('HTML_TAG_PHP_PATH',HTML_TAG_PATH . 'PHP' . DIRECTORY_SEPARATOR); * Force la définition des id sur tout élément HTML généré * Enables the definition of the attribute named "id" for every htmltag and avoid double ids */ -define('HTML_TAG_DEFINE_ID',false); +if(!defined('HTML_TAG_DEFINE_ID')) + define('HTML_TAG_DEFINE_ID',false); /** * Force la non suppression des commentaires de templates * Enables the fact to keep comments in templates */ -define('HTML_TAG_KEEP_COMMENTS',true); +if(!defined('HTML_TAG_KEEP_COMMENTS')) + define('HTML_TAG_KEEP_COMMENTS',false); ?> \ No newline at end of file diff --git a/PHP/HtmlTag.php b/PHP/HtmlTag.php index d23b424..888d576 100644 --- a/PHP/HtmlTag.php +++ b/PHP/HtmlTag.php @@ -106,13 +106,465 @@ class HtmlTag * Array containing all valid tag name * @var array */ - private static $validTagsName = array('a'=>'','abbr'=>'','acronym'=>'','address'=>'','area'=>'','b'=>'','base'=>'','bdo'=>'','big'=>'','blockquote'=>'','body'=>'','br'=>'','button'=>'','caption'=>'','cite'=>'','code'=>'','col'=>'','colgroup'=>'','dd'=>'','del'=>'','dfn'=>'','div'=>'','dl'=>'','DOCTYPE'=>'','dt'=>'','em'=>'','fieldset'=>'','font'=>'','form'=>'','h1'=>'','h2'=>'','h3'=>'','h4'=>'','h5'=>'','h6'=>'','head'=>'','html'=>'','hr'=>'','i'=>'','img'=>'','input'=>'','ins'=>'','kbd'=>'','label'=>'','legend'=>'','li'=>'','link'=>'','list'=>'','map'=>'','meta'=>'','noscript'=>'','object'=>'','ol'=>'','optgroup'=>'','option'=>'','p'=>'','param'=>'','pre'=>'','q'=>'','samp'=>'','script'=>'','select'=>'','small'=>'','span'=>'','strong'=>'','style'=>'','sub'=>'','sup'=>'','table'=>'','tbody'=>'','td'=>'','textarea'=>'','tfoot'=>'','th'=>'','thead'=>'','title'=>'','tr'=>'','tt'=>'','ul'=>'','var'=>''); + private static $validTagsName = array( + 'DOCTYPE'=>'', + 'a'=>'', + 'abbr'=>'', + 'acronym'=>'', + 'address'=>'', + 'area'=>'', + 'b'=>'', + 'base'=>'', + 'bdo'=>'', + 'big'=>'', + 'blockquote'=>'', + 'body'=>'', + 'br'=>'', + 'button'=>'', + 'caption'=>'', + 'cite'=>'', + 'code'=>'', + 'col'=>'', + 'colgroup'=>'', + 'dd'=>'', + 'del'=>'', + 'dfn'=>'', + 'div'=>'', + 'dl'=>'', + 'dt'=>'', + 'em'=>'', + 'embed'=>'', + 'fieldset'=>'', + 'font'=>'', + 'form'=>'', + 'frame'=>'', + 'h1'=>'', + 'h2'=>'', + 'h3'=>'', + 'h4'=>'', + 'h5'=>'', + 'h6'=>'', + 'head'=>'', + 'hr'=>'', + 'html'=>'', + 'i'=>'', + 'iframe'=>'', + 'img'=>'', + 'input'=>'', + 'ins'=>'', + 'kbd'=>'', + 'label'=>'', + 'legend'=>'', + 'li'=>'', + 'link'=>'', + 'list'=>'', + 'map'=>'', + 'meta'=>'', + 'noscript'=>'', + 'object'=>'', + 'ol'=>'', + 'optgroup'=>'', + 'option'=>'', + 'p'=>'', + 'param'=>'', + 'pre'=>'', + 'q'=>'', + 'samp'=>'', + 'script'=>'', + 'select'=>'', + 'small'=>'', + 'span'=>'', + 'strong'=>'', + 'style'=>'', + 'sub'=>'', + 'sup'=>'', + 'table'=>'', + 'tbody'=>'', + 'td'=>'', + 'textarea'=>'', + 'tfoot'=>'', + 'th'=>'', + 'thead'=>'', + 'title'=>'', + 'tr'=>'', + 'tt'=>'', + 'u'=>'', + 'ul'=>'', + 'var'=>''); /** * Tabelau des attributs html valides * Array containing all valid attributes and some specific * @var array */ - private static $validAttributesName = array('abbr'=>'','about'=>'','accesskey'=>'','action'=>'','archive'=>'','alt'=>'','autocomplete'=>'','axis'=>'','charset'=>'','checked'=>'','cite'=>'','class'=>'','cols'=>'','colspan'=>'','content-length'=>'','content'=>'','coords'=>'','datatype'=>'','datetime'=>'','declare'=>'','defaultAction'=>'','dir'=>'','disabled'=>'','edit'=>'','enctype'=>'','encoding'=>'','event'=>'','for'=>'','full'=>'','handler'=>'','headers'=>'','height'=>'','href'=>'','hreflang'=>'','hrefmedia'=>'','hreftype'=>'','http-equiv'=>'','id'=>'','ismap'=>'','key'=>'','label'=>'','layout'=>'','lang'=>'','media'=>'','method'=>'','name'=>'','nextfocus'=>'','observer'=>'','onblur'=>'','onchange'=>'','onclick'=>'','onfocus'=>'','onkeypress'=>'','onkeyup'=>'','onkeydown'=>'','onmousedown'=>'','onmousemove'=>'','onmouseover'=>'','onmouseout'=>'','onmouseup'=>'','onsubmit'=>'','phase'=>'','prevfocus'=>'','propagate'=>'','property'=>'','rel'=>'','repeat-bind'=>'','repeat-model'=>'','repeat-nodeset'=>'','repeat-number'=>'','repeat-startindex'=>'','rev'=>'','readonly'=>'','role'=>'','rows'=>'','rowspan'=>'','scope'=>'','selected'=>'','shape'=>'','span'=>'','src'=>'','srctype'=>'','style'=>'','tabindex'=>'','target'=>'','targetid'=>'','targetrole'=>'','title'=>'','type'=>'','usemap'=>'','value'=>'','valuetype'=>'','version'=>'','width'=>'','xmlns'=>'','xml:base'=>'','xml:id'=>'','xml:lang'=>'','xsi:schemaLocation'=>''); + private static $validAttributesName = array( + 'ATOMICSELECTION'=>'', + 'abbr'=>'', + 'about'=>'', + 'accept'=>'', + 'acceptCharset'=>'', + 'accessKey'=>'', + 'accesskey'=>'', + 'action'=>'', + 'activeElement'=>'', + 'ActiveXObject'=>'', + 'align'=>'', + 'aLink'=>'', + 'alinkColor'=>'', + 'all'=>'', + 'allowfullscreen'=>'', + 'allowscriptaccess'=>'', + 'allowTransparency'=>'', + 'alt'=>'', + 'altHtml'=>'', + 'anchorNode'=>'', + 'anchorOffset'=>'', + 'anchors'=>'', + 'applets'=>'', + 'archive'=>'', + 'async'=>'', + 'attributes'=>'', + 'autocomplete'=>'', + 'autofocus'=>'', + 'axis'=>'', + 'background'=>'', + 'balance'=>'', + 'BaseHref'=>'', + 'BGCOLOR'=>'', + 'bgcolor'=>'', + 'bgProperties'=>'', + 'body'=>'', + 'border'=>'', + 'borderColor'=>'', + 'borderColorDark'=>'', + 'borderColorLight'=>'', + 'bottom'=>'', + 'bottomMargin'=>'', + 'boundElements'=>'', + 'browserLanguage'=>'', + 'canHaveChildren'=>'', + 'canHaveHTML'=>'', + 'caption'=>'', + 'cellIndex'=>'', + 'cellPadding'=>'', + 'cellpadding'=>'', + 'cells'=>'', + 'cellSpacing'=>'', + 'cellspacing'=>'', + 'ch'=>'', + 'characterSet'=>'', + 'charset'=>'', + 'checked'=>'', + 'children'=>'', + 'chOff'=>'', + 'cite'=>'', + 'class'=>'', + 'classid'=>'', + 'className'=>'', + 'clear'=>'', + 'clientHeight'=>'', + 'clientLeft'=>'', + 'clientTop'=>'', + 'clientWidth'=>'', + 'color'=>'', + 'cols'=>'', + 'colSpan'=>'', + 'colspan'=>'', + 'compact'=>'', + 'compatible'=>'', + 'compatMode'=>'', + 'complete'=>'', + 'content'=>'', + 'contentDocument'=>'', + 'contentEditable'=>'', + 'content-length'=>'', + 'contentWindow'=>'', + 'controlRange'=>'', + 'cookie'=>'', + 'coords'=>'', + 'Count'=>'', + 'customError'=>'', + 'data'=>'', + 'dataFld'=>'', + 'dataFormatAs'=>'', + 'dataPageSize'=>'', + 'dataSrc'=>'', + 'datatype'=>'', + 'datetime'=>'', + 'declare'=>'', + 'defaultAction'=>'', + 'defaultCharset'=>'', + 'defaultChecked'=>'', + 'defaultSelected'=>'', + 'defaultValue'=>'', + 'defaultView'=>'', + 'defer'=>'', + 'designMode'=>'', + 'dir'=>'', + 'disabled'=>'', + 'doctype'=>'', + 'document'=>'', + 'documentElement'=>'', + 'documentMode'=>'', + 'domain'=>'', + 'draggable'=>'', + 'dropEffect'=>'', + 'edit'=>'', + 'effectAllowed'=>'', + 'elements'=>'', + 'embeds'=>'', + 'encoding'=>'', + 'enctype'=>'', + 'event'=>'', + 'face'=>'', + 'fgColor'=>'', + 'FieldDelim'=>'', + 'fileCreatedDate'=>'', + 'fileModifiedDate'=>'', + 'files'=>'', + 'fileSize'=>'', + 'fileUpdatedDate'=>'', + 'flashvars'=>'', + 'focusNode'=>'', + 'focusOffset'=>'', + 'for'=>'', + 'form'=>'', + 'formAction'=>'', + 'formEnctype'=>'', + 'formMethod'=>'', + 'formNoValidate'=>'', + 'forms'=>'', + 'formTarget'=>'', + 'frame'=>'', + 'frameBorder'=>'', + 'frameElement'=>'', + 'frames'=>'', + 'frameSpacing'=>'', + 'full'=>'', + 'handler'=>'', + 'head'=>'', + 'headers'=>'', + 'headers'=>'', + 'height'=>'', + 'hidden'=>'', + 'hideFocus'=>'', + 'href'=>'', + 'hreflang'=>'', + 'hrefmedia'=>'', + 'hreftype'=>'', + 'hspace'=>'', + 'htmlFor'=>'', + 'httpEquiv'=>'', + 'http-equiv'=>'', + 'id'=>'', + 'id'=>'', + 'images'=>'', + 'implementation'=>'', + 'indeterminate'=>'', + 'index'=>'', + 'innerHTML'=>'', + 'innerText'=>'', + 'isCollapsed'=>'', + 'isContentEditable'=>'', + 'isDisabled'=>'', + 'isMap'=>'', + 'ismap'=>'', + 'isMultiLine'=>'', + 'isOpen'=>'', + 'key'=>'', + 'label'=>'', + 'label'=>'', + 'lang'=>'', + 'lang'=>'', + 'language'=>'', + 'lastModified'=>'', + 'layout'=>'', + 'leftMargin'=>'', + 'length'=>'', + 'link'=>'', + 'linkColor'=>'', + 'links'=>'', + 'list'=>'', + 'longDesc'=>'', + 'loop'=>'', + 'lowsrc'=>'', + 'marginHeight'=>'', + 'marginWidth'=>'', + 'max'=>'', + 'maxConnectionsPerServer'=>'', + 'maxLength'=>'', + 'maxlength'=>'', + 'media'=>'', + 'method'=>'', + 'Methods'=>'', + 'min'=>'', + 'minlength'=>'', + 'msHidden'=>'', + 'msVisibilityState'=>'', + 'multiple'=>'', + 'name'=>'', + 'naturalHeight'=>'', + 'naturalWidth'=>'', + 'nextfocus'=>'', + 'noHref'=>'', + 'noResize'=>'', + 'noShade'=>'', + 'noValidate'=>'', + 'noWrap'=>'', + 'object'=>'', + 'observer'=>'', + 'offscreenBuffering'=>'', + 'offsetHeight'=>'', + 'offsetLeft'=>'', + 'offsetParent'=>'', + 'offsetTop'=>'', + 'offsetWidth'=>'', + 'onblur'=>'', + 'onchange'=>'', + 'onclick'=>'', + 'onfocus'=>'', + 'onkeydown'=>'', + 'onkeypress'=>'', + 'onkeyup'=>'', + 'onLine'=>'', + 'onmousedown'=>'', + 'onmousemove'=>'', + 'onmouseout'=>'', + 'onmouseover'=>'', + 'onmouseup'=>'', + 'onsubmit'=>'', + 'options'=>'', + 'outerHTML'=>'', + 'outerText'=>'', + 'palette'=>'', + 'parentWindow'=>'', + 'pathname'=>'', + 'pattern'=>'', + 'patternMismatch'=>'', + 'phase'=>'', + 'placeholder'=>'', + 'pluginspace'=>'', + 'pluginspage'=>'', + 'position'=>'', + 'prevfocus'=>'', + 'propagate'=>'', + 'property'=>'', + 'rangeCount'=>'', + 'rangeOverflow'=>'', + 'rangeUnderflow'=>'', + 'readOnly'=>'', + 'readonly'=>'', + 'readyState'=>'', + 'referrer'=>'', + 'rel'=>'', + 'repeat-bind'=>'', + 'repeat-model'=>'', + 'repeat-nodeset'=>'', + 'repeat-number'=>'', + 'repeat-startindex'=>'', + 'required'=>'', + 'rev'=>'', + 'rightMargin'=>'', + 'role'=>'', + 'rowIndex'=>'', + 'rows'=>'', + 'rowSpan'=>'', + 'rowspan'=>'', + 'rules'=>'', + 'sandbox'=>'', + 'scheme'=>'', + 'scope'=>'', + 'screenLeft'=>'', + 'screenTop'=>'', + 'scripts'=>'', + 'scroll'=>'', + 'scrollHeight'=>'', + 'scrolling'=>'', + 'scrollLeft'=>'', + 'scrollTop'=>'', + 'scrollWidth'=>'', + 'sectionRowIndex'=>'', + 'SECURITY'=>'', + 'selected'=>'', + 'selected'=>'', + 'selectedIndex'=>'', + 'selectionEnd'=>'', + 'selectionStart'=>'', + 'self'=>'', + 'shape'=>'', + 'size'=>'', + 'sourceIndex'=>'', + 'span'=>'', + 'specified'=>'', + 'spellcheck'=>'', + 'src'=>'', + 'srctype'=>'', + 'standby'=>'', + 'start'=>'', + 'status'=>'', + 'step'=>'', + 'stepMismatch'=>'', + 'STYLE'=>'', + 'style'=>'', + 'summary'=>'', + 'tabIndex'=>'', + 'tabindex'=>'', + 'tabStop'=>'', + 'tagName'=>'', + 'tagUrn'=>'', + 'target'=>'', + 'target'=>'', + 'targetid'=>'', + 'targetrole'=>'', + 'tBodies'=>'', + 'text'=>'', + 'tFoot'=>'', + 'tHead'=>'', + 'title'=>'', + 'tooLong'=>'', + 'top'=>'', + 'topMargin'=>'', + 'type'=>'', + 'type'=>'', + 'typeMismatch'=>'', + 'uniqueID'=>'', + 'uniqueNumber'=>'', + 'units'=>'', + 'URL'=>'', + 'url'=>'', + 'URLUnencoded'=>'', + 'urn'=>'', + 'useMap'=>'', + 'usemap'=>'', + 'userAgent'=>'', + 'valid'=>'', + 'validationMessage'=>'', + 'validity'=>'', + 'vAlign'=>'', + 'value'=>'', + 'valueAsNumber'=>'', + 'valueMissing'=>'', + 'valueType'=>'', + 'valuetype'=>'', + 'vcard_name'=>'', + 'version'=>'', + 'version'=>'', + 'viewLink'=>'', + 'viewMasterTab'=>'', + 'vLink'=>'', + 'vlinkColor'=>'', + 'volume'=>'', + 'vrml'=>'', + 'vspace'=>'', + 'width'=>'', + 'width'=>'', + 'willValidate'=>'', + 'wmode'=>'', + 'wrap'=>'', + 'xml:base'=>'', + 'xml:id'=>'', + 'xml:lang'=>'', + 'xmlns'=>'', + 'xsi:schemaLocation'=>''); /** * Constructeur de la classe / Class constructor * @@ -130,9 +582,10 @@ class HtmlTag * @param string lang du document / document language * @param string encodage du document / document encoding * @param string reset du domDocument / allows to reset the DOMDocument and the root HTML element + * @param DOMDocumentType * @return HtmlTag */ - public function __construct($_tagName,$_lang = null,$_encoding = HtmlTag::DEFAULT_ENCODING,$_reset = false) + public function __construct($_tagName,$_lang = null,$_encoding = HtmlTag::DEFAULT_ENCODING,$_reset = false,$_doctype = null) { /** * Initialisation dans tous les cas du DOMDocument @@ -143,8 +596,9 @@ public function __construct($_tagName,$_lang = null,$_encoding = HtmlTag::DEFAUL * Création du document général * DOMDocument creation */ - $doctype = DOMImplementation::createDocumentType(HtmlTag::DOCTYPE_ROOT_TAG,HtmlTag::DOCTYPE_DEFINITION,HtmlTag::DOCTYPE_URL); - HtmlTag::$domDocument = DOMImplementation::createDocument(null,null,$doctype); + $domImplementation = new DOMImplementation(); + $doctype = ($_doctype instanceof DOMDocumentType)?$domImplementation->createDocumentType($_doctype->name,$_doctype->publicId,$_doctype->systemId):$domImplementation->createDocumentType(HtmlTag::DOCTYPE_ROOT_TAG,HtmlTag::DOCTYPE_DEFINITION,HtmlTag::DOCTYPE_URL); + HtmlTag::$domDocument = $domImplementation->createDocument(null,null,$doctype); HtmlTag::$domDocument->preserveWhiteSpace = false; HtmlTag::$domDocument->formatOutput = true; HtmlTag::$domDocument->substituteEntities = true; @@ -198,7 +652,9 @@ public static function loadDomDocument($_fileContent,$_resetDomDocument = false, { if(trim($_fileContent) != '') { - $fileContent = str_replace(array('&','&'),'&',trim($_fileContent)); + $fileContent = str_replace(array( + '&', + '&'),'&',trim($_fileContent)); if(strpos($fileContent,'' . "\r\n" . $fileContent; if(!empty($fileContent)) @@ -211,7 +667,20 @@ public static function loadDomDocument($_fileContent,$_resetDomDocument = false, HtmlTag::$domDocument = null; HtmlTag::$htmlDocument = null; HtmlTag::$declaredIds = array(); - new HtmlTag('',null,$_encodingDocument); + /** + * On tente de récupére la langue déclarer sur la balise html + * We try to get the language defined on the html tag + */ + $lang = null; + if($domDocument->getElementsByTagName('html')->length) + { + $html = $domDocument->getElementsByTagName('html')->item(0); + if($html->hasAttribute('xml:lang')) + $lang = $html->getAttribute('xml:lang'); + elseif($html->hasAttribute('xml:lang')) + $lang = $html->getAttribute('lang'); + } + new HtmlTag('',$lang,$_encodingDocument,$_resetDomDocument,$domDocument->doctype); } /** * Tentative de récupération de la partie head @@ -451,13 +920,19 @@ public static function createA($_href,$_anchor,$_attributes = null,$_addtoHtml = public static function &createTag($_tagName,array $_tagAttributes = array(),$_tagType = null,$_addTagTo = null) { $htmlTagObject = null; - if(is_string($_tagName) && class_exists(HtmlTag::__className() . ucfirst(strtolower($_tagName)))) + if(is_string($_tagName)) { - $htmlTagObjectName = HtmlTag::__className() . ucfirst(strtolower($_tagName)); - if(isset($_tagType) && is_scalar($_tagType) && !empty($_tagType)) - $htmlTagObject = new $htmlTagObjectName($_tagType); + $_tagName = trim($_tagName); + if(class_exists(HtmlTag::__className() . ucfirst(strtolower($_tagName)))) + { + $htmlTagObjectName = HtmlTag::__className() . ucfirst(strtolower($_tagName)); + if(isset($_tagType) && is_scalar($_tagType) && !empty($_tagType)) + $htmlTagObject = new $htmlTagObjectName($_tagType); + else + $htmlTagObject = new $htmlTagObjectName(); + } else - $htmlTagObject = new $htmlTagObjectName(); + $htmlTagObject = new HtmlTag($_tagName); if($htmlTagObject->getTagName() == $_tagName) { if(count($_tagAttributes) > 0) @@ -465,8 +940,6 @@ public static function &createTag($_tagName,array $_tagAttributes = array(),$_ta if($htmlTagObject->getDomElement() && ($_addTagTo instanceof HtmlTag)) $_addTagTo->setValue($htmlTagObject); } - else - $htmlTagObject = null; } return $htmlTagObject; } @@ -506,7 +979,9 @@ public function toXml($_sendHeader = false) { if($_sendHeader && !headers_sent()) header('Content-Type: application/xhtml+xml'); - return '' . "\r\n" . str_replace(array('&','&'),'&',$this->toHtml(false)); + return '' . "\r\n" . str_replace(array( + '&', + '&'),'&',$this->toHtml(false)); } else return ''; @@ -553,7 +1028,9 @@ public static function displayFullXml($_sendHeader = false) { if($_sendHeader && !headers_sent()) header('Content-Type: application/xhtml+xml'); - return str_replace(array('&','&'),'&',HtmlTag::displayFullHtml(false)); + return str_replace(array( + '&', + '&'),'&',HtmlTag::displayFullHtml(false)); } else return ''; @@ -618,7 +1095,34 @@ public function addAttribute($_attributeName,$_attributeValue,$_specificAttribut } } else - $attributeValue = $_attributeValue; + { + switch($_attributeName) + { + case 'href': + case 'src': + $attributeValue = trim(str_replace(array( + '%2F', + /*'%2B',*/ + '%23', + '%3A', + '%3F', + '%3D', + '%3B', + '%26'),array( + '/', + /*'+',*/ + '#', + ':', + '?', + '=', + '&', + '&'),rawurlencode(rawurldecode($_attributeValue)))); + break; + default: + $attributeValue = $_attributeValue; + break; + } + } /** * Appel de la méthode propre à l'attribut si existante * et si cette méthode n'est pas appelée depuis la méthode propre à l'attribut @@ -1317,8 +1821,11 @@ private function setTagName($_tagName) case 'DOCTYPE': case 'dt': case 'em': + case 'embed': case 'fieldset': + case 'font': case 'form': + case 'frame': case 'h1': case 'h2': case 'h3': @@ -1328,6 +1835,7 @@ private function setTagName($_tagName) case 'head': case 'html': case 'i': + case 'iframe': case 'ins': case 'kbd': case 'label': @@ -1362,6 +1870,7 @@ private function setTagName($_tagName) case 'tr': case 'tt': case 'ul': + case 'u': case 'samp': case 'var': $this->setHasInnerHtml(true); @@ -1399,14 +1908,14 @@ public static function attributeIsValid($_attributeName) return (is_string($_attributeName) && array_key_exists($_attributeName,HtmlTag::getValidAttributesName())); } /** - * Méthode permettant de déclarer des attributs HTML valides en plus de ceux par défaut - * Method to add valid/specific attribute names + * Méthode permettant de déclarer un attribut HTML valide en plus de ceux par défaut + * Method to add valid/specific attribute name * - * @param string nom de l'attribute + * @param string nom de l'attribut */ - protected function addValidAttribute($_attributeName) + public static function addValidAttribute($_attributeName) { - return (is_string($_attributeName) && (HtmlTag::$validAttributesName[$_attributeName] = '')); + return (is_string($_attributeName) && (HtmlTag::$validAttributesName[$_attributeName] = array_key_exists($_attributeName,HtmlTag::getValidAttributesName())?'':'custom')); } /** * Retourne la liste des tags HTML valides @@ -1430,6 +1939,16 @@ public static function tagIsValid($_tagName) { return (is_string($_tagName) && array_key_exists(strtolower($_tagName),HtmlTag::getValidTagsName())); } + /** + * Méthode permettant de déclarer un tag HTML valide en plus de ceux par défaut + * Method to add valid/specific tag name + * + * @param string nom du tag + */ + public static function addValidTag($_tagName) + { + return (is_string($_tagName) && (HtmlTag::$validTagsName[$_tagName] = array_key_exists($_tagName,HtmlTag::getValidTagsName())?'':'custom')); + } /** * Méthode générale d'ajaout de définition de la valeur de l'objet ou d'ajout d'une valeur * Methode to set the value/add a value to the current element @@ -1463,7 +1982,7 @@ protected function _setValue($_value,$_encodeHtmlEntities = true) { if(is_scalar($_value) && $this->getValueAttribute() != '') $this->addAttribute($this->getValueAttribute(),$_encodeHtmlEntities?htmlentities($_value,ENT_QUOTES,HtmlTag::getEncoding(),false):$_value,true); - elseif(is_scalar($_value) && !empty($_value) && $this->getHasInnerHtml() && $this->getDomElement()) + elseif(is_scalar($_value) && $_value != '' && $this->getHasInnerHtml() && $this->getDomElement()) $this->getDomElement()->appendChild(HtmlTag::$domDocument->createTextNode($_encodeHtmlEntities?htmlentities($_value === ' '?' ':$_value,ENT_QUOTES,HtmlTag::getEncoding(),false):$_value)); elseif(($_value instanceof HtmlTag) && $this->getDomElement()) $this->getDomElement()->appendChild($_value->getDomElement()); @@ -1511,7 +2030,9 @@ public function addHtml($_html) /** * Suppression de tout espace de dbut et de fin */ - $html = str_replace(array('&','&'),'&',trim($_html)); + $html = str_replace(array( + '&', + '&'),'&',trim($_html)); /** * On s'assure d'avoir un code commençant par data) != '') + elseif($this->keepComments() && ($child instanceof DOMComment) && trim($child->data) != '') $this->setValue($child); /** * Sinon si le noeud est un texte non vide @@ -1923,12 +2446,17 @@ public static function findElementBy(DOMElement $_domElement,$_value = '*',$_att * Noeud en cours */ $valid = false; - if(is_scalar($_attributeName) && $_domElement->hasAttribute($_attributeName) && in_array($_value,array('*',$_domElement->getAttribute($_attributeName)))) + if(is_scalar($_attributeName) && $_domElement->hasAttribute($_attributeName) && in_array($_value,array( + '*', + $_domElement->getAttribute($_attributeName)))) $valid = true; elseif(is_array($_attributeName)) { foreach($_attributeName as $attributeName=>$attributeValue) - $valid |= ($_domElement->hasAttribute($attributeName) && in_array($attributeValue,array($_value,'*',$_domElement->getAttribute($attributeName)))); + $valid |= ($_domElement->hasAttribute($attributeName) && in_array($attributeValue,array( + $_value, + '*', + $_domElement->getAttribute($attributeName)))); } if($valid) $_multiples[] = HtmlTag::getHtmlTagFromDOMElement($_domElement); @@ -1936,12 +2464,17 @@ public static function findElementBy(DOMElement $_domElement,$_value = '*',$_att * Noeud enfant */ $valid = false; - if(is_scalar($_attributeName) && $childNodes->item($i)->hasAttribute($_attributeName) && in_array($_value,array('*',$childNodes->item($i)->getAttribute($_attributeName)))) + if(is_scalar($_attributeName) && $childNodes->item($i)->hasAttribute($_attributeName) && in_array($_value,array( + '*', + $childNodes->item($i)->getAttribute($_attributeName)))) $valid = true; elseif(is_array($_attributeName)) { foreach($_attributeName as $attributeName=>$attributeValue) - $valid |= ($childNodes->item($i)->hasAttribute($attributeName) && in_array($attributeValue,array($_value,'*',$childNodes->item($i)->getAttribute($attributeName)))); + $valid |= ($childNodes->item($i)->hasAttribute($attributeName) && in_array($attributeValue,array( + $_value, + '*', + $childNodes->item($i)->getAttribute($attributeName)))); } if($valid) $_multiples[] = HtmlTag::getHtmlTagFromDOMElement($childNodes->item($i)); @@ -2003,8 +2536,11 @@ private function getValueAttribute() case 'DOCTYPE': case 'dt': case 'em': + case 'embed': case 'fieldset': + case 'font': case 'form': + case 'frame': case 'h1': case 'h2': case 'h3': @@ -2014,6 +2550,7 @@ private function getValueAttribute() case 'head': case 'html': case 'i': + case 'iframe': case 'ins': case 'kbd': case 'label': @@ -2046,6 +2583,7 @@ private function getValueAttribute() case 'title': case 'tr': case 'tt': + case 'u': case 'ul': case 'samp': case 'var': @@ -2100,6 +2638,16 @@ public function __toString() {} return ''; } + /** + * Méthode permettant de savoir s'il faut conserver les commentaires, peut être surchargée par certaines classes + * Method to check if comment must be kpet or not, can be override by some classes + * + * @return bool true|false + */ + protected function keepComments() + { + return (defined('HTML_TAG_KEEP_COMMENTS') && HTML_TAG_KEEP_COMMENTS === true); + } /** * Méthode retournant le nom de la classe telle quelle * Method returning the class name diff --git a/PHP/HtmlTagA.php b/PHP/HtmlTagA.php index fee88af..d950abd 100644 --- a/PHP/HtmlTagA.php +++ b/PHP/HtmlTagA.php @@ -42,7 +42,7 @@ public function __construct() */ public function setHref($_href) { - return $this->addAttribute('href',trim($_href),true); + return $this->addAttribute('href',$_href,true); } /** * Méthode permettant de récupérer l'attribut 'href' de l'élément HtmlTag diff --git a/PHP/HtmlTagEmbed.php b/PHP/HtmlTagEmbed.php new file mode 100644 index 0000000..06d8ae1 --- /dev/null +++ b/PHP/HtmlTagEmbed.php @@ -0,0 +1,56 @@ + \ No newline at end of file diff --git a/PHP/HtmlTagFrame.php b/PHP/HtmlTagFrame.php new file mode 100644 index 0000000..813b8cc --- /dev/null +++ b/PHP/HtmlTagFrame.php @@ -0,0 +1,56 @@ + \ No newline at end of file diff --git a/PHP/HtmlTagIframe.php b/PHP/HtmlTagIframe.php new file mode 100644 index 0000000..b0b8721 --- /dev/null +++ b/PHP/HtmlTagIframe.php @@ -0,0 +1,56 @@ + \ No newline at end of file diff --git a/PHP/HtmlTagInput.php b/PHP/HtmlTagInput.php index 8be1b78..8d13f86 100644 --- a/PHP/HtmlTagInput.php +++ b/PHP/HtmlTagInput.php @@ -71,6 +71,21 @@ class HtmlTagInput extends HtmlTag * @var string */ const RESET = 'reset'; + /** + * Nom du type tel + * @var string + */ + const TEL = 'tel'; + /** + * Nom du type email + * @var string + */ + const EMAIL = 'email'; + /** + * Nom du type number + * @var string + */ + const NUMBER = 'number'; /** * Constructeur de la classe / Class constructor * @see parent::__construct() diff --git a/PHP/HtmlTagMap.php b/PHP/HtmlTagMap.php index 3aa2b2c..921b260 100644 --- a/PHP/HtmlTagMap.php +++ b/PHP/HtmlTagMap.php @@ -54,9 +54,9 @@ public function addArea(array $_attributes) * @param HtmlTagArea * @return bool true|false */ - public function setValue(HtmlTagArea $_area) + public function setValue($_area) { - return parent::setValue($_area); + return ($_area instanceof HtmlTagArea)?parent::setValue($_area):false; } /** * Méthode retournant le nom du tag de la classe diff --git a/PHP/HtmlTagObject.php b/PHP/HtmlTagObject.php index 585002b..4fc459c 100644 --- a/PHP/HtmlTagObject.php +++ b/PHP/HtmlTagObject.php @@ -43,7 +43,7 @@ public function __construct() * @param scalar valeur du paramètre / parameter value * @return bool true|false */ - public function addParam($_paramName, $_paramValue) + public function addParam($_paramName,$_paramValue) { if(is_string($_paramName) && is_scalar($_paramValue)) { @@ -61,9 +61,9 @@ public function addParam($_paramName, $_paramValue) * @param HtmlTagParam * @return bool true|false */ - public function setValue(HtmlTagParam $_param) + public function setValue($_param) { - return parent::setValue($_param); + return (($_param instanceof HtmlTagParam) || ($_param instanceof HtmlTagEmbed) || ($_param instanceof HtmlTagObject))?parent::setValue($_param):false; } /** * Méthode retournant le nom du tag de la classe diff --git a/PHP/HtmlTagOptgroup.php b/PHP/HtmlTagOptgroup.php index 62f5550..5d9f423 100644 --- a/PHP/HtmlTagOptgroup.php +++ b/PHP/HtmlTagOptgroup.php @@ -74,9 +74,9 @@ public function unsetLabel() * @param HtmlTagOption * @return bool true|false */ - public function setValue(HtmlTagOption $_option) + public function setValue($_option) { - return parent::setValue($_option); + return ($_option instanceof HtmlTagOption)?parent::setValue($_option):false; } /** * Méthode retournant le nom du tag de la classe diff --git a/PHP/HtmlTagScript.php b/PHP/HtmlTagScript.php index edfb39d..31b9814 100644 --- a/PHP/HtmlTagScript.php +++ b/PHP/HtmlTagScript.php @@ -120,11 +120,23 @@ public static function __tagName() * Override method to ensure JS code is not HTML encoded * @see HtmlTag::_setValue() * + * @param mixed|HtmlTag + * @param bool indique s'il faut ou non encoder les données / indicates if the data has to be html encoded * @return bool true|false */ - public function _setValue($_value) + public function _setValue($_value,$_encodeHtmlEntities = true) { - return parent::_setValue(is_string($_value)?html_entity_decode($_value,ENT_QUOTES,HtmlTag::getEncoding()):$_value,false); + return parent::_setValue(is_string($_value)?html_entity_decode($_value,ENT_QUOTES,HtmlTag::getEncoding()):$_value,$_encodeHtmlEntities && false); + } + /** + * Surcharge de la méthode afin de conserver les commentaires dans le cas de code JS + * @see HtmlTag::keepComments() + * + * @return bool true + */ + protected function keepComments() + { + return true; } /** * Méthode retournant le nom de la classe telle quelle diff --git a/PHP/HtmlTagSelect.php b/PHP/HtmlTagSelect.php index ed39bcc..c1867ba 100644 --- a/PHP/HtmlTagSelect.php +++ b/PHP/HtmlTagSelect.php @@ -53,7 +53,7 @@ public function addSelectOption(HtmlTagOption $_HtmlTagOption) * @param mixed * @param array */ - public function createOption($_content, array $_attributes = array()) + public function createOption($_content,array $_attributes = array()) { $htmlSelectOption = new HtmlTagOption(); $htmlSelectOption->setValue($_content); @@ -69,7 +69,7 @@ public function createOption($_content, array $_attributes = array()) * @param HtmlTagOption|HtmlTagOptgroup * @return bool true|false */ - public function setValue(HtmlTag $_option) + public function setValue($_option) { return (($_option instanceof HtmlTagOptgroup) || ($_option instanceof HtmlTagOption))?parent::setValue($_option):false; } diff --git a/PHP/HtmlTagStyle.php b/PHP/HtmlTagStyle.php index 9ecde00..31bf9b2 100644 --- a/PHP/HtmlTagStyle.php +++ b/PHP/HtmlTagStyle.php @@ -42,6 +42,29 @@ public static function __tagName() { return 'style'; } + /** + * Surcharge de la méthode car le code CSS ne doit pas être encodé en entités HTML + * Override method to ensure CSS code is not HTML encoded + * @see HtmlTag::_setValue() + * + * @param mixed|HtmlTag + * @param bool indique s'il faut ou non encoder les données / indicates if the data has to be html encoded + * @return bool true|false + */ + public function _setValue($_value,$_encodeHtmlEntities = true) + { + return parent::_setValue(is_string($_value)?html_entity_decode($_value,ENT_QUOTES,HtmlTag::getEncoding()):$_value,$_encodeHtmlEntities && false); + } + /** + * Surcharge de la méthode afin de conserver les commentaires dans le cas de code JS + * @see HtmlTag::keepComments() + * + * @return bool true + */ + protected function keepComments() + { + return true; + } /** * Méthode retournant le nom de la classe telle quelle * Method returning the class name diff --git a/PHP/HtmlTagTable.php b/PHP/HtmlTagTable.php index 3238ecf..08c8e70 100644 --- a/PHP/HtmlTagTable.php +++ b/PHP/HtmlTagTable.php @@ -76,6 +76,52 @@ public function setThead(HtmlTagThead $_thead) { return $this->addvalue($_thead); } + /** + * Méthode de définition de la valeur du cellpadding + * Method to set cellpadding attribute + * + * @uses Htmltag::addAttribute() + * @param int valeur + * @return bool true|false + */ + public function setCellpadding($_cellpadding) + { + return $this->addAttribute('cellpadding',intval($_cellpadding),true); + } + /** + * Méthode permettant de supprimer l'attribut cellpadding + * Method to unset cellpadding attribute + * + * @uses Htmltag::unsetAttribute() + * @return bool true|false + */ + public function unsetCellpadding() + { + return $this->unsetAttribute('cellpadding'); + } + /** + * Méthode de définition de la valeur du cellspacing + * Method to set cellspacing attribute + * + * @uses Htmltag::addAttribute() + * @param int valeur + * @return bool true|false + */ + public function setCellspacing($_cellspacing) + { + return $this->addAttribute('cellspacing',intval($_cellspacing),true); + } + /** + * Méthode permettant de supprimer l'attribut cellspacing + * Method to unset cellspacing attribute + * + * @uses Htmltag::unsetAttribute() + * @return bool true|false + */ + public function unsetCellspacing() + { + return $this->unsetAttribute('cellspacing'); + } /** * Méthode retournant le nom du tag de la classe * Method returning the tag name diff --git a/PHP/HtmlTagU.php b/PHP/HtmlTagU.php new file mode 100644 index 0000000..18e880d --- /dev/null +++ b/PHP/HtmlTagU.php @@ -0,0 +1,56 @@ + \ No newline at end of file diff --git a/autoload.inc b/autoload.inc index edfab38..b862c34 100644 --- a/autoload.inc +++ b/autoload.inc @@ -36,9 +36,11 @@ require_once HTML_TAG_PHP_PATH . 'HtmlTagDiv.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagDl.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagDt.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagEm.php'; +require_once HTML_TAG_PHP_PATH . 'HtmlTagEmbed.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagFieldset.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagFont.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagForm.php'; +require_once HTML_TAG_PHP_PATH . 'HtmlTagFrame.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagH.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagH1.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagH2.php'; @@ -49,6 +51,7 @@ require_once HTML_TAG_PHP_PATH . 'HtmlTagH6.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagHead.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagHr.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagI.php'; +require_once HTML_TAG_PHP_PATH . 'HtmlTagIframe.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagImg.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagInput.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagIns.php'; @@ -91,6 +94,7 @@ require_once HTML_TAG_PHP_PATH . 'HtmlTagTitle.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagTpl.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagTr.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagTt.php'; +require_once HTML_TAG_PHP_PATH . 'HtmlTagU.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagUl.php'; require_once HTML_TAG_PHP_PATH . 'HtmlTagVar.php'; ?> \ No newline at end of file