Documentation TYPO3 par Ameos |
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 1999-2004 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 ***************************************************************/ 00068 require('init.php'); 00069 require('template.php'); 00070 $LANG->includeLLFile('EXT:lang/locallang_view_help.xml'); 00071 require_once(PATH_t3lib.'class.t3lib_loadmodules.php'); 00072 00073 00074 00075 00076 00077 00078 00079 00080 00088 class SC_view_help { 00089 var $allowedHTML = '<strong><em><b><i>'; 00090 00091 // For these vars, see init() 00092 var $limitAccess; // If set access to fields and tables is checked. Should be done for true database tables. 00093 var $table; // The "table" key 00094 var $field; // The "field" key 00095 00096 // Internal, static: GPvar: 00097 var $tfID; // Table/FIeld id. 00098 var $back; // Back (previous tfID) 00099 var $renderALL; // If set, then in TOC mode the FULL manual will be printed as well! 00100 00101 // Internal, dynamic: 00102 var $content; // Content accumulation. 00103 00104 00105 00111 function init() { 00112 global $LANG, $TCA; 00113 00114 // Setting GPvars: 00115 $this->tfID = t3lib_div::_GP('tfID'); 00116 $this->back = t3lib_div::_GP('back'); 00117 $this->renderALL = t3lib_div::_GP('renderALL'); 00118 00119 // Set internal table/field to the parts of "tfID" incoming var. 00120 list($this->table,$this->field) = explode('.',$this->tfID); 00121 00122 // limitAccess is checked if the $this->table really IS a table. 00123 $this->limitAccess = isset($TCA[$this->table]) ? TRUE : FALSE; 00124 } 00125 00131 function main() { 00132 global $BE_USER,$LANG,$TCA_DESCR,$TCA,$TBE_TEMPLATE; 00133 00134 // Start HTML output accumulation: 00135 $TBE_TEMPLATE->docType = 'xhtml_trans'; 00136 $TBE_TEMPLATE->divClass = 'typo3-view-help'; 00137 $this->content.= $TBE_TEMPLATE->startPage($LANG->getLL('title')); 00138 00139 if ($this->field=='*') { // If ALL fields is supposed to be shown: 00140 $this->content.= $this->render_Table($this->table); 00141 } elseif ($this->tfID) { // ... otherwise show only single field: 00142 $this->content.= $this->render_Single($this->table,$this->field); 00143 } else { // Render Table Of Contents if nothing else: 00144 $this->content.= $this->render_TOC(); 00145 } 00146 00147 // Print close-button: 00148 # $this->content.='<br /><form action=""><input type="submit" value="'.htmlspecialchars($LANG->getLL('close')).'" onclick="self.close(); return false;" /></form><br/>'; 00149 00150 // End page: 00151 $this->content.= '<br/>'; 00152 $this->content.= $TBE_TEMPLATE->endPage(); 00153 } 00154 00160 function printContent() { 00161 echo $this->content; 00162 } 00163 00164 00165 00166 00167 00168 00169 00170 00171 00172 /************************************ 00173 * 00174 * Rendering main modes 00175 * 00176 ************************************/ 00177 00183 function render_TOC() { 00184 global $TCA_DESCR,$TCA,$LANG,$BE_USER,$TBE_MODULES; 00185 00186 // Initialize: 00187 $CSHkeys = array_flip(array_keys($TCA_DESCR)); 00188 $TCAkeys = array_keys($TCA); 00189 00190 $outputSections = array(); 00191 $tocArray = array(); 00192 00193 00194 // TYPO3 Core Features: 00195 $LANG->loadSingleTableDescription('xMOD_csh_corebe'); 00196 $this->render_TOC_el('xMOD_csh_corebe', 'core', $outputSections, $tocArray, $CSHkeys); 00197 00198 // Backend Modules: 00199 $loadModules = t3lib_div::makeInstance('t3lib_loadModules'); 00200 $loadModules->load($TBE_MODULES); 00201 foreach($loadModules->modules as $mainMod => $info) { 00202 $cshKey = '_MOD_'.$mainMod; 00203 if ($CSHkeys[$cshKey]) { 00204 $LANG->loadSingleTableDescription($cshKey); 00205 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys); 00206 } 00207 00208 if (is_array($info['sub'])) { 00209 foreach($info['sub'] as $subMod => $subInfo) { 00210 $cshKey = '_MOD_'.$mainMod.'_'.$subMod; 00211 if ($CSHkeys[$cshKey]) { 00212 $LANG->loadSingleTableDescription($cshKey); 00213 $this->render_TOC_el($cshKey, 'modules', $outputSections, $tocArray, $CSHkeys); 00214 } 00215 } 00216 } 00217 } 00218 00219 // Database Tables: 00220 foreach($TCAkeys as $table) { 00221 // Load descriptions for table $table 00222 $LANG->loadSingleTableDescription($table); 00223 if (is_array($TCA_DESCR[$table]['columns']) && $BE_USER->check('tables_select',$table)) { 00224 $this->render_TOC_el($table, 'tables', $outputSections, $tocArray, $CSHkeys); 00225 } 00226 } 00227 00228 // Extensions 00229 foreach($CSHkeys as $cshKey => $value) { 00230 if (t3lib_div::isFirstPartOfStr($cshKey, 'xEXT_') && !isset($TCA[$cshKey])) { 00231 $LANG->loadSingleTableDescription($cshKey); 00232 $this->render_TOC_el($cshKey, 'extensions', $outputSections, $tocArray, $CSHkeys); 00233 } 00234 } 00235 00236 // Other: 00237 foreach($CSHkeys as $cshKey => $value) { 00238 if (!t3lib_div::isFirstPartOfStr($cshKey, '_MOD_') && !isset($TCA[$cshKey])) { 00239 $LANG->loadSingleTableDescription($cshKey); 00240 $this->render_TOC_el($cshKey, 'other', $outputSections, $tocArray, $CSHkeys); 00241 } 00242 } 00243 00244 00245 // COMPILE output: 00246 $output = ''; 00247 $output.= ' 00248 00249 <h1>'.$LANG->getLL('manual_title',1).'</h1> 00250 <p>'.t3lib_BEfunc::TYPO3_copyRightNotice().'</p>'; 00251 00252 $output.= ' 00253 00254 <h1>'.$LANG->getLL('introduction',1).'</h1> 00255 <p>'.$LANG->getLL('description',1).'</p>'; 00256 00257 $output.= ' 00258 00259 <h1>'.$LANG->getLL('TOC',1).'</h1>'. 00260 $this->render_TOC_makeTocList($tocArray); 00261 00262 if (!$this->renderALL) { 00263 $output.= ' 00264 <br/> 00265 <p class="c-nav"><a href="view_help.php?renderALL=1">'.$LANG->getLL('full_manual',1).'</a></p>'; 00266 } 00267 00268 if ($this->renderALL) { 00269 $output.= ' 00270 00271 <h1>'.$LANG->getLL('full_manual_chapters',1).'</h1>'. 00272 implode(' 00273 00274 00275 <!-- NEW SECTION: --> 00276 ',$outputSections); 00277 } 00278 00279 return $output; 00280 } 00281 00292 function render_TOC_el($table, $tocCat, &$outputSections, &$tocArray, &$CSHkeys) { 00293 global $LANG; 00294 00295 if ($this->renderALL) { // Render full manual right here! 00296 $outputSections[$table] = $this->render_Table($table); 00297 00298 if ($outputSections[$table]) { 00299 $outputSections[$table] = ' 00300 00301 <!-- New CSHkey/Table: '.$table.' --> 00302 <p class="c-nav"><a name="ANCHOR_'.$table.'" href="#">'.$LANG->getLL('to_top',1).'</a></p> 00303 <h2>'.$this->getTableFieldLabel($table).'</h2> 00304 00305 '.$outputSections[$table]; 00306 $tocArray[$tocCat][$table] = '<a href="#ANCHOR_'.$table.'">'.$this->getTableFieldLabel($table).'</a>'; 00307 } else { 00308 unset($outputSections[$table]); 00309 } 00310 } else { // Only TOC: 00311 $tocArray[$tocCat][$table] = '<p><a href="view_help.php?tfID='.rawurlencode($table.'.*').'">'.$this->getTableFieldLabel($table).'</a></p>'; 00312 } 00313 00314 // Unset CSH key: 00315 unset($CSHkeys[$table]); 00316 } 00317 00324 function render_TOC_makeTocList($tocArray) { 00325 global $LANG; 00326 00327 // The Various manual sections: 00328 $keys = explode(',', 'core,modules,tables,extensions,other'); 00329 00330 // Create TOC bullet list: 00331 $output = ''; 00332 foreach($keys as $tocKey) { 00333 if (is_array($tocArray[$tocKey])) { 00334 $output.=' 00335 <li>'.$LANG->getLL('TOC_'.$tocKey,1).' 00336 <ul> 00337 <li>'.implode('</li> 00338 <li>',$tocArray[$tocKey]).'</li> 00339 </ul> 00340 </li>'; 00341 } 00342 } 00343 00344 // Compile TOC: 00345 $output = ' 00346 00347 <!-- TOC: --> 00348 <div class="c-toc"> 00349 <ul> 00350 '.$output.' 00351 </ul> 00352 </div>'; 00353 00354 return $output; 00355 } 00356 00363 function render_Table($table) { 00364 global $BE_USER,$TCA_DESCR,$TCA,$LANG; 00365 00366 $output = ''; 00367 00368 // Load table TCA 00369 t3lib_div::loadTCA($table); 00370 00371 // Load descriptions for table $table 00372 $LANG->loadSingleTableDescription($table); 00373 00374 if (is_array($TCA_DESCR[$table]['columns']) && (!$this->limitAccess || $BE_USER->check('tables_select',$table))) { 00375 // Initialize variables: 00376 $parts = array(); 00377 $parts[0] = ''; // Reserved for header of table 00378 00379 // Traverse table columns as listed in TCA_DESCR 00380 reset($TCA_DESCR[$table]['columns']); 00381 while(list($field) = each($TCA_DESCR[$table]['columns'])) { 00382 00383 $fieldValue = isset($TCA[$table]) && strcmp($field,'') ? $TCA[$table]['columns'][$field] : array(); 00384 00385 if (is_array($fieldValue) && (!$this->limitAccess || !$fieldValue['exclude'] || $BE_USER->check('non_exclude_fields',$table.':'.$field))) { 00386 if (!$field) { 00387 $parts[0] = $this->printItem($table,'',1); // Header 00388 } else { 00389 $parts[] = $this->printItem($table,$field,1); // Field 00390 } 00391 } 00392 } 00393 00394 if (!strcmp($parts,'')) unset($parts[0]); 00395 $output.= implode('<br />',$parts); 00396 } 00397 00398 // TOC link: 00399 if (!$this->renderALL) { 00400 $tocLink = '<p class="c-nav"><a href="view_help.php">'.$LANG->getLL('goToToc',1).'</a></p>'; 00401 00402 $output = 00403 $tocLink.' 00404 <br/>'. 00405 $output.' 00406 <br />'. 00407 $tocLink; 00408 } 00409 00410 return $output; 00411 } 00412 00420 function render_Single($table,$field) { 00421 global $LANG, $TCA; 00422 00423 $output = ''; 00424 00425 // Load descriptions for table $table 00426 $LANG->loadSingleTableDescription($table); 00427 00428 // Render single item: 00429 $output.= $this->printItem($table,$field); 00430 00431 // Link to Full table description and TOC: 00432 $getLLKey = $this->limitAccess ? 'fullDescription' : 'fullDescription_module'; 00433 $output.= '<br /> 00434 <p class="c-nav"><a href="view_help.php?tfID='.rawurlencode($table.'.*').'">'.$LANG->getLL($getLLKey,1).'</a></p> 00435 <p class="c-nav"><a href="view_help.php">'.$LANG->getLL('goToToc',1).'</a></p>'; 00436 00437 return $output; 00438 } 00439 00440 00441 00442 00443 00444 00445 00446 00447 00448 00449 00450 /************************************ 00451 * 00452 * Rendering CSH items 00453 * 00454 ************************************/ 00455 00463 function make_seeAlso($value,$anchorTable='') { 00464 global $TCA,$BE_USER,$TCA_DESCR; 00465 00466 // Split references by comma, vert.line or linebreak 00467 $items = split(',|'.chr(10),$value); 00468 $lines = array(); 00469 00470 foreach($items as $val) { 00471 $val = trim($val); 00472 if ($val) { 00473 $iP = explode(':',$val); 00474 $iPUrl = t3lib_div::trimExplode('|',$val); 00475 // URL reference: 00476 if (substr($iPUrl[1],0,4)=='http') { 00477 $lines[] = '<a href="'.htmlspecialchars($iPUrl[1]).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>'; 00478 } elseif (substr($iPUrl[1],0,5)=='FILE:') { 00479 $fileName = t3lib_div::getFileAbsFileName(substr($iPUrl[1],5),1,1); 00480 if ($fileName && @is_file($fileName)) { 00481 $fileName = '../'.substr($fileName,strlen(PATH_site)); 00482 $lines[] = '<a href="'.htmlspecialchars($fileName).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>'; 00483 } 00484 } else { 00485 // "table" reference 00486 t3lib_div::loadTCA($iP[0]); 00487 00488 if (!isset($TCA[$iP[0]]) || ((!$iP[1] || is_array($TCA[$iP[0]]['columns'][$iP[1]])) && (!$this->limitAccess || ($BE_USER->check('tables_select',$iP[0]) && (!$iP[1] || !$TCA[$iP[0]]['columns'][$iP[1]]['exclude'] || $BE_USER->check('non_exclude_fields',$iP[0].':'.$iP[1])))))) { // Checking read access: 00489 00490 // Load table descriptions: 00491 #$LANG->loadSingleTableDescription($iP[0]); 00492 if (isset($TCA_DESCR[$iP[0]])) { 00493 // Make see-also link: 00494 $href = ($this->renderALL || ($anchorTable && $iP[0]==$anchorTable) ? '#'.implode('.',$iP) : 'view_help.php?tfID='.rawurlencode(implode('.',$iP)).'&back='.$this->tfID); 00495 $label = $this->getTableFieldLabel($iP[0],$iP[1],' / '); 00496 $lines[] = '<a href="'.htmlspecialchars($href).'">'.htmlspecialchars($label).'</a>'; 00497 } 00498 } 00499 } 00500 } 00501 } 00502 return implode('<br />',$lines); 00503 } 00504 00512 function printImage($images,$descr) { 00513 $code = ''; 00514 // Splitting: 00515 $imgArray = t3lib_div::trimExplode(',', $images, 1); 00516 if (count($imgArray)) { 00517 $descrArray = explode(chr(10),$descr,count($imgArray)); 00518 #debug($descrArray); 00519 foreach($imgArray as $k => $image) { 00520 $descr = $descrArray[$k]; 00521 00522 $absImagePath = t3lib_div::getFileAbsFileName($image,1,1); 00523 if ($absImagePath && @is_file($absImagePath)) { 00524 $imgFile = substr($absImagePath,strlen(PATH_site)); 00525 $imgInfo = @getimagesize($absImagePath); 00526 if (is_array($imgInfo)) { 00527 $imgFile = '../'.$imgFile; 00528 $code.= '<br /><img src="'.$imgFile.'" '.$imgInfo[3].' class="c-inlineimg" alt="" /><br /> 00529 '; 00530 $code.= '<p><em>'.$GLOBALS['LANG']->hscAndCharConv($descr,1).'</em></p> 00531 '; 00532 } else $code.= '<div style="background-color: red; border: 1px solid black; color: white;">NOT AN IMAGE: '.$imgFile.'</div>'; 00533 } else $code.= '<div style="background-color: red; border: 1px solid black; color: white;">IMAGE FILE NOT FOUND: '.$image.'</div>'; 00534 } 00535 } 00536 00537 return $code; 00538 } 00539 00547 function headerLine($str,$type=0) { 00548 switch($type) { 00549 case 1: 00550 $str='<h3>'.htmlspecialchars($str).'</h3> 00551 '; 00552 break; 00553 case 0: 00554 $str='<h4 class="uppercase">'.htmlspecialchars($str).'</h4> 00555 '; 00556 break; 00557 } 00558 00559 return $str; 00560 } 00561 00568 function prepareContent($str) { 00569 $str = $GLOBALS['LANG']->hscAndCharConv($str,0); 00570 return '<p>'.nl2br(trim(strip_tags($str,$this->allowedHTML))).'</p> 00571 '; 00572 } 00573 00583 function printItem($table,$field,$anchors=0) { 00584 global $TCA_DESCR, $LANG, $TCA, $BE_USER; 00585 00586 // Load full table definition in $TCA 00587 t3lib_div::loadTCA($table); 00588 00589 if ($table && (!$field || is_array($TCA_DESCR[$table]['columns'][$field]))) { 00590 // Make seeAlso references. 00591 $seeAlsoRes = $this->make_seeAlso($TCA_DESCR[$table]['columns'][$field]['seeAlso'],$anchors?$table:''); 00592 00593 // Making item: 00594 $out= '<a name="'.$table.'.'.$field.'"></a> 00595 '. 00596 $this->headerLine($this->getTableFieldLabel($table,$field),1). 00597 $this->prepareContent($TCA_DESCR[$table]['columns'][$field]['description']). 00598 ($TCA_DESCR[$table]['columns'][$field]['details'] ? $this->headerLine($LANG->getLL('details').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['details']) : ''). 00599 ($TCA_DESCR[$table]['columns'][$field]['syntax'] ? $this->headerLine($LANG->getLL('syntax').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['syntax']) : ''). 00600 ($TCA_DESCR[$table]['columns'][$field]['image'] ? $this->printImage($TCA_DESCR[$table]['columns'][$field]['image'],$TCA_DESCR[$table]['columns'][$field]['image_descr']) : ''). 00601 ($TCA_DESCR[$table]['columns'][$field]['seeAlso'] && $seeAlsoRes ? $this->headerLine($LANG->getLL('seeAlso').':').'<p>'.$seeAlsoRes.'</p>' : ''). 00602 ($this->back ? '<br /><p><a href="'.htmlspecialchars('view_help.php?tfID='.rawurlencode($this->back)).'" class="typo3-goBack">'.htmlspecialchars($LANG->getLL('goBack')).'</a></p>' : ''). 00603 '<br />'; 00604 } 00605 return $out; 00606 } 00607 00616 function getTableFieldNames($table,$field) { 00617 global $TCA, $TCA_DESCR, $LANG; 00618 00619 $LANG->loadSingleTableDescription($table); 00620 00621 $tableName = is_array($TCA_DESCR[$table]['columns']['']) && $TCA_DESCR[$table]['columns']['']['alttitle'] ? 00622 $TCA_DESCR[$table]['columns']['']['alttitle'] : 00623 (isset($TCA[$table]) ? $TCA[$table]['ctrl']['title'] : ereg_replace('^_MOD_','',$table)); 00624 $fieldName = is_array($TCA_DESCR[$table]['columns'][$field]) && $TCA_DESCR[$table]['columns'][$field]['alttitle'] ? 00625 $TCA_DESCR[$table]['columns'][$field]['alttitle'] : 00626 (isset($TCA[$table])&&isset($TCA[$table]['columns'][$field]) ? $TCA[$table]['columns'][$field]['label'] : $field); 00627 return array($tableName,$fieldName); 00628 } 00629 00639 function getTableFieldLabel($table,$field='',$mergeToken=': ') { 00640 global $LANG; 00641 00642 // Get table / field parts: 00643 list($tableName,$fieldName) = $this->getTableFieldNames($table,$field); 00644 00645 // Create label: 00646 $labelStr = $LANG->sL($tableName). 00647 ($field ? $mergeToken.ereg_replace(':$','', trim($LANG->sL($fieldName))):''); 00648 00649 return $labelStr; 00650 } 00651 } 00652 00653 00654 // Include extension? 00655 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/view_help.php']) { 00656 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/view_help.php']); 00657 } 00658 00659 00660 00661 00662 00663 00664 // Make instance: 00665 $SOBE = t3lib_div::makeInstance('SC_view_help'); 00666 $SOBE->init(); 00667 $SOBE->main(); 00668 $SOBE->printContent(); 00669 ?>