SEO Redirection Plugin - Version 7.6

Version Description

  • Escaping data - part 2
Download this release

Release Info

Developer osamaesh
Plugin Icon 128x128 SEO Redirection Plugin
Version 7.6
Comparing to
See all releases

Code changes from version 7.5 to 7.6

cf/lib/forms/cf.bcheckbox_option.class.php DELETED
@@ -1,250 +0,0 @@
1
- <?php
2
- /*
3
- Author: Fakhri Alsadi
4
- Date: 24-4-2015
5
-
6
- A simple class to create checkbox options
7
- */
8
-
9
- if(!class_exists('bcheckbox_option')){
10
- class bcheckbox_option{
11
-
12
- private $group_name="";
13
- private $list_nodes="";
14
- private $list_selected_nodes = array();
15
- private $style = "default";
16
-
17
- /* set style ------------------------------------------------------------------- */
18
- public function set_style($style)
19
- {
20
- $this->style = $style;
21
- }
22
- /* Get style ------------------------------------------------------------------- */
23
- public function get_style()
24
- {
25
- return $this->style;
26
- }
27
-
28
- /* default style ------------------------------------------------------------------- */
29
- public function set_default_style()
30
- {
31
- $this->set_style("default");
32
- }
33
-
34
- /* default style ------------------------------------------------------------------- */
35
- public function set_primary_style()
36
- {
37
- $this->set_style("primary");
38
- }
39
-
40
-
41
- /* check all css class ------------------------------------------------------------------- */
42
- public function get_check_all_css_class()
43
- {
44
- return 'bcheckbox_check_all';
45
- }
46
-
47
- /* uncheck all css class ------------------------------------------------------------------- */
48
- public function get_uncheck_all_css_class()
49
- {
50
- return 'bcheckbox_unckeck_all';
51
- }
52
-
53
- /* get check uncheck attribute ----------------------------------------------------------*/
54
- public function get_check_uncheck_attribute($group_name)
55
- {
56
- return "data-group=\"$group_name\"";
57
- }
58
-
59
- /* define a group -------------------------------------------------------------------*/
60
- public function set_group($group_name)
61
- {
62
- $this->group_name=$group_name;
63
- }
64
-
65
- /* define a list -------------------------------------------------------------------*/
66
- public function set_list($list_name)
67
- {
68
- $this->set_group($list_name);
69
- $this->list_nodes= array();
70
- }
71
-
72
- /* reset group -------------------------------------------------------------------*/
73
- public function reset_group()
74
- {
75
- $this->group_name="";
76
- }
77
-
78
- /* reset list -------------------------------------------------------------------*/
79
- public function reset_list()
80
- {
81
- $this->reset_group();
82
- $this->list_nodes="";
83
- }
84
-
85
- /* is group -------------------------------------------------------------------*/
86
- public function is_group()
87
- {
88
- return($this->group_name!="");
89
- }
90
-
91
- /* is list -------------------------------------------------------------------*/
92
- public function is_list()
93
- {
94
- return (is_array($this->list_nodes) && $this->is_group());
95
- }
96
-
97
- /* get group name -------------------------------------------------------------------*/
98
- public function get_group_name()
99
- {
100
- return $this->group_name ;
101
- }
102
-
103
- /* get list name -------------------------------------------------------------------*/
104
- public function get_list_name()
105
- {
106
- return $this->get_group_name();
107
- }
108
-
109
- /* add to list ----------------------------------------------------------------*/
110
- public function add_to_list($name, $title)
111
- {
112
- $index= count($this->list_nodes);
113
- $this->list_nodes[$index]['name']= $name;
114
- $this->list_nodes[$index]['title']= $title;
115
- }
116
-
117
- /* Selected items -----------------------------------------------------------------------------*/
118
- public function selected_items($items)
119
- {
120
- if(!is_array($items))
121
- {
122
- $items = explode(",",$items);
123
- }
124
- $this->list_selected_nodes = $items;
125
- }
126
-
127
- /* Create list -------------------------------------------------------------*/
128
- public function create_list_option()
129
- {
130
- if($this->is_list())
131
- {
132
- for($i=0;$i<count($this->list_nodes);$i++)
133
- {
134
- $checked=0;
135
- if(array_search($this->list_nodes[$i]['name'],$this->list_selected_nodes)!==false)
136
- {
137
- $checked=1;
138
- }
139
- echo "<div style=\"margin-top: 3px\">";
140
- $this->create_grouped_option($this->list_nodes[$i]['name'],$checked);
141
-
142
- $list_nodes_title = esc_html($this->list_nodes[$i]['title']);
143
-
144
-
145
- echo " {$list_nodes_title}</div>";
146
- }
147
- }else
148
- {
149
- echo __("You have no lists to create!",'seo-redirection');
150
- }
151
- }
152
-
153
- /* create grouped option ---------------------------------------------------------*/
154
- public function create_grouped_option($value, $checked=0)
155
- {
156
- if($this->is_group())
157
- {
158
- $this->create_option($this->get_group_name(),$value,$checked);
159
- }else
160
- {
161
- echo __("To use this function you must previously used set_group()",'seo-redirection');
162
- }
163
- }
164
-
165
- /* create grouped option ------------------------------------------------------------------ */
166
- public function create_check_all_option($value='bcheckbox_check_unckeck_all', $checked=0)
167
- {
168
- if($this->is_group())
169
- {
170
- $this->create_option($this->get_group_name(),$value,$checked,'bcheckbox_check_unckeck_all');
171
- }else
172
- {
173
- echo __("To use this function you must previously used set_group()",'seo-redirection');
174
- }
175
- }
176
-
177
- /* Create check all button ---------------------------------------------------------------*/
178
- public function create_check_all_button($title="Check All")
179
- {
180
- if($this->is_group())
181
- {
182
- echo "<a {$this->get_check_uncheck_attribute($this->get_group_name())} class=\"btn btn-{$this->get_style()} btn-xs {$this->get_check_all_css_class()}\">
183
- <span class=\"glyphicon glyphicon-check\"></span> $title</a>";
184
- }else
185
- {
186
- echo __("To use this function you must previously used set_group()",'seo-redirection');
187
- }
188
- }
189
-
190
-
191
- /* Create check all button ---------------------------------------------------------------*/
192
- public function create_uncheck_all_button($title="None")
193
- {
194
- if($this->is_group())
195
- {
196
- echo "<a ".esc_js($this->get_check_uncheck_attribute($this->get_group_name()))." class=\"btn btn-".esc_attr($this->get_style())." btn-xs ".esc_attr($this->get_uncheck_all_css_class())."\">
197
- <span class=\"glyphicon glyphicon-unchecked\"></span> $title</a>";
198
- }else
199
- {
200
- echo __("To use this function you must previously used set_group()",'seo-redirection');
201
- }
202
- }
203
-
204
-
205
- /* Create single check box ------------------------------------------------------------------*/
206
- public function create_single_option($name,$checked=0)
207
- {
208
- if($checked!=0)
209
- {
210
- $checked=1;
211
- }
212
- $this->create_option($name,1,$checked);
213
- }
214
-
215
- /* Create Check Option -------------------------------------------------------------------*/
216
- private function create_option($name, $value, $checked=0, $type='')
217
- {
218
- $check_html = "";
219
- $check_class ="";
220
- $brackets="";
221
- $data_group="";
222
- $id=$name;
223
- if($this->is_group())
224
- {
225
- $data_group="data-group=\"{$name}\"";
226
- $brackets="[]";
227
- $id= $name . '_' . str_replace(' ','',$value);
228
- }
229
- if($type!='')
230
- {
231
- $brackets= "_" . $type;
232
- $name= $name . "_" . $type;
233
- }
234
- if($checked==1)
235
- {
236
- $check_html = "checked=\"checked\"";
237
- $check_class = "active";
238
- }
239
- echo "<div data-toggle=\"buttons\" {$data_group} data-id=\"{$id}\" class=\"btn-group bcheckbox $type\">
240
- <label class=\"btn btn-{$this->get_style()} btn-xs {$check_class} {$name}\" id=\"{$id}_label\" >
241
- <input type=\"checkbox\" autocomplete=\"off\" value=\"{$value}\" id=\"{$id}\" name=\"{$name}{$brackets}\" $check_html>
242
- <span class=\"glyphicon glyphicon-ok\"></span>
243
- </label>
244
- </div>";
245
- }
246
-
247
-
248
-
249
- }
250
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cf/lib/forms/cf.dropdownlist.class.php CHANGED
@@ -61,11 +61,11 @@ class dropdown_list{
61
  {
62
  if($this->onchange == '')
63
  {
64
- echo "<select data-size='5' class='selectpicker' name='" . esc_attr($this->name). "' id='" . esc_attr($this->name). "' >" . $this->options . "</select>";
65
 
66
  }else
67
  {
68
- echo "<select data-size='5' class='selectpicker' name='" . esc_attr($this->name). "' id='" . esc_attr($this->name). "' onchange='" . esc_attr($this->onchange) . "' >" . $this->options . "</select>";
69
  }
70
 
71
  if(!is_null($jforms))
61
  {
62
  if($this->onchange == '')
63
  {
64
+ echo "<select data-size='5' class='selectpicker' name='" . esc_attr($this->name). "' id='" . esc_attr($this->name). "' >" . sprintf('%s',$this->options) . "</select>";
65
 
66
  }else
67
  {
68
+ echo "<select data-size='5' class='selectpicker' name='" . esc_attr($this->name). "' id='" . esc_attr($this->name). "' onchange='" . esc_attr($this->onchange) . "' >" . sprintf('%s',$this->options) . "</select>";
69
  }
70
 
71
  if(!is_null($jforms))
common/controls/datagrid.class.php CHANGED
@@ -317,21 +317,7 @@ class datagrid
317
  return !in_array(strtolower($attr),$reserved);
318
  }
319
 
320
- //-----------------------------------------------------------------
321
 
322
- private function get_attrs($elem)
323
- {
324
- $attrs="";
325
- if(is_array($elem))
326
- foreach($elem as $attr => $value)
327
- {
328
- if($this->is_html_attr($attr))
329
- {
330
- $attrs = $attrs . " " . $attr . "=" . "\"" . esc_attr($value) . "\"";
331
- }
332
- }
333
- return $attrs;
334
- }
335
 
336
 
337
  //-----------------------------------------------------------------
@@ -511,7 +497,7 @@ class datagrid
511
  $this->show_table();
512
  if(!array_key_exists('data',$this->body) || count($this->body['data'])==0)
513
  {
514
- echo '<div'. $this->get_attrs($this->table) .'><p align="center">' . esc_html($this->no_data_text) . '</p></div>';
515
 
516
  }
517
  if($this->is_paged())
@@ -556,7 +542,7 @@ class datagrid
556
 
557
  // print the table tag start
558
 
559
- echo '<table'. $this->get_attrs($this->table) .'>';
560
 
561
  if(array_key_exists('data',$header) && count($header['data'])>0){
562
  echo '<thead>';
@@ -594,27 +580,18 @@ class datagrid
594
  if(count($row)<$col_limit)
595
  $col_limit=count($row) ;
596
 
597
- //print row tag start
598
- $trattr='';
599
- $tdattr='';
600
-
601
 
602
  if(array_key_exists('rows',$handler))
603
- $trattr=$this->get_attrs($handler['rows']);
604
 
605
- echo '<tr'. $trattr .'>';
606
  for($i=0;$i<$col_limit;$i++)
607
  {
608
 
609
-
610
-
611
- if(array_key_exists('col',$handler) && is_array($handler['col']) && array_key_exists($i,$handler['col']))
612
- $tdattr=$this->get_attrs($handler['col'][$i]);
613
- else
614
- $tdattr='';
615
-
616
 
617
- echo '<td' .$tdattr . '>' . sprintf('%s',$row[$i]) . '</td>';
618
  }
619
  echo '</tr>';
620
 
317
  return !in_array(strtolower($attr),$reserved);
318
  }
319
 
 
320
 
 
 
 
 
 
 
 
 
 
 
 
 
 
321
 
322
 
323
  //-----------------------------------------------------------------
497
  $this->show_table();
498
  if(!array_key_exists('data',$this->body) || count($this->body['data'])==0)
499
  {
500
+ echo '<div><p align="center">' . esc_html($this->no_data_text) . '</p></div>';
501
 
502
  }
503
  if($this->is_paged())
542
 
543
  // print the table tag start
544
 
545
+ echo '<table class="wp-list-table widefat fixed striped" width="100%">';
546
 
547
  if(array_key_exists('data',$header) && count($header['data'])>0){
548
  echo '<thead>';
580
  if(count($row)<$col_limit)
581
  $col_limit=count($row) ;
582
 
583
+
 
 
 
584
 
585
  if(array_key_exists('rows',$handler))
586
+
587
 
588
+ echo '<tr>';
589
  for($i=0;$i<$col_limit;$i++)
590
  {
591
 
592
+
 
 
 
 
 
 
593
 
594
+ echo '<td>' . sprintf('%s',$row[$i]) . '</td>';
595
  }
596
  echo '</tr>';
597
 
common/controls/pagination.class.php CHANGED
@@ -116,13 +116,7 @@ public function print_pagination()
116
 
117
  $this->pagination_header_html();
118
 
119
- if($this->current_page > 1)
120
- {
121
- if($this->show_first_last)
122
- echo $this->get_page_html(1,$this->first_page_text);
123
- if($this->show_prev_next)
124
- echo $this->get_page_html($this->prev_page,$this->prev_page_text );
125
- }
126
 
127
  $stop=0;
128
  $half_pages="";
@@ -177,18 +171,12 @@ public function print_pagination()
177
  }
178
 
179
 
180
- if($this->current_page >= 1 && $this->pages_count>1 && $this->current_page< $this->pages_count)
181
- {
182
- if($this->show_prev_next)
183
- echo $this->get_page_html($this->next_page,$this->next_page_text);
184
- if($this->show_first_last)
185
- echo $this->get_page_html($this->pages_count,$this->last_page_text);
186
- }
187
 
188
 
189
 
190
- echo $this->get_pages_number_html();
191
- echo $this->get_go_button_html();
 
192
 
193
  $this->pagination_footer_html();
194
 
@@ -199,7 +187,7 @@ public function print_pagination()
199
 
200
  private function get_page_html($page,$name)
201
  {
202
- return '<a href="' . $this->get_page_url($page) . '">' . $name . '</a>';
203
  }
204
 
205
  //------------------------------------------------------------------------
@@ -207,7 +195,7 @@ private function get_page_html($page,$name)
207
  private function get_current_page_html($name)
208
  {
209
 
210
- return '<span class="currentpage">' . $name . '</span>';
211
  }
212
 
213
  //------------------------------------------------------------------------
@@ -217,10 +205,10 @@ private function pagination_header_html()
217
 
218
  $options="";
219
  if($this->direction!='')
220
- $options= $options . ' dir="' . $this->direction . '" ';
221
 
222
  if($this->alignment!='')
223
- $options= $options . ' align="' . $this->alignment . '" ';
224
 
225
 
226
  echo '<div style="text-align:right;" class="pagination tablenav-page" ' . esc_attr($options) . ' >';
@@ -257,38 +245,32 @@ private function get_go_button_html()
257
 
258
  if($this->show_go_button)
259
  echo '<script>
260
- function fun_'. $id .'()
261
  {
262
- var page=parseInt(document.getElementById(\''. $id .'\').value);
263
- var url = "' . $url_structure . '";
264
  if(page>0)
265
  {
266
  window.location= url.replace(/{pagination}/gi, page);
267
  }else
268
  {
269
- alert(\'' . $this->invalid_page_number_text . '\');
270
  }
271
  }
272
- function keypress_'. $id .'(event)
273
  {
274
  var key=event.keyCode;
275
 
276
  if(key == 13)
277
  {
278
- fun_'. $id .'();
279
  return false;
280
  }
281
  }
282
- </script><input onkeydown="return keypress_'. $id .'(event)" type="text" name="' . $id . '" id="' . $id . '" size="3" value="' . $this->current_page . '" ><a onclick="fun_'. $id .'()" href="#">' . $this->go_button_text .'</a>';
283
  }
284
 
285
- //------------------------------------------------------------------------
286
 
287
- private function get_pages_number_html()
288
- {
289
- if($this->show_pages_number)
290
- echo '<span class="tablenav-paging-text">' . $this->current_page . ' ' . $this->pages_number_text . ' ' . $this->pages_count . '</span>';
291
- }
292
  //------------------------------------------------------------------------
293
 
294
 
@@ -326,7 +308,7 @@ private function WPSR_get_current_parameters($remove_parameter="")
326
 
327
  if($_SERVER['QUERY_STRING']!='')
328
  {
329
- $qry = '?' . $_SERVER['QUERY_STRING'];
330
  if($remove_parameter!='')
331
  {
332
  if(array_key_exists($remove_parameter,$_GET)){
116
 
117
  $this->pagination_header_html();
118
 
119
+
 
 
 
 
 
 
120
 
121
  $stop=0;
122
  $half_pages="";
171
  }
172
 
173
 
 
 
 
 
 
 
 
174
 
175
 
176
 
177
+
178
+
179
+ echo esc_html($this->get_go_button_html());
180
 
181
  $this->pagination_footer_html();
182
 
187
 
188
  private function get_page_html($page,$name)
189
  {
190
+ return '<a href="' . esc_url($this->get_page_url($page)) . '">' . esc_html($name) . '</a>';
191
  }
192
 
193
  //------------------------------------------------------------------------
195
  private function get_current_page_html($name)
196
  {
197
 
198
+ return '<span class="currentpage">' . esc_html($name) . '</span>';
199
  }
200
 
201
  //------------------------------------------------------------------------
205
 
206
  $options="";
207
  if($this->direction!='')
208
+ $options= $options . ' dir="' . esc_attr($this->direction) . '" ';
209
 
210
  if($this->alignment!='')
211
+ $options= $options . ' align="' . esc_attr($this->alignment) . '" ';
212
 
213
 
214
  echo '<div style="text-align:right;" class="pagination tablenav-page" ' . esc_attr($options) . ' >';
245
 
246
  if($this->show_go_button)
247
  echo '<script>
248
+ function fun_'. esc_js($id) .'()
249
  {
250
+ var page=parseInt(document.getElementById(\''. esc_js($id) .'\').value);
251
+ var url = "' . esc_js($url_structure) . '";
252
  if(page>0)
253
  {
254
  window.location= url.replace(/{pagination}/gi, page);
255
  }else
256
  {
257
+ alert(\'' . esc_js($this->invalid_page_number_text) . '\');
258
  }
259
  }
260
+ function keypress_'. esc_js($id) .'(event)
261
  {
262
  var key=event.keyCode;
263
 
264
  if(key == 13)
265
  {
266
+ fun_'. esc_js($id) .'();
267
  return false;
268
  }
269
  }
270
+ </script><input onkeydown="return keypress_'. esc_js($id) .'(event)" type="text" name="' . esc_js($id) . '" id="' . esc_js($id) . '" size="3" value="' . esc_js($this->current_page) . '" ><a onclick="fun_'. esc_js($id) .'()" href="#">' . esc_js($this->go_button_text) .'</a>';
271
  }
272
 
 
273
 
 
 
 
 
 
274
  //------------------------------------------------------------------------
275
 
276
 
308
 
309
  if($_SERVER['QUERY_STRING']!='')
310
  {
311
+ $qry = '?' . sanitize_text_field($_SERVER['QUERY_STRING']);
312
  if($remove_parameter!='')
313
  {
314
  if(array_key_exists($remove_parameter,$_GET)){
common/util.php CHANGED
@@ -1,644 +1,637 @@
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
- // code commented by osama
214
- /*
215
- if (array_key_exists("SERVER_PORT",$_SERVER) && $_SERVER["SERVER_PORT"] != "80") {
216
- $pageURL .= $_SERVER["HTTP_HOST"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
217
- } else {
218
- $pageURL .= $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
219
- }
220
- */
221
-
222
- $pageURL .= $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
223
- return $this->sanitize_req($pageURL,"url");
224
- }
225
-
226
- //-----------------------------------------------------
227
-
228
- public function remove_url_http_www($url)
229
- {
230
- $url = str_ireplace("http://www.",'',$url);
231
- $url = str_ireplace("https://www.",'',$url);
232
- $url = str_ireplace("http://",'',$url);
233
- $url = str_ireplace("https://",'',$url);
234
- return $url;
235
- }
236
- //-----------------------------------------------------
237
- public function make_relative_url($url)
238
- {
239
-
240
- if($url=="")
241
- {
242
- return "";
243
- }
244
- $site_url = $this->remove_url_http_www(site_url());
245
-
246
- if(stripos($url,$site_url) !==false)
247
- {
248
- $url_no_www = $this->remove_url_http_www($url);
249
- if(strtolower(substr($url_no_www,0,strlen($site_url))) == strtolower($site_url))
250
- {
251
- $url = str_ireplace($site_url,'',$url_no_www);
252
- }
253
- }
254
- if($url=="")
255
- {
256
- $url="/";
257
- }
258
- return $url;
259
- }
260
-
261
- //----------------------------------------------------
262
- public function make_absolute_url($url)
263
- {
264
- if(substr($url,0,1)=='/')
265
- {
266
- $url = site_url() . $url;
267
- }
268
- return $url;
269
- }
270
-
271
- //----------------------------------------------------
272
-
273
- public function get_current_relative_url()
274
- {
275
- return $this->make_relative_url($this->get_current_URL());
276
- }
277
- //----------------------------------------------------
278
- public function is_valid_url($url)
279
- {
280
- if(stripos($url,'://')!== false || substr($url,0, 1)=='/')
281
- {
282
- return true;
283
- }else{
284
- return false;
285
- }
286
- }
287
- //----------------------------------------------------
288
-
289
- public function WPSR_get_current_parameters($remove_parameter="")
290
- {
291
-
292
- if($_SERVER['QUERY_STRING']!='')
293
- {
294
- $qry = '?' . urldecode($_SERVER['QUERY_STRING']);
295
-
296
- if(is_array($remove_parameter))
297
- {
298
- for($i=0;$i<count($remove_parameter);$i++)
299
- {
300
- if(array_key_exists($remove_parameter[$i],$_GET)){
301
- $string_remove = '&' . $remove_parameter[$i] . "=" . $this->get($remove_parameter[$i]);
302
- $qry=str_replace($string_remove,"",$qry);
303
- $string_remove = '?' . $remove_parameter[$i] . "=" . $this->get($remove_parameter[$i]);
304
- $qry=str_replace($string_remove,"",$qry);
305
- }
306
- }
307
-
308
- }else{
309
- if($remove_parameter!='')
310
- {
311
- if(array_key_exists($remove_parameter,$_GET)){
312
- $string_remove = '&' . $remove_parameter . "=" . $this->get($remove_parameter);
313
- $qry=str_replace($string_remove,"",$qry);
314
- $string_remove = '?' . $remove_parameter . "=" . $this->get($remove_parameter);
315
- $qry=str_replace($string_remove,"",$qry);
316
- }
317
- }
318
- }
319
-
320
- return strip_tags($this->sanitize_req($qry,"url"));
321
- }else
322
- {
323
- return "";
324
- }
325
- }
326
-
327
-
328
- //---------------------------------------------------------------
329
-
330
- public function get_plugin_path($folder='')
331
- {
332
- return WP_PLUGIN_DIR . '/' . $this->get_plugin_folder() . '/' . $folder;
333
- }
334
-
335
- /* get_plugin_path ---------------------------------------------
336
- public function get_plugin_path()
337
- {
338
- return $this->plugin_path;
339
- }*/
340
-
341
- /* get plugin slug -------------------------------------------- */
342
- public function get_plugin_slug()
343
- {
344
- return $this->slug;
345
- }
346
-
347
- /* get plugin slug -------------------------------------------- */
348
- public function get_plugin_file()
349
- {
350
- return $this->plugin_file;
351
- }
352
- //-----------------------------------------------------
353
-
354
-
355
- public function get_plugin_url($url='')
356
- {
357
- return $this->plugin_url;
358
- }
359
-
360
-
361
- //----------------------------------------------------
362
-
363
- public function get_visitor_IP()
364
- {
365
- $ipaddress = $_SERVER['REMOTE_ADDR'];
366
-
367
- if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
368
- $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
369
- } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
370
- $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
371
- }
372
-
373
- return $ipaddress ;
374
- }
375
-
376
- //----------------------------------------------------
377
-
378
-
379
- public function get_visitor_OS()
380
- {
381
-
382
- $userAgent= $_SERVER['HTTP_USER_AGENT'];
383
- $oses = array (
384
- 'iPhone' => '(iPhone)',
385
- 'Windows 3.11' => 'Win16',
386
- 'Windows 95' => '(Windows 95)|(Win95)|(Windows_95)',
387
- 'Windows 98' => '(Windows 98)|(Win98)',
388
- 'Windows 2000' => '(Windows NT 5.0)|(Windows 2000)',
389
- 'Windows XP' => '(Windows NT 5.1)|(Windows XP)',
390
- 'Windows 2003' => '(Windows NT 5.2)',
391
- 'Windows Vista' => '(Windows NT 6.0)|(Windows Vista)',
392
- 'Windows 7' => '(Windows NT 6.1)|(Windows 7)',
393
- 'Windows 8' => '(Windows NT 6.2)|(Windows 8)',
394
- 'Windows NT 4.0' => '(Windows NT 4.0)|(WinNT4.0)|(WinNT)|(Windows NT)',
395
- 'Windows ME' => 'Windows ME',
396
- 'Open BSD'=>'OpenBSD',
397
- 'Sun OS'=>'SunOS',
398
- //'Linux'=>'(Linux)|(X11)', to detect if android or not
399
- 'Safari' => '(Safari)',
400
- 'Macintosh'=>'(Mac_PowerPC)|(Macintosh)',
401
- 'QNX'=>'QNX',
402
- 'BeOS'=>'BeOS',
403
- 'OS/2'=>'OS\/2',
404
- 'SearchBot'=>'(nuhk)|(Googlebot)|(Yammybot)|(Openbot)|(Slurp\/cat)|(msnbot)|(ia_archiver)'
405
- );
406
-
407
- foreach($oses as $os=>$pattern){
408
-
409
- if(preg_match('/'.$pattern. '/i', $userAgent)) {
410
- return $os;
411
- }
412
- }
413
-
414
- // more tests
415
-
416
- $ua = strtolower($userAgent);
417
-
418
- if(stripos($ua,'android') !== false) {
419
- return 'Android';
420
- }
421
-
422
- if(stripos($ua,'iphone') !== false) {
423
- return 'iOS';
424
- }
425
-
426
-
427
- if(stripos($ua,'ipad') !== false) {
428
- return 'iOS';
429
- }
430
-
431
- if(stripos($ua,'ipod') !== false) {
432
- return 'iOS';
433
- }
434
-
435
- if(stripos($ua,'windows') !== false) {
436
- return 'Windows';
437
- }
438
-
439
-
440
- if(stripos($ua,'linux') !== false) {
441
- return 'Linux';
442
- }
443
-
444
-
445
- if(stripos($ua,'googlebot') !== false) {
446
- return 'Googlebot';
447
- }
448
-
449
- if(stripos($ua,'bot') !== false) {
450
- return 'SearchBot';
451
- }
452
-
453
-
454
- return 'Unknown';
455
- }
456
-
457
- //-----------------------------------------------------------------
458
-
459
- public function get_visitor_Browser()
460
- {
461
-
462
- $u_agent= $_SERVER['HTTP_USER_AGENT'];
463
- $bname = 'Unknown';
464
-
465
- if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
466
- {
467
- $bname = 'Internet Explorer';
468
- }
469
- elseif(preg_match('/Firefox/i',$u_agent))
470
- {
471
- $bname = 'Firefox';
472
- }
473
- elseif(preg_match('/Chrome/i',$u_agent))
474
- {
475
- $bname = 'Chrome';
476
- }
477
- elseif(preg_match('/Safari/i',$u_agent))
478
- {
479
- $bname = 'Safari';
480
- }
481
- elseif(preg_match('/Opera/i',$u_agent))
482
- {
483
- $bname = 'Opera';
484
- }
485
- elseif(preg_match('/Netscape/i',$u_agent))
486
- {
487
- $bname = 'Netscape';
488
- }
489
- elseif(preg_match('/googlebot/i',$u_agent))
490
- {
491
- $bname = 'GoogleBot';
492
- }
493
- elseif(preg_match('/bot/i',$u_agent))
494
- {
495
- $bname = 'SearchBot';
496
- }
497
-
498
-
499
- return $bname;
500
-
501
- }
502
-
503
-
504
- //----------------------------------------------------
505
-
506
- public function option_msg($msg,$out='echo')
507
- {
508
- $msg = '<div id="message" class="updated"><p>' . $msg . '</p></div>';
509
- if($out=='echo')
510
- echo $msg;
511
- elseif($out=='push')
512
- $this->push_msg($msg);
513
- }
514
-
515
- //----------------------------------------------------
516
-
517
-
518
- public function info_option_msg($msg,$out='echo')
519
- {
520
-
521
- $msg = '<div id="message" class="updated"><p><div class="info_icon"></div> ' . $msg . '</p></div>';
522
- if($out=='echo')
523
- echo $msg;
524
- elseif($out=='push')
525
- $this->push_msg($msg);
526
-
527
-
528
- }
529
-
530
- //----------------------------------------------------
531
-
532
-
533
- public function warning_option_msg($msg,$out='echo')
534
- {
535
- $msg = '<div id="message" class="error"><p><div class="warning_icon"></div> ' . $msg . '</p></div>';
536
- if($out=='echo')
537
- echo $msg;
538
- elseif($out=='push')
539
- $this->push_msg($msg);
540
-
541
-
542
- }
543
-
544
- //----------------------------------------------------
545
-
546
- public function success_option_msg($msg,$out='echo')
547
- {
548
- $msg = '<div id="message" class="updated"><p><div class="success_icon"></div> ' . $msg . '</p></div>';
549
- if($out=='echo')
550
- echo $msg;
551
- elseif($out=='push')
552
- $this->push_msg($msg);
553
- }
554
-
555
- //----------------------------------------------------
556
-
557
- public function failure_option_msg($msg,$out='echo')
558
- {
559
- $msg = '<div id="message" class="error"><p><div class="failure_icon"></div> ' . $msg . '</p></div>';
560
- if($out=='echo')
561
- echo $msg;
562
- elseif($out=='push')
563
- $this->push_msg($msg);
564
-
565
- }
566
-
567
- //----------------------------------------------------
568
-
569
- private function push_msg($msg)
570
- {
571
- global $utilpro;
572
- $msgs=$utilpro->get_option_value('admin_notices');
573
- if(is_array($msgs))
574
- {
575
- $msgs[count($msgs)]=$msg;
576
-
577
- }else
578
- {
579
- $msgs = array();
580
- $msgs[0]=$msg;
581
- }
582
-
583
- $utilpro->update_option('admin_notices',$msgs);
584
-
585
- }
586
-
587
- //----------------------------------------------------
588
-
589
-
590
- public function there_is_cache()
591
- {
592
-
593
- $plugins=get_option( 'active_plugins' );
594
-
595
- for($i=0;$i<count($plugins);$i++)
596
- {
597
- if ( array_key_exists($i, $plugins) && stripos($plugins[$i],'cache')!==false)
598
- {
599
- return $plugins[$i];
600
- }
601
- }
602
-
603
-
604
- return '';
605
- }
606
-
607
- //----------------------------------------------------
608
-
609
-
610
- public function there_is_plugin($plugin)
611
- {
612
-
613
- $plugins=get_option( 'active_plugins' );
614
-
615
- for($i=0;$i<count($plugins);$i++)
616
- {
617
- $phpfile = substr( $plugins[$i], strrpos( $plugins[$i], '/' )+1 );
618
- $phpfile = explode(".", $phpfile);
619
- $plugin_name = $phpfile[0];
620
- if ($plugin_name==$plugin)
621
- {
622
- return true;
623
- }
624
- }
625
-
626
-
627
- return false;
628
- }
629
-
630
- //---------------------------------------------------------------
631
-
632
- public function regex_prepare($string)
633
- {
634
-
635
- $from= array('.', '+', '*', '?','[','^',']','$','(',')','{','}','=','!','<','>','|',':','-',')','/', '\\');
636
- $to= array('\\.', '\\+', '\\*', '\\?','\\[','\\^','\\]','\\$','\\(','\\)','\\{','\\}','\\=','\\!','\\<','\\>','\\|','\\:','\\-','\\)','\\/','\\\\');
637
- return str_replace($from,$to,$string);
638
-
639
- }
640
-
641
-
642
- }}
643
-
644
  ?>
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 .= esc_url_raw($_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 esc_url_raw($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
  ?>
custom/controls/cf.SR_redirect_cache.class.php CHANGED
@@ -35,10 +35,11 @@ if(!class_exists('free_SR_redirect_cache')){
35
  $pageURL .= "://";
36
 
37
  if (array_key_exists("SERVER_PORT",$_SERVER) && $_SERVER["SERVER_PORT"] != "80") {
38
- $pageURL .= $_SERVER["HTTP_HOST"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
39
  } else {
40
- $pageURL .= $_SERVER["HTTP_HOST"].$_SERVER["REQUEST_URI"];
41
  }
 
42
  return $pageURL;
43
  }
44
 
@@ -50,7 +51,7 @@ if(!class_exists('free_SR_redirect_cache')){
50
  $url = str_ireplace("https://www.",'',$url);
51
  $url = str_ireplace("http://",'',$url);
52
  $url = str_ireplace("https://",'',$url);
53
- return $url;
54
  }
55
  //-----------------------------------------------------
56
  public function make_relative_url($url)
35
  $pageURL .= "://";
36
 
37
  if (array_key_exists("SERVER_PORT",$_SERVER) && $_SERVER["SERVER_PORT"] != "80") {
38
+ $pageURL .= sanitize_text_field($_SERVER["HTTP_HOST"]).":".intval($_SERVER["SERVER_PORT"]).esc_url_raw($_SERVER["REQUEST_URI"]);
39
  } else {
40
+ $pageURL .= sanitize_text_field($_SERVER["HTTP_HOST"]).esc_url_raw($_SERVER["REQUEST_URI"]);
41
  }
42
+
43
  return $pageURL;
44
  }
45
 
51
  $url = str_ireplace("https://www.",'',$url);
52
  $url = str_ireplace("http://",'',$url);
53
  $url = str_ireplace("https://",'',$url);
54
+ return esc_url_raw($url);
55
  }
56
  //-----------------------------------------------------
57
  public function make_relative_url($url)
options/option_export_import.php CHANGED
@@ -3,14 +3,14 @@ global $wpdb, $table_prefix;
3
  require_once WPSR_PATH . "custom/lib/cf.SR_redirect_cache.class.php";
4
  require_once WPSR_PATH . "cf/lib/cf.jforms.class.php";
5
  require_once WPSR_PATH . "cf/lib/forms/cf.dropdownlist.class.php";
6
- require_once WPSR_PATH . "cf/lib/forms/cf.bcheckbox_option.class.php";
7
 
8
  $SR_jforms = new jforms();
9
  $SR_redirect_cache = new clogica_SR_redirect_cache();
10
 
11
  function WPSR_get_current_parameters($remove_parameter = "") {
12
  if ($_SERVER['QUERY_STRING'] != '') {
13
- $qry = '?' . urldecode($_SERVER['QUERY_STRING']);
14
  if (is_array($remove_parameter)) {
15
  for ($i = 0; $i < count($remove_parameter); $i++) {
16
  if (array_key_exists($remove_parameter[$i], $_GET)) {
@@ -43,13 +43,16 @@ function WPSR_echo_message($msgtxt, $type = 'success') {
43
  $icon = "";
44
  if ($type == 'updated' || $type == 'success') {
45
  $css = 'success';
46
- $icon = "<span class=\"glyphicon glyphicon-ok\"></span>";
 
 
47
  } else if ($type == 'error' || $type == 'danger') {
48
  $css = 'danger';
49
- $icon = "<span class=\"glyphicon glyphicon-warning-sign\"></span>";
 
50
  }
51
 
52
- echo '<div class="alert alert-' . esc_attr($css) . '" role="alert">' . $icon . ' ' . esc_html($msgtxt) . '</div>';
53
  }
54
 
55
  function WPSR_csv_arr($file_name) {
@@ -196,7 +199,7 @@ if ( isset($_POST['btn_import']) && $_POST['btn_import'] != '') {
196
  WPSR_echo_message(__("File is deleted!", 'seo-redirection'));
197
  $SR_redirect_cache->free_cache();
198
  } else {
199
- echo $movefile['error'];
200
  }
201
  } else {
202
  WPSR_echo_message(__("Please choose a CSV file", 'seo-redirection'), 'danger');
@@ -233,9 +236,9 @@ if ( isset($_POST['btn_import']) && $_POST['btn_import'] != '') {
233
  <tr>
234
  <td><label class="control-label col-sm-2" for="Rule"><?php _e("Column Titles:", 'seo-redirection') ?> </label></td>
235
  <td>
236
- <?php
237
- $check = new bcheckbox_option();
238
- $check->create_single_option('col_names', 1);
239
  echo __(" Skip the first row of the file (if there is a table header)", 'seo-redirection');
240
  ?>
241
  </td>
3
  require_once WPSR_PATH . "custom/lib/cf.SR_redirect_cache.class.php";
4
  require_once WPSR_PATH . "cf/lib/cf.jforms.class.php";
5
  require_once WPSR_PATH . "cf/lib/forms/cf.dropdownlist.class.php";
6
+
7
 
8
  $SR_jforms = new jforms();
9
  $SR_redirect_cache = new clogica_SR_redirect_cache();
10
 
11
  function WPSR_get_current_parameters($remove_parameter = "") {
12
  if ($_SERVER['QUERY_STRING'] != '') {
13
+ $qry = '?' . urldecode(sanitize_text_field($_SERVER['QUERY_STRING']));
14
  if (is_array($remove_parameter)) {
15
  for ($i = 0; $i < count($remove_parameter); $i++) {
16
  if (array_key_exists($remove_parameter[$i], $_GET)) {
43
  $icon = "";
44
  if ($type == 'updated' || $type == 'success') {
45
  $css = 'success';
46
+
47
+
48
+ echo '<div class="alert alert-' . esc_attr($css) . '" role="alert"><span class="glyphicon glyphicon-ok"></span> ' . esc_html($msgtxt) . '</div>';
49
  } else if ($type == 'error' || $type == 'danger') {
50
  $css = 'danger';
51
+
52
+ echo '<div class="alert alert-' . esc_attr($css) . '" role="alert"><span class="glyphicon glyphicon-warning-sign"></span> ' . esc_html($msgtxt) . '</div>';
53
  }
54
 
55
+
56
  }
57
 
58
  function WPSR_csv_arr($file_name) {
199
  WPSR_echo_message(__("File is deleted!", 'seo-redirection'));
200
  $SR_redirect_cache->free_cache();
201
  } else {
202
+ echo esc_html($movefile['error']);
203
  }
204
  } else {
205
  WPSR_echo_message(__("Please choose a CSV file", 'seo-redirection'), 'danger');
236
  <tr>
237
  <td><label class="control-label col-sm-2" for="Rule"><?php _e("Column Titles:", 'seo-redirection') ?> </label></td>
238
  <td>
239
+ <input type="checkbox" autocomplete="off" value="1" id="col_names" name="col_names" checked="checked">
240
+ <?php
241
+
242
  echo __(" Skip the first row of the file (if there is a table header)", 'seo-redirection');
243
  ?>
244
  </td>
options/option_page_custome_redirection_list.php CHANGED
@@ -200,7 +200,7 @@ isset($_REQUEST['tab']) ? $url_op = WPSR_sanitize_text_or_array_field($_REQUEST[
200
  <?php
201
  echo '<input class="button-primary" id="btnSave" type="button" value="' . __("Add New", "seo-redirection") . '" onclick="return save_function()">';
202
  ?>
203
- <input type="hidden" id="_wpnonce" name="_wpnonce" value="<?php echo $nonce = wp_create_nonce('seoredirection'); ?>" />
204
  <input type="hidden" id="edit" name="edit" value="<?php echo intval($util->get('edit')) ?>">
205
  <input type="hidden" id="add_new" name="add_new" value="">
206
  <input type="hidden" id="edit_exist" name="edit_exist" value="">
200
  <?php
201
  echo '<input class="button-primary" id="btnSave" type="button" value="' . __("Add New", "seo-redirection") . '" onclick="return save_function()">';
202
  ?>
203
+ <input type="hidden" id="_wpnonce" name="_wpnonce" value="<?php echo esc_attr(wp_create_nonce('seoredirection')); ?>" />
204
  <input type="hidden" id="edit" name="edit" value="<?php echo intval($util->get('edit')) ?>">
205
  <input type="hidden" id="add_new" name="add_new" value="">
206
  <input type="hidden" id="edit_exist" name="edit_exist" value="">
options/option_page_goptions.php CHANGED
@@ -74,7 +74,7 @@ $options= $util->get_my_options();
74
  <form method="POST">
75
  <h3><?php _e("General Options","seo-redirection") ?><hr></h3>
76
 
77
- <input type="hidden" id="_wpnonce" name="_wpnonce" value="<?php echo $nonce = wp_create_nonce('seoredirection'); ?>" />
78
 
79
  <table class="cform" align="center" width="100%">
80
  <tr><td>
74
  <form method="POST">
75
  <h3><?php _e("General Options","seo-redirection") ?><hr></h3>
76
 
77
+ <input type="hidden" id="_wpnonce" name="_wpnonce" value="<?php echo esc_attr(wp_create_nonce('seoredirection')); ?>" />
78
 
79
  <table class="cform" align="center" width="100%">
80
  <tr><td>
readme.txt CHANGED
@@ -1,10 +1,9 @@
1
  === SEO Redirection Plugin - 301 Redirect Manager ===
2
- Contributors: fakhris
3
- Donate link: http://www.clogica.com/donations.htm
4
  Tags: post, admin, seo, pages, manage, 301, 404, soft 404, redirect, permalink, redirection, redirection, https, automatic redirection, htaccess, ssl, https redirection, ssl certificate, secure page, secure, force ssl, force https, seo redirection, post redirect, 404 to 301
5
  Requires at least: 4.1
6
  Tested up to: 5.8
7
- Stable tag: 7.5
8
 
9
  SEO Redirection is a powerful redirect manager to manage 301 redirects without requiring knowledge of Apache .htaccess files.
10
 
@@ -74,12 +73,16 @@ Yes, here is the plugin full knowledge base http://www.clogica.com/kb/
74
 
75
  == Upgrade Notice ==
76
 
 
 
 
 
77
  = 7.5 =
78
  * Escaping data
79
 
80
 
81
  = 7.4 =
82
- * Escaping data
83
 
84
 
85
  = 7.3 =
1
  === SEO Redirection Plugin - 301 Redirect Manager ===
2
+ Contributors: wp-buy, osama.esh
 
3
  Tags: post, admin, seo, pages, manage, 301, 404, soft 404, redirect, permalink, redirection, redirection, https, automatic redirection, htaccess, ssl, https redirection, ssl certificate, secure page, secure, force ssl, force https, seo redirection, post redirect, 404 to 301
4
  Requires at least: 4.1
5
  Tested up to: 5.8
6
+ Stable tag: 7.6
7
 
8
  SEO Redirection is a powerful redirect manager to manage 301 redirects without requiring knowledge of Apache .htaccess files.
9
 
73
 
74
  == Upgrade Notice ==
75
 
76
+ = 7.6 =
77
+ * Escaping data - part 2
78
+
79
+
80
  = 7.5 =
81
  * Escaping data
82
 
83
 
84
  = 7.4 =
85
+ * Escaping data & Bug fixing
86
 
87
 
88
  = 7.3 =
seo-redirection.php CHANGED
@@ -1,11 +1,11 @@
1
  <?php
2
  /*
3
  Plugin Name: SEO Redirection
4
- Plugin URI: http://www.clogica.com/product/seo-redirection-premium-wordpress-plugin
5
  Description: By this plugin you can manage all your website redirection types easily.
6
- Author: Fakhri Alsadi
7
- Version: 7.5
8
- Author URI: http://www.clogica.com
9
  Text Domain: seo-redirection
10
  */
11
 
@@ -42,82 +42,86 @@ register_uninstall_hook(__FILE__, 'WPSR_uninstall');
42
 
43
  /////////////////////////////////////////////////////////////////////////
44
 
45
-
46
- function WPSR_multiple_plugin_activate_trial()
47
- {
48
- global $wpdb;
49
- if (is_multisite()) {
50
- if (is_plugin_active_for_network(__FILE__)) {
51
- $blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
52
- foreach ($blogids as $blog_id) {
53
- switch_to_blog($blog_id);
 
54
  }
55
  }
56
  }
 
 
 
57
  }
58
 
59
- register_activation_hook(__FILE__, 'WPSR_multiple_plugin_activate_trial');
60
 
 
 
 
 
61
 
62
- function WPSR_adding_custom_meta_boxes()
63
- {
64
- global $util;
65
- if ($util->get_option_value('show_redirect_box') == '1') {
66
 
67
- $screens = array('post', 'page');
68
 
69
- foreach ($screens as $screen) {
 
 
 
 
 
 
70
 
71
- add_meta_box(
72
- 'WPSR_meta_box',
73
- __('SEO Redirection'),
74
- 'WPSR_render_meta_box',
75
- $screen
76
- );
77
  }
78
-
79
  }
80
  }
 
81
 
 
 
 
 
82
 
83
- function WPSR_render_meta_box($post)
84
- {
85
- global $wpdb, $table_prefix, $util;
86
- $table_name = $table_prefix . 'WP_SEO_Redirection';
87
-
88
- if (get_post_status() != 'auto-draft') {
89
- $permalink = "";
90
- if (in_array($post->post_status, array('draft', 'pending'))) {
91
- list($permalink, $postname) = get_sample_permalink($post->ID);
92
- $permalink = str_replace('%postname%', $postname, $permalink);
93
 
94
- } else {
95
 
96
- $permalink = get_permalink($post->ID);
97
- }
98
 
99
- $permalink = $util->make_relative_url(urldecode($permalink));
100
 
101
- $postID = $post->ID;
102
 
103
 
104
- $theurl = $wpdb->get_row($wpdb->prepare(" select redirect_to,redirect_from from $table_name where postID=%d ", $postID));
105
 
106
- $urlredirect_to = '';
107
- if ($wpdb->num_rows > 0)
108
- $urlredirect_to = $theurl->redirect_to;
109
 
110
- if ($urlredirect_to != '' && $theurl->redirect_from != $permalink) {
111
- // the post_name field changed!
112
- $wpdb->query($wpdb->prepare(" update $table_name set redirect_from=%s where postID=%d ", $permalink, $postID));
113
- if ($util->get_option_value('reflect_modifications') == '1') {
114
- $wpdb->query($wpdb->prepare(" update $table_name set redirect_to=%s where redirect_to=%s ", $permalink, $theurl->redirect_from));
115
- $util->info_option_msg('<b>' . __("SEO Redirection", 'seo-redirection') . '</b>' . __('has detected a change in Permalink, this will be reflected to the redirection records!', 'seo-redirection'));
 
 
116
  }
117
- //-------------------------------------------
118
- }
119
 
120
- echo '
121
  <table border="0" width="100%" cellpadding="2">
122
  <tr>
123
  <td width="99%"><input onchange="redirect_check_click()" type="checkbox" name="redirect_check" id="redirect_check" value="ON">
@@ -134,7 +138,7 @@ function WPSR_render_meta_box($post)
134
  <tr>
135
  <td>
136
  <ul>
137
- <li>' . __(" To make a redirection, put the", 'seo-redirection') . ' <b>' . __("URL", 'seo-redirection') . '</b> ' . __("in the text field above and then click the button ", 'seo-redirection') . '<b>' . __("Update", 'seo-redirection') . '</b>.</li>
138
  <li>' . __("If you have a caching plugin installed, clear cache to reflect the
139
  changes immediately.", 'seo-redirection') . '</li>
140
 
@@ -145,7 +149,7 @@ function WPSR_render_meta_box($post)
145
  </table>
146
  </div>';
147
 
148
- echo "
149
 
150
  <script type='text/javascript'>
151
  function WSR_check_status(x)
@@ -174,37 +178,42 @@ function redirect_check_click()
174
  </script>
175
  ";
176
 
177
- if ($urlredirect_to == '')
178
- echo "<script type='text/javascript'>WSR_check_status(0);</script>";
179
- else
180
- echo "<script type='text/javascript'>WSR_check_status(1);</script>";
181
 
182
 
183
- } else {
184
- echo __('You can not make a redirection for the new posts before saving them.', 'seo-redirection');
 
185
  }
186
  }
187
 
188
-
189
  //--------------------------------------------------------------------------------------------
190
 
191
  //---------------------------------------------------------------
192
  // added 2/2/2020
193
- function WPSR_get_site_404_page_path()
194
- {
195
- $url= str_ireplace("://", "", site_url());
196
- $site_404_page = substr($url, stripos($url, "/"));
197
-
198
- if (stripos($url, "/")=== FALSE || $site_404_page == "/")
199
- $site_404_page = "/index.php?error=404";
200
- else
201
- $site_404_page = $site_404_page . "/index.php?error=404";
202
-
203
- return $site_404_page;
 
 
 
 
204
  }
205
  //---------------------------------------------------------------
206
  // updated 2/2/2020
207
- function WPSR_check_default_permalink()
 
208
  {
209
  $file= get_home_path() . "/.htaccess";
210
  $content="ErrorDocument 404 " . WPSR_get_site_404_page_path();
@@ -236,779 +245,765 @@ function WPSR_check_default_permalink()
236
  * @since 0.1
237
  * @return mixed
238
  */
239
- function WPSR_sanitize_text_or_array_field($array_or_string) {
240
- if( is_string($array_or_string) ){
241
- $array_or_string = sanitize_text_field($array_or_string);
242
- }elseif( is_array($array_or_string) ){
243
- foreach ( $array_or_string as $key => &$value ) {
244
- if ( is_array( $value ) ) {
245
- $value = WPSR_sanitize_text_or_array_field($value);
246
- }
247
- else {
248
- $value = sanitize_text_field( $value );
 
 
 
249
  }
250
  }
251
- }
252
 
253
- return $array_or_string;
 
254
  }
 
255
 
 
 
256
 
257
- function WPSR_get_post_redirection($post_id)
258
- {
259
-
260
- global $wpdb, $util, $table_prefix;
261
- $table_name = $table_prefix . 'WP_SEO_Redirection';
262
 
263
  // Autosave
264
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
265
- return;
266
  // AJAX
267
- if (defined('DOING_AJAX') && DOING_AJAX)
268
- return;
269
  // Post revision
270
- if (false !== wp_is_post_revision($post_id))
271
- return;
272
 
273
- $redirect_from = isset($_POST['wp_seo_redirection_url_from']) ? WPSR_sanitize_text_or_array_field($_POST['wp_seo_redirection_url_from']) : '';
274
- $redirect_to = isset($_POST['wp_seo_redirection_url']) ? WPSR_sanitize_text_or_array_field($_POST['wp_seo_redirection_url']) : '';
275
 
276
- if ($redirect_to != '') {
277
 
278
 
279
- $wpdb->get_results($wpdb->prepare("select ID from $table_name where postID=%d ", $post_id));
280
 
281
- if ($wpdb->num_rows > 0) {
 
 
 
 
 
 
 
 
 
282
 
283
- $sql = $wpdb->prepare("update $table_name set redirect_to=%s,redirect_from=%s,redirect_type='301',url_type=2 where postID=%d", $redirect_to, $redirect_from, $post_id);
284
- $wpdb->query($sql);
285
 
286
  } else {
287
- $wpdb->query($wpdb->prepare("delete from $table_name where redirect_from=%s", $redirect_from));
288
- $sql = $wpdb->prepare("insert into $table_name(redirect_from,redirect_to,redirect_type,url_type,postID) values (%s,%s,'301',2,%d) ", $redirect_from, $redirect_to, $post_id);
289
- $wpdb->query($sql);
290
  }
291
 
292
-
293
- } else {
294
- $wpdb->query($wpdb->prepare("delete from $table_name where postID=%d", $post_id));
295
  }
296
 
297
- $SR_redirect_cache = new free_SR_redirect_cache();
298
- $SR_redirect_cache->free_cache();
299
  }
300
-
301
-
302
  //-------------------------------------------------------------
 
303
 
304
- function WPSR_log_404_redirection($link)
305
- {
306
- global $wpdb, $table_prefix, $util;
307
- $table_name = $table_prefix . 'WP_SEO_404_links';
308
 
309
- $referrer = $util->get_ref();
310
- $ip = $util->get_visitor_IP();
311
- $country = "";//$util->get_visitor_country();
312
- $os = $util->get_visitor_OS();
313
- $browser = $util->get_visitor_Browser();
314
 
315
- if ($os != 'Unknown' || $browser != 'Unknown') {
316
- $wpdb->query($wpdb->prepare(" insert IGNORE into $table_name(ctime,link,referrer,ip,country,os,browser) values(NOW(),%s,%s,%s,%s,%s,%s) ", $link, $referrer, $ip, $country, $os, $browser));
 
317
  }
318
- }
319
-
320
 
 
321
  //-------------------------------------------------------------
 
322
 
323
- function WPSR_log_redirection_history($rID, $postID, $rfrom, $rto, $rtype, $rsrc)
324
- {
325
- global $wpdb, $table_prefix, $util;
326
- $SR_redirect_cache = new free_SR_redirect_cache();
327
- $SR_redirect_cache->free_cache();
328
- $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
329
- $rfrom = esc_url($rfrom);
330
- $referrer = $util->get_ref();
331
- $ip = $util->get_visitor_IP();
332
- $country = "";//$util->get_visitor_country();
333
- $os = $util->get_visitor_OS();
334
- $browser = $util->get_visitor_Browser();
335
 
336
- $wpdb->query($wpdb->prepare(" insert into $table_name(rID,postID,rfrom,rto,rtype,rsrc,ctime,referrer,ip,country,os,browser) values(%d ,%d,%s,%s,%s,%s,NOW(),%s,%s,%s,%s,%s) ", $rID, $postID, $rfrom, $rto, $rtype, $rsrc, $referrer, $ip, $country, $os, $browser));
337
 
338
- $limit = $util->get_option_value('history_limit');
339
 
340
- $expdate = date('Y-n-j', time() - (intval($limit) * 24 * 60 * 60));
341
- $wpdb->query("delete FROM $table_name WHERE date_format(date(ctime),'%Y-%m-%d') < date_format(date('$expdate'),'%Y-%m-%d')");
342
 
343
 
 
344
  }
345
-
346
  //-------------------------------------------------------------
 
347
 
348
- function WPSR_make_redirect($redirect_to, $redirect_type, $redirect_from, $obj = '')
349
- {
350
- global $wpdb, $util,$table_prefix, $post;
351
- if (is_admin()) {
352
- return 0;
353
- }
354
- $SR_redirect_cache = new free_SR_redirect_cache();
355
- if ($redirect_to == $redirect_from || !$util->is_valid_url($redirect_to))
356
- return 0;
357
-
358
- if($util->make_relative_url($redirect_from) == $util->make_relative_url($redirect_to))
359
- return 0;
360
-
361
- if(substr($redirect_from, -1) == "/" || substr($redirect_to, -1) == "/")
362
  {
363
- if(substr($redirect_from, -1) != "/")
364
- {
365
- if(($redirect_from . "/") == $redirect_to )
366
- return 0;
367
- }else
368
- {
369
- if(( $redirect_to . "/") == $redirect_from )
370
- return 0;
371
  }
372
- }
373
-
374
-
375
- if($util->make_relative_url($redirect_from) == $util->make_relative_url($redirect_to))
376
- return 0;
377
-
378
- if(is_object($obj))
379
- {
380
- if($obj->ID >0){
381
- $table_name = $table_prefix . 'WP_SEO_Redirection';
382
- $sql = "update " . $table_name . " set hits=hits+1, access_date= NOW() where ID='" . $obj->ID . "'";
383
- $wpdb->query($sql);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
  }
385
- }
386
-
387
- if (is_object($obj) && $obj->redirect_to_type == 'Folder' && $obj->redirect_to_folder_settings == '2') {
388
 
389
- if ($obj->redirect_from_type == 'Folder') {
390
 
391
- if ($obj->redirect_from_folder_settings == '2' || $obj->redirect_from_folder_settings == '3') {
392
- if (strlen($redirect_from) > strlen($obj->redirect_from)) {
393
- $difference = substr($redirect_from, intval(strlen($obj->redirect_from) - strlen($redirect_from)));
394
- $redirect_to = $redirect_to . $difference;
 
 
 
395
  }
 
 
 
 
396
  }
397
 
398
- } else if ($obj->redirect_from_type == 'Regex') {
399
- $page = substr(strrchr($redirect_from, "/"), 1);
400
- $redirect_to = $redirect_to . '/' . $page;
401
  }
402
 
403
- }
 
 
404
 
405
- $rID = 0;
406
- $rsrc = '404';
407
- $postID = 0;
 
 
 
 
408
 
409
- if (is_object($obj)) {
410
- $rID = $obj->ID;
411
- $postID = $obj->postID;
412
- if ($obj->url_type == 1)
413
- $rsrc = 'Custom';
414
- else if ($obj->url_type == 2)
415
- $rsrc = 'Post';
416
 
417
- }
418
 
419
- if ($util->get_option_value('history_status') == '1') {
 
420
 
421
- WPSR_log_redirection_history($rID, $postID, $redirect_from, $redirect_to, $redirect_type, $rsrc);
422
- }
423
 
424
- $redirect_to = $util->make_absolute_url($redirect_to);
425
 
 
 
426
 
427
- if (is_singular()) {
428
- //$SR_redirect_cache = new free_SR_redirect_cache();
 
429
 
430
- $SR_redirect_cache->add_redirect($post->ID, 1, $redirect_from, $redirect_to, $redirect_type);
431
- $SR_redirect_cache->free_cache();
432
- }
433
-
434
- if ($redirect_type == '301') {
435
- header('HTTP/1.1 301 Moved Permanently');
436
- header("Location: " . $redirect_to);
437
- exit();
438
- } else if ($redirect_type == '307') {
439
- header('HTTP/1.0 307 Temporary Redirect');
440
- header("Location: " . $redirect_to);
441
- exit();
442
- } else if ($redirect_type == '302') {
443
- header("Location: " . $redirect_to);
444
- exit();
445
- }
446
 
 
447
  }
448
 
449
-
450
  //-------------------------------------------------------------
 
451
 
452
- function WPSR_redirect()
453
- {
454
- global $wpdb, $post, $table_prefix, $util;
455
-
456
 
457
- if ($util->get_option_value('plugin_status') != '0') { // if not disabled
458
 
459
- // if disable for admin and the user is admin
460
- if (current_user_can('manage_options') == 1 && $util->get_option_value('plugin_status') == 2) {
461
- // nothing
462
 
463
- } else {
 
 
464
 
465
- $table_name = $table_prefix . 'WP_SEO_Redirection';
466
- $permalink = urldecode($util->get_current_relative_url());
467
- if (substr($permalink, 0, 1) == ":") {
468
- $first_slash = stripos($permalink, "/");
469
- $permalink = substr($permalink, $first_slash, strlen($permalink) - $first_slash);
470
- }
471
- $permalink_alternative = "";
472
- if (substr($permalink, -1) == '/') {
473
- $permalink_alternative = substr($permalink, 0, intval(strlen($permalink) - 1));
474
  } else {
475
- $permalink_alternative = $permalink . '/';
476
- }
477
-
478
- $post_cache_result = "";
479
- $SR_redirect_cache = new free_SR_redirect_cache();
480
- if (is_singular()) {
481
- $post_cache_result = $SR_redirect_cache->redirect_cached($post->ID);
482
- }
483
- if ($post_cache_result == 'not_redirected') {
484
- return 0;
485
- }
486
-
487
- $permalink_options = $wpdb->prepare("( redirect_from = %s OR redirect_from = %s)", $permalink, $permalink_alternative);
488
-
489
- $permalink_regex_options = $wpdb->prepare("(%s regexp regex or %s regexp regex )", $permalink, $permalink_alternative);
490
-
491
- if (($util->get_option_value('redirect_control_panel') != '1') || ($util->get_option_value('redirect_control_panel') == '1' && !preg_match('/^' . str_replace('/', '\/', get_admin_url()) . '/i', $permalink) && !preg_match('/^' . str_replace('/', '\/', site_url()) . '\/wp-login.php/i', $permalink))) {
492
-
493
 
494
- $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex='' and $permalink_options ");
495
- if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
496
- WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
 
 
 
 
 
 
 
 
497
  }
498
 
499
- $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex<>'' and $permalink_regex_options order by LENGTH(regex) desc ");
500
- if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
501
- WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
 
502
  }
 
 
 
 
 
 
 
503
 
 
504
 
505
- if (is_404()) {
506
 
507
- if ($util->get_option_value('p404_discovery_status') == '1') {
508
- WPSR_log_404_redirection($permalink);
 
509
  }
510
 
511
- $options = $util->get_my_options();
512
- if ($options['p404_status'] == '1') {
 
 
 
 
 
 
 
 
 
 
 
 
513
 
514
- WPSR_make_redirect($options['p404_redirect_to'], '301', $permalink);
515
 
 
516
  }
517
  }
518
- }
519
-
520
- if (is_singular() && $post_cache_result == 'not_found') {
521
  $SR_redirect_cache->add_redirect($post->ID, 0, '', '', 0);
522
- }
523
 
 
524
  }
525
  }
526
  }
527
-
528
  //---------------------------------------------------------------
 
529
 
530
- function WPSR_header_code()
531
- {
532
- //wp_enqueue_script('ajaxcustomvar');
533
- /* condition removed to display import popup on Import button(admin notioce message) click on any admin page*/
534
- if (is_admin() && array_key_exists('page', $_GET) && $_GET['page'] == 'seo-redirection.php')
535
-
536
  {
 
 
 
537
 
538
- wp_register_style('c_admin_css_common', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "style.css");
539
- wp_enqueue_style('sweetalert', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "sweetalert.css");
540
- wp_register_style('c_admin_css_custom', plugins_url() . '/' . basename(dirname(__FILE__)) . '/custom/' . "style.css");
541
- wp_enqueue_script('jquery');
542
- wp_localize_script('jquery', 'seoredirection', array('ajax_url' => admin_url('admin-ajax.php'), 'msg' => ""));
543
- wp_enqueue_style('c_admin_css_common');
544
- wp_enqueue_style('c_admin_css_custom');
545
 
546
- wp_enqueue_script('custom', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/js/' . 'bootstrap.min.js', array('jquery'), false, true);
547
- wp_enqueue_script('customJS', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "customJs.js", array('jquery'), false, true);
548
- wp_enqueue_script('sweetalert', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/js/' . "sweetalert.min.js", array('jquery'), false, true);
549
 
550
- wp_enqueue_style('bootstrap', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "bootstrap.css");
551
 
552
 
 
553
  }
554
  }
555
-
556
  //---------------------------------------------------------------
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
557
 
558
- add_action("wp_ajax_customAddUpdate", "WPSR_customAddUpdate_callback");
559
 
560
- function WPSR_customAddUpdate_callback()
561
- {
562
- global $wpdb, $table_prefix, $util;
563
- $table_name = $table_prefix . 'WP_SEO_Redirection';
564
- $table_name_404 = $table_prefix . 'WP_SEO_404_links';
565
- parse_str($_POST['formData'], $_POST);
566
- $nonce = "";
567
- if (isset($_POST['_wpnonce']))
568
- $nonce = WPSR_sanitize_text_or_array_field($_POST['_wpnonce']);
569
- $data = array();
570
- $data['error_string'] = array();
571
- $data['inputerror'] = array();
572
- $data['bool'] = TRUE;
573
- if (trim($_POST['redirect_from']) == '') {
574
- $data['inputerror'][] = 'redirect_from';
575
- $data['error_string'][] = __("You must input the 'Redirect From' URL", "seo-redirection");
576
- $data['bool'] = FALSE;
577
- }
578
-
579
- $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
580
-
581
- $wpdb->get_results(" select ID from $table_name where redirect_from='" . trim($redirect_from) . "' ");
582
- if($wpdb->num_rows > 0){
583
- $data['inputerror'][] = 'redirect_from';
584
- $data['error_string'][] = __("This 'Redirect From' value already exists in database!", "seo-redirection");
585
- $data['bool'] = FALSE;
586
- }
587
-
588
-
589
  // elseif (!preg_match( '/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/', $_POST['redirect_from'])) {
590
  // $data['inputerror'][] = 'redirect_from';
591
  // $data['error_string'][] = __("Invalid redirect from target URL!",'seo-redirection');
592
  // $data['bool'] = FALSE;
593
  // }
594
- if (trim($_POST['redirect_to']) == '') {
595
- $data['inputerror'][] = 'redirect_to';
596
- $data['error_string'][] = __("You must input the 'Redirect To' URL", "seo-redirection");
597
- $data['bool'] = FALSE;
598
- } elseif ($_POST['edit_exist'] == '' && substr (strtolower ($_POST['redirect_to']), 0, 4)!="http" && substr (strtolower ($_POST['redirect_to']), 0, 1)!="/" ) {
599
- $data['inputerror'][] = 'redirect_to';
600
- $data['error_string'][] = __("Invalid redirect target URL!", 'seo-redirection');
601
- $data['bool'] = FALSE;
602
- }
603
- if ($data['bool'] === FALSE) {
604
- echo json_encode($data);
605
- exit();
606
- } else {
607
- if ($_POST['redirect_from'] != '' && wp_verify_nonce($nonce, 'seoredirection')) {
608
-
609
-
610
- $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
611
- $redirect_to = isset($_POST['redirect_to']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_to']) : '';
612
-
613
 
614
- $redirect_from = urldecode($util->make_relative_url($redirect_from));
615
 
616
- $redirect_to = $util->make_relative_url($redirect_to);
617
- $redirect_type = WPSR_sanitize_text_or_array_field($_POST['redirect_type']);
618
 
619
- $redirect_from_type = WPSR_sanitize_text_or_array_field($_POST['redirect_from_type']);
620
- $redirect_from_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_from_folder_settings']);
621
- $redirect_from_subfolders = WPSR_sanitize_text_or_array_field($_POST['redirect_from_subfolders']);
622
 
623
- $redirect_to_type = WPSR_sanitize_text_or_array_field($_POST['redirect_to_type']);
624
- $redirect_to_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_to_folder_settings']);
625
 
626
- $enabled = WPSR_sanitize_text_or_array_field($_POST['enabled']);
 
627
 
628
- $regex = "";
 
 
629
 
630
- if ($redirect_from_type == 'Folder') {
 
631
 
632
- if (substr($redirect_from, -1) != '/')
633
- $redirect_from = $redirect_from . '/';
634
 
635
- if ($redirect_from_folder_settings == 2) {
636
- if ($redirect_from_subfolders == 0) {
637
- $regex = '^' . $util->regex_prepare($redirect_from) . '.*';;
638
- } else {
639
- $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]*$';
640
- }
641
- } else if ($redirect_from_folder_settings == 3) {
642
- if ($redirect_from_subfolders == 0) {
643
- $regex = '^' . $util->regex_prepare($redirect_from) . '.+';
644
- } else {
645
- $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]+$';
 
 
 
 
 
 
 
 
646
  }
647
- }
648
 
649
- } else if ($redirect_from_type == 'Regex') {
650
- $regex = $redirect_from;
651
- }
652
 
653
- if ($redirect_from_type == 'Page' || $redirect_from_type == 'Regex') {
654
- $redirect_from_folder_settings = "";
655
- $redirect_from_subfolders = "";
656
- }
657
 
658
- if ($redirect_to_type == 'Page') {
659
- $redirect_to_folder_settings = "";
660
- }
661
 
662
- if ($redirect_to_type == 'Folder') {
663
- if (substr($redirect_to, -1) != '/')
664
- $redirect_to = $redirect_to . '/';
665
- }
666
 
667
 
668
- if ($_POST['add_new'] != '') {
669
 
670
- $theurl = $wpdb->get_row($wpdb->prepare(" select count(ID) as cnt from $table_name where redirect_from=%s ", $redirect_from));
671
 
672
- if ($theurl->cnt > 0) {
673
- $msg = __("This URL", 'seo-redirection') . " <b>'$redirect_from'</b>" . __("is added previously!", 'seo-redirection');
674
- echo json_encode(array('status' => 'error', 'msg' => $msg));
675
  // $util->failure_option_msg(__("This URL",'seo-redirection')." <b>'$redirect_from'</b>". __("is added previously!",'seo-redirection'));
676
- } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
677
 
 
678
 
679
  if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
680
- $util->failure_option_msg(__('Please input all required fields!', 'seo-redirection'));
681
  } else {
682
 
683
- $wpdb->insert($table_name, array(
684
- 'redirect_from' => $redirect_from,
685
- 'redirect_to' => $redirect_to,
686
- 'redirect_type' => $redirect_type,
687
- 'url_type' => 1,
688
- 'redirect_from_type' => $redirect_from_type,
689
- 'redirect_from_folder_settings' => $redirect_from_folder_settings,
690
- 'redirect_from_subfolders' => $redirect_from_subfolders,
691
- 'redirect_to_type' => $redirect_to_type,
692
- 'redirect_to_folder_settings' => $redirect_to_folder_settings,
693
- 'regex' => $regex,
694
- 'enabled' => $enabled
695
-
696
- ));
697
-
698
- $wpdb->query($wpdb->prepare(" delete from $table_name_404 where link=%s ", $redirect_from));
699
  $SR_redirect_cache = new free_SR_redirect_cache();
700
  $SR_redirect_cache->free_cache();
701
- $msg = "Redirection Added Successfully";
702
- echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
703
- die;
704
  }
 
 
 
705
 
706
  }
707
- } else if ($_POST['edit_exist'] != '') {
708
-
709
- $edit = WPSR_sanitize_text_or_array_field($_POST['edit']);
710
-
711
- if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
712
- $util->failure_option_msg('Please input all required fields!');
713
- } else {
714
-
715
- $wpdb->query($wpdb->prepare("update $table_name set redirect_from=%s,redirect_to=%s,redirect_type=%s,redirect_from_type=%s ,redirect_from_folder_settings=%d,redirect_from_subfolders=%d ,redirect_to_type=%s ,redirect_to_folder_settings=%d ,regex=%s,enabled=%s where ID=%d ", $redirect_from, $redirect_to, $redirect_type, $redirect_from_type, $redirect_from_folder_settings, $redirect_from_subfolders, $redirect_to_type, $redirect_to_folder_settings, $regex, $enabled, $edit));
716
 
717
- $SR_redirect_cache = new free_SR_redirect_cache();
718
- $SR_redirect_cache->free_cache();
719
- }
720
- $msg = "Redirection Update Successfully";
721
- echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
722
- die;
723
 
724
  }
725
 
726
- if ($util->there_is_cache() != '')
727
- $util->info_option_msg(__("You have a cache plugin installed", 'seo-redirection') . " <b>'" . $util->there_is_cache() . "'</b>, " . __("you have to clear cache after any changes to get the changes reflected immediately! ", 'seo-redirection'));
728
-
729
  }
730
 
731
- }
732
-
733
 
734
- die;
 
735
  }
 
736
 
737
- add_action("wp_ajax_customUpdateRec", "WPSR_customUpdateRec_callback");
738
- function WPSR_customUpdateRec_callback()
739
- {
740
 
741
 
742
- global $wpdb, $table_prefix, $util;
743
 
744
- $table_name = $table_prefix . 'WP_SEO_Redirection';
745
- $table_name_404 = $table_prefix . 'WP_SEO_404_links';
746
 
747
- $myid = (int) $_POST['ID'];
748
- $item = $wpdb->get_row($wpdb->prepare(" select * from $table_name where ID=%d ", $myid));
749
 
750
- if ($wpdb->num_rows == 0) {
751
- echo json_encode(array('status' => 'error', 'msg' => __("Sorry, this redirect rule is not found, it may deleted by the user!", 'seo-redirection')));
752
- die;
753
- }
754
 
755
 
756
- $data = array(
757
- "redirect_from" => $item->redirect_from,
758
- "redirect_to" => $item->redirect_to,
759
- "redirect_type" => $item->redirect_type,
760
 
761
- "redirect_from_type" => $item->redirect_from_type,
762
- "redirect_from_folder_settings" => $item->redirect_from_folder_settings,
763
- "redirect_from_subfolders" => $item->redirect_from_subfolders,
764
 
765
- "redirect_to_type" => $item->redirect_to_type,
766
- "redirect_to_folder_settings" => $item->redirect_to_folder_settings,
767
 
768
- "enabled" => $item->enabled
769
- );
770
- echo json_encode(array('status' => 'suucess', 'rec' => $data));
771
- die;
 
772
  }
 
773
 
774
- add_action("wp_ajax_importFromRedirection","WPSR_importFromRedirection_callback");
775
- function WPSR_importFromRedirection_callback()
776
- {
777
- global $wpdb;
778
-
779
- $plugins = get_option( 'active_plugins', array() );
780
- $found = false;
781
- foreach ( $plugins as $plugin )
782
- {
783
- if ( strpos( strval($plugin), 'redirection.php' ) == true && strpos( strval($plugin), 'seo-redirection.php' ) == FALSE )
784
- {
785
- if(isset($_REQUEST['offset']))
786
- {
787
- $offset = WPSR_sanitize_text_or_array_field($_REQUEST['offset']);
788
- $count = 0;
789
- $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
790
- $table_name_404 = $wpdb->prefix . 'WP_SEO_404_links';
791
-
792
-
793
- $table_name_ = $wpdb->prefix . 'redirection_items';
794
- if (strtolower($wpdb->get_var("show tables like '$table_name_'")) == strtolower($table_name_))
795
- {
796
-
797
-
798
- $redirects = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}redirection_items order by id limit ".$offset.",1" );
799
- if($redirects)
800
- {
801
- //print_r($redirects);
802
- $udtcnt = 0;
803
- $inscnt=0;
804
- foreach ( $redirects as $redirect )
805
- {
806
- $redirect_from = stripslashes($redirect->url);
807
- $redirect_from_slash = ltrim(stripslashes($redirect->url),'/');
808
- if($redirect->status=="enabled")
809
- $enabled =1;
810
- else
811
- $enabled =0;
812
-
813
- $group_id = 1;
814
- if($redirect->group_id == "1")
815
- {
816
- $group_id = 2;
817
- }
818
- else if($redirect->group_id == "2")
819
- {
820
- $group_id = 3;
821
- }
822
-
823
- $redirect_from_type = $redirect->regex ? 'Regex' : 'Page';
824
- $redirect_to_type = $redirect->regex ? 'Regex' : 'Page';
825
- $regexp = $redirect->regex ? $redirect->url : '';
826
- $redirectID = $wpdb->get_var($wpdb->prepare("select ID from $table_name where redirect_from=%s or redirect_from=%s", $redirect_from,$redirect_from_slash));
827
-
828
- if ($redirectID > 0)
829
- {
830
-
831
- $update = $wpdb->query($wpdb->prepare("update $table_name set redirect_from=%s,redirect_to=%s,redirect_type=%d, redirect_from_type=%s, redirect_to_type=%s,regex=%s,enabled=%d, grpID=%d,import_flag=%d, redirect_from_folder_settings=%d,redirect_from_subfolders=%d,redirect_to_folder_settings=%d where ID=%d", $redirect_from, stripslashes($redirect->action_data),intval( $redirect->action_code, 10),$redirect_from_type,$redirect_to_type,$regexp,$enabled,$group_id,1,0,0,0, $redirectID));
832
- if($update)
833
- {
834
- $udtcnt++;
835
- }
836
- }
837
- else
838
- {
839
- $wpdb->insert($table_name, array(
840
- 'redirect_from' => stripslashes($redirect->url),
841
- 'redirect_to' => stripslashes($redirect->action_data),
842
- 'redirect_type' =>intval( $redirect->action_code, 10),
843
- 'url_type' => 1,
844
- 'redirect_from_type' => $redirect->regex ? 'Regex' : 'Page',
845
- 'redirect_from_folder_settings' => 0,
846
- 'redirect_from_subfolders' => 0,
847
- 'redirect_to_type' => $redirect->regex ? 'Regex' : 'Page',
848
- 'redirect_to_folder_settings' => 0,
849
- 'regex' => $redirect->regex ? $redirect->url : '',
850
- 'enabled' => $enabled,
851
- 'grpID' => $group_id,
852
- 'import_flag' =>1,
853
- ));
854
-
855
- $inscnt++;
856
- $wpdb->query($wpdb->prepare(" delete from $table_name_404 where link=%s ", $redirect_from));
857
- $SR_redirect_cache = new free_SR_redirect_cache();
858
- $SR_redirect_cache->free_cache();
859
- }
860
- }
861
- $msg = __('Total ','seo-redirection').'<span class="insert_cnt">'.$inscnt.'</span>'.__(' record(s) inserted and ','seo-redirection').'<span class="update_cnt">'.$udtcnt.'</span>'.__(' record(s) updated.','seo-redirection');
862
- echo json_encode(array('status' => 'success','updateCnt'=>$udtcnt,'insertCnt'=>$inscnt,'msg'=>$msg));
863
- }
864
- else
865
- {
866
- $msg = __('No redirects found to import.','seo-redirection');
867
- echo json_encode(array('status' => 'error','msg'=>$msg));
868
- }
869
- }
870
- }
871
- else
872
- {
873
- $msg = __('Something went wrong plase try again.','seo-redirection');
874
- echo json_encode(array('status' => 'error','msg'=>$msg));
875
- }
876
- break;
877
- }
878
-
879
- }
880
- exit;
881
- }
882
 
883
- function WPSR_admin_menu()
884
- {
885
- add_options_page('SEO Redirection', 'SEO Redirection', 'manage_options', basename(__FILE__), 'WPSR_options_menu');
886
  }
 
887
 
 
 
 
 
 
888
  //---------------------------------------------------------------
889
- function WPSR_options_menu()
890
- {
891
- global $util;
892
 
893
- if (!current_user_can('manage_options')) {
894
- wp_die(__('You do not have sufficient permissions to access this page.', 'seo-redirection'));
895
- }
896
 
 
 
 
897
 
898
- if ($util->get_option_value('plugin_status') == '0') {
899
- $util->info_option_msg(__('SEO Redirection is disabled now, you can go to option tab and enable it!', 'seo-redirection'));
900
- } else if ($util->get_option_value('plugin_status') == '2') {
901
- $util->info_option_msg(__('SEO Redirection is', 'seo-redirection') . ' <b>' . __('disabled for admin', 'seo-redirection') . '</b>' . __(' only, you can go to option tab and enable it!', 'seo-redirection'));
902
- }
903
- $total_404_errors = (WPSR_Get_total_404() > 10) ? __('You have', 'seo-redirection') . ' <b style="color:red; background-color:yellow; padding:3px;"> too many </b>' . __(' broken link (404 links)', 'seo-redirection') . ', <br>' : '';
904
 
 
 
 
 
 
 
905
 
906
- echo '<div class="wrap"><h2>' . __("SEO Redirection Free", 'seo-redirection') . '</h2><b>' . __('Upgrade to', 'seo-redirection') . ' <a target="_blank" onclick="swal.clickConfirm();" href="http://www.clogica.com/product/seo-redirection-premium-wordpress-plugin">' . __("Pro Version", "seo-redirection") . '</a>' . __(" to manage 404 errors and empower your site SEO", "seo-redirection") . '&nbsp;&nbsp;&nbsp;<strong style="color:yellow; background-color:red; padding:3px;"> ' . __("NOW 50% OFF ", 'seo-redirection') . '</strong></b><br/><br/>';
907
 
908
- /*if ($total_404_errors != '') {
909
-
910
- ?>
911
- <script type="text/javascript">
912
 
913
- seoredirection.msg = '<?php echo $total_404_errors . '<div class="wrap" style="font-weight:normal; line-height:30px">' . __('Upgrade to', 'seo-redirection') . ' <a target="_blank" href="http://www.clogica.com/product/seo-redirection-premium-wordpress-plugin">' . __("Pro Version", "seo-redirection") . '</a>' . __(" to manage 404 errors and empower your site SEO", "seo-redirection") ?></div>';
914
 
915
- </script>
916
 
917
- <?php
918
- }*/
919
 
920
- if (is_multisite()) {
921
 
922
- echo '<div class="error" id="message"><p></p><div class="warning_icon"></div>' . __('This version does not support Multisite WordPress installation, you may face troubles like losing redirects when adding new sites to your network, the premium version supports multisite well', 'seo-redirection') . '(<a target="_blank" href="http://www.clogica.com/product/seo-redirection-premium-wordpress-plugin">
923
- http://www.clogica.com/product/seo-redirection-premium-wordpress-plugin</a>) <p></p></div>';
924
 
925
- }
926
-
927
- $mytabs = new phptab();
928
-
929
- $mytabs->set_ignore_parameter(array('del', 'search', 'page_num', 'add', 'edit', 'page404', 'do_404_del'));
930
- $mytabs->add_file_tab('cutom', __('Custom Redirects', 'seo-redirection'), 'option_page_custome_redirection.php', 'file');
931
- $mytabs->add_file_tab('posts', __('Post Redirects', 'seo-redirection'), 'option_page_post_redirection_list.php', 'file');
932
- $mytabs->add_file_tab('history', __('History', 'seo-redirection'), 'option_page_history.php', 'file');
933
- $mytabs->add_file_tab('export_import', __('Export/Import', 'seo-redirection'), 'option_export_import.php', 'file');
934
- $mytabs->add_file_tab('404','<span style="color:red;"><b>404 Errors</b></span>','option_page_404.php','file');
935
- $mytabs->add_file_tab('goptions', __('Options', 'seo-redirection'), 'option_page_goptions.php', 'file');
936
- $mytabs->add_file_tab('help', '<span style="color:green;"><b>' . __('Help', 'seo-redirection') . '</b></span>', 'help.php', 'file');
937
- $mytabs->add_file_tab('premium', '<span style="color:brown;"><b>&#9658; ' . __('Premium Features', 'seo-redirection') . '</b></span>', 'premium.php', 'file');
938
- $mytabs->run();
939
 
940
  }
 
 
941
 
 
 
942
 
943
- function WPSR_upgrade()
944
- {
945
-
946
- $util = new clogica_util_1();
947
- $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
948
 
949
- if ($util->get_option_value('plugin_version') != WP_SEO_REDIRECTION_VERSION) {
950
- WPSR_install();
951
- $util->update_option('plugin_version', WP_SEO_REDIRECTION_VERSION);
 
952
  }
953
  }
954
-
955
  //-----------------------------------------------------
956
- function WPSR_install()
957
- {
958
- global $wpdb, $table_prefix;
959
-
960
- $util = new clogica_util_1();
961
- $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
962
-
963
- $options = get_option(WP_SEO_REDIRECTION_OPTIONS);
964
- if (!is_array($options)) {
965
- add_option(WP_SEO_REDIRECTION_OPTIONS);
966
- $options = array();
967
- }
968
 
 
 
 
 
 
969
 
970
- if (!array_key_exists('plugin_status', $options))
971
- $options['plugin_status'] = '1';
972
 
973
- if (!array_key_exists('ip_logging_status', $options))
974
- $options['ip_logging_status'] = '1';
975
 
976
- if (!array_key_exists('redirection_base', $options))
977
- $options['redirection_base'] = site_url();
978
 
979
- if (!array_key_exists('redirect_control_panel', $options))
980
- $options['redirect_control_panel'] = '1';
981
 
982
- if (!array_key_exists('show_redirect_box', $options))
983
- $options['show_redirect_box'] = '1';
984
 
985
- if (!array_key_exists('reflect_modifications', $options))
986
- $options['reflect_modifications'] = '1';
987
 
988
- if (!array_key_exists('history_status', $options))
989
- $options['history_status'] = '1';
990
 
991
- if (!array_key_exists('history_limit', $options))
992
- $options['history_limit'] = '30';
993
 
994
- if (!array_key_exists('p404_discovery_status', $options))
995
- $options['p404_discovery_status'] = '1';
996
 
997
- if (!array_key_exists('p404_redirect_to', $options))
998
- $options['p404_redirect_to'] = site_url();
999
 
1000
- if (!array_key_exists('p404_status', $options))
1001
- $options['p404_status'] = '2';
1002
 
1003
- if (!array_key_exists('keep_data', $options))
1004
- $options['keep_data'] = '1';
1005
 
1006
- update_option(WP_SEO_REDIRECTION_OPTIONS, $options);
 
1007
 
 
1008
 
1009
- $table_name = $table_prefix . 'WP_SEO_Redirection';
1010
- if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1011
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
 
1012
  `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1013
  `enabled` int(1) NOT NULL DEFAULT '1',
1014
  `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
@@ -1028,54 +1023,53 @@ function WPSR_install()
1028
  PRIMARY KEY (`ID`),
1029
  UNIQUE KEY `redirect_from` (`redirect_from`)
1030
  )ENGINE = MyISAM ;";
1031
- $wpdb->query($sql);
1032
-
1033
-
1034
- } else {
1035
- //check if Innodb convert it to myisam.
1036
- $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1037
- if ($status->Engine == 'InnoDB') {
1038
- $wpdb->query("alter table $table_name engine = MyISAM;");
1039
- }
1040
-
1041
- /* add column for import flag */
1042
- $column_data = $wpdb->get_row("SHOW COLUMNS FROM $table_name LIKE 'import_flag'");
1043
 
1044
- if (!$column_data)
1045
- {
1046
- $wpdb->query("ALTER TABLE $table_name ADD COLUMN import_flag tinyint(1) DEFAULT 0");
1047
- }
1048
 
1049
- // if the table exists
1050
- $redirects = $wpdb->get_results(" select redirect_from,redirect_to,ID from $table_name; ");
1051
- foreach ($redirects as $redirect) {
1052
- $redirect_from = $util->make_relative_url($redirect->redirect_from);
1053
- $redirect_to = $util->make_relative_url($redirect->redirect_to);
1054
- $ID = $redirect->ID;
1055
- $wpdb->query($wpdb->prepare(" update $table_name set redirect_from=%s,redirect_to=%s where ID=%d", $redirect_from, $redirect_to, $ID));
1056
- }
1057
-
1058
- // Fix add blog field if not exist.
1059
- if($wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1060
  WHERE TABLE_NAME = '$table_name'
1061
  AND table_schema = DATABASE()
1062
  AND COLUMN_NAME = 'hits' ") == '0') {
1063
 
1064
- $sql="
1065
  ALTER TABLE $table_name
1066
  ADD COLUMN `hits` int(11) unsigned NOT NULL DEFAULT 0,
1067
  ADD COLUMN `access_date` datetime DEFAULT NULL;
1068
  ";
1069
 
1070
- $wpdb->query($sql);
1071
- }
1072
-
1073
 
1074
- }
1075
 
1076
- $table_name = $table_prefix . 'WP_SEO_Cache';
1077
- if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1078
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
 
 
1079
  `ID` int(11) unsigned NOT NULL,
1080
  `is_redirected` int(1) unsigned NOT NULL,
1081
  `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
@@ -1084,34 +1078,34 @@ function WPSR_install()
1084
  PRIMARY KEY (`ID`)
1085
  ) ENGINE = MyISAM ;
1086
  ";
1087
- $wpdb->query($sql);
1088
- } else {
1089
- //check if Innodb convert it to myisam.
1090
- $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1091
- if ($status->Engine == 'InnoDB') {
1092
- $wpdb->query("alter table $table_name engine = MyISAM;");
 
1093
  }
1094
- }
1095
 
1096
 
1097
- $res = $wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1098
  WHERE TABLE_NAME = '$table_name'
1099
  AND table_schema = DATABASE()
1100
  AND COLUMN_NAME = 'redirect_from' ");
1101
-
1102
- if ($res == '0') {
1103
 
1104
- $sql = "
 
 
1105
  ALTER TABLE $table_name
1106
  ADD COLUMN `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL;
1107
  ";
1108
- $wpdb->query($sql);
1109
- }
1110
 
1111
 
1112
- $table_name = $table_prefix . 'WP_SEO_404_links';
1113
- if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1114
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1115
  `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1116
  `ctime` datetime NOT NULL,
1117
  `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
@@ -1124,19 +1118,19 @@ function WPSR_install()
1124
  UNIQUE KEY `link` (`link`)
1125
  ) ENGINE = MyISAM ;
1126
  ";
1127
- $wpdb->query($sql);
1128
- } else {
1129
- //check if Innodb convert it to myisam.
1130
- $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1131
- if ($status->Engine == 'InnoDB') {
1132
- $wpdb->query("alter table $table_name engine = MyISAM;");
 
1133
  }
1134
- }
1135
 
1136
 
1137
- $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
1138
- if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1139
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1140
  `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1141
  `rID` int(11) unsigned DEFAULT NULL,
1142
  `postID` int(11) unsigned DEFAULT NULL,
@@ -1154,75 +1148,78 @@ function WPSR_install()
1154
  ) ENGINE = MyISAM ;
1155
  ";
1156
 
1157
- $wpdb->query($sql);
1158
- } else {
1159
- //check if Innodb convert it to myisam.
1160
- $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1161
- if ($status->Engine == 'InnoDB') {
1162
- $wpdb->query("alter table $table_name engine = MyISAM;");
1163
- }
1164
-
1165
- $res = $wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1166
  WHERE TABLE_NAME = '$table_name'
1167
  AND table_schema = DATABASE()
1168
  AND COLUMN_NAME = 'postID' ");
1169
-
1170
- if ($res == '0') {
1171
 
1172
- $sql = "
 
 
1173
  ALTER TABLE $table_name
1174
  ADD COLUMN `postID` int(11) unsigned DEFAULT NULL;
1175
  ";
1176
- $wpdb->query($sql);
1177
- }
1178
-
1179
-
 
 
1180
  }
1181
 
1182
  }
 
1183
 
 
1184
 
1185
- //---------------------------------------------------------------
 
 
1186
 
 
 
1187
 
1188
- function WPSR_uninstall()
1189
- {
1190
- global $wpdb, $table_prefix;
1191
 
1192
- $util = new clogica_util_1();
1193
- $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
1194
 
 
 
1195
 
1196
- if ($util->get_option_value('keep_data') != '1') {
 
1197
 
1198
- $table_name = $table_prefix . 'WP_SEO_Redirection';
1199
- $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1200
 
1201
- $table_name = $table_prefix . 'WP_SEO_Cache';
1202
- $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1203
 
1204
- $table_name = $table_prefix . 'WP_SEO_404_links';
1205
- $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1206
 
1207
- $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
1208
- $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1209
 
1210
 
1211
- $util->delete_my_options();
1212
  }
1213
 
1214
-
1215
  }
1216
-
1217
-
1218
  //---------------------------------------------------------------
 
1219
 
1220
- function WPSR_HideMessageAjaxFunction()
1221
- {
1222
- add_option('nsr_upgrade_message', 'yes');
 
1223
  }
1224
-
1225
  //---------------------------------------------------------------
 
1226
 
1227
  /* display import from redirection plugin in admin notice */
1228
  function WPSR_admin_notice_callback() {
@@ -1261,6 +1258,8 @@ function WPSR_admin_notice_callback() {
1261
  }
1262
  }
1263
  add_action( 'admin_notices', 'WPSR_admin_notice_callback' );
 
 
1264
 
1265
  add_action('admin_footer','WPSR_import_popup_in_footer');
1266
  function WPSR_import_popup_in_footer()
@@ -1303,7 +1302,7 @@ function WPSR_import_popup_in_footer()
1303
  </div>
1304
  <div class="modal-footer">
1305
  <input class="button-primary" id="btnImport" type="button" value="Import It" onclick="return import_function(<?php echo esc_js($total_org); ?>,0)">
1306
- <input type="hidden" id="_wpnonce" name="_wpnonce" value="<?php echo $nonce = wp_create_nonce('seoredirection_import'); ?>" />
1307
  <input data-dismiss="modal" aria-label="Close" class="button-primary " type="button" value="Cancel" name="cancel">
1308
  </div>
1309
  </div>
@@ -1315,64 +1314,65 @@ function WPSR_import_popup_in_footer()
1315
  }
1316
  }
1317
  }
 
 
1318
 
1319
- add_action('wp_ajax_sr_dismiss_notice','WPSR_dismiss_notice_callback');
1320
- function WPSR_dismiss_notice_callback()
1321
- {
1322
- global $current_user;
1323
- $user_id = $current_user->ID;
1324
- update_user_meta( $user_id, 'sr_notice_dismissed', '1');
1325
- echo "1";
1326
- exit;
 
1327
  }
1328
- function WPSR_getRedirectCount()
1329
- {
1330
- global $wpdb;
1331
-
1332
- $table_name_ = $wpdb->prefix . 'redirection_items';
1333
- if (strtolower($wpdb->get_var("show tables like '$table_name_'")) == strtolower($table_name_))
1334
- {
1335
- $result = $wpdb->get_results("SELECT url FROM {$wpdb->prefix}redirection_items");
1336
- $cnt=0;
1337
- $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
1338
- if($result)
1339
- {
1340
- foreach($result as $redirect)
1341
- {
1342
- $redirect_from = stripslashes($redirect->url);
1343
- $redirect_from_slash = ltrim(stripslashes($redirect->url),'/');
1344
- $redirectID = $wpdb->get_var($wpdb->prepare("select ID from $table_name where redirect_from=%s or redirect_from=%s", $redirect_from,$redirect_from_slash));
1345
- if($redirectID >0)
1346
- {
1347
-
1348
- }
1349
- else
1350
- {
1351
- $cnt++;
1352
- }
1353
- }
1354
-
1355
- }
1356
- return $cnt;
1357
- }else{
1358
- return 0;
1359
- }
1360
  }
1361
- add_action('admin_init','SR_init_delete_callback');
1362
- function SR_init_delete_callback()
1363
- {
1364
- if(isset($_POST['redirect_id']) && count($_POST['redirect_id']) > 0)
1365
- {
1366
-
1367
- global $wpdb,$table_prefix,$util;
1368
- $table_name = $wpdb->prefix. 'WP_SEO_Redirection';
1369
- foreach($_POST['redirect_id'] as $post_id)
1370
- {
1371
- $post_id = (int) $post_id;
1372
- $wpdb->query($wpdb->prepare(" delete from $table_name where ID=%s ",$post_id));
1373
- $SR_redirect_cache = new free_SR_redirect_cache();
1374
- $SR_redirect_cache->free_cache();
1375
- }
1376
-
1377
- }
 
1378
  }
1
  <?php
2
  /*
3
  Plugin Name: SEO Redirection
4
+ Plugin URI: https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/
5
  Description: By this plugin you can manage all your website redirection types easily.
6
+ Author: wp-buy
7
+ Version: 7.6
8
+ Author URI: https://www.wp-buy.com
9
  Text Domain: seo-redirection
10
  */
11
 
42
 
43
  /////////////////////////////////////////////////////////////////////////
44
 
45
+ if(!function_exists("WPSR_multiple_plugin_activate_trial")){
46
+ function WPSR_multiple_plugin_activate_trial()
47
+ {
48
+ global $wpdb;
49
+ if (is_multisite()) {
50
+ if (is_plugin_active_for_network(__FILE__)) {
51
+ $blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
52
+ foreach ($blogids as $blog_id) {
53
+ switch_to_blog($blog_id);
54
+ }
55
  }
56
  }
57
  }
58
+
59
+ register_activation_hook(__FILE__, 'WPSR_multiple_plugin_activate_trial');
60
+
61
  }
62
 
63
+ if(!function_exists("WPSR_adding_custom_meta_boxes")) {
64
 
65
+ function WPSR_adding_custom_meta_boxes()
66
+ {
67
+ global $util;
68
+ if ($util->get_option_value('show_redirect_box') == '1') {
69
 
70
+ $screens = array('post', 'page');
 
 
 
71
 
72
+ foreach ($screens as $screen) {
73
 
74
+ add_meta_box(
75
+ 'WPSR_meta_box',
76
+ __('SEO Redirection'),
77
+ 'WPSR_render_meta_box',
78
+ $screen
79
+ );
80
+ }
81
 
 
 
 
 
 
 
82
  }
 
83
  }
84
  }
85
+ if(!function_exists("WPSR_render_meta_box")) {
86
 
87
+ function WPSR_render_meta_box($post)
88
+ {
89
+ global $wpdb, $table_prefix, $util;
90
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
91
 
92
+ if (get_post_status() != 'auto-draft') {
93
+ $permalink = "";
94
+ if (in_array($post->post_status, array('draft', 'pending'))) {
95
+ list($permalink, $postname) = get_sample_permalink($post->ID);
96
+ $permalink = str_replace('%postname%', $postname, $permalink);
 
 
 
 
 
97
 
98
+ } else {
99
 
100
+ $permalink = get_permalink($post->ID);
101
+ }
102
 
103
+ $permalink = $util->make_relative_url(urldecode($permalink));
104
 
105
+ $postID = $post->ID;
106
 
107
 
108
+ $theurl = $wpdb->get_row($wpdb->prepare(" select redirect_to,redirect_from from $table_name where postID=%d ", $postID));
109
 
110
+ $urlredirect_to = '';
111
+ if ($wpdb->num_rows > 0)
112
+ $urlredirect_to = $theurl->redirect_to;
113
 
114
+ if ($urlredirect_to != '' && $theurl->redirect_from != $permalink) {
115
+ // the post_name field changed!
116
+ $wpdb->query($wpdb->prepare(" update $table_name set redirect_from=%s where postID=%d ", $permalink, $postID));
117
+ if ($util->get_option_value('reflect_modifications') == '1') {
118
+ $wpdb->query($wpdb->prepare(" update $table_name set redirect_to=%s where redirect_to=%s ", $permalink, $theurl->redirect_from));
119
+ $util->info_option_msg('<b>' . __("SEO Redirection", 'seo-redirection') . '</b>' . __('has detected a change in Permalink, this will be reflected to the redirection records!', 'seo-redirection'));
120
+ }
121
+ //-------------------------------------------
122
  }
 
 
123
 
124
+ echo '
125
  <table border="0" width="100%" cellpadding="2">
126
  <tr>
127
  <td width="99%"><input onchange="redirect_check_click()" type="checkbox" name="redirect_check" id="redirect_check" value="ON">
138
  <tr>
139
  <td>
140
  <ul>
141
+ <li>' . __(" To make a redirection, put the", 'seo-redirection') . ' <b>' . __("URL", 'seo-redirection') . '</b> ' . __("in the text field above and then click the button ", 'seo-redirection') . '<b>' . __("Update", 'seo-redirection') . '</b>.</li>
142
  <li>' . __("If you have a caching plugin installed, clear cache to reflect the
143
  changes immediately.", 'seo-redirection') . '</li>
144
 
149
  </table>
150
  </div>';
151
 
152
+ echo "
153
 
154
  <script type='text/javascript'>
155
  function WSR_check_status(x)
178
  </script>
179
  ";
180
 
181
+ if ($urlredirect_to == '')
182
+ echo "<script type='text/javascript'>WSR_check_status(0);</script>";
183
+ else
184
+ echo "<script type='text/javascript'>WSR_check_status(1);</script>";
185
 
186
 
187
+ } else {
188
+ echo __('You can not make a redirection for the new posts before saving them.', 'seo-redirection');
189
+ }
190
  }
191
  }
192
 
 
193
  //--------------------------------------------------------------------------------------------
194
 
195
  //---------------------------------------------------------------
196
  // added 2/2/2020
197
+ if(!function_exists("WPSR_get_site_404_page_path")) {
198
+
199
+ function WPSR_get_site_404_page_path()
200
+ {
201
+ $url = str_ireplace("://", "", site_url());
202
+ $site_404_page = substr($url, stripos($url, "/"));
203
+
204
+ if (stripos($url, "/") === FALSE || $site_404_page == "/")
205
+ $site_404_page = "/index.php?error=404";
206
+ else
207
+ $site_404_page = $site_404_page . "/index.php?error=404";
208
+
209
+ return $site_404_page;
210
+ }
211
+
212
  }
213
  //---------------------------------------------------------------
214
  // updated 2/2/2020
215
+
216
+ function WPSR_check_default_permalink()
217
  {
218
  $file= get_home_path() . "/.htaccess";
219
  $content="ErrorDocument 404 " . WPSR_get_site_404_page_path();
245
  * @since 0.1
246
  * @return mixed
247
  */
248
+ if(!function_exists("WPSR_sanitize_text_or_array_field")) {
249
+
250
+ function WPSR_sanitize_text_or_array_field($array_or_string)
251
+ {
252
+ if (is_string($array_or_string)) {
253
+ $array_or_string = sanitize_text_field($array_or_string);
254
+ } elseif (is_array($array_or_string)) {
255
+ foreach ($array_or_string as $key => &$value) {
256
+ if (is_array($value)) {
257
+ $value = WPSR_sanitize_text_or_array_field($value);
258
+ } else {
259
+ $value = sanitize_text_field($value);
260
+ }
261
  }
262
  }
 
263
 
264
+ return $array_or_string;
265
+ }
266
  }
267
+ if(!function_exists("WPSR_get_post_redirection")) {
268
 
269
+ function WPSR_get_post_redirection($post_id)
270
+ {
271
 
272
+ global $wpdb, $util, $table_prefix;
273
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
 
 
 
274
 
275
  // Autosave
276
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
277
+ return;
278
  // AJAX
279
+ if (defined('DOING_AJAX') && DOING_AJAX)
280
+ return;
281
  // Post revision
282
+ if (false !== wp_is_post_revision($post_id))
283
+ return;
284
 
285
+ $redirect_from = isset($_POST['wp_seo_redirection_url_from']) ? WPSR_sanitize_text_or_array_field($_POST['wp_seo_redirection_url_from']) : '';
286
+ $redirect_to = isset($_POST['wp_seo_redirection_url']) ? WPSR_sanitize_text_or_array_field($_POST['wp_seo_redirection_url']) : '';
287
 
288
+ if ($redirect_to != '') {
289
 
290
 
291
+ $wpdb->get_results($wpdb->prepare("select ID from $table_name where postID=%d ", $post_id));
292
 
293
+ if ($wpdb->num_rows > 0) {
294
+
295
+ $sql = $wpdb->prepare("update $table_name set redirect_to=%s,redirect_from=%s,redirect_type='301',url_type=2 where postID=%d", $redirect_to, $redirect_from, $post_id);
296
+ $wpdb->query($sql);
297
+
298
+ } else {
299
+ $wpdb->query($wpdb->prepare("delete from $table_name where redirect_from=%s", $redirect_from));
300
+ $sql = $wpdb->prepare("insert into $table_name(redirect_from,redirect_to,redirect_type,url_type,postID) values (%s,%s,'301',2,%d) ", $redirect_from, $redirect_to, $post_id);
301
+ $wpdb->query($sql);
302
+ }
303
 
 
 
304
 
305
  } else {
306
+ $wpdb->query($wpdb->prepare("delete from $table_name where postID=%d", $post_id));
 
 
307
  }
308
 
309
+ $SR_redirect_cache = new free_SR_redirect_cache();
310
+ $SR_redirect_cache->free_cache();
 
311
  }
312
 
 
 
313
  }
 
 
314
  //-------------------------------------------------------------
315
+ if(!function_exists("WPSR_log_404_redirection")) {
316
 
317
+ function WPSR_log_404_redirection($link)
318
+ {
319
+ global $wpdb, $table_prefix, $util;
320
+ $table_name = $table_prefix . 'WP_SEO_404_links';
321
 
322
+ $referrer = $util->get_ref();
323
+ $ip = $util->get_visitor_IP();
324
+ $country = "";//$util->get_visitor_country();
325
+ $os = $util->get_visitor_OS();
326
+ $browser = $util->get_visitor_Browser();
327
 
328
+ if ($os != 'Unknown' || $browser != 'Unknown') {
329
+ $wpdb->query($wpdb->prepare(" insert IGNORE into $table_name(ctime,link,referrer,ip,country,os,browser) values(NOW(),%s,%s,%s,%s,%s,%s) ", $link, $referrer, $ip, $country, $os, $browser));
330
+ }
331
  }
 
 
332
 
333
+ }
334
  //-------------------------------------------------------------
335
+ if(!function_exists("WPSR_log_redirection_history")) {
336
 
337
+ function WPSR_log_redirection_history($rID, $postID, $rfrom, $rto, $rtype, $rsrc)
338
+ {
339
+ global $wpdb, $table_prefix, $util;
340
+ $SR_redirect_cache = new free_SR_redirect_cache();
341
+ $SR_redirect_cache->free_cache();
342
+ $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
343
+ $rfrom = esc_url($rfrom);
344
+ $referrer = $util->get_ref();
345
+ $ip = $util->get_visitor_IP();
346
+ $country = "";//$util->get_visitor_country();
347
+ $os = $util->get_visitor_OS();
348
+ $browser = $util->get_visitor_Browser();
349
 
350
+ $wpdb->query($wpdb->prepare(" insert into $table_name(rID,postID,rfrom,rto,rtype,rsrc,ctime,referrer,ip,country,os,browser) values(%d ,%d,%s,%s,%s,%s,NOW(),%s,%s,%s,%s,%s) ", $rID, $postID, $rfrom, $rto, $rtype, $rsrc, $referrer, $ip, $country, $os, $browser));
351
 
352
+ $limit = $util->get_option_value('history_limit');
353
 
354
+ $expdate = date('Y-n-j', time() - (intval($limit) * 24 * 60 * 60));
355
+ $wpdb->query("delete FROM $table_name WHERE date_format(date(ctime),'%Y-%m-%d') < date_format(date('$expdate'),'%Y-%m-%d')");
356
 
357
 
358
+ }
359
  }
 
360
  //-------------------------------------------------------------
361
+ if(!function_exists("WPSR_make_redirect")) {
362
 
363
+ function WPSR_make_redirect($redirect_to, $redirect_type, $redirect_from, $obj = '')
 
 
 
 
 
 
 
 
 
 
 
 
 
364
  {
365
+ global $wpdb, $util, $table_prefix, $post;
366
+ if (is_admin()) {
367
+ return 0;
 
 
 
 
 
368
  }
369
+ $SR_redirect_cache = new free_SR_redirect_cache();
370
+ if ($redirect_to == $redirect_from || !$util->is_valid_url($redirect_to))
371
+ return 0;
372
+
373
+ if ($util->make_relative_url($redirect_from) == $util->make_relative_url($redirect_to))
374
+ return 0;
375
+
376
+ if (substr($redirect_from, -1) == "/" || substr($redirect_to, -1) == "/") {
377
+ if (substr($redirect_from, -1) != "/") {
378
+ if (($redirect_from . "/") == $redirect_to)
379
+ return 0;
380
+ } else {
381
+ if (($redirect_to . "/") == $redirect_from)
382
+ return 0;
383
+ }
384
+ }
385
+
386
+
387
+ if ($util->make_relative_url($redirect_from) == $util->make_relative_url($redirect_to))
388
+ return 0;
389
+
390
+ if (is_object($obj)) {
391
+ if ($obj->ID > 0) {
392
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
393
+ $sql = "update " . $table_name . " set hits=hits+1, access_date= NOW() where ID='" . $obj->ID . "'";
394
+ $wpdb->query($sql);
395
+ }
396
  }
 
 
 
397
 
398
+ if (is_object($obj) && $obj->redirect_to_type == 'Folder' && $obj->redirect_to_folder_settings == '2') {
399
 
400
+ if ($obj->redirect_from_type == 'Folder') {
401
+
402
+ if ($obj->redirect_from_folder_settings == '2' || $obj->redirect_from_folder_settings == '3') {
403
+ if (strlen($redirect_from) > strlen($obj->redirect_from)) {
404
+ $difference = substr($redirect_from, intval(strlen($obj->redirect_from) - strlen($redirect_from)));
405
+ $redirect_to = $redirect_to . $difference;
406
+ }
407
  }
408
+
409
+ } else if ($obj->redirect_from_type == 'Regex') {
410
+ $page = substr(strrchr($redirect_from, "/"), 1);
411
+ $redirect_to = $redirect_to . '/' . $page;
412
  }
413
 
 
 
 
414
  }
415
 
416
+ $rID = 0;
417
+ $rsrc = '404';
418
+ $postID = 0;
419
 
420
+ if (is_object($obj)) {
421
+ $rID = $obj->ID;
422
+ $postID = $obj->postID;
423
+ if ($obj->url_type == 1)
424
+ $rsrc = 'Custom';
425
+ else if ($obj->url_type == 2)
426
+ $rsrc = 'Post';
427
 
428
+ }
 
 
 
 
 
 
429
 
430
+ if ($util->get_option_value('history_status') == '1') {
431
 
432
+ WPSR_log_redirection_history($rID, $postID, $redirect_from, $redirect_to, $redirect_type, $rsrc);
433
+ }
434
 
435
+ $redirect_to = $util->make_absolute_url($redirect_to);
 
436
 
 
437
 
438
+ if (is_singular()) {
439
+ //$SR_redirect_cache = new free_SR_redirect_cache();
440
 
441
+ $SR_redirect_cache->add_redirect($post->ID, 1, $redirect_from, $redirect_to, $redirect_type);
442
+ $SR_redirect_cache->free_cache();
443
+ }
444
 
445
+ if ($redirect_type == '301') {
446
+ header('HTTP/1.1 301 Moved Permanently');
447
+ header("Location: " . $redirect_to);
448
+ exit();
449
+ } else if ($redirect_type == '307') {
450
+ header('HTTP/1.0 307 Temporary Redirect');
451
+ header("Location: " . $redirect_to);
452
+ exit();
453
+ } else if ($redirect_type == '302') {
454
+ header("Location: " . $redirect_to);
455
+ exit();
456
+ }
 
 
 
 
457
 
458
+ }
459
  }
460
 
 
461
  //-------------------------------------------------------------
462
+ if(!function_exists("WPSR_redirect")) {
463
 
464
+ function WPSR_redirect()
465
+ {
466
+ global $wpdb, $post, $table_prefix, $util;
 
467
 
 
468
 
469
+ if ($util->get_option_value('plugin_status') != '0') { // if not disabled
 
 
470
 
471
+ // if disable for admin and the user is admin
472
+ if (current_user_can('manage_options') == 1 && $util->get_option_value('plugin_status') == 2) {
473
+ // nothing
474
 
 
 
 
 
 
 
 
 
 
475
  } else {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
476
 
477
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
478
+ $permalink = urldecode($util->get_current_relative_url());
479
+ if (substr($permalink, 0, 1) == ":") {
480
+ $first_slash = stripos($permalink, "/");
481
+ $permalink = substr($permalink, $first_slash, strlen($permalink) - $first_slash);
482
+ }
483
+ $permalink_alternative = "";
484
+ if (substr($permalink, -1) == '/') {
485
+ $permalink_alternative = substr($permalink, 0, intval(strlen($permalink) - 1));
486
+ } else {
487
+ $permalink_alternative = $permalink . '/';
488
  }
489
 
490
+ $post_cache_result = "";
491
+ $SR_redirect_cache = new free_SR_redirect_cache();
492
+ if (is_singular()) {
493
+ $post_cache_result = $SR_redirect_cache->redirect_cached($post->ID);
494
  }
495
+ if ($post_cache_result == 'not_redirected') {
496
+ return 0;
497
+ }
498
+
499
+ $permalink_options = $wpdb->prepare("( redirect_from = %s OR redirect_from = %s)", $permalink, $permalink_alternative);
500
+
501
+ $permalink_regex_options = $wpdb->prepare("(%s regexp regex or %s regexp regex )", $permalink, $permalink_alternative);
502
 
503
+ if (($util->get_option_value('redirect_control_panel') != '1') || ($util->get_option_value('redirect_control_panel') == '1' && !preg_match('/^' . str_replace('/', '\/', get_admin_url()) . '/i', $permalink) && !preg_match('/^' . str_replace('/', '\/', site_url()) . '\/wp-login.php/i', $permalink))) {
504
 
 
505
 
506
+ $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex='' and $permalink_options ");
507
+ if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
508
+ WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
509
  }
510
 
511
+ $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex<>'' and $permalink_regex_options order by LENGTH(regex) desc ");
512
+ if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
513
+ WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
514
+ }
515
+
516
+
517
+ if (is_404()) {
518
+
519
+ if ($util->get_option_value('p404_discovery_status') == '1') {
520
+ WPSR_log_404_redirection($permalink);
521
+ }
522
+
523
+ $options = $util->get_my_options();
524
+ if ($options['p404_status'] == '1') {
525
 
526
+ WPSR_make_redirect($options['p404_redirect_to'], '301', $permalink);
527
 
528
+ }
529
  }
530
  }
531
+
532
+ if (is_singular() && $post_cache_result == 'not_found') {
 
533
  $SR_redirect_cache->add_redirect($post->ID, 0, '', '', 0);
534
+ }
535
 
536
+ }
537
  }
538
  }
539
  }
 
540
  //---------------------------------------------------------------
541
+ if(!function_exists("WPSR_header_code")) {
542
 
543
+ function WPSR_header_code()
 
 
 
 
 
544
  {
545
+ //wp_enqueue_script('ajaxcustomvar');
546
+ /* condition removed to display import popup on Import button(admin notioce message) click on any admin page*/
547
+ if (is_admin() && array_key_exists('page', $_GET) && $_GET['page'] == 'seo-redirection.php') {
548
 
549
+ wp_register_style('c_admin_css_common', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "style.css");
550
+ wp_enqueue_style('sweetalert', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "sweetalert.css");
551
+ wp_register_style('c_admin_css_custom', plugins_url() . '/' . basename(dirname(__FILE__)) . '/custom/' . "style.css");
552
+ wp_enqueue_script('jquery');
553
+ wp_localize_script('jquery', 'seoredirection', array('ajax_url' => admin_url('admin-ajax.php'), 'msg' => ""));
554
+ wp_enqueue_style('c_admin_css_common');
555
+ wp_enqueue_style('c_admin_css_custom');
556
 
557
+ wp_enqueue_script('custom', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/js/' . 'bootstrap.min.js', array('jquery'), false, true);
558
+ wp_enqueue_script('customJS', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "customJs.js", array('jquery'), false, true);
559
+ wp_enqueue_script('sweetalert', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/js/' . "sweetalert.min.js", array('jquery'), false, true);
560
 
561
+ wp_enqueue_style('bootstrap', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "bootstrap.css");
562
 
563
 
564
+ }
565
  }
566
  }
 
567
  //---------------------------------------------------------------
568
+ if(!function_exists("WPSR_customAddUpdate_callback")) {
569
+
570
+ add_action("wp_ajax_customAddUpdate", "WPSR_customAddUpdate_callback");
571
+
572
+ function WPSR_customAddUpdate_callback()
573
+ {
574
+ global $wpdb, $table_prefix, $util;
575
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
576
+ $table_name_404 = $table_prefix . 'WP_SEO_404_links';
577
+ parse_str($_POST['formData'], $_POST);
578
+ $nonce = "";
579
+ if (isset($_POST['_wpnonce']))
580
+ $nonce = WPSR_sanitize_text_or_array_field($_POST['_wpnonce']);
581
+ $data = array();
582
+ $data['error_string'] = array();
583
+ $data['inputerror'] = array();
584
+ $data['bool'] = TRUE;
585
+ if (trim($_POST['redirect_from']) == '') {
586
+ $data['inputerror'][] = 'redirect_from';
587
+ $data['error_string'][] = __("You must input the 'Redirect From' URL", "seo-redirection");
588
+ $data['bool'] = FALSE;
589
+ }
590
+
591
+ $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
592
+
593
+ $wpdb->get_results(" select ID from $table_name where redirect_from='" . trim($redirect_from) . "' ");
594
+ if ($wpdb->num_rows > 0) {
595
+ $data['inputerror'][] = 'redirect_from';
596
+ $data['error_string'][] = __("This 'Redirect From' value already exists in database!", "seo-redirection");
597
+ $data['bool'] = FALSE;
598
+ }
599
 
 
600
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
601
  // elseif (!preg_match( '/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/', $_POST['redirect_from'])) {
602
  // $data['inputerror'][] = 'redirect_from';
603
  // $data['error_string'][] = __("Invalid redirect from target URL!",'seo-redirection');
604
  // $data['bool'] = FALSE;
605
  // }
606
+ if (trim($_POST['redirect_to']) == '') {
607
+ $data['inputerror'][] = 'redirect_to';
608
+ $data['error_string'][] = __("You must input the 'Redirect To' URL", "seo-redirection");
609
+ $data['bool'] = FALSE;
610
+ } elseif ($_POST['edit_exist'] == '' && substr(strtolower($_POST['redirect_to']), 0, 4) != "http" && substr(strtolower($_POST['redirect_to']), 0, 1) != "/") {
611
+ $data['inputerror'][] = 'redirect_to';
612
+ $data['error_string'][] = __("Invalid redirect target URL!", 'seo-redirection');
613
+ $data['bool'] = FALSE;
614
+ }
615
+ if ($data['bool'] === FALSE) {
616
+ echo json_encode($data);
617
+ exit();
618
+ } else {
619
+ if ($_POST['redirect_from'] != '' && wp_verify_nonce($nonce, 'seoredirection')) {
 
 
 
 
 
620
 
 
621
 
622
+ $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
623
+ $redirect_to = isset($_POST['redirect_to']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_to']) : '';
624
 
 
 
 
625
 
626
+ $redirect_from = urldecode($util->make_relative_url($redirect_from));
 
627
 
628
+ $redirect_to = $util->make_relative_url($redirect_to);
629
+ $redirect_type = WPSR_sanitize_text_or_array_field($_POST['redirect_type']);
630
 
631
+ $redirect_from_type = WPSR_sanitize_text_or_array_field($_POST['redirect_from_type']);
632
+ $redirect_from_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_from_folder_settings']);
633
+ $redirect_from_subfolders = WPSR_sanitize_text_or_array_field($_POST['redirect_from_subfolders']);
634
 
635
+ $redirect_to_type = WPSR_sanitize_text_or_array_field($_POST['redirect_to_type']);
636
+ $redirect_to_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_to_folder_settings']);
637
 
638
+ $enabled = WPSR_sanitize_text_or_array_field($_POST['enabled']);
 
639
 
640
+ $regex = "";
641
+
642
+ if ($redirect_from_type == 'Folder') {
643
+
644
+ if (substr($redirect_from, -1) != '/')
645
+ $redirect_from = $redirect_from . '/';
646
+
647
+ if ($redirect_from_folder_settings == 2) {
648
+ if ($redirect_from_subfolders == 0) {
649
+ $regex = '^' . $util->regex_prepare($redirect_from) . '.*';;
650
+ } else {
651
+ $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]*$';
652
+ }
653
+ } else if ($redirect_from_folder_settings == 3) {
654
+ if ($redirect_from_subfolders == 0) {
655
+ $regex = '^' . $util->regex_prepare($redirect_from) . '.+';
656
+ } else {
657
+ $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]+$';
658
+ }
659
  }
 
660
 
661
+ } else if ($redirect_from_type == 'Regex') {
662
+ $regex = $redirect_from;
663
+ }
664
 
665
+ if ($redirect_from_type == 'Page' || $redirect_from_type == 'Regex') {
666
+ $redirect_from_folder_settings = "";
667
+ $redirect_from_subfolders = "";
668
+ }
669
 
670
+ if ($redirect_to_type == 'Page') {
671
+ $redirect_to_folder_settings = "";
672
+ }
673
 
674
+ if ($redirect_to_type == 'Folder') {
675
+ if (substr($redirect_to, -1) != '/')
676
+ $redirect_to = $redirect_to . '/';
677
+ }
678
 
679
 
680
+ if ($_POST['add_new'] != '') {
681
 
682
+ $theurl = $wpdb->get_row($wpdb->prepare(" select count(ID) as cnt from $table_name where redirect_from=%s ", $redirect_from));
683
 
684
+ if ($theurl->cnt > 0) {
685
+ $msg = __("This URL", 'seo-redirection') . " <b>".esc_html($redirect_from)."</b>" . __("is added previously!", 'seo-redirection');
686
+ echo json_encode(array('status' => 'error', 'msg' => $msg));
687
  // $util->failure_option_msg(__("This URL",'seo-redirection')." <b>'$redirect_from'</b>". __("is added previously!",'seo-redirection'));
688
+ } else {
689
+
690
+
691
+ if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
692
+ $util->failure_option_msg(__('Please input all required fields!', 'seo-redirection'));
693
+ } else {
694
+
695
+ $wpdb->insert($table_name, array(
696
+ 'redirect_from' => $redirect_from,
697
+ 'redirect_to' => $redirect_to,
698
+ 'redirect_type' => $redirect_type,
699
+ 'url_type' => 1,
700
+ 'redirect_from_type' => $redirect_from_type,
701
+ 'redirect_from_folder_settings' => $redirect_from_folder_settings,
702
+ 'redirect_from_subfolders' => $redirect_from_subfolders,
703
+ 'redirect_to_type' => $redirect_to_type,
704
+ 'redirect_to_folder_settings' => $redirect_to_folder_settings,
705
+ 'regex' => $regex,
706
+ 'enabled' => $enabled
707
+
708
+ ));
709
+
710
+ $wpdb->query($wpdb->prepare(" delete from $table_name_404 where link=%s ", $redirect_from));
711
+ $SR_redirect_cache = new free_SR_redirect_cache();
712
+ $SR_redirect_cache->free_cache();
713
+ $msg = "Redirection Added Successfully";
714
+ echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
715
+ die;
716
+ }
717
+
718
+ }
719
+ } else if ($_POST['edit_exist'] != '') {
720
 
721
+ $edit = WPSR_sanitize_text_or_array_field($_POST['edit']);
722
 
723
  if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
724
+ $util->failure_option_msg('Please input all required fields!');
725
  } else {
726
 
727
+ $wpdb->query($wpdb->prepare("update $table_name set redirect_from=%s,redirect_to=%s,redirect_type=%s,redirect_from_type=%s ,redirect_from_folder_settings=%d,redirect_from_subfolders=%d ,redirect_to_type=%s ,redirect_to_folder_settings=%d ,regex=%s,enabled=%s where ID=%d ", $redirect_from, $redirect_to, $redirect_type, $redirect_from_type, $redirect_from_folder_settings, $redirect_from_subfolders, $redirect_to_type, $redirect_to_folder_settings, $regex, $enabled, $edit));
728
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
729
  $SR_redirect_cache = new free_SR_redirect_cache();
730
  $SR_redirect_cache->free_cache();
 
 
 
731
  }
732
+ $msg = "Redirection Update Successfully";
733
+ echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
734
+ die;
735
 
736
  }
 
 
 
 
 
 
 
 
 
737
 
738
+ if ($util->there_is_cache() != '')
739
+ $util->info_option_msg(__("You have a cache plugin installed", 'seo-redirection') . " <b>'" . $util->there_is_cache() . "'</b>, " . __("you have to clear cache after any changes to get the changes reflected immediately! ", 'seo-redirection'));
 
 
 
 
740
 
741
  }
742
 
 
 
 
743
  }
744
 
 
 
745
 
746
+ die;
747
+ }
748
  }
749
+ if(!function_exists("WPSR_customUpdateRec_callback")) {
750
 
751
+ add_action("wp_ajax_customUpdateRec", "WPSR_customUpdateRec_callback");
752
+ function WPSR_customUpdateRec_callback()
753
+ {
754
 
755
 
756
+ global $wpdb, $table_prefix, $util;
757
 
758
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
759
+ $table_name_404 = $table_prefix . 'WP_SEO_404_links';
760
 
761
+ $myid = (int)$_POST['ID'];
762
+ $item = $wpdb->get_row($wpdb->prepare(" select * from $table_name where ID=%d ", $myid));
763
 
764
+ if ($wpdb->num_rows == 0) {
765
+ echo json_encode(array('status' => 'error', 'msg' => __("Sorry, this redirect rule is not found, it may deleted by the user!", 'seo-redirection')));
766
+ die;
767
+ }
768
 
769
 
770
+ $data = array(
771
+ "redirect_from" => $item->redirect_from,
772
+ "redirect_to" => $item->redirect_to,
773
+ "redirect_type" => $item->redirect_type,
774
 
775
+ "redirect_from_type" => $item->redirect_from_type,
776
+ "redirect_from_folder_settings" => $item->redirect_from_folder_settings,
777
+ "redirect_from_subfolders" => $item->redirect_from_subfolders,
778
 
779
+ "redirect_to_type" => $item->redirect_to_type,
780
+ "redirect_to_folder_settings" => $item->redirect_to_folder_settings,
781
 
782
+ "enabled" => $item->enabled
783
+ );
784
+ echo json_encode(array('status' => 'suucess', 'rec' => $data));
785
+ die;
786
+ }
787
  }
788
+ if(!function_exists("WPSR_importFromRedirection_callback")) {
789
 
790
+ add_action("wp_ajax_importFromRedirection", "WPSR_importFromRedirection_callback");
791
+ function WPSR_importFromRedirection_callback()
792
+ {
793
+ global $wpdb;
794
+
795
+ $plugins = get_option('active_plugins', array());
796
+ $found = false;
797
+ foreach ($plugins as $plugin) {
798
+ if (strpos(strval($plugin), 'redirection.php') == true && strpos(strval($plugin), 'seo-redirection.php') == FALSE) {
799
+ if (isset($_REQUEST['offset'])) {
800
+ $offset = WPSR_sanitize_text_or_array_field($_REQUEST['offset']);
801
+ $count = 0;
802
+ $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
803
+ $table_name_404 = $wpdb->prefix . 'WP_SEO_404_links';
804
+
805
+
806
+ $table_name_ = $wpdb->prefix . 'redirection_items';
807
+ if (strtolower($wpdb->get_var("show tables like '$table_name_'")) == strtolower($table_name_)) {
808
+
809
+
810
+ $redirects = $wpdb->get_results("SELECT * FROM {$wpdb->prefix}redirection_items order by id limit " . $offset . ",1");
811
+ if ($redirects) {
812
+ //print_r($redirects);
813
+ $udtcnt = 0;
814
+ $inscnt = 0;
815
+ foreach ($redirects as $redirect) {
816
+ $redirect_from = stripslashes($redirect->url);
817
+ $redirect_from_slash = ltrim(stripslashes($redirect->url), '/');
818
+ if ($redirect->status == "enabled")
819
+ $enabled = 1;
820
+ else
821
+ $enabled = 0;
822
+
823
+ $group_id = 1;
824
+ if ($redirect->group_id == "1") {
825
+ $group_id = 2;
826
+ } else if ($redirect->group_id == "2") {
827
+ $group_id = 3;
828
+ }
829
+
830
+ $redirect_from_type = $redirect->regex ? 'Regex' : 'Page';
831
+ $redirect_to_type = $redirect->regex ? 'Regex' : 'Page';
832
+ $regexp = $redirect->regex ? $redirect->url : '';
833
+ $redirectID = $wpdb->get_var($wpdb->prepare("select ID from $table_name where redirect_from=%s or redirect_from=%s", $redirect_from, $redirect_from_slash));
834
+
835
+ if ($redirectID > 0) {
836
+
837
+ $update = $wpdb->query($wpdb->prepare("update $table_name set redirect_from=%s,redirect_to=%s,redirect_type=%d, redirect_from_type=%s, redirect_to_type=%s,regex=%s,enabled=%d, grpID=%d,import_flag=%d, redirect_from_folder_settings=%d,redirect_from_subfolders=%d,redirect_to_folder_settings=%d where ID=%d", $redirect_from, stripslashes($redirect->action_data), intval($redirect->action_code, 10), $redirect_from_type, $redirect_to_type, $regexp, $enabled, $group_id, 1, 0, 0, 0, $redirectID));
838
+ if ($update) {
839
+ $udtcnt++;
840
+ }
841
+ } else {
842
+ $wpdb->insert($table_name, array(
843
+ 'redirect_from' => stripslashes($redirect->url),
844
+ 'redirect_to' => stripslashes($redirect->action_data),
845
+ 'redirect_type' => intval($redirect->action_code, 10),
846
+ 'url_type' => 1,
847
+ 'redirect_from_type' => $redirect->regex ? 'Regex' : 'Page',
848
+ 'redirect_from_folder_settings' => 0,
849
+ 'redirect_from_subfolders' => 0,
850
+ 'redirect_to_type' => $redirect->regex ? 'Regex' : 'Page',
851
+ 'redirect_to_folder_settings' => 0,
852
+ 'regex' => $redirect->regex ? $redirect->url : '',
853
+ 'enabled' => $enabled,
854
+ 'grpID' => $group_id,
855
+ 'import_flag' => 1,
856
+ ));
857
+
858
+ $inscnt++;
859
+ $wpdb->query($wpdb->prepare(" delete from $table_name_404 where link=%s ", $redirect_from));
860
+ $SR_redirect_cache = new free_SR_redirect_cache();
861
+ $SR_redirect_cache->free_cache();
862
+ }
863
+ }
864
+ $msg = __('Total ', 'seo-redirection') . '<span class="insert_cnt">' . $inscnt . '</span>' . __(' record(s) inserted and ', 'seo-redirection') . '<span class="update_cnt">' . $udtcnt . '</span>' . __(' record(s) updated.', 'seo-redirection');
865
+ echo json_encode(array('status' => 'success', 'updateCnt' => $udtcnt, 'insertCnt' => $inscnt, 'msg' => $msg));
866
+ } else {
867
+ $msg = __('No redirects found to import.', 'seo-redirection');
868
+ echo json_encode(array('status' => 'error', 'msg' => $msg));
869
+ }
870
+ }
871
+ } else {
872
+ $msg = __('Something went wrong plase try again.', 'seo-redirection');
873
+ echo json_encode(array('status' => 'error', 'msg' => $msg));
874
+ }
875
+ break;
876
+ }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
877
 
878
+ }
879
+ exit;
880
+ }
881
  }
882
+ if(!function_exists("WPSR_admin_menu")) {
883
 
884
+ function WPSR_admin_menu()
885
+ {
886
+ add_options_page('SEO Redirection', 'SEO Redirection', 'manage_options', basename(__FILE__), 'WPSR_options_menu');
887
+ }
888
+ }
889
  //---------------------------------------------------------------
890
+ if(!function_exists("WPSR_options_menu")) {
 
 
891
 
892
+ function WPSR_options_menu()
893
+ {
894
+ global $util;
895
 
896
+ if (!current_user_can('manage_options')) {
897
+ wp_die(__('You do not have sufficient permissions to access this page.', 'seo-redirection'));
898
+ }
899
 
 
 
 
 
 
 
900
 
901
+ if ($util->get_option_value('plugin_status') == '0') {
902
+ $util->info_option_msg(__('SEO Redirection is disabled now, you can go to option tab and enable it!', 'seo-redirection'));
903
+ } else if ($util->get_option_value('plugin_status') == '2') {
904
+ $util->info_option_msg(__('SEO Redirection is', 'seo-redirection') . ' <b>' . __('disabled for admin', 'seo-redirection') . '</b>' . __(' only, you can go to option tab and enable it!', 'seo-redirection'));
905
+ }
906
+ $total_404_errors = (WPSR_Get_total_404() > 10) ? __('You have', 'seo-redirection') . ' <b style="color:red; background-color:yellow; padding:3px;"> too many </b>' . __(' broken link (404 links)', 'seo-redirection') . ', <br>' : '';
907
 
 
908
 
909
+ echo '<div class="wrap"><h2>' . __("SEO Redirection Free", 'seo-redirection') . '</h2><b>' . __('Upgrade to', 'seo-redirection') . ' <a target="_blank" onclick="swal.clickConfirm();" href="http://www.clogica.com/product/seo-redirection-premium-wordpress-plugin">' . __("Pro Version", "seo-redirection") . '</a>' . __(" to manage 404 errors and empower your site SEO", "seo-redirection") . '&nbsp;&nbsp;&nbsp;<strong style="color:yellow; background-color:red; padding:3px;"> ' . __("NOW 50% OFF ", 'seo-redirection') . '</strong></b><br/><br/>';
 
 
 
910
 
 
911
 
912
+ if (is_multisite()) {
913
 
914
+ echo '<div class="error" id="message"><p></p><div class="warning_icon"></div>' . __('This version does not support Multisite WordPress installation, you may face troubles like losing redirects when adding new sites to your network, the premium version supports multisite well', 'seo-redirection') . '(<a target="_blank" href="http://www.clogica.com/product/seo-redirection-premium-wordpress-plugin">
915
+ http://www.clogica.com/product/seo-redirection-premium-wordpress-plugin</a>) <p></p></div>';
916
 
917
+ }
918
 
919
+ $mytabs = new phptab();
 
920
 
921
+ $mytabs->set_ignore_parameter(array('del', 'search', 'page_num', 'add', 'edit', 'page404', 'do_404_del'));
922
+ $mytabs->add_file_tab('cutom', __('Custom Redirects', 'seo-redirection'), 'option_page_custome_redirection.php', 'file');
923
+ $mytabs->add_file_tab('posts', __('Post Redirects', 'seo-redirection'), 'option_page_post_redirection_list.php', 'file');
924
+ $mytabs->add_file_tab('history', __('History', 'seo-redirection'), 'option_page_history.php', 'file');
925
+ $mytabs->add_file_tab('export_import', __('Export/Import', 'seo-redirection'), 'option_export_import.php', 'file');
926
+ $mytabs->add_file_tab('404', '<span style="color:red;"><b>404 Errors</b></span>', 'option_page_404.php', 'file');
927
+ $mytabs->add_file_tab('goptions', __('Options', 'seo-redirection'), 'option_page_goptions.php', 'file');
928
+ $mytabs->add_file_tab('help', '<span style="color:green;"><b>' . __('Help', 'seo-redirection') . '</b></span>', 'help.php', 'file');
929
+ $mytabs->add_file_tab('premium', '<span style="color:brown;"><b>&#9658; ' . __('Premium Features', 'seo-redirection') . '</b></span>', 'premium.php', 'file');
930
+ $mytabs->run();
 
 
 
 
931
 
932
  }
933
+ }
934
+ if(!function_exists("WPSR_upgrade")) {
935
 
936
+ function WPSR_upgrade()
937
+ {
938
 
939
+ $util = new clogica_util_1();
940
+ $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
 
 
 
941
 
942
+ if ($util->get_option_value('plugin_version') != WP_SEO_REDIRECTION_VERSION) {
943
+ WPSR_install();
944
+ $util->update_option('plugin_version', WP_SEO_REDIRECTION_VERSION);
945
+ }
946
  }
947
  }
 
948
  //-----------------------------------------------------
949
+ if(!function_exists("WPSR_install")) {
950
+
951
+ function WPSR_install()
952
+ {
953
+ global $wpdb, $table_prefix;
954
+
955
+ $util = new clogica_util_1();
956
+ $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
 
 
 
 
957
 
958
+ $options = get_option(WP_SEO_REDIRECTION_OPTIONS);
959
+ if (!is_array($options)) {
960
+ add_option(WP_SEO_REDIRECTION_OPTIONS);
961
+ $options = array();
962
+ }
963
 
 
 
964
 
965
+ if (!array_key_exists('plugin_status', $options))
966
+ $options['plugin_status'] = '1';
967
 
968
+ if (!array_key_exists('ip_logging_status', $options))
969
+ $options['ip_logging_status'] = '1';
970
 
971
+ if (!array_key_exists('redirection_base', $options))
972
+ $options['redirection_base'] = site_url();
973
 
974
+ if (!array_key_exists('redirect_control_panel', $options))
975
+ $options['redirect_control_panel'] = '1';
976
 
977
+ if (!array_key_exists('show_redirect_box', $options))
978
+ $options['show_redirect_box'] = '1';
979
 
980
+ if (!array_key_exists('reflect_modifications', $options))
981
+ $options['reflect_modifications'] = '1';
982
 
983
+ if (!array_key_exists('history_status', $options))
984
+ $options['history_status'] = '1';
985
 
986
+ if (!array_key_exists('history_limit', $options))
987
+ $options['history_limit'] = '30';
988
 
989
+ if (!array_key_exists('p404_discovery_status', $options))
990
+ $options['p404_discovery_status'] = '1';
991
 
992
+ if (!array_key_exists('p404_redirect_to', $options))
993
+ $options['p404_redirect_to'] = site_url();
994
 
995
+ if (!array_key_exists('p404_status', $options))
996
+ $options['p404_status'] = '2';
997
 
998
+ if (!array_key_exists('keep_data', $options))
999
+ $options['keep_data'] = '1';
1000
 
1001
+ update_option(WP_SEO_REDIRECTION_OPTIONS, $options);
1002
 
1003
+
1004
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
1005
+ if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1006
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1007
  `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1008
  `enabled` int(1) NOT NULL DEFAULT '1',
1009
  `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1023
  PRIMARY KEY (`ID`),
1024
  UNIQUE KEY `redirect_from` (`redirect_from`)
1025
  )ENGINE = MyISAM ;";
1026
+ $wpdb->query($sql);
 
 
 
 
 
 
 
 
 
 
 
1027
 
 
 
 
 
1028
 
1029
+ } else {
1030
+ //check if Innodb convert it to myisam.
1031
+ $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1032
+ if ($status->Engine == 'InnoDB') {
1033
+ $wpdb->query("alter table $table_name engine = MyISAM;");
1034
+ }
1035
+
1036
+ /* add column for import flag */
1037
+ $column_data = $wpdb->get_row("SHOW COLUMNS FROM $table_name LIKE 'import_flag'");
1038
+
1039
+ if (!$column_data) {
1040
+ $wpdb->query("ALTER TABLE $table_name ADD COLUMN import_flag tinyint(1) DEFAULT 0");
1041
+ }
1042
+
1043
+ // if the table exists
1044
+ $redirects = $wpdb->get_results(" select redirect_from,redirect_to,ID from $table_name; ");
1045
+ foreach ($redirects as $redirect) {
1046
+ $redirect_from = $util->make_relative_url($redirect->redirect_from);
1047
+ $redirect_to = $util->make_relative_url($redirect->redirect_to);
1048
+ $ID = $redirect->ID;
1049
+ $wpdb->query($wpdb->prepare(" update $table_name set redirect_from=%s,redirect_to=%s where ID=%d", $redirect_from, $redirect_to, $ID));
1050
+ }
1051
+
1052
+ // Fix add blog field if not exist.
1053
+ if ($wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1054
  WHERE TABLE_NAME = '$table_name'
1055
  AND table_schema = DATABASE()
1056
  AND COLUMN_NAME = 'hits' ") == '0') {
1057
 
1058
+ $sql = "
1059
  ALTER TABLE $table_name
1060
  ADD COLUMN `hits` int(11) unsigned NOT NULL DEFAULT 0,
1061
  ADD COLUMN `access_date` datetime DEFAULT NULL;
1062
  ";
1063
 
1064
+ $wpdb->query($sql);
1065
+ }
 
1066
 
 
1067
 
1068
+ }
1069
+
1070
+ $table_name = $table_prefix . 'WP_SEO_Cache';
1071
+ if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1072
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1073
  `ID` int(11) unsigned NOT NULL,
1074
  `is_redirected` int(1) unsigned NOT NULL,
1075
  `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1078
  PRIMARY KEY (`ID`)
1079
  ) ENGINE = MyISAM ;
1080
  ";
1081
+ $wpdb->query($sql);
1082
+ } else {
1083
+ //check if Innodb convert it to myisam.
1084
+ $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1085
+ if ($status->Engine == 'InnoDB') {
1086
+ $wpdb->query("alter table $table_name engine = MyISAM;");
1087
+ }
1088
  }
 
1089
 
1090
 
1091
+ $res = $wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1092
  WHERE TABLE_NAME = '$table_name'
1093
  AND table_schema = DATABASE()
1094
  AND COLUMN_NAME = 'redirect_from' ");
 
 
1095
 
1096
+ if ($res == '0') {
1097
+
1098
+ $sql = "
1099
  ALTER TABLE $table_name
1100
  ADD COLUMN `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL;
1101
  ";
1102
+ $wpdb->query($sql);
1103
+ }
1104
 
1105
 
1106
+ $table_name = $table_prefix . 'WP_SEO_404_links';
1107
+ if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1108
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1109
  `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1110
  `ctime` datetime NOT NULL,
1111
  `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1118
  UNIQUE KEY `link` (`link`)
1119
  ) ENGINE = MyISAM ;
1120
  ";
1121
+ $wpdb->query($sql);
1122
+ } else {
1123
+ //check if Innodb convert it to myisam.
1124
+ $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1125
+ if ($status->Engine == 'InnoDB') {
1126
+ $wpdb->query("alter table $table_name engine = MyISAM;");
1127
+ }
1128
  }
 
1129
 
1130
 
1131
+ $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
1132
+ if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1133
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1134
  `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1135
  `rID` int(11) unsigned DEFAULT NULL,
1136
  `postID` int(11) unsigned DEFAULT NULL,
1148
  ) ENGINE = MyISAM ;
1149
  ";
1150
 
1151
+ $wpdb->query($sql);
1152
+ } else {
1153
+ //check if Innodb convert it to myisam.
1154
+ $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1155
+ if ($status->Engine == 'InnoDB') {
1156
+ $wpdb->query("alter table $table_name engine = MyISAM;");
1157
+ }
1158
+
1159
+ $res = $wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1160
  WHERE TABLE_NAME = '$table_name'
1161
  AND table_schema = DATABASE()
1162
  AND COLUMN_NAME = 'postID' ");
 
 
1163
 
1164
+ if ($res == '0') {
1165
+
1166
+ $sql = "
1167
  ALTER TABLE $table_name
1168
  ADD COLUMN `postID` int(11) unsigned DEFAULT NULL;
1169
  ";
1170
+ $wpdb->query($sql);
1171
+ }
1172
+
1173
+
1174
+ }
1175
+
1176
  }
1177
 
1178
  }
1179
+ //---------------------------------------------------------------
1180
 
1181
+ if(!function_exists("WPSR_uninstall")) {
1182
 
1183
+ function WPSR_uninstall()
1184
+ {
1185
+ global $wpdb, $table_prefix;
1186
 
1187
+ $util = new clogica_util_1();
1188
+ $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
1189
 
 
 
 
1190
 
1191
+ if ($util->get_option_value('keep_data') != '1') {
 
1192
 
1193
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
1194
+ $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1195
 
1196
+ $table_name = $table_prefix . 'WP_SEO_Cache';
1197
+ $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1198
 
1199
+ $table_name = $table_prefix . 'WP_SEO_404_links';
1200
+ $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1201
 
1202
+ $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
1203
+ $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1204
 
 
 
1205
 
1206
+ $util->delete_my_options();
1207
+ }
1208
 
1209
 
 
1210
  }
1211
 
 
1212
  }
 
 
1213
  //---------------------------------------------------------------
1214
+ if(!function_exists("WPSR_HideMessageAjaxFunction")) {
1215
 
1216
+ function WPSR_HideMessageAjaxFunction()
1217
+ {
1218
+ add_option('nsr_upgrade_message', 'yes');
1219
+ }
1220
  }
 
1221
  //---------------------------------------------------------------
1222
+ if(!function_exists("WPSR_admin_notice_callback")) {
1223
 
1224
  /* display import from redirection plugin in admin notice */
1225
  function WPSR_admin_notice_callback() {
1258
  }
1259
  }
1260
  add_action( 'admin_notices', 'WPSR_admin_notice_callback' );
1261
+ }
1262
+ if(!function_exists("WPSR_import_popup_in_footer")) {
1263
 
1264
  add_action('admin_footer','WPSR_import_popup_in_footer');
1265
  function WPSR_import_popup_in_footer()
1302
  </div>
1303
  <div class="modal-footer">
1304
  <input class="button-primary" id="btnImport" type="button" value="Import It" onclick="return import_function(<?php echo esc_js($total_org); ?>,0)">
1305
+ <input type="hidden" id="_wpnonce" name="_wpnonce" value="<?php echo esc_attr(wp_create_nonce('seoredirection_import')); ?>" />
1306
  <input data-dismiss="modal" aria-label="Close" class="button-primary " type="button" value="Cancel" name="cancel">
1307
  </div>
1308
  </div>
1314
  }
1315
  }
1316
  }
1317
+ }
1318
+ if(!function_exists("WPSR_dismiss_notice_callback")) {
1319
 
1320
+ add_action('wp_ajax_sr_dismiss_notice', 'WPSR_dismiss_notice_callback');
1321
+ function WPSR_dismiss_notice_callback()
1322
+ {
1323
+ global $current_user;
1324
+ $user_id = $current_user->ID;
1325
+ update_user_meta($user_id, 'sr_notice_dismissed', '1');
1326
+ echo "1";
1327
+ exit;
1328
+ }
1329
  }
1330
+ if(!function_exists("WPSR_getRedirectCount")) {
1331
+
1332
+ function WPSR_getRedirectCount()
1333
+ {
1334
+ global $wpdb;
1335
+
1336
+ $table_name_ = $wpdb->prefix . 'redirection_items';
1337
+ if (strtolower($wpdb->get_var("show tables like '$table_name_'")) == strtolower($table_name_)) {
1338
+ $result = $wpdb->get_results("SELECT url FROM {$wpdb->prefix}redirection_items");
1339
+ $cnt = 0;
1340
+ $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
1341
+ if ($result) {
1342
+ foreach ($result as $redirect) {
1343
+ $redirect_from = stripslashes($redirect->url);
1344
+ $redirect_from_slash = ltrim(stripslashes($redirect->url), '/');
1345
+ $redirectID = $wpdb->get_var($wpdb->prepare("select ID from $table_name where redirect_from=%s or redirect_from=%s", $redirect_from, $redirect_from_slash));
1346
+ if ($redirectID > 0) {
1347
+
1348
+ } else {
1349
+ $cnt++;
1350
+ }
1351
+ }
1352
+
1353
+ }
1354
+ return $cnt;
1355
+ } else {
1356
+ return 0;
1357
+ }
1358
+ }
 
 
 
1359
  }
1360
+ if(!function_exists("SR_init_delete_callback")) {
1361
+
1362
+ add_action('admin_init', 'SR_init_delete_callback');
1363
+ function SR_init_delete_callback()
1364
+ {
1365
+ if (isset($_POST['redirect_id']) && count($_POST['redirect_id']) > 0) {
1366
+
1367
+ global $wpdb, $table_prefix, $util;
1368
+ $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
1369
+ foreach ($_POST['redirect_id'] as $post_id) {
1370
+ $post_id = (int)$post_id;
1371
+ $wpdb->query($wpdb->prepare(" delete from $table_name where ID=%s ", $post_id));
1372
+ $SR_redirect_cache = new free_SR_redirect_cache();
1373
+ $SR_redirect_cache->free_cache();
1374
+ }
1375
+
1376
+ }
1377
+ }
1378
  }