Documentation TYPO3 par Ameos

alt_shortcut.php

00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2005 Kasper Skaarhoj (kasperYYYY@typo3.com)
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00064 require('init.php');
00065 require('template.php');
00066 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
00067 require_once(PATH_t3lib.'class.t3lib_loadmodules.php');
00068 require_once(PATH_t3lib.'class.t3lib_basicfilefunc.php');
00069 
00070 
00071 
00072 
00073 
00074 
00082 class SC_alt_shortcut {
00083 
00084                 // Internal, static: GPvar
00085         var $modName;
00086         var $M_modName;
00087         var $URL;
00088         var $editSC;
00089         var $deleteCategory;
00090         var $editName;
00091         var $editGroup;
00092         var $whichItem;
00093 
00094                 // Internal, static:
00095         var $loadModules;               // Modules object
00096         var $doc;                               // Document template object
00097         var $nGroups;                   // Number of groups
00098         var $nGlobals;                  // Number of globals
00099 
00100                 // Internal, dynamic:
00101         var $content;                   // Accumulation of output HTML (string)
00102         var $lines;                             // Accumulation of table cells (array)
00103 
00104         var $editLoaded;                // Flag for defining whether we are editing
00105         var $editError;                 // Can contain edit error message
00106         var $editPath;                  // Set to the record path of the record being edited.
00107         var $editSC_rec;                // Holds the shortcut record when editing
00108         var $theEditRec;                // Page record to be edited
00109         var $editPage;                  // Page alias or id to be edited
00110         var $selOpt;                    // Select options.
00111 
00112         var $alternativeTableUid = array();     // Array with key 0/1 being table/uid of record to edit. Internally set.
00113 
00114 
00115 
00121         function preinit()      {
00122                 global $TBE_MODULES;
00123 
00124                         // Setting GPvars:
00125                 $this->modName = t3lib_div::_GP('modName');
00126                 $this->M_modName = t3lib_div::_GP('motherModName');
00127                 $this->URL = t3lib_div::_GP('URL');
00128                 $this->editSC = t3lib_div::_GP('editShortcut');
00129 
00130                 $this->deleteCategory = t3lib_div::_GP('deleteCategory');
00131                 $this->editPage = t3lib_div::_GP('editPage');
00132                 $this->editName = t3lib_div::_GP('editName');
00133                 $this->editGroup = t3lib_div::_GP('editGroup');
00134                 $this->whichItem = t3lib_div::_GP('whichItem');
00135 
00136                         // Creating modules object
00137                 $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
00138                 $this->loadModules->load($TBE_MODULES);
00139         }
00140 
00146         function preprocess()   {
00147                 global $BE_USER;
00148 
00149                         // Adding a shortcut being set from another frame
00150                 if ($this->modName && $this->URL)       {
00151                         $fields_values = array(
00152                                 'userid' => $BE_USER->user['uid'],
00153                                 'module_name' => $this->modName.'|'.$this->M_modName,
00154                                 'url' => $this->URL,
00155                                 'sorting' => time()
00156                         );
00157                         $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_be_shortcuts', $fields_values);
00158                 }
00159 
00160                         // Selection-clause for users - so users can deleted only their own shortcuts (except admins)
00161                 $addUSERWhere = (!$BE_USER->isAdmin()?' AND userid='.intval($BE_USER->user['uid']):'');
00162 
00163                         // Deleting shortcuts:
00164                 if (strcmp($this->deleteCategory,''))   {
00165                         if (t3lib_div::testInt($this->deleteCategory))  {
00166                                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'sc_group='.intval($this->deleteCategory).$addUSERWhere);
00167                         }
00168                 }
00169 
00170                         // If other changes in post-vars:
00171                 if (is_array($_POST))   {
00172                                 // Saving:
00173                         if (isset($_POST['_savedok_x']) || isset($_POST['_saveclosedok_x']))    {
00174                                 $fields_values = array(
00175                                         'description' => $this->editName,
00176                                         'sc_group' => intval($this->editGroup)
00177                                 );
00178                                 if ($fields_values['sc_group']<0 && !$BE_USER->isAdmin())       {
00179                                         $fields_values['sc_group']=0;
00180                                 }
00181 
00182                                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_be_shortcuts', 'uid='.intval($this->whichItem).$addUSERWhere, $fields_values);
00183                         }
00184                                 // If save without close, keep the session going...
00185                         if (isset($_POST['_savedok_x']))        {
00186                                 $this->editSC=$this->whichItem;
00187                         }
00188                                 // Deleting a single shortcut ?
00189                         if (isset($_POST['_deletedok_x']))      {
00190                                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'uid='.intval($this->whichItem).$addUSERWhere);
00191 
00192                                 if (!$this->editSC)     $this->editSC=-1;       // Just to have the checkbox set...
00193                         }
00194                 }
00195 
00196         }
00197 
00203         function init() {
00204                 global $BACK_PATH;
00205 
00206                 $this->doc = t3lib_div::makeInstance('template');
00207                 $this->doc->backPath = $BACK_PATH;
00208                 $this->doc->form='<form action="alt_shortcut.php" name="shForm" method="post">';
00209                 $this->doc->docType='xhtml_trans';
00210                 $this->doc->divClass='typo3-shortcut';
00211                 $this->doc->JScode.=$this->doc->wrapScriptTags('
00212                         function jump(url,modName,mainModName)  {       //
00213                                         // Clear information about which entry in nav. tree that might have been highlighted.
00214                                 top.fsMod.navFrameHighlightedID = new Array();
00215                                 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav)  {
00216                                         top.content.nav_frame.refresh_nav();
00217                                 }
00218 
00219                                 top.nextLoadModuleUrl = url;
00220                                 top.goToModule(modName);
00221                         }
00222                         function editSh(uid)    {       //
00223                                 document.location="alt_shortcut.php?editShortcut="+uid;
00224                         }
00225                         function submitEditPage(id)     {       //
00226                                 document.location="alt_shortcut.php?editPage="+top.rawurlencode(id);
00227                         }
00228                         ');
00229                 $this->content.=$this->doc->startPage('Shortcut frame');
00230         }
00231 
00237         function main() {
00238                 global $BE_USER,$LANG,$TCA;
00239 
00240                         // Setting groups and globals
00241                 $this->nGroups=4;
00242                 $this->nGlobals=5;
00243 
00244                 $globalGroups=array(-100);
00245                 $shortCutGroups = $BE_USER->getTSConfig('options.shortcutGroups');
00246                 for($a=1;$a<=$this->nGlobals;$a++)      {
00247                         if ($BE_USER->isAdmin() || strcmp($shortCutGroups['properties'][$a],''))        {
00248                                 $globalGroups[]=-$a;
00249                         }
00250                 }
00251 
00252                         // Fetching shortcuts to display for this user:
00253                 $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');
00254 
00255                         // Init vars:
00256                 $this->lines=array();
00257                 $this->editSC_rec='';
00258                 $this->selOpt=array();
00259                 $formerGr='';
00260 
00261                         // Traverse shortcuts
00262                 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))       {
00263                         if ($this->editSC && $row['uid']==$this->editSC)        {
00264                                 $this->editSC_rec=$row;
00265                         }
00266 
00267                         if (strcmp($formerGr,$row['sc_group'])) {
00268                                 if ($row['sc_group']!=-100)     {
00269                                         if ($row['sc_group']>=0)        {
00270                                                 $onC = 'if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL('shortcut_delAllInCat')).')){document.location=\'alt_shortcut.php?deleteCategory='.$row['sc_group'].'\';}return false;';
00271                                                 $this->lines[]='<td>&nbsp;</td><td class="bgColor5"><a href="#" onclick="'.htmlspecialchars($onC).'" title="'.$LANG->getLL('shortcut_delAllInCat',1).'">'.abs($row['sc_group']).'</a></td>';
00272                                         } else {
00273                                                 $this->lines[]='<td>&nbsp;</td><td class="bgColor5">'.abs($row['sc_group']).'</td>';
00274                                         }
00275                                 }
00276                         }
00277 
00278                         $mParts = explode('|',$row['module_name']);
00279                         $row['module_name']=$mParts[0];
00280                         $row['M_module_name']=$mParts[1];
00281                         $mParts = explode('_',$row['M_module_name']?$row['M_module_name']:$row['module_name']);
00282                         $qParts = parse_url($row['url']);
00283 
00284                         $bgColorClass = $row['uid']==$this->editSC ? 'bgColor5' : ($row['sc_group']<0 ? 'bgColor6' : 'bgColor4');
00285                         $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']);
00286 
00287                         $editSH = ($row['sc_group']>=0 || $BE_USER->isAdmin()) ? 'editSh('.intval($row['uid']).');' : "alert('".$LANG->getLL('shortcut_onlyAdmin')."')";
00288                         $jumpSC = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$mParts).'\',\''.$mParts[0].'\');';
00289                         $onC = 'if (document.shForm.editShortcut_check && document.shForm.editShortcut_check.checked){'.$editSH.'}else{'.$jumpSC.'}return false;';
00290                         $this->lines[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
00291                         if (trim($row['description']))  {
00292                                 $kkey = strtolower(substr($row['description'],0,20)).'_'.$row['uid'];
00293                                 $this->selOpt[$kkey]='<option value="'.htmlspecialchars($jumpSC).'">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['description'],50)).'</option>';
00294                         }
00295                         $formerGr=$row['sc_group'];
00296                 }
00297                 ksort($this->selOpt);
00298                 array_unshift($this->selOpt,'<option>['.$LANG->getLL('shortcut_selSC',1).']</option>');
00299 
00300                 $this->editLoadedFunc();
00301                 $this->editPageIdFunc();
00302 
00303                 if (!$this->editLoaded && t3lib_extMgm::isLoaded('cms'))        {
00304                                 $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);" />'.
00305                                         ($this->editError?'&nbsp;<strong><span class="typo3-red">'.htmlspecialchars($this->editError).'</span></strong>':'').
00306                                         (is_array($this->theEditRec)?'&nbsp;<strong>'.$LANG->getLL('shortcut_loadEdit',1).' \''.t3lib_BEfunc::getRecordTitle('pages',$this->theEditRec,1).'\'</strong> ('.htmlspecialchars($this->editPath).')':'').
00307                                         '</td>';
00308                 } else $editIdCode = '';
00309 
00310                         // Adding CSH:
00311                 $editIdCode.= '<td>&nbsp;'.t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'shortcuts', $GLOBALS['BACK_PATH'],'',TRUE).'</td>';
00312 
00313                 $this->content.='
00314 
00315 
00316                         <!--
00317                                 Shortcut Display Table:
00318                         -->
00319                         <table border="0" cellpadding="0" cellspacing="2" id="typo3-shortcuts">
00320                                 <tr>
00321                                 '.implode('
00322                                 ',$this->lines).$editIdCode.'
00323                                 </tr>
00324                         </table>
00325 
00326                         ';
00327 
00328                         // Launch Edit page:
00329                 if ($this->theEditRec['uid'])   {
00330                         $this->content.=$this->doc->wrapScriptTags('top.loadEditId('.$this->theEditRec['uid'].');');
00331                 }
00332 
00333                         // Load alternative table/uid into editing form.
00334                 if (count($this->alternativeTableUid)==2 && isset($TCA[$this->alternativeTableUid[0]]) && t3lib_div::testInt($this->alternativeTableUid[1]))    {
00335                         $JSaction = t3lib_BEfunc::editOnClick('&edit['.$this->alternativeTableUid[0].']['.$this->alternativeTableUid[1].']=edit','','dummy.php');
00336                         $this->content.=$this->doc->wrapScriptTags('function editArbitraryElement() { top.content.'.$JSaction.'; } editArbitraryElement();');
00337                 }
00338         }
00339 
00345         function editLoadedFunc()       {
00346                 global $BE_USER,$LANG;
00347 
00348                 $this->editLoaded=0;
00349                 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.
00350                         $this->editLoaded=1;
00351 
00352                         $opt=array();
00353                         $opt[]='<option value="0"></option>';
00354                         for($a=1;$a<=$this->nGroups;$a++)       {
00355                                 $opt[]='<option value="'.$a.'"'.(!strcmp($this->editSC_rec['sc_group'],$a)?' selected="selected"':'').'>'.$LANG->getLL('shortcut_group',1).' '.$a.'</option>';
00356                         }
00357                         if ($BE_USER->isAdmin())        {
00358                                 for($a=1;$a<=$this->nGlobals;$a++)      {
00359                                         $opt[]='<option value="-'.$a.'"'.(!strcmp($this->editSC_rec['sc_group'],'-'.$a)?' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$a.'</option>';
00360                                 }
00361                                 $opt[]='<option value="-100"'.(!strcmp($this->editSC_rec['sc_group'],'-100')?' selected="selected"':'').'>'.$LANG->getLL('shortcut_GLOBAL',1).': '.$LANG->getLL('shortcut_ALL',1).'</option>';
00362                         }
00363 
00364                                 // border="0" hspace="2" width="21" height="16" - not XHTML compliant in <input type="image" ...>
00365                         $manageForm='
00366 
00367 
00368                                 <!--
00369                                         Shortcut Editing Form:
00370                                 -->
00371                                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-shortcuts-editing">
00372                                         <tr>
00373                                                 <td>&nbsp;&nbsp;</td>
00374                                                 <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>
00375                                                 <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>
00376                                                 <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>
00377                                                 <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>
00378                                                 <td><input name="editName" type="text" value="'.htmlspecialchars($this->editSC_rec['description']).'"'.$this->doc->formWidth(15).' /></td>
00379                                                 <td><select name="editGroup">'.implode('',$opt).'</select></td>
00380                                         </tr>
00381                                 </table>
00382                                 <input type="hidden" name="whichItem" value="'.$this->editSC_rec['uid'].'" />
00383 
00384                                 ';
00385                 } else $manageForm='';
00386 //debug(count($opt));
00387                 if (!$this->editLoaded && count($this->selOpt)>1)       {
00388                         $this->lines[]='<td>&nbsp;</td>';
00389                         $this->lines[]='<td><select name="_selSC" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$this->selOpt).'</select></td>';
00390                 }
00391                 if (count($this->lines))        {
00392                         if (!$BE_USER->getTSConfigVal('options.mayNotCreateEditShortcuts'))     {
00393                                 $this->lines=array_merge(array('<td><input type="checkbox" name="editShortcut_check" value="1"'.($this->editSC?' checked="checked"':'').' />'.$LANG->getLL('shortcut_edit',1).'&nbsp;</td>'),$this->lines);
00394                                 $this->lines[]='<td>'.$manageForm.'</td>';
00395                         }
00396                         $this->lines[]='<td><img src="clear.gif" width="10" height="1" alt="" /></td>';
00397                 }
00398         }
00399 
00406         function editPageIdFunc()       {
00407                 global $BE_USER,$LANG;
00408 
00409                 if (!t3lib_extMgm::isLoaded('cms'))     return;
00410 
00411                         // EDIT page:
00412                 $this->editPage = trim(strtolower($this->editPage));
00413                 $this->editError = '';
00414                 $this->theEditRec = '';
00415                 if ($this->editPage)    {
00416 
00417                                 // First, test alternative value consisting of [table]:[uid] and if not found, proceed with traditional page ID resolve:
00418                         $this->alternativeTableUid = explode(':',$this->editPage);
00419                         if (!(count($this->alternativeTableUid)==2 && $BE_USER->isAdmin()))     {       // We restrict it to admins only just because I'm not really sure if alt_doc.php properly checks permissions of passed records for editing. If alt_doc.php does that, then we can remove this.
00420 
00421                                 $where = ' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
00422                                 if (t3lib_div::testInt($this->editPage))        {
00423                                         $this->theEditRec = t3lib_BEfunc::getRecord ('pages',$this->editPage,'*',$where);
00424                                 } else {
00425                                         $records = t3lib_BEfunc::getRecordsByField('pages','alias',$this->editPage,$where);
00426                                         if (is_array($records)) {
00427                                                 reset($records);
00428                                                 $this->theEditRec = current($records);
00429                                         }
00430                                 }
00431                                 if (!is_array($this->theEditRec) || !$BE_USER->isInWebMount($this->theEditRec['uid']))  {
00432                                         unset($this->theEditRec);
00433                                         $this->editError=$LANG->getLL('shortcut_notEditable');
00434                                 } else {
00435                                                 // Visual path set:
00436                                         $perms_clause = $BE_USER->getPagePermsClause(1);
00437                                         $this->editPath = t3lib_BEfunc::getRecordPath($this->theEditRec['pid'], $perms_clause, 30);
00438 
00439                                         if(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
00440 
00441                                                         // Expanding page tree:
00442                                                 t3lib_BEfunc::openPageTree($this->theEditRec['pid'],!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
00443                                         }
00444                                 }
00445                         }
00446                 }
00447         }
00448 
00454         function printContent() {
00455                 $this->content.= $this->doc->endPage();
00456                 echo $this->content;
00457         }
00458 
00459 
00460 
00461 
00462 
00463 
00464 
00465 
00466 
00467 
00468 
00469         /***************************
00470          *
00471          * OTHER FUNCTIONS:
00472          *
00473          ***************************/
00474 
00482         function mIconFilename($Ifilename,$backPath)    {
00483                 if (t3lib_div::isAbsPath($Ifilename))   {
00484                         $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
00485                 }
00486                 return $backPath.$Ifilename;
00487         }
00488 
00495         function getIcon($modName)      {
00496                 global $LANG;
00497                 if ($LANG->moduleLabels['tabs_images'][$modName.'_tab'])        {
00498                         $icon = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$modName.'_tab'],'');
00499                 } elseif ($modName=='xMOD_alt_doc.php') {
00500                         $icon = 'gfx/edit2.gif';
00501                 } elseif ($modName=='xMOD_file_edit.php') {
00502                         $icon = 'gfx/edit_file.gif';
00503                 } elseif ($modName=='xMOD_wizard_rte.php') {
00504                         $icon = 'gfx/edit_rtewiz.gif';
00505                 } else {
00506                         $icon = 'gfx/dummy_module.gif';
00507                 }
00508                 return $icon;
00509         }
00510 
00519         function itemLabel($inlabel,$modName,$M_modName='')     {
00520                 global $LANG;
00521                 if (substr($modName,0,5)=='xMOD_')      {
00522                         $label=substr($modName,5);
00523                 } else {
00524                         $split = explode('_',$modName);
00525                         $label = $LANG->moduleLabels['tabs'][$split[0].'_tab'];
00526                         if (count($split)>1)    {
00527                                 $label.='>'.$LANG->moduleLabels['tabs'][$modName.'_tab'];
00528                         }
00529                 }
00530                 if ($M_modName) $label.=' ('.$M_modName.')';
00531                 $label.=': '.$inlabel;
00532                 return $label;
00533         }
00534 }
00535 
00536 // Include extension?
00537 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php'])  {
00538         include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']);
00539 }
00540 
00541 
00542 
00543 
00544 
00545 
00546 
00547 
00548 
00549 
00550 
00551 // Make instance:
00552 $SOBE = t3lib_div::makeInstance('SC_alt_shortcut');
00553 $SOBE->preinit();
00554 $SOBE->preprocess();
00555 $SOBE->init();
00556 $SOBE->main();
00557 $SOBE->printContent();
00558 ?>


Généré par Les experts TYPO3 avec  doxygen 1.4.6