Fixed bug 4814: Umlauts error in AJAX Pagetree
[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('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 var $doc;
74 var $active_tempMountPoint = 0; // Temporary mount point (record), if any
75 var $backPath;
76
77 // Internal, static: GPvar:
78 var $ajax; // Is set, if an AJAX call should be handled.
79 var $currentSubScript;
80 var $cMR;
81 var $setTempDBmount; // If not '' (blank) then it will clear (0) or set (>0) Temporary DB mount.
82
83 /**
84 * Initialiation of the class
85 *
86 * @return void
87 */
88 function init() {
89 global $BE_USER,$BACK_PATH;
90
91 // Setting backPath
92 $this->backPath = $BACK_PATH;
93 $this->doc->backPath = $BACK_PATH;
94
95 // Setting GPvars:
96 $this->ajax = t3lib_div::_GP('ajax');
97 $this->cMR = t3lib_div::_GP('cMR');
98 $this->currentSubScript = t3lib_div::_GP('currentSubScript');
99 $this->setTempDBmount = t3lib_div::_GP('setTempDBmount');
100
101 // Create page tree object:
102 $this->pagetree = t3lib_div::makeInstance('webPageTree');
103 $this->pagetree->ext_IconMode = $BE_USER->getTSConfigVal('options.pageTree.disableIconLinkToContextmenu');
104 $this->pagetree->ext_showPageId = $BE_USER->getTSConfigVal('options.pageTree.showPageIdWithTitle');
105 $this->pagetree->thisScript = 'alt_db_navframe.php';
106 $this->pagetree->addField('alias');
107 $this->pagetree->addField('shortcut');
108 $this->pagetree->addField('shortcut_mode');
109 $this->pagetree->addField('mount_pid');
110 $this->pagetree->addField('mount_pid_ol');
111 $this->pagetree->addField('nav_hide');
112 $this->pagetree->addField('url');
113
114 // Temporary DB mounts:
115 $this->initializeTemporaryDBmount();
116
117 // Use template rendering only if this is a non-AJAX call:
118 if (!$this->ajax) {
119 // Setting highlight mode:
120 $this->doHighlight = !$BE_USER->getTSConfigVal('options.pageTree.disableTitleHighlight') && $BE_USER->workspace===0;
121
122 // Create template object:
123 $this->doc = t3lib_div::makeInstance('template');
124 $this->doc->docType = 'xhtml_trans';
125
126 // Adding javascript code for AJAX (prototype), drag&drop and the pagetree
127 $this->doc->JScode = '
128 <script type="text/javascript" src="'.$this->backPath.'prototype.js"></script>
129 <script type="text/javascript" src="'.$this->backPath.'tree.js"></script>'."\n";
130
131 $this->doc->JScode .= $this->doc->wrapScriptTags(
132 ($this->currentSubScript?'top.currentSubScript=unescape("'.rawurlencode($this->currentSubScript).'");':'').'
133 // setting prefs for pagetree and drag & drop
134 Tree.thisScript = "'.$this->pagetree->thisScript.'";
135 DragDrop.changeURL = "'.$this->backPath.'alt_clickmenu.php";
136 DragDrop.backPath = "'.t3lib_div::shortMD5(''.'|'.$GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey']).'";
137 DragDrop.table = "pages";
138
139 // Function, loading the list frame from navigation tree:
140 function jumpTo(id, linkObj, highlightID, bank) { //
141 var theUrl = top.TS.PATH_typo3 + top.currentSubScript + "?id=" + id;
142 top.fsMod.currentBank = bank;
143
144 if (top.condensedMode) top.content.location.href = theUrl;
145 else parent.list_frame.location.href=theUrl;
146
147 '.($this->doHighlight ? 'Tree.highlightActiveItem("web", highlightID + "_" + bank);' : '').'
148 '.(!$GLOBALS['CLIENT']['FORMSTYLE'] ? '' : 'if (linkObj) linkObj.blur(); ').'
149 return false;
150 }
151 '.($this->cMR?"jumpTo(top.fsMod.recentIds['web'],'');":'').'
152 ');
153
154 // Click menu code is added:
155 $CMparts=$this->doc->getContextMenuCode();
156 $this->doc->bodyTagAdditions = $CMparts[1];
157 $this->doc->JScode.= $CMparts[0];
158 $this->doc->postCode.= $CMparts[2];
159 }
160 }
161
162
163 /**
164 * Main function, rendering the browsable page tree
165 *
166 * @return void
167 */
168 function main() {
169 global $LANG,$CLIENT;
170
171 // Produce browse-tree:
172 $tree = $this->pagetree->getBrowsableTree();
173
174 // Output only the tree if this is an AJAX call:
175 if ($this->ajax) {
176 $this->content = $LANG->csConvObj->utf8_encode($tree, $LANG->charSet);
177 return;
178 }
179
180 // Start page:
181 $this->content = $this->doc->startPage('TYPO3 Page Tree');
182
183 // Outputting workspace info
184 if ($GLOBALS['BE_USER']->workspace!==0 || $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.onlineWorkspaceInfo')) {
185 switch($GLOBALS['BE_USER']->workspace) {
186 case 0:
187 $wsTitle = '&nbsp;'.$this->doc->icons(2).'['.$LANG->sL('LLL:EXT:lang/locallang_misc.xml:shortcut_onlineWS',1).']';
188 break;
189 case -1:
190 $wsTitle = '['.$LANG->sL('LLL:EXT:lang/locallang_misc.xml:shortcut_offlineWS',1).']';
191 break;
192 default:
193 $wsTitle = '['.$GLOBALS['BE_USER']->workspace.'] '.htmlspecialchars($GLOBALS['BE_USER']->workspaceRec['title']);
194 break;
195 }
196
197 $this->content.= '
198 <div class="bgColor4 workspace-info">'.
199 '<a href="'.htmlspecialchars('mod/user/ws/index.php').'" target="content">'.
200 '<img'.t3lib_iconWorks::skinImg('','gfx/i/sys_workspace.png','width="18" height="16"').' align="top" alt="" />'.
201 '</a>'.$wsTitle.'
202 </div>
203 ';
204 }
205
206 // Outputting Temporary DB mount notice:
207 if ($this->active_tempMountPoint) {
208 $this->content.= '
209 <div class="bgColor4 c-notice">
210 <img'.t3lib_iconWorks::skinImg('','gfx/icon_note.gif','width="18" height="16"').' align="top" alt="" />'.
211 '<a href="'.htmlspecialchars(t3lib_div::linkThisScript(array('setTempDBmount' => 0))).'">'.
212 $LANG->sl('LLL:EXT:lang/locallang_core.php:labels.temporaryDBmount',1).
213 '</a><br/>
214 '.$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>
215 </div>
216 ';
217 }
218
219 // Outputting page tree:
220 $this->content.= $tree;
221
222 // Outputting refresh-link
223 $this->content.= '
224 <p class="c-refresh">
225 <a href="'.htmlspecialchars(t3lib_div::getIndpEnv('REQUEST_URI')).'">'.
226 '<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="" />'.
227 $LANG->sL('LLL:EXT:lang/locallang_core.php:labels.refresh',1).'</a>
228 </p>
229 <br />';
230
231 // CSH icon:
232 $this->content.= t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'pagetree', $GLOBALS['BACK_PATH']);
233
234 // Adding javascript for drag & drop activation and highlighting
235 $this->content .=$this->doc->wrapScriptTags('
236 '.($this->doHighlight ? 'Tree.highlightActiveItem("",top.fsMod.navFrameHighlightedID["web"]);' : '').'
237 '.(!$this->doc->isCMlayers() ? 'Tree.activateDragDrop = false;' : 'Tree.registerDragDropHandlers();')
238 );
239 }
240
241 /**
242 * Outputting the accumulated content to screen
243 *
244 * @return void
245 */
246 function printContent() {
247 // If we handle an AJAX call, send headers:
248 if ($this->ajax) {
249 header('Content-type: text/html; charset=utf-8');
250 // If it's the regular call to fully output the tree:
251 } else {
252 $this->content.= $this->doc->endPage();
253 $this->content = $this->doc->insertStylesAndJS($this->content);
254 }
255 echo $this->content;
256 }
257
258
259
260
261
262 /**********************************
263 *
264 * Temporary DB mounts
265 *
266 **********************************/
267
268 /**
269 * Getting temporary DB mount
270 *
271 * @return void
272 */
273 function initializeTemporaryDBmount(){
274 global $BE_USER;
275
276 // Set/Cancel Temporary DB Mount:
277 if (strlen($this->setTempDBmount)) {
278 $set = t3lib_div::intInRange($this->setTempDBmount,0);
279 if ($set>0 && $BE_USER->isInWebMount($set)) { // Setting...:
280 $this->settingTemporaryMountPoint($set);
281 } else { // Clear:
282 $this->settingTemporaryMountPoint(0);
283 }
284 }
285
286 // Getting temporary mount point ID:
287 $temporaryMountPoint = intval($BE_USER->getSessionData('pageTree_temporaryMountPoint'));
288
289 // If mount point ID existed and is within users real mount points, then set it temporarily:
290 if ($temporaryMountPoint > 0 && $BE_USER->isInWebMount($temporaryMountPoint)) {
291 if ($this->active_tempMountPoint = t3lib_BEfunc::readPageAccess($temporaryMountPoint, $BE_USER->getPagePermsClause(1))) {
292 $this->pagetree->MOUNTS = array($temporaryMountPoint);
293 }
294 else {
295 // Clear temporary mount point as we have no access to it any longer
296 $this->settingTemporaryMountPoint(0);
297 }
298 }
299 }
300
301
302 /**
303 * Setting temporary page id as DB mount
304 *
305 * @param integer The page id to set as DB mount
306 * @return void
307 */
308 function settingTemporaryMountPoint($pageId) {
309 global $BE_USER;
310
311 // Setting temporary mount point ID:
312 $BE_USER->setAndSaveSessionData('pageTree_temporaryMountPoint',intval($pageId));
313 }
314 }
315
316
317 // Include extension?
318 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_db_navframe.php']) {
319 include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_db_navframe.php']);
320 }
321
322
323
324
325
326 // Make instance:
327 $SOBE = t3lib_div::makeInstance('SC_alt_db_navframe');
328 $SOBE->init();
329 $SOBE->main();
330 $SOBE->printContent();
331
332 ?>