Added more comments, $Id$ keywords etc for the whole core of TYPO3.
[Packages/TYPO3.CMS.git] / typo3 / view_help.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 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 * 93: function init()
44 * 111: function main()
45 * 166: function printContent()
46 * 177: function make_seeAlso($value,$anchorTable='')
47 * 215: function printImage($image,$descr)
48 * 237: function headerLine($str,$type=0)
49 * 258: function prepareContent($str)
50 * 273: function printItem($table,$field,$anchors=0)
51 * 309: 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
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 /**
89 * Initialize
90 *
91 * @return void
92 */
93 function init() {
94 global $LANG;
95
96 // Set internal table/field to the parts of "tfID" incoming var.
97 list($this->table,$this->field)=explode('.',t3lib_div::GPvar('tfID'));
98
99 // Load descriptions for table $this->table
100 $LANG->loadSingleTableDescription($this->table);
101
102 // limitAccess is checked if the $this->table really IS a table.
103 $this->limitAccess = !isset($TCA[$this->table]) ? 0 : 1;
104 }
105
106 /**
107 * Main
108 *
109 * @return void
110 */
111 function main() {
112 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
113 global $TBE_TEMPLATE;
114
115 // Start HTML output accumulation:
116 $TBE_TEMPLATE->docType='xhtml_trans';
117 $TBE_TEMPLATE->divClass='typo3-view-help';
118 $this->content.=$TBE_TEMPLATE->startPage($LANG->getLL('title'));
119
120 // If ALL fields is supposed to be shown:
121 if ($this->field=='*') {
122 // Load table TCA
123 t3lib_div::loadTCA($this->table);
124
125 if (is_array($TCA_DESCR[$this->table]['columns']) && (!$this->limitAccess || $BE_USER->check('tables_select',$this->table))) {
126 // Traverse table columns as listed in TCA_DESCR
127 $parts=array();
128 $parts[0]=''; // Reserved for header of table
129 reset($TCA_DESCR[$this->table]['columns']);
130 while(list($this->field)=each($TCA_DESCR[$this->table]['columns'])) {
131 $fieldValue = isset($TCA[$this->table]) && strcmp($this->field,"") ? $TCA[$this->table]['columns'][$this->field] : array();
132
133 if (is_array($fieldValue) && (!$this->limitAccess || !$fieldValue['exclude'] || $BE_USER->check('non_exclude_fields',$this->table.':'.$this->field))) {
134 if (!$this->field) {
135 $parts[0]=$this->printItem($this->table,'',1);
136 } else {
137 $parts[]=$this->printItem($this->table,$this->field,1);
138 }
139 }
140 }
141
142 if (!strcmp($parts,"")) unset($parts[0]);
143 $this->content.= implode('<br />',$parts);
144 }
145 } else {
146 // ... otherwise show only single field:
147 $this->content.=$this->printItem($this->table,$this->field);
148
149 // Link to Full table description:
150 $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;';
151 $this->content.='<br /><p><a href="#" onclick="'.htmlspecialchars($onClick).'">'.htmlspecialchars($LANG->getLL('fullDescription')).'</a></p>';
152 }
153
154 // Print close-button:
155 $this->content.='<br /><form action=""><input type="submit" value="'.htmlspecialchars($LANG->getLL('close')).'" onclick="self.close(); return false;" /></form>';
156
157 // End page:
158 $this->content.=$TBE_TEMPLATE->endPage();
159 }
160
161 /**
162 * Print output
163 *
164 * @return void
165 */
166 function printContent() {
167 echo $this->content;
168 }
169
170 /**
171 * Make seeAlso links from $value
172 *
173 * @param string See-also input codes
174 * @param string If $anchorTable is set to a tablename, then references to this table will be made as anchors, not URLs.
175 * @return string See-also links HTML
176 */
177 function make_seeAlso($value,$anchorTable='') {
178 global $TCA,$BE_USER;
179 // Split references by comma, vert.line or linebreak
180 $items = split(',|'.chr(10),$value);
181 reset($items);
182 $lines=array();
183 while(list(,$val)=each($items)) {
184 $val = trim($val);
185 if ($val) {
186 $iP = explode(':',$val);
187 $iPUrl = t3lib_div::trimExplode('|',$val);
188 // URL reference:
189 if (substr($iPUrl[1],0,4)=='http') {
190 $lines[]='<a href="'.htmlspecialchars($iPUrl[1]).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>';
191 } else {
192 // "table" reference
193 t3lib_div::loadTCA($iP[0]);
194 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:
195 list($tableName,$fieldName) = $this->getTableFieldNames($iP[0],$iP[1]);
196
197 // Make see-also link:
198 $href = ($anchorTable&&$iP[0]==$anchorTable ? '#'.implode('.',$iP) : 'view_help.php?tfID='.rawurlencode(implode('.',$iP)).'&back='.t3lib_div::GPvar('tfID'));
199 $label = $GLOBALS['LANG']->sL($tableName).($iP[1]?' / '.ereg_replace(':$','',$GLOBALS['LANG']->sL($fieldName)):'');
200 $lines[]='<a href="'.htmlspecialchars($href).'">'.htmlspecialchars($label).'</a>';
201 }
202 }
203 }
204 }
205 return implode('<br />',$lines);
206 }
207
208 /**
209 * Will return an image tag with description in italics.
210 *
211 * @param string Image file reference
212 * @param string Description string
213 * @return string Image HTML codes
214 */
215 function printImage($image,$descr) {
216 $absImagePath = t3lib_div::getFileAbsFileName($image,1,1);
217 if ($absImagePath && @is_file($absImagePath)) {
218 $imgFile = substr($absImagePath,strlen(PATH_site));
219 $imgInfo=@getimagesize($absImagePath);
220 if (is_array($imgInfo)) {
221 $code = '<br /><img src="../'.$imgFile.'" '.$imgInfo[3].' alt="" /><br />
222 ';
223 $code.= '<p><em>'.$GLOBALS['LANG']->hscAndCharConv($descr,0).'</em></p>
224 ';
225 return $code;
226 }
227 }
228 }
229
230 /**
231 * Returns header
232 *
233 * @param string Header text
234 * @param string Header type (1, 0)
235 * @return string The HTML for the header.
236 */
237 function headerLine($str,$type=0) {
238 switch($type) {
239 case 1:
240 $str='<h3>'.htmlspecialchars($str).'</h3>
241 ';
242 break;
243 case 0:
244 $str='<h4>'.htmlspecialchars(t3lib_div::danish_strtoupper($str)).'</h4>
245 ';
246 break;
247 }
248
249 return $str;
250 }
251
252 /**
253 * Returns prepared content
254 *
255 * @param string Content to format.
256 * @return string Formatted content.
257 */
258 function prepareContent($str) {
259 $str = $GLOBALS['LANG']->hscAndCharConv($str,0);
260 return '<p>'.nl2br(trim(strip_tags($str,$this->allowedHTML))).'</p>
261 ';
262 }
263
264 /**
265 * Prints a single $table/$field information piece
266 * If $anchors is set, then seeAlso references to the same table will be page-anchors, not links.
267 *
268 * @param string Table name
269 * @param string Field name
270 * @param boolean If anchors is to be shown.
271 * @return string HTML content
272 */
273 function printItem($table,$field,$anchors=0) {
274 global $TCA_DESCR, $LANG, $TCA, $BE_USER;
275
276 // Load full table definition in $TCA
277 t3lib_div::loadTCA($table);
278
279 if ($table && (!$field || is_array($TCA_DESCR[$table]['columns'][$field]))) {
280 // Make seeAlso references.
281 $seeAlsoRes = $this->make_seeAlso($TCA_DESCR[$table]['columns'][$field]['seeAlso'],$anchors?$table:'');
282
283 // Get Human Readable table and field labels
284 list($tableName,$fieldName) = $this->getTableFieldNames($table,$field);
285
286 // Making item:
287 $out= '<a name="'.$table.'.'.$field.'"></a>
288 '.
289 $this->headerLine($LANG->sL($tableName).': '.($field?ereg_replace(':$','',stripslashes(trim($LANG->sL($fieldName)))):''),1).
290 $this->prepareContent($TCA_DESCR[$table]['columns'][$field]['description']).
291 ($TCA_DESCR[$table]['columns'][$field]['details'] ? $this->headerLine($LANG->getLL('details').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['details']) : '').
292 ($TCA_DESCR[$table]['columns'][$field]['syntax'] ? $this->headerLine($LANG->getLL('syntax').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['syntax']) : '').
293 ($TCA_DESCR[$table]['columns'][$field]['image'] ? $this->printImage($TCA_DESCR[$table]['columns'][$field]['image'],$TCA_DESCR[$table]['columns'][$field]['image_descr']) : '').
294 ($TCA_DESCR[$table]['columns'][$field]['seeAlso'] && $seeAlsoRes ? $this->headerLine($LANG->getLL('seeAlso').':').'<p>'.$seeAlsoRes.'</p>' : '').
295 (t3lib_div::GPvar('back') ? '<br /><p><a href="'.htmlspecialchars('view_help.php?tfID='.rawurlencode(t3lib_div::GPvar('back'))).'" class="typo3-goBack">'.htmlspecialchars($LANG->getLL('goBack')).'</a></p>' : '').
296 '<br />';
297 }
298 return $out;
299 }
300
301 /**
302 * Returns labels for $table and $field.
303 * If $table is "_MOD_" prefixed, the part after "_MOD_" is returned (non-tables, fx. modules)
304 *
305 * @param string Table name
306 * @param string Field name
307 * @return array Table and field labels in a numeric array
308 */
309 function getTableFieldNames($table,$field) {
310 global $TCA, $TCA_DESCR;
311 $tableName = is_array($TCA_DESCR[$table]['columns']['']) && $TCA_DESCR[$table]['columns']['']['alttitle'] ?
312 $TCA_DESCR[$table]['columns']['']['alttitle'] :
313 (isset($TCA[$table]) ? $TCA[$table]['ctrl']['title'] : ereg_replace('^_MOD_','',$table));
314 $fieldName = is_array($TCA_DESCR[$table]['columns'][$field]) && $TCA_DESCR[$table]['columns'][$field]['alttitle'] ?
315 $TCA_DESCR[$table]['columns'][$field]['alttitle'] :
316 (isset($TCA[$table])&&isset($TCA[$table]['columns'][$field]) ? $TCA[$table]['columns'][$field]['label'] : $field);
317 return array($tableName,$fieldName);
318 }
319 }
320
321
322 // Include extension?
323 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/view_help.php']) {
324 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/view_help.php']);
325 }
326
327
328
329
330
331
332 // Make instance:
333 $SOBE = t3lib_div::makeInstance('SC_view_help');
334 $SOBE->init();
335 $SOBE->main();
336 $SOBE->printContent();
337 ?>