PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / trunk
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar vtrunk
3.3.0 3.2.14 3.2.13 3.2.12 3.2.11 3.2.10 3.2.9 3.2.8 3.2.7 trunk 0.2.5.5 0.2.5.6 0.2.5.7 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.2 All 155 releases
notificationx / includes / Types / ContactForm.php

ContactForm.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar trunk, at includes/Types/ContactForm.php

278 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 /**
4 * Extension Abstract
5 *
6 * @package NotificationX\Extensions
7 */
8
9 namespace NotificationX\Types;
10
11 use NotificationX\Core\Rules;
12 use NotificationX\Extensions\ExtensionFactory;
13 use NotificationX\Extensions\GlobalFields;
14 use NotificationX\GetInstance;
15 use NotificationX\Modules;
16
17 /**
18 * Extension Abstract for all Extension.
19 * @method static ContactForm get_instance($args = null)
20 */
21 class ContactForm extends Types {
22 /**
23 * Instance of Admin
24 *
25 * @var Admin
26 */
27 use GetInstance;
28
29 public $priority = 25;
30 public $id = 'form';
31 public $module = [
32 'modules_cf7',
33 'modules_wpf',
34 'modules_njf',
35 'modules_grvf',
36 ];
37 public $default_source = 'cf7';
38 public $default_theme = 'form_theme-one';
39 public $link_type = 'none';
40
41
42 /**
43 * Initially Invoked when initialized.
44 */
45 public function __construct() {
46 parent::__construct();
47 }
48
49 public function init()
50 {
51 parent::init();
52 $this->title = __('Contact Form', 'notificationx');
53 $this->themes = [
54 'theme-one' => [
55 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/form/cf7-theme-two.jpg',
56 'image_shape' => 'circle',
57 // Default values for Add New > Content > Notification Template fields
58 'template' => [
59 'first_param' => 'select_a_tag',
60 'custom_first_param' => __('Someone', 'notificationx'),
61 'second_param' => __('recently contacted via', 'notificationx'),
62 'third_param' => 'tag_title',
63 'custom_third_param' => '',
64 'fourth_param' => 'tag_time',
65 'custom_fourth_param' => __('Some time ago', 'notificationx'),
66 ],
67 ],
68 'theme-two' => [
69 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/form/cf7-theme-one.jpg',
70 'image_shape' => 'circle',
71 'template' => [
72 'first_param' => 'select_a_tag',
73 'custom_first_param' => __('Someone', 'notificationx'),
74 'second_param' => __('recently contacted via', 'notificationx'),
75 'third_param' => 'tag_title',
76 'custom_third_param' => '',
77 'fourth_param' => 'tag_time',
78 'custom_fourth_param' => __('Some time ago', 'notificationx'),
79 ],
80 ],
81 'theme-three' => [
82 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/form/cf7-theme-three.jpg',
83 'image_shape' => 'square',
84 'template' => [
85 'first_param' => 'select_a_tag',
86 'custom_first_param' => __('Someone', 'notificationx'),
87 'second_param' => __('recently contacted via', 'notificationx'),
88 'third_param' => 'tag_title',
89 'custom_third_param' => '',
90 'fourth_param' => 'tag_time',
91 'custom_fourth_param' => __('Some time ago', 'notificationx'),
92 ],
93 ],
94 ];
95 $this->res_themes = [
96 'res-theme-one' => [
97 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_form/cf-res-theme-1.png',
98 'image_shape' => 'circle',
99 // Default values for Add New > Content > Notification Template fields
100 'template' => [
101 'res_first_param' => 'select_a_tag',
102 'res_second_param' => __('just contacted via', 'notificationx'),
103 'res_third_param' => 'tag_title',
104 ],
105 'is_pro' => true,
106 ],
107 'res-theme-two' => [
108 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_form/cf-res-theme-2.png',
109 'image_shape' => 'circle',
110 // Default values for Add New > Content > Notification Template fields
111 'template' => [
112 'res_first_param' => 'select_a_tag',
113 'res_second_param' => __('just contacted via', 'notificationx'),
114 'res_third_param' => 'tag_title',
115 ],
116 'is_pro' => true,
117 ],
118 'res-theme-three' => [
119 'source' => NOTIFICATIONX_ADMIN_URL . 'images/extensions/themes/res_form/cf-res-theme-3.png',
120 'image_shape' => 'circle',
121 // Default values for Add New > Content > Notification Template fields
122 'template' => [
123 'res_first_param' => 'select_a_tag',
124 'res_second_param' => __('just contacted via', 'notificationx'),
125 'res_third_param' => 'tag_title',
126 ],
127 'is_pro' => true,
128 ],
129 ];
130 $this->templates = [
131 // Dropdown options for Add New > Content > Notification Template fields
132 'form_template_new' => [
133 'first_param' => [
134 'select_a_tag' => [
135 'label' => __('Select A Tag', 'notificationx'),
136 'value' => 'select_a_tag',
137 'disabled' => true,
138 ],
139 ],
140 'third_param' => [
141 'tag_title' => __('Form Title', 'notificationx'),
142 // 'tag_custom_form_title' => __('Custom Title', 'notificationx'),
143 ],
144 'fourth_param' => [
145 'tag_time' => __('Definite Time', 'notificationx'),
146 ],
147 // themes for this template.
148 '_themes' => [
149 'form_theme-one',
150 'form_theme-two',
151 'form_theme-three',
152 ],
153 ],
154 ];
155 }
156
157 /**
158 * Hooked to nx_before_metabox_load action.
159 *
160 * @return void
161 */
162 public function init_fields() {
163 parent::init_fields();
164 add_filter('nx_content_fields', [$this, 'add_form_fields'], 9);
165 add_filter('nx_notification_template', [$this, 'notification_template'], 9);
166 // add_filter('nx_customize_fields', [$this, 'customize_fields'], 20);
167 }
168
169 /**
170 * Loading forms input field via ajax for first dropdown.
171 *
172 * @param array $fields
173 * @return array
174 */
175 public function notification_template( $fields ){
176 $fields['first_param']['ajax'] = [
177 'on' => 'click',
178 'api' => "/notificationx/v1/get-data",
179 'data' => [
180 'type' => "ContactForm",
181 'form_type' => "@source",
182 'form_id' => "@form_list",
183 ],
184 'target' => "notification-template[first_param]",
185 'rules' => [
186 'is', 'type', 'form'
187 ]
188 ];
189
190 return $fields;
191 }
192
193 /**
194 * Responsible for passing the ajax request to extension.
195 *
196 * @param array $args
197 * @return void
198 */
199 public static function restResponse( $args ){
200 if( ! isset( $args['form_type'] ) || $args['form_type'] === 'undefined' ) {
201 return new \WP_Error('something', 'NILL');
202 }
203 if( !empty( $args['form_id'] ) ) {
204 $args['form_id'] = isset($args['form_id']['value']) ? $args['form_id']['value'] : $args['form_id'];
205 $args['form_id'] = str_replace(trim($args['form_type']) . '_', '', $args['form_id']);
206 }
207 if ( !isset($args['form_id']) && empty($args['form_id']) ) {
208 return [];
209 }
210 $args['form_id'] = isset($args['form_id']['value']) ? $args['form_id']['value'] : $args['form_id'];
211 $args['form_id'] = str_replace(trim($args['form_type']) . '_', '', $args['form_id']);
212 $form = ExtensionFactory::get_instance()->get( trim( $args['form_type'] ) );
213 if($form && $form->is_active(false)){
214 return $form->restResponse( $args );
215 }
216 return [];
217 }
218
219 /**
220 * Adding fields in the metabox.
221 *
222 * @param array $args Settings arguments.
223 * @return array
224 */
225 public function add_form_fields($fields) {
226
227 $fields['content']['fields']['form_list'] = [
228 'type' => 'select-async',
229 'name' => 'form_list',
230 'label' => __('Select a Form', 'notificationx'),
231 // phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedHooknameFound -- Reviewed for the NotificationX codebase: acceptable in this context.
232 'options' => apply_filters('nx_form_list', [
233 [
234 'label' => "Type for more result...",
235 'value' => null,
236 'disabled' => true,
237 ],
238 ]),
239 'priority' => 20,
240 'rules' => Rules::includes( 'type', $this->id ),
241 'ajax' => [
242 'api' => "/notificationx/v1/get-data",
243 'data' => [
244 'type' => "@type",
245 'source' => "@source",
246 'field' => "form_list",
247 ],
248 ],
249 ];
250
251 return $fields;
252 }
253
254 /**
255 * Undocumented function
256 *
257 * @param array $options
258 * @return array
259 */
260 public function customize_fields($fields) {
261 $behaviour = &$fields['behaviour']['fields'];
262 $behaviour['link_open'] = Rules::is('type', $this->id, true, $behaviour['link_open']);
263 return $fields;
264 }
265
266 public function preview_entry($entry, $settings){
267 $entry = array_merge($entry, [
268 "title" => "Support Us Form",
269 'image_data' => array(
270 'url' => NOTIFICATIONX_PUBLIC_URL . 'image/icons/pink-face-looped.gif',
271 'alt' => '',
272 'classes' => 'greview_icon',
273 ),
274 ]);
275 return $entry;
276 }
277 }
278