WP htaccess Control - Version 1.4

Version Description

(12/03/2010) * Added "Suggested htaccess" features; * Improved Ui.

Download this release

Release Info

Developer andrad
Plugin Icon wp plugin WP htaccess Control
Version 1.4
Comparing to
See all releases

Code changes from version 1.3 to 1.4

gfx/action_stop.gif DELETED
Binary file
gfx/icon_alert.gif DELETED
Binary file
gfx/image_new.gif DELETED
Binary file
gfx/index.php DELETED
File without changes
gfx/readme.txt DELETED
@@ -1,2 +0,0 @@
1
- mini icons - famfamfam.com
2
- Contact: mjames@gmail.com
 
 
index.php CHANGED
@@ -1,7 +1,7 @@
1
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
  <html>
3
  <head>
4
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
5
  <style>
6
  html{background-color:#E4F2FD;}
7
  body{color:#333;font-family:Verdana;font-size:0.8em;width:600px;margin:75px auto;padding:30px;background:white;}
@@ -12,13 +12,8 @@
12
  <title>WP htaccess Control Plugin</title>
13
  </head>
14
  <body>
15
- <h1>WP htaccess Control</h1>
16
- <p><strong>Plugin Author:</strong> <a href="http://dardna.com/" title="Visit the Author">dardna</a></p>
17
- <h2>Features</h2>
18
- <ol>
19
- <li>Adding custom redirect rules to the htaccess file generated by Wordpress;</li>
20
- <li>Customizing the Author Permalink Base.</li>
21
- </ol>
22
  <h2>Links</h2>
23
  <ul>
24
  <li><a href="http://wordpress.org/extend/plugins/wp-htaccess-control/" title="Visit this Plugin at the Wordpress Plugin Directory">WP htaccess Control at the Plugin Directory</a></li>
1
  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
  <html>
3
  <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
5
  <style>
6
  html{background-color:#E4F2FD;}
7
  body{color:#333;font-family:Verdana;font-size:0.8em;width:600px;margin:75px auto;padding:30px;background:white;}
12
  <title>WP htaccess Control Plugin</title>
13
  </head>
14
  <body>
15
+ <h1><a href="http://wordpress.org/extend/plugins/wp-htaccess-control/" title="Visit this Plugin at the Wordpress Plugin Directory">WP htaccess Control</a></h1>
16
+ <p><strong>Plugin Author:</strong> <a href="http://dardna.com/" title="Visit the Author">António Andrade</a></p>
 
 
 
 
 
17
  <h2>Links</h2>
18
  <ul>
19
  <li><a href="http://wordpress.org/extend/plugins/wp-htaccess-control/" title="Visit this Plugin at the Wordpress Plugin Directory">WP htaccess Control at the Plugin Directory</a></li>
readme.txt CHANGED
@@ -1,12 +1,12 @@
1
  === WP htaccess Control ===
2
- Author: andrad
3
  Author URI: http://dardna.com/
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
  Donate link:
6
  Tags: permalinks, permalink, author, htaccess, rewrite, redirect
7
  Requires at least: 2.7
8
  Tested up to: 2.9.2
9
- Stable tag: 1.3
10
 
11
  Provides an interface to add custom htaccess rules to the htaccess file generated by Wordpress and customisation of the Author Permalink Base.
12
 
@@ -16,10 +16,19 @@ Provides an interface to add custom htaccess rules to the htaccess file generate
16
 
17
  **Features:**
18
 
19
- * Customizing htaccess file generated by Wordpress;
20
- * Customizing the Author Permalink Base.
21
 
22
- * If Google XML Sitemap is found installed, you'll be able to use your Custom Author Permalink on the sitemap generated.
 
 
 
 
 
 
 
 
 
23
 
24
  == Installation ==
25
 
@@ -32,13 +41,18 @@ Provides an interface to add custom htaccess rules to the htaccess file generate
32
  == Frequently Asked Questions ==
33
 
34
  = Do you have any questions? =
35
- = Suggestions are of course very welcome and please report any bugs found! =
36
 
37
  == Screenshots ==
38
 
39
- 1. Administration page (as of v.1.3)
40
 
41
  == Changelog ==
 
 
 
 
 
42
  = 1.3 =
43
  * Was using two fields for the custom htaccess when only one was needed, for the sake of simplicity;
44
  * Integrated the Custom Author Permalink with the Google XML Sitemap plugin.
@@ -79,6 +93,8 @@ Provides an interface to add custom htaccess rules to the htaccess file generate
79
  * Initial release (poor interface although working).
80
 
81
  == Upgrade Notice ==
 
 
82
 
83
  = 1.3 =
84
  * Integrated the Custom Author Permalink with the Google XML Sitemap plugin.
1
  === WP htaccess Control ===
2
+ Author: António Andrade
3
  Author URI: http://dardna.com/
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
  Donate link:
6
  Tags: permalinks, permalink, author, htaccess, rewrite, redirect
7
  Requires at least: 2.7
8
  Tested up to: 2.9.2
9
+ Stable tag: 1.4
10
 
11
  Provides an interface to add custom htaccess rules to the htaccess file generated by Wordpress and customisation of the Author Permalink Base.
12
 
16
 
17
  **Features:**
18
 
19
+ * Adding custom rules to the htaccess file generated by Wordpress;
20
+ * Customizing the Author Permalink Base (if Google XML Sitemap is found installed, you'll be able to use your Custom Author Permalink on the sitemap generated);
21
 
22
+ Easy to use "Suggested htaccess" rules:
23
+ * Disable directory browsing;
24
+ * Disable and redirect image hotlinking;
25
+ * Force canonical url (WWW or non-WWW);
26
+ * Limit maximum file upload size;
27
+ * Protect wp-config.php file from access;
28
+ * Protect .htaccess file from access;
29
+ * Set 500 error page;
30
+ * Set admin email on server generated error pages;
31
+ * Disable ServerSignature on server generated error pages.
32
 
33
  == Installation ==
34
 
41
  == Frequently Asked Questions ==
42
 
43
  = Do you have any questions? =
44
+ Suggestions are of course very welcome and please report any bugs found!
45
 
46
  == Screenshots ==
47
 
48
+ 1. Administration page (as of v.1.4)
49
 
50
  == Changelog ==
51
+ = 1.4 =
52
+ (12/03/2010)
53
+ * Added "Suggested htaccess" features;
54
+ * Improved Ui.
55
+
56
  = 1.3 =
57
  * Was using two fields for the custom htaccess when only one was needed, for the sake of simplicity;
58
  * Integrated the Custom Author Permalink with the Google XML Sitemap plugin.
93
  * Initial release (poor interface although working).
94
 
95
  == Upgrade Notice ==
96
+ = 1.4 =
97
+ * Features added.
98
 
99
  = 1.3 =
100
  * Integrated the Custom Author Permalink with the Google XML Sitemap plugin.
screenshot-1.jpg CHANGED
Binary file
wp-htaccess-control-ui.css ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
1
+ .wphtc-menu{margin:10px 0;}
2
+ .wphtc-section{background:#ddd;border:1px solid #ddd;border-bottom:0;margin-top:15px;-moz-border-radius:6px;-webkit-border-radius:6px;}
3
+ .wphtc-section-title{-moz-user-select: none;-khtml-user-select: none;user-select: none;margin-bottom:0;width:100%;border:0;}
4
+ .wphtc-section-title h3{margin:0;padding:10px;cursor:pointer;border-bottom:0;-moz-border-radius:6px;-webkit-border-radius:6px;}
5
+ .wphtc-section-title .handlediv {float:right;height:35px;width:23px;cursor:pointer;}
6
+ .wphtc-inputs{background:#fff;border:1px solid #ddd;border-left:0;border-right:0;-moz-border-radius:6px;-webkit-border-radius:6px;}
7
+ .wphtc-inputs th{font-weight:bold;}
8
+ .wphtc-inputs tr{border-bottom:1px solid #ddd}
9
+ .wphtc-inputs caption{text-align:left;padding:10px;background:white;}
10
+ .form-table{margin:0;}
11
+ #wphtc-footer{text-align:right;}
wp-htaccess-control-ui.js ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ jQuery(document).ready(function(){
2
+ addRewritePairButton();
3
+ collapseSections();
4
+ function addRewritePairButton(){
5
+ jQuery('.add-rewrite-pair').click(function(){addRule();});
6
+ }
7
+ function addRule(){
8
+ num=parseInt(jQuery("#WPhtc_num").val());
9
+ if(!jQuery('.add-rewrite-pair').hasClass('doing')){
10
+ jQuery('.add-rewrite-pair').addClass('doing');
11
+ lastrule=jQuery("#htaccess-rules tr:last").attr('id').split('-');
12
+ newrule=parseInt(lastrule[1])+1;
13
+ jQuery("#htaccess-rules tr:last").clone().attr('id','rule-'+newrule).hide().insertAfter("#htaccess-rules tr:last").fadeIn('slow',
14
+ function(){
15
+ jQuery('.add-rewrite-pair').removeClass('doing');
16
+ }
17
+ )
18
+ .css({display: ""});
19
+ jQuery("#rule-"+newrule+" input:first").val('').attr('name','WPhtc_pat'+newrule);
20
+ jQuery("#rule-"+newrule+" input:last").val('').attr('name','WPhtc_sub'+newrule);
21
+ jQuery("#rule-"+newrule+" td:last").empty();
22
+ jQuery("#WPhtc_num").val(num+1);
23
+ }
24
+ }
25
+ function collapseSections(){
26
+ jQuery(".wphtc-inputs,.wphtc-section-title a").not(".wphtc-inputs:last").hide();
27
+ jQuery(".wphtc-menu").fadeOut(0);
28
+ jQuery(".handlediv").fadeOut(0);
29
+ jQuery(".wphtc-section").hover(
30
+ function(){
31
+ jQuery(this).find(".handlediv").fadeIn(150);
32
+ },
33
+ function(){
34
+ jQuery(this).find(".handlediv").fadeOut(150);
35
+ }
36
+ )
37
+ jQuery(".wphtc-section-title h3").click(
38
+ function(){
39
+ if(jQuery(this).parent().find("a")){
40
+ jQuery(this).parent().find("a").toggle();
41
+ }
42
+ jQuery(this).parent().next(".wphtc-inputs").toggle();
43
+ if(jQuery(".wphtc-inputs:visible").length<2){
44
+ jQuery(".wphtc-menu").fadeOut(250);
45
+ }
46
+ else{
47
+ jQuery(".wphtc-menu").fadeIn(250);
48
+ }
49
+ }
50
+ );
51
+ }
52
+ });
wp-htaccess-control-ui.php CHANGED
@@ -7,116 +7,179 @@ WPhtc::wphtc_page_action();
7
  global $echo;
8
  $WPhtc_data=get_option('WPhtc_data');
9
  ?>
10
- <script type="text/javascript">
11
- jQuery(document).ready(function(){
12
- init();
13
- function init(){
14
- addButton();
15
- }
16
- function addButton(){
17
- jQuery('.wphtc-menu .add').attr('href','#addRule').click(function(){addRule();});
18
- }
19
- function addRule(){
20
- num=parseInt(jQuery("#WPhtc_num").val());
21
- if(!jQuery('.wphtc-menu .add').hasClass('doing')){
22
- jQuery('.wphtc-menu .add').addClass('doing');
23
- lastrule=jQuery("#htaccess-rules tr:last").attr('id').split('-');
24
- newrule=parseInt(lastrule[1])+1;
25
- jQuery("#htaccess-rules tr:last").clone().attr('id','rule-'+newrule).hide().insertAfter("#htaccess-rules tr:last").fadeIn('slow',function(){jQuery('.wphtc-menu .add').removeClass('doing');}).css({display: ""});
26
- jQuery("#rule-"+newrule+" input:first").val('').attr('name','WPhtc_pat'+newrule);
27
- jQuery("#rule-"+newrule+" input:last").val('').attr('name','WPhtc_sub'+newrule);
28
- jQuery("#rule-"+newrule+" td:last").empty();
29
- jQuery("#WPhtc_num").val(num+1);
30
- }
31
- }
32
- });
33
- </script>
34
- <style type="text/css">
35
- h2,h3,.wphtc-menu {float:left;}
36
- h3{clear:left;}
37
- span.description{display:block}
38
- .wphtc-menu {margin:1em;}
39
- .wphtc-menu li{display:inline;margin-right:20px;}
40
- .wphtc-menu img{position:relative;top:2px;}
41
- #wphtc-menu{margin-top:2em;}
42
- #htaccess-rules img{position:relative;top:4px;}
43
- #htaccess-rules a, .wphtc-menu a{text-decoration:none;}
44
- p.alignright{padding-right:20px;}
45
- p,.updated{clear:both;}
46
- </style>
47
- <div class="wrap">
48
  <h2>Wp htaccess Control</h2>
49
- <ul id="wphtc-menu" class="wphtc-menu">
50
- <li><a href="<?php echo $purl?>&action=reset_rules"><img src="<?php echo $plugin_url?>/gfx/icon_alert.gif"> Reset all rules</a></li>
51
- </ul>
52
- <?php if($echo!=''){?>
53
- <div class="updated fade" id="message" style="background-color: rgb(255, 251, 204);"><p><?php echo $echo;?></p></div>
54
- <?php }?>
55
  <form method="post" action="<?php echo $purl?>">
56
- <h3>Custom Author Permalink</h3>
57
- <table class="form-table">
58
- <tr valign="top">
59
- <th scope="row"><label for="blogdescription">Author Base</label></th>
60
- <td>
61
- <input type="text" name="WPhtc_cap" value="<?php echo $WPhtc_data['cap']; ?>" /> <code><?php bloginfo('home')?>/<em>(your-base)</em>/admin</code><br/>
62
- <span class="description">Permalink settings must be set and not Default (/?p=123).</span>
63
- <span class="description">If set, the author base will be used as shown next to the form field.</span>
64
- <span class="description">If you do not want to use a custom Author Permalink base just leave the field empty.</span>
65
- </td>
66
- </tr>
67
- <?php if(class_exists('GoogleSitemapGeneratorLoader')){?>
68
- <tr>
69
- <th>Google XML Sitemap</th>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  <td>
71
- <input type="checkbox" name="WPhtc_sm_enabled" value="1" <?php if($WPhtc_data['sm_enabled']==1){ echo "checked";}?>/> Apply Custom Author Permalink on Generated Sitemap
72
- <span class="description">Leave "Include author pages" unchecked on Google XML Sitemap options page if using this.</span>
73
- <span class="description">However, if you want to adjust the "Priority" or "Change frequency" you should do so on the <a href="options-general.php?page=google-sitemap-generator/sitemap.php">Google XML Sitemap options page</a>.</span>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  </td>
 
75
  </tr>
76
- <?php } ?>
77
- </table>
78
- <h3>Custom htaccess</h3>
79
- <table id="" class="form-table">
80
- <tr>
81
- <td>
82
- <textarea name="WPhtc_hta" cols="70" rows="5"><?php
83
- echo $WPhtc_data['hta'];
84
- if($WPhtc_data['hta_mr']!=""){
85
- echo "\n<IfModule mod_rewrite.c>\nRewriteEngine On\n".$WPhtc_data['hta_mr']."\n</IfModule>";
86
- }?></textarea>
87
- <p class="description">This rules will be printed before any Wordpress rules.</p>
88
- <p class="description">Please double check them before saving as a mistake could make your site unaccessable.</p>
89
- <p class="description">In any case you can always edit your .htaccess file manually.</p>
90
- <p class="description">In case of doubt as where this rules will be kept save a comment line (like #test) and check the end of this page.</p>
91
- </td>
92
- </tr>
93
- </table>
94
- <h3>Rewrite Pairs</h3>
95
- <ul class="wphtc-menu">
96
- <li><a class="add" href="<?php echo $purl?>&action=add_rule" title="Add new htaccess redirection pair"><img src="<?php echo $plugin_url?>/gfx/image_new.gif"> Add rule</a></li>
97
- </ul>
98
- <p class="description">These are rewrite pairs (RewriteRule) which Wordpress can add to its rules.</p>
99
- <table id="htaccess-rules" class="form-table">
100
- <?php
101
- $num=count($WPhtc_data['pats'])?count($WPhtc_data['pats']):1;
102
- if($add_rule){$num++;};
103
- for($i=0;$i<$num;$i++){?>
104
- <tr id="rule-<?php echo $i;?>" valign="top">
105
- <td><input type="text" style="width:100%" name="WPhtc_pat<?php echo $i;?>" value="<?php echo $WPhtc_data['pats'][$i]; ?>" /></td>
106
- <td><input type="text" style="width:100%" name="WPhtc_sub<?php echo $i;?>" value="<?php echo $WPhtc_data['subs'][$i]; ?>" /></td>
107
- <td><a href="<?php echo $purl ?>&action=delete_pair&pair=<?php echo $i?>"><img src="<?php echo $plugin_url?>/gfx/action_stop.gif"> Delete Pair</a></td>
 
 
 
 
 
 
 
 
 
 
 
 
 
108
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  <?php } ?>
110
- </table>
 
111
  <input type="hidden" name="action" value="update" />
112
  <input id="WPhtc_num" type="hidden" name="WPhtc_num" value="<?php echo $num;?>" />
113
- <p class="submit">
114
- <input type="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
115
- </p>
 
116
  </form>
117
- <h3>Current htaccess file as it is generated by Wordpress</h3>
118
- <p>
119
- <code><?php echo str_replace(array("&lt;br /&gt;","&lt;br/&gt;"),"<br/>",htmlspecialchars($WPhtc_data['cur_hta']));?></code>
120
- </p>
121
- </div>
122
- <p class="setting-description alignright"><small><a href="http://dardna.com/wp-htaccess-control" title="Visit WP htaccess Control page at dardna.com">WP htaccess Control</a> by <a href="http://dardna.com" title="Visit dardna.com">dardna</a>, thanks to <a href="http://www.famfamfam.com/lab/icons/mini/" title="Visit 'Mini iconset' page at FamFamFam.com">FamFamFam</a> for the icons.</small></p>
 
 
 
 
 
 
 
7
  global $echo;
8
  $WPhtc_data=get_option('WPhtc_data');
9
  ?>
10
+ <div id="wphtc-page" class="wrap">
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  <h2>Wp htaccess Control</h2>
 
 
 
 
 
 
12
  <form method="post" action="<?php echo $purl?>">
13
+ <?php if($echo!=''){?>
14
+ <div class="updated fade" id="message" style="background-color: rgb(255, 251, 204);"><p><?php echo $echo;?></p></div>
15
+ <?php }?>
16
+ <div class="wphtc-section">
17
+ <div class="wphtc-section-title stuffbox">
18
+ <div title="Click to toggle" class="handlediv" style="background:url('<?php bloginfo("wpurl")?>/wp-admin/images/menu-bits.gif') no-repeat scroll left -111px transparent"><br></div>
19
+ <h3>Custom Author Permalink</h3>
20
+ </div>
21
+ <table class="form-table wphtc-inputs">
22
+ <tr valign="top">
23
+ <th scope="row" style="width:18%;">Author Base</th>
24
+ <td >
25
+ <input type="text" name="WPhtc_cap" value="<?php echo $WPhtc_data['cap']; ?>" />
26
+ <p><code><?php bloginfo('home')?>/<em>(your-base)</em>/admin</code></p>
27
+ </td>
28
+ <td valign="middle">
29
+ <p class="description">Permalink settings must be set and not Default (/?p=123).</p>
30
+ <p class="description">If set, the author base will be used as shown next to the form field.</p>
31
+ <p class="description">If you do not want to use a custom Author Permalink base just leave the field empty.</p>
32
+ </td>
33
+ </tr>
34
+ <?php if(class_exists('GoogleSitemapGeneratorLoader')){?>
35
+ <tr valign="top">
36
+ <th>Google XML Sitemap</th>
37
+ <td>
38
+ <input type="checkbox" name="WPhtc_sm_enabled" value="true" <?php if($WPhtc_data['sm_enabled']){ echo "checked";}?>/> Apply Custom Author Permalink on Generated Sitemap
39
+ </td>
40
+ <td valign="middle" >
41
+ <p class="description">Leave "Include author pages" unchecked on Google XML Sitemap options page if using this.</p>
42
+ <p class="description">However, if you want to adjust the "Priority" or "Change frequency" you should do so on the <a href="options-general.php?page=google-sitemap-generator/sitemap.php">Google XML Sitemap options page</a>.</p>
43
+ </td>
44
+ </tr>
45
+ <?php } ?>
46
+ </table>
47
+ </div>
48
+ <div class="wphtc-section">
49
+ <div class="wphtc-section-title stuffbox">
50
+ <div title="Click to toggle" class="handlediv" style="background:url('<?php bloginfo("wpurl")?>/wp-admin/images/menu-bits.gif') no-repeat scroll left -111px transparent"><br></div>
51
+ <h3>Custom htaccess</h3>
52
+ </div>
53
+ <table class="form-table wphtc-inputs">
54
+ <tr valign="top">
55
  <td>
56
+ <textarea name="WPhtc_hta" style="width:100%;" rows="5"><?php
57
+ echo $WPhtc_data['hta'];
58
+ if($WPhtc_data['hta_mr']!=""){
59
+ echo "\n<IfModule mod_rewrite.c>\nRewriteEngine On\n".$WPhtc_data['hta_mr']."\n</IfModule>";
60
+ }?></textarea>
61
+ </td>
62
+ <td style="width:50%;">
63
+ <p class="description">This rules will be printed before any Wordpress rules.</p>
64
+ <p class="description">Please double check them before saving as a mistake could make your site unaccessable.</p>
65
+ </td>
66
+ </tr>
67
+ </table>
68
+ </div>
69
+ <div class="wphtc-section">
70
+ <div class="wphtc-section-title stuffbox">
71
+ <div title="Click to toggle" class="handlediv" style="background:url('<?php bloginfo("wpurl")?>/wp-admin/images/menu-bits.gif') no-repeat scroll left -111px transparent"><br></div>
72
+ <h3>htaccess Suggestions</h3>
73
+ </div>
74
+ <table class="form-table wphtc-inputs">
75
+ <tr valign="top">
76
+ <th scope="row" style="width:18%;">ServerSignature</th>
77
+ <td style="width:3%;" valign="middle">
78
+ <input type="checkbox" name="WPhtc_disable_serversignature" value="true" <?php if($WPhtc_data['disable_serversignature']){ echo "checked";}?>/>
79
+ </td>
80
+ <td valign="middle">Disable the ServerSignature on server generated error pages.</td>
81
+ </tr>
82
+ <tr valign="top">
83
+ <th scope="row">Indexes</th>
84
+ <td style="width:3%;" valign="middle">
85
+ <input type="checkbox" name="WPhtc_disable_indexes" value="true" <?php if($WPhtc_data['disable_indexes']){ echo "checked";}?>/>
86
+ </td>
87
+ <td valign="middle">Disable directory browsing.</td>
88
+ </tr>
89
+ <tr valign="top">
90
+ <th scope="row">Protect wp-config.php file</th>
91
+ <td style="width:3%;" valign="middle">
92
+ <input type="checkbox" name="WPhtc_protect_wp_config" value="true" <?php if($WPhtc_data['protect_wp_config']){ echo "checked";}?>/>
93
  </td>
94
+ <td valign="middle">Deny access to wp-config.php file.</td>
95
  </tr>
96
+ <tr valign="top">
97
+ <th scope="row">Protect htaccess file</th>
98
+ <td style="width:3%;" valign="middle">
99
+ <input type="checkbox" name="WPhtc_protect_htaccess" value="true" <?php if($WPhtc_data['protect_htaccess']){ echo "checked";}?>/>
100
+ </td>
101
+ <td valign="middle">Deny access to .htaccess file.</td>
102
+ </tr>
103
+ <tr valign="top">
104
+ <th scope="row">Limit Upload Size</th>
105
+ <td style="width:3%;" valign="middle">
106
+ <input type="text" name="WPhtc_up_limit" value="<?php echo $WPhtc_data['up_limit']?>"/>
107
+ </td>
108
+ <td valign="middle">If set, this value in MB will be used as limit to file uploads.</td>
109
+ </tr>
110
+ <tr valign="top">
111
+ <th scope="row">Admin Email</th>
112
+ <td style="width:3%;">
113
+ <input type="text" name="WPhtc_admin_email" value="<?php echo $WPhtc_data['admin_email']?>"/>
114
+ </td>
115
+ <td valign="middle">If set, this will be used as the admin email on server generated error pages.</td>
116
+ </tr>
117
+ <tr valign="top">
118
+ <th scope="row">Disable hotlinking</th>
119
+ <td style="width:3%;">
120
+ <input type="text" name="WPhtc_disable_hotlink" value="<?php echo $WPhtc_data['disable_hotlink']?>"/>
121
+ </td>
122
+ <td valign="middle">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 "-".</td>
123
+ </tr>
124
+ <tr valign="top">
125
+ <th scope="row">500 error</th>
126
+ <td style="width:3%;" valign="middle">
127
+ <input type="text" name="WPhtc_redirect_500" value="<?php echo $WPhtc_data['redirect_500']?>"/>
128
+ </td>
129
+ <td valign="middle">If set, this path will be used as page to 500 errors (example: /error.php).</td>
130
+ </tr>
131
+ <tr valign="top">
132
+ <th scope="row" valign="middle">Canonical Url</th>
133
+ <td style="width:3%;" valign="middle">
134
+ <select name="WPhtc_canon">
135
+ <option value=""></option>
136
+ <option value="www" <?php if($WPhtc_data['canon']=='www'){echo "selected";} ?>>Force WWW</option>
137
+ <option value="simple" <?php if($WPhtc_data['canon']=='simple'){echo "selected";} ?>>Force non-WWW</option>
138
+ </select>
139
+ </td>
140
+ <td valign="middle">This will force canonization.</td>
141
  </tr>
142
+ </table>
143
+ </div>
144
+ <div class="wphtc-section">
145
+ <div class="wphtc-section-title stuffbox">
146
+ <div title="Click to toggle" class="handlediv" style="background:url('<?php bloginfo("wpurl")?>/wp-admin/images/menu-bits.gif') no-repeat scroll left -111px transparent"><br></div>
147
+ <h3>Rewrite Pairs</h3>
148
+
149
+ </div>
150
+ <table id="htaccess-rules" class="form-table wphtc-inputs">
151
+ <caption>
152
+ <a class="add-rewrite-pair button-secondary" href="#AddRewritePair" title="Add new htaccess redirection pair">Add rule</a>
153
+ <span class="description">These are rewrite pairs (RewriteRule) which Wordpress can add inside its rules.</span>
154
+ </caption>
155
+ <?php
156
+ $num=count($WPhtc_data['pats'])?count($WPhtc_data['pats']):1;
157
+ for($i=0;$i<$num;$i++){?>
158
+ <tr id="rule-<?php echo $i;?>" valign="top">
159
+ <td style="width:45%"><input type="text" style="width:100%" name="WPhtc_pat<?php echo $i;?>" value="<?php echo $WPhtc_data['pats'][$i]; ?>" /></td>
160
+ <td style="width:45%"><input type="text" style="width:100%" name="WPhtc_sub<?php echo $i;?>" value="<?php echo $WPhtc_data['subs'][$i]; ?>" /></td>
161
+ <td style="width:10%;" valign="middle"><a class="button-secondary" href="<?php echo $purl ?>&action=delete_pair&pair=<?php echo $i?>">Delete Pair</a></td>
162
+ </tr>
163
  <?php } ?>
164
+ </table>
165
+ </div>
166
  <input type="hidden" name="action" value="update" />
167
  <input id="WPhtc_num" type="hidden" name="WPhtc_num" value="<?php echo $num;?>" />
168
+ <div class="wphtc-menu">
169
+ <a class="button-secondary" href="<?php echo $purl?>&action=reset_rules">Reset all rules</a>
170
+ <input type="submit" class="button-primary" value="Save all changes" />
171
+ </div>
172
  </form>
173
+ <div class="wphtc-section">
174
+ <div class="wphtc-section-title stuffbox">
175
+ <div title="Click to toggle" class="handlediv" style="background:url('<?php bloginfo("wpurl")?>/wp-admin/images/menu-bits.gif') no-repeat scroll left -111px transparent"><br></div>
176
+ <h3>Current htaccess file as it is generated by Wordpress</h3>
177
+ </div>
178
+ <div class="wphtc-inputs">
179
+ <p style="margin-left:10px;">
180
+ <code><?php echo str_replace(array("&lt;br /&gt;","&lt;br/&gt;"),"<br/>",htmlspecialchars($WPhtc_data['cur_hta']));?></code>
181
+ </p>
182
+ </div>
183
+ </div>
184
+ <p id="wphtc-footer"><small><a href="http://dardna.com/wp-htaccess-control" title="Visit WP htaccess Control page at dardna.com">WP htaccess Control</a> by <a href="http://dardna.com" title="Visit dardna.com">António Andrade</a>.</p>
185
+ </div>
wp-htaccess-control.php CHANGED
@@ -3,8 +3,8 @@
3
  Plugin Name: WP htaccess Control
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
  Description: Provides an interface to add custom htaccess rules to the htaccess file generated by wordpress. Also provides customisation of the Author Permalink Base.
6
- Version: 1.3
7
- Author: dardna
8
  Author URI: http://dardna.com
9
  */
10
  /* Copyright 2010 António Andrade (email : dardna@dardna.com)
@@ -86,14 +86,80 @@ if (!class_exists("WPhtc")) {
86
  # Adding Custom Rules to htaccess file generated by Wordpress, everytime the rules are flush
87
  function wphtc_hta_rules($rules){
88
  $WPhtc_data=get_option('WPhtc_data');
89
- if($WPhtc_data['hta']!=''){
90
- $new_rules.="\n# Begin Custom htaccess from WP htaccess Control\n";
91
  $new_rules.=$WPhtc_data['hta']."\n";
92
- $new_rules.="# End Custom htaccess from WP htaccess Control\n\n";
93
  }
94
- // DEPRECATE LATER
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  if($WPhtc_data['hta_mr']!=''){
96
- $insert="\n\n# Begin Custom htaccess from WP htaccess Control\n".$WPhtc_data['hta_mr']."\n# End Custom htaccess from WP htaccess Control\n";
97
  $new_rules.=str_replace("RewriteEngine On","RewriteEngine On".$insert,$rules);
98
  }
99
  else{
@@ -107,7 +173,17 @@ if (!class_exists("WPhtc")) {
107
  }
108
  # Adding our options page to the admin menu
109
  function configure_menu(){
110
- add_submenu_page("options-general.php","WP htaccess Control", "WP htaControl", 6, __FILE__, array('WPhtc','wphtc_page'));
 
 
 
 
 
 
 
 
 
 
111
  }
112
  # Options Page Actions
113
  function wphtc_page_action(){
@@ -125,6 +201,7 @@ if (!class_exists("WPhtc")) {
125
  break;
126
  # if updating, save new rules in database and flush rewrite rules
127
  case 'update':
 
128
  for($i=0;$i<$_POST['WPhtc_num'];$i++){
129
  if(!empty($_POST['WPhtc_pat'.$i]) && !empty($_POST['WPhtc_sub'.$i])){
130
  $WPhtc_data['pats'][$i]=$_POST['WPhtc_pat'.$i];
@@ -138,14 +215,27 @@ if (!class_exists("WPhtc")) {
138
  $WPhtc_data['pats']=array_values($WPhtc_data['pats']);
139
  $WPhtc_data['subs']=array_values($WPhtc_data['subs']);
140
  }
 
141
  $WPhtc_data['hta']=$_POST['WPhtc_hta'];
142
- // DEPRECATING
143
- //$WPhtc_data['hta_mr']=$_POST['WPhtc_hta_mr'];
144
- unset($WPhtc_data['hta_mr']);
 
145
  $WPhtc_data['cap']=$_POST['WPhtc_cap'];
 
 
 
 
 
 
 
 
 
 
 
146
  # Unsetting inclusion of Author pages on Google XML Sitemap options, we'll add those links to the sitemap later with our Custom Author Permalink
147
- $WPhtc_data['sm_enabled']=($_POST['WPhtc_sm_enabled']==1&&$WPhtc_data['cap']!='')?1:0;
148
- if($WPhtc_data['sm_enabled']==1){
149
  $SMoptions=get_option("sm_options");
150
  if($SMoptions&&is_array($SMoptions)){
151
  $SMoptions=get_option("sm_options");
@@ -160,12 +250,7 @@ if (!class_exists("WPhtc")) {
160
  # Flush Rewrite Rules
161
  global $wp_rewrite;
162
  $wp_rewrite->flush_rules();
163
- $echo.="Author permalink structure and htaccess Rules updated.";
164
- break;
165
- # add_rule substituted by jQuery use below but still present just in case (this should be Deprecated really)
166
- case 'add_rule':
167
- $add_rule=true;
168
- $echo='New pair available!';
169
  break;
170
  # deleting individual rewrite pair
171
  case 'delete_pair':
3
  Plugin Name: WP htaccess Control
4
  Plugin URI: http://dardna.com/wp-htaccess-control
5
  Description: Provides an interface to add custom htaccess rules to the htaccess file generated by wordpress. Also provides customisation of the Author Permalink Base.
6
+ Version: 1.4
7
+ Author: António Andrade
8
  Author URI: http://dardna.com
9
  */
10
  /* Copyright 2010 António Andrade (email : dardna@dardna.com)
86
  # Adding Custom Rules to htaccess file generated by Wordpress, everytime the rules are flush
87
  function wphtc_hta_rules($rules){
88
  $WPhtc_data=get_option('WPhtc_data');
89
+ if($WPhtc_data['hta']){
90
+ $new_rules.="\n# WPhtc: Begin Custom htaccess\n";
91
  $new_rules.=$WPhtc_data['hta']."\n";
92
+ $new_rules.="# WPhtc: End Custom htaccess\n\n";
93
  }
94
+ # htaccess suggestions
95
+ if($WPhtc_data['disable_serversignature']){
96
+ $new_rules.="# WPhtC: Disable ServerSignature on generated error pages\n";
97
+ $new_rules.="ServerSignature Off\n\n";
98
+ }
99
+ if($WPhtc_data['admin_email']){
100
+ $new_rules.="# WPhtC: Set admin email\n";
101
+ $new_rules.="SetEnv SERVER_ADMIN ".$WPhtc_data['admin_email']."\n\n";
102
+ }
103
+ if($WPhtc_data['disable_indexes']){
104
+ $new_rules.="# WPhtC: Disable directory browsing\n";
105
+ $new_rules.="Options All -Indexes\n\n";
106
+ }
107
+ if($WPhtc_data['up_limit']){
108
+ $new_rules.="# WPhtC: Limit upload size to ".$WPhtc_data['up_limit']." MB\n";
109
+ $new_rules.="LimitRequestBody ".($WPhtc_data['up_limit']*1024*1024)." \n\n";
110
+ }
111
+ if($WPhtc_data['redirect_500']){
112
+ $new_rules.="# WPhtC: Setting 500 Error page\n";
113
+ $new_rules.="ErrorDocument 500 ".$WPhtc_data['redirect_500']."\n\n";
114
+ }
115
+ if($WPhtc_data['protect_wp_config']){
116
+ $new_rules.="# WPhtC: Protect WP-config.php\n";
117
+ $new_rules.="<files wp-config.php>\n";
118
+ $new_rules.="order allow,deny\n";
119
+ $new_rules.="deny from all\n";
120
+ $new_rules.="</files>\n\n";
121
+ }
122
+ if($WPhtc_data['protect_htaccess']){
123
+ $new_rules.="# WPhtC: Protect .htaccess file\n";
124
+ $new_rules.="<files ~ \"^.*\.([Hh][Tt][Aa])\">\n";
125
+ $new_rules.="order allow,deny\n";
126
+ $new_rules.="deny from all\n";
127
+ $new_rules.="</files>\n\n";
128
+ }
129
+ if($WPhtc_data['disable_hotlink']){
130
+ $new_rules.="# WPhtC: Disable image hotlinking\n";
131
+ $new_rules.="<IfModule mod_rewrite.c>\n";
132
+ $new_rules.="RewriteEngine On\n";
133
+ $new_rules.="RewriteCond %{HTTP_REFERER} !^$\n";
134
+ $new_rules.="RewriteCond %{HTTP_REFERER} !^http://(www\.)?".str_ireplace(array("http://","www."),"",get_bloginfo("url"))."/.*$ [NC]\n";
135
+ $new_rules.="RewriteRule \.(jpg|jpeg|png|gif)$ ".$WPhtc_data['disable_hotlink']." [NC,R,L]\n";
136
+ $new_rules.="</IfModule>\n\n";
137
+ }
138
+ if($WPhtc_data['canon']){
139
+ $url=str_ireplace(array("http://","www."),"",get_bloginfo("url"));
140
+ $url="sub.dom.com";
141
+ $domain=explode("/",$url);
142
+ $escaped_domain=str_ireplace(".","\.",$domain[0]);
143
+ if($WPhtc_data['canon']=='www'){
144
+ $new_rules.="# WPhtC: Setting WWW canon\n";
145
+ $new_rules.="<IfModule mod_rewrite.c>\n";
146
+ $new_rules.="RewriteEngine On\n";
147
+ $new_rules.="RewriteCond %{HTTP_HOST} ^".$escaped_domain." [NC] \n";
148
+ $new_rules.="RewriteRule (.*) http://www.".$domain[0]."/$1 [R=301,L]\n";
149
+ $new_rules.="</IfModule>\n\n";
150
+ }
151
+ else if($WPhtc_data['canon']=='simple'){
152
+ $new_rules.="# WPhtC: Setting canon to non-WWW\n";
153
+ $new_rules.="<IfModule mod_rewrite.c>\n";
154
+ $new_rules.="RewriteEngine On\n";
155
+ $new_rules.="RewriteCond %{HTTP_HOST} ^www\.".$escaped_domain." [NC] \n";
156
+ $new_rules.="RewriteRule (.*) http://".$domain[0]."/$1 [R=301,L]\n";
157
+ $new_rules.="</IfModule>\n\n";
158
+ }
159
+ }
160
+ // DEPRECATE LATER (mod_rewrite)
161
  if($WPhtc_data['hta_mr']!=''){
162
+ $insert="\n\n# WPhtc: Begin Custom htaccess\n".$WPhtc_data['hta_mr']."\n# WPhtc: End Custom htaccess\n";
163
  $new_rules.=str_replace("RewriteEngine On","RewriteEngine On".$insert,$rules);
164
  }
165
  else{
173
  }
174
  # Adding our options page to the admin menu
175
  function configure_menu(){
176
+ $page=add_submenu_page("options-general.php","WP htaccess Control", "WP htaControl", 6, __FILE__, array('WPhtc','wphtc_page'));
177
+ add_action('admin_print_scripts-'.$page, array('WPhtc','wphtc_page_script'));
178
+ add_action('admin_print_styles-'.$page, array('WPhtc','wphtc_page_style'));
179
+ }
180
+ # Enqueue Ui Scripts on Plugin page
181
+ function wphtc_page_script(){
182
+ wp_enqueue_script("wpHtacControlJS", WP_PLUGIN_URL . '/wp-htaccess-control/wp-htaccess-control-ui.js');
183
+ }
184
+ # Enqueue Ui Scripts on Plugin page
185
+ function wphtc_page_style(){
186
+ wp_enqueue_style("wpHtacControlCSS", WP_PLUGIN_URL . '/wp-htaccess-control/wp-htaccess-control-ui.css');
187
  }
188
  # Options Page Actions
189
  function wphtc_page_action(){
201
  break;
202
  # if updating, save new rules in database and flush rewrite rules
203
  case 'update':
204
+ # get Rewrite Pairs
205
  for($i=0;$i<$_POST['WPhtc_num'];$i++){
206
  if(!empty($_POST['WPhtc_pat'.$i]) && !empty($_POST['WPhtc_sub'.$i])){
207
  $WPhtc_data['pats'][$i]=$_POST['WPhtc_pat'.$i];
215
  $WPhtc_data['pats']=array_values($WPhtc_data['pats']);
216
  $WPhtc_data['subs']=array_values($WPhtc_data['subs']);
217
  }
218
+ # get Custom Htaccess
219
  $WPhtc_data['hta']=$_POST['WPhtc_hta'];
220
+ // DEPRECATING
221
+ //$WPhtc_data['hta_mr']=$_POST['WPhtc_hta_mr'];
222
+ unset($WPhtc_data['hta_mr']);
223
+ # get Custom Author Permalink
224
  $WPhtc_data['cap']=$_POST['WPhtc_cap'];
225
+ # get htaccess Suggestions
226
+ $WPhtc_data['disable_serversignature']=$_POST['WPhtc_disable_serversignature'];
227
+ $WPhtc_data['disable_indexes']=$_POST['WPhtc_disable_indexes'];
228
+ $WPhtc_data['up_limit']=(is_numeric($_POST['WPhtc_up_limit'])&&$_POST['WPhtc_up_limit']>0)?$_POST['WPhtc_up_limit']:'';
229
+ $WPhtc_data['protect_wp_config']=$_POST['WPhtc_protect_wp_config'];
230
+ $WPhtc_data['protect_htaccess']=$_POST['WPhtc_protect_htaccess'];
231
+ $WPhtc_data['disable_hotlink']=trim($_POST['WPhtc_disable_hotlink']);
232
+ $WPhtc_data['redirect_500']=trim($_POST['WPhtc_redirect_500']);
233
+ $WPhtc_data['canon']=$_POST['WPhtc_canon'];
234
+ $WPhtc_data['admin_email']=trim($_POST['WPhtc_admin_email']);
235
+
236
  # Unsetting inclusion of Author pages on Google XML Sitemap options, we'll add those links to the sitemap later with our Custom Author Permalink
237
+ $WPhtc_data['sm_enabled']=$_POST['WPhtc_sm_enabled'];
238
+ if($WPhtc_data['sm_enabled']==true){
239
  $SMoptions=get_option("sm_options");
240
  if($SMoptions&&is_array($SMoptions)){
241
  $SMoptions=get_option("sm_options");
250
  # Flush Rewrite Rules
251
  global $wp_rewrite;
252
  $wp_rewrite->flush_rules();
253
+ $echo.="All options updated.";
 
 
 
 
 
254
  break;
255
  # deleting individual rewrite pair
256
  case 'delete_pair':