PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.0.1
ShopBuilder – WooCommerce Builder For Elementor v2.0.1
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.0.1, at app/Models/Base/ListModel.php

115 lines 3.0 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 if ( ! empty( $raw_list ) ) {
27 foreach ( $raw_list as $name => $item ) {
28
29 if ( ! empty( $item['package'] ) && $item['package'] === 'pro-disabled' ) {
30 $item['fields'] = [];
31 $item['active'] = false;
32 $this->full_list[ $name ] = $item;
33 $this->inactive_list[ $name ] = $item;
34 continue;
35 }
36
37 if ( ! isset( $this->db_options[ $name ]['active'] ) && ! empty( $item['active'] ) ) {
38 $item['active'] = 'on';
39 } else {
40 $item['active'] = isset( $this->db_options[ $name ]['active'] ) && $this->db_options[ $name ]['active'] === 'on' ? 'on' : '';
41 }
42
43 if ( ! empty( $item['fields'] ) ) {
44 foreach ( $item['fields'] as $field_key => $field ) {
45 $the_value = $this->db_options[ $name ][ $field_key ] ?? ( $item['fields'][ $field_key ]['value'] ?? '' );
46 $sanitized_value = Fns::stripslashes_value( $the_value );
47 $item['fields'][ $field_key ]['value'] = $sanitized_value;
48 }
49 }
50 $this->full_list[ $name ] = $item;
51
52 if ( 'on' === $item['active'] ) {
53 $this->active_list[ $name ] = $item;
54 } else {
55 $this->inactive_list[ $name ] = $item;
56 }
57 }
58 }
59 }
60
61 /**
62 * @return string Pro Package
63 */
64 protected function pro_package() {
65 return rtsb()->has_pro() ? 'pro' : 'pro-disabled';
66 }
67 /**
68 * @param $key
69 *
70 * @return bool
71 */
72 public function is_widget_active( $key ) {
73 return isset( $this->active_list[ $key ] );
74 }
75
76 /**
77 * @param mixed $list true | anything
78 * @param string $filter_type full|active|inactive
79 *
80 * @return mixed
81 */
82 public function get_list( $list = true, $filter_type = 'full' ) { //
83 if ( $list !== true && isset( $this->full_list[ $list ] ) ) {
84 return $this->full_list[ $list ];
85 }
86
87 return $this->{$filter_type . '_list'};
88 }
89
90 public function get_section() {
91 return [
92 'title' => $this->title,
93 'short_title' => ! empty( $this->short_title ) ? $this->short_title : $this->title,
94 'description' => $this->description,
95 'list' => $this->get_list(),
96 'id' => $this->list_id,
97 'categories' => $this->categories,
98 ];
99 }
100
101 /**
102 * @param $key
103 *
104 * @return array|mixed
105 */
106 public function get_fields( $key ) {
107 return isset( $this->full_list[ $key ]['fields'] ) ? $this->full_list[ $key ]['fields'] : [];
108 }
109
110 public function get_data() {
111 return $this->db_options;
112 }
113
114 abstract protected function raw_list();
115 }