[FOLLOWUP] Convert remaining occurences of makeInstance
[Packages/TYPO3.CMS.git] / typo3 / sysext / openid / Classes / Wizard.php
1 <?php
2 namespace TYPO3\CMS\Openid;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Messaging\FlashMessage;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * OpenID selection wizard for the backend
22 *
23 * @author Christian Weiske <cweiske@cweiske.de>
24 */
25 class Wizard extends OpenidService {
26
27 /**
28 * OpenID of the user after authentication
29 *
30 * @var string
31 */
32 protected $claimedId;
33
34 /**
35 * Name of the form element this wizard should write the OpenID into
36 *
37 * @var string
38 */
39 protected $parentFormItemName;
40
41 /**
42 * Name of the function that needs to be called after setting the value
43 *
44 * @var string
45 */
46 protected $parentFormFieldChangeFunc;
47
48 /**
49 * Run the wizard and output HTML.
50 *
51 * @return void
52 */
53 public function main() {
54 $p = GeneralUtility::_GP('P');
55 if (isset($p['itemName'])) {
56 $this->parentFormItemName = $p['itemName'];
57 }
58 if (isset($p['fieldChangeFunc']['TBE_EDITOR_fieldChanged'])) {
59 $this->parentFormFieldChangeFunc = $p['fieldChangeFunc']['TBE_EDITOR_fieldChanged'];
60 }
61
62 if (\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('tx_openid_mode') === 'finish'
63 && $this->openIDResponse === NULL
64 ) {
65 $this->includePHPOpenIDLibrary();
66 $openIdConsumer = $this->getOpenIDConsumer();
67 $this->openIDResponse = $openIdConsumer->complete($this->getReturnUrl());
68 $this->handleResponse();
69 $this->renderHtml();
70 return;
71 } elseif (GeneralUtility::_POST('openid_url') != '') {
72 $openIDIdentifier = GeneralUtility::_POST('openid_url');
73 $this->sendOpenIDRequest($openIDIdentifier);
74
75 // When sendOpenIDRequest() returns, there was an error
76 $flashMessageService = GeneralUtility::makeInstance(
77 \TYPO3\CMS\Core\Messaging\FlashMessageService::class
78 );
79 $flashMessage = GeneralUtility::makeInstance(
80 FlashMessage::class,
81 sprintf(
82 $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:error.setup'),
83 htmlspecialchars($openIDIdentifier)
84 ),
85 $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:title.error'),
86 FlashMessage::ERROR
87 );
88 $flashMessageService->getMessageQueueByIdentifier()->enqueue($flashMessage);
89 }
90 $this->renderHtml();
91 }
92
93 /**
94 * Return URL to this wizard
95 *
96 * @return string Full URL with protocol and hostname
97 */
98 protected function getSelfUrl() {
99 return GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . TYPO3_mainDir .
100 $GLOBALS['MCONF']['_'];
101 }
102
103 /**
104 * Return URL that shall be called by the OpenID server
105 *
106 * @return string Full URL with protocol and hostname
107 */
108 protected function getReturnUrl() {
109 return $this->getSelfURL() .
110 '&tx_openid_mode=finish' .
111 '&P[itemName]=' . urlencode($this->parentFormItemName) .
112 '&P[fieldChangeFunc][TBE_EDITOR_fieldChanged]]=' . urlencode($this->parentFormFieldChangeFunc);
113 }
114
115 /**
116 * Check OpenID response and set flash messages depending on its state
117 *
118 * @return void
119 *
120 * @uses $openIDResponse
121 */
122 protected function handleResponse() {
123 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
124 $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
125 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
126
127 if (!$this->openIDResponse instanceof \Auth_OpenID_ConsumerResponse) {
128 $flashMessage = GeneralUtility::makeInstance(
129 FlashMessage::class,
130 $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:error.no-response'),
131 $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:title.error'),
132 FlashMessage::ERROR
133 );
134 } elseif ($this->openIDResponse->status == Auth_OpenID_SUCCESS) {
135 // all fine
136 $this->claimedId = $this->getSignedParameter('openid_claimed_id');
137 $flashMessage = GeneralUtility::makeInstance(
138 FlashMessage::class,
139 sprintf(
140 $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:youropenid'),
141 htmlspecialchars($this->claimedId)
142 ),
143 $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:title.success'),
144 FlashMessage::OK
145 );
146 } elseif ($this->openIDResponse->status == Auth_OpenID_CANCEL) {
147 $flashMessage = GeneralUtility::makeInstance(
148 FlashMessage::class,
149 $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:error.cancelled'),
150 $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:title.error'),
151 FlashMessage::ERROR
152 );
153 } else {
154 // another failure. show error message and form again
155 $flashMessage = GeneralUtility::makeInstance(
156 FlashMessage::class,
157 sprintf(
158 $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:error.general'),
159 htmlspecialchars($this->openIDResponse->status),
160 htmlspecialchars($this->openIDResponse->message)
161 ),
162 $GLOBALS['LANG']->sL('LLL:EXT:openid/Resources/Private/Language/Wizard.xlf:title.error'),
163 FlashMessage::ERROR
164 );
165 }
166
167 $defaultFlashMessageQueue->enqueue($flashMessage);
168 }
169
170 /**
171 * Render HTML with messagse and OpenID form and output it
172 *
173 * @return void
174 */
175 protected function renderHtml() {
176 // use FLUID standalone view for wizard content
177 $view = GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class);
178 $view->setTemplatePathAndFilename(
179 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('openid') .
180 'Resources/Private/Templates/Wizard/Content.html'
181 );
182
183 /** @var $flashMessageService \TYPO3\CMS\Core\Messaging\FlashMessageService */
184 $flashMessageService = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Messaging\FlashMessageService::class);
185 $defaultFlashMessageQueue = $flashMessageService->getMessageQueueByIdentifier();
186
187 $messages = array();
188 foreach ($defaultFlashMessageQueue->getAllMessagesAndFlush() as $message) {
189 $messages[] = $message->render();
190 }
191 $view->assign('messages', $messages);
192 $view->assign('formAction', $this->getSelfURL());
193 $view->assign('claimedId', $this->claimedId);
194 $view->assign('parentFormItemName', $this->parentFormItemName);
195 $view->assign('parentFormItemNameNoHr', strtr($this->parentFormItemName, array('_hr' => '')));
196 $view->assign('parentFormFieldChangeFunc', $this->parentFormFieldChangeFunc);
197 $view->assign('showForm', TRUE);
198 if (isset($_REQUEST['openid_url'])) {
199 $view->assign('openid_url', $_REQUEST['openid_url']);
200 }
201
202 header('HTTP/1.0 200 OK');
203 echo $view->render();
204 }
205 }