Diff: STRATO-apps/wordpress_03/app/wp-content/plugins/wp-rocket/inc/classes/class-abstract-render.php
Keine Baseline-Datei – Diff nur gegen leer.
1
-
1
+
<?php
2
+
namespace WP_Rocket;
3
+
4
+
use WP_Rocket\Interfaces\Render_Interface;
5
+
6
+
/**
7
+
* Handle rendering of HTML content created by WP Rocket.
8
+
*
9
+
* @since 3.0
10
+
* @author Remy Perona
11
+
*/
12
+
abstract class Abstract_Render implements Render_Interface {
13
+
/**
14
+
* Path to the templates
15
+
*
16
+
* @since 3.0
17
+
* @author Remy Perona
18
+
*
19
+
* @var string
20
+
*/
21
+
private $template_path;
22
+
23
+
/**
24
+
* Constructor
25
+
*
26
+
* @since 3.0
27
+
* @author Remy Perona
28
+
*
29
+
* @param string $template_path Path to the templates.
30
+
*/
31
+
public function __construct( $template_path ) {
32
+
$this->template_path = $template_path;
33
+
}
34
+
35
+
/**
36
+
* Renders the given template if it's readable.
37
+
*
38
+
* @since 3.0
39
+
* @author Remy Perona
40
+
*
41
+
* @param string $template Template slug.
42
+
* @param array $data Data to pass to the template.
43
+
*/
44
+
public function generate( $template, $data = [] ) {
45
+
$template_path = $this->get_template_path( $template );
46
+
47
+
if ( ! rocket_direct_filesystem()->is_readable( $template_path ) ) {
48
+
return;
49
+
}
50
+
51
+
ob_start();
52
+
53
+
include $template_path;
54
+
55
+
return trim( ob_get_clean() );
56
+
}
57
+
58
+
/**
59
+
* Returns the path a specific template.
60
+
*
61
+
* @since 3.0
62
+
* @author Remy Perona
63
+
*
64
+
* @param string $path Relative path to the template.
65
+
* @return string
66
+
*/
67
+
private function get_template_path( $path ) {
68
+
return $this->template_path . '/' . $path . '.php';
69
+
}
70
+
71
+
/**
72
+
* Displays the button template.
73
+
*
74
+
* @since 3.0
75
+
* @author Remy Perona
76
+
*
77
+
* @param string $type Type of button (can be button or link).
78
+
* @param string $action Action to be performed.
79
+
* @param array $args Optional array of arguments to populate the button attributes.
80
+
* @return void
81
+
*/
82
+
public function render_action_button( $type, $action, $args = [] ) {
83
+
$default = [
84
+
'label' => '',
85
+
'action' => '',
86
+
'url' => '',
87
+
'parameter' => '',
88
+
'attributes' => '',
89
+
'tooltip' => '',
90
+
];
91
+
92
+
$args = wp_parse_args( $args, $default );
93
+
94
+
if ( ! empty( $args['attributes'] ) ) {
95
+
$attributes = '';
96
+
foreach ( $args['attributes'] as $key => $value ) {
97
+
if ( true === $value ) {
98
+
$attributes .= ' ' . sanitize_key( $key );
99
+
continue;
100
+
}
101
+
102
+
$attributes .= ' ' . sanitize_key( $key ) . '="' . esc_attr( $value ) . '"';
103
+
}
104
+
105
+
$args['attributes'] = $attributes;
106
+
}
107
+
108
+
if ( 'link' !== $type ) {
109
+
$args['action'] = $action;
110
+
echo $this->generate( 'buttons/button', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
111
+
return;
112
+
}
113
+
114
+
switch ( $action ) {
115
+
case 'ask_support':
116
+
case 'view_account':
117
+
$args['url'] = rocket_get_external_url(
118
+
'ask_support' === $action ? 'support' : 'account',
119
+
[
120
+
'utm_source' => 'wp_plugin',
121
+
'utm_medium' => 'wp_rocket',
122
+
]
123
+
);
124
+
break;
125
+
case 'purge_cache':
126
+
case 'preload':
127
+
case 'rocket_purge_cloudflare':
128
+
case 'rocket_purge_sucuri':
129
+
case 'rocket_rollback':
130
+
case 'rocket_export':
131
+
case 'rocket_generate_critical_css':
132
+
case 'rocket_purge_rocketcdn':
133
+
case 'rocket_clean_saas':
134
+
case 'rocket_clean_performance_hints':
135
+
case 'rocket_rocket_insights_add_homepage':
136
+
$referer = '';
137
+
138
+
if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
139
+
$referer = filter_var( wp_unslash( $_SERVER['REQUEST_URI'] ), FILTER_SANITIZE_URL );
140
+
$referer = '&_wp_http_referer=' . rawurlencode( remove_query_arg( 'fl_builder', $referer ) );
141
+
}
142
+
143
+
$url = admin_url( 'admin-post.php?action=' . $action );
144
+
145
+
$url .= $referer;
146
+
147
+
if ( ! empty( $args['parameters'] ) ) {
148
+
$url = add_query_arg( $args['parameters'], $url );
149
+
}
150
+
151
+
if ( 'purge_cache' === $action ) {
152
+
$action .= '_all';
153
+
}
154
+
155
+
$args['url'] = wp_nonce_url( $url, $action );
156
+
break;
157
+
case 'documentation':
158
+
$args['url'] = get_rocket_documentation_url();
159
+
break;
160
+
}
161
+
162
+
echo $this->generate( 'buttons/link', $args ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
163
+
}
164
+
165
+
/**
166
+
* Displays or returns a partial template with provided data.
167
+
*
168
+
* @since 3.20
169
+
*
170
+
* @param string $part Partial template name (relative to 'partials/').
171
+
* @param mixed $data Data to pass to the template.
172
+
* @param bool $return_template Optional. Whether to return the template as a string instead of echoing it. Default false.
173
+
*
174
+
* @return void|string Returns the template string if $return_template is true, otherwise echoes the template.
175
+
*/
176
+
public function render_parts_with_data( string $part, $data, $return_template = false ) {
177
+
$template = $this->generate( 'partials/' . $part, $data );
178
+
179
+
if ( $return_template ) {
180
+
return $template;
181
+
}
182
+
183
+
echo $template; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Dynamic content is properly escaped in the view.
184
+
}
185
+
}
186
+