PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 11.1.0
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v11.1.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
← All changes | back/Controllers/Forms/Edition.php +154 -0 10.10.1 → 11.1.0 View file →
@@ -1,0 +1,154 @@
1 +<?php
2 +
3 +namespace AcyMailing\Controllers\Forms;
4 +
5 +use AcyMailing\Classes\FormClass;
6 +
7 +trait Edition
8 +{
9 + public function newForm(): void
10 + {
11 + acym_setVar('layout', 'new_form');
12 +
13 + if (ACYM_CMS === 'joomla') {
14 + $moduleId = acym_loadResult('SELECT extension_id FROM #__extensions WHERE element = "mod_acym"');
15 +
16 + if (empty($moduleId)) {
17 + $widgetUrl = 'index.php?option=com_modules&view=select';
18 + } else {
19 + $widgetUrl = 'index.php?option=com_modules&task=module.add&eid='.intval($moduleId);
20 + }
21 + } else {
22 + if (current_theme_supports('widgets')) {
23 + $widgetUrl = 'widgets.php';
24 + } else {
25 + $widgetUrl = 'site-editor.php';
26 + }
27 + }
28 +
29 + $data = [
30 + 'widget_link' => acym_route($widgetUrl),
31 + 'popup_link' => acym_completeLink('forms&task=edit&type=popup'),
32 + 'header_link' => acym_completeLink('forms&task=edit&type=header'),
33 + 'footer_link' => acym_completeLink('forms&task=edit&type=footer'),
34 + ];
35 +
36 + if (ACYM_CMS === 'wordpress') {
37 + $data['shortcode_link'] = acym_completeLink('forms&task=edit&type=shortcode');
38 + }
39 +
40 + parent::display($data);
41 + }
42 +
43 + public function edit(): void
44 + {
45 + acym_setVar('layout', 'edit');
46 + $formClass = new FormClass();
47 + $id = acym_getVar('int', 'id', 0);
48 + $type = acym_getVar('string', 'type', ACYM_CMS === 'wordpress' ? FormClass::SUB_FORM_TYPE_SHORTCODE : FormClass::SUB_FORM_TYPE_POPUP);
49 + if (
50 + !acym_level(ACYM_ENTERPRISE)
51 + && in_array($type, [FormClass::SUB_FORM_TYPE_POPUP, FormClass::SUB_FORM_TYPE_HEADER, FormClass::SUB_FORM_TYPE_FOOTER])
52 + ) {
53 + acym_enqueueMessage(acym_translation('ACYM_NOT_ALLOWED_CREATE_TYPE_FORM'), 'info');
54 + $this->listing();
55 +
56 + return;
57 + }
58 +
59 + if (empty($id)) {
60 + $form = $formClass->initEmptyForm($type);
61 + $this->breadcrumb[acym_translation('ACYM_NEW_FORM')] = acym_completeLink('forms&task=edit&id=0&type='.$type);
62 + } else {
63 + $form = $formClass->getOneById($id);
64 + $form = $formClass->getFormWithMissingParams(get_object_vars($form));
65 + $this->breadcrumb[$form->name] = acym_completeLink('forms&task=edit&id='.$id);
66 + }
67 +
68 + if (empty($form)) {
69 + $this->listing();
70 +
71 + return;
72 + }
73 +
74 + $allPagesCMS = ['all' => acym_translation('ACYM_ALL_PAGES')];
75 + $allPagesCMS = array_replace($allPagesCMS, acym_getAllPages());
76 +
77 +
78 + $languagesName = ['all' => acym_translation('ACYM_ALL_LANGUAGE_NAME')];
79 + foreach (acym_getLanguages() as $languageCode => $languageArray) {
80 + $languagesName[$languageCode] = $languageArray->name;
81 + }
82 +
83 + $data = [
84 + 'all_languages' => $languagesName,
85 + 'form' => $form,
86 + 'all_pages' => $allPagesCMS,
87 + ];
88 +
89 + parent::display($data);
90 + }
91 +
92 + public function updateFormPreview(): void
93 + {
94 + $formArray = acym_getVar('array', 'form');
95 + if (empty($formArray)) {
96 + acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_GET_FORM_INFORMATION'), [], false);
97 + }
98 +
99 + $formClass = new FormClass();
100 + $form = $formClass->getFormWithMissingParams($formArray);
101 +
102 + $data = [
103 + 'html' => $formClass->renderForm($form, true),
104 + ];
105 +
106 + if (empty($data['html'])) {
107 + acym_sendAjaxResponse(acym_translation('ACYM_SOMETHING_WENT_WRONG_GENERATION_FORM'), [], false);
108 + }
109 +
110 + acym_sendAjaxResponse('', $data);
111 + }
112 +
113 + public function saveAjax(): void
114 + {
115 + wp_verify_nonce(acym_getVar('cmd', '_wpnonce'), 'acymnonce') || die('Invalid Token');
116 + $formArray = acym_getVar('array', 'form');
117 + if (empty($formArray)) {
118 + acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_GET_FORM_INFORMATION'), [], false);
119 + }
120 +
121 + $formClass = new FormClass();
122 + $form = $formClass->getFormWithMissingParams($formArray);
123 + foreach ($form as $column => $value) {
124 + if (is_array($value)) {
125 + $form->$column = json_encode($value);
126 + } else {
127 + $form->$column = $value;
128 + }
129 + }
130 +
131 + $id = $formClass->save($form);
132 + if (empty($id)) {
133 + acym_sendAjaxResponse(acym_translation('ACYM_SOMETHING_WENT_WRONG_FORM_SAVING'), [], false);
134 + } else {
135 + acym_sendAjaxResponse(acym_translation('ACYM_FORM_WELL_SAVED'), ['id' => $id]);
136 + }
137 + }
138 +
139 + public function getArticles(): void
140 + {
141 + $searchedTerm = acym_getVar('string', 'searchedterm', '');
142 +
143 + echo json_encode(acym_getArticles($searchedTerm));
144 + exit;
145 + }
146 +
147 + public function getArticlesById(): void
148 + {
149 + $id = acym_getVar('int', 'article_id', 0);
150 +
151 + echo json_encode(acym_getArticleById($id));
152 + exit;
153 + }
154 +}