Added feature #7124: Add some more functionality to new AJAX interface in the TYPO3...
[Packages/TYPO3.CMS.git] / typo3 / alt_db_navframe.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 * Page navigation tree for the Web module
29 *
30 * $Id$
31 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
32 * XHTML compliant
33 *
34 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
35 */
36 /**
37 * [CLASS/FUNCTION INDEX of SCRIPT]
38 *
39 *
40 * 192: class SC_alt_db_navframe
41 * 210: function init()
42 * 313: function main()
43 * 387: function printContent()
44 *
45 * SECTION: Temporary DB mounts
46 * 415: function initializeTemporaryDBmount()
47 * 449: function settingTemporaryMountPoint($pageId)
48 *
49 * TOTAL FUNCTIONS: 9
50 * (This index is automatically created/updated by the extension "extdeveval")
51 *
52 */
53
54
55 $BACK_PATH = '';
56 require_once('init.php');
57 require('template.php');
58 require_once('class.webpagetree.php');
59
60
61 /**
62 * Main script class for the page tree navigation frame
63 *
64 * @author Kasper Skaarhoj <kasperYYYY@typo3.com>
65 * @package TYPO3
66 * @subpackage core
67 */
68 class SC_alt_db_navframe {
69
70 // Internal:
71 var $content;
72 var $pagetree;
73
74 /**
75 * document template object
76 *
77 * @var template
78 */
79 var $doc;
80 var $active_tempMountPoint = 0; // Temporary mount point (record), if any
81 var $backPath;
82
83 // Internal, static: GPvar:
84 var $currentSubScript;
85 var $cMR;
86 var $setTempDBmount; // If not '' (blank) then it will clear (0) or set (>0) Temporary DB mount.
87
88
89 /**
90 * Initialiation of the class
91 *
92 * @return void
93 */
94 function init() {
95 global $BE_USER,$BACK_PATH;
96
97 // Setting backPath
98 $this->backPath = $BACK_PATH;
99
100 // Setting GPvars:
101 $this->cMR = t3lib_div::_GP('cMR');
102 $this->currentSubScript = t3lib_div::_GP('currentSubScript');
103 $this->setTempDBmount = t3lib_div::_GP('setTempDBmount');
104
105 // Create page tree object:
106 $this->pagetree = t3lib_div::makeInstance('webPageTree');
107 $this->pagetree->ext_IconMode = $BE_USER->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu');
108 $this->pagetree->ext_showPageId = $BE_USER->getTSConfigVal('options.pageTree.showPageIdWithTitle');
109 $this->pagetree->ext_showNavTitle = $BE_USER->getTSConfigVal('options.pageTree.showNavTitle');
110 $this->pagetree->ext_separateNotinmenuPages = $BE_USER->getTSConfigVal('options.pageTree.separateNotinmenuPages');
111 $this->pagetree->ext_alphasortNotinmenuPages = $BE_USER->getTSConfigVal('options.pageTree.alphasortNotinmenuPages');
112 $this->pagetree->thisScript = 'alt_db_navframe.php';
113 $this->pagetree->addField('alias');
114 $this->pagetree->addField('shortcut');
115 $this->pagetree->addField('shortcut_mode');
116 $this->pagetree->addField('mount_pid');
117 $this->pagetree->addField('mount_pid_ol');
118 $this->pagetree->addField('nav_hide');
119 $this->pagetree->addField('nav_title');
120 $this->pagetree->addField('url');
121
122 // Temporary DB mounts:
123 $this->initializeTemporaryDBmount();
124 }
125
126
127 /**
128 * initialization for the visual parts of the class
129 * Use template rendering only if this is a non-AJAX call
130 *
131 * @return void
132 */
133 public function initPage() {
134 global $BE_USER;
135
136 // Setting highlight mode:
137 $this->doHighlight = !$BE_USER->getTSConfigVal('options.pageTree.disableTitleHighlight');
138
139 // If highlighting is active, define the CSS class for the active item depending on the workspace
140 if ($this->doHighlight) {
141 $hlClass = ($BE_USER->workspace === 0 ? 'active' : 'active active-ws wsver'.$BE_USER->workspace);
142 }
143
144 // Create template object:
145 $this->doc = t3lib_div::makeInstance('template');
146 $this->doc->backPath = $BACK_PATH;
147 $this->doc->docType = 'xhtml_trans';
148
149
150 // Adding javascript code for AJAX (prototype), drag&drop and the pagetree as well as the click menu code
151 $this->doc->getDragDropCode('pages');
152 $this->doc->getContextMenuCode();
153
154
155 $this->doc->JScode .= $this->doc->wrapScriptTags(
156 ($this->currentSubScript?'top.currentSubScript=unescape("'.rawurlencode($this->currentSubScript).'");':'').'
157 // setting prefs for pagetree and drag & drop
158 '.($this->doHighlight ? 'Tree.highlightClass = "'.$hlClass.'";' : '').'
159
160 // Function, loading the list frame from navigation tree:
161 function jumpTo(id, linkObj, highlightID, bank) { //
162 var theUrl = top.TS.PATH_typo3 + top.currentSubScript + "?id=" + id;
163 top.fsMod.currentBank = bank;
164
165 if (top.condensedMode) top.content.location.href = theUrl;
166 else parent.list_frame.location.href=theUrl;
167
168 '.($this->doHighlight ? 'Tree.highlightActiveItem("web", highlightID + "_" + bank);' : '').'
169 '.(!$GLOBALS['CLIENT']['FORMSTYLE'] ? '' : 'if (linkObj) linkObj.blur(); ').'
170 return false;
171 }
172 '.($this->cMR?"jumpTo(top.fsMod.recentIds['web'],'');":'').'
173 ');
174
175 $this->doc->bodyTagId = 'bodyTag';
176 }
177
178
179 /**
180 * Main function, rendering the browsable page tree
181 *
182 * @return void
183 */
184 function main() {
185 global $LANG,$CLIENT;
186
187 // Produce browse-tree:
188 $tree = $this->pagetree->getBrowsableTree();
189
190 // Start page:
191 $this->content = $this->doc->startPage('TYPO3 Page Tree');
192
193 // Outputting workspace info
194 if ($GLOBALS['BE_USER']->workspace!==0 || $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.onlineWorkspaceInfo')) {
195 switch($GLOBALS['BE_USER']->workspace) {
196 case 0:
197 $wsTitle = '&nbsp;'.$this->doc->icons(2).'['.$LANG->sL('LLL:EXT:lang/locallang_misc.xml:shortcut_onlineWS',1).']';
198 break;
199 case -1:
200 $wsTitle = '['.$LANG->sL('LLL:EXT:lang/locallang_misc.xml:shortcut_offlineWS',1).']';
201 break;
202 default:
203 $wsTitle = '['.$GLOBALS['BE_USER']->workspace.'] '.htmlspecialchars($GLOBALS['BE_USER']->workspaceRec['title']);
204 break;
205 }
206
207 $this->content.= '
208 <div class="bgColor4 workspace-info">'.
209 '<a href="'.htmlspecialchars('mod/user/ws/index.php').'" target="content">'.
210 '<img'.t3lib_iconWorks::skinImg('','gfx/i/sys_workspace.png','width="18" height="16"').' align="top" alt="" />'.
211 '</a>'.$wsTitle.'
212 </div>
213 ';
214 }
215
216 if (!$GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.hideFilter')) {
217 $this->content.= '
218 <div class="bgColor4">
219 Filter: <input type="text" value="" name="_livesearch" id="_livesearch" onkeyup="filter(this.value);"/>
220 </div><br>
221 ';
222 }
223
224 // Outputting Temporary DB mount notice:
225 if ($this->active_tempMountPoint) {
226 $this->content.= '
227 <div class="bgColor4 c-notice">
228 <img'.t3lib_iconWorks::skinImg('','gfx/icon_note.gif','width="18" height="16"').' align="top" alt="" />'.
229 '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('setTempDBmount' => 0))).'">'.
230 $LANG->sl('LLL:EXT:lang/locallang_core.php:labels.temporaryDBmount',1).
231 '</a><br/>
232 '.$LANG->sl('LLL:EXT:lang/locallang_core.php:labels.path',1).': <span title="'.htmlspecialchars($this->active_tempMountPoint['_thePathFull']).'">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($this->active_tempMountPoint['_thePath'],-50)).'</span>
233 </div>
234 ';
235 }
236
237 // Outputting page tree:
238 $this->content.= $tree;
239
240 // Outputting refresh-link
241 $this->content.= '
242 <p class="c-refresh">
243 <a href="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'">'.
244 '<img'.t3lib_iconWorks::skinImg('','gfx/refresh_n.gif','width="14" height="14"').' title="'.$LANG->sL('LLL:EXT:lang/locallang_core.php:labels.refresh',1).'" alt="" />'.
245 $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.refresh',1).'</a>
246 </p>
247 <br />';
248
249 // CSH icon:
250 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'pagetree', $GLOBALS['BACK_PATH']);
251
252 // Adding javascript for drag & drop activation and highlighting
253 $this->content .= $this->doc->wrapScriptTags('
254 '.($this->doHighlight ? 'Tree.highlightActiveItem("",top.fsMod.navFrameHighlightedID["web"]);' : '').'
255 '.(!$this->doc->isCMlayers() ? 'Tree.activateDragDrop = false;' : 'Tree.registerDragDropHandlers();')
256 );
257 }
258
259 /**
260 * Outputting the accumulated content to screen
261 *
262 * @return void
263 */
264 function printContent() {
265 $this->content.= $this->doc->endPage();
266 $this->content = $this->doc->insertStylesAndJS($this->content);
267 echo $this->content;
268 }
269
270
271
272
273
274 /**********************************
275 *
276 * Temporary DB mounts
277 *
278 **********************************/
279
280 /**
281 * Getting temporary DB mount
282 *
283 * @return void
284 */
285 function initializeTemporaryDBmount(){
286 global $BE_USER;
287
288 // Set/Cancel Temporary DB Mount:
289 if (strlen($this->setTempDBmount)) {
290 $set = t3lib_div::intInRange($this->setTempDBmount,0);
291 if ($set>0 && $BE_USER->isInWebMount($set)) { // Setting...:
292 $this->settingTemporaryMountPoint($set);
293 } else { // Clear:
294 $this->settingTemporaryMountPoint(0);
295 }
296 }
297
298 // Getting temporary mount point ID:
299 $temporaryMountPoint = intval($BE_USER->getSessionData('pageTree_temporaryMountPoint'));
300
301 // If mount point ID existed and is within users real mount points, then set it temporarily:
302 if ($temporaryMountPoint > 0 && $BE_USER->isInWebMount($temporaryMountPoint)) {
303 if ($this->active_tempMountPoint = t3lib_BEfunc::readPageAccess($temporaryMountPoint, $BE_USER->getPagePermsClause(1))) {
304 $this->pagetree->MOUNTS = array($temporaryMountPoint);
305 }
306 else {
307 // Clear temporary mount point as we have no access to it any longer
308 $this->settingTemporaryMountPoint(0);
309 }
310 }
311 }
312
313
314 /**
315 * Setting temporary page id as DB mount
316 *
317 * @param integer The page id to set as DB mount
318 * @return void
319 */
320 function settingTemporaryMountPoint($pageId) {
321 $GLOBALS['BE_USER']->setAndSaveSessionData('pageTree_temporaryMountPoint',intval($pageId));
322 }
323
324
325 /**********************************
326 *
327 * AJAX Calls
328 *
329 **********************************/
330
331 /**
332 * Makes the AJAX call to expand or collapse the pagetree.
333 * Called by typo3/ajax.php
334 *
335 * @param array $params: additional parameters (not used here)
336 * @param TYPO3AJAX &$ajaxObj: reference of the TYPO3AJAX object of this request
337 * @return void
338 */
339 public function ajaxExpandCollapse($params, &$ajaxObj) {
340 global $LANG;
341
342 $this->init();
343 $tree = $this->pagetree->getBrowsableTree();
344 if (!$this->pagetree->ajaxStatus) {
345 $ajaxObj->setError($tree);
346 } else {
347 $ajaxObj->addContent('tree', $tree);
348 }
349 }
350 }
351
352
353 // Include extension?
354 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_db_navframe.php']) {
355 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_db_navframe.php']);
356 }
357
358
359 // Make instance if it is not an AJAX call
360 if (!(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX)) {
361 $SOBE = t3lib_div::makeInstance('SC_alt_db_navframe');
362 $SOBE->init();
363 $SOBE->initPage();
364 $SOBE->main();
365 $SOBE->printContent();
366 }
367
368 ?>