/var/www/html/wp-content/plugins/elementor/core/files/css/post.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
<?php
namespace Elementor\Core\Files\CSS;

use 
Elementor\Controls_Stack;
use 
Elementor\Core\DynamicTags\Dynamic_CSS;
use 
Elementor\Core\Kits\Manager;
use 
Elementor\Element_Base;
use 
Elementor\Plugin;

if ( ! 
defined'ABSPATH' ) ) {
    exit; 
// Exit if accessed directly.
}

/**
 * Elementor post CSS file.
 *
 * Elementor CSS file handler class is responsible for generating the single
 * post CSS file.
 *
 * @since 1.2.0
 */
class Post extends Base {

    
/**
     * Elementor post CSS file prefix.
     */
    
const FILE_PREFIX 'post-';

    const 
META_KEY '_elementor_css';

    
/**
     * Post ID.
     *
     * Holds the current post ID.
     *
     * @var int
     */
    
private $post_id;

    protected function 
is_global_parsing_supported() {
        return 
true;
    }

    
/**
     * Post CSS file constructor.
     *
     * Initializing the CSS file of the post. Set the post ID and initiate the stylesheet.
     *
     * @since 1.2.0
     * @access public
     *
     * @param int $post_id Post ID.
     */
    
public function __construct$post_id ) {
        
$this->post_id $post_id;

        
parent::__construct( static::FILE_PREFIX $post_id '.css' );
    }

    
/**
     * Get CSS file name.
     *
     * Retrieve the CSS file name.
     *
     * @since 1.6.0
     * @access public
     *
     * @return string CSS file name.
     */
    
public function get_name() {
        return 
'post';
    }

    
/**
     * Get post ID.
     *
     * Retrieve the ID of current post.
     *
     * @since 1.2.0
     * @access public
     *
     * @return int Post ID.
     */
    
public function get_post_id() {
        return 
$this->post_id;
    }

    
/**
     * Get unique element selector.
     *
     * Retrieve the unique selector for any given element.
     *
     * @since 1.2.0
     * @access public
     *
     * @param Element_Base $element The element.
     *
     * @return string Unique element selector.
     */
    
public function get_element_unique_selectorElement_Base $element ) {
        return 
'.elementor-' $this->post_id ' .elementor-element' $element->get_unique_selector();
    }

    
/**
     * Load meta data.
     *
     * Retrieve the post CSS file meta data.
     *
     * @since 1.2.0
     * @access protected
     *
     * @return array Post CSS file meta data.
     */
    
protected function load_meta() {
        return 
get_post_meta$this->post_id, static::META_KEYtrue );
    }

    
/**
     * Update meta data.
     *
     * Update the global CSS file meta data.
     *
     * @since 1.2.0
     * @access protected
     *
     * @param array $meta New meta data.
     */
    
protected function update_meta$meta ) {
        
update_post_meta$this->post_id, static::META_KEY$meta );
    }

    
/**
     * Delete meta.
     *
     * Delete the file meta data.
     *
     * @since  2.1.0
     * @access protected
     */
    
protected function delete_meta() {
        
delete_post_meta$this->post_id, static::META_KEY );
    }

    
/**
     * Get post data.
     *
     * Retrieve raw post data from the database.
     *
     * @since 1.9.0
     * @access protected
     *
     * @return array Post data.
     */
    
protected function get_data() {
        
$document Plugin::$instance->documents->get$this->post_id );
        return 
$document $document->get_elements_data() : [];
    }

    
/**
     * Render CSS.
     *
     * Parse the CSS for all the elements.
     *
     * @since 1.2.0
     * @access protected
     */
    
protected function render_css() {
        
$data $this->get_data();

        if ( ! empty( 
$data ) ) {
            foreach ( 
$data as $element_data ) {
                
$element Plugin::$instance->elements_manager->create_element_instance$element_data );

                if ( ! 
$element ) {
                    continue;
                }

                
$this->render_styles$element );
            }
        }
    }

    
/**
     * Enqueue CSS.
     *
     * Enqueue the post CSS file in Elementor.
     *
     * This method ensures that the post was actually built with elementor before
     * enqueueing the post CSS file.
     *
     * @since 1.2.2
     * @access public
     */
    
public function enqueue() {
        
$document Plugin::$instance->documents->get$this->post_id );

        if ( ! 
$document || ! $document->is_built_with_elementor() ) {
            return;
        }

        
parent::enqueue();
    }

    
/**
     * Add controls-stack style rules.
     *
     * Parse the CSS for all the elements inside any given controls stack.
     *
     * This method recursively renders the CSS for all the child elements in the stack.
     *
     * @since 1.6.0
     * @access public
     *
     * @param Controls_Stack $controls_stack The controls stack.
     * @param array          $controls       Controls array.
     * @param array          $values         Values array.
     * @param array          $placeholders   Placeholders.
     * @param array          $replacements   Replacements.
     * @param array          $all_controls   All controls.
     */
    
public function add_controls_stack_style_rulesControls_Stack $controls_stack, array $controls, array $values, array $placeholders, array $replacements, array $all_controls null ) {
        
parent::add_controls_stack_style_rules$controls_stack$controls$values$placeholders$replacements$all_controls );

        if ( 
$controls_stack instanceof Element_Base ) {
            foreach ( 
$controls_stack->get_children() as $child_element ) {
                
$this->render_styles$child_element );
            }
        }
    }

    
/**
     * Get enqueue dependencies.
     *
     * Retrieve the name of the stylesheet used by `wp_enqueue_style()`.
     *
     * @since 1.2.0
     * @access protected
     *
     * @return array Name of the stylesheet.
     */
    
protected function get_enqueue_dependencies() {
        return [ 
'elementor-frontend' ];
    }

    
/**
     * Get inline dependency.
     *
     * Retrieve the name of the stylesheet used by `wp_add_inline_style()`.
     *
     * @since 1.2.0
     * @access protected
     *
     * @return string Name of the stylesheet.
     */
    
protected function get_inline_dependency() {
        return 
'elementor-frontend';
    }

    
/**
     * Get file handle ID.
     *
     * Retrieve the handle ID for the post CSS file.
     *
     * @since 1.2.0
     * @access protected
     *
     * @return string CSS file handle ID.
     */
    
protected function get_file_handle_id() {
        return 
'elementor-post-' $this->post_id;
    }

    
/**
     * Render styles.
     *
     * Parse the CSS for any given element.
     *
     * @since 1.2.0
     * @access protected
     *
     * @param Element_Base $element The element.
     */
    
protected function render_stylesElement_Base $element ) {
        
/**
         * Before element parse CSS.
         *
         * Fires before the CSS of the element is parsed.
         *
         * @since 1.2.0
         *
         * @param Post         $this    The post CSS file.
         * @param Element_Base $element The element.
         */
        
do_action'elementor/element/before_parse_css'$this$element );

        
$this->render_element_global_styles$element );
        
$this->render_element_styles$element );

        
/**
         * After element parse CSS.
         *
         * Fires after the CSS of the element is parsed.
         *
         * @since 1.2.0
         *
         * @param Post         $this    The post CSS file.
         * @param Element_Base $element The element.
         */
        
do_action'elementor/element/parse_css'$this$element );
    }

    private function 
render_element_stylesElement_Base $element ) {
        
$this->add_controls_stack_style_rules(
            
$element,
            
$this->get_style_controls$elementnull$element->get_parsed_dynamic_settings() ),
            
$element->get_settings(),
            [ 
'{{ID}}''{{WRAPPER}}' ],
            [ 
$element->get_id(), $this->get_element_unique_selector$element ) ]
        );
    }

    private function 
render_element_global_stylesElement_Base $element ) {
        if ( 
$this instanceof Dynamic_CSS ) {
            return;
        }

        
/** @var Manager $module */
        
$kits_manager Plugin::$instance->kits_manager;
        
$custom_colors_enabled $kits_manager->is_custom_colors_enabled();
        
$custom_typography_enabled $kits_manager->is_custom_typography_enabled();

        
$controls $element->get_controls();
        
$global_controls = [];
        
$global_values['__globals__'] = [];

        foreach ( 
$controls as $control ) {
            
$this->build_global_controls_and_values(
                
$control,
                
$controls,
                
$global_controls,
                
$global_values,
                
$custom_colors_enabled,
                
$custom_typography_enabled
            
);
        }

        foreach ( 
$global_controls as $control ) {
            
$this->add_control_rules(
                
$control,
                
$controls,
                function( 
$control ) {},
                [ 
'{{WRAPPER}}' ],
                [ 
'.elementor-widget-' $element->get_name() ],
                
$global_values
            
);
        }
    }

    private function 
build_global_controls_and_values$control$controls, &$global_controls, &$global_values$custom_colors_enabled$custom_typography_enabled ) {
        
$is_color_control 'color' === $control['type'];
        
$is_typography_control = isset( $control['groupType'] ) && 'typography' === $control['groupType'];

        
// If it is a color/typography control and default colors/typography are disabled,
        // don't add the default CSS.
        
if ( ( $is_color_control && ! $custom_colors_enabled ) || ( $is_typography_control && ! $custom_typography_enabled ) ) {
            return;
        }

        
$global_control $control;

        
// Handle group controls that don't have a default global property.
        
if ( ! empty( $control['groupType'] ) ) {
            
$global_control $controls$control['groupPrefix'] . $control['groupType'] ];
        }

        
// If the control has a default global defined, add it to the globals array
        // that is used in add_control_rules.
        
if ( ! empty( $control['global']['default'] ) ) {
            
$global_values['__globals__'][ $control['name'] ] = $global_control['global']['default'];
        }

        if ( ! empty( 
$global_control['global']['default'] ) ) {
            
$global_controls[] = $control;
        }
    }
}