WP htaccess Control - Version 3.1

Version Description

(27/04/2012) = * Fix: 3.0 introduced errors (removal of bases regardless of the settings); * Optimized number of actions and filters and database access.

Download this release

Release Info

Developer antonioandra.de
Plugin Icon wp plugin WP htaccess Control
Version 3.1
Comparing to
See all releases

Code changes from version 3.0 to 3.1

Files changed (3) hide show
  1. readme.txt +5 -1
  2. wp-htaccess-control-ui.php +40 -41
  3. wp-htaccess-control.php +233 -216
readme.txt CHANGED
@@ -7,7 +7,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=s4man
7
  Tags: permalinks, permalink, author, htaccess, rewrite, redirect, admin, maintenance, pagination, category, category base, archive, archives
8
  Requires at least: 2.7
9
  Tested up to: 3.3.2
10
- Stable tag: 3.0
11
 
12
  Interface to customize the permalinks (author, category, archives and pagination) and htaccess file generated by Wordpress.
13
 
@@ -76,6 +76,10 @@ Search redirection is based on Mark Jaquith's **Nice Search** but extended so th
76
 
77
  == Changelog ==
78
 
 
 
 
 
79
  = 3.0 (26/04/2012) =
80
  * Feature: base slug and archive creation for any taxonomy;
81
  * Major rewrite of core methods.
7
  Tags: permalinks, permalink, author, htaccess, rewrite, redirect, admin, maintenance, pagination, category, category base, archive, archives
8
  Requires at least: 2.7
9
  Tested up to: 3.3.2
10
+ Stable tag: 3.1
11
 
12
  Interface to customize the permalinks (author, category, archives and pagination) and htaccess file generated by Wordpress.
13
 
76
 
77
  == Changelog ==
78
 
79
+ = 3.1 (27/04/2012) =
80
+ * Fix: 3.0 introduced errors (removal of bases regardless of the settings);
81
+ * Optimized number of actions and filters and database access.
82
+
83
  = 3.0 (26/04/2012) =
84
  * Feature: base slug and archive creation for any taxonomy;
85
  * Major rewrite of core methods.
wp-htaccess-control-ui.php CHANGED
@@ -6,12 +6,11 @@ $plugin_url = WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__));
6
  $q=explode('&',$_SERVER['QUERY_STRING']);
7
  $purl='http'.((!empty($_SERVER['HTTPS'])) ? 's' : '').'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$q[0];
8
  global $WPhtc, $echo;
9
- $WPhtc->wphtc_page_action();
10
- $WPhtc_data=get_option('WPhtc_data');
11
 
12
  ?>
13
  <div id="wphtc-page" class="wrap">
14
- <h2>Wp htaccess Control 3.0</h2>
15
  <?php
16
  if(!current_user_can("administrator")) {
17
  echo '<p>'.__('Please log in as admin','wp-htaccess-control').'</p>';
@@ -48,7 +47,7 @@ $WPhtc_data=get_option('WPhtc_data');
48
  <div class="updated fade" id="message" style="background-color: rgb(255, 251, 204);"><p><?php echo $echo;?></p></div>
49
  <?php }
50
  # Donation Message
51
- if($WPhtc_data['donation_hidden_time']&&$WPhtc_data['donation_hidden_time']<time()){?>
52
  <div class="updated">
53
  <p>
54
  <strong>Is this plugin useful? Consider making a donation encouraging me to continue supporting it!</strong>
@@ -69,7 +68,7 @@ $WPhtc_data=get_option('WPhtc_data');
69
  <td >
70
  <p class="description"><?php _e('This plugin has made such a long way that it should really now be called <strong>WP htaccess and Rewrite Control</strong>.', 'wp-htaccess-control');?></p>
71
  <p class="description"><?php _e('Many core parts of WP htaccess Control have been almost completely re-done in version 3.0 with the goal of providing an universal solution. This means that you can now selectively remove base slugs and create full archives for any custom taxonomy in addiction to the previous Category and Post tags.', 'wp-htaccess-control');?></p>
72
- <p class="description"><?php _e('This changes also mean that some unforeseen issues might arise. Please report them. If your setup seems to get out of control there are a few easy options to reverse all changes: 1) Click on "Reset all rules", at the bottom of this page; 2) rename/delete the plugin folder and re-submit your permalink settings under "Settings > Permalinks" and 3) if the previous did not solve your issue, remove the .htaccess file on your blog\'s root directory and repeat step 2.', 'wp-htaccess-control');?></p>
73
  </td>
74
  </tr>
75
  </table>
@@ -85,7 +84,7 @@ $WPhtc_data=get_option('WPhtc_data');
85
  <tr valign="top">
86
  <th scope="row" style="width:18%;"><?php _e('Author Base', 'wp-htaccess-control'); ?></th>
87
  <td >
88
- <input type="text" name="WPhtc_cap" value="<?php echo $WPhtc_data['cap']; ?>" />
89
  <p><code><?php bloginfo('home')?>/<em><?php _e('(your-base)', 'wp-htaccess-control');?></em>/admin</code></p>
90
  </td>
91
  <td valign="middle">
@@ -98,7 +97,7 @@ $WPhtc_data=get_option('WPhtc_data');
98
  <tr valign="top">
99
  <th>Google XML Sitemap</th>
100
  <td>
101
- <input type="checkbox" name="WPhtc_sm_enabled" value="true" <?php if($WPhtc_data['sm_enabled']){ echo "checked";}?>/> <?php _e('Apply Custom Author Permalink on Generated Sitemap', 'wp-htaccess-control'); ?>
102
  </td>
103
  <td valign="middle" >
104
  <p class="description"><?php _e('Leave "Include author pages" unchecked on Google XML Sitemap options page if using this.', 'wp-htaccess-control'); ?></p>
@@ -118,7 +117,7 @@ $WPhtc_data=get_option('WPhtc_data');
118
  <tr valign="top">
119
  <th scope="row" style="width:18%;"><?php _e('Page Base', 'wp-htaccess-control'); ?></th>
120
  <td >
121
- <input type="text" name="WPhtc_cpp" value="<?php echo $WPhtc_data['cpp']; ?>" />
122
  <p><code><?php bloginfo('home')?>/<em><?php _e('(your-base)', 'wp-htaccess-control');?></em>/2</code></p>
123
  </td>
124
  <td valign="middle">
@@ -139,7 +138,7 @@ $WPhtc_data=get_option('WPhtc_data');
139
  <tr valign="top">
140
  <th scope="row" style="width:18%;"><?php _e('Search Base', 'wp-htaccess-control'); ?></th>
141
  <td >
142
- <input type="text" name="WPhtc_custom_search_permalink" value="<?php echo $WPhtc_data['custom_search_permalink']; ?>" />
143
  <p><code><?php bloginfo('home')?>/<em><?php _e('(your-base)', 'wp-htaccess-control');?></em>/search-term</code></p>
144
  </td>
145
  <td valign="middle">
@@ -161,7 +160,7 @@ $WPhtc_data=get_option('WPhtc_data');
161
  <tr valign="top">
162
  <th scope="row" style="width:18%;"><?php _e('Remove Author Base', 'wp-htaccess-control'); ?></th>
163
  <td >
164
- <input type="checkbox" name="WPhtc_remove_author_base" <?php if($WPhtc_data['remove_author_base']){echo "checked=checked";} ?> />
165
  </td>
166
  <td valign="middle">
167
  <p class="description"><?php _e('If active, the author base will be removed from permalinks:'); ?></p>
@@ -176,7 +175,7 @@ $WPhtc_data=get_option('WPhtc_data');
176
  <tr valign="top">
177
  <th scope="row" style="width:18%;"><?php _e('Remove', 'wp-htaccess-control'); echo " ".$taxonomy->labels->name." " ; _e('Base', 'wp-htaccess-control'); ?></th>
178
  <td >
179
- <input type="checkbox" name="WPhtc_remove_base[<?php echo $taxonomy->name; ?>]" <?php if($WPhtc_data['remove_taxonomy_base'][$taxonomy->name]){echo "checked=checked";} ?> />
180
  </td>
181
  <td valign="middle">
182
  <p class="description"><?php _e('If active, the'); echo " ".$taxonomy->labels->name." "; _e('base will be removed from permalinks:'); ?></p>
@@ -202,7 +201,7 @@ $WPhtc_data=get_option('WPhtc_data');
202
  <tr valign="top">
203
  <th scope="row" style="width:18%;"><?php _e('Create', 'wp-htaccess-control'); echo " ".$taxonomy->labels->name." " ; _e('Archives', 'wp-htaccess-control'); ?></th>
204
  <td >
205
- <input type="checkbox" name="WPhtc_create_archive[<?php echo $taxonomy->name; ?>]" <?php if($WPhtc_data['create_archive'][$taxonomy->name]){echo "checked=checked";} ?> />
206
  </td>
207
  <td valign="middle">
208
  <p class="description"><?php _e('If active, taxonomy-based archives will be accessible:', 'wp-htaccess-control'); ?></p>
@@ -225,7 +224,7 @@ $WPhtc_data=get_option('WPhtc_data');
225
  <table class="form-table wphtc-inputs">
226
  <tr valign="top">
227
  <td>
228
- <textarea name="WPhtc_hta" style="width:100%;" rows="7"><?php echo stripslashes($WPhtc_data['hta']); ?></textarea>
229
  </td>
230
  <td style="width:50%;">
231
  <p class="description"><?php _e('This rules will be printed before any Wordpress rules.', 'wp-htaccess-control'); ?></p>
@@ -248,9 +247,9 @@ $WPhtc_data=get_option('WPhtc_data');
248
  <table class="form-table wphtc-inputs">
249
  <tr valign="top">
250
  <td>
251
- <textarea name="WPhtc_wp_hta" style="width:100%;" rows="7" <?php if($WPhtc_data['jim_morgan_hta']){ echo "readonly='true' class='readonly'";}?>><?php echo stripslashes($WPhtc_data['wp_hta']); ?></textarea>
252
  <p class="description"><?php _e('Leave empty for default.', 'wp-htaccess-control'); ?></p>
253
- <p><input type="checkbox" name="WPhtc_jim_morgan_hta" value="true" <?php if($WPhtc_data['jim_morgan_hta']){ echo "checked";}?>/>
254
  <?php _e("<strong>Use <a href='http://www.webmasterworld.com/apache/4053973.htm'>Jim Morgan's wordpress htaccess</a></strong> (has been reported to \"speed up your WP mod_rewrite code by a factor of more than two\")", 'wp-htaccess-control'); ?></p>
255
  </td>
256
  <td style="width:50%;">
@@ -258,7 +257,7 @@ $WPhtc_data=get_option('WPhtc_data');
258
  <p class="description"><?php _e('Please double check them before saving as a mistake could make your site inaccessible.', 'wp-htaccess-control'); ?></p>
259
  <p class="description"><?php _e('Original rules:', 'wp-htaccess-control'); ?></p>
260
  <p class="description">
261
- <code><?php echo nl2br(htmlspecialchars(substr($WPhtc_data['htaccess_original'],0,-1)));?></code>
262
  </p>
263
  </td>
264
  </tr>
@@ -274,7 +273,7 @@ $WPhtc_data=get_option('WPhtc_data');
274
  <tr valign="top">
275
  <th scope="row" style="width:18%;"><?php _e('ServerSignature', 'wp-htaccess-control'); ?></th>
276
  <td style="width:3%;" valign="middle">
277
- <input type="checkbox" name="WPhtc_disable_serversignature" value="true" <?php if($WPhtc_data['disable_serversignature']){ echo "checked";}?>/>
278
  </td>
279
  <td valign="middle">
280
  <p class="description"><?php _e('Disable the ServerSignature on server generated error pages.', 'wp-htaccess-control'); ?></p>
@@ -283,7 +282,7 @@ $WPhtc_data=get_option('WPhtc_data');
283
  <tr valign="top">
284
  <th scope="row"><?php _e('Indexes', 'wp-htaccess-control'); ?></th>
285
  <td style="width:3%;" valign="middle">
286
- <input type="checkbox" name="WPhtc_disable_indexes" value="true" <?php if($WPhtc_data['disable_indexes']){ echo "checked";}?>/>
287
  </td>
288
  <td valign="middle">
289
  <p class="description"><?php _e('Disable directory browsing.', 'wp-htaccess-control'); ?></p>
@@ -292,7 +291,7 @@ $WPhtc_data=get_option('WPhtc_data');
292
  <tr valign="top">
293
  <th scope="row"><?php _e('Protect wp-config.php file', 'wp-htaccess-control'); ?></th>
294
  <td style="width:3%;" valign="middle">
295
- <input type="checkbox" name="WPhtc_protect_wp_config" value="true" <?php if($WPhtc_data['protect_wp_config']){ echo "checked";}?>/> </td>
296
  <td valign="middle">
297
  <p class="description"><?php _e('Deny access to wp-config.php file.', 'wp-htaccess-control'); ?></p>
298
  </td>
@@ -300,7 +299,7 @@ $WPhtc_data=get_option('WPhtc_data');
300
  <tr valign="top">
301
  <th scope="row"><?php _e('Protect htaccess file', 'wp-htaccess-control'); ?></th>
302
  <td style="width:3%;" valign="middle">
303
- <input type="checkbox" name="WPhtc_protect_htaccess" value="true" <?php if($WPhtc_data['protect_htaccess']){ echo "checked";}?>/> </td>
304
  <td valign="middle">
305
  <p class="description"><?php _e('Deny access to .htaccess file.', 'wp-htaccess-control'); ?></p>
306
  </td>
@@ -308,7 +307,7 @@ $WPhtc_data=get_option('WPhtc_data');
308
  <tr valign="top">
309
  <th scope="row"><?php _e('Protect comments.php', 'wp-htaccess-control'); ?></th>
310
  <td style="width:3%;" valign="middle">
311
- <input type="checkbox" name="WPhtc_protect_comments" value="true" <?php if($WPhtc_data['protect_comments']){ echo "checked";}?>/> </td>
312
  <td valign="middle">
313
  <p class="description"><?php _e('Deny comment posting to no referrer requests. This will avoid spam bots coming from nowhere.', 'wp-htaccess-control'); ?></p>
314
  </td>
@@ -316,7 +315,7 @@ $WPhtc_data=get_option('WPhtc_data');
316
  <tr valign="top">
317
  <th scope="row"><?php _e('mod_gzip', 'wp-htaccess-control'); ?></th>
318
  <td style="width:3%;" valign="middle">
319
- <input type="checkbox" name="WPhtc_gzip" value="true" <?php if($WPhtc_data['gzip']){ echo "checked";}?>/>
320
  </td>
321
  <td valign="middle">
322
  <p class="description"><?php _e('Use mod_gzip if available.', 'wp-htaccess-control'); ?></p>
@@ -325,7 +324,7 @@ $WPhtc_data=get_option('WPhtc_data');
325
  <tr valign="top">
326
  <th scope="row"><?php _e('mod_deflate', 'wp-htaccess-control'); ?></th>
327
  <td style="width:3%;" valign="middle">
328
- <input type="checkbox" name="WPhtc_deflate" value="true" <?php if($WPhtc_data['deflate']){ echo "checked";}?>/>
329
  </td>
330
  <td valign="middle">
331
  <p class="description"><?php _e('Use mod_deflate if available.', 'wp-htaccess-control'); ?></p>
@@ -334,7 +333,7 @@ $WPhtc_data=get_option('WPhtc_data');
334
  <tr valign="top">
335
  <th scope="row"><?php _e('Limit Upload Size', 'wp-htaccess-control'); ?></th>
336
  <td style="width:3%;" valign="middle">
337
- <input type="text" name="WPhtc_up_limit" value="<?php echo $WPhtc_data['up_limit']?>"/>
338
  </td>
339
  <td valign="middle">
340
  <p class="description"><?php _e('If set, this value in MB will be used as limit to file uploads.', 'wp-htaccess-control'); ?></p>
@@ -343,7 +342,7 @@ $WPhtc_data=get_option('WPhtc_data');
343
  <tr valign="top">
344
  <th scope="row"><?php _e('Admin Email', 'wp-htaccess-control'); ?></th>
345
  <td style="width:3%;">
346
- <input type="text" name="WPhtc_admin_email" value="<?php echo $WPhtc_data['admin_email']?>"/>
347
  </td>
348
  <td valign="middle">
349
  <p class="description"><?php _e('If set, this will be used as the admin email on server generated error pages.', 'wp-htaccess-control'); ?></p>
@@ -352,7 +351,7 @@ $WPhtc_data=get_option('WPhtc_data');
352
  <tr valign="top">
353
  <th scope="row"><?php _e('Disable image hotlinking', 'wp-htaccess-control'); ?></th>
354
  <td style="width:3%;">
355
- <input type="text" name="WPhtc_disable_hotlink" value="<?php echo $WPhtc_data['disable_hotlink']?>"/>
356
  </td>
357
  <td valign="middle">
358
  <p class="description"><?php _e('If set, this url will be used as redirection to hotlinked images (you should be using an image url here). If you prefer no output on hotlinked images use "_".', 'wp-htaccess-control'); ?></p>
@@ -361,7 +360,7 @@ $WPhtc_data=get_option('WPhtc_data');
361
  <tr valign="top">
362
  <th scope="row"><?php _e('Disable file hotlinking extensions', 'wp-htaccess-control'); ?></th>
363
  <td style="width:3%;">
364
- <input type="text" name="WPhtc_disable_file_hotlink_ext" value="<?php echo $WPhtc_data['disable_file_hotlink_ext']?>"/>
365
  </td>
366
  <td valign="middle">
367
  <p class="description"><?php _e('If set, this file extensions will not be hotlinkable.', 'wp-htaccess-control'); ?></p>
@@ -371,7 +370,7 @@ $WPhtc_data=get_option('WPhtc_data');
371
  <tr valign="top">
372
  <th scope="row"><?php _e('File hotlinking redirection', 'wp-htaccess-control'); ?></th>
373
  <td style="width:3%;">
374
- <input type="text" name="WPhtc_disable_file_hotlink_redir" value="<?php echo $WPhtc_data['disable_file_hotlink_redir']?>"/>
375
  </td>
376
  <td valign="middle">
377
  <p class="description"><?php _e('If set, this url will be used as redirection for hotlinked files.', 'wp-htaccess-control'); ?></p>
@@ -380,7 +379,7 @@ $WPhtc_data=get_option('WPhtc_data');
380
  <tr valign="top">
381
  <th scope="row"><?php _e('500 error', 'wp-htaccess-control'); ?></th>
382
  <td style="width:3%;" valign="middle">
383
- <input type="text" name="WPhtc_redirect_500" value="<?php echo $WPhtc_data['redirect_500']?>"/>
384
  </td>
385
  <td valign="middle">
386
  <p class="description"><?php _e('If set, this path will be used as page to 500 errors (example: /error.php).', 'wp-htaccess-control'); ?></p>
@@ -389,7 +388,7 @@ $WPhtc_data=get_option('WPhtc_data');
389
  <tr valign="top">
390
  <th scope="row"><?php _e('403 error', 'wp-htaccess-control'); ?></th>
391
  <td style="width:3%;" valign="middle">
392
- <input type="text" name="WPhtc_redirect_403" value="<?php echo $WPhtc_data['redirect_403']?>"/>
393
  </td>
394
  <td valign="middle">
395
  <p class="description"><?php _e('If set, this path will be used as page to 403 errors (example: /error.php).', 'wp-htaccess-control'); ?></p>
@@ -400,8 +399,8 @@ $WPhtc_data=get_option('WPhtc_data');
400
  <td style="width:3%;" valign="middle">
401
  <select name="WPhtc_canon">
402
  <option value=""></option>
403
- <option value="www" <?php if($WPhtc_data['canon']=='www'){echo "selected";} ?>><?php _e('Force WWW', 'wp-htaccess-control'); ?></option>
404
- <option value="simple" <?php if($WPhtc_data['canon']=='simple'){echo "selected";} ?>><?php _e('Force non-WWW', 'wp-htaccess-control'); ?></option>
405
  </select>
406
  </td>
407
  <td valign="middle">
@@ -420,7 +419,7 @@ $WPhtc_data=get_option('WPhtc_data');
420
  <tr valign="top">
421
  <th scope="row" style="width:18%;"><?php _e('Maintenance Active', 'wp-htaccess-control'); ?></th>
422
  <td valign="middle">
423
- <input type="checkbox" name="WPhtc_maintenance_active" value="true" <?php if($WPhtc_data['maintenance_active']){ echo "checked";}?>/>
424
  </td>
425
  <td valign="middle">
426
  <p class="description"><?php _e('Toggles Maintenance Mode.', 'wp-htaccess-control'); ?></p>
@@ -429,7 +428,7 @@ $WPhtc_data=get_option('WPhtc_data');
429
  <tr valign="top">
430
  <th scope="row" style="width:18%;"><?php _e('Allowed IPs', 'wp-htaccess-control'); ?></th>
431
  <td>
432
- <textarea name="WPhtc_maintenance_ips"><?php if(isset($WPhtc_data['maintenance_ips'])){echo implode($WPhtc_data['maintenance_ips'],"\n");}?></textarea>
433
  </td>
434
  <td valign="middle">
435
  <p class="description"><?php _e('List of allowed IPs.', 'wp-htaccess-control'); ?></p>
@@ -439,7 +438,7 @@ $WPhtc_data=get_option('WPhtc_data');
439
  <tr valign="top">
440
  <th scope="row" style="width:18%;"><?php _e('Redirection', 'wp-htaccess-control'); ?></th>
441
  <td>
442
- <input type="text" name="WPhtc_maintenance_redirection" value="<?php echo $WPhtc_data['maintenance_redirection']?>"/>
443
  </td>
444
  <td valign="middle">
445
  <p class="description"><?php _e('If set, this will be used as redirection for disallowed IPs. This could be an external url or a document on your server (local paths begin with a trailing slash)', 'wp-htaccess-control'); ?></p>
@@ -465,7 +464,7 @@ $WPhtc_data=get_option('WPhtc_data');
465
  <tr valign="top">
466
  <th scope="row" style="width:18%;"><?php _e('Disable wp-login.php', 'wp-htaccess-control'); ?></th>
467
  <td>
468
- <input type="checkbox" name="WPhtc_login_disabled" value="true" <?php if($WPhtc_data['login_disabled']){ echo "checked";}?>/>
469
  </td>
470
  <td valign="middle">
471
  <p class="description"><?php _e('This is the main switch. Make sure you know what you\'re doing.', 'wp-htaccess-control'); ?></p>
@@ -474,7 +473,7 @@ $WPhtc_data=get_option('WPhtc_data');
474
  <tr valign="top">
475
  <th scope="row" style="width:18%;"><?php _e('Redirect', 'wp-htaccess-control'); ?></th>
476
  <td valign="middle">
477
- <input type="text" name="WPhtc_login_redirection" value="<?php echo $WPhtc_data['login_redirection']?>"/>
478
  </td>
479
  <td valign="middle">
480
  <p class="description"><?php _e('This will be used as redirection url. You might use something like "member-login" to redirect people to "http://yoursite.com/member-login/". If empty the home page will be served as redirection.', 'wp-htaccess-control'); ?></p>
@@ -483,7 +482,7 @@ $WPhtc_data=get_option('WPhtc_data');
483
  <tr valign="top">
484
  <th scope="row" style="width:18%;"><?php _e('Allowed IPs', 'wp-htaccess-control'); ?></th>
485
  <td>
486
- <textarea name="WPhtc_login_ips"><?php if(isset($WPhtc_data['login_ips'])){echo implode($WPhtc_data['login_ips'],"\n");}?></textarea>
487
  </td>
488
  <td valign="middle">
489
  <p class="description"><?php _e('List of IPs allowed to access wp-login.php.', 'wp-htaccess-control'); ?></p>
@@ -493,7 +492,7 @@ $WPhtc_data=get_option('WPhtc_data');
493
  <tr valign="top">
494
  <th scope="row" style="width:18%;"><?php _e('Half-mode', 'wp-htaccess-control'); ?></th>
495
  <td>
496
- <input type="checkbox" name="WPhtc_login_half_mode" value="true" <?php if($WPhtc_data['login_half_mode']){ echo "checked";}?>/>
497
  </td>
498
  <td valign="middle">
499
  <p class="description"><?php _e('(BETA) If set, this will still allow access to POST (login) requests, logout and to the password recovery form. I don\'t think this is very useful at the moment (login error messages will still show up on wp-login.php) but may be helpful for AJAX use.', 'wp-htaccess-control'); ?></p>
@@ -515,7 +514,7 @@ $WPhtc_data=get_option('WPhtc_data');
515
  </div>
516
  <div class="wphtc-inputs start-open">
517
  <p>
518
- <code><?php echo str_replace(array("&lt;br /&gt;","&lt;br/&gt;"),"<br/>",htmlspecialchars($WPhtc_data['cur_hta']));?></code>
519
  </p>
520
  </div>
521
  </div>
@@ -527,7 +526,7 @@ $WPhtc_data=get_option('WPhtc_data');
527
  </div>
528
  <div class="wphtc-inputs">
529
  <pre>
530
- <?php print_r($WPhtc_data);?>
531
  </pre>
532
 
533
  <pre>
6
  $q=explode('&',$_SERVER['QUERY_STRING']);
7
  $purl='http'.((!empty($_SERVER['HTTPS'])) ? 's' : '').'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'].'?'.$q[0];
8
  global $WPhtc, $echo;
9
+ $WPhtc->page_action();
 
10
 
11
  ?>
12
  <div id="wphtc-page" class="wrap">
13
+ <h2>Wp htaccess Control 3.1</h2>
14
  <?php
15
  if(!current_user_can("administrator")) {
16
  echo '<p>'.__('Please log in as admin','wp-htaccess-control').'</p>';
47
  <div class="updated fade" id="message" style="background-color: rgb(255, 251, 204);"><p><?php echo $echo;?></p></div>
48
  <?php }
49
  # Donation Message
50
+ if($WPhtc->data['donation_hidden_time']&&$WPhtc->data['donation_hidden_time']<time()){?>
51
  <div class="updated">
52
  <p>
53
  <strong>Is this plugin useful? Consider making a donation encouraging me to continue supporting it!</strong>
68
  <td >
69
  <p class="description"><?php _e('This plugin has made such a long way that it should really now be called <strong>WP htaccess and Rewrite Control</strong>.', 'wp-htaccess-control');?></p>
70
  <p class="description"><?php _e('Many core parts of WP htaccess Control have been almost completely re-done in version 3.0 with the goal of providing an universal solution. This means that you can now selectively remove base slugs and create full archives for any custom taxonomy in addiction to the previous Category and Post tags.', 'wp-htaccess-control');?></p>
71
+ <p class="description"><?php _e('This changes also mean that some unforeseen issues might arise. Please report them. If your setup seems to get out of control there are a few easy options to reverse all changes: 1) Click on "Reset all rules", at the bottom of this page; 2) rename/delete the plugin folder and re-submit your permalink settings under "Settings > Permalinks" and 3) if the previous did not solve your issue, remove the .htaccess file on your blog\'s root directory and repeat step 2; 4) in such cases you might want to get back back to the last version you knew working, which you\'ll find at http://wordpress.org/extend/plugins/wp-htaccess-control/download/.', 'wp-htaccess-control');?></p>
72
  </td>
73
  </tr>
74
  </table>
84
  <tr valign="top">
85
  <th scope="row" style="width:18%;"><?php _e('Author Base', 'wp-htaccess-control'); ?></th>
86
  <td >
87
+ <input type="text" name="WPhtc_cap" value="<?php echo $WPhtc->data['cap']; ?>" />
88
  <p><code><?php bloginfo('home')?>/<em><?php _e('(your-base)', 'wp-htaccess-control');?></em>/admin</code></p>
89
  </td>
90
  <td valign="middle">
97
  <tr valign="top">
98
  <th>Google XML Sitemap</th>
99
  <td>
100
+ <input type="checkbox" name="WPhtc_sm_enabled" value="true" <?php if($WPhtc->data['sm_enabled']){ echo "checked";}?>/> <?php _e('Apply Custom Author Permalink on Generated Sitemap', 'wp-htaccess-control'); ?>
101
  </td>
102
  <td valign="middle" >
103
  <p class="description"><?php _e('Leave "Include author pages" unchecked on Google XML Sitemap options page if using this.', 'wp-htaccess-control'); ?></p>
117
  <tr valign="top">
118
  <th scope="row" style="width:18%;"><?php _e('Page Base', 'wp-htaccess-control'); ?></th>
119
  <td >
120
+ <input type="text" name="WPhtc_cpp" value="<?php echo $WPhtc->data['cpp']; ?>" />
121
  <p><code><?php bloginfo('home')?>/<em><?php _e('(your-base)', 'wp-htaccess-control');?></em>/2</code></p>
122
  </td>
123
  <td valign="middle">
138
  <tr valign="top">
139
  <th scope="row" style="width:18%;"><?php _e('Search Base', 'wp-htaccess-control'); ?></th>
140
  <td >
141
+ <input type="text" name="WPhtc_custom_search_permalink" value="<?php echo $WPhtc->data['custom_search_permalink']; ?>" />
142
  <p><code><?php bloginfo('home')?>/<em><?php _e('(your-base)', 'wp-htaccess-control');?></em>/search-term</code></p>
143
  </td>
144
  <td valign="middle">
160
  <tr valign="top">
161
  <th scope="row" style="width:18%;"><?php _e('Remove Author Base', 'wp-htaccess-control'); ?></th>
162
  <td >
163
+ <input type="checkbox" name="WPhtc_remove_author_base" <?php if($WPhtc->data['remove_author_base']){echo "checked=checked";} ?> />
164
  </td>
165
  <td valign="middle">
166
  <p class="description"><?php _e('If active, the author base will be removed from permalinks:'); ?></p>
175
  <tr valign="top">
176
  <th scope="row" style="width:18%;"><?php _e('Remove', 'wp-htaccess-control'); echo " ".$taxonomy->labels->name." " ; _e('Base', 'wp-htaccess-control'); ?></th>
177
  <td >
178
+ <input type="checkbox" name="WPhtc_remove_base[<?php echo $taxonomy->name; ?>]" <?php if($WPhtc->data['remove_taxonomy_base'][$taxonomy->name]){echo "checked=checked";} ?> />
179
  </td>
180
  <td valign="middle">
181
  <p class="description"><?php _e('If active, the'); echo " ".$taxonomy->labels->name." "; _e('base will be removed from permalinks:'); ?></p>
201
  <tr valign="top">
202
  <th scope="row" style="width:18%;"><?php _e('Create', 'wp-htaccess-control'); echo " ".$taxonomy->labels->name." " ; _e('Archives', 'wp-htaccess-control'); ?></th>
203
  <td >
204
+ <input type="checkbox" name="WPhtc_create_archive[<?php echo $taxonomy->name; ?>]" <?php if($WPhtc->data['create_archive'][$taxonomy->name]){echo "checked=checked";} ?> />
205
  </td>
206
  <td valign="middle">
207
  <p class="description"><?php _e('If active, taxonomy-based archives will be accessible:', 'wp-htaccess-control'); ?></p>
224
  <table class="form-table wphtc-inputs">
225
  <tr valign="top">
226
  <td>
227
+ <textarea name="WPhtc_hta" style="width:100%;" rows="7"><?php echo stripslashes($WPhtc->data['hta']); ?></textarea>
228
  </td>
229
  <td style="width:50%;">
230
  <p class="description"><?php _e('This rules will be printed before any Wordpress rules.', 'wp-htaccess-control'); ?></p>
247
  <table class="form-table wphtc-inputs">
248
  <tr valign="top">
249
  <td>
250
+ <textarea name="WPhtc_wp_hta" style="width:100%;" rows="7" <?php if($WPhtc->data['jim_morgan_hta']){ echo "readonly='true' class='readonly'";}?>><?php echo stripslashes($WPhtc->data['wp_hta']); ?></textarea>
251
  <p class="description"><?php _e('Leave empty for default.', 'wp-htaccess-control'); ?></p>
252
+ <p><input type="checkbox" name="WPhtc_jim_morgan_hta" value="true" <?php if($WPhtc->data['jim_morgan_hta']){ echo "checked";}?>/>
253
  <?php _e("<strong>Use <a href='http://www.webmasterworld.com/apache/4053973.htm'>Jim Morgan's wordpress htaccess</a></strong> (has been reported to \"speed up your WP mod_rewrite code by a factor of more than two\")", 'wp-htaccess-control'); ?></p>
254
  </td>
255
  <td style="width:50%;">
257
  <p class="description"><?php _e('Please double check them before saving as a mistake could make your site inaccessible.', 'wp-htaccess-control'); ?></p>
258
  <p class="description"><?php _e('Original rules:', 'wp-htaccess-control'); ?></p>
259
  <p class="description">
260
+ <code><?php echo nl2br(htmlspecialchars(substr($WPhtc->data['htaccess_original'],0,-1)));?></code>
261
  </p>
262
  </td>
263
  </tr>
273
  <tr valign="top">
274
  <th scope="row" style="width:18%;"><?php _e('ServerSignature', 'wp-htaccess-control'); ?></th>
275
  <td style="width:3%;" valign="middle">
276
+ <input type="checkbox" name="WPhtc_disable_serversignature" value="true" <?php if($WPhtc->data['disable_serversignature']){ echo "checked";}?>/>
277
  </td>
278
  <td valign="middle">
279
  <p class="description"><?php _e('Disable the ServerSignature on server generated error pages.', 'wp-htaccess-control'); ?></p>
282
  <tr valign="top">
283
  <th scope="row"><?php _e('Indexes', 'wp-htaccess-control'); ?></th>
284
  <td style="width:3%;" valign="middle">
285
+ <input type="checkbox" name="WPhtc_disable_indexes" value="true" <?php if($WPhtc->data['disable_indexes']){ echo "checked";}?>/>
286
  </td>
287
  <td valign="middle">
288
  <p class="description"><?php _e('Disable directory browsing.', 'wp-htaccess-control'); ?></p>
291
  <tr valign="top">
292
  <th scope="row"><?php _e('Protect wp-config.php file', 'wp-htaccess-control'); ?></th>
293
  <td style="width:3%;" valign="middle">
294
+ <input type="checkbox" name="WPhtc_protect_wp_config" value="true" <?php if($WPhtc->data['protect_wp_config']){ echo "checked";}?>/> </td>
295
  <td valign="middle">
296
  <p class="description"><?php _e('Deny access to wp-config.php file.', 'wp-htaccess-control'); ?></p>
297
  </td>
299
  <tr valign="top">
300
  <th scope="row"><?php _e('Protect htaccess file', 'wp-htaccess-control'); ?></th>
301
  <td style="width:3%;" valign="middle">
302
+ <input type="checkbox" name="WPhtc_protect_htaccess" value="true" <?php if($WPhtc->data['protect_htaccess']){ echo "checked";}?>/> </td>
303
  <td valign="middle">
304
  <p class="description"><?php _e('Deny access to .htaccess file.', 'wp-htaccess-control'); ?></p>
305
  </td>
307
  <tr valign="top">
308
  <th scope="row"><?php _e('Protect comments.php', 'wp-htaccess-control'); ?></th>
309
  <td style="width:3%;" valign="middle">
310
+ <input type="checkbox" name="WPhtc_protect_comments" value="true" <?php if($WPhtc->data['protect_comments']){ echo "checked";}?>/> </td>
311
  <td valign="middle">
312
  <p class="description"><?php _e('Deny comment posting to no referrer requests. This will avoid spam bots coming from nowhere.', 'wp-htaccess-control'); ?></p>
313
  </td>
315
  <tr valign="top">
316
  <th scope="row"><?php _e('mod_gzip', 'wp-htaccess-control'); ?></th>
317
  <td style="width:3%;" valign="middle">
318
+ <input type="checkbox" name="WPhtc_gzip" value="true" <?php if($WPhtc->data['gzip']){ echo "checked";}?>/>
319
  </td>
320
  <td valign="middle">
321
  <p class="description"><?php _e('Use mod_gzip if available.', 'wp-htaccess-control'); ?></p>
324
  <tr valign="top">
325
  <th scope="row"><?php _e('mod_deflate', 'wp-htaccess-control'); ?></th>
326
  <td style="width:3%;" valign="middle">
327
+ <input type="checkbox" name="WPhtc_deflate" value="true" <?php if($WPhtc->data['deflate']){ echo "checked";}?>/>
328
  </td>
329
  <td valign="middle">
330
  <p class="description"><?php _e('Use mod_deflate if available.', 'wp-htaccess-control'); ?></p>
333
  <tr valign="top">
334
  <th scope="row"><?php _e('Limit Upload Size', 'wp-htaccess-control'); ?></th>
335
  <td style="width:3%;" valign="middle">
336
+ <input type="text" name="WPhtc_up_limit" value="<?php echo $WPhtc->data['up_limit']?>"/>
337
  </td>
338
  <td valign="middle">
339
  <p class="description"><?php _e('If set, this value in MB will be used as limit to file uploads.', 'wp-htaccess-control'); ?></p>
342
  <tr valign="top">
343
  <th scope="row"><?php _e('Admin Email', 'wp-htaccess-control'); ?></th>
344
  <td style="width:3%;">
345
+ <input type="text" name="WPhtc_admin_email" value="<?php echo $WPhtc->data['admin_email']?>"/>
346
  </td>
347
  <td valign="middle">
348
  <p class="description"><?php _e('If set, this will be used as the admin email on server generated error pages.', 'wp-htaccess-control'); ?></p>
351
  <tr valign="top">
352
  <th scope="row"><?php _e('Disable image hotlinking', 'wp-htaccess-control'); ?></th>
353
  <td style="width:3%;">
354
+ <input type="text" name="WPhtc_disable_hotlink" value="<?php echo $WPhtc->data['disable_hotlink']?>"/>
355
  </td>
356
  <td valign="middle">
357
  <p class="description"><?php _e('If set, this url will be used as redirection to hotlinked images (you should be using an image url here). If you prefer no output on hotlinked images use "_".', 'wp-htaccess-control'); ?></p>
360
  <tr valign="top">
361
  <th scope="row"><?php _e('Disable file hotlinking extensions', 'wp-htaccess-control'); ?></th>
362
  <td style="width:3%;">
363
+ <input type="text" name="WPhtc_disable_file_hotlink_ext" value="<?php echo $WPhtc->data['disable_file_hotlink_ext']?>"/>
364
  </td>
365
  <td valign="middle">
366
  <p class="description"><?php _e('If set, this file extensions will not be hotlinkable.', 'wp-htaccess-control'); ?></p>
370
  <tr valign="top">
371
  <th scope="row"><?php _e('File hotlinking redirection', 'wp-htaccess-control'); ?></th>
372
  <td style="width:3%;">
373
+ <input type="text" name="WPhtc_disable_file_hotlink_redir" value="<?php echo $WPhtc->data['disable_file_hotlink_redir']?>"/>
374
  </td>
375
  <td valign="middle">
376
  <p class="description"><?php _e('If set, this url will be used as redirection for hotlinked files.', 'wp-htaccess-control'); ?></p>
379
  <tr valign="top">
380
  <th scope="row"><?php _e('500 error', 'wp-htaccess-control'); ?></th>
381
  <td style="width:3%;" valign="middle">
382
+ <input type="text" name="WPhtc_redirect_500" value="<?php echo $WPhtc->data['redirect_500']?>"/>
383
  </td>
384
  <td valign="middle">
385
  <p class="description"><?php _e('If set, this path will be used as page to 500 errors (example: /error.php).', 'wp-htaccess-control'); ?></p>
388
  <tr valign="top">
389
  <th scope="row"><?php _e('403 error', 'wp-htaccess-control'); ?></th>
390
  <td style="width:3%;" valign="middle">
391
+ <input type="text" name="WPhtc_redirect_403" value="<?php echo $WPhtc->data['redirect_403']?>"/>
392
  </td>
393
  <td valign="middle">
394
  <p class="description"><?php _e('If set, this path will be used as page to 403 errors (example: /error.php).', 'wp-htaccess-control'); ?></p>
399
  <td style="width:3%;" valign="middle">
400
  <select name="WPhtc_canon">
401
  <option value=""></option>
402
+ <option value="www" <?php if($WPhtc->data['canon']=='www'){echo "selected";} ?>><?php _e('Force WWW', 'wp-htaccess-control'); ?></option>
403
+ <option value="simple" <?php if($WPhtc->data['canon']=='simple'){echo "selected";} ?>><?php _e('Force non-WWW', 'wp-htaccess-control'); ?></option>
404
  </select>
405
  </td>
406
  <td valign="middle">
419
  <tr valign="top">
420
  <th scope="row" style="width:18%;"><?php _e('Maintenance Active', 'wp-htaccess-control'); ?></th>
421
  <td valign="middle">
422
+ <input type="checkbox" name="WPhtc_maintenance_active" value="true" <?php if($WPhtc->data['maintenance_active']){ echo "checked";}?>/>
423
  </td>
424
  <td valign="middle">
425
  <p class="description"><?php _e('Toggles Maintenance Mode.', 'wp-htaccess-control'); ?></p>
428
  <tr valign="top">
429
  <th scope="row" style="width:18%;"><?php _e('Allowed IPs', 'wp-htaccess-control'); ?></th>
430
  <td>
431
+ <textarea name="WPhtc_maintenance_ips"><?php if(isset($WPhtc->data['maintenance_ips'])){echo implode($WPhtc->data['maintenance_ips'],"\n");}?></textarea>
432
  </td>
433
  <td valign="middle">
434
  <p class="description"><?php _e('List of allowed IPs.', 'wp-htaccess-control'); ?></p>
438
  <tr valign="top">
439
  <th scope="row" style="width:18%;"><?php _e('Redirection', 'wp-htaccess-control'); ?></th>
440
  <td>
441
+ <input type="text" name="WPhtc_maintenance_redirection" value="<?php echo $WPhtc->data['maintenance_redirection']?>"/>
442
  </td>
443
  <td valign="middle">
444
  <p class="description"><?php _e('If set, this will be used as redirection for disallowed IPs. This could be an external url or a document on your server (local paths begin with a trailing slash)', 'wp-htaccess-control'); ?></p>
464
  <tr valign="top">
465
  <th scope="row" style="width:18%;"><?php _e('Disable wp-login.php', 'wp-htaccess-control'); ?></th>
466
  <td>
467
+ <input type="checkbox" name="WPhtc_login_disabled" value="true" <?php if($WPhtc->data['login_disabled']){ echo "checked";}?>/>
468
  </td>
469
  <td valign="middle">
470
  <p class="description"><?php _e('This is the main switch. Make sure you know what you\'re doing.', 'wp-htaccess-control'); ?></p>
473
  <tr valign="top">
474
  <th scope="row" style="width:18%;"><?php _e('Redirect', 'wp-htaccess-control'); ?></th>
475
  <td valign="middle">
476
+ <input type="text" name="WPhtc_login_redirection" value="<?php echo $WPhtc->data['login_redirection']?>"/>
477
  </td>
478
  <td valign="middle">
479
  <p class="description"><?php _e('This will be used as redirection url. You might use something like "member-login" to redirect people to "http://yoursite.com/member-login/". If empty the home page will be served as redirection.', 'wp-htaccess-control'); ?></p>
482
  <tr valign="top">
483
  <th scope="row" style="width:18%;"><?php _e('Allowed IPs', 'wp-htaccess-control'); ?></th>
484
  <td>
485
+ <textarea name="WPhtc_login_ips"><?php if(isset($WPhtc->data['login_ips'])){echo implode($WPhtc->data['login_ips'],"\n");}?></textarea>
486
  </td>
487
  <td valign="middle">
488
  <p class="description"><?php _e('List of IPs allowed to access wp-login.php.', 'wp-htaccess-control'); ?></p>
492
  <tr valign="top">
493
  <th scope="row" style="width:18%;"><?php _e('Half-mode', 'wp-htaccess-control'); ?></th>
494
  <td>
495
+ <input type="checkbox" name="WPhtc_login_half_mode" value="true" <?php if($WPhtc->data['login_half_mode']){ echo "checked";}?>/>
496
  </td>
497
  <td valign="middle">
498
  <p class="description"><?php _e('(BETA) If set, this will still allow access to POST (login) requests, logout and to the password recovery form. I don\'t think this is very useful at the moment (login error messages will still show up on wp-login.php) but may be helpful for AJAX use.', 'wp-htaccess-control'); ?></p>
514
  </div>
515
  <div class="wphtc-inputs start-open">
516
  <p>
517
+ <code><?php echo str_replace(array("&lt;br /&gt;","&lt;br/&gt;"),"<br/>",htmlspecialchars($WPhtc->data['cur_hta']));?></code>
518
  </p>
519
  </div>
520
  </div>
526
  </div>
527
  <div class="wphtc-inputs">
528
  <pre>
529
+ <?php print_r($WPhtc->data);?>
530
  </pre>
531
 
532
  <pre>
wp-htaccess-control.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: WP htaccess Control
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
  Description: Interface to customize the permalinks (author, category, archives and pagination) and htaccess file generated by Wordpress.
6
- Version: 3.0
7
  Author: António Andrade
8
  Author URI: http://dardna.com
9
  */
@@ -28,9 +28,13 @@ Author URI: http://dardna.com
28
 
29
  if (!class_exists("WPhtc")) {
30
  class WPhtc {
 
 
 
31
  function WPhtc() {
 
32
  }
33
- function wphtc_init(){
34
  # set locale
35
  $currentLocale = get_locale();
36
  if(!empty($currentLocale)) {
@@ -38,16 +42,14 @@ if (!class_exists("WPhtc")) {
38
  if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('wp-htaccess-control', $moFile);
39
  }
40
  }
41
- function wphtc_template_redirect(){
42
- $WPhtc_data=get_option('WPhtc_data');
43
- if($WPhtc_data['custom_search_permalink']!=''){
44
  # redirect "?s=*" to "/search-base/*"
45
  if($_GET['s']){
46
- wp_redirect( home_url( $WPhtc_data['custom_search_permalink']. "/" . rawurlencode(get_query_var( 's' )) ) );
47
  }
48
 
49
  # rewrite query
50
- if(strpos($_SERVER["REQUEST_URI"], $WPhtc_data['custom_search_permalink'])){
51
  global $wp_query;
52
  if(strpos($_SERVER["REQUEST_URI"], '/feed')){
53
  preg_match("/feed\/(feed|rdf|rss|rss2|atom)?/",$_SERVER["REQUEST_URI"], $feed);
@@ -58,17 +60,17 @@ if (!class_exists("WPhtc")) {
58
  $format="&feed=feed";
59
  }
60
  }
61
- $page_base=($WPhtc_data['cpp']!='')?$WPhtc_data['cpp']:'page';
62
 
63
  # in need of better regex
64
  if(!strpos($_SERVER["REQUEST_URI"], '/feed')&&!strpos($_SERVER["REQUEST_URI"],$page_base)){
65
- $pattern="/\/".$WPhtc_data['custom_search_permalink']."\/(.+)/";
66
  }
67
  else{
68
- $pattern="/\/".$WPhtc_data['custom_search_permalink']."\/(.+)\/feed|".$page_base."?/";
69
  }
70
 
71
- $pattern="/\/".$WPhtc_data['custom_search_permalink']."\/(.+)/";
72
  preg_match($pattern,$_SERVER["REQUEST_URI"], $matches);
73
  $results=split("/",$matches[1]);
74
  if($results[1]==$page_base){
@@ -76,19 +78,18 @@ if (!class_exists("WPhtc")) {
76
  }
77
  $wp_query=new WP_Query('s='.$results[0].$page.$format );
78
  }
79
- }
80
  }
81
  # return get_search_query on custom search base
82
- function wphtc_get_search_query_filter($query){
83
- $WPhtc_data=get_option('WPhtc_data');
84
- if($WPhtc_data['custom_search_permalink']!=''&&strpos($_SERVER["REQUEST_URI"], $WPhtc_data['custom_search_permalink'])){
85
- $page_base=($WPhtc_data['cpp']!='')?$WPhtc_data['cpp']:'page';
86
  # in need of better regex
87
  if(!strpos($_SERVER["REQUEST_URI"], '/feed')&&!strpos($_SERVER["REQUEST_URI"],"/".$page_base)){
88
- $pattern="/\/".$WPhtc_data['custom_search_permalink']."\/(.+)/";
89
  }
90
  else{
91
- $pattern="/\/".$WPhtc_data['custom_search_permalink']."\/(.+)\/feed|".$page_base."?/";
92
  }
93
  preg_match($pattern,$_SERVER["REQUEST_URI"], $matches);
94
  $results=split("/",$matches[1]);
@@ -96,39 +97,37 @@ if (!class_exists("WPhtc")) {
96
  }
97
  return $query;
98
  }
99
- function wphtc_search_feed_link($link){
100
- $WPhtc_data=get_option('WPhtc_data');
101
- if($WPhtc_data['custom_search_permalink']!=''){
102
- $link=str_replace("search",$WPhtc_data['custom_search_permalink'],$link);
103
- }
104
  return $link;
105
  }
106
- function wphtc_check_first_run(){
107
- $WPhtc_data=get_option('WPhtc_data');
108
 
109
  # MIGRATE OPTIONS
110
 
111
  // deprecating old category base removal
112
- if($WPhtc_data['remove_category_base']){
113
- unset($WPhtc_data['remove_category_base']);
114
- $WPhtc_data['remove_taxonomy_base']['category']=true;
115
  }
116
  // deprecating old category archive
117
- if($WPhtc_data['category_archives']){
118
- unset($WPhtc_data['category_archives']);
119
- $WPhtc_data['create_archive']['category']=true;
120
  }
121
  // deprecating old tag archive
122
- if($WPhtc_data['tag_archives']){
123
- unset($WPhtc_data['tag_archives']);
124
- $WPhtc_data['create_archive']['post_tag']=true;
125
  }
126
- if($WPhtc_data['remove_category_base'] || $WPhtc_data['category_archives'] || $WPhtc_data['tag_archives']){
127
- update_option('WPhtc_data',$WPhtc_data);
128
  }
129
 
130
  # flush rules to get some data filled on first usage
131
- if(!isset($WPhtc_data['htaccess_original'])){
132
  $this->refresh_rewrite_rules();
133
  }
134
  }
@@ -141,31 +140,28 @@ if (!class_exists("WPhtc")) {
141
  wp_schedule_single_event(time(), 'flush_event');
142
  }
143
  # Filter pagination links generated by Wordpress
144
- function wphtc_filter_get_pagenum_link($result){
145
- $WPhtc_data=get_option('WPhtc_data');
146
- if(isset($WPhtc_data['cpp'])&&$WPhtc_data['cpp']!=''){
147
- $result=preg_replace("/".urlencode($WPhtc_data['cpp'])."\/[0-9]+[\/]?/","",$result);
148
- $result=str_replace("page",urlencode($WPhtc_data['cpp']),$result);
149
- }
150
  return $result;
151
  }
152
  # Filter link generated by get_author_posts_url() to use the Custom Author Permalink
153
- function wphtc_filter_author_link($link){
154
- $WPhtc_data=get_option('WPhtc_data');
155
- if($WPhtc_data['remove_author_base']){
156
  $link=str_replace("author/","",$link);
157
  }
158
- else if(isset($WPhtc_data['cap']) && $WPhtc_data['cap']!=''){
159
- $link=str_replace("author",urlencode($WPhtc_data['cap']),$link);
160
  }
161
  return $link;
162
  }
163
 
164
- function wphtc_filter_redirect_canonical($requested_url){
165
  global $wp;
166
- $WPhtc_data=get_option('WPhtc_data');
167
  # Disable canonical redirection on urls using custom pagination permalink
168
- if(isset($WPhtc_data['cpp'])&&$WPhtc_data['cpp']!=''&&get_query_var('paged') > 1&&preg_match("/".urlencode($WPhtc_data['cpp'])."/",$wp->request)){
169
  return false;
170
  }
171
  else{
@@ -183,17 +179,17 @@ if (!class_exists("WPhtc")) {
183
  return $ancestor;
184
  }
185
  # Rewrite Rules: Add Category + Tag + Author Archives; Custom Pagination; Custom Author Base
186
- function wphtc_filter_rewrite_rules($rewrite_rules){
187
- $WPhtc_data=get_option('WPhtc_data');
188
 
189
- $page_base=($WPhtc_data['cpp']!='')?$WPhtc_data['cpp']:'page';
190
 
191
- if($WPhtc_data['create_archive'] || $WPhtc_data['remove_taxonomy_base']){
192
  foreach (get_taxonomies('','objects') as $taxonomy){
193
- if(!$taxonomy->rewrite || !$WPhtc_data['remove_taxonomy_base'][$taxonomy->name] || !$WPhtc_data['create_archive'][$taxonomy->name]){continue;}
194
  $terms=get_terms($taxonomy->name);
195
  foreach($terms as $term){
196
- $base=$WPhtc_data['remove_taxonomy_base'][$taxonomy->name]?"":$taxonomy->rewrite->slug."/";
197
  if($term->parent!=0){
198
  $ancestors=$this->term_ancestors($taxonomy->name,$term->parent)."/";
199
  }
@@ -204,7 +200,7 @@ if (!class_exists("WPhtc")) {
204
  $tax_name=($taxonomy->name=="category")?"category_name":$taxonomy->name;
205
 
206
  # create archives
207
- if($WPhtc_data['create_archive'][$tax_name]){
208
  #year
209
  $new_rules[$base.$ancestors.'('.$term->slug.')/([0-9]{4})/?$'] = 'index.php?'.$tax_name.'=$matches[1]&year=$matches[2]';
210
  $new_rules[$base.$ancestors.'('.$term->slug.')/([0-9]{4})/'.$page_base.'/?([0-9]{1,})/?$'] = 'index.php?'.$tax_name.'=$matches[1]&year=$matches[2]&paged=$matches[3]';
@@ -227,7 +223,7 @@ if (!class_exists("WPhtc")) {
227
  }
228
 
229
  # Author Archives
230
- if($WPhtc_data['remove_author_base']){
231
  $blogusers = get_users('who=authors');
232
  foreach ($blogusers as $user) {
233
 
@@ -244,8 +240,8 @@ if (!class_exists("WPhtc")) {
244
  $rewrite_rules = $new_rules + $rewrite_rules;
245
  }
246
  }
247
- else if(isset($WPhtc_data['author_archives'])){
248
- $author_base = ($WPhtc_data['cap']!='')?$WPhtc_data['cap']:'author';
249
  $new_rules = array(
250
  $author_base.'/([^/]+)/([0-9]{4})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]',
251
  $author_base.'/([^/]+)/([0-9]{4})/'.$page_base.'/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&paged=$matches[3]',
@@ -260,19 +256,19 @@ if (!class_exists("WPhtc")) {
260
  }
261
 
262
  # Custom Pagination; Custom Author Permalink
263
- if((isset($WPhtc_data['cap'])&&$WPhtc_data['cap']!='')||(isset($WPhtc_data['cpp'])&&$WPhtc_data['cpp']!='')){
264
  $rewrite_rules=serialize($rewrite_rules);
265
  # Author
266
- if(isset($WPhtc_data['cap'])&&$WPhtc_data['cap']!=''){
267
- $rewrite_rules=str_replace('author/',$WPhtc_data['cap'].'/',$rewrite_rules);
268
  }
269
  # Pagination
270
- if(isset($WPhtc_data['cpp'])&&$WPhtc_data['cpp']!=''){
271
- $rewrite_rules=str_replace('page/',$WPhtc_data['cpp'].'/',$rewrite_rules);
272
  }
273
  # Search
274
- if(isset($WPhtc_data['custom_search_permalink'])&&$WPhtc_data['custom_search_permalink']!=''){
275
- $rewrite_rules=str_replace('search/',$WPhtc_data['custom_search_permalink'].'/',$rewrite_rules);
276
  }
277
 
278
  $rewrite_rules=unserialize(preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'",$rewrite_rules));
@@ -283,8 +279,8 @@ if (!class_exists("WPhtc")) {
283
  # Adding our Custom Author Base to the sitemap generated by Google XML Sitemaps
284
  # Adapted from sitemap-core.php (line ~2036)
285
  function set_sm(){
286
- $WPhtc_data=get_option('WPhtc_data');
287
- if(class_exists('GoogleSitemapGenerator')&&$WPhtc_data['cap']!=''){
288
  $generatorObject = &GoogleSitemapGenerator::GetInstance();
289
  if ($generatorObject != null){
290
  global $wpdb;
@@ -307,7 +303,7 @@ if (!class_exists("WPhtc")) {
307
  $authors = $wpdb->get_results($sql);
308
  if($authors && is_array($authors)) {
309
  foreach($authors as $author) {
310
- $url=get_bloginfo('home')."/".$WPhtc_data['cap']."/".$author->user_nicename."/";
311
  $generatorObject->AddUrl($url,$generatorObject->GetTimestampFromMySql($author->last_post),$generatorObject->GetOption("cf_auth"),$generatorObject->GetOption("pr_auth"));
312
  }
313
  }
@@ -315,42 +311,42 @@ if (!class_exists("WPhtc")) {
315
  }
316
  }
317
  # Adding rewrite pairs to the .htaccess generated by Wordpress, everytime the rules are flush
318
- function wphtc_wp_rewrite_rules($wp_rewrite){
319
- $WPhtc_data=get_option('WPhtc_data');
320
  # Keeping a copy of the generated htaccess in our option array for later reviewing
321
- $WPhtc_data['cur_hta']='# BEGIN Wordpress<br/>'.nl2br($wp_rewrite->mod_rewrite_rules())."# END Wordpress";
322
- update_option('WPhtc_data',$WPhtc_data);
323
  return $wp_rewrite;
324
  }
325
  # Adding Custom Rules to htaccess file generated by Wordpress, everytime the rules are flush
326
- function wphtc_hta_rules($rules){
327
- $WPhtc_data=get_option('WPhtc_data');
328
  # keeping original hta
329
- if(!isset($WPhtc_data['htaccess_original'])){
330
- $WPhtc_data['htaccess_original']=$rules;
331
- update_option('WPhtc_data',$WPhtc_data);
332
  }
333
  # Maintenance Mode
334
- if($WPhtc_data['maintenance_active']&&isset($WPhtc_data['maintenance_ips'][0])){
335
- $no_ips=count($WPhtc_data['maintenance_ips']);
336
  $new_rules.="\n# WPhtc: Begin Maintenance Mode\n";
337
  # redirect
338
- if($WPhtc_data['maintenance_redirection']!=''){
339
  $new_rules.="RewriteEngine on\n";
340
  $new_rules.="RewriteCond %{REQUEST_URI} !\.(jpe?g|png|gif) [NC]\n";
341
  for($i=0;$i<$no_ips;$i++){
342
- $new_rules.="RewriteCond %{REMOTE_HOST} !^".str_replace(".","\.",trim($WPhtc_data['maintenance_ips'][$i]))."\n";
343
  }
344
- if(substr($WPhtc_data['maintenance_redirection'],0,1)=="/"){
345
- $new_rules.="RewriteCond %{REQUEST_URI} !".$WPhtc_data['maintenance_redirection']."$ [NC]\n";
346
  }
347
- $new_rules.="RewriteRule .* ".$WPhtc_data['maintenance_redirection']." [R=302,L]\n";
348
  }
349
  # no redirection
350
  else{
351
  $new_rules.="order deny,allow\n";
352
  $new_rules.="deny from all\n";
353
- foreach($WPhtc_data['maintenance_ips'] as $ip){
354
  $new_rules.="allow from ".$ip."\n";
355
  }
356
  }
@@ -358,70 +354,70 @@ if (!class_exists("WPhtc")) {
358
  }
359
 
360
  # Login Control
361
- if($WPhtc_data['login_disabled']){
362
- $no_ips=count($WPhtc_data['login_ips']);
363
  $new_rules.="\n# WPhtc: Begin Login Control (start deleting here if you're having trouble logging in)\n";
364
  # redirect
365
  $new_rules.="RewriteEngine on\n";
366
  $new_rules.="RewriteCond %{REQUEST_URI} .wp-login\.php* [NC]\n";
367
- if($WPhtc_data['login_half_mode']){
368
  $new_rules.="RewriteCond %{REQUEST_METHOD} !=POST\n";
369
  $new_rules.="RewriteCond %{QUERY_STRING} !action=(logout|lostpassword|postpass|retrievepassword|resetpass|rp)*\n";
370
  }
371
  if($no_ips>0){
372
  for($i=0;$i<$no_ips;$i++){
373
- $new_rules.="RewriteCond %{REMOTE_HOST} !^".str_replace(".","\.",trim($WPhtc_data['login_ips'][$i]))."\n";
374
  }
375
  }
376
- $new_rules.="RewriteRule .* ".$WPhtc_data['login_redirection']." [R=301,L]\n";
377
  $new_rules.="# WPhtc: End Login Control Mode (stop deleting here if you're having trouble logging in)\n";
378
  }
379
  # Custom htaccess
380
- if($WPhtc_data['hta']){
381
  $new_rules.="\n# WPhtc: Begin Custom htaccess\n";
382
- $new_rules.=stripslashes($WPhtc_data['hta'])."\n";
383
  $new_rules.="# WPhtc: End Custom htaccess\n";
384
  }
385
  # htaccess suggestions
386
- if($WPhtc_data['disable_serversignature']){
387
  $new_rules.="\n# WPhtC: Disable ServerSignature on generated error pages\n";
388
  $new_rules.="ServerSignature Off\n";
389
  }
390
- if($WPhtc_data['admin_email']){
391
  $new_rules.="\n# WPhtC: Set admin email\n";
392
- $new_rules.="SetEnv SERVER_ADMIN ".$WPhtc_data['admin_email']."\n\n";
393
  }
394
- if($WPhtc_data['disable_indexes']){
395
  $new_rules.="\n# WPhtC: Disable directory browsing\n";
396
  $new_rules.="Options All -Indexes\n";
397
  }
398
- if($WPhtc_data['up_limit']){
399
- $new_rules.="\n# WPhtC: Limit upload size to ".$WPhtc_data['up_limit']." MB\n";
400
- $new_rules.="LimitRequestBody ".($WPhtc_data['up_limit']*1024*1024)." \n";
401
  }
402
- if($WPhtc_data['redirect_500']){
403
  $new_rules.="\n# WPhtC: Setting 500 Error page\n";
404
- $new_rules.="ErrorDocument 500 ".$WPhtc_data['redirect_500']."\n";
405
  }
406
- if($WPhtc_data['redirect_403']){
407
  $new_rules.="\n# WPhtC: Setting 403 Error page\n";
408
- $new_rules.="ErrorDocument 403 ".$WPhtc_data['redirect_403']."\n";
409
  }
410
- if($WPhtc_data['protect_wp_config']){
411
  $new_rules.="\n# WPhtC: Protect WP-config.php\n";
412
  $new_rules.="<files wp-config.php>\n";
413
  $new_rules.="order allow,deny\n";
414
  $new_rules.="deny from all\n";
415
  $new_rules.="</files>\n";
416
  }
417
- if($WPhtc_data['protect_htaccess']){
418
  $new_rules.="\n# WPhtC: Protect .htaccess file\n";
419
  $new_rules.="<files ~ \"^.*\.([Hh][Tt][Aa])\">\n";
420
  $new_rules.="order allow,deny\n";
421
  $new_rules.="deny from all\n";
422
  $new_rules.="</files>\n";
423
  }
424
- if($WPhtc_data['protect_comments']){
425
  $new_rules.="\n# WPhtC: Protect comments.php\n";
426
  $new_rules.="RewriteCond %{REQUEST_METHOD} POST\n";
427
  $new_rules.="RewriteCond %{REQUEST_URI} .wp-comments-post\.php*\n";
@@ -429,30 +425,30 @@ if (!class_exists("WPhtc")) {
429
  $new_rules.="RewriteCond %{HTTP_USER_AGENT} ^$\n";
430
  $new_rules.="RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]\n";
431
  }
432
- if($WPhtc_data['disable_hotlink']){
433
  $new_rules.="\n# WPhtC: Disable image hotlinking\n";
434
  $new_rules.="<IfModule mod_rewrite.c>\n";
435
  $new_rules.="RewriteEngine on\n";
436
  $new_rules.="RewriteCond %{HTTP_REFERER} !^$\n";
437
  $new_rules.="RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?".str_ireplace(array("http://","www."),"",get_bloginfo("url"))."/.*$ [NC]\n";
438
- $new_rules.="RewriteRule \.(jpg|jpeg|png|gif)$ ".$WPhtc_data['disable_hotlink']." [NC,R,L]\n";
439
  $new_rules.="</IfModule>\n";
440
  }
441
- if($WPhtc_data['disable_file_hotlink_ext']){
442
- $redir = $WPhtc_data['disable_file_hotlink_redir'] ? $WPhtc_data['disable_file_hotlink_redir'] : "_";
443
  $new_rules.="\n# WPhtC: Disable file hotlinking\n";
444
  $new_rules.="<IfModule mod_rewrite.c>\n";
445
  $new_rules.="RewriteEngine on\n";
446
  $new_rules.="RewriteCond %{HTTP_REFERER} !^$\n";
447
  $new_rules.="RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?".str_ireplace(array("http://","www."),"",get_bloginfo("url"))."/.*$ [NC]\n";
448
- $new_rules.="RewriteRule \.(".str_replace(" ","|",$WPhtc_data['disable_file_hotlink_ext']).")$ ".$redir." [NC,R,L]\n";
449
  $new_rules.="</IfModule>\n";
450
  }
451
- if($WPhtc_data['canon']){
452
  $url=str_ireplace(array("http://","www."),"",get_bloginfo("url"));
453
  $domain=explode("/",$url);
454
  $escaped_domain=str_ireplace(".","\.",$domain[0]);
455
- if($WPhtc_data['canon']=='www'){
456
  $siteurl=get_option('siteurl');
457
  if (!preg_match('/^http:\/\/www\./', $siteurl)) {
458
  $siteurl=str_replace("http://","http://www.",$siteurl);
@@ -464,7 +460,7 @@ if (!class_exists("WPhtc")) {
464
  update_option('home',$homeurl);
465
  }
466
  }
467
- else if($WPhtc_data['canon']=='simple'){
468
  $siteurl=get_option('siteurl');
469
  if (preg_match('/^http:\/\/www\./', $siteurl)) {
470
  $siteurl=str_replace("http://www.","http://",$siteurl);
@@ -477,7 +473,7 @@ if (!class_exists("WPhtc")) {
477
  }
478
  }
479
  }
480
- if($WPhtc_data['gzip']){
481
  $new_rules.="\n# WPhtC: Setting mod_gzip\n";
482
  $new_rules.="<ifModule mod_gzip.c>\n";
483
  $new_rules.="mod_gzip_on Yes\n";
@@ -490,7 +486,7 @@ if (!class_exists("WPhtc")) {
490
  $new_rules.="mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*\n";
491
  $new_rules.="</ifModule>\n";
492
  }
493
- if($WPhtc_data['deflate']){
494
  $new_rules.="\n# WPhtC: Setting mod_deflate\n";
495
  $new_rules.="<IfModule mod_deflate.c>\n";
496
  $new_rules.="AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript\n";
@@ -500,8 +496,8 @@ if (!class_exists("WPhtc")) {
500
  $new_rules.="Header append Vary User-Agent env=!dont-vary\n";
501
  $new_rules.="</IfModule>\n";
502
  }
503
- if($WPhtc_data['wp_hta']&&trim($WPhtc_data['wp_hta'])!=''){
504
- $new_rules.="\n".$WPhtc_data['wp_hta'];
505
  }
506
  else{
507
  $new_rules.="\n".$rules;
@@ -513,21 +509,27 @@ if (!class_exists("WPhtc")) {
513
  function filter_term_link($termlink, $term, $taxonomy){
514
  $txs=get_taxonomies(array('name'=>$taxonomy),"object");
515
  foreach($txs as $t){
516
- return str_replace($t->rewrite['slug']."/","",$termlink);
 
 
 
 
 
 
517
  }
518
  }
519
 
520
  # Filter Taxonomy Base
521
  function remove_taxonomy_base_from_rewrite_rules($rules){
522
- # Let's remove every taxonomy rule here, we'll reacreate them at wphtc_filter_rewrite_rules()
523
  return array();
524
  //return $rules;
525
  }
526
 
527
  # Filter Author Rewrite Rules
528
  function remove_author_base_from_rewrite_rules($author_rewrite) {
529
- $WPhtc_data=get_option('WPhtc_data');
530
- if($WPhtc_data['remove_author_base']){
531
  $author_rewrite=array();
532
  $blogusers = get_users('who=authors');
533
  foreach($blogusers as $user) {
@@ -539,23 +541,23 @@ if (!class_exists("WPhtc")) {
539
  return $author_rewrite;
540
  }
541
  # WP-htaccess Control options page interface
542
- function wphtc_page(){
543
  include (dirname (__FILE__).'/wp-htaccess-control-ui.php');
544
  }
545
  # Adding our options page to the admin menu
546
  function configure_menu(){
547
  if(current_user_can("administrator")){
548
- $page=add_submenu_page("options-general.php","WP htaccess Control", "htaccess Control", 6, __FILE__, array('WPhtc','wphtc_page'));
549
- add_action('admin_print_scripts-'.$page, array('WPhtc','wphtc_page_script'));
550
- add_action('admin_print_styles-'.$page, array('WPhtc','wphtc_page_style'));
551
  }
552
  }
553
  # Enqueue Ui Scripts on Plugin page
554
- function wphtc_page_script(){
555
  wp_enqueue_script("htaccess-control-js", WP_PLUGIN_URL . '/wp-htaccess-control/wp-htaccess-control-ui.js');
556
  }
557
  # Enqueue Ui Scripts on Plugin page
558
- function wphtc_page_style(){
559
  wp_enqueue_style("htaccess-control-css", WP_PLUGIN_URL . '/wp-htaccess-control/wp-htaccess-control-ui.css');
560
  }
561
 
@@ -568,17 +570,17 @@ if (!class_exists("WPhtc")) {
568
  }
569
 
570
  # Options Page Actions
571
- function wphtc_page_action(){
572
- $this->wphtc_check_first_run();
573
  $action=$_REQUEST['action'];
574
  global $echo;
575
  if(isset($action)){
576
- $WPhtc_data=get_option('WPhtc_data');
577
  switch($action){
578
  # Hide donation message for one month
579
  case 'hide_donation_message':
580
- $WPhtc_data['donation_hidden_time']=time()+ 90 * 24 * 60 * 60;
581
- update_option('WPhtc_data',$WPhtc_data);
582
  break;
583
  # if reseting everything just delete the option array
584
  case 'reset_rules':
@@ -593,91 +595,91 @@ if (!class_exists("WPhtc")) {
593
  # if updating, save new rules in database and flush rewrite rules
594
  case 'update':
595
  # first donation hidding time 'now'
596
- if(!$WPhtc_data['donation_hidden_time']){
597
- $WPhtc_data['donation_hidden_time']=time();
598
  }
599
  # nonce
600
  if(!check_admin_referer( 'WPhtc_settings')){
601
  die("You have no permission to do this.");
602
  }
603
  # get Custom Htaccess
604
- $WPhtc_data['hta']=$_POST['WPhtc_hta'];
605
  # get Custom Author Permalink
606
- $WPhtc_data['cap']=$_POST['WPhtc_cap'];
607
  # get Custom Pagination Permalink
608
- $WPhtc_data['cpp']=$_POST['WPhtc_cpp'];
609
  # get Custom Search Permalink
610
- $WPhtc_data['custom_search_permalink']=$_POST['WPhtc_custom_search_permalink'];
611
  # wordpress htaccess and jim morgan's htaccess
612
- $WPhtc_data['wp_hta']=$_POST['WPhtc_wp_hta']."\n";
613
- $WPhtc_data['jim_morgan_hta']=$_POST['WPhtc_jim_morgan_hta'];
614
- if($WPhtc_data['jim_morgan_hta']){
615
- $WPhtc_data['wp_hta'] ="\nRewriteEngine on\n";
616
- $WPhtc_data['wp_hta'].="# Unless you have set a different RewriteBase preceding this point,\n";
617
- $WPhtc_data['wp_hta'].="# you may delete or comment-out the following RewriteBase directive:\n";
618
- $WPhtc_data['wp_hta'].="RewriteBase /\n";
619
- $WPhtc_data['wp_hta'].="# if this request is for \"/\" or has already been rewritten to WP\n";
620
- $WPhtc_data['wp_hta'].="RewriteCond $1 ^(index\.php)?$ [OR]\n";
621
- $WPhtc_data['wp_hta'].="# or if request is for image, css, or js file\n";
622
- $WPhtc_data['wp_hta'].="RewriteCond $1 \.(gif|jpg|jpeg|png|css|js|ico)$ [NC,OR]\n";
623
- $WPhtc_data['wp_hta'].="# or if URL resolves to existing file\n";
624
- $WPhtc_data['wp_hta'].="RewriteCond %{REQUEST_FILENAME} -f [OR]\n";
625
- $WPhtc_data['wp_hta'].="# or if URL resolves to existing directory\n";
626
- $WPhtc_data['wp_hta'].="RewriteCond %{REQUEST_FILENAME} -d\n";
627
- $WPhtc_data['wp_hta'].="# then skip the rewrite to WP\n";
628
- $WPhtc_data['wp_hta'].="RewriteRule ^(.*)$ - [S=1]\n";
629
- $WPhtc_data['wp_hta'].="# else rewrite the request to WP\n";
630
- $WPhtc_data['wp_hta'].="RewriteRule . /index.php [L]\n";
631
  }
632
  # Remove Author Base
633
- $WPhtc_data['remove_author_base']=$_POST['WPhtc_remove_author_base'];
634
  # Advanced Archives
635
- $WPhtc_data['category_archives']=$_POST['WPhtc_category_archives'];
636
- $WPhtc_data['author_archives']=$_POST['WPhtc_author_archives'];
637
- $WPhtc_data['tag_archives']=$_POST['WPhtc_tag_archives'];
638
  # get htaccess Suggestions
639
- $WPhtc_data['disable_serversignature']=$_POST['WPhtc_disable_serversignature'];
640
- $WPhtc_data['disable_indexes']=$_POST['WPhtc_disable_indexes'];
641
- $WPhtc_data['up_limit']=(is_numeric($_POST['WPhtc_up_limit'])&&$_POST['WPhtc_up_limit']>0)?$_POST['WPhtc_up_limit']:'';
642
- $WPhtc_data['protect_wp_config']=$_POST['WPhtc_protect_wp_config'];
643
- $WPhtc_data['protect_htaccess']=$_POST['WPhtc_protect_htaccess'];
644
- $WPhtc_data['protect_comments']=$_POST['WPhtc_protect_comments'];
645
- $WPhtc_data['disable_hotlink']=trim($_POST['WPhtc_disable_hotlink']);
646
- $WPhtc_data['disable_file_hotlink_ext']=trim($_POST['WPhtc_disable_file_hotlink_ext']);
647
- $WPhtc_data['disable_file_hotlink_redir']=trim($_POST['WPhtc_disable_file_hotlink_redir']);
648
- $WPhtc_data['redirect_500']=trim($_POST['WPhtc_redirect_500']);
649
- $WPhtc_data['redirect_403']=trim($_POST['WPhtc_redirect_403']);
650
- $WPhtc_data['canon']=$_POST['WPhtc_canon'];
651
- $WPhtc_data['admin_email']=trim($_POST['WPhtc_admin_email']);
652
- $WPhtc_data['deflate']=trim($_POST['WPhtc_deflate']);
653
- $WPhtc_data['gzip']=trim($_POST['WPhtc_gzip']);
654
  # get maintenance
655
- $WPhtc_data['maintenance_active']=$_POST['WPhtc_maintenance_active'];
656
  $lines=preg_split("/\n|,/",$_POST['WPhtc_maintenance_ips']);
657
- $WPhtc_data['maintenance_ips']=array();
658
  foreach($lines as $line){
659
  trim($line);
660
  if(preg_match("/[a-z,0-9,\.]/",$line)){
661
- $WPhtc_data['maintenance_ips'][]=$line;
662
  }
663
  }
664
- $WPhtc_data['maintenance_redirection']=trim($_POST['WPhtc_maintenance_redirection']);
665
  # get login control data
666
- $WPhtc_data['login_disabled']=$_POST['WPhtc_login_disabled'];
667
- $WPhtc_data['login_half_mode']=$_POST['WPhtc_login_half_mode'];
668
- $WPhtc_data['login_redirection']=trim($_POST['WPhtc_login_redirection']);
669
  $lines=preg_split("/\n|,/",$_POST['WPhtc_login_ips']);
670
- $WPhtc_data['login_ips']=array();
671
  foreach($lines as $line){
672
  trim($line);
673
  if(preg_match("/[a-z,0-9,\.]/",$line)){
674
- $WPhtc_data['login_ips'][]=$line;
675
  }
676
  }
677
 
678
  # Unsetting inclusion of Author pages on Google XML Sitemap options, we'll add those links to the sitemap later with our Custom Author Permalink
679
- $WPhtc_data['sm_enabled']=$_POST['WPhtc_sm_enabled'];
680
- if($WPhtc_data['sm_enabled']==true){
681
  $SMoptions=get_option("sm_options");
682
  if($SMoptions&&is_array($SMoptions)){
683
  $SMoptions=get_option("sm_options");
@@ -689,23 +691,23 @@ if (!class_exists("WPhtc")) {
689
  }
690
 
691
  # Taxonomy Base removal options
692
- unset($WPhtc_data['remove_taxonomy_base']);
693
  if($_POST['WPhtc_remove_base']){
694
  foreach($_POST['WPhtc_remove_base'] as $tax_key=>$remove){
695
- $WPhtc_data['remove_taxonomy_base'][$tax_key]=$remove;
696
  }
697
  }
698
 
699
  # Advanced archives
700
- unset($WPhtc_data['create_archive']);
701
  if($_POST['WPhtc_create_archive']){
702
  foreach($_POST['WPhtc_create_archive'] as $tax_key=>$create_archive){
703
- $WPhtc_data['create_archive'][$tax_key]=$create_archive;
704
  }
705
  }
706
 
707
  # Update WP htaccess Control options
708
- update_option('WPhtc_data',$WPhtc_data);
709
  # Flush Rewrite Rules
710
  $this->refresh_rewrite_rules();
711
  $echo.=__('All options updated.', 'wp-htaccess-control');
@@ -719,36 +721,51 @@ if (class_exists("WPhtc")) {
719
  $WPhtc = new WPhtc();
720
  }
721
  if (isset($WPhtc)) {
722
- add_filter('mod_rewrite_rules', array($WPhtc,'wphtc_hta_rules'));
723
- add_filter('generate_rewrite_rules', array($WPhtc,'wphtc_wp_rewrite_rules'));
724
- add_filter('rewrite_rules_array',array($WPhtc,'wphtc_filter_rewrite_rules'));
725
- add_filter('author_link',array($WPhtc,'wphtc_filter_author_link'));
726
- add_filter('get_pagenum_link',array($WPhtc,'wphtc_filter_get_pagenum_link'));
727
- add_filter('redirect_canonical',array($WPhtc,'wphtc_filter_redirect_canonical'),10,10);
728
- add_filter('get_search_query',array($WPhtc,'wphtc_get_search_query_filter'),10,10);
729
- add_filter('search_feed_link',array($WPhtc,'wphtc_search_feed_link'),10,10);
730
  add_action('admin_menu', array($WPhtc,'configure_menu'));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
731
  add_action('sm_buildmap',array($WPhtc,'set_sm'));
732
- add_action('init', array($WPhtc,'wphtc_init'));
733
- add_action('template_redirect', array($WPhtc,'wphtc_template_redirect') );
734
- add_filter('author_rewrite_rules', array($WPhtc,'remove_author_base_from_rewrite_rules'));
735
- add_filter('term_link',array($WPhtc,'filter_term_link'),10,3);
736
 
737
  /* Taxonomy Base Removal*/
738
- $WPhtc_data=get_option('WPhtc_data');
739
- if($WPhtc_data['remove_taxonomy_base']){
740
- foreach($WPhtc_data['remove_taxonomy_base'] as $tax=>$v){
741
  if($v) {
742
  add_filter($tax.'_rewrite_rules', array($WPhtc,'remove_taxonomy_base_from_rewrite_rules'));
743
  add_filter($tax."_row_actions",array($WPhtc,'filter_tax_table_actions'), 10,2 );
744
  }
745
  }
746
  }
747
-
748
- add_action('flush_event',array($WPhtc,'refresh_rewrite_rules'));
749
- add_action('created_term',array($WPhtc,'refresh_rewrite_rules_later'));
750
- add_action('edited_term',array($WPhtc,'refresh_rewrite_rules_later'));
751
- add_action('delete_term',array($WPhtc,'refresh_rewrite_rules_later'));
 
 
752
  /* This flush should maybe be conditional to content authors only, maybe not */
753
  add_action('user_register',array($WPhtc,'refresh_rewrite_rules_later'));
754
  add_action('delete_user',array($WPhtc,'refresh_rewrite_rules_later'));
3
  Plugin Name: WP htaccess Control
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
  Description: Interface to customize the permalinks (author, category, archives and pagination) and htaccess file generated by Wordpress.
6
+ Version: 3.1
7
  Author: António Andrade
8
  Author URI: http://dardna.com
9
  */
28
 
29
  if (!class_exists("WPhtc")) {
30
  class WPhtc {
31
+
32
+ public $data;
33
+
34
  function WPhtc() {
35
+ $data=get_option('WPhtc_data');
36
  }
37
+ function init(){
38
  # set locale
39
  $currentLocale = get_locale();
40
  if(!empty($currentLocale)) {
42
  if(@file_exists($moFile) && is_readable($moFile)) load_textdomain('wp-htaccess-control', $moFile);
43
  }
44
  }
45
+ function search_template_redirect(){
 
 
46
  # redirect "?s=*" to "/search-base/*"
47
  if($_GET['s']){
48
+ wp_redirect( home_url( $this->data['custom_search_permalink']. "/" . rawurlencode(get_query_var( 's' )) ) );
49
  }
50
 
51
  # rewrite query
52
+ if(strpos($_SERVER["REQUEST_URI"], $this->data['custom_search_permalink'])){
53
  global $wp_query;
54
  if(strpos($_SERVER["REQUEST_URI"], '/feed')){
55
  preg_match("/feed\/(feed|rdf|rss|rss2|atom)?/",$_SERVER["REQUEST_URI"], $feed);
60
  $format="&feed=feed";
61
  }
62
  }
63
+ $page_base=($this->data['cpp']!='')?$this->data['cpp']:'page';
64
 
65
  # in need of better regex
66
  if(!strpos($_SERVER["REQUEST_URI"], '/feed')&&!strpos($_SERVER["REQUEST_URI"],$page_base)){
67
+ $pattern="/\/".$this->data['custom_search_permalink']."\/(.+)/";
68
  }
69
  else{
70
+ $pattern="/\/".$this->data['custom_search_permalink']."\/(.+)\/feed|".$page_base."?/";
71
  }
72
 
73
+ $pattern="/\/".$this->data['custom_search_permalink']."\/(.+)/";
74
  preg_match($pattern,$_SERVER["REQUEST_URI"], $matches);
75
  $results=split("/",$matches[1]);
76
  if($results[1]==$page_base){
78
  }
79
  $wp_query=new WP_Query('s='.$results[0].$page.$format );
80
  }
 
81
  }
82
  # return get_search_query on custom search base
83
+ function get_search_query_filter($query){
84
+
85
+ if($this->data['custom_search_permalink']!=''&&strpos($_SERVER["REQUEST_URI"], $this->data['custom_search_permalink'])){
86
+ $page_base=($this->data['cpp']!='')?$this->data['cpp']:'page';
87
  # in need of better regex
88
  if(!strpos($_SERVER["REQUEST_URI"], '/feed')&&!strpos($_SERVER["REQUEST_URI"],"/".$page_base)){
89
+ $pattern="/\/".$this->data['custom_search_permalink']."\/(.+)/";
90
  }
91
  else{
92
+ $pattern="/\/".$this->data['custom_search_permalink']."\/(.+)\/feed|".$page_base."?/";
93
  }
94
  preg_match($pattern,$_SERVER["REQUEST_URI"], $matches);
95
  $results=split("/",$matches[1]);
97
  }
98
  return $query;
99
  }
100
+ function search_feed_link($link){
101
+
102
+ $link=str_replace("search",$this->data['custom_search_permalink'],$link);
 
 
103
  return $link;
104
  }
105
+ function check_first_run(){
106
+
107
 
108
  # MIGRATE OPTIONS
109
 
110
  // deprecating old category base removal
111
+ if($this->data['remove_category_base']){
112
+ unset($this->data['remove_category_base']);
113
+ $this->data['remove_taxonomy_base']['category']=true;
114
  }
115
  // deprecating old category archive
116
+ if($this->data['category_archives']){
117
+ unset($this->data['category_archives']);
118
+ $this->data['create_archive']['category']=true;
119
  }
120
  // deprecating old tag archive
121
+ if($this->data['tag_archives']){
122
+ unset($this->data['tag_archives']);
123
+ $this->data['create_archive']['post_tag']=true;
124
  }
125
+ if($this->data['remove_category_base'] || $this->data['category_archives'] || $this->data['tag_archives']){
126
+ update_option('WPhtc_data',$this->data);
127
  }
128
 
129
  # flush rules to get some data filled on first usage
130
+ if(!isset($this->data['htaccess_original'])){
131
  $this->refresh_rewrite_rules();
132
  }
133
  }
140
  wp_schedule_single_event(time(), 'flush_event');
141
  }
142
  # Filter pagination links generated by Wordpress
143
+ function filter_get_pagenum_link($result){
144
+ $result=preg_replace("/".urlencode($this->data['cpp'])."\/[0-9]+[\/]?/","",$result);
145
+ $result=str_replace("page",urlencode($this->data['cpp']),$result);
 
 
 
146
  return $result;
147
  }
148
  # Filter link generated by get_author_posts_url() to use the Custom Author Permalink
149
+ function filter_author_link($link){
150
+
151
+ if($this->data['remove_author_base']){
152
  $link=str_replace("author/","",$link);
153
  }
154
+ else if(isset($this->data['cap']) && $this->data['cap']!=''){
155
+ $link=str_replace("author",urlencode($this->data['cap']),$link);
156
  }
157
  return $link;
158
  }
159
 
160
+ function filter_redirect_canonical($requested_url){
161
  global $wp;
162
+
163
  # Disable canonical redirection on urls using custom pagination permalink
164
+ if(isset($this->data['cpp'])&&$this->data['cpp']!=''&&get_query_var('paged') > 1&&preg_match("/".urlencode($this->data['cpp'])."/",$wp->request)){
165
  return false;
166
  }
167
  else{
179
  return $ancestor;
180
  }
181
  # Rewrite Rules: Add Category + Tag + Author Archives; Custom Pagination; Custom Author Base
182
+ function filter_rewrite_rules($rewrite_rules){
183
+
184
 
185
+ $page_base=($this->data['cpp']!='')?$this->data['cpp']:'page';
186
 
187
+ if($this->data['create_archive'] || $this->data['remove_taxonomy_base']){
188
  foreach (get_taxonomies('','objects') as $taxonomy){
189
+ if(!$taxonomy->rewrite || ( !$this->data['remove_taxonomy_base'][$taxonomy->name] && !$this->data['create_archive'][$taxonomy->name] )){continue;}
190
  $terms=get_terms($taxonomy->name);
191
  foreach($terms as $term){
192
+ $base=$this->data['remove_taxonomy_base'][$taxonomy->name]?"":$taxonomy->rewrite->slug."/";
193
  if($term->parent!=0){
194
  $ancestors=$this->term_ancestors($taxonomy->name,$term->parent)."/";
195
  }
200
  $tax_name=($taxonomy->name=="category")?"category_name":$taxonomy->name;
201
 
202
  # create archives
203
+ if($this->data['create_archive'][$tax_name]){
204
  #year
205
  $new_rules[$base.$ancestors.'('.$term->slug.')/([0-9]{4})/?$'] = 'index.php?'.$tax_name.'=$matches[1]&year=$matches[2]';
206
  $new_rules[$base.$ancestors.'('.$term->slug.')/([0-9]{4})/'.$page_base.'/?([0-9]{1,})/?$'] = 'index.php?'.$tax_name.'=$matches[1]&year=$matches[2]&paged=$matches[3]';
223
  }
224
 
225
  # Author Archives
226
+ if($this->data['remove_author_base']){
227
  $blogusers = get_users('who=authors');
228
  foreach ($blogusers as $user) {
229
 
240
  $rewrite_rules = $new_rules + $rewrite_rules;
241
  }
242
  }
243
+ else if(isset($this->data['author_archives'])){
244
+ $author_base = ($this->data['cap']!='')?$this->data['cap']:'author';
245
  $new_rules = array(
246
  $author_base.'/([^/]+)/([0-9]{4})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]',
247
  $author_base.'/([^/]+)/([0-9]{4})/'.$page_base.'/?([0-9]{1,})/?$' => 'index.php?author_name=$matches[1]&year=$matches[2]&paged=$matches[3]',
256
  }
257
 
258
  # Custom Pagination; Custom Author Permalink
259
+ if((isset($this->data['cap'])&&$this->data['cap']!='')||(isset($this->data['cpp'])&&$this->data['cpp']!='')){
260
  $rewrite_rules=serialize($rewrite_rules);
261
  # Author
262
+ if(isset($this->data['cap'])&&$this->data['cap']!=''){
263
+ $rewrite_rules=str_replace('author/',$this->data['cap'].'/',$rewrite_rules);
264
  }
265
  # Pagination
266
+ if(isset($this->data['cpp'])&&$this->data['cpp']!=''){
267
+ $rewrite_rules=str_replace('page/',$this->data['cpp'].'/',$rewrite_rules);
268
  }
269
  # Search
270
+ if(isset($this->data['custom_search_permalink'])&&$this->data['custom_search_permalink']!=''){
271
+ $rewrite_rules=str_replace('search/',$this->data['custom_search_permalink'].'/',$rewrite_rules);
272
  }
273
 
274
  $rewrite_rules=unserialize(preg_replace('!s:(\d+):"(.*?)";!se', "'s:'.strlen('$2').':\"$2\";'",$rewrite_rules));
279
  # Adding our Custom Author Base to the sitemap generated by Google XML Sitemaps
280
  # Adapted from sitemap-core.php (line ~2036)
281
  function set_sm(){
282
+
283
+ if(class_exists('GoogleSitemapGenerator')&&$this->data['cap']!=''){
284
  $generatorObject = &GoogleSitemapGenerator::GetInstance();
285
  if ($generatorObject != null){
286
  global $wpdb;
303
  $authors = $wpdb->get_results($sql);
304
  if($authors && is_array($authors)) {
305
  foreach($authors as $author) {
306
+ $url=get_bloginfo('home')."/".$this->data['cap']."/".$author->user_nicename."/";
307
  $generatorObject->AddUrl($url,$generatorObject->GetTimestampFromMySql($author->last_post),$generatorObject->GetOption("cf_auth"),$generatorObject->GetOption("pr_auth"));
308
  }
309
  }
311
  }
312
  }
313
  # Adding rewrite pairs to the .htaccess generated by Wordpress, everytime the rules are flush
314
+ function wp_rewrite_rules($wp_rewrite){
315
+
316
  # Keeping a copy of the generated htaccess in our option array for later reviewing
317
+ $this->data['cur_hta']='# BEGIN Wordpress<br/>'.nl2br($wp_rewrite->mod_rewrite_rules())."# END Wordpress";
318
+ update_option('WPhtc_data',$this->data);
319
  return $wp_rewrite;
320
  }
321
  # Adding Custom Rules to htaccess file generated by Wordpress, everytime the rules are flush
322
+ function hta_rules($rules){
323
+
324
  # keeping original hta
325
+ if(!isset($this->data['htaccess_original'])){
326
+ $this->data['htaccess_original']=$rules;
327
+ update_option('WPhtc_data',$this->data);
328
  }
329
  # Maintenance Mode
330
+ if($this->data['maintenance_active']&&isset($this->data['maintenance_ips'][0])){
331
+ $no_ips=count($this->data['maintenance_ips']);
332
  $new_rules.="\n# WPhtc: Begin Maintenance Mode\n";
333
  # redirect
334
+ if($this->data['maintenance_redirection']!=''){
335
  $new_rules.="RewriteEngine on\n";
336
  $new_rules.="RewriteCond %{REQUEST_URI} !\.(jpe?g|png|gif) [NC]\n";
337
  for($i=0;$i<$no_ips;$i++){
338
+ $new_rules.="RewriteCond %{REMOTE_HOST} !^".str_replace(".","\.",trim($this->data['maintenance_ips'][$i]))."\n";
339
  }
340
+ if(substr($this->data['maintenance_redirection'],0,1)=="/"){
341
+ $new_rules.="RewriteCond %{REQUEST_URI} !".$this->data['maintenance_redirection']."$ [NC]\n";
342
  }
343
+ $new_rules.="RewriteRule .* ".$this->data['maintenance_redirection']." [R=302,L]\n";
344
  }
345
  # no redirection
346
  else{
347
  $new_rules.="order deny,allow\n";
348
  $new_rules.="deny from all\n";
349
+ foreach($this->data['maintenance_ips'] as $ip){
350
  $new_rules.="allow from ".$ip."\n";
351
  }
352
  }
354
  }
355
 
356
  # Login Control
357
+ if($this->data['login_disabled']){
358
+ $no_ips=count($this->data['login_ips']);
359
  $new_rules.="\n# WPhtc: Begin Login Control (start deleting here if you're having trouble logging in)\n";
360
  # redirect
361
  $new_rules.="RewriteEngine on\n";
362
  $new_rules.="RewriteCond %{REQUEST_URI} .wp-login\.php* [NC]\n";
363
+ if($this->data['login_half_mode']){
364
  $new_rules.="RewriteCond %{REQUEST_METHOD} !=POST\n";
365
  $new_rules.="RewriteCond %{QUERY_STRING} !action=(logout|lostpassword|postpass|retrievepassword|resetpass|rp)*\n";
366
  }
367
  if($no_ips>0){
368
  for($i=0;$i<$no_ips;$i++){
369
+ $new_rules.="RewriteCond %{REMOTE_HOST} !^".str_replace(".","\.",trim($this->data['login_ips'][$i]))."\n";
370
  }
371
  }
372
+ $new_rules.="RewriteRule .* ".$this->data['login_redirection']." [R=301,L]\n";
373
  $new_rules.="# WPhtc: End Login Control Mode (stop deleting here if you're having trouble logging in)\n";
374
  }
375
  # Custom htaccess
376
+ if($this->data['hta']){
377
  $new_rules.="\n# WPhtc: Begin Custom htaccess\n";
378
+ $new_rules.=stripslashes($this->data['hta'])."\n";
379
  $new_rules.="# WPhtc: End Custom htaccess\n";
380
  }
381
  # htaccess suggestions
382
+ if($this->data['disable_serversignature']){
383
  $new_rules.="\n# WPhtC: Disable ServerSignature on generated error pages\n";
384
  $new_rules.="ServerSignature Off\n";
385
  }
386
+ if($this->data['admin_email']){
387
  $new_rules.="\n# WPhtC: Set admin email\n";
388
+ $new_rules.="SetEnv SERVER_ADMIN ".$this->data['admin_email']."\n\n";
389
  }
390
+ if($this->data['disable_indexes']){
391
  $new_rules.="\n# WPhtC: Disable directory browsing\n";
392
  $new_rules.="Options All -Indexes\n";
393
  }
394
+ if($this->data['up_limit']){
395
+ $new_rules.="\n# WPhtC: Limit upload size to ".$this->data['up_limit']." MB\n";
396
+ $new_rules.="LimitRequestBody ".($this->data['up_limit']*1024*1024)." \n";
397
  }
398
+ if($this->data['redirect_500']){
399
  $new_rules.="\n# WPhtC: Setting 500 Error page\n";
400
+ $new_rules.="ErrorDocument 500 ".$this->data['redirect_500']."\n";
401
  }
402
+ if($this->data['redirect_403']){
403
  $new_rules.="\n# WPhtC: Setting 403 Error page\n";
404
+ $new_rules.="ErrorDocument 403 ".$this->data['redirect_403']."\n";
405
  }
406
+ if($this->data['protect_wp_config']){
407
  $new_rules.="\n# WPhtC: Protect WP-config.php\n";
408
  $new_rules.="<files wp-config.php>\n";
409
  $new_rules.="order allow,deny\n";
410
  $new_rules.="deny from all\n";
411
  $new_rules.="</files>\n";
412
  }
413
+ if($this->data['protect_htaccess']){
414
  $new_rules.="\n# WPhtC: Protect .htaccess file\n";
415
  $new_rules.="<files ~ \"^.*\.([Hh][Tt][Aa])\">\n";
416
  $new_rules.="order allow,deny\n";
417
  $new_rules.="deny from all\n";
418
  $new_rules.="</files>\n";
419
  }
420
+ if($this->data['protect_comments']){
421
  $new_rules.="\n# WPhtC: Protect comments.php\n";
422
  $new_rules.="RewriteCond %{REQUEST_METHOD} POST\n";
423
  $new_rules.="RewriteCond %{REQUEST_URI} .wp-comments-post\.php*\n";
425
  $new_rules.="RewriteCond %{HTTP_USER_AGENT} ^$\n";
426
  $new_rules.="RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]\n";
427
  }
428
+ if($this->data['disable_hotlink']){
429
  $new_rules.="\n# WPhtC: Disable image hotlinking\n";
430
  $new_rules.="<IfModule mod_rewrite.c>\n";
431
  $new_rules.="RewriteEngine on\n";
432
  $new_rules.="RewriteCond %{HTTP_REFERER} !^$\n";
433
  $new_rules.="RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?".str_ireplace(array("http://","www."),"",get_bloginfo("url"))."/.*$ [NC]\n";
434
+ $new_rules.="RewriteRule \.(jpg|jpeg|png|gif)$ ".$this->data['disable_hotlink']." [NC,R,L]\n";
435
  $new_rules.="</IfModule>\n";
436
  }
437
+ if($this->data['disable_file_hotlink_ext']){
438
+ $redir = $this->data['disable_file_hotlink_redir'] ? $this->data['disable_file_hotlink_redir'] : "_";
439
  $new_rules.="\n# WPhtC: Disable file hotlinking\n";
440
  $new_rules.="<IfModule mod_rewrite.c>\n";
441
  $new_rules.="RewriteEngine on\n";
442
  $new_rules.="RewriteCond %{HTTP_REFERER} !^$\n";
443
  $new_rules.="RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?".str_ireplace(array("http://","www."),"",get_bloginfo("url"))."/.*$ [NC]\n";
444
+ $new_rules.="RewriteRule \.(".str_replace(" ","|",$this->data['disable_file_hotlink_ext']).")$ ".$redir." [NC,R,L]\n";
445
  $new_rules.="</IfModule>\n";
446
  }
447
+ if($this->data['canon']){
448
  $url=str_ireplace(array("http://","www."),"",get_bloginfo("url"));
449
  $domain=explode("/",$url);
450
  $escaped_domain=str_ireplace(".","\.",$domain[0]);
451
+ if($this->data['canon']=='www'){
452
  $siteurl=get_option('siteurl');
453
  if (!preg_match('/^http:\/\/www\./', $siteurl)) {
454
  $siteurl=str_replace("http://","http://www.",$siteurl);
460
  update_option('home',$homeurl);
461
  }
462
  }
463
+ else if($this->data['canon']=='simple'){
464
  $siteurl=get_option('siteurl');
465
  if (preg_match('/^http:\/\/www\./', $siteurl)) {
466
  $siteurl=str_replace("http://www.","http://",$siteurl);
473
  }
474
  }
475
  }
476
+ if($this->data['gzip']){
477
  $new_rules.="\n# WPhtC: Setting mod_gzip\n";
478
  $new_rules.="<ifModule mod_gzip.c>\n";
479
  $new_rules.="mod_gzip_on Yes\n";
486
  $new_rules.="mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*\n";
487
  $new_rules.="</ifModule>\n";
488
  }
489
+ if($this->data['deflate']){
490
  $new_rules.="\n# WPhtC: Setting mod_deflate\n";
491
  $new_rules.="<IfModule mod_deflate.c>\n";
492
  $new_rules.="AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript\n";
496
  $new_rules.="Header append Vary User-Agent env=!dont-vary\n";
497
  $new_rules.="</IfModule>\n";
498
  }
499
+ if($this->data['wp_hta']&&trim($this->data['wp_hta'])!=''){
500
+ $new_rules.="\n".$this->data['wp_hta'];
501
  }
502
  else{
503
  $new_rules.="\n".$rules;
509
  function filter_term_link($termlink, $term, $taxonomy){
510
  $txs=get_taxonomies(array('name'=>$taxonomy),"object");
511
  foreach($txs as $t){
512
+ //return str_replace($t->rewrite['slug']."/","",$termlink);
513
+ if($term->parent!=0){
514
+ return get_bloginfo('home')."/".$this->term_ancestors($taxonomy,$term->parent).$term->rewrite['slug'];
515
+ }
516
+ else{
517
+ return get_bloginfo('home')."/".$term->rewrite['slug'];
518
+ }
519
  }
520
  }
521
 
522
  # Filter Taxonomy Base
523
  function remove_taxonomy_base_from_rewrite_rules($rules){
524
+ # Let's remove every taxonomy rule here, we'll reacreate them at filter_rewrite_rules()
525
  return array();
526
  //return $rules;
527
  }
528
 
529
  # Filter Author Rewrite Rules
530
  function remove_author_base_from_rewrite_rules($author_rewrite) {
531
+
532
+ if($this->data['remove_author_base']){
533
  $author_rewrite=array();
534
  $blogusers = get_users('who=authors');
535
  foreach($blogusers as $user) {
541
  return $author_rewrite;
542
  }
543
  # WP-htaccess Control options page interface
544
+ function page(){
545
  include (dirname (__FILE__).'/wp-htaccess-control-ui.php');
546
  }
547
  # Adding our options page to the admin menu
548
  function configure_menu(){
549
  if(current_user_can("administrator")){
550
+ $page=add_submenu_page("options-general.php","WP htaccess Control", "htaccess Control", 6, __FILE__, array('WPhtc','page'));
551
+ add_action('admin_print_scripts-'.$page, array('WPhtc','page_script'));
552
+ add_action('admin_print_styles-'.$page, array('WPhtc','page_style'));
553
  }
554
  }
555
  # Enqueue Ui Scripts on Plugin page
556
+ function page_script(){
557
  wp_enqueue_script("htaccess-control-js", WP_PLUGIN_URL . '/wp-htaccess-control/wp-htaccess-control-ui.js');
558
  }
559
  # Enqueue Ui Scripts on Plugin page
560
+ function page_style(){
561
  wp_enqueue_style("htaccess-control-css", WP_PLUGIN_URL . '/wp-htaccess-control/wp-htaccess-control-ui.css');
562
  }
563
 
570
  }
571
 
572
  # Options Page Actions
573
+ function page_action(){
574
+ $this->check_first_run();
575
  $action=$_REQUEST['action'];
576
  global $echo;
577
  if(isset($action)){
578
+
579
  switch($action){
580
  # Hide donation message for one month
581
  case 'hide_donation_message':
582
+ $this->data['donation_hidden_time']=time()+ 90 * 24 * 60 * 60;
583
+ update_option('WPhtc_data',$this->data);
584
  break;
585
  # if reseting everything just delete the option array
586
  case 'reset_rules':
595
  # if updating, save new rules in database and flush rewrite rules
596
  case 'update':
597
  # first donation hidding time 'now'
598
+ if(!$this->data['donation_hidden_time']){
599
+ $this->data['donation_hidden_time']=time();
600
  }
601
  # nonce
602
  if(!check_admin_referer( 'WPhtc_settings')){
603
  die("You have no permission to do this.");
604
  }
605
  # get Custom Htaccess
606
+ $this->data['hta']=$_POST['WPhtc_hta'];
607
  # get Custom Author Permalink
608
+ $this->data['cap']=$_POST['WPhtc_cap'];
609
  # get Custom Pagination Permalink
610
+ $this->data['cpp']=$_POST['WPhtc_cpp'];
611
  # get Custom Search Permalink
612
+ $this->data['custom_search_permalink']=$_POST['WPhtc_custom_search_permalink'];
613
  # wordpress htaccess and jim morgan's htaccess
614
+ $this->data['wp_hta']=$_POST['WPhtc_wp_hta']."\n";
615
+ $this->data['jim_morgan_hta']=$_POST['WPhtc_jim_morgan_hta'];
616
+ if($this->data['jim_morgan_hta']){
617
+ $this->data['wp_hta'] ="\nRewriteEngine on\n";
618
+ $this->data['wp_hta'].="# Unless you have set a different RewriteBase preceding this point,\n";
619
+ $this->data['wp_hta'].="# you may delete or comment-out the following RewriteBase directive:\n";
620
+ $this->data['wp_hta'].="RewriteBase /\n";
621
+ $this->data['wp_hta'].="# if this request is for \"/\" or has already been rewritten to WP\n";
622
+ $this->data['wp_hta'].="RewriteCond $1 ^(index\.php)?$ [OR]\n";
623
+ $this->data['wp_hta'].="# or if request is for image, css, or js file\n";
624
+ $this->data['wp_hta'].="RewriteCond $1 \.(gif|jpg|jpeg|png|css|js|ico)$ [NC,OR]\n";
625
+ $this->data['wp_hta'].="# or if URL resolves to existing file\n";
626
+ $this->data['wp_hta'].="RewriteCond %{REQUEST_FILENAME} -f [OR]\n";
627
+ $this->data['wp_hta'].="# or if URL resolves to existing directory\n";
628
+ $this->data['wp_hta'].="RewriteCond %{REQUEST_FILENAME} -d\n";
629
+ $this->data['wp_hta'].="# then skip the rewrite to WP\n";
630
+ $this->data['wp_hta'].="RewriteRule ^(.*)$ - [S=1]\n";
631
+ $this->data['wp_hta'].="# else rewrite the request to WP\n";
632
+ $this->data['wp_hta'].="RewriteRule . /index.php [L]\n";
633
  }
634
  # Remove Author Base
635
+ $this->data['remove_author_base']=$_POST['WPhtc_remove_author_base'];
636
  # Advanced Archives
637
+ $this->data['category_archives']=$_POST['WPhtc_category_archives'];
638
+ $this->data['author_archives']=$_POST['WPhtc_author_archives'];
639
+ $this->data['tag_archives']=$_POST['WPhtc_tag_archives'];
640
  # get htaccess Suggestions
641
+ $this->data['disable_serversignature']=$_POST['WPhtc_disable_serversignature'];
642
+ $this->data['disable_indexes']=$_POST['WPhtc_disable_indexes'];
643
+ $this->data['up_limit']=(is_numeric($_POST['WPhtc_up_limit'])&&$_POST['WPhtc_up_limit']>0)?$_POST['WPhtc_up_limit']:'';
644
+ $this->data['protect_wp_config']=$_POST['WPhtc_protect_wp_config'];
645
+ $this->data['protect_htaccess']=$_POST['WPhtc_protect_htaccess'];
646
+ $this->data['protect_comments']=$_POST['WPhtc_protect_comments'];
647
+ $this->data['disable_hotlink']=trim($_POST['WPhtc_disable_hotlink']);
648
+ $this->data['disable_file_hotlink_ext']=trim($_POST['WPhtc_disable_file_hotlink_ext']);
649
+ $this->data['disable_file_hotlink_redir']=trim($_POST['WPhtc_disable_file_hotlink_redir']);
650
+ $this->data['redirect_500']=trim($_POST['WPhtc_redirect_500']);
651
+ $this->data['redirect_403']=trim($_POST['WPhtc_redirect_403']);
652
+ $this->data['canon']=$_POST['WPhtc_canon'];
653
+ $this->data['admin_email']=trim($_POST['WPhtc_admin_email']);
654
+ $this->data['deflate']=trim($_POST['WPhtc_deflate']);
655
+ $this->data['gzip']=trim($_POST['WPhtc_gzip']);
656
  # get maintenance
657
+ $this->data['maintenance_active']=$_POST['WPhtc_maintenance_active'];
658
  $lines=preg_split("/\n|,/",$_POST['WPhtc_maintenance_ips']);
659
+ $this->data['maintenance_ips']=array();
660
  foreach($lines as $line){
661
  trim($line);
662
  if(preg_match("/[a-z,0-9,\.]/",$line)){
663
+ $this->data['maintenance_ips'][]=$line;
664
  }
665
  }
666
+ $this->data['maintenance_redirection']=trim($_POST['WPhtc_maintenance_redirection']);
667
  # get login control data
668
+ $this->data['login_disabled']=$_POST['WPhtc_login_disabled'];
669
+ $this->data['login_half_mode']=$_POST['WPhtc_login_half_mode'];
670
+ $this->data['login_redirection']=trim($_POST['WPhtc_login_redirection']);
671
  $lines=preg_split("/\n|,/",$_POST['WPhtc_login_ips']);
672
+ $this->data['login_ips']=array();
673
  foreach($lines as $line){
674
  trim($line);
675
  if(preg_match("/[a-z,0-9,\.]/",$line)){
676
+ $this->data['login_ips'][]=$line;
677
  }
678
  }
679
 
680
  # Unsetting inclusion of Author pages on Google XML Sitemap options, we'll add those links to the sitemap later with our Custom Author Permalink
681
+ $this->data['sm_enabled']=$_POST['WPhtc_sm_enabled'];
682
+ if($this->data['sm_enabled']==true){
683
  $SMoptions=get_option("sm_options");
684
  if($SMoptions&&is_array($SMoptions)){
685
  $SMoptions=get_option("sm_options");
691
  }
692
 
693
  # Taxonomy Base removal options
694
+ unset($this->data['remove_taxonomy_base']);
695
  if($_POST['WPhtc_remove_base']){
696
  foreach($_POST['WPhtc_remove_base'] as $tax_key=>$remove){
697
+ $this->data['remove_taxonomy_base'][$tax_key]=$remove;
698
  }
699
  }
700
 
701
  # Advanced archives
702
+ unset($this->data['create_archive']);
703
  if($_POST['WPhtc_create_archive']){
704
  foreach($_POST['WPhtc_create_archive'] as $tax_key=>$create_archive){
705
+ $this->data['create_archive'][$tax_key]=$create_archive;
706
  }
707
  }
708
 
709
  # Update WP htaccess Control options
710
+ update_option('WPhtc_data',$this->data);
711
  # Flush Rewrite Rules
712
  $this->refresh_rewrite_rules();
713
  $echo.=__('All options updated.', 'wp-htaccess-control');
721
  $WPhtc = new WPhtc();
722
  }
723
  if (isset($WPhtc)) {
724
+
725
+ add_action('init', array($WPhtc,'init'));
726
+ add_filter('mod_rewrite_rules', array($WPhtc,'hta_rules'));
727
+ add_filter('redirect_canonical',array($WPhtc,'filter_redirect_canonical'),10,10);
 
 
 
 
728
  add_action('admin_menu', array($WPhtc,'configure_menu'));
729
+ add_action('flush_event',array($WPhtc,'refresh_rewrite_rules'));
730
+ add_filter('generate_rewrite_rules', array($WPhtc,'wp_rewrite_rules'));
731
+ add_filter('rewrite_rules_array',array($WPhtc,'filter_rewrite_rules'));
732
+
733
+ // AUTHOR improve this
734
+ if($WPhtc->data['cap']!='' || $WPhtc->data['remove_author_base']){
735
+ add_filter('author_link',array($WPhtc,'filter_author_link'));
736
+ add_filter('author_rewrite_rules', array($WPhtc,'remove_author_base_from_rewrite_rules'));
737
+ }
738
+
739
+ // Filter pagination links
740
+ if($WPhtc->data['cpp']!='') add_filter('get_pagenum_link',array($WPhtc,'filter_get_pagenum_link'));
741
+
742
+ // Filter search
743
+ if(trim($WPhtc->data['custom_search_permalink'])!=''){
744
+ add_filter('search_feed_link',array($WPhtc,'search_feed_link'),10,10);
745
+ add_filter('get_search_query',array($WPhtc,'get_search_query_filter'),10,10);
746
+ add_action('template_redirect', array($WPhtc,'search_template_redirect') );
747
+ }
748
+
749
+
750
  add_action('sm_buildmap',array($WPhtc,'set_sm'));
 
 
 
 
751
 
752
  /* Taxonomy Base Removal*/
753
+ if($WPhtc->data['remove_taxonomy_base']){
754
+ add_filter('term_link',array($WPhtc,'filter_term_link'),10,3);
755
+ foreach($WPhtc->data['remove_taxonomy_base'] as $tax=>$v){
756
  if($v) {
757
  add_filter($tax.'_rewrite_rules', array($WPhtc,'remove_taxonomy_base_from_rewrite_rules'));
758
  add_filter($tax."_row_actions",array($WPhtc,'filter_tax_table_actions'), 10,2 );
759
  }
760
  }
761
  }
762
+ /* Term management actions*/
763
+ if($WPhtc->data['remove_taxonomy_base'] || $WPhtc->data['create_archive']){
764
+ add_action('created_term',array($WPhtc,'refresh_rewrite_rules_later'));
765
+ add_action('edited_term',array($WPhtc,'refresh_rewrite_rules_later'));
766
+ add_action('delete_term',array($WPhtc,'refresh_rewrite_rules_later'));
767
+ }
768
+
769
  /* This flush should maybe be conditional to content authors only, maybe not */
770
  add_action('user_register',array($WPhtc,'refresh_rewrite_rules_later'));
771
  add_action('delete_user',array($WPhtc,'refresh_rewrite_rules_later'));