Fixed bug #7896: Hide the page browser if not enough entries are available (Thanks...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / tslib / class.tslib_pibase.php
old mode 100755 (executable)
new mode 100644 (file)
index dc38f54..86ebca3
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
+*  (c) 1999-2009 Kasper Skaarhoj (kasperYYYY@typo3.com)
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
@@ -209,7 +209,7 @@ class tslib_pibase {
 
                        // Setting piVars:
                if ($this->prefixId)    {
-                       $this->piVars = t3lib_div::GParrayMerged($this->prefixId);
+                       $this->piVars = t3lib_div::_GPmerged($this->prefixId);
 
                                // cHash mode check
                                // IMPORTANT FOR CACHED PLUGINS (USER cObject): As soon as you generate cached plugin output which depends on parameters (eg. seeing the details of a news item) you MUST check if a cHash value is set.
@@ -304,7 +304,7 @@ class tslib_pibase {
                $conf['useCacheHash'] = $this->pi_USER_INT_obj ? 0 : $cache;
                $conf['no_cache'] = $this->pi_USER_INT_obj ? 0 : !$cache;
                $conf['parameter'] = $altPageId ? $altPageId : ($this->pi_tmpPageId ? $this->pi_tmpPageId : $GLOBALS['TSFE']->id);
-               $conf['additionalParams'] = $this->conf['parent.']['addParams'].t3lib_div::implodeArrayForUrl('',$urlParameters,'',1).$this->pi_moreParams;
+               $conf['additionalParams'] = $this->conf['parent.']['addParams'].t3lib_div::implodeArrayForUrl('', $urlParameters, '', true).$this->pi_moreParams;
 
                return $this->cObj->typoLink($str, $conf);
        }
@@ -393,7 +393,7 @@ class tslib_pibase {
         * @return      string          The processed input string, modified IF a <a> tag was found
         */
        function pi_openAtagHrefInJSwindow($str,$winName='',$winParams='width=670,height=500,status=0,menubar=0,scrollbars=1,resizable=1')      {
-               if (eregi('(.*)(<a[^>]*>)(.*)',$str,$match))    {
+               if (preg_match('/(.*)(<a[^>]*>)(.*)/i',$str,$match))    {
                        $aTagContent = t3lib_div::get_tag_attributes($match[2]);
                        $match[2]='<a href="#" onclick="'.
                                htmlspecialchars('vHWin=window.open(\''.$GLOBALS['TSFE']->baseUrlWrap($aTagContent['href']).'\',\''.($winName?$winName:md5($aTagContent['href'])).'\',\''.$winParams.'\');vHWin.focus();return false;').
@@ -443,9 +443,10 @@ class tslib_pibase {
         * @param       array           Array with elements to overwrite the default $wrapper-array.
         * @param       string          varname for the pointer.
         * @param       boolean         enable htmlspecialchars() for the pi_getLL function (set this to FALSE if you want f.e use images instead of text for links like 'previous' and 'next').
-        * @return      string          Output HTML-Table, wrapped in <div>-tags with a class attribute (if $wrapArr is not passed,
+        * @param   boolean     forces the output of the page browser if you set this option to "true" (otherwise it's only drawn if enough entries are available)
+        * @return      string          Output HTML-Table, wrapped in <div>-tags with a class attribute (if $wrapArr is not passed,
         */
-       function pi_list_browseresults($showResultCount=1, $tableParams='', $wrapArr=array(), $pointerName='pointer', $hscText=TRUE)    {
+       function pi_list_browseresults($showResultCount=1, $tableParams='', $wrapArr=array(), $pointerName='pointer', $hscText=TRUE, $forceOutput=FALSE) {
 
                // example $wrapArr-array how it could be traversed from an extension
                /* $wrapArr = array(
@@ -466,6 +467,10 @@ class tslib_pibase {
                $maxPages = t3lib_div::intInRange($this->internal['maxPages'],1,100);
                $pi_isOnlyFields = $this->pi_isOnlyFields($this->pi_isOnlyFields);
 
+               if (!$forceOutput && $count <= $results_at_a_time) {
+                       return '';
+               }
+
                        // $showResultCount determines how the results of the pagerowser will be shown.
                        // If set to 0: only the result-browser will be shown
                        //                       1: (default) the text "Displaying results..." and the result-browser will be shown.
@@ -548,7 +553,7 @@ class tslib_pibase {
                                }
                        }
                        if ($pointer<$totalPages-1 || $showFirstLast)   {
-                               if ($pointer==$totalPages-1) { // Link to next page
+                               if ($pointer>=$totalPages-1) { // Link to next page
                                        $links[]=$this->cObj->wrap($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),$wrapper['disabledLinkWrap']);
                                } else {
                                        $links[]=$this->cObj->wrap($this->pi_linkTP_keepPIvars($this->pi_getLL('pi_list_browseresults_next','Next >',$hscText),array($pointerName => $pointer+1),$pi_isOnlyFields),$wrapper['inactiveLinkWrap']);
@@ -640,8 +645,7 @@ class tslib_pibase {
         */
        function pi_list_modeSelector($items=array(),$tableParams='')   {
                $cells=array();
-               reset($items);
-               while(list($k,$v)=each($items)) {
+               foreach ($items as $k => $v) {
                        $cells[]='
                                        <td'.($this->piVars['mode']==$k?$this->pi_classParam('modeSelector-SCell'):'').'><p>'.
                                $this->pi_linkTP_keepPIvars(htmlspecialchars($v),array('mode'=>$k),$this->pi_isOnlyFields($this->pi_isOnlyFields)).
@@ -785,10 +789,13 @@ class tslib_pibase {
         * @param       string          $data: CSS data
         * @param       string          If $selector is set to any CSS selector, eg 'P' or 'H1' or 'TABLE' then the style $data will regard those HTML-elements only
         * @return      void
-        * @deprecated          I think this function should not be used (and probably isn't used anywhere). It was a part of a concept which was left behind quite quickly.
+        * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, I think this function should not be used (and probably isn't used anywhere). It was a part of a concept which was left behind quite quickly.
+        * @obsolete
         * @private
         */
        function pi_setClassStyle($class,$data,$selector='')    {
+               t3lib_div::logDeprecatedFunction();
+
                $GLOBALS['TSFE']->setCSS($this->pi_getClassName($class).($selector?' '.$selector:''),'.'.$this->pi_getClassName($class).($selector?' '.$selector:'').' {'.$data.'}');
        }
 
@@ -945,10 +952,11 @@ class tslib_pibase {
         * @return      string          The value from LOCAL_LANG.
         */
        function pi_getLL($key,$alt='',$hsc=FALSE)      {
+                       // The "from" charset of csConv() is only set for strings from TypoScript via _LOCAL_LANG
                if (isset($this->LOCAL_LANG[$this->LLkey][$key]))       {
-                       $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key], $this->LOCAL_LANG_charset[$this->LLkey][$key]); // The "from" charset is normally empty and thus it will convert from the charset of the system language, but if it is set (see ->pi_loadLL()) it will be used.
+                       $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->LLkey][$key], $this->LOCAL_LANG_charset[$this->LLkey][$key]);
                } elseif ($this->altLLkey && isset($this->LOCAL_LANG[$this->altLLkey][$key]))   {
-                       $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->altLLkey][$key], $this->LOCAL_LANG_charset[$this->altLLkey][$key]);   // The "from" charset is normally empty and thus it will convert from the charset of the system language, but if it is set (see ->pi_loadLL()) it will be used.
+                       $word = $GLOBALS['TSFE']->csConv($this->LOCAL_LANG[$this->altLLkey][$key], $this->LOCAL_LANG_charset[$this->altLLkey][$key]);
                } elseif (isset($this->LOCAL_LANG['default'][$key]))    {
                        $word = $this->LOCAL_LANG['default'][$key];     // No charset conversion because default is english and thereby ASCII
                } else {
@@ -969,28 +977,26 @@ class tslib_pibase {
         */
        function pi_loadLL()    {
                if (!$this->LOCAL_LANG_loaded && $this->scriptRelPath)  {
-                       $basePath = t3lib_extMgm::extPath($this->extKey).dirname($this->scriptRelPath).'/locallang.php';
+                       $basePath = 'EXT:' . $this->extKey . '/' . dirname($this->scriptRelPath) . '/locallang.xml';
 
-                               // php or xml as source: In any case the charset will be that of the system language.
-                               // However, this function guarantees only return output for default language plus the specified language (which is different from how 3.7.0 dealt with it)
-                       $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey);
+                               // Read the strings in the required charset (since TYPO3 4.2)
+                       $this->LOCAL_LANG = t3lib_div::readLLfile($basePath,$this->LLkey,$GLOBALS['TSFE']->renderCharset);
                        if ($this->altLLkey)    {
                                $tempLOCAL_LANG = t3lib_div::readLLfile($basePath,$this->altLLkey);
                                $this->LOCAL_LANG = array_merge(is_array($this->LOCAL_LANG) ? $this->LOCAL_LANG : array(),$tempLOCAL_LANG);
                        }
 
                                // Overlaying labels from TypoScript (including fictitious language keys for non-system languages!):
-                       if (is_array($this->conf['_LOCAL_LANG.']))      {
-                               reset($this->conf['_LOCAL_LANG.']);
-                               while(list($k,$lA)=each($this->conf['_LOCAL_LANG.']))   {
+                       $confLL = $this->conf['_LOCAL_LANG.'];
+                       if (is_array($confLL)) {
+                               foreach ($confLL as $k => $lA) {
                                        if (is_array($lA))      {
                                                $k = substr($k,0,-1);
                                                foreach($lA as $llK => $llV)    {
                                                        if (!is_array($llV))    {
                                                                $this->LOCAL_LANG[$k][$llK] = $llV;
-                                                               if ($k != 'default')    {
-                                                                       $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'];        // For labels coming from the TypoScript (database) the charset is assumed to be "forceCharset" and if that is not set, assumed to be that of the individual system languages (thus no conversion)
-                                                               }
+                                                                       // For labels coming from the TypoScript (database) the charset is assumed to be "forceCharset" and if that is not set, assumed to be that of the individual system languages
+                                                               $this->LOCAL_LANG_charset[$k][$llK] = $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] ? $GLOBALS['TYPO3_CONF_VARS']['BE']['forceCharset'] : $GLOBALS['TSFE']->csConvObj->charSetArray[$k];
                                                        }
                                                }
                                        }
@@ -1043,7 +1049,7 @@ class tslib_pibase {
         * @param       boolean         If set, the function will return the query not as a string but array with the various parts.
         * @return      mixed           The query build.
         * @access private
-        * @deprecated          Use pi_exec_query() instead!
+        * @deprecated since TYPO3 3.6, this function will be removed in TYPO3 4.5, use pi_exec_query() instead!
         */
        function pi_list_query($table,$count=0,$addWhere='',$mm_cat='',$groupBy='',$orderBy='',$query='',$returnQueryArray=FALSE)       {
 
@@ -1066,7 +1072,7 @@ class tslib_pibase {
                }
 
                        // Split the "FROM ... WHERE" string so we get the WHERE part and TABLE names separated...:
-               list($TABLENAMES,$WHERE) = spliti('WHERE', trim($query), 2);
+               list($TABLENAMES, $WHERE) = preg_split('/WHERE/i', trim($query), 2);
                $TABLENAMES = trim(substr(trim($TABLENAMES),5));
                $WHERE = trim($WHERE);
 
@@ -1163,18 +1169,23 @@ class tslib_pibase {
         * @param       integer         $recursive is an integer >=0 telling how deep to dig for pids under each entry in $pid_list
         * @return      string          List of PID values (comma separated)
         */
-       function pi_getPidList($pid_list,$recursive=0)  {
-               if (!strcmp($pid_list,''))      $pid_list = $GLOBALS['TSFE']->id;
-               $recursive = t3lib_div::intInRange($recursive,0);
-
-               $pid_list_arr = array_unique(t3lib_div::trimExplode(',',$pid_list,1));
-               $pid_list = array();
-
-               foreach($pid_list_arr as $val)  {
-                       $val = t3lib_div::intInRange($val,0);
-                       if ($val)       {
-                               $_list = $this->cObj->getTreeList(-1*$val, $recursive);
-                               if ($_list)             $pid_list[] = $_list;
+       function pi_getPidList($pid_list, $recursive = 0) {
+               if (!strcmp($pid_list, '')) {
+                       $pid_list = $GLOBALS['TSFE']->id;
+               }
+
+               $recursive = t3lib_div::intInRange($recursive, 0);
+
+               $pid_list_arr = array_unique(t3lib_div::trimExplode(',', $pid_list, 1));
+               $pid_list     = array();
+
+               foreach($pid_list_arr as $val) {
+                       $val = t3lib_div::intInRange($val, 0);
+                       if ($val) {
+                               $_list = $this->cObj->getTreeList(-1 * $val, $recursive);
+                               if ($_list) {
+                                       $pid_list[] = $_list;
+                               }
                        }
                }
 
@@ -1191,7 +1202,7 @@ class tslib_pibase {
        function pi_prependFieldsWithTable($table,$fieldList)   {
                $list=t3lib_div::trimExplode(',',$fieldList,1);
                $return=array();
-               while(list(,$listItem)=each($list))     {
+               foreach ($list as $listItem) {
                        $return[]=$table.'.'.$listItem;
                }
                return implode(',',$return);
@@ -1257,7 +1268,7 @@ class tslib_pibase {
 
                $fList = t3lib_div::trimExplode(',',$fList,1);
                $tempPiVars = $this->piVars;
-               while(list(,$k)=each($fList))   {
+               foreach ($fList as $k) {
                        if (!t3lib_div::testInt($tempPiVars[$k]) || $tempPiVars[$k]<$lowerThan)         unset($tempPiVars[$k]);
                }
                if (!count($tempPiVars))        return 1;
@@ -1274,8 +1285,7 @@ class tslib_pibase {
         */
        function pi_autoCache($inArray) {
                if (is_array($inArray)) {
-                       reset($inArray);
-                       while(list($fN,$fV)=each($inArray))     {
+                       foreach ($inArray as $fN => $fV) {
                                if (!strcmp($inArray[$fN],''))  {
                                        unset($inArray[$fN]);
                                } elseif (is_array($this->pi_autoCacheFields[$fN]))     {
@@ -1385,4 +1395,5 @@ class tslib_pibase {
 }
 
 // NO extension of class - does not make sense here.
-?>
+
+?>
\ No newline at end of file