| 1 |
<?php |
| 2 |
/** |
| 3 |
* Abstract module |
| 4 |
* |
| 5 |
* @package |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WPFunnels\Admin\Module; |
| 9 |
|
| 10 |
abstract class Wpfnl_Admin_Module |
| 11 |
{ |
| 12 |
protected static $_instances = []; |
| 13 |
|
| 14 |
abstract public function get_name(); |
| 15 |
|
| 16 |
abstract public function init_ajax(); |
| 17 |
|
| 18 |
abstract public function get_view(); |
| 19 |
|
| 20 |
public function get_validation_data() |
| 21 |
{ |
| 22 |
return [ |
| 23 |
'logged_in' => true, |
| 24 |
'user_can' => 'manage_options', |
| 25 |
]; |
| 26 |
} |
| 27 |
|
| 28 |
public static function instance() |
| 29 |
{ |
| 30 |
$class_name = static::class_name(); |
| 31 |
|
| 32 |
if (empty(static::$_instances[ $class_name ])) { |
| 33 |
static::$_instances[ $class_name ] = new static(); |
| 34 |
} |
| 35 |
|
| 36 |
return static::$_instances[ $class_name ]; |
| 37 |
} |
| 38 |
|
| 39 |
public static function class_name() |
| 40 |
{ |
| 41 |
return get_called_class(); |
| 42 |
} |
| 43 |
|
| 44 |
final protected function get_assets_url($file_name, $file_extension, $relative_url = null, $add_min_suffix = 'default') |
| 45 |
{ |
| 46 |
static $is_test_mode = null; |
| 47 |
|
| 48 |
if (null === $is_test_mode) { |
| 49 |
$is_test_mode = defined('SCRIPT_DEBUG') && SCRIPT_DEBUG || defined('ELEMENTOR_TESTS') && ELEMENTOR_TESTS; |
| 50 |
} |
| 51 |
|
| 52 |
if (! $relative_url) { |
| 53 |
$relative_url = $this->get_assets_relative_url() . $file_extension . '/'; |
| 54 |
} |
| 55 |
|
| 56 |
$url = $this->get_assets_base_url() . $relative_url . $file_name; |
| 57 |
|
| 58 |
if ('default' === $add_min_suffix) { |
| 59 |
$add_min_suffix = ! $is_test_mode; |
| 60 |
} |
| 61 |
|
| 62 |
if ($add_min_suffix) { |
| 63 |
$url .= '.min'; |
| 64 |
} |
| 65 |
|
| 66 |
return $url . '.' . $file_extension; |
| 67 |
} |
| 68 |
|
| 69 |
|
| 70 |
final protected function get_js_assets_url($file_name, $relative_url = null, $add_min_suffix = 'default') |
| 71 |
{ |
| 72 |
return $this->get_assets_url($file_name, 'js', $relative_url, $add_min_suffix); |
| 73 |
} |
| 74 |
|
| 75 |
final protected function get_css_assets_url($file_name, $relative_url = null, $add_min_suffix = 'default', $add_direction_suffix = false) |
| 76 |
{ |
| 77 |
static $direction_suffix = null; |
| 78 |
|
| 79 |
if (! $direction_suffix) { |
| 80 |
$direction_suffix = is_rtl() ? '-rtl' : ''; |
| 81 |
} |
| 82 |
|
| 83 |
if ($add_direction_suffix) { |
| 84 |
$file_name .= $direction_suffix; |
| 85 |
} |
| 86 |
|
| 87 |
return $this->get_assets_url($file_name, 'css', $relative_url, $add_min_suffix); |
| 88 |
} |
| 89 |
|
| 90 |
/** |
| 91 |
* Get assets base url |
| 92 |
* |
| 93 |
* @since 2.6.0 |
| 94 |
* @access protected |
| 95 |
* |
| 96 |
* @return string |
| 97 |
*/ |
| 98 |
protected function get_assets_base_url() |
| 99 |
{ |
| 100 |
return ELEMENTOR_URL; |
| 101 |
} |
| 102 |
|
| 103 |
/** |
| 104 |
* Get assets relative url |
| 105 |
* |
| 106 |
* @since 2.3.0 |
| 107 |
* @access protected |
| 108 |
* |
| 109 |
* @return string |
| 110 |
*/ |
| 111 |
protected function get_assets_relative_url() |
| 112 |
{ |
| 113 |
return 'assets/'; |
| 114 |
} |
| 115 |
} |
| 116 |
|