added feature #6442: Hook in browse_links request (for linking to records)
authorIngo Renner <ingo.renner@typo3.org>
Thu, 15 Nov 2007 13:31:35 +0000 (13:31 +0000)
committerIngo Renner <ingo.renner@typo3.org>
Thu, 15 Nov 2007 13:31:35 +0000 (13:31 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2712 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_parsehtml_proc.php
t3lib/interfaces/interface.t3lib_browselinkshook.php [new file with mode: 0644]
typo3/class.browse_links.php
typo3/sysext/rtehtmlarea/mod3/class.tx_rtehtmlarea_browse_links.php

index ab52f88..ace69ec 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,7 @@
 
        * enabled requestUpdate for rte_enabled
        * added feature #6721: add the workspace selector to the cleaner backend toolbar
+       * added feature #6442: Hook in browse_links request (for linking to records)
 
 2007-11-14  Stanislas Rolland  <stanislas.rolland@fructifor.ca>
 
index 95887e2..d26358b 100755 (executable)
@@ -727,6 +727,9 @@ class t3lib_parsehtml_proc extends t3lib_parsehtml {
                                                $page = t3lib_BEfunc::getRecord('pages', $idPart);
                                                if (is_array($page))    {       // Page must exist...
                                                        $href = $siteUrl.'?id='.$link_param;
+                                               } else if(strtolower(substr($link_param, 0, 7)) == 'record:') {
+                                                               // linkHandler - allowing links to start with "record:"
+                                                       $href = $link_param;
                                                } else {
                                                        #$href = '';
                                                        $href = $siteUrl.'?id='.$link_param;
diff --git a/t3lib/interfaces/interface.t3lib_browselinkshook.php b/t3lib/interfaces/interface.t3lib_browselinkshook.php
new file mode 100644 (file)
index 0000000..6daf852
--- /dev/null
@@ -0,0 +1,83 @@
+<?php
+/***************************************************************
+*  Copyright notice
+*
+*  (c) 2007 Ingo Renner <ingo@typo3.org>
+*  All rights reserved
+*
+*  This script is part of the TYPO3 project. The TYPO3 project is
+*  free software; you can redistribute it and/or modify
+*  it under the terms of the GNU General Public License as published by
+*  the Free Software Foundation; either version 2 of the License, or
+*  (at your option) any later version.
+*
+*  The GNU General Public License can be found at
+*  http://www.gnu.org/copyleft/gpl.html.
+*  A copy is found in the textfile GPL.txt and important notices to the license
+*  from the author is found in LICENSE.txt distributed with these scripts.
+*
+*
+*  This script is distributed in the hope that it will be useful,
+*  but WITHOUT ANY WARRANTY; without even the implied warranty of
+*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+*  GNU General Public License for more details.
+*
+*  This copyright notice MUST APPEAR in all copies of the script!
+***************************************************************/
+
+
+/**
+ * interface for classes which hook into browse_links
+ *
+ * @author     Ingo Renner <ingo@typo3.org>
+ * @package TYPO3
+ * @subpackage t3lib
+ */
+interface t3lib_browseLinksHook {
+
+       /**
+        * initializes the hook object
+        *
+        * @param       browse_links    parent browse_links object
+        * @param       array           additional parameters
+        * @return      void
+        */
+       public function init($parentObject, $additionalParameters);
+
+       /**
+        * adds new items to the currently allowed ones and returns them
+        *
+        * @param       array   currently allowed items
+        * @return      array   currently allowed items plus added items
+        */
+       public function addAllowedItems($currentlyAllowedItems);
+
+       /**
+        * modifies the menu definition and returns it
+        *
+        * @param       array   menu definition
+        * @return      array   modified menu definition
+        */
+       public function modifyMenuDefinition($menuDefinition);
+
+       /**
+        * returns a new tab for the browse links wizard
+        *
+        * @param       string          current link selector action
+        * @return      string          a tab for the selected link action
+        */
+       public function getTab($linkSelectorAction);
+
+       /**
+        * checks the current URL and determines what to do
+        *
+        * @param       unknown_type            $href
+        * @param       unknown_type            $siteUrl
+        * @param       unknown_type            $info
+        * @return      unknown_type
+        */
+       public function parseCurrentUrl($href, $siteUrl, $info);
+
+}
+
+?>
\ No newline at end of file
index 3dc7fdb..e4d5aab 100755 (executable)
@@ -754,10 +754,14 @@ class browse_links {
         */
        var $curUrlInfo;
 
+       /**
+       * array which holds hook objects (initialised in init() )
+       */
+       protected $hookObjects;
 
 
        var     $readOnly = FALSE;      // If set, all operations that changes something should be disabled. This is used for alternativeBrowsing file mounts (see options like "options.folderTree.altElementBrowserMountPoints" in browse_links.php).
-       
+
 
        /**
         * Constructor:
@@ -783,6 +787,22 @@ class browse_links {
                        $this->mode='rte';
                }
 
+                       // init hook objects:
+               $this->hookObjects = array();
+               if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'])) {
+                       foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'] as $classData) {
+                               $processObject = &t3lib_div::getUserObj($classData);
+
+                               if(!($processObject instanceof t3lib_browseLinksHook)) {
+                                       throw new UnexpectedValueException('$processObject must implement interface t3lib_browseLinksHook', 1195039394);
+                               }
+
+                               $parameters = array();
+                               $processObject->init($this, $parameters);
+                               $this->hookObjects[] = $processObject;
+                       }
+               }
+
                        // Site URL
                $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL');       // Current site url
 
@@ -1142,6 +1162,12 @@ class browse_links {
 
                        // Initializing the action value, possibly removing blinded values etc:
                $allowedItems = array_diff(explode(',','page,file,url,mail,spec'),t3lib_div::trimExplode(',',$this->thisConfig['blindLinkOptions'],1));
+
+                       //call hook for extra options
+               foreach($this->hookObjects as $hookObject) {
+                       $allowedItems = $hookObject->addAllowedItems($allowedItems);
+               }
+
                reset($allowedItems);
                if (!in_array($this->act,$allowedItems))        $this->act = current($allowedItems);
 
@@ -1183,6 +1209,12 @@ class browse_links {
                        $menuDef['spec']['url'] = '#';
                        $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(\'?act=spec\');return false;"';
                }
+
+                       // call hook for extra options
+               foreach($this->hookObjects as $hookObject) {
+                       $menuDef = $hookObject->modifyMenuDefinition($menuDef);
+               }
+
                $content .= $this->doc->getTabMenuRaw($menuDef);
 
                        // Adding the menu and header to the top of page:
@@ -1314,7 +1346,6 @@ class browse_links {
                                }
                        break;
                        case 'page':
-                       default:
                                $pagetree = t3lib_div::makeInstance('rtePageTree');
                                $pagetree->thisScript = $this->thisScript;
                                $tree=$pagetree->getBrowsableTree();
@@ -1332,6 +1363,13 @@ class browse_links {
                                        </table>
                                        ';
                        break;
+                       default:
+                                       //call hook
+                               foreach($this->hookObjects as $hookObject) {
+                                       $content .= $hookObject->getTab($this->act);
+                               }
+
+                       break;
                }
 
                $content .= '
@@ -2262,6 +2300,12 @@ class browse_links {
                        $info['value']='';
                        $info['act']='page';
                }
+
+                       // let the hook have a look
+               foreach($this->hookObjects as $hookObject) {
+                       $info = $hookObject->parseCurrentUrl($href, $siteUrl, $info);
+               }
+
                return $info;
        }
 
@@ -2392,4 +2436,4 @@ if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['typo3/class
 }
 
 
-?>
+?>
\ No newline at end of file
index 02dadd0..acd64b3 100644 (file)
@@ -50,7 +50,7 @@ require_once (PATH_t3lib.'class.t3lib_basicfilefunc.php');
  * @subpackage core
  */
 class tx_rtehtmlarea_pageTree extends rtePageTree {
-       
+
        /**
         * Create the page navigation tree in HTML
         *
@@ -111,7 +111,7 @@ class tx_rtehtmlarea_pageTree extends rtePageTree {
  * @subpackage core
  */
 class tx_rtehtmlarea_folderTree extends rteFolderTree {
-       
+
        /**
         * Wrapping the title in a link, if applicable.
         *
@@ -127,7 +127,7 @@ class tx_rtehtmlarea_folderTree extends rteFolderTree {
                        return '<span class="typo3-dimmed">'.$title.'</span>';
                }
        }
-       
+
        /**
         * Create the folder navigation tree in HTML
         *
@@ -203,13 +203,13 @@ class tx_rtehtmlarea_browse_links extends browse_links {
        var $setTarget;                 // Target (RTE specific)
        var $setClass;                  // Class (RTE specific)
        var $setTitle;                  // Title (RTE specific)
-       
+
        var $contentTypo3Language;
        var $contentTypo3Charset;
-       
+
        var $editorNo;
        var $buttonConfig = array();
-       
+
        /**
         * Constructor:
         * Initializes a lot of variables, setting JavaScript functions in header etc.
@@ -230,19 +230,34 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                $this->contentTypo3Language = t3lib_div::_GP('typo3ContentLanguage');
                $this->contentTypo3Charset = t3lib_div::_GP('typo3ContentCharset');
                $this->editorNo = t3lib_div::_GP('editorNo');
-               
+
                        // Find "mode"
                $this->mode=t3lib_div::_GP('mode');
                if (!$this->mode)       {
                        $this->mode='rte';
                }
-               
+
+                       // init hook objects:
+               if(is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'])) {
+                       foreach($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['typo3/class.browse_links.php']['browseLinksHook'] as $classData) {
+                               $processObject = &t3lib_div::getUserObj($classData);
+
+                               if(!($processObject instanceof t3lib_browseLinksHook)) {
+                                       throw new UnexpectedValueException('$processObject must implement interface t3lib_browseLinksHook', 1195115652);
+                               }
+
+                               $parameters = array();
+                               $processObject->init($this, $parameters);
+                               $this->hookObjects[] = $processObject;
+                       }
+               }
+
                        // Site URL
                $this->siteURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL');       // Current site url
-               
+
                        // the script to link to
                $this->thisScript = t3lib_div::getIndpEnv('SCRIPT_NAME');
-               
+
                        // CurrentUrl - the current link url must be passed around if it exists
                if ($this->mode=='wizard')      {
                        $currentLinkParts = t3lib_div::trimExplode(' ',$this->P['currentValue']);
@@ -583,6 +598,12 @@ class tx_rtehtmlarea_browse_links extends browse_links {
 
                        // Initializing the action value, possibly removing blinded values etc:
                $allowedItems = explode(',','page,file,url,mail,spec');
+
+                       //call hook for extra options
+               foreach($this->hookObjects as $hookObject) {
+                       $allowedItems = $hookObject->addAllowedItems($allowedItems);
+               }
+
                if (is_array($this->buttonConfig['options.']) && $this->buttonConfig['options.']['removeItems']) {
                        $allowedItems = array_diff($allowedItems,t3lib_div::trimExplode(',',$this->buttonConfig['options.']['removeItems'],1));
                } else {
@@ -592,7 +613,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                if (!in_array($this->act,$allowedItems)) {
                        $this->act = current($allowedItems);
                }
-               
+
                        // Making menu in top:
                $menuDef = array();
                if (!$wiz)      {
@@ -631,11 +652,17 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                        $menuDef['spec']['url'] = '#';
                        $menuDef['spec']['addParams'] = 'onclick="jumpToUrl(\'?act=spec&editorNo='.$this->editorNo.'&contentTypo3Language='.$this->contentTypo3Language.'&contentTypo3Charset='.$this->contentTypo3Charset.'\');return false;"';
                }
+
+                       // call hook for extra options
+               foreach($this->hookObjects as $hookObject) {
+                       $menuDef = $hookObject->modifyMenuDefinition($menuDef);
+               }
+
                $content .= $this->doc->getTabMenuRaw($menuDef);
 
                        // Adding the menu and header to the top of page:
                $content.=$this->printCurrentUrl($this->curUrlInfo['info']).'<br />';
-               
+
                        // Depending on the current action we will create the actual module content for selecting a link:
                switch($this->act)      {
                        case 'mail':
@@ -674,7 +701,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                        break;
                        case 'file':
                                $content.=$this->addAttributesForm();
-                               
+
                                $foldertree = t3lib_div::makeInstance('tx_rtehtmlarea_folderTree');
                                $tree=$foldertree->getBrowsableTree();
 
@@ -781,9 +808,8 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                }
                        break;
                        case 'page':
-                       default:
                                $content.=$this->addAttributesForm();
-                               
+
                                $pagetree = t3lib_div::makeInstance('tx_rtehtmlarea_pageTree');
                                $pagetree->ext_showNavTitle = $GLOBALS['BE_USER']->getTSConfigVal('options.pageTree.showNavTitle');
                                $pagetree->addField('nav_title');
@@ -801,13 +827,20 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                        </table>
                                        ';
                        break;
+                       default:
+                                       // call hook
+                               foreach($this->hookObjects as $hookObject) {
+                                       $content .= $hookObject->getTab($this->act);
+                               }
+
+                       break;
                }
 
                        // End page, return content:
                $content.= $this->doc->endPage();
                return $content;
        }
-       
+
        function addAttributesForm() {
                $ltargetForm = '';
                        // Add target and class selector box and title field:
@@ -819,10 +852,10 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                }
                return $ltargetForm;
        }
-       
+
        function wrapInForm($string) {
                global $LANG;
-               
+
                $form = '
                        <!--
                                Selecting target for link:
@@ -844,10 +877,10 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                </form>';
                return $form;
        }
-       
+
        function addTargetSelector() {
                global $LANG;
-               
+
                $targetSelectorConfig = array();
                $popupSelectorConfig = array();
                if (is_array($this->buttonConfig['targetSelector.'])) {
@@ -856,7 +889,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                if (is_array($this->buttonConfig['popupSelector.'])) {
                        $popupSelectorConfig = $this->buttonConfig['popupSelector.'];
                }
-               
+
                $ltarget = '';
                if ($this->act != 'mail')       {
                        if (!($targetSelectorConfig['disabled'] && $popupSelectorConfig['disabled'])) {
@@ -877,11 +910,11 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                $ltarget .= '
                                                        </td>';
                        }
-                       
+
                        $ltarget .= '
                                                </tr>';
                        if (!$popupSelectorConfig['disabled']) {
-                               
+
                                $selectJS = 'if (document.ltargetform.popup_width.options[document.ltargetform.popup_width.selectedIndex].value>0 && document.ltargetform.popup_height.options[document.ltargetform.popup_height.selectedIndex].value>0)        {
                                        document.ltargetform.ltarget.value = document.ltargetform.popup_width.options[document.ltargetform.popup_width.selectedIndex].value+\'x\'+document.ltargetform.popup_height.options[document.ltargetform.popup_height.selectedIndex].value;
                                        setTarget(document.ltargetform.ltarget.value);
@@ -917,10 +950,10 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                }
                return $ltarget;
        }
-       
+
        function addClassSelector() {
                global $LANG;
-               
+
                $selectClass = '';
                if ($this->classesAnchorJSOptions[$this->act]) {
                        $selectClassJS = '
@@ -948,10 +981,10 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                }
                return $selectClass;
        }
-       
+
        function addTitleSelector() {
                global $LANG;
-               
+
                return '
                                                <tr>
                                                        <td>'.$LANG->getLL('anchor_title',1).':</td>
@@ -960,7 +993,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
                                                        </td>
                                                </tr>';
        }
-       
+
        /**
         * For TBE: Makes an upload form for uploading files to the filemount the user is browsing.
         * The files are uploaded to the tce_file.php script in the core which will handle the upload.
@@ -1014,7 +1047,7 @@ class tx_rtehtmlarea_browse_links extends browse_links {
 
                return $code;
        }
-       
+
        /**
         * For TBE: Makes a form for creating new folders in the filemount the user is browsing.
         * The folder creation request is sent to the tce_file.php script in the core which will handle the creation.