forked from TYPO3-extensions/linkhandler
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass.tx_linkhandler_service_eid.php
233 lines (203 loc) · 7.18 KB
/
class.tx_linkhandler_service_eid.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
/***************************************************************
* Copyright notice
*
* Copyright (c) 2009, AOE media GmbH <dev@aoemedia.de>
* 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_tslib . 'class.tslib_pagegen.php';
require_once PATH_tslib . 'class.tslib_fe.php';
require_once PATH_t3lib . 'class.t3lib_page.php';
require_once PATH_tslib . 'class.tslib_content.php';
require_once PATH_t3lib . 'class.t3lib_userauth.php';
require_once PATH_tslib . 'class.tslib_feuserauth.php';
require_once PATH_t3lib . 'class.t3lib_tstemplate.php';
require_once PATH_t3lib . 'class.t3lib_cs.php';
require_once t3lib_extMgm::extPath('linkhandler') . 'class.tx_linkhandler_handler.php';
/**
* eID script
*
* class.tx_linkhandler_service_eid.php
*
* @author Michael Klapper <klapper@aoemedia.de>
* @copyright Copyright (c) 2009, AOE media GmbH <dev@aoemedia.de>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @version $Id$
* @date $Date$
* @since 07.06.2009 - 00:20:44
* @package TYPO3
* @subpackage tx_linkhandler
* @access public
*/
class tx_linkhandler_service_eid {
/**
* @example "record:tt_news:2"
* @var string
*/
protected $linkHandlerParams = '';
/**
* @example "tt_news:2"
* @var string
*/
protected $linkHandlerValue = '';
/**
* Keyword like "record"
*
* @example $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_content.php']['typolinkLinkHandler']['record']
* @var string
*/
protected $linkHandlerKeyword = '';
/**
* Indicate that the current request is from any WS
*
* @var boolean
*/
protected $isWsPreview = false;
/**
* sys_language_uid
*
* @var integer
*/
protected $languageId = null;
/**
* Contains all required values to build an WS preview link.
*
* The Value is separated by ":"#
* - Workspace ID
* - Backend user ID
* - Time to live for the WS link
*
* @example 1:5:172800
* @var string|null
*/
protected $WSPreviewValue = null;
/**
* @author Michael Klapper <michael.klapper@aoemedia.de>
*/
public function __construct() {
$authCode = (string)t3lib_div::_GP('authCode');
$linkParams = t3lib_div::_GP('linkParams');
$this->setLanguageId(t3lib_div::_GP('L'));
// extract the link-handler and WS preview parameter
if (strpos($linkParams, ';') > 0) {
list ($this->linkHandlerParams, $this->WSPreviewValue) = explode(';', $linkParams);
$this->isWsPreview = true;
} else
$this->linkHandlerParams = $linkParams;
list($this->linkHandlerKeyword) = explode(':', $this->linkHandlerParams);
$this->linkHandlerValue = str_replace($this->linkHandlerKeyword . ':', '', $this->linkHandlerParams);
// check the authCode
if (t3lib_div::stdAuthCode($linkParams . $this->languageId, '', 32) !== $authCode) {
header('HTTP/1.0 401 Access denied.');
exit('Access denied.');
}
$this->initTSFE();
}
/**
* @param integer $languageId
*/
private function setLanguageId($languageId) {
if (is_numeric($languageId)) {
$languageId = intval($languageId);
if ($languageId >= 0) {
$this->languageId = $languageId;
}
}
}
/**
* Initializes tslib_fe and sets it to $GLOBALS['TSFE']
*
* @return void
* @author Michael Klapper <michael.klapper@aoemedia.de>
*/
protected function initTSFE() {
$pid = version_compare(TYPO3_version, '4.6.0', '>=') ? t3lib_utility_Math::convertToPositiveInteger(t3lib_div::_GP('id')) : t3lib_div::intval_positive(t3lib_div::_GP('id'));
if (version_compare(TYPO3_version, '4.3.0', '>=')) {
$GLOBALS['TSFE'] = t3lib_div::makeInstance('tslib_fe', $GLOBALS['TYPO3_CONF_VARS'], $pid, 0, 0, 0);
} else {
$tsfeClassName = t3lib_div::makeInstanceClassName('tslib_fe');
$GLOBALS['TSFE'] = new $tsfeClassName($GLOBALS['TYPO3_CONF_VARS'], $pid, 0, 0, 0);
}
$GLOBALS['TSFE']->connectToDB();
$GLOBALS['TSFE']->initFEuser(); //!TODO first check if already a fe_user session exists - otherwise this line will overwrite the existing one
$GLOBALS['TSFE']->checkAlternativeIdMethods();
$GLOBALS['TSFE']->determineId();
$GLOBALS['TSFE']->getCompressedTCarray();
$GLOBALS['TSFE']->initTemplate();
$GLOBALS['TSFE']->getConfigArray();
$GLOBALS['TSFE']->cObj = t3lib_div::makeInstance('tslib_cObj');
}
/**
* @example ?eID=linkhandlerPreview&linkParams=record:tx_aoetirepresenter_tire:40&id=23
* @return void
* @author Michael Klapper <michael.klapper@aoemedia.de>
*/
public function process() {
$typoLinkSettingsArray = array('returnLast' => 'url');
if ($this->languageId) {
$typoLinkSettingsArray['additionalParams'] = '&L=' . $this->languageId;
}
// if we need a WS preview link we need to disable the realUrl and simulateStaticDocuments
if ($this->isWsPreview === true) {
$GLOBALS['TSFE']->config['config']['tx_realurl_enable'] = 0;
$GLOBALS['TSFE']->config['config']['simulateStaticDocuments'] = 0;
}
/* @var $Linkhandler tx_linkhandler_handler */
$Linkhandler = t3lib_div::makeInstance('tx_linkhandler_handler');
$linkString = $Linkhandler->main(
'',
$typoLinkSettingsArray,
$this->linkHandlerKeyword,
$this->linkHandlerValue,
$this->linkHandlerParams,
$GLOBALS['TSFE']->cObj
);
if ($this->isWsPreview === true) {
list ($wsId, $userId, $timeToLive) = explode(':', $this->WSPreviewValue);
$queryString = $this->getWorkspacePreviewUrl($wsId, $userId, $timeToLive);
} else {
$queryString = $linkString;
}
$fullURL = t3lib_div::getIndpEnv('TYPO3_SITE_URL') . $queryString;
header('Location: ' . $fullURL);
exit();
}
/**
* @param int $workspaceId
* @param int $backendUserId
* @param int $timeToLive
* @return string
*/
private function getWorkspacePreviewUrl($workspaceId, $backendUserId, $timeToLive) {
$previewKeyword = 'index.php?ADMCMD_prev=';
$getVarsStr = str_replace('index.php?', '', $GLOBALS['TSFE']->cObj->lastTypoLinkLD['totalURL']) . '&ADMCMD_previewWS=' . $workspaceId;
if (t3lib_extMgm::isLoaded('version') && class_exists('Tx_Version_Preview')) {
/** @var Tx_Version_Preview $previewObject */
$previewObject = t3lib_div::makeInstance('Tx_Version_Preview');
$previewKeyword .= $previewObject->compilePreviewKeyword($getVarsStr, $backendUserId, $timeToLive);
} else {
$previewKeyword .= t3lib_BEfunc::compilePreviewKeyword($getVarsStr, $backendUserId, $timeToLive);
}
return $previewKeyword;
}
}
/* @var $LinkhandlerService tx_linkhandler_service_eid */
$LinkhandlerService = t3lib_div::makeInstance('tx_linkhandler_service_eid');
$LinkhandlerService->process();
?>