PluginProbe
Elementor Website Builder – more than just a page builder / 3.3.1
Elementor Website Builder – more than just a page builder v3.3.1
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
elementor / core / responsive / files / frontend.php

frontend.php in Elementor Website Builder – more than just a page builder 3.3.1, at core/responsive/files/frontend.php

185 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Elementor\Core\Responsive\Files;
4
5 use Elementor\Core\Breakpoints\Breakpoint;
6 use Elementor\Core\Files\Base;
7 use Elementor\Core\Responsive\Responsive;
8 use Elementor\Plugin;
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit; // Exit if accessed directly
12 }
13
14 class Frontend extends Base {
15
16 const META_KEY = 'elementor-custom-breakpoints-files';
17
18 private $template_file;
19
20 /**
21 * @since 2.1.0
22 * @access public
23 */
24 public function __construct( $file_name, $template_file = null ) {
25 $this->template_file = $template_file;
26
27 parent::__construct( $file_name );
28 }
29
30 /**
31 * @since 2.1.0
32 * @access public
33 */
34 public function parse_content() {
35 $breakpoints = Plugin::$instance->breakpoints->get_active_breakpoints();
36
37 $breakpoints_keys = array_keys( $breakpoints );
38
39 $file_content = file_get_contents( $this->template_file );
40
41 $file_content = preg_replace_callback( '/ELEMENTOR_SCREEN_([A-Z_]+)(?:_(MIN|MAX|NEXT))/', function ( $placeholder_data ) use ( $breakpoints_keys, $breakpoints ) {
42 // Handle BC for legacy template files and Elementor Pro builds.
43 $placeholder_data = $this->maybe_convert_placeholder_data( $placeholder_data );
44
45 if ( 'DESKTOP' === $placeholder_data[1] ) {
46 $value = Plugin::$instance->breakpoints->get_desktop_min_point();
47 } else {
48 $breakpoint_index = array_search( strtolower( $placeholder_data[1] ), $breakpoints_keys, true );
49
50 // Handle cases where a placeholder is found for an additional breakpoint that isn't active.
51 if ( false === $breakpoint_index ) {
52 $value = -1;
53 } else {
54 $is_max_point = 'MAX' === $placeholder_data[2];
55
56 // If the placeholder capture is `MOBILE_NEXT` or `TABLET_NEXT`, the original breakpoint value is used.
57 if ( ! $is_max_point && 'NEXT' !== $placeholder_data[2] ) {
58 $breakpoint_index--;
59 }
60
61 $value = $breakpoints[ $breakpoints_keys[ $breakpoint_index ] ]->get_value();
62
63 if ( ! $is_max_point ) {
64 $value++;
65 }
66 }
67 }
68
69 return $value . 'px';
70 }, $file_content );
71
72 return $file_content;
73 }
74
75 /**
76 * Load meta.
77 *
78 * Retrieve the file meta data.
79 *
80 * @since 2.1.0
81 * @access protected
82 */
83 protected function load_meta() {
84 $option = $this->load_meta_option();
85
86 $file_meta_key = $this->get_file_meta_key();
87
88 if ( empty( $option[ $file_meta_key ] ) ) {
89 return [];
90 }
91
92 return $option[ $file_meta_key ];
93 }
94
95 /**
96 * Update meta.
97 *
98 * Update the file meta data.
99 *
100 * @since 2.1.0
101 * @access protected
102 *
103 * @param array $meta New meta data.
104 */
105 protected function update_meta( $meta ) {
106 $option = $this->load_meta_option();
107
108 $option[ $this->get_file_meta_key() ] = $meta;
109
110 update_option( static::META_KEY, $option );
111 }
112
113 /**
114 * Delete meta.
115 *
116 * Delete the file meta data.
117 *
118 * @since 2.1.0
119 * @access protected
120 */
121 protected function delete_meta() {
122 $option = $this->load_meta_option();
123
124 $file_meta_key = $this->get_file_meta_key();
125
126 if ( isset( $option[ $file_meta_key ] ) ) {
127 unset( $option[ $file_meta_key ] );
128 }
129
130 if ( $option ) {
131 update_option( static::META_KEY, $option );
132 } else {
133 delete_option( static::META_KEY );
134 }
135 }
136
137 /**
138 * @since 2.1.0
139 * @access private
140 */
141 private function get_file_meta_key() {
142 return pathinfo( $this->get_file_name(), PATHINFO_FILENAME );
143 }
144
145 /**
146 * @since 2.1.0
147 * @access private
148 */
149 private function load_meta_option() {
150 $option = get_option( static::META_KEY );
151
152 if ( ! $option ) {
153 $option = [];
154 }
155
156 return $option;
157 }
158
159 /**
160 * Maybe Convert Placeholder Data
161 *
162 * Converts responsive placeholders in Elementor CSS template files from the legacy format into the new format.
163 * Used for backwards compatibility for old Pro versions that were built with an Elementor Core version <3.2.0.
164 *
165 * @since 3.2.3
166 *
167 * @param $placeholder_data
168 * @return mixed
169 */
170 private function maybe_convert_placeholder_data( $placeholder_data ) {
171 switch ( $placeholder_data[1] ) {
172 case 'SM':
173 $placeholder_data[1] = 'MOBILE';
174 break;
175 case 'MD':
176 $placeholder_data[1] = 'TABLET';
177 break;
178 case 'LG':
179 $placeholder_data[1] = 'DESKTOP';
180 }
181
182 return $placeholder_data;
183 }
184 }
185