PluginProbe
SEO Redirection Plugin – 301 Redirect Manager / 9.8
SEO Redirection Plugin – 301 Redirect Manager v9.8
9.19 trunk 4.17 7.1 7.2 7.3 7.4 7.5 7.6 7.7 7.8 7.9 8.1 8.2 8.3 8.4 8.5 8.6 8.7 8.8 8.9 9.1 9.10 9.11 9.12 All 39 releases
seo-redirection / common / util.php

util.php in SEO Redirection Plugin – 301 Redirect Manager 9.8, at common/util.php

639 lines 14.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Author: Fakhri Alsadi
4 Date: 16-7-2010
5 Contact: www.clogica.com info@clogica.com mobile: +972599322252
6 */
7
8 if(!class_exists('clogica_util_1')){
9 class clogica_util_1{
10
11 private $slug;
12 private $plugin_file;
13 private $plugin_path;
14 private $plugin_url;
15
16 private $option_group_name='clogica_option_group';
17 private $plugin_folder='plugin_folder_name';
18
19
20
21 public function init ($option_gruop='clogica_option_group',$plugin_file='')
22 {
23 $this->set_option_gruop($option_gruop);
24 $this->set_plugin_folder(basename(dirname($plugin_file)));
25 $this->plugin_file = $plugin_file;
26 $this->slug = basename($plugin_file);
27 $this->plugin_path = dirname($plugin_file) . '/';
28 $this->plugin_url =plugin_dir_url($plugin_file);
29
30 }
31 public function get($key,$type='text')
32 {
33
34 if(array_key_exists($key,$_GET))
35 {
36 $unsafe_val=$_GET[$key];
37 return $this->sanitize_req($unsafe_val,$type);
38 }
39 else
40 {
41 return '';
42 }
43 }
44
45 //----------------------------------------------------
46
47 public function post($key,$type='text')
48 {
49 if(array_key_exists($key,$_POST))
50 {
51 $unsafe_val=$_POST[$key];
52 return $this->sanitize_req($unsafe_val,$type);
53 }
54 else
55 {
56 return '';
57 }
58 }
59
60
61 //----------------------------------------------------
62
63 public function sanitize_req($unsafe_val,$type='text')
64 {
65 switch ($type) {
66 case 'text':
67 return htmlspecialchars($unsafe_val, ENT_QUOTES, 'UTF-8', false);
68 break;
69
70 case 'int': return intval($unsafe_val);
71 break;
72
73 case 'email': return filter_var($unsafe_val, FILTER_SANITIZE_EMAIL);//sanitize_email($unsafe_val);
74 break;
75
76 case 'filename': return sanitize_file_name($unsafe_val);
77 break;
78
79 case 'title':
80 return htmlspecialchars($unsafe_val, ENT_QUOTES, 'UTF-8', false);
81 break;
82
83 case 'url' : return filter_var($unsafe_val, FILTER_SANITIZE_SPECIAL_CHARS);//sanitize_title($unsafe_val);
84 break;
85
86 default:
87 return htmlspecialchars($unsafe_val, ENT_QUOTES, 'UTF-8', false);
88
89
90 // filter_var($var, FILTER_SANITIZE_URL)
91 // FILTER_SANITIZE_STRING
92 // FILTER_SANITIZE_EMAIL
93 // FILTER_SANITIZE_NUMBER_INT
94
95 }
96 }
97
98 //----------------------------------------------------
99
100 public function get_ref()
101 {
102 if(array_key_exists('HTTP_REFERER',$_SERVER))
103 {
104 return $this->sanitize_req(strip_tags($_SERVER['HTTP_REFERER']),"url");
105 }
106 else
107 {
108 return '';
109 }
110 }
111
112 //----------------------------------------------------
113
114 public function set_option_gruop($option_group_name)
115 {
116 $this->option_group_name=$option_group_name;
117 }
118
119 //----------------------------------------------------
120
121 public function get_option_gruop()
122 {
123 return $this->option_group_name;
124 }
125
126 //----------------------------------------------------
127
128 public function set_plugin_folder($folder)
129 {
130 $this->plugin_folder=$folder;
131 }
132
133
134 //----------------------------------------------------
135
136 public function get_plugin_folder()
137 {
138 return $this->plugin_folder;
139 }
140
141 //----------------------------------------------------
142
143
144 public function update_my_options($options)
145 {
146 update_option($this->get_option_gruop(),$options);
147 }
148
149 //----------------------------------------------------
150
151 public function get_my_options()
152 {
153 $options=get_option($this->get_option_gruop());
154 if(!is_array($options))
155 {
156 add_option($this->get_option_gruop());
157 $options= array();
158 }
159 return $options;
160 }
161
162 //---------------------------------------------------
163
164 public function get_option_value($key)
165 {
166 $options=$this->get_my_options();
167 if(array_key_exists($key,$options))
168 {
169 return $options[$key];
170 }else
171 {
172 return '';
173 }
174 }
175 //----------------------------------------------------
176
177 public function update_option($key,$value)
178 {
179 $options=$this->get_my_options();
180 $options[$key]=$value;
181 $this->update_my_options($options);
182 }
183
184 //----------------------------------------------------
185
186 public function update_post_option($key)
187 {
188 $options=$this->get_my_options();
189 $options[$key]=intval($this->post($key));
190 $this->update_my_options($options);
191 }
192
193
194 //----------------------------------------------------
195
196
197 public function delete_my_options()
198 {
199 delete_option($this->get_option_gruop());
200 }
201
202
203
204 /* get_current_URL ---------------------------------------------- */
205 public function get_current_URL()
206 {
207 $pageURL = 'http';
208 if ( array_key_exists("HTTPS",$_SERVER) && $_SERVER["HTTPS"] == "on")
209 {
210 $pageURL .= "s";
211 }
212 $pageURL .= "://";
213
214
215
216
217 $pageURL .= ($_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"]);
218 return $this->sanitize_req($pageURL,"url");
219 }
220
221 //-----------------------------------------------------
222
223 public function remove_url_http_www($url)
224 {
225 $url = str_ireplace("http://www.",'',$url);
226 $url = str_ireplace("https://www.",'',$url);
227 $url = str_ireplace("http://",'',$url);
228 $url = str_ireplace("https://",'',$url);
229 return ($url);
230 }
231 //-----------------------------------------------------
232 public function make_relative_url($url)
233 {
234
235 if($url=="")
236 {
237 return "";
238 }
239 $site_url = $this->remove_url_http_www(site_url());
240
241 if(stripos($url,$site_url) !==false)
242 {
243 $url_no_www = $this->remove_url_http_www($url);
244 if(strtolower(substr($url_no_www,0,strlen($site_url))) == strtolower($site_url))
245 {
246 $url = str_ireplace($site_url,'',$url_no_www);
247 }
248 }
249 if($url=="")
250 {
251 $url="/";
252 }
253 return esc_url_raw($url);
254 }
255
256 //----------------------------------------------------
257 public function make_absolute_url($url)
258 {
259 if(substr($url,0,1)=='/')
260 {
261 $url = site_url() . $url;
262 }
263 return esc_url_raw($url);
264 }
265
266 //----------------------------------------------------
267
268 public function get_current_relative_url()
269 {
270 return $this->make_relative_url($this->get_current_URL());
271 }
272 //----------------------------------------------------
273 public function is_valid_url($url)
274 {
275 if(stripos($url,'://')!== false || substr($url,0, 1)=='/')
276 {
277 return true;
278 }else{
279 return false;
280 }
281 }
282 //----------------------------------------------------
283
284 public function WPSR_get_current_parameters($remove_parameter="")
285 {
286
287 if($_SERVER['QUERY_STRING']!='')
288 {
289 $qry = '?' . urldecode(sanitize_text_field($_SERVER['QUERY_STRING']));
290
291 if(is_array($remove_parameter))
292 {
293 for($i=0;$i<count($remove_parameter);$i++)
294 {
295 if(array_key_exists($remove_parameter[$i],$_GET)){
296 $string_remove = '&' . $remove_parameter[$i] . "=" . $this->get($remove_parameter[$i]);
297 $qry=str_replace($string_remove,"",$qry);
298 $string_remove = '?' . $remove_parameter[$i] . "=" . $this->get($remove_parameter[$i]);
299 $qry=str_replace($string_remove,"",$qry);
300 }
301 }
302
303 }else{
304 if($remove_parameter!='')
305 {
306 if(array_key_exists($remove_parameter,$_GET)){
307 $string_remove = '&' . $remove_parameter . "=" . $this->get($remove_parameter);
308 $qry=str_replace($string_remove,"",$qry);
309 $string_remove = '?' . $remove_parameter . "=" . $this->get($remove_parameter);
310 $qry=str_replace($string_remove,"",$qry);
311 }
312 }
313 }
314
315 return strip_tags($this->sanitize_req($qry,"url"));
316 }else
317 {
318 return "";
319 }
320 }
321
322
323 //---------------------------------------------------------------
324
325 public function get_plugin_path($folder='')
326 {
327 return WP_PLUGIN_DIR . '/' . $this->get_plugin_folder() . '/' . $folder;
328 }
329
330 /* get_plugin_path ---------------------------------------------
331 public function get_plugin_path()
332 {
333 return $this->plugin_path;
334 }*/
335
336 /* get plugin slug -------------------------------------------- */
337 public function get_plugin_slug()
338 {
339 return $this->slug;
340 }
341
342 /* get plugin slug -------------------------------------------- */
343 public function get_plugin_file()
344 {
345 return $this->plugin_file;
346 }
347 //-----------------------------------------------------
348
349
350 public function get_plugin_url($url='')
351 {
352 return $this->plugin_url;
353 }
354
355
356 //----------------------------------------------------
357
358 public function get_visitor_IP()
359 {
360 $ipaddress = sanitize_text_field($_SERVER['REMOTE_ADDR']);
361
362 if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
363 $ipaddress = sanitize_text_field($_SERVER['HTTP_CLIENT_IP']);
364 } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
365 $ipaddress = sanitize_text_field($_SERVER['HTTP_X_FORWARDED_FOR']);
366 }
367
368 return sanitize_text_field($ipaddress) ;
369 }
370
371 //----------------------------------------------------
372
373
374 public function get_visitor_OS()
375 {
376
377 $userAgent= sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
378 $oses = array (
379 'iPhone' => '(iPhone)',
380 'Windows 3.11' => 'Win16',
381 'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',
382 'Windows 98' => '(Windows 98)|(Win98)',
383 'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
384 'Windows XP' => '(Windows NT 5.1)|(Windows XP)',
385 'Windows 2003' => '(Windows NT 5.2)',
386 'Windows Vista' => '(Windows NT 6.0)|(Windows Vista)',
387 'Windows 7' => '(Windows NT 6.1)|(Windows 7)',
388 'Windows 8' => '(Windows NT 6.2)|(Windows 8)',
389 'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
390 'Windows ME' => 'Windows ME',
391 'Open BSD'=>'OpenBSD',
392 'Sun OS'=>'SunOS',
393 //'Linux'=>'(Linux)|(X11)', to detect if android or not
394 'Safari' => '(Safari)',
395 'Macintosh'=>'(Mac_PowerPC)|(Macintosh)',
396 'QNX'=>'QNX',
397 'BeOS'=>'BeOS',
398 'OS/2'=>'OS\/2',
399 'SearchBot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp\/cat)|(msnbot)|(ia_archiver)'
400 );
401
402 foreach($oses as $os=>$pattern){
403
404 if(preg_match('/'.$pattern. '/i', $userAgent)) {
405 return $os;
406 }
407 }
408
409 // more tests
410
411 $ua = strtolower($userAgent);
412
413 if(stripos($ua,'android') !== false) {
414 return 'Android';
415 }
416
417 if(stripos($ua,'iphone') !== false) {
418 return 'iOS';
419 }
420
421
422 if(stripos($ua,'ipad') !== false) {
423 return 'iOS';
424 }
425
426 if(stripos($ua,'ipod') !== false) {
427 return 'iOS';
428 }
429
430 if(stripos($ua,'windows') !== false) {
431 return 'Windows';
432 }
433
434
435 if(stripos($ua,'linux') !== false) {
436 return 'Linux';
437 }
438
439
440 if(stripos($ua,'googlebot') !== false) {
441 return 'Googlebot';
442 }
443
444 if(stripos($ua,'bot') !== false) {
445 return 'SearchBot';
446 }
447
448
449 return 'Unknown';
450 }
451
452 //-----------------------------------------------------------------
453
454 public function get_visitor_Browser()
455 {
456
457 $u_agent= sanitize_text_field($_SERVER['HTTP_USER_AGENT']);
458 $bname = 'Unknown';
459
460 if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
461 {
462 $bname = 'Internet Explorer';
463 }
464 elseif(preg_match('/Firefox/i',$u_agent))
465 {
466 $bname = 'Firefox';
467 }
468 elseif(preg_match('/Chrome/i',$u_agent))
469 {
470 $bname = 'Chrome';
471 }
472 elseif(preg_match('/Safari/i',$u_agent))
473 {
474 $bname = 'Safari';
475 }
476 elseif(preg_match('/Opera/i',$u_agent))
477 {
478 $bname = 'Opera';
479 }
480 elseif(preg_match('/Netscape/i',$u_agent))
481 {
482 $bname = 'Netscape';
483 }
484 elseif(preg_match('/googlebot/i',$u_agent))
485 {
486 $bname = 'GoogleBot';
487 }
488 elseif(preg_match('/bot/i',$u_agent))
489 {
490 $bname = 'SearchBot';
491 }
492
493
494 return sanitize_text_field($bname);
495
496 }
497
498
499 //----------------------------------------------------
500
501 public function option_msg($msg,$out='echo')
502 {
503
504 if($out=='echo')
505 echo '<div id="message" class="updated"><p>' . esc_html($msg) . '</p></div>';
506 elseif($out=='push')
507 $this->push_msg(esc_html($msg));
508 }
509
510 //----------------------------------------------------
511
512
513 public function info_option_msg($msg,$out='echo')
514 {
515
516
517 if($out=='echo')
518 echo '<div id="message" class="updated"><p><div class="info_icon"></div> ' . esc_html($msg) . '</p></div>';
519 elseif($out=='push')
520 $this->push_msg(esc_html($msg));
521
522
523 }
524
525 //----------------------------------------------------
526
527
528 public function warning_option_msg($msg,$out='echo')
529 {
530
531 if($out=='echo')
532 echo '<div id="message" class="error"><p><div class="warning_icon"></div> ' . esc_html($msg) . '</p></div>';
533 elseif($out=='push')
534 $this->push_msg(esc_html($msg));
535
536
537 }
538
539 //----------------------------------------------------
540
541 public function success_option_msg($msg,$out='echo')
542 {
543
544 if($out=='echo')
545 echo '<div id="message" class="updated"><p><div class="success_icon"></div> ' . esc_html($msg) . '</p></div>';
546 elseif($out=='push')
547 $this->push_msg(esc_html($msg));
548 }
549
550 //----------------------------------------------------
551
552 public function failure_option_msg($msg,$out='echo')
553 {
554
555 if($out=='echo')
556 echo '<div id="message" class="error"><p><div class="failure_icon"></div> ' . esc_html($msg) . '</p></div>';
557 elseif($out=='push')
558 $this->push_msg(esc_html($msg));
559
560 }
561
562 //----------------------------------------------------
563
564 private function push_msg($msg)
565 {
566 global $utilpro;
567 $msgs=$utilpro->get_option_value('admin_notices');
568 if(is_array($msgs))
569 {
570 $msgs[count($msgs)]=$msg;
571
572 }else
573 {
574 $msgs = array();
575 $msgs[0]=$msg;
576 }
577
578 $utilpro->update_option('admin_notices',$msgs);
579
580 }
581
582 //----------------------------------------------------
583
584
585 public function there_is_cache()
586 {
587
588 $plugins=get_option( 'active_plugins' );
589
590 for($i=0;$i<count($plugins);$i++)
591 {
592 if ( array_key_exists($i, $plugins) && stripos($plugins[$i],'cache')!==false)
593 {
594 return $plugins[$i];
595 }
596 }
597
598
599 return '';
600 }
601
602 //----------------------------------------------------
603
604
605 public function there_is_plugin($plugin)
606 {
607
608 $plugins=get_option( 'active_plugins' );
609
610 for($i=0;$i<count($plugins);$i++)
611 {
612 $phpfile = substr( $plugins[$i], strrpos( $plugins[$i], '/' )+1 );
613 $phpfile = explode(".", $phpfile);
614 $plugin_name = $phpfile[0];
615 if ($plugin_name==$plugin)
616 {
617 return true;
618 }
619 }
620
621
622 return false;
623 }
624
625 //---------------------------------------------------------------
626
627 public function regex_prepare($string)
628 {
629
630 $from= array('.', '+', '*', '?','[','^',']','$','(',')','{','}','=','!','<','>','|',':','-',')','/', '\\');
631 $to= array('\\.', '\\+', '\\*', '\\?','\\[','\\^','\\]','\\$','\\(','\\)','\\{','\\}','\\=','\\!','\\<','\\>','\\|','\\:','\\-','\\)','\\/','\\\\');
632 return str_replace($from,$to,$string);
633
634 }
635
636
637 }}
638
639 ?>