PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 3.2.0
ShopBuilder – WooCommerce Builder For Elementor v3.2.0
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
← All changes | app/Models/Base/ListModel.php +120 -11 2.1.63.2.0 View file →
@@ -1,5 +1,10 @@
1 1 <?php
2 +/**
3 + * ListModel
4 + *
5 + * @package RadiusTheme\SB
6 + */
2 7
3 8 namespace RadiusTheme\SB\Models\Base;
4 9
5 10 defined( 'ABSPATH' ) || exit;
@@ -6,28 +11,86 @@
6 11
7 12 use RadiusTheme\SB\Helpers\Fns;
8 13 use RadiusTheme\SB\Models\DataModel;
9 14
15 +/**
16 + * ListModel
17 + */
10 18 abstract class ListModel {
11 -
19 + /**
20 + * List ID
21 + *
22 + * @var string
23 + */
12 24 protected $list_id;
13 25
26 + /**
27 + * List Title
28 + *
29 + * @var string
30 + */
14 31 protected $title;
32 +
33 + /**
34 + * List Short Title
35 + *
36 + * @var string
37 + */
15 38 protected $short_title;
39 +
40 + /**
41 + * List Description
42 + *
43 + * @var string
44 + */
16 45 protected $description;
46 +
47 + /**
48 + * List
49 + *
50 + * @var array
51 + */
17 52 private $full_list = [];
53 +
54 + /**
55 + * Active List
56 + *
57 + * @var array
58 + */
18 59 private $active_list = [];
60 +
61 + /**
62 + * Inactive List
63 + *
64 + * @var array
65 + */
19 66 private $inactive_list = [];
67 +
68 + /**
69 + * Options
70 + *
71 + * @var array
72 + */
20 73 private $db_options = [];
74 +
75 + /**
76 + * Categories
77 + *
78 + * @var array
79 + */
21 80 protected $categories = [];
22 81
82 + /**
83 + * Constructor
84 + */
23 85 public function __construct() {
24 86 $this->db_options = DataModel::source()->get_option( $this->list_id, [] );
25 87 $raw_list = apply_filters( 'rtsb/' . $this->list_id . '/list', $this->raw_list() );
88 +
26 89 if ( ! empty( $raw_list ) ) {
27 90 foreach ( $raw_list as $name => $item ) {
28 91
29 - if ( ! empty( $item['package'] ) && $item['package'] === 'pro-disabled' ) {
92 + if ( ! empty( $item['package'] ) && 'pro-disabled' === $item['package'] ) {
30 93 $item['fields'] = [];
31 94 $item['active'] = false;
32 95 $this->full_list[ $name ] = $item;
33 96 $this->inactive_list[ $name ] = $item;
@@ -36,15 +99,21 @@
36 99
37 100 if ( ! isset( $this->db_options[ $name ]['active'] ) && ! empty( $item['active'] ) ) {
38 101 $item['active'] = 'on';
39 102 } else {
40 - $item['active'] = isset( $this->db_options[ $name ]['active'] ) && $this->db_options[ $name ]['active'] === 'on' ? 'on' : '';
103 + $item['active'] = isset( $this->db_options[ $name ]['active'] ) && 'on' === $this->db_options[ $name ]['active'] ? 'on' : '';
41 104 }
42 105
43 106 if ( ! empty( $item['fields'] ) ) {
44 107 foreach ( $item['fields'] as $field_key => $field ) {
45 108 $the_value = $this->db_options[ $name ][ $field_key ] ?? ( $item['fields'][ $field_key ]['value'] ?? '' );
46 - $sanitized_value = Fns::stripslashes_value( $the_value );
109 + if ( 'repeaters' === $field['type'] && empty( $the_value ) && ! empty( $field['defaults'] ) ) {
110 + $repeater_defaults = array_values( $field['defaults'] );
111 + $the_value = wp_json_encode( $repeater_defaults );
112 + } elseif ( 'repeaters' === $field['type'] && ! empty( $the_value ) ) {
113 + $the_value = json_decode( $the_value );
114 + }
115 + $sanitized_value = Fns::stripslashes_value( $the_value );
47 116 $item['fields'][ $field_key ]['value'] = $sanitized_value;
48 117 }
49 118 }
50 119 $this->full_list[ $name ] = $item;
@@ -63,11 +132,32 @@
63 132 */
64 133 protected function pro_package() {
65 134 return rtsb()->has_pro() ? 'pro' : 'pro-disabled';
66 135 }
136 +
67 137 /**
68 - * @param $key
138 + * @return string Pro Package
139 + */
140 + protected function pro_version_checker() {
141 + $has_pro = rtsb()->has_pro();
142 + $pro_ver = defined( 'RTSBPRO_VERSION' ) ? RTSBPRO_VERSION : 0;
143 +
144 + if ( ! $has_pro ) {
145 + return 'free';
146 + }
147 +
148 + if ( version_compare( $pro_ver, '2.0.0', '>=' ) ) {
149 + return 'pass';
150 + }
151 +
152 + return 'fail';
153 + }
154 +
155 + /**
156 + * Is widget active
69 157 *
158 + * @param string $key Key.
159 + *
70 160 * @return bool
71 161 */
72 162 public function is_widget_active( $key ) {
73 163 return isset( $this->active_list[ $key ] );
@@ -73,15 +163,17 @@
73 163 return isset( $this->active_list[ $key ] );
74 164 }
75 165
76 166 /**
77 - * @param mixed $list true | anything
78 - * @param string $filter_type full|active|inactive
167 + * Get list
79 168 *
169 + * @param bool $list List.
170 + * @param string $filter_type Filter type.
171 + *
80 172 * @return mixed
81 173 */
82 - public function get_list( $list = true, $filter_type = 'full' ) { //
83 - if ( $list !== true && isset( $this->full_list[ $list ] ) ) {
174 + public function get_list( $list = true, $filter_type = 'full' ) {
175 + if ( true !== $list && isset( $this->full_list[ $list ] ) ) {
84 176 return $this->full_list[ $list ];
85 177 }
86 178
87 179 return $this->{$filter_type . '_list'};
@@ -86,8 +178,13 @@
86 178
87 179 return $this->{$filter_type . '_list'};
88 180 }
89 181
182 + /**
183 + * Get section
184 + *
185 + * @return array
186 + */
90 187 public function get_section() {
91 188 return [
92 189 'title' => $this->title,
93 190 'short_title' => ! empty( $this->short_title ) ? $this->short_title : $this->title,
@@ -98,10 +195,12 @@
98 195 ];
99 196 }
100 197
101 198 /**
102 - * @param $key
199 + * Get fields
103 200 *
201 + * @param string $key Key.
202 + *
104 203 * @return array|mixed
105 204 */
106 205 public function get_fields( $key ) {
107 206 return isset( $this->full_list[ $key ]['fields'] ) ? $this->full_list[ $key ]['fields'] : [];
@@ -106,10 +205,20 @@
106 205 public function get_fields( $key ) {
107 206 return isset( $this->full_list[ $key ]['fields'] ) ? $this->full_list[ $key ]['fields'] : [];
108 207 }
109 208
209 + /**
210 + * Get data
211 + *
212 + * @return array
213 + */
110 214 public function get_data() {
111 215 return $this->db_options;
112 216 }
113 217
218 + /**
219 + * Get raw list
220 + *
221 + * @return array
222 + */
114 223 abstract protected function raw_list();
115 -}
224 +}