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
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 class user_plaintext {
00124 var $cObj;
00125 var $conf=array();
00126 var $charWidth=76;
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 function main_plaintext($content,$conf) {
00138 $this->conf = $conf;
00139 $this->siteUrl=$conf['siteUrl'];
00140 $lines = array();
00141 $CType= (string)$this->cObj->data['CType'];
00142 switch($CType) {
00143 case 'header':
00144 $lines[]=$this->getHeader();
00145 if ($this->cObj->data['subheader']) {
00146 $lines[]=$this->breakContent(strip_tags($this->cObj->data['subheader']));
00147 }
00148 break;
00149 case 'text':
00150 case 'textpic':
00151 $lines[]=$this->getHeader();
00152 if ($CType=='textpic' && !($this->cObj->data['imageorient']&24)) {
00153 $lines[]=$this->getImages();
00154 $lines[]='';
00155 }
00156 $lines[]=$this->breakContent(strip_tags($this->parseBody($this->cObj->data['bodytext'])));
00157 if ($CType=='textpic' && ($this->cObj->data['imageorient']&24)) {
00158 $lines[]='';
00159 $lines[]=$this->getImages();
00160 }
00161 break;
00162 case 'image':
00163 $lines[]=$this->getHeader();
00164 $lines[]=$this->getImages();
00165 break;
00166 case 'uploads':
00167 $lines[]=$this->getHeader();
00168 $lines[]=$this->renderUploads($this->cObj->data['media']);
00169 break;
00170 case 'menu':
00171 $lines[]=$this->getHeader();
00172 $lines[]=$this->getMenuSitemap();
00173 break;
00174 case 'shortcut':
00175 $lines[]=$this->getShortcut();
00176 break;
00177 case 'bullets':
00178 $lines[]=$this->getHeader();
00179 $lines[]=$this->breakBulletlist(strip_tags($this->parseBody($this->cObj->data['bodytext'])));
00180 break;
00181 case 'table':
00182 $lines[]=$this->getHeader();
00183 $lines[]=$this->breakTable(strip_tags($this->parseBody($this->cObj->data['bodytext'])));
00184 break;
00185 case 'html':
00186 $lines[]=$this->getHTML();
00187 break;
00188 default:
00189 $defaultOutput = $this->getString($this->conf['defaultOutput']);
00190 if ($defaultOutput) {
00191 $lines[]=str_replace('###CType###',$CType,$defaultOutput);
00192 }
00193 break;
00194 }
00195
00196 $lines[]='';
00197 $content = implode(chr(10),$lines);
00198
00199
00200 $content=$this->userProcess('userProc',$content);
00201 return $content;
00202 }
00203
00204
00205
00206
00207
00208
00209 function getMenuSitemap() {
00210 $str = $this->cObj->cObjGetSingle($this->conf['menu'],$this->conf['menu.']);
00211 $str = $this->breakBulletlist(trim(strip_tags(preg_replace('/<br[ \/]*>/i',chr(10),$this->parseBody($str)))));
00212 return $str;
00213 }
00214
00215
00216
00217
00218
00219
00220 function getShortcut() {
00221 $str = $this->cObj->cObjGetSingle($this->conf['shortcut'],$this->conf['shortcut.']);
00222 return $str;
00223 }
00224
00225
00226
00227
00228
00229
00230
00231 function getHTML($str=array()) {
00232 return $this->breakContent(strip_tags(preg_replace('/<br[ \/]*>/i',chr(10),$this->parseBody(is_string($str)?$str:$this->cObj->data['bodytext']))));
00233 }
00234
00235
00236
00237
00238
00239
00240
00241 function getHeader() {
00242
00243 return $this->renderHeader($this->cObj->data['header'],$this->cObj->data['header_layout']);
00244 }
00245
00246
00247
00248
00249
00250
00251 function getImages() {
00252 $images = $this->renderImages($this->cObj->data['image'],!$this->cObj->data['image_zoom']?$this->cObj->data['image_link']:'',$this->cObj->data['imagecaption']);
00253 return $images;
00254 }
00255
00256
00257
00258
00259
00260
00261
00262 function parseBody($str) {
00263
00264 $str = preg_replace('/<br[ \/]*>/i',' ',$str);
00265 $str = $this->cObj->stdWrap($str,$this->conf['bodytext.']['stdWrap.']);
00266
00267 $aConf = array();
00268 $aConf['parseFunc.']['tags.']['a']='USER';
00269 $aConf['parseFunc.']['tags.']['a.']['userFunc']='user_plaintext->atag_to_http';
00270 $aConf['parseFunc.']['tags.']['a.']['siteUrl'] = $this->siteUrl;
00271
00272 $str = $this->cObj->stdWrap($str,$aConf);
00273 $str = str_replace(' ',' ',t3lib_div::htmlspecialchars_decode($str));
00274 return $str;
00275 }
00276
00277
00278
00279
00280
00281
00282
00283
00284 function renderUploads($str,$upload_path='uploads/media/') {
00285 $files = explode(',',$str);
00286 $lines=array();
00287 if ($this->conf['uploads.']['header']) {$lines[]=$this->getString($this->conf['uploads.']['header']);}
00288 foreach ($files as $k => $file) {
00289 $lines[]=$this->siteUrl.$upload_path.$file;
00290 }
00291 return implode(chr(10),$lines);
00292 }
00293
00294
00295
00296
00297
00298
00299
00300
00301 function renderHeader($str,$type=0) {
00302 if ($str) {
00303 $hConf = $this->conf['header.'];
00304 $defaultType = t3lib_div::intInRange($hConf['defaultType'],1,5);
00305 $type=t3lib_div::intInRange($type,0,6);
00306 if (!$type) $type=$defaultType;
00307 if ($type!=6) {
00308 $tConf = $hConf[$type.'.'];
00309
00310 $lines=array();
00311
00312 $blanks = t3lib_div::intInRange($tConf['preBlanks'],0,1000);
00313 if ($blanks) {
00314 $lines[]=str_pad('', $blanks-1, chr(10));
00315 }
00316
00317 $lines=$this->pad($lines,$tConf['preLineChar'],$tConf['preLineLen']);
00318
00319 $blanks = t3lib_div::intInRange($tConf['preLineBlanks'],0,1000);
00320 if ($blanks) {$lines[]=str_pad('', $blanks-1, chr(10));}
00321
00322 if ($this->cObj->data['date']) {
00323 $lines[] = $this->getString($hConf['datePrefix']).date($hConf['date']?$hConf['date']:$GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$this->cObj->data['date']);
00324 }
00325 $prefix='';
00326 $str=$this->getString($tConf['prefix']).$str;
00327 if ($tConf['autonumber']) $str=$this->cObj->parentRecordNumber.$str;
00328 if ($this->cObj->data['header_position']=='right') {$prefix=str_pad(' ',($this->charWidth-strlen($str)));}
00329 if ($this->cObj->data['header_position']=='center') {$prefix=str_pad(' ',floor(($this->charWidth-strlen($str))/2));}
00330 $lines[]=$this->cObj->stdWrap($prefix.$str,$tConf['stdWrap.']);
00331 if ($this->cObj->data['header_link']) {$lines[] = $this->getString($hConf['linkPrefix']).$this->getLink($this->cObj->data['header_link']);}
00332
00333 $blanks = t3lib_div::intInRange($tConf['postLineBlanks'],0,1000);
00334 if ($blanks) {$lines[]=str_pad('', $blanks-1, chr(10));}
00335
00336 $lines=$this->pad($lines,$tConf['postLineChar'],$tConf['postLineLen']);
00337
00338 $blanks = t3lib_div::intInRange($tConf['postBlanks'],0,1000);
00339 if ($blanks) {$lines[]=str_pad('', $blanks-1, chr(10));}
00340 return implode(chr(10),$lines);
00341 }
00342 }
00343 }
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 function pad($lines,$preLineChar,$len) {
00355 $strPad = t3lib_div::intInRange($len,0,1000);
00356 $strPadChar = $preLineChar?$preLineChar:'-';
00357 if ($strPad) {
00358 $lines[]=str_pad('', $strPad, $strPadChar);
00359 }
00360 return $lines;
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370 function breakContent($str) {
00371 $cParts = explode(chr(10),$str);
00372 $lines=array();
00373 foreach ($cParts as $substrs) {
00374 $lines[]=$this->breakLines($substrs);
00375 }
00376 return implode(chr(10),$lines);
00377 }
00378
00379
00380
00381
00382
00383
00384
00385 function breakBulletlist($str) {
00386 $type = $this->cObj->data['layout'];
00387 $type=t3lib_div::intInRange($type,0,3);
00388
00389 $tConf = $this->conf['bulletlist.'][$type.'.'];
00390
00391 $cParts = explode(chr(10),$str);
00392 $lines=array();
00393 $c=0;
00394 foreach ($cParts as $substrs) {
00395 $c++;
00396 $bullet = $tConf['bullet'] ? $this->getString($tConf['bullet']) : ' - ';
00397 $bLen=strlen($bullet);
00398 $bullet = substr(str_replace('#',$c,$bullet),0,$bLen);
00399 $secondRow = substr($tConf['secondRow']?$this->getString($tConf['secondRow']):str_pad('',strlen($bullet),' '),0,$bLen);
00400
00401 $lines[]=$bullet.$this->breakLines($substrs,chr(10).$secondRow,$this->charWidth-$bLen);
00402
00403 $blanks = t3lib_div::intInRange($tConf['blanks'],0,1000);
00404 if ($blanks) {$lines[]=str_pad('', $blanks-1, chr(10));}
00405 }
00406 return implode(chr(10),$lines);
00407 }
00408
00409
00410
00411
00412
00413
00414
00415 function breakTable($str) {
00416 $cParts = explode(chr(10),$str);
00417 $lines=array();
00418 $cols = intval($this->conf['cols']) ? intval($this->conf['cols']) : 0 ;
00419 $c=0;
00420 foreach ($cParts as $substrs) {
00421 $c++;
00422 if (trim($substrs)) {
00423 $lineParts=explode('|',$substrs);
00424 if (!$cols) $cols=count($lineParts);
00425
00426 for ($a=0;$a<$cols;$a++) {
00427 $jdu = explode(chr(10),$this->breakLines($lineParts[$a],chr(10),ceil($this->charWidth/$cols)));
00428 $lines[$c][$a]=$jdu;
00429 }
00430 }
00431 }
00432 $messure = $this->traverseTable($lines);
00433
00434
00435 $divChar='-';
00436 $joinChar='+';
00437 $colChar='|';
00438
00439
00440 $outLines = array();
00441 $outLines[]=$this->addDiv($messure,'',$divChar,$joinChar,$cols);
00442
00443 foreach ($lines as $k => $v) {
00444 $top = intval($messure[1][$k]);
00445 for ($aa=0;$aa<$top;$aa++) {
00446 $tempArr=array();
00447 for ($bb=0;$bb<$cols;$bb++) {
00448 $tempArr[$bb]=str_pad($v[$bb][$aa],$messure[0][$bb],' ');
00449 }
00450 $outLines[]=$colChar.implode($colChar,$tempArr).$colChar;
00451 }
00452 $outLines[]=$this->addDiv($messure,'',$divChar,$joinChar,$cols);
00453 }
00454 return implode(chr(10),$outLines);
00455 }
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469 function addDiv($messure,$content,$divChar,$joinChar,$cols) {
00470 $tempArr=array();
00471 for ($a=0;$a<$cols;$a++) {
00472 $tempArr[$a]=str_pad($content,$messure[0][$a],$divChar);
00473 }
00474 return $joinChar.implode($joinChar,$tempArr).$joinChar;
00475 }
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 function traverseTable($tableLines) {
00486 $maxLen=array();
00487 $maxLines=array();
00488 foreach ($tableLines as $k => $v) {
00489 foreach ($v as $kk => $vv) {
00490 foreach ($vv as $lk => $lv) {
00491 if (strlen($lv)>intval($maxLen[$kk])) $maxLen[$kk]=strlen($lv);
00492 }
00493 if (count($vv)>intval($maxLines[$k])) $maxLines[$k]=count($vv);
00494 }
00495 }
00496 return array($maxLen,$maxLines);
00497 }
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 function renderImages($str,$links,$caption,$upload_path='uploads/pics/') {
00510 $images = explode(',',$str);
00511 $linksArr = explode(',',$links);
00512 $lines=array();
00513 if ($this->conf['images.']['header']) {$lines[]=$this->getString($this->conf['images.']['header']);}
00514 foreach ($images as $k => $file) {
00515 $lines[]=$this->siteUrl.$upload_path.$file;
00516 if ($links && count($linksArr)>1) {
00517 if (isset($linksArr[$k])) {
00518 $ll=$linksArr[$k];
00519 } else {
00520 $ll=$linksArr[0];
00521 }
00522
00523 $theLink = $this->getLink($ll);
00524 if ($theLink) {$lines[]=$this->getString($this->conf['images.']['linkPrefix']).$theLink;}
00525 }
00526 }
00527 if ($links && count($linksArr)==1) {
00528 $theLink = $this->getLink($links);
00529 if ($theLink) {$lines[]=$this->getString($this->conf['images.']['linkPrefix']).$theLink;}
00530 }
00531 if ($caption) {
00532 $lines[]='';
00533 $cHeader = trim($this->getString($this->conf['images.']['captionHeader']));
00534 if ($cHeader) $lines[]=$cHeader;
00535 $lines[]=$this->breakContent($caption);
00536 }
00537
00538 return implode(chr(10),$lines);
00539 }
00540
00541
00542
00543
00544
00545
00546
00547 function getLink($ll) {
00548 $theLink=$this->cObj->getTypoLink_URL($ll);
00549 if (substr($theLink,0,4)!='http') {
00550 $theLink=$this->siteUrl.$theLink;
00551 }
00552 return $theLink;
00553 }
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564 function breakLines($str,$implChar="\n",$charWidth=0) {
00565 return t3lib_div::breakLinesForEmail($str,$implChar,$charWidth?$charWidth:$this->charWidth);
00566 }
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576 function getString($str) {
00577 $parts = explode('|',$str);
00578 return strcmp($parts[1],'')?$parts[1]:$parts[0];
00579 }
00580
00581
00582
00583
00584
00585
00586
00587
00588 function userProcess($mConfKey,$passVar) {
00589 if ($this->conf[$mConfKey]) {
00590 $funcConf = $this->conf[$mConfKey.'.'];
00591 $funcConf['parentObj'] = $this;
00592 $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);
00593 }
00594 return $passVar;
00595 }
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606 function atag_to_http($content,$conf) {
00607 $this->conf = $conf;
00608 $this->siteUrl=$conf['siteUrl'];
00609 $theLink = trim($this->cObj->parameters['href']);
00610 if (strtolower(substr($theLink,0,7))=='mailto:') {
00611 $theLink=substr($theLink,7);
00612 } elseif (substr($theLink,0,4)!='http') {
00613 $theLink=$this->siteUrl.$theLink;
00614 }
00615 return $this->cObj->getCurrentVal().' (Link: '.$theLink.' )';
00616 }
00617
00618
00619
00620
00621
00622
00623
00624
00625 function typolist($content,$conf) {
00626 $this->conf = $this->cObj->mergeTSRef($conf,'bulletlist');
00627 $this->siteUrl=$conf['siteUrl'];
00628 $str = trim($this->cObj->getCurrentVal());
00629 $this->cObj->data['layout'] = $this->cObj->parameters['type'];
00630 return $this->breakBulletlist($str);
00631 }
00632
00633
00634
00635
00636
00637
00638
00639
00640 function typohead($content,$conf) {
00641 $this->conf = $this->cObj->mergeTSRef($conf,'header');
00642
00643 $this->siteUrl=$conf['siteUrl'];
00644 $str = trim($this->cObj->getCurrentVal());
00645 $this->cObj->data['header_layout'] = $this->cObj->parameters['type'];
00646 $this->cObj->data['header_position'] = $this->cObj->parameters['align'];
00647 $this->cObj->data['header']=$str;
00648
00649 return $this->getHeader();
00650 }
00651
00652
00653
00654
00655
00656
00657
00658
00659 function typocode($content,$conf) {
00660
00661 $this->conf = $conf;
00662 $this->siteUrl=$conf['siteUrl'];
00663 return $this->cObj->getCurrentVal();
00664 }
00665 }
00666
00667
00668
00669
00670 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/plaintextLib.inc']) {
00671 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/plaintextLib.inc']);
00672 }
00673 ?>