| @@ -16,9 +16,8 @@ | ||
| 16 | 16 | use UserAccessManager\UserGroup\UserGroupTypeException; |
| 17 | 17 | use UserAccessManager\Util\Util; |
| 18 | 18 | use UserAccessManager\Wrapper\Php; |
| 19 | 19 | use UserAccessManager\Wrapper\Wordpress; |
| 20 | -use WeakMap; | |
| 21 | 20 | use WP_Comment; |
| 22 | 21 | use WP_Hook; |
| 23 | 22 | use WP_Post; |
| 24 | 23 | use WP_Query; |
| @@ -27,10 +26,8 @@ | ||
| 27 | 26 | { |
| 28 | 27 | private array $wordpressFilters = []; |
| 29 | 28 | private stdClass|array|null $cachedCounts = []; |
| 30 | 29 | |
| 31 | - private WeakMap $posts; | |
| 32 | - | |
| 33 | 30 | public function __construct( |
| 34 | 31 | Php $php, |
| 35 | 32 | Wordpress $wordpress, |
| 36 | 33 | WordpressConfig $wordpressConfig, |
| @@ -52,10 +49,8 @@ | ||
| 52 | 49 | $userHandler, |
| 53 | 50 | $userGroupHandler, |
| 54 | 51 | $accessHandler |
| 55 | 52 | ); |
| 56 | - | |
| 57 | - $this->posts = new WeakMap(); | |
| 58 | 53 | } |
| 59 | 54 | |
| 60 | 55 | public function getWordpressFilters(): array |
| 61 | 56 | { |
| @@ -171,15 +166,15 @@ | ||
| 171 | 166 | |
| 172 | 167 | /** |
| 173 | 168 | * @throws UserGroupTypeException |
| 174 | 169 | */ |
| 175 | - private function processPost(WP_Post $post): WP_Post|bool | |
| 170 | + private function processPost(WP_Post $post): ?WP_Post | |
| 176 | 171 | { |
| 177 | 172 | $post->post_title .= $this->adminOutput($post->post_type, $post->ID); |
| 178 | 173 | |
| 179 | 174 | if ($this->accessHandler->checkObjectAccess($post->post_type, $post->ID) === false) { |
| 180 | 175 | if ($this->removePostFromList($post->post_type) === true) { |
| 181 | - return false; | |
| 176 | + return null; | |
| 182 | 177 | } |
| 183 | 178 | |
| 184 | 179 | $post->post_content = $this->processPostContent($post); |
| 185 | 180 | |
| @@ -197,17 +192,8 @@ | ||
| 197 | 192 | |
| 198 | 193 | /** |
| 199 | 194 | * @throws UserGroupTypeException |
| 200 | 195 | */ |
| 201 | - private function getProcessedPost(WP_Post $post): ?WP_Post | |
| 202 | - { | |
| 203 | - $post = $this->posts[$post] ??= $this->processPost($post); | |
| 204 | - return $post === false ? null : $post; | |
| 205 | - } | |
| 206 | - | |
| 207 | - /** | |
| 208 | - * @throws UserGroupTypeException | |
| 209 | - */ | |
| 210 | 196 | private function filterRawPosts(array $rawPosts): array |
| 211 | 197 | { |
| 212 | 198 | $filteredPosts = []; |
| 213 | 199 | |
| @@ -214,9 +200,9 @@ | ||
| 214 | 200 | foreach ($rawPosts as $rawPost) { |
| 215 | 201 | $post = $this->getPost($rawPost); |
| 216 | 202 | |
| 217 | 203 | if ($post !== false) { |
| 218 | - $post = $this->getProcessedPost($post); | |
| 204 | + $post = $this->processPost($post); | |
| 219 | 205 | |
| 220 | 206 | if ($post !== null) { |
| 221 | 207 | $filteredPosts[] = $post; |
| 222 | 208 | } |
| @@ -253,9 +239,9 @@ | ||
| 253 | 239 | |
| 254 | 240 | /** |
| 255 | 241 | * @throws UserGroupTypeException |
| 256 | 242 | */ |
| 257 | - public function getAttachedFile(string $file, int|string|null $attachmentId): bool|string | |
| 243 | + public function getAttachedFile(string $file, int|string $attachmentId): bool|string | |
| 258 | 244 | { |
| 259 | 245 | $isImage = (bool) preg_match('/(?i)\.(jpg|jpeg|jpe|png|gif)$/', $file); |
| 260 | 246 | |
| 261 | 247 | if ($isImage === false && $this->mainConfig->lockFile() === true) { |
| @@ -273,9 +259,9 @@ | ||
| 273 | 259 | { |
| 274 | 260 | $excludedPosts = $this->accessHandler->getExcludedPosts(); |
| 275 | 261 | |
| 276 | 262 | if ($excludedPosts !== []) { |
| 277 | - $excludedPostsStr = implode(', ', array_map('intval', $excludedPosts)); | |
| 263 | + $excludedPostsStr = implode(', ', $excludedPosts); | |
| 278 | 264 | $query .= " AND $table.ID NOT IN ($excludedPostsStr) "; |
| 279 | 265 | } |
| 280 | 266 | |
| 281 | 267 | return $query; |
| @@ -298,13 +284,13 @@ | ||
| 298 | 284 | } |
| 299 | 285 | |
| 300 | 286 | private function getPostCountQuery(array $excludedPosts, string $type, string $perm): string |
| 301 | 287 | { |
| 302 | - $excludedPosts = implode(', ', array_map('intval', $excludedPosts)); | |
| 303 | - $query = "SELECT post_status, COUNT(*) AS num_posts | |
| 304 | - FROM {$this->database->getPostsTable()} | |
| 288 | + $excludedPosts = implode('\', \'', $excludedPosts); | |
| 289 | + $query = "SELECT post_status, COUNT(*) AS num_posts | |
| 290 | + FROM {$this->database->getPostsTable()} | |
| 305 | 291 | WHERE post_type = %s |
| 306 | - AND ID NOT IN ($excludedPosts)"; | |
| 292 | + AND ID NOT IN ('$excludedPosts')"; | |
| 307 | 293 | |
| 308 | 294 | if ('readable' === $perm |
| 309 | 295 | && $this->wordpress->isUserLoggedIn() === true |
| 310 | 296 | && $this->wordpress->currentUserCan( |
| @@ -387,9 +373,9 @@ | ||
| 387 | 373 | |
| 388 | 374 | /** |
| 389 | 375 | * @throws UserGroupTypeException |
| 390 | 376 | */ |
| 391 | - public function showEditLink(?string $link, int|string|null $postId): string | |
| 377 | + public function showEditLink(?string $link, int|string $postId): string | |
| 392 | 378 | { |
| 393 | 379 | if ($this->mainConfig->hideEditLinkOnNoAccess() === true |
| 394 | 380 | && $this->accessHandler->checkObjectAccess(ObjectHandler::GENERAL_POST_OBJECT_TYPE, $postId, true) === false |
| 395 | 381 | ) { |