2 /***************************************************************
5 * (c) 1999-2004 Kasper Skaarhoj (kasper@typo3.com)
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.
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.
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.
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
29 * Appears in the bottom frame of the backend frameset.
30 * Provides links to registered shortcuts
31 * If the 'cms' extension is loaded you will also have a field for entering page id/alias which will be found/edited
34 * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
35 * XHTML compliant output
37 * @author Kasper Skaarhoj <kasper@typo3.com>
40 * [CLASS/FUNCTION INDEX of SCRIPT]
44 * 82: class SC_alt_shortcut
45 * 118: function preinit()
46 * 143: function preprocess()
47 * 200: function init()
48 * 248: function main()
49 * 346: function editLoadedFunc()
50 * 407: function editPageIdFunc()
51 * 450: function printContent()
53 * SECTION: OTHER FUNCTIONS:
54 * 478: function mIconFilename($Ifilename,$backPath)
55 * 491: function getIcon($modName)
56 * 515: function itemLabel($inlabel,$modName,$M_modName='')
59 * (This index is automatically created/updated by the extension "extdeveval")
65 require ('template.php');
66 include ('sysext/lang/locallang_misc.php');
67 require_once (PATH_t3lib
.'class.t3lib_loadmodules.php');
68 require_once (PATH_t3lib
.'class.t3lib_basicfilefunc.php');
76 * Script Class for the shortcut frame, bottom frame of the backend frameset
78 * @author Kasper Skaarhoj <kasper@typo3.com>
82 class SC_alt_shortcut
{
84 // Internal, static: GPvar
96 var $loadModules; // Modules object
97 var $doc; // Document template object
98 var $nGroups; // Number of groups
99 var $nGlobals; // Number of globals
101 // Internal, dynamic:
102 var $content; // Accumulation of output HTML (string)
103 var $lines; // Accumulation of table cells (array)
105 var $editLoaded; // Flag for defining whether we are editing
106 var $editError; // Can contain edit error message
107 var $editSC_rec; // Holds the shortcut record when editing
108 var $theEditRec; // Page record to be edited
109 var $editPage; // Page alias or id to be edited
110 var $selOpt; // Select options.
114 * Pre-initialization - setting input variables for storing shortcuts etc.
122 $this->modName
= t3lib_div
::_GP('modName');
123 $this->M_modName
= t3lib_div
::_GP('motherModName');
124 $this->URL
= t3lib_div
::_GP('URL');
125 $this->editSC
= t3lib_div
::_GP('editShortcut');
127 $this->deleteCategory
= t3lib_div
::_GP('deleteCategory');
128 $this->editPage
= t3lib_div
::_GP('editPage');
129 $this->editName
= t3lib_div
::_GP('editName');
130 $this->editGroup
= t3lib_div
::_GP('editGroup');
131 $this->whichItem
= t3lib_div
::_GP('whichItem');
133 // Creating modules object
134 $this->loadModules
= t3lib_div
::makeInstance('t3lib_loadModules');
135 $this->loadModules
->load($TBE_MODULES);
139 * Adding shortcuts, editing shortcuts etc.
143 function preprocess() {
144 global $BE_USER,$HTTP_POST_VARS;
146 // Adding a shortcut being set from another frame
147 if ($this->modName
&& $this->URL
) {
148 $fields_values = array(
149 'userid' => $BE_USER->user
['uid'],
150 'module_name' => $this->modName
.'|'.$this->M_modName
,
154 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_be_shortcuts', $fields_values);
157 // Selection-clause for users - so users can deleted only their own shortcuts (except admins)
158 $addUSERWhere = (!$BE_USER->isAdmin()?
' AND userid='.intval($BE_USER->user
['uid']):'');
160 // Deleting shortcuts:
161 if (strcmp($this->deleteCategory
,'')) {
162 if (t3lib_div
::testInt($this->deleteCategory
)) {
163 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'sc_group='.intval($this->deleteCategory
).$addUSERWhere);
167 // If other changes in post-vars:
168 if (is_array($HTTP_POST_VARS)) {
170 if (isset($HTTP_POST_VARS['_savedok_x']) ||
isset($HTTP_POST_VARS['_saveclosedok_x'])) {
171 $fields_values = array(
172 'description' => $this->editName
,
173 'sc_group' => intval($this->editGroup
)
175 if ($fields_values['sc_group']<0 && !$BE_USER->isAdmin()) {
176 $fields_values['sc_group']=0;
179 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_be_shortcuts', 'uid='.intval($this->whichItem
).$addUSERWhere, $fields_values);
181 // If save without close, keep the session going...
182 if (isset($HTTP_POST_VARS['_savedok_x'])) {
183 $this->editSC
=$this->whichItem
;
185 // Deleting a single shortcut ?
186 if (isset($HTTP_POST_VARS['_deletedok_x'])) {
187 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'uid='.intval($this->whichItem
).$addUSERWhere);
189 if (!$this->editSC
) $this->editSC
=-1; // Just to have the checkbox set...
196 * Initialize (page output)
203 // If another page module was specified, replace the default Page module with the new one
204 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
205 $pageModule = t3lib_BEfunc
::isModuleSetInTBE_MODULES($newPageModule) ?
$newPageModule : 'web_layout';
207 $this->doc
= t3lib_div
::makeInstance('template');
208 $this->doc
->backPath
= $BACK_PATH;
209 $this->doc
->form
='<form action="alt_shortcut.php" name="shForm" method="post">';
210 $this->doc
->docType
='xhtml_trans';
211 $this->doc
->divClass
='typo3-shortcut';
212 $this->doc
->JScode
.=$this->doc
->wrapScriptTags('
213 function jump(url,modName,mainModName) { //
214 // Clear information about which entry in nav. tree that might have been highlighted.
215 top.fsMod.navFrameHighlightedID = new Array();
216 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
217 top.content.nav_frame.refresh_nav();
220 top.nextLoadModuleUrl = url;
221 top.goToModule(modName);
223 function editSh(uid) { //
224 document.location="alt_shortcut.php?editShortcut="+uid;
226 function submitEditPage(id) { //
227 document.location="alt_shortcut.php?editPage="+top.rawurlencode(id);
229 function loadEditId(id) { //
230 top.fsMod.recentIds["web"]=id;
231 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_0"; // For highlighting
233 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
234 top.content.nav_frame.refresh_nav();
237 top.goToModule("'.$pageModule.'");
240 $this->content
.=$this->doc
->startPage('Shortcut frame');
244 * Main function, creating content in the frame
249 global $BE_USER,$LANG;
251 // Setting groups and globals
255 $globalGroups=array(-100);
256 $shortCutGroups = $BE_USER->getTSConfig('options.shortcutGroups');
257 for($a=1;$a<=$this->nGlobals
;$a++
) {
258 if ($BE_USER->isAdmin() ||
strcmp($shortCutGroups['properties'][$a],'')) {
263 // Fetching shortcuts to display for this user:
264 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_be_shortcuts', '((userid='.$BE_USER->user
['uid'].' AND sc_group>=0) OR sc_group IN ('.implode(',',$globalGroups).'))', '', 'sc_group,sorting');
267 $this->lines
=array();
268 $this->editSC_rec
='';
269 $this->selOpt
=array();
272 // Traverse shortcuts
273 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
274 if ($this->editSC
&& $row['uid']==$this->editSC
) {
275 $this->editSC_rec
=$row;
278 if (strcmp($formerGr,$row['sc_group'])) {
279 if ($row['sc_group']!=-100) {
280 if ($row['sc_group']>=0) {
281 $onC = 'if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL('shortcut_delAllInCat')).')){document.location=\'alt_shortcut.php?deleteCategory='.$row['sc_group'].'\';}return false;';
282 $this->lines
[]='<td> </td><td class="bgColor5"><a href="#" onclick="'.htmlspecialchars($onC).'" title="'.$LANG->getLL('shortcut_delAllInCat',1).'">'.abs($row['sc_group']).'</a></td>';
284 $this->lines
[]='<td> </td><td class="bgColor5">'.abs($row['sc_group']).'</td>';
289 $mParts = explode('|',$row['module_name']);
290 $row['module_name']=$mParts[0];
291 $row['M_module_name']=$mParts[1];
292 $mParts = explode('_',$row['M_module_name']?
$row['M_module_name']:$row['module_name']);
293 $qParts = parse_url($row['url']);
295 $bgColorClass = $row['uid']==$this->editSC ?
'bgColor5' : ($row['sc_group']<0 ?
'bgColor6' : 'bgColor4');
296 $titleA = $this->itemLabel($row['description']&&($row['uid']!=$this->editSC
) ?
$row['description'] : t3lib_div
::fixed_lgd(rawurldecode($qParts['query']),150),$row['module_name'],$row['M_module_name']);
298 $editSH = ($row['sc_group']>=0 ||
$BE_USER->isAdmin()) ?
'editSh('.intval($row['uid']).');' : "alert('".$LANG->getLL('shortcut_onlyAdmin')."')";
299 $jumpSC = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$mParts).'\',\''.$mParts[0].'\');';
300 $onC = 'if (document.shForm.editShortcut_check && document.shForm.editShortcut_check.checked){'.$editSH.'}else{'.$jumpSC.'}return false;';
301 $this->lines
[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
302 if (trim($row['description'])) {
303 $kkey = strtolower(substr($row['description'],0,20)).'_'.$row['uid'];
304 $this->selOpt
[$kkey]='<option value="'.htmlspecialchars($jumpSC).'">'.htmlspecialchars(t3lib_div
::fixed_lgd($row['description'],50)).'</option>';
306 $formerGr=$row['sc_group'];
308 ksort($this->selOpt
);
309 array_unshift($this->selOpt
,'<option>['.$LANG->getLL('shortcut_selSC',1).']</option>');
311 $this->editLoadedFunc();
312 $this->editPageIdFunc();
314 if (!$this->editLoaded
&& t3lib_extMgm
::isLoaded('cms')) {
315 $editIdCode = '<td nowrap="nowrap">'.$LANG->getLL('shortcut_editID',1).': <input type="text" value="'.($this->editError?
htmlspecialchars($this->editPage
):'').'" name="editPage"'.$this->doc
->formWidth(5).' onchange="submitEditPage(this.value);" />'.
316 ($this->editError?
' <strong><span class="typo3-red">'.htmlspecialchars($this->editError
).'</span></strong>':'').
317 (is_array($this->theEditRec
)?
' <strong>'.$LANG->getLL('shortcut_loadEdit',1).' \''.t3lib_BEfunc
::getRecordTitle('pages',$this->theEditRec
,1).'\'</strong>':'').
319 } else $editIdCode='';
325 Shortcut Display Table:
327 <table border="0" cellpadding="0" cellspacing="2" id="typo3-shortcuts">
330 ',$this->lines
).$editIdCode.'
336 if ($this->theEditRec
['uid']) {
337 $this->content
.=$this->doc
->wrapScriptTags('loadEditId('.$this->theEditRec
['uid'].');');
342 * Creates lines for the editing form.
346 function editLoadedFunc() {
347 global $BE_USER,$LANG;
350 if (is_array($this->editSC_rec
) && ($this->editSC_rec
['sc_group']>=0 ||
$BE_USER->isAdmin())) { // sc_group numbers below 0 requires admin to edit those. sc_group numbers above zero must always be owned by the user himself.
354 $opt[]='<option value="0"></option>';
355 for($a=1;$a<=$this->nGroups
;$a++
) {
356 $opt[]='<option value="'.$a.'"'.(!strcmp($this->editSC_rec
['sc_group'],$a)?
' selected="selected"':'').'>'.$LANG->getLL('shortcut_group',1).' '.$a.'</option>';
358 if ($BE_USER->isAdmin()) {
359 for($a=1;$a<=$this->nGlobals
;$a++
) {
360 $opt[]='<option value="-'.$a.'"'.(!strcmp($this->editSC_rec
['sc_group'],'-'.$a)?
' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$a.'</option>';
362 $opt[]='<option value="-100"'.(!strcmp($this->editSC_rec
['sc_group'],'-100')?
' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$LANG->getLL('shortcut_ALL',1).'</option>';
365 // border="0" hspace="2" width="21" height="16" - not XHTML compliant in <input type="image" ...>
370 Shortcut Editing Form:
372 <table border="0" cellpadding="0" cellspacing="0" id="typo3-shortcuts-editing">
374 <td> </td>
375 <td><input type="image" class="c-inputButton" name="_savedok"'.t3lib_iconWorks
::skinImg($this->doc
->backPath
,'gfx/savedok.gif','').' title="'.$LANG->getLL('shortcut_save',1).'" /></td>
376 <td><input type="image" class="c-inputButton" name="_saveclosedok"'.t3lib_iconWorks
::skinImg($this->doc
->backPath
,'gfx/saveandclosedok.gif','').' title="'.$LANG->getLL('shortcut_saveClose',1).'" /></td>
377 <td><input type="image" class="c-inputButton" name="_closedok"'.t3lib_iconWorks
::skinImg($this->doc
->backPath
,'gfx/closedok.gif','').' title="'.$LANG->getLL('shortcut_close',1).'" /></td>
378 <td><input type="image" class="c-inputButton" name="_deletedok"'.t3lib_iconWorks
::skinImg($this->doc
->backPath
,'gfx/deletedok.gif','').' title="'.$LANG->getLL('shortcut_delete',1).'" /></td>
379 <td><input name="editName" type="text" value="'.htmlspecialchars($this->editSC_rec
['description']).'"'.$this->doc
->formWidth(15).' /></td>
380 <td><select name="editGroup">'.implode('',$opt).'</select></td>
383 <input type="hidden" name="whichItem" value="'.$this->editSC_rec
['uid'].'" />
386 } else $manageForm='';
387 //debug(count($opt));
388 if (!$this->editLoaded
&& count($this->selOpt
)>1) {
389 $this->lines
[]='<td> </td>';
390 $this->lines
[]='<td><select name="_selSC" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$this->selOpt
).'</select></td>';
392 if (count($this->lines
)) {
393 if (!$BE_USER->getTSConfigVal('options.mayNotCreateEditShortcuts')) {
394 $this->lines
=array_merge(array('<td><input type="checkbox" name="editShortcut_check" value="1"'.($this->editSC?
' checked="checked"':'').' />'.$LANG->getLL('shortcut_edit',1).' </td>'),$this->lines
);
395 $this->lines
[]='<td>'.$manageForm.'</td>';
397 $this->lines
[]='<td><img src="clear.gif" width="10" height="1" alt="" /></td>';
402 * If "editPage" value is sent to script and it points to an accessible page, the internal var $this->theEditRec is set to the page record which should be loaded.
407 function editPageIdFunc() {
408 global $BE_USER,$LANG;
410 if (!t3lib_extMgm
::isLoaded('cms')) return;
413 $this->editPage
= trim(strtolower($this->editPage
));
415 $this->theEditRec
='';
416 if ($this->editPage
) {
417 $where=' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
418 if (t3lib_div
::testInt($this->editPage
)) {
419 $this->theEditRec
= t3lib_BEfunc
::getRecord ('pages',$this->editPage
,'*',$where);
421 $records = t3lib_BEfunc
::getRecordsByField('pages','alias',$this->editPage
,$where);
422 if (is_array($records)) {
424 $this->theEditRec
= current($records);
427 if (!is_array($this->theEditRec
) ||
!$BE_USER->isInWebMount($this->theEditRec
['uid'])) {
428 unset($this->theEditRec
);
429 $this->editError
=$LANG->getLL('shortcut_notEditable');
430 } elseif(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
431 $expandedPages=unserialize($BE_USER->uc
['browseTrees']['browsePages']);
432 if (!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded')) $expandedPages=array();
433 $rL=t3lib_BEfunc
::BEgetRootLine($this->theEditRec
['pid']);
435 while(list(,$rLDat)=each($rL)) {
436 $expandedPages[0][$rLDat['uid']]=1;
437 // debug($rLDat['uid']);
439 $BE_USER->uc
['browseTrees']['browsePages'] = serialize($expandedPages);
446 * Outputting the accumulated content to screen
450 function printContent() {
451 $this->content
.= $this->doc
->endPage();
465 /***************************
469 ***************************/
472 * Returns relative filename for icon.
474 * @param string Absolute filename of the icon
475 * @param string Backpath string to prepend the icon after made relative
478 function mIconFilename($Ifilename,$backPath) {
479 if (t3lib_div
::isAbsPath($Ifilename)) {
480 $Ifilename = '../'.substr($Ifilename,strlen(PATH_site
));
482 return $backPath.$Ifilename;
486 * Returns icon for shortcut display
488 * @param string Backend module name
489 * @return string Icon file name
491 function getIcon($modName) {
493 if ($LANG->moduleLabels
['tabs_images'][$modName.'_tab']) {
494 $icon = $this->mIconFilename($LANG->moduleLabels
['tabs_images'][$modName.'_tab'],'');
495 } elseif ($modName=='xMOD_alt_doc.php') {
496 $icon = 'gfx/edit2.gif';
497 } elseif ($modName=='xMOD_file_edit.php') {
498 $icon = 'gfx/edit_file.gif';
499 } elseif ($modName=='xMOD_wizard_rte.php') {
500 $icon = 'gfx/edit_rtewiz.gif';
502 $icon = 'gfx/dummy_module.gif';
508 * Returns title-label for icon
510 * @param string In-label
511 * @param string Backend module name (key)
512 * @param string Backend module label (user defined?)
513 * @return string Label for the shortcut item
515 function itemLabel($inlabel,$modName,$M_modName='') {
517 if (substr($modName,0,5)=='xMOD_') {
518 $label=substr($modName,5);
520 $split = explode('_',$modName);
521 $label = $LANG->moduleLabels
['tabs'][$split[0].'_tab'];
522 if (count($split)>1) {
523 $label.='>'.$LANG->moduleLabels
['tabs'][$modName.'_tab'];
526 if ($M_modName) $label.=' ('.$M_modName.')';
527 $label.=': '.$inlabel;
532 // Include extension?
533 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/alt_shortcut.php']) {
534 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/alt_shortcut.php']);
548 $SOBE = t3lib_div
::makeInstance('SC_alt_shortcut');
553 $SOBE->printContent();