Project

General

Profile

Feature #17847 » 20071125_t3lib_htmltemplate.diff

Administrator Admin, 2007-11-25 13:29

View differences:

t3lib/class.t3lib_htmltemplate.php (revision 0)
<?php
/***************************************************************
* Copyright notice
*
* (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
/**
* Standard functions available for the TYPO3 backend.
* You are encouraged to use this class in your own applications
*
* Call ALL methods without making an object!
* Eg. to get a subpart of a template: 't3lib_HTMLtemplate::getSubpart($content,'###SUBPART###')'
*
*
* @author Kasper Skaarhoj <kasperYYYY@typo3.com>
*/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*
*
* SECTION: HTML template processing functions
* 81: function getSubpart($content, $marker)
* 97: function substituteSubpart($content,$marker,$subpartContent,$recursive=1)
* 110: function substituteMarker($content,$marker,$markContent)
* 3027: function substituteMarkerArray($content,$markContentArray,$wrap='',$uppercase=0)
*
*/
require_once (PATH_t3lib.'class.t3lib_parsehtml.php');
/**
* Standard functions available for the TYPO3 backend.
* Don't instantiate - call functions with "t3lib_HTMLtemplate::" prefixed the function name.
*
* @author Kasper Skaarhoj <kasperYYYY@typo3.com>
* @package TYPO3
* @subpackage t3lib
*/
class t3lib_HTMLtemplate {
/***********************************************
*
* HTML template processing functions
*
***********************************************/
/**
* Returns a subpart from the input content stream.
* A subpart is a part of the input stream which is encapsulated in a string matching the input string, $marker. If this string is found inside of HTML comment tags the start/end points of the content block returned will be that right outside that comment block.
* Example: The contennt string is "Hello <!--###sub1### begin--> World. How are <!--###sub1### end--> you?" If $marker is "###sub1###" then the content returned is " World. How are ". The input content string could just as well have been "Hello ###sub1### World. How are ###sub1### you?" and the result would be the same
* Wrapper for t3lib_parsehtml::getSubpart which behaves identical
*
* @param string The content stream, typically HTML template content.
* @param string The marker string, typically on the form "###[the marker string]###"
* @return string The subpart found, if found.
* @see substituteSubpart(), t3lib_parsehtml::getSubpart()
*/
public function getSubpart($content, $marker) {
return t3lib_parsehtml::getSubpart($content, $marker);
}
/**
* Substitute subpart in input template stream.
* This function substitutes a subpart in $content with the content of $subpartContent.
* Wrapper for t3lib_parsehtml::substituteSubpart which behaves identical
*
* @param string The content stream, typically HTML template content.
* @param string The marker string, typically on the form "###[the marker string]###"
* @param mixed The content to insert instead of the subpart found. If a string, then just plain substitution happens (includes removing the HTML comments of the subpart if found). If $subpartContent happens to be an array, it's [0] and [1] elements are wrapped around the EXISTING content of the subpart (fetched by getSubpart()) thereby not removing the original content.
* @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!
* @return string The processed HTML content string.
* @see getSubpart(), t3lib_parsehtml::substituteSubpart()
*/
public function substituteSubpart($content,$marker,$subpartContent,$recursive=1) {
return t3lib_parsehtml::substituteSubpart($content, $marker, $subpartContent, $recursive);
}
/**
* Substitutes a marker string in the input content (by a simple str_replace())
*
* @param string The content stream, typically HTML template content.
* @param string The marker string, typically on the form "###[the marker string]###"
* @param mixed The content to insert instead of the marker string found.
* @return string The processed HTML content string.
* @see substituteSubpart()
*/
public function substituteMarker($content,$marker,$markContent) {
return str_replace($marker,$markContent,$content);
}
/**
* Multi substitution function with caching.
*
* This function should be a one-stop substitution function for working with HTML-template. It does not substitute by str_replace but by splitting. This secures that the value inserted does not themselves contain markers or subparts.
* This function takes three kinds of substitutions in one:
* $markContentArray is a regular marker-array where the 'keys' are substituted in $content with their values
* $subpartContentArray works exactly like markContentArray only is whole subparts substituted and not only a single marker.
* $wrappedSubpartContentArray is an array of arrays with 0/1 keys where the subparts pointed to by the main key is wrapped with the 0/1 value alternating.
*
* @param string The content stream, typically HTML template content.
* @param array Regular marker-array where the 'keys' are substituted in $content with their values
* @param array Exactly like markContentArray only is whole subparts substituted and not only a single marker.
* @param array An array of arrays with 0/1 keys where the subparts pointed to by the main key is wrapped with the 0/1 value alternating.
* @return string The output content stream
* @see substituteSubpart(), substituteMarker(), substituteMarkerInObject(), TEMPLATE()
*/
/**
* Traverses the input $markContentArray array and for each key the marker by the same name (possibly wrapped and in upper case) will be substituted with the keys value in the array.
* This is very useful if you have a data-record to substitute in some content. In particular when you use the $wrap and $uppercase values to pre-process the markers. Eg. a key name like "myfield" could effectively be represented by the marker "###MYFIELD###" if the wrap value was "###|###" and the $uppercase boolean true.
*
* @param string The content stream, typically HTML template content.
* @param array The array of key/value pairs being marker/content values used in the substitution. For each element in this array the function will substitute a marker in the content stream with the content.
* @param string A wrap value - [part 1] | [part 2] - for the markers before substitution
* @param boolean If set, all marker string substitution is done with upper-case markers.
* @return string The processed output stream
* @see substituteMarker(), substituteMarkerInObject(), TEMPLATE()
*/
public function substituteMarkerArray($content,$markContentArray,$wrap='',$uppercase=0) {
if (is_array($markContentArray)) {
reset($markContentArray);
$wrapArr=t3lib_div::trimExplode('|',$wrap);
foreach($markContentArray as $marker=>$markContent) {
if($uppercase) $marker=strtoupper($marker);
if(strcmp($wrap,'')) $marker=$wrapArr[0].$marker.$wrapArr[1];
$content=str_replace($marker,$markContent,$content);
}
}
return $content;
}
}
?>
(1-1/2)