Revert "[RELEASE] Release of TYPO3 4.6.0alpha1"
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_admin.php
index d5c4a27..63e40b9 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
  *  Copyright notice
  *
- *  (c) 1999-2010 Kasper Skårhøj (kasperYYYY@typo3.com)
+ *  (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com)
  *  All rights reserved
  *
  *  This script is part of the TYPO3 project. The TYPO3 project is
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 /**
- * Contains a class for evaluation of database integrity according to $TCA
+ * Contains a class for evaluation of database integrity according to $GLOBALS['TCA']
  * Most of these functions are considered obsolete!
  *
- * $Id$
  * Revised for TYPO3 3.6 July/2003 by Kasper Skårhøj
  * XHTML compliant
  *
  * @subpackage t3lib
  */
 class t3lib_admin {
-       var $genTree_includeDeleted = TRUE; // if set, genTree() includes deleted pages. This is default.
-       var $genTree_includeVersions = TRUE; // if set, genTree() includes verisonized pages/records. This is default.
-       var $genTree_includeRecords = FALSE; // if set, genTree() includes records from pages.
-       var $perms_clause = ''; // extra where-clauses for the tree-selection
-       var $genTree_makeHTML = 0; // if set, genTree() generates HTML, that visualizes the tree.
+       /** @var bool If set, genTree() includes deleted pages. This is default.*/
+       var $genTree_includeDeleted = TRUE;
+
+       /** @var bool  If set, genTree() includes versionized pages/records. This is default.*/
+       var $genTree_includeVersions = TRUE;
+
+       /** @var bool  If set, genTree() includes records from pages. */
+       var $genTree_includeRecords = FALSE;
+
+       /** @var string  Extra where-clauses for the tree-selection */
+       var $perms_clause = '';
+
+       /** @var int  If set, genTree() generates HTML, that visualizes the tree. */
+       var $genTree_makeHTML = 0;
 
                // internal
-       var $page_idArray = array(); // Will hod id/rec pais from genTree()
+       /** @var array Will hold id/rec pairs from genTree() */
+       var $page_idArray = array();
+
+       /** @var array */
        var $rec_idArray = array();
-       var $getTree_HTML = ''; // Will hold the HTML-code visualising the tree. genTree()
+
+       /** @var string  Will hold the HTML-code visualising the tree. genTree() */
+       var $genTree_HTML = '';
+
+       /** @var string */
        var $backPath = '';
 
                // internal
+       /** @var array */
        var $checkFileRefs = array();
-       var $checkSelectDBRefs = array(); // From the select-fields
-       var $checkGroupDBRefs = array(); // From the group-fields
 
+       /** @var array From the select-fields */
+       var $checkSelectDBRefs = array();
+
+       /** @var array From the group-fields */
+       var $checkGroupDBRefs = array();
+
+       /** @var array Statistics */
        var $recStats = array(
                'allValid' => array(),
                'published_versions' => array(),
                'deleted' => array(),
        );
+
+       /** @var array */
        var $lRecords = array();
+
+       /** @var string */
        var $lostPagesList = '';
 
 
@@ -113,7 +138,7 @@ class t3lib_admin {
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                                'uid,title,doktype,deleted,t3ver_wsid,t3ver_id,t3ver_count,t3ver_swapmode' . (t3lib_extMgm::isLoaded('cms') ? ',hidden' : ''),
                                'pages',
-                                       'pid=-1 AND t3ver_oid=' . intval($theID) . ' ' . ((!$this->genTree_includeDeleted) ? 'AND deleted=0' : '') . $this->perms_clause,
+                               'pid=-1 AND t3ver_oid=' . intval($theID) . ' ' . ((!$this->genTree_includeDeleted) ? 'AND deleted=0' : '') . $this->perms_clause,
                                '',
                                'sorting'
                        );
@@ -121,7 +146,7 @@ class t3lib_admin {
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                                'uid,title,doktype,deleted' . (t3lib_extMgm::isLoaded('cms') ? ',hidden' : ''),
                                'pages',
-                                       'pid=' . intval($theID) . ' ' . ((!$this->genTree_includeDeleted) ? 'AND deleted=0' : '') . $this->perms_clause,
+                               'pid=' . intval($theID) . ' ' . ((!$this->genTree_includeDeleted) ? 'AND deleted=0' : '') . $this->perms_clause,
                                '',
                                'sorting'
                        );
@@ -168,12 +193,12 @@ class t3lib_admin {
                        }
 
                        if ($row['deleted']) {
-                               $this->recStat['deleted']++;
+                               $this->recStats['deleted']++;
                        }
                        if ($row['hidden']) {
-                               $this->recStat['hidden']++;
+                               $this->recStats['hidden']++;
                        }
-                       $this->recStat['doktype'][$row['doktype']]++;
+                       $this->recStats['doktype'][$row['doktype']]++;
 
                                // Create the HTML code prefix for recursive call:
                        $genHTML = $depthData . '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . $LN . '.gif', 'width="18" height="16"') . ' align="top" alt="" />' . $versionLabel;
@@ -198,30 +223,28 @@ class t3lib_admin {
        }
 
        /**
-        * @param       [type]          $theID: ...
-        * @param       [type]          $depthData: ...
-        * @param       [type]          $table: ...
-        * @param       [type]          $versions: ...
-        * @return      [type]          ...
+        * @param       integer         a pid (page-record id) from which to start making the tree
+        * @param       string          HTML-code used when this function calls itself recursively.
+        * @param       string          Table to get the records from
+        * @param       bool            Internal variable, don't set from outside!
+        * @return      void
         */
        function genTree_records($theID, $depthData, $table = '', $versions = FALSE) {
-               global $TCA;
-
                if ($versions) {
                                // Select all records from table pointing to this page:
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                                t3lib_BEfunc::getCommonSelectFields($table),
                                $table,
-                                       'pid=-1 AND t3ver_oid=' . intval($theID) .
-                                                       (!$this->genTree_includeDeleted ? t3lib_BEfunc::deleteClause($table) : '')
+                               'pid=-1 AND t3ver_oid=' . intval($theID) .
+                                               (!$this->genTree_includeDeleted ? t3lib_BEfunc::deleteClause($table) : '')
                        );
                } else {
                                // Select all records from table pointing to this page:
                        $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                                t3lib_BEfunc::getCommonSelectFields($table),
                                $table,
-                                       'pid=' . intval($theID) .
-                                                       (!$this->genTree_includeDeleted ? t3lib_BEfunc::deleteClause($table) : '')
+                               'pid=' . intval($theID) .
+                                               (!$this->genTree_includeDeleted ? t3lib_BEfunc::deleteClause($table) : '')
                        );
                }
 
@@ -269,7 +292,7 @@ class t3lib_admin {
 
 
                                // Select all versions of this record:
-                       if ($this->genTree_includeVersions && $TCA[$table]['ctrl']['versioningWS']) {
+                       if ($this->genTree_includeVersions && $GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
                                $genHTML = $depthData . '<img' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/ol/' . $LN . '.gif', 'width="18" height="16"') . ' align="top" alt="" />';
 
                                $this->genTree_records($newID, $genHTML, $table, TRUE);
@@ -278,9 +301,9 @@ class t3lib_admin {
        }
 
        /**
-        * [Describe function...]
+        * Generates tree and returns statistics
         *
-        * @return      [type]          ...
+        * @return      array           Record statistics
         */
        function genTreeStatus($root = 0) {
                $this->genTree_includeDeleted = TRUE; // if set, genTree() includes deleted pages. This is default.
@@ -302,26 +325,25 @@ class t3lib_admin {
         * @return      void
         */
        function lostRecords($pid_list) {
-               global $TCA;
                $this->lostPagesList = '';
                if ($pid_list) {
-                       foreach ($TCA as $table => $tableConf) {
+                       foreach ($GLOBALS['TCA'] as $table => $tableConf) {
                                t3lib_div::loadTCA($table);
 
                                $pid_list_tmp = $pid_list;
-                               if (!isset($TCA[$table]['ctrl']['versioningWS']) || !$TCA[$table]['ctrl']['versioningWS']) {
+                               if (!isset($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) || !$GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
                                                // Remove preceding "-1," for non-versioned tables
                                        $pid_list_tmp = preg_replace('/^\-1,/', '', $pid_list_tmp);
                                }
 
                                $garbage = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                                       'uid,pid,' . $TCA[$table]['ctrl']['label'],
+                                       'uid,pid,' . $GLOBALS['TCA'][$table]['ctrl']['label'],
                                        $table,
                                                'pid NOT IN (' . $pid_list_tmp . ')'
                                );
                                $lostIdList = array();
                                while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($garbage)) {
-                                       $this->lRecords[$table][$row['uid']] = array('uid' => $row['uid'], 'pid' => $row['pid'], 'title' => strip_tags($row[$TCA[$table]['ctrl']['label']]));
+                                       $this->lRecords[$table][$row['uid']] = array('uid' => $row['uid'], 'pid' => $row['pid'], 'title' => strip_tags($row[$GLOBALS['TCA'][$table]['ctrl']['label']]));
                                        $lostIdList[] = $row['uid'];
                                }
                                if ($table == 'pages') {
@@ -336,7 +358,7 @@ class t3lib_admin {
         *
         * @param       string          Database tablename
         * @param       integer         The uid of the record which will have the PID value set to 0 (zero)
-        * @return      boolean         True if done.
+        * @return      boolean         TRUE if done.
         */
        function fixLostRecord($table, $uid) {
                if ($table && $GLOBALS['TCA'][$table] && $uid && is_array($this->lRecords[$table][$uid]) && $GLOBALS['BE_USER']->user['admin']) {
@@ -356,21 +378,20 @@ class t3lib_admin {
        }
 
        /**
-        * Counts records from $TCA-tables that ARE attached to an existing page.
+        * Counts records from $GLOBALS['TCA']-tables that ARE attached to an existing page.
         *
         * @param       string          list of pid's (page-record uid's). This list is probably made by genTree()
-        * @return      array           an array with the number of records from all $TCA-tables that are attached to a PID in the pid-list.
+        * @return      array           an array with the number of records from all $GLOBALS['TCA']-tables that are attached to a PID in the pid-list.
         */
        function countRecords($pid_list) {
-               global $TCA;
                $list = array();
                $list_n = array();
                if ($pid_list) {
-                       foreach ($TCA as $table => $tableConf) {
+                       foreach ($GLOBALS['TCA'] as $table => $tableConf) {
                                t3lib_div::loadTCA($table);
 
                                $pid_list_tmp = $pid_list;
-                               if (!isset($TCA[$table]['ctrl']['versioningWS']) || !$TCA[$table]['ctrl']['versioningWS']) {
+                               if (!isset($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) || !$GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
                                                // Remove preceding "-1," for non-versioned tables
                                        $pid_list_tmp = preg_replace('/^\-1,/', '', $pid_list_tmp);
                                }
@@ -396,11 +417,10 @@ class t3lib_admin {
         * @return      array           An array with all fields listed that somehow are references to other records (foreign-keys) or files
         */
        function getGroupFields($mode) {
-               global $TCA;
                $result = array();
-               foreach ($TCA as $table => $tableConf) {
+               foreach ($GLOBALS['TCA'] as $table => $tableConf) {
                        t3lib_div::loadTCA($table);
-                       $cols = $TCA[$table]['columns'];
+                       $cols = $GLOBALS['TCA'][$table]['columns'];
                        foreach ($cols as $field => $config) {
                                if ($config['config']['type'] == 'group') {
                                        if (
@@ -428,11 +448,10 @@ class t3lib_admin {
         * @return      array           An array with all fields listed that have references to files in the $uploadfolder
         */
        function getFileFields($uploadfolder) {
-               global $TCA;
                $result = array();
-               foreach ($TCA as $table => $tableConf) {
+               foreach ($GLOBALS['TCA'] as $table => $tableConf) {
                        t3lib_div::loadTCA($table);
-                       $cols = $TCA[$table]['columns'];
+                       $cols = $GLOBALS['TCA'][$table]['columns'];
                        foreach ($cols as $field => $config) {
                                if ($config['config']['type'] == 'group' && $config['config']['internal_type'] == 'file' && $config['config']['uploadfolder'] == $uploadfolder) {
                                        $result[] = array($table, $field);
@@ -443,18 +462,17 @@ class t3lib_admin {
        }
 
        /**
-        * Returns an array with arrays of table/field pairs which are allowed to hold references to the input table name - according to $TCA
+        * Returns an array with arrays of table/field pairs which are allowed to hold references to the input table name - according to $GLOBALS['TCA']
         *
         * @param       string          Table name
         * @return      array
         */
        function getDBFields($theSearchTable) {
-               global $TCA;
                $result = array();
-               reset($TCA);
-               foreach ($TCA as $table => $tableConf) {
+               reset($GLOBALS['TCA']);
+               foreach ($GLOBALS['TCA'] as $table => $tableConf) {
                        t3lib_div::loadTCA($table);
-                       $cols = $TCA[$table]['columns'];
+                       $cols = $GLOBALS['TCA'][$table]['columns'];
                        foreach ($cols as $field => $config) {
                                if ($config['config']['type'] == 'group' && $config['config']['internal_type'] == 'db') {
                                        if (trim($config['config']['allowed']) == '*' || strstr($config['config']['allowed'], $theSearchTable)) {
@@ -476,21 +494,26 @@ class t3lib_admin {
         * @see getGroupFields()
         */
        function selectNonEmptyRecordsWithFkeys($fkey_arrays) {
-               global $TCA;
                if (is_array($fkey_arrays)) {
                        foreach ($fkey_arrays as $table => $field_list) {
-                               if ($TCA[$table] && trim($field_list)) {
+                               if ($GLOBALS['TCA'][$table] && trim($field_list)) {
                                        t3lib_div::loadTCA($table);
                                        $fieldArr = explode(',', $field_list);
 
                                        if (t3lib_extMgm::isLoaded('dbal')) {
                                                $fields = $GLOBALS['TYPO3_DB']->admin_get_fields($table);
                                                $field = array_shift($fieldArr);
-                                               $cl_fl = ($GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'I' || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'N' || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'R') ?
-                                                               $field . '!=0' : $field . '!=\'\'';
+                                               $cl_fl = ($GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'I'
+                                                                       || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'N'
+                                                                       || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'R')
+                                                               ? $field . '!=0'
+                                                               : $field . '!=\'\'';
                                                foreach ($fieldArr as $field) {
-                                                       $cl_fl .= ($GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'I' || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'N' || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'R') ?
-                                                                       ' OR ' . $field . '!=0' : ' OR ' . $field . '!=\'\'';
+                                                       $cl_fl .= ($GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'I'
+                                                                               || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'N'
+                                                                               || $GLOBALS['TYPO3_DB']->MetaType($fields[$field]['type'], $table) == 'R')
+                                                                       ? ' OR ' . $field . '!=0'
+                                                                       : ' OR ' . $field . '!=\'\'';
                                                }
                                                unset($fields);
                                        }
@@ -502,12 +525,13 @@ class t3lib_admin {
                                        while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
                                                foreach ($fieldArr as $field) {
                                                        if (trim($row[$field])) {
-                                                               $fieldConf = $TCA[$table]['columns'][$field]['config'];
+                                                               $fieldConf = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
                                                                if ($fieldConf['type'] == 'group') {
                                                                        if ($fieldConf['internal_type'] == 'file') {
                                                                                        // files...
                                                                                if ($fieldConf['MM']) {
                                                                                        $tempArr = array();
+                                                                                       /** @var $dbAnalysis t3lib_loadDBGroup */
                                                                                        $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
                                                                                        $dbAnalysis->start('', 'files', $fieldConf['MM'], $row['uid']);
                                                                                        foreach ($dbAnalysis->itemArray as $somekey => $someval) {
@@ -526,7 +550,7 @@ class t3lib_admin {
                                                                                }
                                                                        }
                                                                        if ($fieldConf['internal_type'] == 'db') {
-                                                                                       // dbs - group
+                                                                               /** @var $dbAnalysis t3lib_loadDBGroup */
                                                                                $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
                                                                                $dbAnalysis->start($row[$field], $fieldConf['allowed'], $fieldConf['MM'], $row['uid'], $table, $fieldConf);
                                                                                foreach ($dbAnalysis->itemArray as $tempArr) {
@@ -535,7 +559,7 @@ class t3lib_admin {
                                                                        }
                                                                }
                                                                if ($fieldConf['type'] == 'select' && $fieldConf['foreign_table']) {
-                                                                               // dbs - select
+                                                                       /** @var $dbAnalysis t3lib_loadDBGroup */
                                                                        $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
                                                                        $dbAnalysis->start($row[$field], $fieldConf['foreign_table'], $fieldConf['MM'], $row['uid'], $table, $fieldConf);
                                                                        foreach ($dbAnalysis->itemArray as $tempArr) {
@@ -640,9 +664,9 @@ class t3lib_admin {
         * @return      string          HTML Error message
         */
        function testDBRefs($theArray) {
-               global $TCA;
+               $result = '';
                foreach ($theArray as $table => $dbArr) {
-                       if ($TCA[$table]) {
+                       if ($GLOBALS['TCA'][$table]) {
                                $idlist = array_keys($dbArr);
 
                                $theList = implode(',', $idlist);
@@ -674,7 +698,6 @@ class t3lib_admin {
         * @return      array           Array with other arrays containing information about where references was found
         */
        function whereIsRecordReferenced($searchTable, $id) {
-               global $TCA;
                $fileFields = $this->getDBFields($searchTable); // Gets tables / Fields that reference to files...
                $theRecordList = array();
                foreach ($fileFields as $info) {
@@ -682,15 +705,15 @@ class t3lib_admin {
                        $field = $info[1];
                        t3lib_div::loadTCA($table);
                        $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                               'uid,pid,' . $TCA[$table]['ctrl']['label'] . ',' . $field,
+                               'uid,pid,' . $GLOBALS['TCA'][$table]['ctrl']['label'] . ',' . $field,
                                $table,
                                        $field . ' LIKE \'%' . $GLOBALS['TYPO3_DB']->quoteStr($id, $table) . '%\''
                        );
                        while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
                                        // Now this is the field, where the reference COULD come from. But we're not garanteed, so we must carefully examine the data.
-                               $fieldConf = $TCA[$table]['columns'][$field]['config'];
+                               $fieldConf = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
                                $allowedTables = ($fieldConf['type'] == 'group') ? $fieldConf['allowed'] : $fieldConf['foreign_table'];
-
+                               /** @var $dbAnalysis t3lib_loadDBGroup */
                                $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
                                $dbAnalysis->start($row[$field], $allowedTables, $fieldConf['MM'], $row['uid'], $table, $fieldConf);
                                foreach ($dbAnalysis->itemArray as $tempArr) {
@@ -712,19 +735,18 @@ class t3lib_admin {
         * @return      array           Array with other arrays containing information about where references was found
         */
        function whereIsFileReferenced($uploadfolder, $filename) {
-               global $TCA;
                $fileFields = $this->getFileFields($uploadfolder); // Gets tables / Fields that reference to files...
                $theRecordList = array();
                foreach ($fileFields as $info) {
                        $table = $info[0];
                        $field = $info[1];
                        $mres = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                               'uid,pid,' . $TCA[$table]['ctrl']['label'] . ',' . $field,
+                               'uid,pid,' . $GLOBALS['TCA'][$table]['ctrl']['label'] . ',' . $field,
                                $table,
                                        $field . ' LIKE \'%' . $GLOBALS['TYPO3_DB']->quoteStr($filename, $table) . '%\''
                        );
                        while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($mres)) {
-                                       // Now this is the field, where the reference COULD come from. But we're not garanteed, so we must carefully examine the data.
+                                       // Now this is the field, where the reference COULD come from. But we're not guaranteed, so we must carefully examine the data.
                                $tempArr = explode(',', trim($row[$field]));
                                foreach ($tempArr as $file) {
                                        $file = trim($file);
@@ -739,7 +761,7 @@ class t3lib_admin {
 }
 
 
-if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_admin.php']) {
-       include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_admin.php']);
+if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_admin.php'])) {
+       include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_admin.php']);
 }
 ?>
\ No newline at end of file