Fixed bug #12446: Fixed instantiation of UriBuilder (broken since extbase merge)
[Packages/TYPO3.CMS.git] / typo3 / sysext / workspaces / Classes / Service / Befunc.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2010-2011 Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 /**
29 * @author Workspaces Team (http://forge.typo3.org/projects/show/typo3v4-workspaces)
30 * @package Workspaces
31 * @subpackage Service
32 */
33 class tx_Workspaces_Service_Befunc {
34
35 protected static $pageCache = array();
36
37 /**
38 * Hooks into the t3lib_beFunc::viewOnClick and redirects to the workspace preview
39 * only if we're in a workspace and if the frontend-preview is disabled.
40 *
41 * @param $pageUid
42 * @param $backPath
43 * @param $rootLine
44 * @param $anchorSection
45 * @param $viewScript
46 * @param $additionalGetVars
47 * @param $switchFocus
48 * @return void
49 */
50 public function preProcess(&$pageUid, $backPath, $rootLine, $anchorSection, &$viewScript, $additionalGetVars, $switchFocus) {
51
52 // In case a $pageUid is submitted we need to make sure it points to a live-page
53 if ($pageUid > 0) {
54 $pageUid = $this->getLivePageUid($pageUid);
55 }
56
57 if ($GLOBALS['BE_USER']->workspace !== 0) {
58 $ctrl = t3lib_div::makeInstance('Tx_Workspaces_Controller_PreviewController', FALSE);
59 $objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
60 /** @var $uriBuilder Tx_Extbase_MVC_Web_Routing_UriBuilder */
61 $uriBuilder = $objectManager->create('Tx_Extbase_MVC_Web_Routing_UriBuilder');
62 /**
63 * This seems to be very harsh to set this directly to "/typo3 but the viewOnClick also
64 * has /index.php as fixed value here and dealing with the backPath is very error-prone
65 *
66 * @todo make sure this would work in local extension installation too
67 */
68 $backPath = '/' . TYPO3_mainDir;
69 // @todo why do we need these additional params? the URIBuilder should add the controller, but he doesn't :(
70 $additionalParams = '&tx_workspaces_web_workspacesworkspaces%5Bcontroller%5D=Preview&M=web_WorkspacesWorkspaces&id=';
71 $viewScript = $backPath . $uriBuilder->uriFor('index', array(), 'Tx_Workspaces_Controller_PreviewController', 'workspaces', 'web_workspacesworkspaces') . $additionalParams;
72 }
73 }
74
75 /**
76 * Find the Live-Uid for a given page,
77 * the results are cached at run-time to avoid too many database-queries
78 *
79 * @throws InvalidArgumentException
80 * @param $uid
81 * @return void
82 */
83 protected function getLivePageUid($uid) {
84 if (!isset(self::$pageCache[$uid])) {
85 $rec = t3lib_beFunc::getRecord('pages', $uid);
86 if (is_array($rec)) {
87 self::$pageCache[$uid] = $rec['t3ver_oid'] ? $rec['t3ver_oid'] : $uid;
88 } else {
89 throw new InvalidArgumentException('uid is supposed to point to an existing page - given value was:' . $uid, 1290628113);
90 }
91 }
92 return self::$pageCache[$uid];
93 }
94 }
95
96 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Befunc.php'])) {
97 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Befunc.php']);
98 }
99 ?>