First CVS update in a long time - see the top of changelog. In particular the foundat...
[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 $this->content.='<br /><p><a href="#" onclick="'.htmlspecialchars($onClick).'">'.htmlspecialchars($LANG->getLL('fullDescription')).'</a></p>';
159 }
160
161 // Print close-button:
162 $this->content.='<br /><form action=""><input type="submit" value="'.htmlspecialchars($LANG->getLL('close')).'" onclick="self.close(); return false;" /></form>';
163
164 // End page:
165 $this->content.=$TBE_TEMPLATE->endPage();
166 }
167
168 /**
169 * Outputting the accumulated content to screen
170 *
171 * @return void
172 */
173 function printContent() {
174 echo $this->content;
175 }
176
177 /**
178 * Make seeAlso links from $value
179 *
180 * @param string See-also input codes
181 * @param string If $anchorTable is set to a tablename, then references to this table will be made as anchors, not URLs.
182 * @return string See-also links HTML
183 */
184 function make_seeAlso($value,$anchorTable='') {
185 global $TCA,$BE_USER;
186 // Split references by comma, vert.line or linebreak
187 $items = split(',|'.chr(10),$value);
188 reset($items);
189 $lines=array();
190 while(list(,$val)=each($items)) {
191 $val = trim($val);
192 if ($val) {
193 $iP = explode(':',$val);
194 $iPUrl = t3lib_div::trimExplode('|',$val);
195 // URL reference:
196 if (substr($iPUrl[1],0,4)=='http') {
197 $lines[]='<a href="'.htmlspecialchars($iPUrl[1]).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>';
198 } else {
199 // "table" reference
200 t3lib_div::loadTCA($iP[0]);
201 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:
202 list($tableName,$fieldName) = $this->getTableFieldNames($iP[0],$iP[1]);
203
204 // Make see-also link:
205 $href = ($anchorTable&&$iP[0]==$anchorTable ? '#'.implode('.',$iP) : 'view_help.php?tfID='.rawurlencode(implode('.',$iP)).'&back='.$this->tfID);
206 $label = $GLOBALS['LANG']->sL($tableName).($iP[1]?' / '.ereg_replace(':$','',$GLOBALS['LANG']->sL($fieldName)):'');
207 $lines[]='<a href="'.htmlspecialchars($href).'">'.htmlspecialchars($label).'</a>';
208 }
209 }
210 }
211 }
212 return implode('<br />',$lines);
213 }
214
215 /**
216 * Will return an image tag with description in italics.
217 *
218 * @param string Image file reference
219 * @param string Description string
220 * @return string Image HTML codes
221 */
222 function printImage($image,$descr) {
223 $absImagePath = t3lib_div::getFileAbsFileName($image,1,1);
224 if ($absImagePath && @is_file($absImagePath)) {
225 $imgFile = substr($absImagePath,strlen(PATH_site));
226 $imgInfo=@getimagesize($absImagePath);
227 if (is_array($imgInfo)) {
228 $code = '<br /><img src="../'.$imgFile.'" '.$imgInfo[3].' alt="" /><br />
229 ';
230 $code.= '<p><em>'.$GLOBALS['LANG']->hscAndCharConv($descr,0).'</em></p>
231 ';
232 return $code;
233 }
234 }
235 }
236
237 /**
238 * Returns header HTML content
239 *
240 * @param string Header text
241 * @param string Header type (1, 0)
242 * @return string The HTML for the header.
243 */
244 function headerLine($str,$type=0) {
245 switch($type) {
246 case 1:
247 $str='<h3>'.htmlspecialchars($str).'</h3>
248 ';
249 break;
250 case 0:
251 $str='<h4 class="uppercase">'.htmlspecialchars($str).'</h4>
252 ';
253 break;
254 }
255
256 return $str;
257 }
258
259 /**
260 * Returns prepared content
261 *
262 * @param string Content to format.
263 * @return string Formatted content.
264 */
265 function prepareContent($str) {
266 $str = $GLOBALS['LANG']->hscAndCharConv($str,0);
267 return '<p>'.nl2br(trim(strip_tags($str,$this->allowedHTML))).'</p>
268 ';
269 }
270
271 /**
272 * Prints a single $table/$field information piece
273 * If $anchors is set, then seeAlso references to the same table will be page-anchors, not links.
274 *
275 * @param string Table name
276 * @param string Field name
277 * @param boolean If anchors is to be shown.
278 * @return string HTML content
279 */
280 function printItem($table,$field,$anchors=0) {
281 global $TCA_DESCR, $LANG, $TCA, $BE_USER;
282
283 // Load full table definition in $TCA
284 t3lib_div::loadTCA($table);
285
286 if ($table && (!$field || is_array($TCA_DESCR[$table]['columns'][$field]))) {
287 // Make seeAlso references.
288 $seeAlsoRes = $this->make_seeAlso($TCA_DESCR[$table]['columns'][$field]['seeAlso'],$anchors?$table:'');
289
290 // Get Human Readable table and field labels
291 list($tableName,$fieldName) = $this->getTableFieldNames($table,$field);
292
293 // Making item:
294 $out= '<a name="'.$table.'.'.$field.'"></a>
295 '.
296 $this->headerLine($LANG->sL($tableName).': '.($field?ereg_replace(':$','',trim($LANG->sL($fieldName))):''),1).
297 $this->prepareContent($TCA_DESCR[$table]['columns'][$field]['description']).
298 ($TCA_DESCR[$table]['columns'][$field]['details'] ? $this->headerLine($LANG->getLL('details').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['details']) : '').
299 ($TCA_DESCR[$table]['columns'][$field]['syntax'] ? $this->headerLine($LANG->getLL('syntax').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['syntax']) : '').
300 ($TCA_DESCR[$table]['columns'][$field]['image'] ? $this->printImage($TCA_DESCR[$table]['columns'][$field]['image'],$TCA_DESCR[$table]['columns'][$field]['image_descr']) : '').
301 ($TCA_DESCR[$table]['columns'][$field]['seeAlso'] && $seeAlsoRes ? $this->headerLine($LANG->getLL('seeAlso').':').'<p>'.$seeAlsoRes.'</p>' : '').
302 ($this->back ? '<br /><p><a href="'.htmlspecialchars('view_help.php?tfID='.rawurlencode($this->back)).'" class="typo3-goBack">'.htmlspecialchars($LANG->getLL('goBack')).'</a></p>' : '').
303 '<br />';
304 }
305 return $out;
306 }
307
308 /**
309 * Returns labels for $table and $field.
310 * If $table is "_MOD_" prefixed, the part after "_MOD_" is returned (non-tables, fx. modules)
311 *
312 * @param string Table name
313 * @param string Field name
314 * @return array Table and field labels in a numeric array
315 */
316 function getTableFieldNames($table,$field) {
317 global $TCA, $TCA_DESCR;
318 $tableName = is_array($TCA_DESCR[$table]['columns']['']) && $TCA_DESCR[$table]['columns']['']['alttitle'] ?
319 $TCA_DESCR[$table]['columns']['']['alttitle'] :
320 (isset($TCA[$table]) ? $TCA[$table]['ctrl']['title'] : ereg_replace('^_MOD_','',$table));
321 $fieldName = is_array($TCA_DESCR[$table]['columns'][$field]) && $TCA_DESCR[$table]['columns'][$field]['alttitle'] ?
322 $TCA_DESCR[$table]['columns'][$field]['alttitle'] :
323 (isset($TCA[$table])&&isset($TCA[$table]['columns'][$field]) ? $TCA[$table]['columns'][$field]['label'] : $field);
324 return array($tableName,$fieldName);
325 }
326 }
327
328
329 // Include extension?
330 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/view_help.php']) {
331 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/view_help.php']);
332 }
333
334
335
336
337
338
339 // Make instance:
340 $SOBE = t3lib_div::makeInstance('SC_view_help');
341 $SOBE->init();
342 $SOBE->main();
343 $SOBE->printContent();
344 ?>