PluginProbe
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar / 3.2.8
NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar v3.2.8
3.3.1 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 All 156 releases
notificationx / includes / Extensions / Extension.php

Extension.php in NotificationX – FOMO, Live Sales Notification, WooCommerce Sales Popup, GDPR, Social Proof, Announcement Banner & Floating Notification Bar 3.2.8, at includes/Extensions/Extension.php

814 lines 27.8 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\Extensions;
10
11 use NotificationX\Admin\Cron;
12 use NotificationX\NotificationX;
13 use NotificationX\Admin\Entries;
14 use NotificationX\Admin\Settings;
15 use NotificationX\Core\Database;
16 use NotificationX\Core\Helper;
17 use NotificationX\Core\Modules;
18 use NotificationX\Core\PostType;
19 use NotificationX\Core\Rules;
20 use NotificationX\Core\Themes;
21 use NotificationX\Types\TypeFactory;
22 use NotificationX\Types\Types;
23 use NotificationX\Core\Limiter;
24
25 /**
26 * Extension Abstract for all Extension.
27 */
28 abstract class Extension {
29
30 public $id;
31 public $title;
32 public $img = '';
33 public $doc_link = 'https://notificationx.com/docs/';
34 public $types = '';
35 public $themes = [];
36 public $res_themes = [];
37 public $selected_themes = [];
38 public $is_pro = false;
39 public $popup = null;
40 public $module = '';
41 public $module_title = '';
42 public $version = '';
43 public $class = '';
44 public $function = '';
45 public $constant = '';
46 public $templates = [];
47 public $mobile_templates = [];
48 public $cron_schedule = '';
49 public $exclude_custom_themes = false;
50 public $priority = 5;
51 public $module_priority = 5;
52 public $show_on_module = true;
53 public $show_on_type = true;
54 /**
55 * All Active Notification Items
56 *
57 * @var array
58 */
59 public $enabled_types = [];
60 public $default_theme = '';
61 public $link_type = '';
62
63 // @todo Something
64 // public abstract function save_post($post_id, $post, $update);
65 // public abstract function get_notification_ready($type, $data = array());
66
67 /**
68 * Initially Invoked when initialized.
69 *
70 * @hook init; Called in init hook.
71 */
72 public function __construct() {
73 $modules = Modules::get_instance();
74 $module_name = $this->register_module();
75 if ($modules->is_enabled($module_name)) {
76 $type_factory = TypeFactory::get_instance();
77 if( $this->show_on_type ) {
78 $type_factory->register_types($this->types);
79 }
80 $this->initialize();
81 }
82 add_action('init', [$this, '__init_extension']);
83 }
84
85 public function initialize(){
86 do_action('nx::extension::init', $this);
87 add_action('nx_before_metabox_load', [$this, '__init_fields']);
88 add_action('nx_before_settings_fields', [$this, 'init_settings_fields']);
89
90 if($this->is_active(false)) {
91 $this->init();
92 $this->admin_actions();
93 $this->public_actions();
94 if(did_action('wpml_st_loaded')){
95 $this->wpml_actions();
96 }
97 add_action('nx_before_metabox_load', [$this, 'init_fields']);
98 }
99 }
100
101 /**
102 * common init function for admin and frontend.
103 */
104 public function init(){
105 // shouldn't do is_active check.
106 if(method_exists($this, 'save_post')){
107 add_filter("nx_save_post_{$this->id}", array($this, 'save_post'), 10, 3);
108 }
109 if(method_exists($this, 'saved_post')){
110 add_filter("nx_saved_post_{$this->id}", array($this, 'saved_post'), 10, 3);
111 }
112 if(method_exists($this, 'preview_entry')){
113 add_filter("nx_preview_entry_{$this->id}", array($this, 'preview_entry'), 10, 2);
114 }
115 if(method_exists($this, 'preview_settings')){
116 add_filter("nx_preview_settings_{$this->id}", array($this, 'preview_settings'), 10, 2);
117 }
118 add_filter("nx_saved_post_{$this->id}", array($this, 'add_cron_job'), 15, 3);
119 }
120
121 public function __init_extension() {
122 $this->init_extension();
123 if( $this->show_on_module ) {
124 Modules::get_instance()->update($this->module,'label',$this->module_title);
125 }
126 }
127
128 public function init_extension() {}
129
130 /**
131 * common init function for admin and frontend.
132 */
133 public function init_settings_fields(){
134
135 }
136
137 /**
138 * common init function .
139 */
140 public function __init_fields(){
141 add_filter('nx_themes', [$this, '__nx_themes']);
142 add_filter('nx_res_themes', [$this, '__nx_res_themes']);
143 add_filter('nx_sources', [$this, '__nx_sources'], 10, 1);
144 add_filter('nx_link_types_dependency', [$this, '__link_types_dependency']);
145 add_filter('nx_notification_template', [$this, '__notification_template']);
146 add_filter('nx_notification_template_mobile', [$this, '__notification_mobile_template']);
147 add_filter('nx_notification_template_dependency', [$this, '__notification_template_dependency']);
148 add_filter('nx_notification_template_mobile_dependency', [$this, '__notification_template_mobile_dependency']);
149 add_filter('nx_source_trigger', [$this, '__source_trigger']);
150 add_filter('nx_themes_trigger', [$this, '__themes_trigger']);
151 add_filter('nx_themes_trigger_for_responsive', [$this, '__res_themes_trigger']);
152 add_filter('nx_is_pro_sources', [$this, '__is_pro_sources']);
153
154 if(method_exists($this, 'doc')){
155 add_filter('nx_instructions', [$this, 'nx_instructions']);
156 }
157 if(method_exists($this, 'source_error_message')){
158 add_filter('source_error_message', [$this, 'source_error_message']);
159 }
160 }
161
162 /**
163 * common init function for admin and frontend.
164 */
165 public function init_fields(){
166 }
167
168 /**
169 * Runs when modules is enabled.
170 *
171 * @return void
172 */
173 public function public_actions() {
174 if (method_exists($this, 'fallback_data')) {
175 add_filter("nx_fallback_data_{$this->id}", array($this, 'fallback_data'), 11, 3);
176 }
177 if (method_exists($this, 'notification_image')) {
178 add_filter("nx_notification_image_{$this->id}", array($this, 'notification_image'), 10, 3);
179 }
180
181 }
182
183 /**
184 * Runs when modules is enabled.
185 *
186 * @return void
187 */
188 public function admin_actions() {
189 // add_action('nx_get_conversions_ready', array($this, 'get_notification_ready'), 10, 2);
190 }
191
192 public function wpml_actions(){
193
194 }
195
196 public function get_link_type(){
197 $link_type = $this->link_type;
198 if(empty($link_type)){
199 $type = $this->get_type();
200 if(!empty($type->link_type)){
201 $link_type = $type->link_type;
202 }
203 }
204 if($link_type === '-1'){
205 $link_type = '';
206 }
207 return $link_type;
208 }
209
210 /**
211 * Get themes for the extension.
212 *
213 *
214 * @param array $args Settings arguments.
215 * @return mixed
216 */
217 public function __source_trigger($triggers){
218 if(empty($this->default_theme)){
219 $type = TypeFactory::get_instance()->get($this->types);
220 $this->default_theme = $type->default_theme;
221 }
222 if(!empty($this->default_theme)){
223 $triggers[$this->id]['themes'] = "@themes:{$this->default_theme}";
224 }
225 $triggers[$this->id]['position'] = "@position:bottom_left";
226
227 $link_type = $this->get_link_type();
228
229 if (!empty($link_type)){
230 $triggers[$this->id]['link_type'] = "@link_type:{$link_type}";
231 }
232 return $triggers;
233 }
234
235 /**
236 * Runs when modules is enabled.
237 *
238 * @return void
239 */
240 public function __nx_themes($themes) {
241 $_themes = $this->get_themes();
242
243 $i = 0;
244 if(is_array($_themes)){
245 foreach ($_themes as $tname => $theme) {
246 if (empty($themes[$tname])) {
247 $themes[$tname] = [
248 'label' => $tname,
249 'value' => $tname,
250 'is_pro' => isset($theme['is_pro']) ? $theme['is_pro'] && ! NotificationX::is_pro() : null,
251 'icon' => isset($theme['source']) ? $theme['source'] : $theme,
252 // @todo converts
253 // 'trigger' => isset($theme['template']) ? ['notification-template' => $theme['template']] : null,
254 ];
255 if(!empty($theme['column'])){
256 $themes[$tname]['column'] = $theme['column'];
257 }
258 if(!empty($theme['rules'])){
259 $themes[$tname]['rules'] = $theme['rules'];
260 }
261 }
262
263 $themes[$tname] = Rules::includes('source', $this->id, false, $themes[$tname]);
264 // $themes[$tname] = Rules::includes('type', $this->types, false, $themes[$tname]);
265 // $themes[$tname] = Rules::includes('i', [++$i], false, $themes[$tname]);
266 // $themes[$tname] = Rules::includes('i', [++$i], false, $themes[$tname]);
267 // $themes[$tname] = Rules::includes('i', [++$i], false, $themes[$tname]);
268 }
269 }
270 return $themes;
271 }
272
273 /**
274 * Runs when modules is enabled.
275 *
276 * @return void
277 */
278 public function __nx_res_themes($themes) {
279 $_themes = $this->get_res_themes();
280 $i = 0;
281 if(is_array($_themes)){
282 foreach ($_themes as $tname => $theme) {
283 if (empty($themes[$tname])) {
284 $themes[$tname] = [
285 'label' => $tname,
286 'value' => $tname,
287 'is_pro' => isset($theme['is_pro']) ? $theme['is_pro'] && ! NotificationX::is_pro() : null,
288 'icon' => isset($theme['source']) ? $theme['source'] : $theme,
289 // @todo converts
290 // 'trigger' => isset($theme['template']) ? ['notification-template' => $theme['template']] : null,
291 ];
292 if(!empty($theme['column'])){
293 $themes[$tname]['column'] = $theme['column'];
294 }
295 }
296 $template = isset($theme['_template']) ? $theme['_template'] : '';
297 if( $template ) {
298 $templates = $this->get_templates();
299 $main_themes = isset( $templates[$template] ) ? (isset( $templates[$template]['_themes'] ) ? $templates[$template]['_themes'] : '') : '' ;
300 $themes[$tname] = Rules::includes('themes', $main_themes, false, $themes[$tname]);
301 }
302 $themes[$tname] = Rules::includes('source', $this->id, false, $themes[$tname]);
303 }
304 }
305 return $themes;
306 }
307
308
309 /**
310 * Get themes for the extension.
311 *
312 *
313 * @param array $args Settings arguments.
314 * @return mixed
315 */
316 public function __themes_trigger($triggers) {
317 $_themes = $this->get_themes();
318 if (is_array($_themes)) {
319 foreach ($_themes as $tname => $theme) {
320 if(!empty($theme['template']) && $templates = $theme['template']){
321 foreach ($templates as $key => $value) {
322 $t = "@notification-template.{$key}:{$value}";
323 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname])){
324 $triggers[$tname][] = $t;
325 }
326 }
327 }
328 if(empty($theme['defaults']['link_button'])){
329 $t = "@link_button:false";
330 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname])){
331 $triggers[$tname][] = $t;
332 }
333 }
334 if(!empty($theme['defaults']) && $defaults = $theme['defaults']){
335 foreach ($defaults as $key => $value) {
336 if(is_array($value) && empty($triggers[$tname][$key])){
337 $triggers[$tname][$key] = $value;
338 }
339 else{
340 $t = "@{$key}:{$value}";
341 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname])){
342 $triggers[$tname][] = $t;
343 }
344 }
345 }
346 }
347 if(!empty($theme['image_shape'])){
348 $t = "@image_shape:{$theme['image_shape']}";
349 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname])){
350 $triggers[$tname][] = $t;
351 }
352 // default image shape for theme.
353 $t = "@image_shape_default:{$theme['image_shape']}";
354 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname])){
355 $triggers[$tname][] = $t;
356 }
357 }
358 if(!empty($theme['inline_location'])){
359 $t = $theme['inline_location'];
360 if(empty($triggers[$tname]['inline_location'])){
361 $triggers[$tname]['inline_location'] = $theme['inline_location'];
362 }
363 }
364 if(!empty($theme['show_notification_image'])){
365 $t = "@show_notification_image:{$theme['show_notification_image']}";
366 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname]))
367 $triggers[$tname][] = $t;
368 }
369 }
370 }
371 return $triggers;
372 }
373
374 /**
375 * Get responsive themes for the extension.
376 *
377 *
378 * @param array $args Settings arguments.
379 * @return mixed
380 */
381 public function __res_themes_trigger($triggers) {
382 $_themes = $this->get_res_themes();
383 if (is_array($_themes)) {
384 foreach ($_themes as $tname => $theme) {
385 if(!empty($theme['template']) && $templates = $theme['template']){
386 foreach ($templates as $key => $value) {
387 $t = "@notification-template-mobile.{$key}:{$value}";
388 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname])){
389 $triggers[$tname][] = $t;
390 }
391 }
392 }
393 if(empty($theme['defaults']['link_button'])){
394 $t = "@link_button:false";
395 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname])){
396 $triggers[$tname][] = $t;
397 }
398 }
399 if(!empty($theme['defaults']) && $defaults = $theme['defaults']){
400 foreach ($defaults as $key => $value) {
401 if(is_array($value) && empty($triggers[$tname][$key])){
402 $triggers[$tname][$key] = $value;
403 }
404 else{
405 $t = "@{$key}:{$value}";
406 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname])){
407 $triggers[$tname][] = $t;
408 }
409 }
410 }
411 }
412 if(!empty($theme['image_shape'])){
413 $t = "@image_shape:{$theme['image_shape']}";
414 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname])){
415 $triggers[$tname][] = $t;
416 }
417 // default image shape for theme.
418 $t = "@image_shape_default:{$theme['image_shape']}";
419 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname])){
420 $triggers[$tname][] = $t;
421 }
422 }
423 if(!empty($theme['inline_location'])){
424 $t = $theme['inline_location'];
425 if(empty($triggers[$tname]['inline_location'])){
426 $triggers[$tname]['inline_location'] = $theme['inline_location'];
427 }
428 }
429 if(!empty($theme['show_notification_image'])){
430 $t = "@show_notification_image:{$theme['show_notification_image']}";
431 if(empty($triggers[$tname]) || !in_array($t, $triggers[$tname]))
432 $triggers[$tname][] = $t;
433 }
434 }
435 }
436 return $triggers;
437 }
438
439 /**
440 * Runs when modules is enabled.
441 *
442 * @return void
443 */
444 public function __nx_sources($sources) {
445 $sources[] = [
446 'rules' => ['is', 'type', $this->types],
447 'label' => $this->title,
448 'icon' => $this->img,
449 'value' => $this->id,
450 'is_pro' => $this->is_pro && ! NotificationX::is_pro(),
451 'popup' => apply_filters('nx_pro_alert_popup', $this->popup),
452 'priority' => $this->priority,
453 ];
454 return $sources;
455 }
456
457 /**
458 * Adds dependency if a option was added to link type field from Types.
459 *
460 * @param array $dependency
461 * @return array
462 */
463 public function __link_types_dependency($dependency) {
464 $link_type = $this->get_link_type();
465 if (!empty($link_type)){
466 $dependency[] = $this->id;
467 }
468 return $dependency;
469 }
470
471 /**
472 * Adds options and dependency for `Notification Template` field from `Content` tab.
473 *
474 * @param array $templates `Notification Template` fields.
475 * @return array
476 */
477 public function __notification_template($templates){
478 foreach ($this->get_templates() as $key => $tmpl) {
479 if(!empty($tmpl['_themes'])){
480 $type = 'themes';
481 $themes = $tmpl['_themes'];
482 unset($tmpl['_themes']);
483 }
484 elseif(!empty($tmpl['_source'])) {
485 $type = 'source';
486 $themes = $tmpl['_source'];
487 unset($tmpl['_source']);
488 }
489
490 foreach ($tmpl as $param => $options) {
491 foreach ($options as $name => $label) {
492 if(empty($templates[$param]['options'][$name])){
493 if(is_array($label)){
494 $templates[$param]['options'][$name] = $label;
495 }
496 else{
497 $templates[$param]['options'][$name] = [
498 'value' => $name,
499 'label' => $label,
500 'rules' => [],
501 ];
502 }
503 }
504 $templates[$param]['options'][$name] = Rules::includes($type, $themes, false, $templates[$param]['options'][$name]);
505 }
506 }
507 }
508
509 if(is_array($this->get_themes())){
510 foreach ($this->get_themes() as $name => $theme) {
511 if(!empty($theme['template'])){
512 foreach ($theme['template'] as $param => $value) {
513 if(strpos($param, 'custom_') === 0 || empty($templates[$param])) continue;
514 $templates[$param] = Rules::includes('themes', [$name], false, $templates[$param]);
515 }
516 }
517 }
518 }
519
520 return $templates;
521 }
522
523 /**
524 * Adds options and dependency for `Notification Template` field from `Content` tab.
525 *
526 * @param array $templates `Notification Template` fields.
527 * @return array
528 */
529 public function __notification_template_dependency($dependency){
530 if($this->get_templates()){
531 $dependency[] = $this->id;
532 }
533 return $dependency;
534 }
535
536 public function get_type(){
537 return TypeFactory::get_instance()->get($this->types);
538 }
539
540 /**
541 * Get themes for the extension.
542 *
543 *
544 * @param array $args Settings arguments.
545 * @return mixed
546 */
547 public function get_themes() {
548 if (empty($this->themes)) {
549 $type_obj = $this->get_type();
550 if ($type_obj instanceof Types) {
551 $themes = $type_obj->get_themes();
552 return $this->array_add_prefix($themes, $this->types . "_");
553 }
554 }
555 return $this->array_add_prefix($this->themes, $this->id . "_");
556 }
557
558 /**
559 * Get responsive themes for the extension.
560 *
561 *
562 * @param array $args Settings arguments.
563 * @return mixed
564 */
565 public function get_res_themes() {
566 if (empty($this->res_themes)) {
567 $type_obj = $this->get_type();
568 if ($type_obj instanceof Types) {
569 $themes = $type_obj->get_res_themes();
570 return $this->array_add_prefix($themes, $this->types . "_");
571 }
572 }
573 return $this->array_add_prefix($this->res_themes, $this->id . "_");
574 }
575
576 /**
577 * Get themes for the extension.
578 *
579 *
580 * @param array $args Settings arguments.
581 * @return mixed
582 */
583 public function get_themes_name() {
584 return array_keys($this->get_themes());
585 }
586
587 public function array_add_prefix($array, $prefix){
588 return ! is_array( $array ) ? $array : array_combine(
589 array_map( function( $key ) use( $prefix ) {
590 return $prefix . $key;
591 }, array_keys( $array ) ),
592 $array
593 );
594 }
595
596 /**
597 * Get templates for the extension.
598 *
599 *
600 * @return array
601 */
602 public function get_templates(){
603 if(empty($this->templates)){
604 $type_obj = $this->get_type();
605 if ($type_obj instanceof Types) {
606 return $type_obj->get_templates();
607 }
608 }
609 return $this->templates;
610 }
611
612 /**
613 * Undocumented function
614 *
615 * @param [array] $modules
616 * @return array
617 */
618 public function register_module() {
619 if( $this->show_on_module ) {
620 $modules = Modules::get_instance();
621 return $modules->add(array(
622 'value' => $this->module,
623 'label' => $this->module_title,
624 'link' => $this->doc_link,
625 'is_pro' => $this->is_pro && ! NotificationX::is_pro(),
626 'badge' => $this->is_pro,
627 'priority' => $this->module_priority,
628 ));
629 }
630
631 }
632
633 public function delete_notification($entry_key = null, $nx_id = null) {
634 $where = [
635 // 'source' => $this->id
636 ];
637 if (!empty($entry_key)) {
638 $where['entry_key'] = $entry_key;
639 }
640 if (!empty($nx_id)) {
641 $where['nx_id'] = $nx_id;
642 }
643 if (!empty($where)) {
644 return Entries::get_instance()->delete_entries($where);
645 }
646 return false;
647 }
648
649 // @todo accept multiple entries.
650 public function update_notifications($entries) {
651 if(is_array($entries) && !empty($entries[0]['nx_id'])){
652 $post = PostType::get_instance()->get_post($entries[0]['nx_id']);
653 foreach ($entries as $key => $entry) {
654 $can_entry = apply_filters("nx_can_entry_{$this->id}", true, $entry, $post);
655 if(!$can_entry){
656 unset($entries[$key]);
657 }
658 }
659 Limiter::get_instance()->remove($post['nx_id'], count($entries));
660 Entries::get_instance()->insert_entries(array_values($entries));
661 }
662 }
663
664 // @todo Something
665 public function update_notification($entry, $force = true) { // , $nx_id = 0
666 if (empty($entry['nx_id'])) { // empty($nx_id) &&
667 $this->save($entry, $force);
668 } else {
669 if(!$force){
670 $is_exits = Database::get_instance()->get_posts(
671 Database::$table_entries, 'count(*)', [
672 'nx_id' => $entry['nx_id'],
673 'source' => $this->id,
674 'entry_key' => $entry['entry_key'],
675 ] );
676 if(!empty($is_exits[0]['count(*)'])) return false;
677 }
678 // @todo add object caching
679 $post = PostType::get_instance()->get_post($entry['nx_id']);
680 $can_entry = apply_filters("nx_can_entry_{$this->id}", true, $entry, $post);
681 if($can_entry){
682 Limiter::get_instance()->remove($post['nx_id'], 1);
683 Entries::get_instance()->insert_entry($entry);
684 }
685 }
686 }
687
688 /**
689 * This method is responsible for save the data
690 *
691 * @param string $this->id - notification type
692 * @param array $data - notification data to save.
693 * @return boolean
694 */
695 protected function save($entry, $force = true) {
696 $posts = PostType::get_instance()->get_posts([
697 'source' => $this->id,
698 'enabled' => true,
699 ]);
700 if (!empty($posts)) {
701 foreach ($posts as $post) {
702 $entry['nx_id'] = $post['nx_id'];
703 $this->update_notification($entry, $force);
704 }
705 }
706 }
707
708 /**
709 * this function is responsible for check a type of notification is created or not
710 *
711 * @param string $type
712 * @return boolean
713 */
714 public function is_active($check_enabled = true) {
715
716 if (!empty($this->class) && !class_exists($this->class)) {
717 return false;
718 }
719 if (!empty($this->function) && !function_exists($this->function)) {
720 return false;
721 }
722 if (!empty($this->constant) && !defined($this->constant)) {
723 return false;
724 }
725 if ($check_enabled) {
726 $active_sources = PostType::get_instance()->get_active_items();
727 if (!empty($active_sources)) {
728 return in_array($this->id, $active_sources);
729 }
730 return false;
731 }
732 return true;
733 }
734
735 public function class_exists() {
736 if (!empty($this->class)) {
737 return class_exists($this->class);
738 }
739 if (!empty($this->function)) {
740 return function_exists($this->function);
741 }
742 if (!empty($this->constant)) {
743 return defined($this->constant);
744 }
745 return true;
746 }
747
748 /**
749 * This method is responsible for save the data
750 *
751 * @param string $this->id - notification type
752 * @param array $data - notification data to save.
753 * @return boolean
754 */
755 protected function notEmpty($key, $array, $default = null) {
756 if(!empty($array[$key])){
757 return $array[$key];
758 }
759 return $default;
760 }
761
762 /**
763 * Generating Full Name with one letter from last name
764 * @since 1.3.9
765 * @param string $first_name
766 * @param string $last_name
767 * @return string
768 */
769 protected function name($first_name = '', $last_name = '') {
770 $name = Helper::name($first_name, $last_name);
771 return $name;
772 }
773
774 public function remote_get($url, $args = array(), $raw = false) {
775 return Helper::remote_get($url, $args, $raw);
776 }
777
778 /**
779 * This method is responsible for save the data
780 *
781 * @param string $type - notification type
782 * @param array $data - notification data to save.
783 * @return boolean
784 */
785 protected function sort_data($arr) {
786 // @todo add sorting.
787 return $arr;
788 }
789
790 public function restResponse( $params ){
791 error_log('FROM Extenson');
792 error_log( $params );
793 }
794
795 public function nx_instructions($instructions){
796 if(method_exists($this, 'doc')){
797 $instructions[$this->types][$this->id] = $this->doc();
798 }
799 return $instructions;
800 }
801
802 public function __is_pro_sources($sources){
803 $sources[$this->id] = $this->is_pro;
804 return $sources;
805 }
806
807 public function add_cron_job($post, $data, $nx_id){
808 if(!empty($this->cron_schedule)){
809 Cron::get_instance()->set_cron($nx_id, $this->cron_schedule);
810 }
811 }
812
813 }
814