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

1,340 lines 55.7 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.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 $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
478 //-------------------------------------------------------------
479 if(!function_exists("WPSR_redirect")) {
480
481 function WPSR_redirect()
482 {
483 global $wpdb, $post, $table_prefix, $util;
484
485
486 if ($util->get_option_value('plugin_status') != '0') { // if not disabled
487
488 // if disable for admin and the user is admin
489 if (current_user_can('manage_options') == 1 && $util->get_option_value('plugin_status') == 2) {
490 // nothing
491
492 } else {
493
494 $table_name = $table_prefix . 'WP_SEO_Redirection';
495 $permalink = urldecode($util->get_current_relative_url());
496
497 if (substr($permalink, 0, 1) == ":") {
498 $first_slash = stripos($permalink, "/");
499 $permalink = substr($permalink, $first_slash, strlen($permalink) - $first_slash);
500 }
501 $permalink_alternative = "";
502 if (substr($permalink, -1) == '/') {
503 $permalink_alternative = substr($permalink, 0, intval(strlen($permalink) - 1));
504 } else {
505 $permalink_alternative = $permalink . '/';
506 }
507
508 $post_cache_result = "";
509 $SR_redirect_cache = new free_SR_redirect_cache();
510 if (is_singular()) {
511 $post_cache_result = $SR_redirect_cache->redirect_cached($post->ID);
512 }
513
514 if ($post_cache_result == 'not_redirected') {
515
516 return 0;
517 }
518
519 $permalink_options = $wpdb->prepare("( redirect_from = %s OR redirect_from = %s)", $permalink, $permalink_alternative);
520
521 $permalink_regex_options = $wpdb->prepare("(%s regexp regex or %s regexp regex )", $permalink, $permalink_alternative);
522
523
524 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))) {
525
526 $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex='' and $permalink_options ");
527 if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
528 WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
529 }
530
531 $theurl = $wpdb->get_row(" select * from $table_name where enabled=1 and regex<>'' and $permalink_regex_options order by LENGTH(regex) desc ");
532 if ($wpdb->num_rows > 0 && $theurl->redirect_to != '') {
533 WPSR_make_redirect($theurl->redirect_to, $theurl->redirect_type, $permalink, $theurl);
534 }
535
536
537 if (is_404()) {
538
539 if ($util->get_option_value('p404_discovery_status') == '1') {
540 WPSR_log_404_redirection($permalink);
541 }
542
543 $options = $util->get_my_options();
544 if ($options['p404_status'] == '1') {
545
546 WPSR_make_redirect($options['p404_redirect_to'], '301', $permalink);
547
548 }
549 }
550 }
551
552 if (is_singular() && $post_cache_result == 'not_found') {
553 $SR_redirect_cache->add_redirect($post->ID, 0, '', '', 0);
554 }
555
556 }
557 }
558 }
559 }
560 //---------------------------------------------------------------
561 if(!function_exists("WPSR_header_code")) {
562
563 function WPSR_header_code()
564 {
565
566 $my_page = isset($_REQUEST['page']) ? $_REQUEST['page'] : '';
567 if ($my_page == 'seo-redirection.php') {
568
569 wp_register_style('c_admin_css_common', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "style.css");
570 wp_enqueue_style('sweetalert', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "sweetalert.css");
571 wp_register_style('c_admin_css_custom', plugins_url() . '/' . basename(dirname(__FILE__)) . '/custom/' . "style.css");
572 wp_enqueue_script('jquery');
573 wp_localize_script('jquery', 'seoredirection', array('ajax_url' => admin_url('admin-ajax.php'), 'msg' => ""));
574 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');
575 wp_enqueue_style('c_admin_css_custom');
576
577 wp_enqueue_script('custom', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/js/' . 'bootstrap.min.js', array('jquery'), false, true);
578 wp_enqueue_script('customJS', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "customJs.js", array('jquery'), 1.1, true);
579 wp_enqueue_script('sweetalert', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/js/' . "sweetalert.min.js", array('jquery'), false, true);
580
581 wp_enqueue_style('bootstrap', plugins_url() . '/' . basename(dirname(__FILE__)) . '/common/' . "bootstrap.css");
582
583
584 }
585 }
586 }
587 //---------------------------------------------------------------
588 if(!function_exists("WPSR_customAddUpdate_callback")) {
589
590 add_action("wp_ajax_customAddUpdate", "WPSR_customAddUpdate_callback");
591
592 function WPSR_customAddUpdate_callback()
593 {
594 global $wpdb, $table_prefix, $util;
595 $table_name = $table_prefix . 'WP_SEO_Redirection';
596 $table_name_404 = $table_prefix . 'WP_SEO_404_links';
597 parse_str($_POST['formData'], $_POST);
598 $nonce = "";
599 if (isset($_POST['_wpnonce']))
600 $nonce = WPSR_sanitize_text_or_array_field($_POST['_wpnonce']);
601 $data = array();
602 $data['error_string'] = array();
603 $data['inputerror'] = array();
604 $data['bool'] = TRUE;
605 if (trim($_POST['redirect_from']) == '') {
606 $data['inputerror'][] = 'redirect_from';
607 $data['error_string'][] = __("You must input the 'Redirect From' URL", "seo-redirection");
608 $data['bool'] = FALSE;
609 }
610
611 $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
612
613 /* $wpdb->get_results(" select ID from $table_name where redirect_from='" . trim($redirect_from) . "' ");
614 if ($wpdb->num_rows > 0) {
615 $data['inputerror'][] = 'redirect_from';
616 $data['error_string'][] = __("This 'Redirect From' value already exists in database!", "seo-redirection");
617 $data['bool'] = FALSE;
618 }
619
620 */
621 // elseif (!preg_match( '/((http|https)\:\/\/)?[a-zA-Z0-9\.\/\?\:@\-_=#]+\.([a-zA-Z0-9\&\.\/\?\:@\-_=#])*/', $_POST['redirect_from'])) {
622 // $data['inputerror'][] = 'redirect_from';
623 // $data['error_string'][] = __("Invalid redirect from target URL!",'seo-redirection');
624 // $data['bool'] = FALSE;
625 // }
626 if (trim($_POST['redirect_to']) == '') {
627 $data['inputerror'][] = 'redirect_to';
628 $data['error_string'][] = __("You must input the 'Redirect To' URL", "seo-redirection");
629 $data['bool'] = FALSE;
630 } elseif ($_POST['edit_exist'] == '' && substr(strtolower($_POST['redirect_to']), 0, 4) != "http" && substr(strtolower($_POST['redirect_to']), 0, 1) != "/") {
631 $data['inputerror'][] = 'redirect_to';
632 $data['error_string'][] = __("Invalid redirect target URL!", 'seo-redirection');
633 $data['bool'] = FALSE;
634 }
635 if ($data['bool'] === FALSE) {
636 echo json_encode($data);
637 exit();
638 } else {
639 if ($_POST['redirect_from'] != '' && wp_verify_nonce($nonce, 'seoredirection')) {
640
641
642 $redirect_from = isset($_POST['redirect_from']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_from']) : '';
643 $redirect_to = isset($_POST['redirect_to']) ? WPSR_sanitize_text_or_array_field($_POST['redirect_to']) : '';
644
645
646 $redirect_from = urldecode($util->make_relative_url($redirect_from));
647
648 $redirect_to = $util->make_relative_url($redirect_to);
649 $redirect_type = WPSR_sanitize_text_or_array_field($_POST['redirect_type']);
650
651 $redirect_from_type = WPSR_sanitize_text_or_array_field($_POST['redirect_from_type']);
652 $redirect_from_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_from_folder_settings']);
653 $redirect_from_subfolders = WPSR_sanitize_text_or_array_field($_POST['redirect_from_subfolders']);
654
655 $redirect_to_type = WPSR_sanitize_text_or_array_field($_POST['redirect_to_type']);
656 $redirect_to_folder_settings = WPSR_sanitize_text_or_array_field($_POST['redirect_to_folder_settings']);
657
658 $enabled = WPSR_sanitize_text_or_array_field($_POST['enabled']);
659
660 $regex = "";
661
662 if ($redirect_from_type == 'Folder') {
663
664 if (substr($redirect_from, -1) != '/')
665 $redirect_from = $redirect_from . '/';
666
667 if ($redirect_from_folder_settings == 2) {
668 if ($redirect_from_subfolders == 0) {
669 $regex = '^' . $util->regex_prepare($redirect_from) . '.*';;
670 } else {
671 $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]*$';
672 }
673 } else if ($redirect_from_folder_settings == 3) {
674 if ($redirect_from_subfolders == 0) {
675 $regex = '^' . $util->regex_prepare($redirect_from) . '.+';
676 } else {
677 $regex = '^' . $util->regex_prepare($redirect_from) . '[^/]+$';
678 }
679 }
680
681 } else if ($redirect_from_type == 'Regex') {
682 $regex = $redirect_from;
683 }
684
685 if ($redirect_from_type == 'Page' || $redirect_from_type == 'Regex') {
686 $redirect_from_folder_settings = "";
687 $redirect_from_subfolders = "";
688 }
689
690 if ($redirect_to_type == 'Page') {
691 $redirect_to_folder_settings = "";
692 }
693
694 if ($redirect_to_type == 'Folder') {
695 if (substr($redirect_to, -1) != '/')
696 $redirect_to = $redirect_to . '/';
697 }
698
699
700 if ($_POST['add_new'] != '') {
701
702 $theurl = $wpdb->get_row($wpdb->prepare(" select count(ID) as cnt from $table_name where redirect_from=%s ", $redirect_from));
703
704 if ($theurl->cnt > 0) {
705 $msg = __("This URL", 'seo-redirection') . " <b>".esc_html($redirect_from)."</b>" . __("is added previously!", 'seo-redirection');
706 echo json_encode(array('status' => 'error', 'msg' => $msg));
707 // $util->failure_option_msg(__("This URL",'seo-redirection')." <b>'$redirect_from'</b>". __("is added previously!",'seo-redirection'));
708 } else {
709
710
711 if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
712 $util->failure_option_msg(__('Please input all required fields!', 'seo-redirection'));
713 } else {
714
715 $wpdb->insert($table_name, array(
716 'redirect_from' => $redirect_from,
717 'redirect_to' => $redirect_to,
718 'redirect_type' => $redirect_type,
719 'url_type' => 1,
720 'redirect_from_type' => $redirect_from_type,
721 'redirect_from_folder_settings' => $redirect_from_folder_settings,
722 'redirect_from_subfolders' => $redirect_from_subfolders,
723 'redirect_to_type' => $redirect_to_type,
724 'redirect_to_folder_settings' => $redirect_to_folder_settings,
725 'regex' => $regex,
726 'enabled' => $enabled
727
728 ));
729
730 $wpdb->query($wpdb->prepare(" delete from $table_name_404 where link=%s ", $redirect_from));
731 $SR_redirect_cache = new free_SR_redirect_cache();
732 $SR_redirect_cache->free_cache();
733 $msg = "Redirection Added Successfully";
734 echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
735 die;
736 }
737
738 }
739 } else if ($_POST['edit_exist'] != '') {
740
741 $edit = WPSR_sanitize_text_or_array_field($_POST['edit']);
742
743 if ($redirect_from == '' || $redirect_to == '' || $redirect_type == '') {
744 $util->failure_option_msg('Please input all required fields!');
745 } else {
746
747 $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));
748
749 $SR_redirect_cache = new free_SR_redirect_cache();
750 $SR_redirect_cache->free_cache();
751 }
752 $msg = "Redirection Update Successfully";
753 echo json_encode(array('status' => 'success', 'msg' => $msg, 'url' => admin_url('options-general.php?page=seo-redirection.php')));
754 die;
755
756 }
757
758 if ($util->there_is_cache() != '')
759 $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'));
760
761 }
762
763 }
764
765
766 die;
767 }
768 }
769 if(!function_exists("WPSR_customUpdateRec_callback")) {
770
771 add_action("wp_ajax_customUpdateRec", "WPSR_customUpdateRec_callback");
772 function WPSR_customUpdateRec_callback()
773 {
774
775
776 global $wpdb, $table_prefix, $util;
777
778 $table_name = $table_prefix . 'WP_SEO_Redirection';
779 $table_name_404 = $table_prefix . 'WP_SEO_404_links';
780
781 $myid = (int)$_POST['ID'];
782 $item = $wpdb->get_row($wpdb->prepare(" select * from $table_name where ID=%d ", $myid));
783
784 if ($wpdb->num_rows == 0) {
785 echo json_encode(array('status' => 'error', 'msg' => __("Sorry, this redirect rule is not found, it may deleted by the user!", 'seo-redirection')));
786 die;
787 }
788
789
790 $data = array(
791 "redirect_from" => $item->redirect_from,
792 "redirect_to" => $item->redirect_to,
793 "redirect_type" => $item->redirect_type,
794
795 "redirect_from_type" => $item->redirect_from_type,
796 "redirect_from_folder_settings" => $item->redirect_from_folder_settings,
797 "redirect_from_subfolders" => $item->redirect_from_subfolders,
798
799 "redirect_to_type" => $item->redirect_to_type,
800 "redirect_to_folder_settings" => $item->redirect_to_folder_settings,
801
802 "enabled" => $item->enabled
803 );
804 echo json_encode(array('status' => 'suucess', 'rec' => $data));
805 die;
806 }
807 }
808
809 if(!function_exists("WPSR_admin_menu")) {
810
811 function WPSR_admin_menu()
812 {
813 add_options_page('SEO Redirection', 'SEO Redirection', 'manage_options', basename(__FILE__), 'WPSR_options_menu');
814 }
815 }
816 //---------------------------------------------------------------
817 if(!function_exists("WPSR_options_menu")) {
818
819 function WPSR_options_menu()
820 {
821 global $util;
822
823 if (!current_user_can('manage_options')) {
824 wp_die(__('You do not have sufficient permissions to access this page.', 'seo-redirection'));
825 }
826
827
828 if ($util->get_option_value('plugin_status') == '0') {
829 $util->info_option_msg(__('SEO Redirection is disabled now, you can go to option tab and enable it!', 'seo-redirection'));
830 } else if ($util->get_option_value('plugin_status') == '2') {
831 $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'));
832 }
833 $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>' : '';
834
835
836 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/>';
837
838 if ($total_404_errors != '') {
839 ?>
840 <script type="text/javascript">
841
842 seoredirection.msg = '<?php echo wp_kses_post($total_404_errors); ?>';
843
844 </script>
845
846 <?php
847 }
848
849 if (is_multisite()) {
850
851 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/">
852 https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin/</a>) <p></p></div>';
853
854 }
855
856 $mytabs = new phptab();
857
858 $mytabs->set_ignore_parameter(array( 'search', 'page_num', 'add', 'edit', 'page404', 'do_404_del'));
859 $mytabs->add_file_tab('cutom', __('Custom Redirects', 'seo-redirection'), 'option_page_custome_redirection.php', 'file');
860 $mytabs->add_file_tab('posts', __('Post Redirects', 'seo-redirection'), 'option_page_post_redirection_list.php', 'file');
861 $mytabs->add_file_tab('history', __('History', 'seo-redirection'), 'option_page_history.php', 'file');
862 $mytabs->add_file_tab('404', '<span style="color:red;"><b>404 Errors</b></span>', 'option_page_404.php', 'file');
863 $mytabs->add_file_tab('goptions', __('Options', 'seo-redirection'), 'option_page_goptions.php', 'file');
864 $mytabs->add_file_tab('help', '<span style="color:green;"><b>' . __('Help', 'seo-redirection') . '</b></span>', 'help.php', 'file');
865 $mytabs->add_file_tab('premium', '<span style="color:brown;"><b>&#9658; ' . __('Premium Features', 'seo-redirection') . '</b></span>', 'premium.php', 'file');
866 $mytabs->run();
867
868 $imgpath = $util->get_plugin_url() . 'custom/images/';
869
870 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>';
871 echo __('<p><a href="https://www.wp-buy.com/product/seo-redirection-premium-wordpress-plugin" target="_blank"><img src="' . $imgpath . 'seopro.png" /></a></p>');
872 }
873 }
874 if(!function_exists("WPSR_upgrade")) {
875
876 function WPSR_upgrade()
877 {
878
879 $util = new clogica_util_1();
880 $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
881
882 if ($util->get_option_value('plugin_version') != WP_SEO_REDIRECTION_VERSION) {
883 WPSR_install();
884 $util->update_option('plugin_version', WP_SEO_REDIRECTION_VERSION);
885 }
886 }
887 }
888 //-----------------------------------------------------
889 if(!function_exists("WPSR_install")) {
890
891 function WPSR_install()
892 {
893 global $wpdb, $table_prefix;
894
895 $util = new clogica_util_1();
896 $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
897
898 $options = get_option(WP_SEO_REDIRECTION_OPTIONS);
899 if (!is_array($options)) {
900 add_option(WP_SEO_REDIRECTION_OPTIONS);
901 $options = array();
902 }
903
904
905 if (!array_key_exists('plugin_status', $options))
906 $options['plugin_status'] = '1';
907
908 if (!array_key_exists('ip_logging_status', $options))
909 $options['ip_logging_status'] = '1';
910
911 if (!array_key_exists('redirection_base', $options))
912 $options['redirection_base'] = site_url();
913
914 if (!array_key_exists('redirect_control_panel', $options))
915 $options['redirect_control_panel'] = '1';
916
917 if (!array_key_exists('show_redirect_box', $options))
918 $options['show_redirect_box'] = '1';
919
920 if (!array_key_exists('reflect_modifications', $options))
921 $options['reflect_modifications'] = '1';
922
923 if (!array_key_exists('history_status', $options))
924 $options['history_status'] = '1';
925
926 if (!array_key_exists('history_limit', $options))
927 $options['history_limit'] = '30';
928
929 if (!array_key_exists('p404_discovery_status', $options))
930 $options['p404_discovery_status'] = '1';
931
932 if (!array_key_exists('p404_redirect_to', $options))
933 $options['p404_redirect_to'] = site_url();
934
935 if (!array_key_exists('p404_status', $options))
936 $options['p404_status'] = '2';
937
938 if (!array_key_exists('keep_data', $options))
939 $options['keep_data'] = '1';
940
941 update_option(WP_SEO_REDIRECTION_OPTIONS, $options);
942
943
944 $table_name = $table_prefix . 'WP_SEO_Redirection';
945 if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
946 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
947 `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
948 `enabled` int(1) NOT NULL DEFAULT '1',
949 `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
950 `redirect_from_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
951 `redirect_from_folder_settings` int(1) NOT NULL,
952 `redirect_from_subfolders` int(1) NOT NULL DEFAULT '1',
953 `redirect_to` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
954 `redirect_to_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
955 `redirect_to_folder_settings` int(1) NOT NULL DEFAULT '1',
956 `regex` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
957 `redirect_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
958 `url_type` int(2) NOT NULL DEFAULT 1,
959 `postID` int(11) unsigned DEFAULT NULL,
960 `import_flag` tinyint(1) NOT NULL DEFAULT 0,
961 `hits` int(11) unsigned NOT NULL DEFAULT 0,
962 `access_date` datetime DEFAULT NULL,
963 PRIMARY KEY (`ID`),
964 UNIQUE KEY `redirect_from` (`redirect_from`)
965 )ENGINE = MyISAM ;";
966 $wpdb->query($sql);
967
968
969 } else {
970 //check if Innodb convert it to myisam.
971 $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
972 if ($status->Engine == 'InnoDB') {
973 $wpdb->query("alter table $table_name engine = MyISAM;");
974 }
975
976 /* add column for import flag */
977 $column_data = $wpdb->get_row("SHOW COLUMNS FROM $table_name LIKE 'import_flag'");
978
979 if (!$column_data) {
980 $wpdb->query("ALTER TABLE $table_name ADD COLUMN import_flag tinyint(1) DEFAULT 0");
981 }
982
983 // if the table exists
984 $redirects = $wpdb->get_results(" select redirect_from,redirect_to,ID from $table_name; ");
985 foreach ($redirects as $redirect) {
986 $redirect_from = $util->make_relative_url($redirect->redirect_from);
987 $redirect_to = $util->make_relative_url($redirect->redirect_to);
988 $ID = $redirect->ID;
989 $wpdb->query($wpdb->prepare(" update $table_name set redirect_from=%s,redirect_to=%s where ID=%d", $redirect_from, $redirect_to, $ID));
990 }
991
992 // Fix add blog field if not exist.
993 if ($wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
994 WHERE TABLE_NAME = '$table_name'
995 AND table_schema = DATABASE()
996 AND COLUMN_NAME = 'hits' ") == '0') {
997
998 $sql = "
999 ALTER TABLE $table_name
1000 ADD COLUMN `hits` int(11) unsigned NOT NULL DEFAULT 0,
1001 ADD COLUMN `access_date` datetime DEFAULT NULL;
1002 ";
1003
1004 $wpdb->query($sql);
1005 }
1006
1007
1008 }
1009
1010 $table_name = $table_prefix . 'WP_SEO_Cache';
1011 if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1012 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1013 `ID` int(11) unsigned NOT NULL,
1014 `is_redirected` int(1) unsigned NOT NULL,
1015 `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1016 `redirect_to` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1017 `redirect_type` int(3) unsigned NOT NULL DEFAULT 301,
1018 PRIMARY KEY (`ID`)
1019 ) ENGINE = MyISAM ;
1020 ";
1021 $wpdb->query($sql);
1022 } else {
1023 //check if Innodb convert it to myisam.
1024 $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1025 if ($status->Engine == 'InnoDB') {
1026 $wpdb->query("alter table $table_name engine = MyISAM;");
1027 }
1028 }
1029
1030
1031 $res = $wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1032 WHERE TABLE_NAME = '$table_name'
1033 AND table_schema = DATABASE()
1034 AND COLUMN_NAME = 'redirect_from' ");
1035
1036 if ($res == '0') {
1037
1038 $sql = "
1039 ALTER TABLE $table_name
1040 ADD COLUMN `redirect_from` varchar(255) COLLATE utf8_unicode_ci NOT NULL;
1041 ";
1042 $wpdb->query($sql);
1043 }
1044
1045
1046 $table_name = $table_prefix . 'WP_SEO_404_links';
1047 if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1048 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1049 `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1050 `ctime` datetime NOT NULL,
1051 `link` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1052 `referrer` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1053 `ip` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1054 `country` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
1055 `os` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1056 `browser` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1057 PRIMARY KEY (`ID`),
1058 UNIQUE KEY `link` (`link`)
1059 ) ENGINE = MyISAM ;
1060 ";
1061 $wpdb->query($sql);
1062 } else {
1063 //check if Innodb convert it to myisam.
1064 $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1065 if ($status->Engine == 'InnoDB') {
1066 $wpdb->query("alter table $table_name engine = MyISAM;");
1067 }
1068 }
1069
1070
1071 $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
1072 if (strtolower($wpdb->get_var("show tables like '$table_name'")) != strtolower($table_name)) {
1073 $sql = "CREATE TABLE IF NOT EXISTS `$table_name` (
1074 `ID` int(11) unsigned NOT NULL AUTO_INCREMENT,
1075 `rID` int(11) unsigned DEFAULT NULL,
1076 `postID` int(11) unsigned DEFAULT NULL,
1077 `ctime` datetime NOT NULL,
1078 `rfrom` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1079 `rto` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1080 `rtype` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1081 `rsrc` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1082 `referrer` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
1083 `ip` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1084 `country` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
1085 `os` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1086 `browser` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
1087 PRIMARY KEY (`ID`)
1088 ) ENGINE = MyISAM ;
1089 ";
1090
1091 $wpdb->query($sql);
1092 } else {
1093 //check if Innodb convert it to myisam.
1094 $status = $wpdb->get_row("SHOW TABLE STATUS WHERE Name = '$table_name'");
1095 if ($status->Engine == 'InnoDB') {
1096 $wpdb->query("alter table $table_name engine = MyISAM;");
1097 }
1098
1099 $res = $wpdb->get_var(" SELECT count(*) as cnt FROM INFORMATION_SCHEMA.COLUMNS
1100 WHERE TABLE_NAME = '$table_name'
1101 AND table_schema = DATABASE()
1102 AND COLUMN_NAME = 'postID' ");
1103
1104 if ($res == '0') {
1105
1106 $sql = "
1107 ALTER TABLE $table_name
1108 ADD COLUMN `postID` int(11) unsigned DEFAULT NULL;
1109 ";
1110 $wpdb->query($sql);
1111 }
1112
1113
1114 }
1115
1116 }
1117
1118 }
1119 //---------------------------------------------------------------
1120
1121 if(!function_exists("WPSR_uninstall")) {
1122
1123 function WPSR_uninstall()
1124 {
1125 global $wpdb, $table_prefix;
1126
1127 $util = new clogica_util_1();
1128 $util->init(WP_SEO_REDIRECTION_OPTIONS, __FILE__);
1129
1130
1131 if ($util->get_option_value('keep_data') != '1') {
1132
1133 $table_name = $table_prefix . 'WP_SEO_Redirection';
1134 $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1135
1136 $table_name = $table_prefix . 'WP_SEO_Cache';
1137 $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1138
1139 $table_name = $table_prefix . 'WP_SEO_404_links';
1140 $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1141
1142 $table_name = $table_prefix . 'WP_SEO_Redirection_LOG';
1143 $wpdb->query($wpdb->prepare(" DROP TABLE %s ", $table_name));
1144
1145
1146 $util->delete_my_options();
1147 }
1148
1149
1150 }
1151
1152 }
1153 //---------------------------------------------------------------
1154 if(!function_exists("WPSR_HideMessageAjaxFunction")) {
1155
1156 function WPSR_HideMessageAjaxFunction()
1157 {
1158 add_option('nsr_upgrade_message', 'yes');
1159 }
1160 }
1161 //---------------------------------------------------------------
1162 if(!function_exists("WPSR_admin_notice_callback")) {
1163
1164 /* display import from redirection plugin in admin notice */
1165 function WPSR_admin_notice_callback() {
1166 global $wpdb;
1167 global $current_user;
1168 $plugins = get_option( 'active_plugins', array() );
1169 $found = false;
1170 $user_id = $current_user->ID;
1171 $val = get_user_meta($user_id, 'sr_notice_dismissed',true);
1172
1173 foreach ( $plugins as $plugin )
1174 {
1175 if ( strpos( strval($plugin), 'redirection.php' ) == true && $val != 1 && strpos( strval($plugin), 'seo-redirection.php' ) == FALSE )
1176 {
1177 $found = true;
1178 //$total = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_items");
1179 $total = WPSR_getRedirectCount();
1180 if($total > 0){
1181 ?>
1182 <div class="notice-success notice is-dismissible sr_notice">
1183 <p>
1184 <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'); ?>
1185 <?php
1186 $SR_import = isset($_GET['SR_import']) ? sanitize_text_field($_GET['SR_import']) : '';
1187 if($SR_import == 'yes'){?>
1188 <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>
1189 <?php }else{ ?>
1190 <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>
1191 <?php }?>
1192 </p>
1193 </div>
1194 <?php
1195 }
1196 break;
1197 }
1198 }
1199 }
1200 add_action( 'admin_notices', 'WPSR_admin_notice_callback' );
1201 }
1202
1203 if(!function_exists("WPSR_dismiss_notice_callback")) {
1204
1205 add_action('wp_ajax_sr_dismiss_notice', 'WPSR_dismiss_notice_callback');
1206 function WPSR_dismiss_notice_callback()
1207 {
1208 global $current_user;
1209 $user_id = $current_user->ID;
1210 update_user_meta($user_id, 'sr_notice_dismissed', '1');
1211 echo "1";
1212 exit;
1213 }
1214 }
1215 if(!function_exists("WPSR_getRedirectCount")) {
1216
1217 function WPSR_getRedirectCount()
1218 {
1219 global $wpdb;
1220
1221 $table_name_ = $wpdb->prefix . 'redirection_items';
1222 if (strtolower($wpdb->get_var("show tables like '$table_name_'")) == strtolower($table_name_)) {
1223 $result = $wpdb->get_results("SELECT url FROM {$wpdb->prefix}redirection_items");
1224 $cnt = 0;
1225 $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
1226 if ($result) {
1227 foreach ($result as $redirect) {
1228 $redirect_from = stripslashes($redirect->url);
1229 $redirect_from_slash = ltrim(stripslashes($redirect->url), '/');
1230 $redirectID = $wpdb->get_var($wpdb->prepare("select ID from $table_name where redirect_from=%s or redirect_from=%s", $redirect_from, $redirect_from_slash));
1231 if ($redirectID > 0) {
1232
1233 } else {
1234 $cnt++;
1235 }
1236 }
1237
1238 }
1239 return $cnt;
1240 } else {
1241 return 0;
1242 }
1243 }
1244 }
1245 if(!function_exists("SR_init_delete_callback")) {
1246
1247 add_action('admin_init', 'SR_init_delete_callback');
1248 function SR_init_delete_callback()
1249 {
1250 if (isset($_POST['redirect_id']) && count($_POST['redirect_id']) > 0) {
1251
1252 $nonce = '';
1253 if(isset($_REQUEST['_wpnonce']))
1254 $nonce = WPSR_sanitize_text_or_array_field($_REQUEST['_wpnonce']);
1255
1256 if(wp_verify_nonce( $nonce, 'seoredirection' )){
1257
1258 global $wpdb, $table_prefix, $util;
1259 $table_name = $wpdb->prefix . 'WP_SEO_Redirection';
1260 foreach ($_POST['redirect_id'] as $post_id) {
1261 $post_id = (int)$post_id;
1262 $wpdb->query($wpdb->prepare(" delete from $table_name where ID=%s ", $post_id));
1263 $SR_redirect_cache = new free_SR_redirect_cache();
1264 $SR_redirect_cache->free_cache();
1265 }
1266 }
1267 }
1268 }
1269 }
1270
1271
1272
1273
1274 //---------------------------------------------------------------
1275
1276 function WPSR_HideMessageAjaxFunction()
1277 {
1278 add_option('nsr_upgrade_message', 'yes');
1279 }
1280
1281
1282 function WPSR_after_plugin_row($plugin_file, $plugin_data, $status)
1283 {
1284
1285 if (get_option('nsr_upgrade_message') != 'yes') {
1286 $class_name = $plugin_data['slug'];
1287 $class_name = isset($plugin_data['slug']) ? $plugin_data['slug'] : 'seo-redirection';
1288
1289 echo '<tr id="' . $class_name . '-plugin-update-tr" class="plugin-update-tr active">';
1290 echo '<td colspan="6" class="plugin-update">';
1291 echo '<div id="' . $class_name . '-upgradeMsg" class="update-message notice inline notice-warning notice-alt" >';
1292
1293 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 ';
1294
1295 echo '<span id="HideMe" style="cursor:pointer" ><a href="javascript:void(0)"><strong>dismiss</strong></a> this message</span>';
1296 echo '</div>';
1297 echo '</td>';
1298 echo '</tr>';
1299
1300 ?>
1301
1302 <script type="text/javascript">
1303 jQuery(document).ready(function () {
1304 var row = jQuery('#<?php echo $class_name;?>-plugin-update-tr').closest('tr').prev();
1305 jQuery(row).addClass('update');
1306
1307 jQuery("#HideMe").click(function () {
1308 jQuery.ajax({
1309 type: 'POST',
1310 url: '<?php echo admin_url();?>/admin-ajax.php',
1311 data: {
1312 action: 'WPSR_HideMessageAjaxFunction'
1313 },
1314 success: function (data, textStatus, XMLHttpRequest) {
1315
1316 jQuery("#<?php echo $class_name;?>-upgradeMsg").hide();
1317
1318 },
1319 error: function (MLHttpRequest, textStatus, errorThrown) {
1320 alert(errorThrown);
1321 }
1322 });
1323 });
1324
1325 });
1326 </script>
1327
1328 <?php
1329 }
1330 }
1331
1332 $path = plugin_basename(__FILE__);
1333 add_action("after_plugin_row_{$path}", 'WPSR_after_plugin_row', 10, 3);
1334 // creating Ajax call for WordPress
1335 add_action('wp_ajax_nopriv_WPSR_HideMessageAjaxFunction', 'WPSR_HideMessageAjaxFunction');
1336 add_action('wp_ajax_WPSR_HideMessageAjaxFunction', 'WPSR_HideMessageAjaxFunction');
1337 //---------------------------------------------------------------
1338
1339 ?>
1340