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/Helpers/EditorHelper.php +0 -395 10.10.2 → 11.1.1 View file →
@@ -1,395 +1,0 @@
1 -<?php
2 -
3 -namespace AcyMailing\Helpers;
4 -
5 -use AcyMailing\Classes\MailClass;
6 -use AcyMailing\Classes\ZoneClass;
7 -use AcyMailing\Core\AcymObject;
8 -use AcyMailing\Types\DtextType;
9 -use Joomla\CMS\Editor\Editor as Editor;
10 -use Joomla\CMS\Factory;
11 -
12 -class EditorHelper extends AcymObject
13 -{
14 - private string $width = '95%';
15 - private string $height = '600';
16 -
17 - private int $cols = 100;
18 - private int $rows = 30;
19 -
20 - private $myEditor;
21 - public string $editor = '';
22 -
23 - private string $editorContent = '';
24 - private array $editorConfig = [];
25 - private array $emailsTest;
26 - private string $name = 'editor_content';
27 -
28 - public string $settings = 'editor_settings';
29 - public string $stylesheet = 'editor_stylesheet';
30 - public string $content = '';
31 - public int $mailId = 0;
32 - public bool $automation = false;
33 - public bool $walkThrough = false;
34 -
35 - public array $data = [];
36 - private string $defaultTemplate = '';
37 -
38 - public string $autoSave;
39 -
40 - public function display(): void
41 - {
42 - if ($this->isDragAndDrop()) {
43 - ob_start();
44 - include acym_getPartial('editor', 'default_template');
45 - $this->defaultTemplate = ob_get_clean();
46 -
47 - acym_disableCmsEditor();
48 - $currentEmail = acym_currentUserEmail();
49 - $this->emailsTest = [$currentEmail => $currentEmail];
50 - acym_addScript(false, ACYM_JS.'tinymce/tinymce.min.js?v='.filemtime(ACYM_MEDIA.'js'.DS.'tinymce/tinymce.min.js'));
51 -
52 - $data = $this->data;
53 - $mailId = empty($data['mail']->mail_id) ? (empty($data['mail']->id) ? 0 : $data['mail']->id) : $data['mail']->mail_id;
54 - $data['tabHelper'] = new TabHelper();
55 - $data['plugins'] = acym_trigger('dynamicText', [$mailId]);
56 - usort(
57 - $data['plugins'],
58 - function ($a, $b) {
59 - return strtolower($a->name ?? '') > strtolower($b->name ?? '') ? 1 : -1;
60 - }
61 - );
62 -
63 - $zoneClass = new ZoneClass();
64 - $data['custom_zones'] = $zoneClass->getAll();
65 - usort($data['custom_zones'], function ($a, $b) {
66 - return strtolower($a->name) > strtolower($b->name) ? 1 : -1;
67 - });
68 -
69 - acym_setVar('mail_id', $mailId);
70 - acym_setVar('mail_type', empty($data['mail']->type) ? '' : $data['mail']->type);
71 - acym_setVar('automation', $this->automation ? 1 : 0);
72 -
73 - include acym_getPartial('editor', 'editor_wysid');
74 - } else {
75 -
76 - if (acym_isLeftMenuNecessary()) echo '</div>';
77 -
78 - echo '</div><div class="acym_no_foundation">';
79 -
80 - $dtextType = new DtextType();
81 - $dtextType->display(['withButton' => false]);
82 -
83 - $method = 'displayWordPress';
84 - $this->$method();
85 -
86 - if (acym_isLeftMenuNecessary()) echo '<div>';
87 - }
88 - }
89 -
90 - public function isDragAndDrop(): bool
91 - {
92 - return strpos($this->content, 'acym__wysid__template') !== false || $this->editor === 'acyEditor';
93 - }
94 -
95 - private function displayJoomla(): void
96 - {
97 - $dtextType = new DtextType();
98 - $dtextType->displayButton(
99 - [
100 - 'icon' => 'acymicon-chevrons',
101 - 'text' => acym_translation('ACYM_INSERT_DYNAMIC_TEXT'),
102 - 'class' => 'button button-secondary margin-bottom-0 margin-top-1',
103 - ]
104 - );
105 -
106 - $this->editor = acym_getCMSConfig('editor', 'tinymce');
107 -
108 - if (!class_exists('Joomla\CMS\Editor\Editor')) {
109 - $this->myEditor = Factory::getEditor($this->editor);
110 - } else {
111 - $this->myEditor = Editor::getInstance($this->editor);
112 - }
113 - $this->myEditor->initialise();
114 -
115 - $this->editorConfig['extended_elements'] = 'table[background|cellspacing|cellpadding|width|align|bgcolor|border|style|class|id],tr[background|width|bgcolor|style|class|id|valign],td[background|width|align|bgcolor|valign|colspan|rowspan|height|style|class|id|nowrap]';
116 -
117 - if (!empty($this->mailId)) {
118 - $cssurl = acym_completeLink((acym_isAdmin() ? '' : 'front').'mails&task=loadCSS&id='.$this->mailId.'&time='.time());
119 - $classMail = new MailClass();
120 - $filepath = $classMail->createTemplateFile($this->mailId);
121 -
122 - if ($this->editor === 'tinymce') {
123 - $this->editorConfig['content_css_custom'] = $cssurl.'&local=http';
124 - $this->editorConfig['content_css'] = '0';
125 -
126 - if (!ACYM_J40) {
127 - $access = [];
128 - for ($i = 1; $i < 20; $i++) {
129 - $access[] = $i;
130 - }
131 -
132 - $this->editorConfig['configuration'] = (object)[
133 - 'toolbars' => (object)['AcyCustomCSS' => []],
134 - 'setoptions' => [
135 - 'AcyCustomCSS' => (object)[
136 - 'access' => $access,
137 - 'content_css' => '0',
138 - 'content_css_custom' => $cssurl.'&local=http',
139 - ],
140 - ],
141 - ];
142 - }
143 - } elseif ($this->editor === 'jckeditor' || $this->editor === 'fckeditor') {
144 - $this->editorConfig['content_css_custom'] = $filepath;
145 - $this->editorConfig['content_css'] = '0';
146 - $this->editorConfig['editor_css'] = '0';
147 - } else {
148 - $fileurl = str_replace(DS, '/', ACYM_MEDIA_FOLDER).'templates/css/template_'.$this->mailId.'.css?time='.time();
149 - $this->editorConfig['custom_css_url'] = $cssurl;
150 - $this->editorConfig['custom_css_file'] = $fileurl;
151 - $this->editorConfig['custom_css_path'] = $filepath;
152 - acym_setVar('acycssfile', $fileurl);
153 - }
154 - }
155 -
156 - if (empty($this->editorContent)) {
157 - $this->content = acym_escape($this->content);
158 - ob_start();
159 -
160 - echo $this->myEditor->display(
161 - $this->name,
162 - $this->content,
163 - $this->width,
164 - $this->height,
165 - $this->cols,
166 - $this->rows,
167 - ['pagebreak', 'readmore'],
168 - null,
169 - 'com_content',
170 - null,
171 - $this->editorConfig
172 - );
173 -
174 - $this->editorContent = ob_get_clean();
175 - }
176 -
177 - if (method_exists($this->myEditor, 'save')) {
178 - acym_addScript(true, 'function acyOnSaveEditor(){'.$this->myEditor->save($this->name).'}');
179 - }
180 -
181 - echo $this->editorContent;
182 - }
183 -
184 - private function displayWordPress(): void
185 - {
186 - add_filter('mce_external_plugins', [$this, 'addPlugins']);
187 - add_filter('mce_buttons', [$this, 'addButtons']);
188 - add_filter('mce_buttons_2', [$this, 'addButtonsToolbar']);
189 - add_action('media_buttons', [$this, 'addDtextButton']);
190 -
191 - $mailClass = new MailClass();
192 -
193 - $mail = $mailClass->getOneById($this->mailId);
194 - $stylesheet = empty($mail) ? '' : trim(preg_replace('/\s\s+/', ' ', $mailClass->buildCSS($mail->stylesheet)));
195 - $stylesheet = str_replace(['"', "\r\n", "\n"], ['\"', '', ''], $stylesheet);
196 -
197 - $options = [
198 - 'editor_css' => '<style type="text/css">
199 - .alignleft{float:left;margin:0.5em 1em 0.5em 0;}
200 - .aligncenter{display: block;margin-left: auto;margin-right: auto;}
201 - .alignright{float: right;margin: 0.5em 0 0.5em 1em;}
202 - </style>',
203 - 'editor_height' => $this->height,
204 - 'textarea_rows' => $this->rows,
205 - 'wpautop' => false,
206 - 'tinymce' => [
207 - 'content_css' => '',
208 - 'content_style' => '.alignleft{float:left;margin:0.5em 1em 0.5em 0;} .aligncenter{display: block;margin-left: auto;margin-right: auto;} .alignright{float: right;margin: 0.5em 0 0.5em 1em;}'.$stylesheet,
209 - ],
210 - ];
211 -
212 - wp_editor($this->content, $this->name, $options);
213 - }
214 -
215 - public function addDtextButton(string $editor_id = 'content'): void
216 - {
217 - static $instance = 0;
218 - ++$instance;
219 -
220 - $img = '<i class="acymicon-chevrons"></i> ';
221 -
222 - printf(
223 - '<button type="button" class="button" id="acym__dtext__button" data-editor="%s">%s</button>',
224 - esc_attr($editor_id),
225 - $img.acym_translation('ACYM_INSERT_DYNAMIC_TEXT')
226 - );
227 - }
228 -
229 - private function getWYSIDSettings(): string
230 - {
231 - $ctrl = acym_getVar('string', 'ctrl');
232 - if ($this->isResetCampaign() || !in_array($ctrl, ['dashboard', 'mails', 'campaigns', 'frontmails', 'frontcampaigns'])) {
233 - return '{}';
234 - }
235 -
236 - $mailId = acym_getVar('int', 'from', 0);
237 - if (empty($mailId)) {
238 - if ($this->settings !== 'editor_settings') {
239 - return $this->settings;
240 - }
241 -
242 - $mailId = acym_getVar('int', 'id');
243 - $campaignId = acym_getVar('int', 'campaignId');
244 - if (!empty($campaignId) && $ctrl === 'campaigns') {
245 - $mailId = acym_loadResult('SELECT mail_id FROM #__acym_campaign WHERE id = '.intval($campaignId));
246 - }
247 -
248 - if (empty($mailId)) {
249 - return '{}';
250 - }
251 - }
252 -
253 - $settings = acym_loadResult('SELECT settings FROM #__acym_mail WHERE id = '.intval($mailId));
254 -
255 - return empty($settings) ? '{}' : $settings;
256 - }
257 -
258 - private function getWYSIDStylesheet(): string
259 - {
260 - $ctrl = acym_getVar('string', 'ctrl');
261 - if ($this->isResetCampaign() || !in_array($ctrl, ['mails', 'campaigns', 'frontmails', 'frontcampaigns'])) {
262 - return '';
263 - }
264 -
265 - $mailId = acym_getVar('int', 'from', 0);
266 - if (empty($mailId)) {
267 - if ($this->stylesheet !== 'editor_stylesheet') {
268 - return $this->stylesheet;
269 - }
270 -
271 - $mailId = acym_getVar('int', 'id');
272 - $campaignId = acym_getVar('int', 'campaignId');
273 - if (!empty($campaignId) && in_array($ctrl, ['campaigns', 'frontcampaigns'])) {
274 - $mailId = acym_loadResult('SELECT mail_id FROM #__acym_campaign WHERE id = '.intval($campaignId));
275 - }
276 - }
277 -
278 - $notification = acym_getVar('string', 'notification');
279 - if (!empty($mailId)) {
280 - $stylesheet = acym_loadResult('SELECT stylesheet FROM #__acym_mail WHERE id = '.intval($mailId));
281 - } elseif (!empty($notification)) {
282 - $stylesheet = acym_loadResult(
283 - 'SELECT stylesheet
284 - FROM #__acym_mail
285 - WHERE `type` = '.acym_escapeDB(MailClass::TYPE_NOTIFICATION).'
286 - AND `name` = '.acym_escapeDB($notification)
287 - );
288 - }
289 -
290 - return empty($stylesheet) ? '' : $stylesheet;
291 - }
292 -
293 - private function isResetCampaign(): bool
294 - {
295 - $fromId = acym_getVar('int', 'from', 0);
296 -
297 - return -1 === $fromId;
298 - }
299 -
300 - private function addButtonAtPosition(array &$buttons, string $newButton, string $after): void
301 - {
302 - $position = array_search($after, $buttons);
303 -
304 - if ($position === false) {
305 - array_push($buttons, 'separator', $newButton);
306 - } else {
307 - array_splice($buttons, $position + 1, 0, $newButton);
308 - }
309 - }
310 -
311 - public function addPlugins(array $plugins): array
312 - {
313 - $plugins['table'] = ACYM_JS.'tinymce/table.min.js';
314 -
315 - return $plugins;
316 - }
317 -
318 - public function addButtons(array $buttons): array
319 - {
320 - $position = array_search('wp_more', $buttons);
321 - if ($position !== false) {
322 - $buttons[$position] = '';
323 - }
324 -
325 - array_unshift($buttons, 'separator', 'fontsizeselect');
326 - array_unshift($buttons, 'separator', 'fontselect');
327 - array_push($buttons, 'separator', 'table');
328 -
329 - $this->addButtonAtPosition($buttons, 'alignjustify', 'alignright');
330 - $this->addButtonAtPosition($buttons, 'underline', 'italic');
331 - $this->addButtonAtPosition($buttons, 'strikethrough', 'underline');
332 -
333 - return $buttons;
334 - }
335 -
336 - public function addButtonsToolbar(array $buttons): array
337 - {
338 - $position = array_search('strikethrough', $buttons);
339 - if ($position !== false) {
340 - $buttons[$position] = '';
341 - }
342 - $this->addButtonAtPosition($buttons, 'backcolor', 'forecolor');
343 -
344 - return $buttons;
345 - }
346 -
347 - public function getSettingsStyle($settings): string
348 - {
349 - if (empty($settings)) {
350 - return '';
351 - }
352 -
353 - if (is_string($settings) && substr($settings, 0, 2) === '{"') {
354 - $settings = json_decode($settings, true);
355 - }
356 -
357 - if (!is_array($settings)) {
358 - return '';
359 - }
360 -
361 - $styles = '';
362 - foreach ($settings as $element => $rules) {
363 - $values = '';
364 - foreach ($rules as $ruleName => $value) {
365 - if ($ruleName == 'overridden') continue;
366 - $values .= $ruleName.': '.$value.';';
367 - }
368 - $styles .= '#acym__wysid__template .acym__wysid__column__element__td .acym__wysid__tinymce--text '.$element.':not(.acym__wysid__content-no-settings-style){';
369 - $styles .= $values;
370 - $styles .= '}';
371 -
372 - $styles .= '#acym__wysid__template .acym__wysid__column__element__td .acymailing_content '.$element.':not(.acym__wysid__content-no-settings-style){';
373 - $styles .= $values;
374 - $styles .= '}';
375 - }
376 -
377 - return $styles;
378 - }
379 -
380 - private function getDefaultColors(): string
381 - {
382 - $mailSettings = new \stdClass();
383 - if (isset($this->data['mail']->mail_settings) && !empty($this->data['mail']->mail_settings)) {
384 - $mailSettings = json_decode($this->data['mail']->mail_settings, false);
385 - } elseif (isset($this->data['mailInformation']->mail_settings) && !empty($this->data['mailInformation']->mail_settings)) {
386 - $mailSettings = json_decode($this->data['mailInformation']->mail_settings, false);
387 - }
388 -
389 - if (!empty($mailSettings->mainColors)) {
390 - return $mailSettings->mainColors;
391 - }
392 -
393 - return '';
394 - }
395 -}