| [ Index ] |
|
Code source de Typo3 4.1.3 |
[Code source] [Imprimer] [Statistiques]
Contains class with functions for parsing HTML code. $Id: class.t3lib_parsehtml.php 1421 2006-04-10 09:27:15Z mundaun $ Revised for TYPO3 3.6 July/2003 by Kasper Skaarhoj
| Author: | Kasper Skaarhoj <kasperYYYY@typo3.com> |
| Poids: | 1326 lignes (53 kb) |
| Inclus ou requis: | 0 fois |
| Référencé: | 0 fois |
| Nécessite: | 0 fichiers |
t3lib_parsehtml:: (28 méthodes):
getSubpart()
substituteSubpart()
splitIntoBlock()
splitIntoBlockRecursiveProc()
splitTags()
getAllParts()
removeFirstAndLastTag()
getFirstTag()
getFirstTagName()
get_tag_attributes()
split_tag_attributes()
checkTagTypeCounts()
HTMLcleaner()
bidir_htmlspecialchars()
prefixResourcePath()
prefixRelPath()
cleanFontTags()
mapTags()
unprotectTags()
stripTagsExcept()
caseShift()
compileTagAttribs()
get_tag_attributes_classic()
indentLines()
HTMLparserConfig()
XHTML_clean()
processTag()
processContent()
Classe: t3lib_parsehtml - X-Ref
Functions for parsing HTML.| getSubpart($content, $marker) X-Ref |
| Returns the first subpart encapsulated in the marker, $marker (possibly present in $content as a HTML comment) param: string Content with subpart wrapped in fx. "###CONTENT_PART###" inside. param: string Marker string, eg. "###CONTENT_PART###" return: string |
| substituteSubpart($content,$marker,$subpartContent,$recursive=1,$keepMarker=0) X-Ref |
| Substitutes a subpart in $content with the content of $subpartContent. param: string Content with subpart wrapped in fx. "###CONTENT_PART###" inside. param: string Marker string, eg. "###CONTENT_PART###" param: array If $subpartContent happens to be an array, it's [0] and [1] elements are wrapped around the content of the subpart (fetched by getSubpart()) param: boolean If $recursive is set, the function calls itself with the content set to the remaining part of the content after the second marker. This means that proceding subparts are ALSO substituted! param: boolean If set, the marker around the subpart is not removed, but kept in the output return: string Processed input content |
| splitIntoBlock($tag,$content,$eliminateExtraEndTags=0) X-Ref |
| Returns an array with the $content divided by tag-blocks specified with the list of tags, $tag Even numbers in the array are outside the blocks, Odd numbers are block-content. Use ->getAllParts() and ->removeFirstAndLastTag() to process the content if needed. param: string List of tags, comma separated. param: string HTML-content param: boolean If set, excessive end tags are ignored - you should probably set this in most cases. return: array Even numbers in the array are outside the blocks, Odd numbers are block-content. |
| splitIntoBlockRecursiveProc($tag,$content,&$procObj,$callBackContent,$callBackTags,$level=0) X-Ref |
| Splitting content into blocks *recursively* and processing tags/content with call back functions. param: string Tag list, see splitIntoBlock() param: string Content, see splitIntoBlock() param: object Object where call back methods are. param: string Name of call back method for content; "function callBackContent($str,$level)" param: string Name of call back method for tags; "function callBackTags($tags,$level)" param: integer Indent level return: string Processed content |
| splitTags($tag,$content) X-Ref |
| Returns an array with the $content divided by tag-blocks specified with the list of tags, $tag Even numbers in the array are outside the blocks, Odd numbers are block-content. Use ->getAllParts() and ->removeFirstAndLastTag() to process the content if needed. param: string List of tags param: string HTML-content return: array Even numbers in the array are outside the blocks, Odd numbers are block-content. |
| getAllParts($parts,$tag_parts=1,$include_tag=1) X-Ref |
| Returns an array with either tag or non-tag content of the result from ->splitIntoBlock()/->splitTags() param: array Parts generated by ->splitIntoBlock() or >splitTags() param: boolean Whether to return the tag-parts (default,true) or what was outside the tags. param: boolean Whether to include the tags in the tag-parts (most useful for input made by ->splitIntoBlock()) return: array Tag-parts/Non-tag-parts depending on input argument settings |
| removeFirstAndLastTag($str) X-Ref |
| Removes the first and last tag in the string Anything before the first and after the last tags respectively is also removed param: string String to process return: string |
| getFirstTag($str) X-Ref |
| Returns the first tag in $str Actually everything from the begining of the $str is returned, so you better make sure the tag is the first thing... param: string HTML string with tags return: string |
| getFirstTagName($str,$preserveCase=FALSE) X-Ref |
| Returns the NAME of the first tag in $str param: string HTML tag (The element name MUST be separated from the attributes by a space character! Just *whitespace* will not do) param: boolean If set, then the tag is NOT converted to uppercase by case is preserved. return: string Tag name in upper case |
| get_tag_attributes($tag,$deHSC=0) X-Ref |
| Returns an array with all attributes as keys. Attributes are only lowercase a-z If a attribute is empty (shorthand), then the value for the key is empty. You can check if it existed with isset() param: string Tag: $tag is either a whole tag (eg '<TAG OPTION ATTRIB=VALUE>') or the parameterlist (ex ' OPTION ATTRIB=VALUE>') param: boolean If set, the attribute values are de-htmlspecialchar'ed. Should actually always be set! return: array array(Tag attributes,Attribute meta-data) |
| split_tag_attributes($tag) X-Ref |
| Returns an array with the 'components' from an attribute list. The result is normally analyzed by get_tag_attributes Removes tag-name if found param: string The tag or attributes return: array |
| checkTagTypeCounts($content,$blockTags='a,b,blockquote,body,div,em,font,form,h1,h2,h3,h4,h5,h6,i,li,map,ol,option,p,pre,select,span,strong,table,td,textarea,tr,u,ul', $soloTags='br,hr,img,input,area') X-Ref |
| Checks whether block/solo tags are found in the correct amounts in HTML content Block tags are tags which are required to have an equal amount of start and end tags, eg. "<table>...</table>" Solo tags are tags which are required to have ONLY start tags (possibly with an XHTML ending like ".../>") NOTICE: Correct XHTML might actually fail since "<br></br>" is allowed as well as "<br/>". However only the LATTER is accepted by this function (with "br" in the "solo-tag" list), the first example will result in a warning. NOTICE: Correct XHTML might actually fail since "<p/>" is allowed as well as "<p></p>". However only the LATTER is accepted by this function (with "p" in the "block-tag" list), the first example will result in an ERROR! NOTICE: Correct HTML version "something" allows eg. <p> and <li> to be NON-ended (implicitly ended by other tags). However this is NOT accepted by this function (with "p" and "li" in the block-tag list) and it will result in an ERROR! param: string HTML content to analyze param: string Tag names for block tags (eg. table or div or p) in lowercase, commalist (eg. "table,div,p") param: string Tag names for solo tags (eg. img, br or input) in lowercase, commalist ("img,br,input") return: array Analyse data. |
| HTMLcleaner($content, $tags=array() X-Ref |
| Function that can clean up HTML content according to configuration given in the $tags array. Initializing the $tags array to allow a list of tags (in this case <B>,<I>,<U> and <A>), set it like this: $tags = array_flip(explode(',','b,a,i,u')) If the value of the $tags[$tagname] entry is an array, advanced processing of the tags is initialized. These are the options: $tags[$tagname] = Array( 'overrideAttribs' => '' If set, this string is preset as the attributes of the tag 'allowedAttribs' => '0' (zero) = no attributes allowed, '[commalist of attributes]' = only allowed attributes. If blank, all attributes are allowed. 'fixAttrib' => Array( '[attribute name]' => Array ( 'set' => Force the attribute value to this value. 'unset' => Boolean: If set, the attribute is unset. 'default' => If no attribute exists by this name, this value is set as default value (if this value is not blank) 'always' => Boolean. If set, the attribute is always processed. Normally an attribute is processed only if it exists 'trim,intval,lower,upper' => All booleans. If any of these keys are set, the value is passed through the respective PHP-functions. 'range' => Array ('[low limit]','[high limit, optional]') Setting integer range. 'list' => Array ('[value1/default]','[value2]','[value3]') Attribute must be in this list. If not, the value is set to the first element. 'removeIfFalse' => Boolean/'blank'. If set, then the attribute is removed if it is 'false'. If this value is set to 'blank' then the value must be a blank string (that means a 'zero' value will not be removed) 'removeIfEquals' => [value] If the attribute value matches the value set here, then it is removed. 'casesensitiveComp' => 1 If set, then the removeIfEquals and list comparisons will be case sensitive. Otherwise not. ) ), 'protect' => '', Boolean. If set, the tag <> is converted to < and > 'remap' => '', String. If set, the tagname is remapped to this tagname 'rmTagIfNoAttrib' => '', Boolean. If set, then the tag is removed if no attributes happend to be there. 'nesting' => '', Boolean/'global'. If set true, then this tag must have starting and ending tags in the correct order. Any tags not in this order will be discarded. Thus '</B><B><I></B></I></B>' will be converted to '<B><I></B></I>'. Is the value 'global' then true nesting in relation to other tags marked for 'global' nesting control is preserved. This means that if <B> and <I> are set for global nesting then this string '</B><B><I></B></I></B>' is converted to '<B></B>' ) param: string $content; is the HTML-content being processed. This is also the result being returned. param: array $tags; is an array where each key is a tagname in lowercase. Only tags present as keys in this array are preserved. The value of the key can be an array with a vast number of options to configure. param: string $keepAll; boolean/'protect', if set, then all tags are kept regardless of tags present as keys in $tags-array. If 'protect' then the preserved tags have their <> converted to < and > param: integer $hSC; Values -1,0,1,2: Set to zero= disabled, set to 1 then the content BETWEEN tags is htmlspecialchar()'ed, set to -1 its the opposite and set to 2 the content will be HSC'ed BUT with preservation for real entities (eg. "&" or "ê") param: array Configuration array send along as $conf to the internal functions ->processContent() and ->processTag() return: string Processed HTML content |
| bidir_htmlspecialchars($value,$dir) X-Ref |
| Converts htmlspecialchars forth ($dir=1) AND back ($dir=-1) param: string Input value param: integer Direction: forth ($dir=1, dir=2 for preserving entities) AND back ($dir=-1) return: string Output value |
| prefixResourcePath($main_prefix,$content,$alternatives=array() X-Ref |
| Prefixes the relative paths of hrefs/src/action in the tags [td,table,body,img,input,form,link,script,a] in the $content with the $main_prefix or and alternative given by $alternatives param: string Prefix string param: string HTML content param: array Array with alternative prefixes for certain of the tags. key=>value pairs where the keys are the tag element names in uppercase param: string Suffix string (put after the resource). return: string Processed HTML content |
| prefixRelPath($prefix,$srcVal,$suffix='') X-Ref |
| Internal sub-function for ->prefixResourcePath() param: string Prefix string param: string Relative path/URL param: string Suffix string return: string Output path, prefixed if no scheme in input string |
| cleanFontTags($value,$keepFace=0,$keepSize=0,$keepColor=0) X-Ref |
| Cleans up the input $value for fonttags. If keepFace,-Size and -Color is set then font-tags with an allowed property is kept. Else deleted. param: string HTML content with font-tags inside to clean up. param: boolean If set, keep "face" attribute param: boolean If set, keep "size" attribute param: boolean If set, keep "color" attribute return: string Processed HTML content |
| mapTags($value,$tags=array() X-Ref |
| This is used to map certain tag-names into other names. param: string HTML content param: array Array with tag key=>value pairs where key is from-tag and value is to-tag param: string Alternative less-than char to search for (search regex string) param: string Alternative less-than char to replace with (replace regex string) return: string Processed HTML content |
| unprotectTags($content,$tagList='') X-Ref |
| This converts htmlspecialchar()'ed tags (from $tagList) back to real tags. Eg. '<strong>' would be converted back to '<strong>' if found in $tagList param: string HTML content param: string Tag list, separated by comma. Lowercase! return: string Processed HTML content |
| stripTagsExcept($value,$tagList) X-Ref |
| Strips tags except the tags in the list, $tagList OBSOLETE - use PHP function strip_tags() param: string Value to process param: string List of tags return: string Output value |
| caseShift($str,$flag,$cacheKey='') X-Ref |
| Internal function for case shifting of a string or whole array param: mixed Input string/array param: boolean If $str is a string AND this boolean(caseSensitive) is false, the string is returned in uppercase param: string Key string used for internal caching of the results. Could be an MD5 hash of the serialized version of the input $str if that is an array. return: string Output string, processed |
| compileTagAttribs($tagAttrib,$meta=array() X-Ref |
| Compiling an array with tag attributes into a string param: array Tag attributes param: array Meta information about these attributes (like if they were quoted) param: boolean If set, then the attribute names will be set in lower case, value quotes in double-quotes and the value will be htmlspecialchar()'ed return: string Imploded attributes, eg: 'attribute="value" attrib2="value2"' |
| get_tag_attributes_classic($tag,$deHSC=0) X-Ref |
| Get tag attributes, the classic version (which had some limitations?) param: string The tag param: boolean De-htmlspecialchar flag. return: array |
| indentLines($content, $number=1, $indentChar="\t") X-Ref |
| Indents input content with $number instances of $indentChar param: string Content string, multiple lines. param: integer Number of indents param: string Indent character/string return: string Indented code (typ. HTML) |
| HTMLparserConfig($TSconfig,$keepTags=array() X-Ref |
| Converts TSconfig into an array for the HTMLcleaner function. param: array TSconfig for HTMLcleaner param: array Array of tags to keep (?) return: array |
| XHTML_clean($content) X-Ref |
| Tries to convert the content to be XHTML compliant and other stuff like that. STILL EXPERIMENTAL. See comments below. What it does NOT do (yet) according to XHTML specs.: - Wellformedness: Nesting is NOT checked - name/id attribute issue is not observed at this point. - Certain nesting of elements not allowed. Most interesting, <PRE> cannot contain img, big,small,sub,sup ... - Wrapping scripts and style element contents in CDATA - or alternatively they should have entitites converted. - Setting charsets may put some special requirements on both XML declaration/ meta-http-equiv. (C.9) - UTF-8 encoding is in fact expected by XML!! - stylesheet element and attribute names are NOT converted to lowercase - ampersands (and entities in general I think) MUST be converted to an entity reference! (&s;). This may mean further conversion of non-tag content before output to page. May be related to the charset issue as a whole. - Minimized values not allowed: Must do this: selected="selected" What it does at this point: - All tags (frame,base,meta,link + img,br,hr,area,input) is ended with "/>" - others? - Lowercase for elements and attributes - All attributes in quotes - Add "alt" attribute to img-tags if it's not there already. param: string Content to clean up return: string Cleaned up content returned. |
| processTag($value,$conf,$endTag,$protected=0) X-Ref |
| Processing all tags themselves (Some additions by Sacha Vorbeck) param: string Tag to process param: array Configuration array passing instructions for processing. If count()==0, function will return value unprocessed. See source code for details param: boolean Is endtag, then set this. param: boolean If set, just return value straight away return: string Processed value. |
| processContent($value,$dir,$conf) X-Ref |
| Processing content between tags for HTML_cleaner param: string The value param: integer Direction, either -1 or +1. 0 (zero) means no change to input value. param: mixed Not used, ignore. return: string The processed value. |
| Généré le : Sun Nov 25 17:13:16 2007 | par Balluche grâce à PHPXref 0.7 |
|