PluginProbe
Elementor Website Builder – more than just a page builder / 3.2.3
Elementor Website Builder – more than just a page builder v3.2.3
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.2.3, at core/responsive/files/frontend.php

179 lines 3.7 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]+)_([A-Z]+)/', 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 $is_max_point = 'MAX' === $placeholder_data[2];
51
52 if ( ! $is_max_point ) {
53 $breakpoint_index--;
54 }
55
56 $value = $breakpoints[ $breakpoints_keys[ $breakpoint_index ] ]->get_value();
57
58 if ( ! $is_max_point ) {
59 $value++;
60 }
61 }
62
63 return $value . 'px';
64 }, $file_content );
65
66 return $file_content;
67 }
68
69 /**
70 * Load meta.
71 *
72 * Retrieve the file meta data.
73 *
74 * @since 2.1.0
75 * @access protected
76 */
77 protected function load_meta() {
78 $option = $this->load_meta_option();
79
80 $file_meta_key = $this->get_file_meta_key();
81
82 if ( empty( $option[ $file_meta_key ] ) ) {
83 return [];
84 }
85
86 return $option[ $file_meta_key ];
87 }
88
89 /**
90 * Update meta.
91 *
92 * Update the file meta data.
93 *
94 * @since 2.1.0
95 * @access protected
96 *
97 * @param array $meta New meta data.
98 */
99 protected function update_meta( $meta ) {
100 $option = $this->load_meta_option();
101
102 $option[ $this->get_file_meta_key() ] = $meta;
103
104 update_option( static::META_KEY, $option );
105 }
106
107 /**
108 * Delete meta.
109 *
110 * Delete the file meta data.
111 *
112 * @since 2.1.0
113 * @access protected
114 */
115 protected function delete_meta() {
116 $option = $this->load_meta_option();
117
118 $file_meta_key = $this->get_file_meta_key();
119
120 if ( isset( $option[ $file_meta_key ] ) ) {
121 unset( $option[ $file_meta_key ] );
122 }
123
124 if ( $option ) {
125 update_option( static::META_KEY, $option );
126 } else {
127 delete_option( static::META_KEY );
128 }
129 }
130
131 /**
132 * @since 2.1.0
133 * @access private
134 */
135 private function get_file_meta_key() {
136 return pathinfo( $this->get_file_name(), PATHINFO_FILENAME );
137 }
138
139 /**
140 * @since 2.1.0
141 * @access private
142 */
143 private function load_meta_option() {
144 $option = get_option( static::META_KEY );
145
146 if ( ! $option ) {
147 $option = [];
148 }
149
150 return $option;
151 }
152
153 /**
154 * Maybe Convert Placeholder Data
155 *
156 * Converts responsive placeholders in Elementor CSS template files from the legacy format into the new format.
157 * Used for backwards compatibility for old Pro versions that were built with an Elementor Core version <3.2.0.
158 *
159 * @since 3.2.3
160 *
161 * @param $placeholder_data
162 * @return mixed
163 */
164 private function maybe_convert_placeholder_data( $placeholder_data ) {
165 switch ( $placeholder_data[1] ) {
166 case 'SM':
167 $placeholder_data[1] = 'MOBILE';
168 break;
169 case 'MD':
170 $placeholder_data[1] = 'TABLET';
171 break;
172 case 'LG':
173 $placeholder_data[1] = 'DESKTOP';
174 }
175
176 return $placeholder_data;
177 }
178 }
179