"TYPO3 4.0.1: typo3_src-4.0.1/typo3/sysext/cms/web_info/class.tx_cms_webinfo_lang.php Source File", "datetime" => "Sat Dec 2 19:22:30 2006", "date" => "2 Dec 2006", "doxygenversion" => "1.4.6", "projectname" => "TYPO3 4.0.1", "projectnumber" => "4.0.1" ); get_header($doxygen_vars); ?>

class.tx_cms_webinfo_lang.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (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 ***************************************************************/
00053 require_once(PATH_t3lib.'class.t3lib_pagetree.php');
00054 require_once(PATH_t3lib.'class.t3lib_extobjbase.php');
00055 
00056 
00057 
00058 
00066 class tx_cms_webinfo_lang extends t3lib_extobjbase {
00067 
00073         function modMenu()      {
00074                 global $LANG;
00075 
00076                 $menuArray = array (
00077                         'depth' => array(
00078                                 1 => $LANG->getLL('depth_1'),
00079                                 2 => $LANG->getLL('depth_2'),
00080                                 3 => $LANG->getLL('depth_3')
00081                         ),
00082                         'details' => ''
00083                 );
00084 
00085                         // Languages:
00086                 $lang = $this->getSystemLanguages();
00087                 $menuArray['lang']=array(
00088                         0 => '[All]'
00089                 );
00090                 foreach($lang as $langRec)      {
00091                         $menuArray['lang'][$langRec['uid']] = $langRec['title'];
00092                 }
00093 
00094                 return $menuArray;
00095         }
00096 
00102         function main() {
00103                 global $BACK_PATH,$LANG,$SOBE;
00104 
00105                 if ($this->pObj->id)    {
00106                         $theOutput = '';
00107 
00108                                 // Depth selector:
00109                         $h_func = t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[depth]',$this->pObj->MOD_SETTINGS['depth'],$this->pObj->MOD_MENU['depth'],'index.php');
00110                         $h_func.= t3lib_BEfunc::getFuncMenu($this->pObj->id,'SET[lang]',$this->pObj->MOD_SETTINGS['lang'],$this->pObj->MOD_MENU['lang'],'index.php');
00111                         $h_func.= t3lib_BEfunc::getFuncCheck($this->pObj->id,'SET[details]',$this->pObj->MOD_SETTINGS['details'],'index.php').' Details';
00112                         $theOutput.= $h_func;
00113 
00114                                 // Add CSH:
00115                         $theOutput.= t3lib_BEfunc::cshItem('_MOD_web_info','lang',$GLOBALS['BACK_PATH'],'|<br/>');
00116 
00117                                 // Showing the tree:
00118                                 // Initialize starting point of page tree:
00119                         $treeStartingPoint = intval($this->pObj->id);
00120                         $treeStartingRecord = t3lib_BEfunc::getRecordWSOL('pages', $treeStartingPoint);
00121                         $depth = $this->pObj->MOD_SETTINGS['depth'];
00122 
00123                                 // Initialize tree object:
00124                         $tree = t3lib_div::makeInstance('t3lib_pageTree');
00125                         $tree->init('AND '.$GLOBALS['BE_USER']->getPagePermsClause(1));
00126                         $tree->addField('l18n_cfg');
00127 
00128                                 // Creating top icon; the current page
00129                         $HTML = t3lib_iconWorks::getIconImage('pages', $treeStartingRecord, $GLOBALS['BACK_PATH'],'align="top"');
00130                         $tree->tree[] = array(
00131                                 'row' => $treeStartingRecord,
00132                                 'HTML'=>$HTML
00133                         );
00134 
00135                                 // Create the tree from starting point:
00136                         $tree->getTree($treeStartingPoint, $depth, '');
00137                         #debug($tree->tree);
00138 
00139                                 // Add CSS needed:
00140                         $css_content = '
00141                                 TABLE#langTable {
00142                                         margin-top: 10px;
00143                                 }
00144                                 TABLE#langTable TR TD {
00145                                         padding-left : 2px;
00146                                         padding-right : 2px;
00147                                         white-space: nowrap;
00148                                 }
00149                                 TD.c-blocked { background-color: red; }
00150                                 TD.c-ok { background-color: #669966; }
00151                                 TD.c-fallback {  }
00152                                 TD.c-leftLine {border-left: 2px solid black; }
00153                                 .bgColor5 { font-weight: bold; }
00154                         ';
00155                         $marker = '/*###POSTCSSMARKER###*/';
00156                         $this->pObj->content = str_replace($marker,$css_content.chr(10).$marker,$this->pObj->content);
00157 
00158                                 // Render information table:
00159                         $theOutput.= $this->renderL10nTable($tree);
00160                 }
00161 
00162                 return $theOutput;
00163         }
00164 
00171         function renderL10nTable(&$tree)        {
00172                 global $LANG;
00173 
00174                         // System languages retrieved:
00175                 $languages = $this->getSystemLanguages();
00176 
00177                         // Title length:
00178                 $titleLen = $GLOBALS['BE_USER']->uc['titleLen'];
00179 
00180                         // Put together the TREE:
00181                 $output = '';
00182                 $newOL_js = array();
00183                 $langRecUids = array();
00184                 foreach($tree->tree as $data)   {
00185                         $tCells = array();
00186                         $langRecUids[0][] = $data['row']['uid'];
00187 
00188                                 // Page icons / titles etc.
00189                         $tCells[] = '<td'.($data['row']['_CSSCLASS'] ? ' class="'.$data['row']['_CSSCLASS'].'"' : '').'>'.
00190                                                         $data['HTML'].
00191                                                         htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['title'],$titleLen)).
00192                                                         (strcmp($data['row']['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($data['row']['nav_title'],$titleLen)).'</em>]' : '').
00193                                                         '</td>';
00194 
00195                                 // DEFAULT language:
00196                                 // "View page" link is created:
00197                         $viewPageLink= '<a href="#" onclick="'.
00198                                         htmlspecialchars(t3lib_BEfunc::viewOnClick($data['row']['uid'],$GLOBALS['BACK_PATH'],'','','','&L=###LANG_UID###')).'">'.
00199                                         '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/zoom.gif','width="12" height="12"').' title="'.$LANG->getLL('lang_renderl10n_viewPage','1').'" border="0" alt="" />'.
00200                                         '</a>';
00201                         $status = $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-ok';
00202 
00203                                 // Create links:
00204                         $info = '';
00205                         $editUid = $data['row']['uid'];
00206                         $params = '&edit[pages]['.$editUid.']=edit';
00207                         $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
00208                                         '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editDefaultLanguagePage','1').'" border="0" alt="" />'.
00209                                         '</a>';
00210                         $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]=0"); return false;').'">'.
00211                                         '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit_page.gif','width="12" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPage','1').'" border="0" alt="" />'.
00212                                         '</a>';
00213                         $info.= str_replace('###LANG_UID###','0',$viewPageLink);
00214 
00215                         $info.= '&nbsp;';
00216                         $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;';
00217                         $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;';
00218 
00219                                 // Put into cell:
00220                         $tCells[] = '<td class="'.$status.' c-leftLine">'.$info.'</td>';
00221                         $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],0).'</td>';
00222 
00223                                 // Traverse system languages:
00224                         foreach($languages as $langRow) {
00225                                 if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid'])      {
00226                                         $row = $this->getLangStatus($data['row']['uid'], $langRow['uid']);
00227                                         $info = '';
00228 
00229                                         if (is_array($row))     {
00230                                                 $langRecUids[$langRow['uid']][] = $row['uid'];
00231                                                 $status = $row['_HIDDEN'] ? (t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback') : 'c-ok';
00232                                                 $icon = t3lib_iconWorks::getIconImage(
00233                                                         'pages_language_overlay',
00234                                                         $row,
00235                                                         $GLOBALS['BACK_PATH'],
00236                                                         'align="top" class="c-recIcon"'
00237                                                 );
00238 
00239                                                 $info = $icon.
00240                                                                         htmlspecialchars(t3lib_div::fixed_lgd_cs($row['title'],$titleLen)).
00241                                                                         (strcmp($row['nav_title'],'') ? ' [Nav: <em>'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['nav_title'],$titleLen)).'</em>]' : '').
00242                                                                         ($row['_COUNT']>1 ? '<div>'.$LANG->getLL('lang_renderl10n_badThingThereAre','1').'</div>':'');
00243                                                 $tCells[] = '<td class="'.$status.' c-leftLine">'.
00244                                                                                 $info.
00245                                                                                 ($this->pObj->MOD_SETTINGS['details'] ? $this->getLocalizedElementInfo($data['row']['uid'],$langRow['uid']) : '').
00246                                                                                 '</td>';
00247 
00248                                                         // Edit whole record:
00249                                                 $info = '';
00250                                                 $editUid = $row['uid'];
00251                                                 $params = '&edit[pages_language_overlay]['.$editUid.']=edit';
00252                                                 $info.= '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">'.
00253                                                                 '<img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLanguageOverlayRecord','1').'" border="0" alt="" />'.
00254                                                                 '</a>';
00255 
00256                                                 $info.= '<a href="#" onclick="'.htmlspecialchars('top.loadEditId('.intval($data['row']['uid']).',"&SET[language]='.$langRow['uid'].'"); return false;').'">'.
00257                                                                 '<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="" />'.
00258                                                                 '</a>';
00259                                                 $info.= str_replace('###LANG_UID###',$langRow['uid'],$viewPageLink);
00260 
00261                                                 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
00262                                                 $tCells[] = '<td class="'.$status.'" title="'.$LANG->getLL('lang_renderl10n_CEcount','1').'" align="center">'.$this->getContentElementCount($data['row']['uid'],$langRow['uid']).'</td>';
00263                                         } else {
00264                                                 $status = t3lib_div::hideIfNotTranslated($data['row']['l18n_cfg']) || $data['row']['l18n_cfg']&1 ? 'c-blocked' : 'c-fallback';
00265                                                 $tCells[] = '<td class="'.$status.' c-leftLine">&nbsp;</td>';
00266                                                 $tCells[] = '<td class="'.$status.'">&nbsp;</td>';
00267 
00268                                                 $info = '';
00269                                                 $info.= '<input type="checkbox" name="newOL['.$langRow['uid'].']['.$data['row']['uid'].']" value="1" />';
00270                                                 $newOL_js[$langRow['uid']].= '
00271                                                         +(document.webinfoForm[\'newOL['.$langRow['uid'].']['.$data['row']['uid'].']\'].checked ? \'&edit[pages_language_overlay]['.$data['row']['uid'].']=new\' : \'\')
00272                                                 ';
00273                                                 $tCells[] = '<td class="'.$status.'">'.$info.'</td>';
00274                                         }
00275                                 }
00276                         }
00277 
00278                         $output.= '
00279                                 <tr class="bgColor4">
00280                                         '.implode('
00281                                         ',$tCells).'
00282                                 </tr>';
00283                 }
00284 
00285                         // Put together HEADER:
00286                 $tCells = array();
00287                 $tCells[] = '<td>'.$LANG->getLL('lang_renderl10n_page','1').':</td>';
00288 
00289                 if (is_array($langRecUids[0]))  {
00290                         $params = '&edit[pages]['.implode(',',$langRecUids[0]).']=edit&columnsOnly=title,nav_title,l18n_cfg,hidden';
00291                         $editIco = '<a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
00292                                 <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editPageProperties','1').'" border="0" alt="" />
00293                                 </a>';
00294                 } else $editIco = '';
00295                 $tCells[] = '<td class="c-leftLine" colspan="2">'.
00296                                         $LANG->getLL('lang_renderl10n_default','1').':'.
00297                                         $editIco.
00298                                         '</td>';
00299 
00300                 foreach($languages as $langRow) {
00301                         if ($this->pObj->MOD_SETTINGS['lang']==0 || (int)$this->pObj->MOD_SETTINGS['lang']===(int)$langRow['uid'])      {
00302                                         // Title:
00303                                 $tCells[] = '<td class="c-leftLine">'.htmlspecialchars($langRow['title']).'</td>';
00304 
00305                                         // Edit language overlay records:
00306                                 if (is_array($langRecUids[$langRow['uid']]))    {
00307                                         $params = '&edit[pages_language_overlay]['.implode(',',$langRecUids[$langRow['uid']]).']=edit&columnsOnly=title,nav_title,hidden';
00308                                         $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
00309                                                 <img'.t3lib_iconWorks::skinImg($GLOBALS['BACK_PATH'],'gfx/edit2.gif','width="11" height="12"').' title="'.$LANG->getLL('lang_renderl10n_editLangOverlays','1').'" border="0" alt="" />
00310                                                 </a></td>';
00311                                 } else {
00312                                         $tCells[] = '<td>&nbsp;</td>';
00313                                 }
00314 
00315                                         // Create new overlay records:
00316                                 $params = "'".$newOL_js[$langRow['uid']]."+'&columnsOnly=title,hidden,sys_language_uid&defVals[pages_language_overlay][sys_language_uid]=".$langRow['uid'];
00317                                 $tCells[] = '<td><a href="#" onclick="'.htmlspecialchars(t3lib_BEfunc::editOnClick($params,$GLOBALS['BACK_PATH'])).'">
00318                                         <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="" />
00319                                         </a></td>';
00320                         }
00321                 }
00322 
00323                 $output = '
00324                         <tr class="bgColor5">
00325                                 '.implode('
00326                                 ',$tCells).'
00327                         </tr>'.$output;
00328 
00329                 $output = '
00330 
00331                 <table border="0" cellspacing="0" cellpadding="0" id="langTable">'.$output.'
00332                 </table>';
00333 
00334                 return $output;
00335         }
00336 
00342         function getSystemLanguages()   {
00343                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00344                         '*',
00345                         'sys_language',
00346                         '1'.t3lib_BEfunc::deleteClause('sys_language')
00347                 );
00348 
00349                 $outputArray = array();
00350                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00351                         $outputArray[] = $row;
00352                 }
00353 
00354                 return $outputArray;
00355         }
00356 
00364         function getLangStatus($pageId, $langId)        {
00365                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00366                         '*',
00367                         'pages_language_overlay',
00368                         'pid='.intval($pageId).
00369                                 ' AND sys_language_uid='.intval($langId).
00370                                 t3lib_BEfunc::deleteClause('pages_language_overlay').
00371                                 t3lib_BEfunc::versioningPlaceholderClause('pages_language_overlay')
00372                 );
00373 
00374                 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
00375                 if (is_array($row))     {
00376                         t3lib_BEfunc::workspaceOL('pages_language_overlay',$row);
00377                         $row['_COUNT'] = $GLOBALS['TYPO3_DB']->sql_num_rows($res);
00378                         $row['_HIDDEN'] = $row['hidden'] ||
00379                                                         (intval($row['endtime']) > 0 && intval($row['endtime']) < time()) ||
00380                                                         (time() < intval($row['starttime']));
00381                 }
00382 
00383                 return $row;
00384         }
00385 
00393         function getLocalizedElementInfo($pageId,$sysLang)      {
00394                 global $TCA;
00395 
00396                 $info = '<hr/>';
00397                 foreach($TCA as $table => $cfg) {
00398                         if ($table!='pages' && $TCA[$table]['ctrl']['languageField'] && $TCA[$table]['ctrl']['transOrigPointerField'])  {
00399 #                       $info.='<h3>'.$table.'</h3>';
00400                                 if ($TCA[$table]['ctrl']['transOrigPointerTable'])      {
00401                                         #$info.='Table "'.$table.'" is skipped because it had a transOrigPointerTable set which is not supported - yet.';
00402                                 } else {
00403 
00404                                                 // First, select all records that are default language OR international:
00405                                         $allRows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00406                                                 '*',
00407                                                 $table,
00408                                                 'pid='.intval($pageId).
00409                                                         ' AND '.$TCA[$table]['ctrl']['languageField'].'<=0'.
00410                                                         t3lib_BEfunc::deleteClause($table).
00411                                                         t3lib_BEfunc::versioningPlaceholderClause($table)
00412                                         );
00413                                         if (count($allRows))    {
00414                         $info.='<h3>'.$table.'</h3>';
00415 
00416 $info.='[<b>'.$TCA[$table]['ctrl']['languageField'].'</b>]';
00417 $info.='[<b>'.$TCA[$table]['ctrl']['transOrigPointerField'].'</b>]';
00418 $info.='[<b>'.$TCA[$table]['ctrl']['transOrigDiffSourceField'].'</b>]';
00419 
00420                                                         // Now, for each record, look for localization:
00421                                                 $translationsUids = array(0);
00422                                                 foreach($allRows as $row)       {
00423                                                         $info.='UID:'.$row['uid'].'/lang:'.$row[$TCA[$table]['ctrl']['languageField']].' has translations:';
00424                                                         $translations = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00425                                                                 '*',
00426                                                                 $table,
00427                                                                 'pid='.intval($pageId).
00428                                                                         ' AND '.$TCA[$table]['ctrl']['languageField'].'='.intval($sysLang).
00429                                                                         ' AND '.$TCA[$table]['ctrl']['transOrigPointerField'].'='.intval($row['uid']).
00430                                                                         t3lib_BEfunc::deleteClause($table).
00431                                                                         t3lib_BEfunc::versioningPlaceholderClause($table)
00432                                                         );
00433 
00434                                                         foreach($translations as $c => $tr)     {
00435                                                                 $info.=($c>0 ? 'UPS!!':'').'['.$tr['uid'].'],';
00436                                                                 $translationsUids[] = $tr['uid'];
00437                                                         }
00438 
00439 
00440 
00441                                                         $info.='<br/>';
00442                                                 }
00443 
00444                                                         // Look for "lost" translations
00445                                                 $lostTranslations = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows(
00446                                                         'uid',
00447                                                         $table,
00448                                                         'pid='.intval($pageId).
00449                                                                 ' AND '.$TCA[$table]['ctrl']['languageField'].'='.intval($sysLang).
00450                                                                 ' AND uid NOT IN ('.implode(',',$translationsUids).')'.
00451                                                                 t3lib_BEfunc::deleteClause($table).
00452                                                                 t3lib_BEfunc::versioningPlaceholderClause($table)
00453                                                 );
00454                                                 if (count($lostTranslations))   {
00455                                                         $info.=t3lib_div::view_array($lostTranslations);
00456                                                 }
00457                                         }
00458                                 }
00459                         }
00460                 }
00461                 return $info;
00462         }
00463 
00471         function getContentElementCount($pageId,$sysLang)       {
00472                 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00473                         'count(*)',
00474                         'tt_content',
00475                         'pid='.intval($pageId).
00476                                 ' AND sys_language_uid='.intval($sysLang).
00477                                 t3lib_BEfunc::deleteClause('tt_content').
00478                                 t3lib_BEfunc::versioningPlaceholderClause('tt_content')
00479                 );
00480 
00481                 list($count) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
00482                 return $count ? $count : '-';
00483         }
00484 }
00485 
00486 
00487 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php'])  {
00488         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/cms/web_info/class.tx_cms_webinfo_lang.php']);
00489 }
00490 ?>