| @@ -1,16 +1,13 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace Elementor\Core\Responsive\Files; |
| 4 | 4 | |
| 5 | -use Elementor\Core\Breakpoints\Breakpoint; | |
| 6 | 5 | use Elementor\Core\Files\Base; |
| 7 | 6 | use Elementor\Core\Responsive\Responsive; |
| 8 | -use Elementor\Plugin; | |
| 9 | -use Elementor\Utils; | |
| 10 | 7 | |
| 11 | 8 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | - exit; // Exit if accessed directly. | |
| 9 | + exit; // Exit if accessed directly | |
| 13 | 10 | } |
| 14 | 11 | |
| 15 | 12 | class Frontend extends Base { |
| 16 | 13 | |
| @@ -32,52 +29,27 @@ | ||
| 32 | 29 | * @since 2.1.0 |
| 33 | 30 | * @access public |
| 34 | 31 | */ |
| 35 | 32 | public function parse_content() { |
| 36 | - $breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints(); | |
| 33 | + $breakpoints = Responsive::get_breakpoints(); | |
| 37 | 34 | |
| 38 | 35 | $breakpoints_keys = array_keys( $breakpoints ); |
| 39 | 36 | |
| 40 | - $file_content = Utils::file_get_contents( $this->template_file ); | |
| 37 | + $file_content = file_get_contents( $this->template_file ); | |
| 41 | 38 | |
| 42 | - // The regex pattern parses placeholders located in the frontend _templates.scss file. | |
| 43 | - $file_content = preg_replace_callback( '/ELEMENTOR_SCREEN_([A-Z_]+)(?:_(MIN|MAX|NEXT))/', function ( $placeholder_data ) use ( $breakpoints_keys, $breakpoints ) { | |
| 44 | - // Handle BC for legacy template files and Elementor Pro builds. | |
| 45 | - $placeholder_data = $this->maybe_convert_placeholder_data( $placeholder_data ); | |
| 39 | + $file_content = preg_replace_callback( '/ELEMENTOR_SCREEN_([A-Z]+)_([A-Z]+)/', function ( $placeholder_data ) use ( $breakpoints_keys, $breakpoints ) { | |
| 40 | + $breakpoint_index = array_search( strtolower( $placeholder_data[1] ), $breakpoints_keys ); | |
| 46 | 41 | |
| 47 | - $breakpoint_index = array_search( strtolower( $placeholder_data[1] ), $breakpoints_keys, true ); | |
| 42 | + $is_max_point = 'MAX' === $placeholder_data[2]; | |
| 48 | 43 | |
| 49 | - if ( 'DESKTOP' === $placeholder_data[1] ) { | |
| 50 | - if ( 'MIN' === $placeholder_data[2] ) { | |
| 51 | - $value = Plugin::$instance->breakpoints->get_desktop_min_point(); | |
| 52 | - } elseif ( isset( $breakpoints['widescreen'] ) ) { | |
| 53 | - // If the 'widescreen' breakpoint is active, the Desktop's max value is the Widescreen breakpoint - 1px. | |
| 54 | - $value = $breakpoints['widescreen']->get_value() - 1; | |
| 55 | - } else { | |
| 56 | - // If the 'widescreen' breakpoint is not active, the Desktop device should not have a max value. | |
| 57 | - $value = 99999; | |
| 58 | - } | |
| 59 | - } elseif ( false === $breakpoint_index ) { | |
| 60 | - // If the breakpoint in the placeholder is not active - use a -1 value for the media query, to make | |
| 61 | - // sure the setting is printed (to avoid a PHP error) but doesn't apply. | |
| 62 | - return -1; | |
| 63 | - } elseif ( 'WIDESCREEN' === $placeholder_data[1] ) { | |
| 64 | - $value = $breakpoints['widescreen']->get_value(); | |
| 65 | - } else { | |
| 66 | - $breakpoint_index = array_search( strtolower( $placeholder_data[1] ), $breakpoints_keys, true ); | |
| 44 | + if ( $is_max_point ) { | |
| 45 | + $breakpoint_index++; | |
| 46 | + } | |
| 67 | 47 | |
| 68 | - $is_max_point = 'MAX' === $placeholder_data[2]; | |
| 48 | + $value = $breakpoints[ $breakpoints_keys[ $breakpoint_index ] ]; | |
| 69 | 49 | |
| 70 | - // If the placeholder capture is `MOBILE_NEXT` or `TABLET_NEXT`, the original breakpoint value is used. | |
| 71 | - if ( ! $is_max_point && 'NEXT' !== $placeholder_data[2] ) { | |
| 72 | - $breakpoint_index--; | |
| 73 | - } | |
| 74 | - | |
| 75 | - $value = $breakpoints[ $breakpoints_keys[ $breakpoint_index ] ]->get_value(); | |
| 76 | - | |
| 77 | - if ( ! $is_max_point ) { | |
| 78 | - $value++; | |
| 79 | - } | |
| 50 | + if ( $is_max_point ) { | |
| 51 | + $value--; | |
| 80 | 52 | } |
| 81 | 53 | |
| 82 | 54 | return $value . 'px'; |
| 83 | 55 | }, $file_content ); |
| @@ -166,29 +138,6 @@ | ||
| 166 | 138 | $option = []; |
| 167 | 139 | } |
| 168 | 140 | |
| 169 | 141 | return $option; |
| 170 | - } | |
| 171 | - | |
| 172 | - /** | |
| 173 | - * Maybe Convert Placeholder Data | |
| 174 | - * | |
| 175 | - * Converts responsive placeholders in Elementor CSS template files from the legacy format into the new format. | |
| 176 | - * Used for backwards compatibility for old Pro versions that were built with an Elementor Core version <3.2.0. | |
| 177 | - * | |
| 178 | - * @since 3.2.3 | |
| 179 | - */ | |
| 180 | - private function maybe_convert_placeholder_data( $placeholder_data ) { | |
| 181 | - switch ( $placeholder_data[1] ) { | |
| 182 | - case 'SM': | |
| 183 | - $placeholder_data[1] = 'MOBILE'; | |
| 184 | - break; | |
| 185 | - case 'MD': | |
| 186 | - $placeholder_data[1] = 'TABLET'; | |
| 187 | - break; | |
| 188 | - case 'LG': | |
| 189 | - $placeholder_data[1] = 'DESKTOP'; | |
| 190 | - } | |
| 191 | - | |
| 192 | - return $placeholder_data; | |
| 193 | 142 | } |
| 194 | 143 | } |