PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.1
11.1.1 11.1.0 11.0.5 11.0.4 11.0.3 11.0.2 11.0.1 11.0.0 10.11.1 10.11.0 10.10.2 10.10.1 10.10.0 10.9.1 trunk 10.0.0 10.0.1 10.1.0 10.1.1 10.1.2 10.1.3 10.1.4 10.2.0 10.2.1 10.2.2 All 62 releases
← All changes | back/dynamics/post/plugin.php +0 -654 10.2.2 → 11.1.1 View file →
@@ -1,654 +1,0 @@
1 -<?php
2 -
3 -use AcyMailing\Core\AcymPlugin;
4 -use AcyMailing\Helpers\TabHelper;
5 -
6 -class plgAcymPost extends AcymPlugin
7 -{
8 - private $groupedByCategory = false;
9 - private $currentCategory = null;
10 - private $acfFields = [];
11 - private $handledFieldTypes = [
12 - 'text',
13 - 'textarea',
14 - 'number',
15 - 'range',
16 - 'email',
17 - 'url',
18 - 'password',
19 - 'image',
20 - 'file',
21 - 'select',
22 - 'checkbox',
23 - 'radio',
24 - 'true_false',
25 - 'date_picker',
26 - 'date_time_picker',
27 - 'time_picker',
28 - 'color_picker',
29 - 'button_group',
30 - 'link',
31 - ];
32 -
33 - public function __construct()
34 - {
35 - parent::__construct();
36 - $this->cms = 'WordPress';
37 - $this->rootCategoryId = 0;
38 -
39 - $this->pluginDescription->name = acym_translation('ACYM_ARTICLE');
40 - $this->pluginDescription->icon = '<i class="cell acymicon-wordpress"></i>';
41 - $this->pluginDescription->icontype = 'raw';
42 -
43 - if (ACYM_CMS === 'wordpress') {
44 - $this->displayOptions = [
45 - 'title' => ['ACYM_TITLE', true],
46 - 'image' => ['ACYM_FEATURED_IMAGE', true],
47 - 'excerpt' => ['ACYM_EXCERPT', false],
48 - 'intro' => ['ACYM_INTRO_ONLY', true],
49 - 'content' => ['ACYM_FULL_TEXT', false],
50 - 'cats' => ['ACYM_CATEGORIES', false],
51 - 'author' => ['ACYM_AUTHOR', false],
52 - 'readmore' => ['ACYM_READ_MORE', false],
53 - ];
54 -
55 - $this->initCustomView(true);
56 -
57 - $this->settings = [
58 - 'custom_view' => [
59 - 'type' => 'custom_view',
60 - 'tags' => array_merge($this->displayOptions, $this->replaceOptions, $this->customOptions, $this->elementOptions),
61 - ],
62 - ];
63 - }
64 - }
65 -
66 - public function initCustomOptionsCustomView()
67 - {
68 - $customFields = acym_loadObjectList('SELECT post_title, post_excerpt, post_content FROM #__posts WHERE post_status = "publish" AND post_type = "acf-field"');
69 - if (empty($customFields)) {
70 - return;
71 - }
72 -
73 - foreach ($customFields as $customField) {
74 - $settings = unserialize($customField->post_content);
75 - if (!in_array($settings['type'], $this->handledFieldTypes)) {
76 - continue;
77 - }
78 -
79 - $this->customOptions[$customField->post_excerpt] = [$customField->post_title];
80 - }
81 - }
82 -
83 - public function getStandardStructure(&$customView)
84 - {
85 - $tag = new stdClass();
86 - $tag->id = 0;
87 -
88 - $format = new stdClass();
89 - $format->tag = $tag;
90 - $format->title = '{title}';
91 - $format->afterTitle = '';
92 - $format->afterArticle = '';
93 - $format->imagePath = '{image}';
94 - $format->description = '{intro}';
95 - $format->link = '{link}';
96 - $format->customFields = [];
97 - $customView = '<div class="acymailing_content">'.$this->pluginHelper->getStandardDisplay($format).'</div>';
98 - }
99 -
100 - public function initReplaceOptionsCustomView()
101 - {
102 - $this->replaceOptions = [
103 - 'link' => ['ACYM_LINK'],
104 - 'picthtml' => ['ACYM_IMAGE'],
105 - 'readmore' => ['ACYM_READ_MORE'],
106 - ];
107 - }
108 -
109 - public function initElementOptionsCustomView()
110 - {
111 - $query = 'SELECT post.*
112 - FROM #__posts AS post
113 - WHERE post.post_type = "post"
114 - AND post.post_status = "publish"';
115 - $element = acym_loadObject($query);
116 - if (empty($element)) return;
117 - foreach ($element as $key => $value) {
118 - $this->elementOptions[$key] = [$key];
119 - }
120 - }
121 -
122 - public function getPossibleIntegrations()
123 - {
124 - return $this->pluginDescription;
125 - }
126 -
127 - public function insertionOptions($defaultValues = null)
128 - {
129 - $this->defaultValues = $defaultValues;
130 - $this->prepareWPCategories('category');
131 -
132 - $tabHelper = new TabHelper();
133 - $identifier = $this->name;
134 - $tabHelper->startTab(acym_translation('ACYM_ONE_BY_ONE'), !empty($this->defaultValues->defaultPluginTab) && $identifier === $this->defaultValues->defaultPluginTab);
135 -
136 - $defaultSizes = ['thumbnail', 'medium', 'medium_large', 'large', 'post-thumbnail'];
137 - $imageFeaturedSize = ['full' => 'ACYM_ORIGINAL_IMAGE_RESOLUTION'];
138 -
139 - foreach (wp_get_registered_image_subsizes() as $sizeName => $sizes) {
140 - if (in_array($sizeName, $defaultSizes) && (!empty($sizes['width']) || !empty($sizes['height']))) {
141 - $imageFeaturedSize[$sizeName] = $sizes['width'].'x'.$sizes['height'].'px';
142 - }
143 - }
144 -
145 - $displayOptions = [
146 - [
147 - 'title' => 'ACYM_DISPLAY',
148 - 'type' => 'checkbox',
149 - 'name' => 'display',
150 - 'options' => $this->displayOptions,
151 - ],
152 - ];
153 -
154 - $this->initAcfData();
155 - if (!empty($this->acfFields)) {
156 - $customFieldsOptions = [];
157 - foreach ($this->acfFields as $field) {
158 - if (!in_array($field['type'], $this->handledFieldTypes)) {
159 - continue;
160 - }
161 - $customFieldsOptions[$field['ID']] = [$field['label'], false];
162 - }
163 - $displayOptions[] = [
164 - 'title' => 'ACF',
165 - 'type' => 'checkbox',
166 - 'name' => 'acf',
167 - 'options' => $customFieldsOptions,
168 - ];
169 - }
170 -
171 - $displayOptions = array_merge(
172 - $displayOptions,
173 - [
174 - [
175 - 'title' => 'ACYM_FEATURED_IMAGE_SIZE',
176 - 'type' => 'select',
177 - 'name' => 'size',
178 - 'options' => $imageFeaturedSize,
179 - 'default' => 'full',
180 - ],
181 - [
182 - 'title' => 'ACYM_CLICKABLE_TITLE',
183 - 'type' => 'boolean',
184 - 'name' => 'clickable',
185 - 'default' => true,
186 - ],
187 - [
188 - 'title' => 'ACYM_CLICKABLE_IMAGE',
189 - 'type' => 'boolean',
190 - 'name' => 'clickableimg',
191 - 'default' => false,
192 - ],
193 - [
194 - 'title' => 'ACYM_REPLACE_SHORTCODES',
195 - 'type' => 'boolean',
196 - 'name' => 'replaceshortcode',
197 - 'default' => false,
198 - ],
199 - [
200 - 'title' => 'ACYM_TRUNCATE',
201 - 'type' => 'intextfield',
202 - 'isNumber' => 1,
203 - 'name' => 'wrap',
204 - 'text' => 'ACYM_TRUNCATE_AFTER',
205 - 'default' => 0,
206 - ],
207 - [
208 - 'title' => 'ACYM_DISPLAY_PICTURES',
209 - 'type' => 'pictures',
210 - 'name' => 'pictures',
211 - ],
212 - ]
213 - );
214 -
215 - $zoneContent = $this->getFilteringZone().$this->prepareListing();
216 - echo $this->displaySelectionZone($zoneContent);
217 - echo $this->pluginHelper->displayOptions($displayOptions, $identifier, 'individual', $this->defaultValues);
218 -
219 - $tabHelper->endTab();
220 - $identifier = 'auto'.$this->name;
221 - $tabHelper->startTab(acym_translation('ACYM_BY_CATEGORY'), !empty($this->defaultValues->defaultPluginTab) && $identifier === $this->defaultValues->defaultPluginTab);
222 -
223 - $catOptions = [
224 - [
225 - 'title' => 'ACYM_ORDER_BY',
226 - 'type' => 'select',
227 - 'name' => 'order',
228 - 'options' => [
229 - 'ID' => 'ACYM_ID',
230 - 'post_date' => 'ACYM_PUBLISHING_DATE',
231 - 'post_modified' => 'ACYM_MODIFICATION_DATE',
232 - 'post_title' => 'ACYM_TITLE',
233 - 'menu_order' => 'ACYM_MENU_ORDER',
234 - 'rand' => 'ACYM_RANDOM',
235 - ],
236 - ],
237 - [
238 - 'title' => 'ACYM_GROUP_BY_CATEGORY',
239 - 'type' => 'boolean',
240 - 'name' => 'groupbycat',
241 - 'default' => false,
242 - ],
243 - ];
244 - $this->autoContentOptions($catOptions);
245 -
246 - $this->autoCampaignOptions($catOptions);
247 -
248 - $displayOptions = array_merge($displayOptions, $catOptions);
249 -
250 - ob_start();
251 - acym_display(acym_translation('ACYM_SPECIAL_CONTENT_WARNING'), 'warning', false);
252 - $warningMessage = ob_get_clean();
253 - echo $this->displaySelectionZone($warningMessage.$this->getCategoryListing());
254 - echo $this->pluginHelper->displayOptions($displayOptions, $identifier, 'grouped', $this->defaultValues);
255 -
256 - $tabHelper->endTab();
257 -
258 - $tabHelper->display('plugin');
259 - }
260 -
261 - public function prepareListing()
262 - {
263 - $this->querySelect = 'SELECT post.ID, post.post_title, post.post_date, post.post_content ';
264 - $this->query = 'FROM #__posts AS post ';
265 - $this->filters = [];
266 - $this->filters[] = 'post.post_type = "post"';
267 - $this->filters[] = 'post.post_status = "publish"';
268 - $this->searchFields = ['post.ID', 'post.post_title'];
269 - $this->pageInfo->order = 'post.ID';
270 - $this->elementIdTable = 'post';
271 - $this->elementIdColumn = 'ID';
272 -
273 - parent::prepareListing();
274 -
275 - if (!empty($this->pageInfo->filter_cat)) {
276 - $this->query .= 'JOIN #__term_relationships AS cat ON post.ID = cat.object_id';
277 - $this->filters[] = 'cat.term_taxonomy_id = '.intval($this->pageInfo->filter_cat);
278 - }
279 -
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 - $listingOptions = [
293 - 'header' => [
294 - 'post_title' => [
295 - 'label' => 'ACYM_TITLE',
296 - 'size' => '7',
297 - ],
298 - 'post_date' => [
299 - 'label' => 'ACYM_PUBLISHING_DATE',
300 - 'size' => '4',
301 - 'type' => 'date',
302 - ],
303 - 'ID' => [
304 - 'label' => 'ACYM_ID',
305 - 'size' => '1',
306 - 'class' => 'text-center',
307 - ],
308 - ],
309 - 'id' => 'ID',
310 - 'rows' => $rows,
311 - ];
312 -
313 - return $this->getElementsListing($listingOptions);
314 - }
315 -
316 - public function replaceContent(&$email)
317 - {
318 - $this->initAcfData();
319 - $this->replaceMultiple($email);
320 - $this->replaceOne($email);
321 - }
322 -
323 - public function generateByCategory(&$email)
324 - {
325 - $tags = $this->pluginHelper->extractTags($email, 'auto'.$this->name);
326 - $this->tags = [];
327 -
328 - if (empty($tags)) return $this->generateCampaignResult;
329 -
330 - foreach ($tags as $oneTag => $parameter) {
331 - if (isset($this->tags[$oneTag])) continue;
332 -
333 - $query = 'SELECT DISTINCT post.`ID`
334 - FROM #__posts AS post
335 - LEFT JOIN #__term_relationships AS cat ON post.ID = cat.object_id';
336 -
337 - $where = [];
338 -
339 - $selectedArea = $this->getSelectedArea($parameter);
340 - if (!empty($selectedArea)) {
341 - $where[] = 'cat.term_taxonomy_id IN ('.implode(',', $selectedArea).')';
342 - }
343 -
344 - $where[] = 'post.post_type = "post"';
345 - $where[] = 'post.post_status = "publish"';
346 - if (!empty($parameter->min_publish)) {
347 - $parameter->min_publish = acym_date(acym_replaceDate($parameter->min_publish), 'Y-m-d H:i:s', false);
348 - $where[] = 'post.post_date_gmt >= '.acym_escapeDB($parameter->min_publish);
349 - }
350 -
351 - if (!empty($parameter->onlynew)) {
352 - $lastGenerated = $this->getLastGenerated($email->id);
353 - if (!empty($lastGenerated)) {
354 - $where[] = 'post.post_date_gmt > '.acym_escapeDB(acym_date($lastGenerated, 'Y-m-d H:i:s', false));
355 - }
356 - }
357 -
358 - $query .= ' WHERE ('.implode(') AND (', $where).')';
359 -
360 - $this->groupedByCategory = !empty($parameter->groupbycat);
361 - $this->tags[$oneTag] = $this->finalizeCategoryFormat($query, $parameter, 'post');
362 - }
363 -
364 - return $this->generateCampaignResult;
365 - }
366 -
367 - protected function groupByCategory($elements)
368 - {
369 - if (!$this->groupedByCategory || empty($elements)) return $elements;
370 -
371 - acym_arrayToInteger($elements);
372 - $idsWithCatids = acym_loadObjectList(
373 - 'SELECT map.`object_id`, taxonomy.`term_id`
374 - FROM #__term_relationships AS map
375 - JOIN #__term_taxonomy AS taxonomy
376 - ON map.`term_taxonomy_id` = taxonomy.`term_taxonomy_id`
377 - WHERE taxonomy.`taxonomy` = "category"
378 - AND map.`object_id` IN ('.implode(', ', $elements).')'
379 - );
380 - usort(
381 - $idsWithCatids,
382 - function ($a, $b) {
383 - return strtolower($a->term_id) > strtolower($b->term_id) ? 1 : -1;
384 - }
385 - );
386 - $elements = [];
387 - foreach ($idsWithCatids as $oneArticle) {
388 - if (in_array($oneArticle->object_id, $elements)) continue;
389 - $elements[] = $oneArticle->object_id;
390 - }
391 -
392 - return $elements;
393 - }
394 -
395 - public function replaceIndividualContent($tag)
396 - {
397 - $allowedStatuses = ['publish'];
398 - $allowedStatuses = acym_triggerCmsHook('onAcymPostInsertion', [$allowedStatuses], false);
399 - if (empty($allowedStatuses) || !is_array($allowedStatuses)) {
400 - $allowedStatuses = ['publish'];
401 - }
402 - $allowedStatuses = array_map('acym_escapeDB', $allowedStatuses);
403 -
404 - $query = 'SELECT post.*, `user`.`user_nicename`, `user`.`display_name`
405 - FROM #__posts AS post
406 - LEFT JOIN #__users AS `user`
407 - ON `user`.`ID` = `post`.`post_author`
408 - WHERE post.post_type = "post"
409 - AND post.post_status IN ('.implode(', ', $allowedStatuses).')
410 - AND post.ID = '.intval($tag->id);
411 -
412 - $element = $this->initIndividualContent($tag, $query);
413 -
414 - if (empty($element)) return '';
415 -
416 - $varFields = $this->getCustomLayoutVars($element);
417 -
418 - $link = get_permalink($element->ID);
419 - $link = $this->getLinkTranslated($link);
420 - $varFields['{link}'] = $link;
421 -
422 - $title = '';
423 - $varFields['{title}'] = $element->post_title;
424 - if (in_array('title', $tag->display)) $title = $varFields['{title}'];
425 -
426 - $afterTitle = '';
427 - $afterArticle = '';
428 -
429 - $imagePath = '';
430 - $imageId = get_post_thumbnail_id($tag->id);
431 - if (!empty($imageId)) {
432 - if (empty($tag->size)) $tag->size = 'full';
433 - $imagePath = get_the_post_thumbnail_url($tag->id, $tag->size);
434 - }
435 - $varFields['{image}'] = $imagePath;
436 - $varFields['{picthtml}'] = '<img class="content_main_image" alt="" src="'.$imagePath.'">';
437 - if (!in_array('image', $tag->display)) $imagePath = '';
438 -
439 - $contentText = '';
440 - $varFields['{excerpt}'] = $this->cleanExtensionContent($element->post_excerpt);
441 - if (in_array('excerpt', $tag->display) && !empty($varFields['{excerpt}'])) {
442 - $contentText .= '<p>'.$varFields['{excerpt}'].'</p>';
443 - }
444 -
445 - $varFields['{content}'] = $this->cleanExtensionContent($element->post_content);
446 - $varFields['{intro}'] = $this->cleanExtensionContent($this->getIntro($element->post_content));
447 - $varFields['{content}'] = !empty($tag->replaceshortcode) ? $this->replaceShortcode($varFields['{content}']) : $varFields['{content}'];
448 - $varFields['{intro}'] = !empty($tag->replaceshortcode) ? $this->replaceShortcode($varFields['{intro}']) : $varFields['{intro}'];
449 - if (in_array('content', $tag->display)) {
450 - $contentText .= $varFields['{content}'];
451 - } elseif (in_array('intro', $tag->display)) {
452 - $contentText .= $varFields['{intro}'];
453 - }
454 -
455 - $customFields = [];
456 - $varFields['{author}'] = empty($element->display_name) ? $element->user_nicename : $element->display_name;
457 - if (in_array('author', $tag->display) && !empty($varFields['{author}'])) {
458 - $customFields[] = [
459 - $varFields['{author}'],
460 - acym_translation('ACYM_AUTHOR'),
461 - ];
462 - }
463 -
464 - $varFields['{cats}'] = get_the_term_list($tag->id, 'category', '', ', ');
465 - if (in_array('cats', $tag->display)) {
466 - $customFields[] = [
467 - $varFields['{cats}'],
468 - acym_translation('ACYM_CATEGORIES'),
469 - ];
470 - }
471 -
472 - $varFields['{readmore}'] = '<a class="acymailing_readmore_link" style="text-decoration:none;" target="_blank" href="'.$link.'"><span class="acymailing_readmore">'.acym_escape(
473 - acym_translation('ACYM_READ_MORE')
474 - ).'</span></a>';
475 - if (in_array('readmore', $tag->display)) {
476 - $afterArticle .= $varFields['{readmore}'];
477 - }
478 -
479 - if (!empty($this->acfFields)) {
480 - $tag->acf = empty($tag->acf) ? [] : explode(',', $tag->acf);
481 -
482 - foreach ($this->acfFields as $field) {
483 - $varFields['{'.$field['name'].'}'] = acf_get_value($tag->id, $field);
484 -
485 - if (empty($varFields['{'.$field['name'].'}']) && (!is_string($varFields['{'.$field['name'].'}']) || strlen($varFields['{'.$field['name'].'}']) === 0)) {
486 - continue;
487 - }
488 -
489 - $varFields['{'.$field['name'].'}'] = $this->getFormattedAcfFieldValue($varFields['{'.$field['name'].'}'], $tag->id, $field);
490 -
491 - if (in_array($field['ID'], $tag->acf) && strlen($varFields['{'.$field['name'].'}']) > 0) {
492 - $customFields[] = [
493 - $varFields['{'.$field['name'].'}'],
494 - acf_get_field_label($field),
495 - ];
496 - }
497 - }
498 - }
499 -
500 - $format = new stdClass();
501 - $format->tag = $tag;
502 - $format->title = $title;
503 - $format->afterTitle = $afterTitle;
504 - $format->afterArticle = $afterArticle;
505 - $format->imagePath = $imagePath;
506 - $format->description = $contentText;
507 - $format->link = empty($tag->clickable) && empty($tag->clickableimg) ? '' : $link;
508 - $format->customFields = $customFields;
509 - $result = '<div class="acymailing_content">'.$this->pluginHelper->getStandardDisplay($format).'</div>';
510 -
511 - $categoryTitle = '';
512 - $postCategories = acym_loadObjectList(
513 - 'SELECT terms.`term_id`, terms.`name`
514 - FROM #__terms AS terms
515 - JOIN #__term_taxonomy AS taxonomy
516 - ON terms.`term_id` = taxonomy.`term_id`
517 - JOIN #__term_relationships AS map
518 - ON map.`term_taxonomy_id` = taxonomy.`term_taxonomy_id`
519 - WHERE map.`object_id` = '.intval($element->ID),
520 - 'term_id'
521 - );
522 - $catIds = array_keys($postCategories);
523 - if (!empty($tag->groupbycat) && !in_array($this->currentCategory, $catIds)) {
524 - $this->currentCategory = min($catIds);
525 -
526 - $categoryTitle = '<h1 class="acymailing_category_title">'.$postCategories[$this->currentCategory]->name.'</h1>';
527 - $categoryTitle = '<a target="_blank" href="'.get_category_link($this->currentCategory).'">'.$categoryTitle.'</a>';
528 - }
529 -
530 - return $categoryTitle.$this->finalizeElementFormat($result, $tag, $varFields);
531 - }
532 -
533 - public function getPosts(bool $ajax = true, int $postPerPage = 20)
534 - {
535 - $return = $ajax ? [] : [0 => [0, acym_translation('ACYM_SELECT_AN_ARTICLE')]];
536 -
537 - $search = acym_getVar('string', 'searchedterm', '');
538 - if (!empty($search)) {
539 - $search = acym_escapeDB('%'.$search.'%');
540 - $search = 'post_title LIKE '.$search.' OR post_name LIKE '.$search.' OR post_content LIKE '.$search;
541 - $search = ' AND ('.$search.')';
542 - }
543 -
544 - $limit = '';
545 - if (!empty($postPerPage)) {
546 - $limit = 'LIMIT '.$postPerPage;
547 - }
548 -
549 - $query = 'SELECT ID, post_title FROM #__posts WHERE post_status = "publish" AND post_type IN ("post", "page") '.$search.' '.$limit;
550 - $posts = acym_loadObjectList($query);
551 - foreach ($posts as $post) {
552 - $return[] = [$post->ID, $post->post_title];
553 - }
554 -
555 - if ($ajax) {
556 - echo json_encode($return);
557 - exit;
558 - } else {
559 - return $return;
560 - }
561 - }
562 -
563 - protected function getTranslationId($elementId, $translationTool, $defaultLanguage = false)
564 - {
565 - $elementId = intval($elementId);
566 - $languageCode = $this->emailLanguage;
567 -
568 - if ($defaultLanguage) {
569 - $languageCode = $this->config->get('multilingual_default', ACYM_DEFAULT_LANGUAGE);
570 - } else {
571 - $idDefaultLanguage = $this->getTranslationId($elementId, $translationTool, true);
572 -
573 - if ($idDefaultLanguage !== $elementId) {
574 - return $elementId;
575 - }
576 - }
577 -
578 - $languageCode = substr($languageCode, 0, 2);
579 -
580 - if ($translationTool === 'polylang') {
581 - if (acym_isExtensionActive('polylang/polylang.php') && function_exists('pll_get_post')) {
582 - $translationId = pll_get_post($elementId, $languageCode);
583 - if (!empty($translationId)) $elementId = $translationId;
584 - }
585 - } elseif ($translationTool === 'wpml') {
586 - if (acym_isExtensionActive('sitepress-multilingual-cms/sitepress.php')) {
587 - $elementId = apply_filters('wpml_object_id', $elementId, 'post', true, $languageCode);
588 - }
589 - }
590 -
591 - return intval($elementId);
592 - }
593 -
594 - private function initAcfData(): void
595 - {
596 - $installed = acym_isExtensionActive('advanced-custom-fields/acf.php') || acym_isExtensionActive('advanced-custom-fields-pro/acf.php');
597 - if (!$installed || !function_exists('acf_get_field_groups')) {
598 - return;
599 - }
600 -
601 - $fieldGroups = acf_get_field_groups(['post_type' => 'post']);
602 - foreach ($fieldGroups as $fieldGroup) {
603 - if (empty($fieldGroup['active'])) {
604 - continue;
605 - }
606 -
607 - $this->acfFields = array_merge($this->acfFields, acf_get_fields($fieldGroup));
608 - }
609 - }
610 -
611 - private function getFormattedAcfFieldValue($value, $postId, $field): string
612 - {
613 - $value = acf_format_value($value, $postId, $field);
614 - if ($field['type'] === 'email') {
615 - $value = '<a href="mailto:'.$value.'">'.$value.'</a>';
616 - } elseif ($field['type'] === 'url') {
617 - $value = '<a href="'.$value.'" target="_blank">'.$value.'</a>';
618 - } elseif ($field['type'] === 'link') {
619 - $value = '<a href="'.$value['url'].'" target="_blank">'.(empty($value['title']) ? $value['url'] : $value['title']).'</a>';
620 - } elseif ($field['type'] === 'image') {
621 - if (empty($value['link'])) {
622 - $value = '';
623 - } else {
624 - $alt = acym_escape($value['alt']);
625 -
626 - $value = '<img alt="'.$alt.'" src="'.$value['link'].'" />';
627 - }
628 - } elseif (in_array($field['type'], ['checkbox', 'select'])) {
629 - if (is_array($value)) {
630 - $value = implode(', ', $value);
631 - }
632 - } elseif ($field['type'] === 'true_false') {
633 - $value = empty($value) ? acym_translation('ACYM_NO') : acym_translation('ACYM_YES');
634 - } elseif ($field['type'] === 'file') {
635 - if (empty($value['link'])) {
636 - $value = '';
637 - } else {
638 - $value = '<a href="'.$value['link'].'" target="_blank">'.acym_escape(
639 - $value['filename']
640 - ).'</a>';
641 - }
642 - } elseif ($field['type'] === 'textarea') {
643 - $value = nl2br($value);
644 - } elseif (in_array($field['type'], ['time_picker', 'date_picker', 'date_time_picker'])) {
645 - if ($field['display_format'] !== $field['return_format']) {
646 - $value = date($field['display_format'], strtotime($value));
647 - }
648 - } else {
649 - $value = acym_escape($value);
650 - }
651 -
652 - return $value;
653 - }
654 -}