PluginProbe
User Access Manager / 2.3.2
User Access Manager v2.3.2
2.3.20 2.3.19 2.3.18 2.3.17 2.3.16 2.3.15 2.3.14 2.3.13 trunk 0.6 0.6.1 0.6.2 0.7 0.7 Beta 0.7.0.1 0.8 0.8.0.1 0.8.0.2 0.9 0.9.1 0.9.1.1 0.9.1.2 0.9.1.3 0.9.1.4 1.0 All 136 releases
← All changes | src/Controller/Frontend/RedirectController.php +31 -65 2.3.162.3.2 View file →
@@ -24,9 +24,8 @@
24 24 {
25 25 use LoginControllerTrait;
26 26
27 27 public const POST_URL_CACHE_KEY = 'PostUrls';
28 - public const REDIRECT_TO_PARAMETER = 'redirect_to';
29 28
30 29 public function __construct(
31 30 Php $php,
32 31 Wordpress $wordpress,
@@ -73,74 +72,48 @@
73 72
74 73 return $postUrls[$url];
75 74 }
76 75
77 - private function normalizeAttachmentUrl(array $uploadDirs, string $objectUrl): string
76 + private function getFileSettingsByType(string $objectType, string $objectUrl): ?FileObject
78 77 {
79 - $uploadDir = str_replace(ABSPATH, '/', $uploadDirs['basedir']);
80 - $regex = '/.*' . str_replace('/', '\/', $uploadDir) . '\//i';
81 - $cleanObjectUrl = preg_replace($regex, '', $objectUrl);
82 - $uploadUrl = str_replace('/files', $uploadDir, $uploadDirs['baseurl']);
78 + $fileObject = null;
83 79
84 - return rtrim($uploadUrl, '/') . '/' . ltrim($cleanObjectUrl, '/');
85 - }
80 + if ($objectType === ObjectHandler::ATTACHMENT_OBJECT_TYPE) {
81 + $uploadDirs = $this->wordpress->getUploadDir();
82 + $uploadDir = str_replace(ABSPATH, '/', $uploadDirs['basedir']);
83 + $regex = '/.*' . str_replace('/', '\/', $uploadDir) . '\//i';
84 + $cleanObjectUrl = preg_replace($regex, '', $objectUrl);
85 + $uploadUrl = str_replace('/files', $uploadDir, $uploadDirs['baseurl']);
86 + $objectUrl = rtrim($uploadUrl, '/') . '/' . ltrim($cleanObjectUrl, '/');
86 87
87 - private function getAttachmentFileObject(string $objectUrl): ?FileObject
88 - {
89 - $uploadDirs = $this->wordpress->getUploadDir();
90 - $postId = $this->getPostIdByUrl($this->normalizeAttachmentUrl($uploadDirs, $objectUrl));
88 + $post = $this->objectHandler->getPost($this->getPostIdByUrl($objectUrl));
89 + $postType = $post->post_type ?? '';
91 90
92 - if ($postId < 1) {
93 - return null;
94 - }
91 + if ($postType === ObjectHandler::ATTACHMENT_OBJECT_TYPE) {
92 + $multiPath = str_replace('/files', $uploadDir, $uploadDirs['baseurl']);
95 93
96 - $post = $this->objectHandler->getPost($postId);
94 + $fileObject = $this->fileObjectFactory->createFileObject(
95 + $post->ID,
96 + $objectType,
97 + $uploadDirs['basedir'] . str_replace($multiPath, '', $objectUrl),
98 + $this->wordpress->attachmentIsImage($post->ID)
99 + );
100 + }
101 + } else {
102 + $extraParameter = $this->getRequestParameter('uamextra');
97 103
98 - if (($post->post_type ?? '') !== ObjectHandler::ATTACHMENT_OBJECT_TYPE) {
99 - return null;
104 + $fileObject = $this->wordpress->applyFilters(
105 + 'uam_get_file_settings_by_type',
106 + $fileObject,
107 + $objectType,
108 + $objectUrl,
109 + $extraParameter
110 + );
100 111 }
101 112
102 - $file = $this->wordpress->getAttachedFile($post->ID);
103 -
104 - if ($file === false || $this->isInsideUploadDirectory($file, $uploadDirs['basedir']) === false) {
105 - return null;
106 - }
107 -
108 - return $this->fileObjectFactory->createFileObject(
109 - $post->ID,
110 - ObjectHandler::ATTACHMENT_OBJECT_TYPE,
111 - $file,
112 - $this->wordpress->attachmentIsImage($post->ID)
113 - );
113 + return $fileObject;
114 114 }
115 115
116 - private function isInsideUploadDirectory(string $file, string $uploadBaseDir): bool
117 - {
118 - $realFile = $this->php->realpath($file);
119 - $realUploadBaseDir = $this->php->realpath($uploadBaseDir);
120 -
121 - return $realFile !== false
122 - && $realUploadBaseDir !== false
123 - && str_starts_with($realFile, $realUploadBaseDir . DIRECTORY_SEPARATOR);
124 - }
125 -
126 - private function getFileSettingsByType(string $objectType, string $objectUrl): ?FileObject
127 - {
128 - if ($objectType === ObjectHandler::ATTACHMENT_OBJECT_TYPE) {
129 - return $this->getAttachmentFileObject($objectUrl);
130 - }
131 -
132 - $extraParameter = $this->getRequestParameter('uamextra');
133 -
134 - return $this->wordpress->applyFilters(
135 - 'uam_get_file_settings_by_type',
136 - null,
137 - $objectType,
138 - $objectUrl,
139 - $extraParameter
140 - );
141 - }
142 -
143 116 /**
144 117 * @throws UserGroupTypeException
145 118 */
146 119 public function getFile(string $objectType, string $objectUrl): void
@@ -185,11 +158,8 @@
185 158 } elseif ($redirect === 'custom_url') {
186 159 $url = $this->mainConfig->getRedirectCustomUrl();
187 160 } elseif ($redirect === 'login') {
188 161 $url = $this->getLoginUrl();
189 - } elseif ($redirect === 'origin') {
190 - $referer = $this->wordpress->getReferer();
191 - $url = $referer !== false ? $referer : $this->wordpress->getHomeUrl('/');
192 162 } else {
193 163 $url = $this->wordpress->getHomeUrl('/');
194 164 }
195 165
@@ -214,12 +184,8 @@
214 184 $url = $this->getRedirectUrlAndPermalink($permalink);
215 185 $currentUrl = $this->util->getCurrentUrl();
216 186
217 187 if ($url !== null && $url !== $currentUrl && $permalink !== $currentUrl) {
218 - if ($this->mainConfig->appendRedirectToParameter() === true) {
219 - $url = $this->wordpress->addQueryArg([self::REDIRECT_TO_PARAMETER => $currentUrl], $url);
220 - }
221 -
222 188 $this->wordpress->wpRedirect($url);
223 189 $this->php->callExit();
224 190 }
225 191 }
@@ -292,9 +258,9 @@
292 258
293 259 return $headers;
294 260 }
295 261
296 - public function getFileUrl(string $url, int|string|null $id): string
262 + public function getFileUrl(string $url, int|string $id): string
297 263 {
298 264 // Nginx always supports real urls so we need the new urls only
299 265 // if we don't use nginx and mod_rewrite is disabled
300 266 if ($this->mainConfig->lockFile() === true