PluginProbe
RabbitLoader / 2.18.2
RabbitLoader v2.18.2
4.0.2 4.0.1 4.0 3.2.0 3.1.1 3.1.0 3.0.5 3.0.3 3.0.4 2.17.1 2.17.2 2.17.3 2.17.4 2.17.5 2.17.6 2.17.7 2.18.0 2.18.1 2.18.2 2.18.3 2.18.4 2.18.5 2.18.6 2.18.7 2.18.8 All 129 releases
rabbit-loader / inc / tab_settings.php

tab_settings.php in RabbitLoader 2.18.2, at inc/tab_settings.php

370 lines 19.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if(class_exists('RabbitLoader_21_Tab_Settings')){
4 #it seems we have a conflict
5 return;
6 }
7
8 class RabbitLoader_21_Tab_Settings extends RabbitLoader_21_Tab_Init{
9
10 public static function init(){
11 }
12
13 public static function echoMainContent(){
14
15 $isConnected = self::isPluginActivated();
16
17 $rlaction = RabbitLoader_21_Util_Core::get_param('rlaction');
18 $page = RabbitLoader_21_Util_Core::get_param('page');
19 $tab = RabbitLoader_21_Util_Core::get_param('tab');
20
21 $urlparts = parse_url(home_url());
22 $domain = $urlparts['scheme'].'://'.$urlparts['host'];
23 if(!empty($urlparts['port'])){
24 $domain.=':'.$urlparts['port'];
25 }
26
27 if(strcmp($rlaction, 'disconnect')===0){
28 RabbitLoader_21_Core::update_auth_keys('', '', 'user action disconnect');
29 RabbitLoader_21_Core::update_api_tokens('', '', '', '', 'user action disconnect');
30 $isConnected = false;
31 $url_connect = add_query_arg(array('tab'=>$tab,'page'=>$page, 'rlaction'=>false));
32 echo '<script>window.location="'.$url_connect.'";</script>';
33 return;
34 }else if(strcmp($rlaction,'savekeys')===0){
35 $connected = false;
36
37 $apikey = RabbitLoader_21_Util_Core::get_param('apikey', true);
38 if(!empty($apikey)){
39 RabbitLoader_21_Core::update_auth_keys($apikey, $urlparts['host'], '');
40 $connected = true;
41 }
42
43 $tokens = RabbitLoader_21_Util_Core::get_param('token', true);
44 $tokens = base64_decode($tokens);
45 if($tokens){
46 $tokens = json_decode($tokens, true);
47 if(!empty($tokens['api_token']) && !empty($tokens['push_key'])){
48 RabbitLoader_21_Core::update_api_tokens($tokens['api_token'], $tokens['push_key'], $urlparts['host'], $tokens['did'], '');
49 $connected = true;
50 }
51 if(isset($tokens['cdn_prefix'])){
52 update_option('rabbitloader_cdn_prefix', $tokens['cdn_prefix'], true);
53 }
54 }
55
56 if($connected){
57 $url_connect = add_query_arg(array('tab'=>'home','page'=>$page, 'rlaction'=>false, 'apikey'=>false, 'apisecret'=>false, 'token'=>false));
58 do_action('rl_site_connected');
59 echo '<script>window.location="'.$url_connect.'";</script>';
60 }
61 }
62 if($isConnected){
63 $url_disconnect = add_query_arg(array('tab'=>$tab,'page'=>$page, 'rlaction'=>'disconnect'), null);
64 ?>
65 <div class="" style="max-width: 1160px; margin:40px auto;">
66 <?php
67 self::show_cf_box();
68 self::general();
69 self::excludeUrls();
70 self::ignoreParams();
71 self::echoConnectedBox($url_disconnect);
72 self::advanceSettings();
73 ?>
74 </div>
75 <?php
76 }else{
77
78 $url_redirect = $domain.add_query_arg(array('tab'=>$tab,'page'=>$page, 'rlaction'=>'savekeys'));
79
80 $url_oauth = RabbitLoader_21_Core::getRLDomain()."account/?source=wp-plugin&action=connect&site_url=".urlencode(site_url())."&redirect_url=".urlencode($url_redirect).'&cms_v='.get_bloginfo( 'version').'&plugin_v='.RABBITLOADER_PLUG_VERSION;
81
82 ?>
83 <style>
84 @import url("https://fonts.googleapis.com/css2?family=Inter:wght@100;200;300;400;500;600;700;800;900&display=swap");
85 </style>
86 <div class="div-connect-parent">
87 <div class="rl-content-area border-bottom">
88 <img src="https://rabbitloader.com/assets/img/core-img/logo-dark.png?v=210327" />
89 </div>
90 <div class="rl-content-area border-bottom">
91 <h4>Get 100/100 PageSpeed</h4>
92 <p>on Google PageSpeed Insight</p>
93
94 <?php
95 $conflictPluginMessages = RabbitLoader_21_Conflicts::getMessages();
96 if(empty($conflictPluginMessages)){
97 echo '<a href="'.$url_oauth.'" class="rl-btn rl-btn-primary my-4">Activate RabbitLoader</a>';
98 }else{
99 foreach ($conflictPluginMessages as $plugMessage) {
100 echo '<div class="alert alert-danger" role="alert">';
101 _e($plugMessage, RABBITLOADER_TEXT_DOMAIN);
102 echo '</div>';
103 }
104
105 echo '<div class="my-4">';
106 _e('The above warning(s) need to be fixed before activating RabbitLoader.');
107 echo '</div>';
108 }
109 ?>
110
111 </div>
112 <div class="rl-content-area footer-area">
113 <div class="footer-nav">
114 <ul class="d-flex my-2">
115 <li><a href="https://rabbitloader.com/" target="_blank">All Features</a></li>
116 <li><a href="https://rabbitloader.com/terms/" target="_blank">Terms &amp; Conditions</a></li>
117 <li><a href="mailto:support@rabbitloader.com" target="_blank">Get Support</a></li>
118 </ul>
119 </div>
120 </div>
121 </div>
122 <?php } ?>
123 <?php
124 }
125
126 private static function echoConnectedBox($disconnect_url){
127 ?>
128 <div class="row mb-4">
129 <div class="col">
130 <div class="bg-white rounded p-4">
131 <div class="row">
132
133 <div class="col-8 text-secondary">
134 <h5 class="mt-0">Connected</h5>
135 <span>Your website is connected with RabbitLoader service.</span>
136
137 <div class="mt-4">
138 <a type="button" class="btn btn-outline-danger" href="<?php echo $disconnect_url;?>">Disconnect from RabbitLoader</a>
139 </div>
140 </div>
141
142 <div class="col-4 text-center">
143 <img src="<?php echo RABBITLOADER_PLUG_URL;?>/assets/checked-2.png" class="img-fluid" style="max-height:150px;" />
144 </div>
145
146 </div>
147 </div>
148 </div>
149 </div>
150 <?php
151 }
152
153 private static function general(){
154 //introduced@2.14.0
155 RabbitLoader_21_Core::getWpUserOption($user_options);
156 if(isset($_POST['form_name']) && strcmp($_POST['form_name'], 'general_settings')==0){
157 $user_options['purge_on_change'] = !empty($_POST['chk_purge_on_change']);
158 $user_options['private_mode_val'] = !empty($_POST['chk_private_mode']);
159 RabbitLoader_21_Core::updateUserOption($user_options);
160 }
161 $purge_on_change = !empty($user_options['purge_on_change']);
162 $private_mode_val = !empty($user_options['private_mode_val']);
163 ?>
164 <div class="row mb-4">
165 <div class="col">
166 <div class="bg-white rounded p-4">
167 <div class="row">
168 <div class="col-sm-12 col-md-12 text-secondary">
169 <h5 class="mt-0">General Settings</h5>
170 <span></span>
171 <div class="mt-4">
172 <form method="post">
173 <input type="hidden" name="form_name" value="general_settings" />
174 <div class="form-check">
175 <input class="form-check-input" type="checkbox" value="1" id="chk_purge_on_change" name="chk_purge_on_change" style="margin-top: 0.25em; vertical-align: top;" <?php echo $purge_on_change?' checked="checked" ':'';?> >
176 <label class="form-check-label" for="chk_purge_on_change">
177 <?php RabbitLoader_21_Util_WP::_e('Instant content change is crucial for my visitors (default: off)');?>
178 </label>
179 <span class="dashicons dashicons-info-outline text-secondary tpopup" title="Click to know more" title-html="<div style='text-align:left'><h4>Cache replace behavior when content is modified</h4><br><b>If on:</b> When you update a page or post content, the current cache will be wiped out and the pages would be optimized again. This is useful for sites where content freshness is crucial over the speed performance. This can cause an intermittent low PageSpeed score.<br><b>If off</b>: When you update a page or post content, the system will keep serving the visitors from currently cached content but start updating the cache gradually with the fresh content. This is recommended for most users.<br><a href='https://rabbitloader.com/kb/purging-cache-wordpress-plugin/' target='_blank'>read more</a></div>" style="font-size: 16px; line-height: 28px;"></span>
180
181 <?php
182 if($purge_on_change){
183 echo '<span class="text-danger d-block mb-2" style="font-size: 0.75rem;">';
184 RabbitLoader_21_Util_WP::_e('You may see fluctuations in SpeedScore because the above checkbox is on.');
185 echo ' <a href="https://rabbitloader.com/kb/fluctuations-in-pagespeed-performance-score/" target="_blank" title="Click to know more about this.">Know Why.</a></span>';
186 echo '<div class="notice notice-error"><p><b>';
187 RabbitLoader_21_Util_WP::_e('Warning'); echo ': </b> ';
188 RabbitLoader_21_Util_WP::_e('You may see fluctuations in SpeedScore because the "Instant content change" checkbox is on.'); echo '</p></div>';
189 }
190 ?>
191 </div>
192 <div class="form-check">
193 <input class="form-check-input" type="checkbox" value="1" id="chk_private_mode" name="chk_private_mode" style="margin-top: 0.25em; vertical-align: top;" <?php echo $private_mode_val?' checked="checked" ':'';?> >
194 <label class="form-check-label" for="chk_private_mode">
195 <?php RabbitLoader_21_Util_WP::_e('Turn on \'Me\' mode to do testing or resolving conflicts (default: off)'); ?>
196 </label>
197 <span class="dashicons dashicons-info-outline text-secondary tpopup" title="Click to know more about Me mode" title-html="<div style='text-align:left'><h4>'Me' Mode</h4><br><b>If on:</b> Me mode is for testing and debugging. Only you can see the RabbitLoader optimized pages by appending '?rltest=1' to URLs. Regular visitors will continue to see the original webpages without any affect of RabbitLoader. Keep this on if you are facing any compatibility issues likely due to RabbitLoader.<br><br><b>If off</b>: All public pages will be served with RabbitLoader optimization on. This is recommended for most users.</div>" style="font-size: 16px; line-height: 28px;"></span>
198 </div>
199
200 <button type="submit" class="btn btn-primary mt-2">Save</a>
201 </form>
202 </div>
203 </div>
204 </div>
205 </div>
206 </div>
207 </div>
208 <?php
209 }
210
211 private static function excludeUrls(){
212 //depreciated@2.14.0
213 RabbitLoader_21_Core::getWpOption($rl_wp_options);
214 if(empty($rl_wp_options['exclude_patterns'])){
215 $rl_wp_options['exclude_patterns'] = '';
216 }
217 $exclude_patterns = $rl_wp_options['exclude_patterns'];
218
219 //introduced@2.14.0
220 RabbitLoader_21_Core::getWpUserOption($user_options);
221 $shouldMigrate = !empty($exclude_patterns) && empty($user_options['exclude_patterns']);
222 $userUpdating = isset($_POST['exclude_patterns']);
223 if($userUpdating || $shouldMigrate){
224 if($userUpdating){
225 $user_options['exclude_patterns'] = sanitize_textarea_field($_POST['exclude_patterns']);
226 RabbitLoader_21_Admin::onPostChange('all', 'EX_PATTERN_CHANGE');
227 }else{
228 $user_options['exclude_patterns'] = $exclude_patterns;
229 }
230 RabbitLoader_21_Core::updateUserOption($user_options);
231 }
232 $exclude_patterns = $user_options['exclude_patterns'];
233
234 ?>
235 <div class="row mb-4">
236 <div class="col">
237 <div class="bg-white rounded p-4">
238 <div class="row">
239 <div class="col-sm-12 col-md-8 text-secondary">
240 <h5 class="mt-0">Exclude URLs</h5>
241 <span>Any URL matching the below patterns will be skipped from RabbitLoader optimization-</span>
242 <div class="mt-4">
243 <form method="post">
244 <textarea class="form-control" rows="5" placeholder="e.g. /path/* without domain name" name="exclude_patterns"><?php echo $exclude_patterns;?></textarea>
245 <button type="submit" class="btn btn-primary mt-2">Save</a>
246 </form>
247 </div>
248 </div>
249 <div class="col-sm-12 col-md-4">
250 <h5 class="mt-0">Guidelines</h5>
251 <ul class="" style="list-style:circle;">
252 <li>If the request URL matches the given <b>shell wildcard pattern</b>, it will not be optimized.</li>
253 <li>You can put one pattern per line</li>
254 <li>A wildcard character (*) can be used in the pattern. For example, /category/* will exclude all URLs starting with /category/.</li>
255 <li><a target="_blank" href="https://rabbitloader.com/kb/exclude-urls-from-cached/" title="Excluding URLs from being cached">Read documentation</a>
256 </ul>
257 </div>
258 </div>
259 </div>
260 </div>
261 </div>
262 <?php
263 }
264
265 private static function ignoreParams(){
266 //depreciated@2.14.0
267 RabbitLoader_21_Core::getWpOption($rl_wp_options);
268 if(empty($rl_wp_options['ignore_params'])){
269 $rl_wp_options['ignore_params'] = '';
270 }
271 $ignore_params = $rl_wp_options['ignore_params'];
272
273 //introduced@2.14.0
274 RabbitLoader_21_Core::getWpUserOption($user_options);
275 $shouldMigrate = !empty($ignore_params) && empty($user_options['ignore_params']);
276 $userUpdating = isset($_POST['ignore_params']);
277 if($userUpdating || $shouldMigrate){
278 if($userUpdating){
279 $user_options['ignore_params'] = sanitize_textarea_field($_POST['ignore_params']);
280 }else{
281 $user_options['ignore_params'] = $ignore_params;
282 }
283 RabbitLoader_21_Core::updateUserOption($user_options);
284 }
285 $ignore_params = $user_options['ignore_params'];
286 ?>
287 <div class="row mb-4">
288 <div class="col">
289 <div class="bg-white rounded p-4">
290 <div class="row">
291 <div class="col-sm-12 col-md-8 text-secondary">
292 <h5 class="mt-0">Ignore Parameters</h5>
293 <span>Query/GET parameters mentioned below will be ignored when creating cached copy of a page -</span>
294 <div class="mt-4">
295 <form method="post">
296 <textarea class="form-control" rows="5" placeholder="e.g. fbclid" name="ignore_params"><?php echo $ignore_params;?></textarea>
297 <button type="submit" class="btn btn-primary mt-2">Save</a>
298 </form>
299 </div>
300 </div>
301 <div class="col-sm-12 col-md-4">
302 <h5 class="mt-0">Guidelines</h5>
303 <ul class="" style="list-style:circle;">
304 <li>You can put one parameter per line.</li>
305 <li>Parameter name should be without any special characters such as &amp;, ?or =.</li>
306 <li>Regex or shell wildcard pattern can not be used here.</li>
307 <li>Many popular params are ignored by default, <a target="_blank" href="https://rabbitloader.com/kb/ignori-url-parameters-caching/" title="Ignoring URL parameters from caching key">read documentation</a>
308 </ul>
309 </div>
310 </div>
311 </div>
312 </div>
313 </div>
314 <?php
315 }
316
317 private static function advanceSettings(){
318 ?>
319 <div class="row">
320 <div class="col">
321 <p>Advance reports and more controls are available on your RabbitLoader account portal.</p>
322 </div>
323 </div>
324 <div class="row">
325 <?php
326 $links = ['rules'=>'Manage Page Rules', 'cloudflare'=>'Cloudflare Integration', 'purge'=>'Purge Log'];
327 foreach($links as $hash=>$label){
328 $icon = ' <span class="dashicons dashicons-external mt-1"></span>';
329 $link = ' href="https://rabbitloader.com/account/#'.$hash.'" target="_blank" ';
330
331 echo '
332 <div class="col text-center">
333 <div class=""><a class="rl-dash-buttons btn-lg w-100" '.$link.'>'.$label.$icon.' </a></div>
334 </div>';
335 }
336 ?>
337 </div>
338 <?php
339 }
340
341 private static function show_cf_box(){
342 if(empty($_SERVER['HTTP_CDN_LOOP']) || $_SERVER['HTTP_CDN_LOOP']!='cloudflare'){
343 return;
344 }
345 ?>
346 <div class="row mb-4">
347 <div class="col">
348 <div class="bg-white rounded p-4">
349 <div class="row">
350 <div class="col-8 text-secondary">
351 <h5 class="mt-0"><?php RabbitLoader_21_Util_WP::_e('Using Cloudflare?');?></h5>
352 <span><?php RabbitLoader_21_Util_WP::_e('If you are using Cloudflare, there are a few settings required in order to avoid conflicts and get the best performance.');?></span>
353
354 <div class="mt-5">
355 <a target="_blank" class="btn btn-primary" href="https://rabbitloader.com/kb/cloudflare-settings-for-best-performance/" ><?php RabbitLoader_21_Util_WP::_e('Show recommended settings');?></a>
356 </div>
357
358 </div>
359 <div class="col-4 text-center">
360 <img src="<?php echo RABBITLOADER_PLUG_URL;?>/assets/help.jpg" class="img-fluid" style="max-height:170px;"/>
361 </div>
362 </div>
363 </div>
364 </div>
365 </div>
366 <?php
367 }
368 }
369
370 ?>