Documentation TYPO3 par Ameos

plaintextLib.inc

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 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 ***************************************************************/
00123 class user_plaintext {
00124         var $cObj;
00125         var $conf=array();
00126         var $charWidth=76;
00127 
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[]='';    // First break.
00197                 $content = implode(chr(10),$lines);
00198 
00199                         // User processing:
00200                 $content=$this->userProcess('userProc',$content);
00201                 return $content;
00202         }
00203 
00209         function getMenuSitemap()       {
00210                 $str = $this->cObj->cObjGetSingle($this->conf['menu'],$this->conf['menu.']);
00211                 $str = $this->breakBulletlist(trim(strip_tags(eregi_replace('<br[ /]*>',chr(10),$this->parseBody($str)))));
00212                 return $str;
00213         }
00214 
00220         function getShortcut()  {
00221                 $str = $this->cObj->cObjGetSingle($this->conf['shortcut'],$this->conf['shortcut.']);
00222                 return $str;
00223         }
00224 
00231         function getHTML($str=array())  {
00232                 return $this->breakContent(strip_tags(eregi_replace('<br[ /]*>',chr(10),$this->parseBody(is_string($str)?$str:$this->cObj->data['bodytext']))));
00233         }
00234 
00241         function getHeader()    {
00242                 // links...
00243                 return $this->renderHeader($this->cObj->data['header'],$this->cObj->data['header_layout']);
00244         }
00245 
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 
00262         function parseBody($str)        {
00263                         // First, regular parsing:
00264                 $str = eregi_replace('<br[ /]*>',' ',$str);
00265                 $str = $this->cObj->stdWrap($str,$this->conf['bodytext.']['stdWrap.']);
00266                         // Then all a-tags:
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('&nbsp;',' ',t3lib_div::htmlspecialchars_decode($str));
00274                 return $str;
00275         }
00276 
00284         function renderUploads($str,$upload_path='uploads/media/')      {
00285                 $files = explode(',',$str);
00286                 reset($files);
00287                 $lines=array();
00288                 if ($this->conf['uploads.']['header'])  {$lines[]=$this->getString($this->conf['uploads.']['header']);}
00289                 while(list($k,$file)=each($files))      {
00290                         $lines[]=$this->siteUrl.$upload_path.$file;
00291                 }
00292                 return implode(chr(10),$lines);
00293         }
00294 
00302         function renderHeader($str,$type=0)     {
00303                 if ($str)       {
00304                         $hConf = $this->conf['header.'];
00305                         $defaultType = t3lib_div::intInRange($hConf['defaultType'],1,5);
00306                         $type=t3lib_div::intInRange($type,0,6);
00307                         if (!$type)     $type=$defaultType;
00308                         if ($type!=6)   {       // not hidden
00309                                 $tConf = $hConf[$type.'.'];
00310 
00311                                 $lines=array();
00312 
00313                                 $blanks = t3lib_div::intInRange($tConf['preBlanks'],0,1000);
00314                                 if ($blanks)    {
00315                                         $lines[]=str_pad('', $blanks-1, chr(10));
00316                                 }
00317 
00318                                 $lines=$this->pad($lines,$tConf['preLineChar'],$tConf['preLineLen']);
00319 
00320                                 $blanks = t3lib_div::intInRange($tConf['preLineBlanks'],0,1000);
00321                                 if ($blanks)    {$lines[]=str_pad('', $blanks-1, chr(10));}
00322 
00323                                 if ($this->cObj->data['date'])  {
00324                                         $lines[] = $this->getString($hConf['datePrefix']).date($hConf['date']?$hConf['date']:$GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$this->cObj->data['date']);
00325                                 }
00326                                 $prefix='';
00327                                 $str=$this->getString($tConf['prefix']).$str;
00328                                 if ($tConf['autonumber'])       $str=$this->cObj->parentRecordNumber.$str;
00329                                 if ($this->cObj->data['header_position']=='right')      {$prefix=str_pad(' ',($this->charWidth-strlen($str)));}
00330                                 if ($this->cObj->data['header_position']=='center')     {$prefix=str_pad(' ',floor(($this->charWidth-strlen($str))/2));}
00331                                 $lines[]=$this->cObj->stdWrap($prefix.$str,$tConf['stdWrap.']);
00332                                 if ($this->cObj->data['header_link'])           {$lines[] = $this->getString($hConf['linkPrefix']).$this->getLink($this->cObj->data['header_link']);}
00333 
00334                                 $blanks = t3lib_div::intInRange($tConf['postLineBlanks'],0,1000);
00335                                 if ($blanks)    {$lines[]=str_pad('', $blanks-1, chr(10));}
00336 
00337                                 $lines=$this->pad($lines,$tConf['postLineChar'],$tConf['postLineLen']);
00338 
00339                                 $blanks = t3lib_div::intInRange($tConf['postBlanks'],0,1000);
00340                                 if ($blanks)    {$lines[]=str_pad('', $blanks-1, chr(10));}
00341                                 return implode(chr(10),$lines);
00342                         }
00343                 }
00344         }
00345 
00355         function pad($lines,$preLineChar,$len)  {
00356                 $strPad = t3lib_div::intInRange($len,0,1000);
00357                 $strPadChar = $preLineChar?$preLineChar:'-';
00358                 if ($strPad)    {
00359                         $lines[]=str_pad('', $strPad, $strPadChar);
00360                 }
00361                 return $lines;
00362         }
00363 
00371         function breakContent($str)     {
00372                 $cParts = explode(chr(10),$str);
00373                 reset($cParts);
00374                 $lines=array();
00375                 while(list(,$substrs)=each($cParts))    {
00376                         $lines[]=$this->breakLines($substrs);
00377                 }
00378                 return implode(chr(10),$lines);
00379         }
00380 
00387         function breakBulletlist($str)  {
00388                 $type = $this->cObj->data['layout'];
00389                 $type=t3lib_div::intInRange($type,0,3);
00390 
00391                 $tConf = $this->conf['bulletlist.'][$type.'.'];
00392 
00393                 $cParts = explode(chr(10),$str);
00394                 reset($cParts);
00395                 $lines=array();
00396                 $c=0;
00397                 while(list(,$substrs)=each($cParts))    {
00398                         $c++;
00399                         $bullet = $tConf['bullet'] ? $this->getString($tConf['bullet']) : ' - ';
00400                         $bLen=strlen($bullet);
00401                         $bullet = substr(str_replace('#',$c,$bullet),0,$bLen);
00402                         $secondRow = substr($tConf['secondRow']?$this->getString($tConf['secondRow']):str_pad('',strlen($bullet),' '),0,$bLen);
00403 
00404                         $lines[]=$bullet.$this->breakLines($substrs,chr(10).$secondRow,$this->charWidth-$bLen);
00405 
00406                         $blanks = t3lib_div::intInRange($tConf['blanks'],0,1000);
00407                         if ($blanks)    {$lines[]=str_pad('', $blanks-1, chr(10));}
00408                 }
00409                 return implode(chr(10),$lines);
00410         }
00411 
00418         function breakTable($str)       {
00419                 $cParts = explode(chr(10),$str);
00420                 reset($cParts);
00421                 $lines=array();
00422                 $cols = intval($this->conf['cols']) ? intval($this->conf['cols']) : 0 ;
00423                 $c=0;
00424                 while(list(,$substrs)=each($cParts))    {
00425                         $c++;
00426                         if (trim($substrs))     {
00427                                 $lineParts=explode('|',$substrs);
00428                                 if (!$cols)     $cols=count($lineParts);
00429 
00430                                 for ($a=0;$a<$cols;$a++)        {
00431                                         $jdu = explode(chr(10),$this->breakLines($lineParts[$a],chr(10),ceil($this->charWidth/$cols)));
00432                                         $lines[$c][$a]=$jdu;
00433                                 }
00434                         }
00435                 }
00436                 $messure = $this->traverseTable($lines);
00437 
00438 
00439                 $divChar='-';
00440                 $joinChar='+';
00441                 $colChar='|';
00442 
00443                 // Make table:
00444                 $outLines = array();
00445                 $outLines[]=$this->addDiv($messure,'',$divChar,$joinChar,$cols);
00446 
00447                 reset($lines);
00448                 while(list($k,$v)=each($lines)) {
00449                         $top = intval($messure[1][$k]);
00450                         for ($aa=0;$aa<$top;$aa++)      {
00451                                 $tempArr=array();
00452                                 for ($bb=0;$bb<$cols;$bb++)     {
00453                                         $tempArr[$bb]=str_pad($v[$bb][$aa],$messure[0][$bb],' ');
00454                                 }
00455                                 $outLines[]=$colChar.implode($colChar,$tempArr).$colChar;
00456                         }
00457                         $outLines[]=$this->addDiv($messure,'',$divChar,$joinChar,$cols);
00458                 }
00459                 return implode(chr(10),$outLines);
00460         }
00461 
00474         function addDiv($messure,$content,$divChar,$joinChar,$cols)     {
00475                 $tempArr=array();
00476                 for ($a=0;$a<$cols;$a++)        {
00477                         $tempArr[$a]=str_pad($content,$messure[0][$a],$divChar);
00478                 }
00479                 return $joinChar.implode($joinChar,$tempArr).$joinChar;
00480         }
00481 
00490         function traverseTable($tableLines)     {
00491                 $maxLen=array();
00492                 $maxLines=array();
00493                 reset($tableLines);
00494                 while(list($k,$v)=each($tableLines))    {
00495                         reset($v);
00496                         while(list($kk,$vv)=each($v))   {
00497                                 reset($vv);
00498                                 while(list($lk,$lv)=each($vv))  {
00499                                         if (strlen($lv)>intval($maxLen[$kk]))   $maxLen[$kk]=strlen($lv);
00500                                 }
00501                                 if (count($vv)>intval($maxLines[$k]))   $maxLines[$k]=count($vv);
00502                         }
00503                 }
00504                 return array($maxLen,$maxLines);
00505         }
00506 
00517         function renderImages($str,$links,$caption,$upload_path='uploads/pics/')        {
00518                 $images = explode(',',$str);
00519                 $linksArr = explode(',',$links);
00520                 reset($images);
00521                 $lines=array();
00522                 if ($this->conf['images.']['header'])   {$lines[]=$this->getString($this->conf['images.']['header']);}
00523                 while(list($k,$file)=each($images))     {
00524                         $lines[]=$this->siteUrl.$upload_path.$file;
00525                         if ($links && count($linksArr)>1)       {
00526                                 if (isset($linksArr[$k]))       {
00527                                         $ll=$linksArr[$k];
00528                                 } else {
00529                                         $ll=$linksArr[0];
00530                                 }
00531 
00532                                 $theLink = $this->getLink($ll);
00533                                 if ($theLink)   {$lines[]=$this->getString($this->conf['images.']['linkPrefix']).$theLink;}
00534                         }
00535                 }
00536                 if ($links && count($linksArr)==1)      {
00537                         $theLink = $this->getLink($links);
00538                         if ($theLink)   {$lines[]=$this->getString($this->conf['images.']['linkPrefix']).$theLink;}
00539                 }
00540                 if ($caption)   {
00541                         $lines[]='';
00542                         $cHeader = trim($this->getString($this->conf['images.']['captionHeader']));
00543                         if ($cHeader)           $lines[]=$cHeader;
00544                         $lines[]=$this->breakContent($caption);
00545                 }
00546 
00547                 return implode(chr(10),$lines);
00548         }
00549 
00556         function getLink($ll)   {
00557                 $theLink=$this->cObj->getTypoLink_URL($ll);
00558                 if (substr($theLink,0,4)!='http')       {
00559                         $theLink=$this->siteUrl.$theLink;
00560                 }
00561                 return $theLink;
00562         }
00563 
00573         function breakLines($str,$implChar="\n",$charWidth=0)   {
00574                 return t3lib_div::breakLinesForEmail($str,$implChar,$charWidth?$charWidth:$this->charWidth);
00575         }
00576 
00585         function getString($str)        {
00586                 $parts = explode('|',$str);
00587                 return strcmp($parts[1],'')?$parts[1]:$parts[0];
00588         }
00589 
00597         function userProcess($mConfKey,$passVar)        {
00598                 if ($this->conf[$mConfKey])     {
00599                         $funcConf = $this->conf[$mConfKey.'.'];
00600                         $funcConf['parentObj']=&$this;
00601                         $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);
00602                 }
00603                 return $passVar;
00604         }
00605 
00615         function atag_to_http($content,$conf)   {
00616                 $this->conf = $conf;
00617                 $this->siteUrl=$conf['siteUrl'];
00618                 $theLink  = trim($this->cObj->parameters['href']);
00619                 if (strtolower(substr($theLink,0,7))=='mailto:')        {
00620                         $theLink=substr($theLink,7);
00621                 } elseif (substr($theLink,0,4)!='http') {
00622                         $theLink=$this->siteUrl.$theLink;
00623                 }
00624                 return $this->cObj->getCurrentVal().' (Link: '.$theLink.' )';
00625         }
00626 
00634         function typolist($content,$conf)       {
00635                 $this->conf = $this->cObj->mergeTSRef($conf,'bulletlist');
00636                 $this->siteUrl=$conf['siteUrl'];
00637                 $str = trim($this->cObj->getCurrentVal());
00638                 $this->cObj->data['layout'] = $this->cObj->parameters['type'];
00639                 return $this->breakBulletlist($str);
00640         }
00641 
00649         function typohead($content,$conf)       {
00650                 $this->conf = $this->cObj->mergeTSRef($conf,'header');
00651 
00652                 $this->siteUrl=$conf['siteUrl'];
00653                 $str = trim($this->cObj->getCurrentVal());
00654                 $this->cObj->data['header_layout'] = $this->cObj->parameters['type'];
00655                 $this->cObj->data['header_position'] = $this->cObj->parameters['align'];
00656                 $this->cObj->data['header']=$str;
00657 
00658                 return $this->getHeader();
00659         }
00660 
00668         function typocode($content,$conf)       {
00669                         // Nothing is really done here...
00670                 $this->conf = $conf;
00671                 $this->siteUrl=$conf['siteUrl'];
00672                 return $this->cObj->getCurrentVal();
00673         }
00674 }
00675 
00676 
00677 
00678 
00679 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/plaintextLib.inc'])  {
00680         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['media/scripts/plaintextLib.inc']);
00681 }
00682 ?>


Généré par Les spécialistes TYPO3 avec  doxygen 1.4.6