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 6949b86..c41cd9a 100644 (file)
@@ -2,7 +2,7 @@
 /***************************************************************
 *  Copyright notice
 *
-*  (c) 1999-2004 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.
  *
@@ -72,13 +66,25 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
        function modMenu()      {
                global $LANG;
 
-               return array (
+               $menuArray = array (
                        'depth' => array(
+                               0 => $LANG->getLL('depth_0'),
                                1 => $LANG->getLL('depth_1'),
                                2 => $LANG->getLL('depth_2'),
                                3 => $LANG->getLL('depth_3')
-                       )
+                       ),
+               );
+
+                       // Languages:
+               $lang = $this->getSystemLanguages();
+               $menuArray['lang']=array(
+                       0 => '[All]'
                );
+               foreach($lang as $langRec)      {
+                       $menuArray['lang'][$langRec['uid']] = $langRec['title'];
+               }
+
+               return $menuArray;
        }
 
        /**
@@ -94,15 +100,16 @@ 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');
                        $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:
                        $treeStartingPoint = intval($this->pObj->id);
-                       $treeStartingRecord = t3lib_BEfunc::getRecord('pages', $treeStartingPoint);
+                       $treeStartingRecord = t3lib_BEfunc::getRecordWSOL('pages', $treeStartingPoint);
                        $depth = $this->pObj->MOD_SETTINGS['depth'];
 
                                // Initialize tree object:
@@ -118,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);
@@ -171,7 +176,7 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
                        $langRecUids[0][] = $data['row']['uid'];
 
                                // Page icons / titles etc.
-                       $tCells[] = '<td>'.
+                       $tCells[] = '<td'.($data['row']['_CSSCLASS'] ? ' class="'.$data['row']['_CSSCLASS'].'"' : '').'>'.
                                                        $data['HTML'].
                                                        htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['title'],$titleLen)).
                                                        (strcmp($data['row']['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['nav_title'],$titleLen)).'</em>]' : '').
@@ -199,59 +204,71 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
 
                        $info.= '&nbsp;';
                        $info.= $data['row']['l18n_cfg']&1 ? '<span title="'.$LANG->sL('LLL:EXT:cms/locallang_tca.php:pages.l18n_cfg.I.1','1').'">D</span>' : '&nbsp;';
-                       $info.= $data['row']['l18n_cfg']&2 ? '<span title="'.$LANG->sL('LLL:EXT:cms/locallang_tca.php:pages.l18n_cfg.I.2','1').'">N</span>' : '&nbsp;';
+                       $info.= t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) ? '<span title="'.$LANG->sL('LLL:EXT:cms/locallang_tca.php:pages.l18n_cfg.I.2','1').'">N</span>' : '&nbsp;';
 
                                // Put into cell:
                        $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) {
-                               $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']);
-                               $info = '';
-
-                               if (is_array($row))     {
-                                       $langRecUids[$langRow['uid']][] = $row['uid'];
-                                       $status = $row['_HIDDEN'] ? ($data['row']['l18n_cfg']&2 || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback') : 'c-ok';
-                                       $icon = t3lib_iconWorks::getIconImage(
-                                               'pages_language_overlay',
-                                               $row,
-                                               $GLOBALS['BACK_PATH'],
-                                               'align="top" class="c-recIcon"'
-                                       );
-
-                                       $info = $icon.
-                                                               htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'],$titleLen)).
-                                                               (strcmp($row['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['nav_title'],$titleLen)).'</em>]' : '').
-                                                               ($row['_COUNT']>1 ? '<div>'.$LANG->getLL('lang_renderl10n_badThingThereAre','1').'</div>':'');
-                                       $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>';
-
-                                               // Edit whole record:
+                               if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid'])      {
+                                       $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']);
                                        $info = '';
-                                       $editUid = $row['uid'];
-                                       $params = '&edit[pages_language_overlay]['.$editUid.']=edit';
-                                       $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
-                                                       '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLanguageOverlayRecord','1').'" border="0" alt="" />'.
-                                                       '</a>';
-
-                                       $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]='.$langRow['uid'].'"); return false;').'">'.
-                                                       '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit_page.gif','width="12" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPageLang','1').'" border="0" alt="" />'.
-                                                       '</a>';
-                                       $info.= str_replace('###LANG_UID###',$langRow['uid'],$viewPageLink);
-
-                                       $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 = $data['row']['l18n_cfg']&2 || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback';
-                                       $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>';
+                                       if (is_array($row))     {
+                                               $langRecUids[$langRow['uid']][] = $row['uid'];
+                                               $status = $row['_HIDDEN'] ? (t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback') : 'c-ok';
+                                               $icon = t3lib_iconWorks::getIconImage(
+                                                       'pages_language_overlay',
+                                                       $row,
+                                                       $GLOBALS['BACK_PATH'],
+                                                       'align="top" class="c-recIcon"'
+                                               );
+
+                                               $info = $icon.
+                                                                       htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'],$titleLen)).
+                                                                       (strcmp($row['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['nav_title'],$titleLen)).'</em>]' : '').
+                                                                       ($row['_COUNT']>1 ? '<div>'.$LANG->getLL('lang_renderl10n_badThingThereAre','1').'</div>':'');
+                                               $tCells[] = '<td class="'.$status.' c-leftLine">'.
+                                                                               $info.
+                                                                               '</td>';
+
+                                                       // Edit whole record:
+                                               $info = '';
+                                               $editUid = $row['uid'];
+                                               $params = '&edit[pages_language_overlay]['.$editUid.']=edit';
+                                               $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLanguageOverlayRecord','1').'" border="0" alt="" />'.
+                                                               '</a>';
+
+                                               $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]='.$langRow['uid'].'"); return false;').'">'.
+                                                               '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit_page.gif','width="12" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPageLang','1').'" border="0" alt="" />'.
+                                                               '</a>';
+                                               $info.= str_replace('###LANG_UID###',$langRow['uid'],$viewPageLink);
+
+                                               $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 {
+                                               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>';
+                                               $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
+                                       }
                                }
                        }
 
@@ -269,7 +286,7 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
                if (is_array($langRecUids[0]))  {
                        $params = '&edit[pages]['.implode(',',$langRecUids[0]).']=edit&columnsOnly=title,nav_title,l18n_cfg,hidden';
                        $editIco = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
-                               <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPageHeaders','1').'" border="0" alt="" />
+                               <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPageProperties','1').'" border="0" alt="" />
                                </a>';
                } else $editIco = '';
                $tCells[] = '<td class="c-leftLine" colspan="2">'.
@@ -278,24 +295,26 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
                                        '</td>';
 
                foreach($languages as $langRow) {
-                               // Title:
-                       $tCells[] = '<td class="c-leftLine">'.htmlspecialchars($langRow['title']).'</td>';
+                       if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid'])      {
+                                       // Title:
+                               $tCells[] = '<td class="c-leftLine">'.htmlspecialchars($langRow['title']).'</td>';
+
+                                       // Edit language overlay records:
+                               if (is_array($langRecUids[$langRow['uid']]))    {
+                                       $params = '&edit[pages_language_overlay]['.implode(',',$langRecUids[$langRow['uid']]).']=edit&columnsOnly=title,nav_title,hidden';
+                                       $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
+                                               <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLangOverlays','1').'" border="0" alt="" />
+                                               </a></td>';
+                               } else {
+                                       $tCells[] = '<td>&nbsp;</td>';
+                               }
 
-                               // Edit language overlay records:
-                       if (is_array($langRecUids[$langRow['uid']]))    {
-                               $params = '&edit[pages_language_overlay]['.implode(',',$langRecUids[$langRow['uid']]).']=edit&columnsOnly=title,nav_title,hidden';
+                                       // Create new overlay records:
+                               $params = "'".$newOL_js[$langRow['uid']]."+'&columnsOnly=title,hidden,sys_language_uid&defVals[pages_language_overlay][sys_language_uid]=".$langRow['uid'];
                                $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
-                                       <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLangOverlays','1').'" border="0" alt="" />
+                                       <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/new_el.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_getlangsta_createNewTranslationHeaders','1').'" border="0" alt="" />
                                        </a></td>';
-                       } else {
-                               $tCells[] = '<td>&nbsp;</td>';
                        }
-
-                               // Create new overlay records:
-                       $params = "'".$newOL_js[$langRow['uid']]."+'&columnsOnly=title,hidden,sys_language_uid&defVals[pages_language_overlay][sys_language_uid]=".$langRow['uid'];
-                       $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
-                               <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/new_el.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_getlangsta_createNewTranslationHeaders','1').'" border="0" alt="" />
-                               </a></td>';
                }
 
                $output = '
@@ -318,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;
@@ -345,15 +377,17 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
                        'pages_language_overlay',
                        'pid='.intval($pageId).
                                ' AND sys_language_uid='.intval($langId).
-                               t3lib_BEfunc::deleteClause('pages_language_overlay')
+                               t3lib_BEfunc::deleteClause('pages_language_overlay').
+                               t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay')
                );
 
                $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
+               t3lib_BEfunc::workspaceOL('pages_language_overlay',$row);
                if (is_array($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;
@@ -367,15 +401,14 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
         * @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 : '-';
        }
 }
@@ -384,4 +417,5 @@ class tx_cms_webinfo_lang extends t3lib_extobjbase {
 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