"TYPO3 4.0.1: typo3_src-4.0.1/t3lib/class.t3lib_syntaxhl.php Source File", "datetime" => "Sat Dec 2 19:22:19 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2006 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 'itemType' => array('<span style="font-weight: bold; color: #804000;">','</span>'), 00117 'section' => array('<span style="font-weight: bold; color: #604080;">','</span>'), 00118 'numIndex' => array('<span style="color: #333333;">','</span>'), 00119 '_unknown' => array('<span style="font-style: italic; color: #666666;">','</span>'), 00120 00121 00122 'sDEF' => array('<span style="font-weight: bold; color: #008000;">','</span>'), 00123 'level:sheet' => array('<span style="font-weight: bold; color: #008000;">','</span>'), 00124 00125 'lDEF' => array('<span style="font-weight: bold; color: #000080;">','</span>'), 00126 'level:language' => array('<span style="font-weight: bold; color: #000080;">','</span>'), 00127 00128 'level:fieldname' => array('<span style="font-weight: bold; color: #666666;">','</span>'), 00129 00130 'vDEF' => array('<span style="font-weight: bold; color: #008080;">','</span>'), 00131 'level:value' => array('<span style="font-weight: bold; color: #008080;">','</span>'), 00132 00133 'currentSheetId' => array('<span style="color: #000080;">','</span>'), 00134 'currentLangId' => array('<span style="color: #000080;">','</span>'), 00135 ); 00136 00137 00138 00139 00140 00141 00142 00143 00144 /************************************* 00145 * 00146 * Markup of Data Structure, <T3DataStructure> 00147 * 00148 *************************************/ 00149 00156 function highLight_DS($str) { 00157 00158 // Parse DS to verify that it is valid: 00159 $DS = t3lib_div::xml2array($str); 00160 if (is_array($DS)) { 00161 $completeTagList = array_unique($this->getAllTags($str)); // Complete list of tags in DS 00162 00163 // Highlighting source: 00164 $this->htmlParse = t3lib_div::makeInstance('t3lib_parsehtml'); // Init parser object 00165 $struct = $this->splitXMLbyTags(implode(',',$completeTagList),$str); // Split the XML by the found tags, recursively into LARGE array. 00166 $markUp = $this->highLight_DS_markUpRecursively($struct); // Perform color-markup on the parsed content. Markup preserves the LINE formatting of the XML. 00167 00168 // Return content: 00169 return $markUp; 00170 } else $error = 'ERROR: The input content failed XML parsing: '.$DS; 00171 return $error; 00172 } 00173 00183 function highLight_DS_markUpRecursively($struct,$parent='',$app='') { 00184 $output=''; 00185 foreach($struct as $k => $v) { 00186 if ($k%2) { 00187 $nextApp = $app; 00188 $wrap = array('',''); 00189 00190 switch($app) { 00191 case 'TCEforms': 00192 case 'tx_templavoila': 00193 $wrap = $this->DS_wrapTags['_applicationContents']; 00194 break; 00195 case 'el': 00196 default: 00197 if ($parent=='el') { 00198 $wrap = $this->DS_wrapTags['parent:el']; 00199 $nextApp = 'el'; 00200 } elseif ($parent=='sheets') { 00201 $wrap = $this->DS_wrapTags['parent:sheets']; 00202 } else { 00203 $wrap = $this->DS_wrapTags[$v['tagName']]; 00204 $nextApp = ''; 00205 } 00206 00207 // If no wrap defined, us "unknown" definition 00208 if (!is_array($wrap)) { 00209 $wrap = $this->DS_wrapTags['_unknown']; 00210 } 00211 00212 // Check for application sections in the XML: 00213 if ($app=='el' || $parent=='ROOT') { 00214 switch($v['tagName']) { 00215 case 'TCEforms': 00216 case 'tx_templavoila': 00217 $nextApp = $v['tagName']; 00218 $wrap = $this->DS_wrapTags['_applicationTag']; 00219 break; 00220 } 00221 } 00222 break; 00223 } 00224 00225 $output.=$wrap[0].htmlspecialchars($v['tag']).$wrap[1]; 00226 $output.=$this->highLight_DS_markUpRecursively($v['sub'],$v['tagName'],$nextApp); 00227 $output.=$wrap[0].htmlspecialchars('</'.$v['tagName'].'>').$wrap[1]; 00228 } else { 00229 $output.=htmlspecialchars($v); 00230 } 00231 } 00232 00233 return $output; 00234 } 00235 00236 00237 00238 00239 00240 00241 00242 00243 00244 00245 00246 00247 00248 00249 00250 00251 00252 00253 00254 00255 00256 /************************************* 00257 * 00258 * Markup of Data Structure, <T3FlexForms> 00259 * 00260 *************************************/ 00261 00268 function highLight_FF($str) { 00269 00270 // Parse DS to verify that it is valid: 00271 $DS = t3lib_div::xml2array($str); 00272 if (is_array($DS)) { 00273 $completeTagList = array_unique($this->getAllTags($str)); // Complete list of tags in DS 00274 00275 // Highlighting source: 00276 $this->htmlParse = t3lib_div::makeInstance('t3lib_parsehtml'); // Init parser object 00277 $struct = $this->splitXMLbyTags(implode(',',$completeTagList),$str); // Split the XML by the found tags, recursively into LARGE array. 00278 $markUp = $this->highLight_FF_markUpRecursively($struct); // Perform color-markup on the parsed content. Markup preserves the LINE formatting of the XML. 00279 00280 // Return content: 00281 return $markUp; 00282 } else $error = 'ERROR: The input content failed XML parsing: '.$DS; 00283 return $error; 00284 } 00285 00295 function highLight_FF_markUpRecursively($struct,$parent='',$app='') { 00296 $output=''; 00297 00298 // Setting levels: 00299 if ($parent=='data') { 00300 $app='sheet'; 00301 } elseif($app=='sheet') { 00302 $app='language'; 00303 } elseif($app=='language') { 00304 $app='fieldname'; 00305 } elseif($app=='fieldname') { 00306 $app='value'; 00307 } elseif($app=='el' || $app=='numIndex') { 00308 $app='fieldname'; 00309 } 00310 00311 // Traverse structure: 00312 foreach($struct as $k => $v) { 00313 if ($k%2) { 00314 $wrap = array('',''); 00315 00316 if ($v['tagName'] == 'numIndex') { 00317 $app = 'numIndex'; 00318 } 00319 00320 // Default wrap: 00321 $wrap = $this->FF_wrapTags[$v['tagName']]; 00322 00323 // If no wrap defined, us "unknown" definition 00324 if (!is_array($wrap)) { 00325 switch($app) { 00326 case 'sheet': 00327 case 'language': 00328 case 'fieldname': 00329 case 'value': 00330 $wrap = $this->FF_wrapTags['level:'.$app]; 00331 break; 00332 default: 00333 $wrap = $this->FF_wrapTags['_unknown']; 00334 break; 00335 } 00336 } 00337 00338 if ($v['tagName']=='el') { 00339 $app='el'; 00340 } 00341 00342 $output.=$wrap[0].htmlspecialchars($v['tag']).$wrap[1]; 00343 $output.=$this->highLight_FF_markUpRecursively($v['sub'],$v['tagName'],$app); 00344 $output.=$wrap[0].htmlspecialchars('</'.$v['tagName'].'>').$wrap[1]; 00345 } else { 00346 $output.=htmlspecialchars($v); 00347 } 00348 } 00349 00350 return $output; 00351 } 00352 00353 00354 00355 00356 00357 00358 00359 00360 00361 00362 00363 00364 /************************************* 00365 * 00366 * Various 00367 * 00368 *************************************/ 00369 00376 function getAllTags($str) { 00377 00378 // Init: 00379 $tags = array(); 00380 $token = md5(microtime()); 00381 00382 // Markup all tag names with token. 00383 $markUpStr = ereg_replace('<([[:alnum:]_]+)[^>]*>',$token.'\1'.$token,$str); 00384 00385 // Splitting by token: 00386 $parts = explode($token,$markUpStr); 00387 00388 // Traversing parts: 00389 foreach($parts as $k => $v) { 00390 if ($k%2) { 00391 $tags[]=$v; 00392 } 00393 } 00394 00395 // Returning tags: 00396 return $tags; 00397 } 00398 00407 function splitXMLbyTags($tagList,$str) { 00408 $struct = $this->htmlParse->splitIntoBlock($tagList,$str); 00409 00410 // Traverse level: 00411 foreach($struct as $k => $v) { 00412 if ($k%2) { 00413 $tag = $this->htmlParse->getFirstTag($v); 00414 $tagName = $this->htmlParse->getFirstTagName($tag,TRUE); 00415 $struct[$k] = array( 00416 'tag' => $tag, 00417 'tagName' => $tagName, 00418 'sub' => $this->splitXMLbyTags($tagList,$this->htmlParse->removeFirstAndLastTag($struct[$k])) 00419 ); 00420 } 00421 } 00422 00423 return $struct; 00424 } 00425 } 00426 00427 00428 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_syntaxhl.php']) { 00429 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_syntaxhl.php']); 00430 } 00431 ?>