Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2004 Kasper Skaarhoj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00074 require_once(PATH_t3lib.'class.t3lib_parsehtml.php'); 00075 00076 00084 class t3lib_syntaxhl { 00085 00086 // Internal, dynamic: 00087 var $htmlParse; // Parse object. 00088 00089 // External, static: 00090 var $DS_wrapTags = array( 00091 'T3DataStructure' => array('<span style="font-weight: bold;">','</span>'), 00092 'type' => array('<span style="font-weight: bold; color: #000080;">','</span>'), 00093 'section' => array('<span style="font-weight: bold; color: #000080;">','</span>'), 00094 'el' => array('<span style="font-weight: bold; color: #800000;">','</span>'), 00095 'meta' => array('<span style="font-weight: bold; color: #800080;">','</span>'), 00096 '_unknown' => array('<span style="font-style: italic; color: #666666;">','</span>'), 00097 00098 '_applicationTag' => array('<span style="font-weight: bold; color: #FF6600;">','</span>'), 00099 '_applicationContents' => array('<span style="font-style: italic; color: #C29336;">','</span>'), 00100 00101 'sheets' => array('<span style="font-weight: bold; color: #008000;">','</span>'), 00102 'parent:sheets' => array('<span style="color: #008000;">','</span>'), 00103 00104 'ROOT' => array('<span style="font-weight: bold; color: #008080;">','</span>'), 00105 'parent:el' => array('<span style="font-weight: bold; color: #008080;">','</span>'), 00106 00107 'langDisable' => array('<span style="color: #000080;">','</span>'), 00108 'langChildren' => array('<span style="color: #000080;">','</span>'), 00109 ); 00110 00111 var $FF_wrapTags = array( 00112 'T3FlexForms' => array('<span style="font-weight: bold;">','</span>'), 00113 'meta' => array('<span style="font-weight: bold; color: #800080;">','</span>'), 00114 'data' => array('<span style="font-weight: bold; color: #800080;">','</span>'), 00115 'el' => array('<span style="font-weight: bold; color: #80a000;">','</span>'), 00116 'numIndex' => array('<span style="color: #333333;">','</span>'), 00117 '_unknown' => array('<span style="font-style: italic; color: #666666;">','</span>'), 00118 00119 00120 'sDEF' => array('<span style="font-weight: bold; color: #008000;">','</span>'), 00121 'level:sheet' => array('<span style="font-weight: bold; color: #008000;">','</span>'), 00122 00123 'lDEF' => array('<span style="font-weight: bold; color: #000080;">','</span>'), 00124 'level:language' => array('<span style="font-weight: bold; color: #000080;">','</span>'), 00125 00126 'level:fieldname' => array('<span style="font-weight: bold; color: #666666;">','</span>'), 00127 00128 'vDEF' => array('<span style="font-weight: bold; color: #008080;">','</span>'), 00129 'level:value' => array('<span style="font-weight: bold; color: #008080;">','</span>'), 00130 00131 'currentSheetId' => array('<span style="color: #000080;">','</span>'), 00132 'currentLangId' => array('<span style="color: #000080;">','</span>'), 00133 ); 00134 00135 00136 00137 00138 00139 00140 00141 00142 /************************************* 00143 * 00144 * Markup of Data Structure, <T3DataStructure> 00145 * 00146 *************************************/ 00147 00154 function highLight_DS($str) { 00155 00156 // Parse DS to verify that it is valid: 00157 $DS = t3lib_div::xml2array($str); 00158 if (is_array($DS)) { 00159 $completeTagList = array_unique($this->getAllTags($str)); // Complete list of tags in DS 00160 00161 // Highlighting source: 00162 $this->htmlParse = t3lib_div::makeInstance('t3lib_parsehtml'); // Init parser object 00163 $struct = $this->splitXMLbyTags(implode(',',$completeTagList),$str); // Split the XML by the found tags, recursively into LARGE array. 00164 $markUp = $this->highLight_DS_markUpRecursively($struct); // Perform color-markup on the parsed content. Markup preserves the LINE formatting of the XML. 00165 00166 // Return content: 00167 return $markUp; 00168 } else $error = 'ERROR: The input content failed XML parsing: '.$DS; 00169 return $error; 00170 } 00171 00181 function highLight_DS_markUpRecursively($struct,$parent='',$app='') { 00182 $output=''; 00183 foreach($struct as $k => $v) { 00184 if ($k%2) { 00185 $nextApp = $app; 00186 $wrap = array('',''); 00187 00188 switch($app) { 00189 case 'TCEforms': 00190 case 'tx_templavoila': 00191 $wrap = $this->DS_wrapTags['_applicationContents']; 00192 break; 00193 case 'el': 00194 default: 00195 if ($parent=='el') { 00196 $wrap = $this->DS_wrapTags['parent:el']; 00197 $nextApp = 'el'; 00198 } elseif ($parent=='sheets') { 00199 $wrap = $this->DS_wrapTags['parent:sheets']; 00200 } else { 00201 $wrap = $this->DS_wrapTags[$v['tagName']]; 00202 $nextApp = ''; 00203 } 00204 00205 // If no wrap defined, us "unknown" definition 00206 if (!is_array($wrap)) { 00207 $wrap = $this->DS_wrapTags['_unknown']; 00208 } 00209 00210 // Check for application sections in the XML: 00211 if ($app=='el' || $parent=='ROOT') { 00212 switch($v['tagName']) { 00213 case 'TCEforms': 00214 case 'tx_templavoila': 00215 $nextApp = $v['tagName']; 00216 $wrap = $this->DS_wrapTags['_applicationTag']; 00217 break; 00218 } 00219 } 00220 break; 00221 } 00222 00223 $output.=$wrap[0].htmlspecialchars($v['tag']).$wrap[1]; 00224 $output.=$this->highLight_DS_markUpRecursively($v['sub'],$v['tagName'],$nextApp); 00225 $output.=$wrap[0].htmlspecialchars('</'.$v['tagName'].'>').$wrap[1]; 00226 } else { 00227 $output.=htmlspecialchars($v); 00228 } 00229 } 00230 00231 return $output; 00232 } 00233 00234 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 /************************************* 00255 * 00256 * Markup of Data Structure, <T3FlexForms> 00257 * 00258 *************************************/ 00259 00266 function highLight_FF($str) { 00267 00268 // Parse DS to verify that it is valid: 00269 $DS = t3lib_div::xml2array($str); 00270 if (is_array($DS)) { 00271 $completeTagList = array_unique($this->getAllTags($str)); // Complete list of tags in DS 00272 00273 // Highlighting source: 00274 $this->htmlParse = t3lib_div::makeInstance('t3lib_parsehtml'); // Init parser object 00275 $struct = $this->splitXMLbyTags(implode(',',$completeTagList),$str); // Split the XML by the found tags, recursively into LARGE array. 00276 $markUp = $this->highLight_FF_markUpRecursively($struct); // Perform color-markup on the parsed content. Markup preserves the LINE formatting of the XML. 00277 00278 // Return content: 00279 return $markUp; 00280 } else $error = 'ERROR: The input content failed XML parsing: '.$DS; 00281 return $error; 00282 } 00283 00293 function highLight_FF_markUpRecursively($struct,$parent='',$app='') { 00294 $output=''; 00295 00296 // Setting levels: 00297 if ($parent=='data') { 00298 $app='sheet'; 00299 } elseif($app=='sheet') { 00300 $app='language'; 00301 } elseif($app=='language') { 00302 $app='fieldname'; 00303 } elseif($app=='fieldname') { 00304 $app='value'; 00305 } elseif($app=='el' || $app=='numIndex') { 00306 $app='fieldname'; 00307 } 00308 00309 // Traverse structure: 00310 foreach($struct as $k => $v) { 00311 if ($k%2) { 00312 $wrap = array('',''); 00313 00314 if ($v['tagName'] == 'numIndex') { 00315 $app = 'numIndex'; 00316 } 00317 00318 // Default wrap: 00319 $wrap = $this->FF_wrapTags[$v['tagName']]; 00320 00321 // If no wrap defined, us "unknown" definition 00322 if (!is_array($wrap)) { 00323 switch($app) { 00324 case 'sheet': 00325 case 'language': 00326 case 'fieldname': 00327 case 'value': 00328 $wrap = $this->FF_wrapTags['level:'.$app]; 00329 break; 00330 default: 00331 $wrap = $this->FF_wrapTags['_unknown']; 00332 break; 00333 } 00334 } 00335 00336 if ($v['tagName']=='el') { 00337 $app='el'; 00338 } 00339 00340 $output.=$wrap[0].htmlspecialchars($v['tag']).$wrap[1]; 00341 $output.=$this->highLight_FF_markUpRecursively($v['sub'],$v['tagName'],$app); 00342 $output.=$wrap[0].htmlspecialchars('</'.$v['tagName'].'>').$wrap[1]; 00343 } else { 00344 $output.=htmlspecialchars($v); 00345 } 00346 } 00347 00348 return $output; 00349 } 00350 00351 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 /************************************* 00363 * 00364 * Various 00365 * 00366 *************************************/ 00367 00374 function getAllTags($str) { 00375 00376 // Init: 00377 $tags = array(); 00378 $token = md5(microtime()); 00379 00380 // Markup all tag names with token. 00381 $markUpStr = ereg_replace('<([[:alnum:]_]+)[^>]*>',$token.'\1'.$token,$str); 00382 00383 // Splitting by token: 00384 $parts = explode($token,$markUpStr); 00385 00386 // Traversing parts: 00387 foreach($parts as $k => $v) { 00388 if ($k%2) { 00389 $tags[]=$v; 00390 } 00391 } 00392 00393 // Returning tags: 00394 return $tags; 00395 } 00396 00405 function splitXMLbyTags($tagList,$str) { 00406 $struct = $this->htmlParse->splitIntoBlock($tagList,$str); 00407 00408 // Traverse level: 00409 foreach($struct as $k => $v) { 00410 if ($k%2) { 00411 $tag = $this->htmlParse->getFirstTag($v); 00412 $tagName = $this->htmlParse->getFirstTagName($tag,TRUE); 00413 $struct[$k] = array( 00414 'tag' => $tag, 00415 'tagName' => $tagName, 00416 'sub' => $this->splitXMLbyTags($tagList,$this->htmlParse->removeFirstAndLastTag($struct[$k])) 00417 ); 00418 } 00419 } 00420 00421 return $struct; 00422 } 00423 } 00424 00425 00426 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_syntaxhl.php']) { 00427 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_syntaxhl.php']); 00428 } 00429 ?>