PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.1.4
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.1.4
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 / page / plugin.php

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

281 lines 9.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
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(&$customView)
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()
54 {
55 $this->replaceOptions = [
56 'link' => ['ACYM_LINK'],
57 'picthtml' => ['ACYM_IMAGE'],
58 'readmore' => ['ACYM_READ_MORE'],
59 ];
60 }
61
62 public function initElementOptionsCustomView()
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()
76 {
77 return $this->pluginDescription;
78 }
79
80 public function insertionOptions($defaultValues = null)
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 echo $this->displaySelectionZone($zoneContent);
126 echo $this->pluginHelper->displayOptions($displayOptions, $this->name, 'individual', $this->defaultValues);
127 }
128
129 public function prepareListing()
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 $rows[$i]->post_title = acym_tooltip(
147 [
148 'hoveredText' => '<i class="acymicon-exclamation-triangle"></i>',
149 'textShownInTooltip' => acym_translation('ACYM_SPECIAL_CONTENT_WARNING'),
150 ]
151 ).$rows[$i]->post_title;
152 }
153 }
154
155 $listingOptions = [
156 'header' => [
157 'post_title' => [
158 'label' => 'ACYM_TITLE',
159 'size' => '7',
160 ],
161 'post_date' => [
162 'label' => 'ACYM_DATE_CREATED',
163 'size' => '4',
164 'type' => 'date',
165 ],
166 'ID' => [
167 'label' => 'ACYM_ID',
168 'size' => '1',
169 'class' => 'text-center',
170 ],
171 ],
172 'id' => 'ID',
173 'rows' => $rows,
174 ];
175
176 return $this->getElementsListing($listingOptions);
177 }
178
179 public function replaceContent(&$email)
180 {
181 $this->replaceOne($email);
182 }
183
184 public function replaceIndividualContent($tag)
185 {
186 $query = 'SELECT page.*
187 FROM #__posts AS page
188 WHERE page.post_type = "page"
189 AND page.post_status = "publish"
190 AND page.ID = '.intval($tag->id);
191
192 $element = $this->initIndividualContent($tag, $query);
193
194 if (empty($element)) return '';
195
196 $varFields = $this->getCustomLayoutVars($element);
197
198 $link = get_permalink($element->ID);
199 $link = $this->getLinkTranslated($link);
200 $varFields['{link}'] = $link;
201
202 $title = '';
203 $varFields['{title}'] = $element->post_title;
204 if (in_array('title', $tag->display)) $title = $varFields['{title}'];
205
206 $afterTitle = '';
207 $afterArticle = '';
208
209 $imagePath = '';
210 $imageId = get_post_thumbnail_id($tag->id);
211 if (!empty($imageId)) {
212 $imagePath = get_the_post_thumbnail_url($tag->id);
213 }
214 $varFields['{image}'] = $imagePath;
215 $varFields['{picthtml}'] = '<img alt="" src="'.$imagePath.'">';
216 if (!in_array('image', $tag->display)) $imagePath = '';
217
218 $contentText = '';
219 $varFields['{content}'] = $this->cleanExtensionContent($element->post_content);
220 $varFields['{intro}'] = $this->cleanExtensionContent($this->getIntro($element->post_content));
221 $varFields['{content}'] = !empty($tag->replaceshortcode) ? $this->replaceShortcode($varFields['{content}']) : $varFields['{content}'];
222 $varFields['{intro}'] = !empty($tag->replaceshortcode) ? $this->replaceShortcode($varFields['{intro}']) : $varFields['{intro}'];
223 if (in_array('content', $tag->display)) {
224 $contentText .= $varFields['{content}'];
225 } elseif (in_array('intro', $tag->display)) {
226 $contentText .= $varFields['{intro}'];
227 }
228
229 $customFields = [];
230
231 $varFields['{readmore}'] = '<a class="acymailing_readmore_link" style="text-decoration:none;" target="_blank" href="'.$link.'"><span class="acymailing_readmore">'.acym_escape(
232 acym_translation('ACYM_READ_MORE')
233 ).'</span></a>';
234 if (in_array('readmore', $tag->display)) $afterArticle .= $varFields['{readmore}'];
235
236 $format = new stdClass();
237 $format->tag = $tag;
238 $format->title = $title;
239 $format->afterTitle = $afterTitle;
240 $format->afterArticle = $afterArticle;
241 $format->imagePath = $imagePath;
242 $format->description = $contentText;
243 $format->link = empty($tag->clickable) && empty($tag->clickableimg) ? '' : $link;
244 $format->customFields = $customFields;
245 $result = '<div class="acymailing_content">'.$this->pluginHelper->getStandardDisplay($format).'</div>';
246
247 return $this->finalizeElementFormat($result, $tag, $varFields);
248 }
249
250 protected function getTranslationId($elementId, $translationTool, $defaultLanguage = false)
251 {
252 $elementId = intval($elementId);
253 $languageCode = $this->emailLanguage;
254
255 if ($defaultLanguage) {
256 $languageCode = $this->config->get('multilingual_default', ACYM_DEFAULT_LANGUAGE);
257 } else {
258 $idDefaultLanguage = $this->getTranslationId($elementId, $translationTool, true);
259
260 if ($idDefaultLanguage !== $elementId) {
261 return $elementId;
262 }
263 }
264
265 $languageCode = substr($languageCode, 0, 2);
266
267 if ($translationTool === 'polylang') {
268 if (acym_isExtensionActive('polylang/polylang.php') && function_exists('pll_get_post')) {
269 $translationId = pll_get_post($elementId, $languageCode);
270 if (!empty($translationId)) $elementId = $translationId;
271 }
272 } elseif ($translationTool === 'wpml') {
273 if (acym_isExtensionActive('sitepress-multilingual-cms/sitepress.php')) {
274 $elementId = apply_filters('wpml_object_id', $elementId, 'post', true, $languageCode);
275 }
276 }
277
278 return intval($elementId);
279 }
280 }
281