Documentation TYPO3 par Ameos

class.tx_cssstyledcontent_pi1.php

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 ***************************************************************/
00055 require_once(PATH_tslib.'class.tslib_pibase.php');
00056 
00057 
00058 
00067 class tx_cssstyledcontent_pi1 extends tslib_pibase {
00068 
00069                 // Default plugin variables:
00070         var $prefixId = 'tx_cssstyledcontent_pi1';              // Same as class name
00071         var $scriptRelPath = 'pi1/class.tx_cssstyledcontent_pi1.php';   // Path to this script relative to the extension dir.
00072         var $extKey = 'css_styled_content';             // The extension key.
00073         var $conf = array();
00074 
00075 
00076 
00077 
00078 
00079 
00080 
00081         /***********************************
00082          *
00083          * Rendering of Content Elements:
00084          *
00085          ***********************************/
00086 
00095         function render_bullets($content,$conf) {
00096 
00097                         // Look for hook before running default code for function
00098                 if ($hookObj = &$this->hookRequest('render_bullets'))   {
00099                         return $hookObj->render_bullets($content,$conf);
00100                 } else {
00101 
00102                                 // Get bodytext field content, returning blank if empty:
00103                         $content = trim($this->cObj->data['bodytext']);
00104                         if (!strcmp($content,''))       return '';
00105 
00106                                 // Split into single lines:
00107                         $lines = t3lib_div::trimExplode(chr(10),$content);
00108                         while(list($k)=each($lines))    {
00109                                 $lines[$k]='
00110                                         <li>'.$this->cObj->stdWrap($lines[$k],$conf['innerStdWrap.']).'</li>';
00111                         }
00112 
00113                                 // Set header type:
00114                         $type = intval($this->cObj->data['layout']);
00115 
00116                                 // Compile list:
00117                         $out = '
00118                                 <ul class="csc-bulletlist csc-bulletlist-'.$type.'">'.
00119                                         implode('',$lines).'
00120                                 </ul>';
00121 
00122                                 // Calling stdWrap:
00123                         if ($conf['stdWrap.']) {
00124                                 $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
00125                         }
00126 
00127                                 // Return value
00128                         return $out;
00129                 }
00130         }
00131 
00140         function render_table($content,$conf)   {
00141 
00142                         // Look for hook before running default code for function
00143                 if ($hookObj = &$this->hookRequest('render_table'))     {
00144                         return $hookObj->render_table($content,$conf);
00145                 } else {
00146 
00147                                 // Get bodytext field content
00148                         $content = trim($this->cObj->data['bodytext']);
00149                         if (!strcmp($content,''))       return '';
00150 
00151                                 // Split into single lines (will become table-rows):
00152                         $rows = t3lib_div::trimExplode(chr(10),$content);
00153 
00154                                 // Find number of columns to render:
00155                         $cols = t3lib_div::intInRange($this->cObj->data['cols']?$this->cObj->data['cols']:count(explode('|',current($rows))),0,100);
00156 
00157                                 // Traverse rows (rendering the table here)
00158                         $rCount = count($rows);
00159                         foreach($rows as $k => $v)      {
00160                                 $cells = explode('|',$v);
00161                                 $newCells=array();
00162                                 for($a=0;$a<$cols;$a++) {
00163                                         if (!strcmp(trim($cells[$a]),''))       $cells[$a]='&nbsp;';
00164                                         $cellAttribs =  ($a>0 && ($cols-1)==$a) ? ' class="td-last"' : ' class="td-'.$a.'"';
00165                                         $newCells[$a] = '
00166                                                 <td'.$cellAttribs.'><p>'.$this->cObj->stdWrap($cells[$a],$conf['innerStdWrap.']).'</p></td>';
00167                                 }
00168 
00169                                 $oddEven = $k%2 ? 'tr-odd' : 'tr-even';
00170                                 $rowAttribs =  ($k>0 && ($rCount-1)==$k) ? ' class="'.$oddEven.' tr-last"' : ' class="'.$oddEven.' tr-'.$k.'"';
00171                                 $rows[$k]='
00172                                         <tr'.$rowAttribs.'>'.implode('',$newCells).'
00173                                         </tr>';
00174                         }
00175 
00176                                 // Set header type:
00177                         $type = intval($this->cObj->data['layout']);
00178 
00179                                 // Table tag params.
00180                         $tableTagParams = $this->getTableAttributes($conf,$type);
00181                         $tableTagParams['class'] = 'contenttable contenttable-'.$type;
00182 
00183                                 // Compile table output:
00184                         $out = '
00185                                 <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.
00186                                         implode('',$rows).'
00187                                 </table>';
00188 
00189                                 // Calling stdWrap:
00190                         if ($conf['stdWrap.']) {
00191                                 $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
00192                         }
00193 
00194                                 // Return value
00195                         return $out;
00196                 }
00197         }
00198 
00207         function render_uploads($content,$conf) {
00208 
00209                         // Look for hook before running default code for function
00210                 if ($hookObj = &$this->hookRequest('render_uploads'))   {
00211                         return $hookObj->render_uploads($content,$conf);
00212                 } else {
00213 
00214                         $out = '';
00215 
00216                                 // Set layout type:
00217                         $type = intval($this->cObj->data['layout']);
00218 
00219                                 // Get the list of files (using stdWrap function since that is easiest)
00220                         $lConf=array();
00221                         $lConf['override.']['filelist.']['field'] = 'select_key';
00222                         $fileList = $this->cObj->stdWrap($this->cObj->data['media'],$lConf);
00223 
00224                                 // Explode into an array:
00225                         $fileArray = t3lib_div::trimExplode(',',$fileList,1);
00226 
00227                                 // If there were files to list...:
00228                         if (count($fileArray))  {
00229 
00230                                         // Get the path from which the images came:
00231                                 $selectKeyValues = explode('|',$this->cObj->data['select_key']);
00232                                 $path = trim($selectKeyValues[0]) ? trim($selectKeyValues[0]) : 'uploads/media/';
00233 
00234                                         // Get the descriptions for the files (if any):
00235                                 $descriptions = t3lib_div::trimExplode(chr(10),$this->cObj->data['imagecaption']);
00236 
00237                                         // Adding hardcoded TS to linkProc configuration:
00238                                 $conf['linkProc.']['path.']['current'] = 1;
00239                                 $conf['linkProc.']['icon'] = 1; // Always render icon - is inserted by PHP if needed.
00240                                 $conf['linkProc.']['icon.']['wrap'] = ' | //**//';      // Temporary, internal split-token!
00241                                 $conf['linkProc.']['icon_link'] = 1;    // ALways link the icon
00242                                 $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.
00243 
00244                                         // Traverse the files found:
00245                                 $filesData = array();
00246                                 foreach($fileArray as $key => $fileName)        {
00247                                         $absPath = t3lib_div::getFileAbsFileName($path.$fileName);
00248                                         if (@is_file($absPath)) {
00249                                                 $fI = pathinfo($fileName);
00250                                                 $filesData[$key] = array();
00251 
00252                                                 $filesData[$key]['filename'] = $fileName;
00253                                                 $filesData[$key]['path'] = $path;
00254                                                 $filesData[$key]['filesize'] = filesize($absPath);
00255                                                 $filesData[$key]['fileextension'] = strtolower($fI['extension']);
00256                                                 $filesData[$key]['description'] = trim($descriptions[$key]);
00257 
00258                                                 $this->cObj->setCurrentVal($path);
00259                                                 $GLOBALS['TSFE']->register['ICON_REL_PATH'] = $path.$fileName;
00260                                                 $filesData[$key]['linkedFilenameParts'] = explode('//**//',$this->cObj->filelink($fileName, $conf['linkProc.']));
00261                                         }
00262                                 }
00263 
00264                                         // Now, lets render the list!
00265                                 $tRows = array();
00266                                 foreach($filesData as $key => $fileD)   {
00267 
00268                                                 // Setting class of table row for odd/even rows:
00269                                         $oddEven = $key%2 ? 'tr-odd' : 'tr-even';
00270 
00271                                                 // Render row, based on the "layout" setting
00272                                         $tRows[]='
00273                                         <tr class="'.$oddEven.'">'.($type>0 ? '
00274                                                 <td class="csc-uploads-icon">
00275                                                         '.$fileD['linkedFilenameParts'][0].'
00276                                                 </td>' : '').'
00277                                                 <td class="csc-uploads-fileName">
00278                                                         <p>'.$fileD['linkedFilenameParts'][1].'</p>'.
00279                                                         ($fileD['description'] ? '
00280                                                         <p class="csc-uploads-description">'.htmlspecialchars($fileD['description']).'</p>' : '').'
00281                                                 </td>'.($this->cObj->data['filelink_size'] ? '
00282                                                 <td class="csc-uploads-fileSize">
00283                                                         <p>'.t3lib_div::formatSize($fileD['filesize']).'</p>
00284                                                 </td>' : '').'
00285                                         </tr>';
00286                                 }
00287 
00288                                         // Table tag params.
00289                                 $tableTagParams = $this->getTableAttributes($conf,$type);
00290                                 $tableTagParams['class'] = 'csc-uploads csc-uploads-'.$type;
00291 
00292 
00293                                         // Compile it all into table tags:
00294                                 $out = '
00295                                 <table '.t3lib_div::implodeAttributes($tableTagParams).'>
00296                                         '.implode('',$tRows).'
00297                                 </table>';
00298                         }
00299 
00300                                 // Calling stdWrap:
00301                         if ($conf['stdWrap.']) {
00302                                 $out = $this->cObj->stdWrap($out, $conf['stdWrap.']);
00303                         }
00304 
00305                                 // Return value
00306                         return $out;
00307                 }
00308         }
00309 
00310 
00311 
00312 
00313 
00314 
00315 
00316 
00317 
00318 
00319 
00320 
00321 
00322         /************************************
00323          *
00324          * Helper functions
00325          *
00326          ************************************/
00327 
00335         function getTableAttributes($conf,$type)        {
00336 
00337                         // Initializing:
00338                 $tableTagParams_conf = $conf['tableParams_'.$type.'.'];
00339 
00340                 $conf['color.'][200] = '';
00341                 $conf['color.'][240] = 'black';
00342                 $conf['color.'][241] = 'white';
00343                 $conf['color.'][242] = '#333333';
00344                 $conf['color.'][243] = 'gray';
00345                 $conf['color.'][244] = 'silver';
00346 
00347                         // Create table attributes array:
00348                 $tableTagParams = array();
00349                 $tableTagParams['border'] =  $this->cObj->data['table_border'] ? intval($this->cObj->data['table_border']) : $tableTagParams_conf['border'];
00350                 $tableTagParams['cellspacing'] =  $this->cObj->data['table_cellspacing'] ? intval($this->cObj->data['table_cellspacing']) : $tableTagParams_conf['cellspacing'];
00351                 $tableTagParams['cellpadding'] =  $this->cObj->data['table_cellpadding'] ? intval($this->cObj->data['table_cellpadding']) : $tableTagParams_conf['cellpadding'];
00352                 $tableTagParams['bgcolor'] =  isset($conf['color.'][$this->cObj->data['table_bgColor']]) ? $conf['color.'][$this->cObj->data['table_bgColor']] : $conf['color.']['default'];
00353 
00354                         // Return result:
00355                 return $tableTagParams;
00356         }
00357 
00364         function &hookRequest($functionName)    {
00365                 global $TYPO3_CONF_VARS;
00366 
00367                         // Hook: menuConfig_preProcessModMenu
00368                 if ($TYPO3_CONF_VARS['EXTCONF']['css_styled_content']['pi1_hooks'][$functionName]) {
00369                         $hookObj = &t3lib_div::getUserObj($TYPO3_CONF_VARS['EXTCONF']['css_styled_content']['pi1_hooks'][$functionName]);
00370                         if (method_exists ($hookObj, $functionName)) {
00371                                 $hookObj->pObj = &$this;
00372                                 return $hookObj;
00373                         }
00374                 }
00375         }
00376 }
00377 
00378 
00379 
00380 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/css_styled_content/pi1/class.tx_cssstyledcontent_pi1.php'])    {
00381         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/css_styled_content/pi1/class.tx_cssstyledcontent_pi1.php']);
00382 }
00383 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6