PluginProbe
SEO Redirection Plugin – 301 Redirect Manager / 9.5
SEO Redirection Plugin – 301 Redirect Manager v9.5
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 9.5, at seo-redirection.php

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