Redirection - Version 2.6

Version Description

  • Show example CSV
  • Allow regex and redirect code to be set on import
  • Fix a bunch of database installation problems
Download this release

Release Info

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

Code changes from version 2.5 to 2.6

admin.css CHANGED
@@ -162,3 +162,12 @@ table.items table.edit th {
162
  margin-top: 15px;
163
  width: 100%;
164
  }
 
 
 
 
 
 
 
 
 
162
  margin-top: 15px;
163
  width: 100%;
164
  }
165
+
166
+ ul.translators {
167
+ list-style-type: disc;
168
+ margin-left: 30px;
169
+ }
170
+
171
+ ul.translators li {
172
+ line-height: 1em;
173
+ }
fileio/apache.php CHANGED
@@ -26,7 +26,7 @@ class Red_Apache_File extends Red_FileIO {
26
  return $htaccess->get();
27
  }
28
 
29
- function load( $group, $data, $filename = '' ) {
30
  // Remove any comments
31
  $data = preg_replace( '@#(.*)@', '', $data );
32
  $data = str_replace( "\n", "\r", $data );
@@ -80,9 +80,9 @@ class Red_Apache_File extends Red_FileIO {
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';
26
  return $htaccess->get();
27
  }
28
 
29
+ public function load( $group, $filename, $data ) {
30
  // Remove any comments
31
  $data = preg_replace( '@#(.*)@', '', $data );
32
  $data = str_replace( "\n", "\r", $data );
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';
fileio/csv.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
 
3
  class Red_Csv_File extends Red_FileIO {
4
- function export( array $items ) {
5
  $filename = 'redirection-'.date_i18n( get_option( 'date_format' ) ).'.csv';
6
 
7
  header( 'Content-Type: text/csv' );
@@ -14,42 +14,40 @@ class Red_Csv_File extends Red_FileIO {
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(),
20
- $line->is_regex(),
21
- $line->get_action_type(),
22
- $line->get_action_code(),
23
- $line->get_action_type(),
24
- $line->get_hits(),
25
- $line->get_title(),
26
- );
27
-
28
- $csv = array_map( array( $this, 'escape_csv' ), $csv );
29
- fwrite( $stdout, join( $csv, ',') );
30
  }
31
  }
32
 
33
- private function escape_csv( $item ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  return '"'.str_replace( '"', '""', $item ).'"';
35
  }
36
 
37
- function load( $group, $data, $filename = '' ) {
38
  $count = 0;
39
  $file = fopen( $filename, 'r' );
40
 
41
  if ( $file ) {
42
  while ( ( $csv = fgetcsv( $file, 1000, ',' ) ) ) {
43
- if ( $csv[0] !== 'source' && $csv[1] !== 'target' ) {
44
- Red_Item::create( array(
45
- 'source' => trim( $csv[0] ),
46
- 'target' => trim( $csv[1] ),
47
- 'regex' => $this->is_regex( $csv[0] ),
48
- 'group_id' => $group,
49
- 'match' => 'url',
50
- 'red_action' => 'url',
51
- ) );
52
 
 
 
53
  $count++;
54
  }
55
  }
@@ -58,11 +56,32 @@ class Red_Csv_File extends Red_FileIO {
58
  return $count;
59
  }
60
 
61
- function is_regex( $url ) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  $regex = '()[]$^*';
63
 
64
- if ( strpbrk( $url, $regex ) === false )
65
  return false;
 
66
 
67
  return true;
68
  }
1
  <?php
2
 
3
  class Red_Csv_File extends Red_FileIO {
4
+ public function export( array $items ) {
5
  $filename = 'redirection-'.date_i18n( get_option( 'date_format' ) ).'.csv';
6
 
7
  header( 'Content-Type: text/csv' );
14
  fputcsv( $stdout, array( 'source', 'target', 'regex', 'type', 'code', 'match', 'hits', 'title' ) );
15
 
16
  foreach ( $items as $line ) {
17
+ fwrite( $stdout, $this->item_as_csv( $line ) );
 
 
 
 
 
 
 
 
 
 
 
 
18
  }
19
  }
20
 
21
+ public function item_as_csv( $item ) {
22
+ $csv = array(
23
+ $item->get_url(),
24
+ $item->get_action_data(),
25
+ $item->is_regex() ? 1 : 0,
26
+ $item->get_action_type(),
27
+ $item->get_action_code(),
28
+ $item->get_action_type(),
29
+ $item->get_hits(),
30
+ $item->get_title(),
31
+ );
32
+
33
+ $csv = array_map( array( $this, 'escape_csv' ), $csv );
34
+ return join( $csv, ',' );
35
+ }
36
+
37
+ public function escape_csv( $item ) {
38
  return '"'.str_replace( '"', '""', $item ).'"';
39
  }
40
 
41
+ public function load( $group, $filename, $data ) {
42
  $count = 0;
43
  $file = fopen( $filename, 'r' );
44
 
45
  if ( $file ) {
46
  while ( ( $csv = fgetcsv( $file, 1000, ',' ) ) ) {
47
+ $item = $this->csv_as_item( $csv, $group );
 
 
 
 
 
 
 
 
48
 
49
+ if ( $item ) {
50
+ Red_Item::create( $item );
51
  $count++;
52
  }
53
  }
56
  return $count;
57
  }
58
 
59
+ public function csv_as_item( $csv, $group ) {
60
+ if ( $csv[0] !== 'source' && $csv[1] !== 'target' && count( $csv ) > 1 ) {
61
+ return array(
62
+ 'source' => trim( $csv[0] ),
63
+ 'target' => trim( $csv[1] ),
64
+ 'regex' => isset( $csv[2] ) ? $this->parse_regex( $csv[2] ) : $this->is_regex( $csv[0] ),
65
+ 'group_id' => $group,
66
+ 'match' => 'url',
67
+ 'red_action' => 'url',
68
+ 'action_code' => isset( $csv[3] ) ? intval( $csv[3], 10 ) : 301,
69
+ );
70
+ }
71
+
72
+ return false;
73
+ }
74
+
75
+ private function parse_regex( $value ) {
76
+ return intval( $value, 10 ) === 1 ? true : false;
77
+ }
78
+
79
+ private function is_regex( $url ) {
80
  $regex = '()[]$^*';
81
 
82
+ if ( strpbrk( $url, $regex ) === false ) {
83
  return false;
84
+ }
85
 
86
  return true;
87
  }
models/database.php CHANGED
@@ -1,236 +1,254 @@
1
  <?php
2
 
3
  class RE_Database {
4
- private function get_charset() {
5
  global $wpdb;
6
 
7
  $charset_collate = '';
8
- if ( ! empty( $wpdb->charset ) )
9
  $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
 
10
 
11
- if ( ! empty( $wpdb->collate ) )
12
- $charset_collate .= " COLLATE $wpdb->collate";
 
13
 
14
  return $charset_collate;
15
  }
16
 
17
- public function install() {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
  global $wpdb;
19
 
20
  $charset_collate = $this->get_charset();
21
 
22
- $create = array(
23
- "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}redirection_items`(
24
- `id` int(11) unsigned NOT NULL auto_increment,
25
- `url` mediumtext NOT NULL,
26
- `regex` int(11) unsigned NOT NULL default '0',
27
- `position` int(11) unsigned NOT NULL default '0',
28
- `last_count` int(10) unsigned NOT NULL default '0',
29
- `last_access` datetime NOT NULL,
30
- `group_id` int(11) NOT NULL default '0',
31
- `status` enum('enabled','disabled' ) NOT NULL default 'enabled',
32
- `action_type` varchar(20) NOT NULL,
33
- `action_code` int(11) unsigned NOT NULL,
34
- `action_data` mediumtext,
35
- `match_type` varchar(20) NOT NULL,
36
- `title` varchar(50) NULL,
37
- PRIMARY KEY ( `id`),
38
- KEY `url` (`url`(200)),
39
- KEY `status` (`status`),
40
- KEY `regex` (`regex`),
41
- KEY `group_idpos` (`group_id`,`position`),
42
- KEY `group` (`group_id`)
43
- ) $charset_collate",
44
-
45
- "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}redirection_groups`(
46
- `id` int(11) NOT NULL auto_increment,
47
- `name` varchar(50) NOT NULL,
48
- `tracking` int(11) NOT NULL default '1',
49
- `module_id` int(11) unsigned NOT NULL default '0',
50
- `status` enum('enabled','disabled' ) NOT NULL default 'enabled',
51
- `position` int(11) unsigned NOT NULL default '0',
52
- PRIMARY KEY ( `id`),
53
- KEY `module_id` (`module_id`),
54
- KEY `status` (`status`)
55
- ) $charset_collate",
56
-
57
- "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}redirection_logs`(
58
- `id` int(11) unsigned NOT NULL auto_increment,
59
- `created` datetime NOT NULL,
60
- `url` mediumtext NOT NULL,
61
- `sent_to` mediumtext,
62
- `agent` mediumtext NOT NULL,
63
- `referrer` mediumtext,
64
- `redirection_id` int(11) unsigned default NULL,
65
- `ip` varchar(17) NOT NULL default '',
66
- `module_id` int(11) unsigned NOT NULL,
67
- `group_id` int(11) unsigned default NULL,
68
- PRIMARY KEY ( `id`),
69
- KEY `created` (`created`),
70
- KEY `redirection_id` (`redirection_id`),
71
- KEY `ip` (`ip`),
72
- KEY `group_id` (`group_id`),
73
- KEY `module_id` (`module_id`)
74
- ) $charset_collate",
75
-
76
- "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}redirection_404` (
77
- `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
78
- `created` datetime NOT NULL,
79
- `url` varchar(255) NOT NULL DEFAULT '',
80
- `agent` varchar(255) DEFAULT NULL,
81
- `referrer` varchar(255) DEFAULT NULL,
82
- `ip` int(10) unsigned NOT NULL,
83
- PRIMARY KEY (`id`),
84
- KEY `created` (`created`),
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 ( intval( $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_groups", 10 ) ) === 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
 
101
- $options = get_option( 'redirection_options' );
102
- $options['monitor_post'] = 2;
103
- $options['monitor_category'] = 2;
104
 
105
- update_option( 'redirection_options', $options );
 
 
 
106
  }
107
  }
108
 
109
- public function upgrade( $current, $target ) {
110
  global $wpdb;
111
 
112
  $wpdb->show_errors();
113
 
114
- // No previous version? Install the DB tables
115
- if ( $current === false )
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;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139
  }
140
 
141
- // Set our current version
142
- update_option( 'redirection_version', $target );
143
-
144
  $wpdb->hide_errors();
145
- return $success;
146
  }
147
 
148
- private function upgrade_to_231() {
 
 
 
 
 
149
  global $wpdb;
150
 
151
- $charset_collate = $this->get_charset();
152
-
153
- $wpdb->query( "DELETE FROM {$wpdb->prefix}redirection_modules WHERE type='404'" );
154
- $wpdb->query( "UPDATE {$wpdb->prefix}redirection_groups SET module_id=1 WHERE module_id=3" );
155
-
156
- $wpdb->query( "CREATE TABLE IF NOT EXISTS `{$wpdb->prefix}redirection_404` (
157
- `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
158
- `created` datetime NOT NULL,
159
- `url` varchar(255) NOT NULL DEFAULT '',
160
- `agent` varchar(255) DEFAULT NULL,
161
- `referrer` varchar(255) DEFAULT NULL,
162
- `ip` int(10) unsigned NOT NULL,
163
- PRIMARY KEY (`id`),
164
- KEY `created` (`created`),
165
- KEY `url` (`url`),
166
- KEY `ip` (`ip`,`id`),
167
- KEY `referrer` (`referrer`)
168
- ) $charset_collate;" );
169
  }
170
 
 
 
 
 
171
  private function upgrade_to_232() {
172
  global $wpdb;
173
 
174
  $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_modules;" );
175
  }
176
 
177
- private function upgrade_from_20() {
178
- global $wpdb;
179
-
180
- $this->upgrade_from_21();
181
- $this->upgrade_from_22();
182
- }
183
-
184
- private function upgrade_from_21() {
185
  global $wpdb;
186
 
187
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD `title` varchar(50) NULL" );
188
-
189
- $this->upgrade_from_22();
190
  }
191
 
192
- private function upgrade_from_22() {
 
 
 
 
193
  global $wpdb;
194
 
195
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` CHANGE `title` `title` varchar(50) NULL" );
 
 
 
 
 
 
196
  }
197
 
 
 
 
 
 
198
  private function upgrade_to_216() {
199
  global $wpdb;
200
 
201
  $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_groups` ADD INDEX(module_id)" );
202
  $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_groups` ADD INDEX(status)" );
203
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX(url(200))" );
204
  $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX(status)" );
205
  $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX(regex)" );
206
  }
207
 
208
- private function upgrade_to_220() {
 
 
 
209
  global $wpdb;
210
 
211
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX `group_idpos` (`group_id`,`position`)" );
212
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX `group` (`group_id`)" );
213
-
214
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `group` (`group_id`)" );
215
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `redirection_id` (`redirection_id`)" );
216
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `created` (`created`)" );
217
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `ip` (`ip`)" );
218
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `group_id` (`group_id`)" );
219
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `module_id` (`module_id`)" );
220
-
221
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_modules` ADD INDEX `name` (`name`)" );
222
- $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_modules` ADD INDEX `type` (`type`)" );
223
  }
224
 
225
- public function remove( $plugin ) {
226
  global $wpdb;
227
 
228
- $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection;" );
229
- $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_items;" );
230
- $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_logs;" );
231
- $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_groups;" );
232
- $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_modules;" );
233
- $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_404;" );
234
 
235
  delete_option( 'redirection_lookup' );
236
  delete_option( 'redirection_post' );
1
  <?php
2
 
3
  class RE_Database {
4
+ public function get_charset() {
5
  global $wpdb;
6
 
7
  $charset_collate = '';
8
+ if ( ! empty( $wpdb->charset ) ) {
9
  $charset_collate = "DEFAULT CHARACTER SET $wpdb->charset";
10
+ }
11
 
12
+ if ( ! empty( $wpdb->collate ) ) {
13
+ $charset_collate .= " COLLATE=$wpdb->collate";
14
+ }
15
 
16
  return $charset_collate;
17
  }
18
 
19
+ private function create_items_sql( $prefix, $charset_collate ) {
20
+ return "CREATE TABLE IF NOT EXISTS `{$prefix}redirection_items` (
21
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
22
+ `url` mediumtext NOT NULL,
23
+ `regex` int(11) unsigned NOT NULL DEFAULT '0',
24
+ `position` int(11) unsigned NOT NULL DEFAULT '0',
25
+ `last_count` int(10) unsigned NOT NULL DEFAULT '0',
26
+ `last_access` datetime NOT NULL,
27
+ `group_id` int(11) NOT NULL DEFAULT '0',
28
+ `status` enum('enabled','disabled') NOT NULL DEFAULT 'enabled',
29
+ `action_type` varchar(20) NOT NULL,
30
+ `action_code` int(11) unsigned NOT NULL,
31
+ `action_data` mediumtext,
32
+ `match_type` varchar(20) NOT NULL,
33
+ `title` varchar(50) DEFAULT NULL,
34
+ PRIMARY KEY (`id`),
35
+ KEY `url` (`url`(191)),
36
+ KEY `status` (`status`),
37
+ KEY `regex` (`regex`),
38
+ KEY `group_idpos` (`group_id`,`position`),
39
+ KEY `group` (`group_id`)
40
+ ) $charset_collate";
41
+ }
42
+
43
+ private function create_groups_sql( $prefix, $charset_collate ) {
44
+ return "CREATE TABLE IF NOT EXISTS `{$prefix}redirection_groups` (
45
+ `id` int(11) NOT NULL AUTO_INCREMENT,
46
+ `name` varchar(50) NOT NULL,
47
+ `tracking` int(11) NOT NULL DEFAULT '1',
48
+ `module_id` int(11) unsigned NOT NULL DEFAULT '0',
49
+ `status` enum('enabled','disabled') NOT NULL DEFAULT 'enabled',
50
+ `position` int(11) unsigned NOT NULL DEFAULT '0',
51
+ PRIMARY KEY (`id`),
52
+ KEY `module_id` (`module_id`),
53
+ KEY `status` (`status`)
54
+ ) $charset_collate";
55
+ }
56
+
57
+ private function create_log_sql( $prefix, $charset_collate ) {
58
+ return "CREATE TABLE IF NOT EXISTS `{$prefix}redirection_logs` (
59
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
60
+ `created` datetime NOT NULL,
61
+ `url` mediumtext NOT NULL,
62
+ `sent_to` mediumtext,
63
+ `agent` mediumtext NOT NULL,
64
+ `referrer` mediumtext,
65
+ `redirection_id` int(11) unsigned DEFAULT NULL,
66
+ `ip` varchar(17) NOT NULL DEFAULT '',
67
+ `module_id` int(11) unsigned NOT NULL,
68
+ `group_id` int(11) unsigned DEFAULT NULL,
69
+ PRIMARY KEY (`id`),
70
+ KEY `created` (`created`),
71
+ KEY `redirection_id` (`redirection_id`),
72
+ KEY `ip` (`ip`),
73
+ KEY `group_id` (`group_id`),
74
+ KEY `module_id` (`module_id`)
75
+ ) $charset_collate";
76
+ }
77
+
78
+ private function create_404_sql( $prefix, $charset_collate ) {
79
+ return "CREATE TABLE IF NOT EXISTS `{$prefix}redirection_404` (
80
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
81
+ `created` datetime NOT NULL,
82
+ `url` varchar(255) NOT NULL DEFAULT '',
83
+ `agent` varchar(255) DEFAULT NULL,
84
+ `referrer` varchar(255) DEFAULT NULL,
85
+ `ip` int(10) unsigned NOT NULL,
86
+ PRIMARY KEY (`id`),
87
+ KEY `created` (`created`),
88
+ KEY `url` (`url`(191)),
89
+ KEY `ip` (`ip`),
90
+ KEY `referrer` (`referrer`(191))
91
+ ) $charset_collate";
92
+ }
93
+
94
+ public function get_all_tables() {
95
  global $wpdb;
96
 
97
  $charset_collate = $this->get_charset();
98
 
99
+ return array(
100
+ "{$wpdb->prefix}redirection_items" => $this->create_items_sql( $wpdb->prefix, $charset_collate ),
101
+ "{$wpdb->prefix}redirection_groups" => $this->create_groups_sql( $wpdb->prefix, $charset_collate ),
102
+ "{$wpdb->prefix}redirection_logs" => $this->create_log_sql( $wpdb->prefix, $charset_collate ),
103
+ "{$wpdb->prefix}redirection_404" => $this->create_404_sql( $wpdb->prefix, $charset_collate ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  );
105
+ }
106
 
107
+ public function createDefaults() {
108
+ $this->createDefaultGroups();
 
 
109
 
110
+ update_option( 'redirection_version', REDIRECTION_VERSION );
111
+ }
112
+
113
+ private function createDefaultGroups() {
114
+ global $wpdb;
115
 
116
+ $existing_groups = $wpdb->get_var( "SELECT COUNT(*) FROM {$wpdb->prefix}redirection_groups" );
 
 
117
 
118
+ // Default groups
119
+ if ( intval( $existing_groups, 10 ) === 0 ) {
120
+ $wpdb->insert( $wpdb->prefix.'redirection_groups', array( 'name' => __( 'Redirections' ), 'module_id' => 1, 'position' => 0 ) );
121
+ $wpdb->insert( $wpdb->prefix.'redirection_groups', array( 'name' => __( 'Modified Posts' ), 'module_id' => 1, 'position' => 1 ) );
122
  }
123
  }
124
 
125
+ public function install() {
126
  global $wpdb;
127
 
128
  $wpdb->show_errors();
129
 
130
+ foreach ( $this->get_all_tables() as $sql ) {
131
+ if ( $wpdb->query( $sql ) === false ) {
132
+ throw new Exception( 'There was a database error installing Redirection - please post these details to https://github.com/johngodley/redirection/issues' );
133
+ return false;
134
+ }
135
+ }
 
 
 
 
 
136
 
137
+ $this->createDefaults();
138
+ $wpdb->hide_errors();
139
 
140
+ return true;
141
+ }
142
 
143
+ public function upgrade( $current, $target ) {
144
+ global $wpdb;
145
 
146
+ $wpdb->show_errors();
 
147
 
148
+ if ( $current !== false ) {
149
+ $versions = array(
150
+ '2.0.1' => 'upgrade_to_201',
151
+ '2.1.16' => 'upgrade_to_216',
152
+ '2.2' => 'upgrade_to_220',
153
+ '2.3.1' => 'upgrade_to_231',
154
+ '2.3.2' => 'upgrade_to_232',
155
+ '2.3.3' => 'upgrade_to_233',
156
+ );
157
+
158
+ foreach ( $versions AS $vers => $upgrade ) {
159
+ if ( version_compare( $current, $vers ) === -1 ) {
160
+ $this->$upgrade();
161
+ }
162
+ }
163
+
164
+ update_option( 'redirection_version', $target );
165
  }
166
 
 
 
 
167
  $wpdb->hide_errors();
 
168
  }
169
 
170
+ /**
171
+ * 2.32 => 2.3.3
172
+ * Migrate any groups with incorrect module_ids
173
+ * Create a group if none exists
174
+ */
175
+ private function upgrade_to_233() {
176
  global $wpdb;
177
 
178
+ $wpdb->query( "UPDATE {$wpdb->prefix}redirection_groups SET module_id=1 WHERE module_id > 2" );
179
+ $this->createDefaultGroups();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
  }
181
 
182
+ /**
183
+ * 2.3.1 => 2.3.2
184
+ * Delete the redirection_modules table
185
+ */
186
  private function upgrade_to_232() {
187
  global $wpdb;
188
 
189
  $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_modules;" );
190
  }
191
 
192
+ /**
193
+ * 2.2 => 2.3.1
194
+ * Update any group referring to 404 module to WordPress module
195
+ * Create 404 log table
196
+ */
197
+ private function upgrade_to_231() {
 
 
198
  global $wpdb;
199
 
200
+ $wpdb->query( "UPDATE {$wpdb->prefix}redirection_groups SET module_id=1 WHERE module_id=3" );
201
+ $wpdb->query( $this->create_404_sql( $wpdb->prefix, $this->get_charset() ) );
 
202
  }
203
 
204
+ /**
205
+ * 2.1.6 => 2.2.0
206
+ * Add indices to redirection items and logs
207
+ */
208
+ private function upgrade_to_220() {
209
  global $wpdb;
210
 
211
+ $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX `group_idpos` (`group_id`,`position`)" );
212
+ $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX `group` (`group_id`)" );
213
+ $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `created` (`created`)" );
214
+ $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `redirection_id` (`redirection_id`)" );
215
+ $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `ip` (`ip`)" );
216
+ $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `group_id` (`group_id`)" );
217
+ $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_logs` ADD INDEX `module_id` (`module_id`)" );
218
  }
219
 
220
+ /**
221
+ * 2.0.1 => 2.1.6
222
+ * Update any group referring to 404 module to WordPress module
223
+ * Create 404 log table
224
+ */
225
  private function upgrade_to_216() {
226
  global $wpdb;
227
 
228
  $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_groups` ADD INDEX(module_id)" );
229
  $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_groups` ADD INDEX(status)" );
230
+ $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX(url(191))" );
231
  $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX(status)" );
232
  $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD INDEX(regex)" );
233
  }
234
 
235
+ /**
236
+ * <2.0.1 => 2.0.1
237
+ */
238
+ private function upgrade_to_201() {
239
  global $wpdb;
240
 
241
+ $wpdb->query( "ALTER TABLE `{$wpdb->prefix}redirection_items` ADD `title` varchar(50) NULL" );
 
 
 
 
 
 
 
 
 
 
 
242
  }
243
 
244
+ public function remove() {
245
  global $wpdb;
246
 
247
+ $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_items" );
248
+ $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_logs" );
249
+ $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_groups" );
250
+ $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_modules" );
251
+ $wpdb->query( "DROP TABLE IF EXISTS {$wpdb->prefix}redirection_404" );
 
252
 
253
  delete_option( 'redirection_lookup' );
254
  delete_option( 'redirection_post' );
models/file-io.php CHANGED
@@ -34,19 +34,18 @@ abstract class Red_FileIO {
34
  include dirname( dirname( __FILE__ ) ).'/fileio/csv.php';
35
  $importer = new Red_Csv_File();
36
  $data = '';
37
- }
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'] );
45
  }
46
 
47
  return 0;
48
  }
49
 
50
  abstract function export( array $items );
51
- abstract function load( $group, $data, $filename = '' );
52
  }
34
  include dirname( dirname( __FILE__ ) ).'/fileio/csv.php';
35
  $importer = new Red_Csv_File();
36
  $data = '';
37
+ } else {
 
38
  include dirname( dirname( __FILE__ ) ).'/fileio/apache.php';
39
  $importer = new Red_Apache_File();
40
  $data = @file_get_contents( $file['tmp_name'] );
41
  }
42
 
43
+ return $importer->load( $group, $file['tmp_name'], $data );
44
  }
45
 
46
  return 0;
47
  }
48
 
49
  abstract function export( array $items );
50
+ abstract function load( $group, $filename, $data );
51
  }
models/htaccess.php CHANGED
@@ -5,13 +5,23 @@ class Red_Htaccess {
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
 
11
  private function encode2nd( $url ) {
12
  $url = urlencode( $url );
13
  $url = str_replace( '%2F', '/', $url );
 
14
  $url = str_replace( '%3A', ':', $url );
 
 
 
15
  $url = str_replace( '+', '%20', $url );
16
  $url = str_replace( '%24', '$', $url );
17
  return $url;
@@ -20,18 +30,29 @@ class Red_Htaccess {
20
  private function encode( $url ) {
21
  $url = urlencode( $url );
22
  $url = str_replace( '%2F', '/', $url );
 
23
  $url = str_replace( '+', '%20', $url );
24
  $url = str_replace( '.', '\\.', $url );
25
  return $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 );
34
  $url = str_replace( '%24', '$', $url );
 
 
 
 
 
 
 
35
  return $url;
36
  }
37
 
@@ -84,11 +105,12 @@ class Red_Htaccess {
84
  $this->items[] = sprintf( 'RewriteCond %%{QUERY_STRING} ^%s$', $url_parts['query'] );
85
  }
86
 
87
- $to = $this->target( $item->get_action_type(), $match->url, $item->get_action_code(), $item->is_regex() );
88
  $from = $this->encode_from( $url );
89
 
90
- if ( $item->is_regex() )
91
  $from = $this->encode_regex( $item->get_url() );
 
92
 
93
  if ( $to )
94
  $this->items[] = sprintf( 'RewriteRule %s %s', $from, $to );
@@ -181,9 +203,10 @@ class Red_Htaccess {
181
  public function save( $filename, $content_to_save = false ) {
182
  $existing = false;
183
 
184
- if ( file_exists( $filename ) )
185
- $existing = @file_get_contents( $filename );
 
186
 
187
- return @file_put_contents( $filename, $this->get( $existing ) );
188
  }
189
  }
5
  const INSERT_REGEX = '@\n?# Created by Redirection(.*?)# End of Redirection\n?@sm';
6
 
7
  private function encode_from( $url ) {
8
+ $url = $this->encode( $url );
9
+
10
+ // Apache 2 does not need a leading slashing
11
+ $url = ltrim( $url, '/' );
12
+
13
+ // Exactly match the URL
14
+ return '^'.$url.'$';
15
  }
16
 
17
  private function encode2nd( $url ) {
18
  $url = urlencode( $url );
19
  $url = str_replace( '%2F', '/', $url );
20
+ $url = str_replace( '%3F', '?', $url );
21
  $url = str_replace( '%3A', ':', $url );
22
+ $url = str_replace( '%3D', '=', $url );
23
+ $url = str_replace( '%26', '&', $url );
24
+ $url = str_replace( '%25', '%', $url );
25
  $url = str_replace( '+', '%20', $url );
26
  $url = str_replace( '%24', '$', $url );
27
  return $url;
30
  private function encode( $url ) {
31
  $url = urlencode( $url );
32
  $url = str_replace( '%2F', '/', $url );
33
+ $url = str_replace( '%3F', '?', $url );
34
  $url = str_replace( '+', '%20', $url );
35
  $url = str_replace( '.', '\\.', $url );
36
  return $url;
37
  }
38
 
39
  private function encode_regex( $url ) {
40
+ // Remove any newlines
41
  $url = preg_replace( "/[\r\n\t].*?$/s", '', $url );
42
+
43
+ // Remove invalid characters
44
  $url = preg_replace( '/[^\PC\s]/u', '', $url );
45
+
46
+ // Make sure spaces are quoted
47
  $url = str_replace( ' ', '%20', $url );
 
 
48
  $url = str_replace( '%24', '$', $url );
49
+
50
+ // No leading slash
51
+ $url = ltrim( $url, '/' );
52
+
53
+ // If pattern has a ^ at the start then ensure we don't have a slash immediatley after
54
+ $url = preg_replace( '@^\^/@', '^', $url );
55
+
56
  return $url;
57
  }
58
 
105
  $this->items[] = sprintf( 'RewriteCond %%{QUERY_STRING} ^%s$', $url_parts['query'] );
106
  }
107
 
108
+ $to = $this->target( $item->get_action_type(), $match->url, $item->get_action_code(), $item->is_regex() );
109
  $from = $this->encode_from( $url );
110
 
111
+ if ( $item->is_regex() ) {
112
  $from = $this->encode_regex( $item->get_url() );
113
+ }
114
 
115
  if ( $to )
116
  $this->items[] = sprintf( 'RewriteRule %s %s', $from, $to );
203
  public function save( $filename, $content_to_save = false ) {
204
  $existing = false;
205
 
206
+ if ( file_exists( $filename ) ) {
207
+ $existing = file_get_contents( $filename );
208
+ }
209
 
210
+ return file_put_contents( $filename, $this->get( $existing ) );
211
  }
212
  }
models/redirect.php CHANGED
@@ -277,8 +277,9 @@ class Red_Item {
277
  // Save this
278
  $wpdb->update( $wpdb->prefix.'redirection_items', array( 'url' => $this->url, 'regex' => $this->regex, 'action_code' => $this->action_code, 'action_data' => $data, 'group_id' => $this->group_id, 'title' => $this->title ), array( 'id' => $this->id ) );
279
 
 
 
280
  if ( $old_group !== $this->group_id ) {
281
- Red_Module::flush( $this->group_id );
282
  Red_Module::flush( $old_group );
283
  }
284
  }
@@ -333,21 +334,41 @@ class Red_Item {
333
 
334
  function visit( $url, $target ) {
335
  if ( $this->tracking && $this->id ) {
336
- global $wpdb, $redirection;
337
 
338
  // Update the counters
339
  $count = $this->last_count + 1;
340
  $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}redirection_items SET last_count=%d, last_access=NOW() WHERE id=%d", $count, $this->id ) );
341
 
342
- if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
343
- $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
344
- elseif ( isset( $_SERVER['REMOTE_ADDR'] ) )
345
- $ip = $_SERVER['REMOTE_ADDR'];
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
 
353
  public function is_enabled() {
277
  // Save this
278
  $wpdb->update( $wpdb->prefix.'redirection_items', array( 'url' => $this->url, 'regex' => $this->regex, 'action_code' => $this->action_code, 'action_data' => $data, 'group_id' => $this->group_id, 'title' => $this->title ), array( 'id' => $this->id ) );
279
 
280
+ Red_Module::flush( $this->group_id );
281
+
282
  if ( $old_group !== $this->group_id ) {
 
283
  Red_Module::flush( $old_group );
284
  }
285
  }
334
 
335
  function visit( $url, $target ) {
336
  if ( $this->tracking && $this->id ) {
337
+ global $wpdb;
338
 
339
  // Update the counters
340
  $count = $this->last_count + 1;
341
  $wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->prefix}redirection_items SET last_count=%d, last_access=NOW() WHERE id=%d", $count, $this->id ) );
342
 
 
 
 
 
 
343
  $options = red_get_options();
344
+ if ( isset( $options['expire_redirect'] ) && $options['expire_redirect'] >= 0 ) {
345
+ $log = RE_Log::create( $url, $target, $this->get_user_agent(), $this->get_ip(), $this->get_referrer(), array( 'redirect_id' => $this->id, 'group_id' => $this->group_id ) );
346
+ }
347
+ }
348
+ }
349
+
350
+ private function get_ip() {
351
+ if ( isset( $_SERVER['HTTP_X_FORWARDED_FOR'] ) )
352
+ return $_SERVER['HTTP_X_FORWARDED_FOR'];
353
+ elseif ( isset( $_SERVER['REMOTE_ADDR'] ) )
354
+ return $_SERVER['REMOTE_ADDR'];
355
+ return '';
356
+ }
357
+
358
+ private function get_referrer() {
359
+ if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
360
+ return $_SERVER['HTTP_REFERER'];
361
  }
362
+
363
+ return '';
364
+ }
365
+
366
+ private function get_user_agent() {
367
+ if ( isset( $_SERVER['HTTP_USER_AGENT'] ) ) {
368
+ return $_SERVER['HTTP_USER_AGENT'];
369
+ }
370
+
371
+ return '';
372
  }
373
 
374
  public function is_enabled() {
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.2
6
- Tested up to: 4.7
7
- Stable tag: 2.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,13 +97,18 @@ The plugin works in a similar manner to how WordPress handles permalinks and sho
97
 
98
  == Changelog ==
99
 
 
 
 
 
 
100
  = 2.5 =
101
  * Fix no group created on install
102
  * Fix missing export key on install
103
- * Add 408 HTTP code, props to radenui
104
  * Fix imported URLs set to regex, props to alpipego
105
  * Fix sorting of URLs, props to JordanReiter
106
- * Don't cache 407s, props to rmarchant
107
  * Abort redirect exit if no redirection happened, props to junc
108
 
109
  = 2.4.5 =
3
  Donate link: http://urbangiraffe.com/about/
4
  Tags: post, admin, seo, pages, manage, 301, 404, redirect, permalink
5
  Requires at least: 4.2
6
+ Tested up to: 4.7.5
7
+ Stable tag: 2.6
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.6 =
101
+ * Show example CSV
102
+ * Allow regex and redirect code to be set on import
103
+ * Fix a bunch of database installation problems
104
+
105
  = 2.5 =
106
  * Fix no group created on install
107
  * Fix missing export key on install
108
+ * Add 308 HTTP code, props to radenui
109
  * Fix imported URLs set to regex, props to alpipego
110
  * Fix sorting of URLs, props to JordanReiter
111
+ * Don't cache 307s, props to rmarchant
112
  * Abort redirect exit if no redirection happened, props to junc
113
 
114
  = 2.4.5 =
redirection-admin.php CHANGED
@@ -41,6 +41,8 @@ class Redirection_Admin {
41
  add_action( 'wp_ajax_red_get_nginx', array( &$this, 'ajax_get_nginx' ) );
42
 
43
  $this->monitor = new Red_Monitor( red_get_options() );
 
 
44
  }
45
 
46
  public static function plugin_activated() {
@@ -107,6 +109,11 @@ class Redirection_Admin {
107
  include_once dirname( REDIRECTION_FILE ).'/models/database.php';
108
 
109
  $database = new RE_Database();
 
 
 
 
 
110
  return $database->upgrade( $version, REDIRECTION_VERSION );
111
  }
112
 
@@ -159,7 +166,21 @@ class Redirection_Admin {
159
  }
160
 
161
  function admin_menu() {
162
- add_management_page( __( 'Redirection', 'redirection' ), __( 'Redirection', 'redirection' ), apply_filters( 'redirection_role', 'administrator' ), basename( REDIRECTION_FILE ), array( &$this, 'admin_screen' ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  }
164
 
165
  function admin_screen() {
@@ -194,15 +215,14 @@ class Redirection_Admin {
194
  }
195
 
196
  function inject() {
197
- $options = red_get_options();
198
-
199
  if ( isset( $_POST['id'] ) && ! isset( $_POST['action'] ) ) {
200
  wp_safe_redirect( add_query_arg( 'id', intval( $_POST['id'] ), $_SERVER['REQUEST_URI'] ) );
201
  die();
202
  }
203
 
204
- if ( isset( $_GET['token'] ) && isset( $_GET['page'] ) && isset( $_GET['sub'] ) && $_GET['token'] === $options['token'] && $_GET['page'] === 'redirection.php' ) {
205
  $exporter = Red_FileIO::create( $_GET['sub'] );
 
206
  if ( $exporter ) {
207
  $items = Red_Item::get_all_for_module( intval( $_GET['module'] ) );
208
 
@@ -333,7 +353,7 @@ class Redirection_Admin {
333
  $start = strpos( $readme, 'Redirection is available in' );
334
  $end = strpos( $readme, '==', $start );
335
  if ( $start !== false && $end !== false ) {
336
- if ( preg_match_all( '/^\* (.*?) by (.*?)/m', substr( $readme, $start, $end ), $matches ) > 0 ) {
337
  $locales = $matches[1];
338
  }
339
  }
41
  add_action( 'wp_ajax_red_get_nginx', array( &$this, 'ajax_get_nginx' ) );
42
 
43
  $this->monitor = new Red_Monitor( red_get_options() );
44
+
45
+ $this->export_rss();
46
  }
47
 
48
  public static function plugin_activated() {
109
  include_once dirname( REDIRECTION_FILE ).'/models/database.php';
110
 
111
  $database = new RE_Database();
112
+
113
+ if ( $version === false ) {
114
+ $database->install();
115
+ }
116
+
117
  return $database->upgrade( $version, REDIRECTION_VERSION );
118
  }
119
 
166
  }
167
 
168
  function admin_menu() {
169
+ add_management_page( 'Redirection', 'Redirection', apply_filters( 'redirection_role', 'administrator' ), basename( REDIRECTION_FILE ), array( &$this, 'admin_screen' ) );
170
+ }
171
+
172
+ function export_rss() {
173
+ if ( isset( $_GET['token'] ) && isset( $_GET['page'] ) && isset( $_GET['sub'] ) && $_GET['page'] === 'redirection.php' && $_GET['sub'] === 'rss' ) {
174
+ $options = red_get_options();
175
+
176
+ if ( $_GET['token'] === $options['token'] && !empty( $options['token'] ) ) {
177
+ $items = Red_Item::get_all_for_module( intval( $_GET['module'] ) );
178
+
179
+ $exporter = Red_FileIO::create( 'rss' );
180
+ $exporter->export( $items );
181
+ die();
182
+ }
183
+ }
184
  }
185
 
186
  function admin_screen() {
215
  }
216
 
217
  function inject() {
 
 
218
  if ( isset( $_POST['id'] ) && ! isset( $_POST['action'] ) ) {
219
  wp_safe_redirect( add_query_arg( 'id', intval( $_POST['id'] ), $_SERVER['REQUEST_URI'] ) );
220
  die();
221
  }
222
 
223
+ if ( isset( $_GET['page'] ) && isset( $_GET['sub'] ) && $_GET['page'] === 'redirection.php' ) {
224
  $exporter = Red_FileIO::create( $_GET['sub'] );
225
+
226
  if ( $exporter ) {
227
  $items = Red_Item::get_all_for_module( intval( $_GET['module'] ) );
228
 
353
  $start = strpos( $readme, 'Redirection is available in' );
354
  $end = strpos( $readme, '==', $start );
355
  if ( $start !== false && $end !== false ) {
356
+ if ( preg_match_all( '/^\* (.*? by .*)/m', substr( $readme, $start, $end ), $matches ) > 0 ) {
357
  $locales = $matches[1];
358
  }
359
  }
redirection.php CHANGED
@@ -3,7 +3,7 @@
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.5
7
  Author: John Godley
8
  Author URI: http://urbangiraffe.com
9
  Text Domain: redirection
@@ -21,15 +21,15 @@ For full license details see license.txt
21
  ============================================================================================================
22
  */
23
 
24
- define( 'REDIRECTION_VERSION', '2.3.2' ); // DB schema version. Only change if DB needs changing
25
  define( 'REDIRECTION_FILE', __FILE__ );
26
 
 
27
  include dirname( __FILE__ ).'/models/module.php';
28
  include dirname( __FILE__ ).'/models/log.php';
29
  include dirname( __FILE__ ).'/models/flusher.php';
30
  include dirname( __FILE__ ).'/models/match.php';
31
  include dirname( __FILE__ ).'/models/action.php';
32
- include dirname( __FILE__ ).'/models/redirect.php';
33
 
34
  function red_get_options() {
35
  $options = get_option( 'redirection_options' );
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.6
7
  Author: John Godley
8
  Author URI: http://urbangiraffe.com
9
  Text Domain: redirection
21
  ============================================================================================================
22
  */
23
 
24
+ define( 'REDIRECTION_VERSION', '2.3.3' ); // DB schema version. Only change if DB needs changing
25
  define( 'REDIRECTION_FILE', __FILE__ );
26
 
27
+ include dirname( __FILE__ ).'/models/redirect.php';
28
  include dirname( __FILE__ ).'/models/module.php';
29
  include dirname( __FILE__ ).'/models/log.php';
30
  include dirname( __FILE__ ).'/models/flusher.php';
31
  include dirname( __FILE__ ).'/models/match.php';
32
  include dirname( __FILE__ ).'/models/action.php';
 
33
 
34
  function red_get_options() {
35
  $options = get_option( 'redirection_options' );
view/group-list.php CHANGED
@@ -1,7 +1,5 @@
1
  <?php if ( !defined( 'ABSPATH' ) ) die( 'No direct access allowed' ); ?>
2
  <div class="wrap">
3
- <?php screen_icon(); ?>
4
-
5
  <h2><?php _e( 'Groups', 'redirection' ); ?></a></h2>
6
 
7
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
1
  <?php if ( !defined( 'ABSPATH' ) ) die( 'No direct access allowed' ); ?>
2
  <div class="wrap">
 
 
3
  <h2><?php _e( 'Groups', 'redirection' ); ?></a></h2>
4
 
5
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
view/item-list.php CHANGED
@@ -1,7 +1,5 @@
1
  <?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
2
  <div class="wrap">
3
- <?php screen_icon(); ?>
4
-
5
  <h2><?php _e( 'Redirections', 'redirection' ); ?></h2>
6
 
7
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
1
  <?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
2
  <div class="wrap">
 
 
3
  <h2><?php _e( 'Redirections', 'redirection' ); ?></h2>
4
 
5
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
view/log.php CHANGED
@@ -1,7 +1,5 @@
1
  <?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
2
  <div class="wrap">
3
- <?php screen_icon(); ?>
4
-
5
  <h2><?php _e ('Redirection Log', 'redirection'); ?></h2>
6
 
7
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
1
  <?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
2
  <div class="wrap">
 
 
3
  <h2><?php _e ('Redirection Log', 'redirection'); ?></h2>
4
 
5
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
view/module-list.php CHANGED
@@ -1,7 +1,5 @@
1
  <?php if ( !defined( 'ABSPATH' ) ) die( 'No direct access allowed' ); ?>
2
  <div class="wrap">
3
- <?php screen_icon(); ?>
4
-
5
  <h2><?php _e( 'Modules', 'redirection' ); ?></h2>
6
 
7
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
1
  <?php if ( !defined( 'ABSPATH' ) ) die( 'No direct access allowed' ); ?>
2
  <div class="wrap">
 
 
3
  <h2><?php _e( 'Modules', 'redirection' ); ?></h2>
4
 
5
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
view/options.php CHANGED
@@ -14,8 +14,6 @@ $expiry = array(
14
  ?>
15
 
16
  <div class="wrap">
17
- <?php screen_icon( ); ?>
18
-
19
  <h2><?php _e( 'Options', 'redirection' ) ?></h2>
20
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
21
 
@@ -96,6 +94,11 @@ $expiry = array(
96
  </select>
97
  <input class="button-primary" type="submit" name="import" value="<?php _e( 'Upload', 'redirection' ); ?>"/>
98
  </form>
 
 
 
 
 
99
  </div>
100
 
101
  <div class="wrap">
14
  ?>
15
 
16
  <div class="wrap">
 
 
17
  <h2><?php _e( 'Options', 'redirection' ) ?></h2>
18
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
19
 
94
  </select>
95
  <input class="button-primary" type="submit" name="import" value="<?php _e( 'Upload', 'redirection' ); ?>"/>
96
  </form>
97
+
98
+ <h5>CSV Format</h5>
99
+ <code>
100
+ Source URL, Target URL, [Regex 0=false, 1=true], [HTTP Code]
101
+ </code>
102
  </div>
103
 
104
  <div class="wrap">
view/support.php CHANGED
@@ -1,13 +1,11 @@
1
  <?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
2
  <div class="wrap supporter">
3
- <?php screen_icon(); ?>
4
-
5
  <h2><?php _e ('Redirection Support', 'redirection'); ?></h2>
6
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
7
 
8
  <p style="clear: both; padding-top: 20px">
9
  <?php _e( 'Redirection is free to use - life is wonderful and lovely! However, it has required a great deal of time and effort to develop and if it has been useful you can help support this development by <strong>making a small donation</strong>.', 'redirection'); ?>
10
- <?php _e( 'This will act as an incentive for me to carry on developing. You get some useful software and I get to carry on making it. Everybody wins.', 'redirection'); ?>
11
  </p>
12
 
13
  <p><?php _e( 'Please note that a donation is just a donation - it is not a payment for support. I am not a business, this is not a product, and I\'m afraid I cannot provide paid support' ); ?></p>
@@ -20,7 +18,7 @@
20
  <input type="hidden" name="cmd" value="_xclick">
21
  <input type="hidden" name="business" value="admin@urbangiraffe.com">
22
  <input type="hidden" name="item_name" value="Redirection - Individual">
23
- <input type="hidden" name="amount" value="16.00">
24
  <input type="hidden" name="buyer_credit_promo_code" value="">
25
  <input type="hidden" name="buyer_credit_product_category" value="">
26
  <input type="hidden" name="buyer_credit_shipping_method" value="">
@@ -35,7 +33,7 @@
35
  <input type="image" style="border: none" src="<?php echo plugins_url( '/images/donate.gif', REDIRECTION_FILE ); ?>" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
36
  </form>
37
 
38
- <p><strong>$16</strong><br/><?php _e( 'Individual<br/>Donation', 'redirection' ); ?></p>
39
  </li>
40
  <li>
41
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
@@ -59,9 +57,26 @@
59
  </li>
60
  </ul>
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  <h3 style="clear: both"><?php _e( 'Translations', 'redirection' )?></h3>
63
 
64
- <p><?php _e( 'If you\'re multi-lingual then you may want to consider donating a translation:', 'redirection' )?>
65
 
66
  <ul class="translators">
67
  <?php foreach( $this->locales() AS $language ) : ?>
1
  <?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>
2
  <div class="wrap supporter">
 
 
3
  <h2><?php _e ('Redirection Support', 'redirection'); ?></h2>
4
  <?php $this->render( 'submenu', array( 'options' => $options ) ); ?>
5
 
6
  <p style="clear: both; padding-top: 20px">
7
  <?php _e( 'Redirection is free to use - life is wonderful and lovely! However, it has required a great deal of time and effort to develop and if it has been useful you can help support this development by <strong>making a small donation</strong>.', 'redirection'); ?>
8
+ <?php _e( 'This will act as an incentive for me to carry on developing. You get some useful software and I get to carry on making it. Everybody wins.', 'redirection'); ?>
9
  </p>
10
 
11
  <p><?php _e( 'Please note that a donation is just a donation - it is not a payment for support. I am not a business, this is not a product, and I\'m afraid I cannot provide paid support' ); ?></p>
18
  <input type="hidden" name="cmd" value="_xclick">
19
  <input type="hidden" name="business" value="admin@urbangiraffe.com">
20
  <input type="hidden" name="item_name" value="Redirection - Individual">
21
+ <input type="hidden" name="amount" value="20.00">
22
  <input type="hidden" name="buyer_credit_promo_code" value="">
23
  <input type="hidden" name="buyer_credit_product_category" value="">
24
  <input type="hidden" name="buyer_credit_shipping_method" value="">
33
  <input type="image" style="border: none" src="<?php echo plugins_url( '/images/donate.gif', REDIRECTION_FILE ); ?>" border="0" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"/>
34
  </form>
35
 
36
+ <p><strong>$20</strong><br/><?php _e( 'Individual<br/>Donation', 'redirection' ); ?></p>
37
  </li>
38
  <li>
39
  <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
57
  </li>
58
  </ul>
59
 
60
+ <h3 style="clear: both"><?php _e( 'Help! Frequently Asked Questions', 'redirection' )?></h3>
61
+
62
+ <ul>
63
+ <li>
64
+ <h3>I deleted a redirection, why is it still redirecting?</h3>
65
+ <p>Your browser will cache redirections. If you have deleted a redirection and your browser is still performing the redirection then <a href="http://www.refreshyourcache.com/en/home/">clear your browser cache</a>.</p>
66
+ </li>
67
+ <li>
68
+ <h3>Can I open a redirect in a new tab?</h3>
69
+ <p>It's not possible to do this on the server. Instead you will need to add <code>target="blank"</code> to your link.</p>
70
+ </li>
71
+ <li>
72
+ <h3>Something isn't working!</h3>
73
+ <p>Please disable all other plugins and check if the problem persists. If it does please report it <a href="https://github.com/johngodley/redirection/">here</a> with full details about the problem and a way to reproduce it.</p>
74
+ </li>
75
+ </ul>
76
+
77
  <h3 style="clear: both"><?php _e( 'Translations', 'redirection' )?></h3>
78
 
79
+ <p><?php _e( 'Many thanks to the following for their translations:', 'redirection' )?>
80
 
81
  <ul class="translators">
82
  <?php foreach( $this->locales() AS $language ) : ?>