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 * 202: function init()
48 * 237: function main()
49 * 336: function editLoadedFunc()
50 * 397: function editPageIdFunc()
51 * 440: function printContent()
53 * SECTION: OTHER FUNCTIONS:
54 * 468: function mIconFilename($Ifilename,$backPath)
55 * 481: function getIcon($modName)
56 * 505: 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
::GPvar('modName');
123 $this->M_modName
= t3lib_div
::GPvar('motherModName');
124 $this->URL
= t3lib_div
::GPvar('URL');
125 $this->editSC
= t3lib_div
::GPvar('editShortcut');
127 $this->deleteCategory
= t3lib_div
::GPvar('deleteCategory');
128 $this->editPage
= t3lib_div
::GPvar('editPage');
129 $this->editName
= t3lib_div
::GPvar('editName');
130 $this->editGroup
= t3lib_div
::GPvar('editGroup');
131 $this->whichItem
= t3lib_div
::GPvar('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 $fields_values['userid']=$BE_USER->user
['uid'];
150 $fields_values['module_name']=$this->modName
.'|'.$this->M_modName
;
151 $fields_values['url']=$this->URL
;
152 $fields_values['sorting']=time();
153 $query = t3lib_BEfunc
::DBcompileInsert('sys_be_shortcuts',$fields_values);
154 $res = mysql(TYPO3_db
,$query);
158 // Selection-clause for users - so users can deleted only their own shortcuts (except admins)
159 $addUSERWhere = (!$BE_USER->isAdmin()?
' AND userid='.intval($BE_USER->user
['uid']):'');
161 // Deleting shortcuts:
162 if (strcmp($this->deleteCategory
,'')) {
163 if (t3lib_div
::testInt($this->deleteCategory
)) {
164 $q = 'DELETE FROM sys_be_shortcuts WHERE sc_group='.$this->deleteCategory
.$addUSERWhere;
165 $res=mysql(TYPO3_db
,$q);
169 // If other changes in post-vars:
170 if ($HTTP_POST_VARS) {
172 if (isset($HTTP_POST_VARS['_savedok_x']) ||
isset($HTTP_POST_VARS['_saveclosedok_x'])) {
173 $fields_values=array();
174 $fields_values['description']=$this->editName
;
175 $fields_values['sc_group']=intval($this->editGroup
);
176 if ($fields_values['sc_group']<0 && !$BE_USER->isAdmin()) {
177 $fields_values['sc_group']=0;
180 $q = t3lib_BEfunc
::DBcompileUpdate('sys_be_shortcuts','uid='.intval($this->whichItem
).$addUSERWhere,$fields_values);
181 $res=mysql(TYPO3_db
,$q);
183 // If save without close, keep the session going...
184 if (isset($HTTP_POST_VARS['_savedok_x'])) {
185 $this->editSC
=$this->whichItem
;
187 // Deleting a single shortcut ?
188 if (isset($HTTP_POST_VARS['_deletedok_x'])) {
189 $q = 'DELETE FROM sys_be_shortcuts WHERE uid='.intval($this->whichItem
).$addUSERWhere;
190 $res=mysql(TYPO3_db
,$q);
191 if (!$this->editSC
) $this->editSC
=-1; // Just to have the checkbox set...
198 * Initialize (page output)
205 // If another page module was specified, replace the default Page module with the new one
206 $newPageModule = trim($GLOBALS['BE_USER']->getTSConfigVal('options.overridePageModule'));
207 $pageModule = t3lib_BEfunc
::isModuleSetInTBE_MODULES($newPageModule) ?
$newPageModule : 'web_layout';
209 $this->doc
= t3lib_div
::makeInstance('template');
210 $this->doc
->backPath
= $BACK_PATH;
211 $this->doc
->form
='<form action="alt_shortcut.php" name="shForm" method="post">';
212 $this->doc
->docType
='xhtml_trans';
213 $this->doc
->divClass
='typo3-shortcut';
214 $this->doc
->JScode
.=$this->doc
->wrapScriptTags('
215 function jump(url,modName,mainModName) { //
216 // Clear information about which entry in nav. tree that might have been highlighted.
217 top.fsMod.navFrameHighlightedID = new Array();
218 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
219 top.content.nav_frame.refresh_nav();
222 top.nextLoadModuleUrl = url;
223 top.goToModule(modName);
225 function editSh(uid) { //
226 document.location="alt_shortcut.php?editShortcut="+uid;
228 function submitEditPage(id) { //
229 document.location="alt_shortcut.php?editPage="+top.rawurlencode(id);
231 function loadEditId(id) { //
232 top.fsMod.recentIds["web"]=id;
233 top.fsMod.navFrameHighlightedID["web"]="pages"+id+"_0"; // For highlighting
235 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav) {
236 top.content.nav_frame.refresh_nav();
239 top.goToModule("'.$pageModule.'");
242 $this->content
.=$this->doc
->startPage('Shortcut frame');
246 * Main function, creating content in the frame
251 global $BE_USER,$LANG;
253 // Setting groups and globals
257 $globalGroups=array(-100);
258 $shortCutGroups = $BE_USER->getTSConfig('options.shortcutGroups');
259 for($a=1;$a<=$this->nGlobals
;$a++
) {
260 if ($BE_USER->isAdmin() ||
strcmp($shortCutGroups['properties'][$a],'')) {
265 // Fetching shortcuts to display for this user:
266 $query = 'SELECT * FROM sys_be_shortcuts WHERE ((userid='.$BE_USER->user
['uid'].' AND sc_group>=0) OR sc_group IN ('.implode(',',$globalGroups).')) ORDER BY sc_group,sorting';
267 $res = mysql(TYPO3_db
,$query);
270 $this->lines
=array();
271 $this->editSC_rec
='';
272 $this->selOpt
=array();
275 // Traverse shortcuts
276 while($row=mysql_fetch_assoc($res)) {
277 if ($this->editSC
&& $row['uid']==$this->editSC
) {
278 $this->editSC_rec
=$row;
281 if (strcmp($formerGr,$row['sc_group'])) {
282 if ($row['sc_group']!=-100) {
283 if ($row['sc_group']>=0) {
284 $onC = 'if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL('shortcut_delAllInCat')).')){document.location=\'alt_shortcut.php?deleteCategory='.$row['sc_group'].'\';}return false;';
285 $this->lines
[]='<td> </td><td class="bgColor5"><a href="#" onclick="'.htmlspecialchars($onC).'" title="'.$LANG->getLL('shortcut_delAllInCat',1).'">'.abs($row['sc_group']).'</a></td>';
287 $this->lines
[]='<td> </td><td class="bgColor5">'.abs($row['sc_group']).'</td>';
292 $mParts = explode('|',$row['module_name']);
293 $row['module_name']=$mParts[0];
294 $row['M_module_name']=$mParts[1];
295 $mParts = explode('_',$row['M_module_name']?
$row['M_module_name']:$row['module_name']);
296 $qParts = parse_url($row['url']);
298 $bgColorClass = $row['uid']==$this->editSC ?
'bgColor5' : ($row['sc_group']<0 ?
'bgColor6' : 'bgColor4');
299 $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']);
301 $editSH = ($row['sc_group']>=0 ||
$BE_USER->isAdmin()) ?
'editSh('.intval($row['uid']).');' : "alert('".$LANG->getLL('shortcut_onlyAdmin')."')";
302 $jumpSC = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$mParts).'\',\''.$mParts[0].'\');';
303 $onC = 'if (document.shForm.editShortcut_check && document.shForm.editShortcut_check.checked){'.$editSH.'}else{'.$jumpSC.'}return false;';
304 $this->lines
[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
305 if (trim($row['description'])) {
306 $kkey = strtolower(substr($row['description'],0,20)).'_'.$row['uid'];
307 $this->selOpt
[$kkey]='<option value="'.htmlspecialchars($jumpSC).'">'.htmlspecialchars(t3lib_div
::fixed_lgd($row['description'],50)).'</option>';
309 $formerGr=$row['sc_group'];
311 ksort($this->selOpt
);
312 array_unshift($this->selOpt
,'<option>['.$LANG->getLL('shortcut_selSC',1).']</option>');
314 $this->editLoadedFunc();
315 $this->editPageIdFunc();
317 if (!$this->editLoaded
&& t3lib_extMgm
::isLoaded('cms')) {
318 $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);" />'.
319 ($this->editError?
' <strong><span class="typo3-red">'.htmlspecialchars($this->editError
).'</span></strong>':'').
320 (is_array($this->theEditRec
)?
' <strong>'.$LANG->getLL('shortcut_loadEdit',1).' \''.t3lib_BEfunc
::getRecordTitle('pages',$this->theEditRec
,1).'\'</strong>':'').
322 } else $editIdCode='';
328 Shortcut Display Table:
330 <table border="0" cellpadding="0" cellspacing="2" id="typo3-shortcuts">
333 ',$this->lines
).$editIdCode.'
339 if ($this->theEditRec
['uid']) {
340 $this->content
.=$this->doc
->wrapScriptTags('loadEditId('.$this->theEditRec
['uid'].');');
345 * Creates lines for the editing form.
349 function editLoadedFunc() {
350 global $BE_USER,$LANG;
353 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.
357 $opt[]='<option value="0"></option>';
358 for($a=1;$a<=$this->nGroups
;$a++
) {
359 $opt[]='<option value="'.$a.'"'.(!strcmp($this->editSC_rec
['sc_group'],$a)?
' selected="selected"':'').'>'.$LANG->getLL('shortcut_group',1).' '.$a.'</option>';
361 if ($BE_USER->isAdmin()) {
362 for($a=1;$a<=$this->nGlobals
;$a++
) {
363 $opt[]='<option value="-'.$a.'"'.(!strcmp($this->editSC_rec
['sc_group'],'-'.$a)?
' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$a.'</option>';
365 $opt[]='<option value="-100"'.(!strcmp($this->editSC_rec
['sc_group'],'-100')?
' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$LANG->getLL('shortcut_ALL',1).'</option>';
368 // border="0" hspace="2" width="21" height="16" - not XHTML compliant in <input type="image" ...>
373 Shortcut Editing Form:
375 <table border="0" cellpadding="0" cellspacing="0" id="typo3-shortcuts-editing">
377 <td> </td>
378 <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>
379 <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>
380 <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>
381 <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>
382 <td><input name="editName" type="text" value="'.htmlspecialchars($this->editSC_rec
['description']).'"'.$this->doc
->formWidth(15).' /></td>
383 <td><select name="editGroup">'.implode('',$opt).'</select></td>
386 <input type="hidden" name="whichItem" value="'.$this->editSC_rec
['uid'].'" />
389 } else $manageForm='';
390 //debug(count($opt));
391 if (!$this->editLoaded
&& count($this->selOpt
)>1) {
392 $this->lines
[]='<td> </td>';
393 $this->lines
[]='<td><select name="_selSC" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$this->selOpt
).'</select></td>';
395 if (count($this->lines
)) {
396 if (!$BE_USER->getTSConfigVal('options.mayNotCreateEditShortcuts')) {
397 $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
);
398 $this->lines
[]='<td>'.$manageForm.'</td>';
400 $this->lines
[]='<td><img src="clear.gif" width="10" height="1" alt="" /></td>';
405 * 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.
410 function editPageIdFunc() {
411 global $BE_USER,$LANG;
413 if (!t3lib_extMgm
::isLoaded('cms')) return;
416 $this->editPage
= trim(strtolower($this->editPage
));
418 $this->theEditRec
='';
419 if ($this->editPage
) {
420 $where=' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
421 if (t3lib_div
::testInt($this->editPage
)) {
422 $this->theEditRec
= t3lib_BEfunc
::getRecord ('pages',$this->editPage
,'*',$where);
424 $records = t3lib_BEfunc
::getRecordsByField('pages','alias',$this->editPage
,$where);
425 if (is_array($records)) {
427 $this->theEditRec
= current($records);
430 if (!is_array($this->theEditRec
) ||
!$BE_USER->isInWebMount($this->theEditRec
['uid'])) {
431 unset($this->theEditRec
);
432 $this->editError
=$LANG->getLL('shortcut_notEditable');
433 } elseif(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
434 $expandedPages=unserialize($BE_USER->uc
['browsePages']);
435 if (!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded')) $expandedPages=array();
436 $rL=t3lib_BEfunc
::BEgetRootLine($this->theEditRec
['pid']);
438 while(list(,$rLDat)=each($rL)) {
439 $expandedPages[0][$rLDat['uid']]=1;
440 // debug($rLDat['uid']);
442 $BE_USER->uc
['browsePages'] = serialize($expandedPages);
449 * Outputting the accumulated content to screen
453 function printContent() {
454 $this->content
.= $this->doc
->endPage();
468 /***************************
472 ***************************/
475 * Returns relative filename for icon.
477 * @param string Absolute filename of the icon
478 * @param string Backpath string to prepend the icon after made relative
481 function mIconFilename($Ifilename,$backPath) {
482 if (t3lib_div
::isAbsPath($Ifilename)) {
483 $Ifilename = '../'.substr($Ifilename,strlen(PATH_site
));
485 return $backPath.$Ifilename;
489 * Returns icon for shortcut display
491 * @param string Backend module name
492 * @return string Icon file name
494 function getIcon($modName) {
496 if ($LANG->moduleLabels
['tabs_images'][$modName.'_tab']) {
497 $icon = $this->mIconFilename($LANG->moduleLabels
['tabs_images'][$modName.'_tab'],'');
498 } elseif ($modName=='xMOD_alt_doc.php') {
499 $icon = 'gfx/edit2.gif';
500 } elseif ($modName=='xMOD_file_edit.php') {
501 $icon = 'gfx/edit_file.gif';
502 } elseif ($modName=='xMOD_wizard_rte.php') {
503 $icon = 'gfx/edit_rtewiz.gif';
505 $icon = 'gfx/dummy_module.gif';
511 * Returns title-label for icon
513 * @param string In-label
514 * @param string Backend module name (key)
515 * @param string Backend module label (user defined?)
516 * @return string Label for the shortcut item
518 function itemLabel($inlabel,$modName,$M_modName='') {
520 if (substr($modName,0,5)=='xMOD_') {
521 $label=substr($modName,5);
523 $split = explode('_',$modName);
524 $label = $LANG->moduleLabels
['tabs'][$split[0].'_tab'];
525 if (count($split)>1) {
526 $label.='>'.$LANG->moduleLabels
['tabs'][$modName.'_tab'];
529 if ($M_modName) $label.=' ('.$M_modName.')';
530 $label.=': '.$inlabel;
535 // Include extension?
536 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/alt_shortcut.php']) {
537 include_once($TYPO3_CONF_VARS[TYPO3_MODE
]['XCLASS']['typo3/alt_shortcut.php']);
551 $SOBE = t3lib_div
::makeInstance('SC_alt_shortcut');
556 $SOBE->printContent();