Added feature #15754: ExtDirect in Frontend (Thanks to Stefan Galinksi)
authorErnesto Baschny <ernst@cron-it.de>
Tue, 21 Sep 2010 17:27:49 +0000 (17:27 +0000)
committerErnesto Baschny <ernst@cron-it.de>
Tue, 21 Sep 2010 17:27:49 +0000 (17:27 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@8836 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
NEWS.txt
t3lib/class.t3lib_pagerenderer.php
t3lib/extjs/class.t3lib_extjs_extdirectapi.php
typo3/sysext/cms/ext_autoload.php
typo3/sysext/cms/ext_localconf.php
typo3/sysext/cms/tslib/class.tslib_extdirecteid.php [new file with mode: 0644]
typo3/sysext/cms/tslib/extdirecteid.php [new file with mode: 0644]

index f50bc34..58d9d0a 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2010-09-21  Ernesto Baschny  <ernst@cron-it.de>
+
+       * Added feature #15754: ExtDirect in Frontend (Thanks to Stefan Galinksi)
+
 2010-09-21  Xavier Perseguers  <typo3@perseguers.ch>
 
        * Raised DBAL to version 1.2.0alpha2
index 8bcf5a2..ad58f0b 100644 (file)
--- a/NEWS.txt
+++ b/NEWS.txt
@@ -107,8 +107,11 @@ Development
                http://forge.typo3.org/projects/typo3v45-projects/files
        * Catch all ExtDirect Exceptions and show them in the DebugConsole.
          It now also allows you to call debug() (#15513).
-       * DebugConsole now also catch console-calls from Javascript if no console is available. This allows eg debug prints 
-         in browsers having no console like the IE 
+       * DebugConsole now also catch console-calls from Javascript if no
+         console is available. This allows eg debug prints in browsers
+         having no console like the IE
+       * ExtDirect is available in the frontend now (#15754):
+         http://wiki.typo3.org/ExtDirect
 
 TypoScript
 ==========
index d631767..5542ac8 100644 (file)
@@ -916,18 +916,24 @@ class t3lib_PageRenderer implements t3lib_Singleton {
 
                                if (TYPO3ViewportInstance !== null) {
                                        TYPO3ViewportInstance.DebugConsole.addTab(message, header, group);
+                               } else if (typeof console === "object") {
+                                       console.log(message);
                                } else {
                                        document.write(message);
                                }
                        };
 
                        Ext.Direct.on("exception", function(event) {
-                               extDirectDebug(
-                                       "<p>" + event.message + "<\/p>" +
-                                       "<p style=\"margin-top: 20px;\">" +
+                               var backtrace = "";
+                               if (event.where) {
+                                       backtrace = "<p style=\"margin-top: 20px;\">" +
                                                "<strong>Backtrace:<\/strong><br \/>" +
                                                event.where.replace(/#/g, "<br \/>#") +
-                                       "<\/p>",
+                                               "<\/p>";
+                               }
+
+                               extDirectDebug(
+                                       "<p>" + event.message + "<\/p>" + backtrace,
                                        event.method,
                                        "ExtDirect - Exception"
                                );
index 6cb7c58..27c150c 100644 (file)
@@ -73,7 +73,9 @@ class t3lib_extjs_ExtDirectApi {
 
                        // look up into the cache
                $cacheIdentifier = 'ExtDirectApi';
-               $cacheHash = md5($cacheIdentifier . $filterNamespace . serialize($this->settings));
+               $cacheHash = md5($cacheIdentifier . $filterNamespace .
+                       serialize($this->settings) . TYPO3_MODE);
+               
                        // with no_cache always generate the javascript content
                $cacheContent = $noCache ? '' : t3lib_pageSelect::getHash($cacheHash);
 
@@ -168,7 +170,7 @@ class t3lib_extjs_ExtDirectApi {
 
                                if (!isset($javascriptNamespaces[$javascriptNamespace])) {
                                        $javascriptNamespaces[$javascriptNamespace] = array(
-                                               'url' => t3lib_div::locationHeaderUrl('ajax.php?ajaxID=ExtDirect::route&namespace=') . rawurlencode($javascriptNamespace),
+                                               'url' => $this->getRoutingUrl($javascriptNamespace),
                                                'type' => 'remoting',
                                                'actions' => array(),
                                                'namespace' => $javascriptNamespace
@@ -194,6 +196,24 @@ class t3lib_extjs_ExtDirectApi {
 
                return $javascriptNamespaces;
        }
+
+       /**
+        * Returns the convenient path for the routing Urls based on the TYPO3 mode.
+        *
+        * @param string $namespace
+        * @return string
+        */
+       public function getRoutingUrl($namespace) {
+               $url = '';
+               if (TYPO3_MODE === 'FE') {
+                       $url = t3lib_div::locationHeaderUrl('?eID=ExtDirect&action=route&namespace=');
+               } else {
+                       $url = t3lib_div::locationHeaderUrl('ajax.php?ajaxID=ExtDirect::route&namespace=');
+               }
+               $url .= rawurlencode($namespace);
+
+               return $url;
+       }
 }
 
 if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_extjs_extdirectapi.php'])       {
index cab75d5..b0b8dad 100644 (file)
@@ -25,6 +25,7 @@ return array(
        'fe_loaddbgroup' => PATH_tslib . 'class.tslib_pagegen.php',
        'tslib_pibase' => PATH_tslib . 'class.tslib_pibase.php',
        'tslib_search' => PATH_tslib . 'class.tslib_search.php',
+       'tslib_extdirecteid' => PATH_tslib . 'class.tslib_extdirecteid.php',
        'sc_tslib_showpic' => PATH_tslib . 'showpic.php',
        'tx_cms_mediaitems' => PATH_tslib . 'hooks/class.tx_cms_mediaitems.php',
        'tx_cms_treelistcacheupdate' => PATH_tslib . 'hooks/class.tx_cms_treelistcacheupdate.php',
index e403245..e9d6760 100755 (executable)
@@ -193,5 +193,7 @@ $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processDatamapC
 $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['processCmdmapClass'][]  = 'EXT:cms/tslib/hooks/class.tx_cms_treelistcacheupdate.php:&tx_cms_treelistCacheUpdate';
 $TYPO3_CONF_VARS['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['moveRecordClass'][]     = 'EXT:cms/tslib/hooks/class.tx_cms_treelistcacheupdate.php:&tx_cms_treelistCacheUpdate';
 
+       // register eID provider for ExtDirect for the frontend
+$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['ExtDirect'] = PATH_tslib . 'extdirecteid.php';
 
 ?>
\ No newline at end of file
diff --git a/typo3/sysext/cms/tslib/class.tslib_extdirecteid.php b/typo3/sysext/cms/tslib/class.tslib_extdirecteid.php
new file mode 100644 (file)
index 0000000..c19366b
--- /dev/null
@@ -0,0 +1,86 @@
+<?php
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2010 Stefan Galinski <stefan.galinski@gmail.com>
+ *
+ * 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.
+ *
+ * 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!
+ ***************************************************************/
+
+require_once(PATH_site . 'typo3/classes/class.typo3ajax.php');
+
+/**
+ * eID controller for ExtDirect
+ *
+ * @author     Stefan Galinski <stefan.galinski@gmail.com>
+ * @package    TYPO3
+ */
+class tslib_ExtDirectEid {
+       /**
+        * Ajax Instance
+        * 
+        * @property TYPO3AJAX
+        * @var TYPO3AJAX
+        */
+       protected $ajaxObjext = NULL;
+
+       /**
+        * Routes the given eID action to the related ExtDirect method with the necessary
+        * ajax object.
+        * 
+        * @return void
+        */
+       public function routeAction() {
+               $GLOBALS['LANG'] = t3lib_div::makeInstance('language');
+               $GLOBALS['LANG']->init();
+
+               tslib_eidtools::connectDB();
+
+               $ajaxID = t3lib_div::_GP('action');
+               $ajaxScript = $GLOBALS['TYPO3_CONF_VARS']['BE']['AJAX']['ExtDirect::' . $ajaxID];
+               $this->ajaxObject = t3lib_div::makeInstance('TYPO3AJAX', 'ExtDirect::' . $ajaxID);
+
+               $parameters = array();
+               t3lib_div::callUserFunction($ajaxScript, $parameters, $this->ajaxObject, FALSE, TRUE);
+       }
+
+       /**
+        * Returns true if the associated action in _GET is allowed.
+        *
+        * @return boolean
+        */
+       public function actionIsAllowed() {
+               if (!in_array(t3lib_div::_GP('action'), array('route', 'getAPI'))) {
+                       return FALSE;
+               }
+
+               return TRUE;
+       }
+
+       /**
+        * Renders/Echoes the ajax output
+        *
+        * @return void
+        */
+       public function render() {
+               $this->ajaxObject->render();
+       }
+}
+
+?>
diff --git a/typo3/sysext/cms/tslib/extdirecteid.php b/typo3/sysext/cms/tslib/extdirecteid.php
new file mode 100644 (file)
index 0000000..4749169
--- /dev/null
@@ -0,0 +1,36 @@
+<?php
+/***************************************************************
+ * Copyright notice
+ *
+ * (c) 2010 Stefan Galinski <stefan.galinski@gmail.com>
+ *
+ * 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.
+ *
+ * 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!
+ ***************************************************************/
+
+if (!defined('PATH_typo3conf')) {
+       die('Could not access this script directly!');
+}
+
+$extDirectEidInstance = t3lib_div::makeInstance('tslib_ExtDirectEid');
+if ($extDirectEidInstance->actionIsAllowed()) {
+       $extDirectEidInstance->routeAction();
+       $extDirectEidInstance->render();
+}
+
+?>
\ No newline at end of file