Project

General

Profile

Feature #13518 » 13518_workspaces_extension.patch

Sonja Schubert, 2011-03-03 15:06

View differences:

Classes/ExtDirect/ActionHandler.php (revision )
* @return string the full domain including the protocol http:// or https://, but without the trailing '/'
*/
public function generateWorkspacePreviewLink($uid) {
$ttlHours = intval($GLOBALS['BE_USER']->getTSConfigVal('options.workspaces.previewLinkTTLHours'));
$ttlHours = ($ttlHours ? $ttlHours : 24*2) * 3600;
$linkParams = array(
'ADMCMD_prev' => t3lib_BEfunc::compilePreviewKeyword('', $GLOBALS['BE_USER']->user['uid'], $ttlHours, $this->getCurrentWorkspace()),
'id' => $uid
);
return t3lib_BEfunc::getViewDomain($uid) . '/index.php?' . t3lib_div::implodeArrayForUrl('', $linkParams);
$previewLink = $this->workspaceService->generateWorkspacePreviewLink($uid);
return $previewLink;
}
/**
Classes/Service/Workspaces.php (revision )
* @subpackage Service
*/
class tx_Workspaces_Service_Workspaces {
protected static $pageCache = array();
const TABLE_WORKSPACE = 'sys_workspace';
const SELECT_ALL_WORKSPACES = -98;
const LIVE_WORKSPACE_ID = 0;
......
return $availableWorkspaces;
}
/**
* Gets the current workspace ID.
*
* @return integer The current workspace ID
*/
public function getCurrentWorkspace() {
$workspaceId = $GLOBALS['BE_USER']->workspace;
if ($GLOBALS['BE_USER']->isAdmin()) {
$activeId = $GLOBALS['BE_USER']->getSessionData('tx_workspace_activeWorkspace');
$workspaceId = $activeId !== NULL ? $activeId : $workspaceId;
}
return $workspaceId;
}
/**
* Find the title for the requested workspace.
......
}
return $result;
}
/**
* Generates a workspace preview link.
*
* @param integer $uid The ID of the record to be linked
* @return string the full domain including the protocol http:// or https://, but without the trailing '/'
*/
public function generateWorkspacePreviewLink($uid) {
$ttlHours = intval($GLOBALS['BE_USER']->getTSConfigVal('options.workspaces.previewLinkTTLHours'));
$ttlHours = ($ttlHours ? $ttlHours : 24*2) * 3600;
$linkParams = array(
'ADMCMD_prev' => t3lib_BEfunc::compilePreviewKeyword('', $GLOBALS['BE_USER']->user['uid'], $ttlHours, $this->getCurrentWorkspace()),
'id' => $uid
);
return t3lib_BEfunc::getViewDomain($uid) . '/index.php?' . t3lib_div::implodeArrayForUrl('', $linkParams);
}
}
/**
* Generates a workspace splitted preview link.
*
* @param integer $uid The ID of the record to be linked
* @return string the full domain including the protocol http:// or https://, but without the trailing '/'
*/
public function generateWorkspaceSplittedPreviewLink($uid, $addDomain = FALSE) {
// In case a $pageUid is submitted we need to make sure it points to a live-page
if ($uid > 0) {
$uid = $this->getLivePageUid($uid);
}
$objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
/** @var $uriBuilder Tx_Extbase_MVC_Web_Routing_UriBuilder */
$uriBuilder = $objectManager->create('Tx_Extbase_MVC_Web_Routing_UriBuilder');
/**
* This seems to be very harsh to set this directly to "/typo3 but the viewOnClick also
* has /index.php as fixed value here and dealing with the backPath is very error-prone
*
* @todo make sure this would work in local extension installation too
*/
$backPath = '/' . TYPO3_mainDir;
// @todo why do we need these additional params? the URIBuilder should add the controller, but he doesn't :(
$additionalParams = '&tx_workspaces_web_workspacesworkspaces%5Bcontroller%5D=Preview&M=web_WorkspacesWorkspaces&id='.$uid;
$viewScript = $backPath . $uriBuilder->uriFor('index', array(), 'Tx_Workspaces_Controller_PreviewController', 'workspaces', 'web_workspacesworkspaces') . $additionalParams;
if ($addDomain == TRUE) {
return t3lib_BEfunc::getViewDomain($uid) . $viewScript;
} else {
return $viewScript;
}
}
/**
* Find the Live-Uid for a given page,
* the results are cached at run-time to avoid too many database-queries
*
* @throws InvalidArgumentException
* @param $uid
* @return void
*/
protected function getLivePageUid($uid) {
if (!isset(self::$pageCache[$uid])) {
$rec = t3lib_beFunc::getRecord('pages', $uid);
if (is_array($rec)) {
self::$pageCache[$uid] = $rec['t3ver_oid'] ? $rec['t3ver_oid'] : $uid;
} else {
throw new InvalidArgumentException('uid is supposed to point to an existing page - given value was:' . $uid, 1290628113);
}
}
return self::$pageCache[$uid];
}
}
if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Workspaces.php'])) {
include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Workspaces.php']);
}
?>
?>
Classes/ExtDirect/AbstractHandler.php (revision )
*/
abstract class tx_Workspaces_ExtDirect_AbstractHandler {
/**
* @var Tx_Workspaces_Service_Workspaces
*/
protected $workspaceService;
/**
* Creates this object.
*/
public function __construct() {
$this->workspaceService = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
}
/**
* Gets the current workspace ID.
*
* @return integer The current workspace ID
*/
protected function getCurrentWorkspace() {
$workspaceId = $GLOBALS['BE_USER']->workspace;
if ($GLOBALS['BE_USER']->isAdmin()) {
$activeId = $GLOBALS['BE_USER']->getSessionData('tx_workspace_activeWorkspace');
$workspaceId = $activeId !== NULL ? $activeId : $workspaceId;
}
$workspaceId = $this->workspaceService->getCurrentWorkspace();
return $workspaceId;
}
Classes/Service/Befunc.php (revision )
*/
class tx_Workspaces_Service_Befunc {
protected static $pageCache = array();
/**
* Hooks into the t3lib_beFunc::viewOnClick and redirects to the workspace preview
* only if we're in a workspace and if the frontend-preview is disabled.
......
*/
public function preProcess(&$pageUid, $backPath, $rootLine, $anchorSection, &$viewScript, $additionalGetVars, $switchFocus) {
// In case a $pageUid is submitted we need to make sure it points to a live-page
if ($pageUid > 0) {
$pageUid = $this->getLivePageUid($pageUid);
}
$workspaceService = t3lib_div::makeInstance('tx_Workspaces_Service_Workspaces');
if ($GLOBALS['BE_USER']->workspace !== 0) {
$ctrl = t3lib_div::makeInstance('Tx_Workspaces_Controller_PreviewController', FALSE);
$objectManager = t3lib_div::makeInstance('Tx_Extbase_Object_ObjectManager');
/** @var $uriBuilder Tx_Extbase_MVC_Web_Routing_UriBuilder */
$uriBuilder = $objectManager->create('Tx_Extbase_MVC_Web_Routing_UriBuilder');
/**
* This seems to be very harsh to set this directly to "/typo3 but the viewOnClick also
* has /index.php as fixed value here and dealing with the backPath is very error-prone
*
* @todo make sure this would work in local extension installation too
*/
$backPath = '/' . TYPO3_mainDir;
// @todo why do we need these additional params? the URIBuilder should add the controller, but he doesn't :(
$additionalParams = '&tx_workspaces_web_workspacesworkspaces%5Bcontroller%5D=Preview&M=web_WorkspacesWorkspaces&id=';
$viewScript = $backPath . $uriBuilder->uriFor('index', array(), 'Tx_Workspaces_Controller_PreviewController', 'workspaces', 'web_workspacesworkspaces') . $additionalParams;
$viewScript = $workspaceService->generateWorkspaceSplittedPreviewLink($pageUid);
}
}
}
}
/**
* Find the Live-Uid for a given page,
* the results are cached at run-time to avoid too many database-queries
*
* @throws InvalidArgumentException
* @param $uid
* @return void
*/
protected function getLivePageUid($uid) {
if (!isset(self::$pageCache[$uid])) {
$rec = t3lib_beFunc::getRecord('pages', $uid);
if (is_array($rec)) {
self::$pageCache[$uid] = $rec['t3ver_oid'] ? $rec['t3ver_oid'] : $uid;
} else {
throw new InvalidArgumentException('uid is supposed to point to an existing page - given value was:' . $uid, 1290628113);
}
}
return self::$pageCache[$uid];
}
}
if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Befunc.php'])) {
include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/workspaces/Classes/Service/Befunc.php']);
}
(2-2/3)