@@ -25,148 +25,148 @@ |
||
| 25 | 25 | class AccessService extends AbstractService |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * Session service |
|
| 30 | - * |
|
| 31 | - * @var \HVP\Html5videoplayerPowermail\Service\SessionService |
|
| 32 | - * @inject |
|
| 33 | - */ |
|
| 34 | - protected $sessionService; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Uri Builder |
|
| 38 | - * |
|
| 39 | - * @var \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder |
|
| 40 | - * @inject |
|
| 41 | - */ |
|
| 42 | - protected $uriBuilder; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Flexform service |
|
| 46 | - * |
|
| 47 | - * @var \TYPO3\CMS\Extbase\Service\FlexFormService |
|
| 48 | - * @inject |
|
| 49 | - */ |
|
| 50 | - protected $flexFormService; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * The session name |
|
| 54 | - * |
|
| 55 | - * @var string |
|
| 56 | - */ |
|
| 57 | - protected $sessionName = 'submittedForms'; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * @param Video $video |
|
| 61 | - */ |
|
| 62 | - public function checkVideoAccess(Video $video = null) |
|
| 63 | - { |
|
| 64 | - if ($video === null) { |
|
| 65 | - return; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $formProtection = $this->getFormProtection($video); |
|
| 69 | - if ($formProtection <= 0) { |
|
| 70 | - return; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // disable the cache |
|
| 74 | - GlobalUtility::getTypoScriptFrontendController() |
|
| 75 | - ->set_no_cache('Do not cache video detail page, because every request is check via html5videoplayer_powermail'); |
|
| 76 | - |
|
| 77 | - if ($this->isAccessableByCurrentUser($formProtection)) { |
|
| 78 | - return; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $formPage = $this->findFormPage($formProtection); |
|
| 82 | - if ($formPage) { |
|
| 83 | - $this->sessionService->set('videoReturnUrl', GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); |
|
| 84 | - |
|
| 85 | - $uri = $this->uriBuilder->setTargetPageUid($formPage) |
|
| 86 | - ->build(); |
|
| 87 | - HttpUtility::redirect($uri, HttpUtility::HTTP_STATUS_403); |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * @param Form $form |
|
| 93 | - */ |
|
| 94 | - public function triggerFormSubmit(Form $form) |
|
| 95 | - { |
|
| 96 | - if ($this->sessionService->has('videoReturnUrl') && $this->isProtectionForm($form)) { |
|
| 97 | - $forms = $this->sessionService->has($this->sessionName) ? $this->sessionService->get($this->sessionName) : []; |
|
| 98 | - $forms[] = $form->getUid(); |
|
| 99 | - $this->sessionService->set($this->sessionName, $forms); |
|
| 100 | - HttpUtility::redirect($this->sessionService->get('videoReturnUrl')); |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Find the given page UID of the form Protection ID |
|
| 106 | - * |
|
| 107 | - * @param int $formProtectionId |
|
| 108 | - * |
|
| 109 | - * @return int |
|
| 110 | - */ |
|
| 111 | - protected function findFormPage($formProtectionId) |
|
| 112 | - { |
|
| 113 | - $pluings = $this->findPowermailPlugins(); |
|
| 114 | - foreach ($pluings as $plugin) { |
|
| 115 | - $configuration = $this->flexFormService->convertFlexFormContentToArray($plugin['pi_flexform']); |
|
| 116 | - if (isset($configuration['settings']['flexform']['main']['form'])) { |
|
| 117 | - $formId = $configuration['settings']['flexform']['main']['form']; |
|
| 118 | - if (MathUtility::canBeInterpretedAsInteger($formId) && (int)$formId == $formProtectionId) { |
|
| 119 | - return $plugin['pid']; |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - return 0; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Find all includes Powermail plugins |
|
| 128 | - * |
|
| 129 | - * @return array |
|
| 130 | - */ |
|
| 131 | - protected function findPowermailPlugins() |
|
| 132 | - { |
|
| 133 | - $database = GlobalUtility::getDatabaseConnection(); |
|
| 134 | - $pageRepository = new PageRepository(); |
|
| 135 | - return $database->exec_SELECTgetRows('uid,pid,pi_flexform', 'tt_content', 'CType="list" AND list_type="powermail_pi1"' . $pageRepository->enableFields('tt_content')); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @param $formProtectionId |
|
| 140 | - * |
|
| 141 | - * @return bool |
|
| 142 | - */ |
|
| 143 | - protected function isAccessableByCurrentUser($formProtectionId) |
|
| 144 | - { |
|
| 145 | - $forms = $this->sessionService->has($this->sessionName) ? $this->sessionService->get($this->sessionName) : []; |
|
| 146 | - return in_array((int)$formProtectionId, $forms); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * @param Form $form |
|
| 151 | - * |
|
| 152 | - * @return bool |
|
| 153 | - */ |
|
| 154 | - protected function isProtectionForm(Form $form) |
|
| 155 | - { |
|
| 156 | - return (bool)GlobalUtility::getDatabaseConnection() |
|
| 157 | - ->exec_SELECTcountRows('*', 'tx_html5videoplayer_domain_model_video', 'powermail_protection=' . $form->getUid()); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Get the Form protection value |
|
| 162 | - * |
|
| 163 | - * @param Video $video |
|
| 164 | - * |
|
| 165 | - * @return int |
|
| 166 | - */ |
|
| 167 | - protected function getFormProtection(Video $video) |
|
| 168 | - { |
|
| 169 | - $record = BackendUtility::getRecord('tx_html5videoplayer_domain_model_video', $video->getUid()); |
|
| 170 | - return (int)$record['powermail_protection']; |
|
| 171 | - } |
|
| 28 | + /** |
|
| 29 | + * Session service |
|
| 30 | + * |
|
| 31 | + * @var \HVP\Html5videoplayerPowermail\Service\SessionService |
|
| 32 | + * @inject |
|
| 33 | + */ |
|
| 34 | + protected $sessionService; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Uri Builder |
|
| 38 | + * |
|
| 39 | + * @var \TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder |
|
| 40 | + * @inject |
|
| 41 | + */ |
|
| 42 | + protected $uriBuilder; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Flexform service |
|
| 46 | + * |
|
| 47 | + * @var \TYPO3\CMS\Extbase\Service\FlexFormService |
|
| 48 | + * @inject |
|
| 49 | + */ |
|
| 50 | + protected $flexFormService; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * The session name |
|
| 54 | + * |
|
| 55 | + * @var string |
|
| 56 | + */ |
|
| 57 | + protected $sessionName = 'submittedForms'; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * @param Video $video |
|
| 61 | + */ |
|
| 62 | + public function checkVideoAccess(Video $video = null) |
|
| 63 | + { |
|
| 64 | + if ($video === null) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $formProtection = $this->getFormProtection($video); |
|
| 69 | + if ($formProtection <= 0) { |
|
| 70 | + return; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // disable the cache |
|
| 74 | + GlobalUtility::getTypoScriptFrontendController() |
|
| 75 | + ->set_no_cache('Do not cache video detail page, because every request is check via html5videoplayer_powermail'); |
|
| 76 | + |
|
| 77 | + if ($this->isAccessableByCurrentUser($formProtection)) { |
|
| 78 | + return; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $formPage = $this->findFormPage($formProtection); |
|
| 82 | + if ($formPage) { |
|
| 83 | + $this->sessionService->set('videoReturnUrl', GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); |
|
| 84 | + |
|
| 85 | + $uri = $this->uriBuilder->setTargetPageUid($formPage) |
|
| 86 | + ->build(); |
|
| 87 | + HttpUtility::redirect($uri, HttpUtility::HTTP_STATUS_403); |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * @param Form $form |
|
| 93 | + */ |
|
| 94 | + public function triggerFormSubmit(Form $form) |
|
| 95 | + { |
|
| 96 | + if ($this->sessionService->has('videoReturnUrl') && $this->isProtectionForm($form)) { |
|
| 97 | + $forms = $this->sessionService->has($this->sessionName) ? $this->sessionService->get($this->sessionName) : []; |
|
| 98 | + $forms[] = $form->getUid(); |
|
| 99 | + $this->sessionService->set($this->sessionName, $forms); |
|
| 100 | + HttpUtility::redirect($this->sessionService->get('videoReturnUrl')); |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Find the given page UID of the form Protection ID |
|
| 106 | + * |
|
| 107 | + * @param int $formProtectionId |
|
| 108 | + * |
|
| 109 | + * @return int |
|
| 110 | + */ |
|
| 111 | + protected function findFormPage($formProtectionId) |
|
| 112 | + { |
|
| 113 | + $pluings = $this->findPowermailPlugins(); |
|
| 114 | + foreach ($pluings as $plugin) { |
|
| 115 | + $configuration = $this->flexFormService->convertFlexFormContentToArray($plugin['pi_flexform']); |
|
| 116 | + if (isset($configuration['settings']['flexform']['main']['form'])) { |
|
| 117 | + $formId = $configuration['settings']['flexform']['main']['form']; |
|
| 118 | + if (MathUtility::canBeInterpretedAsInteger($formId) && (int)$formId == $formProtectionId) { |
|
| 119 | + return $plugin['pid']; |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + return 0; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Find all includes Powermail plugins |
|
| 128 | + * |
|
| 129 | + * @return array |
|
| 130 | + */ |
|
| 131 | + protected function findPowermailPlugins() |
|
| 132 | + { |
|
| 133 | + $database = GlobalUtility::getDatabaseConnection(); |
|
| 134 | + $pageRepository = new PageRepository(); |
|
| 135 | + return $database->exec_SELECTgetRows('uid,pid,pi_flexform', 'tt_content', 'CType="list" AND list_type="powermail_pi1"' . $pageRepository->enableFields('tt_content')); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @param $formProtectionId |
|
| 140 | + * |
|
| 141 | + * @return bool |
|
| 142 | + */ |
|
| 143 | + protected function isAccessableByCurrentUser($formProtectionId) |
|
| 144 | + { |
|
| 145 | + $forms = $this->sessionService->has($this->sessionName) ? $this->sessionService->get($this->sessionName) : []; |
|
| 146 | + return in_array((int)$formProtectionId, $forms); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * @param Form $form |
|
| 151 | + * |
|
| 152 | + * @return bool |
|
| 153 | + */ |
|
| 154 | + protected function isProtectionForm(Form $form) |
|
| 155 | + { |
|
| 156 | + return (bool)GlobalUtility::getDatabaseConnection() |
|
| 157 | + ->exec_SELECTcountRows('*', 'tx_html5videoplayer_domain_model_video', 'powermail_protection=' . $form->getUid()); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Get the Form protection value |
|
| 162 | + * |
|
| 163 | + * @param Video $video |
|
| 164 | + * |
|
| 165 | + * @return int |
|
| 166 | + */ |
|
| 167 | + protected function getFormProtection(Video $video) |
|
| 168 | + { |
|
| 169 | + $record = BackendUtility::getRecord('tx_html5videoplayer_domain_model_video', $video->getUid()); |
|
| 170 | + return (int)$record['powermail_protection']; |
|
| 171 | + } |
|
| 172 | 172 | } |