| [ Root ] [ Search ] [ Index ] |
PHP Cross Reference of WordPress 3.0Provided by Yoast |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Permalink settings administration panel. 4 * 5 * @package WordPress 6 * @subpackage Administration 7 */ 8 9 /** WordPress Administration Bootstrap */ 10 require_once ('./admin.php'); 11 12 if ( ! current_user_can( 'manage_options' ) ) 13 wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) ); 14 15 $title = __('Permalink Settings'); 16 $parent_file = 'options-general.php'; 17 18 add_contextual_help($current_screen, 19 '<p>' . __('This screen provides some common options for your default permalinks URL structure.') . '</p>' . 20 '<p>' . __('If you pick an option other than Default, your general URL path with structure tags, terms surrounded by <code>%</code>, will also appear in the custom structure field and your path can be further modified there.') . '</p>' . 21 '<p>' . __('When you assign multiple categories or tags to a post, only one can show up in the permalink: the lowest numbered category. This applies if your custom structure includes <code>%category%</code> or <code>%tag%</code>.') . '</p>' . 22 '<p>' . __('Note that permalinks beginning with the category, tag, author or postname structure tags require more advanced server resources. Double-check your hosting details to make sure those are in place or start your permalinks with other structure tags.') . '</p>' . 23 '<p>' . __('The Optional fields let you customize the “category” and “tag” base names that will appear in archive URLs. For example, the page listing all posts in the “Uncategorized” category could be <code>/topics/uncategorized</code> instead of <code>/category/uncategorized</code>.') . '</p>' . 24 '<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>' . 25 '<p><strong>' . __('For more information:') . '</strong></p>' . 26 '<p>' . __('<a href="http://codex.wordpress.org/Settings_Permalinks_SubPanel" target="_blank">Permalinks Settings Documentation</a>') . '</p>' . 27 '<p>' . __('<a href="http://codex.wordpress.org/Using_Permalinks" target="_blank">Using Permalinks Documentation</a>') . '</p>' . 28 '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>' 29 ); 30 31 /** 32 * Display JavaScript on the page. 33 * 34 * @package WordPress 35 * @subpackage Permalink_Settings_Panel 36 */ 37 function add_js() { 38 ?> 39 <script type="text/javascript"> 40 //<![CDATA[ 41 function GetElementsWithClassName(elementName, className) { 42 var allElements = document.getElementsByTagName(elementName); 43 var elemColl = new Array(); 44 for (i = 0; i < allElements.length; i++) { 45 if (allElements[i].className == className) { 46 elemColl[elemColl.length] = allElements[i]; 47 } 48 } 49 return elemColl; 50 } 51 52 function upit() { 53 var inputColl = GetElementsWithClassName('input', 'tog'); 54 var structure = document.getElementById('permalink_structure'); 55 var inputs = ''; 56 for (i = 0; i < inputColl.length; i++) { 57 if ( inputColl[i].checked && inputColl[i].value != '') { 58 inputs += inputColl[i].value + ' '; 59 } 60 } 61 inputs = inputs.substr(0,inputs.length - 1); 62 if ( 'custom' != inputs ) 63 structure.value = inputs; 64 } 65 66 function blurry() { 67 if (!document.getElementById) return; 68 69 var structure = document.getElementById('permalink_structure'); 70 structure.onfocus = function () { document.getElementById('custom_selection').checked = 'checked'; } 71 72 var aInputs = document.getElementsByTagName('input'); 73 74 for (var i = 0; i < aInputs.length; i++) { 75 aInputs[i].onclick = aInputs[i].onkeyup = upit; 76 } 77 } 78 79 window.onload = blurry; 80 //]]> 81 </script> 82 <?php 83 } 84 add_filter('admin_head', 'add_js'); 85 86 include ('./admin-header.php'); 87 88 $home_path = get_home_path(); 89 $iis7_permalinks = iis7_supports_permalinks(); 90 91 $prefix = $blog_prefix = ''; 92 if ( ! got_mod_rewrite() && ! $iis7_permalinks ) 93 $prefix = '/index.php'; 94 if ( is_multisite() && !is_subdomain_install() && is_main_site() ) 95 $blog_prefix = '/blog'; 96 97 if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) { 98 check_admin_referer('update-permalink'); 99 100 if ( isset( $_POST['permalink_structure'] ) ) { 101 if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] ) 102 $permalink_structure = $_POST['selection']; 103 else 104 $permalink_structure = $_POST['permalink_structure']; 105 106 if ( ! empty( $permalink_structure ) ) { 107 $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) ); 108 if ( $prefix && $blog_prefix ) 109 $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure ); 110 else 111 $permalink_structure = $blog_prefix . $permalink_structure; 112 } 113 $wp_rewrite->set_permalink_structure( $permalink_structure ); 114 } 115 116 if ( isset( $_POST['category_base'] ) ) { 117 $category_base = $_POST['category_base']; 118 if ( ! empty( $category_base ) ) 119 $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) ); 120 $wp_rewrite->set_category_base( $category_base ); 121 } 122 123 if ( isset( $_POST['tag_base'] ) ) { 124 $tag_base = $_POST['tag_base']; 125 if ( ! empty( $tag_base ) ) 126 $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) ); 127 $wp_rewrite->set_tag_base( $tag_base ); 128 } 129 } 130 131 $permalink_structure = get_option('permalink_structure'); 132 $category_base = get_option('category_base'); 133 $tag_base = get_option( 'tag_base' ); 134 135 if ( $iis7_permalinks ) { 136 if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') ) 137 $writable = true; 138 else 139 $writable = false; 140 } else { 141 if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') ) 142 $writable = true; 143 else 144 $writable = false; 145 } 146 147 if ( $wp_rewrite->using_index_permalinks() ) 148 $usingpi = true; 149 else 150 $usingpi = false; 151 152 $wp_rewrite->flush_rules(); 153 154 155 if (isset($_POST['submit'])) : ?> 156 <div id="message" class="updated"><p><?php 157 if ( ! is_multisite() ) { 158 if ( $iis7_permalinks ) { 159 if ( $permalink_structure && ! $usingpi && ! $writable ) 160 _e('You should update your web.config now'); 161 else if ( $permalink_structure && ! $usingpi && $writable ) 162 _e('Permalink structure updated. Remove write access on web.config file now!'); 163 else 164 _e('Permalink structure updated'); 165 } else { 166 if ( $permalink_structure && ! $usingpi && ! $writable ) 167 _e('You should update your .htaccess now.'); 168 else 169 _e('Permalink structure updated.'); 170 } 171 } else { 172 _e('Permalink structure updated.'); 173 } 174 ?> 175 </p></div> 176 <?php endif; ?> 177 178 <div class="wrap"> 179 <?php screen_icon(); ?> 180 <h2><?php echo esc_html( $title ); ?></h2> 181 182 <form name="form" action="options-permalink.php" method="post"> 183 <?php wp_nonce_field('update-permalink') ?> 184 185 <p><?php _e('By default WordPress uses web <abbr title="Universal Resource Locator">URL</abbr>s which have question marks and lots of numbers in them, however WordPress offers you the ability to create a custom URL structure for your permalinks and archives. This can improve the aesthetics, usability, and forward-compatibility of your links. A <a href="http://codex.wordpress.org/Using_Permalinks">number of tags are available</a>, and here are some examples to get you started.'); ?></p> 186 187 <?php 188 if ( is_multisite() && !is_subdomain_install() && is_main_site() ) { 189 $permalink_structure = preg_replace( '|^/?blog|', '', $permalink_structure ); 190 $category_base = preg_replace( '|^/?blog|', '', $category_base ); 191 $tag_base = preg_replace( '|^/?blog|', '', $tag_base ); 192 } 193 194 $structures = array( 195 '', 196 $prefix . '/%year%/%monthnum%/%day%/%postname%/', 197 $prefix . '/%year%/%monthnum%/%postname%/', 198 $prefix . '/archives/%post_id%' 199 ); 200 ?> 201 <h3><?php _e('Common settings'); ?></h3> 202 <table class="form-table"> 203 <tr> 204 <th><label><input name="selection" type="radio" value="" class="tog" <?php checked('', $permalink_structure); ?> /> <?php _e('Default'); ?></label></th> 205 <td><code><?php echo get_option('home'); ?>/?p=123</code></td> 206 </tr> 207 <tr> 208 <th><label><input name="selection" type="radio" value="<?php echo esc_attr($structures[1]); ?>" class="tog" <?php checked($structures[1], $permalink_structure); ?> /> <?php _e('Day and name'); ?></label></th> 209 <td><code><?php echo get_option('home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/sample-post/'; ?></code></td> 210 </tr> 211 <tr> 212 <th><label><input name="selection" type="radio" value="<?php echo esc_attr($structures[2]); ?>" class="tog" <?php checked($structures[2], $permalink_structure); ?> /> <?php _e('Month and name'); ?></label></th> 213 <td><code><?php echo get_option('home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/sample-post/'; ?></code></td> 214 </tr> 215 <tr> 216 <th><label><input name="selection" type="radio" value="<?php echo esc_attr($structures[3]); ?>" class="tog" <?php checked($structures[3], $permalink_structure); ?> /> <?php _e('Numeric'); ?></label></th> 217 <td><code><?php echo get_option('home') . $blog_prefix . $prefix; ?>/archives/123</code></td> 218 </tr> 219 <tr> 220 <th> 221 <label><input name="selection" id="custom_selection" type="radio" value="custom" class="tog" <?php checked( !in_array($permalink_structure, $structures) ); ?> /> 222 <?php _e('Custom Structure'); ?> 223 </label> 224 </th> 225 <td> 226 <?php echo $blog_prefix; ?> 227 <input name="permalink_structure" id="permalink_structure" type="text" value="<?php echo esc_attr($permalink_structure); ?>" class="regular-text code" /> 228 </td> 229 </tr> 230 </table> 231 232 <h3><?php _e('Optional'); ?></h3> 233 <?php if ( $is_apache || $iis7_permalinks ) : ?> 234 <p><?php _e('If you like, you may enter custom structures for your category and tag <abbr title="Universal Resource Locator">URL</abbr>s here. For example, using <kbd>topics</kbd> as your category base would make your category links like <code>http://example.org/topics/uncategorized/</code>. If you leave these blank the defaults will be used.') ?></p> 235 <?php else : ?> 236 <p><?php _e('If you like, you may enter custom structures for your category and tag <abbr title="Universal Resource Locator">URL</abbr>s here. For example, using <code>topics</code> as your category base would make your category links like <code>http://example.org/index.php/topics/uncategorized/</code>. If you leave these blank the defaults will be used.') ?></p> 237 <?php endif; ?> 238 239 <table class="form-table"> 240 <tr> 241 <th><label for="category_base"><?php /* translators: prefix for category permalinks */ _e('Category base'); ?></label></th> 242 <td><?php echo $blog_prefix; ?> <input name="category_base" id="category_base" type="text" value="<?php echo esc_attr( $category_base ); ?>" class="regular-text code" /></td> 243 </tr> 244 <tr> 245 <th><label for="tag_base"><?php _e('Tag base'); ?></label></th> 246 <td><?php echo $blog_prefix; ?> <input name="tag_base" id="tag_base" type="text" value="<?php echo esc_attr($tag_base); ?>" class="regular-text code" /></td> 247 </tr> 248 <?php do_settings_fields('permalink', 'optional'); ?> 249 </table> 250 251 <?php do_settings_sections('permalink'); ?> 252 253 <p class="submit"> 254 <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" /> 255 </p> 256 </form> 257 <?php if ( !is_multisite() ) { ?> 258 <?php if ( $iis7_permalinks ) : 259 if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) : 260 if ( file_exists($home_path . 'web.config') ) : ?> 261 <p><?php _e('If your <code>web.config</code> file were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn’t so this is the url rewrite rule you should have in your <code>web.config</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all. Then insert this rule inside of the <code>/<configuration>/<system.webServer>/<rewrite>/<rules></code> element in <code>web.config</code> file.') ?></p> 262 <form action="options-permalink.php" method="post"> 263 <?php wp_nonce_field('update-permalink') ?> 264 <p><textarea rows="9" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_html($wp_rewrite->iis7_url_rewrite_rules()); ?></textarea></p> 265 </form> 266 <p><?php _e('If you temporarily make your <code>web.config</code> file writable for us to generate rewrite rules automatically, do not forget to revert the permissions after rule has been saved.') ?></p> 267 <?php else : ?> 268 <p><?php _e('If the root directory of your site were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn’t so this is the url rewrite rule you should have in your <code>web.config</code> file. Create a new file, called <code>web.config</code> in the root directory of your site. Click in the field and press <kbd>CTRL + a</kbd> to select all. Then insert this code into the <code>web.config</code> file.') ?></p> 269 <form action="options-permalink.php" method="post"> 270 <?php wp_nonce_field('update-permalink') ?> 271 <p><textarea rows="18" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_html($wp_rewrite->iis7_url_rewrite_rules(true)); ?></textarea></p> 272 </form> 273 <p><?php _e('If you temporarily make your site’s root directory writable for us to generate the <code>web.config</code> file automatically, do not forget to revert the permissions after the file has been created.') ?></p> 274 <?php endif; ?> 275 <?php endif; ?> 276 <?php else : 277 if ( $permalink_structure && ! $usingpi && ! $writable ) : ?> 278 <p><?php _e('If your <code>.htaccess</code> file were <a href="http://codex.wordpress.org/Changing_File_Permissions">writable</a>, we could do this automatically, but it isn’t so these are the mod_rewrite rules you should have in your <code>.htaccess</code> file. Click in the field and press <kbd>CTRL + a</kbd> to select all.') ?></p> 279 <form action="options-permalink.php" method="post"> 280 <?php wp_nonce_field('update-permalink') ?> 281 <p><textarea rows="6" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo esc_html($wp_rewrite->mod_rewrite_rules()); ?></textarea></p> 282 </form> 283 <?php endif; ?> 284 <?php endif; ?> 285 <?php } // multisite ?> 286 287 </div> 288 289 <?php require ('./admin-footer.php'); ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Oct 14 05:11:12 2010 | Cross-referenced by PHPXref 0.7 |