PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.0.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.0.0
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
acymailing / back / dynamics / post / plugin.php

plugin.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 11.0.0, at back/dynamics/post/plugin.php

665 lines 24.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 use AcyMailing\Core\AcymPlugin;
4 use AcyMailing\Helpers\TabHelper;
5
6 class plgAcymPost extends AcymPlugin
7 {
8 private bool $groupedByCategory = false;
9 private $currentCategory = null;
10 private array $acfFields = [];
11 private array $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(string &$customView): void
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(): void
101 {
102 $this->replaceOptions = [
103 'link' => ['ACYM_LINK'],
104 'picthtml' => ['ACYM_IMAGE'],
105 'readmore' => ['ACYM_READ_MORE'],
106 ];
107 }
108
109 public function initElementOptionsCustomView(): void
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(): ?object
123 {
124 return $this->pluginDescription;
125 }
126
127 public function insertionOptions(?object $defaultValues = null): void
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 $this->displaySelectionZone($zoneContent);
217 $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 $this->displaySelectionZone($warningMessage.$this->getCategoryListing());
254 $this->pluginHelper->displayOptions($displayOptions, $identifier, 'grouped', $this->defaultValues);
255
256 $tabHelper->endTab();
257
258 $tabHelper->display('plugin');
259 }
260
261 public function prepareListing(): string
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 a category is selected
276 if (!empty($this->pageInfo->filter_cat)) {
277 $this->query .= 'JOIN #__term_relationships AS cat ON post.ID = cat.object_id';
278 $this->filters[] = 'cat.term_taxonomy_id = '.intval($this->pageInfo->filter_cat);
279 }
280
281 $rows = $this->getElements();
282 foreach ($rows as $i => $row) {
283 if (str_replace(['wp:core-embed', 'wp:shortcode'], '', $row->post_content) !== $row->post_content) {
284 ob_start();
285 acym_tooltip(
286 [
287 'hoveredText' => '<i class="acymicon-exclamation-triangle"></i>',
288 'textShownInTooltip' => acym_translation('ACYM_SPECIAL_CONTENT_WARNING'),
289 ]
290 );
291 $rows[$i]->post_title = ob_get_clean().$rows[$i]->post_title;
292 }
293 }
294
295 $listingOptions = [
296 'header' => [
297 'post_title' => [
298 'label' => 'ACYM_TITLE',
299 'size' => '7',
300 ],
301 'post_date' => [
302 'label' => 'ACYM_PUBLISHING_DATE',
303 'size' => '4',
304 'type' => 'date',
305 ],
306 'ID' => [
307 'label' => 'ACYM_ID',
308 'size' => '1',
309 'class' => 'text-center',
310 ],
311 ],
312 'id' => 'ID',
313 'rows' => $rows,
314 ];
315
316 return $this->getElementsListing($listingOptions);
317 }
318
319 public function replaceContent(object &$email): void
320 {
321 $this->initAcfData();
322 $this->replaceMultiple($email);
323 $this->replaceOne($email);
324 }
325
326 public function generateByCategory(object &$email): object
327 {
328 $tags = $this->pluginHelper->extractTags($email, 'auto'.$this->name);
329 $this->tags = [];
330
331 if (empty($tags)) return $this->generateCampaignResult;
332
333 foreach ($tags as $oneTag => $parameter) {
334 if (isset($this->tags[$oneTag])) continue;
335
336 $query = 'SELECT DISTINCT post.`ID`
337 FROM #__posts AS post
338 LEFT JOIN #__term_relationships AS cat ON post.ID = cat.object_id';
339
340 $where = [];
341
342 $selectedArea = $this->getSelectedArea($parameter);
343 if (!empty($selectedArea)) {
344 $where[] = 'cat.term_taxonomy_id IN ('.implode(',', $selectedArea).')';
345 }
346
347 $where[] = 'post.post_type = "post"';
348 $where[] = 'post.post_status = "publish"';
349 if (!empty($parameter->min_publish)) {
350 $parameter->min_publish = acym_date(acym_replaceDate($parameter->min_publish), 'Y-m-d H:i:s', false);
351 $where[] = 'post.post_date_gmt >= '.acym_escapeDB($parameter->min_publish);
352 }
353
354 if (!empty($parameter->onlynew)) {
355 $lastGenerated = $this->getLastGenerated($email->id);
356 if (!empty($lastGenerated)) {
357 $where[] = 'post.post_date_gmt > '.acym_escapeDB(acym_date($lastGenerated, 'Y-m-d H:i:s', false));
358 }
359 }
360
361 $query .= ' WHERE ('.implode(') AND (', $where).')';
362
363 $this->groupedByCategory = !empty($parameter->groupbycat);
364 $this->tags[$oneTag] = $this->finalizeCategoryFormat($query, $parameter, 'post');
365 }
366
367 return $this->generateCampaignResult;
368 }
369
370 protected function groupByCategory(array $elements): array
371 {
372 if (!$this->groupedByCategory || empty($elements)) return $elements;
373
374 acym_arrayToInteger($elements);
375 $idsWithCatids = acym_loadObjectList(
376 'SELECT map.`object_id`, taxonomy.`term_id`
377 FROM #__term_relationships AS map
378 JOIN #__term_taxonomy AS taxonomy
379 ON map.`term_taxonomy_id` = taxonomy.`term_taxonomy_id`
380 WHERE taxonomy.`taxonomy` = "category"
381 AND map.`object_id` IN ('.implode(', ', $elements).')'
382 );
383 usort(
384 $idsWithCatids,
385 function ($a, $b) {
386 return strtolower($a->term_id) > strtolower($b->term_id) ? 1 : -1;
387 }
388 );
389 $elements = [];
390 foreach ($idsWithCatids as $oneArticle) {
391 if (in_array($oneArticle->object_id, $elements)) continue;
392 $elements[] = $oneArticle->object_id;
393 }
394
395 return $elements;
396 }
397
398 public function replaceIndividualContent(object $tag): string
399 {
400 $allowedStatuses = ['publish'];
401 $allowedStatuses = acym_triggerCmsHook('onAcymPostInsertion', [$allowedStatuses], false);
402 if (empty($allowedStatuses) || !is_array($allowedStatuses)) {
403 $allowedStatuses = ['publish'];
404 }
405 $allowedStatuses = array_map('acym_escapeDB', $allowedStatuses);
406
407 $query = 'SELECT post.*, `user`.`user_nicename`, `user`.`display_name`
408 FROM #__posts AS post
409 LEFT JOIN #__users AS `user`
410 ON `user`.`ID` = `post`.`post_author`
411 WHERE post.post_type = "post"
412 AND post.post_status IN ('.implode(', ', $allowedStatuses).')
413 AND post.ID = '.intval($tag->id);
414
415 $element = $this->initIndividualContent($tag, $query);
416
417 if (empty($element)) return '';
418
419 $varFields = $this->getCustomLayoutVars($element);
420
421 $link = get_permalink($element->ID);
422 $link = $this->getLinkTranslated($link);
423 $varFields['{link}'] = $link;
424
425 $title = '';
426 $varFields['{title}'] = $element->post_title;
427 if (in_array('title', $tag->display)) $title = $varFields['{title}'];
428
429 $afterTitle = '';
430 $afterArticle = '';
431
432 $imagePath = '';
433 $imageId = get_post_thumbnail_id($tag->id);
434 if (!empty($imageId)) {
435 if (empty($tag->size)) $tag->size = 'full';
436 $imagePath = get_the_post_thumbnail_url($tag->id, $tag->size);
437 }
438 $varFields['{image}'] = $imagePath;
439 $varFields['{picthtml}'] = '<img class="content_main_image" alt="" src="'.$imagePath.'">';
440 if (!in_array('image', $tag->display)) $imagePath = '';
441
442 $contentText = '';
443 $varFields['{excerpt}'] = $this->cleanExtensionContent($element->post_excerpt);
444 if (in_array('excerpt', $tag->display) && !empty($varFields['{excerpt}'])) {
445 $contentText .= '<p>'.$varFields['{excerpt}'].'</p>';
446 }
447
448 $varFields['{content}'] = $this->cleanExtensionContent($element->post_content);
449 $varFields['{intro}'] = $this->cleanExtensionContent($this->getIntro($element->post_content));
450 $varFields['{content}'] = !empty($tag->replaceshortcode) ? $this->replaceShortcode($varFields['{content}']) : $varFields['{content}'];
451 $varFields['{intro}'] = !empty($tag->replaceshortcode) ? $this->replaceShortcode($varFields['{intro}']) : $varFields['{intro}'];
452 if (in_array('content', $tag->display)) {
453 $contentText .= $varFields['{content}'];
454 } elseif (in_array('intro', $tag->display)) {
455 $contentText .= $varFields['{intro}'];
456 }
457
458 $customFields = [];
459 $varFields['{author}'] = empty($element->display_name) ? $element->user_nicename : $element->display_name;
460 if (in_array('author', $tag->display) && !empty($varFields['{author}'])) {
461 $customFields[] = [
462 $varFields['{author}'],
463 acym_translation('ACYM_AUTHOR'),
464 ];
465 }
466
467 $varFields['{cats}'] = get_the_term_list($tag->id, 'category', '', ', ');
468 if (in_array('cats', $tag->display)) {
469 $customFields[] = [
470 $varFields['{cats}'],
471 acym_translation('ACYM_CATEGORIES'),
472 ];
473 }
474
475 $varFields['{readmore}'] = '<a class="acymailing_readmore_link" style="text-decoration:none;" target="_blank" href="'.$link.'"><span class="acymailing_readmore">'.esc_html(
476 acym_translation('ACYM_READ_MORE')
477 ).'</span></a>';
478 if (in_array('readmore', $tag->display)) {
479 $afterArticle .= $varFields['{readmore}'];
480 }
481
482 if (!empty($this->acfFields)) {
483 $tag->acf = empty($tag->acf) ? [] : explode(',', $tag->acf);
484
485 foreach ($this->acfFields as $field) {
486 $varFields['{'.$field['name'].'}'] = acf_get_value($tag->id, $field);
487
488 if (empty($varFields['{'.$field['name'].'}']) && (!is_string($varFields['{'.$field['name'].'}']) || strlen($varFields['{'.$field['name'].'}']) === 0)) {
489 continue;
490 }
491
492 $varFields['{'.$field['name'].'}'] = $this->getFormattedAcfFieldValue($varFields['{'.$field['name'].'}'], $tag->id, $field);
493
494 if (in_array($field['ID'], $tag->acf) && strlen($varFields['{'.$field['name'].'}']) > 0) {
495 $customFields[] = [
496 $varFields['{'.$field['name'].'}'],
497 acf_get_field_label($field),
498 ];
499 }
500 }
501 }
502
503 $format = new stdClass();
504 $format->tag = $tag;
505 $format->title = $title;
506 $format->afterTitle = $afterTitle;
507 $format->afterArticle = $afterArticle;
508 $format->imagePath = $imagePath;
509 $format->description = $contentText;
510 $format->link = empty($tag->clickable) && empty($tag->clickableimg) ? '' : $link;
511 $format->customFields = $customFields;
512 $result = '<div class="acymailing_content">'.$this->pluginHelper->getStandardDisplay($format).'</div>';
513
514 $categoryTitle = '';
515 $postCategories = acym_loadObjectList(
516 'SELECT terms.`term_id`, terms.`name`
517 FROM #__terms AS terms
518 JOIN #__term_taxonomy AS taxonomy
519 ON terms.`term_id` = taxonomy.`term_id`
520 JOIN #__term_relationships AS map
521 ON map.`term_taxonomy_id` = taxonomy.`term_taxonomy_id`
522 WHERE map.`object_id` = '.intval($element->ID),
523 'term_id'
524 );
525 $catIds = array_keys($postCategories);
526 if (!empty($tag->groupbycat) && !in_array($this->currentCategory, $catIds)) {
527 $this->currentCategory = min($catIds);
528
529 $categoryTitle = '<h1 class="acymailing_category_title">'.$postCategories[$this->currentCategory]->name.'</h1>';
530 $categoryTitle = '<div class="acymailing_content"><a target="_blank" href="'.get_category_link($this->currentCategory).'">'.$categoryTitle.'</a></div>';
531 }
532
533 return $categoryTitle.$this->finalizeElementFormat($result, $tag, $varFields);
534 }
535
536 /**
537 * Used in Gutenberg block and elementor
538 *
539 * @param bool $ajax
540 * @param int $postPerPage
541 *
542 * @return array|array[]|void
543 */
544 public function getPosts(bool $ajax = true, int $postPerPage = 20)
545 {
546 $return = $ajax ? [] : [0 => [0, acym_translation('ACYM_SELECT_AN_ARTICLE')]];
547
548 $search = acym_getVar('string', 'searchedterm', '');
549 if (!empty($search)) {
550 $search = acym_escapeDB('%'.$search.'%');
551 $search = 'post_title LIKE '.$search.' OR post_name LIKE '.$search.' OR post_content LIKE '.$search;
552 $search = ' AND ('.$search.')';
553 }
554
555 $limit = '';
556 if (!empty($postPerPage)) {
557 $limit = 'LIMIT '.$postPerPage;
558 }
559
560 $query = 'SELECT ID, post_title FROM #__posts WHERE post_status = "publish" AND post_type IN ("post", "page") '.$search.' '.$limit;
561 $posts = acym_loadObjectList($query);
562 foreach ($posts as $post) {
563 $return[] = [$post->ID, $post->post_title];
564 }
565
566 if ($ajax) {
567 echo json_encode($return);
568 exit;
569 } else {
570 return $return;
571 }
572 }
573
574 protected function getTranslationId(int $elementId, string $translationTool, bool $defaultLanguage = false): int
575 {
576 $languageCode = $this->emailLanguage;
577
578 if ($defaultLanguage) {
579 $languageCode = $this->config->get('multilingual_default', ACYM_DEFAULT_LANGUAGE);
580 } else {
581 $idDefaultLanguage = $this->getTranslationId($elementId, $translationTool, true);
582
583 // We only translate inserted articles of the default language
584 if ($idDefaultLanguage !== $elementId) {
585 return $elementId;
586 }
587 }
588
589 $languageCode = substr($languageCode, 0, 2);
590
591 if ($translationTool === 'polylang') {
592 if (acym_isExtensionActive('polylang/polylang.php') && function_exists('pll_get_post')) {
593 $translationId = pll_get_post($elementId, $languageCode);
594 if (!empty($translationId)) $elementId = $translationId;
595 }
596 } elseif ($translationTool === 'wpml') {
597 if (acym_isExtensionActive('sitepress-multilingual-cms/sitepress.php')) {
598 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML hook for integration.
599 $elementId = apply_filters('wpml_object_id', $elementId, 'post', true, $languageCode);
600 }
601 }
602
603 return intval($elementId);
604 }
605
606 private function initAcfData(): void
607 {
608 $installed = acym_isExtensionActive('advanced-custom-fields/acf.php') || acym_isExtensionActive('advanced-custom-fields-pro/acf.php');
609 if (!$installed || !function_exists('acf_get_field_groups')) {
610 return;
611 }
612
613 $fieldGroups = acf_get_field_groups(['post_type' => 'post']);
614 foreach ($fieldGroups as $fieldGroup) {
615 if (empty($fieldGroup['active'])) {
616 continue;
617 }
618
619 $this->acfFields = array_merge($this->acfFields, acf_get_fields($fieldGroup));
620 }
621 }
622
623 private function getFormattedAcfFieldValue($value, $postId, $field): string
624 {
625 $value = acf_format_value($value, $postId, $field);
626 if ($field['type'] === 'email') {
627 $value = '<a href="mailto:'.$value.'">'.$value.'</a>';
628 } elseif ($field['type'] === 'url') {
629 $value = '<a href="'.$value.'" target="_blank">'.$value.'</a>';
630 } elseif ($field['type'] === 'link') {
631 $value = '<a href="'.$value['url'].'" target="_blank">'.(empty($value['title']) ? $value['url'] : $value['title']).'</a>';
632 } elseif ($field['type'] === 'image') {
633 if (empty($value['link'])) {
634 $value = '';
635 } else {
636 $value = '<img alt="'.esc_attr($value['alt']).'" src="'.esc_url($value['link']).'" />';
637 }
638 } elseif (in_array($field['type'], ['checkbox', 'select'])) {
639 if (is_array($value)) {
640 $value = implode(', ', $value);
641 }
642 } elseif ($field['type'] === 'true_false') {
643 $value = empty($value) ? acym_translation('ACYM_NO') : acym_translation('ACYM_YES');
644 } elseif ($field['type'] === 'file') {
645 if (empty($value['link'])) {
646 $value = '';
647 } else {
648 $value = '<a href="'.$value['link'].'" target="_blank">'.esc_html(
649 $value['filename']
650 ).'</a>';
651 }
652 } elseif ($field['type'] === 'textarea') {
653 $value = nl2br($value);
654 } elseif (in_array($field['type'], ['time_picker', 'date_picker', 'date_time_picker'])) {
655 if ($field['display_format'] !== $field['return_format']) {
656 $value = gmdate($field['display_format'], strtotime($value));
657 }
658 } else {
659 $value = esc_html($value);
660 }
661
662 return $value;
663 }
664 }
665