Eggplant 301 Redirects - Version 2.3.0

Version Description

Added sorting. Fixed a bug when upgrading from V1 to V2, and the infamous "Invalid Destination" url.

Download this release

Release Info

Developer shawn@eggplantstudios.ca
Plugin Icon 128x128 Eggplant 301 Redirects
Version 2.3.0
Comparing to
See all releases

Code changes from version 2.2.8 to 2.3.0

class.drop-down-pages.php CHANGED
@@ -10,15 +10,9 @@
10
  * @return string or HTML content, if not displaying.
11
  */
12
 
13
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
 
15
-
16
- if( !function_exists('eps_dropdown_pages'))
17
- {
18
-
19
-
20
- function eps_dropdown_pages($args = '')
21
- {
22
  $defaults = array(
23
  'posts_per_page' => -1,
24
  'offset' => 0,
@@ -79,7 +73,5 @@ class EPS_Walker_PageDropdown extends Walker {
79
  $output[$object->ID] = $pad . esc_html( apply_filters( 'list_pages', $object->post_title, $object ) );
80
  }
81
  }
82
-
83
-
84
- } // End function exists.
85
  ?>
10
  * @return string or HTML content, if not displaying.
11
  */
12
 
 
13
 
14
+ if( !function_exists('eps_dropdown_pages')) {
15
+ function eps_dropdown_pages($args = '') {
 
 
 
 
 
16
  $defaults = array(
17
  'posts_per_page' => -1,
18
  'offset' => 0,
73
  $output[$object->ID] = $pad . esc_html( apply_filters( 'list_pages', $object->post_title, $object ) );
74
  }
75
  }
76
+ }
 
 
77
  ?>
css/eps_redirect.css CHANGED
@@ -37,14 +37,20 @@
37
  overflow: hidden;
38
  }
39
 
 
 
 
 
 
 
40
  .eps-table th {
41
  padding: 6px 10px;
42
  background: #2A95C5;
43
  color:#FFFFFF;
44
  }
45
 
46
- .eps-table td.redirect-hits, .eps-table th.redirect-hits {
47
- width: 26px;
48
  text-align: center;
49
  padding-left: 4px;
50
  padding-right: 4px;
@@ -120,8 +126,8 @@ select.eps-small-select { display: inline-block; }
120
  .eps-margin-top { margin-top: 12px; }
121
  .eps-grey-text { color: #999999; }
122
  .float-right { float: right; }
123
- .text-center { text-align: center; }
124
-
125
  .eps-url {
126
  text-decoration: none; font-size: 12px !important;
127
  background: #ffffff;
37
  overflow: hidden;
38
  }
39
 
40
+ .eps-table th a:link,
41
+ .eps-table th a:visited {
42
+ color: white;
43
+ text-decoration: none;
44
+ }
45
+
46
  .eps-table th {
47
  padding: 6px 10px;
48
  background: #2A95C5;
49
  color:#FFFFFF;
50
  }
51
 
52
+ .eps-table td.redirect-small, .eps-table th.redirect-small {
53
+ width: 40px;
54
  text-align: center;
55
  padding-left: 4px;
56
  padding-right: 4px;
126
  .eps-margin-top { margin-top: 12px; }
127
  .eps-grey-text { color: #999999; }
128
  .float-right { float: right; }
129
+ .eps-text-center { text-align: center; }
130
+ .eps-small { font-size: 10px; }
131
  .eps-url {
132
  text-decoration: none; font-size: 12px !important;
133
  background: #ffffff;
eps-301-redirects.php CHANGED
@@ -15,7 +15,7 @@
15
  *
16
  * @package EPS 301 Redirects
17
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
18
- * @version 2.2.8
19
  */
20
 
21
 
@@ -25,7 +25,7 @@
25
  Plugin Name: Eggplant 301 Redirects
26
  Plugin URI: http://www.eggplantstudios.ca
27
  Description: Create your own 301 redirects using this powerful plugin.
28
- Version: 2.2.8
29
  Author: Shawn Wernig http://www.eggplantstudios.ca
30
  License: GPLv2 or later
31
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
@@ -36,7 +36,7 @@ if( ! defined( 'EPS_REDIRECT_PRO' ) )
36
 
37
  define ( 'EPS_REDIRECT_PATH', plugin_dir_path(__FILE__) );
38
  define ( 'EPS_REDIRECT_URL', plugins_url() . '/eps-301-redirects/');
39
- define ( 'EPS_REDIRECT_VERSION', '2.2.8');
40
  define ( 'EPS_REDIRECT_PRO', false);
41
 
42
  include( EPS_REDIRECT_PATH.'eps-form-elements.php');
@@ -101,7 +101,6 @@ class EPS_Redirects {
101
  */
102
  public function do_redirect() {
103
  if ( is_admin() ) return false;
104
-
105
  $redirects = self::get_redirects( true ); // True for only active redirects.
106
 
107
  if (empty($redirects)) return false; // No redirects.
@@ -109,30 +108,33 @@ class EPS_Redirects {
109
  // Get current url
110
  $url_request = self::get_url();
111
 
112
- // Extract the query string
113
  $query_string = explode('?', $url_request);
114
  $query_string = ( isset($query_string[1]) ) ? $query_string[1] : false;
115
 
116
- // Check all redirects for matches
117
  foreach ($redirects as $redirect )
118
  {
119
  $from = urldecode( $redirect->url_from );
120
 
121
  if( $redirect->status != 'inactive' && rtrim( trim($url_request),'/') === self::format_from_url( trim($from) ) )
122
  {
123
- // Match, this needs to be redirected
124
 
 
125
  // increment this hit counter.
126
- self::increment_field( $redirect->id, 'count');
127
 
128
- // Set the header status
129
- self::set_header_status( $redirect->status );
 
 
 
 
 
 
130
 
131
- // Resolve the new location
132
  $to = ($redirect->type == "url" && !is_numeric( $redirect->url_to )) ? urldecode($redirect->url_to) : get_permalink( $redirect->url_to );
133
  $to = ( $query_string ) ? $to . "?" . $query_string : $to;
134
 
135
- // Send em off!
136
  header ('Location: ' . $to, true, (int) $redirect->status);
137
  exit();
138
  }
@@ -140,18 +142,6 @@ class EPS_Redirects {
140
  }
141
  }
142
 
143
- private static function set_header_status( $status = '301' )
144
- {
145
- if( $status == '302' )
146
- {
147
- header ('HTTP/1.1 301 Moved Permanently');
148
- }
149
- else
150
- {
151
- header ('HTTP/1.1 301 Moved Temporarily');
152
- }
153
- }
154
-
155
  /**
156
  *
157
  * FORMAT FROM URL
@@ -163,8 +153,7 @@ class EPS_Redirects {
163
  *
164
  */
165
  private function format_from_url( $string ) {
166
- // Legacy, just in case I need it again.
167
- //$from = home_url() . '/' . $string;
168
  //return strtolower( rtrim( $from,'/') );
169
 
170
 
@@ -186,12 +175,16 @@ class EPS_Redirects {
186
  */
187
  public static function get_url() {
188
  return strtolower( urldecode( $_SERVER['REQUEST_URI'] ) );
189
- // Legacy, just in case I need it again.
190
  //$protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http';
191
  //return strtolower( urldecode( $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
192
  }
193
 
 
 
 
194
 
 
 
195
  /**
196
  *
197
  * PARSE SERIAL ARRAY
@@ -364,10 +357,17 @@ class EPS_Redirects {
364
  public static function get_redirects( $active_only = false ) {
365
  global $wpdb;
366
  $table_name = $wpdb->prefix . "redirects";
367
-
368
- $results = $wpdb->get_results(
369
- "SELECT * FROM $table_name WHERE status != 404 " . ( ( $active_only ) ? "AND status != 'inactive'" : null ) . " ORDER BY id DESC"
370
- );
 
 
 
 
 
 
 
371
 
372
  return $results;
373
  }
@@ -453,7 +453,6 @@ class EPS_Redirects {
453
  echo json_encode( array( 'id' => $_POST['id']) );
454
  exit();
455
  }
456
-
457
  private static function _delete( $id ){
458
  global $wpdb;
459
  $table_name = $wpdb->prefix . "redirects";
@@ -538,12 +537,39 @@ class EPS_Redirects {
538
 
539
  public static function check_404()
540
  {
541
- // deprecated
542
- return false;
543
  }
544
 
545
  }
546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
547
  // Run the plugin.
548
  $EPS_Redirects = new EPS_Redirects();
549
 
@@ -562,4 +588,6 @@ else
562
  }
563
  }
564
  }
 
 
565
  ?>
15
  *
16
  * @package EPS 301 Redirects
17
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
18
+ * @version 2.3.0
19
  */
20
 
21
 
25
  Plugin Name: Eggplant 301 Redirects
26
  Plugin URI: http://www.eggplantstudios.ca
27
  Description: Create your own 301 redirects using this powerful plugin.
28
+ Version: 2.3.0
29
  Author: Shawn Wernig http://www.eggplantstudios.ca
30
  License: GPLv2 or later
31
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
36
 
37
  define ( 'EPS_REDIRECT_PATH', plugin_dir_path(__FILE__) );
38
  define ( 'EPS_REDIRECT_URL', plugins_url() . '/eps-301-redirects/');
39
+ define ( 'EPS_REDIRECT_VERSION', '2.3.0');
40
  define ( 'EPS_REDIRECT_PRO', false);
41
 
42
  include( EPS_REDIRECT_PATH.'eps-form-elements.php');
101
  */
102
  public function do_redirect() {
103
  if ( is_admin() ) return false;
 
104
  $redirects = self::get_redirects( true ); // True for only active redirects.
105
 
106
  if (empty($redirects)) return false; // No redirects.
108
  // Get current url
109
  $url_request = self::get_url();
110
 
 
111
  $query_string = explode('?', $url_request);
112
  $query_string = ( isset($query_string[1]) ) ? $query_string[1] : false;
113
 
114
+
115
  foreach ($redirects as $redirect )
116
  {
117
  $from = urldecode( $redirect->url_from );
118
 
119
  if( $redirect->status != 'inactive' && rtrim( trim($url_request),'/') === self::format_from_url( trim($from) ) )
120
  {
 
121
 
122
+ // Match, this needs to be redirected
123
  // increment this hit counter.
124
+ self::increment_field($redirect->id, 'count');
125
 
126
+ if( $redirect->status == '301' )
127
+ {
128
+ header ('HTTP/1.1 301 Moved Permanently');
129
+ }
130
+ elseif ( $redirect->status == '302' )
131
+ {
132
+ header ('HTTP/1.1 302 Moved Temporarily');
133
+ }
134
 
 
135
  $to = ($redirect->type == "url" && !is_numeric( $redirect->url_to )) ? urldecode($redirect->url_to) : get_permalink( $redirect->url_to );
136
  $to = ( $query_string ) ? $to . "?" . $query_string : $to;
137
 
 
138
  header ('Location: ' . $to, true, (int) $redirect->status);
139
  exit();
140
  }
142
  }
143
  }
144
 
 
 
 
 
 
 
 
 
 
 
 
 
145
  /**
146
  *
147
  * FORMAT FROM URL
153
  *
154
  */
155
  private function format_from_url( $string ) {
156
+ //$from = home_url() . '/' . $string;
 
157
  //return strtolower( rtrim( $from,'/') );
158
 
159
 
175
  */
176
  public static function get_url() {
177
  return strtolower( urldecode( $_SERVER['REQUEST_URI'] ) );
 
178
  //$protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http';
179
  //return strtolower( urldecode( $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
180
  }
181
 
182
+
183
+
184
+
185
 
186
+
187
+
188
  /**
189
  *
190
  * PARSE SERIAL ARRAY
357
  public static function get_redirects( $active_only = false ) {
358
  global $wpdb;
359
  $table_name = $wpdb->prefix . "redirects";
360
+ $orderby = ( isset($_GET['orderby']) ) ? esc_sql( $_GET['orderby'] ) : 'id';
361
+ $order = ( isset($_GET['order']) ) ? esc_sql( $_GET['order'] ) : 'desc';
362
+ $orderby = ( in_array( strtolower($orderby), array('id','url_from','url_to','count') ) ) ? $orderby : 'id';
363
+ $order = ( in_array( strtolower($order), array('asc','desc') ) ) ? $order : 'desc';
364
+
365
+ $query = "SELECT *
366
+ FROM $table_name
367
+ WHERE status != 404 " . ( ( $active_only ) ? "AND status != 'inactive'" : null ) . "
368
+ ORDER BY $orderby $order";
369
+ //die($query);
370
+ $results = $wpdb->get_results( $query );
371
 
372
  return $results;
373
  }
453
  echo json_encode( array( 'id' => $_POST['id']) );
454
  exit();
455
  }
 
456
  private static function _delete( $id ){
457
  global $wpdb;
458
  $table_name = $wpdb->prefix . "redirects";
537
 
538
  public static function check_404()
539
  {
540
+
 
541
  }
542
 
543
  }
544
 
545
+
546
+
547
+
548
+
549
+ /**
550
+ * Outputs an object or array in a readable form.
551
+ *
552
+ * @return void
553
+ * @param $string = the object to prettify; Typically a string.
554
+ * @author epstudios
555
+ */
556
+ if( !function_exists('eps_prettify')) {
557
+ function eps_prettify( $string ) {
558
+ return ucwords( str_replace("_"," ",$string) );
559
+ }
560
+ }
561
+
562
+ if( !function_exists('eps_view')) {
563
+ function eps_view( $object ) {
564
+ echo '<pre>';
565
+ print_r($object);
566
+ echo '</pre>';
567
+ }
568
+ }
569
+
570
+
571
+
572
+
573
  // Run the plugin.
574
  $EPS_Redirects = new EPS_Redirects();
575
 
588
  }
589
  }
590
  }
591
+
592
+
593
  ?>
eps-form-elements.php CHANGED
@@ -25,7 +25,6 @@
25
  * @author epstudios
26
  *
27
  */
28
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
29
 
30
  function eps_get_selector( $redirect = false ) {
31
  $current_post = ( isset( $redirect->url_to ) && is_numeric( $redirect->url_to ) ) ? get_post( intval( $redirect->url_to ) ) : null;
@@ -185,4 +184,30 @@ function eps_get_term_archive_select(){
185
  $html .= '</select>';
186
  return $html;
187
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
188
  ?>
25
  * @author epstudios
26
  *
27
  */
 
28
 
29
  function eps_get_selector( $redirect = false ) {
30
  $current_post = ( isset( $redirect->url_to ) && is_numeric( $redirect->url_to ) ) ? get_post( intval( $redirect->url_to ) ) : null;
184
  $html .= '</select>';
185
  return $html;
186
  }
187
+
188
+ function eps_get_ordered_filter( $field, $label, $classes = array() )
189
+ {
190
+ global $EPS_Redirects_Plugin;
191
+ $nextOrder = 'asc';
192
+ $arrow = false;
193
+
194
+ if( isset( $_GET['orderby'] ) && $_GET['orderby']== $field )
195
+ {
196
+ $arrow = '&darr;';
197
+
198
+ if( isset( $_GET['order'] ) && $_GET['order'] != 'desc' )
199
+ {
200
+ $nextOrder = 'desc';
201
+ $arrow = '&uarr;';
202
+ }
203
+ }
204
+
205
+ printf(
206
+ '<a class="%s" href="%s">%s %s</a>',
207
+ implode(' ', $classes ),
208
+ $EPS_Redirects_Plugin->admin_url( array( 'orderby' => $field, 'order' => $nextOrder) ),
209
+ $label,
210
+ $arrow
211
+ );
212
+ }
213
  ?>
js/scripts.js CHANGED
@@ -1,3 +1,8 @@
 
 
 
 
 
1
  jQuery(document).ready(function ($) {
2
 
3
  /**
1
+ /* Author:
2
+
3
+ */
4
+
5
+
6
  jQuery(document).ready(function ($) {
7
 
8
  /**
libs/eps-plugin-options.php CHANGED
@@ -1,16 +1,15 @@
1
  <?php
2
  /**
3
  *
4
- * Plugin Options Handler - Customized for EPS 301 Redirects
5
  *
6
  * @author Shawn Wernig, Eggplant Studios, www.eggplantstudios.ca
7
- * @version 1.0.5
8
  * @copyright 2015 Eggplant Studios
9
  * @package EPS Boilerplate
10
  *
11
  *
12
  */
13
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
14
 
15
  if( ! class_exists('EPS_Redirects_Plugin_Options') )
16
  {
1
  <?php
2
  /**
3
  *
4
+ * Plugin Options Handler
5
  *
6
  * @author Shawn Wernig, Eggplant Studios, www.eggplantstudios.ca
7
+ * @version 1.0.0
8
  * @copyright 2015 Eggplant Studios
9
  * @package EPS Boilerplate
10
  *
11
  *
12
  */
 
13
 
14
  if( ! class_exists('EPS_Redirects_Plugin_Options') )
15
  {
plugin.php CHANGED
@@ -6,7 +6,6 @@
6
  *
7
  *
8
  */
9
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
10
 
11
 
12
 
@@ -40,7 +39,7 @@ class EPS_Redirects_Plugin {
40
 
41
 
42
  protected $options;
43
-
44
 
45
  public function __construct()
46
  {
@@ -63,7 +62,6 @@ class EPS_Redirects_Plugin {
63
  add_action( 'import-export_admin_tab', array($this, 'admin_tab_import_export'), 10, 1 );
64
  add_action( 'eps_redirects_panels_left', array($this, 'admin_panel_cache'));
65
  add_action( 'eps_redirects_panels_right', array($this, 'admin_panel_donate'));
66
- add_action( 'eps_redirects_admin_head', array($this, 'admin_header_notices'));
67
 
68
  // Actions
69
  add_action( 'admin_init', array($this, 'check_plugin_actions'));
@@ -103,6 +101,13 @@ class EPS_Redirects_Plugin {
103
  }
104
  public static function _deactivation() {}
105
 
 
 
 
 
 
 
 
106
  /**
107
  *
108
  * update_self
@@ -119,7 +124,7 @@ class EPS_Redirects_Plugin {
119
 
120
  if( version_compare($version, '2.0.0', '<')) {
121
  // migrate old format to new format.
122
- $this->_migrate_to_v2();
123
  }
124
  $this->set_current_version( EPS_REDIRECT_VERSION );
125
  return EPS_REDIRECT_VERSION;
@@ -135,8 +140,8 @@ class EPS_Redirects_Plugin {
135
  * @author epstudios
136
  *
137
  */
138
- protected function _migrate_to_v2() {
139
- $redirects = get_option( 'eps_redirects' );
140
 
141
  if (empty($redirects)) return false; // No redirects to migrate.
142
 
@@ -193,7 +198,7 @@ class EPS_Redirects_Plugin {
193
  *
194
  * plugin_resources
195
  *
196
- * Enqueues the resources
197
  *
198
  * @return nothing
199
  * @author epstudios
@@ -209,6 +214,21 @@ class EPS_Redirects_Plugin {
209
  wp_enqueue_script('eps_redirect_script', EPS_REDIRECT_URL .'js/scripts.js');
210
  wp_enqueue_style('eps_redirect_styles', EPS_REDIRECT_URL .'css/eps_redirect.css');
211
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
212
  }
213
 
214
  /**
@@ -229,27 +249,32 @@ class EPS_Redirects_Plugin {
229
  self::_upload();
230
  }
231
  // Export a CSV
232
- if( isset($_POST['eps_redirect_export']) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
 
233
  self::export_csv();
234
  }
235
 
236
  // Refresh the Transient Cache
237
- if ( isset( $_POST['eps_redirect_refresh'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
 
238
  $post_types = get_post_types(array('public'=>true), 'objects');
239
- foreach ($post_types as $post_type ) {
 
240
  $options = eps_dropdown_pages( array('post_type'=>$post_type->name ) );
241
  set_transient( 'post_type_cache_'.$post_type->name, $options, HOUR_IN_SECONDS );
242
  }
243
- add_action( 'admin_notices', array($this, 'admin_notice_refresh_cache') );
244
  }
245
 
246
  // Save Redirects
247
- if ( isset( $_POST['eps_redirect_submit'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
 
248
  self::_save_redirects( EPS_Redirects::_parse_serial_array($_POST['redirect']) );
249
  }
250
 
251
  // Create tables
252
- if( isset($_GET['action']) && $_GET['action'] == 'eps_create_tables' ) {
 
253
  $result = self::_create_redirect_table();
254
  }
255
  }
@@ -304,17 +329,41 @@ class EPS_Redirects_Plugin {
304
  */
305
  private function _upload() {
306
  $new_redirects = array();
307
- $mimes = array('application/vnd.ms-excel','text/plain','text/csv','text/tsv');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
308
  ini_set('auto_detect_line_endings',TRUE);
309
 
310
  if( !in_array($_FILES['eps_redirect_upload_file']['type'], $mimes) ) {
311
- add_action( 'admin_notices', array($this, 'admin_notice_bad_csv') );
 
 
312
  return false;
313
  }
314
 
315
  // open the file.
316
  if (($handle = fopen($_FILES['eps_redirect_upload_file']['tmp_name'], "r")) !== FALSE)
317
  {
 
318
  while (($redirect = fgetcsv($handle, 0, ",")) !== FALSE)
319
  {
320
  $redirect = array_filter($redirect);
@@ -323,9 +372,15 @@ class EPS_Redirects_Plugin {
323
 
324
  $args = count($redirect);
325
 
326
- if( $args > 4 || $args < 2 ) {
 
327
  // Bad line. Too many/few arguments.
328
- add_action( 'admin_notices', array($this, 'admin_notice_bad_csv_entry') );
 
 
 
 
 
329
  continue;
330
  }
331
 
@@ -360,7 +415,7 @@ class EPS_Redirects_Plugin {
360
  );
361
 
362
  array_push($new_redirects, $new_redirect);
363
-
364
  }
365
  fclose($handle); // close file.
366
  }
@@ -378,17 +433,29 @@ class EPS_Redirects_Plugin {
378
  if( ! EPS_Redirects::redirect_exists( $redirect ) )
379
  {
380
  $save_redirects[] = $redirect;
 
 
 
 
 
381
  }
382
  break;
383
  case 'update':
384
  if( $entry = EPS_Redirects::redirect_exists( $redirect ) )
385
  {
386
  $redirect['id'] = $entry->id;
 
 
 
 
 
 
 
387
  }
388
- $save_redirects[] = $redirect;
389
  break;
390
  default:
391
  $save_redirects[] = $redirect;
 
392
  break;
393
  }
394
  }
@@ -396,17 +463,21 @@ class EPS_Redirects_Plugin {
396
  if( ! empty( $save_redirects ) )
397
  {
398
  EPS_Redirects::_save_redirects( $save_redirects );
399
- add_action( 'admin_notices', array($this, 'admin_notice_upload_success') );
400
- }
401
- else
402
- {
403
- add_action( 'admin_notices', array($this, 'admin_notice_upload_success_no_new') );
404
  }
405
 
 
 
 
 
 
 
 
 
 
406
  }
407
  else
408
  {
409
- add_action( 'admin_notices', array($this, 'admin_notice_upload_error') );
410
  }
411
  ini_set('auto_detect_line_endings',FALSE);
412
  }
@@ -446,26 +517,6 @@ class EPS_Redirects_Plugin {
446
  include ( EPS_REDIRECT_PATH . 'templates/admin-tab-error.php' );
447
  }
448
 
449
- public static function admin_header_notices()
450
- {
451
- global $wp_rewrite;
452
- global $wpdb;
453
- $table_name = $wpdb->prefix . "redirects";
454
- if( !isset($wp_rewrite->permalink_structure) || empty($wp_rewrite->permalink_structure) ) {
455
- echo '<div class="error clear"><div class="eps-padding">';
456
- echo '<strong>WARNING:</strong> EPS 301 Redirects requires that a permalink structure is set. The Default Wordpress permalink structure is not compatible. Please update the <a href="options-permalink.php" title="Permalinks">Permalink Structure</a>.</div>';
457
- echo '</div></div>';
458
- }
459
-
460
- if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
461
- {
462
- $url = admin_url('options-general.php?page=eps_redirects');
463
- echo '<div class="error clear"><div class="eps-padding">';
464
- echo '<strong>WARNING:</strong> It looks like we need to <a href="'.$url.'&action=eps_create_tables" title="Permalinks">Create the Database Tables First!</a></div>';
465
- echo '</div></div>'; }
466
-
467
- }
468
-
469
 
470
  /**
471
  *
@@ -519,35 +570,35 @@ class EPS_Redirects_Plugin {
519
  * @author epstudios
520
  *
521
  */
522
- function admin_notice_tables() {
523
- $this->admin_notice('SUCCESS: Table has been created. Happy redirecting!', "success");
 
 
524
  }
 
 
 
 
 
 
 
 
 
525
 
526
- function admin_notice_bad_csv() {
527
- $this->admin_notice("WARNING: Not a valid CSV file! No new redirects have been added.", "error");
528
- }
529
- function admin_notice_upload_success() {
530
- $this->admin_notice("SUCCCESS: New redirects have been added.");
531
- }
532
- function admin_notice_upload_success_no_new() {
533
- $this->admin_notice("SUCCCESS: But no new redirects have been added. (Possibly Duplicates?)");
534
- }
535
- function admin_notice_upload_error() {
536
- $this->admin_notice("WARNING: Something's up. No new redirects were added, please review your CSV file.", "error");
537
- }
538
- function admin_notice_bad_csv_entry() {
539
- $this->admin_notice("WARNING: Encountered a bad Redirect entry in your CSV file.", "error");
540
- }
541
- function admin_notice_refresh_cache() {
542
- $this->admin_notice("SUCCCESS: Cache Refreshed.");
543
  }
544
- protected function admin_notice( $string, $type = "updated" ) {
545
  printf('<div class="%s"><p>%s</p></div>',
546
- $type,
547
- $string
548
  );
549
  }
550
-
551
  }
552
 
553
  // Init the plugin.
6
  *
7
  *
8
  */
 
9
 
10
 
11
 
39
 
40
 
41
  protected $options;
42
+ protected $messages = array();
43
 
44
  public function __construct()
45
  {
62
  add_action( 'import-export_admin_tab', array($this, 'admin_tab_import_export'), 10, 1 );
63
  add_action( 'eps_redirects_panels_left', array($this, 'admin_panel_cache'));
64
  add_action( 'eps_redirects_panels_right', array($this, 'admin_panel_donate'));
 
65
 
66
  // Actions
67
  add_action( 'admin_init', array($this, 'check_plugin_actions'));
101
  }
102
  public static function _deactivation() {}
103
 
104
+
105
+ public function admin_url( $vars = array() )
106
+ {
107
+ $vars = array( 'page' => $this->config['page_slug'] ) + $vars;
108
+ $url = 'options-general.php?' . http_build_query( $vars );
109
+ return admin_url( $url );
110
+ }
111
  /**
112
  *
113
  * update_self
124
 
125
  if( version_compare($version, '2.0.0', '<')) {
126
  // migrate old format to new format.
127
+ add_action('admin_init', array($this, '_migrate_to_v2'), 1 );
128
  }
129
  $this->set_current_version( EPS_REDIRECT_VERSION );
130
  return EPS_REDIRECT_VERSION;
140
  * @author epstudios
141
  *
142
  */
143
+ public static function _migrate_to_v2() {
144
+ $redirects = get_option( self::$option_slug );
145
 
146
  if (empty($redirects)) return false; // No redirects to migrate.
147
 
198
  *
199
  * plugin_resources
200
  *
201
+ * Enqueues the resources, and makes sure we have what we need to proceed.
202
  *
203
  * @return nothing
204
  * @author epstudios
214
  wp_enqueue_script('eps_redirect_script', EPS_REDIRECT_URL .'js/scripts.js');
215
  wp_enqueue_style('eps_redirect_styles', EPS_REDIRECT_URL .'css/eps_redirect.css');
216
  }
217
+
218
+ global $wp_rewrite;
219
+ if( !isset($wp_rewrite->permalink_structure) || empty($wp_rewrite->permalink_structure) )
220
+ {
221
+ $EPS_Redirects_Plugin->add_admin_message('WARNING: EPS 301 Redirects requires that a permalink structure is set. The Default Wordpress permalink structure is not compatible. Please update the <a href="options-permalink.php" title="Permalinks">Permalink Structure</a>', "error" );
222
+ }
223
+
224
+ global $wpdb;
225
+ $table_name = $wpdb->prefix . "redirects";
226
+ if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name)
227
+ {
228
+ $url = $EPS_Redirects_Plugin->admin_url( array('action' => 'eps_create_tables') );
229
+ $EPS_Redirects_Plugin->add_admin_message('WARNING: It looks like we need to <a href="'.$url.'" title="Permalinks">Create the Database Tables First!</a>', "error" );
230
+ }
231
+
232
  }
233
 
234
  /**
249
  self::_upload();
250
  }
251
  // Export a CSV
252
+ if( isset($_POST['eps_redirect_export']) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') )
253
+ {
254
  self::export_csv();
255
  }
256
 
257
  // Refresh the Transient Cache
258
+ if ( isset( $_POST['eps_redirect_refresh'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') )
259
+ {
260
  $post_types = get_post_types(array('public'=>true), 'objects');
261
+ foreach ($post_types as $post_type )
262
+ {
263
  $options = eps_dropdown_pages( array('post_type'=>$post_type->name ) );
264
  set_transient( 'post_type_cache_'.$post_type->name, $options, HOUR_IN_SECONDS );
265
  }
266
+ $this->add_admin_message("SUCCCESS: Cache Refreshed.", "updated" );
267
  }
268
 
269
  // Save Redirects
270
+ if ( isset( $_POST['eps_redirect_submit'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') )
271
+ {
272
  self::_save_redirects( EPS_Redirects::_parse_serial_array($_POST['redirect']) );
273
  }
274
 
275
  // Create tables
276
+ if( isset($_GET['action']) && $_GET['action'] == 'eps_create_tables' )
277
+ {
278
  $result = self::_create_redirect_table();
279
  }
280
  }
329
  */
330
  private function _upload() {
331
  $new_redirects = array();
332
+
333
+ $counter = array(
334
+ 'new' => 0,
335
+ 'updated' => 0,
336
+ 'skipped' => 0,
337
+ 'errors' => 0,
338
+ 'total' => 0
339
+ );
340
+
341
+ $mimes = array(
342
+ 'text/csv',
343
+ 'text/tsv',
344
+ 'text/plain',
345
+ 'application/csv',
346
+ 'text/comma-separated-values',
347
+ 'application/excel',
348
+ 'application/vnd.ms-excel',
349
+ 'application/vnd.msexcel',
350
+ 'text/anytext',
351
+ 'application/octet-stream',
352
+ 'application/txt'
353
+ );
354
  ini_set('auto_detect_line_endings',TRUE);
355
 
356
  if( !in_array($_FILES['eps_redirect_upload_file']['type'], $mimes) ) {
357
+ $this->add_admin_message(sprintf("WARNING: Not a valid CSV file - the Mime Type '%s' is wrong! No new redirects have been added.",
358
+ $_FILES['eps_redirect_upload_file']['type']
359
+ ), "error" );
360
  return false;
361
  }
362
 
363
  // open the file.
364
  if (($handle = fopen($_FILES['eps_redirect_upload_file']['tmp_name'], "r")) !== FALSE)
365
  {
366
+ $counter['total'] = 1;
367
  while (($redirect = fgetcsv($handle, 0, ",")) !== FALSE)
368
  {
369
  $redirect = array_filter($redirect);
372
 
373
  $args = count($redirect);
374
 
375
+ if( $args > 4 || $args < 2 )
376
+ {
377
  // Bad line. Too many/few arguments.
378
+ $this->add_admin_message(
379
+ sprintf("WARNING: Encountered a badly formed entry in your CSV file on line %d (we skipped it).",
380
+ $counter['total']
381
+ ),
382
+ "error" );
383
+ $counter['errors'] ++;
384
  continue;
385
  }
386
 
415
  );
416
 
417
  array_push($new_redirects, $new_redirect);
418
+ $counter['total'] ++;
419
  }
420
  fclose($handle); // close file.
421
  }
433
  if( ! EPS_Redirects::redirect_exists( $redirect ) )
434
  {
435
  $save_redirects[] = $redirect;
436
+ $counter['new'] ++;
437
+ }
438
+ else
439
+ {
440
+ $counter['skipped'] ++;
441
  }
442
  break;
443
  case 'update':
444
  if( $entry = EPS_Redirects::redirect_exists( $redirect ) )
445
  {
446
  $redirect['id'] = $entry->id;
447
+ $counter['updated'] ++;
448
+ $save_redirects[] = $redirect;
449
+ }
450
+ else
451
+ {
452
+ $save_redirects[] = $redirect;
453
+ $counter['new'] ++;
454
  }
 
455
  break;
456
  default:
457
  $save_redirects[] = $redirect;
458
+ $counter['new'] ++;
459
  break;
460
  }
461
  }
463
  if( ! empty( $save_redirects ) )
464
  {
465
  EPS_Redirects::_save_redirects( $save_redirects );
 
 
 
 
 
466
  }
467
 
468
+ $this->add_admin_message(sprintf(
469
+ "SUCCCESS: %d New Redirects, %d Updated, %d Skipped, %d Errors. (Attempted to import %d redirects).",
470
+ $counter['new'],
471
+ $counter['updated'],
472
+ $counter['skipped'],
473
+ $counter['errors'],
474
+ $counter['total']
475
+ ), "updated" );
476
+
477
  }
478
  else
479
  {
480
+ $this->add_admin_message("WARNING: Something's up. No new redirects were added, please review your CSV file.", "error" );
481
  }
482
  ini_set('auto_detect_line_endings',FALSE);
483
  }
517
  include ( EPS_REDIRECT_PATH . 'templates/admin-tab-error.php' );
518
  }
519
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
520
 
521
  /**
522
  *
570
  * @author epstudios
571
  *
572
  */
573
+ protected function add_admin_message( $message, $code )
574
+ {
575
+ $this->messages[] = array( $code => $message );
576
+ add_action( 'admin_notices', array($this, 'display_admin_messages') );
577
  }
578
+ public static function display_admin_messages()
579
+ {
580
+ global $EPS_Redirects_Plugin;
581
+ if( is_array( $EPS_Redirects_Plugin->messages ) && ! empty( $EPS_Redirects_Plugin->messages ) )
582
+ {
583
+ foreach( $EPS_Redirects_Plugin->messages as $entry )
584
+ {
585
+ $code = key($entry);
586
+ $message = reset($entry);
587
 
588
+ if( ! in_array($code, array('error','updated') ) )
589
+ {
590
+ $code = 'updated';
591
+ }
592
+ $EPS_Redirects_Plugin->admin_notice( $message, $code);
593
+ }
594
+ }
 
 
 
 
 
 
 
 
 
 
595
  }
596
+ public function admin_notice( $string, $type = "updated" ) {
597
  printf('<div class="%s"><p>%s</p></div>',
598
+ $type,
599
+ $string
600
  );
601
  }
 
602
  }
603
 
604
  // Init the plugin.
readme.txt CHANGED
@@ -10,7 +10,7 @@ Requires at least: 3.0.1
10
 
11
  Tested up to: 4.2.1
12
 
13
- Stable tag: 2.2.8
14
 
15
  License: GPLv2 or later
16
 
@@ -116,7 +116,10 @@ By default, any URL with a query string is considered unique, and will redirect
116
 
117
  == Changelog ==
118
 
119
- = 2.2.8 =
 
 
 
120
  That silly bug with the database tables not being created has been squashed. Improved query performance.
121
 
122
  = 2.2.6 =
@@ -176,7 +179,11 @@ Overhauled the entire plugin. Redirects are stored in their own table. Gracefull
176
 
177
  == Upgrade Notice ==
178
 
179
- = 2.2.8 =
 
 
 
 
180
  That silly bug with the database tables not being created has been squashed. Improved query performance.
181
 
182
  = 2.2.6 =
10
 
11
  Tested up to: 4.2.1
12
 
13
+ Stable tag: 2.3.0
14
 
15
  License: GPLv2 or later
16
 
116
 
117
  == Changelog ==
118
 
119
+ = 2.3.0 =
120
+ Added sorting. Fixed a bug when upgrading from V1 to V2, and the infamous "Invalid Destination" url.
121
+
122
+ = 2.2.7 =
123
  That silly bug with the database tables not being created has been squashed. Improved query performance.
124
 
125
  = 2.2.6 =
179
 
180
  == Upgrade Notice ==
181
 
182
+ = 2.3.0 =
183
+ Added sorting. Fixed a bug when upgrading from V1 to V2, and the infamous "Invalid Destination" url.
184
+
185
+
186
+ = 2.2.7 =
187
  That silly bug with the database tables not being created has been squashed. Improved query performance.
188
 
189
  = 2.2.6 =
templates/admin-panel-cache.php CHANGED
@@ -8,8 +8,6 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
-
13
  ?>
14
 
15
  <div class="eps-panel eps-margin-top">
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
  ?>
12
 
13
  <div class="eps-panel eps-margin-top">
templates/admin-panel-donate.php CHANGED
@@ -8,8 +8,6 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
-
13
  ?>
14
 
15
 
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
  ?>
12
 
13
 
templates/admin-tab-404s.php CHANGED
@@ -8,8 +8,6 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
-
13
  ?>
14
 
15
  <div class="wrap">
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
  ?>
12
 
13
  <div class="wrap">
templates/admin-tab-error.php CHANGED
@@ -8,8 +8,6 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
-
13
  ?>
14
 
15
 
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
  ?>
12
 
13
 
templates/admin-tab-import-export.php CHANGED
@@ -8,8 +8,6 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
-
13
  ?>
14
 
15
  <div class="wrap">
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
  ?>
12
 
13
  <div class="wrap">
templates/admin-tab-redirects.php CHANGED
@@ -8,7 +8,8 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
 
12
 
13
  ?>
14
 
@@ -18,13 +19,14 @@ if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
18
 
19
  <table id="eps-redirect-entries" class="eps-table eps-table-striped">
20
  <tr>
21
- <th>Request URL</th>
22
- <th>Redirect To</th>
23
- <th class="redirect-hits">Hits</th>
 
24
  <th class="redirect-actions">Actions</th>
25
  </tr>
26
 
27
- <tr id="eps-redirect-add" style="display:none"><td colspan="4"><a href="#" id="eps-redirect-new"><span>+</span></a></td></tr>
28
 
29
  <?php
30
  echo EPS_Redirects::get_inline_edit_entry();
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
+ global $EPS_Redirects_Plugin;
12
+
13
 
14
  ?>
15
 
19
 
20
  <table id="eps-redirect-entries" class="eps-table eps-table-striped">
21
  <tr>
22
+ <th class="redirect-small"> <?php eps_get_ordered_filter('id', 'ID'); ?> </th>
23
+ <th> <?php eps_get_ordered_filter('url_from', 'Redirect From'); ?> </th>
24
+ <th> <?php eps_get_ordered_filter('url_to', 'Redirect To'); ?> </th>
25
+ <th class="redirect-small"> <?php eps_get_ordered_filter('count', 'Hits'); ?> </th>
26
  <th class="redirect-actions">Actions</th>
27
  </tr>
28
 
29
+ <tr id="eps-redirect-add" style="display:none"><td colspan="5"><a href="#" id="eps-redirect-new"><span>+</span></a></td></tr>
30
 
31
  <?php
32
  echo EPS_Redirects::get_inline_edit_entry();
templates/template.redirect-entry-edit-inline.php CHANGED
@@ -9,11 +9,10 @@
9
  *
10
  */
11
 
12
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
13
 
14
  ?>
15
  <tr id="eps-redirect-edit">
16
- <td colspan="4">
17
  <form id="eps-redirect-save" method="post" action="">
18
  <table class="eps-table">
19
  <tr class="id-<?php echo ($redirect_id) ? $redirect_id : 'new'; ?>">
9
  *
10
  */
11
 
 
12
 
13
  ?>
14
  <tr id="eps-redirect-edit">
15
+ <td colspan="5">
16
  <form id="eps-redirect-save" method="post" action="">
17
  <table class="eps-table">
18
  <tr class="id-<?php echo ($redirect_id) ? $redirect_id : 'new'; ?>">
templates/template.redirect-entry-edit.php CHANGED
@@ -8,8 +8,6 @@
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
11
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
12
-
13
 
14
  $redirect = self::get_redirect( $redirect_id );
15
 
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
  */
 
 
11
 
12
  $redirect = self::get_redirect( $redirect_id );
13
 
templates/template.redirect-entry.php CHANGED
@@ -7,8 +7,6 @@
7
  * @package EPS 301 Redirects
8
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
9
  */
10
- if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
11
-
12
 
13
  global $EPS_Redirects_Plugin;
14
  $query_args = array( 'page' => $EPS_Redirects_Plugin->config('page_slug'), 'delete_redirect' => esc_attr( $redirect->id ) );
@@ -16,6 +14,9 @@ $query_args = array( 'page' => $EPS_Redirects_Plugin->config('page_slug'), 'dele
16
 
17
  ?>
18
  <tr class="redirect-entry <?php echo esc_attr( $redirect->status ); ?> id-<?php echo esc_attr( $redirect->id ); ?>" data-id="<?php echo esc_attr( $redirect->id ); ?>" data-status="<?php echo esc_attr( $redirect->status ); ?>">
 
 
 
19
  <td>
20
  <a target="_blank" class="eps-url" href="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>" title="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>">
21
  <span class="eps-url-root eps-url-startcap"><?php echo ($redirect->status == 'inactive' ) ? 'OFF': esc_attr($redirect->status); ?></span><span class="eps-url-root"><?php bloginfo('url'); ?>/</span><span class="eps-url-fragment eps-url-endcap"><?php echo esc_attr($dfrom); ?></span>
7
  * @package EPS 301 Redirects
8
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
9
  */
 
 
10
 
11
  global $EPS_Redirects_Plugin;
12
  $query_args = array( 'page' => $EPS_Redirects_Plugin->config('page_slug'), 'delete_redirect' => esc_attr( $redirect->id ) );
14
 
15
  ?>
16
  <tr class="redirect-entry <?php echo esc_attr( $redirect->status ); ?> id-<?php echo esc_attr( $redirect->id ); ?>" data-id="<?php echo esc_attr( $redirect->id ); ?>" data-status="<?php echo esc_attr( $redirect->status ); ?>">
17
+ <td>
18
+ <p class="eps-grey-text eps-text-center eps-small"><?php echo $redirect->id; ?></p>
19
+ </td>
20
  <td>
21
  <a target="_blank" class="eps-url" href="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>" title="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>">
22
  <span class="eps-url-root eps-url-startcap"><?php echo ($redirect->status == 'inactive' ) ? 'OFF': esc_attr($redirect->status); ?></span><span class="eps-url-root"><?php bloginfo('url'); ?>/</span><span class="eps-url-fragment eps-url-endcap"><?php echo esc_attr($dfrom); ?></span>