Eggplant 301 Redirects - Version 2.1.1

Version Description

Fixed an issue where users with a lot of redirects were being limited, this fix also changed up the admin area. Redirects are now editable via AJAX, and the add new form was moved to the top.

Download this release

Release Info

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

Code changes from version 2.0.1 to 2.1.1

class.drop-down-pages.php CHANGED
@@ -7,8 +7,10 @@
7
  * @since 2.1.0
8
  *
9
  * @param array|string $args Optional. Override default arguments.
10
- * @return string HTML content, if not displaying.
11
  */
 
 
12
  if( !function_exists('eps_dropdown_pages')) {
13
  function eps_dropdown_pages($args = '') {
14
  $defaults = array(
7
  * @since 2.1.0
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(
css/eps_redirect.css CHANGED
@@ -1,65 +1,43 @@
1
  /*----------------------------------------------------------*/
2
  /*--------------------- Entries Table ----------------------*/
3
  /*----------------------------------------------------------*/
 
 
4
 
5
 
6
- #eps-redirect-entries {
7
- margin-top: 32px;
8
  width: 100%;
9
  table-layout:fixed;
10
  }
11
 
12
- #eps-redirect-entries h3 { margin: 8px; font-size: 20px; font-weight: 100; border-bottom: 1px solid #eeeeee; padding-bottom: 12px; }
 
13
 
14
- #eps-redirect-entries tr.redirect-entry td,
15
- #eps-redirect-entries tr.redirect-entry th { padding: 10px; text-align: left; overflow: hidden; }
 
16
 
17
- #eps-redirect-entries tr.redirect-entry td.text-center,
18
- #eps-redirect-entries tr.redirect-entry th.text-center { text-align: center; }
19
-
20
-
21
- #eps-redirect-entries tr.redirect-entry th {
22
  padding: 6px 10px;
23
- -webkit-box-shadow:rgba(120, 200, 230, 0.498039) 0 1px 0 inset;
24
- background-color:#21759B;
25
- background-image:linear-gradient(#2A95C5, #21759B);
26
- border-color:#21759B #21759B #1E6A8D;
27
- box-shadow:rgba(120, 200, 230, 0.498039) 0 1px 0 inset;
28
  color:#FFFFFF;
29
  }
30
- #eps-redirect-entries tr.redirect-entry th:nth-child(1) {
31
- width: 60px !important;
32
- }
33
- #eps-redirect-entries tr.redirect-entry th:nth-child(4) {
34
- width: 20px !important;
35
- }
36
- #eps-redirect-entries tr.redirect-entry th:nth-child(5) {
37
- width: 80px !important;
38
- }
39
-
40
- #eps-redirect-entries tr.redirect-entry {
41
- background: #fafafa;
42
- }
43
- #eps-redirect-entries tr.redirect-entry:nth-child(even) {
44
  background: #fcfcfc;
45
  }
 
 
 
 
46
 
47
- #eps-redirect-entries td.redirect-actions { min-width: 90px; }
48
 
49
- #eps-redirect-entries .eps-request-url { width: 18em; }
50
- #eps-redirect-entries .eps-redirect-url { width: 18em; }
51
 
52
- #eps-redirect-entries tr.redirect-entry select,
53
- #eps-redirect-entries tr.redirect-entry input {
54
- font-size:13px;
55
- display:inline-block; zoom: 1; *display: inline;
56
- max-width: 100%;
57
- }
58
 
59
 
60
- #eps-redirect-entries tr.redirect-entry select {
61
- margin-right: 3px;
62
- }
63
 
64
  /*----------------------------------------------------------*/
65
  /*---------------------- notifications ---------------------*/
@@ -86,42 +64,37 @@
86
  /*-------------------------- Buttons -----------------------*/
87
  /*----------------------------------------------------------*/
88
 
89
- a.eps-text-link, a.eps-text-link:visited, a.eps-text-link:link {
 
 
 
 
 
90
  text-decoration: none;
91
- height: 28px; line-height: 26px;
92
- padding: 0 10px 1px;
93
- display:inline-block; zoom: 1; *display: inline;
94
- border: 1px solid #cccccc;
95
- background: #f7f7f7;
96
- color: #555555;
97
- margin: 0;
98
- -webkit-box-shadow: #FFFFFF 0 1px 0 inset, rgba(0, 0, 0, 0.0784314) 0 1px 0;
99
- -moz-box-shadow: #FFFFFF 0 1px 0 inset, rgba(0, 0, 0, 0.0784314) 0 1px 0;
100
- box-shadow:#FFFFFF 0 1px 0 inset, rgba(0, 0, 0, 0.0784314) 0 1px 0;
101
- -webkit-box-sizing:border-box;
102
- -moz-box-sizing:border-box;
103
- box-sizing:border-box;
104
- -webkit-border-radius: 3px;
105
- -moz-border-radius: 3px;
106
- border-radius: 3px;
107
  }
108
-
109
-
110
-
111
- a.eps-text-link:hover { background: #fafafa; }
112
-
113
- a.eps-text-link.remove {
114
- color: #aa0000;
115
- -webkit-border-radius: 12px;
116
- -moz-border-radius: 12px;
117
- border-radius: 12px;
 
 
 
118
  }
119
- a.eps-text-link.remove:hover { color: #fafafa; background: #aa0000; }
120
- a.eps-text-link.inactive { color: #aaaaaa !important; cursor: default; }
121
- a.eps-text-link.new {
122
- margin-top: 32px;
123
  }
124
 
 
 
 
125
  /*----------------------------------------------------------*/
126
  /*--------------------------- tabs -------------------------*/
127
  /*----------------------------------------------------------*/
@@ -151,18 +124,72 @@ a.eps-text-link.new {
151
  #eps-tabs .eps-tab { display: none; }
152
  #eps-tabs .eps-tab:first-child { display: block; }
153
 
 
154
 
155
  /*----------------------------------------------------------*/
156
  /*-------------------------- misc ------------------------*/
157
  /*----------------------------------------------------------*/
158
 
159
  .eps-padding { padding: 12px; }
160
- .eps-grey-text { font-style: italic; color: #999999; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
161
 
162
  /*----------------------------------------------------------*/
163
  /*------------------------ donate ------------------------*/
164
  /*----------------------------------------------------------*/
165
 
 
 
166
  #donate-box {
167
  border: 1px solid #d6d6d6; background: white; box-shadow: 1px 1px 6px #f4f4f4;
168
  width: 250px;
@@ -173,48 +200,46 @@ a.eps-text-link.new {
173
  #donate-box p { margin-bottom: 12px; }
174
  #donate-box h3 { margin-bottom: 12px; font-size: 1.2em; }
175
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176
  /*----------------------------------------------------------*/
177
  /*-------------------- media queries ---------------------*/
178
  /*----------------------------------------------------------*/
179
 
180
  @media only screen and (max-width : 600px) {
181
- #eps-redirect-entries tr.redirect-entry th:nth-child(1),
182
- #eps-redirect-entries tr.redirect-entry th:nth-child(4),
183
- #eps-redirect-entries tr.redirect-entry th:nth-child(5),
184
- #eps-redirect-entries tr.redirect-entry td:nth-child(1),
185
- #eps-redirect-entries tr.redirect-entry td:nth-child(4),
186
- #eps-redirect-entries tr.redirect-entry td:nth-child(5) {
187
  width: 0px !important;
188
- background: red;
189
  }
190
  #eps-tabs { padding: 12px 12px; }
191
- #eps-redirect-entries tr.redirect-entry select,
192
- #eps-redirect-entries tr.redirect-entry input {
193
- display: block;
194
- width: 100%;
195
- margin-bottom: 2px;
196
- }
197
- #donate-box { width: 100% !important; }
198
- .button { display: block !important; width: 100%; }
199
  #eps-redirect-entries tr.redirect-entry td,
200
  #eps-redirect-entries tr.redirect-entry th { padding: 5px; }
201
  }
202
 
203
 
204
  @media only screen and (max-width : 768px) and (min-width : 600px) {
205
- #eps-redirect-entries tr.redirect-entry select,
206
- #eps-redirect-entries tr.redirect-entry input {
207
- display: block;
208
- width: 100%;
209
- margin-bottom: 2px;
210
- }
211
- #donate-box { width: 100% !important; }
212
  }
 
213
  @media only screen and (max-width : 1024px) and (min-width : 768px) {
214
- #eps-redirect-entries tr.redirect-entry select,
215
- #eps-redirect-entries tr.redirect-entry input {
216
- display: block;
217
- width: 100%;
218
- margin-bottom: 2px;
219
- }
220
  }
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
  /*----------------------------------------------------------*/
43
  /*---------------------- notifications ---------------------*/
64
  /*-------------------------- Buttons -----------------------*/
65
  /*----------------------------------------------------------*/
66
 
67
+ #eps-redirect-new {
68
+ display: block;
69
+ background: #fafafa;
70
+ border: 2px solid #f4f4f4;
71
+ text-align: center;
72
+ padding: 8px;
73
  text-decoration: none;
74
+ width: 10%; min-width: 100px;
75
+ margin: 0px auto;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
76
  }
77
+ #eps-redirect-new:hover {
78
+ background: #fcfcfc;
79
+ }
80
+ #eps-redirect-new span {
81
+ display: block;
82
+ margin: 0px auto;
83
+ font-size: 32px;
84
+ background: #fcfcfc;
85
+ border: 2px solid #f4f4f4;
86
+ width: 32px; height: 32px; line-height: 32px;
87
+ -webkit-border-radius: 16px;
88
+ -moz-border-radius: 16px;
89
+ border-radius: 16px;
90
  }
91
+ #eps-redirect-new:hover span {
92
+ background: #ffffff;
 
 
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
  /*----------------------------------------------------------*/
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 ------------------------*/
131
  /*----------------------------------------------------------*/
132
 
133
  .eps-padding { padding: 12px; }
134
+ .eps-margin-top { margin-top: 12px; }
135
+ .eps-grey-text { color: #999999; }
136
+ .float-right { float: right; }
137
+ .text-center { text-align: center; }
138
+
139
+ .eps-url {
140
+ text-decoration: none; font-size: 12px !important;
141
+ background: #ffffff;
142
+ display: block;
143
+ border: 1px solid #eeeeee;
144
+ -webkit-border-radius: 4px;
145
+ -moz-border-radius: 4px;
146
+ -o-border-radius: 4px;
147
+ }
148
+
149
+
150
+ .eps-warning.eps-url {
151
+ border: 1px solid #c34343;
152
+ color: #c34343;
153
+ }
154
+ .eps-warning.eps-url .eps-url-root {
155
+ background: #f9f1f1;
156
+ }
157
+
158
+ #eps-redirect-save .eps-url { display: inline-block; }
159
+
160
+ .eps-url > span {
161
+ padding: 3px 6px;
162
+ display: inline-block;
163
+ background: #f4f4f4;
164
+ }
165
+
166
+ .eps-url .eps-url-root {
167
+ color: #aaaaaa;
168
+ }
169
+
170
+ .eps-url .eps-url-fragment {
171
+ font-weight: bold;
172
+ background: #ffffff;
173
+ }
174
+
175
+ .eps-url .eps-url-endcap {
176
+ -webkit-border-radius: 0px 4px 4px 0px;
177
+ -moz-border-radius: 0px 4px 4px 0px;
178
+ border-radius: 0px 4px 4px 0px;
179
+ }
180
+ .eps-url .eps-url-startcap {
181
+ -webkit-border-radius: 4px 0px 0px 4px;
182
+ -moz-border-radius: 4px 0px 0px 4px;
183
+ border-radius: 4px 0px 0px 4px;
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;
195
  width: 250px;
200
  #donate-box p { margin-bottom: 12px; }
201
  #donate-box h3 { margin-bottom: 12px; font-size: 1.2em; }
202
 
203
+ /*----------------------------------------------------------*/
204
+ /*------------------------ Helpers ------------------------*/
205
+ /*----------------------------------------------------------*/
206
+
207
+
208
+ /* Contain floats: nicolasgallagher.com/micro-group-hack/ */
209
+ .group:before, .group:after { content: ""; display: table; }
210
+ .group:after { clear: both; }
211
+ .group { zoom: 1; }
212
+
213
+ .right { float: right; }
214
+ .left { float: left; }
215
+
216
+ .text-right { text-align: right; }
217
  /*----------------------------------------------------------*/
218
  /*-------------------- media queries ---------------------*/
219
  /*----------------------------------------------------------*/
220
 
221
  @media only screen and (max-width : 600px) {
222
+ #eps-redirect-entries tr.redirect-entry .redirect-hits {
 
 
 
 
 
223
  width: 0px !important;
 
224
  }
225
  #eps-tabs { padding: 12px 12px; }
226
+ .eps-url .eps-url-root { display: none; }
227
+
228
+ .eps-panel{ width: 100% !important; }
 
 
 
 
 
229
  #eps-redirect-entries tr.redirect-entry td,
230
  #eps-redirect-entries tr.redirect-entry th { padding: 5px; }
231
  }
232
 
233
 
234
  @media only screen and (max-width : 768px) and (min-width : 600px) {
235
+ .eps-panel{ width: 100% !important; }
236
+ .eps-url .eps-url-root { display: none; }
237
+
 
 
 
 
238
  }
239
+
240
  @media only screen and (max-width : 1024px) and (min-width : 768px) {
241
+ .eps-url .eps-url-root { display: none; }
242
+
243
+
244
+
 
 
245
  }
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.0.1
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.0.1
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
@@ -33,7 +33,7 @@ License URI: http://www.gnu.org/licenses/gpl-2.0.html
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.0.1');
37
 
38
  register_activation_hook(__FILE__, array('EPS_Redirects', 'eps_redirect_activation'));
39
  register_deactivation_hook(__FILE__, array('EPS_Redirects', 'eps_redirect_deactivation'));
@@ -43,10 +43,10 @@ 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
 
@@ -59,19 +59,29 @@ class EPS_Redirects {
59
  */
60
  public function __construct(){
61
  if(is_admin()){
62
- add_action('activated_plugin', array($this,'activation_error'));
63
- add_action('admin_menu', array($this, 'add_plugin_page'));
64
- add_action('admin_init', array($this, '_save'));
65
- add_action('init', array($this, 'enqueue_resources'));
66
- add_action('admin_footer_text', array($this, 'set_ajax_url'));
 
 
67
 
68
  // Ajax funcs
69
- add_action('wp_ajax_eps_redirect_get_new_entry', array($this, 'ajax_get_blank_entry') );
70
- add_action('wp_ajax_eps_redirect_delete_entry', array($this, 'ajax_eps_delete_entry') );
 
 
 
71
 
72
  if( isset($_GET['page']) && $_GET['page'] == self::$page_slug) {
73
  add_action('admin_init', array($this, 'clear_cache'));
74
  }
 
 
 
 
 
75
  } else {
76
  add_action('init', array($this,'do_redirect'), 1); // Priority 1 for redirects.
77
  }
@@ -141,14 +151,14 @@ class EPS_Redirects {
141
  'id' => false,
142
  'url_to' => urldecode($to),
143
  'url_from' => $from,
144
- 'type' => 'url',
145
  'status' => '301'
146
  );
147
  }
148
 
149
  self::_save_redirects( $new_redirects );
150
 
151
- //update_option( self::$option_slug, null );
152
  }
153
 
154
  /**
@@ -195,6 +205,7 @@ class EPS_Redirects {
195
  wp_enqueue_script('jquery');
196
  wp_enqueue_script('eps_redirect_script', EPS_REDIRECT_URL .'js/scripts.js');
197
  wp_enqueue_style('eps_redirect_styles', EPS_REDIRECT_URL .'css/eps_redirect.css');
 
198
  }
199
 
200
  /**
@@ -232,12 +243,13 @@ class EPS_Redirects {
232
  $from = urldecode( $redirect->url_from );
233
  $to = ($redirect->type == "url" && !is_numeric( $redirect->url_to )) ? urldecode($redirect->url_to) : get_permalink( $redirect->url_to );
234
 
 
235
  if( $redirect->status != 'inactive' && rtrim( trim($url_request),'/') === self::format_from_url( trim($from) ) ) {
236
  // Match, this needs to be redirected
237
  //increment this hit counter.
238
  self::increment_field($redirect->id, 'count');
239
 
240
- if( $redirect->status == '301' ) {
241
  header ('HTTP/1.1 301 Moved Permanently');
242
  } elseif ( $redirect->status == '302' ) {
243
  header ('HTTP/1.1 301 Moved Temporarily');
@@ -304,21 +316,90 @@ class EPS_Redirects {
304
  *
305
  */
306
  public function _save(){
 
 
 
 
307
 
308
  // Refresh the Transient Cache
309
  if ( isset( $_POST['eps_redirect_refresh'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') ) {
310
  $post_types = get_post_types(array('public'=>true), 'objects');
311
- foreach ($post_types as $post_type ) {
312
  $options = eps_dropdown_pages( array('post_type'=>$post_type->name ) );
313
  set_transient( 'post_type_cache_'.$post_type->name, $options, HOUR_IN_SECONDS );
314
  }
315
  }
316
 
317
  // Save Redirects
318
- if ( isset( $_POST['eps_redirect_submit'] ) && wp_verify_nonce( $_POST['eps_redirect_nonce_submit'], 'eps_redirect_nonce') )
319
  $this->_save_redirects( self::_parse_serial_array($_POST['redirect']) );
 
320
 
321
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
322
 
323
  /**
324
  *
@@ -342,11 +423,53 @@ class EPS_Redirects {
342
  'url_from' => $array['url_from'][$i],
343
  'url_to' => $array['url_to'][$i],
344
  'type' => ( is_numeric($array['url_to'][$i]) ) ? 'post' : 'url',
345
- 'status' => isset( $array['status'][$i] ) ? $array['status'][$i] : 'active'
346
  );
347
  }
348
  return $new_redirects;
349
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
350
 
351
  /**
352
  *
@@ -363,35 +486,50 @@ class EPS_Redirects {
363
  if( empty( $array ) ) return false;
364
  global $wpdb;
365
  $table_name = $wpdb->prefix . "redirects";
 
 
 
366
 
367
  foreach( $array as $redirect ) {
 
368
  if( !$redirect['id'] || empty($redirect['id']) ) {
369
  // new
 
 
 
 
 
 
 
 
 
370
  $wpdb->insert(
371
  $table_name,
372
- array(
373
- 'url_from' => trim( $redirect['url_from'] ),
374
- 'url_to' => trim( $redirect['url_to']),
375
- 'type' => trim( $redirect['type']),
376
- 'status' => trim( $redirect['status'])
377
- )
378
  );
379
-
380
  } else {
381
  // existing
 
 
 
 
 
 
 
 
 
382
  $wpdb->update(
383
  $table_name,
384
- array(
385
- 'url_from' => trim( $redirect['url_from']),
386
- 'url_to' => trim( $redirect['url_to']),
387
- 'type' => trim( $redirect['type']),
388
- 'status' => trim( $redirect['status'])
389
- ),
390
  array( 'id' => $redirect['id'] )
391
  );
 
 
392
  }
393
 
394
  }
 
395
 
396
  }
397
  /**
@@ -407,10 +545,18 @@ class EPS_Redirects {
407
  global $wpdb;
408
  $table_name = $wpdb->prefix . "redirects";
409
  $results = $wpdb->get_results(
410
- "SELECT * FROM $table_name " . ( ( $active_only ) ? "WHERE status != 'inactive'" : null )
411
  );
412
  return $results;
413
  }
 
 
 
 
 
 
 
 
414
 
415
  /**
416
  *
@@ -439,7 +585,7 @@ class EPS_Redirects {
439
  * @author epstudios
440
  *
441
  */
442
- public function do_inputs(){
443
  $redirects = self::get_redirects( );
444
  $html = '';
445
  if (empty($redirects)) return false;
@@ -474,11 +620,17 @@ class EPS_Redirects {
474
  echo json_encode( array( 'id' => $_POST['id']) );
475
  exit();
476
  }
 
 
 
 
 
477
 
478
  /**
479
  *
480
- * GET_BLANK_ENTRY
481
- * AJAX_GET_BLANK_ENTRY
 
482
  *
483
  * This function will return a blank row ready for user input.
484
  *
@@ -486,16 +638,40 @@ class EPS_Redirects {
486
  * @author epstudios
487
  *
488
  */
489
- public static function get_blank_entry() {
490
  ob_start();
491
- include( EPS_REDIRECT_PATH . 'templates/template.redirect-entry-empty.php');
 
 
 
 
492
  $html = ob_get_contents();
493
  ob_end_clean();
494
  return $html;
495
  }
496
 
497
- public static function ajax_get_blank_entry() {
498
- echo self::get_blank_entry(); exit();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
499
  }
500
 
501
  public function clear_cache() {
@@ -505,6 +681,7 @@ class EPS_Redirects {
505
  }
506
 
507
 
 
508
  /**
509
  *
510
  * SET_AJAX_URL
@@ -518,15 +695,56 @@ class EPS_Redirects {
518
  echo '<script>var eps_redirect_ajax_url = "'. admin_url( 'admin-ajax.php' ) . '"</script>';
519
  }
520
 
 
 
521
  public function activation_error() {
522
  file_put_contents(EPS_REDIRECT_PATH. '/error_activation.html', ob_get_contents());
523
  }
524
 
525
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
526
  }
527
 
528
 
529
 
 
 
530
  /**
531
  * Outputs an object or array in a readable form.
532
  *
15
  *
16
  * @package EPS 301 Redirects
17
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
18
+ * @version 2.1.1
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.1.1
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
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.1');
37
 
38
  register_activation_hook(__FILE__, array('EPS_Redirects', 'eps_redirect_activation'));
39
  register_deactivation_hook(__FILE__, array('EPS_Redirects', 'eps_redirect_deactivation'));
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
 
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
  }
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
  /**
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
  /**
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' ) {
253
  header ('HTTP/1.1 301 Moved Permanently');
254
  } elseif ( $redirect->status == '302' ) {
255
  header ('HTTP/1.1 301 Moved Temporarily');
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
  *
423
  'url_from' => $array['url_from'][$i],
424
  'url_to' => $array['url_to'][$i],
425
  'type' => ( is_numeric($array['url_to'][$i]) ) ? 'post' : 'url',
426
+ 'status' => isset( $array['status'][$i] ) ? $array['status'][$i] : '301'
427
  );
428
  }
429
  return $new_redirects;
430
  }
431
+ /**
432
+ *
433
+ * AJAX SAVE REDIRECTS
434
+ *
435
+ * Saves a single redirectvia ajax.
436
+ *
437
+ * TODO: Maybe refactor this to reduce the number of queries.
438
+ *
439
+ * @return nothing
440
+ * @author epstudios
441
+ */
442
+ public function ajax_save_redirect() {
443
+
444
+ $update = array(
445
+ 'id' => ( $_POST['id'] ) ? $_POST['id'] : false,
446
+ 'url_from' => $_POST['url_from'], // remove the $root from the url if supplied, and a leading /
447
+ 'url_to' => $_POST['url_to'],
448
+ 'type' => ( is_numeric($_POST['url_to']) ? 'post' : 'url' ),
449
+ 'status' => $_POST['status']
450
+ );
451
+
452
+ $ids = self::_save_redirects( array( $update ) );
453
+
454
+ $updated_id = $ids[0]; // we expect only one returned id.
455
+
456
+ // now get the new entry...
457
+ $redirect = self::get_redirect( $updated_id );
458
+ $html = '';
459
+
460
+ ob_start();
461
+ $dfrom = urldecode($redirect->url_from);
462
+ $dto = urldecode($redirect->url_to );
463
+ include( EPS_REDIRECT_PATH . 'templates/template.redirect-entry.php');
464
+ $html = ob_get_contents();
465
+ ob_end_clean();
466
+ echo json_encode( array(
467
+ 'html' => $html,
468
+ 'redirect_id' => $updated_id
469
+ ));
470
+
471
+ exit();
472
+ }
473
 
474
  /**
475
  *
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']), '/' ) ),
499
+ 'url_to' => trim( $redirect['url_to'] ),
500
+ 'type' => trim( $redirect['type'] ),
501
+ 'status' => trim( $redirect['status'] )
502
+ );
503
+ // Add count if exists:
504
+ if( isset( $redirect['count'] ) && is_numeric( $redirect['count'] ) ) $entry['count'] = $redirect['count'];
505
+
506
  $wpdb->insert(
507
  $table_name,
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']), '/' ) ),
515
+ 'url_to' => trim( $redirect['url_to'] ),
516
+ 'type' => trim( $redirect['type'] ),
517
+ 'status' => trim( $redirect['status'] )
518
+ );
519
+ // Add count if exists:
520
+ if( isset( $redirect['count'] ) && is_numeric( $redirect['count'] ) ) $entry['count'] = $redirect['count'];
521
+
522
  $wpdb->update(
523
  $table_name,
524
+ $entry,
 
 
 
 
 
525
  array( 'id' => $redirect['id'] )
526
  );
527
+
528
+ $ids[] = $redirect['id'];
529
  }
530
 
531
  }
532
+ return $ids; // return array of affected ids.
533
 
534
  }
535
  /**
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(
556
+ "SELECT * FROM $table_name WHERE id = " . intval($redirect_id) . " LIMIT 1"
557
+ );
558
+ return array_shift($results);
559
+ }
560
 
561
  /**
562
  *
585
  * @author epstudios
586
  *
587
  */
588
+ public function do_entries(){
589
  $redirects = self::get_redirects( );
590
  $html = '';
591
  if (empty($redirects)) return false;
620
  echo json_encode( array( 'id' => $_POST['id']) );
621
  exit();
622
  }
623
+ private static function _delete( $id ){
624
+ global $wpdb;
625
+ $table_name = $wpdb->prefix . "redirects";
626
+ $wpdb->delete( $table_name, array( 'ID' => intval( $id ) ) );
627
+ }
628
 
629
  /**
630
  *
631
+ * GET_ENTRY
632
+ * AJAX_GET_ENTRY
633
+ * GET_EDIT_ENTRY
634
  *
635
  * This function will return a blank row ready for user input.
636
  *
638
  * @author epstudios
639
  *
640
  */
641
+ public static function get_entry( $redirect_id = false ) {
642
  ob_start();
643
+ ?>
644
+ <tr class="id-<?php echo ($redirect_id) ? $redirect_id : 'new'; ?>">
645
+ <?php include( EPS_REDIRECT_PATH . 'templates/template.redirect-entry-edit.php'); ?>
646
+ </tr>
647
+ <?php
648
  $html = ob_get_contents();
649
  ob_end_clean();
650
  return $html;
651
  }
652
 
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();
664
+ ob_end_clean();
665
+ echo json_encode( array(
666
+ 'html' => $html,
667
+ 'redirect_id' => $redirect_id
668
+ ));
669
+ exit();
670
+ }
671
+
672
+
673
+ public static function ajax_get_entry() {
674
+ echo self::get_entry(); exit();
675
  }
676
 
677
  public function clear_cache() {
681
  }
682
 
683
 
684
+
685
  /**
686
  *
687
  * SET_AJAX_URL
695
  echo '<script>var eps_redirect_ajax_url = "'. admin_url( 'admin-ajax.php' ) . '"</script>';
696
  }
697
 
698
+
699
+
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
 
745
 
746
+
747
+
748
  /**
749
  * Outputs an object or array in a readable form.
750
  *
eps-form-elements.php CHANGED
@@ -4,18 +4,15 @@
4
  * EPS 301 REDIRECTS
5
  *
6
  *
 
7
  *
8
- * This plugin creates a nice Wordpress settings page for creating 301 redirects on your Wordpress
9
- * blog or website. Often used when migrating sites, or doing major redesigns, 301 redirects can
10
- * sometimes be a pain - it's my hope that this plugin helps you seamlessly create these redirects
11
- * in with this quick and efficient interface.
12
  *
13
- * PHP version 5
14
  *
15
  *
16
  * @package EPS 301 Redirects
17
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
18
- * @version 1.4.0
19
  */
20
 
21
  /**
@@ -32,97 +29,159 @@
32
  function eps_get_selector( $redirect = false ) {
33
  $current_post = ( isset( $redirect->url_to ) && is_numeric( $redirect->url_to ) ) ? get_post( intval( $redirect->url_to ) ) : null;
34
 
35
- $post_types = get_post_types(array('public'=>true), 'objects');
36
-
37
-
 
 
38
  $html = eps_get_type_select($post_types, $current_post);
 
 
 
 
39
 
40
-
 
41
 
42
  // The default input, javascript will populate this input with the final URL for submission.
43
- $html .= '<input class="eps-redirect-url"
44
  type="text"
45
  name="redirect[url_to][]"
46
  value="'.( isset( $redirect->url_to ) ? $redirect->url_to : null ).'"
47
- placeholder="'.get_bloginfo('home').'" '.
48
- ( ( isset( $redirect->type ) && $redirect->type != 'post' || !isset($redirect->type) ) ? null : ' style="display:none;"' ).
49
- '/>';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
-
52
- // Get all the post type select boxes.
53
  foreach ($post_types as $post_type ) {
54
- $html .= eps_get_post_type_selects($post_type->name, $current_post);
55
  }
56
- //$html .=
57
-
58
- // Get the term select box.
59
- $html .= eps_get_term_archive_select();
60
  return $html;
61
-
62
-
63
  }
64
 
65
 
 
 
 
 
 
 
 
 
 
 
66
  function eps_get_post_type_selects( $post_type, $current_post = false ) {
67
  // Start the select.
68
- $html = '<select class="'.$post_type.' url-selector" '.( (isset($current_post) && $current_post->post_type == $post_type ) ? null : 'style="display:none;"').'>';
 
69
  $html .= '<option value="">...</option>';
70
 
71
  if ( false === ( $options = get_transient( 'post_type_cache_'.$post_type ) ) ) {
72
  $options = eps_dropdown_pages( array('post_type'=>$post_type ) );
73
  set_transient( 'post_type_cache_'.$post_type, $options, HOUR_IN_SECONDS );
74
- }
75
-
76
  foreach( $options as $option => $value ) {
77
- $html .= '<option value="'.$value.'" '.( isset($current_post) && $current_post->ID == $value ? 'selected="selected"' : null ).' >'. ( strlen($option) > 32 ? substr($option,0,32).'...' : $option ) . '</option>';
78
  }
79
  $html .= '</select>';
80
- return $html;
81
-
82
- }
83
- function eps_get_type_select( $post_types, $current_post = false ){
84
- $html = '<select class="type-select">';
85
- $html .= '<option value="eps-redirect-url">Custom</option>';
86
 
87
- foreach ($post_types as $post_type ) {
88
- $html .= '<option value="'.$post_type->name.'" '.( isset( $current_post ) && $current_post->post_type == $post_type->name ? 'selected="selected"' : null).'>'. $post_type->labels->singular_name. '</option>';
89
- }
90
- $html .= '<option value="term">Term Archive</option>';
91
- $html .= '</select>';
92
  return $html;
93
  }
94
 
95
-
96
- /**
97
- *
98
- * GET_TERM_ARCHIVE_SELECT
99
- *
100
- * This function will output a select box with all the taxonomies and terms.
101
- *
102
- * @return html string
103
- * @author epstudios
104
- *
105
- */
106
- function eps_get_term_archive_select(){
107
- $taxonomies = get_taxonomies( '', 'objects' );
108
-
109
- if (!$taxonomies) return false;
 
 
 
 
 
 
 
 
110
 
111
- // Start the select.
112
- $html = '<select class="term url-selector" style="display:none;">';
113
- $html .= '<option value="" selected default>...</option>';
114
 
115
- // Loop through all taxonomies.
116
- foreach ($taxonomies as $tax ) {
117
- $terms = get_terms( $tax->name, array('hide_empty' => false) ); // show empty terms.
118
- $html .= '<option value="'.$tax->name.'" disabled>'. $tax->labels->singular_name. '</option>';
119
-
120
- // Loop through all terms in this taxonomy and insert them as options.
121
- foreach($terms as $term)
122
- $html .= '<option value="'.get_term_link($term).'">&nbsp;&nbsp;- '. $term->name. '</option>';
123
-
124
- }
125
- $html .= '</select>';
126
- return $html;
127
  }
 
 
 
128
  ?>
4
  * EPS 301 REDIRECTS
5
  *
6
  *
7
+ * eps-form-elements.php
8
  *
9
+ * Responsible for some of the more 'complex' form elements such as post type dropdowns.
 
 
 
10
  *
 
11
  *
12
  *
13
  * @package EPS 301 Redirects
14
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
15
+ * @version 2.1.0
16
  */
17
 
18
  /**
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;
31
 
32
+ $post_types = get_post_types(array(
33
+ 'public' => true,
34
+ 'publicly_queryable' => true
35
+ ), 'objects');
36
+
37
  $html = eps_get_type_select($post_types, $current_post);
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 );
41
+ }
42
 
43
+ // Get the term select box.
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"
48
  type="text"
49
  name="redirect[url_to][]"
50
  value="'.( isset( $redirect->url_to ) ? $redirect->url_to : null ).'"
51
+ placeholder="'.get_bloginfo('home').
52
+ ( ( isset( $redirect->type ) && $redirect->type != 'post' || !isset($redirect->type) ) ? null : ' style="display:none;"' ) .
53
+ '" />';
54
+
55
+ return $html;
56
+ }
57
+
58
+
59
+ /**
60
+ *
61
+ * GET_DESTINATION
62
+ *
63
+ * This function will output the formatted destination string.
64
+ *
65
+ * @return html string
66
+ * @author epstudios
67
+ *
68
+ */
69
+ function eps_get_destination( $redirect = false ) {
70
+ if(isset( $redirect->url_to ) ) {
71
+ if( is_numeric( $redirect->url_to ) ) {
72
+ // This redirect points to a post
73
+ if( get_permalink($redirect->url_to) ) {
74
+ ?>
75
+ <a target="_blank" class="eps-url" href="<?php echo get_permalink($redirect->url_to); ?>" title="<?php echo get_permalink($redirect->url_to); ?>">
76
+ <span class="eps-url-root eps-url-startcap" ><?php echo strtoupper( get_post_type( $redirect->url_to ) ); ?></span><span class="eps-url-root">ID: <?php echo $redirect->url_to; ?> </span><span class="eps-url-fragment eps-url-endcap "><?php echo get_the_title($redirect->url_to); ?> </span>
77
+ </a>
78
+ <?php
79
+ } else {
80
+ ?>
81
+ <span class="eps-url eps-warning">
82
+ <span class="eps-url-root eps-url-startcap">ID: <?php echo $redirect->url_to; ?> </span>
83
+ <span class="eps-url-fragment eps-url-endcap ">DOES NOT EXIST</span>
84
+ </span>
85
+ <?php
86
+ }
87
+ } else {
88
+ // This is redirect points to a url
89
+ ?>
90
+ <a target="_blank" class="eps-url" href="<?php echo esc_attr( $redirect->url_to ); ?>" title="<?php echo esc_attr( $redirect->url_to ); ?>">
91
+ <span class="eps-url-root eps-url-startcap" >URL:</span><span class="eps-url-fragment eps-url-endcap "><?php echo esc_attr( $redirect->url_to ); ?></span>
92
+ </a>
93
+ <?php
94
+ }
95
+
96
+ } else {
97
+ echo '<span class="eps-warning">Invalid Destination URL</span>';
98
+ }
99
+ }
100
+
101
+
102
+
103
+ /**
104
+ *
105
+ * GET_TYPE_SELECT
106
+ *
107
+ * This function will output the available destination types.
108
+ *
109
+ * @return html string
110
+ * @author epstudios
111
+ *
112
+ */
113
+ function eps_get_type_select( $post_types, $current_post = false ){
114
+ $html = '<select class="type-select eps-small-select">';
115
+ $html .= '<option value="eps-url-input">Custom</option>';
116
 
 
 
117
  foreach ($post_types as $post_type ) {
118
+ $html .= '<option value="'.$post_type->name.'" '.( isset( $current_post ) && $current_post->post_type == $post_type->name ? 'selected="selected"' : null).'>'. $post_type->labels->singular_name. '</option>';
119
  }
120
+ $html .= '<option value="term">Term Archive</option>';
121
+ $html .= '</select>';
 
 
122
  return $html;
 
 
123
  }
124
 
125
 
126
+ /**
127
+ *
128
+ * GET_POST_TYPE_SELECT
129
+ *
130
+ * This function will output the available post types.
131
+ *
132
+ * @return html string
133
+ * @author epstudios
134
+ *
135
+ */
136
  function eps_get_post_type_selects( $post_type, $current_post = false ) {
137
  // Start the select.
138
+
139
+ $html = '<select class="select-'.$post_type.' url-selector eps-small-select" '.( (isset($current_post) && $current_post->post_type == $post_type ) ? null : 'style="display:none;"').'>';
140
  $html .= '<option value="">...</option>';
141
 
142
  if ( false === ( $options = get_transient( 'post_type_cache_'.$post_type ) ) ) {
143
  $options = eps_dropdown_pages( array('post_type'=>$post_type ) );
144
  set_transient( 'post_type_cache_'.$post_type, $options, HOUR_IN_SECONDS );
145
+ }
146
+
147
  foreach( $options as $option => $value ) {
148
+ $html .= '<option value="'.$value.'" '.( isset($current_post) && $current_post->ID == $value ? 'selected="selected"' : null ).' >'. ucwords( $option ) . '</option>';
149
  }
150
  $html .= '</select>';
 
 
 
 
 
 
151
 
 
 
 
 
 
152
  return $html;
153
  }
154
 
155
+ /**
156
+ *
157
+ * GET_TERM_ARCHIVE_SELECT
158
+ *
159
+ * This function will output a select box with all the taxonomies and terms.
160
+ *
161
+ * @return html string
162
+ * @author epstudios
163
+ *
164
+ */
165
+ function eps_get_term_archive_select(){
166
+ $taxonomies = get_taxonomies( '', 'objects' );
167
+
168
+ if (!$taxonomies) return false;
169
+
170
+ // Start the select.
171
+ $html = '<select class="select-term url-selector eps-small-select" style="display:none;">';
172
+ $html .= '<option value="" selected default>...</option>';
173
+
174
+ // Loop through all taxonomies.
175
+ foreach ($taxonomies as $tax ) {
176
+ $terms = get_terms( $tax->name, array('hide_empty' => false) ); // show empty terms.
177
+ $html .= '<option value="'.$tax->name.'" disabled>'. $tax->labels->singular_name. '</option>';
178
 
179
+ // Loop through all terms in this taxonomy and insert them as options.
180
+ foreach($terms as $term)
181
+ $html .= '<option value="'.get_term_link($term).'">&nbsp;&nbsp;- '. $term->name. '</option>';
182
 
 
 
 
 
 
 
 
 
 
 
 
 
183
  }
184
+ $html .= '</select>';
185
+ return $html;
186
+ }
187
  ?>
js/scripts.js CHANGED
@@ -13,7 +13,7 @@ jQuery(document).ready(function ($) {
13
  $(document).on("change", 'select.type-select', function() {
14
  var input_type = $(this).val();
15
  $(this).siblings().hide();
16
- $(this).siblings('.'+input_type).show();
17
  });
18
 
19
  /**
@@ -22,34 +22,170 @@ jQuery(document).ready(function ($) {
22
  * When a select box is changed, send that new value to our input.
23
  */
24
  $(document).on("change", 'select.url-selector', function() {
25
- $(this).siblings('.eps-redirect-url').val( $(this).val() );
26
- console.log( $(this).closest('tr.redirect-entry').find('.eps-text-link.test') );
27
- $(this).closest('tr.redirect-entry').find('.eps-text-link.test').addClass('inactive');
28
  });
29
 
 
 
 
30
  /**
 
 
 
 
31
  *
32
  *
33
- * Grey out the test button if it's been changed.
34
  */
35
- $('tr.redirect-entry .eps-text-link.test').on('click', function(e) {
36
- if( $(this).hasClass('inactive') ) e.preventDefault();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  });
38
 
39
 
 
40
  /**
41
  *
42
  *
43
- * Get a new blank input.
 
 
 
 
44
  */
45
- $('#eps-redirect-add').click( function(e){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  e.preventDefault();
47
- var request = $.post( eps_redirect_ajax_url, {
48
- 'action' : 'eps_redirect_get_new_entry'
49
- });
50
- request.done(function( data ) {
51
- $('#eps-redirect-entries tr:last-child').before( data );
52
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
53
  });
54
 
55
 
@@ -60,31 +196,33 @@ jQuery(document).ready(function ($) {
60
  *
61
  * Delete an entry.
62
  */
63
- $('.eps-text-link.remove').click( function(e){
64
  e.preventDefault();
 
 
 
 
65
  var request = $.post( eps_redirect_ajax_url, {
66
  'action' : 'eps_redirect_delete_entry',
67
- 'id' : $(this).siblings('.redirect-id').val()
68
  });
69
  request.done(function( data ) {
70
  var response = JSON.parse(data);
71
- $('tr.redirect-entry.id-'+response.id).remove();
 
 
72
  });
73
 
74
-
75
  });
76
 
77
 
78
-
79
-
80
-
81
-
82
  /**
83
  *
84
  *
85
  * Tabs
86
  */
87
- $('#eps-tab-nav .eps-tab-nav-item').click(function(e){
88
  //e.preventDefault();
89
  var target = $(this).attr('href');
90
 
@@ -99,22 +237,6 @@ jQuery(document).ready(function ($) {
99
  });
100
 
101
 
102
-
103
- /**
104
- *
105
- *
106
- * Open up the tab as per the current location
107
- */
108
- var hash = window.location.hash;
109
-
110
- if( hash ) {
111
- $('#eps-tabs .eps-tab').hide();
112
- $(hash+'-pane').show();
113
- $('#eps-tab-nav .eps-tab-nav-item').removeClass('active');
114
- $('#eps-tab-nav .eps-tab-nav-item').eq( $(hash +'-pane').index() ).addClass('active');
115
- } else {
116
- $('#eps-tab-nav .eps-tab-nav-item').show();
117
- }
118
 
119
  });
120
 
13
  $(document).on("change", 'select.type-select', function() {
14
  var input_type = $(this).val();
15
  $(this).siblings().hide();
16
+ $(this).parent('td').find('.select-'+input_type).show();
17
  });
18
 
19
  /**
22
  * When a select box is changed, send that new value to our input.
23
  */
24
  $(document).on("change", 'select.url-selector', function() {
25
+ $(this).parent('td').find('.eps-url-input').val( $(this).val() );
 
 
26
  });
27
 
28
+
29
+
30
+
31
  /**
32
+ *
33
+ * Edit a Redirect
34
+ *
35
+ * Gets the redirect edit form, and replaces the row.
36
  *
37
  *
 
38
  */
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
63
+ alert('Couldn\'t find this redirect.');
64
+ }
65
+ });
66
  });
67
 
68
 
69
+
70
  /**
71
  *
72
  *
73
+ * Cancel an Edit.
74
+ *
75
+ * Cancels the Edit implement on a redirect entry.
76
+ *
77
+ *
78
  */
79
+ $('.eps-table').on('click', 'a.eps-redirect-cancel', function(e){
80
+ e.preventDefault();
81
+ $('#eps-redirect-edit').remove();
82
+ $('tr.redirect-entry').removeClass('active');
83
+ $('#eps-redirect-add').show();
84
+ });
85
+
86
+
87
+
88
+ /**
89
+ *
90
+ *
91
+ * AJAX Save a New or Existing Redirect.
92
+ *
93
+ * Checks for a form submission, then handles it VIA ajax.
94
+ *
95
+ */
96
+ $('.eps-table').on('submit', '#eps-redirect-save', function(e){
97
  e.preventDefault();
98
+
99
+ $('#eps-redirect-save input[type="submit"]').prop('disabled', true); // Disable button to disallow multiple submissions.
100
+
101
+ $.ajax({
102
+ type: 'POST',
103
+ url: eps_redirect_ajax_url,
104
+ data: {
105
+ 'action': 'eps_redirect_save',
106
+ 'id': $('#eps-redirect-save input[name="redirect[id][]"]').val(),
107
+ 'status': $('#eps-redirect-save select[name="redirect[status][]"]').val(),
108
+ 'url_from': $('#eps-redirect-save input[name="redirect[url_from][]"]').val(),
109
+ 'url_to': $('#eps-redirect-save input[name="redirect[url_to][]"]').val()
110
+ },
111
+ success: function(data){
112
+ // Successful Request:
113
+ var data = jQuery.parseJSON( data );
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();
124
+ }
125
+ $('#eps-redirect-save input[type="submit"]').prop('disabled', false); // Re-enable button.
126
+
127
+ },
128
+ error: function(){
129
+ // failed request; give feedback to user
130
+ alert('Couldn\'t find this redirect.');
131
+ $('#eps-redirect-save input[type="submit"]').prop('disabled', false); // Re-enable button.
132
+ }
133
+ });
134
+
135
+
136
+
137
+ });
138
+
139
+
140
+
141
+
142
+ /**
143
+ *
144
+ * New Redirect.
145
+ *
146
+ * Get a new blank edit form for a new redirect.
147
+ *
148
+ * We expect to receive an id of 0 returned from the Ajax query.
149
+ *
150
+ */
151
+ $('.eps-table #eps-redirect-new').on('click', function(e){
152
+ e.preventDefault();
153
+ $(this).prop('disabled', true); $(this).attr('disabled', 'disabled'); // Disable button to disallow multiple submissions.
154
+
155
+ // Do the request
156
+ $.ajax({
157
+ type: 'POST',
158
+ url: eps_redirect_ajax_url,
159
+ data: {
160
+ 'action': 'eps_redirect_get_inline_edit_entry',
161
+ 'redirect_id': false,
162
+ },
163
+ success: function(data){
164
+ var data = jQuery.parseJSON( data );
165
+ $('#eps-redirect-edit').remove();
166
+ $('tr.redirect-entry').removeClass('active');
167
+
168
+
169
+ if( data.redirect_id == 0 ) {
170
+ // If it's new, do a new.
171
+ $('#eps-redirect-add').hide();
172
+ $(data.html).insertBefore('tr#eps-redirect-add');
173
+ } else {
174
+ // If it's a new blank form.. why have an id?
175
+ alert('Something strange happened. A new entry could not be loaded.');
176
+ }
177
+ $(this).prop('disabled', false); $(this).attr('disabled', false); // Disable button to disallow multiple submissions.
178
+
179
+ },
180
+ error: function(){
181
+ // failed request; give feedback to user
182
+ alert('A new entry form could not be loaded.');
183
+ $(this).prop('disabled', false); $(this).attr('disabled', false); // Disable button to disallow multiple submissions.
184
+ }
185
+ });
186
+
187
+
188
+
189
  });
190
 
191
 
196
  *
197
  * Delete an entry.
198
  */
199
+ $('.redirect-actions a.eps-redirect-remove').on('click', function(e){
200
  e.preventDefault();
201
+ if( $(this).attr('disabled') ) return false;
202
+
203
+ $(this).prop('disabled', true); $(this).attr('disabled', 'disabled'); // Disable button to disallow multiple submissions.
204
+
205
  var request = $.post( eps_redirect_ajax_url, {
206
  'action' : 'eps_redirect_delete_entry',
207
+ 'id' : $(this).data('id')
208
  });
209
  request.done(function( data ) {
210
  var response = JSON.parse(data);
211
+ $('tr.redirect-entry.id-'+response.id).fadeOut();
212
+ $(this).prop('disabled', false); $(this).attr('disabled', false); // Disable button to disallow multiple submissions.
213
+
214
  });
215
 
 
216
  });
217
 
218
 
219
+
 
 
 
220
  /**
221
  *
222
  *
223
  * Tabs
224
  */
225
+ $('#eps-tab-nav .eps-tab-nav-item').on('click', function(e){
226
  //e.preventDefault();
227
  var target = $(this).attr('href');
228
 
237
  });
238
 
239
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
 
241
  });
242
 
readme.txt CHANGED
@@ -4,7 +4,7 @@ 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.0.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -59,7 +59,12 @@ EPS 301 Redirects requires that you use anything but the default permalink struc
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, spelling mistakes and invalid characters.
 
 
 
 
 
63
 
64
 
65
  = My redirects aren't getting the 301 status code =
@@ -72,6 +77,10 @@ Your Request or Redirect URLS may be incorrect; please ensure that you are suppl
72
  Click the small X beside the redirect you wish to remove. Save changes.
73
 
74
 
 
 
 
 
75
 
76
 
77
 
@@ -83,6 +92,10 @@ Click the small X beside the redirect you wish to remove. Save changes.
83
 
84
  == Changelog ==
85
 
 
 
 
 
86
  = 2.0.1 =
87
  Fixed an issue where the Automatic Update would not call the import process for pre 2.0 versions.
88
 
@@ -121,6 +134,10 @@ Overhauled the entire plugin. Redirects are stored in their own table. Gracefull
121
 
122
  == Upgrade Notice ==
123
 
 
 
 
 
124
  = 2.0.1 =
125
  Fixed an issue where the Automatic Update would not call the import process for pre 2.0 versions.
126
 
4
  Tags: 301 redirects, redirects
5
  Requires at least: 3.0.1
6
  Tested up to: 3.8.1
7
+ Stable tag: 2.1.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
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 =
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
 
93
  == Changelog ==
94
 
95
+ = 2.1.1 =
96
+ Fixed an issue where users with a lot of redirects were being limited, this fix also changed up the admin area. Redirects are now editable via AJAX, and the ‘add new’ form was moved to the top.
97
+
98
+
99
  = 2.0.1 =
100
  Fixed an issue where the Automatic Update would not call the import process for pre 2.0 versions.
101
 
134
 
135
  == Upgrade Notice ==
136
 
137
+ = 2.1.1 =
138
+ Fixed an issue where users with a lot of redirects were being limited, this fix also changed up the admin area. Redirects are now editable via AJAX, and the ‘add new’ form was moved to the top.
139
+
140
+
141
  = 2.0.1 =
142
  Fixed an issue where the Automatic Update would not call the import process for pre 2.0 versions.
143
 
templates/admin.php CHANGED
@@ -1,19 +1,21 @@
1
  <?php
2
  /**
3
  *
4
- * EPS OPENGRAPH
5
  *
 
6
  *
 
7
  *
8
- * This plugin creates opengrah data for pages, posts and custom post types.
9
  *
10
- * PHP version 5
11
  *
12
  *
13
  * @package EPS 301 Redirects
14
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
15
- * @version 1.3.4
16
  */
 
 
17
  global $wp_rewrite;
18
 
19
  ?>
@@ -42,7 +44,8 @@ global $wp_rewrite;
42
  </div>
43
 
44
  </div>
45
- <div id="donate-box">
 
46
  <div class="eps-padding">
47
  <p>Comments, questions, bugs and feature requests can be sent to: <a href="mailto:plugins@eggplantstudios.ca">plugins@eggplantstudios.ca</a></p>
48
  <hr>
@@ -57,6 +60,26 @@ global $wp_rewrite;
57
  </form>
58
  </div>
59
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
60
  </div>
61
 
62
 
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
  ?>
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>
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
 
templates/admin.redirects.php CHANGED
@@ -1,43 +1,36 @@
1
  <?php
2
  /**
3
  *
4
- * EPS OPENGRAPH
5
  *
 
6
  *
 
7
  *
8
- * This plugin creates opengrah data for pages, posts and custom post types.
9
  *
10
- * PHP version 5
11
  *
12
  *
13
  * @package EPS 301 Redirects
14
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
15
- * @version 1.3.4
16
  */
17
  ?>
18
- <div id="eps-redirect-redirects-pane" class="eps-tab">
19
 
20
- <form method="post" action="">
21
- <table id="eps-redirect-entries">
22
- <tr class="redirect-entry">
23
- <th>Status</th>
24
  <th>Request URL</th>
25
  <th>Redirect To</th>
26
- <th>Hits</th>
27
- <th>Actions</th>
28
- </tr> <?php
29
- echo self::do_inputs();
30
- echo self::get_blank_entry();
31
- ?>
32
- <tr><td colspan="3"><a class="eps-text-link new" href="#" id="eps-redirect-add">+ Add Empty</a></td></tr>
33
- </table>
34
- <hr class="eps-divider">
35
- <p class="submit">
36
- <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
37
- <input type="submit" name="eps_redirect_refresh" id="submit" class="button button-secondary" value="Refresh Cache"/>&nbsp;&nbsp;
38
- <input type="submit" name="eps_redirect_submit" id="submit" class="button button-primary" value="Save Changes"/>
39
- <p><small class="eps-grey-text">Refresh the cache if the dropdowns are out of date.</small></p>
40
- </p>
41
- </form>
42
 
43
- </div>
 
 
 
 
 
 
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>
23
  <th>Redirect To</th>
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>
templates/admin.settings.php DELETED
@@ -1,51 +0,0 @@
1
- <?php
2
- /**
3
- *
4
- * EPS redirects
5
- *
6
- *
7
- *
8
- * This plugin creates opengrah data for pages, posts and custom post types.
9
- *
10
- * PHP version 5
11
- *
12
- *
13
- * @package EPS 301 Redirects
14
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
15
- * @version 1.3.4
16
- */
17
-
18
-
19
- ?>
20
-
21
-
22
- <div id="eps-redirect-settings-pane" class="eps-tab">
23
-
24
-
25
- <form method="post" action="">
26
-
27
- <table class="eps-redirect-table">
28
- <tr>
29
- <td class="eps-redirect-section-spacer">&nbsp;</td>
30
- <td>
31
- <table class="eps-redirect-meta">
32
- <tr><th>Test Urls?</th>
33
- <td class="padding">
34
-
35
- <label><input type="checkbox" name="eps_redirect_settings[test_urls]" <?php echo( isset($settings['test_urls']) && $settings['test_urls'] == 'on' ) ? 'checked="checked"': null; ?>> Turn URL testing ON </label>
36
- <br>
37
- <small>This will test your redirects on the Admin Panel to help debug. Warning, this can severly affect page load times, please consider not using this if you have more than 20 redirects.</small>
38
- </td>
39
- </tr>
40
- </table>
41
- </td>
42
- </tr>
43
-
44
- </table>
45
- <hr class="eps-divider">
46
- <p class="submit">
47
- <?php wp_nonce_field('eps_redirect_setting_nonce', 'eps_redirect_setting_nonce_submit'); ?>
48
- <input type="submit" name="eps_redirect_settings_submit" id="submit" class="button button-primary" value="Save Changes"/>
49
- </p>
50
- </form>
51
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
templates/template.redirect-entry-edit-inline.php ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
19
+ ?>
20
+ <tr id="eps-redirect-edit">
21
+ <td colspan="4">
22
+ <form id="eps-redirect-save" method="post" action="">
23
+ <table class="eps-table">
24
+ <tr class="id-<?php echo ($redirect_id) ? $redirect_id : 'new'; ?>">
25
+ <?php include( EPS_REDIRECT_PATH . 'templates/template.redirect-entry-edit.php'); ?>
26
+ <td class="redirect-actions">
27
+ <?php if( $redirect_id ) { ?>
28
+ <a class="button eps-redirect-cancel">Close</a>
29
+ <?php } ?>
30
+ <?php wp_nonce_field('eps_redirect_nonce', 'eps_redirect_nonce_submit'); ?>
31
+ <input type="submit" name="eps_redirect_submit" class="button button-primary eps-redirect-edit" value="Save">
32
+ </td>
33
+ </tr>
34
+ </table>
35
+ </form>
36
+ </td>
37
+ </tr>
templates/template.redirect-entry-edit.php ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 );
19
+
20
+ ?>
21
+ <td>
22
+ <input type="hidden" type="text" name="redirect[id][]" value="<?php echo ($redirect_id) ? $redirect_id : ''; ?>" >
23
+
24
+ <select name="redirect[status][]" class="eps-small-select">
25
+ <option default value="301" <?php echo ( $redirect && $redirect->status == '301' ) ? 'selected="selected"' : null; ?>>301</option>
26
+ <option value="302" <?php echo ( $redirect && $redirect->status == '302' ) ? 'selected="selected"' : null; ?>>302</option>
27
+ <option value="inactive" <?php echo ( $redirect && $redirect->status == 'inactive' ) ? 'selected="selected"' : null; ?>>Off</option>
28
+ </select>
29
+
30
+ <div class="eps-url"><span class="eps-url-root"><?php bloginfo('url'); ?>/&nbsp;</span></div>
31
+ <input class="eps-url-input" type="text" name="redirect[url_from][]" value="<?php echo ($redirect) ? $redirect->url_from : ''; ?>" >
32
+
33
+ </td>
34
+ <td>
35
+ <?php echo eps_get_selector( $redirect ); ?>
36
+ </td>
templates/template.redirect-entry-empty.php DELETED
@@ -1,33 +0,0 @@
1
- <?php
2
- /**
3
- *
4
- * EPS redirects
5
- *
6
- *
7
- *
8
- * PHP version 5
9
- *
10
- *
11
- * @package EPS 301 Redirects
12
- * @author Shawn Wernig ( shawn@eggplantstudios.ca )
13
- * @version 1.3.4
14
- */
15
-
16
-
17
- ?>
18
- <tr class="redirect-entry">
19
- <td>
20
- <select name="redirect[status][]" class="simple">
21
- <option value="301">301</option>
22
- <option value="302">302</option>
23
- <option value="inactive">Off</option>
24
- </select>
25
- </td>
26
- <td>
27
- <span class="eps-grey-text"><small><?php bloginfo('home'); ?>/&nbsp;</small></span>
28
- <input class="eps-request-url" type="text" name="redirect[url_from][]" value="" >
29
- </td>
30
- <td><?php echo eps_get_selector(); ?></td>
31
- <td></td>
32
- <td class="redirect-actions">&nbsp;</td>
33
- </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
templates/template.redirect-entry.php CHANGED
@@ -1,40 +1,37 @@
1
  <?php
2
  /**
3
  *
4
- * EPS redirects
5
  *
 
 
 
6
  *
7
  *
8
- * PHP version 5
9
  *
10
  *
11
  * @package EPS 301 Redirects
12
  * @author Shawn Wernig ( shawn@eggplantstudios.ca )
13
- * @version 1.3.4
14
  */
15
 
 
 
 
16
 
17
  ?>
18
- <tr class="redirect-entry <?php echo $redirect->status; ?> id-<?php echo $redirect->id; ?>">
19
- <td><span>
20
- <select name="redirect[status][]" class="simple">
21
- <option value="301" <?php echo ( $redirect->status == '301' ) ? 'selected="selected"' : null; ?>>301</option>
22
- <option value="302" <?php echo ( $redirect->status == '302' ) ? 'selected="selected"' : null; ?>>302</option>
23
- <option value="inactive" <?php echo ( $redirect->status == 'inactive' ) ? 'selected="selected"' : null; ?>>Off</option>
24
- </select>
25
- </span>
26
- </td>
27
  <td>
28
- <span class="eps-grey-text"><small><?php bloginfo('home'); ?>/&nbsp;</small></span>
29
- <input class="eps-request-url" type="text" name="redirect[url_from][]" value="<?php echo $dfrom; ?>" >
 
30
  </td>
31
  <td>
32
- <?php echo eps_get_selector( $redirect ); ?>
33
  </td>
34
- <td class="text-center"><strong><?php echo $redirect->count; ?></strong></td>
35
  <td class="redirect-actions">
36
- <input type="hidden" class="redirect-id" name="redirect[id][]" value="<?php echo $redirect->id; ?>" >
37
- <a class="eps-text-link test" href="<?php echo self::format_from_url( $redirect->url_from ); ?>" target="_blank">Test</a>
38
- <a class="eps-text-link remove eps-redirect-remove" href="#" class="">&times;</a>
39
  </td>
40
  </tr>
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>
27
+ </a>
28
  </td>
29
  <td>
30
+ <?php echo eps_get_destination( $redirect ); ?>
31
  </td>
32
+ <td class="redirect-hits"><strong><?php echo esc_attr( $redirect->count ); ?></strong></td>
33
  <td class="redirect-actions">
34
+ <a class="button eps-redirect-edit" href="#eps-redirect-edit" data-id="<?php echo esc_attr( $redirect->id ); ?>">Edit</a>
35
+ <a class="button eps-redirect-remove" href="<?php echo add_query_arg( $query_args, admin_url( '/options-general.php' ) ); ?>" data-id="<?php echo esc_attr( $redirect->id ); ?>">&times;</a>
 
36
  </td>
37
  </tr>