|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2011 Kasper Skårhøj (kasperYYYY@typo3.com) 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * A copy is found in the textfile GPL.txt and important notices to the license 00017 * from the author is found in LICENSE.txt distributed with these scripts. 00018 * 00019 * 00020 * This script is distributed in the hope that it will be useful, 00021 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00023 * GNU General Public License for more details. 00024 * 00025 * This copyright notice MUST APPEAR in all copies of the script! 00026 ***************************************************************/ 00027 /** 00028 * Contains a class with functions for page related overview of translations. 00029 * 00030 * $Id: class.tx_cms_webinfo_lang.php 10120 2011-01-18 20:03:36Z ohader $ 00031 * 00032 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00033 */ 00034 /** 00035 * [CLASS/FUNCTION INDEX of SCRIPT] 00036 * 00037 * 00038 * 00039 * 66: class tx_cms_webinfo_lang extends t3lib_extobjbase 00040 * 73: function modMenu() 00041 * 102: function main() 00042 * 171: function renderL10nTable(&$tree) 00043 * 342: function getSystemLanguages() 00044 * 364: function getLangStatus($pageId, $langId) 00045 * 393: function getLocalizedElementInfo($pageId,$sysLang) 00046 * 471: function getContentElementCount($pageId,$sysLang) 00047 * 00048 * TOTAL FUNCTIONS: 7 00049 * (This index is automatically created/updated by the extension "extdeveval") 00050 * 00051 */ 00052 /** 00053 * Class for displaying translation status of pages in the tree. 00054 * 00055 * @author Kasper Skårhøj <kasperYYYY@typo3.com> 00056 * @package TYPO3 00057 * @subpackage tx_cms 00058 */ 00059 class tx_cms_webinfo_lang extends t3lib_extobjbase { 00060 00061 /** 00062 * Returns the menu array 00063 * 00064 * @return array 00065 */ 00066 function modMenu() { 00067 global $LANG; 00068 00069 $menuArray = array ( 00070 'depth' => array( 00071 0 => $LANG->getLL('depth_0'), 00072 1 => $LANG->getLL('depth_1'), 00073 2 => $LANG->getLL('depth_2'), 00074 3 => $LANG->getLL('depth_3'), 00075 999 => $LANG->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_infi'), 00076 ), 00077 ); 00078 00079 // Languages: 00080 $lang = $this->getSystemLanguages(); 00081 $menuArray['lang']=array( 00082 0 => '[All]' 00083 ); 00084 foreach($lang as $langRec) { 00085 $menuArray['lang'][$langRec['uid']] = $langRec['title']; 00086 } 00087 00088 return $menuArray; 00089 } 00090 00091 /** 00092 * MAIN function for page information of localization 00093 * 00094 * @return string Output HTML for the module. 00095 */ 00096 function main() { 00097 global $BACK_PATH,$LANG,$SOBE; 00098 00099 if ($this->pObj->id) { 00100 $theOutput = ''; 00101 00102 // Depth selector: 00103 $h_func = t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[depth]',$this->pObj->MOD_SETTINGS['depth'],$this->pObj->MOD_MENU['depth'],'index.php'); 00104 $h_func.= t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[lang]',$this->pObj->MOD_SETTINGS['lang'],$this->pObj->MOD_MENU['lang'],'index.php'); 00105 $theOutput.= $h_func; 00106 00107 // Add CSH: 00108 $theOutput .= t3lib_BEfunc::cshItem('_MOD_web_info', 'lang', $GLOBALS['BACK_PATH'], '|<br />'); 00109 00110 // Showing the tree: 00111 // Initialize starting point of page tree: 00112 $treeStartingPoint = intval($this->pObj->id); 00113 $treeStartingRecord = t3lib_BEfunc::getRecordWSOL('pages', $treeStartingPoint); 00114 $depth = $this->pObj->MOD_SETTINGS['depth']; 00115 00116 // Initialize tree object: 00117 $tree = t3lib_div::makeInstance('t3lib_pageTree'); 00118 $tree->init('AND '.$GLOBALS['BE_USER']->getPagePermsClause(1)); 00119 $tree->addField('l18n_cfg'); 00120 00121 // Creating top icon; the current page 00122 $HTML = t3lib_iconWorks::getSpriteIconForRecord('pages', $treeStartingRecord); 00123 $tree->tree[] = array( 00124 'row' => $treeStartingRecord, 00125 'HTML'=>$HTML 00126 ); 00127 00128 // Create the tree from starting point: 00129 if ($depth) $tree->getTree($treeStartingPoint, $depth, ''); 00130 00131 // Render information table: 00132 $theOutput.= $this->renderL10nTable($tree); 00133 } 00134 00135 return $theOutput; 00136 } 00137 00138 /** 00139 * Rendering the localization information table. 00140 * 00141 * @param array The Page tree data 00142 * @return string HTML for the localization information table. 00143 */ 00144 function renderL10nTable(&$tree) { 00145 global $LANG; 00146 00147 // System languages retrieved: 00148 $languages = $this->getSystemLanguages(); 00149 00150 // Title length: 00151 $titleLen = $GLOBALS['BE_USER']->uc['titleLen']; 00152 00153 // Put together the TREE: 00154 $output = ''; 00155 $newOL_js = array(); 00156 $langRecUids = array(); 00157 foreach($tree->tree as $data) { 00158 $tCells = array(); 00159 $langRecUids[0][] = $data['row']['uid']; 00160 00161 // Page icons / titles etc. 00162 $tCells[] = '<td'.($data['row']['_CSSCLASS'] ? ' class="'.$data['row']['_CSSCLASS'].'"' : '').'>'. 00163 $data['HTML']. 00164 htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['title'],$titleLen)). 00165 (strcmp($data['row']['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['nav_title'],$titleLen)).'</em>]' : ''). 00166 '</td>'; 00167 00168 // DEFAULT language: 00169 // "View page" link is created: 00170 $viewPageLink= '<a href="#" onclick="'. 00171 htmlspecialchars(t3lib_BEfunc::viewOnClick($data['row']['uid'],$GLOBALS['BACK_PATH'],'','','','&L=###LANG_UID###')).'" title="' . $LANG->getLL('lang_renderl10n_viewPage', TRUE) . '">' . 00172 t3lib_iconWorks::getSpriteIcon('actions-document-view') . 00173 '</a>'; 00174 $status = $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-ok'; 00175 00176 // Create links: 00177 $info = ''; 00178 $editUid = $data['row']['uid']; 00179 $params = '&edit[pages]['.$editUid.']=edit'; 00180 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'" title="' . $LANG->getLL('lang_renderl10n_editDefaultLanguagePage', TRUE) . '">'. 00181 t3lib_iconWorks::getSpriteIcon('actions-document-open') . 00182 '</a>'; 00183 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]=0"); return false;').'" title="' . $LANG->getLL('lang_renderl10n_editPage', TRUE) . '">' . 00184 t3lib_iconWorks::getSpriteIcon('actions-page-open') . 00185 '</a>'; 00186 $info.= str_replace('###LANG_UID###','0',$viewPageLink); 00187 00188 $info.= ' '; 00189 $info.= $data['row']['l18n_cfg']&1 ? '<span title="'.$LANG->sL('LLL:EXT:cms/locallang_tca.php:pages.l18n_cfg.I.1','1').'">D</span>' : ' '; 00190 $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>' : ' '; 00191 00192 // Put into cell: 00193 $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>'; 00194 $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],0).'</td>'; 00195 00196 $modSharedTSconfig = t3lib_BEfunc::getModTSconfig($data['row']['uid'], 'mod.SHARED'); 00197 $disableLanguages = isset($modSharedTSconfig['properties']['disableLanguages']) ? t3lib_div::trimExplode(',', $modSharedTSconfig['properties']['disableLanguages'], 1) : array(); 00198 00199 // Traverse system languages: 00200 foreach($languages as $langRow) { 00201 if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid']) { 00202 $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']); 00203 $info = ''; 00204 00205 if (is_array($row)) { 00206 $langRecUids[$langRow['uid']][] = $row['uid']; 00207 $status = $row['_HIDDEN'] ? (t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback') : 'c-ok'; 00208 $icon = t3lib_iconWorks::getSpriteIconForRecord( 00209 'pages_language_overlay', 00210 $row, 00211 array('class' => 'c-recIcon') 00212 ); 00213 00214 $info = $icon. 00215 htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'],$titleLen)). 00216 (strcmp($row['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['nav_title'],$titleLen)).'</em>]' : ''). 00217 ($row['_COUNT']>1 ? '<div>'.$LANG->getLL('lang_renderl10n_badThingThereAre','1').'</div>':''); 00218 $tCells[] = '<td class="'.$status.' c-leftLine">'. 00219 $info. 00220 '</td>'; 00221 00222 // Edit whole record: 00223 $info = ''; 00224 $editUid = $row['uid']; 00225 $params = '&edit[pages_language_overlay]['.$editUid.']=edit'; 00226 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'" title="' . $LANG->getLL('lang_renderl10n_editLanguageOverlayRecord', TRUE) . '">' . 00227 t3lib_iconWorks::getSpriteIcon('actions-document-open') . 00228 '</a>'; 00229 00230 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]='.$langRow['uid'].'"); return false;').'" title="' . $LANG->getLL('lang_renderl10n_editPageLang', TRUE) . '">' . 00231 t3lib_iconWorks::getSpriteIcon('actions-page-open') . 00232 '</a>'; 00233 $info.= str_replace('###LANG_UID###',$langRow['uid'],$viewPageLink); 00234 00235 $tCells[] = '<td class="'.$status.'">'.$info.'</td>'; 00236 $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],$langRow['uid']).'</td>'; 00237 } else { 00238 if (in_array($langRow['uid'], $disableLanguages)) { 00239 // Language has been disabled for this page 00240 $status = 'c-blocked'; 00241 $info = ''; 00242 } else { 00243 $status = t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback'; 00244 $info = '<input type="checkbox" name="newOL['.$langRow['uid'].']['.$data['row']['uid'].']" value="1" />'; 00245 $newOL_js[$langRow['uid']].= ' 00246 +(document.webinfoForm[\'newOL['.$langRow['uid'].']['.$data['row']['uid'].']\'].checked ? \'&edit[pages_language_overlay]['.$data['row']['uid'].']=new\' : \'\') 00247 '; 00248 } 00249 00250 $tCells[] = '<td class="'.$status.' c-leftLine"> </td>'; 00251 $tCells[] = '<td class="'.$status.'"> </td>'; 00252 $tCells[] = '<td class="'.$status.'">'.$info.'</td>'; 00253 } 00254 } 00255 } 00256 00257 $output.= ' 00258 <tr class="bgColor4"> 00259 '.implode(' 00260 ',$tCells).' 00261 </tr>'; 00262 } 00263 00264 // Put together HEADER: 00265 $tCells = array(); 00266 $tCells[] = '<td>'.$LANG->getLL('lang_renderl10n_page','1').':</td>'; 00267 00268 if (is_array($langRecUids[0])) { 00269 $params = '&edit[pages]['.implode(',',$langRecUids[0]).']=edit&columnsOnly=title,nav_title,l18n_cfg,hidden'; 00270 $editIco = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'" title="' . $LANG->getLL('lang_renderl10n_editPageProperties', TRUE) . '">' . 00271 t3lib_iconWorks::getSpriteIcon('actions-document-new') . 00272 '</a>'; 00273 } else $editIco = ''; 00274 $tCells[] = '<td class="c-leftLine" colspan="2">'. 00275 $LANG->getLL('lang_renderl10n_default','1').':'. 00276 $editIco. 00277 '</td>'; 00278 00279 foreach($languages as $langRow) { 00280 if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid']) { 00281 // Title: 00282 $tCells[] = '<td class="c-leftLine">'.htmlspecialchars($langRow['title']).'</td>'; 00283 00284 // Edit language overlay records: 00285 if (is_array($langRecUids[$langRow['uid']])) { 00286 $params = '&edit[pages_language_overlay]['.implode(',',$langRecUids[$langRow['uid']]).']=edit&columnsOnly=title,nav_title,hidden'; 00287 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'" title="' . $LANG->getLL('lang_renderl10n_editLangOverlays', TRUE) . '">' . 00288 t3lib_iconWorks::getSpriteIcon('actions-document-open') . 00289 '</a></td>'; 00290 } else { 00291 $tCells[] = '<td> </td>'; 00292 } 00293 00294 // Create new overlay records: 00295 $params = "'".$newOL_js[$langRow['uid']]."+'&columnsOnly=title,hidden,sys_language_uid&defVals[pages_language_overlay][sys_language_uid]=".$langRow['uid']; 00296 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'" title="' . $LANG->getLL('lang_getlangsta_createNewTranslationHeaders', TRUE) . '">' . 00297 t3lib_iconWorks::getSpriteIcon('actions-document-new') . 00298 '</a></td>'; 00299 } 00300 } 00301 00302 $output = ' 00303 <tr class="t3-row-header"> 00304 '.implode(' 00305 ',$tCells).' 00306 </tr>'.$output; 00307 00308 $output = ' 00309 00310 <table border="0" cellspacing="0" cellpadding="0" id="langTable" class="typo3-dblist">' . $output . ' 00311 </table>'; 00312 00313 return $output; 00314 } 00315 00316 /** 00317 * Selects all system languages (from sys_language) 00318 * 00319 * @return array System language records in an array. 00320 */ 00321 function getSystemLanguages() { 00322 if (!$GLOBALS['BE_USER']->user['admin'] && 00323 strlen($GLOBALS['BE_USER']->groupData['allowed_languages'])) { 00324 00325 $allowed_languages = array_flip(explode(',', $GLOBALS['BE_USER']->groupData['allowed_languages'])); 00326 } 00327 00328 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00329 '*', 00330 'sys_language', 00331 '1=1'.t3lib_BEfunc::deleteClause('sys_language') 00332 ); 00333 00334 $outputArray = array(); 00335 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { 00336 if (is_array($allowed_languages) && count($allowed_languages)) { 00337 if (isset($allowed_languages[$row['uid']])) { 00338 $outputArray[] = $row; 00339 } 00340 } 00341 else { 00342 $outputArray[] = $row; 00343 } 00344 } 00345 00346 return $outputArray; 00347 } 00348 00349 /** 00350 * Get an alternative language record for a specific page / language 00351 * 00352 * @param integer Page ID to look up for. 00353 * @param integer Language UID to select for. 00354 * @return array pages_languages_overlay record 00355 */ 00356 function getLangStatus($pageId, $langId) { 00357 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery( 00358 '*', 00359 'pages_language_overlay', 00360 'pid='.intval($pageId). 00361 ' AND sys_language_uid='.intval($langId). 00362 t3lib_BEfunc::deleteClause('pages_language_overlay'). 00363 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay') 00364 ); 00365 00366 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res); 00367 t3lib_BEfunc::workspaceOL('pages_language_overlay',$row); 00368 if (is_array($row)) { 00369 $row['_COUNT'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res); 00370 $row['_HIDDEN'] = $row['hidden'] || 00371 (intval($row['endtime']) > 0 && intval($row['endtime']) < $GLOBALS['EXEC_TIME']) || 00372 ($GLOBALS['EXEC_TIME'] < intval($row['starttime'])); 00373 } 00374 00375 return $row; 00376 } 00377 00378 /** 00379 * Counting content elements for a single language on a page. 00380 * 00381 * @param integer Page id to select for. 00382 * @param integer Sys language uid 00383 * @return integer Number of content elements from the PID where the language is set to a certain value. 00384 */ 00385 function getContentElementCount($pageId,$sysLang) { 00386 $count = $GLOBALS['TYPO3_DB']->exec_SELECTcountRows( 00387 'uid', 00388 'tt_content', 00389 'pid=' . intval($pageId) . 00390 ' AND sys_language_uid=' . intval($sysLang) . 00391 t3lib_BEfunc::deleteClause('tt_content') . 00392 t3lib_BEfunc::versioningPlaceholderClause('tt_content') 00393 ); 00394 return $count ? $count : '-'; 00395 } 00396 } 00397 00398 00399 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php'])) { 00400 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']); 00401 } 00402 00403 ?>
1.8.0