activation-actions.php
4 years ago
build-inline-scripts.php
3 weeks ago
build-modules.php
4 months ago
build-widgets.php
4 months ago
config-list.php
4 months ago
editor-promotion.php
3 weeks ago
handler-api.php
6 months ago
handler-widget.php
4 years ago
plugin-unsubscribe.php
3 weeks ago
config-list.php
69 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite\Core; |
| 3 | |
| 4 | abstract class Config_List { |
| 5 | |
| 6 | use \ElementsKit_Lite\Traits\Singleton; |
| 7 | |
| 8 | private $full_list = array(); |
| 9 | private $active_list = array(); |
| 10 | |
| 11 | protected $optional_list = array(); |
| 12 | protected $required_list = array(); |
| 13 | |
| 14 | protected $type; |
| 15 | |
| 16 | public function __construct() { |
| 17 | $this->set_optional_list(); |
| 18 | $this->set_required_list(); |
| 19 | $this->set_full_list(); |
| 20 | $this->set_active_list(); |
| 21 | } |
| 22 | |
| 23 | public function get_list( $data = 'full', $module = null ) { |
| 24 | if ( $module != null ) { |
| 25 | return ( $this->{$data . '_list'}[ $module ] ?? false ); |
| 26 | } |
| 27 | |
| 28 | // Return all items including pro-disabled for promotion purposes |
| 29 | if ( $data === 'all' ) { |
| 30 | return $this->full_list; |
| 31 | } |
| 32 | |
| 33 | return $this->{$data . '_list'}; |
| 34 | } |
| 35 | |
| 36 | public function is_active( $item ) { |
| 37 | |
| 38 | $item = ( $this->active_list[ $item ] ?? array() ); |
| 39 | |
| 40 | return empty( $item['package'] ) ? false : ( ( $item['package'] == 'free' || $item['package'] == 'pro' ) ); |
| 41 | } |
| 42 | |
| 43 | private function set_active_list() { |
| 44 | $database_list = \ElementsKit_Lite\Libs\Framework\Attr::instance()->utils->get_option( $this->type . '_list', array() ); |
| 45 | |
| 46 | foreach ( $this->full_list as $key => $item ) { |
| 47 | |
| 48 | if ( isset( $database_list[ $key ]['status'] ) && $database_list[ $key ]['status'] == 'inactive' && ! key_exists( $key, $this->required_list ) ) { |
| 49 | continue; |
| 50 | } |
| 51 | |
| 52 | if ( isset( $item['package'] ) && $item['package'] == 'pro-disabled' ) { |
| 53 | continue; |
| 54 | } |
| 55 | |
| 56 | $this->active_list[ $key ] = $item; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | private function set_full_list() { |
| 61 | $this->full_list = array_merge( $this->required_list, $this->optional_list ); |
| 62 | } |
| 63 | |
| 64 | abstract protected function set_required_list(); |
| 65 | |
| 66 | abstract protected function set_optional_list(); |
| 67 | |
| 68 | } |
| 69 |