(feature/cleanup) Refactored clickmenu to speed up the BE
[Packages/TYPO3.CMS.git] / typo3 / sysext / tstemplate / ts / index.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@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 * Module: TypoScript Tools
29 *
30 *
31 * $TYPO3_CONF_VARS["MODS"]["web_ts"]["onlineResourceDir"] = Directory of default resources. Eg. "fileadmin/res/" or so.
32 *
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36
37
38
39 unset($MCONF);
40 require ("conf.php");
41 require ($BACK_PATH."init.php");
42 require ($BACK_PATH."template.php");
43 require_once (PATH_t3lib."class.t3lib_page.php");
44 require_once (PATH_t3lib."class.t3lib_tstemplate.php");
45 require_once (PATH_t3lib."class.t3lib_tsparser_ext.php");
46
47 require_once (PATH_t3lib."class.t3lib_scbase.php");
48
49 $BE_USER->modAccess($MCONF,1);
50
51
52 // ***************************
53 // Script Classes
54 // ***************************
55 class SC_mod_web_ts_index extends t3lib_SCbase {
56 var $perms_clause;
57 var $e;
58 var $sObj;
59 var $edit;
60 var $textExtensions = 'html,htm,txt,css,tmpl,inc,js';
61
62 var $modMenu_type = '';
63 var $modMenu_dontValidateList = '';
64 var $modMenu_setDefaultList = '';
65
66 function init() {
67 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
68
69 parent::init();
70
71 $this->id = intval(t3lib_div::_GP("id"));
72 $this->e = t3lib_div::_GP("e");
73 $this->sObj = t3lib_div::_GP("sObj");
74 $this->edit = t3lib_div::_GP("edit");
75
76 $this->perms_clause = $BE_USER->getPagePermsClause(1);
77
78 if (t3lib_div::_GP("clear_all_cache")) {
79 $this->include_once[]=PATH_t3lib."class.t3lib_tcemain.php";
80 }
81 }
82 function clearCache() {
83 if (t3lib_div::_GP("clear_all_cache")) {
84 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
85 $tce->stripslashes_values=0;
86 $tce->start(Array(),Array());
87 $tce->clear_cacheCmd("all");
88 }
89 }
90 function main() {
91 global $BE_USER,$LANG,$BACK_PATH,$TCA_DESCR,$TCA,$CLIENT,$TYPO3_CONF_VARS;
92
93 // Access check...
94 // The page will show only if there is a valid page and if this page may be viewed by the user
95 $pageinfo = t3lib_BEfunc::readPageAccess($this->id,$this->perms_clause);
96 $access = is_array($pageinfo) ? 1 : 0;
97
98 if ($this->id && $access) {
99 $this->doc = t3lib_div::makeInstance("template");
100 $this->doc->backPath = $BACK_PATH;
101
102
103 // JavaScript
104 $this->doc->JScode = '
105 <script language="javascript" type="text/javascript">
106 script_ended = 0;
107 function jumpToUrl(URL) {
108 window.location.href = URL;
109 }
110 function uFormUrl(aname) {
111 document.forms[0].action = "index.php?id='.$this->id.'#"+aname;
112 }
113 function brPoint(lnumber,t) {
114 window.location.href = "index.php?id='.$this->id.'&SET[function]=tx_tstemplateobjbrowser&SET[ts_browser_type]="+(t?"setup":"const")+"&breakPointLN="+lnumber;
115 return false;
116 }
117 </script>
118 ';
119
120 $this->doc->postCode='
121 <script language="javascript" type="text/javascript">
122 script_ended = 1;
123 if (top.fsMod) top.fsMod.recentIds["web"] = '.intval($this->id).';
124 </script>
125 ';
126
127 $this->doc->inDocStylesArray[] = '
128 TABLE#typo3-objectBrowser A { text-decoration: none; }
129 TABLE#typo3-objectBrowser .comment { color: maroon; font-weight: bold; }
130 ';
131
132
133 // Setting up the context sensitive menu:
134 $this->doc->getContextMenuCode();
135
136
137 $headerSection = $this->doc->getHeader("pages",$pageinfo,$pageinfo["_thePath"]).'<br>'.
138 $LANG->sL("LLL:EXT:lang/locallang_core.php:labels.path").': '.
139 '<span title="'.htmlspecialchars($pageinfo['_thePathFull']).'">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($pageinfo['_thePath'],-50)).'</span>';
140
141 // Draw the header.
142 $this->doc->form='<form action="index.php?id='.$this->id.'" method="post" enctype="'.$GLOBALS["TYPO3_CONF_VARS"]["SYS"]["form_enctype"].'" name="editForm">';
143 $this->content.=$this->doc->startPage("Template Tools");
144 $this->content.=$this->doc->header("Template Tools");
145 $this->content.=$this->doc->spacer(5);
146 $this->content.=$this->doc->section('',$this->doc->funcMenu($headerSection,t3lib_BEfunc::getFuncMenu($this->id,"SET[function]",$this->MOD_SETTINGS["function"],$this->MOD_MENU["function"])));
147
148
149 $this->extObjContent();
150
151
152
153 // ShortCut
154 if ($BE_USER->mayMakeShortcut()) {
155 $this->content.=$this->doc->spacer(20).$this->doc->section('',$this->doc->makeShortcutIcon("id,e,sObj,template","function,ts_browser_type,constant_editor_cat",$this->MCONF["name"]));
156 }
157 $this->content.=$this->doc->spacer(10);
158 } else {
159 // If no access or if ID == zero
160
161 $this->doc = t3lib_div::makeInstance("mediumDoc");
162 $this->doc->backPath = $BACK_PATH;
163
164 $this->content.=$this->doc->startPage("Template Tools");
165 $this->content.=$this->doc->header("Template Tools");
166 $this->content.=$this->doc->spacer(5);
167
168
169 // Template pages:
170 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
171 'pages.uid, count(*) AS count, max(sys_template.root) AS root_max_val, min(sys_template.root) AS root_min_val',
172 'pages,sys_template',
173 'pages.uid=sys_template.pid'.
174 t3lib_BEfunc::deleteClause('pages').
175 t3lib_BEfunc::versioningPlaceholderClause('pages').
176 t3lib_BEfunc::deleteClause('sys_template').
177 t3lib_BEfunc::versioningPlaceholderClause('sys_template'),
178 'pages.uid'
179 );
180 $templateArray = array();
181 $pArray = array();
182 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
183 $this->setInPageArray(
184 $pArray,
185 t3lib_BEfunc::BEgetRootLine ($row["uid"],"AND 1=1"),
186 $row
187 );
188 }
189
190 $lines = array();
191 $lines[] = '<tr class="bgColor5">
192 <td nowrap><strong>Page name</strong></td>
193 <td nowrap><strong># Templates</strong></td>
194 <td nowrap><strong>Is Root?</strong></td>
195 <td nowrap><strong>Is Ext?</strong></td>
196 </tr>';
197 $lines = array_merge($lines,$this->renderList($pArray));
198
199 $table = '<table border=0 cellpadding=0 cellspacing=1>'.implode("",$lines).'</table>';
200 $this->content.= $this->doc->section("",'
201 <BR>
202 This is an overview of the pages in the database containing one or more template records. Click a page title to go to the page.
203 <BR><BR>
204 '.$table);
205 // debug($pArray);
206 // ********************************************
207 // RENDER LIST of pages with templates, END
208 // ********************************************
209
210
211
212 // ShortCut
213 if ($BE_USER->mayMakeShortcut()) {
214 $this->content.=$this->doc->spacer(20).$this->doc->section('',$this->doc->makeShortcutIcon("id","",$this->MCONF["name"]));
215 }
216
217 $this->content.=$this->doc->spacer(10);
218 }
219 }
220 function printContent() {
221
222 $this->content.=$this->doc->endPage();
223 echo $this->content;
224 }
225
226 // ***************************
227 // OTHER FUNCTIONS:
228 // ***************************
229 function getCountCacheTables($humanReadable) {
230 $out=array();
231
232 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'cache_pages', '');
233 list($out["cache_pages"]) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
234
235 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'cache_pagesection', '');
236 list($out["cache_pagesection"]) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
237
238 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('count(*)', 'cache_hash', '');
239 list($out["cache_hash"]) = $GLOBALS['TYPO3_DB']->sql_fetch_row($res);
240
241 if ($humanReadable) {
242 $newOut=array();
243 reset($out);
244 while(list($k,$v)=each($out)) {
245 $newOut[]=$k.":".$v;
246 }
247 $out=implode($newOut,", ");
248 }
249 return $out;
250 }
251
252 function linkWrapTemplateTitle($title,$onlyKey="") {
253 if ($onlyKey) {
254 $title = '<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&e['.$onlyKey.']=1&SET[function]=tx_tstemplateinfo">'.htmlspecialchars($title).'</a>';
255 } else {
256 $title = '<a href="index.php?id='.$GLOBALS["SOBE"]->id.'&e[constants]=1&e[config]=1&SET[function]=tx_tstemplateinfo">'.htmlspecialchars($title).'</a>';
257 }
258 return $title;
259 }
260 function noTemplate($newStandardTemplate=0) {
261 global $SOBE;
262
263 $tmpl = t3lib_div::makeInstance("t3lib_tsparser_ext"); // Defined global here!
264 $tmpl->tt_track = 0; // Do not log time-performance information
265 $tmpl->init();
266
267 $confirm = ' onClick="return confirm(\'Are you sure you want to do this?\');"';
268
269 // No template
270 $theOutput.=$this->doc->spacer(10);
271 $theOutput.=$this->doc->section('<span class="typo3-red">No template</span>',"There was no template on this page!<BR>Create a template record first in order to edit constants!",0,0,0,1);
272 // New standard?
273 if ($newStandardTemplate) {
274 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('title,uid', 'static_template', '', '', 'title');
275 $opt = "";
276 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
277 if (substr(trim($row["title"]),0,8)=="template") {
278 $opt.='<option value="'.$row["uid"].'">'.htmlspecialchars($row["title"]).'</option>';
279 }
280 }
281 $selector = '<select name="createStandard"><option></option>'.$opt.'</select>';
282 // Extension?
283 $theOutput.=$this->doc->spacer(10);
284 $theOutput.=$this->doc->section("Create new website",'If you want this page to be the root of a new website, optionally based on one of the standard templates, then press the button below:<BR>
285 <BR>
286 '.$selector.'<BR>
287 <img src="'.$GLOBALS["BACK_PATH"].'gfx/icon_warning.gif" width=18 height=16 hspace=5 align=top><input type="Submit" name="newWebsite" value="Create template for a new site"'.$confirm.'>',0,1);
288 }
289 // Extension?
290 $theOutput.=$this->doc->spacer(10);
291 $theOutput.=$this->doc->section("Create extension template",'An extension template allows you to enter TypoScript values that will affect only this page and subpages.<BR><BR><img src="'.$GLOBALS["BACK_PATH"].'gfx/icon_warning.gif" width=18 height=16 hspace=5 align=top><input type="submit" name="createExtension" value="Click here to create an extension template."'.$confirm.'>',0,1);
292
293 // Go to first appearing...
294 $first = $tmpl->ext_prevPageWithTemplate($this->id,$this->perms_clause);
295 if ($first) {
296 $theOutput.=$this->doc->spacer(10);
297 $theOutput.=$this->doc->section("Go to closest page with template",sprintf("Closest template is on page '%s' (uid %s).<BR><BR>%s<strong>Click here to go.</strong>%s",$first["title"],$first["uid"],'<a href="index.php?id='.$first["uid"].'">','</a>'),0,1);
298 }
299 return $theOutput;
300 }
301 function templateMenu() {
302 $tmpl = t3lib_div::makeInstance("t3lib_tsparser_ext"); // Defined global here!
303 $tmpl->tt_track = 0; // Do not log time-performance information
304 $tmpl->init();
305 $all = $tmpl->ext_getAllTemplates($this->id,$this->perms_clause);
306 $menu='';
307 if (count($all)>1) {
308 $this->MOD_MENU['templatesOnPage']=array();
309 foreach($all as $d) {
310 $this->MOD_MENU['templatesOnPage'][$d['uid']] = $d['title'];
311 }
312 }
313
314 $this->MOD_SETTINGS = t3lib_BEfunc::getModuleData($this->MOD_MENU, t3lib_div::_GP('SET'), $this->MCONF['name'], $this->modMenu_type, $this->modMenu_dontValidateList, $this->modMenu_setDefaultList);
315 $menu = t3lib_BEfunc::getFuncMenu($this->id,'SET[templatesOnPage]',$this->MOD_SETTINGS['templatesOnPage'],$this->MOD_MENU['templatesOnPage']);
316
317 return $menu;
318 }
319 function createTemplate($id) {
320 if (t3lib_div::_GP("createExtension")) {
321 require_once (PATH_t3lib."class.t3lib_tcemain.php");
322 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
323 $tce->stripslashes_values=0;
324 $recData=array();
325 $recData["sys_template"]["NEW"] = array(
326 "pid" => $id,
327 "title" => "+ext",
328 "sorting" => time()
329 );
330 $tce->start($recData,Array());
331 $tce->process_datamap();
332 } elseif (t3lib_div::_GP("newWebsite")) {
333 require_once (PATH_t3lib."class.t3lib_tcemain.php");
334 $tce = t3lib_div::makeInstance("t3lib_TCEmain");
335 $tce->stripslashes_values=0;
336 $recData=array();
337 if (intval(t3lib_div::_GP("createStandard"))) {
338 $staticT = intval(t3lib_div::_GP("createStandard"));
339 $recData["sys_template"]["NEW"] = array(
340 "pid" => $id,
341 "title" => "NEW SITE, based on standard",
342 "sorting" => 0,
343 "root" => 1,
344 "clear" => 3,
345 "include_static" => $staticT.",57" // 57 is cSet
346 );
347 } else {
348 $recData["sys_template"]["NEW"] = array(
349 "pid" => $id,
350 "title" => "NEW SITE",
351 "sorting" => 0,
352 "root" => 1,
353 "clear" => 3,
354 "config" => '
355 # Default PAGE object:
356 page = PAGE
357 page.10 = TEXT
358 page.10.value = HELLO WORLD!
359 '
360 );
361 }
362 $tce->start($recData,Array());
363 $tce->process_datamap();
364 $tce->clear_cacheCmd("all");
365 }
366 }
367 // ********************************************
368 // RENDER LIST of pages with templates, BEGIN
369 // ********************************************
370 function setInPageArray(&$pArray,$rlArr,$row) {
371 ksort($rlArr);
372 reset($rlArr);
373 if (!$rlArr[0]["uid"]) array_shift($rlArr);
374
375 $cEl = current($rlArr);
376 $pArray[$cEl["uid"]]=$cEl["title"];
377 array_shift($rlArr);
378 if (count($rlArr)) {
379 if (!isset($pArray[$cEl["uid"]."."])) $pArray[$cEl["uid"]."."]=array();
380 $this->setInPageArray($pArray[$cEl["uid"]."."],$rlArr,$row);
381 } else {
382 $pArray[$cEl["uid"]."_"]=$row;
383 }
384 }
385 function renderList($pArray,$lines=array(),$c=0) {
386 if (is_array($pArray)) {
387 reset($pArray);
388 while(list($k,$v)=each($pArray)) {
389 if (t3lib_div::testInt($k)) {
390 if (isset($pArray[$k."_"])) {
391 $lines[]='<tr class="bgColor4">
392 <td nowrap><img src=clear.gif width=1 height=1 hspace='.($c*10).' align=top>'.
393 '<a href="'.t3lib_div::linkThisScript(array("id"=>$k)).'">'.
394 t3lib_iconWorks::getIconImage("pages",t3lib_BEfunc::getRecordWSOL("pages",$k),$GLOBALS["BACK_PATH"],' align="top" title="ID: '.$k.'"').
395 t3lib_div::fixed_lgd_cs($pArray[$k],30).'</a></td>
396 <td align=center>'.$pArray[$k."_"]["count"].'</td>
397 <td align=center>'.($pArray[$k."_"]["root_max_val"]>0?"x":"&nbsp;").'</td>
398 <td align=center>'.($pArray[$k."_"]["root_min_val"]==0?"x":"&nbsp;").'</td>
399 </tr>';
400 } else {
401 $lines[]='<tr>
402 <td nowrap colspan=3><img src=clear.gif width=1 height=1 hspace='.($c*10).' align=top>'.
403 t3lib_iconWorks::getIconImage("pages",t3lib_BEfunc::getRecordWSOL("pages",$k),$GLOBALS["BACK_PATH"]," align=top").
404 t3lib_div::fixed_lgd_cs($pArray[$k],30).'</td>
405 </tr>';
406 }
407 $lines=$this->renderList($pArray[$k."."],$lines,$c+1);
408 }
409 }
410 }
411 return $lines;
412 }
413 }
414
415 // Include extension?
416 if (defined("TYPO3_MODE") && $TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate/ts/index.php"]) {
417 include_once($TYPO3_CONF_VARS[TYPO3_MODE]["XCLASS"]["ext/tstemplate/ts/index.php"]);
418 }
419
420
421
422
423
424
425
426
427
428
429
430
431 // Make instance:
432 $SOBE = t3lib_div::makeInstance("SC_mod_web_ts_index");
433 $SOBE->init();
434
435 // Include files?
436 foreach($SOBE->include_once as $INC_FILE) include_once($INC_FILE);
437 $SOBE->checkExtObj(); // Checking for first level external objects
438
439 $SOBE->clearCache();
440 $SOBE->main();
441 $SOBE->printContent();
442 ?>