* Added new CSH entries at various places using a new method in t3lib_BEfunc. The...
[Packages/TYPO3.CMS.git] / typo3 / view_help.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27 /**
28 * Document for viewing the online help texts, also known as TCA_DESCR.
29 * See Inside TYPO3 for details.
30 *
31 * $Id$
32 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
33 * XHTML-trans compliant
34 *
35 * @author Kasper Skaarhoj <kasper@typo3.com>
36 */
37 /**
38 * [CLASS/FUNCTION INDEX of SCRIPT]
39 *
40 *
41 *
42 * 78: class SC_view_help
43 * 97: function init()
44 * 119: function main()
45 * 173: function printContent()
46 * 184: function make_seeAlso($value,$anchorTable='')
47 * 222: function printImage($image,$descr)
48 * 244: function headerLine($str,$type=0)
49 * 265: function prepareContent($str)
50 * 280: function printItem($table,$field,$anchors=0)
51 * 316: function getTableFieldNames($table,$field)
52 *
53 * TOTAL FUNCTIONS: 9
54 * (This index is automatically created/updated by the extension "extdeveval")
55 *
56 */
57
58 require ('init.php');
59 require ('template.php');
60 include ('sysext/lang/locallang_view_help.php');
61
62
63
64
65
66
67
68
69
70
71 /**
72 * Script Class for rendering the Context Sensitive Help documents, either the single display in the small pop-up window or the full-table view in the larger window.
73 *
74 * @author Kasper Skaarhoj <kasper@typo3.com>
75 * @package TYPO3
76 * @subpackage core
77 */
78 class SC_view_help {
79 var $allowedHTML = '<strong><em><b><i>';
80
81 var $content; // Content accumulation.
82
83 // For these vars, see init()
84 var $limitAccess; // If set access to fields and tables is checked. Should be done for true database tables.
85 var $table; // The "table" key
86 var $field; // The "field" key
87
88 // Internal, static: GPvar:
89 var $tfID; // Table/FIeld id.
90 var $back; // Back (previous tfID)
91
92 /**
93 * Initialize the class for various input etc.
94 *
95 * @return void
96 */
97 function init() {
98 global $LANG;
99
100 // Setting GPvars:
101 $this->tfID = t3lib_div::_GP('tfID');
102 $this->back = t3lib_div::_GP('back');
103
104 // Set internal table/field to the parts of "tfID" incoming var.
105 list($this->table,$this->field)=explode('.',$this->tfID);
106
107 // Load descriptions for table $this->table
108 $LANG->loadSingleTableDescription($this->table);
109
110 // limitAccess is checked if the $this->table really IS a table.
111 $this->limitAccess = !isset($TCA[$this->table]) ? 0 : 1;
112 }
113
114 /**
115 * Main function, rendering the display
116 *
117 * @return void
118 */
119 function main() {
120 global $BE_USER,$LANG,$TCA_DESCR,$TCA,$TBE_TEMPLATE;
121
122 // Start HTML output accumulation:
123 $TBE_TEMPLATE->docType='xhtml_trans';
124 $TBE_TEMPLATE->divClass='typo3-view-help';
125 $this->content.=$TBE_TEMPLATE->startPage($LANG->getLL('title'));
126
127 // If ALL fields is supposed to be shown:
128 if ($this->field=='*') {
129 // Load table TCA
130 t3lib_div::loadTCA($this->table);
131
132 if (is_array($TCA_DESCR[$this->table]['columns']) && (!$this->limitAccess || $BE_USER->check('tables_select',$this->table))) {
133 // Traverse table columns as listed in TCA_DESCR
134 $parts=array();
135 $parts[0]=''; // Reserved for header of table
136 reset($TCA_DESCR[$this->table]['columns']);
137 while(list($this->field)=each($TCA_DESCR[$this->table]['columns'])) {
138 $fieldValue = isset($TCA[$this->table]) && strcmp($this->field,"") ? $TCA[$this->table]['columns'][$this->field] : array();
139
140 if (is_array($fieldValue) && (!$this->limitAccess || !$fieldValue['exclude'] || $BE_USER->check('non_exclude_fields',$this->table.':'.$this->field))) {
141 if (!$this->field) {
142 $parts[0]=$this->printItem($this->table,'',1);
143 } else {
144 $parts[]=$this->printItem($this->table,$this->field,1);
145 }
146 }
147 }
148
149 if (!strcmp($parts,"")) unset($parts[0]);
150 $this->content.= implode('<br />',$parts);
151 }
152 } else {
153 // ... otherwise show only single field:
154 $this->content.=$this->printItem($this->table,$this->field);
155
156 // Link to Full table description:
157 # $onClick = 'vHWin=window.open(\'view_help.php?tfID='.rawurlencode($this->table.'.*').'&ONLY='.$LANG->lang.'\',\'fullHelpWindow\',\'width=600,scrollbars=1,status=1,menubar=1,location=1,resizable=1,toolbar=1\');vHWin.focus();return false;';
158 $onClick = 'document.location = \'view_help.php?tfID='.rawurlencode($this->table.'.*').'&ONLY='.$LANG->lang.'\';return false;';
159 $this->content.='<br /><p><a href="#" onclick="'.htmlspecialchars($onClick).'">'.htmlspecialchars($LANG->getLL('fullDescription')).'</a></p>';
160 }
161
162 // Print close-button:
163 $this->content.='<br /><form action=""><input type="submit" value="'.htmlspecialchars($LANG->getLL('close')).'" onclick="self.close(); return false;" /></form>
164 <br/>';
165
166 // End page:
167 $this->content.=$TBE_TEMPLATE->endPage();
168 }
169
170 /**
171 * Outputting the accumulated content to screen
172 *
173 * @return void
174 */
175 function printContent() {
176 echo $this->content;
177 }
178
179 /**
180 * Make seeAlso links from $value
181 *
182 * @param string See-also input codes
183 * @param string If $anchorTable is set to a tablename, then references to this table will be made as anchors, not URLs.
184 * @return string See-also links HTML
185 */
186 function make_seeAlso($value,$anchorTable='') {
187 global $TCA,$BE_USER;
188 // Split references by comma, vert.line or linebreak
189 $items = split(',|'.chr(10),$value);
190 reset($items);
191 $lines=array();
192 while(list(,$val)=each($items)) {
193 $val = trim($val);
194 if ($val) {
195 $iP = explode(':',$val);
196 $iPUrl = t3lib_div::trimExplode('|',$val);
197 // URL reference:
198 if (substr($iPUrl[1],0,4)=='http') {
199 $lines[]='<a href="'.htmlspecialchars($iPUrl[1]).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>';
200 } else {
201 // "table" reference
202 t3lib_div::loadTCA($iP[0]);
203 if (!isset($TCA[$iP[0]]) || (is_array($TCA[$iP[0]]['columns'][$iP[1]]) && (!$this->limitAccess || ($BE_USER->check('tables_select',$iP[0]) && (!$TCA[$iP[0]]['columns'][$iP[1]]['exclude'] || $BE_USER->check('non_exclude_fields',$iP[0].':'.$iP[1])))))) { // Checking read access:
204 list($tableName,$fieldName) = $this->getTableFieldNames($iP[0],$iP[1]);
205
206 // Make see-also link:
207 $href = ($anchorTable&&$iP[0]==$anchorTable ? '#'.implode('.',$iP) : 'view_help.php?tfID='.rawurlencode(implode('.',$iP)).'&back='.$this->tfID);
208 $label = $GLOBALS['LANG']->sL($tableName).($iP[1]?' / '.ereg_replace(':$','',$GLOBALS['LANG']->sL($fieldName)):'');
209 $lines[]='<a href="'.htmlspecialchars($href).'">'.htmlspecialchars($label).'</a>';
210 }
211 }
212 }
213 }
214 return implode('<br />',$lines);
215 }
216
217 /**
218 * Will return an image tag with description in italics.
219 *
220 * @param string Image file reference
221 * @param string Description string
222 * @return string Image HTML codes
223 */
224 function printImage($image,$descr) {
225 $absImagePath = t3lib_div::getFileAbsFileName($image,1,1);
226 if ($absImagePath && @is_file($absImagePath)) {
227 $imgFile = substr($absImagePath,strlen(PATH_site));
228 $imgInfo=@getimagesize($absImagePath);
229 if (is_array($imgInfo)) {
230 $code = '<br /><img src="../'.$imgFile.'" '.$imgInfo[3].' alt="" /><br />
231 ';
232 $code.= '<p><em>'.$GLOBALS['LANG']->hscAndCharConv($descr,0).'</em></p>
233 ';
234 return $code;
235 }
236 }
237 }
238
239 /**
240 * Returns header HTML content
241 *
242 * @param string Header text
243 * @param string Header type (1, 0)
244 * @return string The HTML for the header.
245 */
246 function headerLine($str,$type=0) {
247 switch($type) {
248 case 1:
249 $str='<h3>'.htmlspecialchars($str).'</h3>
250 ';
251 break;
252 case 0:
253 $str='<h4 class="uppercase">'.htmlspecialchars($str).'</h4>
254 ';
255 break;
256 }
257
258 return $str;
259 }
260
261 /**
262 * Returns prepared content
263 *
264 * @param string Content to format.
265 * @return string Formatted content.
266 */
267 function prepareContent($str) {
268 $str = $GLOBALS['LANG']->hscAndCharConv($str,0);
269 return '<p>'.nl2br(trim(strip_tags($str,$this->allowedHTML))).'</p>
270 ';
271 }
272
273 /**
274 * Prints a single $table/$field information piece
275 * If $anchors is set, then seeAlso references to the same table will be page-anchors, not links.
276 *
277 * @param string Table name
278 * @param string Field name
279 * @param boolean If anchors is to be shown.
280 * @return string HTML content
281 */
282 function printItem($table,$field,$anchors=0) {
283 global $TCA_DESCR, $LANG, $TCA, $BE_USER;
284
285 // Load full table definition in $TCA
286 t3lib_div::loadTCA($table);
287
288 if ($table && (!$field || is_array($TCA_DESCR[$table]['columns'][$field]))) {
289 // Make seeAlso references.
290 $seeAlsoRes = $this->make_seeAlso($TCA_DESCR[$table]['columns'][$field]['seeAlso'],$anchors?$table:'');
291
292 // Get Human Readable table and field labels
293 list($tableName,$fieldName) = $this->getTableFieldNames($table,$field);
294
295 // Making item:
296 $out= '<a name="'.$table.'.'.$field.'"></a>
297 '.
298 $this->headerLine($LANG->sL($tableName).': '.($field?ereg_replace(':$','',trim($LANG->sL($fieldName))):''),1).
299 $this->prepareContent($TCA_DESCR[$table]['columns'][$field]['description']).
300 ($TCA_DESCR[$table]['columns'][$field]['details'] ? $this->headerLine($LANG->getLL('details').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['details']) : '').
301 ($TCA_DESCR[$table]['columns'][$field]['syntax'] ? $this->headerLine($LANG->getLL('syntax').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['syntax']) : '').
302 ($TCA_DESCR[$table]['columns'][$field]['image'] ? $this->printImage($TCA_DESCR[$table]['columns'][$field]['image'],$TCA_DESCR[$table]['columns'][$field]['image_descr']) : '').
303 ($TCA_DESCR[$table]['columns'][$field]['seeAlso'] && $seeAlsoRes ? $this->headerLine($LANG->getLL('seeAlso').':').'<p>'.$seeAlsoRes.'</p>' : '').
304 ($this->back ? '<br /><p><a href="'.htmlspecialchars('view_help.php?tfID='.rawurlencode($this->back)).'" class="typo3-goBack">'.htmlspecialchars($LANG->getLL('goBack')).'</a></p>' : '').
305 '<br />';
306 }
307 return $out;
308 }
309
310 /**
311 * Returns labels for $table and $field.
312 * If $table is "_MOD_" prefixed, the part after "_MOD_" is returned (non-tables, fx. modules)
313 *
314 * @param string Table name
315 * @param string Field name
316 * @return array Table and field labels in a numeric array
317 */
318 function getTableFieldNames($table,$field) {
319 global $TCA, $TCA_DESCR;
320 $tableName = is_array($TCA_DESCR[$table]['columns']['']) && $TCA_DESCR[$table]['columns']['']['alttitle'] ?
321 $TCA_DESCR[$table]['columns']['']['alttitle'] :
322 (isset($TCA[$table]) ? $TCA[$table]['ctrl']['title'] : ereg_replace('^_MOD_','',$table));
323 $fieldName = is_array($TCA_DESCR[$table]['columns'][$field]) && $TCA_DESCR[$table]['columns'][$field]['alttitle'] ?
324 $TCA_DESCR[$table]['columns'][$field]['alttitle'] :
325 (isset($TCA[$table])&&isset($TCA[$table]['columns'][$field]) ? $TCA[$table]['columns'][$field]['label'] : $field);
326 return array($tableName,$fieldName);
327 }
328 }
329
330
331 // Include extension?
332 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/view_help.php']) {
333 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/view_help.php']);
334 }
335
336
337
338
339
340
341 // Make instance:
342 $SOBE = t3lib_div::makeInstance('SC_view_help');
343 $SOBE->init();
344 $SOBE->main();
345 $SOBE->printContent();
346 ?>