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

seo-redirection.php in SEO Redirection Plugin – 301 Redirect Manager 8.3, at seo-redirection.php

1,334 lines 55.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 ?>
1334