/var/www/html_us/wp-content/plugins/elementor/modules/system-info/reporters/base.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
<?php
namespace Elementor\Modules\System_Info\Reporters;

use 
Elementor\Modules\System_Info\Helpers\Model_Helper;
use 
Elementor\Utils;

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

/**
 * Elementor base reporter.
 *
 * A base abstract class that provides the needed properties and methods to
 * manage and handle reporter in inheriting classes.
 *
 * @since 2.9.0
 * @abstract
 */
abstract class Base {

    
/**
     * Reporter properties.
     *
     * Holds the list of all the properties of the report.
     *
     * @access protected
     * @static
     *
     * @var array
     */
    
protected $_properties;

    
/**
     * Get report title.
     *
     * Retrieve the title of the report.
     *
     * @since 2.9.0
     * @access public
     * @abstract
     */
    
abstract public function get_title();

    
/**
     * Get report fields.
     *
     * Retrieve the required fields for the report.
     *
     * @since 2.9.0
     * @access public
     * @abstract
     */
    
abstract public function get_fields();

    
/**
     * Is report enabled.
     *
     * Whether the report is enabled.
     *
     * @since 2.9.0
     * @access public
     *
     * @return bool Whether the report is enabled.
     */
    
public function is_enabled() {
        return 
true;
    }

    public function 
print_html() {
        foreach ( 
$this->get_report'html' ) as $field ) {
            
$warning_class = ! empty( $field['warning'] ) ? ' class="elementor-warning"' '';
            
$log_label = ! empty( $field['label'] ) ? $field['label'] . ':' '';
            
?>
            <tr<?php Utils::print_unescaped_internal_string$warning_class ); ?>>
                <td><?php Utils::print_unescaped_internal_string$log_label ); ?></td>
                <td><?php Utils::print_unescaped_internal_string$field['value'] ); ?></td>
                <td><?php
                
if ( ! empty( $field['recommendation'] ) ) :
                    
Utils::print_unescaped_internal_string$field['recommendation'] );
                    endif;
                
?></td>
            </tr>
            <?php
        
}
    }

    public function 
print_html_label$label ) {
        
Utils::print_unescaped_internal_string$label );
    }

    public function 
print_raw$tabs_count ) {
        
$indent str_repeat"\t"$tabs_count );

        
$report $this->get_report'raw' );

        echo 
PHP_EOL $indent '== ' $this->get_title() . ' =='// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        
echo PHP_EOL;

        foreach ( 
$report as $field_name => $field ) :
            
$sub_indent str_repeat"\t"$tabs_count );

            
$label $field['label'];

            if ( ! empty( 
$label ) ) {
                
$label .= ': ';
            }
            echo 
"{$sub_indent}{$label}{$field['value']}PHP_EOL// phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
        
endforeach;
    }

    
/**
     * Get report.
     *
     * Retrieve the report with all it's containing fields.
     *
     * @since 2.9.0
     * @access public
     *
     * @return \WP_Error | array {
     *    Report fields.
     *
     *    @type string $name Field name.
     *    @type string $label Field label.
     * }
     */
    
final public function get_report$format '' ) {
        
$result = [];

        
$format = ( empty( $format ) ) ? '' $format '_';

        foreach ( 
$this->get_fields() as $field_name => $field_label ) {
            
$method 'get_' $format $field_name;

            if ( ! 
method_exists$this$method ) ) {
                
$method 'get_' $field_name;
                
//fallback:
                
if ( ! method_exists$this$method ) ) {
                    return new 
\WP_Errorsprintf"Getter method for the field '%s' wasn't found in %s."$field_nameget_called_class() ) );
                }
            }

            
$reporter_field = [
                
'name' => $field_name,
                
'label' => $field_label,
            ];

            
$reporter_field array_merge$reporter_field$this->$method() );
            
$result$field_name ] = $reporter_field;
        }

        return 
$result;
    }

    
/**
     * Get properties keys.
     *
     * Retrieve the keys of the properties.
     *
     * @since 2.9.0
     * @access public
     * @static
     *
     * @return array {
     *    Property keys.
     *
     *    @type string $name   Property name.
     *    @type string $fields Property fields.
     * }
     */
    
public static function get_properties_keys() {
        return [
            
'name',
            
'format',
            
'fields',
        ];
    }

    
/**
     * Filter possible properties.
     *
     * Retrieve possible properties filtered by property keys.
     *
     * @since 2.9.0
     * @access public
     * @static
     *
     * @param array $properties Properties to filter.
     *
     * @return array Possible properties filtered by property keys.
     */
    
final public static function filter_possible_properties$properties ) {
        return 
Model_Helper::filter_possible_propertiesself::get_properties_keys(), $properties );
    }

    
/**
     * Set properties.
     *
     * Add/update properties to the report.
     *
     * @since 2.9.0
     * @access public
     *
     * @param array $key   Property key.
     * @param array $value Optional. Property value. Default is `null`.
     */
    
final public function set_properties$key$value null ) {
        if ( 
is_array$key ) ) {
            
$key self::filter_possible_properties$key );

            foreach ( 
$key as $sub_key => $sub_value ) {
                
$this->set_properties$sub_key$sub_value );
            }

            return;
        }

        if ( ! 
in_array$keyself::get_properties_keys(), true ) ) {
            return;
        }

        
$this->_properties$key ] = $value;
    }

    
/**
     * Reporter base constructor.
     *
     * Initializing the reporter base class.
     *
     * @since 2.9.0
     * @access public
     *
     * @param array $properties Optional. Properties to filter. Default is `null`.
     */
    
public function __construct$properties null ) {
        
$this->_properties array_fill_keysself::get_properties_keys(), null );

        if ( 
$properties ) {
            
$this->set_properties$propertiesnull );
        }
    }
}