alt_shortcut.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 1999-2008 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 ***************************************************************/
00027 /**
00028  * Shortcut frame
00029  * Appears in the bottom frame of the backend frameset.
00030  * Provides links to registered shortcuts
00031  * If the 'cms' extension is loaded you will also have a field for entering page id/alias which will be found/edited
00032  *
00033  * $Id: alt_shortcut.php 4591 2008-12-22 11:56:15Z steffenk $
00034  * Revised for TYPO3 3.6 2/2003 by Kasper Skaarhoj
00035  * XHTML compliant output
00036  *
00037  * @author  Kasper Skaarhoj <kasperYYYY@typo3.com>
00038  */
00039 /**
00040  * [CLASS/FUNCTION INDEX of SCRIPT]
00041  *
00042  *
00043  *
00044  *   86: class SC_alt_shortcut
00045  *  125:     function preinit()
00046  *  152:     function preprocess()
00047  *  234:     function init()
00048  *  275:     function main()
00049  *  452:     function editLoadedFunc()
00050  *  532:     function editPageIdFunc()
00051  *  586:     function printContent()
00052  *
00053  *              SECTION: WORKSPACE FUNCTIONS:
00054  *  611:     function workspaceSelector()
00055  *
00056  *              SECTION: OTHER FUNCTIONS:
00057  *  686:     function mIconFilename($Ifilename,$backPath)
00058  *  702:     function getIcon($modName)
00059  *  726:     function itemLabel($inlabel,$modName,$M_modName='')
00060  *  748:     function getLinkedPageId($url)
00061  *
00062  * TOTAL FUNCTIONS: 12
00063  * (This index is automatically created/updated by the extension "extdeveval")
00064  *
00065  */
00066 
00067 
00068 require('init.php');
00069 require('template.php');
00070 $LANG->includeLLFile('EXT:lang/locallang_misc.xml');
00071 require_once(PATH_t3lib.'class.t3lib_loadmodules.php');
00072 require_once(PATH_t3lib.'class.t3lib_basicfilefunc.php');
00073 
00074 
00075 
00076 
00077 
00078 
00079 /**
00080  * Script Class for the shortcut frame, bottom frame of the backend frameset
00081  *
00082  * @author  Kasper Skaarhoj <kasperYYYY@typo3.com>
00083  * @package TYPO3
00084  * @subpackage core
00085  */
00086 class SC_alt_shortcut {
00087 
00088         // Internal, static: GPvar
00089     var $modName;
00090     var $M_modName;
00091     var $URL;
00092     var $editSC;
00093     var $deleteCategory;
00094     var $editName;
00095     var $editGroup;
00096     var $whichItem;
00097 
00098         // Internal, static:
00099     /**
00100      * Object for backend modules, load modules-object
00101      *
00102      * @var t3lib_loadModules
00103      */
00104     var $loadModules;
00105     protected $isAjaxCall;
00106 
00107     /**
00108      * Document template object
00109      *
00110      * @var template
00111      */
00112     var $doc;
00113 
00114         // Internal, dynamic:
00115     var $content;           // Accumulation of output HTML (string)
00116     var $lines;             // Accumulation of table cells (array)
00117 
00118     var $editLoaded;        // Flag for defining whether we are editing
00119     var $editError;         // Can contain edit error message
00120     var $editPath;          // Set to the record path of the record being edited.
00121     var $editSC_rec;        // Holds the shortcut record when editing
00122     var $theEditRec;        // Page record to be edited
00123     var $editPage;          // Page alias or id to be edited
00124     var $selOpt;            // Select options.
00125     var $searchFor;         // Text to search for...
00126     var $groupLabels=array();   // Labels of all groups. If value is 1, the system will try to find a label in the locallang array.
00127 
00128     var $alternativeTableUid = array(); // Array with key 0/1 being table/uid of record to edit. Internally set.
00129 
00130 
00131 
00132     /**
00133      * Pre-initialization - setting input variables for storing shortcuts etc.
00134      *
00135      * @return  void
00136      */
00137     function preinit()  {
00138         global $TBE_MODULES;
00139 
00140             // Setting GPvars:
00141         $this->isAjaxCall             = (boolean) t3lib_div::_GP('ajax');
00142         $this->modName                = t3lib_div::_GP('modName');
00143         $this->M_modName              = t3lib_div::_GP('motherModName');
00144         $this->URL                    = t3lib_div::_GP('URL');
00145         $this->editSC                 = t3lib_div::_GP('editShortcut');
00146 
00147         $this->deleteCategory         = t3lib_div::_GP('deleteCategory');
00148         $this->editPage               = t3lib_div::_GP('editPage');
00149         $this->changeWorkspace        = t3lib_div::_GP('changeWorkspace');
00150         $this->changeWorkspacePreview = t3lib_div::_GP('changeWorkspacePreview');
00151         $this->editName               = t3lib_div::_GP('editName');
00152         $this->editGroup              = t3lib_div::_GP('editGroup');
00153         $this->whichItem              = t3lib_div::_GP('whichItem');
00154 
00155             // Creating modules object
00156         $this->loadModules = t3lib_div::makeInstance('t3lib_loadModules');
00157         $this->loadModules->load($TBE_MODULES);
00158     }
00159 
00160     /**
00161      * Adding shortcuts, editing shortcuts etc.
00162      *
00163      * @return  void
00164      */
00165     function preprocess()   {
00166         global $BE_USER;
00167         $description = '';  // Default description
00168         $url = urldecode($this->URL);
00169 
00170             // Lookup the title of this page and use it as default description
00171         $page_id = $this->getLinkedPageId($url);         
00172         if (t3lib_div::testInt($page_id))   {
00173             if (preg_match('/\&edit\[(.*)\]\[(.*)\]=edit/',$url,$matches))  {
00174                     // Edit record
00175                 $description = '';  // TODO: Set something useful
00176             } else {
00177                     // Page listing
00178                 $pageRow = t3lib_BEfunc::getRecord('pages',$page_id);
00179                 if (count($pageRow))    {
00180                         // If $page_id is an integer, set the description to the title of that page
00181                     $description = $pageRow['title'];
00182                 }
00183             }
00184         } else {
00185             if (preg_match('/\/$/', $page_id))  {
00186                     // If $page_id is a string and ends with a slash, assume it is a fileadmin reference and set the description to the basename of that path
00187                 $description = basename($page_id);
00188             }
00189         }
00190 
00191 
00192             // Adding a shortcut being set from another frame
00193         if ($this->modName && $this->URL)   {
00194             $fields_values = array(
00195                 'userid' => $BE_USER->user['uid'],
00196                 'module_name' => $this->modName.'|'.$this->M_modName,
00197                 'url' => $this->URL,
00198                 'description' => $description,
00199                 'sorting' => time(),
00200             );
00201             $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_be_shortcuts', $fields_values);
00202         }
00203 
00204             // Selection-clause for users - so users can deleted only their own shortcuts (except admins)
00205         $addUSERWhere = (!$BE_USER->isAdmin()?' AND userid='.intval($BE_USER->user['uid']):'');
00206 
00207             // Deleting shortcuts:
00208         if (strcmp($this->deleteCategory,''))   {
00209             if (t3lib_div::testInt($this->deleteCategory))  {
00210                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'sc_group='.intval($this->deleteCategory).$addUSERWhere);
00211             }
00212         }
00213 
00214             // If other changes in post-vars:
00215         if (is_array($_POST))   {
00216                 // Saving:
00217             if (isset($_POST['_savedok_x']) || isset($_POST['_saveclosedok_x']))    {
00218                 $fields_values = array(
00219                     'description' => $this->editName,
00220                     'sc_group' => intval($this->editGroup)
00221                 );
00222                 if ($fields_values['sc_group']<0 && !$BE_USER->isAdmin())   {
00223                     $fields_values['sc_group']=0;
00224                 }
00225 
00226                 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_be_shortcuts', 'uid='.intval($this->whichItem).$addUSERWhere, $fields_values);
00227             }
00228                 // If save without close, keep the session going...
00229             if (isset($_POST['_savedok_x']))    {
00230                 $this->editSC=$this->whichItem;
00231             }
00232                 // Deleting a single shortcut ?
00233             if (isset($_POST['_deletedok_x']))  {
00234                 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'uid='.intval($this->whichItem).$addUSERWhere);
00235 
00236                 if (!$this->editSC) $this->editSC=-1;   // Just to have the checkbox set...
00237             }
00238         }
00239 
00240     }
00241 
00242     /**
00243      * Initialize (page output)
00244      *
00245      * @return  void
00246      */
00247     function init() {
00248         global $BACK_PATH;
00249 
00250         $this->doc = t3lib_div::makeInstance('template');
00251         $this->doc->backPath = $BACK_PATH;
00252         $this->doc->form='<form action="alt_shortcut.php" name="shForm" method="post">';
00253         $this->doc->divClass='typo3-shortcut';
00254         $this->doc->JScode.=$this->doc->wrapScriptTags('
00255             function jump(url,modName,mainModName)  {   //
00256                     // Clear information about which entry in nav. tree that might have been highlighted.
00257                 top.fsMod.navFrameHighlightedID = new Array();
00258                 if (top.content && top.content.nav_frame && top.content.nav_frame.refresh_nav)  {
00259                     top.content.nav_frame.refresh_nav();
00260                 }
00261 
00262                 top.nextLoadModuleUrl = url;
00263                 top.goToModule(modName);
00264             }
00265             function editSh(uid)    {   //
00266                 window.location.href="alt_shortcut.php?editShortcut="+uid;
00267             }
00268             function submitEditPage(id) {   //
00269                 window.location.href="alt_shortcut.php?editPage="+top.rawurlencodeAndRemoveSiteUrl(id);
00270             }
00271             function changeWorkspace(workspaceId)   {   //
00272                 window.location.href="alt_shortcut.php?changeWorkspace="+top.rawurlencodeAndRemoveSiteUrl(workspaceId);
00273             }
00274             function changeWorkspacePreview(newstate)   {   //
00275                 window.location.href="alt_shortcut.php?changeWorkspacePreview="+newstate;
00276             }
00277             function refreshShortcuts() {
00278                 window.location.href = document.URL;
00279             }
00280 
00281             ');
00282         $this->content.=$this->doc->startPage('Shortcut frame');
00283     }
00284 
00285     /**
00286      * Main function, creating content in the frame
00287      *
00288      * @return  void
00289      */
00290     function main() {
00291         global $BE_USER,$LANG,$TCA;
00292 
00293             // By default, 5 groups are set
00294         $this->groupLabels=array(
00295             1 => 1,
00296             2 => 1,
00297             3 => 1,
00298             4 => 1,
00299             5 => 1,
00300         );
00301 
00302         $shortCutGroups = $BE_USER->getTSConfig('options.shortcutGroups');
00303         if (is_array($shortCutGroups['properties']) && count($shortCutGroups['properties']))    {
00304             foreach ($shortCutGroups['properties'] as $k=>$v)   {
00305                 if (strcmp('',$v) && strcmp('0',$v))    {
00306                     $this->groupLabels[$k] = (string)$v;
00307                 } elseif ($BE_USER->isAdmin())  {
00308                     unset($this->groupLabels[$k]);
00309                 }
00310             }
00311         }
00312 
00313             // List of global groups that will be loaded. All global groups have negative IDs.
00314         $globalGroups = -100;   // Group -100 is kind of superglobal and can't be changed.
00315         if (count($this->groupLabels))  {
00316             $globalGroups .= ','.implode(',',array_keys($this->groupLabels));
00317             $globalGroups = str_replace(',',',-',$globalGroups);    // Ugly hack to make the UIDs negative - is there any better solution?
00318         }
00319 
00320             // Fetching shortcuts to display for this user:
00321         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery('*', 'sys_be_shortcuts', '((userid='.$BE_USER->user['uid'].' AND sc_group>=0) OR sc_group IN ('.$globalGroups.'))', '', 'sc_group,sorting');
00322 
00323             // Init vars:
00324         $this->lines=array();
00325         $this->linesPre=array();
00326         $this->editSC_rec='';
00327         $this->selOpt=array();
00328         $formerGr='';
00329 
00330             // Traverse shortcuts
00331         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res))   {
00332             $mParts = explode('|',$row['module_name']);
00333             $row['module_name']=$mParts[0];
00334             $row['M_module_name']=$mParts[1];
00335             $mParts = explode('_',$row['M_module_name']?$row['M_module_name']:$row['module_name']);
00336             $qParts = parse_url($row['url']);
00337 
00338             if (!$BE_USER->isAdmin())   {
00339                     // Check for module access
00340                 if (!isset($LANG->moduleLabels['tabs_images'][implode('_',$mParts).'_tab']))    {   // Nice hack to check if the user has access to this module - otherwise the translation label would not have been loaded :-)
00341                     continue;
00342                 }
00343 
00344                 $page_id = $this->getLinkedPageId($row['url']);
00345                 if (t3lib_div::testInt($page_id))   {
00346                         // Check for webmount access
00347                     if (!$GLOBALS['BE_USER']->isInWebMount($page_id)) continue;
00348 
00349                         // Check for record access
00350                     $pageRow = t3lib_BEfunc::getRecord('pages',$page_id);
00351                     if (!$GLOBALS['BE_USER']->doesUserHaveAccess($pageRow,$perms=1)) continue;
00352                 }
00353             }
00354 
00355             if ($this->editSC && $row['uid']==$this->editSC)    {
00356                 $this->editSC_rec=$row;
00357             }
00358 
00359             $sc_group = $row['sc_group'];
00360             if ($sc_group && strcmp($formerGr,$sc_group))   {
00361                 if ($sc_group!=-100)    {
00362                     if ($this->groupLabels[abs($sc_group)] && strcmp('1',$this->groupLabels[abs($sc_group)]))   {
00363                         $label = $this->groupLabels[abs($sc_group)];
00364                     } else {
00365                         $label = $LANG->getLL('shortcut_group_'.abs($sc_group),1);
00366                         if (!$label)    $label = $LANG->getLL('shortcut_group',1).' '.abs($sc_group);   // Fallback label
00367                     }
00368 
00369                     if ($sc_group>=0)   {
00370                         $onC = 'if (confirm('.$GLOBALS['LANG']->JScharCode($LANG->getLL('shortcut_delAllInCat')).')){window.location.href=\'alt_shortcut.php?deleteCategory='.$sc_group.'\';}return false;';
00371                         $this->linesPre[]='<td>&nbsp;</td><td class="bgColor5"><a href="#" onclick="'.htmlspecialchars($onC).'" title="'.$LANG->getLL('shortcut_delAllInCat',1).'">'.$label.'</a></td>';
00372                     } else {
00373                         $label = $LANG->getLL('shortcut_global',1).': '.($label ? $label : abs($sc_group)); // Fallback label
00374                         $this->lines[]='<td>&nbsp;</td><td class="bgColor5">'.$label.'</td>';
00375                     }
00376                     unset($label);
00377                 }
00378             }
00379 
00380             $bgColorClass = $row['uid']==$this->editSC ? 'bgColor5' : ($row['sc_group']<0 ? 'bgColor6' : 'bgColor4');
00381 
00382             if ($row['description']&&($row['uid']!=$this->editSC))  {
00383                 $label = $row['description'];
00384             } else {
00385                 $label = t3lib_div::fixed_lgd(rawurldecode($qParts['query']),150);
00386             }
00387             $titleA = $this->itemLabel($label,$row['module_name'],$row['M_module_name']);
00388 
00389             $editSH = ($row['sc_group']>=0 || $BE_USER->isAdmin()) ? 'editSh('.intval($row['uid']).');' : "alert('".$LANG->getLL('shortcut_onlyAdmin')."')";
00390             $jumpSC = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$mParts).'\',\''.$mParts[0].'\');';
00391             $onC = 'if (document.shForm.editShortcut_check && document.shForm.editShortcut_check.checked){'.$editSH.'}else{'.$jumpSC.'}return false;';
00392             if ($sc_group>=0)   {   // user defined groups show up first
00393                 $this->linesPre[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
00394             } else {
00395                 $this->lines[]='<td class="'.$bgColorClass.'"><a href="#" onclick="'.htmlspecialchars($onC).'"><img src="'.$this->getIcon($row['module_name']).'" title="'.htmlspecialchars($titleA).'" alt="" /></a></td>';
00396             }
00397             if (trim($row['description']))  {
00398                 $kkey = strtolower(substr($row['description'],0,20)).'_'.$row['uid'];
00399                 $this->selOpt[$kkey]='<option value="'.htmlspecialchars($jumpSC).'">'.htmlspecialchars(t3lib_div::fixed_lgd_cs($row['description'],50)).'</option>';
00400             }
00401             $formerGr=$row['sc_group'];
00402         }
00403         ksort($this->selOpt);
00404         array_unshift($this->selOpt,'<option>['.$LANG->getLL('shortcut_selSC',1).']</option>');
00405 
00406         $this->editLoadedFunc();
00407         $this->editPageIdFunc();
00408 
00409         if (!$this->editLoaded && t3lib_extMgm::isLoaded('cms'))    {
00410                 $editIdCode = '<td nowrap="nowrap">'.$LANG->getLL('shortcut_editID',1).': <input type="text" value="'.($this->editError?htmlspecialchars($this->editPage):'').'" name="editPage"'.$this->doc->formWidth(15).' onchange="submitEditPage(this.value);" />'.
00411                     ($this->editError?'&nbsp;<strong><span class="typo3-red">'.htmlspecialchars($this->editError).'</span></strong>':'').
00412                     (is_array($this->theEditRec)?'&nbsp;<strong>'.$LANG->getLL('shortcut_loadEdit',1).' \''.t3lib_BEfunc::getRecordTitle('pages',$this->theEditRec,TRUE).'\'</strong> ('.htmlspecialchars($this->editPath).')':'').
00413                     ($this->searchFor?'&nbsp;'.$LANG->getLL('shortcut_searchFor',1).' <strong>\''.htmlspecialchars($this->searchFor).'\'</strong>':'').
00414                     '</td>';
00415         } else $editIdCode = '';
00416 
00417             // Adding CSH:
00418         $editIdCode.= '<td>&nbsp;'.t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'shortcuts', $GLOBALS['BACK_PATH'],'',TRUE).'</td>';
00419 
00420             // Compile it all:
00421         $this->content.='
00422 
00423             <table border="0" cellpadding="0" cellspacing="0" width="99%">
00424                 <tr>
00425                     <td>
00426                         <!--
00427                             Shortcut Display Table:
00428                         -->
00429                         <table border="0" cellpadding="0" cellspacing="2" id="typo3-shortcuts">
00430                             <tr>
00431                             '.implode('
00432                             ',$this->lines).$editIdCode.'
00433                             </tr>
00434                         </table>
00435                     </td>
00436                     <td align="right">';
00437         if ($this->hasWorkspaceAccess()) {
00438             $this->content .= $this->workspaceSelector() .
00439                                 t3lib_BEfunc::cshItem('xMOD_csh_corebe', 'workspaceSelector', $GLOBALS['BACK_PATH'],'',TRUE);
00440         }
00441         $this->content .= '
00442                     </td>
00443                 </tr>
00444             </table>
00445             ';
00446 
00447             // Launch Edit page:
00448         if ($this->theEditRec['uid'])   {
00449             $this->content.=$this->doc->wrapScriptTags('top.loadEditId('.$this->theEditRec['uid'].');');
00450 
00451         }
00452 
00453             // Load alternative table/uid into editing form.
00454         if (count($this->alternativeTableUid)==2 && isset($TCA[$this->alternativeTableUid[0]]) && t3lib_div::testInt($this->alternativeTableUid[1]))    {
00455             $JSaction = t3lib_BEfunc::editOnClick('&edit['.$this->alternativeTableUid[0].']['.$this->alternativeTableUid[1].']=edit','','dummy.php');
00456             $this->content.=$this->doc->wrapScriptTags('function editArbitraryElement() { top.content.'.$JSaction.'; } editArbitraryElement();');
00457         }
00458 
00459             // Load search for something.
00460         if ($this->searchFor)   {
00461             $firstMP = intval($GLOBALS['WEBMOUNTS'][0]);
00462             $this->content.= $this->doc->wrapScriptTags('jump(unescape("'.rawurlencode('db_list.php?id='.$firstMP.'&search_field='.rawurlencode($this->searchFor).'&search_levels=4').'"),"web_list","web");');
00463         }
00464     }
00465 
00466     /**
00467      * Creates lines for the editing form.
00468      *
00469      * @return  void
00470      */
00471     function editLoadedFunc()   {
00472         global $BE_USER,$LANG;
00473 
00474         $this->editLoaded=0;
00475         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.
00476             $this->editLoaded=1;
00477 
00478             $opt=array();
00479             $opt[]='<option value="0"></option>';
00480 
00481             foreach($this->groupLabels as $k=>$v)   {
00482                 if ($v && strcmp('1',$v))   {
00483                     $label = $v;
00484                 } else {
00485                     $label = $LANG->getLL('shortcut_group_'.$k,1);
00486                     if (!$label)    $label = $LANG->getLL('shortcut_group',1).' '.$k;   // Fallback label
00487                 }
00488                 $opt[]='<option value="'.$k.'"'.(!strcmp($this->editSC_rec['sc_group'],$k)?' selected="selected"':'').'>'.$label.'</option>';
00489             }
00490 
00491             if ($BE_USER->isAdmin())    {
00492                 foreach($this->groupLabels as $k=>$v)   {
00493                     if ($v && strcmp('1',$v))   {
00494                         $label = $v;
00495                     } else {
00496                         $label = $LANG->getLL('shortcut_group_'.$k,1);
00497                         if (!$label)    $label = $LANG->getLL('shortcut_group',1).' '.$k;   // Fallback label
00498                     }
00499                     $label = $LANG->getLL('shortcut_global',1).': '.$label; // Add a prefix for global groups
00500 
00501                     $opt[]='<option value="-'.$k.'"'.(!strcmp($this->editSC_rec['sc_group'],'-'.$k)?' selected="selected"':'').'>'.$label.'</option>';
00502                 }
00503                 $opt[]='<option value="-100"'.(!strcmp($this->editSC_rec['sc_group'],'-100')?' selected="selected"':'').'>'.$LANG->getLL('shortcut_global',1).': '.$LANG->getLL('shortcut_all',1).'</option>';
00504             }
00505 
00506                 // border="0" hspace="2" width="21" height="16" - not XHTML compliant in <input type="image" ...>
00507             $manageForm='
00508 
00509                 <!--
00510                     Shortcut Editing Form:
00511                 -->
00512                 <table border="0" cellpadding="0" cellspacing="0" id="typo3-shortcuts-editing">
00513                     <tr>
00514                         <td>&nbsp;&nbsp;</td>
00515                         <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>
00516                         <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>
00517                         <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>
00518                         <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>
00519                         <td><input name="editName" type="text" value="'.htmlspecialchars($this->editSC_rec['description']).'"'.$this->doc->formWidth(15).' /></td>
00520                         <td><select name="editGroup">'.implode('',$opt).'</select></td>
00521                     </tr>
00522                 </table>
00523                 <input type="hidden" name="whichItem" value="'.$this->editSC_rec['uid'].'" />
00524 
00525                 ';
00526         } else $manageForm='';
00527 
00528         if (!$this->editLoaded && count($this->selOpt)>1)   {
00529             $this->lines[]='<td>&nbsp;</td>';
00530             $this->lines[]='<td><select name="_selSC" onchange="eval(this.options[this.selectedIndex].value);this.selectedIndex=0;">'.implode('',$this->selOpt).'</select></td>';
00531         }
00532 
00533             // $this->linesPre contains elements with sc_group>=0
00534         $this->lines = array_merge($this->linesPre,$this->lines);
00535 
00536         if (count($this->lines))    {
00537             if (!$BE_USER->getTSConfigVal('options.mayNotCreateEditShortcuts')) {
00538                 $this->lines=array_merge(array('<td><input type="checkbox" id="editShortcut_check" name="editShortcut_check" value="1"'.($this->editSC?' checked="checked"':'').' /> <label for="editShortcut_check">'.$LANG->getLL('shortcut_edit',1).'</label>&nbsp;</td>'),$this->lines);
00539                 $this->lines[]='<td>'.$manageForm.'</td>';
00540             }
00541             $this->lines[]='<td><img src="clear.gif" width="10" height="1" alt="" /></td>';
00542         }
00543     }
00544 
00545     /**
00546      * 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.
00547      * Returns void
00548      *
00549      * @return  void
00550      */
00551     function editPageIdFunc()   {
00552         global $BE_USER,$LANG;
00553 
00554         if (!t3lib_extMgm::isLoaded('cms')) return;
00555 
00556             // EDIT page:
00557         $this->editPage = trim($LANG->csConvObj->conv_case($LANG->charSet,$this->editPage,'toLower'));
00558         $this->editError = '';
00559         $this->theEditRec = '';
00560         $this->searchFor = '';
00561         if ($this->editPage)    {
00562 
00563                 // First, test alternative value consisting of [table]:[uid] and if not found, proceed with traditional page ID resolve:
00564             $this->alternativeTableUid = explode(':',$this->editPage);
00565             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.
00566 
00567                 $where = ' AND ('.$BE_USER->getPagePermsClause(2).' OR '.$BE_USER->getPagePermsClause(16).')';
00568                 if (t3lib_div::testInt($this->editPage))    {
00569                     $this->theEditRec = t3lib_BEfunc::getRecordWSOL('pages',$this->editPage,'*',$where);
00570                 } else {
00571                     $records = t3lib_BEfunc::getRecordsByField('pages','alias',$this->editPage,$where);
00572                     if (is_array($records)) {
00573                         reset($records);
00574                         $this->theEditRec = current($records);
00575                         t3lib_BEfunc::workspaceOL('pages',$this->theEditRec);
00576                     }
00577                 }
00578                 if (!is_array($this->theEditRec))   {
00579                     unset($this->theEditRec);
00580                     $this->searchFor = $this->editPage;
00581                 } elseif (!$BE_USER->isInWebMount($this->theEditRec['uid'])) {
00582                     unset($this->theEditRec);
00583                     $this->editError=$LANG->getLL('shortcut_notEditable');
00584                 } else {
00585 
00586                         // Visual path set:
00587                     $perms_clause = $BE_USER->getPagePermsClause(1);
00588                     $this->editPath = t3lib_BEfunc::getRecordPath($this->theEditRec['pid'], $perms_clause, 30);
00589 
00590                     if(!$BE_USER->getTSConfigVal('options.shortcut_onEditId_dontSetPageTree')) {
00591 
00592                             // Expanding page tree:
00593                         t3lib_BEfunc::openPageTree($this->theEditRec['pid'],!$BE_USER->getTSConfigVal('options.shortcut_onEditId_keepExistingExpanded'));
00594                     }
00595                 }
00596             }
00597         }
00598     }
00599 
00600     /**
00601      * Outputting the accumulated content to screen
00602      *
00603      * @return  void
00604      */
00605     function printContent() {
00606         $content = '';
00607 
00608         $this->content.= $this->doc->endPage();
00609         $this->content = $this->doc->insertStylesAndJS($this->content);
00610 
00611         if($this->editPage && $this->isAjaxCall) {
00612             $data = array();
00613 
00614                 // edit page
00615             if($this->theEditRec['uid']) {
00616                 $data['type']       = 'page';
00617                 $data['editRecord'] = $this->theEditRec['uid'];
00618             }
00619 
00620                 // edit alternative table/uid
00621             if(count($this->alternativeTableUid) == 2
00622             && isset($GLOBALS['TCA'][$this->alternativeTableUid[0]])
00623             && t3lib_div::testInt($this->alternativeTableUid[1])) {
00624                 $data['type']             = 'alternative';
00625                 $data['alternativeTable'] = $this->alternativeTableUid[0];
00626                 $data['alternativeUid']   = $this->alternativeTableUid[1];
00627             }
00628 
00629                 // search for something else
00630             if($this->searchFor) {
00631                 $data['type']            = 'search';
00632                 $data['firstMountPoint'] = intval($GLOBALS['WEBMOUNTS'][0]);
00633                 $data['searchFor']       = rawurlencode($this->searchFor);
00634             }
00635 
00636             $content = json_encode($data);
00637 
00638             header('Content-type: application/json; charset=utf-8');
00639             header('X-JSON: '.$content);
00640         } else {
00641             $content = $this->content;
00642         }
00643 
00644         echo $content;
00645     }
00646 
00647 
00648 
00649 
00650 
00651 
00652 
00653 
00654 
00655     /***************************
00656      *
00657      * WORKSPACE FUNCTIONS:
00658      *
00659      ***************************/
00660 
00661     /**
00662      * Create selector for workspaces and change workspace if command is given to do that.
00663      *
00664      * @return  string      HTML
00665      */
00666     function workspaceSelector()    {
00667         global $TYPO3_DB,$BE_USER,$LANG;
00668 
00669             // Changing workspace and if so, reloading entire backend:
00670         if (strlen($this->changeWorkspace)) {
00671             $BE_USER->setWorkspace($this->changeWorkspace);
00672             return $this->doc->wrapScriptTags('top.location.href="'. t3lib_BEfunc::getBackendScript() . '";');
00673         }
00674             // Changing workspace and if so, reloading entire backend:
00675         if (strlen($this->changeWorkspacePreview))  {
00676             $BE_USER->setWorkspacePreview($this->changeWorkspacePreview);
00677         }
00678 
00679             // Create options array:
00680         $options = array();
00681         if ($BE_USER->checkWorkspace(array('uid' => 0)))    {
00682             $options[0] = '['.$LANG->getLL('shortcut_onlineWS').']';
00683         }
00684         if ($BE_USER->checkWorkspace(array('uid' => -1)))   {
00685             $options[-1] = '['.$LANG->getLL('shortcut_offlineWS').']';
00686         }
00687 
00688             // Add custom workspaces (selecting all, filtering by BE_USER check):
00689         $workspaces = $TYPO3_DB->exec_SELECTgetRows('uid,title,adminusers,members,reviewers','sys_workspace','pid=0'.t3lib_BEfunc::deleteClause('sys_workspace'),'','title');
00690         if (count($workspaces)) {
00691             foreach ($workspaces as $rec)   {
00692                 if ($BE_USER->checkWorkspace($rec)) {
00693                     $options[$rec['uid']] = $rec['uid'].': '.$rec['title'];
00694                 }
00695             }
00696         }
00697 
00698             // Build selector box:
00699         if (count($options))    {
00700             foreach($options as $value => $label)   {
00701                 $selected = ((int)$BE_USER->workspace===$value ? ' selected="selected"' : '');
00702                 $options[$value] = '<option value="'.htmlspecialchars($value).'"'.$selected.'>'.htmlspecialchars($label).'</option>';
00703             }
00704         } else {
00705             $options[] = '<option value="-99">'.$LANG->getLL('shortcut_noWSfound',1).'</option>';
00706         }
00707 
00708         $selector = '';
00709             // Preview:
00710         if ($BE_USER->workspace!==0)    {
00711             $selector.= '<label for="workspacePreview">Frontend Preview:</label> <input type="checkbox" name="workspacePreview" id="workspacePreview" onclick="changeWorkspacePreview('.($BE_USER->user['workspace_preview'] ? 0 : 1).')"; '.($BE_USER->user['workspace_preview'] ? 'checked="checked"' : '').'/>&nbsp;';
00712         }
00713 
00714         $selector.= '<a href="mod/user/ws/index.php" target="content">'.
00715                     t3lib_iconWorks::getIconImage('sys_workspace',array(),$this->doc->backPath,'align="top"').
00716                     '</a>';
00717         if (count($options) > 1) {
00718             $selector .= '<select name="_workspaceSelector" onchange="changeWorkspace(this.options[this.selectedIndex].value);">'.implode('',$options).'</select>';
00719         }
00720 
00721         return $selector;
00722     }
00723 
00724 
00725 
00726 
00727 
00728 
00729 
00730     /***************************
00731      *
00732      * OTHER FUNCTIONS:
00733      *
00734      ***************************/
00735 
00736     /**
00737      * Returns relative filename for icon.
00738      *
00739      * @param   string      Absolute filename of the icon
00740      * @param   string      Backpath string to prepend the icon after made relative
00741      * @return  void
00742      */
00743     function mIconFilename($Ifilename,$backPath)    {
00744             // Change icon of fileadmin references - otherwise it doesn't differ with Web->List
00745         $Ifilename = str_replace ('mod/file/list/list.gif', 'mod/file/file.gif', $Ifilename);
00746 
00747         if (t3lib_div::isAbsPath($Ifilename))   {
00748             $Ifilename = '../'.substr($Ifilename,strlen(PATH_site));
00749         }
00750         return $backPath.$Ifilename;
00751     }
00752 
00753     /**
00754      * Returns icon for shortcut display
00755      *
00756      * @param   string      Backend module name
00757      * @return  string      Icon file name
00758      */
00759     function getIcon($modName)  {
00760         global $LANG;
00761         if ($LANG->moduleLabels['tabs_images'][$modName.'_tab'])    {
00762             $icon = $this->mIconFilename($LANG->moduleLabels['tabs_images'][$modName.'_tab'],'');
00763         } elseif ($modName=='xMOD_alt_doc.php') {
00764             $icon = 'gfx/edit2.gif';
00765         } elseif ($modName=='xMOD_file_edit.php') {
00766             $icon = 'gfx/edit_file.gif';
00767         } elseif ($modName=='xMOD_wizard_rte.php') {
00768             $icon = 'gfx/edit_rtewiz.gif';
00769         } else {
00770             $icon = 'gfx/dummy_module.gif';
00771         }
00772         return $icon;
00773     }
00774 
00775     /**
00776      * Returns title-label for icon
00777      *
00778      * @param   string      In-label
00779      * @param   string      Backend module name (key)
00780      * @param   string      Backend module label (user defined?)
00781      * @return  string      Label for the shortcut item
00782      */
00783     function itemLabel($inlabel,$modName,$M_modName='') {
00784         global $LANG;
00785         if (substr($modName,0,5)=='xMOD_')  {
00786             $label=substr($modName,5);
00787         } else {
00788             $split = explode('_',$modName);
00789             $label = $LANG->moduleLabels['tabs'][$split[0].'_tab'];
00790             if (count($split)>1)    {
00791                 $label.='>'.$LANG->moduleLabels['tabs'][$modName.'_tab'];
00792             }
00793         }
00794         if ($M_modName) $label.=' ('.$M_modName.')';
00795         $label.=': '.$inlabel;
00796         return $label;
00797     }
00798 
00799     /**
00800      * Return the ID of the page in the URL if found.
00801      *
00802      * @param   string      The URL of the current shortcut link
00803      * @return  string      If a page ID was found, it is returned. Otherwise: 0
00804      */
00805     function getLinkedPageId($url)  {
00806         return preg_replace('/.*[\?&]id=([^&]+).*/', '$1', $url);
00807     }
00808 
00809     /**
00810      * Checks if user has access to Workspace module.
00811      *
00812      * @return  boolean     Returns true if user has access to workspace module.
00813      */
00814     function hasWorkspaceAccess() {
00815         $MCONF = array();
00816         include('mod/user/ws/conf.php');
00817         return $GLOBALS['BE_USER']->modAccess(array('name' => 'user', 'access' => 'user,group'), false) && $GLOBALS['BE_USER']->modAccess($MCONF, false);
00818     }
00819 }
00820 
00821 
00822 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php'])  {
00823     include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/alt_shortcut.php']);
00824 }
00825 
00826 
00827 
00828 // Make instance:
00829 $SOBE = t3lib_div::makeInstance('SC_alt_shortcut');
00830 $SOBE->preinit();
00831 $SOBE->preprocess();
00832 $SOBE->init();
00833 $SOBE->main();
00834 $SOBE->printContent();
00835 
00836 ?>

Generated on Sat Jan 3 04:23:28 2009 for TYPO3 API by  doxygen 1.4.7