| 1 |
<?php |
| 2 |
namespace Elementor\Core\Responsive; |
| 3 |
|
| 4 |
use Elementor\Core\Responsive\Files\Frontend; |
| 5 |
use Elementor\Plugin; |
| 6 |
|
| 7 |
if ( ! defined( 'ABSPATH' ) ) { |
| 8 |
exit; // Exit if accessed directly. |
| 9 |
} |
| 10 |
|
| 11 |
/** |
| 12 |
* Elementor responsive. |
| 13 |
* |
| 14 |
* Elementor responsive handler class is responsible for setting up Elementor |
| 15 |
* responsive breakpoints. |
| 16 |
* |
| 17 |
* @since 1.0.0 |
| 18 |
*/ |
| 19 |
class Responsive { |
| 20 |
|
| 21 |
/** |
| 22 |
* The Elementor breakpoint prefix. |
| 23 |
*/ |
| 24 |
const BREAKPOINT_OPTION_PREFIX = 'viewport_'; |
| 25 |
|
| 26 |
/** |
| 27 |
* Default breakpoints. |
| 28 |
* |
| 29 |
* Holds the default responsive breakpoints. |
| 30 |
* |
| 31 |
* @since 1.0.0 |
| 32 |
* @access private |
| 33 |
* @static |
| 34 |
* |
| 35 |
* @var array Default breakpoints. |
| 36 |
*/ |
| 37 |
private static $default_breakpoints = [ |
| 38 |
'xs' => 0, |
| 39 |
'sm' => 480, |
| 40 |
'md' => 768, |
| 41 |
'lg' => 1025, |
| 42 |
'xl' => 1440, |
| 43 |
'xxl' => 1600, |
| 44 |
]; |
| 45 |
|
| 46 |
/** |
| 47 |
* Editable breakpoint keys. |
| 48 |
* |
| 49 |
* Holds the editable breakpoint keys. |
| 50 |
* |
| 51 |
* @since 1.0.0 |
| 52 |
* @access private |
| 53 |
* @static |
| 54 |
* |
| 55 |
* @var array Editable breakpoint keys. |
| 56 |
*/ |
| 57 |
private static $editable_breakpoints_keys = [ |
| 58 |
'md', |
| 59 |
'lg', |
| 60 |
]; |
| 61 |
|
| 62 |
/** |
| 63 |
* Get default breakpoints. |
| 64 |
* |
| 65 |
* Retrieve the default responsive breakpoints. |
| 66 |
* |
| 67 |
* @since 1.0.0 |
| 68 |
* @access public |
| 69 |
* @static |
| 70 |
* |
| 71 |
* @return array Default breakpoints. |
| 72 |
*/ |
| 73 |
public static function get_default_breakpoints() { |
| 74 |
return self::$default_breakpoints; |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Get editable breakpoints. |
| 79 |
* |
| 80 |
* Retrieve the editable breakpoints. |
| 81 |
* |
| 82 |
* @since 1.0.0 |
| 83 |
* @access public |
| 84 |
* @static |
| 85 |
* |
| 86 |
* @return array Editable breakpoints. |
| 87 |
*/ |
| 88 |
public static function get_editable_breakpoints() { |
| 89 |
return array_intersect_key( self::get_breakpoints(), array_flip( self::$editable_breakpoints_keys ) ); |
| 90 |
} |
| 91 |
|
| 92 |
/** |
| 93 |
* Get breakpoints. |
| 94 |
* |
| 95 |
* Retrieve the responsive breakpoints. |
| 96 |
* |
| 97 |
* @since 1.0.0 |
| 98 |
* @access public |
| 99 |
* @static |
| 100 |
* |
| 101 |
* @return array Responsive breakpoints. |
| 102 |
*/ |
| 103 |
public static function get_breakpoints() { |
| 104 |
return array_reduce( |
| 105 |
array_keys( self::$default_breakpoints ), function( $new_array, $breakpoint_key ) { |
| 106 |
if ( ! in_array( $breakpoint_key, self::$editable_breakpoints_keys ) ) { |
| 107 |
$new_array[ $breakpoint_key ] = self::$default_breakpoints[ $breakpoint_key ]; |
| 108 |
} else { |
| 109 |
$saved_option = Plugin::$instance->kits_manager->get_current_settings( self::BREAKPOINT_OPTION_PREFIX . $breakpoint_key ); |
| 110 |
|
| 111 |
$new_array[ $breakpoint_key ] = $saved_option ? (int) $saved_option : self::$default_breakpoints[ $breakpoint_key ]; |
| 112 |
} |
| 113 |
|
| 114 |
return $new_array; |
| 115 |
}, [] |
| 116 |
); |
| 117 |
} |
| 118 |
|
| 119 |
/** |
| 120 |
* @since 2.1.0 |
| 121 |
* @access public |
| 122 |
* @static |
| 123 |
*/ |
| 124 |
public static function has_custom_breakpoints() { |
| 125 |
return ! ! array_diff( self::$default_breakpoints, self::get_breakpoints() ); |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* @since 2.1.0 |
| 130 |
* @access public |
| 131 |
* @static |
| 132 |
*/ |
| 133 |
public static function get_stylesheet_templates_path() { |
| 134 |
return ELEMENTOR_ASSETS_PATH . 'css/templates/'; |
| 135 |
} |
| 136 |
|
| 137 |
/** |
| 138 |
* @since 2.1.0 |
| 139 |
* @access public |
| 140 |
* @static |
| 141 |
*/ |
| 142 |
public static function compile_stylesheet_templates() { |
| 143 |
foreach ( self::get_stylesheet_templates() as $file_name => $template_path ) { |
| 144 |
$file = new Frontend( $file_name, $template_path ); |
| 145 |
|
| 146 |
$file->update(); |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* @since 2.1.0 |
| 152 |
* @access private |
| 153 |
* @static |
| 154 |
*/ |
| 155 |
private static function get_stylesheet_templates() { |
| 156 |
$templates_paths = glob( self::get_stylesheet_templates_path() . '*.css' ); |
| 157 |
|
| 158 |
$templates = []; |
| 159 |
|
| 160 |
foreach ( $templates_paths as $template_path ) { |
| 161 |
$file_name = 'custom-' . basename( $template_path ); |
| 162 |
|
| 163 |
$templates[ $file_name ] = $template_path; |
| 164 |
} |
| 165 |
|
| 166 |
return apply_filters( 'elementor/core/responsive/get_stylesheet_templates', $templates ); |
| 167 |
} |
| 168 |
} |
| 169 |
|