Initial revision
[Packages/TYPO3.CMS.git] / typo3 / view_help.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2003 Kasper Skårhøj (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 * @author Kasper Skårhøj <kasper@typo3.com>
32 * @package TYPO3
33 * @subpackage core
34 *
35 * Revised for TYPO3 3.6 2/2003 by Kasper Skårhøj
36 * XHTML-trans compliant
37 */
38
39
40 require ('init.php');
41 require ('template.php');
42 include ('sysext/lang/locallang_view_help.php');
43
44
45
46 // ***************************
47 // Script Class
48 // ***************************
49 class SC_view_help {
50 var $allowedHTML = '<strong><em><b><i>';
51
52 var $content; // Content accumulation.
53
54 // For these vars, see init()
55 var $limitAccess; // If set access to fields and tables is checked. Should be done for true database tables.
56 var $table; // The "table" key
57 var $field; // The "field" key
58
59 /**
60 * Initialize
61 */
62 function init() {
63 global $LANG;
64
65 // Set internal table/field to the parts of "tfID" incoming var.
66 list($this->table,$this->field)=explode('.',t3lib_div::GPvar('tfID'));
67
68 // Load descriptions for table $this->table
69 $LANG->loadSingleTableDescription($this->table);
70
71 // limitAccess is checked if the $this->table really IS a table.
72 $this->limitAccess = !isset($TCA[$this->table]) ? 0 : 1;
73 }
74
75 /**
76 * Main
77 */
78 function main() {
79 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$HTTP_GET_VARS,$HTTP_POST_VARS,$CLIENT,$TYPO3_CONF_VARS;
80 global $TBE_TEMPLATE;
81
82 // Start HTML output accumulation:
83 $TBE_TEMPLATE->docType='xhtml_trans';
84 $TBE_TEMPLATE->divClass='typo3-view-help';
85 $this->content.=$TBE_TEMPLATE->startPage($LANG->getLL('title'));
86
87 // If ALL fields is supposed to be shown:
88 if ($this->field=='*') {
89 // Load table TCA
90 t3lib_div::loadTCA($this->table);
91
92 if (is_array($TCA_DESCR[$this->table]['columns']) && (!$this->limitAccess || $BE_USER->check('tables_select',$this->table))) {
93 // Traverse table columns as listed in TCA_DESCR
94 $parts=array();
95 $parts[0]=''; // Reserved for header of table
96 reset($TCA_DESCR[$this->table]['columns']);
97 while(list($this->field)=each($TCA_DESCR[$this->table]['columns'])) {
98 $fieldValue = isset($TCA[$this->table]) && strcmp($this->field,"") ? $TCA[$this->table]['columns'][$this->field] : array();
99
100 if (is_array($fieldValue) && (!$this->limitAccess || !$fieldValue['exclude'] || $BE_USER->check('non_exclude_fields',$this->table.':'.$this->field))) {
101 if (!$this->field) {
102 $parts[0]=$this->printItem($this->table,'',1);
103 } else {
104 $parts[]=$this->printItem($this->table,$this->field,1);
105 }
106 }
107 }
108
109 if (!strcmp($parts,"")) unset($parts[0]);
110 $this->content.= implode('<br />',$parts);
111 }
112 } else {
113 // ... otherwise show only single field:
114 $this->content.=$this->printItem($this->table,$this->field);
115
116 // Link to Full table description:
117 $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;';
118 $this->content.='<br /><p><a href="#" onclick="'.htmlspecialchars($onClick).'">'.htmlspecialchars($LANG->getLL('fullDescription')).'</a></p>';
119 }
120
121 // Print close-button:
122 $this->content.='<br /><form action=""><input type="submit" value="'.htmlspecialchars($LANG->getLL('close')).'" onclick="self.close(); return false;" /></form>';
123
124 // End page:
125 $this->content.=$TBE_TEMPLATE->endPage();
126 }
127
128 /**
129 * Print output
130 */
131 function printContent() {
132 echo $this->content;
133 }
134
135 /**
136 * Make seeAlso links from $value
137 * If $anchorTable is set to a tablename, then references to this table will be made as anchors, not URLs.
138 */
139 function make_seeAlso($value,$anchorTable='') {
140 global $TCA,$BE_USER;
141 // Split references by comma, vert.line or linebreak
142 $items = split(',|'.chr(10),$value);
143 reset($items);
144 $lines=array();
145 while(list(,$val)=each($items)) {
146 $val = trim($val);
147 if ($val) {
148 $iP = explode(':',$val);
149 $iPUrl = t3lib_div::trimExplode('|',$val);
150 // URL reference:
151 if (substr($iPUrl[1],0,4)=='http') {
152 $lines[]='<a href="'.htmlspecialchars($iPUrl[1]).'" target="_blank"><em>'.htmlspecialchars($iPUrl[0]).'</em></a>';
153 } else {
154 // "table" reference
155 t3lib_div::loadTCA($iP[0]);
156 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:
157 list($tableName,$fieldName) = $this->getTableFieldNames($iP[0],$iP[1]);
158
159 // Make see-also link:
160 $href = ($anchorTable&&$iP[0]==$anchorTable ? '#'.implode('.',$iP) : 'view_help.php?tfID='.rawurlencode(implode('.',$iP)).'&back='.t3lib_div::GPvar('tfID'));
161 $label = $GLOBALS['LANG']->sL($tableName).($iP[1]?' / '.ereg_replace(':$','',$GLOBALS['LANG']->sL($fieldName)):'');
162 $lines[]='<a href="'.htmlspecialchars($href).'">'.htmlspecialchars($label).'</a>';
163 }
164 }
165 }
166 }
167 return implode('<br />',$lines);
168 }
169
170 /**
171 * Will return an image tag with description in italics.
172 */
173 function printImage($image,$descr) {
174 $absImagePath = t3lib_div::getFileAbsFileName($image,1,1);
175 if ($absImagePath && @is_file($absImagePath)) {
176 $imgFile = substr($absImagePath,strlen(PATH_site));
177 $imgInfo=@getimagesize($absImagePath);
178 if (is_array($imgInfo)) {
179 $code = '<br /><img src="../'.$imgFile.'" '.$imgInfo[3].' alt="" /><br />
180 ';
181 $code.= '<p><em>'.$GLOBALS['LANG']->hscAndCharConv($descr,0).'</em></p>
182 ';
183 return $code;
184 }
185 }
186 }
187
188 /**
189 * Returns header
190 */
191 function headerLine($str,$type=0) {
192 switch($type) {
193 case 1:
194 $str='<h3>'.htmlspecialchars($str).'</h3>
195 ';
196 break;
197 case 0:
198 $str='<h4>'.htmlspecialchars(t3lib_div::danish_strtoupper($str)).'</h4>
199 ';
200 break;
201 }
202
203 return $str;
204 }
205
206 /**
207 * Returns prepared content
208 */
209 function prepareContent($str) {
210 $str = $GLOBALS['LANG']->hscAndCharConv($str,0);
211 return '<p>'.nl2br(trim(strip_tags($str,$this->allowedHTML))).'</p>
212 ';
213 }
214
215 /**
216 * Prints a single $table/$field information piece
217 * If $anchors is set, then seeAlso references to the same table will be page-anchors, not links.
218 */
219 function printItem($table,$field,$anchors=0) {
220 global $TCA_DESCR, $LANG, $TCA, $BE_USER;
221
222 // Load full table definition in $TCA
223 t3lib_div::loadTCA($table);
224
225 if ($table && (!$field || is_array($TCA_DESCR[$table]['columns'][$field]))) {
226 // Make seeAlso references.
227 $seeAlsoRes = $this->make_seeAlso($TCA_DESCR[$table]['columns'][$field]['seeAlso'],$anchors?$table:'');
228
229 // Get Human Readable table and field labels
230 list($tableName,$fieldName) = $this->getTableFieldNames($table,$field);
231
232 // Making item:
233 $out= '<a name="'.$table.'.'.$field.'"></a>
234 '.
235 $this->headerLine($LANG->sL($tableName).': '.($field?ereg_replace(':$','',stripslashes(trim($LANG->sL($fieldName)))):''),1).
236 $this->prepareContent($TCA_DESCR[$table]['columns'][$field]['description']).
237 ($TCA_DESCR[$table]['columns'][$field]['details'] ? $this->headerLine($LANG->getLL('details').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['details']) : '').
238 ($TCA_DESCR[$table]['columns'][$field]['syntax'] ? $this->headerLine($LANG->getLL('syntax').':').$this->prepareContent($TCA_DESCR[$table]['columns'][$field]['syntax']) : '').
239 ($TCA_DESCR[$table]['columns'][$field]['image'] ? $this->printImage($TCA_DESCR[$table]['columns'][$field]['image'],$TCA_DESCR[$table]['columns'][$field]['image_descr']) : '').
240 ($TCA_DESCR[$table]['columns'][$field]['seeAlso'] && $seeAlsoRes ? $this->headerLine($LANG->getLL('seeAlso').':').'<p>'.$seeAlsoRes.'</p>' : '').
241 (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>' : '').
242 '<br />';
243 }
244 return $out;
245 }
246
247 /**
248 * Returns labels for $table and $field.
249 * If $table is "_MOD_" prefixed, the part after "_MOD_" is returned (non-tables, fx. modules)
250 */
251 function getTableFieldNames($table,$field) {
252 global $TCA, $TCA_DESCR;
253 $tableName = is_array($TCA_DESCR[$table]['columns']['']) && $TCA_DESCR[$table]['columns']['']['alttitle'] ?
254 $TCA_DESCR[$table]['columns']['']['alttitle'] :
255 (isset($TCA[$table]) ? $TCA[$table]['ctrl']['title'] : ereg_replace('^_MOD_','',$table));
256 $fieldName = is_array($TCA_DESCR[$table]['columns'][$field]) && $TCA_DESCR[$table]['columns'][$field]['alttitle'] ?
257 $TCA_DESCR[$table]['columns'][$field]['alttitle'] :
258 (isset($TCA[$table])&&isset($TCA[$table]['columns'][$field]) ? $TCA[$table]['columns'][$field]['label'] : $field);
259 return array($tableName,$fieldName);
260 }
261 }
262
263
264 // Include extension?
265 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/view_help.php']) {
266 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/view_help.php']);
267 }
268
269
270
271
272
273
274 // Make instance:
275 $SOBE = t3lib_div::makeInstance('SC_view_help');
276 $SOBE->init();
277 $SOBE->main();
278 $SOBE->printContent();
279 ?>