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

150 lines 2.9 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 if ( 'DESKTOP' === $placeholder_data[1] ) {
43 $value = Plugin::$instance->breakpoints->get_desktop_min_point();
44 } else {
45 $breakpoint_index = array_search( strtolower( $placeholder_data[1] ), $breakpoints_keys, true );
46
47 $is_max_point = 'MAX' === $placeholder_data[2];
48
49 if ( ! $is_max_point ) {
50 $breakpoint_index--;
51 }
52
53 $value = $breakpoints[ $breakpoints_keys[ $breakpoint_index ] ]->get_value();
54
55 if ( ! $is_max_point ) {
56 $value++;
57 }
58 }
59
60 return $value . 'px';
61 }, $file_content );
62
63 return $file_content;
64 }
65
66 /**
67 * Load meta.
68 *
69 * Retrieve the file meta data.
70 *
71 * @since 2.1.0
72 * @access protected
73 */
74 protected function load_meta() {
75 $option = $this->load_meta_option();
76
77 $file_meta_key = $this->get_file_meta_key();
78
79 if ( empty( $option[ $file_meta_key ] ) ) {
80 return [];
81 }
82
83 return $option[ $file_meta_key ];
84 }
85
86 /**
87 * Update meta.
88 *
89 * Update the file meta data.
90 *
91 * @since 2.1.0
92 * @access protected
93 *
94 * @param array $meta New meta data.
95 */
96 protected function update_meta( $meta ) {
97 $option = $this->load_meta_option();
98
99 $option[ $this->get_file_meta_key() ] = $meta;
100
101 update_option( static::META_KEY, $option );
102 }
103
104 /**
105 * Delete meta.
106 *
107 * Delete the file meta data.
108 *
109 * @since 2.1.0
110 * @access protected
111 */
112 protected function delete_meta() {
113 $option = $this->load_meta_option();
114
115 $file_meta_key = $this->get_file_meta_key();
116
117 if ( isset( $option[ $file_meta_key ] ) ) {
118 unset( $option[ $file_meta_key ] );
119 }
120
121 if ( $option ) {
122 update_option( static::META_KEY, $option );
123 } else {
124 delete_option( static::META_KEY );
125 }
126 }
127
128 /**
129 * @since 2.1.0
130 * @access private
131 */
132 private function get_file_meta_key() {
133 return pathinfo( $this->get_file_name(), PATHINFO_FILENAME );
134 }
135
136 /**
137 * @since 2.1.0
138 * @access private
139 */
140 private function load_meta_option() {
141 $option = get_option( static::META_KEY );
142
143 if ( ! $option ) {
144 $option = [];
145 }
146
147 return $option;
148 }
149 }
150