PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.1.11
ShopBuilder – WooCommerce Builder For Elementor v2.1.11
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Models / Base / ListModel.php

ListModel.php in ShopBuilder – WooCommerce Builder For Elementor 2.1.11, at app/Models/Base/ListModel.php

121 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\Models\Base;
4
5 defined( 'ABSPATH' ) || exit;
6
7 use RadiusTheme\SB\Helpers\Fns;
8 use RadiusTheme\SB\Models\DataModel;
9
10 abstract class ListModel {
11
12 protected $list_id;
13
14 protected $title;
15 protected $short_title;
16 protected $description;
17 private $full_list = [];
18 private $active_list = [];
19 private $inactive_list = [];
20 private $db_options = [];
21 protected $categories = [];
22
23 public function __construct() {
24 $this->db_options = DataModel::source()->get_option( $this->list_id, [] );
25 $raw_list = apply_filters( 'rtsb/' . $this->list_id . '/list', $this->raw_list() );
26
27 if ( ! empty( $raw_list ) ) {
28 foreach ( $raw_list as $name => $item ) {
29
30 if ( ! empty( $item['package'] ) && $item['package'] === 'pro-disabled' ) {
31 $item['fields'] = [];
32 $item['active'] = false;
33 $this->full_list[ $name ] = $item;
34 $this->inactive_list[ $name ] = $item;
35 continue;
36 }
37
38 if ( ! isset( $this->db_options[ $name ]['active'] ) && ! empty( $item['active'] ) ) {
39 $item['active'] = 'on';
40 } else {
41 $item['active'] = isset( $this->db_options[ $name ]['active'] ) && $this->db_options[ $name ]['active'] === 'on' ? 'on' : '';
42 }
43
44 if ( ! empty( $item['fields'] ) ) {
45 foreach ( $item['fields'] as $field_key => $field ) {
46 $the_value = $this->db_options[ $name ][ $field_key ] ?? ( $item['fields'][ $field_key ]['value'] ?? '' );
47 if ( 'repeaters' === $field['type'] && empty( $the_value ) && ! empty( $field['defaults'] ) ) {
48 $repeater_defaults = array_values( $field['defaults'] );
49 $the_value = wp_json_encode( $repeater_defaults );
50 }
51 $sanitized_value = Fns::stripslashes_value( $the_value );
52 $item['fields'][ $field_key ]['value'] = $sanitized_value;
53 }
54 }
55 $this->full_list[ $name ] = $item;
56
57 if ( 'on' === $item['active'] ) {
58 $this->active_list[ $name ] = $item;
59 } else {
60 $this->inactive_list[ $name ] = $item;
61 }
62 }
63 }
64 }
65
66 /**
67 * @return string Pro Package
68 */
69 protected function pro_package() {
70 return rtsb()->has_pro() ? 'pro' : 'pro-disabled';
71 }
72 /**
73 * @param $key
74 *
75 * @return bool
76 */
77 public function is_widget_active( $key ) {
78 return isset( $this->active_list[ $key ] );
79 }
80
81 /**
82 * @param mixed $list true | anything
83 * @param string $filter_type full|active|inactive
84 *
85 * @return mixed
86 */
87 public function get_list( $list = true, $filter_type = 'full' ) {
88 if ( $list !== true && isset( $this->full_list[ $list ] ) ) {
89 return $this->full_list[ $list ];
90 }
91
92 return $this->{$filter_type . '_list'};
93 }
94
95 public function get_section() {
96 return [
97 'title' => $this->title,
98 'short_title' => ! empty( $this->short_title ) ? $this->short_title : $this->title,
99 'description' => $this->description,
100 'list' => $this->get_list(),
101 'id' => $this->list_id,
102 'categories' => $this->categories,
103 ];
104 }
105
106 /**
107 * @param $key
108 *
109 * @return array|mixed
110 */
111 public function get_fields( $key ) {
112 return isset( $this->full_list[ $key ]['fields'] ) ? $this->full_list[ $key ]['fields'] : [];
113 }
114
115 public function get_data() {
116 return $this->db_options;
117 }
118
119 abstract protected function raw_list();
120 }
121