PluginProbe
SEO Redirection Plugin – 301 Redirect Manager / 8.4
SEO Redirection Plugin – 301 Redirect Manager v8.4
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 8.4, at common/util.php

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