| @@ -4,12 +4,12 @@ | ||
| 4 | 4 | use AcyMailing\Helpers\TabHelper; |
| 5 | 5 | |
| 6 | 6 | class plgAcymPost extends AcymPlugin |
| 7 | 7 | { |
| 8 | - private $groupedByCategory = false; | |
| 8 | + private bool $groupedByCategory = false; | |
| 9 | 9 | private $currentCategory = null; |
| 10 | - private $acfFields = []; | |
| 11 | - private $handledFieldTypes = [ | |
| 10 | + private array $acfFields = []; | |
| 11 | + private array $handledFieldTypes = [ | |
| 12 | 12 | 'text', |
| 13 | 13 | 'textarea', |
| 14 | 14 | 'number', |
| 15 | 15 | 'range', |
| @@ -79,9 +79,9 @@ | ||
| 79 | 79 | $this->customOptions[$customField->post_excerpt] = [$customField->post_title]; |
| 80 | 80 | } |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | - public function getStandardStructure(&$customView) | |
| 83 | + public function getStandardStructure(string &$customView): void | |
| 84 | 84 | { |
| 85 | 85 | $tag = new stdClass(); |
| 86 | 86 | $tag->id = 0; |
| 87 | 87 | |
| @@ -96,9 +96,9 @@ | ||
| 96 | 96 | $format->customFields = []; |
| 97 | 97 | $customView = '<div class="acymailing_content">'.$this->pluginHelper->getStandardDisplay($format).'</div>'; |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | - public function initReplaceOptionsCustomView() | |
| 100 | + public function initReplaceOptionsCustomView(): void | |
| 101 | 101 | { |
| 102 | 102 | $this->replaceOptions = [ |
| 103 | 103 | 'link' => ['ACYM_LINK'], |
| 104 | 104 | 'picthtml' => ['ACYM_IMAGE'], |
| @@ -105,9 +105,9 @@ | ||
| 105 | 105 | 'readmore' => ['ACYM_READ_MORE'], |
| 106 | 106 | ]; |
| 107 | 107 | } |
| 108 | 108 | |
| 109 | - public function initElementOptionsCustomView() | |
| 109 | + public function initElementOptionsCustomView(): void | |
| 110 | 110 | { |
| 111 | 111 | $query = 'SELECT post.* |
| 112 | 112 | FROM #__posts AS post |
| 113 | 113 | WHERE post.post_type = "post" |
| @@ -118,14 +118,14 @@ | ||
| 118 | 118 | $this->elementOptions[$key] = [$key]; |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - public function getPossibleIntegrations() | |
| 122 | + public function getPossibleIntegrations(): ?object | |
| 123 | 123 | { |
| 124 | 124 | return $this->pluginDescription; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - public function insertionOptions($defaultValues = null) | |
| 127 | + public function insertionOptions(?object $defaultValues = null): void | |
| 128 | 128 | { |
| 129 | 129 | $this->defaultValues = $defaultValues; |
| 130 | 130 | $this->prepareWPCategories('category'); |
| 131 | 131 | |
| @@ -212,10 +212,10 @@ | ||
| 212 | 212 | ] |
| 213 | 213 | ); |
| 214 | 214 | |
| 215 | 215 | $zoneContent = $this->getFilteringZone().$this->prepareListing(); |
| 216 | - echo $this->displaySelectionZone($zoneContent); | |
| 217 | - echo $this->pluginHelper->displayOptions($displayOptions, $identifier, 'individual', $this->defaultValues); | |
| 216 | + $this->displaySelectionZone($zoneContent); | |
| 217 | + $this->pluginHelper->displayOptions($displayOptions, $identifier, 'individual', $this->defaultValues); | |
| 218 | 218 | |
| 219 | 219 | $tabHelper->endTab(); |
| 220 | 220 | $identifier = 'auto'.$this->name; |
| 221 | 221 | $tabHelper->startTab(acym_translation('ACYM_BY_CATEGORY'), !empty($this->defaultValues->defaultPluginTab) && $identifier === $this->defaultValues->defaultPluginTab); |
| @@ -249,10 +249,10 @@ | ||
| 249 | 249 | |
| 250 | 250 | ob_start(); |
| 251 | 251 | acym_display(acym_translation('ACYM_SPECIAL_CONTENT_WARNING'), 'warning', false); |
| 252 | 252 | $warningMessage = ob_get_clean(); |
| 253 | - echo $this->displaySelectionZone($warningMessage.$this->getCategoryListing()); | |
| 254 | - echo $this->pluginHelper->displayOptions($displayOptions, $identifier, 'grouped', $this->defaultValues); | |
| 253 | + $this->displaySelectionZone($warningMessage.$this->getCategoryListing()); | |
| 254 | + $this->pluginHelper->displayOptions($displayOptions, $identifier, 'grouped', $this->defaultValues); | |
| 255 | 255 | |
| 256 | 256 | $tabHelper->endTab(); |
| 257 | 257 | |
| 258 | 258 | $tabHelper->display('plugin'); |
| @@ -257,9 +257,9 @@ | ||
| 257 | 257 | |
| 258 | 258 | $tabHelper->display('plugin'); |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | - public function prepareListing() | |
| 261 | + public function prepareListing(): string | |
| 262 | 262 | { |
| 263 | 263 | $this->querySelect = 'SELECT post.ID, post.post_title, post.post_date, post.post_content '; |
| 264 | 264 | $this->query = 'FROM #__posts AS post '; |
| 265 | 265 | $this->filters = []; |
| @@ -271,25 +271,14 @@ | ||
| 271 | 271 | $this->elementIdColumn = 'ID'; |
| 272 | 272 | |
| 273 | 273 | parent::prepareListing(); |
| 274 | 274 | |
| 275 | + //if a category is selected | |
| 275 | 276 | if (!empty($this->pageInfo->filter_cat)) { |
| 276 | 277 | $this->query .= 'JOIN #__term_relationships AS cat ON post.ID = cat.object_id'; |
| 277 | 278 | $this->filters[] = 'cat.term_taxonomy_id = '.intval($this->pageInfo->filter_cat); |
| 278 | 279 | } |
| 279 | 280 | |
| 280 | - $rows = $this->getElements(); | |
| 281 | - foreach ($rows as $i => $row) { | |
| 282 | - if (str_replace(['wp:core-embed', 'wp:shortcode'], '', $row->post_content) !== $row->post_content) { | |
| 283 | - $rows[$i]->post_title = acym_tooltip( | |
| 284 | - [ | |
| 285 | - 'hoveredText' => '<i class="acymicon-exclamation-triangle"></i>', | |
| 286 | - 'textShownInTooltip' => acym_translation('ACYM_SPECIAL_CONTENT_WARNING'), | |
| 287 | - ] | |
| 288 | - ).$rows[$i]->post_title; | |
| 289 | - } | |
| 290 | - } | |
| 291 | - | |
| 292 | 281 | $listingOptions = [ |
| 293 | 282 | 'header' => [ |
| 294 | 283 | 'post_title' => [ |
| 295 | 284 | 'label' => 'ACYM_TITLE', |
| @@ -306,15 +295,15 @@ | ||
| 306 | 295 | 'class' => 'text-center', |
| 307 | 296 | ], |
| 308 | 297 | ], |
| 309 | 298 | 'id' => 'ID', |
| 310 | - 'rows' => $rows, | |
| 299 | + 'rows' => $this->getElements(), | |
| 311 | 300 | ]; |
| 312 | 301 | |
| 313 | 302 | return $this->getElementsListing($listingOptions); |
| 314 | 303 | } |
| 315 | 304 | |
| 316 | - public function replaceContent(&$email) | |
| 305 | + public function replaceContent(object &$email): void | |
| 317 | 306 | { |
| 318 | 307 | $this->initAcfData(); |
| 319 | 308 | $this->replaceMultiple($email); |
| 320 | 309 | $this->replaceOne($email); |
| @@ -319,9 +308,9 @@ | ||
| 319 | 308 | $this->replaceMultiple($email); |
| 320 | 309 | $this->replaceOne($email); |
| 321 | 310 | } |
| 322 | 311 | |
| 323 | - public function generateByCategory(&$email) | |
| 312 | + public function generateByCategory(object &$email): object | |
| 324 | 313 | { |
| 325 | 314 | $tags = $this->pluginHelper->extractTags($email, 'auto'.$this->name); |
| 326 | 315 | $this->tags = []; |
| 327 | 316 | |
| @@ -363,9 +352,9 @@ | ||
| 363 | 352 | |
| 364 | 353 | return $this->generateCampaignResult; |
| 365 | 354 | } |
| 366 | 355 | |
| 367 | - protected function groupByCategory($elements) | |
| 356 | + protected function groupByCategory(array $elements): array | |
| 368 | 357 | { |
| 369 | 358 | if (!$this->groupedByCategory || empty($elements)) return $elements; |
| 370 | 359 | |
| 371 | 360 | acym_arrayToInteger($elements); |
| @@ -391,9 +380,9 @@ | ||
| 391 | 380 | |
| 392 | 381 | return $elements; |
| 393 | 382 | } |
| 394 | 383 | |
| 395 | - public function replaceIndividualContent($tag) | |
| 384 | + public function replaceIndividualContent(object $tag): string | |
| 396 | 385 | { |
| 397 | 386 | $allowedStatuses = ['publish']; |
| 398 | 387 | $allowedStatuses = acym_triggerCmsHook('onAcymPostInsertion', [$allowedStatuses], false); |
| 399 | 388 | if (empty($allowedStatuses) || !is_array($allowedStatuses)) { |
| @@ -468,9 +457,9 @@ | ||
| 468 | 457 | acym_translation('ACYM_CATEGORIES'), |
| 469 | 458 | ]; |
| 470 | 459 | } |
| 471 | 460 | |
| 472 | - $varFields['{readmore}'] = '<a class="acymailing_readmore_link" style="text-decoration:none;" target="_blank" href="'.$link.'"><span class="acymailing_readmore">'.acym_escape( | |
| 461 | + $varFields['{readmore}'] = '<a class="acymailing_readmore_link" style="text-decoration:none;" target="_blank" href="'.$link.'"><span class="acymailing_readmore">'.esc_html( | |
| 473 | 462 | acym_translation('ACYM_READ_MORE') |
| 474 | 463 | ).'</span></a>'; |
| 475 | 464 | if (in_array('readmore', $tag->display)) { |
| 476 | 465 | $afterArticle .= $varFields['{readmore}']; |
| @@ -523,14 +512,22 @@ | ||
| 523 | 512 | if (!empty($tag->groupbycat) && !in_array($this->currentCategory, $catIds)) { |
| 524 | 513 | $this->currentCategory = min($catIds); |
| 525 | 514 | |
| 526 | 515 | $categoryTitle = '<h1 class="acymailing_category_title">'.$postCategories[$this->currentCategory]->name.'</h1>'; |
| 527 | - $categoryTitle = '<a target="_blank" href="'.get_category_link($this->currentCategory).'">'.$categoryTitle.'</a>'; | |
| 516 | + $categoryTitle = '<div class="acymailing_content"><a target="_blank" href="'.get_category_link($this->currentCategory).'">'.$categoryTitle.'</a></div>'; | |
| 528 | 517 | } |
| 529 | 518 | |
| 530 | 519 | return $categoryTitle.$this->finalizeElementFormat($result, $tag, $varFields); |
| 531 | 520 | } |
| 532 | 521 | |
| 522 | + /** | |
| 523 | + * Used in Gutenberg block and elementor | |
| 524 | + * | |
| 525 | + * @param bool $ajax | |
| 526 | + * @param int $postPerPage | |
| 527 | + * | |
| 528 | + * @return array|array[]|void | |
| 529 | + */ | |
| 533 | 530 | public function getPosts(bool $ajax = true, int $postPerPage = 20) |
| 534 | 531 | { |
| 535 | 532 | $return = $ajax ? [] : [0 => [0, acym_translation('ACYM_SELECT_AN_ARTICLE')]]; |
| 536 | 533 | |
| @@ -559,11 +556,10 @@ | ||
| 559 | 556 | return $return; |
| 560 | 557 | } |
| 561 | 558 | } |
| 562 | 559 | |
| 563 | - protected function getTranslationId($elementId, $translationTool, $defaultLanguage = false) | |
| 560 | + protected function getTranslationId(int $elementId, string $translationTool, bool $defaultLanguage = false): int | |
| 564 | 561 | { |
| 565 | - $elementId = intval($elementId); | |
| 566 | 562 | $languageCode = $this->emailLanguage; |
| 567 | 563 | |
| 568 | 564 | if ($defaultLanguage) { |
| 569 | 565 | $languageCode = $this->config->get('multilingual_default', ACYM_DEFAULT_LANGUAGE); |
| @@ -569,8 +565,9 @@ | ||
| 569 | 565 | $languageCode = $this->config->get('multilingual_default', ACYM_DEFAULT_LANGUAGE); |
| 570 | 566 | } else { |
| 571 | 567 | $idDefaultLanguage = $this->getTranslationId($elementId, $translationTool, true); |
| 572 | 568 | |
| 569 | + // We only translate inserted articles of the default language | |
| 573 | 570 | if ($idDefaultLanguage !== $elementId) { |
| 574 | 571 | return $elementId; |
| 575 | 572 | } |
| 576 | 573 | } |
| @@ -583,8 +580,9 @@ | ||
| 583 | 580 | if (!empty($translationId)) $elementId = $translationId; |
| 584 | 581 | } |
| 585 | 582 | } elseif ($translationTool === 'wpml') { |
| 586 | 583 | if (acym_isExtensionActive('sitepress-multilingual-cms/sitepress.php')) { |
| 584 | + // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML hook for integration. | |
| 587 | 585 | $elementId = apply_filters('wpml_object_id', $elementId, 'post', true, $languageCode); |
| 588 | 586 | } |
| 589 | 587 | } |
| 590 | 588 | |
| @@ -592,9 +590,10 @@ | ||
| 592 | 590 | } |
| 593 | 591 | |
| 594 | 592 | private function initAcfData(): void |
| 595 | 593 | { |
| 596 | - if (!acym_isExtensionActive('advanced-custom-fields/acf.php') || !function_exists('acf_get_field_groups')) { | |
| 594 | + $installed = acym_isExtensionActive('advanced-custom-fields/acf.php') || acym_isExtensionActive('advanced-custom-fields-pro/acf.php'); | |
| 595 | + if (!$installed || !function_exists('acf_get_field_groups')) { | |
| 597 | 596 | return; |
| 598 | 597 | } |
| 599 | 598 | |
| 600 | 599 | $fieldGroups = acf_get_field_groups(['post_type' => 'post']); |
| @@ -619,11 +618,9 @@ | ||
| 619 | 618 | } elseif ($field['type'] === 'image') { |
| 620 | 619 | if (empty($value['link'])) { |
| 621 | 620 | $value = ''; |
| 622 | 621 | } else { |
| 623 | - $alt = acym_escape($value['alt']); | |
| 624 | - | |
| 625 | - $value = '<img alt="'.$alt.'" src="'.$value['link'].'" />'; | |
| 622 | + $value = '<img alt="'.esc_attr($value['alt']).'" src="'.esc_url($value['link']).'" />'; | |
| 626 | 623 | } |
| 627 | 624 | } elseif (in_array($field['type'], ['checkbox', 'select'])) { |
| 628 | 625 | if (is_array($value)) { |
| 629 | 626 | $value = implode(', ', $value); |
| @@ -633,9 +630,9 @@ | ||
| 633 | 630 | } elseif ($field['type'] === 'file') { |
| 634 | 631 | if (empty($value['link'])) { |
| 635 | 632 | $value = ''; |
| 636 | 633 | } else { |
| 637 | - $value = '<a href="'.$value['link'].'" target="_blank">'.acym_escape( | |
| 634 | + $value = '<a href="'.$value['link'].'" target="_blank">'.esc_html( | |
| 638 | 635 | $value['filename'] |
| 639 | 636 | ).'</a>'; |
| 640 | 637 | } |
| 641 | 638 | } elseif ($field['type'] === 'textarea') { |
| @@ -641,12 +638,12 @@ | ||
| 641 | 638 | } elseif ($field['type'] === 'textarea') { |
| 642 | 639 | $value = nl2br($value); |
| 643 | 640 | } elseif (in_array($field['type'], ['time_picker', 'date_picker', 'date_time_picker'])) { |
| 644 | 641 | if ($field['display_format'] !== $field['return_format']) { |
| 645 | - $value = date($field['display_format'], strtotime($value)); | |
| 642 | + $value = gmdate($field['display_format'], strtotime($value)); | |
| 646 | 643 | } |
| 647 | 644 | } else { |
| 648 | - $value = acym_escape($value); | |
| 645 | + $value = esc_html($value); | |
| 649 | 646 | } |
| 650 | 647 | |
| 651 | 648 | return $value; |
| 652 | 649 | } |