00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00074 require_once(PATH_t3lib.'class.t3lib_parsehtml.php');
00075
00076
00084 class t3lib_syntaxhl {
00085
00086
00087 var $htmlParse;
00088
00089
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
00145
00146
00147
00154 function highLight_DS($str) {
00155
00156
00157 $DS = t3lib_div::xml2array($str);
00158 if (is_array($DS)) {
00159 $completeTagList = array_unique($this->getAllTags($str));
00160
00161
00162 $this->htmlParse = t3lib_div::makeInstance('t3lib_parsehtml');
00163 $struct = $this->splitXMLbyTags(implode(',',$completeTagList),$str);
00164 $markUp = $this->highLight_DS_markUpRecursively($struct);
00165
00166
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
00206 if (!is_array($wrap)) {
00207 $wrap = $this->DS_wrapTags['_unknown'];
00208 }
00209
00210
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
00257
00258
00259
00266 function highLight_FF($str) {
00267
00268
00269 $DS = t3lib_div::xml2array($str);
00270 if (is_array($DS)) {
00271 $completeTagList = array_unique($this->getAllTags($str));
00272
00273
00274 $this->htmlParse = t3lib_div::makeInstance('t3lib_parsehtml');
00275 $struct = $this->splitXMLbyTags(implode(',',$completeTagList),$str);
00276 $markUp = $this->highLight_FF_markUpRecursively($struct);
00277
00278
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
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
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
00319 $wrap = $this->FF_wrapTags[$v['tagName']];
00320
00321
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
00365
00366
00367
00374 function getAllTags($str) {
00375
00376
00377 $tags = array();
00378 $token = md5(microtime());
00379
00380
00381 $markUpStr = ereg_replace('<([[:alnum:]_]+)[^>]*>',$token.'\1'.$token,$str);
00382
00383
00384 $parts = explode($token,$markUpStr);
00385
00386
00387 foreach($parts as $k => $v) {
00388 if ($k%2) {
00389 $tags[]=$v;
00390 }
00391 }
00392
00393
00394 return $tags;
00395 }
00396
00405 function splitXMLbyTags($tagList,$str) {
00406 $struct = $this->htmlParse->splitIntoBlock($tagList,$str);
00407
00408
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 ?>