Fixed #11430: Performance improvement: use $GLOBALS['EXEC_TIME'] instead of time...
[Packages/TYPO3.CMS.git] / typo3 / sysext / cms / web_info / class.tx_cms_webinfo_lang.php
index 9c338df..c41cd9a 100644 (file)
@@ -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
  *
  *
  *
- *   65: class tx_cms_webinfo_lang extends t3lib_extobjbase
- *   72:     function modMenu()
- *   89:     function main()
- *  156:     function renderL10nTable(&$tree)
- *  320:     function getSystemLanguages()
- *  342:     function getLangStatus($pageId, $langId)
- *  369:     function getContentElementCount($pageId,$sysLang)
+ *   66: class tx_cms_webinfo_lang extends t3lib_extobjbase
+ *   73:     function modMenu()
+ *  102:     function main()
+ *  171:     function renderL10nTable(&$tree)
+ *  342:     function getSystemLanguages()
+ *  364:     function getLangStatus($pageId, $langId)
+ *  393:     function getLocalizedElementInfo($pageId,$sysLang)
+ *  471:     function getContentElementCount($pageId,$sysLang)
  *
- * TOTAL FUNCTIONS: 6
+ * TOTAL FUNCTIONS: 7
  * (This index is automatically created/updated by the extension "extdeveval")
  *
  */
-
-require_once(PATH_t3lib.'class.t3lib_pagetree.php');
-require_once(PATH_t3lib.'class.t3lib_extobjbase.php');
-
-
-
-
 /**
  * Class for displaying translation status of pages in the tree.
  *
@@ -74,11 +68,11 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
 
                $menuArray = array (
                        'depth' => array(
+                               0 => $LANG->getLL('depth_0'),
                                1 => $LANG->getLL('depth_1'),
                                2 => $LANG->getLL('depth_2'),
                                3 => $LANG->getLL('depth_3')
                        ),
-                       'details' => ''
                );
 
                        // Languages:
@@ -107,11 +101,10 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
                                // Depth selector:
                        $h_func = t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[depth]',$this->pObj->MOD_SETTINGS['depth'],$this->pObj->MOD_MENU['depth'],'index.php');
                        $h_func.= t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[lang]',$this->pObj->MOD_SETTINGS['lang'],$this->pObj->MOD_MENU['lang'],'index.php');
-                       $h_func.= t3lib_BEfunc::getFuncCheck($this->pObj->id,'SET[details]',$this->pObj->MOD_SETTINGS['details'],'index.php').' Details';
                        $theOutput.= $h_func;
 
                                // Add CSH:
-                       $theOutput.= t3lib_BEfunc::cshItem('_MOD_web_info','lang',$GLOBALS['BACK_PATH'],'|<br/>');
+                       $theOutput .= t3lib_BEfunc::cshItem('_MOD_web_info', 'lang', $GLOBALS['BACK_PATH'], '|<br />');
 
                                // Showing the tree:
                                // Initialize starting point of page tree:
@@ -132,27 +125,25 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
                        );
 
                                // Create the tree from starting point:
-                       $tree->getTree($treeStartingPoint, $depth, '');
+                       if ($depth)     $tree->getTree($treeStartingPoint, $depth, '');
                        #debug($tree->tree);
 
                                // Add CSS needed:
-                       $css_content = '
-                               TABLE#langTable {
+                       $this->pObj->doc->inDocStylesArray[] = '
+                               table#langTable {
                                        margin-top: 10px;
                                }
-                               TABLE#langTable TR TD {
+                               table#langTable tr td {
                                        padding-left : 2px;
                                        padding-right : 2px;
                                        white-space: nowrap;
                                }
-                               TD.c-blocked { background-color: red; }
-                               TD.c-ok { background-color: #669966; }
-                               TD.c-fallback {  }
-                               TD.c-leftLine {border-left: 2px solid black; }
+                               td.c-blocked { background-color: #f72116; }
+                               td.c-ok { background-color: #86b571; }
+                               td.c-fallback {  }
+                               td.c-leftLine {border-left: 2px solid black; }
                                .bgColor5 { font-weight: bold; }
                        ';
-                       $marker = '/*###POSTCSSMARKER###*/';
-                       $this->pObj->content = str_replace($marker,$css_content.chr(10).$marker,$this->pObj->content);
 
                                // Render information table:
                        $theOutput.= $this->renderL10nTable($tree);
@@ -219,6 +210,9 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
                        $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>';
                        $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],0).'</td>';
 
+                       $modSharedTSconfig = t3lib_BEfunc::getModTSconfig($data['row']['uid'], 'mod.SHARED');
+                       $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages']) ? t3lib_div::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], 1) : array();
+
                                // Traverse system languages:
                        foreach($languages as $langRow) {
                                if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid'])      {
@@ -241,7 +235,6 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
                                                                        ($row['_COUNT']>1 ? '<div>'.$LANG->getLL('lang_renderl10n_badThingThereAre','1').'</div>':'');
                                                $tCells[] = '<td class="'.$status.' c-leftLine">'.
                                                                                $info.
-                                                                               ($this->pObj->MOD_SETTINGS['details'] ? $this->getLocalizedElementInfo($data['row']['uid'],$langRow['uid']) : '').
                                                                                '</td>';
 
                                                        // Edit whole record:
@@ -260,15 +253,20 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
                                                $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
                                                $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],$langRow['uid']).'</td>';
                                        } else {
-                                               $status = t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback';
+                                               if (in_array($langRow['uid'], $disableLanguages)) {
+                                                               // Language has been disabled for this page
+                                                       $status = 'c-blocked';
+                                                       $info = '';
+                                               } else {
+                                                       $status = t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback';
+                                                       $info = '<input type="checkbox" name="newOL['.$langRow['uid'].']['.$data['row']['uid'].']" value="1" />';
+                                                       $newOL_js[$langRow['uid']].= '
+                                                               +(document.webinfoForm[\'newOL['.$langRow['uid'].']['.$data['row']['uid'].']\'].checked ? \'&edit[pages_language_overlay]['.$data['row']['uid'].']=new\' : \'\')
+                                                       ';
+                                               }
+
                                                $tCells[] = '<td class="'.$status.' c-leftLine">&nbsp;</td>';
                                                $tCells[] = '<td class="'.$status.'">&nbsp;</td>';
-
-                                               $info = '';
-                                               $info.= '<input type="checkbox" name="newOL['.$langRow['uid'].']['.$data['row']['uid'].']" value="1" />';
-                                               $newOL_js[$langRow['uid']].= '
-                                                       +(document.webinfoForm[\'newOL['.$langRow['uid'].']['.$data['row']['uid'].']\'].checked ? \'&edit[pages_language_overlay]['.$data['row']['uid'].']=new\' : \'\')
-                                               ';
                                                $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
                                        }
                                }
@@ -339,15 +337,28 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
         * @return      array           System language records in an array.
         */
        function getSystemLanguages()   {
+               if (!$GLOBALS['BE_USER']->user['admin'] &&
+                       strlen($GLOBALS['BE_USER']->groupData['allowed_languages'])) {
+
+                       $allowed_languages = array_flip(explode(',', $GLOBALS['BE_USER']->groupData['allowed_languages']));
+               }
+
                $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
                        '*',
                        'sys_language',
-                       '1'.t3lib_BEfunc::deleteClause('sys_language')
+                       '1=1'.t3lib_BEfunc::deleteClause('sys_language')
                );
 
                $outputArray = array();
                while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
-                       $outputArray[] = $row;
+                       if (is_array($allowed_languages) && count($allowed_languages)) {
+                               if (isset($allowed_languages[$row['uid']])) {
+                                       $outputArray[] = $row;
+                               }
+                       }
+                       else {
+                               $outputArray[] = $row;
+                       }
                }
 
                return $outputArray;
@@ -371,12 +382,12 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
                );
 
                $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+               t3lib_BEfunc::workspaceOL('pages_language_overlay',$row);
                if (is_array($row))     {
-                       t3lib_BEfunc::workspaceOL('pages_language_overlay',$row);
                        $row['_COUNT'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
                        $row['_HIDDEN'] = $row['hidden'] ||
-                                                       (intval($row['endtime']) > 0 && intval($row['endtime']) < time()) ||
-                                                       (time() < intval($row['starttime']));
+                                                       (intval($row['endtime']) > 0 && intval($row['endtime']) < $GLOBALS['EXEC_TIME']) ||
+                                                       ($GLOBALS['EXEC_TIME'] < intval($row['starttime']));
                }
 
                return $row;
@@ -389,95 +400,15 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
         * @param       integer         Sys language uid
         * @return      integer         Number of content elements from the PID where the language is set to a certain value.
         */
-       function getLocalizedElementInfo($pageId,$sysLang)      {
-               global $TCA;
-
-               $info = '<hr/>';
-               foreach($TCA as $table => $cfg) {
-                       if ($table!='pages' && $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'])  {
-#                      $info.='<h3>'.$table.'</h3>';
-                               if ($TCA[$table]['ctrl']['transOrigPointerTable'])      {
-                                       #$info.='Table "'.$table.'" is skipped because it had a transOrigPointerTable set which is not supported - yet.';
-                               } else {
-
-                                               // First, select all records that are default language OR international:
-                                       $allRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                               '*',
-                                               $table,
-                                               'pid='.intval($pageId).
-                                                       ' AND '.$TCA[$table]['ctrl']['languageField'].'<=0'.
-                                                       t3lib_BEfunc::deleteClause($table).
-                                                       t3lib_BEfunc::versioningPlaceholderClause($table)
-                                       );
-                                       if (count($allRows))    {
-                       $info.='<h3>'.$table.'</h3>';
-
-$info.='[<b>'.$TCA[$table]['ctrl']['languageField'].'</b>]';
-$info.='[<b>'.$TCA[$table]['ctrl']['transOrigPointerField'].'</b>]';
-$info.='[<b>'.$TCA[$table]['ctrl']['transOrigDiffSourceField'].'</b>]';
-
-                                                       // Now, for each record, look for localization:
-                                               $translationsUids = array(0);
-                                               foreach($allRows as $row)       {
-                                                       $info.='UID:'.$row['uid'].'/lang:'.$row[$TCA[$table]['ctrl']['languageField']].' has translations:';
-                                                       $translations = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                                               '*',
-                                                               $table,
-                                                               'pid='.intval($pageId).
-                                                                       ' AND '.$TCA[$table]['ctrl']['languageField'].'='.intval($sysLang).
-                                                                       ' AND '.$TCA[$table]['ctrl']['transOrigPointerField'].'='.intval($row['uid']).
-                                                                       t3lib_BEfunc::deleteClause($table).
-                                                                       t3lib_BEfunc::versioningPlaceholderClause($table)
-                                                       );
-
-                                                       foreach($translations as $c => $tr)     {
-                                                               $info.=($c>0 ? 'UPS!!':'').'['.$tr['uid'].'],';
-                                                               $translationsUids[] = $tr['uid'];
-                                                       }
-
-
-
-                                                       $info.='<br/>';
-                                               }
-
-                                                       // Look for "lost" translations
-                                               $lostTranslations = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
-                                                       'uid',
-                                                       $table,
-                                                       'pid='.intval($pageId).
-                                                               ' AND '.$TCA[$table]['ctrl']['languageField'].'='.intval($sysLang).
-                                                               ' AND uid NOT IN ('.implode(',',$translationsUids).')'.
-                                                               t3lib_BEfunc::deleteClause($table).
-                                                               t3lib_BEfunc::versioningPlaceholderClause($table)
-                                               );
-                                               if (count($lostTranslations))   {
-                                                       $info.=t3lib_div::view_array($lostTranslations);
-                                               }
-                                       }
-                               }
-                       }
-               }
-               return $info;
-       }
-
-       /**
-        * Counting content elements for a single language on a page.
-        *
-        * @param       integer         Page id to select for.
-        * @param       integer         Sys language uid
-        * @return      integer         Number of content elements from the PID where the language is set to a certain value.
-        */
        function getContentElementCount($pageId,$sysLang)       {
-               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
-                       'count(*)',
+               $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows(
+                       'uid',
                        'tt_content',
-                       'pid='.intval($pageId).
-                               ' AND sys_language_uid='.intval($sysLang).
-                               t3lib_BEfunc::deleteClause('tt_content').
+                       'pid=' . intval($pageId) .
+                               ' AND sys_language_uid=' . intval($sysLang) .
+                               t3lib_BEfunc::deleteClause('tt_content') .
                                t3lib_BEfunc::versioningPlaceholderClause('tt_content')
                );
-
-               list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
                return $count ? $count : '-';
        }
 }
@@ -486,4 +417,5 @@ $info.='[<b>'.$TCA[$table]['ctrl']['transOrigDiffSourceField'].'</b>]';
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']) {
        include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']);
 }
+
 ?>
\ No newline at end of file