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