TYPO3 API  SVNRelease
class.tslib_content_template.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003  *  Copyright notice
00004  *
00005  *  (c) 2010-2011 Xavier Perseguers <typo3@perseguers.ch>
00006  *  (c) 2010-2011 Steffen Kamper <steffen@typo3.org>
00007  *  All rights reserved
00008  *
00009  *  This script is part of the TYPO3 project. The TYPO3 project is
00010  *  free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  The GNU General Public License can be found at
00016  *  http://www.gnu.org/copyleft/gpl.html.
00017  *  A copy is found in the textfile GPL.txt and important notices to the license
00018  *  from the author is found in LICENSE.txt distributed with these scripts.
00019  *
00020  *
00021  *  This script is distributed in the hope that it will be useful,
00022  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024  *  GNU General Public License for more details.
00025  *
00026  *  This copyright notice MUST APPEAR in all copies of the script!
00027  ***************************************************************/
00028 
00029 /**
00030  * Contains TEMPLATE class object.
00031  *
00032  * $Id: class.tslib_content.php 7905 2010-06-13 14:42:33Z ohader $
00033  * @author Xavier Perseguers <typo3@perseguers.ch>
00034  * @author Steffen Kamper <steffen@typo3.org>
00035  */
00036 class tslib_content_Template extends tslib_content_Abstract {
00037 
00038     /**
00039      * Rendering the cObject, TEMPLATE
00040      *
00041      * @param   array       Array of TypoScript properties
00042      * @return  string      Output
00043      * @see substituteMarkerArrayCached()
00044      */
00045     public function render($conf = array()) {
00046         $subparts = array();
00047         $marks = array();
00048         $wraps = array();
00049 
00050         $markerWrap = isset($conf['markerWrap.'])
00051             ? $this->cObj->stdWrap($conf['markerWrap'], $conf['markerWrap.'])
00052             : $conf['markerWrap'];
00053         if(!$markerWrap) {
00054             $markerWrap = '### | ###';
00055         }
00056 
00057         list ($PRE, $POST) = explode('|', $markerWrap);
00058         $POST = trim($POST);
00059         $PRE = trim($PRE);
00060 
00061             // Getting the content
00062         $content = $this->cObj->cObjGetSingle($conf['template'], $conf['template.'], 'template');
00063         $workOnSubpart = isset($conf['workOnSubpart.'])
00064             ? $this->cObj->stdWrap($conf['workOnSubpart'], $conf['workOnSubpart.'])
00065             : $conf['workOnSubpart'];
00066         if ($workOnSubpart) {
00067             $content = $this->cObj->getSubpart($content, $PRE . $workOnSubpart . $POST);
00068         }
00069 
00070             // Fixing all relative paths found:
00071         if ($conf['relPathPrefix']) {
00072             $htmlParser = t3lib_div::makeInstance('t3lib_parsehtml');
00073             $content = $htmlParser->prefixResourcePath($conf['relPathPrefix'], $content, $conf['relPathPrefix.']);
00074         }
00075 
00076         if ($content) {
00077             $nonCachedSubst = isset($conf['nonCachedSubst.'])
00078                 ? $this->cObj->stdWrap($conf['nonCachedSubst'], $conf['nonCachedSubst.'])
00079                 : $conf['nonCachedSubst'];
00080             if ($nonCachedSubst) { // NON-CACHED:
00081                     // Getting marks
00082                 if (is_array($conf['marks.'])) {
00083                     foreach ($conf['marks.'] as $theKey => $theValue) {
00084                         if (!strstr($theKey, '.')) {
00085                             $content = str_replace(
00086                                 $PRE . $theKey . $POST,
00087                                 $this->cObj->cObjGetSingle(
00088                                     $theValue, $conf['marks.'][$theKey . '.'],
00089                                     'marks.' . $theKey
00090                                 ),
00091                                 $content);
00092                         }
00093                     }
00094                 }
00095 
00096                     // Getting subparts.
00097                 if (is_array($conf['subparts.'])) {
00098                     foreach ($conf['subparts.'] as $theKey => $theValue) {
00099                         if (!strstr($theKey, '.')) {
00100                             $subpart = $this->cObj->getSubpart($content, $PRE . $theKey . $POST);
00101                             if ($subpart) {
00102                                 $this->cObj->setCurrentVal($subpart);
00103                                 $content = $this->cObj->substituteSubpart(
00104                                     $content,
00105                                     $PRE . $theKey . $POST,
00106                                     $this->cObj->cObjGetSingle(
00107                                         $theValue,
00108                                         $conf['subparts.'][$theKey . '.'],
00109                                         'subparts.' . $theKey),
00110                                         TRUE
00111                                     );
00112                             }
00113                         }
00114                     }
00115                 }
00116                     // Getting subpart wraps
00117                 if (is_array($conf['wraps.'])) {
00118                     foreach ($conf['wraps.'] as $theKey => $theValue) {
00119                         if (!strstr($theKey, '.')) {
00120                             $subpart = $this->cObj->getSubpart($content, $PRE . $theKey . $POST);
00121                             if ($subpart) {
00122                                 $this->cObj->setCurrentVal($subpart);
00123                                 $content = $this->cObj->substituteSubpart(
00124                                     $content,
00125                                     $PRE . $theKey . $POST,
00126                                     explode('|', $this->cObj->cObjGetSingle(
00127                                         $theValue, $conf['wraps.'][$theKey . '.'],
00128                                         'wraps.' . $theKey)
00129                                     ),
00130                                     TRUE
00131                                 );
00132                             }
00133                         }
00134                     }
00135                 }
00136             } else { // CACHED
00137                     // Getting subparts.
00138                 if (is_array($conf['subparts.'])) {
00139                     foreach ($conf['subparts.'] as $theKey => $theValue) {
00140                         if (!strstr($theKey, '.')) {
00141                             $subpart = $this->cObj->getSubpart($content, $PRE . $theKey . $POST);
00142                             if ($subpart) {
00143                                 $GLOBALS['TSFE']->register['SUBPART_' . $theKey] = $subpart;
00144                                 $subparts[$theKey]['name'] = $theValue;
00145                                 $subparts[$theKey]['conf'] = $conf['subparts.'][$theKey . '.'];
00146                             }
00147                         }
00148                     }
00149                 }
00150                 // Getting marks
00151                 if (is_array($conf['marks.'])) {
00152                     foreach ($conf['marks.'] as $theKey => $theValue) {
00153                         if (!strstr($theKey, '.')) {
00154                             $marks[$theKey]['name'] = $theValue;
00155                             $marks[$theKey]['conf'] = $conf['marks.'][$theKey . '.'];
00156                         }
00157                     }
00158                 }
00159                     // Getting subpart wraps
00160                 if (is_array($conf['wraps.'])) {
00161                     foreach ($conf['wraps.'] as $theKey => $theValue) {
00162                         if (!strstr($theKey, '.')) {
00163                             $wraps[$theKey]['name'] = $theValue;
00164                             $wraps[$theKey]['conf'] = $conf['wraps.'][$theKey . '.'];
00165                         }
00166                     }
00167                 }
00168                     // Getting subparts
00169                 $subpartArray = array();
00170                 foreach ($subparts as $theKey => $theValue) {
00171                     // Set current with the content of the subpart...
00172                     $this->cObj->data[$this->cObj->currentValKey] = $GLOBALS['TSFE']->register['SUBPART_' . $theKey];
00173                     // Get subpart cObject and substitute it!
00174                     $subpartArray[$PRE . $theKey . $POST] = $this->cObj->cObjGetSingle(
00175                         $theValue['name'],
00176                         $theValue['conf'],
00177                         'subparts.' . $theKey
00178                     );
00179                 }
00180                 $this->cObj->data[$this->cObj->currentValKey] = ''; // Reset current to empty
00181 
00182 
00183                     // Getting marks
00184                 $markerArray = array();
00185                 foreach ($marks as $theKey => $theValue) {
00186                     $markerArray[$PRE . $theKey . $POST] = $this->cObj->cObjGetSingle(
00187                         $theValue['name'],
00188                         $theValue['conf'],
00189                         'marks.' . $theKey
00190                     );
00191                 }
00192                     // Getting wraps
00193                 $subpartWraps = array();
00194                 foreach ($wraps as $theKey => $theValue) {
00195                     $subpartWraps[$PRE . $theKey . $POST] = explode(
00196                         '|',
00197                         $this->cObj->cObjGetSingle(
00198                             $theValue['name'],
00199                             $theValue['conf'],
00200                             'wraps.' . $theKey
00201                         )
00202                     );
00203                 }
00204 
00205                     // Substitution
00206                 $substMarksSeparately = isset($conf['substMarksSeparately.'])
00207                     ? $this->cObj->stdWrap($conf['substMarksSeparately'], $conf['substMarksSeparately.'])
00208                     : $conf['substMarksSeparately'];
00209                 if ($substMarksSeparately) {
00210                     $content = $this->cObj->substituteMarkerArrayCached($content, array(), $subpartArray, $subpartWraps);
00211                     $content = $this->cObj->substituteMarkerArray($content, $markerArray);
00212                 } else {
00213                     $content = $this->cObj->substituteMarkerArrayCached($content, $markerArray, $subpartArray, $subpartWraps);
00214                 }
00215             }
00216         }
00217 
00218         if (isset($conf['stdWrap.'])) {
00219             $content = $this->cObj->stdWrap($content, $conf['stdWrap.']);
00220         }
00221 
00222         return $content;
00223     }
00224 
00225 }
00226 
00227 
00228 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_template.php'])) {
00229     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['tslib/content/class.tslib_content_template.php']);
00230 }
00231 
00232 ?>