Documentation TYPO3 par Ameos

class.tx_cssstyledcontent_pi1.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2002-2004 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 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00051 require_once(PATH_tslib.'class.tslib_pibase.php');
00052 
00053 
00054 
00063 class tx_cssstyledcontent_pi1 extends tslib_pibase {
00064 
00065                 // Default plugin variables:
00066         var $prefixId = 'tx_cssstyledcontent_pi1';              // Same as class name
00067         var $scriptRelPath = 'pi1/class.tx_cssstyledcontent_pi1.php';   // Path to this script relative to the extension dir.
00068         var $extKey = 'css_styled_content';             // The extension key.
00069         var $conf = array();
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00077         /***********************************
00078          *
00079          * Rendering of Content Elements:
00080          *
00081          ***********************************/
00082 
00091         function render_bullets($content,$conf) {
00092 
00093                         // Get bodytext field content, returning blank if empty:
00094                 $content = trim($this->cObj->data['bodytext']);
00095                 if (!strcmp($content,''))       return '';
00096 
00097                         // Split into single lines:
00098                 $lines = t3lib_div::trimExplode(chr(10),$content);
00099                 while(list($k)=each($lines))    {
00100                         $lines[$k]='
00101                                 <li>'.$this->cObj->stdWrap($lines[$k],$conf['innerStdWrap.']).'</li>';
00102                 }
00103 
00104                         // Set header type:
00105                 $type = intval($this->cObj->data['layout']);
00106 
00107                         // Compile list:
00108                 $out = '
00109                         <ul class="csc-bulletlist csc-bulletlist-'.$type.'">'.
00110                                 implode('',$lines).'
00111                         </ul>';
00112 
00113                         // Calling stdWrap:
00114                 if ($conf['stdWrap.']) {
00115                         $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
00116                 }
00117 
00118                         // Return value
00119                 return $out;
00120         }
00121 
00130         function render_table($content,$conf)   {
00131 
00132                         // Get bodytext field content
00133                 $content = trim($this->cObj->data['bodytext']);
00134                 if (!strcmp($content,''))       return '';
00135 
00136                         // Split into single lines (will become table-rows):
00137                 $rows = t3lib_div::trimExplode(chr(10),$content);
00138 
00139                         // Find number of columns to render:
00140                 $cols = t3lib_div::intInRange($this->cObj->data['cols']?$this->cObj->data['cols']:count(explode('|',current($rows))),0,100);
00141 
00142                         // Traverse rows (rendering the table here)
00143                 $rCount = count($rows);
00144                 foreach($rows as $k => $v)      {
00145                         $cells = explode('|',$v);
00146                         $newCells=array();
00147                         for($a=0;$a<$cols;$a++) {
00148                                 if (!strcmp(trim($cells[$a]),''))       $cells[$a]='&nbsp;';
00149                                 $cellAttribs =  ($a>0 && ($cols-1)==$a) ? ' class="td-last"' : ' class="td-'.$a.'"';
00150                                 $newCells[$a] = '
00151                                         <td'.$cellAttribs.'><p>'.$this->cObj->stdWrap($cells[$a],$conf['innerStdWrap.']).'</p></td>';
00152                         }
00153 
00154                         $oddEven = $k%2 ? 'tr-odd' : 'tr-even';
00155                         $rowAttribs =  ($k>0 && ($rCount-1)==$k) ? ' class="'.$oddEven.' tr-last"' : ' class="'.$oddEven.' tr-'.$k.'"';
00156                         $rows[$k]='
00157                                 <tr'.$rowAttribs.'>'.implode('',$newCells).'
00158                                 </tr>';
00159                 }
00160 
00161                         // Set header type:
00162                 $type = intval($this->cObj->data['layout']);
00163 
00164                         // Table tag params.
00165                 $tableTagParams = $this->getTableAttributes($conf,$type);
00166                 $tableTagParams['class'] = 'contenttable contenttable-'.$type;
00167 
00168                         // Compile table output:
00169                 $out = '
00170                         <table '.t3lib_div::implodeAttributes($tableTagParams).'>'.     // Omitted xhtmlSafe argument TRUE - none of the values will be needed to be converted anyways, no need to spend processing time on that.
00171                                 implode('',$rows).'
00172                         </table>';
00173 
00174                         // Calling stdWrap:
00175                 if ($conf['stdWrap.']) {
00176                         $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
00177                 }
00178 
00179                         // Return value
00180                 return $out;
00181         }
00182 
00191         function render_uploads($content,$conf) {
00192 
00193                 $out = '';
00194 
00195                         // Set layout type:
00196                 $type = intval($this->cObj->data['layout']);
00197 
00198                         // Get the list of files (using stdWrap function since that is easiest)
00199                 $lConf=array();
00200                 $lConf['override.']['filelist.']['field'] = 'select_key';
00201                 $fileList = $this->cObj->stdWrap($this->cObj->data['media'],$lConf);
00202 
00203                         // Explode into an array:
00204                 $fileArray = t3lib_div::trimExplode(',',$fileList,1);
00205 
00206                         // If there were files to list...:
00207                 if (count($fileArray))  {
00208 
00209                                 // Get the path from which the images came:
00210                         $selectKeyValues = explode('|',$this->cObj->data['select_key']);
00211                         $path = trim($selectKeyValues[0]) ? trim($selectKeyValues[0]) : 'uploads/media/';
00212 
00213                                 // Get the descriptions for the files (if any):
00214                         $descriptions = t3lib_div::trimExplode(chr(10),$this->cObj->data['imagecaption']);
00215 
00216                                 // Adding hardcoded TS to linkProc configuration:
00217                         $conf['linkProc.']['path.']['current'] = 1;
00218                         $conf['linkProc.']['icon'] = 1; // Always render icon - is inserted by PHP if needed.
00219                         $conf['linkProc.']['icon.']['wrap'] = ' | //**//';      // Temporary, internal split-token!
00220                         $conf['linkProc.']['icon_link'] = 1;    // ALways link the icon
00221                         $conf['linkProc.']['icon_image_ext_list'] = ($type==2 || $type==3) ? $GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] : '';  // If the layout is type 2 or 3 we will render an image based icon if possible.
00222 
00223                                 // Traverse the files found:
00224                         $filesData = array();
00225                         foreach($fileArray as $key => $fileName)        {
00226                                 $absPath = t3lib_div::getFileAbsFileName($path.$fileName);
00227                                 if (@is_file($absPath)) {
00228                                         $fI = pathinfo($fileName);
00229                                         $filesData[$key] = array();
00230 
00231                                         $filesData[$key]['filename'] = $fileName;
00232                                         $filesData[$key]['path'] = $path;
00233                                         $filesData[$key]['filesize'] = filesize($absPath);
00234                                         $filesData[$key]['fileextension'] = strtolower($fI['extension']);
00235                                         $filesData[$key]['description'] = trim($descriptions[$key]);
00236 
00237                                         $this->cObj->setCurrentVal($path);
00238                                         $GLOBALS['TSFE']->register['ICON_REL_PATH'] = $path.$fileName;
00239                                         $filesData[$key]['linkedFilenameParts'] = explode('//**//',$this->cObj->filelink($fileName, $conf['linkProc.']));
00240                                 }
00241                         }
00242 
00243                                 // Now, lets render the list!
00244                         $tRows = array();
00245                         foreach($filesData as $key => $fileD)   {
00246 
00247                                         // Setting class of table row for odd/even rows:
00248                                 $oddEven = $key%2 ? 'tr-odd' : 'tr-even';
00249 
00250                                         // Render row, based on the "layout" setting
00251                                 $tRows[]='
00252                                 <tr class="'.$oddEven.'">'.($type>0 ? '
00253                                         <td class="csc-uploads-icon">
00254                                                 '.$fileD['linkedFilenameParts'][0].'
00255                                         </td>' : '').'
00256                                         <td class="csc-uploads-fileName">
00257                                                 <p>'.$fileD['linkedFilenameParts'][1].'</p>'.
00258                                                 ($fileD['description'] ? '
00259                                                 <p class="csc-uploads-description">'.htmlspecialchars($fileD['description']).'</p>' : '').'
00260                                         </td>'.($this->cObj->data['filelink_size'] ? '
00261                                         <td class="csc-uploads-fileSize">
00262                                                 <p>'.t3lib_div::formatSize($fileD['filesize']).'</p>
00263                                         </td>' : '').'
00264                                 </tr>';
00265                         }
00266 
00267                                 // Table tag params.
00268                         $tableTagParams = $this->getTableAttributes($conf,$type);
00269                         $tableTagParams['class'] = 'csc-uploads csc-uploads-'.$type;
00270 
00271 
00272                                 // Compile it all into table tags:
00273                         $out = '
00274                         <table '.t3lib_div::implodeAttributes($tableTagParams).'>
00275                                 '.implode('',$tRows).'
00276                         </table>';
00277                 }
00278 
00279                         // Calling stdWrap:
00280                 if ($conf['stdWrap.']) {
00281                         $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
00282                 }
00283 
00284                         // Return value
00285                 return $out;
00286         }
00287 
00288 
00289 
00290 
00291 
00292 
00293 
00294 
00295 
00296 
00297 
00298 
00299 
00300         /************************************
00301          *
00302          * Helper functions
00303          *
00304          ************************************/
00305 
00313         function getTableAttributes($conf,$type)        {
00314 
00315                         // Initializing:
00316                 $tableTagParams_conf = $conf['tableParams_'.$type.'.'];
00317 
00318                 $conf['color.'][200] = '';
00319                 $conf['color.'][240] = 'black';
00320                 $conf['color.'][241] = 'white';
00321                 $conf['color.'][242] = '#333333';
00322                 $conf['color.'][243] = 'gray';
00323                 $conf['color.'][244] = 'silver';
00324 
00325                         // Create table attributes array:
00326                 $tableTagParams = array();
00327                 $tableTagParams['border'] =  $this->cObj->data['table_border'] ? intval($this->cObj->data['table_border']) : $tableTagParams_conf['border'];
00328                 $tableTagParams['cellspacing'] =  $this->cObj->data['table_cellspacing'] ? intval($this->cObj->data['table_cellspacing']) : $tableTagParams_conf['cellspacing'];
00329                 $tableTagParams['cellpadding'] =  $this->cObj->data['table_cellpadding'] ? intval($this->cObj->data['table_cellpadding']) : $tableTagParams_conf['cellpadding'];
00330                 $tableTagParams['bgcolor'] =  isset($conf['color.'][$this->cObj->data['table_bgColor']]) ? $conf['color.'][$this->cObj->data['table_bgColor']] : $conf['color.']['default'];
00331 
00332                         // Return result:
00333                 return $tableTagParams;
00334         }
00335 }
00336 
00337 
00338 
00339 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/css_styled_content/pi1/class.tx_cssstyledcontent_pi1.php'])    {
00340         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/css_styled_content/pi1/class.tx_cssstyledcontent_pi1.php']);
00341 }
00342 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6