Eggplant 301 Redirects - Version 2.2.0

Version Description

Minor bug fixes. Greatly improved import feature. Redirects include query strings. Export feature added. Http/Https agnostic. Pro version added with 404 management.

Download this release

Release Info

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

Code changes from version 2.1.2 to 2.2.0

class.drop-down-pages.php CHANGED
@@ -9,8 +9,8 @@
9
  * @param array|string $args Optional. Override default arguments.
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(
@@ -67,9 +67,10 @@ class EPS_Walker_PageDropdown extends Walker {
67
  var $tree_type = 'page';
68
  var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
69
 
70
- function start_el(&$output, $page, $depth, $args, $id = 0) {
 
71
  $pad = str_repeat(' ', $depth * 3);
72
- $output[$page->ID] = $pad . esc_html( apply_filters( 'list_pages', $page->post_title, $page ) );
73
  }
74
  }
75
  }
9
  * @param array|string $args Optional. Override default arguments.
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(
67
  var $tree_type = 'page';
68
  var $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
69
 
70
+ function start_el(&$output, $object, $depth = 0, $args = Array(), $current_object_id = 0)
71
+ {
72
  $pad = str_repeat(' ', $depth * 3);
73
+ $output[$object->ID] = $pad . esc_html( apply_filters( 'list_pages', $object->post_title, $object ) );
74
  }
75
  }
76
  }
css/eps_redirect.css CHANGED
@@ -1,42 +1,57 @@
1
  /*----------------------------------------------------------*/
2
  /*--------------------- Entries Table ----------------------*/
3
  /*----------------------------------------------------------*/
4
- .eps-col1 { width: 40%; float: left; }
5
- .eps-col3 { width: 60%; float: left; }
6
-
7
 
8
  .eps-table {
9
  width: 100%;
10
  table-layout:fixed;
11
- }
12
 
13
- .eps-table .eps-table tr, #eps-redirect-save tr { background: #fefefe; }
14
- #eps-redirect-save, .eps-table .eps-table { border: 1px solid #eeeeee; }
 
 
 
 
 
 
 
15
 
16
- #eps-redirect-entries { border: 1px solid #eeeeee; }
17
- .eps-table td,
18
- .eps-table th { padding: 5px; text-align: left; overflow: hidden; }
19
 
20
- .eps-table th {
21
- padding: 6px 10px;
22
- background: #2A95C5;
23
- color:#FFFFFF;
24
- }
25
-
26
 
27
  .eps-table tr {
28
  background: #fcfcfc;
29
  }
30
- .eps-table tr.active { display: none; }
 
 
 
31
  .eps-table.eps-table-striped tr:nth-child(even) {
32
  background: #fafafa;
33
  }
34
 
 
 
 
 
 
 
35
 
36
- .eps-table td.redirect-hits, .eps-table th.redirect-hits { width: 26px; text-align: center; padding-left: 4px; padding-right: 4px; }
37
- .eps-table td.redirect-actions, .eps-table th.redirect-actions { width: 120px; }
38
-
 
 
39
 
 
 
 
 
 
 
 
 
 
40
 
41
 
42
  /*----------------------------------------------------------*/
@@ -93,38 +108,9 @@
93
  }
94
 
95
  .url-input { display: inline-block; width: 350px; max-width: 100%; }
96
- select.eps-small-select { display: inline-block; }
97
-
98
- /*----------------------------------------------------------*/
99
- /*--------------------------- tabs -------------------------*/
100
- /*----------------------------------------------------------*/
101
-
102
- #eps-tabs { padding: 12px 32px; border: 1px solid #d6d6d6; background: white; box-shadow: 1px 1px 6px #f4f4f4; }
103
 
104
- #eps-tab-nav { margin-top: 32px; }
105
- #eps-tab-nav a, #eps-tab-nav a:link, #eps-tab-nav a:visited {
106
- display: inline-block;
107
- border: 1px solid #d6d6d6;
108
- padding: 16px 32px;
109
- background: #fafafa;
110
- text-decoration: none;
111
- font-size: 16px; font-weight: bold;
112
- position: relative; bottom: 0px;
113
- -webkit-transition: all 100ms;
114
- }
115
-
116
- #eps-tab-nav a.active, #eps-tab-nav a:hover{
117
- background: white;
118
- position: relative;
119
- bottom: -1px;
120
- padding: 20px 32px;
121
- background: white;
122
- border-bottom: none;
123
- }
124
- #eps-tabs .eps-tab { display: none; }
125
- #eps-tabs .eps-tab:first-child { display: block; }
126
 
127
- #eps-tabs .eps-tab hr { border-top: 1px solid #eeeeee; margin: 16px 0px; }
128
 
129
  /*----------------------------------------------------------*/
130
  /*-------------------------- misc ------------------------*/
@@ -184,11 +170,57 @@ select.eps-small-select { display: inline-block; }
184
  }
185
  .eps-url .eps-url-nopadding { padding: 0px; }
186
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
  /*----------------------------------------------------------*/
188
  /*------------------------ donate ------------------------*/
189
  /*----------------------------------------------------------*/
190
 
191
- .eps-panel { border: 1px solid #d6d6d6; background: white; box-shadow: 1px 1px 6px #f4f4f4; }
192
 
193
  #donate-box {
194
  border: 1px solid #d6d6d6; background: white; box-shadow: 1px 1px 6px #f4f4f4;
@@ -204,6 +236,14 @@ select.eps-small-select { display: inline-block; }
204
  /*------------------------ Helpers ------------------------*/
205
  /*----------------------------------------------------------*/
206
 
 
 
 
 
 
 
 
 
207
 
208
  /* Contain floats: nicolasgallagher.com/micro-group-hack/ */
209
  .group:before, .group:after { content: ""; display: table; }
@@ -214,6 +254,13 @@ select.eps-small-select { display: inline-block; }
214
  .left { float: left; }
215
 
216
  .text-right { text-align: right; }
 
 
 
 
 
 
 
217
  /*----------------------------------------------------------*/
218
  /*-------------------- media queries ---------------------*/
219
  /*----------------------------------------------------------*/
1
  /*----------------------------------------------------------*/
2
  /*--------------------- Entries Table ----------------------*/
3
  /*----------------------------------------------------------*/
 
 
 
4
 
5
  .eps-table {
6
  width: 100%;
7
  table-layout:fixed;
8
+ }
9
 
10
+ .eps-table .eps-table tr, #eps-redirect-save tr {
11
+ background: #fefefe;
12
+ }
13
+
14
+ #eps-redirect-save,
15
+ #eps-redirect-entries,
16
+ .eps-table .eps-table {
17
+ border: 1px solid #eeeeee;
18
+ }
19
 
 
 
 
20
 
 
 
 
 
 
 
21
 
22
  .eps-table tr {
23
  background: #fcfcfc;
24
  }
25
+ .eps-table tr.active {
26
+ display: none;
27
+ }
28
+
29
  .eps-table.eps-table-striped tr:nth-child(even) {
30
  background: #fafafa;
31
  }
32
 
33
+ .eps-table td,
34
+ .eps-table th {
35
+ padding: 5px;
36
+ text-align: left;
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;
51
+ }
52
+ .eps-table td.redirect-actions, .eps-table th.redirect-actions {
53
+ width: 120px;
54
+ }
55
 
56
 
57
  /*----------------------------------------------------------*/
108
  }
109
 
110
  .url-input { display: inline-block; width: 350px; max-width: 100%; }
 
 
 
 
 
 
 
111
 
112
+ select.eps-small-select { display: inline-block; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
 
 
114
 
115
  /*----------------------------------------------------------*/
116
  /*-------------------------- misc ------------------------*/
170
  }
171
  .eps-url .eps-url-nopadding { padding: 0px; }
172
 
173
+
174
+ /*----------------------------------------------------------*/
175
+ /*------------------------ upgrade ------------------------*/
176
+ /*----------------------------------------------------------*/
177
+
178
+ .eps-redirects-big-button,
179
+ .eps-redirects-big-button:link,
180
+ .eps-redirects-big-button:hover
181
+ {
182
+ display: block;
183
+ padding: 32px 16px;
184
+ text-align: center;
185
+ background: #444444;
186
+ color: #bbbbbb;
187
+ color: white;
188
+ text-decoration: none;
189
+ font-size: 16px;
190
+ transition: all 600ms;
191
+ }
192
+ .eps-redirects-big-button:hover {
193
+ background: #333333;
194
+ color: #ffffff;
195
+ }
196
+ #eps-redirects-checklist {
197
+ margin-top: 16px;
198
+ }
199
+ #eps-redirects-checklist,
200
+ #eps-redirects-checklist li {
201
+ display: block;
202
+ list-style: none;
203
+ }
204
+ #eps-redirects-checklist li
205
+ {
206
+ border: 1px solid #eeeeee;
207
+ background: url('../images/icon-check.png') left center no-repeat;
208
+ padding: 16px;
209
+ padding-left: 72px;
210
+ }
211
+ #eps-redirects-checklist li > span
212
+ {
213
+ border-left: 1px solid #dddddd;
214
+ display: inline-block;
215
+ padding: 16px;
216
+ font-size: 18px; line-height: 150%;
217
+ }
218
+
219
  /*----------------------------------------------------------*/
220
  /*------------------------ donate ------------------------*/
221
  /*----------------------------------------------------------*/
222
 
223
+ .eps-panel { border: 1px solid #d6d6d6; background: white; box-shadow: 1px 1px 6px #f4f4f4; padding: 20px; }
224
 
225
  #donate-box {
226
  border: 1px solid #d6d6d6; background: white; box-shadow: 1px 1px 6px #f4f4f4;
236
  /*------------------------ Helpers ------------------------*/
237
  /*----------------------------------------------------------*/
238
 
239
+ .eps-redirects-50 {
240
+ width: 50%;
241
+ margin: 0px; padding: 0px;
242
+ float: left;
243
+ }
244
+ .eps-redirects-lead {
245
+ font-size: 18px;
246
+ }
247
 
248
  /* Contain floats: nicolasgallagher.com/micro-group-hack/ */
249
  .group:before, .group:after { content: ""; display: table; }
254
  .left { float: left; }
255
 
256
  .text-right { text-align: right; }
257
+
258
+ .eps-redirects-fit {
259
+ display: block; max-width: 100%; width: 100%;
260
+ }
261
+
262
+ .padding { padding: 16px; }
263
+ .padding-lots { padding: 32px; }
264
  /*----------------------------------------------------------*/
265
  /*-------------------- media queries ---------------------*/
266
  /*----------------------------------------------------------*/
eps-301-redirects.php CHANGED
@@ -15,41 +15,41 @@
15
  *
16
  * @package EPS 301 Redirects
17
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
18
- * @version 2.1.2
19
  */
20
 
21
 
22
-
23
 
24
  /*
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.1.2
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
32
  */
33
 
34
- define ( 'EPS_REDIRECT_PATH', plugin_dir_path(__FILE__) );
35
- define ( 'EPS_REDIRECT_URL', plugin_dir_url( __FILE__ ) );
36
- define ( 'EPS_REDIRECT_VERSION', '2.1.2');
37
 
38
- register_activation_hook(__FILE__, array('EPS_Redirects', 'eps_redirect_activation'));
39
- register_deactivation_hook(__FILE__, array('EPS_Redirects', 'eps_redirect_deactivation'));
40
 
41
- include(EPS_REDIRECT_PATH.'eps-form-elements.php');
42
- include(EPS_REDIRECT_PATH.'class.drop-down-pages.php');
 
 
43
 
44
- class EPS_Redirects {
45
-
46
- static $option_slug = 'eps_redirects';
47
- static $option_section_slug = 'eps_redirects_list';
48
- static $page_slug = 'eps_redirects';
49
- static $page_title = '301 Redirects';
50
 
51
 
52
 
 
 
53
  /**
54
  *
55
  * Constructor
@@ -58,169 +58,38 @@ class EPS_Redirects {
58
  *
59
  */
60
  public function __construct(){
61
- if(is_admin()){
62
-
63
- // actions
64
- add_action('activated_plugin', array($this,'activation_error'));
65
- add_action('admin_menu', array($this, 'add_plugin_page'));
66
- add_action('admin_init', array($this, '_save'));
67
- add_action('init', array($this, 'enqueue_resources'));
68
- add_action('admin_footer_text', array($this, 'set_ajax_url'));
 
 
 
 
 
 
 
 
69
 
70
  // Ajax funcs
71
  add_action('wp_ajax_eps_redirect_get_new_entry', array($this, 'ajax_get_entry') );
72
  add_action('wp_ajax_eps_redirect_delete_entry', array($this, 'ajax_eps_delete_entry') );
73
  add_action('wp_ajax_eps_redirect_get_inline_edit_entry', array($this, 'ajax_get_inline_edit_entry') );
74
  add_action('wp_ajax_eps_redirect_save', array($this, 'ajax_save_redirect') );
75
-
76
-
77
- if( isset($_GET['page']) && $_GET['page'] == self::$page_slug) {
78
- add_action('admin_init', array($this, 'clear_cache'));
79
- }
80
-
81
- if( isset($_GET['delete_redirect']) && is_numeric( $_GET['delete_redirect'] ) ) {
82
- self::_delete( $_GET['delete_redirect'] );
83
- }
84
-
85
- } else {
86
- add_action('init', array($this,'do_redirect'), 1); // Priority 1 for redirects.
87
- }
88
-
89
- if ( !self::is_current_version() ) self::update_self();
90
-
91
- }
92
-
93
- /**
94
- *
95
- *
96
- * Activation and Deactivation Handlers.
97
- *
98
- * @return nothing
99
- * @author epstudios
100
- */
101
- public static function eps_redirect_activation() {
102
- self::update_self();
103
- }
104
- public static function eps_redirect_deactivation() {
105
- }
106
-
107
- function is_current_version(){
108
- $version = get_option( 'eps_redirects_version' );
109
- return version_compare($version, EPS_REDIRECT_VERSION, '=') ? true : false;
110
- }
111
 
112
- /**
113
- *
114
- * CHECK VERSION
115
- *
116
- * This function will check the current version and do any fixes required
117
- *
118
- * @return string - version number.
119
- * @author epstudios
120
- *
121
- */
122
- public function update_self() {
123
- $version = get_option( 'eps_redirects_version' );
124
- self::_create_tables(); // Maybe create the tables
125
-
126
- if( version_compare($version, '2.0.0', '<')) {
127
- // migrate old format to new format.
128
- self::_migrate_to_v2();
129
- }
130
-
131
- update_option( 'eps_redirects_version', EPS_REDIRECT_VERSION );
132
- return EPS_REDIRECT_VERSION;
133
- }
134
-
135
- /**
136
- *
137
- *
138
- * MIGRATE TO V2
139
- *
140
- * Will migrate the old storage method to the new tables.
141
- *
142
- */
143
- public function _migrate_to_v2() {
144
- $redirects = get_option( self::$option_slug );
145
- if (empty($redirects)) return false; // No redirects to migrate.
146
-
147
- $new_redirects = array();
148
-
149
- foreach ($redirects as $from => $to ) {
150
- $new_redirects[] = array(
151
- 'id' => false,
152
- 'url_to' => urldecode($to),
153
- 'url_from' => $from,
154
- 'type' => 'url',
155
- 'status' => '301'
156
- );
157
  }
158
 
159
- self::_save_redirects( $new_redirects );
160
-
161
- //update_option( self::$option_slug, null ); // This would delete all old redirects. Lets leave them be.
162
- }
163
-
164
- /**
165
- *
166
- * CREATE TABLES
167
- *
168
- * Creates the new database architecture
169
- *
170
- * @return nothing
171
- * @author epstudios
172
- *
173
- */
174
- private function _create_tables() {
175
- global $wpdb;
176
-
177
- $table_name = $wpdb->prefix . "redirects";
178
-
179
- $sql = "CREATE TABLE $table_name (
180
- id mediumint(9) NOT NULL AUTO_INCREMENT,
181
- url_from VARCHAR(256) DEFAULT '' NOT NULL,
182
- url_to VARCHAR(256) DEFAULT '' NOT NULL,
183
- status VARCHAR(12) DEFAULT '301' NOT NULL,
184
- type VARCHAR(12) DEFAULT 'url' NOT NULL,
185
- count mediumint(9) DEFAULT 0 NOT NULL,
186
- UNIQUE KEY id (id)
187
- );";
188
-
189
- require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
190
- dbDelta( $sql );
191
- }
192
-
193
-
194
- /**
195
- *
196
- * ENQUEUE_RESOURCES
197
- *
198
- * This function will queue up the javascript and CSS for the plugin.
199
- *
200
- * @return html string
201
- * @author epstudios
202
- *
203
- */
204
- public function enqueue_resources(){
205
- wp_enqueue_script('jquery');
206
- wp_enqueue_script('eps_redirect_script', EPS_REDIRECT_URL .'js/scripts.js');
207
- wp_enqueue_style('eps_redirect_styles', EPS_REDIRECT_URL .'css/eps_redirect.css');
208
- add_thickbox();
209
- }
210
-
211
- /**
212
- *
213
- * ADD_PLUGIN_PAGE
214
- *
215
- * This function initialize the plugin page.
216
- *
217
- * @return html string
218
- * @author epstudios
219
- *
220
- */
221
- public function add_plugin_page(){
222
- add_options_page('301 Redirects', 'EPS 301 Redirects', 'manage_options', self::$page_slug, array($this, 'do_admin_page'));
223
  }
 
224
 
225
  /**
226
  *
@@ -232,21 +101,28 @@ class EPS_Redirects {
232
  *
233
  */
234
  public function do_redirect() {
235
-
236
  $redirects = self::get_redirects( true ); // True for only active redirects.
 
237
  if (empty($redirects)) return false; // No redirects.
238
-
239
  // Get current url
240
  $url_request = self::get_url();
241
 
242
- foreach ($redirects as $redirect ) {
 
 
 
 
 
243
  $from = urldecode( $redirect->url_from );
244
  $to = ($redirect->type == "url" && !is_numeric( $redirect->url_to )) ? urldecode($redirect->url_to) : get_permalink( $redirect->url_to );
245
-
246
-
247
- if( $redirect->status != 'inactive' && rtrim( trim($url_request),'/') === self::format_from_url( trim($from) ) ) {
 
248
  // Match, this needs to be redirected
249
- //increment this hit counter.
250
  self::increment_field($redirect->id, 'count');
251
 
252
  if( $redirect->status == '301' ) {
@@ -254,7 +130,10 @@ class EPS_Redirects {
254
  } elseif ( $redirect->status == '302' ) {
255
  header ('HTTP/1.1 301 Moved Temporarily');
256
  }
257
- header ('Location: ' . $to, true, (int) $redirect->status);
 
 
 
258
  exit();
259
  }
260
 
@@ -272,8 +151,10 @@ class EPS_Redirects {
272
  *
273
  */
274
  private function format_from_url( $string ) {
275
- $from = home_url() . '/' . $string;
276
- return strtolower( rtrim( $from,'/') );
 
 
277
  }
278
 
279
  /**
@@ -286,120 +167,17 @@ class EPS_Redirects {
286
  * @author epstudios
287
  *
288
  */
289
- function get_url() {
290
- $protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http';
291
- return strtolower( urldecode( $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
 
292
  }
293
 
294
 
295
- /**
296
- *
297
- * DO_ADMIN_PAGE
298
- *
299
- * This function will create the admin page.
300
- *
301
- * @author epstudios
302
- *
303
- */
304
- public function do_admin_page(){
305
- include ( EPS_REDIRECT_PATH . 'templates/admin.php' );
306
- }
307
-
308
- /**
309
- *
310
- * _SAVE
311
- *
312
- * This function handles various POST requests.
313
- *
314
- * @return html string
315
- * @author epstudios
316
- *
317
- */
318
- public function _save(){
319
- // Upload a CSV
320
- if( isset($_POST['eps_redirect_upload']) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
321
- self::_upload();
322
- }
323
-
324
- // Refresh the Transient Cache
325
- if ( isset( $_POST['eps_redirect_refresh'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
326
- $post_types = get_post_types(array('public'=>true), 'objects');
327
- foreach ($post_types as $post_type ) {
328
- $options = eps_dropdown_pages( array('post_type'=>$post_type->name ) );
329
- set_transient( 'post_type_cache_'.$post_type->name, $options, HOUR_IN_SECONDS );
330
- }
331
- }
332
-
333
- // Save Redirects
334
- if ( isset( $_POST['eps_redirect_submit'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
335
- $this->_save_redirects( self::_parse_serial_array($_POST['redirect']) );
336
- }
337
 
338
- }
339
 
340
- /**
341
- *
342
- * _UPLOAD
343
- *
344
- * This function handles the upload of CSV files.
345
- *
346
- * @return html string
347
- * @author epstudios
348
- *
349
- */
350
- private function _upload() {
351
- $new_redirects = array();
352
- $mimes = array('application/vnd.ms-excel','text/plain','text/csv','text/tsv');
353
 
354
- if( !in_array($_FILES['eps_redirect_upload_file']['type'], $mimes) ) {
355
- add_action( 'admin_notices', array($this, 'admin_notice_bad_csv') );
356
- return false;
357
- }
358
-
359
- // open the fule.
360
- if (($handle = fopen($_FILES['eps_redirect_upload_file']['tmp_name'], "r")) !== FALSE) {
361
-
362
- while (($redirect = fgetcsv($handle, 1000, ",")) !== FALSE) {
363
- $args = count($redirect);
364
-
365
-
366
- if( $args > 4 || $args < 3 ) {
367
- // Bad line. Too many/few arguments.
368
- add_action( 'admin_notices', array($this, 'admin_notice_bad_csv_entry') );
369
- continue;
370
- }
371
-
372
- switch( strtolower( $redirect[0] ) ) {
373
- case '302': $status = 302; break;
374
- case 'off':
375
- case 'no':
376
- case 'inactive': $status = 'inactive'; break;
377
- default: $status = 301; break;
378
- }
379
-
380
- // new redirect!
381
- $new_redirect = array(
382
- 'id' => false, // new
383
- 'url_from' => $redirect[1],
384
- 'url_to' => $redirect[2],
385
- 'type' => ( is_numeric( $redirect[2] ) ) ? 'post' : 'url',
386
- 'status' => $status,
387
- 'count' => ( isset( $redirect[3] ) && is_numeric( $redirect[3] ) ) ? $redirect[3] : 0
388
- );
389
-
390
- array_push($new_redirects, $new_redirect);
391
-
392
- }
393
- fclose($handle); // close file.
394
- }
395
 
396
- if( $new_redirects ) {
397
- self::_save_redirects( $new_redirects );
398
- add_action( 'admin_notices', array($this, 'admin_notice_upload_success') );
399
- } else {
400
- add_action( 'admin_notices', array($this, 'admin_notice_upload_error') );
401
- }
402
- }
403
 
404
  /**
405
  *
@@ -411,7 +189,7 @@ class EPS_Redirects {
411
  * @author epstudios
412
  *
413
  */
414
- private function _parse_serial_array( $array ){
415
  $new_redirects = array();
416
  $total = count( $array['url_from'] );
417
 
@@ -428,6 +206,7 @@ class EPS_Redirects {
428
  }
429
  return $new_redirects;
430
  }
 
431
  /**
432
  *
433
  * AJAX SAVE REDIRECTS
@@ -470,7 +249,25 @@ class EPS_Redirects {
470
 
471
  exit();
472
  }
473
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
474
  /**
475
  *
476
  * SAVE REDIRECTS
@@ -482,17 +279,24 @@ class EPS_Redirects {
482
  * @return nothing
483
  * @author epstudios
484
  */
485
- private function _save_redirects( $array ) {
486
  if( empty( $array ) ) return false;
487
  global $wpdb;
488
  $table_name = $wpdb->prefix . "redirects";
489
- $root = get_bloginfo('url') . '/';
490
  $ids = array();
491
 
492
 
493
  foreach( $array as $redirect ) {
494
 
495
- if( !$redirect['id'] || empty($redirect['id']) ) {
 
 
 
 
 
 
 
496
  // new
497
  $entry = array(
498
  'url_from' => trim( ltrim( str_replace($root, null, $redirect['url_from']), '/' ) ),
@@ -508,7 +312,9 @@ class EPS_Redirects {
508
  $entry
509
  );
510
  $ids[] = $wpdb->insert_id;
511
- } else {
 
 
512
  // existing
513
  $entry = array(
514
  'url_from' => trim( ltrim( str_replace($root, null, $redirect['url_from']), '/' ) ),
@@ -533,6 +339,7 @@ class EPS_Redirects {
533
 
534
  }
535
  /**
 
536
  * GET REDIRECTS
537
  *
538
  * Gets the redirects. Can be switched to return Active Only redirects.
@@ -541,15 +348,29 @@ class EPS_Redirects {
541
  * @author epstudios
542
  *
543
  */
544
- public function get_redirects( $active_only = false ) {
545
  global $wpdb;
546
  $table_name = $wpdb->prefix . "redirects";
 
547
  $results = $wpdb->get_results(
548
- "SELECT * FROM $table_name " . ( ( $active_only ) ? "WHERE status != 'inactive'" : null ) . " ORDER BY id DESC"
549
  );
 
 
 
 
 
 
 
 
 
 
 
 
550
  return $results;
551
  }
552
- public function get_redirect( $redirect_id ) {
 
553
  global $wpdb;
554
  $table_name = $wpdb->prefix . "redirects";
555
  $results = $wpdb->get_results(
@@ -568,7 +389,7 @@ class EPS_Redirects {
568
  * @author epstudios
569
  *
570
  */
571
- public function increment_field( $id, $field ) {
572
  global $wpdb;
573
  $table_name = $wpdb->prefix . "redirects";
574
  $results = $wpdb->query( "UPDATE $table_name SET $field = $field + 1 WHERE id = $id");
@@ -585,7 +406,7 @@ class EPS_Redirects {
585
  * @author epstudios
586
  *
587
  */
588
- public function do_entries(){
589
  $redirects = self::get_redirects( );
590
  $html = '';
591
  if (empty($redirects)) return false;
@@ -600,7 +421,6 @@ class EPS_Redirects {
600
  return $html;
601
  }
602
 
603
-
604
  /**
605
  *
606
  * DELETE_ENTRY
@@ -653,11 +473,11 @@ class EPS_Redirects {
653
  public static function get_inline_edit_entry($redirect_id = false) {
654
  include( EPS_REDIRECT_PATH . 'templates/template.redirect-entry-edit-inline.php');
655
  }
 
656
 
657
  public static function ajax_get_inline_edit_entry() {
658
-
659
  $redirect_id = isset( $_REQUEST['redirect_id'] ) ? intval( $_REQUEST['redirect_id'] ) : false;
660
-
661
  ob_start();
662
  self::get_inline_edit_entry($redirect_id);
663
  $html = ob_get_contents();
@@ -700,45 +520,13 @@ class EPS_Redirects {
700
  public function activation_error() {
701
  file_put_contents(EPS_REDIRECT_PATH. '/error_activation.html', ob_get_contents());
702
  }
 
703
 
704
-
705
- /**
706
- *
707
- * NOTICES
708
- *
709
- * This function will output a variable containing the admin ajax url for use in javascript.
710
- *
711
- * @author epstudios
712
- *
713
- */
714
- function admin_notice_bad_csv() {
715
- ?>
716
- <div class="error">
717
- <p>WARNING: Not a valid CSV file! No new redirects have been added.</p>
718
- </div>
719
- <?php
720
- }
721
- function admin_notice_upload_success() {
722
- ?>
723
- <div class="updated">
724
- <p>SUCCCESS: New redirects have been added.</p>
725
- </div>
726
- <?php
727
- }
728
- function admin_notice_upload_error() {
729
- ?>
730
- <div class="updated">
731
- <p>WARNING: Something's up. No new redirects were added, please review your CSV file.</p>
732
- </div>
733
- <?php
734
  }
735
- function admin_notice_bad_csv_entry() {
736
- ?>
737
- <div class="error">
738
- <p>WARNING: Encountered a bad Redirect entry in your CSV file.</p>
739
- </div>
740
- <?php
741
- }
742
  }
743
 
744
 
@@ -771,4 +559,6 @@ function eps_view( $object ) {
771
 
772
  // Run the plugin.
773
  $EPS_Redirects = new EPS_Redirects();
 
 
774
  ?>
15
  *
16
  * @package EPS 301 Redirects
17
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
18
+ * @version 2.2.0
19
  */
20
 
21
 
22
+
23
 
24
  /*
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.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
32
  */
33
 
34
+ if( ! defined( 'EPS_REDIRECT_PRO' ) )
35
+ {
 
36
 
 
 
37
 
38
+ define ( 'EPS_REDIRECT_PATH', plugin_dir_path(__FILE__) );
39
+ define ( 'EPS_REDIRECT_URL', plugin_dir_url( __FILE__ ) );
40
+ define ( 'EPS_REDIRECT_VERSION', '2.2.0');
41
+ define ( 'EPS_REDIRECT_PRO', false);
42
 
43
+ include(EPS_REDIRECT_PATH.'eps-form-elements.php');
44
+ include(EPS_REDIRECT_PATH.'class.drop-down-pages.php');
45
+ include(EPS_REDIRECT_PATH.'libs/eps-plugin.php');
46
+ include(EPS_REDIRECT_PATH.'libs/eps-plugin-options.php');
47
+ include(EPS_REDIRECT_PATH.'plugin.php');
 
48
 
49
 
50
 
51
+ class EPS_Redirects {
52
+
53
  /**
54
  *
55
  * Constructor
58
  *
59
  */
60
  public function __construct(){
61
+ global $EPS_Redirects_Plugin;
62
+
63
+ if(is_admin() )
64
+ {
65
+
66
+ if( isset($_GET['page']) && $_GET['page'] == $EPS_Redirects_Plugin->config('page_slug') )
67
+ {
68
+ // actions
69
+ add_action('activated_plugin', array($this, 'activation_error'));
70
+ add_action('admin_footer_text', array($this, 'set_ajax_url'));
71
+
72
+ // Other
73
+ add_action('admin_init', array($this, 'clear_cache'));
74
+
75
+ }
76
+
77
 
78
  // Ajax funcs
79
  add_action('wp_ajax_eps_redirect_get_new_entry', array($this, 'ajax_get_entry') );
80
  add_action('wp_ajax_eps_redirect_delete_entry', array($this, 'ajax_eps_delete_entry') );
81
  add_action('wp_ajax_eps_redirect_get_inline_edit_entry', array($this, 'ajax_get_inline_edit_entry') );
82
  add_action('wp_ajax_eps_redirect_save', array($this, 'ajax_save_redirect') );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
+ }
85
+ else
86
+ {
87
+ add_action('init', array($this, 'do_redirect'), 1); // Priority 1 for redirects.
88
+ add_action('template_redirect', array($this, 'check_404'), 1); // Priority 1 for redirects.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  }
90
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
  }
92
+
93
 
94
  /**
95
  *
101
  *
102
  */
103
  public function do_redirect() {
104
+ if ( is_admin() ) return false;
105
  $redirects = self::get_redirects( true ); // True for only active redirects.
106
+
107
  if (empty($redirects)) return false; // No redirects.
108
+
109
  // Get current url
110
  $url_request = self::get_url();
111
 
112
+ $query_string = explode('?', $url_request);
113
+ $query_string = ( isset($query_string[1]) ) ? $query_string[1] : false;
114
+
115
+
116
+ foreach ($redirects as $redirect )
117
+ {
118
  $from = urldecode( $redirect->url_from );
119
  $to = ($redirect->type == "url" && !is_numeric( $redirect->url_to )) ? urldecode($redirect->url_to) : get_permalink( $redirect->url_to );
120
+
121
+ if( $redirect->status != 'inactive' && rtrim( trim($url_request),'/') === self::format_from_url( trim($from) ) )
122
+ {
123
+
124
  // Match, this needs to be redirected
125
+ // increment this hit counter.
126
  self::increment_field($redirect->id, 'count');
127
 
128
  if( $redirect->status == '301' ) {
130
  } elseif ( $redirect->status == '302' ) {
131
  header ('HTTP/1.1 301 Moved Temporarily');
132
  }
133
+
134
+ $to = ( $query_string ) ? $to . "?" . $query_string : $to;
135
+
136
+ header ('Location: ' . $to, true, (int) $redirect->status);
137
  exit();
138
  }
139
 
151
  *
152
  */
153
  private function format_from_url( $string ) {
154
+ $complete = home_url() . '/' . $string;
155
+ list($uprotocol,$uempty,$uhost,$from) = explode( '/', $complete, 4);
156
+ $from = '/' . $from;
157
+ return strtolower( rtrim( $from, '/') );
158
  }
159
 
160
  /**
167
  * @author epstudios
168
  *
169
  */
170
+ public static function get_url() {
171
+ return strtolower( urldecode( $_SERVER['REQUEST_URI'] ) );
172
+ //$protocol = ( isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' ) ? 'https' : 'http';
173
+ //return strtolower( urldecode( $protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] ) );
174
  }
175
 
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
 
 
178
 
 
 
 
 
 
 
 
 
 
 
 
 
 
179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
180
 
 
 
 
 
 
 
 
181
 
182
  /**
183
  *
189
  * @author epstudios
190
  *
191
  */
192
+ public static function _parse_serial_array( $array ){
193
  $new_redirects = array();
194
  $total = count( $array['url_from'] );
195
 
206
  }
207
  return $new_redirects;
208
  }
209
+
210
  /**
211
  *
212
  * AJAX SAVE REDIRECTS
249
 
250
  exit();
251
  }
252
+
253
+ /**
254
+ *
255
+ * redirect_exists
256
+ *
257
+ * Checks if a redirect exists for a given url_from
258
+ *
259
+ * @param $redirect
260
+ * @return bool
261
+ */
262
+ public static function redirect_exists( $redirect )
263
+ {
264
+ global $wpdb;
265
+ $table_name = $wpdb->prefix . "redirects";
266
+ $query = "SELECT id FROM $table_name WHERE url_from = '" . $redirect['url_from'] . "'";
267
+ $result = $wpdb->get_row( $query );
268
+ return ( $result ) ? $result : false;
269
+ }
270
+
271
  /**
272
  *
273
  * SAVE REDIRECTS
279
  * @return nothing
280
  * @author epstudios
281
  */
282
+ public static function _save_redirects( $array ) {
283
  if( empty( $array ) ) return false;
284
  global $wpdb;
285
  $table_name = $wpdb->prefix . "redirects";
286
+ $root = get_bloginfo('url') . '/';
287
  $ids = array();
288
 
289
 
290
  foreach( $array as $redirect ) {
291
 
292
+ if( ! isset( $redirect['id'] ) || empty($redirect['id']) ) {
293
+
294
+ // If the user supplied a post_id, is it valid? If so, use it!
295
+ if( $post_id = url_to_postid( $redirect['url_to'] ) )
296
+ {
297
+ $redirect['url_to'] = $post_id;
298
+ }
299
+
300
  // new
301
  $entry = array(
302
  'url_from' => trim( ltrim( str_replace($root, null, $redirect['url_from']), '/' ) ),
312
  $entry
313
  );
314
  $ids[] = $wpdb->insert_id;
315
+ }
316
+ else
317
+ {
318
  // existing
319
  $entry = array(
320
  'url_from' => trim( ltrim( str_replace($root, null, $redirect['url_from']), '/' ) ),
339
 
340
  }
341
  /**
342
+ *
343
  * GET REDIRECTS
344
  *
345
  * Gets the redirects. Can be switched to return Active Only redirects.
348
  * @author epstudios
349
  *
350
  */
351
+ public static function get_redirects( $active_only = false ) {
352
  global $wpdb;
353
  $table_name = $wpdb->prefix . "redirects";
354
+
355
  $results = $wpdb->get_results(
356
+ "SELECT * FROM $table_name WHERE status != 404 " . ( ( $active_only ) ? "AND status != 'inactive'" : null ) . " ORDER BY id DESC"
357
  );
358
+
359
+ return $results;
360
+ }
361
+
362
+ public static function get_all() {
363
+ global $wpdb;
364
+ $table_name = $wpdb->prefix . "redirects";
365
+
366
+ $results = $wpdb->get_results(
367
+ "SELECT * FROM $table_name ORDER BY id DESC"
368
+ );
369
+
370
  return $results;
371
  }
372
+
373
+ public static function get_redirect( $redirect_id ) {
374
  global $wpdb;
375
  $table_name = $wpdb->prefix . "redirects";
376
  $results = $wpdb->get_results(
389
  * @author epstudios
390
  *
391
  */
392
+ public static function increment_field( $id, $field ) {
393
  global $wpdb;
394
  $table_name = $wpdb->prefix . "redirects";
395
  $results = $wpdb->query( "UPDATE $table_name SET $field = $field + 1 WHERE id = $id");
406
  * @author epstudios
407
  *
408
  */
409
+ public static function list_redirects(){
410
  $redirects = self::get_redirects( );
411
  $html = '';
412
  if (empty($redirects)) return false;
421
  return $html;
422
  }
423
 
 
424
  /**
425
  *
426
  * DELETE_ENTRY
473
  public static function get_inline_edit_entry($redirect_id = false) {
474
  include( EPS_REDIRECT_PATH . 'templates/template.redirect-entry-edit-inline.php');
475
  }
476
+
477
 
478
  public static function ajax_get_inline_edit_entry() {
 
479
  $redirect_id = isset( $_REQUEST['redirect_id'] ) ? intval( $_REQUEST['redirect_id'] ) : false;
480
+
481
  ob_start();
482
  self::get_inline_edit_entry($redirect_id);
483
  $html = ob_get_contents();
520
  public function activation_error() {
521
  file_put_contents(EPS_REDIRECT_PATH. '/error_activation.html', ob_get_contents());
522
  }
523
+
524
 
525
+ public static function check_404()
526
+ {
527
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
528
  }
529
+
 
 
 
 
 
 
530
  }
531
 
532
 
559
 
560
  // Run the plugin.
561
  $EPS_Redirects = new EPS_Redirects();
562
+
563
+ }
564
  ?>
eps-form-elements.php CHANGED
@@ -34,6 +34,7 @@ function eps_get_selector( $redirect = false ) {
34
  ), 'objects');
35
 
36
  $html = eps_get_type_select($post_types, $current_post);
 
37
  // Get all the post type select boxes.
38
  foreach ($post_types as $post_type ) {
39
  $html .= eps_get_post_type_selects( $post_type->name, $current_post );
@@ -43,12 +44,12 @@ function eps_get_selector( $redirect = false ) {
43
  $html .= eps_get_term_archive_select();
44
 
45
  // The default input, javascript will populate this input with the final URL for submission.
46
- $html .= '<input class="eps-url-input"
47
  type="text"
48
  name="redirect[url_to][]"
49
  value="'.( isset( $redirect->url_to ) ? $redirect->url_to : null ).'"
50
- placeholder="'.get_bloginfo('home').
51
- ( ( isset( $redirect->type ) && $redirect->type != 'post' || !isset($redirect->type) ) ? null : ' style="display:none;"' ) .
52
  '" />';
53
 
54
  return $html;
34
  ), 'objects');
35
 
36
  $html = eps_get_type_select($post_types, $current_post);
37
+
38
  // Get all the post type select boxes.
39
  foreach ($post_types as $post_type ) {
40
  $html .= eps_get_post_type_selects( $post_type->name, $current_post );
44
  $html .= eps_get_term_archive_select();
45
 
46
  // The default input, javascript will populate this input with the final URL for submission.
47
+ $html .= '<input class="eps-url-input select-eps-url-input"
48
  type="text"
49
  name="redirect[url_to][]"
50
  value="'.( isset( $redirect->url_to ) ? $redirect->url_to : null ).'"
51
+ placeholder="'.get_bloginfo('url').'" ' .
52
+ ( ! isset($redirect->type) || ( ( isset( $redirect->type ) && $redirect->type != 'post' ) ) ? null : ' style="display:none;"' ) .
53
  '" />';
54
 
55
  return $html;
error_activation.html ADDED
File without changes
example.csv ADDED
@@ -0,0 +1,4 @@
 
 
 
 
1
+ off,from_url_1,redirect_to_url
2
+ 301,from_url_2,1
3
+ 302,from_url_3,redirect_to_url
4
+ 404,from_url_4,2
images/icon-check.png ADDED
Binary file
images/icon-eps-redirects.jpg ADDED
Binary file
js/scripts.js CHANGED
@@ -39,24 +39,22 @@ jQuery(document).ready(function ($) {
39
  $('.eps-table').on('click', '.redirect-actions a.eps-redirect-edit', function(e){
40
  e.preventDefault();
41
  var redirect_id = $(this).data('id');
42
-
43
  // Do the request
44
  $.ajax({
45
  type: 'POST',
46
  url: eps_redirect_ajax_url,
47
  data: {
48
- 'action': 'eps_redirect_get_inline_edit_entry',
49
- 'redirect_id': redirect_id,
50
  },
51
  success: function(data){
52
  var data = jQuery.parseJSON( data );
53
-
54
  $('#eps-redirect-edit').remove();
55
  $('tr.redirect-entry').removeClass('active');
56
  $('tr.redirect-entry[data-id='+data.redirect_id+']').addClass('active');
57
  $(data.html).insertAfter('tr.redirect-entry[data-id='+data.redirect_id+']');
58
  $('#eps-redirect-add').show();
59
-
60
  },
61
  error: function(){
62
  // failed request; give feedback to user
@@ -64,7 +62,8 @@ jQuery(document).ready(function ($) {
64
  }
65
  });
66
  });
67
-
 
68
 
69
 
70
  /**
@@ -114,10 +113,20 @@ jQuery(document).ready(function ($) {
114
 
115
  $('#eps-redirect-edit').remove();
116
  $('tr.redirect-entry').removeClass('active');
117
- if( $('tr.redirect-entry[data-id='+data.redirect_id+']').length ) {
 
118
  // entry exists, so update it
119
- $('tr.redirect-entry[data-id='+data.redirect_id+']').replaceWith( data.html );
120
- } else {
 
 
 
 
 
 
 
 
 
121
  // new entry, add it
122
  $(data.html).insertAfter('tr#eps-redirect-add');
123
  $('#eps-redirect-add').show();
39
  $('.eps-table').on('click', '.redirect-actions a.eps-redirect-edit', function(e){
40
  e.preventDefault();
41
  var redirect_id = $(this).data('id');
 
42
  // Do the request
43
  $.ajax({
44
  type: 'POST',
45
  url: eps_redirect_ajax_url,
46
  data: {
47
+ 'action': 'eps_redirect_get_inline_edit_entry',
48
+ 'redirect_id': redirect_id
49
  },
50
  success: function(data){
51
  var data = jQuery.parseJSON( data );
52
+ console.log( data );
53
  $('#eps-redirect-edit').remove();
54
  $('tr.redirect-entry').removeClass('active');
55
  $('tr.redirect-entry[data-id='+data.redirect_id+']').addClass('active');
56
  $(data.html).insertAfter('tr.redirect-entry[data-id='+data.redirect_id+']');
57
  $('#eps-redirect-add').show();
 
58
  },
59
  error: function(){
60
  // failed request; give feedback to user
62
  }
63
  });
64
  });
65
+
66
+
67
 
68
 
69
  /**
113
 
114
  $('#eps-redirect-edit').remove();
115
  $('tr.redirect-entry').removeClass('active');
116
+ if( $('tr.redirect-entry[data-id='+data.redirect_id+']').length )
117
+ {
118
  // entry exists, so update it
119
+ if( $('tr.redirect-entry[data-status="404"]').length )
120
+ {
121
+ $('tr.redirect-entry[data-id='+data.redirect_id+']').hide();
122
+ }
123
+ else
124
+ {
125
+ $('tr.redirect-entry[data-id='+data.redirect_id+']').replaceWith( data.html );
126
+ }
127
+ }
128
+ else
129
+ {
130
  // new entry, add it
131
  $(data.html).insertAfter('tr#eps-redirect-add');
132
  $('#eps-redirect-add').show();
libs/eps-plugin-options.php ADDED
@@ -0,0 +1,312 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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_Plugin_Options') )
15
+ {
16
+
17
+ class EPS_Plugin_Options {
18
+
19
+ /**
20
+ *
21
+ * Will be populated with the JSON file.
22
+ *
23
+ * @var array
24
+ *
25
+ */
26
+ public $settings = array();
27
+
28
+ public $plugin;
29
+
30
+ private $menu_locations = array(
31
+ 'menu', 'dashboard', 'posts', 'media', 'links', 'pages', 'comments', 'theme', 'plugins', 'users', 'management', 'options'
32
+ );
33
+
34
+
35
+ /**
36
+ *
37
+ * Initialize the Theme Options, and register some actions.
38
+ *
39
+ */
40
+ public function __construct( EPS_Plugin $Plugin ){
41
+ $this->plugin = $Plugin;
42
+ $this->build_settings();
43
+ add_action( 'admin_init', array($this, 'options_defaults') );
44
+ add_action( 'admin_init', array($this, 'register_settings') );
45
+ add_action( 'admin_menu', array($this, 'add_options_page') );
46
+ }
47
+
48
+ /**
49
+ *
50
+ * Pull settings from the theme-options.json file.
51
+ *
52
+ */
53
+ private function build_settings() {
54
+ $this->settings = $this->parse_json_from_url( $this->plugin->config('path') . 'options.json' );
55
+ }
56
+
57
+ private function parse_json_from_url( $uri )
58
+ {
59
+ $json = file_get_contents( $uri );
60
+ $data = json_decode($json,true);
61
+ return $data;
62
+ }
63
+
64
+ /**
65
+ *
66
+ * Build the setting slug based on section.
67
+ *
68
+ * @param string $section
69
+ * @return string
70
+ */
71
+ private function setting_slug( $section = 'general' ) {
72
+ return $this->plugin->config('option_slug') . '_' . $section;
73
+ }
74
+
75
+
76
+ /**
77
+ *
78
+ * Registers the settings based on the JSON file we imported.
79
+ *
80
+ */
81
+ public function register_settings() {
82
+
83
+ foreach( $this->settings as $section => $args ) {
84
+
85
+ register_setting(
86
+ $this->setting_slug( $section ),
87
+ $this->setting_slug( $section ),
88
+ array( $this, 'sanitize_inputs' )
89
+ );
90
+
91
+ add_settings_section(
92
+ $this->setting_slug( $section ),
93
+ $args['title'],
94
+ // array( $this, 'section_'.$section.'_callback'),
95
+ array( $this, 'section_callback'),
96
+ $this->plugin->config('option_slug') . '_' . $section
97
+ );
98
+
99
+ foreach( $args['fields'] as $slug => $args ) {
100
+ $args['section'] = $section;
101
+ add_settings_field(
102
+ $slug,
103
+ $args['label'],
104
+ array( $this, 'field_callback'),
105
+ $this->setting_slug( $section ),
106
+ $this->setting_slug( $section ),
107
+ $args
108
+ );
109
+
110
+ }
111
+ }
112
+ }
113
+
114
+
115
+ /**
116
+ *
117
+ * Sanitize inputs. TODO
118
+ *
119
+ * @param $args
120
+ * @return mixed
121
+ */
122
+ public function sanitize_inputs( $args ) {
123
+ return $args;
124
+ }
125
+
126
+ /**
127
+ *
128
+ * If this is the first time we're loading this, we can use the JSON file to populate some defaults.
129
+ *
130
+ */
131
+ public function options_defaults() {
132
+
133
+ foreach( $this->settings as $section => $args ) {
134
+
135
+ $settings = get_option( $this->setting_slug( $section ) );
136
+
137
+ if ( empty( $settings ) ) {
138
+ $settings = array();
139
+ foreach( $args['fields'] as $slug => $args ) {
140
+ $settings[$slug] = $args['default'];
141
+ }
142
+
143
+ add_option( $this->setting_slug( $section ), $settings, '', 'yes' );
144
+ }
145
+
146
+ }
147
+
148
+ }
149
+
150
+ /**
151
+ *
152
+ * Outputs the Sections intro HTML. A callback.
153
+ *
154
+ * TODO: Can this be made more dynamic?
155
+ *
156
+ * @param $args
157
+ *
158
+ */
159
+ function section_callback( $args ) {
160
+ $tab = ( isset( $_GET['tab'] ) ) ? $_GET['tab'] : array_keys( $this->settings )[0];
161
+ echo $this->settings[$tab]['description'];
162
+ }
163
+
164
+ /**
165
+ *
166
+ * Output the Field HTML based on the JSON and 'type' of input.
167
+ *
168
+ * @param $args
169
+ *
170
+ */
171
+ function field_callback( $args ) {
172
+ $option_slug = $this->setting_slug( $args['section'] );
173
+ $setting = get_option( $this->setting_slug( $args['section'] ) );
174
+ printf ("<input type='text' name='%s[%s]' value='%s' /><small>%s</small>",
175
+ $option_slug,
176
+ $args['slug'],
177
+ ( isset( $setting[ $args['slug'] ] ) ? $setting[ $args['slug'] ] : null ),
178
+ $args['description']
179
+ );
180
+ }
181
+
182
+ /**
183
+ *
184
+ * ADD_PLUGIN_PAGE
185
+ *
186
+ * This function initialize the plugin settings page.
187
+ *
188
+ * @return string
189
+ * @author epstudios
190
+ *
191
+ */
192
+ public function add_options_page(){
193
+ if( in_array( $this->plugin->config('menu_location'), $this->menu_locations ) )
194
+ {
195
+ $func = sprintf("add_%s_page", $this->plugin->config('menu_location') );
196
+ return $func($this->plugin->name, $this->plugin->name, $this->plugin->config('page_permission'), $this->plugin->config('page_slug'), array($this, 'do_admin_page'));
197
+ }
198
+ else
199
+ {
200
+ // TODO proper errors dude.
201
+ printf( 'ERROR: menu location "%s" not valid.', $this->config['menu_location'] );
202
+ }
203
+ return false;
204
+ }
205
+
206
+ /**
207
+ *
208
+ * DO_ADMIN_PAGE
209
+ *
210
+ * This function will create the admin page.
211
+ *
212
+ * @author epstudios
213
+ *
214
+ */
215
+ public function do_admin_page(){
216
+ $current_tab = isset( $_GET['tab'] ) ? $_GET['tab'] : false;
217
+ if( ! $current_tab )
218
+ {
219
+ $sections = $this->settings;
220
+ $current_tab = key($sections);
221
+ }
222
+ ?>
223
+ <div class="wrap">
224
+ <h2><?php echo $this->plugin->name; ?> Settings</h2>
225
+ <?php $this->get_tab_nav( $current_tab ); ?>
226
+ <?php $this->get_tab( $current_tab ); ?>
227
+ </div>
228
+ <?php
229
+ }
230
+
231
+ /**
232
+ *
233
+ * Outputs the tab navigation based on our sections.
234
+ *
235
+ * @param string $current
236
+ */
237
+ function get_tab_nav( $current = 'general' ) {
238
+ echo '<div id="icon-themes" class="icon32"><br></div>';
239
+ echo '<h2 class="nav-tab-wrapper">';
240
+
241
+
242
+ foreach( $this->settings as $tab => $args ){
243
+ $class = ( $tab == $current ) ? ' nav-tab-active' : '';
244
+ printf("<a class='nav-tab%s' href='?page=%s&tab=%s'>%s</a>",
245
+ $class,
246
+ $this->plugin->config('option_slug'),
247
+ $tab,
248
+ $args['title']
249
+ );
250
+ }
251
+ echo '</h2>';
252
+ }
253
+
254
+ /**
255
+ *
256
+ * Gets the content for the current tab.
257
+ *
258
+ * @param string $tab
259
+ *
260
+ */
261
+ public function get_tab( $tab = 'general' ) {
262
+ if ( $this->tab_exists( $tab ) ) {
263
+
264
+
265
+ if(has_action( $tab.'_admin_tab'))
266
+ {
267
+ do_action( $tab.'_admin_tab', $this->settings[$tab] );
268
+ }
269
+ else
270
+ {
271
+ ?>
272
+ <form method="post" action="<?php echo admin_url('options.php'); ?>">
273
+ <?php
274
+
275
+ settings_fields( $this->setting_slug( $tab ) );
276
+ do_action( $this->setting_section_callback( $tab, "_before") );
277
+ do_settings_sections( $this->plugin->config('option_slug') . '_' . $tab );
278
+ do_action( $this->setting_section_callback($tab, '_after') );
279
+ submit_button();
280
+
281
+ ?>
282
+ </form>
283
+ <?php
284
+ }
285
+ }
286
+ }
287
+
288
+ private function setting_section_callback( $tab, $suffix = '' )
289
+ {
290
+ return $this->plugin->config('option_slug') . '_settings_' . $this->settings[$tab]['callback'] . $suffix;
291
+ }
292
+
293
+
294
+ /**
295
+ *
296
+ * Checks to see if a tab exists.
297
+ *
298
+ * @param $tab
299
+ * @return bool
300
+ * @throws Exception
301
+ *
302
+ */
303
+ public function tab_exists( $tab ) {
304
+ if ( ! array_key_exists( $tab, $this->settings ) ) {
305
+ throw new Exception('Tab does not exist');
306
+ }
307
+ return true;
308
+ }
309
+
310
+ }
311
+
312
+ }
libs/eps-plugin.php ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * EPS Plugin
4
+ *
5
+ * @author Shawn Wernig, Eggplant Studios, www.eggplantstudios.ca
6
+ * @version 1.0.0
7
+ * @copyright 2015 Eggplant Studios
8
+ * @package EPS Boilerplate
9
+ */
10
+
11
+ require_once('eps-plugin-options.php');
12
+
13
+ if( ! class_exists('EPS_Plugin') )
14
+ {
15
+ class EPS_Plugin {
16
+
17
+ protected $config = array(
18
+ 'version' => '',
19
+ 'option_slug' => '',
20
+ 'page_slug' => '',
21
+ 'page_title' => '',
22
+ 'url' => '',
23
+ 'path' => ''
24
+ );
25
+
26
+ protected $resources = array(
27
+ 'css' => array(
28
+ 'admin.css'
29
+ ),
30
+ 'js' => array(
31
+ 'admin.js'
32
+ )
33
+ );
34
+
35
+
36
+ protected $tables = array();
37
+
38
+ protected $dependencies = array();
39
+
40
+ protected $options;
41
+
42
+ public $name = '';
43
+
44
+
45
+ /**
46
+ *
47
+ * Constructor
48
+ *
49
+ * Add some actions.
50
+ *
51
+ */
52
+ public function __construct(){
53
+ $this->config['url'] = plugins_url() . $this->config['directory'] . '/';
54
+ $this->config['path'] = ABSPATH . 'wp-content/plugins/' . $this->config['directory'] . '/';
55
+ $this->settings = new EPS_Plugin_Options( $this );
56
+
57
+ register_activation_hook( __FILE__, array($this->name, '_activation'));
58
+ register_deactivation_hook( __FILE__, array($this->name, '_deactivation'));
59
+ if ( !self::is_current_version() ) self::update_self();
60
+ add_action('init', array($this, 'plugin_resources'));
61
+ }
62
+
63
+
64
+ public function resolve_dependencies()
65
+ {
66
+ include_once( ABSPATH . 'wp-admin/includes/plugin.php' );
67
+ foreach( $this->dependencies as $name => $path_to_plugin )
68
+ {
69
+ if ( ! is_plugin_active( $path_to_plugin ) )
70
+ {
71
+ echo $name . ' IS NOT INSTALLED!';
72
+ }
73
+ }
74
+ }
75
+
76
+ public static function plugin_resources()
77
+ {
78
+
79
+ }
80
+
81
+ private function resource_path( $path, $resource )
82
+ {
83
+ return strtolower(
84
+ $this->config['url']
85
+ . $path . '/'
86
+ . $resource );
87
+ }
88
+
89
+ private function resource_name( $resource )
90
+ {
91
+ return strtolower( $this->name . '_' . key( $resource ) );
92
+ }
93
+
94
+ /**
95
+ *
96
+ *
97
+ * Activation and Deactivation Handlers.
98
+ *
99
+ * @return nothing
100
+ * @author epstudios
101
+ */
102
+ public function activation_error() {
103
+ file_put_contents($this->config('path'). '/error_activation.html', ob_get_contents());
104
+ }
105
+
106
+ public function _activation() {
107
+ if ( !self::is_current_version() ) self::update_self();
108
+ }
109
+
110
+ public function _deactivation() {}
111
+
112
+ public function is_current_version()
113
+ {
114
+ return version_compare( $this->current_version(), $this->config['version'], '=') ? true : false;
115
+ }
116
+ public function current_version()
117
+ {
118
+ return get_option( $this->config['option_slug'] . '_version' );
119
+ }
120
+ public function set_current_version( $version )
121
+ {
122
+ update_option( $this->config['option_slug'] . '_version', $version );
123
+ }
124
+ /**
125
+ *
126
+ * CHECK VERSION
127
+ *
128
+ * This function will check the current version and do any fixes required
129
+ *
130
+ * @return string - version number.
131
+ * @author epstudios
132
+ *
133
+ */
134
+ public function update_self() {
135
+ $this->set_current_version( $this->config['version'] );
136
+ return $this->config['version'];
137
+ }
138
+
139
+ public function config($name)
140
+ {
141
+ return ( isset($this->config[ $name ]) ) ? $this->config[ $name ] : false;
142
+ }
143
+
144
+ /**
145
+ *
146
+ * CREATE TABLES
147
+ *
148
+ * Creates the new database architecture
149
+ *
150
+ * TODO This could be more elegant - and check for syntax errors too.
151
+ *
152
+ * @return nothing
153
+ * @author epstudios
154
+ *
155
+ */
156
+ protected function _create_tables()
157
+ {
158
+ global $wpdb;
159
+
160
+ $sql = '';
161
+
162
+ foreach( $this->tables as $name => $data )
163
+ {
164
+ $sql .= sprintf("CREATE TABLE `%s` (\n", $wpdb->prefix . $name );
165
+
166
+ foreach($data['columns'] as $name => $attr )
167
+ {
168
+ $sql .= sprintf( "`%s` %s, \n", $name, $attr );
169
+ }
170
+
171
+ $sql .= "PRIMARY KEY (`ID`), \n";
172
+
173
+ if( isset($data['foreign_keys']) && !empty($data['foreign_keys']) )
174
+ {
175
+ foreach( $data['foreign_keys'] as $name => $reference )
176
+ {
177
+ $sql .= sprintf( "FOREIGN KEY (`%s`) REFERENCES %s%s ON DELETE CASCADE ON UPDATE CASCADE, \n", $name, $wpdb->prefix, $reference );
178
+ }
179
+ }
180
+
181
+ $sql = substr($sql, 0, -3);
182
+ $sql .= "\n";
183
+ $sql .= ");\n\n";
184
+ }
185
+
186
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
187
+ dbDelta( $sql );
188
+ }
189
+ }
190
+
191
+ }
192
+
193
+ ?>
options.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "redirects":{
3
+ "title":"Redirects",
4
+ "description":"",
5
+ "callback":"redirects",
6
+ "fields":{}
7
+ },
8
+ "404s":{
9
+ "title":"404s",
10
+ "description":"",
11
+ "callback":"404s",
12
+ "fields":{}
13
+ },
14
+ "import-export":{
15
+ "title":"Import/Export",
16
+ "description":"",
17
+ "callback":"import_export",
18
+ "fields":{}
19
+ }
20
+ }
plugin.php ADDED
@@ -0,0 +1,430 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * Class EPS_Redirects_Plugin
4
+ *
5
+ * Inits the EPS_Redirects Plugin's core functionality and admin management.
6
+ *
7
+ *
8
+ */
9
+
10
+
11
+ class EPS_Redirects_Plugin extends EPS_Plugin {
12
+
13
+ protected $config = array(
14
+ 'version' => '2.2.0',
15
+ 'option_slug' => 'eps_redirects',
16
+ 'page_slug' => 'eps_redirects',
17
+ 'page_title' => 'EPS Redirects',
18
+ 'menu_location' => 'options',
19
+ 'page_permission' => 'manage_options',
20
+ 'directory' => 'eps-301-redirects'
21
+ );
22
+
23
+ protected $dependancies = array();
24
+
25
+ protected $tables = array();
26
+
27
+ public $name = 'EPS Redirects';
28
+
29
+ public function __construct()
30
+ {
31
+ parent::__construct();
32
+
33
+ // Template Hooks
34
+ add_action( 'redirects_admin_tab', array($this, 'admin_tab_redirects'), 10, 1 );
35
+ add_action( '404s_admin_tab', array($this, 'admin_tab_404s'), 10, 1 );
36
+ add_action( 'import-export_admin_tab', array($this, 'admin_tab_import_export'), 10, 1 );
37
+ add_action( 'eps_redirects_panels_left', array($this, 'admin_panel_cache'));
38
+ add_action( 'eps_redirects_panels_right', array($this, 'admin_panel_donate'));
39
+ add_action('eps_redirects_admin_head', array($this, 'admin_header_notices'));
40
+
41
+ // Actions
42
+ add_action('admin_init', array($this, 'check_plugin_actions'));
43
+
44
+ }
45
+
46
+ /**
47
+ *
48
+ * update_self
49
+ *
50
+ * This function will check the current version and do any fixes required
51
+ *
52
+ * @return string - version number.
53
+ * @author epstudios
54
+ *
55
+ */
56
+ public function update_self()
57
+ {
58
+
59
+ $version = get_option( 'eps_redirects_version' );
60
+ $this->_create_tables(); // Maybe create the tables
61
+
62
+ if( version_compare($version, '2.0.0', '<')) {
63
+ // migrate old format to new format.
64
+ $this->_migrate_to_v2();
65
+ }
66
+ $this->set_current_version( EPS_REDIRECT_VERSION );
67
+ return EPS_REDIRECT_VERSION;
68
+ }
69
+
70
+ /**
71
+ *
72
+ * _migrate_to_v2
73
+ *
74
+ * Will migrate the old storage method to the new tables.
75
+ *
76
+ * @return nothing
77
+ * @author epstudios
78
+ *
79
+ */
80
+ protected function _migrate_to_v2() {
81
+ $redirects = get_option( self::$option_slug );
82
+
83
+ if (empty($redirects)) return false; // No redirects to migrate.
84
+
85
+ $new_redirects = array();
86
+
87
+ foreach ($redirects as $from => $to ) {
88
+ $new_redirects[] = array(
89
+ 'id' => false,
90
+ 'url_to' => urldecode($to),
91
+ 'url_from' => $from,
92
+ 'type' => 'url',
93
+ 'status' => '301'
94
+ );
95
+ }
96
+
97
+ EPS_Redirects::_save_redirects( $new_redirects );
98
+ }
99
+
100
+ /**
101
+ *
102
+ * _create_tables
103
+ *
104
+ * Creates the database architecture
105
+ *
106
+ * @return nothing
107
+ * @author epstudios
108
+ *
109
+ */
110
+ public function _create_tables()
111
+ {
112
+ global $wpdb;
113
+
114
+ $table_name = $wpdb->prefix . "redirects";
115
+
116
+ $sql = "CREATE TABLE $table_name (
117
+ id mediumint(9) NOT NULL AUTO_INCREMENT,
118
+ url_from VARCHAR(256) DEFAULT '' NOT NULL,
119
+ url_to VARCHAR(256) DEFAULT '' NOT NULL,
120
+ status VARCHAR(12) DEFAULT '301' NOT NULL,
121
+ type VARCHAR(12) DEFAULT 'url' NOT NULL,
122
+ count mediumint(9) DEFAULT 0 NOT NULL,
123
+ UNIQUE KEY id (id)
124
+ );";
125
+
126
+ require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
127
+ dbDelta( $sql );
128
+ }
129
+
130
+
131
+
132
+
133
+
134
+ /**
135
+ *
136
+ * plugin_resources
137
+ *
138
+ * Enqueues the resources
139
+ *
140
+ * @return nothing
141
+ * @author epstudios
142
+ *
143
+ */
144
+ public static function plugin_resources()
145
+ {
146
+ global $EPS_Redirects_Plugin;
147
+ if( is_admin() && isset($_GET['page']) && $_GET['page'] == $EPS_Redirects_Plugin->config('page_slug') ) {
148
+ wp_enqueue_script('jquery');
149
+ wp_enqueue_script('eps_redirect_script', EPS_REDIRECT_URL .'js/scripts.js');
150
+ wp_enqueue_style('eps_redirect_styles', EPS_REDIRECT_URL .'css/eps_redirect.css');
151
+ }
152
+ }
153
+
154
+ /**
155
+ *
156
+ * check_plugin_actions
157
+ *
158
+ * This function handles various POST requests.
159
+ *
160
+ * @return nothing
161
+ * @author epstudios
162
+ *
163
+ */
164
+ public function check_plugin_actions(){
165
+ if( is_admin() && isset($_GET['page']) && $_GET['page'] == $this->config('page_slug') )
166
+ {
167
+ // Upload a CSV
168
+ if( isset($_POST['eps_redirect_upload']) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
169
+ self::_upload();
170
+ }
171
+ // Export a CSV
172
+ if( isset($_POST['eps_redirect_export']) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
173
+ self::export_csv();
174
+ }
175
+
176
+ // Refresh the Transient Cache
177
+ if ( isset( $_POST['eps_redirect_refresh'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
178
+ $post_types = get_post_types(array('public'=>true), 'objects');
179
+ foreach ($post_types as $post_type ) {
180
+ $options = eps_dropdown_pages( array('post_type'=>$post_type->name ) );
181
+ set_transient( 'post_type_cache_'.$post_type->name, $options, HOUR_IN_SECONDS );
182
+ }
183
+ add_action( 'admin_notices', array($this, 'admin_notice_refresh_cache') );
184
+ }
185
+
186
+ // Save Redirects
187
+ if ( isset( $_POST['eps_redirect_submit'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
188
+ self::_save_redirects( EPS_Redirects::_parse_serial_array($_POST['redirect']) );
189
+ }
190
+ }
191
+ }
192
+
193
+
194
+ /**
195
+ *
196
+ * export_csv
197
+ *
198
+ * @return nothing
199
+ * @author epstudios
200
+ *
201
+ */
202
+ public static function export_csv()
203
+ {
204
+ $entries = EPS_Redirects::get_all();
205
+ $filename = sprintf("%s-redirects.csv",
206
+ date('Y-m-d')
207
+ );
208
+ if( $entries )
209
+ {
210
+ header('Content-disposition: attachment; filename='.$filename);
211
+ header('Content-type: text/csv');
212
+
213
+ foreach( $entries as $entry )
214
+ {
215
+ $csv = array(
216
+ $entry->status,
217
+ $entry->url_from,
218
+ $entry->url_to,
219
+ $entry->count
220
+ );
221
+ echo implode(',',$csv);
222
+ echo "\n";
223
+ }
224
+
225
+ die();
226
+ }
227
+
228
+ }
229
+
230
+ /**
231
+ *
232
+ * _upload
233
+ *
234
+ * This function handles the upload of CSV files, in accordance to the upload method specified.
235
+ *
236
+ * @return html string
237
+ * @author epstudios
238
+ *
239
+ */
240
+ private function _upload() {
241
+ $new_redirects = array();
242
+ $mimes = array('application/vnd.ms-excel','text/plain','text/csv','text/tsv');
243
+ ini_set('auto_detect_line_endings',TRUE);
244
+
245
+ if( !in_array($_FILES['eps_redirect_upload_file']['type'], $mimes) ) {
246
+ add_action( 'admin_notices', array($this, 'admin_notice_bad_csv') );
247
+ return false;
248
+ }
249
+
250
+ // open the file.
251
+ if (($handle = fopen($_FILES['eps_redirect_upload_file']['tmp_name'], "r")) !== FALSE)
252
+ {
253
+ while (($redirect = fgetcsv($handle, 0, ",")) !== FALSE)
254
+ {
255
+ $redirect = array_filter($redirect);
256
+
257
+ if( empty( $redirect ) ) continue;
258
+
259
+ $args = count($redirect);
260
+
261
+ if( $args > 4 || $args < 2 ) {
262
+ // Bad line. Too many/few arguments.
263
+ add_action( 'admin_notices', array($this, 'admin_notice_bad_csv_entry') );
264
+ continue;
265
+ }
266
+
267
+ $status = (isset($redirect[0])) ? $redirect[0] : false;
268
+ $url_from = (isset($redirect[1])) ? $redirect[1] : false;
269
+ $url_to = (isset($redirect[2])) ? $redirect[2] : false;
270
+ $count = (isset($redirect[3])) ? $redirect[3] : false;
271
+
272
+ switch( strtolower( $status ) ) {
273
+ case '404': $status = 404; break;
274
+ case '302': $status = 302; break;
275
+ case 'off':
276
+ case 'no':
277
+ case 'inactive': $status = 'inactive'; break;
278
+ default: $status = 301; break;
279
+ }
280
+
281
+ // If the user supplied a post_id, is it valid? If so, use it!
282
+ if( $url_to && $post_id = url_to_postid( $url_to ) )
283
+ {
284
+ $url_to = $post_id;
285
+ }
286
+
287
+ // new redirect!
288
+ $new_redirect = array(
289
+ 'id' => false, // new
290
+ 'url_from' => $url_from,
291
+ 'url_to' => $url_to,
292
+ 'type' => ( is_numeric( $url_to ) ) ? 'post' : 'url',
293
+ 'status' => $status,
294
+ 'count' => $count
295
+ );
296
+
297
+ array_push($new_redirects, $new_redirect);
298
+
299
+ }
300
+ fclose($handle); // close file.
301
+ }
302
+
303
+
304
+ if( $new_redirects )
305
+ {
306
+ $save_redirects = array();
307
+ foreach( $new_redirects as $redirect )
308
+ {
309
+ // Decide how to handle duplicates:
310
+ switch( strtolower( $_POST['eps_redirect_upload_method'] ) )
311
+ {
312
+ case 'skip':
313
+ if( ! EPS_Redirects::redirect_exists( $redirect ) )
314
+ {
315
+ $save_redirects[] = $redirect;
316
+ }
317
+ break;
318
+ case 'update':
319
+ if( $entry = EPS_Redirects::redirect_exists( $redirect ) )
320
+ {
321
+ $redirect['id'] = $entry->id;
322
+ }
323
+ $save_redirects[] = $redirect;
324
+ break;
325
+ case 'ignore':
326
+ $save_redirects[] = $redirect;
327
+ break;
328
+ }
329
+ }
330
+
331
+ if( ! empty( $save_redirects ) )
332
+ {
333
+ EPS_Redirects::_save_redirects( $save_redirects );
334
+ add_action( 'admin_notices', array($this, 'admin_notice_upload_success') );
335
+ }
336
+ else
337
+ {
338
+ add_action( 'admin_notices', array($this, 'admin_notice_upload_success_no_new') );
339
+ }
340
+
341
+ }
342
+ else
343
+ {
344
+ add_action( 'admin_notices', array($this, 'admin_notice_upload_error') );
345
+ }
346
+ ini_set('auto_detect_line_endings',FALSE);
347
+ }
348
+
349
+
350
+
351
+ /**
352
+ *
353
+ * Template Hooks
354
+ *
355
+ * @author epstudios
356
+ *
357
+ */
358
+ public static function admin_panel_cache()
359
+ {
360
+ include ( EPS_REDIRECT_PATH . 'templates/admin-panel-cache.php' );
361
+ }
362
+ public static function admin_panel_donate()
363
+ {
364
+ include ( EPS_REDIRECT_PATH . 'templates/admin-panel-donate.php' );
365
+ }
366
+
367
+ public static function admin_tab_redirects( $options )
368
+ {
369
+ include ( EPS_REDIRECT_PATH . 'templates/admin-tab-redirects.php' );
370
+ }
371
+ public static function admin_tab_404s( $options )
372
+ {
373
+ include ( EPS_REDIRECT_PATH . 'templates/admin-tab-404s.php' );
374
+ }
375
+ public static function admin_tab_import_export( $options )
376
+ {
377
+ include ( EPS_REDIRECT_PATH . 'templates/admin-tab-import-export.php' );
378
+ }
379
+
380
+ public static function admin_header_notices()
381
+ {
382
+ global $wp_rewrite;
383
+ if( !isset($wp_rewrite->permalink_structure) || empty($wp_rewrite->permalink_structure) ) {
384
+ echo '<div class="error clear"><div class="eps-padding">';
385
+ 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>';
386
+ echo '</div></div>';
387
+ }
388
+ }
389
+
390
+
391
+
392
+ /**
393
+ *
394
+ * Notices
395
+ *
396
+ * These functions will output a variable containing the admin ajax url for use in javascript.
397
+ *
398
+ * @author epstudios
399
+ *
400
+ */
401
+ function admin_notice_bad_csv() {
402
+ $this->admin_notice("WARNING: Not a valid CSV file! No new redirects have been added.", "error");
403
+ }
404
+ function admin_notice_upload_success() {
405
+ $this->admin_notice("SUCCCESS: New redirects have been added.");
406
+ }
407
+ function admin_notice_upload_success_no_new() {
408
+ $this->admin_notice("SUCCCESS: But no new redirects have been added. (Possibly Duplicates?)");
409
+ }
410
+ function admin_notice_upload_error() {
411
+ $this->admin_notice("WARNING: Something's up. No new redirects were added, please review your CSV file.", "error");
412
+ }
413
+ function admin_notice_bad_csv_entry() {
414
+ $this->admin_notice("WARNING: Encountered a bad Redirect entry in your CSV file.", "error");
415
+ }
416
+ function admin_notice_refresh_cache() {
417
+ $this->admin_notice("SUCCCESS: Cache Refreshed.");
418
+ }
419
+ protected function admin_notice( $string, $type = "updated" ) {
420
+ printf('<div class="%s"><p>%s</p></div>',
421
+ $type,
422
+ $string
423
+ );
424
+ }
425
+
426
+ }
427
+
428
+ // Init the plugin.
429
+ $EPS_Redirects_Plugin = new EPS_Redirects_Plugin();
430
+ ?>
readme.txt CHANGED
@@ -1,18 +1,46 @@
1
  === Plugin Name ===
 
2
  Contributors: shawneggplantstudiosca
 
3
  Donate link: none
 
4
  Tags: 301 redirects, redirects
 
5
  Requires at least: 3.0.1
6
- Tested up to: 3.8.1
7
- Stable tag: 2.1.2
 
 
 
8
  License: GPLv2 or later
 
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
11
  Easily manage and create 301 redirects for your Wordpress website. A robust interface allows you create and validate redirects.
12
 
13
  == Description ==
14
 
15
- **EPS 301 Redirects?** helps you manage and create 301 redirects for your Wordpress website. A robust interface allows you to select the *Destination URL* from drop down menus, and validates your redirects for troubleshooting.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
 
18
  **What is a 301 Redirect?**
@@ -27,12 +55,6 @@ A 301 redirect indicates that the page requested has been permanently moved to t
27
  1. You have content that expires (or is otherwise no longer available) and you wish to redirect users elsewhere.
28
 
29
 
30
- **Features**
31
- * Choose from Pages, Posts, Custom Post types, Archives, Term Archives,
32
- * Creates its own database table, for faster indexing
33
-
34
-
35
-
36
 
37
  Created by Shawn Wernig [Eggplant Studios](http://www.eggplantstudios.ca/ "Eggplant Studios")
38
 
@@ -52,35 +74,37 @@ Created by Shawn Wernig [Eggplant Studios](http://www.eggplantstudios.ca/ "Eggpl
52
 
53
  == Frequently Asked Questions ==
54
 
55
- = I'm getting an error about the default permalink structure? =
56
-
57
- EPS 301 Redirects requires that you use anything but the default permalink structure.
58
 
 
59
 
60
- = My redirects aren't working =
61
 
62
- This could be caused by many things, but please ensure that you are supplying valid URLs. Most common are extra spaces, extra slashes, spelling mistakes and invalid characters.
63
 
 
64
 
65
- = My redirects aren't working - the old .html page still shows =
 
66
  For this plugin to work, the page must be within the Wordpress environment. If you are redirecting older .html or .php files, you must first delete them. The plugin can’t redirect if the file still exists, sorry! You should look into .htaccess redirects if you want to keep these files on your server.
67
 
 
68
 
 
69
 
70
- = My redirects aren't getting the 301 status code =
71
 
72
- Your Request or Redirect URLS may be incorrect; please ensure that you are supplying valid URLs. Check slashes. Try Viewing the page by clicking the TEST button - does it load correctly?
73
 
 
74
 
75
- = How do I delete a redirect? =
76
-
77
- Click the small X beside the redirect you wish to remove. Save changes.
78
-
79
 
80
- = How do I add wildcards. or folder redirects? =
81
 
82
- Unfortunately this is not supported. You should look into .htaccess redirects for these advanced features.
83
 
 
84
 
85
 
86
 
@@ -92,6 +116,9 @@ Unfortunately this is not supported. You should look into .htaccess redirects fo
92
 
93
  == Changelog ==
94
 
 
 
 
95
  = 2.1.2 =
96
  Minor bug fixes.
97
 
@@ -137,6 +164,9 @@ Overhauled the entire plugin. Redirects are stored in their own table. Gracefull
137
 
138
  == Upgrade Notice ==
139
 
 
 
 
140
  = 2.1.2 =
141
  Minor bug fixes.
142
 
1
  === Plugin Name ===
2
+
3
  Contributors: shawneggplantstudiosca
4
+
5
  Donate link: none
6
+
7
  Tags: 301 redirects, redirects
8
+
9
  Requires at least: 3.0.1
10
+
11
+ Tested up to: 4.2.1
12
+
13
+ Stable tag: 2.2.0
14
+
15
  License: GPLv2 or later
16
+
17
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
18
 
19
  Easily manage and create 301 redirects for your Wordpress website. A robust interface allows you create and validate redirects.
20
 
21
  == Description ==
22
 
23
+ **EPS 301 Redirects** helps you manage and create 301 redirects for your Wordpress website to improve your SEO and guest experience. With a user-friendly interface, EPS 301 Redirects is easy to install and configure. This plugin is installed on over 20,000 Wordpress Websites, and the number grows higher every day. This plugin is perfect for new site designs, repairing links after re-organizing your existing Wordpress content, or when your site has content that expires and you wish to avoid sending visitors to 404 pages.
24
+
25
+
26
+ **Features**
27
+
28
+ 1. Choose from Pages, Posts, Custom Post types, Archives, and Term Archives from dropdown menus.
29
+ 1. Or, set a custom destination URL!
30
+ 1. Retain query strings across redirects
31
+ 1. Super-fast redirection
32
+ Improved Import/Export feature for bulk additions.
33
+ 1. A 404 logger (pro version), that will easily convert into new redirects.
34
+
35
+ **The Pro version of EPS 301 Redirects includes a new 404 logging feature:**
36
+
37
+ The Pro Version of EPS 301 Redirects will add a new 404 tracking feature. Every 404 error will be logged, and you will have the power and flexibility to redirect them wherever you want them to go.
38
+
39
+ 1. See which Request URLs are causing 404 errors on your site.
40
+ 1. Discover which 404 errors are receiving the most traffic.
41
+ 1. Improve SEO by lowering your total number of 404 errors.
42
+ 1. Easily fix the 404 errors by turning them into redirects.
43
+
44
 
45
 
46
  **What is a 301 Redirect?**
55
  1. You have content that expires (or is otherwise no longer available) and you wish to redirect users elsewhere.
56
 
57
 
 
 
 
 
 
 
58
 
59
  Created by Shawn Wernig [Eggplant Studios](http://www.eggplantstudios.ca/ "Eggplant Studios")
60
 
74
 
75
  == Frequently Asked Questions ==
76
 
77
+ =What is a 301 Redirect?=
78
+ A redirect is a simple way to re-route traffic coming to a Requested URL to different Destination URL.
 
79
 
80
+ A 301 redirect indicates that the page requested has been permanently moved to the Destination URL, and helps pass on the Requested URLs traffic in a search engine friendly manner. Creating a 301 redirect tells search engines that the Requested URL has moved permanently, and that the content can now be found on the Destination URL. An important feature is that search engines will pass along any clout the Requested URL used to have to the Destination URL.
81
 
82
+ =I'm getting an error about the default permalink structure?=
83
 
84
+ EPS 301 Redirects requires that you use anything but the default permalink structure.
85
 
86
+ =My redirects aren't working=
87
 
88
+ This could be caused by many things, but please ensure that you are supplying valid URLs. Most common are extra spaces, extra slashes, spelling mistakes and invalid characters. If you're sure they're right, chances are your browser has cached the 301 redirect (in an attempt to make the redirection faster for you), but sometimes it doesn't refresh as fast as we would like. Clear your browser cache, or wait a few minutes to fix this problem.
89
+ My redirects aren't working - the old .html page still shows
90
  For this plugin to work, the page must be within the Wordpress environment. If you are redirecting older .html or .php files, you must first delete them. The plugin can’t redirect if the file still exists, sorry! You should look into .htaccess redirects if you want to keep these files on your server.
91
 
92
+ =My redirects aren't getting the 301 status code=
93
 
94
+ Your Request or Redirect URLS may be incorrect; please ensure that you are supplying valid URLs. Check slashes. Try Viewing the page by clicking the Request URL - does it load correctly?
95
 
96
+ =How do I delete a redirect?=
97
 
98
+ Click the small X beside the redirect you wish to remove.
99
 
100
+ =How do I add wildcards. or folder redirects?=
101
 
102
+ Unfortunately this is not supported. You should look into .htaccess redirects for these advanced features.
 
 
 
103
 
 
104
 
105
+ =What about query strings?=
106
 
107
+ By default, any URL with a query string is considered unique, and will redirect to a unique page (if you so wish). The query string will be added to the Destination URL, which allows you to keep your tracking codes, affiliate codes, and other important data!
108
 
109
 
110
 
116
 
117
  == Changelog ==
118
 
119
+ = 2.2.0 =
120
+ Minor bug fixes. Greatly improved import feature. Redirects include query strings. Export feature added. Http/Https agnostic. Pro version added with 404 management.
121
+
122
  = 2.1.2 =
123
  Minor bug fixes.
124
 
164
 
165
  == Upgrade Notice ==
166
 
167
+ = 2.2.0 =
168
+ Minor bug fixes. Greatly improved import feature, added Export feature plus many other updates. A Pro Version is now available with 404 Management!
169
+
170
  = 2.1.2 =
171
  Minor bug fixes.
172
 
templates/admin-panel-cache.php ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Admin Panel Cache
5
+ *
6
+ * The cache panel widget.
7
+ *
8
+ * @package EPS 301 Redirects
9
+ * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
+ */
11
+ ?>
12
+
13
+ <div class="eps-panel eps-margin-top">
14
+ <form method="post" action="">
15
+ <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
16
+ <input type="submit" name="eps_redirect_refresh" id="submit" class="button button-secondary" value="Refresh Cache"/>
17
+ <br><small class="eps-grey-text">Refresh the cache if the dropdowns are out of date.</small>
18
+ </form>
19
+ </div>
templates/admin-panel-donate.php ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * Admin Panel Donate
5
+ *
6
+ * The donate panel widget.
7
+ *
8
+ * @package EPS 301 Redirects
9
+ * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
+ */
11
+ ?>
12
+
13
+
14
+ <div id="donate-box" class="eps-panel">
15
+ <div class="eps-padding">
16
+ <p>Comments, questions, bugs and feature requests can be sent to: <a href="mailto:plugins@eggplantstudios.ca">plugins@eggplantstudios.ca</a>. Please quote the plugin version: <?php echo get_option( 'eps_redirects_version' ); ?></p>
17
+ <hr>
18
+ <h3>Please consider donating</h3>
19
+ <p>Your donations help support future versions EPS 301 Redirects.</p>
20
+ <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
21
+ <p>
22
+ <input type="hidden" name="cmd" value="_s-xclick">
23
+ <input type="hidden" name="hosted_button_id" value="2WC9XYFX49CSQ">
24
+ <input class="button button-secondary" type="submit" name="submit" value="Donate">
25
+ </p>
26
+ </form>
27
+ </div>
28
+ </div>
templates/admin-tab-404s.php ADDED
@@ -0,0 +1,50 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * The 404 Tab.
5
+ *
6
+ * The main admin area for the 404 tab.
7
+ *
8
+ * @package EPS 301 Redirects
9
+ * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
+ */
11
+ ?>
12
+
13
+ <div class="wrap">
14
+ <?php do_action('eps_redirects_admin_head'); ?>
15
+
16
+ <div class="eps-panel eps-margin-top group">
17
+ <div class="eps-redirects-50 group">
18
+ <h1>Take your redirects to the next level!</h1>
19
+ <p class="eps-redirects-lead">The <a href="http://www.eggplantstudios.ca/cart/?add_to_cart=2974" target="_blank">Pro Version of EPS 301 Redirects</a> will add a new 404 tracking feature. Every 404 error will be logged, and you will have the power and flexibility to redirect them wherever you want them to go.</p>
20
+
21
+ <ul id="eps-redirects-checklist">
22
+ <li><span>See which Request URLs are causing 404 errors on your site.</span></li>
23
+ <li><span>Discover which 404 errors are receiving the most traffic.</span></li>
24
+ <li><span>Improve SEO by lowering your total number of 404 errors.</span></li>
25
+ <li><span>Easily fix the 404 errors by turning them into redirects.</span></li>
26
+ </ul>
27
+ </div>
28
+ <div class="eps-redirects-50 group">
29
+ <div class="padding-lots">
30
+ <a href="http://www.eggplantstudios.ca/cart/?add_to_cart=2974" target="_blank">
31
+ <img class="eps-redirects-fit" src="<?php echo EPS_REDIRECT_URL; ?>/images/icon-eps-redirects.jpg" title="Upgrade EPS 301 Redirects">
32
+ </a>
33
+ <a class="eps-redirects-big-button" href="http://www.eggplantstudios.ca/cart/?add_to_cart=2974" target="_blank">BUY NOW &bull; ONLY $15.00</a>
34
+
35
+ </div>
36
+ </div>
37
+ </div>
38
+
39
+
40
+ <div class="right">
41
+ <?php do_action('eps_redirects_panels_right'); ?>
42
+ </div>
43
+ <div class="left">
44
+ <?php do_action('eps_redirects_panels_left'); ?>
45
+ </div>
46
+ </div>
47
+
48
+
49
+
50
+
templates/admin-tab-import-export.php ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ *
4
+ * The Import/Export Tab.
5
+ *
6
+ * The main admin area for the import/export tab.
7
+ *
8
+ * @package EPS 301 Redirects
9
+ * @author Shawn Wernig ( shawn@eggplantstudios.ca )
10
+ */
11
+ ?>
12
+
13
+ <div class="wrap">
14
+
15
+ <?php do_action('eps_redirects_admin_head'); ?>
16
+
17
+ <div class="eps-panel eps-margin-top">
18
+ <h3>Import:</h3>
19
+ <form method="post" action="" class="eps-padding" enctype="multipart/form-data">
20
+ <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
21
+ <input accept="csv" type="file" name="eps_redirect_upload_file" value="">
22
+ <input type="submit" name="eps_redirect_upload" id="submit" class="button button-secondary" value="Upload CSV"/>
23
+ <p>
24
+ <input type="radio" name="eps_redirect_upload_method" value="skip" checked="checked"> Skip Duplicates
25
+ &nbsp;&nbsp;&nbsp;<input type="radio" name="eps_redirect_upload_method" value="update"> Update Duplicates
26
+ &nbsp;&nbsp;&nbsp;<input type="radio" name="eps_redirect_upload_method" value="ignore"> Ignore Duplicates
27
+ </p>
28
+
29
+ <br><small class="eps-grey-text">Supply Columns: <strong>Status</strong> (301,302,inactive), <strong>Request URL</strong>, <strong>Redirect To</strong> (ID or URL). <a href="<?php echo EPS_REDIRECT_URL . 'example.csv'?>" target="_blank">Download Example CSV</a></small>
30
+ </form>
31
+ </div>
32
+
33
+ <div class="eps-panel eps-margin-top">
34
+ <h3>Export:</h3>
35
+ <form method="post" action="">
36
+ <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
37
+ <input type="submit" name="eps_redirect_export" id="submit" class="button button-secondary" value="Export Redirects"/>
38
+ <br><small class="eps-grey-text">Export a backup copy of your redirects.</small>
39
+ </form>
40
+ </div>
41
+
42
+ <div class="right">
43
+ <?php do_action('eps_redirects_panels_right'); ?>
44
+ </div>
45
+ <div class="left">
46
+ <?php do_action('eps_redirects_panels_left'); ?>
47
+ </div>
48
+ </div>
templates/{admin.redirects.php → admin-tab-redirects.php} RENAMED
@@ -1,22 +1,19 @@
1
  <?php
2
  /**
3
- *
4
- * EPS 301 Redirects.
5
- *
6
- * Admin.redirects.php
7
- *
8
- * Outputs the redirects table.
9
- *
10
- *
11
  *
 
 
 
12
  *
13
  * @package EPS 301 Redirects
14
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
15
- * @version 2.1.0
16
  */
17
  ?>
18
 
19
- <div id="eps-redirect-redirects-pane" class="eps-tab group">
 
 
 
20
  <table id="eps-redirect-entries" class="eps-table eps-table-striped">
21
  <tr>
22
  <th>Request URL</th>
@@ -24,13 +21,24 @@
24
  <th class="redirect-hits">Hits</th>
25
  <th class="redirect-actions">Actions</th>
26
  </tr>
27
-
28
  <tr id="eps-redirect-add" style="display:none"><td colspan="4"><a href="#" id="eps-redirect-new"><span>+</span></a></td></tr>
29
 
30
- <?php echo self::get_inline_edit_entry(); ?>
31
-
32
  <?php
33
- echo self::do_entries();
 
34
  ?>
35
- </table>
 
 
 
 
 
 
 
 
36
  </div>
 
 
 
 
1
  <?php
2
  /**
 
 
 
 
 
 
 
 
3
  *
4
+ * The Redirects Tab.
5
+ *
6
+ * The main admin area for the redirects tab.
7
  *
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
 
10
  */
11
  ?>
12
 
13
+
14
+ <div class="wrap">
15
+ <?php do_action('eps_redirects_admin_head'); ?>
16
+
17
  <table id="eps-redirect-entries" class="eps-table eps-table-striped">
18
  <tr>
19
  <th>Request URL</th>
21
  <th class="redirect-hits">Hits</th>
22
  <th class="redirect-actions">Actions</th>
23
  </tr>
24
+
25
  <tr id="eps-redirect-add" style="display:none"><td colspan="4"><a href="#" id="eps-redirect-new"><span>+</span></a></td></tr>
26
 
 
 
27
  <?php
28
+ echo EPS_Redirects::get_inline_edit_entry();
29
+ echo EPS_Redirects::list_redirects();
30
  ?>
31
+ </table>
32
+
33
+
34
+ <div class="right">
35
+ <?php do_action('eps_redirects_panels_right'); ?>
36
+ </div>
37
+ <div class="left">
38
+ <?php do_action('eps_redirects_panels_left'); ?>
39
+ </div>
40
  </div>
41
+
42
+
43
+
44
+
templates/admin.php DELETED
@@ -1,87 +0,0 @@
1
- <?php
2
- /**
3
- *
4
- * EPS 301 Redirects.
5
- *
6
- * Admin.php
7
- *
8
- * Outputs the admin page - and includes the tabs.
9
- *
10
- *
11
- *
12
- *
13
- * @package EPS 301 Redirects
14
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
15
- * @version 2.1.0
16
- */
17
-
18
-
19
- global $wp_rewrite;
20
-
21
- ?>
22
-
23
- <div class="wrap">
24
- <header id="eps-header">
25
- <div id="icon-eggplant">&nbsp;</div>
26
- <h2 class="eps-title"><?php echo self::$page_title; ?> <?php echo get_option( 'eps_redirects_version' ); ?></h2>
27
- </header>
28
-
29
- <?php
30
- if( !isset($wp_rewrite->permalink_structure) || empty($wp_rewrite->permalink_structure) ) {
31
- echo '<div class="error clear"><div class="eps-padding">';
32
- 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>';
33
- echo '</div></div>';
34
- }
35
- ?>
36
- <div id="eps-tabgroup">
37
-
38
- <div id="eps-tab-nav">
39
- <a href="#eps-redirect-redirects" class="active eps-tab-nav-item">Redirects</a>
40
- </div>
41
-
42
- <div id="eps-tabs">
43
- <?php include ( EPS_REDIRECT_PATH . 'templates/admin.redirects.php' ); ?>
44
- </div>
45
-
46
- </div>
47
-
48
- <div id="donate-box" class="eps-panel">
49
- <div class="eps-padding">
50
- <p>Comments, questions, bugs and feature requests can be sent to: <a href="mailto:plugins@eggplantstudios.ca">plugins@eggplantstudios.ca</a></p>
51
- <hr>
52
- <h3>Please consider donating</h3>
53
- <p>Your donations help support future versions EPS 301 Redirects.</p>
54
- <form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
55
- <p>
56
- <input type="hidden" name="cmd" value="_s-xclick">
57
- <input type="hidden" name="hosted_button_id" value="2WC9XYFX49CSQ">
58
- <input class="button button-secondary" type="submit" name="submit" value="Donate">
59
- </p>
60
- </form>
61
- </div>
62
- </div>
63
- <div class="left">
64
- <div class="eps-panel eps-margin-top">
65
- <form method="post" action="" class="eps-padding" enctype="multipart/form-data">
66
- <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
67
- <input accept="csv" type="file" name="eps_redirect_upload_file" value="">
68
- <input type="submit" name="eps_redirect_upload" id="submit" class="button button-secondary" value="Upload CSV"/>
69
- <br><small class="eps-grey-text">Supply Columns: <strong>Status</strong> (301,302,inactive), <strong>Request URL</strong>, <strong>Redirect To</strong> (ID or URL).</small>
70
- </form>
71
- </div>
72
-
73
- <div class="eps-panel left eps-margin-top">
74
- <form method="post" action="" class="eps-padding">
75
- <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
76
- <input type="submit" name="eps_redirect_refresh" id="submit" class="button button-secondary" value="Refresh Cache"/>
77
- <br><small class="eps-grey-text">Refresh the cache if the dropdowns are out of date.</small>
78
- </form>
79
- </div>
80
- </div>
81
-
82
-
83
- </div>
84
-
85
-
86
-
87
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
templates/template.redirect-entry-edit-inline.php CHANGED
@@ -1,18 +1,12 @@
1
  <?php
2
  /**
3
- *
4
- * EPS 301 Redirects.
5
- *
6
- * template.redirect-entry-edit-inline.php
7
- *
8
  * Outputs the whole inline entry edit html.
9
- *
10
- *
11
  *
12
  *
13
  * @package EPS 301 Redirects
14
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
15
- * @version 2.1.0
16
  */
17
 
18
 
1
  <?php
2
  /**
3
+ *
 
 
 
 
4
  * Outputs the whole inline entry edit html.
 
 
5
  *
6
  *
7
  * @package EPS 301 Redirects
8
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
9
+ *
10
  */
11
 
12
 
templates/template.redirect-entry-edit.php CHANGED
@@ -1,18 +1,12 @@
1
  <?php
2
  /**
3
  *
4
- * EPS 301 Redirects.
5
- *
6
- * template.redirect-entry-edit.php
7
- *
8
  * Outputs the edit form for a given $redirect_id. If $redirect_id is not set, assume this is a new redirect form.
9
  *
10
  *
11
- *
12
- *
13
  * @package EPS 301 Redirects
14
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
15
- * @version 2.1.0
16
  */
17
 
18
  $redirect = self::get_redirect( $redirect_id );
1
  <?php
2
  /**
3
  *
4
+ *
 
 
 
5
  * Outputs the edit form for a given $redirect_id. If $redirect_id is not set, assume this is a new redirect form.
6
  *
7
  *
 
 
8
  * @package EPS 301 Redirects
9
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
 
10
  */
11
 
12
  $redirect = self::get_redirect( $redirect_id );
templates/template.redirect-entry.php CHANGED
@@ -1,26 +1,19 @@
1
  <?php
2
  /**
3
- *
4
- * EPS 301 Redirects.
5
- *
6
- * template.redirect-entry.php
7
- *
8
- * Outputs the redirect entry for review. This is not used to edit - merely to list them.
9
- *
10
- *
11
  *
12
  *
13
  * @package EPS 301 Redirects
14
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
15
- * @version 2.1.0
16
  */
17
 
18
-
19
- $query_args = array( 'page' => self::$page_slug, 'delete_redirect' => esc_attr( $redirect->id ) );
20
 
21
 
22
  ?>
23
- <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 ); ?>">
24
  <td>
25
  <a target="_blank" class="eps-url" href="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>" title="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>">
26
  <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>
1
  <?php
2
  /**
3
+ *
4
+ * The Redirect List Entry Template.
 
 
 
 
 
 
5
  *
6
  *
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 ) );
13
 
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
  <a target="_blank" class="eps-url" href="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>" title="<?php bloginfo('url'); ?>/<?php echo esc_attr($dfrom); ?>">
19
  <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>