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