Follow-up to bug #8399: Table index was too long after changing the field size
[Packages/TYPO3.CMS.git] / t3lib / class.t3lib_befunc.php
index d20e3de..408f60e 100755 (executable)
@@ -78,7 +78,7 @@
  *
  *              SECTION: Caching related
  * 1105:     function storeHash($hash,$data,$ident)
- * 1125:     function getHash($hash,$expTime=0)
+ * 1125:     function getHash($hash)
  *
  *              SECTION: TypoScript related
  * 1161:     function getPagesTSconfig($id,$rootLine='',$returnPartArray=0)
@@ -341,7 +341,7 @@ final class t3lib_BEfunc {
         * @param       array           Array of fields
         * @param       string          Table in which we are searching (for DBAL detection of quoteStr() method)
         * @return      string          WHERE clause for search
-        * @deprecated          Use $GLOBALS['TYPO3_DB']->searchQuery() directly!
+        * @deprecated since TYPO3 4.0 - Use $GLOBALS['TYPO3_DB']->searchQuery() directly!
         */
        public static function searchQuery($searchWords, $fields, $table = '') {
                return $GLOBALS['TYPO3_DB']->searchQuery($searchWords, $fields, $table);
@@ -356,7 +356,7 @@ final class t3lib_BEfunc {
         * @param       string          Table field name
         * @param       string          Value to find in list
         * @return      string          WHERE clause for a query
-        * @deprecated          Use $GLOBALS['TYPO3_DB']->listQuery() directly!
+        * @deprecated since TYPO3 4.0 - Use $GLOBALS['TYPO3_DB']->listQuery() directly!
         */
        public static function listQuery($field, $value) {
                return $GLOBALS['TYPO3_DB']->listQuery($field, $value, '');
@@ -436,9 +436,9 @@ final class t3lib_BEfunc {
                                }
                        }
                }
-               $outQ = ' AND '.($inv ? '('.implode(' OR ', $invQuery).')' : implode(' AND ', $query));
+               $outQ = ($inv ? '(' . implode(' OR ', $invQuery) . ')' : implode(' AND ', $query));
 
-               return $outQ;
+               return $outQ ? ' AND ' . $outQ : '';
        }
 
        /**
@@ -500,7 +500,7 @@ final class t3lib_BEfunc {
         * @param       string          Optional ORDER BY field(s), if none, supply blank string.
         * @param       string          Optional LIMIT value ([begin,]max), if none, supply blank string.
         * @return      string          Full SQL query
-        * @deprecated
+        * @deprecated since TYPO3 4.0
         * @see t3lib_DB::exec_SELECT_mm_query()
         */
        public static function mm_query($select, $local_table, $mm_table, $foreign_table, $whereClause = '', $groupBy = '', $orderBy = '', $limit = '') {
@@ -523,7 +523,7 @@ final class t3lib_BEfunc {
         * @param       string          Table name
         * @param       array           Field values as key=>value pairs.
         * @return      string          Full SQL query for INSERT
-        * @deprecated
+        * @deprecated since TYPO3 4.0
         */
        public static function DBcompileInsert($table, $fields_values) {
                return $GLOBALS['TYPO3_DB']->INSERTquery($table, $fields_values);
@@ -537,7 +537,7 @@ final class t3lib_BEfunc {
         * @param       string          WHERE clause, eg. "uid=1"
         * @param       array           Field values as key=>value pairs.
         * @return      string          Full SQL query for UPDATE
-        * @deprecated
+        * @deprecated since TYPO3 4.0
         */
        public static function DBcompileUpdate($table, $where, $fields_values) {
                return $GLOBALS['TYPO3_DB']->UPDATEquery($table, $where, $fields_values);
@@ -599,6 +599,7 @@ final class t3lib_BEfunc {
                        } else {
                                break;
                        }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
                }
                if ($uid==0) {$theRowArray[] = Array('uid'=>0, 'title'=>'');}
                if (is_array($theRowArray)) {
@@ -706,6 +707,7 @@ final class t3lib_BEfunc {
                        } else {
                                break;
                        }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
                }
 
                if ($fullTitleLimit) {
@@ -834,6 +836,7 @@ final class t3lib_BEfunc {
                while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                        $sysLanguages[] = array($row['title'].' ['.$row['uid'].']', $row['uid'], ($row['flag'] ? 'flags/'.$row['flag'] : ''));
                }
+               $GLOBALS['TYPO3_DB']->sql_free_result($res);
 
                return $sysLanguages;
        }
@@ -866,8 +869,8 @@ final class t3lib_BEfunc {
                $localizationMode = false;
                if (is_array($fieldOrConfig) && count($fieldOrConfig)) {
                        $config = $fieldOrConfig;
-               } elseif (is_string($fieldOrConfig) && isset($GLOBALS['TCA'][$table]['columns'][$field]['config'])) {
-                       $config = $GLOBALS['TCA'][$table]['columns'][$field]['config'];
+               } elseif (is_string($fieldOrConfig) && isset($GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'])) {
+                       $config = $GLOBALS['TCA'][$table]['columns'][$fieldOrConfig]['config'];
                }
                if (is_array($config) && isset($config['type']) && $config['type']=='inline' && self::isTableLocalizable($table)) {
                        $localizationMode = (isset($config['behaviour']['localizationMode']) && $config['behaviour']['localizationMode'] ? $config['behaviour']['localizationMode'] : 'select');
@@ -1125,6 +1128,7 @@ final class t3lib_BEfunc {
                                                                );
                                        $newRecordPidValue = 0;
                                        $rr = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+                                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
 
                                                // break if no result from SQL db or if looping...
                                        if (!is_array($rr) || isset($uidAcc[$rr['uid']]))       break;
@@ -1195,47 +1199,45 @@ final class t3lib_BEfunc {
         *******************************************/
 
        /**
-        * Stores the string value $data in the 'cache_hash' table with the hash key, $hash, and visual/symbolic identification, $ident
+        * Stores the string value $data in the 'cache_hash' cache with the
+        * hash key, $hash, and visual/symbolic identification, $ident
         * IDENTICAL to the function by same name found in t3lib_page:
         * Usage: 2
         *
         * @param       string          32 bit hash string (eg. a md5 hash of a serialized array identifying the data being stored)
         * @param       string          The data string. If you want to store an array, then just serialize it first.
-        * @param       string          $ident is just a textual identification in order to inform about the content! May be 20 characters long.
+        * @param       string          $ident is just a textual identification in order to inform about the content!
         * @return      void
         */
        public static function storeHash($hash, $data, $ident) {
-               $insertFields = array(
-                       'hash' => $hash,
-                       'content' => $data,
-                       'ident' => $ident,
-                       'tstamp' => time()
+               $GLOBALS['typo3CacheManager']->getCache('cache_hash')->save(
+                       $hash,
+                       $data,
+                       array('ident_' . $ident),
+                       0 // unlimited lifetime
                );
-               $GLOBALS['TYPO3_DB']->exec_DELETEquery('cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash'));
-               $GLOBALS['TYPO3_DB']->exec_INSERTquery('cache_hash', $insertFields);
        }
 
        /**
-        * Returns string value stored for the hash string in the table "cache_hash"
+        * Returns string value stored for the hash string in the cache "cache_hash"
         * Can be used to retrieved a cached value
+        *
         * IDENTICAL to the function by same name found in t3lib_page
-        * Usage: 2
         *
-        * @param       string          Hash key, 32 bytes hex
-        * @param       integer         $expTime represents the expire time in seconds. For instance a value of 3600 would allow cached content within the last hour, otherwise nothing is returned.
+        * @param       string          The hash-string which was used to store the data value
         * @return      string
         */
-       public static function getHash($hash, $expTime = 0) {
-                       // if expTime is not set, the hash will never expire
-               $expTime = intval($expTime);
-               if ($expTime) {
-                       $whereAdd = ' AND tstamp > '.(time()-$expTime);
+       public static function getHash($hash) {
+               $hashContent = null;
+
+               $contentHashCache = $GLOBALS['typo3CacheManager']->getCache('cache_hash');
+               $cacheEntry = $contentHashCache->load($hash);
+
+               if ($cacheEntry) {
+                       $hashContent = $cacheEntry;
                }
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('content', 'cache_hash', 'hash='.$GLOBALS['TYPO3_DB']->fullQuoteStr($hash, 'cache_hash').$whereAdd);
-               $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
-               $GLOBALS['TYPO3_DB']->sql_free_result($res);
 
-               return (is_array($row) ? $row['content'] : null);
+               return $hashContent;
        }
 
 
@@ -1281,7 +1283,7 @@ final class t3lib_BEfunc {
                        // Parsing the user TS (or getting from cache)
                $userTS = implode($TSdataArray, chr(10).'[GLOBAL]'.chr(10));
                $hash = md5('pageTS:'.$userTS);
-               $cachedContent = t3lib_BEfunc::getHash($hash, 0);
+               $cachedContent = t3lib_BEfunc::getHash($hash);
                $TSconfig = array();
                if (isset($cachedContent)) {
                        $TSconfig = unserialize($cachedContent);
@@ -1417,6 +1419,8 @@ final class t3lib_BEfunc {
                while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                        $be_user_Array[$row['uid']] = $row;
                }
+               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+
                return $be_user_Array;
        }
 
@@ -1430,10 +1434,13 @@ final class t3lib_BEfunc {
         */
        public static function getGroupNames($fields = 'title,uid', $where = '') {
                $be_group_Array = Array();
+
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($fields, 'be_groups', 'pid=0 '.$where.t3lib_BEfunc::deleteClause('be_groups'), '', 'title');
                while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                        $be_group_Array[$row['uid']] = $row;
                }
+               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+
                return $be_group_Array;
        }
 
@@ -1635,7 +1642,7 @@ final class t3lib_BEfunc {
         * @param       string          String to set as title-attribute. If no $content is given only the attribute name is returned.
         * @param       boolean         If $hsc is set, then content of the attribute is htmlspecialchar()'ed (which is good for XHTML and other reasons...)
         * @return      string
-        * @deprecated          The idea made sense with older browsers, but now all browsers should support the "title" attribute - so just hardcode the title attribute instead!
+        * @deprecated since TYPO3 4.0 - The idea made sense with older browsers, but now all browsers should support the "title" attribute - so just hardcode the title attribute instead!
         */
        public static function titleAttrib($content = '', $hsc = 0) {
                global $CLIENT;
@@ -2110,13 +2117,15 @@ final class t3lib_BEfunc {
                                                        while($MMrow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($MMres)) {
                                                                $mmlA[] = ($noRecordLookup?$MMrow['uid']:t3lib_BEfunc::getRecordTitle($theColConf['foreign_table'], $MMrow, FALSE, $forceResult));
                                                        }
+                                                       $GLOBALS['TYPO3_DB']->sql_free_result($MMres);
+
                                                        if (is_array($mmlA)) {
                                                                $l = implode('; ', $mmlA);
                                                        } else {
                                                                $l = '';
                                                        }
                                                } else {
-                                                       $l = 'n/A';
+                                                       $l = 'N/A';
                                                }
                                        } else {
                                                $l = t3lib_BEfunc::getLabelFromItemlist($table, $col, $value);
@@ -2151,7 +2160,7 @@ final class t3lib_BEfunc {
                                break;
                                case 'check':
                                        if (!is_array($theColConf['items']) || count($theColConf['items'])==1) {
-                                               $l = $value ? 'Yes' : '';
+                                               $l = $value ? $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:yes') : '';
                                        } else {
                                                reset($theColConf['items']);
                                                $lA = Array();
@@ -2887,6 +2896,7 @@ final class t3lib_BEfunc {
                if ($table && $uid) {
                        $fields_values = array(
                                'userid' => $user_id,
+                               'feuserid' => 0,
                                'tstamp' => $GLOBALS['EXEC_TIME'],
                                'record_table' => $table,
                                'record_uid' => $uid,
@@ -2921,20 +2931,39 @@ final class t3lib_BEfunc {
                                                                AND sys_lockedrecords.tstamp > '.($GLOBALS['EXEC_TIME']-2*3600)
                                                );
                        while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
+                                       // Get the type of the user that locked this record: 
+                               if ($row['userid']) {
+                                       $userTypeLabel = 'beUser';
+                               } elseif ($row['feuserid']) {
+                                       $userTypeLabel = 'feUser';
+                               } else {
+                                       $userTypeLabel = 'user';
+                               }
+                               $userType = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.' . $userTypeLabel);
+                                       // Get the username (if available):
+                               if ($row['username']) {
+                                       $userName = $row['username'];
+                               } else {
+                                       $userName = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.unknownUser');
+                               }
+
                                $LOCKED_RECORDS[$row['record_table'].':'.$row['record_uid']] = $row;
                                $LOCKED_RECORDS[$row['record_table'].':'.$row['record_uid']]['msg'] = sprintf(
-                                       $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecord'),
-                                       $row['username'],
+                                       $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecordUser'),
+                                       $userType,
+                                       $userName,
                                        t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'], $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'))
                                );
                                if ($row['record_pid'] && !isset($LOCKED_RECORDS[$row['record_table'].':'.$row['record_pid']])) {
                                        $LOCKED_RECORDS['pages:'.$row['record_pid']]['msg'] = sprintf(
-                                               $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecord_content'),
-                                               $row['username'],
+                                               $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.lockedRecordUser_content'),
+                                               $userType,
+                                               $userName,
                                                t3lib_BEfunc::calcAge($GLOBALS['EXEC_TIME']-$row['tstamp'], $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.minutesHoursDaysYears'))
                                        );
                                }
                        }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
                }
                return $LOCKED_RECORDS[$table.':'.$uid];
        }
@@ -3337,9 +3366,10 @@ final class t3lib_BEfunc {
        public static function isModuleSetInTBE_MODULES($modName) {
                reset($GLOBALS['TBE_MODULES']);
                $loaded = array();
+
                while(list($mkey, $list) = each($GLOBALS['TBE_MODULES'])) {
                        $loaded[$mkey] = 1;
-                       if (trim($list)) {
+                       if (!is_array($list) && trim($list)) {
                                $subList = t3lib_div::trimExplode(',', $list, 1);
                                while(list(,$skey) = each($subList)) {
                                        $loaded[$mkey.'_'.$skey] = 1;
@@ -3442,6 +3472,7 @@ final class t3lib_BEfunc {
                                }
                                $outputRows[] = $row;
                        }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
 
                                // Set real-pid:
                        foreach($outputRows as $idx => $oRow) {
@@ -3909,6 +3940,7 @@ final class t3lib_BEfunc {
                                        '</a>');
 
                        }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
 
                        if (@is_file($enableInstallToolFile)) {
                                $url = t3lib_div::getIndpEnv('TYPO3_REQUEST_SCRIPT').'?adminWarning_cmd=remove_ENABLE_INSTALL_TOOL';
@@ -3927,6 +3959,18 @@ final class t3lib_BEfunc {
                                        '</a>');
                        }
 
+                               // Check if fileDenyPattern was changed which is dangerous on Apache
+                       if ($GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] != FILE_DENY_PATTERN_DEFAULT ) {
+                               $warnings['file_deny_pattern'] = sprintf(
+                                       $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.file_deny_pattern'),
+                                       '<br /><pre>'.htmlspecialchars(FILE_DENY_PATTERN_DEFAULT).'</pre><br />');
+                       }
+
+                               // Check if fileDenyPattern allows to upload .htaccess files which is dangerous on Apache
+                       if ($GLOBALS['TYPO3_CONF_VARS']['BE']['fileDenyPattern'] != FILE_DENY_PATTERN_DEFAULT && t3lib_div::verifyFilenameAgainstDenyPattern(".htaccess"))      {
+                               $warnings['file_deny_htaccess'] = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.file_deny_htaccess');
+                       }
+
                                // Check if there are still updates to perform
                        if (!t3lib_div::compat_version(TYPO3_branch)) {
                                $url = 'install/index.php?redirect_url=index.php'.urlencode('?TYPO3_INSTALL[type]=update');
@@ -3958,9 +4002,11 @@ final class t3lib_BEfunc {
 
                        if (count($warnings)) {
                                $style = ' style="margin-bottom:10px;"';
-                               $content = '<table border="0" cellpadding="0" cellspacing="0" class="warningbox"><tr><td>'.
-                                       $GLOBALS['TBE_TEMPLATE']->icons(3).'Important notice!<br /><ul><li'.$style.'>'.
-                                       implode('</li><li'.$style.'>', $warnings).'</li></ul>'.
+                               $content = '<table border="0" cellpadding="0" cellspacing="0" class="warningbox"><tr><td>' .
+                                       $GLOBALS['TBE_TEMPLATE']->icons(3) . '<span class="warningboxheader">' .
+                                       $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:warning.header') .
+                                       '</span><br /><ul><li' . $style.'>' .
+                                       implode('</li><li' . $style . '>', $warnings) . '</li></ul>' .
                                        '</td></tr></table>';
 
                                unset($warnings);
@@ -4034,7 +4080,7 @@ final class t3lib_BEfunc {
         * @param       string          The URL/script to jump to (used in A tag)
         * @return      array           Two keys, rows and list
         * @internal
-        * @deprecated
+        * @deprecated since TYPO3 4.0
         * @obsolete
         */
        public static function getListOfBackendModules($name, $perms_clause, $backPath = '', $script = 'index.php') {
@@ -4050,6 +4096,8 @@ final class t3lib_BEfunc {
                                        htmlspecialchars($row['title']).
                                        '</a></span><br />';
                }
+               $GLOBALS['TYPO3_DB']->sql_free_result($res);
+
                return array('rows'=>$theRows, 'list'=>$out);
        }
 
@@ -4080,4 +4128,4 @@ final class t3lib_BEfunc {
                return $script;
        }
 }
-?>
+?>
\ No newline at end of file