Redirection - Version 2.4.5

Version Description

  • Ensure cleanup code runs even if plugin was updated
  • Extra sanitization of Apache & Nginx files, props to Ed Shirey
  • Fix regex bug, props to romulodl
  • Fix bug in correct group not being shown in dropdown
Download this release

Release Info

Developer johnny5
Plugin Icon 128x128 Redirection
Version 2.4.5
Comparing to
See all releases

Code changes from version 2.4.4 to 2.4.5

actions/error.php CHANGED
@@ -9,10 +9,10 @@ class Error_Action extends Red_Action {
9
  return false;
10
  }
11
 
12
- function action_codes() {
13
- return array (
14
  404 => get_status_header_desc( 404 ),
15
- 410 => get_status_header_desc( 410 )
16
  );
17
  }
18
 
9
  return false;
10
  }
11
 
12
+ function action_codes() {
13
+ return array(
14
  404 => get_status_header_desc( 404 ),
15
+ 410 => get_status_header_desc( 410 ),
16
  );
17
  }
18
 
actions/nothing.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
 
3
- class Nothing_Action extends Red_Action
4
- {
5
- function can_perform_action () { return false; }
 
6
  }
1
  <?php
2
 
3
+ class Nothing_Action extends Red_Action {
4
+ function can_perform_action () {
5
+ return false;
6
+ }
7
  }
actions/pass.php CHANGED
@@ -1,44 +1,37 @@
1
  <?php
2
 
3
- class Pass_Action extends Red_Action
4
- {
5
- function process_before ($code, $target)
6
- {
7
  // Determine what we are passing to: local URL, remote URL, file
8
- if (substr ($target, 0, 7) == 'http://' || substr ($target, 0, 8) == 'https://') {
9
- echo @wp_remote_fopen ($target);
10
  die();
11
  }
12
- else if (substr ($target, 0, 7) == 'file://')
13
- {
14
- $parts = explode ('?', substr ($target, 7));
15
- if (count ($parts) > 1)
16
- {
17
  // Put parameters into the environment
18
- $args = explode ('&', $parts[1]);
19
- if (count ($args) > 0)
20
- {
21
- foreach ($args AS $arg)
22
- {
23
- $tmp = explode ('=', $arg);
24
- if (count ($tmp) == 1)
25
- $_GET[$arg] = '';
26
  else
27
- $_GET[$tmp[0]] = $tmp[1];
28
  }
29
  }
30
  }
31
 
32
- include ($parts[0]);
33
- exit ();
34
  }
35
- else
36
- {
37
  $_SERVER['REQUEST_URI'] = $target;
38
- if (strpos ($target, '?'))
39
- {
40
- $_SERVER['QUERY_STRING'] = substr ($target, strpos ($target, '?') + 1);
41
- parse_str ($_SERVER['QUERY_STRING'], $_GET);
42
  }
43
  }
44
 
1
  <?php
2
 
3
+ class Pass_Action extends Red_Action {
4
+ function process_before( $code, $target ) {
 
 
5
  // Determine what we are passing to: local URL, remote URL, file
6
+ if ( substr( $target, 0, 7 ) === 'http://' || substr( $target, 0, 8 ) === 'https://' ) {
7
+ echo @wp_remote_fopen( $target );
8
  die();
9
  }
10
+ else if ( substr( $target, 0, 7 ) === 'file://' ) {
11
+ $parts = explode( '?', substr( $target, 7 ) );
12
+ if ( count( $parts ) > 1 ) {
 
 
13
  // Put parameters into the environment
14
+ $args = explode( '&', $parts[1] );
15
+
16
+ if ( count( $args ) > 0 ) {
17
+ foreach ( $args as $arg ) {
18
+ $tmp = explode( '=', $arg );
19
+ if ( count( $tmp ) === 1 )
20
+ $_GET[ $arg ] = '';
 
21
  else
22
+ $_GET[ $tmp[0] ] = $tmp[1];
23
  }
24
  }
25
  }
26
 
27
+ include( $parts[0] );
28
+ exit();
29
  }
30
+ else {
 
31
  $_SERVER['REQUEST_URI'] = $target;
32
+ if ( strpos( $target, '?' ) ) {
33
+ $_SERVER['QUERY_STRING'] = substr( $target, strpos( $target, '?' ) + 1 );
34
+ parse_str( $_SERVER['QUERY_STRING'], $_GET );
 
35
  }
36
  }
37
 
actions/random.php CHANGED
@@ -1,49 +1,31 @@
1
  <?php
2
- /**
3
- * Redirection
4
- *
5
- * @package Redirection
6
- * @author John Godley
7
- * @copyright Copyright (C) John Godley
8
- **/
9
 
10
- /*
11
- ============================================================================================================
12
- This software is provided "as is" and any express or implied warranties, including, but not limited to, the
13
- implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall
14
- the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or
15
- consequential damages (including, but not limited to, procurement of substitute goods or services; loss of
16
- use, data, or profits; or business interruption) however caused and on any theory of liability, whether in
17
- contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of
18
- this software, even if advised of the possibility of such damage.
19
-
20
- For full license details see license.txt
21
- ============================================================================================================ */
22
 
23
- class Random_Action extends Red_Action
24
- {
25
- function can_change_code () { return true; }
26
- function can_perform_action () { return false; }
27
 
28
- function action_codes ()
29
- {
30
- return array
31
- (
32
- 301 => get_status_header_desc (301),
33
- 302 => get_status_header_desc (302),
34
- 307 => get_status_header_desc (307)
35
  );
36
  }
37
 
38
- function process_before ($code, $target)
39
- {
40
  // Pick a random WordPress page
41
  global $wpdb;
42
- $id = $wpdb->get_var ("SELECT ID FROM {$wpdb->prefix}posts WHERE post_status='publish' AND post_password='' AND post_type='post' ORDER BY RAND() LIMIT 0,1");
43
 
44
- $target = str_replace (get_bloginfo ('url'), '', get_permalink ($id));
 
 
45
 
46
- wp_redirect ($target, $code);
47
- exit ();
48
  }
49
  }
1
  <?php
 
 
 
 
 
 
 
2
 
3
+ class Random_Action extends Red_Action {
4
+ function can_change_code() {
5
+ return true;
6
+ }
 
 
 
 
 
 
 
 
7
 
8
+ function can_perform_action() {
9
+ return false;
10
+ }
 
11
 
12
+ function action_codes() {
13
+ return array(
14
+ 301 => get_status_header_desc( 301 ),
15
+ 302 => get_status_header_desc( 302 ),
16
+ 307 => get_status_header_desc( 307 ),
 
 
17
  );
18
  }
19
 
20
+ function process_before( $code, $target ) {
 
21
  // Pick a random WordPress page
22
  global $wpdb;
 
23
 
24
+ $id = $wpdb->get_var( "SELECT ID FROM {$wpdb->prefix}posts WHERE post_status='publish' AND post_password='' AND post_type='post' ORDER BY RAND() LIMIT 0,1" );
25
+
26
+ $target = str_replace( get_bloginfo( 'url' ), '', get_permalink( $id ) );
27
 
28
+ wp_redirect( $target, $code );
29
+ exit();
30
  }
31
  }
actions/url.php CHANGED
@@ -5,11 +5,11 @@ class Url_Action extends Red_Action {
5
  return true;
6
  }
7
 
8
- function action_codes() {
9
  return array(
10
  301 => get_status_header_desc( 301 ),
11
  302 => get_status_header_desc( 302 ),
12
- 307 => get_status_header_desc( 307 )
13
  );
14
  }
15
 
5
  return true;
6
  }
7
 
8
+ function action_codes() {
9
  return array(
10
  301 => get_status_header_desc( 301 ),
11
  302 => get_status_header_desc( 302 ),
12
+ 307 => get_status_header_desc( 307 ),
13
  );
14
  }
15
 
fileio/apache.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  class Red_Apache_File extends Red_FileIO {
4
- var $htaccess;
5
 
6
  function export( array $items ) {
7
  $filename = 'redirection-'.date_i18n( get_option( 'date_format' ) ).'.htaccess';
@@ -11,7 +11,7 @@ class Red_Apache_File extends Red_FileIO {
11
  header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
12
  header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
13
 
14
- echo $htaccess->generate( $items );
15
  }
16
 
17
  public function get( array $items ) {
@@ -19,7 +19,7 @@ class Red_Apache_File extends Red_FileIO {
19
 
20
  $htaccess = new Red_Htaccess();
21
 
22
- foreach ( $items AS $item ) {
23
  $htaccess->add( $item );
24
  }
25
 
@@ -28,34 +28,63 @@ class Red_Apache_File extends Red_FileIO {
28
 
29
  function load( $group, $data, $filename = '' ) {
30
  // Remove any comments
31
- $data = preg_replace ('@#(.*)@', '', $data);
32
- $data = str_replace ("\n", "\r", $data);
33
- $data = str_replace ('\\ ', '%20', $data);
34
 
35
  // Split it into lines
36
- $lines = array_filter (explode ("\r", $data));
 
37
  if ( count( $lines ) > 0 ) {
38
- foreach ( $lines AS $line ) {
39
- if ( preg_match ('@rewriterule\s+(.*?)\s+(.*?)\s+(\[.*\])*@i', $line, $matches) > 0 )
40
- $items[] = array('source' => $this->regex_url ($matches[1]), 'target' => $this->decode_url ($matches[2]), 'code' => $this->get_code ($matches[3]), 'regex' => $this->is_regex ($matches[1]) );
41
- elseif ( preg_match( '@Redirect\s+(.*?)\s+(.*?)\s+(.*)@i', $line, $matches) > 0 )
42
- $items[] = array( 'source' => $this->decode_url ($matches[2]), 'target' => $this->decode_url ($matches[3]), 'code' => $this->get_code ($matches[1]) );
43
- elseif ( preg_match( '@Redirect\s+(.*?)\s+(.*?)@i', $line, $matches) > 0 )
44
- $items[] = array( 'source' => $this->decode_url ($matches[1]), 'target' => $this->decode_url ($matches[2]), 'code' => 302);
45
- elseif ( preg_match( '@Redirectmatch\s+(.*?)\s+(.*?)\s+(.*)@i', $line, $matches) > 0 )
46
- $items[] = array( 'source' => $this->decode_url ($matches[2]), 'target' => $this->decode_url ($matches[3]), 'code' => $this->get_code ($matches[1]), 'regex' => true );
47
- elseif ( preg_match( '@Redirectmatch\s+(.*?)\s+(.*?)@i', $line, $matches) > 0 )
48
- $items[] = array( 'source' => $this->decode_url ($matches[1]), 'target' => $this->decode_url ($matches[2]), 'code' => 302, 'regex' => true );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
  }
50
 
51
  // Add items to group
52
  if ( count( $items ) > 0 ) {
53
- foreach ( $items AS $item ) {
54
  $item['group_id'] = $group;
55
  $item['red_action'] = 'url';
56
  $item['match'] = 'url';
57
 
58
- if ( $item['code'] == 0 )
59
  $item['red_action'] = 'pass';
60
 
61
  Red_Item::create( $item );
@@ -79,9 +108,9 @@ class Red_Apache_File extends Red_FileIO {
79
  $escape = false;
80
 
81
  for ( $x = 0; $x < strlen( $url ); $x++ ) {
82
- if ( $url{$x} == '\\' )
83
  $escape = true;
84
- elseif ( strpos( $regex, $url{$x} ) !== false && !$escape )
85
  return true;
86
  else
87
  $escape = false;
@@ -107,7 +136,7 @@ class Red_Apache_File extends Red_FileIO {
107
  $tmp = ltrim( $url, '^' );
108
  $tmp = rtrim( $tmp, '$' );
109
 
110
- if ( $this->is_str_regex( $tmp ) == false )
111
  return '/'.$this->decode_url( $tmp );
112
 
113
  return '/'.$this->decode_url( $url );
1
  <?php
2
 
3
  class Red_Apache_File extends Red_FileIO {
4
+ public $htaccess;
5
 
6
  function export( array $items ) {
7
  $filename = 'redirection-'.date_i18n( get_option( 'date_format' ) ).'.htaccess';
11
  header( 'Expires: Mon, 26 Jul 1997 05:00:00 GMT' );
12
  header( 'Content-Disposition: attachment; filename="'.$filename.'"' );
13
 
14
+ echo $this->get( $items );
15
  }
16
 
17
  public function get( array $items ) {
19
 
20
  $htaccess = new Red_Htaccess();
21
 
22
+ foreach ( $items as $item ) {
23
  $htaccess->add( $item );
24
  }
25
 
28
 
29
  function load( $group, $data, $filename = '' ) {
30
  // Remove any comments
31
+ $data = preg_replace( '@#(.*)@', '', $data );
32
+ $data = str_replace( "\n", "\r", $data );
33
+ $data = str_replace( '\\ ', '%20', $data );
34
 
35
  // Split it into lines
36
+ $lines = array_filter( explode( "\r", $data ) );
37
+
38
  if ( count( $lines ) > 0 ) {
39
+ foreach ( $lines as $line ) {
40
+ if ( preg_match( '@rewriterule\s+(.*?)\s+(.*?)\s+(\[.*\])*@i', $line, $matches ) > 0 ) {
41
+ $items[] = array(
42
+ 'source' => $this->regex_url( $matches[1] ),
43
+ 'target' => $this->decode_url( $matches[2] ),
44
+ 'code' => $this->get_code( $matches[3] ),
45
+ 'regex' => $this->is_regex( $matches[1] ),
46
+ );
47
+ }
48
+ elseif ( preg_match( '@Redirect\s+(.*?)\s+(.*?)\s+(.*)@i', $line, $matches ) > 0 ) {
49
+ $items[] = array(
50
+ 'source' => $this->decode_url( $matches[2] ),
51
+ 'target' => $this->decode_url( $matches[3] ),
52
+ 'code' => $this->get_code( $matches[1] ),
53
+ );
54
+ }
55
+ elseif ( preg_match( '@Redirect\s+(.*?)\s+(.*?)@i', $line, $matches ) > 0 ) {
56
+ $items[] = array(
57
+ 'source' => $this->decode_url( $matches[1] ),
58
+ 'target' => $this->decode_url( $matches[2] ),
59
+ 'code' => 302,
60
+ );
61
+ }
62
+ elseif ( preg_match( '@Redirectmatch\s+(.*?)\s+(.*?)\s+(.*)@i', $line, $matches ) > 0 ) {
63
+ $items[] = array(
64
+ 'source' => $this->decode_url( $matches[2] ),
65
+ 'target' => $this->decode_url( $matches[3] ),
66
+ 'code' => $this->get_code( $matches[1] ),
67
+ 'regex' => true,
68
+ );
69
+ }
70
+ elseif ( preg_match( '@Redirectmatch\s+(.*?)\s+(.*?)@i', $line, $matches ) > 0 ) {
71
+ $items[] = array(
72
+ 'source' => $this->decode_url( $matches[1] ),
73
+ 'target' => $this->decode_url( $matches[2] ),
74
+ 'code' => 302,
75
+ 'regex' => true,
76
+ );
77
+ }
78
  }
79
 
80
  // Add items to group
81
  if ( count( $items ) > 0 ) {
82
+ foreach ( $items as $item ) {
83
  $item['group_id'] = $group;
84
  $item['red_action'] = 'url';
85
  $item['match'] = 'url';
86
 
87
+ if ( $item['code'] === 0 )
88
  $item['red_action'] = 'pass';
89
 
90
  Red_Item::create( $item );
108
  $escape = false;
109
 
110
  for ( $x = 0; $x < strlen( $url ); $x++ ) {
111
+ if ( $url{$x} === '\\' )
112
  $escape = true;
113
+ elseif ( strpos( $regex, $url{$x} ) !== false && ! $escape )
114
  return true;
115
  else
116
  $escape = false;
136
  $tmp = ltrim( $url, '^' );
137
  $tmp = rtrim( $tmp, '$' );
138
 
139
+ if ( $this->is_str_regex( $tmp ) === false )
140
  return '/'.$this->decode_url( $tmp );
141
 
142
  return '/'.$this->decode_url( $url );
fileio/csv.php CHANGED
@@ -13,7 +13,7 @@ class Red_Csv_File extends Red_FileIO {
13
 
14
  fputcsv( $stdout, array( 'source', 'target', 'regex', 'type', 'code', 'match', 'hits', 'title' ) );
15
 
16
- foreach ( $items AS $line ) {
17
  $csv = array(
18
  $line->get_url(),
19
  $line->get_action_data(),
@@ -35,14 +35,14 @@ class Red_Csv_File extends Red_FileIO {
35
 
36
  if ( $file ) {
37
  while ( ( $csv = fgetcsv( $file, 1000, ',' ) ) ) {
38
- if ( $csv[0] != 'source' && $csv[1] != 'target') {
39
  Red_Item::create( array(
40
  'source' => trim( $csv[0] ),
41
  'target' => trim( $csv[1] ),
42
  'regex' => $this->is_regex( $csv[0] ),
43
  'group_id' => $group,
44
  'match' => 'url',
45
- 'red_action' => 'url'
46
  ) );
47
 
48
  $count++;
13
 
14
  fputcsv( $stdout, array( 'source', 'target', 'regex', 'type', 'code', 'match', 'hits', 'title' ) );
15
 
16
+ foreach ( $items as $line ) {
17
  $csv = array(
18
  $line->get_url(),
19
  $line->get_action_data(),
35
 
36
  if ( $file ) {
37
  while ( ( $csv = fgetcsv( $file, 1000, ',' ) ) ) {
38
+ if ( $csv[0] !== 'source' && $csv[1] !== 'target' ) {
39
  Red_Item::create( array(
40
  'source' => trim( $csv[0] ),
41
  'target' => trim( $csv[1] ),
42
  'regex' => $this->is_regex( $csv[0] ),
43
  'group_id' => $group,
44
  'match' => 'url',
45
+ 'red_action' => 'url',
46
  ) );
47
 
48
  $count++;
fileio/nginx.php CHANGED
@@ -20,12 +20,12 @@ class Red_Nginx_File extends Red_FileIO {
20
  $version = get_plugin_data( dirname( dirname( __FILE__ ) ).'/redirection.php' );
21
 
22
  $lines[] = '# Created by Redirection';
23
- $lines[] = '# '.date ('r');
24
  $lines[] = '# Redirection '.trim( $version['Version'] ).' - http://urbangiraffe.com/plugins/redirection/';
25
  $lines[] = '';
26
  $lines[] = 'server {';
27
 
28
- foreach ( $items AS $item ) {
29
  $lines[] = $this->get_nginx_item( $item );
30
  }
31
 
@@ -91,8 +91,11 @@ class Red_Nginx_File extends Red_FileIO {
91
  }
92
 
93
  private function add_redirect( $source, $target, $code ) {
 
 
 
 
 
94
  return 'rewrite ^'.$source.'$ '.$target.' '.$code.';';
95
  }
96
  }
97
-
98
-
20
  $version = get_plugin_data( dirname( dirname( __FILE__ ) ).'/redirection.php' );
21
 
22
  $lines[] = '# Created by Redirection';
23
+ $lines[] = '# '.date( 'r' );
24
  $lines[] = '# Redirection '.trim( $version['Version'] ).' - http://urbangiraffe.com/plugins/redirection/';
25
  $lines[] = '';
26
  $lines[] = 'server {';
27
 
28
+ foreach ( $items as $item ) {
29
  $lines[] = $this->get_nginx_item( $item );
30
  }
31
 
91
  }
92
 
93
  private function add_redirect( $source, $target, $code ) {
94
+ $source = preg_replace( "/[\r\n\t].*?$/s", '', $source );
95
+ $source = preg_replace( '/[^\PC\s]/u', '', $source );
96
+ $target = preg_replace( "/[\r\n\t].*?$/s", '', $target );
97
+ $target = preg_replace( '/[^\PC\s]/u', '', $target );
98
+
99
  return 'rewrite ^'.$source.'$ '.$target.' '.$code.';';
100
  }
101
  }
 
 
fileio/rss.php CHANGED
@@ -10,14 +10,17 @@ class Red_Rss_File extends Red_FileIO {
10
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
11
  xmlns:dc="http://purl.org/dc/elements/1.1/">
12
  <channel>
13
- <title>Redirection <?php ' - '; bloginfo_rss( 'name' ); ?></title>
14
  <link><?php esc_url( bloginfo_rss( 'url' ) ) ?></link>
15
  <description><?php esc_html( bloginfo_rss( 'description' ) ) ?></description>
16
  <pubDate><?php echo esc_html( mysql2date( 'D, d M Y H:i:s +0000', get_lastpostmodified( 'GMT' ), false ) ); ?></pubDate>
17
- <generator><?php echo esc_html( 'http://wordpress.org/?v=' ); bloginfo_rss( 'version' ); ?></generator>
 
 
 
18
  <language><?php echo esc_html( get_option( 'rss_language' ) ); ?></language>
19
- <?php
20
- foreach ( (array)$items as $log ) : ?>
21
  <item>
22
  <title><?php echo esc_html( $log->get_url() ); ?></title>
23
  <link><![CDATA[<?php echo esc_url( home_url() ); echo esc_url( $log->get_url() ); ?>]]></link>
10
  xmlns:wfw="http://wellformedweb.org/CommentAPI/"
11
  xmlns:dc="http://purl.org/dc/elements/1.1/">
12
  <channel>
13
+ <title>Redirection - <?php bloginfo_rss( 'name' ); ?></title>
14
  <link><?php esc_url( bloginfo_rss( 'url' ) ) ?></link>
15
  <description><?php esc_html( bloginfo_rss( 'description' ) ) ?></description>
16
  <pubDate><?php echo esc_html( mysql2date( 'D, d M Y H:i:s +0000', get_lastpostmodified( 'GMT' ), false ) ); ?></pubDate>
17
+ <generator>
18
+ <?php echo esc_html( 'http://wordpress.org/?v=' ); ?>
19
+ <?php bloginfo_rss( 'version' ); ?>
20
+ </generator>
21
  <language><?php echo esc_html( get_option( 'rss_language' ) ); ?></language>
22
+
23
+ <?php foreach ( (array) $items as $log ) : ?>
24
  <item>
25
  <title><?php echo esc_html( $log->get_url() ); ?></title>
26
  <link><![CDATA[<?php echo esc_url( home_url() ); echo esc_url( $log->get_url() ); ?>]]></link>
matches/login.php CHANGED
@@ -1,33 +1,13 @@
1
  <?php
2
- /**
3
- * Redirection
4
- *
5
- * @package Redirection
6
- * @author John Godley
7
- * @copyright Copyright( C ) John Godley
8
- **/
9
-
10
- /*
11
- ============================================================================================================
12
- This software is provided "as is" and any express or implied warranties, including, but not limited to, the
13
- implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall
14
- the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or
15
- consequential damages( including, but not limited to, procurement of substitute goods or services; loss of
16
- use, data, or profits; or business interruption ) however caused and on any theory of liability, whether in
17
- contract, strict liability, or tort( including negligence or otherwise ) arising in any way out of the use of
18
- this software, even if advised of the possibility of such damage.
19
-
20
- For full license details see license.txt
21
- ============================================================================================================ */
22
 
23
  class Login_Match extends Red_Match {
24
- var $user_agent = '';
25
 
26
  function name() {
27
  return __( 'URL and login status', 'redirection' );
28
  }
29
 
30
- function show() {
31
  ?>
32
  <tr>
33
  <th></th>
@@ -64,17 +44,17 @@ class Login_Match extends Red_Match {
64
  <?php
65
  }
66
 
67
- function save( $details ) {
68
  if ( isset( $details['target'] ) )
69
- $details['target'] = $details;
70
 
71
  return array(
72
- 'url_loggedin' => isset( $details['url_loggedin'] ) ? $details['url_loggedin'] : false,
73
- 'url_loggedout' => isset( $details['url_loggedout'] ) ? $details['url_loggedout'] : false,
74
  );
75
  }
76
 
77
- function initialize( $url ) {
78
  $this->url = array( $url, '' );
79
  }
80
 
@@ -89,11 +69,14 @@ class Login_Match extends Red_Match {
89
  return $target;
90
  }
91
 
92
- function wants_it() {
93
  if ( is_user_logged_in() && strlen( $this->url_loggedin ) > 0 )
94
  return true;
95
- if ( !is_user_logged_in() && strlen( $this->url_loggedout ) > 0 )
 
96
  return true;
 
 
97
  }
98
 
99
  function match_name() {
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  class Login_Match extends Red_Match {
4
+ public $user_agent = '';
5
 
6
  function name() {
7
  return __( 'URL and login status', 'redirection' );
8
  }
9
 
10
+ function show() {
11
  ?>
12
  <tr>
13
  <th></th>
44
  <?php
45
  }
46
 
47
+ function save( $details ) {
48
  if ( isset( $details['target'] ) )
49
+ $details['target'] = $this->sanitize_url( $details );
50
 
51
  return array(
52
+ 'url_loggedin' => isset( $details['url_loggedin'] ) ? $this->sanitize_url( $details['url_loggedin'] ) : false,
53
+ 'url_loggedout' => isset( $details['url_loggedout'] ) ? $this->sanitize_url( $details['url_loggedout'] ) : false,
54
  );
55
  }
56
 
57
+ function initialize( $url ) {
58
  $this->url = array( $url, '' );
59
  }
60
 
69
  return $target;
70
  }
71
 
72
+ function wants_it() {
73
  if ( is_user_logged_in() && strlen( $this->url_loggedin ) > 0 )
74
  return true;
75
+
76
+ if ( ! is_user_logged_in() && strlen( $this->url_loggedout ) > 0 )
77
  return true;
78
+
79
+ return false;
80
  }
81
 
82
  function match_name() {
matches/referrer.php CHANGED
@@ -1,28 +1,8 @@
1
  <?php
2
- /**
3
- * Redirection
4
- *
5
- * @package Redirection
6
- * @author John Godley
7
- * @copyright Copyright( C ) John Godley
8
- **/
9
-
10
- /*
11
- ============================================================================================================
12
- This software is provided "as is" and any express or implied warranties, including, but not limited to, the
13
- implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall
14
- the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or
15
- consequential damages( including, but not limited to, procurement of substitute goods or services; loss of
16
- use, data, or profits; or business interruption ) however caused and on any theory of liability, whether in
17
- contract, strict liability, or tort( including negligence or otherwise ) arising in any way out of the use of
18
- this software, even if advised of the possibility of such damage.
19
-
20
- For full license details see license.txt
21
- ============================================================================================================ */
22
 
23
  class Referrer_Match extends Red_Match {
24
- var $referrer;
25
- var $regex;
26
 
27
  function name() {
28
  return __( 'URL and referrer', 'redirection' );
@@ -32,7 +12,7 @@ class Referrer_Match extends Red_Match {
32
  $codes = array(
33
  301 => get_status_header_desc( 301 ),
34
  302 => get_status_header_desc( 302 ),
35
- 307 => get_status_header_desc( 307 )
36
  );
37
 
38
  ?>
@@ -40,15 +20,15 @@ class Referrer_Match extends Red_Match {
40
  <th width="100"><?php _e( 'Referrer', 'redirection' ); ?>:</th>
41
  <td valign="top">
42
  <input style="width: 85%" type="text" name="referrer" value="<?php echo esc_attr( $this->referrer ); ?>"/>
43
- <label><?php _e( 'Regex', 'redirection' ); ?>: <input type="checkbox" name="regex" <?php if ( $this->regex == true ) echo ' checked="checked"' ?>/></label>
44
  </td>
45
  </tr>
46
  <tr>
47
  <th><?php _e( 'HTTP Code', 'redirection' ); ?>:</th>
48
  <td>
49
  <select name="action_code">
50
- <?php foreach ( $codes AS $key => $code ) : ?>
51
- <option value="<?php echo $key ?>"<?php if ( $key == $this->action_code ) echo ' selected="selected"' ?>><?php printf( '%s - %s', $key, $code ) ?></option>
52
  <?php endforeach?>
53
  </select>
54
  </td>
@@ -84,18 +64,22 @@ class Referrer_Match extends Red_Match {
84
  <?php
85
  }
86
 
87
- function save( $details ) {
88
  if ( isset( $details['target'] ) )
89
- $details['url_from'] = $details['target'];
90
 
91
  return array(
92
- 'url_from' => $details['url_from'],
93
- 'url_notfrom' => isset( $details['url_notfrom'] ) ? $details['url_notfrom'] : false,
94
  'regex' => isset( $details['regex'] ) ? true : false,
95
- 'referrer' => isset( $details['referrer'] ) ? $details['referrer'] : false
96
  );
97
  }
98
 
 
 
 
 
99
  function initialize( $url ) {
100
  $this->url = array( $url, '' );
101
  }
@@ -109,18 +93,18 @@ class Referrer_Match extends Red_Match {
109
  $target = false;
110
 
111
  // Check if referrer matches
112
- if ( ( $this->regex == false && $_SERVER['HTTP_REFERER'] == $this->referrer ) ||( $this->regex == true && preg_match( '@'.str_replace( '@', '\\@', $this->referrer ).'@', $_SERVER['HTTP_REFERER'], $matches ) ) ) {
113
  $target = $this->url_from;
114
 
115
  if ( $regex )
116
  $target = preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $target, $url );
117
  }
118
- elseif ( $this->url_notfrom != '' )
119
  $target = $this->url_notfrom;
120
  return $target;
121
  }
122
 
123
- function match_name() {
124
  return sprintf( 'referrer - <code>%s</code>', $this->referrer );
125
  }
126
  }
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  class Referrer_Match extends Red_Match {
4
+ public $referrer;
5
+ public $regex;
6
 
7
  function name() {
8
  return __( 'URL and referrer', 'redirection' );
12
  $codes = array(
13
  301 => get_status_header_desc( 301 ),
14
  302 => get_status_header_desc( 302 ),
15
+ 307 => get_status_header_desc( 307 ),
16
  );
17
 
18
  ?>
20
  <th width="100"><?php _e( 'Referrer', 'redirection' ); ?>:</th>
21
  <td valign="top">
22
  <input style="width: 85%" type="text" name="referrer" value="<?php echo esc_attr( $this->referrer ); ?>"/>
23
+ <label><?php _e( 'Regex', 'redirection' ); ?>: <input type="checkbox" name="regex" <?php if ( $this->regex === true ) echo ' checked="checked"' ?>/></label>
24
  </td>
25
  </tr>
26
  <tr>
27
  <th><?php _e( 'HTTP Code', 'redirection' ); ?>:</th>
28
  <td>
29
  <select name="action_code">
30
+ <?php foreach ( $codes as $key => $code ) : ?>
31
+ <option value="<?php echo $key ?>"<?php if ( $key === intval( $this->action_code ) ) echo ' selected="selected"' ?>><?php printf( '%s - %s', $key, $code ) ?></option>
32
  <?php endforeach?>
33
  </select>
34
  </td>
64
  <?php
65
  }
66
 
67
+ function save( $details ) {
68
  if ( isset( $details['target'] ) )
69
+ $details['url_from'] = $this->sanitize_url( $details['target'] );
70
 
71
  return array(
72
+ 'url_from' => $this->sanitize_url( $details['url_from'] ),
73
+ 'url_notfrom' => isset( $details['url_notfrom'] ) ? $this->sanitize_url( $details['url_notfrom'] ) : false,
74
  'regex' => isset( $details['regex'] ) ? true : false,
75
+ 'referrer' => isset( $details['referrer'] ) ? $this->sanitize_referrer( $details['referrer'] ) : false,
76
  );
77
  }
78
 
79
+ public function sanitize_referrer( $agent ) {
80
+ return $this->sanitize_url( $agent );
81
+ }
82
+
83
  function initialize( $url ) {
84
  $this->url = array( $url, '' );
85
  }
93
  $target = false;
94
 
95
  // Check if referrer matches
96
+ if ( ( $this->regex === false && $_SERVER['HTTP_REFERER'] === $this->referrer ) || ( $this->regex === true && preg_match( '@'.str_replace( '@', '\\@', $this->referrer ).'@', $_SERVER['HTTP_REFERER'], $matches ) ) ) {
97
  $target = $this->url_from;
98
 
99
  if ( $regex )
100
  $target = preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $target, $url );
101
  }
102
+ elseif ( $this->url_notfrom !== '' )
103
  $target = $this->url_notfrom;
104
  return $target;
105
  }
106
 
107
+ function match_name() {
108
  return sprintf( 'referrer - <code>%s</code>', $this->referrer );
109
  }
110
  }
matches/url.php CHANGED
@@ -1,24 +1,4 @@
1
  <?php
2
- /**
3
- * Redirection
4
- *
5
- * @package Redirection
6
- * @author John Godley
7
- * @copyright Copyright (C) John Godley
8
- **/
9
-
10
- /*
11
- ============================================================================================================
12
- This software is provided "as is" and any express or implied warranties, including, but not limited to, the
13
- implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall
14
- the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or
15
- consequential damages (including, but not limited to, procurement of substitute goods or services; loss of
16
- use, data, or profits; or business interruption) however caused and on any theory of liability, whether in
17
- contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of
18
- this software, even if advised of the possibility of such damage.
19
-
20
- For full license details see license.txt
21
- ============================================================================================================ */
22
 
23
  class URL_Match extends Red_Match {
24
  function name () {
@@ -47,11 +27,11 @@ class URL_Match extends Red_Match {
47
  <?php endif;
48
  }
49
 
50
- function save( $details ) {
51
- if ( !isset( $details['target'] ) || strlen( $details['target'] ) == 0 )
52
  $details['target'] = '/';
53
 
54
- return array( 'url' => $details['target'] );
55
  }
56
 
57
  function get_target( $url, $matched_url, $regex ) {
@@ -59,7 +39,7 @@ class URL_Match extends Red_Match {
59
  if ( $regex )
60
  $target = preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $this->url, $url );
61
 
62
- if ( $target == '' )
63
  return $matched_url;
64
  return $target;
65
  }
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  class URL_Match extends Red_Match {
4
  function name () {
27
  <?php endif;
28
  }
29
 
30
+ function save( $details ) {
31
+ if ( ! isset( $details['target'] ) || strlen( $details['target'] ) === 0 )
32
  $details['target'] = '/';
33
 
34
+ return array( 'url' => $this->sanitize_url( $details['target'] ) );
35
  }
36
 
37
  function get_target( $url, $matched_url, $regex ) {
39
  if ( $regex )
40
  $target = preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $this->url, $url );
41
 
42
+ if ( $target === '' )
43
  return $matched_url;
44
  return $target;
45
  }
matches/user-agent.php CHANGED
@@ -1,33 +1,13 @@
1
  <?php
2
- /**
3
- * Redirection
4
- *
5
- * @package Redirection
6
- * @author John Godley
7
- * @copyright Copyright( C ) John Godley
8
- **/
9
-
10
- /*
11
- ============================================================================================================
12
- This software is provided "as is" and any express or implied warranties, including, but not limited to, the
13
- implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall
14
- the copyright owner or contributors be liable for any direct, indirect, incidental, special, exemplary, or
15
- consequential damages( including, but not limited to, procurement of substitute goods or services; loss of
16
- use, data, or profits; or business interruption ) however caused and on any theory of liability, whether in
17
- contract, strict liability, or tort( including negligence or otherwise ) arising in any way out of the use of
18
- this software, even if advised of the possibility of such damage.
19
-
20
- For full license details see license.txt
21
- ============================================================================================================ */
22
 
23
  class Agent_Match extends Red_Match {
24
- var $user_agent;
25
 
26
  function name() {
27
  return __( 'URL and user agent', 'redirection' );
28
  }
29
 
30
- function show() {
31
  $defined = array(
32
  'feedburner|feedvalidator' => __( 'FeedBurner', 'redirection' ),
33
  'MSIE' => __( 'Internet Explorer', 'redirection' ),
@@ -41,29 +21,30 @@ class Agent_Match extends Red_Match {
41
  );
42
 
43
  ?>
44
- <tr>
45
- <th width="100"><?php _e( 'User Agent', 'redirection' ); ?>:</th>
46
- <td>
47
- <input id="user_agent_<?php echo $this->id ?>" style="width: 65%" type="text" name="user_agent" value="<?php echo esc_attr( $this->user_agent ); ?>"/>
48
- <select style="width: 30%" class="change-user-agent">
49
- <?php foreach ( $defined AS $key => $value ) : ?>
50
- <option value="<?php echo $key ?>"<?php if ( $key == $this->user_agent ) echo ' selected="selected"' ?>><?php echo esc_html( $value ) ?></option>
51
- <?php endforeach; ?>
52
- </select>
53
- </td>
54
- </tr>
55
- <?php if ( $this->action->can_change_code() ) : ?>
56
- <tr>
57
- <th><?php _e( 'HTTP Code', 'redirection' ); ?>:</th>
58
- <td>
59
- <select name="action_code">
60
- <?php $this->action->display_actions(); ?>
61
- </select>
62
- </td>
63
- </tr>
64
- <?php endif; ?>
65
 
66
- <?php if ( $this->action->can_perform_action() ) : ?>
 
 
 
 
 
 
 
 
 
 
 
67
  <tr>
68
  <th></th>
69
  <td>
@@ -93,21 +74,24 @@ class Agent_Match extends Red_Match {
93
  <input style="width: 95%" type="text" name="url_notfrom" value="<?php echo esc_attr( $this->url_notfrom ); ?>" id="new"/><br/>
94
  </td>
95
  </tr>
96
- <?php endif; ?>
97
- <?php
98
  }
99
 
100
- function save( $details ) {
101
  if ( isset( $details['target'] ) )
102
- $details['url_from'] = $details['target'];
103
 
104
  return array(
105
- 'url_from' => isset( $details['url_from'] ) ? $details['url_from'] : false,
106
- 'url_notfrom' => isset( $details['url_notfrom'] ) ? $details['url_notfrom'] : false,
107
- 'user_agent' => isset( $details['user_agent'] ) ? $details['user_agent'] : false
108
  );
109
  }
110
 
 
 
 
 
111
  function initialize( $url ) {
112
  $this->url = array( $url, '' );
113
  }
@@ -121,12 +105,12 @@ class Agent_Match extends Red_Match {
121
  // Check if referrer matches
122
  if ( preg_match( '@'.str_replace( '@', '\\@', $this->user_agent ).'@i', $_SERVER['HTTP_USER_AGENT'], $matches ) > 0 )
123
  return preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $this->url_from, $url );
124
- elseif ( $this->url_notfrom != '' )
125
  return $this->url_notfrom;
126
  return false;
127
  }
128
 
129
- function match_name() {
130
  return sprintf( 'user agent - %s', $this->user_agent );
131
  }
132
  }
1
  <?php
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  class Agent_Match extends Red_Match {
4
+ public $user_agent;
5
 
6
  function name() {
7
  return __( 'URL and user agent', 'redirection' );
8
  }
9
 
10
+ function show() {
11
  $defined = array(
12
  'feedburner|feedvalidator' => __( 'FeedBurner', 'redirection' ),
13
  'MSIE' => __( 'Internet Explorer', 'redirection' ),
21
  );
22
 
23
  ?>
24
+ <tr>
25
+ <th width="100"><?php _e( 'User Agent', 'redirection' ); ?>:</th>
26
+ <td>
27
+ <input id="user_agent_<?php echo $this->id ?>" style="width: 65%" type="text" name="user_agent" value="<?php echo esc_attr( $this->user_agent ); ?>"/>
28
+ <select style="width: 30%" class="change-user-agent">
29
+ <?php foreach ( $defined as $key => $value ) : ?>
30
+ <option value="<?php echo $key ?>"<?php if ( $key === $this->user_agent ) echo ' selected="selected"' ?>><?php echo esc_html( $value ) ?></option>
31
+ <?php endforeach; ?>
32
+ </select>
33
+ </td>
34
+ </tr>
 
 
 
 
 
 
 
 
 
 
35
 
36
+ <?php if ( $this->action->can_change_code() ) : ?>
37
+ <tr>
38
+ <th><?php _e( 'HTTP Code', 'redirection' ); ?>:</th>
39
+ <td>
40
+ <select name="action_code">
41
+ <?php $this->action->display_actions(); ?>
42
+ </select>
43
+ </td>
44
+ </tr>
45
+ <?php endif; ?>
46
+
47
+ <?php if ( $this->action->can_perform_action() ) : ?>
48
  <tr>
49
  <th></th>
50
  <td>
74
  <input style="width: 95%" type="text" name="url_notfrom" value="<?php echo esc_attr( $this->url_notfrom ); ?>" id="new"/><br/>
75
  </td>
76
  </tr>
77
+ <?php endif;
 
78
  }
79
 
80
+ function save( $details ) {
81
  if ( isset( $details['target'] ) )
82
+ $details['url_from'] = $this->sanitize_url( $details['target'] );
83
 
84
  return array(
85
+ 'url_from' => isset( $details['url_from'] ) ? $this->sanitize_url( $details['url_from'] ) : false,
86
+ 'url_notfrom' => isset( $details['url_notfrom'] ) ? $this->sanitize_url( $details['url_notfrom'] ) : false,
87
+ 'user_agent' => isset( $details['user_agent'] ) ? $this->sanitize_agent( $details['user_agent'] ) : false,
88
  );
89
  }
90
 
91
+ private function sanitize_agent( $agent ) {
92
+ return $this->sanitize_url( $agent );
93
+ }
94
+
95
  function initialize( $url ) {
96
  $this->url = array( $url, '' );
97
  }
105
  // Check if referrer matches
106
  if ( preg_match( '@'.str_replace( '@', '\\@', $this->user_agent ).'@i', $_SERVER['HTTP_USER_AGENT'], $matches ) > 0 )
107
  return preg_replace( '@'.str_replace( '@', '\\@', $matched_url ).'@', $this->url_from, $url );
108
+ elseif ( $this->url_notfrom !== '' )
109
  return $this->url_notfrom;
110
  return false;
111
  }
112
 
113
+ function match_name() {
114
  return sprintf( 'user agent - %s', $this->user_agent );
115
  }
116
  }
models/action.php CHANGED
@@ -1,29 +1,30 @@
1
  <?php
2
 
3
- class Red_Action
4
- {
5
- function __construct ($values)
6
- {
7
- if (is_array ($values))
8
- {
9
- foreach ($values AS $key => $value)
10
  $this->$key = $value;
 
11
  }
12
  }
13
 
14
- function can_change_code () { return false;}
 
 
 
 
 
15
 
16
- function config () { }
 
17
 
18
- static function create ($name, $code)
19
- {
20
- $avail = self::available ();
21
- if (isset ($avail[$name]))
22
- {
23
- if (!class_exists (strtolower ($avail[$name][1])))
24
- include (dirname (__FILE__).'/../actions/'.$avail[$name][0]);
25
 
26
- $obj = new $avail[$name][1] (array ('action_code' => $code));
27
  $obj->type = $name;
28
  return $obj;
29
  }
@@ -31,33 +32,39 @@ class Red_Action
31
  return false;
32
  }
33
 
34
- static function available ()
35
- {
36
- return array
37
- (
38
- 'url' => array ('url.php', 'Url_Action'),
39
- 'error' => array ('error.php', 'Error_Action'),
40
- 'nothing' => array ('nothing.php', 'Nothing_Action'),
41
- 'random' => array ('random.php', 'Random_Action'),
42
- 'pass' => array ('pass.php', 'Pass_Action'),
43
  );
44
  }
45
 
46
- function type ()
47
- {
48
  return $this->type;
49
  }
50
 
51
- function process_before ($code, $target) { return true; }
52
- function process_after ($code, $target) { return true; }
53
- function can_perform_action () { return true; }
54
- function action_codes () { return array ();}
55
 
56
- function display_actions ()
57
- {
58
- foreach ($this->action_codes () AS $key => $code)
59
- echo '<option value="'.$key.'"'.(($key == $this->action_code) ? ' selected="selected"' : '').'>'.sprintf ('%s - %s', $key, $code).'</option>';
60
  }
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  }
63
- ?>
1
  <?php
2
 
3
+ class Red_Action {
4
+ function __construct( $values ) {
5
+ if ( is_array( $values ) ) {
6
+ foreach ( $values as $key => $value ) {
 
 
 
7
  $this->$key = $value;
8
+ }
9
  }
10
  }
11
 
12
+ function can_change_code() {
13
+ return false;
14
+ }
15
+
16
+ function config() {
17
+ }
18
 
19
+ static function create( $name, $code ) {
20
+ $avail = self::available();
21
 
22
+ if ( isset( $avail[ $name ] ) ) {
23
+ if ( ! class_exists( strtolower( $avail[ $name ][1] ) ) ) {
24
+ include dirname( __FILE__ ).'/../actions/'.$avail[ $name ][0];
25
+ }
 
 
 
26
 
27
+ $obj = new $avail[ $name ][1]( array( 'action_code' => $code ) );
28
  $obj->type = $name;
29
  return $obj;
30
  }
32
  return false;
33
  }
34
 
35
+ static function available() {
36
+ return array(
37
+ 'url' => array( 'url.php', 'Url_Action' ),
38
+ 'error' => array( 'error.php', 'Error_Action' ),
39
+ 'nothing' => array( 'nothing.php', 'Nothing_Action' ),
40
+ 'random' => array( 'random.php', 'Random_Action' ),
41
+ 'pass' => array( 'pass.php', 'Pass_Action' ),
 
 
42
  );
43
  }
44
 
45
+ function type() {
 
46
  return $this->type;
47
  }
48
 
49
+ function process_before( $code, $target ) {
50
+ return true;
51
+ }
 
52
 
53
+ function process_after( $code, $target ) {
54
+ return true;
 
 
55
  }
56
 
57
+ function can_perform_action () {
58
+ return true;
59
+ }
60
+
61
+ function action_codes () {
62
+ return array();
63
+ }
64
+
65
+ function display_actions() {
66
+ foreach ( $this->action_codes() as $key => $code ) {
67
+ echo '<option value="'.$key.'"'.( ( $key === intval( $this->action_code ) ) ? ' selected="selected"' : '' ).'>'.sprintf( '%s - %s', $key, $code ).'</option>';
68
+ }
69
+ }
70
  }
 
models/database.php CHANGED
@@ -85,16 +85,16 @@ class RE_Database {
85
  KEY `url` (`url`),
86
  KEY `ip` (`ip`),
87
  KEY `referrer` (`referrer`)
88
- ) $charset_collate;"
89
  );
90
 
91
- foreach ( $create AS $sql ) {
92
  if ( $wpdb->query( $sql ) === false )
93
  return false;
94
  }
95
 
96
  // Groups
97
- if ( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_groups" ) == 0 ) {
98
  $wpdb->insert( $wpdb->prefix.'redirection_groups', array( 'name' => __( 'Redirections' ), 'module_id' => 1, 'position' => 0 ) );
99
  $wpdb->insert( $wpdb->prefix.'redirection_groups', array( 'name' => __( 'Modified Posts' ), 'module_id' => 1, 'position' => 1 ) );
100
 
@@ -116,23 +116,23 @@ class RE_Database {
116
  $success = $this->install();
117
  else {
118
  // Try and upgrade from a previous version
119
- if ( $current == '2.0' )
120
  $this->upgrade_from_20();
121
- elseif ( $current == '2.0.1' )
122
  $this->upgrade_from_21();
123
- elseif ( $current == '2.0.2' )
124
  $this->upgrade_from_22();
125
 
126
- if ( version_compare( $current, '2.1.16' ) == -1 )
127
  $this->upgrade_to_216();
128
 
129
- if ( version_compare( $current, '2.2' ) == -1 )
130
  $this->upgrade_to_220();
131
 
132
- if ( version_compare( $current, '2.3.1' ) == -1 )
133
  $this->upgrade_to_231();
134
 
135
- if ( version_compare( $current, '2.3.2' ) == -1 )
136
  $this->upgrade_to_232();
137
 
138
  $success = true;
85
  KEY `url` (`url`),
86
  KEY `ip` (`ip`),
87
  KEY `referrer` (`referrer`)
88
+ ) $charset_collate;",
89
  );
90
 
91
+ foreach ( $create as $sql ) {
92
  if ( $wpdb->query( $sql ) === false )
93
  return false;
94
  }
95
 
96
  // Groups
97
+ if ( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_groups" ) === 0 ) {
98
  $wpdb->insert( $wpdb->prefix.'redirection_groups', array( 'name' => __( 'Redirections' ), 'module_id' => 1, 'position' => 0 ) );
99
  $wpdb->insert( $wpdb->prefix.'redirection_groups', array( 'name' => __( 'Modified Posts' ), 'module_id' => 1, 'position' => 1 ) );
100
 
116
  $success = $this->install();
117
  else {
118
  // Try and upgrade from a previous version
119
+ if ( $current === '2.0' )
120
  $this->upgrade_from_20();
121
+ elseif ( $current === '2.0.1' )
122
  $this->upgrade_from_21();
123
+ elseif ( $current === '2.0.2' )
124
  $this->upgrade_from_22();
125
 
126
+ if ( version_compare( $current, '2.1.16' ) === -1 )
127
  $this->upgrade_to_216();
128
 
129
+ if ( version_compare( $current, '2.2' ) === -1 )
130
  $this->upgrade_to_220();
131
 
132
+ if ( version_compare( $current, '2.3.1' ) === -1 )
133
  $this->upgrade_to_231();
134
 
135
+ if ( version_compare( $current, '2.3.2' ) === -1 )
136
  $this->upgrade_to_232();
137
 
138
  $success = true;
models/file-io.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  abstract class Red_FileIO {
4
- var $items = array();
5
 
6
  public static function create( $type ) {
7
  $exporter = false;
@@ -30,7 +30,7 @@ abstract class Red_FileIO {
30
  if ( is_uploaded_file( $file['tmp_name'] ) ) {
31
  $parts = pathinfo( $file['name'] );
32
 
33
- if ( isset( $parts['extension'] ) && $parts['extension'] == 'csv' ) {
34
  include dirname( dirname( __FILE__ ) ).'/fileio/csv.php';
35
  $importer = new Red_Csv_File();
36
  $data = '';
@@ -38,7 +38,7 @@ abstract class Red_FileIO {
38
  else {
39
  include dirname( dirname( __FILE__ ) ).'/fileio/apache.php';
40
  $importer = new Red_Apache_File();
41
- $data = @file_get_contents ($file['tmp_name']);
42
  }
43
 
44
  return $importer->load( $group, $data, $file['tmp_name'] );
1
  <?php
2
 
3
  abstract class Red_FileIO {
4
+ public $items = array();
5
 
6
  public static function create( $type ) {
7
  $exporter = false;
30
  if ( is_uploaded_file( $file['tmp_name'] ) ) {
31
  $parts = pathinfo( $file['name'] );
32
 
33
+ if ( isset( $parts['extension'] ) && $parts['extension'] === 'csv' ) {
34
  include dirname( dirname( __FILE__ ) ).'/fileio/csv.php';
35
  $importer = new Red_Csv_File();
36
  $data = '';
38
  else {
39
  include dirname( dirname( __FILE__ ) ).'/fileio/apache.php';
40
  $importer = new Red_Apache_File();
41
+ $data = @file_get_contents( $file['tmp_name'] );
42
  }
43
 
44
  return $importer->load( $group, $data, $file['tmp_name'] );
models/flusher.php CHANGED
@@ -7,18 +7,17 @@ class Red_Flusher {
7
  const DELETE_KEEP_ON = 15; // 15 minutes
8
 
9
  public function flush() {
10
- $total = 0;
11
  $options = red_get_options();
12
 
13
- $total += $this->expire_logs( $options['expire_redirect'] );
14
- $total += $this->expire_404( $options['expire_404'] );
15
 
16
  if ( $total >= self::DELETE_MAX ) {
17
- $next = time() + self::DELETE_KEEP_ON;
18
 
19
- // There are still more logs to clear - keep on doing until we've clean or until the next normal event
20
  if ( $next < wp_next_scheduled( self::DELETE_HOOK ) ) {
21
- wp_schedule_single_event( time() + ( self::DELETE_KEEP_ON * 60 ), self::DELETE_HOOK );
22
  }
23
  }
24
 
@@ -26,6 +25,8 @@ class Red_Flusher {
26
  }
27
 
28
  private function optimize_logs() {
 
 
29
  $rand = mt_rand( 1, 5000 );
30
 
31
  if ( $rand === 11 )
@@ -34,14 +35,14 @@ class Red_Flusher {
34
  $wpdb->query( "OPTIMIZE TABLE {$wpdb->prefix}redirection_404" );
35
  }
36
 
37
- private function expire_logs( $expiry_time ) {
38
  global $wpdb;
39
 
40
  if ( $expiry_time > 0 ) {
41
- $logs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_logs WHERE created < DATE_SUB(NOW(), INTERVAL %d DAY)", $expiry_time ) );
42
 
43
  if ( $logs > 0 ) {
44
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_logs WHERE created < DATE_SUB(NOW(), INTERVAL %d DAY) LIMIT %d", $expiry_time, self::DELETE_MAX ) );
45
  return min( self::DELETE_MAX, $logs );
46
  }
47
  }
@@ -49,30 +50,17 @@ class Red_Flusher {
49
  return 0;
50
  }
51
 
52
- private function expire_404( $expiry_time ) {
53
- global $wpdb;
54
-
55
- if ( $expiry_time > 0 ) {
56
- $l404 = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_404 WHERE created < DATE_SUB(NOW(), INTERVAL %d DAY)", $expiry_time ) );
57
-
58
- if ( $l404 > 0 ) {
59
- $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_404 WHERE created < DATE_SUB(NOW(), INTERVAL %d DAY) LIMIT %d", $expiry_time, self::DELETE_MAX ) );
60
- return min( self::DELETE_MAX, $l404 );
61
- }
62
- }
63
-
64
- return 0;
65
- }
66
-
67
  public static function schedule() {
68
  $options = red_get_options();
69
 
70
  if ( $options['expire_redirect'] > 0 || $options['expire_404'] > 0 ) {
71
- if ( !wp_next_scheduled( self::DELETE_HOOK ) )
72
  wp_schedule_event( time(), self::DELETE_FREQ, self::DELETE_HOOK );
 
73
  }
74
- else
75
  Red_Flusher::clear();
 
76
  }
77
 
78
  public static function clear() {
7
  const DELETE_KEEP_ON = 15; // 15 minutes
8
 
9
  public function flush() {
 
10
  $options = red_get_options();
11
 
12
+ $total = $this->expire_logs( 'redirection_logs', $options['expire_redirect'] );
13
+ $total += $this->expire_logs( 'redirection_404', $options['expire_404'] );
14
 
15
  if ( $total >= self::DELETE_MAX ) {
16
+ $next = time() + ( self::DELETE_KEEP_ON * 60 );
17
 
18
+ // There are still more logs to clear - keep on doing until we're clean or until the next normal event
19
  if ( $next < wp_next_scheduled( self::DELETE_HOOK ) ) {
20
+ wp_schedule_single_event( $next, self::DELETE_HOOK );
21
  }
22
  }
23
 
25
  }
26
 
27
  private function optimize_logs() {
28
+ global $wpdb;
29
+
30
  $rand = mt_rand( 1, 5000 );
31
 
32
  if ( $rand === 11 )
35
  $wpdb->query( "OPTIMIZE TABLE {$wpdb->prefix}redirection_404" );
36
  }
37
 
38
+ private function expire_logs( $table, $expiry_time ) {
39
  global $wpdb;
40
 
41
  if ( $expiry_time > 0 ) {
42
+ $logs = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}{$table} WHERE created < DATE_SUB(NOW(), INTERVAL %d DAY)", $expiry_time ) );
43
 
44
  if ( $logs > 0 ) {
45
+ $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}{$table} WHERE created < DATE_SUB(NOW(), INTERVAL %d DAY) LIMIT %d", $expiry_time, self::DELETE_MAX ) );
46
  return min( self::DELETE_MAX, $logs );
47
  }
48
  }
50
  return 0;
51
  }
52
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  public static function schedule() {
54
  $options = red_get_options();
55
 
56
  if ( $options['expire_redirect'] > 0 || $options['expire_404'] > 0 ) {
57
+ if ( ! wp_next_scheduled( self::DELETE_HOOK ) ) {
58
  wp_schedule_event( time(), self::DELETE_FREQ, self::DELETE_HOOK );
59
+ }
60
  }
61
+ else {
62
  Red_Flusher::clear();
63
+ }
64
  }
65
 
66
  public static function clear() {
models/group.php CHANGED
@@ -10,7 +10,7 @@ class Red_Group {
10
 
11
  public function __construct( $values = '' ) {
12
  if ( is_object( $values ) ) {
13
- foreach ( $values AS $key => $value ) {
14
  $this->$key = $value;
15
  }
16
  }
@@ -44,10 +44,10 @@ class Red_Group {
44
  $rows = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}redirection_groups" );
45
 
46
  if ( $rows ) {
47
- foreach ( $rows AS $row ) {
48
  $module = Red_Module::get( $row->module_id );
49
  if ( $module ) {
50
- $data[$module->get_name()][$row->id] = $row->name;
51
  }
52
  }
53
  }
@@ -66,7 +66,7 @@ class Red_Group {
66
  $data = array(
67
  'name' => trim( $name ),
68
  'module_id' => intval( $module_id ),
69
- 'position' => intval( $position )
70
  );
71
 
72
  $wpdb->insert( $wpdb->prefix.'redirection_groups', $data );
@@ -100,12 +100,12 @@ class Red_Group {
100
  // Delete all items in this group
101
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_items WHERE group_id=%d", $this->id ) );
102
 
103
- Red_Module::flush( $this->id );
104
 
105
  // Delete the group
106
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_groups WHERE id=%d", $this->id ) );
107
 
108
- if ( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_groups" ) == 0 )
109
  $wpdb->insert( $wpdb->prefix.'redirection_groups', array( 'name' => __( 'Redirections' ), 'module_id' => 1, 'position' => 0 ) );
110
  }
111
 
10
 
11
  public function __construct( $values = '' ) {
12
  if ( is_object( $values ) ) {
13
+ foreach ( $values as $key => $value ) {
14
  $this->$key = $value;
15
  }
16
  }
44
  $rows = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}redirection_groups" );
45
 
46
  if ( $rows ) {
47
+ foreach ( $rows as $row ) {
48
  $module = Red_Module::get( $row->module_id );
49
  if ( $module ) {
50
+ $data[ $module->get_name() ][ $row->id ] = $row->name;
51
  }
52
  }
53
  }
66
  $data = array(
67
  'name' => trim( $name ),
68
  'module_id' => intval( $module_id ),
69
+ 'position' => intval( $position ),
70
  );
71
 
72
  $wpdb->insert( $wpdb->prefix.'redirection_groups', $data );
100
  // Delete all items in this group
101
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_items WHERE group_id=%d", $this->id ) );
102
 
103
+ Red_Module::flush( $this->id );
104
 
105
  // Delete the group
106
  $wpdb->query( $wpdb->prepare( "DELETE FROM {$wpdb->prefix}redirection_groups WHERE id=%d", $this->id ) );
107
 
108
+ if ( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_groups" ) === 0 )
109
  $wpdb->insert( $wpdb->prefix.'redirection_groups', array( 'name' => __( 'Redirections' ), 'module_id' => 1, 'position' => 0 ) );
110
  }
111
 
models/htaccess.php CHANGED
@@ -4,7 +4,7 @@ class Red_Htaccess {
4
  private $items = array();
5
  const INSERT_REGEX = '@\n?# Created by Redirection(.*?)# End of Redirection\n?@sm';
6
 
7
- private function encode_from( $url ) {
8
  return '^'.$this->encode( $url ).'$';
9
  }
10
 
@@ -17,7 +17,7 @@ class Red_Htaccess {
17
  return $url;
18
  }
19
 
20
- private function encode( $url ) {
21
  $url = urlencode( $url );
22
  $url = str_replace( '%2F', '/', $url );
23
  $url = str_replace( '+', '%20', $url );
@@ -26,6 +26,8 @@ class Red_Htaccess {
26
  }
27
 
28
  private function encode_regex( $url ) {
 
 
29
  $url = str_replace( ' ', '%20', $url );
30
  $url = str_replace( '.', '\\.', $url );
31
  $url = str_replace( '\\.*', '.*', $url );
@@ -76,7 +78,7 @@ class Red_Htaccess {
76
  private function add_url( $item, $match ) {
77
  $url = $item->get_url();
78
 
79
- if ( $item->is_regex() == false && strpos( $url, '?') !== false || strpos( $url, '&' ) !== false ) {
80
  $url_parts = parse_url( $url );
81
  $url = $url_parts['path'];
82
  $this->items[] = sprintf( 'RewriteCond %%{QUERY_STRING} ^%s$', $url_parts['query'] );
@@ -109,7 +111,7 @@ class Red_Htaccess {
109
  }
110
 
111
  private function action_error( $data, $code, $regex) {
112
- if ( $code == '410' )
113
  return '/ [G,L]';
114
  return '/ [F,L]';
115
  }
@@ -135,7 +137,7 @@ class Red_Htaccess {
135
  $version = get_plugin_data( dirname( dirname( __FILE__ ) ).'/redirection.php' );
136
 
137
  $text[] = '# Created by Redirection';
138
- $text[] = '# '.date ('r');
139
  $text[] = '# Redirection '.trim( $version['Version'] ).' - http://urbangiraffe.com/plugins/redirection/';
140
  $text[] = '';
141
 
4
  private $items = array();
5
  const INSERT_REGEX = '@\n?# Created by Redirection(.*?)# End of Redirection\n?@sm';
6
 
7
+ private function encode_from( $url ) {
8
  return '^'.$this->encode( $url ).'$';
9
  }
10
 
17
  return $url;
18
  }
19
 
20
+ private function encode( $url ) {
21
  $url = urlencode( $url );
22
  $url = str_replace( '%2F', '/', $url );
23
  $url = str_replace( '+', '%20', $url );
26
  }
27
 
28
  private function encode_regex( $url ) {
29
+ $url = preg_replace( "/[\r\n\t].*?$/s", '', $url );
30
+ $url = preg_replace( '/[^\PC\s]/u', '', $url );
31
  $url = str_replace( ' ', '%20', $url );
32
  $url = str_replace( '.', '\\.', $url );
33
  $url = str_replace( '\\.*', '.*', $url );
78
  private function add_url( $item, $match ) {
79
  $url = $item->get_url();
80
 
81
+ if ( $item->is_regex() === false && strpos( $url, '?' ) !== false || strpos( $url, '&' ) !== false ) {
82
  $url_parts = parse_url( $url );
83
  $url = $url_parts['path'];
84
  $this->items[] = sprintf( 'RewriteCond %%{QUERY_STRING} ^%s$', $url_parts['query'] );
111
  }
112
 
113
  private function action_error( $data, $code, $regex) {
114
+ if ( $code === '410' )
115
  return '/ [G,L]';
116
  return '/ [F,L]';
117
  }
137
  $version = get_plugin_data( dirname( dirname( __FILE__ ) ).'/redirection.php' );
138
 
139
  $text[] = '# Created by Redirection';
140
+ $text[] = '# '.date( 'r' );
141
  $text[] = '# Redirection '.trim( $version['Version'] ).' - http://urbangiraffe.com/plugins/redirection/';
142
  $text[] = '';
143
 
models/log.php CHANGED
@@ -1,16 +1,16 @@
1
  <?php
2
 
3
  class RE_Log {
4
- var $id;
5
- var $created;
6
- var $url;
7
- var $agent;
8
- var $referrer;
9
- var $ip;
10
- var $redirection_id;
11
 
12
  function __construct( $values ) {
13
- foreach ( $values AS $key => $value ) {
14
  $this->$key = $value;
15
  }
16
 
@@ -36,10 +36,10 @@ class RE_Log {
36
  'ip' => $ip,
37
  );
38
 
39
- if ( !empty( $agent ) )
40
  $insert['agent'] = $agent;
41
 
42
- if ( !empty( $referrer ) )
43
  $insert['referrer'] = $referrer;
44
 
45
  $insert['sent_to'] = $target;
@@ -53,7 +53,7 @@ class RE_Log {
53
  }
54
 
55
  static function show_url( $url ) {
56
- return implode('&#8203;/', explode( '/', substr( $url, 0, 80 ) ) ).( strlen( $url ) > 80 ? '...' : '' );
57
  }
58
 
59
  static function delete( $id ) {
@@ -75,19 +75,19 @@ class RE_Log {
75
  global $wpdb;
76
 
77
  $where = array();
78
- if ( $type == 'module' )
79
  $where[] = $wpdb->prepare( 'module_id=%d', $id );
80
- elseif ( $type == 'group' )
81
  $where[] = $wpdb->prepare( 'group_id=%d AND redirection_id IS NOT NULL', $id );
82
- elseif ( $type == 'redirect' )
83
  $where[] = $wpdb->prepare( 'redirection_id=%d', $id );
84
 
85
  if ( isset( $_REQUEST['s'] ) )
86
- $where[] = $wpdb->prepare( 'url LIKE %s', '%'.like_escape( $_REQUEST['s'] ).'%' );
87
 
88
- $where_cond = "";
89
  if ( count( $where ) > 0 )
90
- $where_cond = " WHERE ".implode( ' AND ', $where );
91
 
92
  $wpdb->query( "DELETE FROM {$wpdb->prefix}redirection_logs ".$where_cond );
93
  }
@@ -109,7 +109,7 @@ class RE_Log {
109
  $extra = '';
110
  $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_logs";
111
  if ( isset( $_REQUEST['s'] ) )
112
- $extra = $wpdb->prepare( " WHERE url LIKE %s", '%'.like_escape( $_REQUEST['s'] ).'%' );
113
 
114
  $total_items = $wpdb->get_var( $sql.$extra );
115
  $exported = 0;
@@ -118,7 +118,7 @@ class RE_Log {
118
  $rows = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}redirection_logs LIMIT %d,%d", $exported, 100 ) );
119
  $exported += count( $rows );
120
 
121
- foreach ( $rows AS $row ) {
122
  $csv = array(
123
  $row->created,
124
  $row->url,
@@ -138,19 +138,19 @@ class RE_Log {
138
  }
139
 
140
  class RE_404 {
141
- var $id;
142
- var $created;
143
- var $url;
144
- var $agent;
145
- var $referrer;
146
- var $ip;
147
 
148
  function __construct( $values ) {
149
- foreach ( $values AS $key => $value ) {
150
  $this->$key = $value;
151
- }
152
 
153
- $this->created = mysql2date ('U', $this->created);
154
  }
155
 
156
  static function get_by_id( $id ) {
@@ -171,10 +171,10 @@ class RE_404 {
171
  'ip' => ip2long( $ip ),
172
  );
173
 
174
- if ( !empty( $agent ) )
175
  $insert['agent'] = $agent;
176
 
177
- if ( !empty( $referrer ) )
178
  $insert['referrer'] = $referrer;
179
 
180
  $wpdb->insert( $wpdb->prefix.'redirection_404', $insert );
@@ -191,11 +191,11 @@ class RE_404 {
191
 
192
  $where = array();
193
  if ( isset( $_REQUEST['s'] ) )
194
- $where[] = $wpdb->prepare( 'url LIKE %s', '%'.like_escape( $_REQUEST['s'] ).'%' );
195
 
196
- $where_cond = "";
197
  if ( count( $where ) > 0 )
198
- $where_cond = " WHERE ".implode( ' AND ', $where );
199
 
200
  $wpdb->query( "DELETE FROM {$wpdb->prefix}redirection_404 ".$where_cond );
201
  }
@@ -217,7 +217,7 @@ class RE_404 {
217
  $extra = '';
218
  $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_404";
219
  if ( isset( $_REQUEST['s'] ) )
220
- $extra = $wpdb->prepare( " WHERE url LIKE %s", '%'.like_escape( $_REQUEST['s'] ).'%' );
221
 
222
  $total_items = $wpdb->get_var( $sql.$extra );
223
  $exported = 0;
@@ -226,7 +226,7 @@ class RE_404 {
226
  $rows = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}redirection_404 LIMIT %d,%d", $exported, 100 ) );
227
  $exported += count( $rows );
228
 
229
- foreach ( $rows AS $row ) {
230
  $csv = array(
231
  $row->created,
232
  $row->url,
1
  <?php
2
 
3
  class RE_Log {
4
+ public $id;
5
+ public $created;
6
+ public $url;
7
+ public $agent;
8
+ public $referrer;
9
+ public $ip;
10
+ public $redirection_id;
11
 
12
  function __construct( $values ) {
13
+ foreach ( $values as $key => $value ) {
14
  $this->$key = $value;
15
  }
16
 
36
  'ip' => $ip,
37
  );
38
 
39
+ if ( ! empty( $agent ) )
40
  $insert['agent'] = $agent;
41
 
42
+ if ( ! empty( $referrer ) )
43
  $insert['referrer'] = $referrer;
44
 
45
  $insert['sent_to'] = $target;
53
  }
54
 
55
  static function show_url( $url ) {
56
+ return implode( '&#8203;/', explode( '/', substr( $url, 0, 80 ) ) ).( strlen( $url ) > 80 ? '...' : '' );
57
  }
58
 
59
  static function delete( $id ) {
75
  global $wpdb;
76
 
77
  $where = array();
78
+ if ( $type === 'module' )
79
  $where[] = $wpdb->prepare( 'module_id=%d', $id );
80
+ elseif ( $type === 'group' )
81
  $where[] = $wpdb->prepare( 'group_id=%d AND redirection_id IS NOT NULL', $id );
82
+ elseif ( $type === 'redirect' )
83
  $where[] = $wpdb->prepare( 'redirection_id=%d', $id );
84
 
85
  if ( isset( $_REQUEST['s'] ) )
86
+ $where[] = $wpdb->prepare( 'url LIKE %s', '%'.$wpdb->esc_like( $_REQUEST['s'] ).'%' );
87
 
88
+ $where_cond = '';
89
  if ( count( $where ) > 0 )
90
+ $where_cond = ' WHERE '.implode( ' AND ', $where );
91
 
92
  $wpdb->query( "DELETE FROM {$wpdb->prefix}redirection_logs ".$where_cond );
93
  }
109
  $extra = '';
110
  $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_logs";
111
  if ( isset( $_REQUEST['s'] ) )
112
+ $extra = $wpdb->prepare( ' WHERE url LIKE %s', '%'.$wpdb->esc_like( $_REQUEST['s'] ).'%' );
113
 
114
  $total_items = $wpdb->get_var( $sql.$extra );
115
  $exported = 0;
118
  $rows = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}redirection_logs LIMIT %d,%d", $exported, 100 ) );
119
  $exported += count( $rows );
120
 
121
+ foreach ( $rows as $row ) {
122
  $csv = array(
123
  $row->created,
124
  $row->url,
138
  }
139
 
140
  class RE_404 {
141
+ public $id;
142
+ public $created;
143
+ public $url;
144
+ public $agent;
145
+ public $referrer;
146
+ public $ip;
147
 
148
  function __construct( $values ) {
149
+ foreach ( $values as $key => $value ) {
150
  $this->$key = $value;
151
+ }
152
 
153
+ $this->created = mysql2date( 'U', $this->created );
154
  }
155
 
156
  static function get_by_id( $id ) {
171
  'ip' => ip2long( $ip ),
172
  );
173
 
174
+ if ( ! empty( $agent ) )
175
  $insert['agent'] = $agent;
176
 
177
+ if ( ! empty( $referrer ) )
178
  $insert['referrer'] = $referrer;
179
 
180
  $wpdb->insert( $wpdb->prefix.'redirection_404', $insert );
191
 
192
  $where = array();
193
  if ( isset( $_REQUEST['s'] ) )
194
+ $where[] = $wpdb->prepare( 'url LIKE %s', '%'.$wpdb->esc_like( $_REQUEST['s'] ).'%' );
195
 
196
+ $where_cond = '';
197
  if ( count( $where ) > 0 )
198
+ $where_cond = ' WHERE '.implode( ' AND ', $where );
199
 
200
  $wpdb->query( "DELETE FROM {$wpdb->prefix}redirection_404 ".$where_cond );
201
  }
217
  $extra = '';
218
  $sql = "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_404";
219
  if ( isset( $_REQUEST['s'] ) )
220
+ $extra = $wpdb->prepare( ' WHERE url LIKE %s', '%'.$wpdb->esc_like( $_REQUEST['s'] ).'%' );
221
 
222
  $total_items = $wpdb->get_var( $sql.$extra );
223
  $exported = 0;
226
  $rows = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->prefix}redirection_404 LIMIT %d,%d", $exported, 100 ) );
227
  $exported += count( $rows );
228
 
229
+ foreach ( $rows as $row ) {
230
  $csv = array(
231
  $row->created,
232
  $row->url,
models/match.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  class Red_Match {
4
- var $url;
5
 
6
  function __construct( $values = '' ) {
7
  if ( $values ) {
@@ -10,7 +10,7 @@ class Red_Match {
10
  $obj = maybe_unserialize( $values );
11
 
12
  if ( is_array( $obj ) ) {
13
- foreach ( $obj AS $key => $value ) {
14
  $this->$key = $value;
15
  }
16
  }
@@ -19,7 +19,7 @@ class Red_Match {
19
 
20
  function data( $details ) {
21
  $data = $this->save( $details );
22
- if ( count( $data ) == 1 && !is_array( current( $data ) ) )
23
  $data = current( $data );
24
  else
25
  $data = serialize( $data );
@@ -45,13 +45,23 @@ class Red_Match {
45
  return false;
46
  }
47
 
 
 
 
 
 
 
 
 
 
 
48
  static function create( $name, $data = '' ) {
49
  $avail = self::available();
50
- if ( isset( $avail[strtolower( $name )] ) ) {
51
  $classname = $name.'_match';
52
 
53
- if ( !class_exists( strtolower( $classname ) ) )
54
- include( dirname( __FILE__ ).'/../matches/'.$avail[strtolower( $name )] );
55
  return new $classname( $data );
56
  }
57
 
@@ -62,16 +72,16 @@ class Red_Match {
62
  $data = array();
63
 
64
  $avail = self::available();
65
- foreach ( $avail AS $name => $file ) {
66
  $obj = self::create( $name );
67
- $data[$name] = $obj->name();
68
  }
69
 
70
  return $data;
71
  }
72
 
73
  static function available() {
74
- return array (
75
  'url' => 'url.php',
76
  'referrer' => 'referrer.php',
77
  'agent' => 'user-agent.php',
1
  <?php
2
 
3
  class Red_Match {
4
+ public $url;
5
 
6
  function __construct( $values = '' ) {
7
  if ( $values ) {
10
  $obj = maybe_unserialize( $values );
11
 
12
  if ( is_array( $obj ) ) {
13
+ foreach ( $obj as $key => $value ) {
14
  $this->$key = $value;
15
  }
16
  }
19
 
20
  function data( $details ) {
21
  $data = $this->save( $details );
22
+ if ( count( $data ) === 1 && ! is_array( current( $data ) ) )
23
  $data = current( $data );
24
  else
25
  $data = serialize( $data );
45
  return false;
46
  }
47
 
48
+ function sanitize_url( $url ) {
49
+ // No new lines
50
+ $url = preg_replace( "/[\r\n\t].*?$/s", '', $url );
51
+
52
+ // Clean control codes
53
+ $url = preg_replace( '/[^\PC\s]/u', '', $url );
54
+
55
+ return $url;
56
+ }
57
+
58
  static function create( $name, $data = '' ) {
59
  $avail = self::available();
60
+ if ( isset( $avail[ strtolower( $name ) ] ) ) {
61
  $classname = $name.'_match';
62
 
63
+ if ( ! class_exists( strtolower( $classname ) ) )
64
+ include( dirname( __FILE__ ).'/../matches/'.$avail[ strtolower( $name ) ] );
65
  return new $classname( $data );
66
  }
67
 
72
  $data = array();
73
 
74
  $avail = self::available();
75
+ foreach ( $avail as $name => $file ) {
76
  $obj = self::create( $name );
77
+ $data[ $name ] = $obj->name();
78
  }
79
 
80
  return $data;
81
  }
82
 
83
  static function available() {
84
+ return array(
85
  'url' => 'url.php',
86
  'referrer' => 'referrer.php',
87
  'agent' => 'user-agent.php',
models/module.php CHANGED
@@ -15,11 +15,11 @@ abstract class Red_Module {
15
  $options = red_get_options();
16
 
17
  if ( $id === Apache_Module::MODULE_ID )
18
- return new Apache_Module( isset( $options['modules'][Apache_Module::MODULE_ID] ) ? $options['modules'][Apache_Module::MODULE_ID] : array() );
19
  else if ( $id === WordPress_Module::MODULE_ID )
20
- return new WordPress_Module( isset( $options['modules'][WordPress_Module::MODULE_ID] ) ? $options['modules'][WordPress_Module::MODULE_ID] : array() );
21
  else if ( $id === Nginx_Module::MODULE_ID )
22
- return new Nginx_Module( isset( $options['modules'][Nginx_Module::MODULE_ID] ) ? $options['modules'][Nginx_Module::MODULE_ID] : array() );
23
 
24
  return false;
25
  }
15
  $options = red_get_options();
16
 
17
  if ( $id === Apache_Module::MODULE_ID )
18
+ return new Apache_Module( isset( $options['modules'][ Apache_Module::MODULE_ID ] ) ? $options['modules'][ Apache_Module::MODULE_ID ] : array() );
19
  else if ( $id === WordPress_Module::MODULE_ID )
20
+ return new WordPress_Module( isset( $options['modules'][ WordPress_Module::MODULE_ID ] ) ? $options['modules'][ WordPress_Module::MODULE_ID ] : array() );
21
  else if ( $id === Nginx_Module::MODULE_ID )
22
+ return new Nginx_Module( isset( $options['modules'][ Nginx_Module::MODULE_ID ] ) ? $options['modules'][ Nginx_Module::MODULE_ID ] : array() );
23
 
24
  return false;
25
  }
models/pager.php CHANGED
@@ -1,7 +1,8 @@
1
  <?php
2
 
3
- if ( !class_exists( 'WP_List_Table' ) )
4
- require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
 
5
 
6
  class Redirection_Table extends WP_List_Table {
7
  private $groups;
@@ -15,18 +16,18 @@ class Redirection_Table extends WP_List_Table {
15
 
16
  //Set parent defaults
17
  parent::__construct( array(
18
- 'singular' => 'item', //singular name of the listed records
19
- 'plural' => 'items', //plural name of the listed records
20
- 'ajax' => false //does this table support ajax?
21
  ) );
22
  }
23
 
24
- function get_columns(){
25
  $columns = array(
26
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
27
- 'type' => __( 'Type', 'redirection' ),
28
- 'url' => __( 'URL', 'redirection' ),
29
- 'hits' => __( 'Hits', 'redirection' ),
30
  'last_access' => __( 'Last Access', 'redirection' ),
31
  );
32
 
@@ -38,7 +39,7 @@ class Redirection_Table extends WP_List_Table {
38
  }
39
 
40
  function column_last_access( $item ) {
41
- if ( $item->get_last_hit() == 0 )
42
  return '&mdash;';
43
  return date_i18n( get_option( 'date_format' ), $item->get_last_hit() );
44
  }
@@ -49,7 +50,7 @@ class Redirection_Table extends WP_List_Table {
49
 
50
  function column_url( $item ) {
51
  $actions = array(
52
- 'edit' => sprintf( '<a class="red-ajax" data-action="%s" data-nonce="%s" data-id="%s" href="#">'.__( 'Edit', 'redirection' ).'</a>', 'red_redirect_edit', wp_create_nonce( 'red-edit_'.$item->get_id() ), $item->get_id() ),
53
  'delete' => sprintf( '<a class="red-auto" data-action="%s" href="#">'.__( 'Delete', 'redirection' ).'</a>', 'delete', $item->get_id() ),
54
  );
55
 
@@ -69,11 +70,11 @@ class Redirection_Table extends WP_List_Table {
69
  return sprintf( '%1$s %2$s', $before.'<a href="'.esc_url( $item->get_url() ).'">'.esc_html( $title ).'</a>'.$after, $this->row_actions( $actions ) );
70
  }
71
 
72
- function column_cb($item){
73
  return sprintf(
74
  '<input type="checkbox" name="%1$s[]" value="%2$s" />',
75
  /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
76
- /*$2%s*/ $item->get_id() //The value of the checkbox should be the record's id
77
  );
78
  }
79
 
@@ -90,7 +91,7 @@ class Redirection_Table extends WP_List_Table {
90
 
91
  function get_sortable_columns() {
92
  $sortable_columns = array(
93
- 'url' => array( 'url', false),
94
  );
95
  return $sortable_columns;
96
  }
@@ -107,14 +108,14 @@ class Redirection_Table extends WP_List_Table {
107
  }
108
 
109
  function process_bulk_action() {
110
- if ( !isset( $_POST['item'] ) )
111
  return;
112
 
113
  if ( in_array( $this->current_action(), array( 'reset', 'enable', 'disable', 'delete' ) ) ) {
114
  $redirections = array();
115
  $flush = array();
116
 
117
- foreach( (array)$_POST['item'] AS $id ) {
118
  $redirect = Red_Item::get_by_id( intval( $id ) );
119
 
120
  if ( $redirect ) {
@@ -134,14 +135,14 @@ class Redirection_Table extends WP_List_Table {
134
  }
135
 
136
  $flush = array_unique( $flush );
137
- foreach ( $flush AS $group_id ) {
138
  Red_Module::flush( $group_id );
139
  }
140
  }
141
  }
142
 
143
  function extra_tablenav( $which ) {
144
- if ( $which == 'bottom' )
145
  return;
146
 
147
  ?>
@@ -149,9 +150,9 @@ class Redirection_Table extends WP_List_Table {
149
  <select name="id">
150
  <option value="0"<?php selected( 0, $this->current_group_id ); ?>><?php _e( 'No group filter', 'redirection' ); ?></option>
151
 
152
- <?php foreach ( $this->groups AS $module_name => $groups ) : ?>
153
  <optgroup label="<?php echo esc_attr( $module_name ); ?>">
154
- <?php foreach ( $groups AS $group_id => $group ) : ?>
155
  <option value="<?php echo esc_attr( $group_id ); ?>"<?php selected( $group_id, $this->current_group_id ); ?>>
156
  <?php echo esc_html( $group ); ?>
157
  </option>
@@ -188,10 +189,10 @@ class Redirection_Table extends WP_List_Table {
188
  $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
189
  $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
190
 
191
- if ( !in_array( $orderby, array_keys( $sortable ) ) )
192
  $orderby = 'id';
193
 
194
- if ( !in_array( $order, array( 'asc', 'desc' ) ) )
195
  $order = 'desc';
196
 
197
  $where = array();
@@ -199,25 +200,25 @@ class Redirection_Table extends WP_List_Table {
199
  $where[] = $wpdb->prepare( 'url LIKE %s', '%'.$wpdb->esc_like( $_GET['s'] ).'%' );
200
 
201
  if ( isset( $_REQUEST['id'] ) && intval( $_REQUEST['id'] ) > 0 )
202
- $where[] = $wpdb->prepare( "group_id=%d", intval( $_REQUEST['id'] ) );
203
 
204
- $where_cond = "";
205
  if ( count( $where ) > 0 )
206
- $where_cond = " WHERE ".implode( ' AND ', $where );
207
 
208
  $table = $wpdb->prefix.'redirection_items';
209
- $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
210
  $this->total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
211
 
212
  $this->items = array();
213
- foreach ( (array)$rows AS $row ) {
214
  $this->items[] = new Red_Item( $row );
215
  }
216
 
217
  $this->set_pagination_args( array(
218
  'total_items' => $this->total_items,
219
- 'per_page' => $per_page,
220
- 'total_pages' => ceil( $this->total_items / $per_page )
221
  ) );
222
  }
223
  }
@@ -230,18 +231,18 @@ class Redirection_Group_Table extends WP_List_Table {
230
 
231
  //Set parent defaults
232
  parent::__construct( array(
233
- 'singular' => 'item', //singular name of the listed records
234
- 'plural' => 'items', //plural name of the listed records
235
- 'ajax' => false //does this table support ajax?
236
  ) );
237
  }
238
 
239
- function get_columns(){
240
  $columns = array(
241
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
242
- 'name' => __( 'Name', 'redirection' ),
243
  'redirects' => __( 'Redirects', 'redirection' ),
244
- 'module' => __( 'Module', 'redirection' ),
245
  );
246
 
247
  return $columns;
@@ -278,11 +279,11 @@ class Redirection_Group_Table extends WP_List_Table {
278
  return esc_html( __( 'Unknown', 'redirection' ) );
279
  }
280
 
281
- function column_cb($item){
282
  return sprintf(
283
  '<input type="checkbox" name="%1$s[]" value="%2$s" />',
284
  /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
285
- /*$2%s*/ $item->id //The value of the checkbox should be the record's id
286
  );
287
  }
288
 
@@ -305,13 +306,13 @@ class Redirection_Group_Table extends WP_List_Table {
305
  }
306
 
307
  function process_bulk_action() {
308
- if ( !isset( $_POST['item'] ) )
309
  return;
310
 
311
  if ( in_array( $this->current_action(), array( 'delete', 'enable', 'disable' ) ) ) {
312
  $groups = array();
313
 
314
- foreach( (array)$_POST['item'] AS $id ) {
315
  $group = Red_Group::get( intval( $id ) );
316
 
317
  if ( $group ) {
@@ -343,7 +344,7 @@ class Redirection_Group_Table extends WP_List_Table {
343
  }
344
 
345
  function extra_tablenav( $which ) {
346
- if ( $which == 'bottom' )
347
  return;
348
 
349
  $selected = 0;
@@ -353,7 +354,7 @@ class Redirection_Group_Table extends WP_List_Table {
353
  <div class="alignleft actions">
354
  <select name="id">
355
  <option value="0"<?php selected( 0, $selected ); ?>><?php _e( 'All modules', 'redirection' ); ?></option>
356
- <?php foreach ( $this->modules AS $module_id => $module ) : ?>
357
  <option value="<?php echo esc_attr( $module_id ); ?>"<?php selected( $module_id, $selected ); ?>>
358
  <?php echo esc_html( $module->get_name() ); ?>
359
  </option>
@@ -383,10 +384,10 @@ class Redirection_Group_Table extends WP_List_Table {
383
  $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
384
  $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
385
 
386
- if ( !in_array( $orderby, array_keys( $sortable ) ) )
387
  $orderby = $wpdb->prefix.'redirection_groups.name';
388
 
389
- if ( !in_array( $order, array( 'asc', 'desc' ) ) )
390
  $order = 'desc';
391
 
392
  $where = array();
@@ -394,25 +395,25 @@ class Redirection_Group_Table extends WP_List_Table {
394
  $where[] = $wpdb->prepare( 'name LIKE %s', '%'.$wpdb->esc_like( $_GET['s'] ).'%' );
395
 
396
  if ( isset( $_REQUEST['id'] ) && intval( $_REQUEST['id'] ) > 0 )
397
- $where[] = $wpdb->prepare( "module_id=%d", intval( $_REQUEST['id'] ) );
398
 
399
- $where_cond = "";
400
  if ( count( $where ) > 0 )
401
- $where_cond = " WHERE ".implode( ' AND ', $where );
402
 
403
  $table = $wpdb->prefix.'redirection_groups';
404
  $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
405
  $this->total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
406
 
407
  $this->items = array();
408
- foreach ( (array)$rows AS $row ) {
409
  $this->items[] = new Red_Group( $row );
410
  }
411
 
412
  $this->set_pagination_args( array(
413
  'total_items' => $this->total_items,
414
- 'per_page' => $per_page,
415
- 'total_pages' => ceil( $this->total_items / $per_page )
416
  ) );
417
  }
418
  }
@@ -427,16 +428,16 @@ class Redirection_Log_Table extends WP_List_Table {
427
 
428
  //Set parent defaults
429
  parent::__construct( array(
430
- 'singular' => 'item', //singular name of the listed records
431
- 'plural' => 'items', //plural name of the listed records
432
- 'ajax' => false //does this table support ajax?
433
  ) );
434
  }
435
 
436
  function column_created( $item ) {
437
  $actions = array();
438
 
439
- if ( $item->sent_to == '' ) {
440
  $actions['add'] = '<a href="'.esc_url( $item->url ).'" class="add-log">'.__( 'Add redirect', 'redirection' ).'</a>';
441
  }
442
 
@@ -463,45 +464,45 @@ class Redirection_Log_Table extends WP_List_Table {
463
  return sprintf( '%1$s %2$s', '<a href="'.esc_url( $item->referrer ).'">'.esc_html( parse_url( $item->referrer, PHP_URL_HOST ) ).'</a>', $this->row_actions( $actions ) );
464
  }
465
 
466
- function column_cb($item){
467
  return sprintf(
468
  '<input type="checkbox" name="%1$s[]" value="%2$s" />',
469
  /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
470
- /*$2%s*/ $item->id //The value of the checkbox should be the record's id
471
  );
472
  }
473
 
474
- function get_columns(){
475
  $columns = array(
476
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
477
- 'created' => __( 'Date', 'redirection' ),
478
- 'url' => __( 'Source URL', 'redirection' ),
479
  'referrer' => __( 'Referrer', 'redirection' ),
480
- 'ip' => __( 'IP', 'redirection' ),
481
  );
482
  return $columns;
483
  }
484
 
485
  function get_sortable_columns() {
486
  $sortable_columns = array(
487
- 'created' => array( 'id', true ),
488
- 'url' => array( 'url', false),
489
  'referrer' => array( 'referrer', false ),
490
- 'ip' => array( 'item_id', false ),
491
  );
492
  return $sortable_columns;
493
  }
494
 
495
  function get_bulk_actions() {
496
  $actions = array(
497
- 'delete' => __( 'Delete', 'redirection' )
498
  );
499
  return $actions;
500
  }
501
 
502
  function process_bulk_action() {
503
  if ( 'delete' === $this->current_action() ) {
504
- foreach( $_POST['item'] AS $id ) {
505
  RE_Log::delete( intval( $id ) );
506
  }
507
  }
@@ -525,33 +526,33 @@ class Redirection_Log_Table extends WP_List_Table {
525
  $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
526
  $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
527
 
528
- if ( !in_array( $orderby, array_keys( $sortable ) ) )
529
  $orderby = 'id';
530
 
531
- if ( !in_array( $order, array( 'asc', 'desc' ) ) )
532
  $order = 'desc';
533
 
534
  $where = array();
535
  if ( isset( $_GET['s'] ) && strlen( $_GET['s'] ) > 0 )
536
  $where[] = $wpdb->prepare( 'url LIKE %s', '%'.$wpdb->esc_like( $_GET['s'] ).'%' );
537
 
538
- $where_cond = "";
539
  if ( count( $where ) > 0 )
540
- $where_cond = " WHERE ".implode( ' AND ', $where );
541
 
542
  $table = $wpdb->prefix.'redirection_logs';
543
- $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
544
  $total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
545
 
546
  $this->items = array();
547
- foreach ( (array)$rows AS $row ) {
548
  $this->items[] = new RE_Log( $row );
549
  }
550
 
551
  $this->set_pagination_args( array(
552
  'total_items' => $total_items,
553
- 'per_page' => $per_page,
554
- 'total_pages' => ceil( $total_items / $per_page )
555
  ) );
556
  }
557
  }
@@ -564,9 +565,9 @@ class Redirection_404_Table extends WP_List_Table {
564
 
565
  //Set parent defaults
566
  parent::__construct( array(
567
- 'singular' => 'item', //singular name of the listed records
568
- 'plural' => 'items', //plural name of the listed records
569
- 'ajax' => false //does this table support ajax?
570
  ) );
571
  }
572
 
@@ -594,21 +595,21 @@ class Redirection_404_Table extends WP_List_Table {
594
  return sprintf( '%1$s %2$s', '<a href="'.esc_url( $item->referrer ).'">'.esc_html( parse_url( $item->referrer, PHP_URL_HOST ) ).'</a>', $this->row_actions( $actions ) );
595
  }
596
 
597
- function column_cb($item){
598
  return sprintf(
599
  '<input type="checkbox" name="%1$s[]" value="%2$s" />',
600
  /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
601
- /*$2%s*/ $item->id //The value of the checkbox should be the record's id
602
  );
603
  }
604
 
605
- function get_columns(){
606
  $columns = array(
607
- 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
608
  'created' => __( 'Date', 'redirection' ),
609
- 'url' => __( 'Source URL', 'redirection' ),
610
  'referrer' => __( 'Referrer', 'redirection' ),
611
- 'ip' => __( 'IP', 'redirection' ),
612
  );
613
  return $columns;
614
  }
@@ -616,7 +617,7 @@ class Redirection_404_Table extends WP_List_Table {
616
  function get_sortable_columns() {
617
  $sortable_columns = array(
618
  'created' => array( 'id', true ),
619
- 'url' => array( 'url', false),
620
  'referrer' => array( 'referrer', false ),
621
  );
622
  return $sortable_columns;
@@ -624,14 +625,14 @@ class Redirection_404_Table extends WP_List_Table {
624
 
625
  function get_bulk_actions() {
626
  $actions = array(
627
- 'delete' => __( 'Delete', 'redirection' )
628
  );
629
  return $actions;
630
  }
631
 
632
  function process_bulk_action() {
633
  if ( 'delete' === $this->current_action() ) {
634
- foreach( $_POST['item'] AS $id ) {
635
  RE_404::delete( intval( $id ) );
636
  }
637
  }
@@ -655,10 +656,10 @@ class Redirection_404_Table extends WP_List_Table {
655
  $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
656
  $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
657
 
658
- if ( !in_array( $orderby, array_keys( $sortable ) ) )
659
  $orderby = 'id';
660
 
661
- if ( !in_array( $order, array( 'asc', 'desc' ) ) )
662
  $order = 'desc';
663
 
664
  $where = array();
@@ -668,23 +669,23 @@ class Redirection_404_Table extends WP_List_Table {
668
  if ( $restrict_by_ip !== false )
669
  $where[] = $wpdb->prepare( 'ip=INET_ATON(%s)', $restrict_by_ip );
670
 
671
- $where_cond = "";
672
  if ( count( $where ) > 0 )
673
- $where_cond = " WHERE ".implode( ' AND ', $where );
674
 
675
  $table = $wpdb->prefix.'redirection_404';
676
- $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
677
  $total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
678
 
679
  $this->items = array();
680
- foreach ( (array)$rows AS $row ) {
681
  $this->items[] = new RE_Log( $row );
682
  }
683
 
684
  $this->set_pagination_args( array(
685
  'total_items' => $total_items,
686
- 'per_page' => $per_page,
687
- 'total_pages' => ceil( $total_items / $per_page )
688
  ) );
689
  }
690
  }
@@ -697,9 +698,9 @@ class Redirection_Module_Table extends WP_List_Table {
697
 
698
  //Set parent defaults
699
  parent::__construct( array(
700
- 'singular' => 'item', //singular name of the listed records
701
- 'plural' => 'items', //plural name of the listed records
702
- 'ajax' => false //does this table support ajax?
703
  ) );
704
  }
705
 
@@ -723,7 +724,7 @@ class Redirection_Module_Table extends WP_List_Table {
723
 
724
  $actions['csv'] = sprintf( '<a href="%s">CSV</a>', '?page=redirection.php&amp;token='.$this->token.'&amp;sub=csv&amp;module='.intval( $item->get_id() ) );
725
  $actions['view-htaccess'] = sprintf( '<a href="#" class="red-ajax" data-id="%d" data-action="red_get_htaccess" data-nonce="%s">.htaccess</a>', $item->get_id(), wp_create_nonce( 'red_get_htaccess' ) );
726
- $actions['view-nginx'] = sprintf( '<a href="#" class="red-ajax" data-id="%d" data-action="red_get_nginx" data-nonce="%s">Nginx</a>', $item->get_id(), wp_create_nonce( 'red_get_nginx' ) );
727
 
728
  if ( count( $config ) > 0 )
729
  $config = '<div class="module-config">'.join( '<br/>', $config ).'</div>';
@@ -749,8 +750,8 @@ class Redirection_Module_Table extends WP_List_Table {
749
  $this->total_items = count( $this->items );
750
  $this->set_pagination_args( array(
751
  'total_items' => $this->total_items,
752
- 'per_page' => 100,
753
- 'total_pages' => ceil( $this->total_items / 100 )
754
  ) );
755
  }
756
  }
1
  <?php
2
 
3
+ if ( ! class_exists( 'WP_List_Table' ) ) {
4
+ require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
5
+ }
6
 
7
  class Redirection_Table extends WP_List_Table {
8
  private $groups;
16
 
17
  //Set parent defaults
18
  parent::__construct( array(
19
+ 'singular' => 'item', //singular name of the listed records
20
+ 'plural' => 'items', //plural name of the listed records
21
+ 'ajax' => false, //does this table support ajax?
22
  ) );
23
  }
24
 
25
+ function get_columns() {
26
  $columns = array(
27
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
28
+ 'type' => __( 'Type', 'redirection' ),
29
+ 'url' => __( 'URL', 'redirection' ),
30
+ 'hits' => __( 'Hits', 'redirection' ),
31
  'last_access' => __( 'Last Access', 'redirection' ),
32
  );
33
 
39
  }
40
 
41
  function column_last_access( $item ) {
42
+ if ( $item->get_last_hit() === 0 )
43
  return '&mdash;';
44
  return date_i18n( get_option( 'date_format' ), $item->get_last_hit() );
45
  }
50
 
51
  function column_url( $item ) {
52
  $actions = array(
53
+ 'edit' => sprintf( '<a class="red-ajax" data-action="%s" data-nonce="%s" data-id="%s" href="#">'.__( 'Edit', 'redirection' ).'</a>', 'red_redirect_edit', wp_create_nonce( 'red-edit_'.$item->get_id() ), $item->get_id() ),
54
  'delete' => sprintf( '<a class="red-auto" data-action="%s" href="#">'.__( 'Delete', 'redirection' ).'</a>', 'delete', $item->get_id() ),
55
  );
56
 
70
  return sprintf( '%1$s %2$s', $before.'<a href="'.esc_url( $item->get_url() ).'">'.esc_html( $title ).'</a>'.$after, $this->row_actions( $actions ) );
71
  }
72
 
73
+ function column_cb( $item ) {
74
  return sprintf(
75
  '<input type="checkbox" name="%1$s[]" value="%2$s" />',
76
  /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
77
+ /*$2%s*/ $item->get_id() //The value of the checkbox should be the record's id
78
  );
79
  }
80
 
91
 
92
  function get_sortable_columns() {
93
  $sortable_columns = array(
94
+ 'url' => array( 'url', false ),
95
  );
96
  return $sortable_columns;
97
  }
108
  }
109
 
110
  function process_bulk_action() {
111
+ if ( ! isset( $_POST['item'] ) )
112
  return;
113
 
114
  if ( in_array( $this->current_action(), array( 'reset', 'enable', 'disable', 'delete' ) ) ) {
115
  $redirections = array();
116
  $flush = array();
117
 
118
+ foreach( (array) $_POST['item'] as $id ) {
119
  $redirect = Red_Item::get_by_id( intval( $id ) );
120
 
121
  if ( $redirect ) {
135
  }
136
 
137
  $flush = array_unique( $flush );
138
+ foreach ( $flush as $group_id ) {
139
  Red_Module::flush( $group_id );
140
  }
141
  }
142
  }
143
 
144
  function extra_tablenav( $which ) {
145
+ if ( $which === 'bottom' )
146
  return;
147
 
148
  ?>
150
  <select name="id">
151
  <option value="0"<?php selected( 0, $this->current_group_id ); ?>><?php _e( 'No group filter', 'redirection' ); ?></option>
152
 
153
+ <?php foreach ( $this->groups as $module_name => $groups ) : ?>
154
  <optgroup label="<?php echo esc_attr( $module_name ); ?>">
155
+ <?php foreach ( $groups as $group_id => $group ) : ?>
156
  <option value="<?php echo esc_attr( $group_id ); ?>"<?php selected( $group_id, $this->current_group_id ); ?>>
157
  <?php echo esc_html( $group ); ?>
158
  </option>
189
  $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
190
  $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
191
 
192
+ if ( ! in_array( $orderby, array_keys( $sortable ) ) )
193
  $orderby = 'id';
194
 
195
+ if ( ! in_array( $order, array( 'asc', 'desc' ) ) )
196
  $order = 'desc';
197
 
198
  $where = array();
200
  $where[] = $wpdb->prepare( 'url LIKE %s', '%'.$wpdb->esc_like( $_GET['s'] ).'%' );
201
 
202
  if ( isset( $_REQUEST['id'] ) && intval( $_REQUEST['id'] ) > 0 )
203
+ $where[] = $wpdb->prepare( 'group_id=%d', intval( $_REQUEST['id'] ) );
204
 
205
+ $where_cond = '';
206
  if ( count( $where ) > 0 )
207
+ $where_cond = ' WHERE '.implode( ' AND ', $where );
208
 
209
  $table = $wpdb->prefix.'redirection_items';
210
+ $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
211
  $this->total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
212
 
213
  $this->items = array();
214
+ foreach ( (array) $rows as $row ) {
215
  $this->items[] = new Red_Item( $row );
216
  }
217
 
218
  $this->set_pagination_args( array(
219
  'total_items' => $this->total_items,
220
+ 'per_page' => $per_page,
221
+ 'total_pages' => ceil( $this->total_items / $per_page ),
222
  ) );
223
  }
224
  }
231
 
232
  //Set parent defaults
233
  parent::__construct( array(
234
+ 'singular' => 'item', //singular name of the listed records
235
+ 'plural' => 'items', //plural name of the listed records
236
+ 'ajax' => false, //does this table support ajax?
237
  ) );
238
  }
239
 
240
+ function get_columns() {
241
  $columns = array(
242
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
243
+ 'name' => __( 'Name', 'redirection' ),
244
  'redirects' => __( 'Redirects', 'redirection' ),
245
+ 'module' => __( 'Module', 'redirection' ),
246
  );
247
 
248
  return $columns;
279
  return esc_html( __( 'Unknown', 'redirection' ) );
280
  }
281
 
282
+ function column_cb( $item ) {
283
  return sprintf(
284
  '<input type="checkbox" name="%1$s[]" value="%2$s" />',
285
  /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
286
+ /*$2%s*/ $item->id //The value of the checkbox should be the record's id
287
  );
288
  }
289
 
306
  }
307
 
308
  function process_bulk_action() {
309
+ if ( ! isset( $_POST['item'] ) )
310
  return;
311
 
312
  if ( in_array( $this->current_action(), array( 'delete', 'enable', 'disable' ) ) ) {
313
  $groups = array();
314
 
315
+ foreach( (array) $_POST['item'] as $id ) {
316
  $group = Red_Group::get( intval( $id ) );
317
 
318
  if ( $group ) {
344
  }
345
 
346
  function extra_tablenav( $which ) {
347
+ if ( $which === 'bottom' )
348
  return;
349
 
350
  $selected = 0;
354
  <div class="alignleft actions">
355
  <select name="id">
356
  <option value="0"<?php selected( 0, $selected ); ?>><?php _e( 'All modules', 'redirection' ); ?></option>
357
+ <?php foreach ( $this->modules as $module_id => $module ) : ?>
358
  <option value="<?php echo esc_attr( $module_id ); ?>"<?php selected( $module_id, $selected ); ?>>
359
  <?php echo esc_html( $module->get_name() ); ?>
360
  </option>
384
  $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
385
  $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
386
 
387
+ if ( ! in_array( $orderby, array_keys( $sortable ) ) )
388
  $orderby = $wpdb->prefix.'redirection_groups.name';
389
 
390
+ if ( ! in_array( $order, array( 'asc', 'desc' ) ) )
391
  $order = 'desc';
392
 
393
  $where = array();
395
  $where[] = $wpdb->prepare( 'name LIKE %s', '%'.$wpdb->esc_like( $_GET['s'] ).'%' );
396
 
397
  if ( isset( $_REQUEST['id'] ) && intval( $_REQUEST['id'] ) > 0 )
398
+ $where[] = $wpdb->prepare( 'module_id=%d', intval( $_REQUEST['id'] ) );
399
 
400
+ $where_cond = '';
401
  if ( count( $where ) > 0 )
402
+ $where_cond = ' WHERE '.implode( ' AND ', $where );
403
 
404
  $table = $wpdb->prefix.'redirection_groups';
405
  $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
406
  $this->total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
407
 
408
  $this->items = array();
409
+ foreach ( (array) $rows as $row ) {
410
  $this->items[] = new Red_Group( $row );
411
  }
412
 
413
  $this->set_pagination_args( array(
414
  'total_items' => $this->total_items,
415
+ 'per_page' => $per_page,
416
+ 'total_pages' => ceil( $this->total_items / $per_page ),
417
  ) );
418
  }
419
  }
428
 
429
  //Set parent defaults
430
  parent::__construct( array(
431
+ 'singular' => 'item', //singular name of the listed records
432
+ 'plural' => 'items', //plural name of the listed records
433
+ 'ajax' => false, //does this table support ajax?
434
  ) );
435
  }
436
 
437
  function column_created( $item ) {
438
  $actions = array();
439
 
440
+ if ( $item->sent_to === '' ) {
441
  $actions['add'] = '<a href="'.esc_url( $item->url ).'" class="add-log">'.__( 'Add redirect', 'redirection' ).'</a>';
442
  }
443
 
464
  return sprintf( '%1$s %2$s', '<a href="'.esc_url( $item->referrer ).'">'.esc_html( parse_url( $item->referrer, PHP_URL_HOST ) ).'</a>', $this->row_actions( $actions ) );
465
  }
466
 
467
+ function column_cb( $item ) {
468
  return sprintf(
469
  '<input type="checkbox" name="%1$s[]" value="%2$s" />',
470
  /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
471
+ /*$2%s*/ $item->id //The value of the checkbox should be the record's id
472
  );
473
  }
474
 
475
+ function get_columns() {
476
  $columns = array(
477
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
478
+ 'created' => __( 'Date', 'redirection' ),
479
+ 'url' => __( 'Source URL', 'redirection' ),
480
  'referrer' => __( 'Referrer', 'redirection' ),
481
+ 'ip' => __( 'IP', 'redirection' ),
482
  );
483
  return $columns;
484
  }
485
 
486
  function get_sortable_columns() {
487
  $sortable_columns = array(
488
+ 'created' => array( 'id', true ),
489
+ 'url' => array( 'url', false ),
490
  'referrer' => array( 'referrer', false ),
491
+ 'ip' => array( 'item_id', false ),
492
  );
493
  return $sortable_columns;
494
  }
495
 
496
  function get_bulk_actions() {
497
  $actions = array(
498
+ 'delete' => __( 'Delete', 'redirection' ),
499
  );
500
  return $actions;
501
  }
502
 
503
  function process_bulk_action() {
504
  if ( 'delete' === $this->current_action() ) {
505
+ foreach( $_POST['item'] as $id ) {
506
  RE_Log::delete( intval( $id ) );
507
  }
508
  }
526
  $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
527
  $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
528
 
529
+ if ( ! in_array( $orderby, array_keys( $sortable ) ) )
530
  $orderby = 'id';
531
 
532
+ if ( ! in_array( $order, array( 'asc', 'desc' ) ) )
533
  $order = 'desc';
534
 
535
  $where = array();
536
  if ( isset( $_GET['s'] ) && strlen( $_GET['s'] ) > 0 )
537
  $where[] = $wpdb->prepare( 'url LIKE %s', '%'.$wpdb->esc_like( $_GET['s'] ).'%' );
538
 
539
+ $where_cond = '';
540
  if ( count( $where ) > 0 )
541
+ $where_cond = ' WHERE '.implode( ' AND ', $where );
542
 
543
  $table = $wpdb->prefix.'redirection_logs';
544
+ $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
545
  $total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
546
 
547
  $this->items = array();
548
+ foreach ( (array) $rows as $row ) {
549
  $this->items[] = new RE_Log( $row );
550
  }
551
 
552
  $this->set_pagination_args( array(
553
  'total_items' => $total_items,
554
+ 'per_page' => $per_page,
555
+ 'total_pages' => ceil( $total_items / $per_page ),
556
  ) );
557
  }
558
  }
565
 
566
  //Set parent defaults
567
  parent::__construct( array(
568
+ 'singular' => 'item', //singular name of the listed records
569
+ 'plural' => 'items', //plural name of the listed records
570
+ 'ajax' => false, //does this table support ajax?
571
  ) );
572
  }
573
 
595
  return sprintf( '%1$s %2$s', '<a href="'.esc_url( $item->referrer ).'">'.esc_html( parse_url( $item->referrer, PHP_URL_HOST ) ).'</a>', $this->row_actions( $actions ) );
596
  }
597
 
598
+ function column_cb( $item ) {
599
  return sprintf(
600
  '<input type="checkbox" name="%1$s[]" value="%2$s" />',
601
  /*$1%s*/ $this->_args['singular'], //Let's simply repurpose the table's singular label ("movie")
602
+ /*$2%s*/ $item->id //The value of the checkbox should be the record's id
603
  );
604
  }
605
 
606
+ function get_columns() {
607
  $columns = array(
608
+ 'cb' => '<input type="checkbox" />', //Render a checkbox instead of text
609
  'created' => __( 'Date', 'redirection' ),
610
+ 'url' => __( 'Source URL', 'redirection' ),
611
  'referrer' => __( 'Referrer', 'redirection' ),
612
+ 'ip' => __( 'IP', 'redirection' ),
613
  );
614
  return $columns;
615
  }
617
  function get_sortable_columns() {
618
  $sortable_columns = array(
619
  'created' => array( 'id', true ),
620
+ 'url' => array( 'url', false ),
621
  'referrer' => array( 'referrer', false ),
622
  );
623
  return $sortable_columns;
625
 
626
  function get_bulk_actions() {
627
  $actions = array(
628
+ 'delete' => __( 'Delete', 'redirection' ),
629
  );
630
  return $actions;
631
  }
632
 
633
  function process_bulk_action() {
634
  if ( 'delete' === $this->current_action() ) {
635
+ foreach( $_POST['item'] as $id ) {
636
  RE_404::delete( intval( $id ) );
637
  }
638
  }
656
  $orderby = ( ! empty( $_GET['orderby'] ) ) ? $_GET['orderby'] : 'id';
657
  $order = ( ! empty( $_GET['order'] ) ) ? strtolower( $_GET['order'] ) : 'desc';
658
 
659
+ if ( ! in_array( $orderby, array_keys( $sortable ) ) )
660
  $orderby = 'id';
661
 
662
+ if ( ! in_array( $order, array( 'asc', 'desc' ) ) )
663
  $order = 'desc';
664
 
665
  $where = array();
669
  if ( $restrict_by_ip !== false )
670
  $where[] = $wpdb->prepare( 'ip=INET_ATON(%s)', $restrict_by_ip );
671
 
672
+ $where_cond = '';
673
  if ( count( $where ) > 0 )
674
+ $where_cond = ' WHERE '.implode( ' AND ', $where );
675
 
676
  $table = $wpdb->prefix.'redirection_404';
677
+ $rows = $wpdb->get_results( "SELECT * FROM {$table} ".$where_cond.$wpdb->prepare( " ORDER BY $orderby $order LIMIT %d,%d", ( $this->get_pagenum() - 1 ) * $per_page, $per_page ) );
678
  $total_items = $wpdb->get_var( "SELECT COUNT(*) FROM {$table}".$where_cond );
679
 
680
  $this->items = array();
681
+ foreach ( (array) $rows as $row ) {
682
  $this->items[] = new RE_Log( $row );
683
  }
684
 
685
  $this->set_pagination_args( array(
686
  'total_items' => $total_items,
687
+ 'per_page' => $per_page,
688
+ 'total_pages' => ceil( $total_items / $per_page ),
689
  ) );
690
  }
691
  }
698
 
699
  //Set parent defaults
700
  parent::__construct( array(
701
+ 'singular' => 'item', //singular name of the listed records
702
+ 'plural' => 'items', //plural name of the listed records
703
+ 'ajax' => false, //does this table support ajax?
704
  ) );
705
  }
706
 
724
 
725
  $actions['csv'] = sprintf( '<a href="%s">CSV</a>', '?page=redirection.php&amp;token='.$this->token.'&amp;sub=csv&amp;module='.intval( $item->get_id() ) );
726
  $actions['view-htaccess'] = sprintf( '<a href="#" class="red-ajax" data-id="%d" data-action="red_get_htaccess" data-nonce="%s">.htaccess</a>', $item->get_id(), wp_create_nonce( 'red_get_htaccess' ) );
727
+ $actions['view-nginx'] = sprintf( '<a href="#" class="red-ajax" data-id="%d" data-action="red_get_nginx" data-nonce="%s">Nginx</a>', $item->get_id(), wp_create_nonce( 'red_get_nginx' ) );
728
 
729
  if ( count( $config ) > 0 )
730
  $config = '<div class="module-config">'.join( '<br/>', $config ).'</div>';
750
  $this->total_items = count( $this->items );
751
  $this->set_pagination_args( array(
752
  'total_items' => $this->total_items,
753
+ 'per_page' => 100,
754
+ 'total_pages' => ceil( $this->total_items / 100 ),
755
  ) );
756
  }
757
  }
models/redirect.php CHANGED
@@ -18,7 +18,7 @@ class Red_Item {
18
  private $position;
19
  private $group_id;
20
 
21
- function __construct( $values, $type = '', $match = '' ) {
22
  if ( is_object( $values ) ) {
23
  foreach ( $values as $key => $value ) {
24
  $this->$key = $value;
@@ -28,6 +28,7 @@ class Red_Item {
28
  $this->match_type = 'url';
29
  }
30
 
 
31
  $this->match = Red_Match::create( $this->match_type, $this->action_data );
32
  $this->match->id = $this->id;
33
  $this->match->action_code = $this->action_code;
@@ -45,7 +46,7 @@ class Red_Item {
45
  else
46
  $this->action = Red_Action::create( 'nothing', 0 );
47
 
48
- if ( $this->last_access == '0000-00-00 00:00:00' )
49
  $this->last_access = 0;
50
  else
51
  $this->last_access = mysql2date( 'U', $this->last_access );
@@ -60,13 +61,12 @@ class Red_Item {
60
  static function get_all_for_module( $module ) {
61
  global $wpdb;
62
 
63
- $sql = $wpdb->prepare( "SELECT @redirection_items.*,@redirection_groups.tracking FROM @redirection_items INNER JOIN @redirection_groups ON @redirection_groups.id=@redirection_items.group_id AND @redirection_groups.status='enabled' AND @redirection_groups.module_id=%d WHERE @redirection_items.status='enabled' ORDER BY @redirection_groups.position,@redirection_items.position", $module );
64
- $sql = str_replace( '@', $wpdb->prefix, $sql );
65
 
66
  $rows = $wpdb->get_results( $sql );
67
  $items = array();
68
- if ( count( $rows) > 0 ) {
69
- foreach ( $rows AS $row ) {
70
  $items[] = new Red_Item( $row );
71
  }
72
  }
@@ -74,16 +74,15 @@ class Red_Item {
74
  return $items;
75
  }
76
 
77
- static function get_for_url( $url, $type ) {
78
  global $wpdb;
79
 
80
- $sql = $wpdb->prepare( "SELECT @redirection_items.*,@redirection_groups.position AS group_pos FROM @redirection_items INNER JOIN @redirection_groups ON @redirection_groups.id=@redirection_items.group_id AND @redirection_groups.status='enabled' AND @redirection_groups.module_id=%d WHERE (@redirection_items.regex=1 OR @redirection_items.url=%s)", WordPress_Module::MODULE_ID, $url );
81
- $sql = str_replace( '@', $wpdb->prefix, $sql);
82
 
83
- $rows = $wpdb->get_results( $sql ) ;
84
  $items = array();
85
  if ( count( $rows ) > 0 ) {
86
- foreach ( $rows AS $row ) {
87
  $items[] = array( 'position' => ( $row->group_pos * 1000 ) + $row->position, 'item' => new Red_Item( $row ) );
88
  }
89
  }
@@ -117,7 +116,7 @@ class Red_Item {
117
  $rows = $wpdb->get_results( $sql );
118
  $items = array();
119
 
120
- foreach( (array)$rows AS $row ) {
121
  $items[] = new Red_Item( $row );
122
  }
123
 
@@ -139,7 +138,7 @@ class Red_Item {
139
 
140
  $url = $options['auto_target'];
141
  $url = str_replace( '$dec$', $id, $url );
142
- $url = str_replace( '$hex$', sprintf( '%x', $id), $url );
143
  return $url;
144
  }
145
 
@@ -157,7 +156,7 @@ class Red_Item {
157
  $details['target'] = self::auto_generate();
158
 
159
  // Make sure we don't redirect to ourself
160
- if ( $details['source'] == $details['target'] )
161
  return new WP_Error( 'redirect-add', __( 'Source and target URL must be different', 'redirection' ) );
162
 
163
  $parsed_url = parse_url( $details['source'] );
@@ -171,27 +170,27 @@ class Red_Item {
171
  $group_id = intval( $details['group_id'] );
172
  $group = Red_Group::get( $group_id );
173
 
174
- if ( $group_id <= 0 || !$group )
175
  return new WP_Error( 'redirect-add', __( 'Invalid group when creating redirect', 'redirection' ) );
176
 
177
- if ( !$matcher )
178
  return new WP_Error( 'redirect-add', __( 'Invalid source URL when creating redirect for given match type', 'redirection' ) );
179
 
180
- $regex = ( isset( $details['regex']) && $details['regex'] != false) ? 1 : 0;
181
  $position = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_items WHERE group_id=%d", $group_id ) );
182
 
183
  $action = $details['red_action'];
184
  $action_code = 0;
185
- if ( $action == 'url' || $action == 'random' )
186
  $action_code = 301;
187
- elseif ( $action == 'error' )
188
  $action_code = 404;
189
 
190
  if ( isset( $details['action_code'] ) )
191
  $action_code = intval( $details['action_code'] );
192
 
193
  $data = array(
194
- 'url' => self::sanitize_url( $details['source'], $regex),
195
  'action_type' => $details['red_action'],
196
  'regex' => $regex,
197
  'position' => $position,
@@ -199,7 +198,7 @@ class Red_Item {
199
  'action_data' => $matcher->data( $details ),
200
  'action_code' => $action_code,
201
  'last_access' => '0000-00-00 00:00:00',
202
- 'group_id' => $group_id
203
  );
204
 
205
  $data = apply_filters( 'redirection_create_redirect', $data );
@@ -223,8 +222,8 @@ class Red_Item {
223
 
224
  // Reorder all elements
225
  $rows = $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}redirection_items ORDER BY position" );
226
- if ( count( $rows) > 0 ) {
227
- foreach ( $rows AS $pos => $row ) {
228
  $wpdb->update( $wpdb->prefix.'redirection_items', array( 'position' => $pos ), array( 'id' => $row->id ) );
229
  }
230
  }
@@ -232,13 +231,24 @@ class Red_Item {
232
  Red_Module::flush( $this->group_id );
233
  }
234
 
235
- static function sanitize_url( $url, $regex ) {
236
  // Make sure that the old URL is relative
237
  $url = preg_replace( '@^https?://(.*?)/@', '/', $url );
238
  $url = preg_replace( '@^https?://(.*?)$@', '/', $url );
239
 
240
- if ( substr( $url, 0, 1) != '/' && $regex == false )
 
 
 
 
 
 
 
 
 
 
241
  $url = '/'.$url;
 
242
  return $url;
243
  }
244
 
@@ -277,7 +287,7 @@ class Red_Item {
277
  static function save_order( $items, $start ) {
278
  global $wpdb;
279
 
280
- foreach ( $items AS $pos => $id ) {
281
  $wpdb->update( $wpdb->prefix.'redirection_items', array( 'position' => $pos + $start ), array( 'id' => $id ) );
282
  }
283
 
@@ -289,12 +299,12 @@ class Red_Item {
289
  $matches = false;
290
 
291
  // Check if we match the URL
292
- if ( ( $this->regex == false && ( $this->url == $url || $this->url == rtrim( $url, '/' ) || $this->url == urldecode( $url ) ) ) ||( $this->regex == true && @preg_match( '@'.str_replace( '@', '\\@', $this->url).'@', $url, $matches) > 0) ||( $this->regex == true && @preg_match( '@'.str_replace( '@', '\\@', $this->url).'@', urldecode( $url ), $matches) > 0) ) {
293
  // Check if our match wants this URL
294
  $target = $this->match->get_target( $url, $this->url, $this->regex );
295
 
296
  if ( $target ) {
297
- $target = $this->replaceSpecialTags( $target );
298
 
299
  $this->visit( $url, $target );
300
 
@@ -306,12 +316,12 @@ class Red_Item {
306
  return false;
307
  }
308
 
309
- function replaceSpecialTags( $target ) {
310
  if ( is_numeric( $target ) )
311
  $target = get_permalink( $target );
312
  else {
313
  $user = wp_get_current_user();
314
- if ( !empty( $user ) ) {
315
  $target = str_replace( '%userid%', $user->ID, $target );
316
  $target = str_replace( '%userlogin%', isset( $user->user_login ) ? $user->user_login : '', $target );
317
  $target = str_replace( '%userurl%', isset( $user->user_url ) ? $user->user_url : '', $target );
@@ -336,7 +346,7 @@ class Red_Item {
336
 
337
  $options = red_get_options();
338
  if ( isset( $options['expire_redirect'] ) && $options['expire_redirect'] >= 0 )
339
- $log = RE_Log::create( $url, $target, $_SERVER['HTTP_USER_AGENT'], $ip, isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '', array( 'redirect_id' => $this->id, 'group_id' => $this->group_id) );
340
  }
341
  }
342
 
@@ -389,7 +399,7 @@ class Red_Item {
389
  );
390
 
391
  if ( $action )
392
- return $actions[$action];
393
  return $actions;
394
  }
395
 
@@ -397,10 +407,10 @@ class Red_Item {
397
  return $this->match->match_name();
398
  }
399
 
400
- function type() {
401
- if ( ( $this->action_type == 'url' || $this->action_type == 'error' || $this->action_type == 'random' ) && $this->action_code > 0 )
402
  return $this->action_code;
403
- else if ( $this->action_type == 'pass' )
404
  return 'pass';
405
  return '&mdash;';
406
  }
18
  private $position;
19
  private $group_id;
20
 
21
+ function __construct( $values, $type = '', $match = '' ) {
22
  if ( is_object( $values ) ) {
23
  foreach ( $values as $key => $value ) {
24
  $this->$key = $value;
28
  $this->match_type = 'url';
29
  }
30
 
31
+ $this->regex = (bool)$this->regex;
32
  $this->match = Red_Match::create( $this->match_type, $this->action_data );
33
  $this->match->id = $this->id;
34
  $this->match->action_code = $this->action_code;
46
  else
47
  $this->action = Red_Action::create( 'nothing', 0 );
48
 
49
+ if ( $this->last_access === '0000-00-00 00:00:00' )
50
  $this->last_access = 0;
51
  else
52
  $this->last_access = mysql2date( 'U', $this->last_access );
61
  static function get_all_for_module( $module ) {
62
  global $wpdb;
63
 
64
+ $sql = $wpdb->prepare( "SELECT {$wpdb->prefix}redirection_items.*,{$wpdb->prefix}redirection_groups.tracking FROM {$wpdb->prefix}redirection_items INNER JOIN {$wpdb->prefix}redirection_groups ON {$wpdb->prefix}redirection_groups.id={$wpdb->prefix}redirection_items.group_id AND {$wpdb->prefix}redirection_groups.status='enabled' AND {$wpdb->prefix}redirection_groups.module_id=%d WHERE {$wpdb->prefix}redirection_items.status='enabled' ORDER BY {$wpdb->prefix}redirection_groups.position,{$wpdb->prefix}redirection_items.position", $module );
 
65
 
66
  $rows = $wpdb->get_results( $sql );
67
  $items = array();
68
+ if ( count( $rows ) > 0 ) {
69
+ foreach ( $rows as $row ) {
70
  $items[] = new Red_Item( $row );
71
  }
72
  }
74
  return $items;
75
  }
76
 
77
+ static function get_for_url( $url, $type ) {
78
  global $wpdb;
79
 
80
+ $sql = $wpdb->prepare( "SELECT {$wpdb->prefix}redirection_items.*,{$wpdb->prefix}redirection_groups.position AS group_pos FROM {$wpdb->prefix}redirection_items INNER JOIN {$wpdb->prefix}redirection_groups ON {$wpdb->prefix}redirection_groups.id={$wpdb->prefix}redirection_items.group_id AND {$wpdb->prefix}redirection_groups.status='enabled' AND {$wpdb->prefix}redirection_groups.module_id=%d WHERE ({$wpdb->prefix}redirection_items.regex=1 OR {$wpdb->prefix}redirection_items.url=%s)", WordPress_Module::MODULE_ID, $url );
 
81
 
82
+ $rows = $wpdb->get_results( $sql );
83
  $items = array();
84
  if ( count( $rows ) > 0 ) {
85
+ foreach ( $rows as $row ) {
86
  $items[] = array( 'position' => ( $row->group_pos * 1000 ) + $row->position, 'item' => new Red_Item( $row ) );
87
  }
88
  }
116
  $rows = $wpdb->get_results( $sql );
117
  $items = array();
118
 
119
+ foreach ( (array) $rows as $row ) {
120
  $items[] = new Red_Item( $row );
121
  }
122
 
138
 
139
  $url = $options['auto_target'];
140
  $url = str_replace( '$dec$', $id, $url );
141
+ $url = str_replace( '$hex$', sprintf( '%x', $id ), $url );
142
  return $url;
143
  }
144
 
156
  $details['target'] = self::auto_generate();
157
 
158
  // Make sure we don't redirect to ourself
159
+ if ( $details['source'] === $details['target'] )
160
  return new WP_Error( 'redirect-add', __( 'Source and target URL must be different', 'redirection' ) );
161
 
162
  $parsed_url = parse_url( $details['source'] );
170
  $group_id = intval( $details['group_id'] );
171
  $group = Red_Group::get( $group_id );
172
 
173
+ if ( $group_id <= 0 || ! $group )
174
  return new WP_Error( 'redirect-add', __( 'Invalid group when creating redirect', 'redirection' ) );
175
 
176
+ if ( ! $matcher )
177
  return new WP_Error( 'redirect-add', __( 'Invalid source URL when creating redirect for given match type', 'redirection' ) );
178
 
179
+ $regex = ( isset( $details['regex'] ) && $details['regex'] !== false ) ? 1 : 0;
180
  $position = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_items WHERE group_id=%d", $group_id ) );
181
 
182
  $action = $details['red_action'];
183
  $action_code = 0;
184
+ if ( $action === 'url' || $action === 'random' )
185
  $action_code = 301;
186
+ elseif ( $action === 'error' )
187
  $action_code = 404;
188
 
189
  if ( isset( $details['action_code'] ) )
190
  $action_code = intval( $details['action_code'] );
191
 
192
  $data = array(
193
+ 'url' => self::sanitize_url( $details['source'], $regex ),
194
  'action_type' => $details['red_action'],
195
  'regex' => $regex,
196
  'position' => $position,
198
  'action_data' => $matcher->data( $details ),
199
  'action_code' => $action_code,
200
  'last_access' => '0000-00-00 00:00:00',
201
+ 'group_id' => $group_id,
202
  );
203
 
204
  $data = apply_filters( 'redirection_create_redirect', $data );
222
 
223
  // Reorder all elements
224
  $rows = $wpdb->get_results( "SELECT id FROM {$wpdb->prefix}redirection_items ORDER BY position" );
225
+ if ( count( $rows ) > 0 ) {
226
+ foreach ( $rows as $pos => $row ) {
227
  $wpdb->update( $wpdb->prefix.'redirection_items', array( 'position' => $pos ), array( 'id' => $row->id ) );
228
  }
229
  }
231
  Red_Module::flush( $this->group_id );
232
  }
233
 
234
+ static function sanitize_url( $url, $regex = false ) {
235
  // Make sure that the old URL is relative
236
  $url = preg_replace( '@^https?://(.*?)/@', '/', $url );
237
  $url = preg_replace( '@^https?://(.*?)$@', '/', $url );
238
 
239
+ // No hash
240
+ $url = preg_replace( '/#.*$/', '', $url );
241
+
242
+ // No new lines
243
+ $url = preg_replace( "/[\r\n\t].*?$/s", '', $url );
244
+
245
+ // Clean control codes
246
+ $url = preg_replace( '/[^\PC\s]/u', '', $url );
247
+
248
+ // Ensure a slash at start
249
+ if ( substr( $url, 0, 1 ) !== '/' && $regex === false )
250
  $url = '/'.$url;
251
+
252
  return $url;
253
  }
254
 
287
  static function save_order( $items, $start ) {
288
  global $wpdb;
289
 
290
+ foreach ( $items as $pos => $id ) {
291
  $wpdb->update( $wpdb->prefix.'redirection_items', array( 'position' => $pos + $start ), array( 'id' => $id ) );
292
  }
293
 
299
  $matches = false;
300
 
301
  // Check if we match the URL
302
+ if ( ( $this->regex === false && ( $this->url === $url || $this->url === rtrim( $url, '/' ) || $this->url === urldecode( $url ) ) ) || ( $this->regex === true && @preg_match( '@'.str_replace( '@', '\\@', $this->url ).'@', $url, $matches ) > 0) || ( $this->regex === true && @preg_match( '@'.str_replace( '@', '\\@', $this->url ).'@', urldecode( $url ), $matches ) > 0) ) {
303
  // Check if our match wants this URL
304
  $target = $this->match->get_target( $url, $this->url, $this->regex );
305
 
306
  if ( $target ) {
307
+ $target = $this->replace_special_tags( $target );
308
 
309
  $this->visit( $url, $target );
310
 
316
  return false;
317
  }
318
 
319
+ function replace_special_tags( $target ) {
320
  if ( is_numeric( $target ) )
321
  $target = get_permalink( $target );
322
  else {
323
  $user = wp_get_current_user();
324
+ if ( ! empty( $user ) ) {
325
  $target = str_replace( '%userid%', $user->ID, $target );
326
  $target = str_replace( '%userlogin%', isset( $user->user_login ) ? $user->user_login : '', $target );
327
  $target = str_replace( '%userurl%', isset( $user->user_url ) ? $user->user_url : '', $target );
346
 
347
  $options = red_get_options();
348
  if ( isset( $options['expire_redirect'] ) && $options['expire_redirect'] >= 0 )
349
+ $log = RE_Log::create( $url, $target, $_SERVER['HTTP_USER_AGENT'], $ip, isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : '', array( 'redirect_id' => $this->id, 'group_id' => $this->group_id ) );
350
  }
351
  }
352
 
399
  );
400
 
401
  if ( $action )
402
+ return $actions[ $action ];
403
  return $actions;
404
  }
405
 
407
  return $this->match->match_name();
408
  }
409
 
410
+ function type() {
411
+ if ( ( $this->action_type === 'url' || $this->action_type === 'error' || $this->action_type === 'random' ) && $this->action_code > 0 )
412
  return $this->action_code;
413
+ else if ( $this->action_type === 'pass' )
414
  return 'pass';
415
  return '&mdash;';
416
  }
modules/apache.php CHANGED
@@ -17,9 +17,9 @@ class Apache_Module extends Red_Module {
17
  protected function load( $data ) {
18
  $mine = array( 'location', 'canonical' );
19
 
20
- foreach ( $mine AS $key ) {
21
- if ( isset( $data[$key] ) )
22
- $this->$key = $data[$key];
23
  }
24
  }
25
 
@@ -34,7 +34,7 @@ class Apache_Module extends Red_Module {
34
  // Produce the .htaccess file
35
  $htaccess = new Red_Htaccess();
36
  if ( is_array( $items ) && count( $items ) > 0 ) {
37
- foreach ( $items AS $item ) {
38
  if ( $item->is_enabled() )
39
  $htaccess->add( $item );
40
  }
@@ -51,7 +51,7 @@ class Apache_Module extends Red_Module {
51
  'canonical' => isset( $data['canonical'] ) ? $data['canonical'] : false,
52
  );
53
 
54
- if ( !empty( $this->location ) && $save['location'] !== $this->location ) {
55
  // Location has moved. Remove from old location
56
  $htaccess = new Red_Htaccess();
57
  $htaccess->save( $this->location, '' );
@@ -63,7 +63,7 @@ class Apache_Module extends Red_Module {
63
  return __( 'Cannot write to chosen location - check path and permissions.', 'redirection' );
64
 
65
  $options = red_get_options();
66
- $options['modules'][self::MODULE_ID] = $save;
67
 
68
  update_option( 'redirection_options', $options );
69
  return true;
@@ -98,7 +98,7 @@ class Apache_Module extends Red_Module {
98
  }
99
 
100
  public function get_config() {
101
- if ( !empty( $this->location ) )
102
  return array( sprintf( __( '<code>.htaccess</code> saved to %s', 'redirection' ), esc_html( $this->location ) ) );
103
 
104
  return array();
17
  protected function load( $data ) {
18
  $mine = array( 'location', 'canonical' );
19
 
20
+ foreach ( $mine as $key ) {
21
+ if ( isset( $data[ $key ] ) )
22
+ $this->$key = $data[ $key ];
23
  }
24
  }
25
 
34
  // Produce the .htaccess file
35
  $htaccess = new Red_Htaccess();
36
  if ( is_array( $items ) && count( $items ) > 0 ) {
37
+ foreach ( $items as $item ) {
38
  if ( $item->is_enabled() )
39
  $htaccess->add( $item );
40
  }
51
  'canonical' => isset( $data['canonical'] ) ? $data['canonical'] : false,
52
  );
53
 
54
+ if ( ! empty( $this->location ) && $save['location'] !== $this->location ) {
55
  // Location has moved. Remove from old location
56
  $htaccess = new Red_Htaccess();
57
  $htaccess->save( $this->location, '' );
63
  return __( 'Cannot write to chosen location - check path and permissions.', 'redirection' );
64
 
65
  $options = red_get_options();
66
+ $options['modules'][ self::MODULE_ID ] = $save;
67
 
68
  update_option( 'redirection_options', $options );
69
  return true;
98
  }
99
 
100
  public function get_config() {
101
+ if ( ! empty( $this->location ) )
102
  return array( sprintf( __( '<code>.htaccess</code> saved to %s', 'redirection' ), esc_html( $this->location ) ) );
103
 
104
  return array();
modules/nginx.php CHANGED
@@ -17,9 +17,9 @@ class Nginx_Module extends Red_Module {
17
  protected function load( $data ) {
18
  $mine = array( 'location', 'canonical' );
19
 
20
- foreach ( $mine AS $key ) {
21
- if ( isset( $data[$key] ) )
22
- $this->$key = $data[$key];
23
  }
24
  }
25
 
17
  protected function load( $data ) {
18
  $mine = array( 'location', 'canonical' );
19
 
20
+ foreach ( $mine as $key ) {
21
+ if ( isset( $data[ $key ] ) )
22
+ $this->$key = $data[ $key ];
23
  }
24
  }
25
 
modules/wordpress.php CHANGED
@@ -37,12 +37,12 @@ class WordPress_Module extends Red_Module {
37
  $url = $_SERVER['REQUEST_URI'];
38
 
39
  // Make sure we don't try and redirect something essential
40
- if ( !$this->protected_url( $url ) && $this->matched === false ) {
41
  do_action( 'redirection_first', $url, $this );
42
 
43
  $redirects = Red_Item::get_for_url( $url, 'wp' );
44
 
45
- foreach ( (array)$redirects AS $item ) {
46
  if ( $item->matches( $url ) ) {
47
  $this->matched = $item;
48
  break;
@@ -69,13 +69,13 @@ class WordPress_Module extends Red_Module {
69
 
70
  public function status_header( $status ) {
71
  // Fix for incorrect headers sent when using FastCGI/IIS
72
- if ( substr( php_sapi_name(), 0, 3 ) == 'cgi' )
73
  return str_replace( 'HTTP/1.1', 'Status:', $status );
74
  return $status;
75
  }
76
 
77
  public function send_headers( $obj ) {
78
- if ( !empty( $this->matched ) && $this->matched->match->action_code == '410' ) {
79
  add_filter( 'status_header', array( &$this, 'set_header_410' ) );
80
  }
81
  }
@@ -87,22 +87,23 @@ class WordPress_Module extends Red_Module {
87
  public function wp_redirect( $url, $status ) {
88
  global $wp_version, $is_IIS;
89
 
90
- if ( $is_IIS ) {
91
  header( "Refresh: 0;url=$url" );
92
  return $url;
93
  }
94
- elseif ( $status == 301 && php_sapi_name() == 'cgi-fcgi' ) {
95
- $servers_to_check = array( 'lighttpd', 'nginx' );
96
- foreach ( $servers_to_check as $name ) {
97
- if ( stripos( $_SERVER['SERVER_SOFTWARE'], $name ) !== false ) {
98
- status_header( $status );
99
- header( "Location: $url" );
100
- exit( 0 );
101
- }
102
- }
103
- }
104
-
105
- status_header( $status );
 
106
  return $url;
107
  }
108
 
37
  $url = $_SERVER['REQUEST_URI'];
38
 
39
  // Make sure we don't try and redirect something essential
40
+ if ( ! $this->protected_url( $url ) && $this->matched === false ) {
41
  do_action( 'redirection_first', $url, $this );
42
 
43
  $redirects = Red_Item::get_for_url( $url, 'wp' );
44
 
45
+ foreach ( (array) $redirects as $item ) {
46
  if ( $item->matches( $url ) ) {
47
  $this->matched = $item;
48
  break;
69
 
70
  public function status_header( $status ) {
71
  // Fix for incorrect headers sent when using FastCGI/IIS
72
+ if ( substr( php_sapi_name(), 0, 3 ) === 'cgi' )
73
  return str_replace( 'HTTP/1.1', 'Status:', $status );
74
  return $status;
75
  }
76
 
77
  public function send_headers( $obj ) {
78
+ if ( ! empty( $this->matched ) && $this->matched->match->action_code === '410' ) {
79
  add_filter( 'status_header', array( &$this, 'set_header_410' ) );
80
  }
81
  }
87
  public function wp_redirect( $url, $status ) {
88
  global $wp_version, $is_IIS;
89
 
90
+ if ( $is_IIS ) {
91
  header( "Refresh: 0;url=$url" );
92
  return $url;
93
  }
94
+ elseif ( $status === 301 && php_sapi_name() === 'cgi-fcgi' ) {
95
+ $servers_to_check = array( 'lighttpd', 'nginx' );
96
+
97
+ foreach ( $servers_to_check as $name ) {
98
+ if ( stripos( $_SERVER['SERVER_SOFTWARE'], $name ) !== false ) {
99
+ status_header( $status );
100
+ header( "Location: $url" );
101
+ exit( 0 );
102
+ }
103
+ }
104
+ }
105
+
106
+ status_header( $status );
107
  return $url;
108
  }
109
 
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: johnny5
3
  Donate link: http://urbangiraffe.com/about/
4
  Tags: post, admin, seo, pages, manage, 301, 404, redirect, permalink
5
  Requires at least: 4.1
6
- Tested up to: 4.4
7
- Stable tag: 2.4.4
8
 
9
  Redirection is a WordPress plugin to manage 301 redirections and keep track of 404 errors without requiring knowledge of Apache .htaccess files.
10
 
@@ -97,6 +97,12 @@ The plugin works in a similar manner to how WordPress handles permalinks and sho
97
 
98
  == Changelog ==
99
 
 
 
 
 
 
 
100
  = 2.4.4 =
101
  * Fix large advanced settings icon
102
  * Add text domain to plugin file, props Bernhard Kau
@@ -159,7 +165,7 @@ The plugin works in a similar manner to how WordPress handles permalinks and sho
159
  * Fix unnecessary protected
160
 
161
  = 2.3.10 =
162
- * Another compatability fix for PHP < 5.3
163
  * Fix incorrect module ID used when creating a group
164
  * Fix .htaccess duplication, props to Jörg Liwa
165
 
@@ -200,11 +206,11 @@ The plugin works in a similar manner to how WordPress handles permalinks and sho
200
  * Fix pagination
201
 
202
  = 2.3.2 =
203
- * WP 3.5 compat
204
  * Fix export
205
 
206
  = 2.3.0 =
207
- * Remove 404 module and move 404 logs into a seperate option
208
  * Add Danish translation, thanks to Rasmus Himmelstrup
209
 
210
  = 2.2.14 =
@@ -235,7 +241,7 @@ The plugin works in a similar manner to how WordPress handles permalinks and sho
235
  * Add Greek, thanks to Stefanos Kofopoulos
236
 
237
  = 2.2.7 =
238
- * Better database compat
239
 
240
  = 2.2.6 =
241
  * Remove warning from VaultPress
3
  Donate link: http://urbangiraffe.com/about/
4
  Tags: post, admin, seo, pages, manage, 301, 404, redirect, permalink
5
  Requires at least: 4.1
6
+ Tested up to: 4.6
7
+ Stable tag: 2.4.5
8
 
9
  Redirection is a WordPress plugin to manage 301 redirections and keep track of 404 errors without requiring knowledge of Apache .htaccess files.
10
 
97
 
98
  == Changelog ==
99
 
100
+ = 2.4.5 =
101
+ * Ensure cleanup code runs even if plugin was updated
102
+ * Extra sanitization of Apache & Nginx files, props to Ed Shirey
103
+ * Fix regex bug, props to romulodl
104
+ * Fix bug in correct group not being shown in dropdown
105
+
106
  = 2.4.4 =
107
  * Fix large advanced settings icon
108
  * Add text domain to plugin file, props Bernhard Kau
165
  * Fix unnecessary protected
166
 
167
  = 2.3.10 =
168
+ * Another compatibility fix for PHP < 5.3
169
  * Fix incorrect module ID used when creating a group
170
  * Fix .htaccess duplication, props to Jörg Liwa
171
 
206
  * Fix pagination
207
 
208
  = 2.3.2 =
209
+ * WP 3.5 compatibility
210
  * Fix export
211
 
212
  = 2.3.0 =
213
+ * Remove 404 module and move 404 logs into a separate option
214
  * Add Danish translation, thanks to Rasmus Himmelstrup
215
 
216
  = 2.2.14 =
241
  * Add Greek, thanks to Stefanos Kofopoulos
242
 
243
  = 2.2.7 =
244
+ * Better database compatibility
245
 
246
  = 2.2.6 =
247
  * Remove warning from VaultPress
redirection-admin.php CHANGED
@@ -97,6 +97,8 @@ class Redirection_Admin {
97
  private static function update() {
98
  $version = get_option( 'redirection_version' );
99
 
 
 
100
  if ( $version !== REDIRECTION_VERSION ) {
101
  include_once dirname( REDIRECTION_FILE ).'/models/database.php';
102
 
97
  private static function update() {
98
  $version = get_option( 'redirection_version' );
99
 
100
+ Red_Flusher::schedule();
101
+
102
  if ( $version !== REDIRECTION_VERSION ) {
103
  include_once dirname( REDIRECTION_FILE ).'/models/database.php';
104
 
redirection.php CHANGED
@@ -3,10 +3,11 @@
3
  Plugin Name: Redirection
4
  Plugin URI: http://urbangiraffe.com/plugins/redirection/
5
  Description: Manage all your 301 redirects and monitor 404 errors
6
- Version: 2.4.4
7
  Author: John Godley
8
  Author URI: http://urbangiraffe.com
9
  Text Domain: redirection
 
10
  ============================================================================================================
11
  This software is provided "as is" and any express or implied warranties, including, but not limited to, the
12
  implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall
@@ -42,12 +43,12 @@ function red_get_options() {
42
  'auto_target' => '',
43
  'expire_redirect' => 7,
44
  'expire_404' => 7,
45
- 'modules' => array()
46
  ) );
47
 
48
- foreach ( $defaults AS $key => $value ) {
49
- if ( !isset( $options[$key] ) )
50
- $options[$key] = $value;
51
  }
52
 
53
  $options['lookup'] = apply_filters( 'red_lookup_ip', 'http://urbangiraffe.com/map/?ip=' );
3
  Plugin Name: Redirection
4
  Plugin URI: http://urbangiraffe.com/plugins/redirection/
5
  Description: Manage all your 301 redirects and monitor 404 errors
6
+ Version: 2.4.5
7
  Author: John Godley
8
  Author URI: http://urbangiraffe.com
9
  Text Domain: redirection
10
+ Domain Path: /locale
11
  ============================================================================================================
12
  This software is provided "as is" and any express or implied warranties, including, but not limited to, the
13
  implied warranties of merchantibility and fitness for a particular purpose are disclaimed. In no event shall
43
  'auto_target' => '',
44
  'expire_redirect' => 7,
45
  'expire_404' => 7,
46
+ 'modules' => array(),
47
  ) );
48
 
49
+ foreach ( $defaults as $key => $value ) {
50
+ if ( ! isset( $options[ $key ] ) )
51
+ $options[ $key ] = $value;
52
  }
53
 
54
  $options['lookup'] = apply_filters( 'red_lookup_ip', 'http://urbangiraffe.com/map/?ip=' );
view/add.php CHANGED
@@ -36,7 +36,7 @@
36
  <th><?php _e( 'Group', 'redirection' ); ?>:</th>
37
  <td>
38
  <select name="group_id">
39
- <?php echo $this->select( Red_Group::get_for_select(), $group )?>
40
  </select>
41
  </td>
42
  </tr>
36
  <th><?php _e( 'Group', 'redirection' ); ?>:</th>
37
  <td>
38
  <select name="group_id">
39
+ <?php echo $this->select( Red_Group::get_for_select(), ( isset( $group ) ? intval( $group ) : '' ) )?>
40
  </select>
41
  </td>
42
  </tr>
view/item-edit.php CHANGED
@@ -18,7 +18,7 @@
18
  <th width="100"><?php _e( 'Group', 'redirection' ); ?>:</th>
19
  <td>
20
  <select name="group_id">
21
- <?php echo $this->select( Red_Group::get_for_select(), $redirect->get_group_id() );?>
22
  </select>
23
  </td>
24
  </tr>
18
  <th width="100"><?php _e( 'Group', 'redirection' ); ?>:</th>
19
  <td>
20
  <select name="group_id">
21
+ <?php echo $this->select( Red_Group::get_for_select(), intval( $redirect->get_group_id() ) );?>
22
  </select>
23
  </td>
24
  </tr>
view/options.php CHANGED
@@ -34,7 +34,7 @@ $expiry = array(
34
  <th align="right"><?php _e( 'Redirect Logs', 'redirection' ); ?>:</th>
35
  <td>
36
  <select name="expire_redirect">
37
- <?php echo $this->select( $expiry, $options['expire_redirect'] ); ?>
38
  </select>
39
 
40
  <?php _e( '(time to keep logs for)', 'redirection' ); ?>
@@ -44,7 +44,7 @@ $expiry = array(
44
  <th align="right"><?php _e( '404 Logs', 'redirection' ); ?>:</th>
45
  <td>
46
  <select name="expire_404">
47
- <?php echo $this->select( $expiry, $options['expire_404'] ); ?>
48
  </select>
49
 
50
  <?php _e( '(time to keep logs for)', 'redirection' ); ?>
@@ -55,7 +55,7 @@ $expiry = array(
55
  <td>
56
  <select name="monitor_post">
57
  <option value="0"><?php _e( 'Don\'t monitor', 'redirection' ); ?></option>
58
- <?php echo $this->select( $groups, $options['monitor_post'] );?>
59
  </select>
60
  </td>
61
  </tr>
34
  <th align="right"><?php _e( 'Redirect Logs', 'redirection' ); ?>:</th>
35
  <td>
36
  <select name="expire_redirect">
37
+ <?php echo $this->select( $expiry, intval( $options['expire_redirect'] ) ); ?>
38
  </select>
39
 
40
  <?php _e( '(time to keep logs for)', 'redirection' ); ?>
44
  <th align="right"><?php _e( '404 Logs', 'redirection' ); ?>:</th>
45
  <td>
46
  <select name="expire_404">
47
+ <?php echo $this->select( $expiry, intval( $options['expire_404'] ) ); ?>
48
  </select>
49
 
50
  <?php _e( '(time to keep logs for)', 'redirection' ); ?>
55
  <td>
56
  <select name="monitor_post">
57
  <option value="0"><?php _e( 'Don\'t monitor', 'redirection' ); ?></option>
58
+ <?php echo $this->select( $groups, intval( $options['monitor_post'] ) );?>
59
  </select>
60
  </td>
61
  </tr>