TYPO3 API  SVNRelease
plaintextLib.inc
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2009 Kasper Skårhøj (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 ***************************************************************/
00027 /**
00028  * Generating plain text content of content elements for Direct Mails
00029  *
00030  * $Id: plaintextLib.inc 5947 2009-09-16 17:57:09Z ohader $
00031  * Revised for TYPO3 3.6 June/2003 by Kasper Skårhøj
00032  *
00033  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00034  */
00035 /**
00036  * [CLASS/FUNCTION INDEX of SCRIPT]
00037  *
00038  *
00039  *
00040  *  123: class user_plaintext
00041  *  137:     function main_plaintext($content,$conf)
00042  *  209:     function getMenuSitemap()
00043  *  220:     function getShortcut()
00044  *  231:     function getHTML($str=array())
00045  *  241:     function getHeader()
00046  *  251:     function getImages()
00047  *  262:     function parseBody($str)
00048  *  284:     function renderUploads($str,$upload_path='uploads/media/')
00049  *  302:     function renderHeader($str,$type=0)
00050  *  353:     function pad($lines,$preLineChar,$len)
00051  *  369:     function breakContent($str)
00052  *  385:     function breakBulletlist($str)
00053  *  416:     function breakTable($str)
00054  *  472:     function addDiv($messure,$content,$divChar,$joinChar,$cols)
00055  *  488:     function traverseTable($tableLines)
00056  *  515:     function renderImages($str,$links,$caption,$upload_path='uploads/pics/')
00057  *  554:     function getLink($ll)
00058  *  571:     function breakLines($str,$implChar="\n",$charWidth=0)
00059  *  583:     function getString($str)
00060  *  595:     function userProcess($mConfKey,$passVar)
00061  *  613:     function atag_to_http($content,$conf)
00062  *  632:     function typolist($content,$conf)
00063  *  647:     function typohead($content,$conf)
00064  *  666:     function typocode($content,$conf)
00065  *
00066  * TOTAL FUNCTIONS: 24
00067  * (This index is automatically created/updated by the extension "extdeveval")
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  * Alternative rendering of content elements for Plain Text emails. That means text-only output. No HTML at all. Used by the Direct Mail extension.
00093  * Normally the plain text output should appear with type=99.
00094  * To use this library you can include the static template "plugin.alt.plaintext"
00095  *
00096  * ## Insert DMailer Boundaries for all elements.
00097  * config.insertDmailerBoundaries = 1
00098  * includeLibs.plaintextLib = media/scripts/plaintextLib.inc
00099  *
00100  * ## Set up page/type number:
00101  * alt_plaintext >
00102  * alt_plaintext = PAGE
00103  * alt_plaintext.typeNum=99
00104  * alt_plaintext.config.disableAllHeaderCode = 1
00105  * alt_plaintext.10 = TEMPLATE
00106  * alt_plaintext.10 {
00107  *   template = FILE
00108  *   template.file = {$plugin.alt.plaintext.file.template}
00109  *   marks.CONTENT < styles.content.get
00110  *   marks.CONTENT.renderObj = < lib.alt_plaintext.renderObj
00111  *   marks.DATE = TEXT
00112  *   marks.DATE.data = date:U
00113  *   marks.DATE.strftime = %e. %B %Y
00114  * }
00115  *
00116  * (And then also "lib.alt_plaintext.renderObj" is configured extensively - basically with the TypoScript options passed to this class. See the static template "plugin.alt.plaintext")
00117  *
00118  * @author  Kasper Skårhøj <kasperYYYY@typo3.com>
00119  * @package TYPO3
00120  * @subpackage tslib
00121  * @link http://typo3.org/doc.0.html?&tx_extrepmgm_pi1[extUid]=270&tx_extrepmgm_pi1[tocEl]=398&cHash=e3024de334
00122  */
00123 class user_plaintext {
00124     var $cObj;
00125     var $conf=array();
00126     var $charWidth=76;
00127 
00128     /**
00129      * Main function, called from TypoScript
00130      * A content object that renders "tt_content" records. See the comment to this class for TypoScript example of how to trigger it.
00131      * This detects the CType of the current content element and renders it accordingly. Only wellknown types are rendered.
00132      *
00133      * @param   string      Empty, ignore.
00134      * @param   array       TypoScript properties for this content object/function call
00135      * @return  string      Plain text content
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 'list':
00182                 $lines[]=$this->getHeader();
00183                 $lines[]=$this->getList();
00184             break;
00185             case 'table':
00186                 $lines[]=$this->getHeader();
00187                 $lines[]=$this->breakTable(strip_tags($this->parseBody($this->cObj->data['bodytext'])));
00188             break;
00189             case 'html':
00190                 $lines[]=$this->getHTML();
00191             break;
00192             default:
00193                 $defaultOutput = $this->getString($this->conf['defaultOutput']);
00194                 if ($defaultOutput) {
00195                     $lines[]=str_replace('###CType###',$CType,$defaultOutput);
00196                 }
00197             break;
00198         }
00199 
00200         $lines[]='';    // First break.
00201         $content = implode(chr(10),$lines);
00202 
00203             // User processing:
00204         $content=$this->userProcess('userProc',$content);
00205         return $content;
00206     }
00207 
00208     /**
00209      * Creates a menu/sitemap
00210      *
00211      * @return  string      Content
00212      */
00213     function getMenuSitemap()   {
00214         $str = $this->cObj->cObjGetSingle($this->conf['menu'],$this->conf['menu.']);
00215         $str = $this->breakBulletlist(trim(strip_tags(preg_replace('/<br[ \/]*>/i',chr(10),$this->parseBody($str)))));
00216         return $str;
00217     }
00218 
00219     /**
00220      * Creates a shortcut ("Insert Records")
00221      *
00222      * @return  string      Content
00223      */
00224     function getShortcut()  {
00225         $str = $this->cObj->cObjGetSingle($this->conf['shortcut'],$this->conf['shortcut.']);
00226         return $str;
00227     }
00228 
00229     /**
00230      * Creates an HTML element (stripping tags of course)
00231      *
00232      * @param   string      HTML content to process. If not passed along, the bodytext field is used.
00233      * @return  string      Content
00234      */
00235     function getHTML($str=array())  {
00236         return $this->breakContent(strip_tags(preg_replace('/<br[ \/]*>/i',chr(10),$this->parseBody(is_string($str)?$str:$this->cObj->data['bodytext']))));
00237     }
00238 
00239     /**
00240      * Creates a header (used for most elements)
00241      *
00242      * @return  string      Content
00243      * @see renderHeader()
00244      */
00245     function getHeader()    {
00246         // links...
00247         return $this->renderHeader($this->cObj->data['header'],$this->cObj->data['header_layout']);
00248     }
00249 
00250     /**
00251      * Get images found in the "image" field of "tt_content"
00252      *
00253      * @return  string      Content
00254      */
00255     function getImages()    {
00256         $images = $this->renderImages($this->cObj->data['image'],!$this->cObj->data['image_zoom']?$this->cObj->data['image_link']:'',$this->cObj->data['imagecaption']);
00257         return $images;
00258     }
00259 
00260     /**
00261      * Parsing the bodytext field content, removing typical entities and <br /> tags.
00262      *
00263      * @param   string      Field content from "bodytext"
00264      * @return  string      Processed content
00265      */
00266     function parseBody($str)    {
00267             // First, regular parsing:
00268         $str = preg_replace('/<br[ \/]*>/i',' ',$str);
00269         $str = $this->cObj->stdWrap($str,$this->conf['bodytext.']['stdWrap.']);
00270             // Then all a-tags:
00271         $aConf = array();
00272         $aConf['parseFunc.']['tags.']['a']='USER';
00273         $aConf['parseFunc.']['tags.']['a.']['userFunc']='user_plaintext->atag_to_http';
00274         $aConf['parseFunc.']['tags.']['a.']['siteUrl'] = $this->siteUrl;
00275 
00276         $str = $this->cObj->stdWrap($str,$aConf);
00277         $str = str_replace('&nbsp;',' ',t3lib_div::htmlspecialchars_decode($str));
00278         return $str;
00279     }
00280 
00281     /**
00282      * Creates a list of links to uploaded files.
00283      *
00284      * @param   string      List of uploaded filenames from "uploads/media/" (or $upload_path)
00285      * @param   string      Alternative path value
00286      * @return  string      Content
00287      */
00288     function renderUploads($str,$upload_path='uploads/media/')  {
00289         $files = explode(',',$str);
00290         reset($files);
00291         $lines=array();
00292         if ($this->conf['uploads.']['header'])  {$lines[]=$this->getString($this->conf['uploads.']['header']);}
00293         while(list($k,$file)=each($files))  {
00294             $lines[]=$this->siteUrl.$upload_path.$file;
00295         }
00296         return implode(chr(10),$lines);
00297     }
00298 
00299     /**
00300      * Creates a list
00301      *
00302      * @param   string  type of content
00303      * @return  string  Content
00304      */
00305     function getList($CType = 'list') {
00306         $str = $this->cObj->cObjGetSingle($this->conf[$CType], $this->conf[$CType . '.']);
00307         return trim(strip_tags($this->parseBody($str)));
00308     }
00309 
00310     /**
00311      * Renders a content element header, observing the layout type giving different header formattings
00312      *
00313      * @param   string      The header string
00314      * @param   integer     The layout type of the header (in the content element)
00315      * @return  string      Content
00316      */
00317     function renderHeader($str,$type=0) {
00318         if ($str)   {
00319             $hConf = $this->conf['header.'];
00320             $defaultType = t3lib_div::intInRange($hConf['defaultType'],1,5);
00321             $type=t3lib_div::intInRange($type,0,6);
00322             if (!$type) $type=$defaultType;
00323             if ($type!=6)   {   // not hidden
00324                 $tConf = $hConf[$type.'.'];
00325 
00326                 $lines=array();
00327 
00328                 $blanks = t3lib_div::intInRange($tConf['preBlanks'],0,1000);
00329                 if ($blanks)    {
00330                     $lines[]=str_pad('', $blanks-1, chr(10));
00331                 }
00332 
00333                 $lines=$this->pad($lines,$tConf['preLineChar'],$tConf['preLineLen']);
00334 
00335                 $blanks = t3lib_div::intInRange($tConf['preLineBlanks'],0,1000);
00336                 if ($blanks)    {$lines[]=str_pad('', $blanks-1, chr(10));}
00337 
00338                 if ($this->cObj->data['date'])  {
00339                     $lines[] = $this->getString($hConf['datePrefix']).date($hConf['date']?$hConf['date']:$GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$this->cObj->data['date']);
00340                 }
00341                 $prefix='';
00342                 $str=$this->getString($tConf['prefix']).$str;
00343                 if ($tConf['autonumber'])   $str=$this->cObj->parentRecordNumber.$str;
00344                 if ($this->cObj->data['header_position']=='right')  {$prefix=str_pad(' ',($this->charWidth-strlen($str)));}
00345                 if ($this->cObj->data['header_position']=='center') {$prefix=str_pad(' ',floor(($this->charWidth-strlen($str))/2));}
00346                 $lines[]=$this->cObj->stdWrap($prefix.$str,$tConf['stdWrap.']);
00347                 if ($this->cObj->data['header_link'])       {$lines[] = $this->getString($hConf['linkPrefix']).$this->getLink($this->cObj->data['header_link']);}
00348 
00349                 $blanks = t3lib_div::intInRange($tConf['postLineBlanks'],0,1000);
00350                 if ($blanks)    {$lines[]=str_pad('', $blanks-1, chr(10));}
00351 
00352                 $lines=$this->pad($lines,$tConf['postLineChar'],$tConf['postLineLen']);
00353 
00354                 $blanks = t3lib_div::intInRange($tConf['postBlanks'],0,1000);
00355                 if ($blanks)    {$lines[]=str_pad('', $blanks-1, chr(10));}
00356                 return implode(chr(10),$lines);
00357             }
00358         }
00359     }
00360 
00361     /**
00362      * Function used to repeat a char pattern in head lines (like if you want "********" above/below a header)
00363      *
00364      * @param   array       Array of existing lines to which the new char-pattern should be added
00365      * @param   string      The character pattern to repeat. Default is "-"
00366      * @param   integer     The length of the line. $preLineChar will be repeated to fill in this length.
00367      * @return  array       The input array with a new line added.
00368      * @see renderHeader()
00369      */
00370     function pad($lines,$preLineChar,$len)  {
00371         $strPad = t3lib_div::intInRange($len,0,1000);
00372         $strPadChar = $preLineChar?$preLineChar:'-';
00373         if ($strPad)    {
00374             $lines[]=str_pad('', $strPad, $strPadChar);
00375         }
00376         return $lines;
00377     }
00378 
00379     /**
00380      * Function used to wrap the bodytext field content (or image caption) into lines of a max length of
00381      *
00382      * @param   string      The content to break
00383      * @return  string      Processed value.
00384      * @see main_plaintext(), breakLines()
00385      */
00386     function breakContent($str) {
00387         $cParts = explode(chr(10),$str);
00388         reset($cParts);
00389         $lines=array();
00390         while(list(,$substrs)=each($cParts))    {
00391             $lines[]=$this->breakLines($substrs);
00392         }
00393         return implode(chr(10),$lines);
00394     }
00395 
00396     /**
00397      * Breaks content lines into a bullet list
00398      *
00399      * @param   string      Content string to make into a bullet list
00400      * @return  string      Processed value
00401      */
00402     function breakBulletlist($str)  {
00403         $type = $this->cObj->data['layout'];
00404         $type=t3lib_div::intInRange($type,0,3);
00405 
00406         $tConf = $this->conf['bulletlist.'][$type.'.'];
00407 
00408         $cParts = explode(chr(10),$str);
00409         reset($cParts);
00410         $lines=array();
00411         $c=0;
00412         while(list(,$substrs)=each($cParts))    {
00413             $c++;
00414             $bullet = $tConf['bullet'] ? $this->getString($tConf['bullet']) : ' - ';
00415             $bLen=strlen($bullet);
00416             $bullet = substr(str_replace('#',$c,$bullet),0,$bLen);
00417             $secondRow = substr($tConf['secondRow']?$this->getString($tConf['secondRow']):str_pad('',strlen($bullet),' '),0,$bLen);
00418 
00419             $lines[]=$bullet.$this->breakLines($substrs,chr(10).$secondRow,$this->charWidth-$bLen);
00420 
00421             $blanks = t3lib_div::intInRange($tConf['blanks'],0,1000);
00422             if ($blanks)    {$lines[]=str_pad('', $blanks-1, chr(10));}
00423         }
00424         return implode(chr(10),$lines);
00425     }
00426 
00427     /**
00428      * Formatting a table in plain text (based on the paradigm of lines being content rows and cells separated by "|")
00429      *
00430      * @param   string      Content string
00431      * @return  string      Processed value
00432      */
00433     function breakTable($str)   {
00434         $cParts = explode(chr(10),$str);
00435         reset($cParts);
00436         $lines=array();
00437         $cols = intval($this->conf['cols']) ? intval($this->conf['cols']) : 0 ;
00438         $c=0;
00439         while(list(,$substrs)=each($cParts))    {
00440             $c++;
00441             if (trim($substrs)) {
00442                 $lineParts=explode('|',$substrs);
00443                 if (!$cols) $cols=count($lineParts);
00444 
00445                 for ($a=0;$a<$cols;$a++)    {
00446                     $jdu = explode(chr(10),$this->breakLines($lineParts[$a],chr(10),ceil($this->charWidth/$cols)));
00447                     $lines[$c][$a]=$jdu;
00448                 }
00449             }
00450         }
00451         $messure = $this->traverseTable($lines);
00452 
00453 
00454         $divChar='-';
00455         $joinChar='+';
00456         $colChar='|';
00457 
00458         // Make table:
00459         $outLines = array();
00460         $outLines[]=$this->addDiv($messure,'',$divChar,$joinChar,$cols);
00461 
00462         reset($lines);
00463         while(list($k,$v)=each($lines)) {
00464             $top = intval($messure[1][$k]);
00465             for ($aa=0;$aa<$top;$aa++)  {
00466                 $tempArr=array();
00467                 for ($bb=0;$bb<$cols;$bb++) {
00468                     $tempArr[$bb]=str_pad($v[$bb][$aa],$messure[0][$bb],' ');
00469                 }
00470                 $outLines[]=$colChar.implode($colChar,$tempArr).$colChar;
00471             }
00472             $outLines[]=$this->addDiv($messure,'',$divChar,$joinChar,$cols);
00473         }
00474         return implode(chr(10),$outLines);
00475     }
00476 
00477     /**
00478      * Subfunction for breakTable(): Adds a divider line between table rows.
00479      *
00480      * @param   array       Some information about sizes
00481      * @param   string      Empty string.
00482      * @param   string      Character to use for the divider line, typically "-"
00483      * @param   string      Join character, typically "+"
00484      * @param   integer     Number of table columns
00485      * @return  string      Divider line for the table
00486      * @access private
00487      * @see breakTable()
00488      */
00489     function addDiv($messure,$content,$divChar,$joinChar,$cols) {
00490         $tempArr=array();
00491         for ($a=0;$a<$cols;$a++)    {
00492             $tempArr[$a]=str_pad($content,$messure[0][$a],$divChar);
00493         }
00494         return $joinChar.implode($joinChar,$tempArr).$joinChar;
00495     }
00496 
00497     /**
00498      * Traverses the table lines/cells and creates arrays with statistics for line numbers and lengths
00499      *
00500      * @param   array       Array with [table rows] [table cells] [lines in cell]
00501      * @return  array       Statistics (max lines/lengths)
00502      * @access private
00503      * @see breakTable()
00504      */
00505     function traverseTable($tableLines) {
00506         $maxLen=array();
00507         $maxLines=array();
00508         reset($tableLines);
00509         while(list($k,$v)=each($tableLines))    {
00510             reset($v);
00511             while(list($kk,$vv)=each($v))   {
00512                 reset($vv);
00513                 while(list($lk,$lv)=each($vv))  {
00514                     if (strlen($lv)>intval($maxLen[$kk]))   $maxLen[$kk]=strlen($lv);
00515                 }
00516                 if (count($vv)>intval($maxLines[$k]))   $maxLines[$k]=count($vv);
00517             }
00518         }
00519         return array($maxLen,$maxLines);
00520     }
00521 
00522     /**
00523      * Render block of images - which means creating lines with links to the images.
00524      *
00525      * @param   string      List of image filenames (from "image" field in tt_content records)
00526      * @param   string      Link value from the "image_link" field in tt_content records
00527      * @param   string      Caption text
00528      * @param   string      Alternative relative path for the files listed in $str
00529      * @return  string      Content
00530      * @see getImages()
00531      */
00532     function renderImages($str,$links,$caption,$upload_path='uploads/pics/')    {
00533         $images = explode(',',$str);
00534         $linksArr = explode(',',$links);
00535         reset($images);
00536         $lines=array();
00537         if ($this->conf['images.']['header'])   {$lines[]=$this->getString($this->conf['images.']['header']);}
00538         while(list($k,$file)=each($images)) {
00539             $lines[]=$this->siteUrl.$upload_path.$file;
00540             if ($links && count($linksArr)>1)   {
00541                 if (isset($linksArr[$k]))   {
00542                     $ll=$linksArr[$k];
00543                 } else {
00544                     $ll=$linksArr[0];
00545                 }
00546 
00547                 $theLink = $this->getLink($ll);
00548                 if ($theLink)   {$lines[]=$this->getString($this->conf['images.']['linkPrefix']).$theLink;}
00549             }
00550         }
00551         if ($links && count($linksArr)==1)  {
00552             $theLink = $this->getLink($links);
00553             if ($theLink)   {$lines[]=$this->getString($this->conf['images.']['linkPrefix']).$theLink;}
00554         }
00555         if ($caption)   {
00556             $lines[]='';
00557             $cHeader = trim($this->getString($this->conf['images.']['captionHeader']));
00558             if ($cHeader)       $lines[]=$cHeader;
00559             $lines[]=$this->breakContent($caption);
00560         }
00561 
00562         return implode(chr(10),$lines);
00563     }
00564 
00565     /**
00566      * Returns a typolink URL based on input.
00567      *
00568      * @param   string      Parameter to typolink
00569      * @return  string      The URL returned from $this->cObj->getTypoLink_URL(); - possibly it prefixed with the URL of the site if not present already
00570      */
00571     function getLink($ll)   {
00572         $theLink=$this->cObj->getTypoLink_URL($ll);
00573         if (substr($theLink,0,4)!='http')   {
00574             $theLink=$this->siteUrl.$theLink;
00575         }
00576         return $theLink;
00577     }
00578 
00579     /**
00580      * Breaking lines into fixed length lines, using t3lib_div::breakLinesForEmail()
00581      *
00582      * @param   string      The string to break
00583      * @param   string      Line break character
00584      * @param   integer     Length of lines, default is $this->charWidth
00585      * @return  string      Processed string
00586      * @see t3lib_div::breakLinesForEmail()
00587      */
00588     function breakLines($str,$implChar="\n",$charWidth=0)   {
00589         return t3lib_div::breakLinesForEmail($str,$implChar,$charWidth?$charWidth:$this->charWidth);
00590     }
00591 
00592     /**
00593      * Explodes a string with "|" and if the second part is found it will return this, otherwise the first part.
00594      * Used for many TypoScript properties used in this class since they need preceeding whitespace to be preserved.
00595      *
00596      * @param   string      Input string
00597      * @return  string      Output string
00598      * @access private
00599      */
00600     function getString($str)    {
00601         $parts = explode('|',$str);
00602         return strcmp($parts[1],'')?$parts[1]:$parts[0];
00603     }
00604 
00605     /**
00606      * Calls a user function for processing of data
00607      *
00608      * @param   string      TypoScript property name, pointing to the definition of the user function to call (from the TypoScript array internally in this class). This array is passed to the user function. Notice that "parentObj" property is a reference to this class ($this)
00609      * @param   mixed       Variable to process
00610      * @return  mixed       The processed $passVar as returned by the function call
00611      */
00612     function userProcess($mConfKey,$passVar)    {
00613         if ($this->conf[$mConfKey]) {
00614             $funcConf = $this->conf[$mConfKey.'.'];
00615             $funcConf['parentObj'] = $this;
00616             $passVar = $GLOBALS['TSFE']->cObj->callUserFunction($this->conf[$mConfKey], $funcConf, $passVar);
00617         }
00618         return $passVar;
00619     }
00620 
00621     /**
00622      * Function used by TypoScript "parseFunc" to process links in the bodytext.
00623      * Extracts the link and shows it in plain text in a parathesis next to the link text. If link was relative the site URL was prepended.
00624      *
00625      * @param   string      Empty, ignore.
00626      * @param   array       TypoScript parameters
00627      * @return  string      Processed output.
00628      * @see parseBody()
00629      */
00630     function atag_to_http($content,$conf)   {
00631         $this->conf = $conf;
00632         $this->siteUrl=$conf['siteUrl'];
00633         $theLink  = trim($this->cObj->parameters['href']);
00634         if (strtolower(substr($theLink,0,7))=='mailto:')    {
00635             $theLink=substr($theLink,7);
00636         } elseif (substr($theLink,0,4)!='http') {
00637             $theLink=$this->siteUrl.$theLink;
00638         }
00639         return $this->cObj->getCurrentVal().' (Link: '.$theLink.' )';
00640     }
00641 
00642     /**
00643      * User function (called from TypoScript) for generating a bullet list (used in parsefunc)
00644      *
00645      * @param   string      Empty, ignore.
00646      * @param   array       TypoScript parameters
00647      * @return  string      Processed output.
00648      */
00649     function typolist($content,$conf)   {
00650         $this->conf = $this->cObj->mergeTSRef($conf,'bulletlist');
00651         $this->siteUrl=$conf['siteUrl'];
00652         $str = trim($this->cObj->getCurrentVal());
00653         $this->cObj->data['layout'] = $this->cObj->parameters['type'];
00654         return $this->breakBulletlist($str);
00655     }
00656 
00657     /**
00658      * User function (called from TypoScript) for generating a typo header tag (used in parsefunc)
00659      *
00660      * @param   string      Empty, ignore.
00661      * @param   array       TypoScript parameters
00662      * @return  string      Processed output.
00663      */
00664     function typohead($content,$conf)   {
00665         $this->conf = $this->cObj->mergeTSRef($conf,'header');
00666 
00667         $this->siteUrl=$conf['siteUrl'];
00668         $str = trim($this->cObj->getCurrentVal());
00669         $this->cObj->data['header_layout'] = $this->cObj->parameters['type'];
00670         $this->cObj->data['header_position'] = $this->cObj->parameters['align'];
00671         $this->cObj->data['header']=$str;
00672 
00673         return $this->getHeader();
00674     }
00675 
00676     /**
00677      * User function (called from TypoScript) for generating a code listing (used in parsefunc)
00678      *
00679      * @param   string      Empty, ignore.
00680      * @param   array       TypoScript parameters
00681      * @return  string      Processed output.
00682      */
00683     function typocode($content,$conf)   {
00684             // Nothing is really done here...
00685         $this->conf = $conf;
00686         $this->siteUrl=$conf['siteUrl'];
00687         return $this->cObj->getCurrentVal();
00688     }
00689 }
00690 
00691 
00692 
00693 
00694 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['media/scripts/plaintextLib.inc'])) {
00695     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['media/scripts/plaintextLib.inc']);
00696 }
00697 ?>