Documentation TYPO3 par Ameos

show_item.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2006 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 ***************************************************************/
00059 $BACK_PATH = '';
00060 require($BACK_PATH.'init.php');
00061 require($BACK_PATH.'template.php');
00062 require_once(PATH_t3lib.'class.t3lib_page.php');
00063 require_once(PATH_t3lib.'class.t3lib_loaddbgroup.php');
00064 require_once(PATH_t3lib.'class.t3lib_transferdata.php');
00065 
00066 
00067 
00068 
00069 
00070 
00071 
00072 
00073 
00074 
00075 
00076 
00084 class transferData extends t3lib_transferData   {
00085 
00086         var $formname = 'loadform';
00087         var $loading = 1;
00088 
00089                 // Extra for show_item.php:
00090         var $theRecord = Array();
00091 
00101         function regItem($table, $id, $field, $content) {
00102                 t3lib_div::loadTCA($table);
00103                 $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
00104                 switch($config['type']) {
00105                         case 'input':
00106                                 if (isset($config['checkbox']) && $content==$config['checkbox'])        {$content=''; break;}
00107                                 if (t3lib_div::inList($config['eval'],'date'))  {$content = Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$content); }
00108                         break;
00109                         case 'group':
00110                         break;
00111                         case 'select':
00112                         break;
00113                 }
00114                 $this->theRecord[$field]=$content;
00115         }
00116 }
00117 
00118 
00119 
00120 
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00135 class SC_show_item {
00136 
00137                 // GET vars:
00138         var $table;                     // Record table (or filename)
00139         var $uid;                       // Record uid  (or '' when filename)
00140 
00141                 // Internal, static:
00142         var $perms_clause;      // Page select clause
00143         var $access;            // If true, access to element is granted
00144         var $type;                      // Which type of element: "file" or "db"
00145         var $doc;                       // Document Template Object
00146 
00147                 // Internal, dynamic:
00148         var $content;           // Content Accumulation
00149         var $file;                      // For type "file": Filename
00150         var $pageinfo;          // For type "db": Set to page record of the parent page of the item set (if type="db")
00151         var $row;                       // For type "db": The database record row.
00152 
00153 
00160         function init() {
00161                 global $BE_USER,$LANG,$BACK_PATH,$TCA;
00162 
00163                         // Setting input variables.
00164                 $this->table = t3lib_div::_GET('table');
00165                 $this->uid = t3lib_div::_GET('uid');
00166 
00167                         // Initialize:
00168                 $this->perms_clause = $BE_USER->getPagePermsClause(1);
00169                 $this->access = 0;      // Set to true if there is access to the record / file.
00170                 $this->type = '';       // Sets the type, "db" or "file". If blank, nothing can be shown.
00171 
00172                         // Checking if the $table value is really a table and if the user has access to it.
00173                 if (isset($TCA[$this->table]))  {
00174                         t3lib_div::loadTCA($this->table);
00175                         $this->type = 'db';
00176                         $this->uid = intval($this->uid);
00177 
00178                                 // Check permissions and uid value:
00179                         if ($this->uid && $BE_USER->check('tables_select',$this->table))        {
00180                                 if ((string)$this->table=='pages')      {
00181                                         $this->pageinfo = t3lib_BEfunc::readPageAccess($this->uid,$this->perms_clause);
00182                                         $this->access = is_array($this->pageinfo) ? 1 : 0;
00183                                         $this->row = $this->pageinfo;
00184                                 } else {
00185                                         $this->row = t3lib_BEfunc::getRecord($this->table,$this->uid);
00186                                         if ($this->row) {
00187                                                 $this->pageinfo = t3lib_BEfunc::readPageAccess($this->row['pid'],$this->perms_clause);
00188                                                 $this->access = is_array($this->pageinfo) ? 1 : 0;
00189                                         }
00190                                 }
00191 
00192                                 $treatData = t3lib_div::makeInstance('t3lib_transferData');
00193                                 $treatData->renderRecord($this->table, $this->uid, 0, $this->row);
00194                                 $cRow = $treatData->theRecord;
00195                         }
00196                 } else  {
00197                         // if the filereference $this->file is relative, we correct the path
00198                         if (substr($this->table,0,3)=='../')    {
00199                                 $this->file = PATH_site.ereg_replace('^\.\./','',$this->table);
00200                         } else {
00201                                 $this->file = $this->table;
00202                         }
00203                         if (@is_file($this->file) && t3lib_div::isAllowedAbsPath($this->file))  {
00204                                 $this->type = 'file';
00205                                 $this->access = 1;
00206                         }
00207                 }
00208 
00209                         // Initialize document template object:
00210                 $this->doc = t3lib_div::makeInstance('smallDoc');
00211                 $this->doc->backPath = $BACK_PATH;
00212                 $this->doc->docType = 'xhtml_trans';
00213 
00214                         // Starting the page by creating page header stuff:
00215                 $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:show_item.php.viewItem'));
00216                 $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:show_item.php.viewItem'));
00217                 $this->content.=$this->doc->spacer(5);
00218         }
00219 
00225         function main() {
00226                 global $LANG;
00227 
00228                 if ($this->access)      {
00229                         $returnLinkTag = t3lib_div::_GP('returnUrl') ? '<a href="'.t3lib_div::_GP('returnUrl').'" class="typo3-goBack">' : '<a href="#" onclick="window.close();">';
00230 
00231                                 // render type by user func
00232                         $typeRendered = false;
00233                         if (is_array ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'])) {
00234                                 foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] as $classRef) {
00235                                         $typeRenderObj = t3lib_div::getUserObj($classRef);
00236                                         if(is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render'))    {
00237                                                 if ($typeRenderObj->isValid($this->type, $this)) {
00238                                                         $this->content .=  $typeRenderObj->render($this->type, $this);
00239                                                         $typeRendered = true;
00240                                                         break;
00241                                                 }
00242                                         }
00243                                 }
00244                         }
00245 
00246                                 // if type was not rendered use default rendering functions
00247                         if(!$typeRendered) {
00248                                         // Branch out based on type:
00249                                 switch($this->type)     {
00250                                         case 'db':
00251                                                 $this->renderDBInfo();
00252                                         break;
00253                                         case 'file':
00254                                                 $this->renderFileInfo($returnLinkTag);
00255                                         break;
00256                                 }
00257                         }
00258 
00259                                 // If return Url is set, output link to go back:
00260                         if (t3lib_div::_GP('returnUrl'))        {
00261                                 $this->content = $this->doc->section('',$returnLinkTag.'<strong>'.$LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.goBack',1).'</strong></a><br /><br />').$this->content;
00262 
00263                                 $this->content .= $this->doc->section('','<br />'.$returnLinkTag.'<strong>'.$LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.goBack',1).'</strong></a>');
00264                         }
00265                 }
00266         }
00267 
00273         function renderDBInfo() {
00274                 global $LANG,$TCA;
00275 
00276                         // Print header, path etc:
00277                 $code = $this->doc->getHeader($this->table,$this->row,$this->pageinfo['_thePath'],1).'<br />';
00278                 $this->content.= $this->doc->section('',$code);
00279 
00280                         // Initialize variables:
00281                 $tableRows = Array();
00282                 $i = 0;
00283 
00284                         // Traverse the list of fields to display for the record:
00285                 $fieldList = t3lib_div::trimExplode(',',$TCA[$this->table]['interface']['showRecordFieldList'],1);
00286                 foreach($fieldList as $name)    {
00287                         $name = trim($name);
00288                         if ($TCA[$this->table]['columns'][$name])       {
00289                                 if (!$TCA[$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields',$this->table.':'.$name))        {
00290                                         $i++;
00291                                         $tableRows[] = '
00292                                                 <tr>
00293                                                         <td class="bgColor5">'.$LANG->sL(t3lib_BEfunc::getItemLabel($this->table,$name),1).'</td>
00294                                                         <td class="bgColor4">'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($this->table,$name,$this->row[$name])).'</td>
00295                                                 </tr>';
00296                                 }
00297                         }
00298                 }
00299 
00300                         // Create table from the information:
00301                 $tableCode = '
00302                                         <table border="0" cellpadding="1" cellspacing="1" id="typo3-showitem">
00303                                                 '.implode('',$tableRows).'
00304                                         </table>';
00305                 $this->content.=$this->doc->section('',$tableCode);
00306                 $this->content.=$this->doc->divider(2);
00307 
00308                         // Add path and table information in the bottom:
00309                 $code = '';
00310                 $code.= $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.path').': '.t3lib_div::fixed_lgd_cs($this->pageinfo['_thePath'],-48).'<br />';
00311                 $code.= $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.table').': '.$LANG->sL($TCA[$this->table]['ctrl']['title']).' ('.$this->table.') - UID: '.$this->uid.'<br />';
00312                 $this->content.= $this->doc->section('', $code);
00313 
00314                         // References:
00315                 $this->content.= $this->doc->section('References to this item:',$this->makeRef($this->table,$this->row['uid']));
00316 
00317                         // References:
00318                 $this->content.= $this->doc->section('References from this item:',$this->makeRefFrom($this->table,$this->row['uid']));
00319         }
00320 
00327         function renderFileInfo($returnLinkTag) {
00328                 global $LANG;
00329 
00330                         // Initialize object to work on the image:
00331                 require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
00332                 $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
00333                 $imgObj->init();
00334                 $imgObj->mayScaleUp = 0;
00335                 $imgObj->absPrefix = PATH_site;
00336 
00337                         // Read Image Dimensions (returns false if file was not an image type, otherwise dimensions in an array)
00338                 $imgInfo = '';
00339                 $imgInfo = $imgObj->getImageDimensions($this->file);
00340 
00341                         // File information
00342                 $fI = t3lib_div::split_fileref($this->file);
00343                 $ext = $fI['fileext'];
00344 
00345                 $code = '';
00346 
00347                         // Setting header:
00348                 $icon = t3lib_BEfunc::getFileIcon($ext);
00349                 $url = 'gfx/fileicons/'.$icon;
00350                 $fileName = '<img src="'.$url.'" width="18" height="16" align="top" alt="" /><b>'.$LANG->sL('LLL:EXT:lang/locallang_core.php:show_item.php.file',1).':</b> '.$fI['file'];
00351                 if (t3lib_div::isFirstPartOfStr($this->file,PATH_site)) {
00352                         $code.= '<a href="../'.substr($this->file,strlen(PATH_site)).'" target="_blank">'.$fileName.'</a>';
00353                 } else {
00354                         $code.= $fileName;
00355                 }
00356                 $code.=' &nbsp;&nbsp;<b>'.$LANG->sL('LLL:EXT:lang/locallang_core.php:show_item.php.filesize').':</b> '.t3lib_div::formatSize(@filesize($this->file)).'<br />
00357                         ';
00358                 if (is_array($imgInfo)) {
00359                         $code.= '<b>'.$LANG->sL('LLL:EXT:lang/locallang_core.php:show_item.php.dimensions').':</b> '.$imgInfo[0].'x'.$imgInfo[1].' pixels';
00360                 }
00361                 $this->content.=$this->doc->section('',$code);
00362                 $this->content.=$this->doc->divider(2);
00363 
00364                         // If the file was an image...:
00365                 if (is_array($imgInfo)) {
00366 
00367                         $imgInfo = $imgObj->imageMagickConvert($this->file,'web','346','200m','','','',1);
00368                         $imgInfo[3] = '../'.substr($imgInfo[3],strlen(PATH_site));
00369                         $code = '<br />
00370                                 <div align="center">'.$returnLinkTag.$imgObj->imgTag($imgInfo).'</a></div>';
00371                         $this->content.= $this->doc->section('', $code);
00372                 } else {
00373                         $this->content.= $this->doc->spacer(10);
00374                         $lowerFilename = strtolower($this->file);
00375 
00376                                 // Archive files:
00377                         if (TYPO3_OS!='WIN' && !$GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function'])     {
00378                                 if ($ext=='zip')        {
00379                                         $code = '';
00380                                         $t = array();
00381                                         exec('unzip -l '.$this->file, $t);
00382                                         if (is_array($t))       {
00383                                                 reset($t);
00384                                                 next($t);
00385                                                 next($t);
00386                                                 next($t);
00387                                                 while(list(,$val)=each($t))     {
00388                                                         $parts = explode(' ',trim($val),7);
00389                                                         $code.= '
00390                                                                 '.$parts[6].'<br />';
00391                                                 }
00392                                                 $code = '
00393                                                         <span class="nobr">'.$code.'
00394                                                         </span>
00395                                                         <br /><br />';
00396                                         }
00397                                         $this->content.= $this->doc->section('', $code);
00398                                 } elseif($ext=='tar' || $ext=='tgz' || substr($lowerFilename,-6)=='tar.gz' || substr($lowerFilename,-5)=='tar.z')       {
00399                                         $code = '';
00400                                         if ($ext=='tar')        {
00401                                                 $compr = '';
00402                                         } else {
00403                                                 $compr = 'z';
00404                                         }
00405                                         $t = array();
00406                                         exec('tar t'.$compr.'f '.$this->file, $t);
00407                                         if (is_array($t))       {
00408                                                 foreach($t as $val)     {
00409                                                         $code.='
00410                                                                 '.$val.'<br />';
00411                                                 }
00412 
00413                                                 $code.='
00414                                                                  -------<br/>
00415                                                                  '.count($t).' files';
00416 
00417                                                 $code = '
00418                                                         <span class="nobr">'.$code.'
00419                                                         </span>
00420                                                         <br /><br />';
00421                                         }
00422                                         $this->content.= $this->doc->section('',$code);
00423                                 }
00424                         } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
00425                                 $this->content.= $this->doc->section('','Sorry, TYPO3_CONF_VARS[BE][disable_exec_function] was set, so cannot display content of archive file.');
00426                         }
00427 
00428                                 // Font files:
00429                         if ($ext=='ttf')        {
00430                                 $thumbScript = 'thumbs.php';
00431                                 $check = basename($this->file).':'.filemtime($this->file).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
00432                                 $params = '&file='.rawurlencode($this->file);
00433                                 $params.= '&md5sum='.t3lib_div::shortMD5($check);
00434                                 $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
00435                                 $thumb = '<br />
00436                                         <div align="center">'.$returnLinkTag.'<img src="'.htmlspecialchars($url).'" border="0" title="'.htmlspecialchars(trim($this->file)).'" alt="" /></a></div>';
00437                                 $this->content.= $this->doc->section('',$thumb);
00438                         }
00439                 }
00440 
00441 
00442                         // References:
00443                 $this->content.= $this->doc->section('References to this item:',$this->makeRef('_FILE',$this->file));
00444         }
00445 
00451         function printContent() {
00452                 $this->content.= $this->doc->endPage();
00453                 $this->content = $this->doc->insertStylesAndJS($this->content);
00454                 echo $this->content;
00455         }
00456 
00464         function makeRef($table,$ref)   {
00465 
00466                 if ($table==='_FILE')   {
00467                                 // First, fit path to match what is stored in the refindex:
00468                         $fullIdent = $ref;
00469 
00470                         if (t3lib_div::isFirstPartOfStr($fullIdent,PATH_site))  {
00471                                 $fullIdent = substr($fullIdent,strlen(PATH_site));
00472                         }
00473 
00474                                 // Look up the path:
00475                         $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00476                                 '*',
00477                                 'sys_refindex',
00478                                 'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr('_FILE','sys_refindex').
00479                                         ' AND ref_string='.$GLOBALS['TYPO3_DB']->fullQuoteStr($fullIdent,'sys_refindex').
00480                                         ' AND deleted=0'
00481                         );
00482                 } else {
00483                                 // Look up the path:
00484                         $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00485                                 '*',
00486                                 'sys_refindex',
00487                                 'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
00488                                         ' AND ref_uid='.intval($ref).
00489                                         ' AND deleted=0'
00490                         );
00491                 }
00492 
00493                         // Compile information for title tag:
00494                 $infoData = array();
00495                 if (count($rows))       {
00496                         $infoData[] = '<tr class="bgColor5 tableheader">' .
00497                                         '<td>Table:</td>' .
00498                                         '<td>Uid:</td>' .
00499                                         '<td>Field:</td>'.
00500                                         '<td>Flexpointer:</td>'.
00501                                         '<td>Softref Key:</td>'.
00502                                         '<td>Sorting:</td>'.
00503                                         '</tr>';
00504                 }
00505                 foreach($rows as $row)  {
00506                         $infoData[] = '<tr class="bgColor4"">' .
00507                                         '<td>'.$row['tablename'].'</td>' .
00508                                         '<td>'.$row['recuid'].'</td>' .
00509                                         '<td>'.$row['field'].'</td>'.
00510                                         '<td>'.$row['flexpointer'].'</td>'.
00511                                         '<td>'.$row['softref_key'].'</td>'.
00512                                         '<td>'.$row['sorting'].'</td>'.
00513                                         '</tr>';
00514                 }
00515 
00516                 return count($infoData) ? '<table border="0" cellpadding="1" cellspacing="1">'.implode('',$infoData).'</table>' : '';
00517         }
00518 
00526         function makeRefFrom($table,$ref)       {
00527 
00528                         // Look up the path:
00529                 $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00530                         '*',
00531                         'sys_refindex',
00532                         'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
00533                                 ' AND recuid='.intval($ref)
00534                 );
00535 
00536                         // Compile information for title tag:
00537                 $infoData = array();
00538                 if (count($rows))       {
00539                         $infoData[] = '<tr class="bgColor5 tableheader">' .
00540                                         '<td>Field:</td>'.
00541                                         '<td>Flexpointer:</td>'.
00542                                         '<td>Softref Key:</td>'.
00543                                         '<td>Sorting:</td>'.
00544                                         '<td>Ref Table:</td>' .
00545                                         '<td>Ref Uid:</td>' .
00546                                         '<td>Ref String:</td>' .
00547                                         '</tr>';
00548                 }
00549                 foreach($rows as $row)  {
00550                         $infoData[] = '<tr class="bgColor4"">' .
00551                                         '<td>'.$row['field'].'</td>'.
00552                                         '<td>'.$row['flexpointer'].'</td>'.
00553                                         '<td>'.$row['softref_key'].'</td>'.
00554                                         '<td>'.$row['sorting'].'</td>'.
00555                                         '<td>'.$row['ref_table'].'</td>' .
00556                                         '<td>'.$row['ref_uid'].'</td>' .
00557                                         '<td>'.$row['ref_string'].'</td>' .
00558                                         '</tr>';
00559                 }
00560 
00561                 return count($infoData) ? '<table border="0" cellpadding="1" cellspacing="1">'.implode('',$infoData).'</table>' : '';
00562         }
00563 }
00564 
00565 // Include extension?
00566 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/show_item.php'])     {
00567         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/show_item.php']);
00568 }
00569 
00570 
00571 
00572 
00573 
00574 
00575 
00576 
00577 
00578 
00579 
00580 
00581 // Make instance:
00582 $SOBE = t3lib_div::makeInstance('SC_show_item');
00583 $SOBE->init();
00584 $SOBE->main();
00585 $SOBE->printContent();
00586 ?>


Généré par Le spécialiste TYPO3 avec  doxygen 1.4.6