PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / trunk
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress vtrunk
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 10.3.0 10.4.0 All 60 releases
acymailing / back / dynamics / page / plugin.php

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

284 lines 10.1 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
5 class plgAcymPage extends AcymPlugin
6 {
7 public function __construct()
8 {
9 parent::__construct();
10 $this->cms = 'WordPress';
11
12 $this->pluginDescription->name = acym_translation('ACYM_PAGE');
13 $this->pluginDescription->icon = '<div class="wp-menu-image dashicons-before dashicons-admin-page"></div>';
14 $this->pluginDescription->icontype = 'raw';
15
16 if (ACYM_CMS === 'wordpress') {
17 $this->displayOptions = [
18 'title' => ['ACYM_TITLE', true],
19 'image' => ['ACYM_FEATURED_IMAGE', true],
20 'intro' => ['ACYM_INTRO_ONLY', true],
21 'content' => ['ACYM_FULL_TEXT', false],
22 'readmore' => ['ACYM_READ_MORE', false],
23 ];
24
25 $this->initCustomView();
26
27 $this->settings = [
28 'custom_view' => [
29 'type' => 'custom_view',
30 'tags' => array_merge($this->displayOptions, $this->replaceOptions, $this->elementOptions),
31 ],
32 ];
33 }
34 }
35
36 public function getStandardStructure(string &$customView): void
37 {
38 $tag = new stdClass();
39 $tag->id = 0;
40
41 $format = new stdClass();
42 $format->tag = $tag;
43 $format->title = '{title}';
44 $format->afterTitle = '';
45 $format->afterArticle = '';
46 $format->imagePath = '{image}';
47 $format->description = '{intro}';
48 $format->link = '{link}';
49 $format->customFields = [];
50 $customView = '<div class="acymailing_content">'.$this->pluginHelper->getStandardDisplay($format).'</div>';
51 }
52
53 public function initReplaceOptionsCustomView(): void
54 {
55 $this->replaceOptions = [
56 'link' => ['ACYM_LINK'],
57 'picthtml' => ['ACYM_IMAGE'],
58 'readmore' => ['ACYM_READ_MORE'],
59 ];
60 }
61
62 public function initElementOptionsCustomView(): void
63 {
64 $query = 'SELECT page.*
65 FROM #__posts AS page
66 WHERE page.post_type = "page"
67 AND page.post_status = "publish"';
68 $element = acym_loadObject($query);
69 if (empty($element)) return;
70 foreach ($element as $key => $value) {
71 $this->elementOptions[$key] = [$key];
72 }
73 }
74
75 public function getPossibleIntegrations(): ?object
76 {
77 return $this->pluginDescription;
78 }
79
80 public function insertionOptions(?object $defaultValues = null): void
81 {
82 $this->defaultValues = $defaultValues;
83
84 $displayOptions = [
85 [
86 'title' => 'ACYM_DISPLAY',
87 'type' => 'checkbox',
88 'name' => 'display',
89 'options' => $this->displayOptions,
90 ],
91 [
92 'title' => 'ACYM_CLICKABLE_TITLE',
93 'type' => 'boolean',
94 'name' => 'clickable',
95 'default' => true,
96 ],
97 [
98 'title' => 'ACYM_CLICKABLE_IMAGE',
99 'type' => 'boolean',
100 'name' => 'clickableimg',
101 'default' => false,
102 ],
103 [
104 'title' => 'ACYM_REPLACE_SHORTCODES',
105 'type' => 'boolean',
106 'name' => 'replaceshortcode',
107 'default' => false,
108 ],
109 [
110 'title' => 'ACYM_TRUNCATE',
111 'type' => 'intextfield',
112 'isNumber' => 1,
113 'name' => 'wrap',
114 'text' => 'ACYM_TRUNCATE_AFTER',
115 'default' => 0,
116 ],
117 [
118 'title' => 'ACYM_DISPLAY_PICTURES',
119 'type' => 'pictures',
120 'name' => 'pictures',
121 ],
122 ];
123
124 $zoneContent = $this->getFilteringZone(false).$this->prepareListing();
125 $this->displaySelectionZone($zoneContent);
126 $this->pluginHelper->displayOptions($displayOptions, $this->name, 'individual', $this->defaultValues);
127 }
128
129 public function prepareListing(): string
130 {
131 $this->querySelect = 'SELECT page.ID, page.post_title, page.post_date, page.post_content ';
132 $this->query = 'FROM #__posts AS page ';
133 $this->filters = [];
134 $this->filters[] = 'page.post_type = "page"';
135 $this->filters[] = 'page.post_status = "publish"';
136 $this->searchFields = ['page.ID', 'page.post_title'];
137 $this->pageInfo->order = 'page.ID';
138 $this->elementIdTable = 'page';
139 $this->elementIdColumn = 'ID';
140
141 parent::prepareListing();
142
143 $rows = $this->getElements();
144 foreach ($rows as $i => $row) {
145 if (str_replace(['wp:core-embed', 'wp:shortcode'], '', $row->post_content) !== $row->post_content) {
146 ob_start();
147 acym_tooltip(
148 [
149 'hoveredText' => '<i class="acymicon-exclamation-triangle"></i>',
150 'textShownInTooltip' => acym_translation('ACYM_SPECIAL_CONTENT_WARNING'),
151 ]
152 );
153 $rows[$i]->post_title = ob_get_clean().$rows[$i]->post_title;
154 }
155 }
156
157 $listingOptions = [
158 'header' => [
159 'post_title' => [
160 'label' => 'ACYM_TITLE',
161 'size' => '7',
162 ],
163 'post_date' => [
164 'label' => 'ACYM_DATE_CREATED',
165 'size' => '4',
166 'type' => 'date',
167 ],
168 'ID' => [
169 'label' => 'ACYM_ID',
170 'size' => '1',
171 'class' => 'text-center',
172 ],
173 ],
174 'id' => 'ID',
175 'rows' => $rows,
176 ];
177
178 return $this->getElementsListing($listingOptions);
179 }
180
181 public function replaceContent(object &$email): void
182 {
183 $this->replaceOne($email);
184 }
185
186 public function replaceIndividualContent(object $tag): string
187 {
188 $query = 'SELECT page.*
189 FROM #__posts AS page
190 WHERE page.post_type = "page"
191 AND page.post_status = "publish"
192 AND page.ID = '.intval($tag->id);
193
194 $element = $this->initIndividualContent($tag, $query);
195
196 if (empty($element)) return '';
197
198 $varFields = $this->getCustomLayoutVars($element);
199
200 $link = get_permalink($element->ID);
201 $link = $this->getLinkTranslated($link);
202 $varFields['{link}'] = $link;
203
204 $title = '';
205 $varFields['{title}'] = $element->post_title;
206 if (in_array('title', $tag->display)) $title = $varFields['{title}'];
207
208 $afterTitle = '';
209 $afterArticle = '';
210
211 $imagePath = '';
212 $imageId = get_post_thumbnail_id($tag->id);
213 if (!empty($imageId)) {
214 $imagePath = get_the_post_thumbnail_url($tag->id);
215 }
216 $varFields['{image}'] = $imagePath;
217 $varFields['{picthtml}'] = '<img alt="" src="'.$imagePath.'">';
218 if (!in_array('image', $tag->display)) $imagePath = '';
219
220 $contentText = '';
221 $varFields['{content}'] = $this->cleanExtensionContent($element->post_content);
222 $varFields['{intro}'] = $this->cleanExtensionContent($this->getIntro($element->post_content));
223 $varFields['{content}'] = !empty($tag->replaceshortcode) ? $this->replaceShortcode($varFields['{content}']) : $varFields['{content}'];
224 $varFields['{intro}'] = !empty($tag->replaceshortcode) ? $this->replaceShortcode($varFields['{intro}']) : $varFields['{intro}'];
225 if (in_array('content', $tag->display)) {
226 $contentText .= $varFields['{content}'];
227 } elseif (in_array('intro', $tag->display)) {
228 $contentText .= $varFields['{intro}'];
229 }
230
231 $customFields = [];
232
233 $varFields['{readmore}'] = '<a class="acymailing_readmore_link" style="text-decoration:none;" target="_blank" href="'.$link.'"><span class="acymailing_readmore">'.esc_html(
234 acym_translation('ACYM_READ_MORE')
235 ).'</span></a>';
236 if (in_array('readmore', $tag->display)) $afterArticle .= $varFields['{readmore}'];
237
238 $format = new stdClass();
239 $format->tag = $tag;
240 $format->title = $title;
241 $format->afterTitle = $afterTitle;
242 $format->afterArticle = $afterArticle;
243 $format->imagePath = $imagePath;
244 $format->description = $contentText;
245 $format->link = empty($tag->clickable) && empty($tag->clickableimg) ? '' : $link;
246 $format->customFields = $customFields;
247 $result = '<div class="acymailing_content">'.$this->pluginHelper->getStandardDisplay($format).'</div>';
248
249 return $this->finalizeElementFormat($result, $tag, $varFields);
250 }
251
252 protected function getTranslationId(int $elementId, string $translationTool, bool $defaultLanguage = false): int
253 {
254 $languageCode = $this->emailLanguage;
255
256 if ($defaultLanguage) {
257 $languageCode = $this->config->get('multilingual_default', ACYM_DEFAULT_LANGUAGE);
258 } else {
259 $idDefaultLanguage = $this->getTranslationId($elementId, $translationTool, true);
260
261 // We only translate inserted articles of the default language
262 if ($idDefaultLanguage !== $elementId) {
263 return $elementId;
264 }
265 }
266
267 $languageCode = substr($languageCode, 0, 2);
268
269 if ($translationTool === 'polylang') {
270 if (acym_isExtensionActive('polylang/polylang.php') && function_exists('pll_get_post')) {
271 $translationId = pll_get_post($elementId, $languageCode);
272 if (!empty($translationId)) $elementId = $translationId;
273 }
274 } elseif ($translationTool === 'wpml') {
275 if (acym_isExtensionActive('sitepress-multilingual-cms/sitepress.php')) {
276 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- WPML hook for integration.
277 $elementId = apply_filters('wpml_object_id', $elementId, 'post', true, $languageCode);
278 }
279 }
280
281 return intval($elementId);
282 }
283 }
284