SEO Redirection Plugin - Version 8.3

Version Description

  • add settings page link under plugin name
  • Bug fixing in updating redirects
Download this release

Release Info

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

Code changes from version 8.2 to 8.3

options/option_page_custome_redirection_list.php CHANGED
@@ -182,7 +182,7 @@ isset($_REQUEST['tab']) ? $url_op = WPSR_sanitize_text_or_array_field($_REQUEST[
182
  </td>
183
  </tr>
184
  </table>
185
- <p id="invalid_redirect_from" style="color: red; display: none;">Note: It seems that the field "Redirect from" has an invalid value. <a href="https://www.clogica.com/kb/why-having-the-red-message-seems-to-be-invalid-click-here.htm" target="_blank">Click here to know why?</a></p>
186
  <label id="msg_response">
187
  </label>
188
  <br/>
182
  </td>
183
  </tr>
184
  </table>
185
+
186
  <label id="msg_response">
187
  </label>
188
  <br/>
readme.txt CHANGED
@@ -2,8 +2,8 @@
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.1
6
- Stable tag: 8.2
7
 
8
  SEO Redirection is a powerful redirect manager to manage 301 redirects without requiring knowledge of Apache .htaccess files.
9
 
@@ -73,6 +73,10 @@ Yes, here is the plugin full knowledge base http://www.clogica.com/kb/
73
 
74
  == Upgrade Notice ==
75
 
 
 
 
 
76
  = 8.2 =
77
  * Important security fixes in Ajax requests
78
 
@@ -212,6 +216,10 @@ Yes, here is the plugin full knowledge base http://www.clogica.com/kb/
212
 
213
  == Changelog ==
214
 
 
 
 
 
215
  = 8.2 =
216
  * Important security fixes in Ajax requests
217
 
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.2
6
+ Stable tag: 8.4
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
+ = 8.3 =
77
+ * add settings page link under plugin name
78
+ * Bug fixing in updating redirects
79
+
80
  = 8.2 =
81
  * Important security fixes in Ajax requests
82
 
216
 
217
  == Changelog ==
218
 
219
+ = 8.3 =
220
+ * add settings page link under plugin name
221
+ * Bug fixing in updating redirects
222
+
223
  = 8.2 =
224
  * Important security fixes in Ajax requests
225
 
seo-redirection.php CHANGED
@@ -1,1323 +1,1333 @@
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: 8.2
8
- Author URI: https://www.wp-buy.com
9
- Text Domain: seo-redirection
10
- */
11
-
12
- require_once('common/controls.php');
13
- require_once('custom/controls.php');
14
- require_once('custom/controls/cf.SR_redirect_cache.class.php');
15
-
16
- define('WPSR_PATH', plugin_dir_path(__FILE__));
17
-
18
- if (!defined('WPSR_URL')) define('WPSR_URL', plugin_dir_url(__FILE__));
19
-
20
-
21
- if (!defined('WP_SEO_REDIRECTION_OPTIONS')) {
22
- define('WP_SEO_REDIRECTION_OPTIONS', 'wp-seo-redirection-group');
23
- }
24
-
25
- if (!defined('WP_SEO_REDIRECTION_VERSION')) {
26
- define('WP_SEO_REDIRECTION_VERSION', 6.4);
27
- }
28
-
29
- $util = new clogica_util_1();
30
- $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
31
-
32
- add_action('admin_enqueue_scripts', 'WPSR_header_code');
33
- add_action('admin_menu', 'WPSR_admin_menu');
34
- add_action('wp', 'WPSR_redirect', 1);
35
- add_action('save_post', 'WPSR_get_post_redirection');
36
- add_action('add_meta_boxes', 'WPSR_adding_custom_meta_boxes', 10, 3);
37
- add_action('admin_head', 'WPSR_check_default_permalink');
38
- add_action('plugins_loaded', 'WPSR_upgrade');
39
-
40
- register_activation_hook(__FILE__, 'WPSR_upgrade');
41
- register_uninstall_hook(__FILE__, 'WPSR_uninstall');
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">
128
- Redirect&nbsp;<font id="wp_seo_redirection_url_from_label" color="#008000">' . esc_html($permalink) . '</font><input type="hidden" ID="wp_seo_redirection_url_from" name="wp_seo_redirection_url_from" value="' . esc_attr($permalink) . '"></td>
129
- </tr>
130
- </table>
131
- <div id="redirect_frame">
132
- <table border="0" width="100%" cellpadding="2">
133
- <tr>
134
- <td>
135
-
136
- <b>' . __(" Redirect to", 'seo-redirection') . '</b><input type="text" name="wp_seo_redirection_url" id="wp_seo_redirection_url" value="' . esc_attr($urlredirect_to) . '" size="62"></td>
137
- </tr>
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
-
145
- <li>' . __("To remove the redirection, just uncheck the check box above and then click the button", 'seo-redirection') . ' <b>' . __("Update", 'seo-redirection') . '</b>.</li>
146
- </ul>
147
- </td>
148
- </tr>
149
- </table>
150
- </div>';
151
-
152
- echo "
153
-
154
- <script type='text/javascript'>
155
- function WSR_check_status(x)
156
- {
157
-
158
- if(x==0)
159
- {
160
- document.getElementById('redirect_check').checked=false;
161
- document.getElementById('redirect_frame').style.display = 'none';
162
- document.getElementById('wp_seo_redirection_url').value='';
163
- }else
164
- {
165
- document.getElementById('redirect_check').checked=true;
166
- document.getElementById('redirect_frame').style.display= 'block';
167
- }
168
-
169
- }
170
-
171
- function redirect_check_click()
172
- {
173
- if(document.getElementById('redirect_check').checked)
174
- WSR_check_status(1);
175
- else
176
- WSR_check_status(0);
177
- }
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();
220
-
221
- $marker_name="FRedirect_ErrorDocument";
222
- $filestr ="";
223
-
224
- if(file_exists($file)){
225
- $f = @fopen( $file, 'r+' );
226
- $filestr = @fread($f , filesize($file));
227
- if (strpos($filestr , $marker_name) === false)
228
- {
229
- insert_with_markers( $file, $marker_name, $content );
230
- }
231
- }else
232
- {
233
- insert_with_markers( $file, $marker_name, $content );
234
- }
235
-
236
- }
237
-
238
- //------------------------------------------------------------------------
239
-
240
-
241
- /**
242
- * Recursive sanitation for text or array
243
- *
244
- * @param $array_or_string (array|string)
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
-
366
- global $wpdb, $util, $table_prefix, $post;
367
-
368
- if (is_admin()) {
369
- return 0;
370
- }
371
- $SR_redirect_cache = new free_SR_redirect_cache();
372
- if ($redirect_to == $redirect_from || !$util->is_valid_url($redirect_to))
373
- return 0;
374
-
375
- if ($util->make_relative_url($redirect_from) == $util->make_relative_url($redirect_to))
376
- return 0;
377
-
378
- if (substr($redirect_from, -1) == "/" || substr($redirect_to, -1) == "/") {
379
- if (substr($redirect_from, -1) != "/") {
380
- if (($redirect_from . "/") == $redirect_to)
381
- return 0;
382
- } else {
383
- if (($redirect_to . "/") == $redirect_from)
384
- return 0;
385
- }
386
- }
387
-
388
-
389
- if ($util->make_relative_url($redirect_from) == $util->make_relative_url($redirect_to))
390
- return 0;
391
-
392
- if (is_object($obj)) {
393
- if ($obj->ID > 0) {
394
- $table_name = $table_prefix . 'WP_SEO_Redirection';
395
- $sql = "update " . $table_name . " set hits=hits+1, access_date= NOW() where ID='" . $obj->ID . "'";
396
- $wpdb->query($sql);
397
- }
398
- }
399
-
400
- if (is_object($obj) && $obj->redirect_to_type == 'Folder' && $obj->redirect_to_folder_settings == '2') {
401
-
402
- if ($obj->redirect_from_type == 'Folder') {
403
-
404
- if ($obj->redirect_from_folder_settings == '2' || $obj->redirect_from_folder_settings == '3') {
405
- if (strlen($redirect_from) > strlen($obj->redirect_from)) {
406
- $difference = substr($redirect_from, intval(strlen($obj->redirect_from) - strlen($redirect_from)));
407
- $redirect_to = $redirect_to . $difference;
408
- }
409
- }
410
-
411
- } else if ($obj->redirect_from_type == 'Regex') {
412
- $page = substr(strrchr($redirect_from, "/"), 1);
413
- $redirect_to = $redirect_to . '/' . $page;
414
- }
415
-
416
- }
417
-
418
- $rID = 0;
419
- $rsrc = '404';
420
- $postID = 0;
421
-
422
- if (is_object($obj)) {
423
- $rID = $obj->ID;
424
- $postID = $obj->postID;
425
- if ($obj->url_type == 1)
426
- $rsrc = 'Custom';
427
- else if ($obj->url_type == 2)
428
- $rsrc = 'Post';
429
-
430
- }
431
-
432
- if ($util->get_option_value('history_status') == '1') {
433
-
434
- WPSR_log_redirection_history($rID, $postID, $redirect_from, $redirect_to, $redirect_type, $rsrc);
435
- }
436
-
437
- $redirect_to = $util->make_absolute_url($redirect_to);
438
-
439
-
440
- if (is_singular()) {
441
- //$SR_redirect_cache = new free_SR_redirect_cache();
442
-
443
- $SR_redirect_cache->add_redirect($post->ID, 1, $redirect_from, $redirect_to, $redirect_type);
444
- $SR_redirect_cache->free_cache();
445
- }
446
-
447
- if ($redirect_type == '301') {
448
- header('HTTP/1.1 301 Moved Permanently');
449
- header("Location: " . $redirect_to);
450
- exit();
451
- } else if ($redirect_type == '307') {
452
- header('HTTP/1.0 307 Temporary Redirect');
453
- header("Location: " . $redirect_to);
454
- exit();
455
- } else if ($redirect_type == '302') {
456
- header("Location: " . $redirect_to);
457
- exit();
458
- }
459
-
460
- }
461
- }
462
-
463
- //-------------------------------------------------------------
464
- if(!function_exists("WPSR_redirect")) {
465
-
466
- function WPSR_redirect()
467
- {
468
- global $wpdb, $post, $table_prefix, $util;
469
-
470
-
471
- if ($util->get_option_value('plugin_status') != '0') { // if not disabled
472
-
473
- // if disable for admin and the user is admin
474
- if (current_user_can('manage_options') == 1 && $util->get_option_value('plugin_status') == 2) {
475
- // nothing
476
-
477
- } else {
478
-
479
- $table_name = $table_prefix . 'WP_SEO_Redirection';
480
- $permalink = urldecode($util->get_current_relative_url());
481
-
482
- if (substr($permalink, 0, 1) == ":") {
483
- $first_slash = stripos($permalink, "/");
484
- $permalink = substr($permalink, $first_slash, strlen($permalink) - $first_slash);
485
- }
486
- $permalink_alternative = "";
487
- if (substr($permalink, -1) == '/') {
488
- $permalink_alternative = substr($permalink, 0, intval(strlen($permalink) - 1));
489
- } else {
490
- $permalink_alternative = $permalink . '/';
491
- }
492
-
493
- $post_cache_result = "";
494
- $SR_redirect_cache = new free_SR_redirect_cache();
495
- if (is_singular()) {
496
- $post_cache_result = $SR_redirect_cache->redirect_cached($post->ID);
497
- }
498
-
499
- if ($post_cache_result == 'not_redirected') {
500
-
501
- return 0;
502
- }
503
-
504
- $permalink_options = $wpdb->prepare("( redirect_from = %s OR redirect_from = %s)", $permalink, $permalink_alternative);
505
-
506
- $permalink_regex_options = $wpdb->prepare("(%s regexp regex or %s regexp regex )", $permalink, $permalink_alternative);
507
-
508
-
509
- 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))) {
510
-
511
- $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex='' and $permalink_options ");
512
- if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
513
- WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
514
- }
515
-
516
- $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex<>'' and $permalink_regex_options order by LENGTH(regex) desc ");
517
- if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
518
- WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
519
- }
520
-
521
-
522
- if (is_404()) {
523
-
524
- if ($util->get_option_value('p404_discovery_status') == '1') {
525
- WPSR_log_404_redirection($permalink);
526
- }
527
-
528
- $options = $util->get_my_options();
529
- if ($options['p404_status'] == '1') {
530
-
531
- WPSR_make_redirect($options['p404_redirect_to'], '301', $permalink);
532
-
533
- }
534
- }
535
- }
536
-
537
- if (is_singular() && $post_cache_result == 'not_found') {
538
- $SR_redirect_cache->add_redirect($post->ID, 0, '', '', 0);
539
- }
540
-
541
- }
542
- }
543
- }
544
- }
545
- //---------------------------------------------------------------
546
- if(!function_exists("WPSR_header_code")) {
547
-
548
- function WPSR_header_code()
549
- {
550
-
551
- $my_page = isset($_REQUEST['page']) ? $_REQUEST['page'] : '';
552
- if ($my_page == 'seo-redirection.php') {
553
-
554
- wp_register_style('c_admin_css_common', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "style.css");
555
- wp_enqueue_style('sweetalert', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "sweetalert.css");
556
- wp_register_style('c_admin_css_custom', plugins_url() . '/' . basename(dirname(__FILE__)) . '/custom/' . "style.css");
557
- wp_enqueue_script('jquery');
558
- wp_localize_script('jquery', 'seoredirection', array('ajax_url' => admin_url('admin-ajax.php'), 'msg' => ""));
559
- wp_enqueue_style('c_admin_css_common');
560
- wp_enqueue_style('c_admin_css_custom');
561
-
562
- wp_enqueue_script('custom', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/js/' . 'bootstrap.min.js', array('jquery'), false, true);
563
- wp_enqueue_script('customJS', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "customJs.js", array('jquery'), 1.1, true);
564
- wp_enqueue_script('sweetalert', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/js/' . "sweetalert.min.js", array('jquery'), false, true);
565
-
566
- wp_enqueue_style('bootstrap', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "bootstrap.css");
567
-
568
-
569
- }
570
- }
571
- }
572
- //---------------------------------------------------------------
573
- if(!function_exists("WPSR_customAddUpdate_callback")) {
574
-
575
- add_action("wp_ajax_customAddUpdate", "WPSR_customAddUpdate_callback");
576
-
577
- function WPSR_customAddUpdate_callback()
578
- {
579
- global $wpdb, $table_prefix, $util;
580
- $table_name = $table_prefix . 'WP_SEO_Redirection';
581
- $table_name_404 = $table_prefix . 'WP_SEO_404_links';
582
- parse_str($_POST['formData'], $_POST);
583
- $nonce = "";
584
- if (isset($_POST['_wpnonce']))
585
- $nonce = WPSR_sanitize_text_or_array_field($_POST['_wpnonce']);
586
- $data = array();
587
- $data['error_string'] = array();
588
- $data['inputerror'] = array();
589
- $data['bool'] = TRUE;
590
- if (trim($_POST['redirect_from']) == '') {
591
- $data['inputerror'][] = 'redirect_from';
592
- $data['error_string'][] = __("You must input the 'Redirect From' URL", "seo-redirection");
593
- $data['bool'] = FALSE;
594
- }
595
-
596
- $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
597
-
598
- $wpdb->get_results(" select ID from $table_name where redirect_from='" . trim($redirect_from) . "' ");
599
- if ($wpdb->num_rows > 0) {
600
- $data['inputerror'][] = 'redirect_from';
601
- $data['error_string'][] = __("This 'Redirect From' value already exists in database!", "seo-redirection");
602
- $data['bool'] = FALSE;
603
- }
604
-
605
-
606
- // elseif (!preg_match( '/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/', $_POST['redirect_from'])) {
607
- // $data['inputerror'][] = 'redirect_from';
608
- // $data['error_string'][] = __("Invalid redirect from target URL!",'seo-redirection');
609
- // $data['bool'] = FALSE;
610
- // }
611
- if (trim($_POST['redirect_to']) == '') {
612
- $data['inputerror'][] = 'redirect_to';
613
- $data['error_string'][] = __("You must input the 'Redirect To' URL", "seo-redirection");
614
- $data['bool'] = FALSE;
615
- } elseif ($_POST['edit_exist'] == '' && substr(strtolower($_POST['redirect_to']), 0, 4) != "http" && substr(strtolower($_POST['redirect_to']), 0, 1) != "/") {
616
- $data['inputerror'][] = 'redirect_to';
617
- $data['error_string'][] = __("Invalid redirect target URL!", 'seo-redirection');
618
- $data['bool'] = FALSE;
619
- }
620
- if ($data['bool'] === FALSE) {
621
- echo json_encode($data);
622
- exit();
623
- } else {
624
- if ($_POST['redirect_from'] != '' && wp_verify_nonce($nonce, 'seoredirection')) {
625
-
626
-
627
- $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
628
- $redirect_to = isset($_POST['redirect_to']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_to']) : '';
629
-
630
-
631
- $redirect_from = urldecode($util->make_relative_url($redirect_from));
632
-
633
- $redirect_to = $util->make_relative_url($redirect_to);
634
- $redirect_type = WPSR_sanitize_text_or_array_field($_POST['redirect_type']);
635
-
636
- $redirect_from_type = WPSR_sanitize_text_or_array_field($_POST['redirect_from_type']);
637
- $redirect_from_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_from_folder_settings']);
638
- $redirect_from_subfolders = WPSR_sanitize_text_or_array_field($_POST['redirect_from_subfolders']);
639
-
640
- $redirect_to_type = WPSR_sanitize_text_or_array_field($_POST['redirect_to_type']);
641
- $redirect_to_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_to_folder_settings']);
642
-
643
- $enabled = WPSR_sanitize_text_or_array_field($_POST['enabled']);
644
-
645
- $regex = "";
646
-
647
- if ($redirect_from_type == 'Folder') {
648
-
649
- if (substr($redirect_from, -1) != '/')
650
- $redirect_from = $redirect_from . '/';
651
-
652
- if ($redirect_from_folder_settings == 2) {
653
- if ($redirect_from_subfolders == 0) {
654
- $regex = '^' . $util->regex_prepare($redirect_from) . '.*';;
655
- } else {
656
- $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]*$';
657
- }
658
- } else if ($redirect_from_folder_settings == 3) {
659
- if ($redirect_from_subfolders == 0) {
660
- $regex = '^' . $util->regex_prepare($redirect_from) . '.+';
661
- } else {
662
- $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]+$';
663
- }
664
- }
665
-
666
- } else if ($redirect_from_type == 'Regex') {
667
- $regex = $redirect_from;
668
- }
669
-
670
- if ($redirect_from_type == 'Page' || $redirect_from_type == 'Regex') {
671
- $redirect_from_folder_settings = "";
672
- $redirect_from_subfolders = "";
673
- }
674
-
675
- if ($redirect_to_type == 'Page') {
676
- $redirect_to_folder_settings = "";
677
- }
678
-
679
- if ($redirect_to_type == 'Folder') {
680
- if (substr($redirect_to, -1) != '/')
681
- $redirect_to = $redirect_to . '/';
682
- }
683
-
684
-
685
- if ($_POST['add_new'] != '') {
686
-
687
- $theurl = $wpdb->get_row($wpdb->prepare(" select count(ID) as cnt from $table_name where redirect_from=%s ", $redirect_from));
688
-
689
- if ($theurl->cnt > 0) {
690
- $msg = __("This URL", 'seo-redirection') . " <b>".esc_html($redirect_from)."</b>" . __("is added previously!", 'seo-redirection');
691
- echo json_encode(array('status' => 'error', 'msg' => $msg));
692
- // $util->failure_option_msg(__("This URL",'seo-redirection')." <b>'$redirect_from'</b>". __("is added previously!",'seo-redirection'));
693
- } else {
694
-
695
-
696
- if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
697
- $util->failure_option_msg(__('Please input all required fields!', 'seo-redirection'));
698
- } else {
699
-
700
- $wpdb->insert($table_name, array(
701
- 'redirect_from' => $redirect_from,
702
- 'redirect_to' => $redirect_to,
703
- 'redirect_type' => $redirect_type,
704
- 'url_type' => 1,
705
- 'redirect_from_type' => $redirect_from_type,
706
- 'redirect_from_folder_settings' => $redirect_from_folder_settings,
707
- 'redirect_from_subfolders' => $redirect_from_subfolders,
708
- 'redirect_to_type' => $redirect_to_type,
709
- 'redirect_to_folder_settings' => $redirect_to_folder_settings,
710
- 'regex' => $regex,
711
- 'enabled' => $enabled
712
-
713
- ));
714
-
715
- $wpdb->query($wpdb->prepare(" delete from $table_name_404 where link=%s ", $redirect_from));
716
- $SR_redirect_cache = new free_SR_redirect_cache();
717
- $SR_redirect_cache->free_cache();
718
- $msg = "Redirection Added Successfully";
719
- echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
720
- die;
721
- }
722
-
723
- }
724
- } else if ($_POST['edit_exist'] != '') {
725
-
726
- $edit = WPSR_sanitize_text_or_array_field($_POST['edit']);
727
-
728
- if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
729
- $util->failure_option_msg('Please input all required fields!');
730
- } else {
731
-
732
- $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));
733
-
734
- $SR_redirect_cache = new free_SR_redirect_cache();
735
- $SR_redirect_cache->free_cache();
736
- }
737
- $msg = "Redirection Update Successfully";
738
- echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
739
- die;
740
-
741
- }
742
-
743
- if ($util->there_is_cache() != '')
744
- $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'));
745
-
746
- }
747
-
748
- }
749
-
750
-
751
- die;
752
- }
753
- }
754
- if(!function_exists("WPSR_customUpdateRec_callback")) {
755
-
756
- add_action("wp_ajax_customUpdateRec", "WPSR_customUpdateRec_callback");
757
- function WPSR_customUpdateRec_callback()
758
- {
759
-
760
-
761
- global $wpdb, $table_prefix, $util;
762
-
763
- $table_name = $table_prefix . 'WP_SEO_Redirection';
764
- $table_name_404 = $table_prefix . 'WP_SEO_404_links';
765
-
766
- $myid = (int)$_POST['ID'];
767
- $item = $wpdb->get_row($wpdb->prepare(" select * from $table_name where ID=%d ", $myid));
768
-
769
- if ($wpdb->num_rows == 0) {
770
- echo json_encode(array('status' => 'error', 'msg' => __("Sorry, this redirect rule is not found, it may deleted by the user!", 'seo-redirection')));
771
- die;
772
- }
773
-
774
-
775
- $data = array(
776
- "redirect_from" => $item->redirect_from,
777
- "redirect_to" => $item->redirect_to,
778
- "redirect_type" => $item->redirect_type,
779
-
780
- "redirect_from_type" => $item->redirect_from_type,
781
- "redirect_from_folder_settings" => $item->redirect_from_folder_settings,
782
- "redirect_from_subfolders" => $item->redirect_from_subfolders,
783
-
784
- "redirect_to_type" => $item->redirect_to_type,
785
- "redirect_to_folder_settings" => $item->redirect_to_folder_settings,
786
-
787
- "enabled" => $item->enabled
788
- );
789
- echo json_encode(array('status' => 'suucess', 'rec' => $data));
790
- die;
791
- }
792
- }
793
-
794
- if(!function_exists("WPSR_admin_menu")) {
795
-
796
- function WPSR_admin_menu()
797
- {
798
- add_options_page('SEO Redirection', 'SEO Redirection', 'manage_options', basename(__FILE__), 'WPSR_options_menu');
799
- }
800
- }
801
- //---------------------------------------------------------------
802
- if(!function_exists("WPSR_options_menu")) {
803
-
804
- function WPSR_options_menu()
805
- {
806
- global $util;
807
-
808
- if (!current_user_can('manage_options')) {
809
- wp_die(__('You do not have sufficient permissions to access this page.', 'seo-redirection'));
810
- }
811
-
812
-
813
- if ($util->get_option_value('plugin_status') == '0') {
814
- $util->info_option_msg(__('SEO Redirection is disabled now, you can go to option tab and enable it!', 'seo-redirection'));
815
- } else if ($util->get_option_value('plugin_status') == '2') {
816
- $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'));
817
- }
818
- $total_404_errors = (WPSR_Get_total_404() > 5) ? __('You have', 'seo-redirection') . ' <b style="color:red; background-color:yellow; padding:3px;">' . intval(WPSR_Get_total_404()) .'</b>' . __(' broken link (404 links)', 'seo-redirection') . ', <br>'.'<div class="wrap" style="font-weight:normal; line-height:30px">' . __('Upgrade to', 'wsr') . ' <a target="_blank" href="https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin">' . __("pro version", "wsr") . '</a>' . __(" to manage 404 errors and empower your site SEO", "wsr").'</div>' : '';
819
-
820
-
821
- echo '<div class="wrap"><h2>' . __("SEO Redirection Free", 'seo-redirection') . '</h2><b>' . __('Upgrade to', 'seo-redirection') . ' <a target="_blank" onclick="swal.clickConfirm();" href="https://www.wp-buy.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/>';
822
-
823
- if ($total_404_errors != '') {
824
- ?>
825
- <script type="text/javascript">
826
-
827
- seoredirection.msg = '<?php echo wp_kses_post($total_404_errors); ?>';
828
-
829
- </script>
830
-
831
- <?php
832
- }
833
-
834
- if (is_multisite()) {
835
-
836
- 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="https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/">
837
- https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/</a>) <p></p></div>';
838
-
839
- }
840
-
841
- $mytabs = new phptab();
842
-
843
- $mytabs->set_ignore_parameter(array( 'search', 'page_num', 'add', 'edit', 'page404', 'do_404_del'));
844
- $mytabs->add_file_tab('cutom', __('Custom Redirects', 'seo-redirection'), 'option_page_custome_redirection.php', 'file');
845
- $mytabs->add_file_tab('posts', __('Post Redirects', 'seo-redirection'), 'option_page_post_redirection_list.php', 'file');
846
- $mytabs->add_file_tab('history', __('History', 'seo-redirection'), 'option_page_history.php', 'file');
847
- $mytabs->add_file_tab('404', '<span style="color:red;"><b>404 Errors</b></span>', 'option_page_404.php', 'file');
848
- $mytabs->add_file_tab('goptions', __('Options', 'seo-redirection'), 'option_page_goptions.php', 'file');
849
- $mytabs->add_file_tab('help', '<span style="color:green;"><b>' . __('Help', 'seo-redirection') . '</b></span>', 'help.php', 'file');
850
- $mytabs->add_file_tab('premium', '<span style="color:brown;"><b>&#9658; ' . __('Premium Features', 'seo-redirection') . '</b></span>', 'premium.php', 'file');
851
- $mytabs->run();
852
-
853
- $imgpath = $util->get_plugin_url() . 'custom/images/';
854
-
855
- echo '<p>&nbsp;</p><p style="color:green"><a target="_blank" href="http://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin"><b>' . __("Upgrade to premium version now", "wsr") . '</b></a>' . __(" to get more features", "wsr") . ' , <small>' . __("The premium version of SEO redirection is completely different from the free version as there are a lot more features included.", "wsr") . '</small></p>';
856
- echo __('<p><a href="https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin" target="_blank"><img src="' . $imgpath . 'seopro.png" /></a></p>');
857
- }
858
- }
859
- if(!function_exists("WPSR_upgrade")) {
860
-
861
- function WPSR_upgrade()
862
- {
863
-
864
- $util = new clogica_util_1();
865
- $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
866
-
867
- if ($util->get_option_value('plugin_version') != WP_SEO_REDIRECTION_VERSION) {
868
- WPSR_install();
869
- $util->update_option('plugin_version', WP_SEO_REDIRECTION_VERSION);
870
- }
871
- }
872
- }
873
- //-----------------------------------------------------
874
- if(!function_exists("WPSR_install")) {
875
-
876
- function WPSR_install()
877
- {
878
- global $wpdb, $table_prefix;
879
-
880
- $util = new clogica_util_1();
881
- $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
882
-
883
- $options = get_option(WP_SEO_REDIRECTION_OPTIONS);
884
- if (!is_array($options)) {
885
- add_option(WP_SEO_REDIRECTION_OPTIONS);
886
- $options = array();
887
- }
888
-
889
-
890
- if (!array_key_exists('plugin_status', $options))
891
- $options['plugin_status'] = '1';
892
-
893
- if (!array_key_exists('ip_logging_status', $options))
894
- $options['ip_logging_status'] = '1';
895
-
896
- if (!array_key_exists('redirection_base', $options))
897
- $options['redirection_base'] = site_url();
898
-
899
- if (!array_key_exists('redirect_control_panel', $options))
900
- $options['redirect_control_panel'] = '1';
901
-
902
- if (!array_key_exists('show_redirect_box', $options))
903
- $options['show_redirect_box'] = '1';
904
-
905
- if (!array_key_exists('reflect_modifications', $options))
906
- $options['reflect_modifications'] = '1';
907
-
908
- if (!array_key_exists('history_status', $options))
909
- $options['history_status'] = '1';
910
-
911
- if (!array_key_exists('history_limit', $options))
912
- $options['history_limit'] = '30';
913
-
914
- if (!array_key_exists('p404_discovery_status', $options))
915
- $options['p404_discovery_status'] = '1';
916
-
917
- if (!array_key_exists('p404_redirect_to', $options))
918
- $options['p404_redirect_to'] = site_url();
919
-
920
- if (!array_key_exists('p404_status', $options))
921
- $options['p404_status'] = '2';
922
-
923
- if (!array_key_exists('keep_data', $options))
924
- $options['keep_data'] = '1';
925
-
926
- update_option(WP_SEO_REDIRECTION_OPTIONS, $options);
927
-
928
-
929
- $table_name = $table_prefix . 'WP_SEO_Redirection';
930
- if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
931
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
932
- `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
933
- `enabled` int(1) NOT NULL DEFAULT '1',
934
- `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
935
- `redirect_from_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
936
- `redirect_from_folder_settings` int(1) NOT NULL,
937
- `redirect_from_subfolders` int(1) NOT NULL DEFAULT '1',
938
- `redirect_to` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
939
- `redirect_to_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
940
- `redirect_to_folder_settings` int(1) NOT NULL DEFAULT '1',
941
- `regex` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
942
- `redirect_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
943
- `url_type` int(2) NOT NULL DEFAULT 1,
944
- `postID` int(11) unsigned DEFAULT NULL,
945
- `import_flag` tinyint(1) NOT NULL DEFAULT 0,
946
- `hits` int(11) unsigned NOT NULL DEFAULT 0,
947
- `access_date` datetime DEFAULT NULL,
948
- PRIMARY KEY (`ID`),
949
- UNIQUE KEY `redirect_from` (`redirect_from`)
950
- )ENGINE = MyISAM ;";
951
- $wpdb->query($sql);
952
-
953
-
954
- } else {
955
- //check if Innodb convert it to myisam.
956
- $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
957
- if ($status->Engine == 'InnoDB') {
958
- $wpdb->query("alter table $table_name engine = MyISAM;");
959
- }
960
-
961
- /* add column for import flag */
962
- $column_data = $wpdb->get_row("SHOW COLUMNS FROM $table_name LIKE 'import_flag'");
963
-
964
- if (!$column_data) {
965
- $wpdb->query("ALTER TABLE $table_name ADD COLUMN import_flag tinyint(1) DEFAULT 0");
966
- }
967
-
968
- // if the table exists
969
- $redirects = $wpdb->get_results(" select redirect_from,redirect_to,ID from $table_name; ");
970
- foreach ($redirects as $redirect) {
971
- $redirect_from = $util->make_relative_url($redirect->redirect_from);
972
- $redirect_to = $util->make_relative_url($redirect->redirect_to);
973
- $ID = $redirect->ID;
974
- $wpdb->query($wpdb->prepare(" update $table_name set redirect_from=%s,redirect_to=%s where ID=%d", $redirect_from, $redirect_to, $ID));
975
- }
976
-
977
- // Fix add blog field if not exist.
978
- if ($wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
979
- WHERE TABLE_NAME = '$table_name'
980
- AND table_schema = DATABASE()
981
- AND COLUMN_NAME = 'hits' ") == '0') {
982
-
983
- $sql = "
984
- ALTER TABLE $table_name
985
- ADD COLUMN `hits` int(11) unsigned NOT NULL DEFAULT 0,
986
- ADD COLUMN `access_date` datetime DEFAULT NULL;
987
- ";
988
-
989
- $wpdb->query($sql);
990
- }
991
-
992
-
993
- }
994
-
995
- $table_name = $table_prefix . 'WP_SEO_Cache';
996
- if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
997
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
998
- `ID` int(11) unsigned NOT NULL,
999
- `is_redirected` int(1) unsigned NOT NULL,
1000
- `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1001
- `redirect_to` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1002
- `redirect_type` int(3) unsigned NOT NULL DEFAULT 301,
1003
- PRIMARY KEY (`ID`)
1004
- ) ENGINE = MyISAM ;
1005
- ";
1006
- $wpdb->query($sql);
1007
- } else {
1008
- //check if Innodb convert it to myisam.
1009
- $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1010
- if ($status->Engine == 'InnoDB') {
1011
- $wpdb->query("alter table $table_name engine = MyISAM;");
1012
- }
1013
- }
1014
-
1015
-
1016
- $res = $wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1017
- WHERE TABLE_NAME = '$table_name'
1018
- AND table_schema = DATABASE()
1019
- AND COLUMN_NAME = 'redirect_from' ");
1020
-
1021
- if ($res == '0') {
1022
-
1023
- $sql = "
1024
- ALTER TABLE $table_name
1025
- ADD COLUMN `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL;
1026
- ";
1027
- $wpdb->query($sql);
1028
- }
1029
-
1030
-
1031
- $table_name = $table_prefix . 'WP_SEO_404_links';
1032
- if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1033
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1034
- `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1035
- `ctime` datetime NOT NULL,
1036
- `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1037
- `referrer` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1038
- `ip` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1039
- `country` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
1040
- `os` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1041
- `browser` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1042
- PRIMARY KEY (`ID`),
1043
- UNIQUE KEY `link` (`link`)
1044
- ) ENGINE = MyISAM ;
1045
- ";
1046
- $wpdb->query($sql);
1047
- } else {
1048
- //check if Innodb convert it to myisam.
1049
- $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1050
- if ($status->Engine == 'InnoDB') {
1051
- $wpdb->query("alter table $table_name engine = MyISAM;");
1052
- }
1053
- }
1054
-
1055
-
1056
- $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
1057
- if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1058
- $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1059
- `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1060
- `rID` int(11) unsigned DEFAULT NULL,
1061
- `postID` int(11) unsigned DEFAULT NULL,
1062
- `ctime` datetime NOT NULL,
1063
- `rfrom` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1064
- `rto` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1065
- `rtype` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1066
- `rsrc` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1067
- `referrer` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1068
- `ip` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1069
- `country` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
1070
- `os` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1071
- `browser` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1072
- PRIMARY KEY (`ID`)
1073
- ) ENGINE = MyISAM ;
1074
- ";
1075
-
1076
- $wpdb->query($sql);
1077
- } else {
1078
- //check if Innodb convert it to myisam.
1079
- $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1080
- if ($status->Engine == 'InnoDB') {
1081
- $wpdb->query("alter table $table_name engine = MyISAM;");
1082
- }
1083
-
1084
- $res = $wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1085
- WHERE TABLE_NAME = '$table_name'
1086
- AND table_schema = DATABASE()
1087
- AND COLUMN_NAME = 'postID' ");
1088
-
1089
- if ($res == '0') {
1090
-
1091
- $sql = "
1092
- ALTER TABLE $table_name
1093
- ADD COLUMN `postID` int(11) unsigned DEFAULT NULL;
1094
- ";
1095
- $wpdb->query($sql);
1096
- }
1097
-
1098
-
1099
- }
1100
-
1101
- }
1102
-
1103
- }
1104
- //---------------------------------------------------------------
1105
-
1106
- if(!function_exists("WPSR_uninstall")) {
1107
-
1108
- function WPSR_uninstall()
1109
- {
1110
- global $wpdb, $table_prefix;
1111
-
1112
- $util = new clogica_util_1();
1113
- $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
1114
-
1115
-
1116
- if ($util->get_option_value('keep_data') != '1') {
1117
-
1118
- $table_name = $table_prefix . 'WP_SEO_Redirection';
1119
- $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1120
-
1121
- $table_name = $table_prefix . 'WP_SEO_Cache';
1122
- $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1123
-
1124
- $table_name = $table_prefix . 'WP_SEO_404_links';
1125
- $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1126
-
1127
- $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
1128
- $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1129
-
1130
-
1131
- $util->delete_my_options();
1132
- }
1133
-
1134
-
1135
- }
1136
-
1137
- }
1138
- //---------------------------------------------------------------
1139
- if(!function_exists("WPSR_HideMessageAjaxFunction")) {
1140
-
1141
- function WPSR_HideMessageAjaxFunction()
1142
- {
1143
- add_option('nsr_upgrade_message', 'yes');
1144
- }
1145
- }
1146
- //---------------------------------------------------------------
1147
- if(!function_exists("WPSR_admin_notice_callback")) {
1148
-
1149
- /* display import from redirection plugin in admin notice */
1150
- function WPSR_admin_notice_callback() {
1151
- global $wpdb;
1152
- global $current_user;
1153
- $plugins = get_option( 'active_plugins', array() );
1154
- $found = false;
1155
- $user_id = $current_user->ID;
1156
- $val = get_user_meta($user_id, 'sr_notice_dismissed',true);
1157
-
1158
- foreach ( $plugins as $plugin )
1159
- {
1160
- if ( strpos( strval($plugin), 'redirection.php' ) == true && $val != 1 && strpos( strval($plugin), 'seo-redirection.php' ) == FALSE )
1161
- {
1162
- $found = true;
1163
- //$total = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_items");
1164
- $total = WPSR_getRedirectCount();
1165
- if($total > 0){
1166
- ?>
1167
- <div class="notice-success notice is-dismissible sr_notice">
1168
- <p>
1169
- <strong><?php _e('SEO Redirection : ', 'seo-redirection'); ?></strong><?php echo __( 'The plugin detected ','seo-redirection').intval($total).__(' redirects in the Redirection plugin, Import it now. ','seo-redirection'); ?>
1170
- <?php
1171
- $SR_import = isset($_GET['SR_import']) ? sanitize_text_field($_GET['SR_import']) : '';
1172
- if($SR_import == 'yes'){?>
1173
- <button type='button' data-toggle="modal" class="button" href="#" data-target="#import_modal" value="btn_import"><span style="margin-top: 3px;" class="dashicons dashicons-migrate"></span>&nbsp; <?php _e('Import Now','seo-redirection'); ?></button>
1174
- <?php }else{ ?>
1175
- <a href="options-general.php?page=seo-redirection.php&tab=export_import&SR_import=yes" data-target="#import_modal" value="btn_import"><?php _e('Import','seo-redirection'); ?></a>
1176
- <?php }?>
1177
- </p>
1178
- </div>
1179
- <?php
1180
- }
1181
- break;
1182
- }
1183
- }
1184
- }
1185
- add_action( 'admin_notices', 'WPSR_admin_notice_callback' );
1186
- }
1187
-
1188
- if(!function_exists("WPSR_dismiss_notice_callback")) {
1189
-
1190
- add_action('wp_ajax_sr_dismiss_notice', 'WPSR_dismiss_notice_callback');
1191
- function WPSR_dismiss_notice_callback()
1192
- {
1193
- global $current_user;
1194
- $user_id = $current_user->ID;
1195
- update_user_meta($user_id, 'sr_notice_dismissed', '1');
1196
- echo "1";
1197
- exit;
1198
- }
1199
- }
1200
- if(!function_exists("WPSR_getRedirectCount")) {
1201
-
1202
- function WPSR_getRedirectCount()
1203
- {
1204
- global $wpdb;
1205
-
1206
- $table_name_ = $wpdb->prefix . 'redirection_items';
1207
- if (strtolower($wpdb->get_var("show tables like '$table_name_'")) == strtolower($table_name_)) {
1208
- $result = $wpdb->get_results("SELECT url FROM {$wpdb->prefix}redirection_items");
1209
- $cnt = 0;
1210
- $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
1211
- if ($result) {
1212
- foreach ($result as $redirect) {
1213
- $redirect_from = stripslashes($redirect->url);
1214
- $redirect_from_slash = ltrim(stripslashes($redirect->url), '/');
1215
- $redirectID = $wpdb->get_var($wpdb->prepare("select ID from $table_name where redirect_from=%s or redirect_from=%s", $redirect_from, $redirect_from_slash));
1216
- if ($redirectID > 0) {
1217
-
1218
- } else {
1219
- $cnt++;
1220
- }
1221
- }
1222
-
1223
- }
1224
- return $cnt;
1225
- } else {
1226
- return 0;
1227
- }
1228
- }
1229
- }
1230
- if(!function_exists("SR_init_delete_callback")) {
1231
-
1232
- add_action('admin_init', 'SR_init_delete_callback');
1233
- function SR_init_delete_callback()
1234
- {
1235
- if (isset($_POST['redirect_id']) && count($_POST['redirect_id']) > 0) {
1236
-
1237
- $nonce = '';
1238
- if(isset($_REQUEST['_wpnonce']))
1239
- $nonce = WPSR_sanitize_text_or_array_field($_REQUEST['_wpnonce']);
1240
-
1241
- if(wp_verify_nonce( $nonce, 'seoredirection' )){
1242
-
1243
- global $wpdb, $table_prefix, $util;
1244
- $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
1245
- foreach ($_POST['redirect_id'] as $post_id) {
1246
- $post_id = (int)$post_id;
1247
- $wpdb->query($wpdb->prepare(" delete from $table_name where ID=%s ", $post_id));
1248
- $SR_redirect_cache = new free_SR_redirect_cache();
1249
- $SR_redirect_cache->free_cache();
1250
- }
1251
- }
1252
- }
1253
- }
1254
- }
1255
-
1256
-
1257
-
1258
-
1259
- //---------------------------------------------------------------
1260
-
1261
- function WPSR_HideMessageAjaxFunction()
1262
- {
1263
- add_option('nsr_upgrade_message', 'yes');
1264
- }
1265
-
1266
-
1267
- function WPSR_after_plugin_row($plugin_file, $plugin_data, $status)
1268
- {
1269
-
1270
- if (get_option('nsr_upgrade_message') != 'yes') {
1271
- $class_name = $plugin_data['slug'];
1272
-
1273
- echo '<tr id="' . $class_name . '-plugin-update-tr" class="plugin-update-tr active">';
1274
- echo '<td colspan="6" class="plugin-update">';
1275
- echo '<div id="' . $class_name . '-upgradeMsg" class="update-message notice inline notice-warning notice-alt" >';
1276
-
1277
- echo 'You are running SEO redirection free. To get more features, you can <a href="http://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin" target="_blank"><strong>upgrade now</strong></a> or ';
1278
-
1279
- echo '<span id="HideMe" style="cursor:pointer" ><a href="javascript:void(0)"><strong>dismiss</strong></a> this message</span>';
1280
- echo '</div>';
1281
- echo '</td>';
1282
- echo '</tr>';
1283
-
1284
- ?>
1285
-
1286
- <script type="text/javascript">
1287
- jQuery(document).ready(function () {
1288
- var row = jQuery('#<?php echo $class_name;?>-plugin-update-tr').closest('tr').prev();
1289
- jQuery(row).addClass('update');
1290
-
1291
- jQuery("#HideMe").click(function () {
1292
- jQuery.ajax({
1293
- type: 'POST',
1294
- url: '<?php echo admin_url();?>/admin-ajax.php',
1295
- data: {
1296
- action: 'WPSR_HideMessageAjaxFunction'
1297
- },
1298
- success: function (data, textStatus, XMLHttpRequest) {
1299
-
1300
- jQuery("#<?php echo $class_name;?>-upgradeMsg").hide();
1301
-
1302
- },
1303
- error: function (MLHttpRequest, textStatus, errorThrown) {
1304
- alert(errorThrown);
1305
- }
1306
- });
1307
- });
1308
-
1309
- });
1310
- </script>
1311
-
1312
- <?php
1313
- }
1314
- }
1315
-
1316
- $path = plugin_basename(__FILE__);
1317
- add_action("after_plugin_row_{$path}", 'WPSR_after_plugin_row', 10, 3);
1318
- // creating Ajax call for WordPress
1319
- add_action('wp_ajax_nopriv_WPSR_HideMessageAjaxFunction', 'WPSR_HideMessageAjaxFunction');
1320
- add_action('wp_ajax_WPSR_HideMessageAjaxFunction', 'WPSR_HideMessageAjaxFunction');
1321
- //---------------------------------------------------------------
1322
-
1323
- ?>
 
 
 
 
 
 
 
 
 
 
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: 8.3
8
+ Author URI: https://www.wp-buy.com
9
+ Text Domain: seo-redirection
10
+ */
11
+
12
+ require_once('common/controls.php');
13
+ require_once('custom/controls.php');
14
+ require_once('custom/controls/cf.SR_redirect_cache.class.php');
15
+
16
+ define('WPSR_PATH', plugin_dir_path(__FILE__));
17
+
18
+ if (!defined('WPSR_URL')) define('WPSR_URL', plugin_dir_url(__FILE__));
19
+
20
+
21
+ if (!defined('WP_SEO_REDIRECTION_OPTIONS')) {
22
+ define('WP_SEO_REDIRECTION_OPTIONS', 'wp-seo-redirection-group');
23
+ }
24
+
25
+ if (!defined('WP_SEO_REDIRECTION_VERSION')) {
26
+ define('WP_SEO_REDIRECTION_VERSION', 6.4);
27
+ }
28
+
29
+ $util = new clogica_util_1();
30
+ $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
31
+
32
+
33
+ add_action('admin_enqueue_scripts', 'WPSR_header_code');
34
+ add_action('admin_menu', 'WPSR_admin_menu');
35
+ add_action('wp', 'WPSR_redirect', 1);
36
+ add_action('save_post', 'WPSR_get_post_redirection');
37
+ add_action('add_meta_boxes', 'WPSR_adding_custom_meta_boxes', 10, 3);
38
+ add_action('admin_head', 'WPSR_check_default_permalink');
39
+ add_action('plugins_loaded', 'WPSR_upgrade');
40
+
41
+ register_activation_hook(__FILE__, 'WPSR_upgrade');
42
+ register_uninstall_hook(__FILE__, 'WPSR_uninstall');
43
+
44
+ /////////////////////////////////////////////////////////////////////////
45
+
46
+ if(!function_exists("WPSR__filter_action_links")){
47
+ function WPSR__filter_action_links( $links ) {
48
+ $links['settings'] = sprintf('<a href="%s">Settings</a>', admin_url( 'options-general.php?page=seo-redirection.php' ));
49
+ $links['MorePlugins'] = sprintf('<a href="%s"><b style="color:#f18500">More Plugins</b></a>', admin_url( 'plugin-install.php?s=wp-buy&tab=search&type=author' ));
50
+ return $links;
51
+ }
52
+ add_filter( 'plugin_action_links_'.plugin_basename(__FILE__), 'WPSR__filter_action_links', 10, 1 );
53
+ }
54
+
55
+ if(!function_exists("WPSR_multiple_plugin_activate_trial")){
56
+ function WPSR_multiple_plugin_activate_trial()
57
+ {
58
+ global $wpdb;
59
+ if (is_multisite()) {
60
+ if (is_plugin_active_for_network(__FILE__)) {
61
+ $blogids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
62
+ foreach ($blogids as $blog_id) {
63
+ switch_to_blog($blog_id);
64
+ }
65
+ }
66
+ }
67
+ }
68
+
69
+ register_activation_hook(__FILE__, 'WPSR_multiple_plugin_activate_trial');
70
+
71
+ }
72
+
73
+ if(!function_exists("WPSR_adding_custom_meta_boxes")) {
74
+
75
+ function WPSR_adding_custom_meta_boxes()
76
+ {
77
+ global $util;
78
+ if ($util->get_option_value('show_redirect_box') == '1') {
79
+
80
+ $screens = array('post', 'page');
81
+
82
+ foreach ($screens as $screen) {
83
+
84
+ add_meta_box(
85
+ 'WPSR_meta_box',
86
+ __('SEO Redirection'),
87
+ 'WPSR_render_meta_box',
88
+ $screen
89
+ );
90
+ }
91
+
92
+ }
93
+ }
94
+ }
95
+ if(!function_exists("WPSR_render_meta_box")) {
96
+
97
+ function WPSR_render_meta_box($post)
98
+ {
99
+ global $wpdb, $table_prefix, $util;
100
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
101
+
102
+ if (get_post_status() != 'auto-draft') {
103
+ $permalink = "";
104
+ if (in_array($post->post_status, array('draft', 'pending'))) {
105
+ list($permalink, $postname) = get_sample_permalink($post->ID);
106
+ $permalink = str_replace('%postname%', $postname, $permalink);
107
+
108
+ } else {
109
+
110
+ $permalink = get_permalink($post->ID);
111
+ }
112
+
113
+ $permalink = $util->make_relative_url(urldecode($permalink));
114
+
115
+ $postID = $post->ID;
116
+
117
+
118
+ $theurl = $wpdb->get_row($wpdb->prepare(" select redirect_to,redirect_from from $table_name where postID=%d ", $postID));
119
+
120
+ $urlredirect_to = '';
121
+ if ($wpdb->num_rows > 0)
122
+ $urlredirect_to = $theurl->redirect_to;
123
+
124
+ if ($urlredirect_to != '' && $theurl->redirect_from != $permalink) {
125
+ // the post_name field changed!
126
+ $wpdb->query($wpdb->prepare(" update $table_name set redirect_from=%s where postID=%d ", $permalink, $postID));
127
+ if ($util->get_option_value('reflect_modifications') == '1') {
128
+ $wpdb->query($wpdb->prepare(" update $table_name set redirect_to=%s where redirect_to=%s ", $permalink, $theurl->redirect_from));
129
+ $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'));
130
+ }
131
+ //-------------------------------------------
132
+ }
133
+
134
+ echo '
135
+ <table border="0" width="100%" cellpadding="2">
136
+ <tr>
137
+ <td width="99%"><input onchange="redirect_check_click()" type="checkbox" name="redirect_check" id="redirect_check" value="ON">
138
+ Redirect&nbsp;<font id="wp_seo_redirection_url_from_label" color="#008000">' . esc_html($permalink) . '</font><input type="hidden" ID="wp_seo_redirection_url_from" name="wp_seo_redirection_url_from" value="' . esc_attr($permalink) . '"></td>
139
+ </tr>
140
+ </table>
141
+ <div id="redirect_frame">
142
+ <table border="0" width="100%" cellpadding="2">
143
+ <tr>
144
+ <td>
145
+
146
+ <b>' . __(" Redirect to", 'seo-redirection') . '</b><input type="text" name="wp_seo_redirection_url" id="wp_seo_redirection_url" value="' . esc_attr($urlredirect_to) . '" size="62"></td>
147
+ </tr>
148
+ <tr>
149
+ <td>
150
+ <ul>
151
+ <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>
152
+ <li>' . __("If you have a caching plugin installed, clear cache to reflect the
153
+ changes immediately.", 'seo-redirection') . '</li>
154
+
155
+ <li>' . __("To remove the redirection, just uncheck the check box above and then click the button", 'seo-redirection') . ' <b>' . __("Update", 'seo-redirection') . '</b>.</li>
156
+ </ul>
157
+ </td>
158
+ </tr>
159
+ </table>
160
+ </div>';
161
+
162
+ echo "
163
+
164
+ <script type='text/javascript'>
165
+ function WSR_check_status(x)
166
+ {
167
+
168
+ if(x==0)
169
+ {
170
+ document.getElementById('redirect_check').checked=false;
171
+ document.getElementById('redirect_frame').style.display = 'none';
172
+ document.getElementById('wp_seo_redirection_url').value='';
173
+ }else
174
+ {
175
+ document.getElementById('redirect_check').checked=true;
176
+ document.getElementById('redirect_frame').style.display= 'block';
177
+ }
178
+
179
+ }
180
+
181
+ function redirect_check_click()
182
+ {
183
+ if(document.getElementById('redirect_check').checked)
184
+ WSR_check_status(1);
185
+ else
186
+ WSR_check_status(0);
187
+ }
188
+ </script>
189
+ ";
190
+
191
+ if ($urlredirect_to == '')
192
+ echo "<script type='text/javascript'>WSR_check_status(0);</script>";
193
+ else
194
+ echo "<script type='text/javascript'>WSR_check_status(1);</script>";
195
+
196
+
197
+ } else {
198
+ echo __('You can not make a redirection for the new posts before saving them.', 'seo-redirection');
199
+ }
200
+ }
201
+ }
202
+
203
+ //--------------------------------------------------------------------------------------------
204
+
205
+ //---------------------------------------------------------------
206
+ // added 2/2/2020
207
+ if(!function_exists("WPSR_get_site_404_page_path")) {
208
+
209
+ function WPSR_get_site_404_page_path()
210
+ {
211
+ $url = str_ireplace("://", "", site_url());
212
+ $site_404_page = substr($url, stripos($url, "/"));
213
+
214
+ if (stripos($url, "/") === FALSE || $site_404_page == "/")
215
+ $site_404_page = "/index.php?error=404";
216
+ else
217
+ $site_404_page = $site_404_page . "/index.php?error=404";
218
+
219
+ return $site_404_page;
220
+ }
221
+
222
+ }
223
+ //---------------------------------------------------------------
224
+ // updated 2/2/2020
225
+
226
+ function WPSR_check_default_permalink()
227
+ {
228
+ $file= get_home_path() . "/.htaccess";
229
+ $content="ErrorDocument 404 " . WPSR_get_site_404_page_path();
230
+
231
+ $marker_name="FRedirect_ErrorDocument";
232
+ $filestr ="";
233
+
234
+ if(file_exists($file)){
235
+ $f = @fopen( $file, 'r+' );
236
+ $filestr = @fread($f , filesize($file));
237
+ if (strpos($filestr , $marker_name) === false)
238
+ {
239
+ insert_with_markers( $file, $marker_name, $content );
240
+ }
241
+ }else
242
+ {
243
+ insert_with_markers( $file, $marker_name, $content );
244
+ }
245
+
246
+ }
247
+
248
+ //------------------------------------------------------------------------
249
+
250
+
251
+ /**
252
+ * Recursive sanitation for text or array
253
+ *
254
+ * @param $array_or_string (array|string)
255
+ * @since 0.1
256
+ * @return mixed
257
+ */
258
+ if(!function_exists("WPSR_sanitize_text_or_array_field")) {
259
+
260
+ function WPSR_sanitize_text_or_array_field($array_or_string)
261
+ {
262
+ if (is_string($array_or_string)) {
263
+ $array_or_string = sanitize_text_field($array_or_string);
264
+ } elseif (is_array($array_or_string)) {
265
+ foreach ($array_or_string as $key => &$value) {
266
+ if (is_array($value)) {
267
+ $value = WPSR_sanitize_text_or_array_field($value);
268
+ } else {
269
+ $value = sanitize_text_field($value);
270
+ }
271
+ }
272
+ }
273
+
274
+ return $array_or_string;
275
+ }
276
+ }
277
+ if(!function_exists("WPSR_get_post_redirection")) {
278
+
279
+ function WPSR_get_post_redirection($post_id)
280
+ {
281
+
282
+ global $wpdb, $util, $table_prefix;
283
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
284
+
285
+ // Autosave
286
+ if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
287
+ return;
288
+ // AJAX
289
+ if (defined('DOING_AJAX') && DOING_AJAX)
290
+ return;
291
+ // Post revision
292
+ if (false !== wp_is_post_revision($post_id))
293
+ return;
294
+
295
+ $redirect_from = isset($_POST['wp_seo_redirection_url_from']) ? WPSR_sanitize_text_or_array_field($_POST['wp_seo_redirection_url_from']) : '';
296
+ $redirect_to = isset($_POST['wp_seo_redirection_url']) ? WPSR_sanitize_text_or_array_field($_POST['wp_seo_redirection_url']) : '';
297
+
298
+ if ($redirect_to != '') {
299
+
300
+
301
+ $wpdb->get_results($wpdb->prepare("select ID from $table_name where postID=%d ", $post_id));
302
+
303
+ if ($wpdb->num_rows > 0) {
304
+
305
+ $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);
306
+ $wpdb->query($sql);
307
+
308
+ } else {
309
+ $wpdb->query($wpdb->prepare("delete from $table_name where redirect_from=%s", $redirect_from));
310
+ $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);
311
+ $wpdb->query($sql);
312
+ }
313
+
314
+
315
+ } else {
316
+ $wpdb->query($wpdb->prepare("delete from $table_name where postID=%d", $post_id));
317
+ }
318
+
319
+ $SR_redirect_cache = new free_SR_redirect_cache();
320
+ $SR_redirect_cache->free_cache();
321
+ }
322
+
323
+ }
324
+ //-------------------------------------------------------------
325
+ if(!function_exists("WPSR_log_404_redirection")) {
326
+
327
+ function WPSR_log_404_redirection($link)
328
+ {
329
+ global $wpdb, $table_prefix, $util;
330
+ $table_name = $table_prefix . 'WP_SEO_404_links';
331
+
332
+ $referrer = $util->get_ref();
333
+ $ip = $util->get_visitor_IP();
334
+ $country = "";//$util->get_visitor_country();
335
+ $os = $util->get_visitor_OS();
336
+ $browser = $util->get_visitor_Browser();
337
+
338
+ if ($os != 'Unknown' || $browser != 'Unknown') {
339
+ $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));
340
+ }
341
+ }
342
+
343
+ }
344
+ //-------------------------------------------------------------
345
+ if(!function_exists("WPSR_log_redirection_history")) {
346
+
347
+ function WPSR_log_redirection_history($rID, $postID, $rfrom, $rto, $rtype, $rsrc)
348
+ {
349
+ global $wpdb, $table_prefix, $util;
350
+ $SR_redirect_cache = new free_SR_redirect_cache();
351
+ $SR_redirect_cache->free_cache();
352
+ $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
353
+ $rfrom = esc_url($rfrom);
354
+ $referrer = $util->get_ref();
355
+ $ip = $util->get_visitor_IP();
356
+ $country = "";//$util->get_visitor_country();
357
+ $os = $util->get_visitor_OS();
358
+ $browser = $util->get_visitor_Browser();
359
+
360
+ $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));
361
+
362
+ $limit = $util->get_option_value('history_limit');
363
+
364
+ $expdate = date('Y-n-j', time() - (intval($limit) * 24 * 60 * 60));
365
+ $wpdb->query("delete FROM $table_name WHERE date_format(date(ctime),'%Y-%m-%d') < date_format(date('$expdate'),'%Y-%m-%d')");
366
+
367
+
368
+ }
369
+ }
370
+ //-------------------------------------------------------------
371
+ if(!function_exists("WPSR_make_redirect")) {
372
+
373
+ function WPSR_make_redirect($redirect_to, $redirect_type, $redirect_from, $obj = '')
374
+ {
375
+
376
+ global $wpdb, $util, $table_prefix, $post;
377
+
378
+ if (is_admin()) {
379
+ return 0;
380
+ }
381
+ $SR_redirect_cache = new free_SR_redirect_cache();
382
+ if ($redirect_to == $redirect_from || !$util->is_valid_url($redirect_to))
383
+ return 0;
384
+
385
+ if ($util->make_relative_url($redirect_from) == $util->make_relative_url($redirect_to))
386
+ return 0;
387
+
388
+ if (substr($redirect_from, -1) == "/" || substr($redirect_to, -1) == "/") {
389
+ if (substr($redirect_from, -1) != "/") {
390
+ if (($redirect_from . "/") == $redirect_to)
391
+ return 0;
392
+ } else {
393
+ if (($redirect_to . "/") == $redirect_from)
394
+ return 0;
395
+ }
396
+ }
397
+
398
+
399
+ if ($util->make_relative_url($redirect_from) == $util->make_relative_url($redirect_to))
400
+ return 0;
401
+
402
+ if (is_object($obj)) {
403
+ if ($obj->ID > 0) {
404
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
405
+ $sql = "update " . $table_name . " set hits=hits+1, access_date= NOW() where ID='" . $obj->ID . "'";
406
+ $wpdb->query($sql);
407
+ }
408
+ }
409
+
410
+ if (is_object($obj) && $obj->redirect_to_type == 'Folder' && $obj->redirect_to_folder_settings == '2') {
411
+
412
+ if ($obj->redirect_from_type == 'Folder') {
413
+
414
+ if ($obj->redirect_from_folder_settings == '2' || $obj->redirect_from_folder_settings == '3') {
415
+ if (strlen($redirect_from) > strlen($obj->redirect_from)) {
416
+ $difference = substr($redirect_from, intval(strlen($obj->redirect_from) - strlen($redirect_from)));
417
+ $redirect_to = $redirect_to . $difference;
418
+ }
419
+ }
420
+
421
+ } else if ($obj->redirect_from_type == 'Regex') {
422
+ $page = substr(strrchr($redirect_from, "/"), 1);
423
+ $redirect_to = $redirect_to . '/' . $page;
424
+ }
425
+
426
+ }
427
+
428
+ $rID = 0;
429
+ $rsrc = '404';
430
+ $postID = 0;
431
+
432
+ if (is_object($obj)) {
433
+ $rID = $obj->ID;
434
+ $postID = $obj->postID;
435
+ if ($obj->url_type == 1)
436
+ $rsrc = 'Custom';
437
+ else if ($obj->url_type == 2)
438
+ $rsrc = 'Post';
439
+
440
+ }
441
+
442
+ if ($util->get_option_value('history_status') == '1') {
443
+
444
+ WPSR_log_redirection_history($rID, $postID, $redirect_from, $redirect_to, $redirect_type, $rsrc);
445
+ }
446
+
447
+ $redirect_to = $util->make_absolute_url($redirect_to);
448
+
449
+
450
+ if (is_singular()) {
451
+ //$SR_redirect_cache = new free_SR_redirect_cache();
452
+
453
+ $SR_redirect_cache->add_redirect($post->ID, 1, $redirect_from, $redirect_to, $redirect_type);
454
+ $SR_redirect_cache->free_cache();
455
+ }
456
+
457
+ if ($redirect_type == '301') {
458
+ header('HTTP/1.1 301 Moved Permanently');
459
+ header("Location: " . $redirect_to);
460
+ exit();
461
+ } else if ($redirect_type == '307') {
462
+ header('HTTP/1.0 307 Temporary Redirect');
463
+ header("Location: " . $redirect_to);
464
+ exit();
465
+ } else if ($redirect_type == '302') {
466
+ header("Location: " . $redirect_to);
467
+ exit();
468
+ }
469
+
470
+ }
471
+ }
472
+
473
+ //-------------------------------------------------------------
474
+ if(!function_exists("WPSR_redirect")) {
475
+
476
+ function WPSR_redirect()
477
+ {
478
+ global $wpdb, $post, $table_prefix, $util;
479
+
480
+
481
+ if ($util->get_option_value('plugin_status') != '0') { // if not disabled
482
+
483
+ // if disable for admin and the user is admin
484
+ if (current_user_can('manage_options') == 1 && $util->get_option_value('plugin_status') == 2) {
485
+ // nothing
486
+
487
+ } else {
488
+
489
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
490
+ $permalink = urldecode($util->get_current_relative_url());
491
+
492
+ if (substr($permalink, 0, 1) == ":") {
493
+ $first_slash = stripos($permalink, "/");
494
+ $permalink = substr($permalink, $first_slash, strlen($permalink) - $first_slash);
495
+ }
496
+ $permalink_alternative = "";
497
+ if (substr($permalink, -1) == '/') {
498
+ $permalink_alternative = substr($permalink, 0, intval(strlen($permalink) - 1));
499
+ } else {
500
+ $permalink_alternative = $permalink . '/';
501
+ }
502
+
503
+ $post_cache_result = "";
504
+ $SR_redirect_cache = new free_SR_redirect_cache();
505
+ if (is_singular()) {
506
+ $post_cache_result = $SR_redirect_cache->redirect_cached($post->ID);
507
+ }
508
+
509
+ if ($post_cache_result == 'not_redirected') {
510
+
511
+ return 0;
512
+ }
513
+
514
+ $permalink_options = $wpdb->prepare("( redirect_from = %s OR redirect_from = %s)", $permalink, $permalink_alternative);
515
+
516
+ $permalink_regex_options = $wpdb->prepare("(%s regexp regex or %s regexp regex )", $permalink, $permalink_alternative);
517
+
518
+
519
+ 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))) {
520
+
521
+ $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex='' and $permalink_options ");
522
+ if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
523
+ WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
524
+ }
525
+
526
+ $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex<>'' and $permalink_regex_options order by LENGTH(regex) desc ");
527
+ if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
528
+ WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
529
+ }
530
+
531
+
532
+ if (is_404()) {
533
+
534
+ if ($util->get_option_value('p404_discovery_status') == '1') {
535
+ WPSR_log_404_redirection($permalink);
536
+ }
537
+
538
+ $options = $util->get_my_options();
539
+ if ($options['p404_status'] == '1') {
540
+
541
+ WPSR_make_redirect($options['p404_redirect_to'], '301', $permalink);
542
+
543
+ }
544
+ }
545
+ }
546
+
547
+ if (is_singular() && $post_cache_result == 'not_found') {
548
+ $SR_redirect_cache->add_redirect($post->ID, 0, '', '', 0);
549
+ }
550
+
551
+ }
552
+ }
553
+ }
554
+ }
555
+ //---------------------------------------------------------------
556
+ if(!function_exists("WPSR_header_code")) {
557
+
558
+ function WPSR_header_code()
559
+ {
560
+
561
+ $my_page = isset($_REQUEST['page']) ? $_REQUEST['page'] : '';
562
+ if ($my_page == 'seo-redirection.php') {
563
+
564
+ wp_register_style('c_admin_css_common', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "style.css");
565
+ wp_enqueue_style('sweetalert', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "sweetalert.css");
566
+ wp_register_style('c_admin_css_custom', plugins_url() . '/' . basename(dirname(__FILE__)) . '/custom/' . "style.css");
567
+ wp_enqueue_script('jquery');
568
+ wp_localize_script('jquery', 'seoredirection', array('ajax_url' => admin_url('admin-ajax.php'), 'msg' => ""));
569
+ wp_enqueue_style('c_admin_css_common');
570
+ wp_enqueue_style('c_admin_css_custom');
571
+
572
+ wp_enqueue_script('custom', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/js/' . 'bootstrap.min.js', array('jquery'), false, true);
573
+ wp_enqueue_script('customJS', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "customJs.js", array('jquery'), 1.1, true);
574
+ wp_enqueue_script('sweetalert', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/js/' . "sweetalert.min.js", array('jquery'), false, true);
575
+
576
+ wp_enqueue_style('bootstrap', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "bootstrap.css");
577
+
578
+
579
+ }
580
+ }
581
+ }
582
+ //---------------------------------------------------------------
583
+ if(!function_exists("WPSR_customAddUpdate_callback")) {
584
+
585
+ add_action("wp_ajax_customAddUpdate", "WPSR_customAddUpdate_callback");
586
+
587
+ function WPSR_customAddUpdate_callback()
588
+ {
589
+ global $wpdb, $table_prefix, $util;
590
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
591
+ $table_name_404 = $table_prefix . 'WP_SEO_404_links';
592
+ parse_str($_POST['formData'], $_POST);
593
+ $nonce = "";
594
+ if (isset($_POST['_wpnonce']))
595
+ $nonce = WPSR_sanitize_text_or_array_field($_POST['_wpnonce']);
596
+ $data = array();
597
+ $data['error_string'] = array();
598
+ $data['inputerror'] = array();
599
+ $data['bool'] = TRUE;
600
+ if (trim($_POST['redirect_from']) == '') {
601
+ $data['inputerror'][] = 'redirect_from';
602
+ $data['error_string'][] = __("You must input the 'Redirect From' URL", "seo-redirection");
603
+ $data['bool'] = FALSE;
604
+ }
605
+
606
+ $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
607
+
608
+ /* $wpdb->get_results(" select ID from $table_name where redirect_from='" . trim($redirect_from) . "' ");
609
+ if ($wpdb->num_rows > 0) {
610
+ $data['inputerror'][] = 'redirect_from';
611
+ $data['error_string'][] = __("This 'Redirect From' value already exists in database!", "seo-redirection");
612
+ $data['bool'] = FALSE;
613
+ }
614
+
615
+ */
616
+ // elseif (!preg_match( '/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/', $_POST['redirect_from'])) {
617
+ // $data['inputerror'][] = 'redirect_from';
618
+ // $data['error_string'][] = __("Invalid redirect from target URL!",'seo-redirection');
619
+ // $data['bool'] = FALSE;
620
+ // }
621
+ if (trim($_POST['redirect_to']) == '') {
622
+ $data['inputerror'][] = 'redirect_to';
623
+ $data['error_string'][] = __("You must input the 'Redirect To' URL", "seo-redirection");
624
+ $data['bool'] = FALSE;
625
+ } elseif ($_POST['edit_exist'] == '' && substr(strtolower($_POST['redirect_to']), 0, 4) != "http" && substr(strtolower($_POST['redirect_to']), 0, 1) != "/") {
626
+ $data['inputerror'][] = 'redirect_to';
627
+ $data['error_string'][] = __("Invalid redirect target URL!", 'seo-redirection');
628
+ $data['bool'] = FALSE;
629
+ }
630
+ if ($data['bool'] === FALSE) {
631
+ echo json_encode($data);
632
+ exit();
633
+ } else {
634
+ if ($_POST['redirect_from'] != '' && wp_verify_nonce($nonce, 'seoredirection')) {
635
+
636
+
637
+ $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
638
+ $redirect_to = isset($_POST['redirect_to']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_to']) : '';
639
+
640
+
641
+ $redirect_from = urldecode($util->make_relative_url($redirect_from));
642
+
643
+ $redirect_to = $util->make_relative_url($redirect_to);
644
+ $redirect_type = WPSR_sanitize_text_or_array_field($_POST['redirect_type']);
645
+
646
+ $redirect_from_type = WPSR_sanitize_text_or_array_field($_POST['redirect_from_type']);
647
+ $redirect_from_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_from_folder_settings']);
648
+ $redirect_from_subfolders = WPSR_sanitize_text_or_array_field($_POST['redirect_from_subfolders']);
649
+
650
+ $redirect_to_type = WPSR_sanitize_text_or_array_field($_POST['redirect_to_type']);
651
+ $redirect_to_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_to_folder_settings']);
652
+
653
+ $enabled = WPSR_sanitize_text_or_array_field($_POST['enabled']);
654
+
655
+ $regex = "";
656
+
657
+ if ($redirect_from_type == 'Folder') {
658
+
659
+ if (substr($redirect_from, -1) != '/')
660
+ $redirect_from = $redirect_from . '/';
661
+
662
+ if ($redirect_from_folder_settings == 2) {
663
+ if ($redirect_from_subfolders == 0) {
664
+ $regex = '^' . $util->regex_prepare($redirect_from) . '.*';;
665
+ } else {
666
+ $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]*$';
667
+ }
668
+ } else if ($redirect_from_folder_settings == 3) {
669
+ if ($redirect_from_subfolders == 0) {
670
+ $regex = '^' . $util->regex_prepare($redirect_from) . '.+';
671
+ } else {
672
+ $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]+$';
673
+ }
674
+ }
675
+
676
+ } else if ($redirect_from_type == 'Regex') {
677
+ $regex = $redirect_from;
678
+ }
679
+
680
+ if ($redirect_from_type == 'Page' || $redirect_from_type == 'Regex') {
681
+ $redirect_from_folder_settings = "";
682
+ $redirect_from_subfolders = "";
683
+ }
684
+
685
+ if ($redirect_to_type == 'Page') {
686
+ $redirect_to_folder_settings = "";
687
+ }
688
+
689
+ if ($redirect_to_type == 'Folder') {
690
+ if (substr($redirect_to, -1) != '/')
691
+ $redirect_to = $redirect_to . '/';
692
+ }
693
+
694
+
695
+ if ($_POST['add_new'] != '') {
696
+
697
+ $theurl = $wpdb->get_row($wpdb->prepare(" select count(ID) as cnt from $table_name where redirect_from=%s ", $redirect_from));
698
+
699
+ if ($theurl->cnt > 0) {
700
+ $msg = __("This URL", 'seo-redirection') . " <b>".esc_html($redirect_from)."</b>" . __("is added previously!", 'seo-redirection');
701
+ echo json_encode(array('status' => 'error', 'msg' => $msg));
702
+ // $util->failure_option_msg(__("This URL",'seo-redirection')." <b>'$redirect_from'</b>". __("is added previously!",'seo-redirection'));
703
+ } else {
704
+
705
+
706
+ if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
707
+ $util->failure_option_msg(__('Please input all required fields!', 'seo-redirection'));
708
+ } else {
709
+
710
+ $wpdb->insert($table_name, array(
711
+ 'redirect_from' => $redirect_from,
712
+ 'redirect_to' => $redirect_to,
713
+ 'redirect_type' => $redirect_type,
714
+ 'url_type' => 1,
715
+ 'redirect_from_type' => $redirect_from_type,
716
+ 'redirect_from_folder_settings' => $redirect_from_folder_settings,
717
+ 'redirect_from_subfolders' => $redirect_from_subfolders,
718
+ 'redirect_to_type' => $redirect_to_type,
719
+ 'redirect_to_folder_settings' => $redirect_to_folder_settings,
720
+ 'regex' => $regex,
721
+ 'enabled' => $enabled
722
+
723
+ ));
724
+
725
+ $wpdb->query($wpdb->prepare(" delete from $table_name_404 where link=%s ", $redirect_from));
726
+ $SR_redirect_cache = new free_SR_redirect_cache();
727
+ $SR_redirect_cache->free_cache();
728
+ $msg = "Redirection Added Successfully";
729
+ echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
730
+ die;
731
+ }
732
+
733
+ }
734
+ } else if ($_POST['edit_exist'] != '') {
735
+
736
+ $edit = WPSR_sanitize_text_or_array_field($_POST['edit']);
737
+
738
+ if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
739
+ $util->failure_option_msg('Please input all required fields!');
740
+ } else {
741
+
742
+ $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));
743
+
744
+ $SR_redirect_cache = new free_SR_redirect_cache();
745
+ $SR_redirect_cache->free_cache();
746
+ }
747
+ $msg = "Redirection Update Successfully";
748
+ echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
749
+ die;
750
+
751
+ }
752
+
753
+ if ($util->there_is_cache() != '')
754
+ $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'));
755
+
756
+ }
757
+
758
+ }
759
+
760
+
761
+ die;
762
+ }
763
+ }
764
+ if(!function_exists("WPSR_customUpdateRec_callback")) {
765
+
766
+ add_action("wp_ajax_customUpdateRec", "WPSR_customUpdateRec_callback");
767
+ function WPSR_customUpdateRec_callback()
768
+ {
769
+
770
+
771
+ global $wpdb, $table_prefix, $util;
772
+
773
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
774
+ $table_name_404 = $table_prefix . 'WP_SEO_404_links';
775
+
776
+ $myid = (int)$_POST['ID'];
777
+ $item = $wpdb->get_row($wpdb->prepare(" select * from $table_name where ID=%d ", $myid));
778
+
779
+ if ($wpdb->num_rows == 0) {
780
+ echo json_encode(array('status' => 'error', 'msg' => __("Sorry, this redirect rule is not found, it may deleted by the user!", 'seo-redirection')));
781
+ die;
782
+ }
783
+
784
+
785
+ $data = array(
786
+ "redirect_from" => $item->redirect_from,
787
+ "redirect_to" => $item->redirect_to,
788
+ "redirect_type" => $item->redirect_type,
789
+
790
+ "redirect_from_type" => $item->redirect_from_type,
791
+ "redirect_from_folder_settings" => $item->redirect_from_folder_settings,
792
+ "redirect_from_subfolders" => $item->redirect_from_subfolders,
793
+
794
+ "redirect_to_type" => $item->redirect_to_type,
795
+ "redirect_to_folder_settings" => $item->redirect_to_folder_settings,
796
+
797
+ "enabled" => $item->enabled
798
+ );
799
+ echo json_encode(array('status' => 'suucess', 'rec' => $data));
800
+ die;
801
+ }
802
+ }
803
+
804
+ if(!function_exists("WPSR_admin_menu")) {
805
+
806
+ function WPSR_admin_menu()
807
+ {
808
+ add_options_page('SEO Redirection', 'SEO Redirection', 'manage_options', basename(__FILE__), 'WPSR_options_menu');
809
+ }
810
+ }
811
+ //---------------------------------------------------------------
812
+ if(!function_exists("WPSR_options_menu")) {
813
+
814
+ function WPSR_options_menu()
815
+ {
816
+ global $util;
817
+
818
+ if (!current_user_can('manage_options')) {
819
+ wp_die(__('You do not have sufficient permissions to access this page.', 'seo-redirection'));
820
+ }
821
+
822
+
823
+ if ($util->get_option_value('plugin_status') == '0') {
824
+ $util->info_option_msg(__('SEO Redirection is disabled now, you can go to option tab and enable it!', 'seo-redirection'));
825
+ } else if ($util->get_option_value('plugin_status') == '2') {
826
+ $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'));
827
+ }
828
+ $total_404_errors = (WPSR_Get_total_404() > 5) ? __('You have', 'seo-redirection') . ' <b style="color:red; background-color:yellow; padding:3px;">' . intval(WPSR_Get_total_404()) .'</b>' . __(' broken link (404 links)', 'seo-redirection') . ', <br>'.'<div class="wrap" style="font-weight:normal; line-height:30px">' . __('Upgrade to', 'wsr') . ' <a target="_blank" href="https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin">' . __("pro version", "wsr") . '</a>' . __(" to manage 404 errors and empower your site SEO", "wsr").'</div>' : '';
829
+
830
+
831
+ echo '<div class="wrap"><h2>' . __("SEO Redirection Free", 'seo-redirection') . '</h2><b>' . __('Upgrade to', 'seo-redirection') . ' <a target="_blank" onclick="swal.clickConfirm();" href="https://www.wp-buy.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/>';
832
+
833
+ if ($total_404_errors != '') {
834
+ ?>
835
+ <script type="text/javascript">
836
+
837
+ seoredirection.msg = '<?php echo wp_kses_post($total_404_errors); ?>';
838
+
839
+ </script>
840
+
841
+ <?php
842
+ }
843
+
844
+ if (is_multisite()) {
845
+
846
+ 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="https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/">
847
+ https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/</a>) <p></p></div>';
848
+
849
+ }
850
+
851
+ $mytabs = new phptab();
852
+
853
+ $mytabs->set_ignore_parameter(array( 'search', 'page_num', 'add', 'edit', 'page404', 'do_404_del'));
854
+ $mytabs->add_file_tab('cutom', __('Custom Redirects', 'seo-redirection'), 'option_page_custome_redirection.php', 'file');
855
+ $mytabs->add_file_tab('posts', __('Post Redirects', 'seo-redirection'), 'option_page_post_redirection_list.php', 'file');
856
+ $mytabs->add_file_tab('history', __('History', 'seo-redirection'), 'option_page_history.php', 'file');
857
+ $mytabs->add_file_tab('404', '<span style="color:red;"><b>404 Errors</b></span>', 'option_page_404.php', 'file');
858
+ $mytabs->add_file_tab('goptions', __('Options', 'seo-redirection'), 'option_page_goptions.php', 'file');
859
+ $mytabs->add_file_tab('help', '<span style="color:green;"><b>' . __('Help', 'seo-redirection') . '</b></span>', 'help.php', 'file');
860
+ $mytabs->add_file_tab('premium', '<span style="color:brown;"><b>&#9658; ' . __('Premium Features', 'seo-redirection') . '</b></span>', 'premium.php', 'file');
861
+ $mytabs->run();
862
+
863
+ $imgpath = $util->get_plugin_url() . 'custom/images/';
864
+
865
+ echo '<p>&nbsp;</p><p style="color:green"><a target="_blank" href="http://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin"><b>' . __("Upgrade to premium version now", "wsr") . '</b></a>' . __(" to get more features", "wsr") . ' , <small>' . __("The premium version of SEO redirection is completely different from the free version as there are a lot more features included.", "wsr") . '</small></p>';
866
+ echo __('<p><a href="https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin" target="_blank"><img src="' . $imgpath . 'seopro.png" /></a></p>');
867
+ }
868
+ }
869
+ if(!function_exists("WPSR_upgrade")) {
870
+
871
+ function WPSR_upgrade()
872
+ {
873
+
874
+ $util = new clogica_util_1();
875
+ $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
876
+
877
+ if ($util->get_option_value('plugin_version') != WP_SEO_REDIRECTION_VERSION) {
878
+ WPSR_install();
879
+ $util->update_option('plugin_version', WP_SEO_REDIRECTION_VERSION);
880
+ }
881
+ }
882
+ }
883
+ //-----------------------------------------------------
884
+ if(!function_exists("WPSR_install")) {
885
+
886
+ function WPSR_install()
887
+ {
888
+ global $wpdb, $table_prefix;
889
+
890
+ $util = new clogica_util_1();
891
+ $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
892
+
893
+ $options = get_option(WP_SEO_REDIRECTION_OPTIONS);
894
+ if (!is_array($options)) {
895
+ add_option(WP_SEO_REDIRECTION_OPTIONS);
896
+ $options = array();
897
+ }
898
+
899
+
900
+ if (!array_key_exists('plugin_status', $options))
901
+ $options['plugin_status'] = '1';
902
+
903
+ if (!array_key_exists('ip_logging_status', $options))
904
+ $options['ip_logging_status'] = '1';
905
+
906
+ if (!array_key_exists('redirection_base', $options))
907
+ $options['redirection_base'] = site_url();
908
+
909
+ if (!array_key_exists('redirect_control_panel', $options))
910
+ $options['redirect_control_panel'] = '1';
911
+
912
+ if (!array_key_exists('show_redirect_box', $options))
913
+ $options['show_redirect_box'] = '1';
914
+
915
+ if (!array_key_exists('reflect_modifications', $options))
916
+ $options['reflect_modifications'] = '1';
917
+
918
+ if (!array_key_exists('history_status', $options))
919
+ $options['history_status'] = '1';
920
+
921
+ if (!array_key_exists('history_limit', $options))
922
+ $options['history_limit'] = '30';
923
+
924
+ if (!array_key_exists('p404_discovery_status', $options))
925
+ $options['p404_discovery_status'] = '1';
926
+
927
+ if (!array_key_exists('p404_redirect_to', $options))
928
+ $options['p404_redirect_to'] = site_url();
929
+
930
+ if (!array_key_exists('p404_status', $options))
931
+ $options['p404_status'] = '2';
932
+
933
+ if (!array_key_exists('keep_data', $options))
934
+ $options['keep_data'] = '1';
935
+
936
+ update_option(WP_SEO_REDIRECTION_OPTIONS, $options);
937
+
938
+
939
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
940
+ if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
941
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
942
+ `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
943
+ `enabled` int(1) NOT NULL DEFAULT '1',
944
+ `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
945
+ `redirect_from_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
946
+ `redirect_from_folder_settings` int(1) NOT NULL,
947
+ `redirect_from_subfolders` int(1) NOT NULL DEFAULT '1',
948
+ `redirect_to` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
949
+ `redirect_to_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
950
+ `redirect_to_folder_settings` int(1) NOT NULL DEFAULT '1',
951
+ `regex` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
952
+ `redirect_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
953
+ `url_type` int(2) NOT NULL DEFAULT 1,
954
+ `postID` int(11) unsigned DEFAULT NULL,
955
+ `import_flag` tinyint(1) NOT NULL DEFAULT 0,
956
+ `hits` int(11) unsigned NOT NULL DEFAULT 0,
957
+ `access_date` datetime DEFAULT NULL,
958
+ PRIMARY KEY (`ID`),
959
+ UNIQUE KEY `redirect_from` (`redirect_from`)
960
+ )ENGINE = MyISAM ;";
961
+ $wpdb->query($sql);
962
+
963
+
964
+ } else {
965
+ //check if Innodb convert it to myisam.
966
+ $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
967
+ if ($status->Engine == 'InnoDB') {
968
+ $wpdb->query("alter table $table_name engine = MyISAM;");
969
+ }
970
+
971
+ /* add column for import flag */
972
+ $column_data = $wpdb->get_row("SHOW COLUMNS FROM $table_name LIKE 'import_flag'");
973
+
974
+ if (!$column_data) {
975
+ $wpdb->query("ALTER TABLE $table_name ADD COLUMN import_flag tinyint(1) DEFAULT 0");
976
+ }
977
+
978
+ // if the table exists
979
+ $redirects = $wpdb->get_results(" select redirect_from,redirect_to,ID from $table_name; ");
980
+ foreach ($redirects as $redirect) {
981
+ $redirect_from = $util->make_relative_url($redirect->redirect_from);
982
+ $redirect_to = $util->make_relative_url($redirect->redirect_to);
983
+ $ID = $redirect->ID;
984
+ $wpdb->query($wpdb->prepare(" update $table_name set redirect_from=%s,redirect_to=%s where ID=%d", $redirect_from, $redirect_to, $ID));
985
+ }
986
+
987
+ // Fix add blog field if not exist.
988
+ if ($wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
989
+ WHERE TABLE_NAME = '$table_name'
990
+ AND table_schema = DATABASE()
991
+ AND COLUMN_NAME = 'hits' ") == '0') {
992
+
993
+ $sql = "
994
+ ALTER TABLE $table_name
995
+ ADD COLUMN `hits` int(11) unsigned NOT NULL DEFAULT 0,
996
+ ADD COLUMN `access_date` datetime DEFAULT NULL;
997
+ ";
998
+
999
+ $wpdb->query($sql);
1000
+ }
1001
+
1002
+
1003
+ }
1004
+
1005
+ $table_name = $table_prefix . 'WP_SEO_Cache';
1006
+ if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1007
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1008
+ `ID` int(11) unsigned NOT NULL,
1009
+ `is_redirected` int(1) unsigned NOT NULL,
1010
+ `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1011
+ `redirect_to` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1012
+ `redirect_type` int(3) unsigned NOT NULL DEFAULT 301,
1013
+ PRIMARY KEY (`ID`)
1014
+ ) ENGINE = MyISAM ;
1015
+ ";
1016
+ $wpdb->query($sql);
1017
+ } else {
1018
+ //check if Innodb convert it to myisam.
1019
+ $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1020
+ if ($status->Engine == 'InnoDB') {
1021
+ $wpdb->query("alter table $table_name engine = MyISAM;");
1022
+ }
1023
+ }
1024
+
1025
+
1026
+ $res = $wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1027
+ WHERE TABLE_NAME = '$table_name'
1028
+ AND table_schema = DATABASE()
1029
+ AND COLUMN_NAME = 'redirect_from' ");
1030
+
1031
+ if ($res == '0') {
1032
+
1033
+ $sql = "
1034
+ ALTER TABLE $table_name
1035
+ ADD COLUMN `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL;
1036
+ ";
1037
+ $wpdb->query($sql);
1038
+ }
1039
+
1040
+
1041
+ $table_name = $table_prefix . 'WP_SEO_404_links';
1042
+ if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1043
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1044
+ `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1045
+ `ctime` datetime NOT NULL,
1046
+ `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1047
+ `referrer` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1048
+ `ip` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1049
+ `country` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
1050
+ `os` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1051
+ `browser` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1052
+ PRIMARY KEY (`ID`),
1053
+ UNIQUE KEY `link` (`link`)
1054
+ ) ENGINE = MyISAM ;
1055
+ ";
1056
+ $wpdb->query($sql);
1057
+ } else {
1058
+ //check if Innodb convert it to myisam.
1059
+ $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1060
+ if ($status->Engine == 'InnoDB') {
1061
+ $wpdb->query("alter table $table_name engine = MyISAM;");
1062
+ }
1063
+ }
1064
+
1065
+
1066
+ $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
1067
+ if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1068
+ $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1069
+ `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1070
+ `rID` int(11) unsigned DEFAULT NULL,
1071
+ `postID` int(11) unsigned DEFAULT NULL,
1072
+ `ctime` datetime NOT NULL,
1073
+ `rfrom` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1074
+ `rto` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1075
+ `rtype` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1076
+ `rsrc` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1077
+ `referrer` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1078
+ `ip` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1079
+ `country` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
1080
+ `os` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1081
+ `browser` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1082
+ PRIMARY KEY (`ID`)
1083
+ ) ENGINE = MyISAM ;
1084
+ ";
1085
+
1086
+ $wpdb->query($sql);
1087
+ } else {
1088
+ //check if Innodb convert it to myisam.
1089
+ $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1090
+ if ($status->Engine == 'InnoDB') {
1091
+ $wpdb->query("alter table $table_name engine = MyISAM;");
1092
+ }
1093
+
1094
+ $res = $wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1095
+ WHERE TABLE_NAME = '$table_name'
1096
+ AND table_schema = DATABASE()
1097
+ AND COLUMN_NAME = 'postID' ");
1098
+
1099
+ if ($res == '0') {
1100
+
1101
+ $sql = "
1102
+ ALTER TABLE $table_name
1103
+ ADD COLUMN `postID` int(11) unsigned DEFAULT NULL;
1104
+ ";
1105
+ $wpdb->query($sql);
1106
+ }
1107
+
1108
+
1109
+ }
1110
+
1111
+ }
1112
+
1113
+ }
1114
+ //---------------------------------------------------------------
1115
+
1116
+ if(!function_exists("WPSR_uninstall")) {
1117
+
1118
+ function WPSR_uninstall()
1119
+ {
1120
+ global $wpdb, $table_prefix;
1121
+
1122
+ $util = new clogica_util_1();
1123
+ $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
1124
+
1125
+
1126
+ if ($util->get_option_value('keep_data') != '1') {
1127
+
1128
+ $table_name = $table_prefix . 'WP_SEO_Redirection';
1129
+ $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1130
+
1131
+ $table_name = $table_prefix . 'WP_SEO_Cache';
1132
+ $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1133
+
1134
+ $table_name = $table_prefix . 'WP_SEO_404_links';
1135
+ $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1136
+
1137
+ $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
1138
+ $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1139
+
1140
+
1141
+ $util->delete_my_options();
1142
+ }
1143
+
1144
+
1145
+ }
1146
+
1147
+ }
1148
+ //---------------------------------------------------------------
1149
+ if(!function_exists("WPSR_HideMessageAjaxFunction")) {
1150
+
1151
+ function WPSR_HideMessageAjaxFunction()
1152
+ {
1153
+ add_option('nsr_upgrade_message', 'yes');
1154
+ }
1155
+ }
1156
+ //---------------------------------------------------------------
1157
+ if(!function_exists("WPSR_admin_notice_callback")) {
1158
+
1159
+ /* display import from redirection plugin in admin notice */
1160
+ function WPSR_admin_notice_callback() {
1161
+ global $wpdb;
1162
+ global $current_user;
1163
+ $plugins = get_option( 'active_plugins', array() );
1164
+ $found = false;
1165
+ $user_id = $current_user->ID;
1166
+ $val = get_user_meta($user_id, 'sr_notice_dismissed',true);
1167
+
1168
+ foreach ( $plugins as $plugin )
1169
+ {
1170
+ if ( strpos( strval($plugin), 'redirection.php' ) == true && $val != 1 && strpos( strval($plugin), 'seo-redirection.php' ) == FALSE )
1171
+ {
1172
+ $found = true;
1173
+ //$total = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_items");
1174
+ $total = WPSR_getRedirectCount();
1175
+ if($total > 0){
1176
+ ?>
1177
+ <div class="notice-success notice is-dismissible sr_notice">
1178
+ <p>
1179
+ <strong><?php _e('SEO Redirection : ', 'seo-redirection'); ?></strong><?php echo __( 'The plugin detected ','seo-redirection').intval($total).__(' redirects in the Redirection plugin, Import it now. ','seo-redirection'); ?>
1180
+ <?php
1181
+ $SR_import = isset($_GET['SR_import']) ? sanitize_text_field($_GET['SR_import']) : '';
1182
+ if($SR_import == 'yes'){?>
1183
+ <button type='button' data-toggle="modal" class="button" href="#" data-target="#import_modal" value="btn_import"><span style="margin-top: 3px;" class="dashicons dashicons-migrate"></span>&nbsp; <?php _e('Import Now','seo-redirection'); ?></button>
1184
+ <?php }else{ ?>
1185
+ <a href="options-general.php?page=seo-redirection.php&tab=export_import&SR_import=yes" data-target="#import_modal" value="btn_import"><?php _e('Import','seo-redirection'); ?></a>
1186
+ <?php }?>
1187
+ </p>
1188
+ </div>
1189
+ <?php
1190
+ }
1191
+ break;
1192
+ }
1193
+ }
1194
+ }
1195
+ add_action( 'admin_notices', 'WPSR_admin_notice_callback' );
1196
+ }
1197
+
1198
+ if(!function_exists("WPSR_dismiss_notice_callback")) {
1199
+
1200
+ add_action('wp_ajax_sr_dismiss_notice', 'WPSR_dismiss_notice_callback');
1201
+ function WPSR_dismiss_notice_callback()
1202
+ {
1203
+ global $current_user;
1204
+ $user_id = $current_user->ID;
1205
+ update_user_meta($user_id, 'sr_notice_dismissed', '1');
1206
+ echo "1";
1207
+ exit;
1208
+ }
1209
+ }
1210
+ if(!function_exists("WPSR_getRedirectCount")) {
1211
+
1212
+ function WPSR_getRedirectCount()
1213
+ {
1214
+ global $wpdb;
1215
+
1216
+ $table_name_ = $wpdb->prefix . 'redirection_items';
1217
+ if (strtolower($wpdb->get_var("show tables like '$table_name_'")) == strtolower($table_name_)) {
1218
+ $result = $wpdb->get_results("SELECT url FROM {$wpdb->prefix}redirection_items");
1219
+ $cnt = 0;
1220
+ $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
1221
+ if ($result) {
1222
+ foreach ($result as $redirect) {
1223
+ $redirect_from = stripslashes($redirect->url);
1224
+ $redirect_from_slash = ltrim(stripslashes($redirect->url), '/');
1225
+ $redirectID = $wpdb->get_var($wpdb->prepare("select ID from $table_name where redirect_from=%s or redirect_from=%s", $redirect_from, $redirect_from_slash));
1226
+ if ($redirectID > 0) {
1227
+
1228
+ } else {
1229
+ $cnt++;
1230
+ }
1231
+ }
1232
+
1233
+ }
1234
+ return $cnt;
1235
+ } else {
1236
+ return 0;
1237
+ }
1238
+ }
1239
+ }
1240
+ if(!function_exists("SR_init_delete_callback")) {
1241
+
1242
+ add_action('admin_init', 'SR_init_delete_callback');
1243
+ function SR_init_delete_callback()
1244
+ {
1245
+ if (isset($_POST['redirect_id']) && count($_POST['redirect_id']) > 0) {
1246
+
1247
+ $nonce = '';
1248
+ if(isset($_REQUEST['_wpnonce']))
1249
+ $nonce = WPSR_sanitize_text_or_array_field($_REQUEST['_wpnonce']);
1250
+
1251
+ if(wp_verify_nonce( $nonce, 'seoredirection' )){
1252
+
1253
+ global $wpdb, $table_prefix, $util;
1254
+ $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
1255
+ foreach ($_POST['redirect_id'] as $post_id) {
1256
+ $post_id = (int)$post_id;
1257
+ $wpdb->query($wpdb->prepare(" delete from $table_name where ID=%s ", $post_id));
1258
+ $SR_redirect_cache = new free_SR_redirect_cache();
1259
+ $SR_redirect_cache->free_cache();
1260
+ }
1261
+ }
1262
+ }
1263
+ }
1264
+ }
1265
+
1266
+
1267
+
1268
+
1269
+ //---------------------------------------------------------------
1270
+
1271
+ function WPSR_HideMessageAjaxFunction()
1272
+ {
1273
+ add_option('nsr_upgrade_message', 'yes');
1274
+ }
1275
+
1276
+
1277
+ function WPSR_after_plugin_row($plugin_file, $plugin_data, $status)
1278
+ {
1279
+
1280
+ if (get_option('nsr_upgrade_message') != 'yes') {
1281
+ $class_name = $plugin_data['slug'];
1282
+
1283
+ echo '<tr id="' . $class_name . '-plugin-update-tr" class="plugin-update-tr active">';
1284
+ echo '<td colspan="6" class="plugin-update">';
1285
+ echo '<div id="' . $class_name . '-upgradeMsg" class="update-message notice inline notice-warning notice-alt" >';
1286
+
1287
+ echo 'You are running SEO redirection free. To get more features, you can <a href="http://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin" target="_blank"><strong>upgrade now</strong></a> or ';
1288
+
1289
+ echo '<span id="HideMe" style="cursor:pointer" ><a href="javascript:void(0)"><strong>dismiss</strong></a> this message</span>';
1290
+ echo '</div>';
1291
+ echo '</td>';
1292
+ echo '</tr>';
1293
+
1294
+ ?>
1295
+
1296
+ <script type="text/javascript">
1297
+ jQuery(document).ready(function () {
1298
+ var row = jQuery('#<?php echo $class_name;?>-plugin-update-tr').closest('tr').prev();
1299
+ jQuery(row).addClass('update');
1300
+
1301
+ jQuery("#HideMe").click(function () {
1302
+ jQuery.ajax({
1303
+ type: 'POST',
1304
+ url: '<?php echo admin_url();?>/admin-ajax.php',
1305
+ data: {
1306
+ action: 'WPSR_HideMessageAjaxFunction'
1307
+ },
1308
+ success: function (data, textStatus, XMLHttpRequest) {
1309
+
1310
+ jQuery("#<?php echo $class_name;?>-upgradeMsg").hide();
1311
+
1312
+ },
1313
+ error: function (MLHttpRequest, textStatus, errorThrown) {
1314
+ alert(errorThrown);
1315
+ }
1316
+ });
1317
+ });
1318
+
1319
+ });
1320
+ </script>
1321
+
1322
+ <?php
1323
+ }
1324
+ }
1325
+
1326
+ $path = plugin_basename(__FILE__);
1327
+ add_action("after_plugin_row_{$path}", 'WPSR_after_plugin_row', 10, 3);
1328
+ // creating Ajax call for WordPress
1329
+ add_action('wp_ajax_nopriv_WPSR_HideMessageAjaxFunction', 'WPSR_HideMessageAjaxFunction');
1330
+ add_action('wp_ajax_WPSR_HideMessageAjaxFunction', 'WPSR_HideMessageAjaxFunction');
1331
+ //---------------------------------------------------------------
1332
+
1333
+ ?>