PluginProbe
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress / 10.0.1
AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress v10.0.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
acymailing / back / Controllers / Forms / Edition.php

Edition.php in AcyMailing – An Ultimate Newsletter Plugin and Marketing Automation Solution for WordPress 10.0.1, at back/Controllers/Forms/Edition.php

160 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace AcyMailing\Controllers\Forms;
4
5 use AcyMailing\Classes\FormClass;
6
7 trait Edition
8 {
9 public function newForm()
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()
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 (!acym_level(ACYM_ENTERPRISE) && in_array(
50 $type,
51 [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($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 'menu_render_settings' => $formClass->prepareMenuHtml($form, 'options'),
88 'menu_render_style' => $formClass->prepareMenuHtml($form, 'styles'),
89 ];
90
91 parent::display($data);
92 }
93
94 public function updateFormPreview()
95 {
96 $formArray = acym_getVar('array', 'form');
97 if (empty($formArray)) {
98 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_GET_FORM_INFORMATION'), [], false);
99 }
100
101 $formClass = new FormClass();
102 $form = $formClass->getFormWithMissingParams($formArray);
103 if (empty($form)) {
104 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_GET_FORM_INFORMATION'), [], false);
105 }
106
107 $data = [
108 'html' => $formClass->renderForm($form, true),
109 ];
110
111 if (empty($data['html'])) {
112 acym_sendAjaxResponse(acym_translation('ACYM_SOMETHING_WENT_WRONG_GENERATION_FORM'), [], false);
113 }
114
115 acym_sendAjaxResponse('', $data);
116 }
117
118 public function saveAjax()
119 {
120 acym_checkToken();
121 $formArray = acym_getVar('array', 'form');
122 if (empty($formArray)) {
123 acym_sendAjaxResponse(acym_translation('ACYM_COULD_NOT_GET_FORM_INFORMATION'), [], false);
124 }
125
126 $formClass = new FormClass();
127 $form = $formClass->getFormWithMissingParams($formArray);
128 foreach ($form as $column => $value) {
129 if (is_array($value)) {
130 $form->$column = json_encode($value);
131 } else {
132 $form->$column = $value;
133 }
134 }
135
136 $id = $formClass->save($form);
137 if (empty($id)) {
138 acym_sendAjaxResponse(acym_translation('ACYM_SOMETHING_WENT_WRONG_FORM_SAVING'), [], false);
139 } else {
140 acym_sendAjaxResponse(acym_translation('ACYM_FORM_WELL_SAVED'), ['id' => $id]);
141 }
142 }
143
144 public function getArticles()
145 {
146 $searchedTerm = acym_getVar('string', 'searchedterm', '');
147
148 echo json_encode(acym_getArticles($searchedTerm));
149 exit;
150 }
151
152 public function getArticlesById()
153 {
154 $id = acym_getVar('int', 'article_id', 0);
155
156 echo json_encode(acym_getArticleById($id));
157 exit;
158 }
159 }
160