PluginProbe
RabbitLoader / 2.17.6
RabbitLoader v2.17.6
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.17.6, at inc/tab_settings.php

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