[ Index ]
 

Code source de Typo3 4.1.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/typo3/ -> show_item.php (source)

   1  <?php
   2  /***************************************************************
   3  *  Copyright notice
   4  *
   5  *  (c) 1999-2006 Kasper Skaarhoj (kasperYYYY@typo3.com)
   6  *  All rights reserved
   7  *
   8  *  This script is part of the TYPO3 project. The TYPO3 project is
   9  *  free software; you can redistribute it and/or modify
  10  *  it under the terms of the GNU General Public License as published by
  11  *  the Free Software Foundation; either version 2 of the License, or
  12  *  (at your option) any later version.
  13  *
  14  *  The GNU General Public License can be found at
  15  *  http://www.gnu.org/copyleft/gpl.html.
  16  *  A copy is found in the textfile GPL.txt and important notices to the license
  17  *  from the author is found in LICENSE.txt distributed with these scripts.
  18  *
  19  *
  20  *  This script is distributed in the hope that it will be useful,
  21  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  22  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23  *  GNU General Public License for more details.
  24  *
  25  *  This copyright notice MUST APPEAR in all copies of the script!
  26  ***************************************************************/
  27  /**
  28   * Shows information about a database or file item
  29   *
  30   * $Id: show_item.php 1855 2006-12-05 00:22:45Z mundaun $
  31   * Revised for TYPO3 3.7 May/2004 by Kasper Skaarhoj
  32   *
  33   * @author    Kasper Skaarhoj <kasperYYYY@typo3.com>
  34   */
  35  /**
  36   * [CLASS/FUNCTION INDEX of SCRIPT]
  37   *
  38   *
  39   *
  40   *   84: class transferData extends t3lib_transferData
  41   *  101:     function regItem($table, $id, $field, $content)
  42   *
  43   *
  44   *  135: class SC_show_item
  45   *  160:     function init()
  46   *  225:     function main()
  47   *  273:     function renderDBInfo()
  48   *  327:     function renderFileInfo($returnLinkTag)
  49   *  449:     function printContent()
  50   *  462:     function makeRef($table,$ref)
  51   *  524:     function makeRefFrom($table,$ref)
  52   *
  53   * TOTAL FUNCTIONS: 8
  54   * (This index is automatically created/updated by the extension "extdeveval")
  55   *
  56   */
  57  
  58  
  59  $BACK_PATH = '';
  60  require ($BACK_PATH.'init.php');
  61  require ($BACK_PATH.'template.php');
  62  require_once(PATH_t3lib.'class.t3lib_page.php');
  63  require_once(PATH_t3lib.'class.t3lib_loaddbgroup.php');
  64  require_once(PATH_t3lib.'class.t3lib_transferdata.php');
  65  
  66  
  67  
  68  
  69  
  70  
  71  
  72  
  73  
  74  
  75  
  76  
  77  /**
  78   * Extension of transfer data class
  79   *
  80   * @author    Kasper Skaarhoj <kasperYYYY@typo3.com>
  81   * @package TYPO3
  82   * @subpackage core
  83   */
  84  class transferData extends t3lib_transferData    {
  85  
  86      var $formname = 'loadform';
  87      var $loading = 1;
  88  
  89          // Extra for show_item.php:
  90      var $theRecord = Array();
  91  
  92      /**
  93       * Register item function.
  94       *
  95       * @param    string        Table name
  96       * @param    integer        Record uid
  97       * @param    string        Field name
  98       * @param    string        Content string.
  99       * @return    void
 100       */
 101  	function regItem($table, $id, $field, $content)    {
 102          t3lib_div::loadTCA($table);
 103          $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
 104          switch($config['type'])    {
 105              case 'input':
 106                  if (isset($config['checkbox']) && $content==$config['checkbox'])    {$content=''; break;}
 107                  if (t3lib_div::inList($config['eval'],'date'))    {$content = Date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'],$content); }
 108              break;
 109              case 'group':
 110              break;
 111              case 'select':
 112              break;
 113          }
 114          $this->theRecord[$field]=$content;
 115      }
 116  }
 117  
 118  
 119  
 120  
 121  
 122  
 123  
 124  
 125  
 126  
 127  
 128  /**
 129   * Script Class for showing information about an item.
 130   *
 131   * @author    Kasper Skaarhoj <kasperYYYY@typo3.com>
 132   * @package TYPO3
 133   * @subpackage core
 134   */
 135  class SC_show_item {
 136  
 137          // GET vars:
 138      var $table;            // Record table (or filename)
 139      var $uid;            // Record uid  (or '' when filename)
 140  
 141          // Internal, static:
 142      var $perms_clause;    // Page select clause
 143      var $access;        // If true, access to element is granted
 144      var $type;            // Which type of element: "file" or "db"
 145      var $doc;            // Document Template Object
 146  
 147          // Internal, dynamic:
 148      var $content;        // Content Accumulation
 149      var $file;            // For type "file": Filename
 150      var $pageinfo;        // For type "db": Set to page record of the parent page of the item set (if type="db")
 151      var $row;            // For type "db": The database record row.
 152  
 153  
 154      /**
 155       * Initialization of the class
 156       * Will determine if table/uid GET vars are database record or a file and if the user has access to view information about the item.
 157       *
 158       * @return    void
 159       */
 160  	function init()    {
 161          global $BE_USER,$LANG,$BACK_PATH,$TCA;
 162  
 163              // Setting input variables.
 164          $this->table = t3lib_div::_GET('table');
 165          $this->uid = t3lib_div::_GET('uid');
 166  
 167              // Initialize:
 168          $this->perms_clause = $BE_USER->getPagePermsClause(1);
 169          $this->access = 0;    // Set to true if there is access to the record / file.
 170          $this->type = '';    // Sets the type, "db" or "file". If blank, nothing can be shown.
 171  
 172              // Checking if the $table value is really a table and if the user has access to it.
 173          if (isset($TCA[$this->table]))    {
 174              t3lib_div::loadTCA($this->table);
 175              $this->type = 'db';
 176              $this->uid = intval($this->uid);
 177  
 178                  // Check permissions and uid value:
 179              if ($this->uid && $BE_USER->check('tables_select',$this->table))    {
 180                  if ((string)$this->table=='pages')    {
 181                      $this->pageinfo = t3lib_BEfunc::readPageAccess($this->uid,$this->perms_clause);
 182                      $this->access = is_array($this->pageinfo) ? 1 : 0;
 183                      $this->row = $this->pageinfo;
 184                  } else {
 185                      $this->row = t3lib_BEfunc::getRecord($this->table,$this->uid);
 186                      if ($this->row)    {
 187                          $this->pageinfo = t3lib_BEfunc::readPageAccess($this->row['pid'],$this->perms_clause);
 188                          $this->access = is_array($this->pageinfo) ? 1 : 0;
 189                      }
 190                  }
 191  
 192                  $treatData = t3lib_div::makeInstance('t3lib_transferData');
 193                  $treatData->renderRecord($this->table, $this->uid, 0, $this->row);
 194                  $cRow = $treatData->theRecord;
 195              }
 196          } else    {
 197              // if the filereference $this->file is relative, we correct the path
 198              if (substr($this->table,0,3)=='../')    {
 199                  $this->file = PATH_site.ereg_replace('^\.\./','',$this->table);
 200              } else {
 201                  $this->file = $this->table;
 202              }
 203              if (@is_file($this->file) && t3lib_div::isAllowedAbsPath($this->file))    {
 204                  $this->type = 'file';
 205                  $this->access = 1;
 206              }
 207          }
 208  
 209              // Initialize document template object:
 210          $this->doc = t3lib_div::makeInstance('smallDoc');
 211          $this->doc->backPath = $BACK_PATH;
 212          $this->doc->docType = 'xhtml_trans';
 213  
 214              // Starting the page by creating page header stuff:
 215          $this->content.=$this->doc->startPage($LANG->sL('LLL:EXT:lang/locallang_core.php:show_item.php.viewItem'));
 216          $this->content.=$this->doc->header($LANG->sL('LLL:EXT:lang/locallang_core.php:show_item.php.viewItem'));
 217          $this->content.=$this->doc->spacer(5);
 218      }
 219  
 220      /**
 221       * Main function. Will generate the information to display for the item set internally.
 222       *
 223       * @return    void
 224       */
 225  	function main()    {
 226          global $LANG;
 227  
 228          if ($this->access)    {
 229              $returnLinkTag = t3lib_div::_GP('returnUrl') ? '<a href="'.t3lib_div::_GP('returnUrl').'" class="typo3-goBack">' : '<a href="#" onclick="window.close();">';
 230  
 231                  // render type by user func
 232              $typeRendered = false;
 233              if (is_array ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'])) {
 234                  foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/show_item.php']['typeRendering'] as $classRef) {
 235                      $typeRenderObj = t3lib_div::getUserObj($classRef);
 236                      if(is_object($typeRenderObj) && method_exists($typeRenderObj, 'isValid') && method_exists($typeRenderObj, 'render'))    {
 237                          if ($typeRenderObj->isValid($this->type, $this)) {
 238                              $this->content .=  $typeRenderObj->render($this->type, $this);
 239                              $typeRendered = true;
 240                              break;
 241                          }
 242                      }
 243                  }
 244              }
 245  
 246                  // if type was not rendered use default rendering functions
 247              if(!$typeRendered) {
 248                      // Branch out based on type:
 249                  switch($this->type)    {
 250                      case 'db':
 251                          $this->renderDBInfo();
 252                      break;
 253                      case 'file':
 254                          $this->renderFileInfo($returnLinkTag);
 255                      break;
 256                  }
 257              }
 258  
 259                  // If return Url is set, output link to go back:
 260              if (t3lib_div::_GP('returnUrl'))    {
 261                  $this->content = $this->doc->section('',$returnLinkTag.'<strong>'.$LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.goBack',1).'</strong></a><br /><br />').$this->content;
 262  
 263                  $this->content .= $this->doc->section('','<br />'.$returnLinkTag.'<strong>'.$LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.goBack',1).'</strong></a>');
 264              }
 265          }
 266      }
 267  
 268      /**
 269       * Main function. Will generate the information to display for the item set internally.
 270       *
 271       * @return    void
 272       */
 273  	function renderDBInfo()    {
 274          global $LANG,$TCA;
 275  
 276              // Print header, path etc:
 277          $code = $this->doc->getHeader($this->table,$this->row,$this->pageinfo['_thePath'],1).'<br />';
 278          $this->content.= $this->doc->section('',$code);
 279  
 280              // Initialize variables:
 281          $tableRows = Array();
 282          $i = 0;
 283  
 284              // Traverse the list of fields to display for the record:
 285          $fieldList = t3lib_div::trimExplode(',',$TCA[$this->table]['interface']['showRecordFieldList'],1);
 286          foreach($fieldList as $name)    {
 287              $name = trim($name);
 288              if ($TCA[$this->table]['columns'][$name])    {
 289                  if (!$TCA[$this->table]['columns'][$name]['exclude'] || $GLOBALS['BE_USER']->check('non_exclude_fields',$this->table.':'.$name))    {
 290                      $i++;
 291                      $tableRows[] = '
 292                          <tr>
 293                              <td class="bgColor5">'.$LANG->sL(t3lib_BEfunc::getItemLabel($this->table,$name),1).'</td>
 294                              <td class="bgColor4">'.htmlspecialchars(t3lib_BEfunc::getProcessedValue($this->table,$name,$this->row[$name])).'</td>
 295                          </tr>';
 296                  }
 297              }
 298          }
 299  
 300              // Create table from the information:
 301          $tableCode = '
 302                      <table border="0" cellpadding="1" cellspacing="1" id="typo3-showitem">
 303                          '.implode('',$tableRows).'
 304                      </table>';
 305          $this->content.=$this->doc->section('',$tableCode);
 306          $this->content.=$this->doc->divider(2);
 307  
 308              // Add path and table information in the bottom:
 309          $code = '';
 310          $code.= $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.path').': '.t3lib_div::fixed_lgd_cs($this->pageinfo['_thePath'],-48).'<br />';
 311          $code.= $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.table').': '.$LANG->sL($TCA[$this->table]['ctrl']['title']).' ('.$this->table.') - UID: '.$this->uid.'<br />';
 312          $this->content.= $this->doc->section('', $code);
 313  
 314              // References:
 315          $this->content.= $this->doc->section('References to this item:',$this->makeRef($this->table,$this->row['uid']));
 316  
 317              // References:
 318          $this->content.= $this->doc->section('References from this item:',$this->makeRefFrom($this->table,$this->row['uid']));
 319      }
 320  
 321      /**
 322       * Main function. Will generate the information to display for the item set internally.
 323       *
 324       * @param    string        <a> tag closing/returning.
 325       * @return    void
 326       */
 327  	function renderFileInfo($returnLinkTag)    {
 328          global $LANG;
 329  
 330              // Initialize object to work on the image:
 331          require_once(PATH_t3lib.'class.t3lib_stdgraphic.php');
 332          $imgObj = t3lib_div::makeInstance('t3lib_stdGraphic');
 333          $imgObj->init();
 334          $imgObj->mayScaleUp = 0;
 335          $imgObj->absPrefix = PATH_site;
 336  
 337              // Read Image Dimensions (returns false if file was not an image type, otherwise dimensions in an array)
 338          $imgInfo = '';
 339          $imgInfo = $imgObj->getImageDimensions($this->file);
 340  
 341              // File information
 342          $fI = t3lib_div::split_fileref($this->file);
 343          $ext = $fI['fileext'];
 344  
 345          $code = '';
 346  
 347              // Setting header:
 348          $icon = t3lib_BEfunc::getFileIcon($ext);
 349          $url = 'gfx/fileicons/'.$icon;
 350          $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'];
 351          if (t3lib_div::isFirstPartOfStr($this->file,PATH_site))    {
 352              $code.= '<a href="../'.substr($this->file,strlen(PATH_site)).'" target="_blank">'.$fileName.'</a>';
 353          } else {
 354              $code.= $fileName;
 355          }
 356          $code.=' &nbsp;&nbsp;<b>'.$LANG->sL('LLL:EXT:lang/locallang_core.php:show_item.php.filesize').':</b> '.t3lib_div::formatSize(@filesize($this->file)).'<br />
 357              ';
 358          if (is_array($imgInfo))    {
 359              $code.= '<b>'.$LANG->sL('LLL:EXT:lang/locallang_core.php:show_item.php.dimensions').':</b> '.$imgInfo[0].'x'.$imgInfo[1].' pixels';
 360          }
 361          $this->content.=$this->doc->section('',$code);
 362          $this->content.=$this->doc->divider(2);
 363  
 364              // If the file was an image...:
 365          if (is_array($imgInfo))    {
 366  
 367              $imgInfo = $imgObj->imageMagickConvert($this->file,'web','346','200m','','','',1);
 368              $imgInfo[3] = '../'.substr($imgInfo[3],strlen(PATH_site));
 369              $code = '<br />
 370                  <div align="center">'.$returnLinkTag.$imgObj->imgTag($imgInfo).'</a></div>';
 371              $this->content.= $this->doc->section('', $code);
 372          } else {
 373              $this->content.= $this->doc->spacer(10);
 374              $lowerFilename = strtolower($this->file);
 375  
 376                  // Archive files:
 377              if (TYPO3_OS!='WIN' && !$GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function'])    {
 378                  if ($ext=='zip')    {
 379                      $code = '';
 380                      $t = array();
 381                      exec('unzip -l '.$this->file, $t);
 382                      if (is_array($t))    {
 383                          reset($t);
 384                          next($t);
 385                          next($t);
 386                          next($t);
 387                          while(list(,$val)=each($t))    {
 388                              $parts = explode(' ',trim($val),7);
 389                              $code.= '
 390                                  '.$parts[6].'<br />';
 391                          }
 392                          $code = '
 393                              <span class="nobr">'.$code.'
 394                              </span>
 395                              <br /><br />';
 396                      }
 397                      $this->content.= $this->doc->section('', $code);
 398                  } elseif($ext=='tar' || $ext=='tgz' || substr($lowerFilename,-6)=='tar.gz' || substr($lowerFilename,-5)=='tar.z')    {
 399                      $code = '';
 400                      if ($ext=='tar')    {
 401                          $compr = '';
 402                      } else {
 403                          $compr = 'z';
 404                      }
 405                      $t = array();
 406                      exec('tar t'.$compr.'f '.$this->file, $t);
 407                      if (is_array($t))    {
 408                          foreach($t as $val)    {
 409                              $code.='
 410                                  '.$val.'<br />';
 411                          }
 412  
 413                          $code.='
 414                                   -------<br/>
 415                                   '.count($t).' files';
 416  
 417                          $code = '
 418                              <span class="nobr">'.$code.'
 419                              </span>
 420                              <br /><br />';
 421                      }
 422                      $this->content.= $this->doc->section('',$code);
 423                  }
 424              } elseif ($GLOBALS['TYPO3_CONF_VARS']['BE']['disable_exec_function']) {
 425                  $this->content.= $this->doc->section('','Sorry, TYPO3_CONF_VARS[BE][disable_exec_function] was set, so cannot display content of archive file.');
 426              }
 427  
 428                  // Font files:
 429              if ($ext=='ttf')    {
 430                  $thumbScript = 'thumbs.php';
 431                  $check = basename($this->file).':'.filemtime($this->file).':'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'];
 432                  $params = '&file='.rawurlencode($this->file);
 433                  $params.= '&md5sum='.t3lib_div::shortMD5($check);
 434                  $url = $thumbScript.'?&dummy='.$GLOBALS['EXEC_TIME'].$params;
 435                  $thumb = '<br />
 436                      <div align="center">'.$returnLinkTag.'<img src="'.htmlspecialchars($url).'" border="0" title="'.htmlspecialchars(trim($this->file)).'" alt="" /></a></div>';
 437                  $this->content.= $this->doc->section('',$thumb);
 438              }
 439          }
 440  
 441  
 442              // References:
 443          $this->content.= $this->doc->section('References to this item:',$this->makeRef('_FILE',$this->file));
 444      }
 445  
 446      /**
 447       * End page and print content
 448       *
 449       * @return    void
 450       */
 451  	function printContent()    {
 452          $this->content.= $this->doc->endPage();
 453          $this->content = $this->doc->insertStylesAndJS($this->content);
 454          echo $this->content;
 455      }
 456  
 457      /**
 458       * Make reference display
 459       *
 460       * @param    string        Table name
 461       * @param    string        Filename or uid
 462       * @return    string        HTML
 463       */
 464  	function makeRef($table,$ref)    {
 465  
 466          if ($table==='_FILE')    {
 467                  // First, fit path to match what is stored in the refindex:
 468              $fullIdent = $ref;
 469  
 470              if (t3lib_div::isFirstPartOfStr($fullIdent,PATH_site))    {
 471                  $fullIdent = substr($fullIdent,strlen(PATH_site));
 472              }
 473  
 474                  // Look up the path:
 475              $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
 476                  '*',
 477                  'sys_refindex',
 478                  'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr('_FILE','sys_refindex').
 479                      ' AND ref_string='.$GLOBALS['TYPO3_DB']->fullQuoteStr($fullIdent,'sys_refindex').
 480                      ' AND deleted=0'
 481              );
 482          } else {
 483                  // Look up the path:
 484              $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
 485                  '*',
 486                  'sys_refindex',
 487                  'ref_table='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
 488                      ' AND ref_uid='.intval($ref).
 489                      ' AND deleted=0'
 490              );
 491          }
 492  
 493              // Compile information for title tag:
 494          $infoData = array();
 495          if (count($rows))    {
 496              $infoData[] = '<tr class="bgColor5 tableheader">' .
 497                      '<td>Table:</td>' .
 498                      '<td>Uid:</td>' .
 499                      '<td>Field:</td>'.
 500                      '<td>Flexpointer:</td>'.
 501                      '<td>Softref Key:</td>'.
 502                      '<td>Sorting:</td>'.
 503                      '</tr>';
 504          }
 505          foreach($rows as $row)    {
 506              $infoData[] = '<tr class="bgColor4"">' .
 507                      '<td>'.$row['tablename'].'</td>' .
 508                      '<td>'.$row['recuid'].'</td>' .
 509                      '<td>'.$row['field'].'</td>'.
 510                      '<td>'.$row['flexpointer'].'</td>'.
 511                      '<td>'.$row['softref_key'].'</td>'.
 512                      '<td>'.$row['sorting'].'</td>'.
 513                      '</tr>';
 514          }
 515  
 516          return count($infoData) ? '<table border="0" cellpadding="1" cellspacing="1">'.implode('',$infoData).'</table>' : '';
 517      }
 518  
 519      /**
 520       * Make reference display (what this elements points to)
 521       *
 522       * @param    string        Table name
 523       * @param    string        Filename or uid
 524       * @return    string        HTML
 525       */
 526  	function makeRefFrom($table,$ref)    {
 527  
 528              // Look up the path:
 529          $rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
 530              '*',
 531              'sys_refindex',
 532              'tablename='.$GLOBALS['TYPO3_DB']->fullQuoteStr($table,'sys_refindex').
 533                  ' AND recuid='.intval($ref)
 534          );
 535  
 536              // Compile information for title tag:
 537          $infoData = array();
 538          if (count($rows))    {
 539              $infoData[] = '<tr class="bgColor5 tableheader">' .
 540                      '<td>Field:</td>'.
 541                      '<td>Flexpointer:</td>'.
 542                      '<td>Softref Key:</td>'.
 543                      '<td>Sorting:</td>'.
 544                      '<td>Ref Table:</td>' .
 545                      '<td>Ref Uid:</td>' .
 546                      '<td>Ref String:</td>' .
 547                      '</tr>';
 548          }
 549          foreach($rows as $row)    {
 550              $infoData[] = '<tr class="bgColor4"">' .
 551                      '<td>'.$row['field'].'</td>'.
 552                      '<td>'.$row['flexpointer'].'</td>'.
 553                      '<td>'.$row['softref_key'].'</td>'.
 554                      '<td>'.$row['sorting'].'</td>'.
 555                      '<td>'.$row['ref_table'].'</td>' .
 556                      '<td>'.$row['ref_uid'].'</td>' .
 557                      '<td>'.$row['ref_string'].'</td>' .
 558                      '</tr>';
 559          }
 560  
 561          return count($infoData) ? '<table border="0" cellpadding="1" cellspacing="1">'.implode('',$infoData).'</table>' : '';
 562      }
 563  }
 564  
 565  // Include extension?
 566  if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/show_item.php'])    {
 567      include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/show_item.php']);
 568  }
 569  
 570  
 571  
 572  
 573  
 574  
 575  
 576  
 577  
 578  
 579  
 580  
 581  // Make instance:
 582  $SOBE = t3lib_div::makeInstance('SC_show_item');
 583  $SOBE->init();
 584  $SOBE->main();
 585  $SOBE->printContent();
 586  ?>


Généré le : Sun Nov 25 17:13:16 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics