PageRenderTime 27ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-admin/options-permalink.php

http://cartonbank.googlecode.com/
PHP | 289 lines | 238 code | 36 blank | 15 comment | 72 complexity | 26871c53e4a3a34d0a0e039169f26d36 MD5 | raw file
Possible License(s): GPL-3.0, GPL-2.0, LGPL-2.1, AGPL-1.0, LGPL-3.0
  1. <?php
  2. /**
  3. * Permalink settings administration panel.
  4. *
  5. * @package WordPress
  6. * @subpackage Administration
  7. */
  8. /** WordPress Administration Bootstrap */
  9. require_once('./admin.php');
  10. if ( ! current_user_can( 'manage_options' ) )
  11. wp_die( __( 'You do not have sufficient permissions to manage options for this site.' ) );
  12. $title = __('Permalink Settings');
  13. $parent_file = 'options-general.php';
  14. add_contextual_help($current_screen,
  15. '<p>' . __('This screen provides some common options for your default permalinks URL structure.') . '</p>' .
  16. '<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>' .
  17. '<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>' .
  18. '<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>' .
  19. '<p>' . __('The Optional fields let you customize the &#8220;category&#8221; and &#8220;tag&#8221; base names that will appear in archive URLs. For example, the page listing all posts in the &#8220;Uncategorized&#8221; category could be <code>/topics/uncategorized</code> instead of <code>/category/uncategorized</code>.') . '</p>' .
  20. '<p>' . __('You must click the Save Changes button at the bottom of the screen for new settings to take effect.') . '</p>' .
  21. '<p><strong>' . __('For more information:') . '</strong></p>' .
  22. '<p>' . __('<a href="http://codex.wordpress.org/Settings_Permalinks_SubPanel" target="_blank">Permalinks Settings Documentation</a>') . '</p>' .
  23. '<p>' . __('<a href="http://codex.wordpress.org/Using_Permalinks" target="_blank">Using Permalinks Documentation</a>') . '</p>' .
  24. '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>'
  25. );
  26. /**
  27. * Display JavaScript on the page.
  28. *
  29. * @package WordPress
  30. * @subpackage Permalink_Settings_Panel
  31. */
  32. function add_js() {
  33. ?>
  34. <script type="text/javascript">
  35. //<![CDATA[
  36. function GetElementsWithClassName(elementName, className) {
  37. var allElements = document.getElementsByTagName(elementName);
  38. var elemColl = new Array();
  39. for (i = 0; i < allElements.length; i++) {
  40. if (allElements[i].className == className) {
  41. elemColl[elemColl.length] = allElements[i];
  42. }
  43. }
  44. return elemColl;
  45. }
  46. function upit() {
  47. var inputColl = GetElementsWithClassName('input', 'tog');
  48. var structure = document.getElementById('permalink_structure');
  49. var inputs = '';
  50. for (i = 0; i < inputColl.length; i++) {
  51. if ( inputColl[i].checked && inputColl[i].value != '') {
  52. inputs += inputColl[i].value + ' ';
  53. }
  54. }
  55. inputs = inputs.substr(0,inputs.length - 1);
  56. if ( 'custom' != inputs )
  57. structure.value = inputs;
  58. }
  59. function blurry() {
  60. if (!document.getElementById) return;
  61. var structure = document.getElementById('permalink_structure');
  62. structure.onfocus = function () { document.getElementById('custom_selection').checked = 'checked'; }
  63. var aInputs = document.getElementsByTagName('input');
  64. for (var i = 0; i < aInputs.length; i++) {
  65. aInputs[i].onclick = aInputs[i].onkeyup = upit;
  66. }
  67. }
  68. window.onload = blurry;
  69. //]]>
  70. </script>
  71. <?php
  72. }
  73. add_filter('admin_head', 'add_js');
  74. include('./admin-header.php');
  75. $home_path = get_home_path();
  76. $iis7_permalinks = iis7_supports_permalinks();
  77. $prefix = $blog_prefix = '';
  78. if ( ! got_mod_rewrite() && ! $iis7_permalinks )
  79. $prefix = '/index.php';
  80. if ( is_multisite() && !is_subdomain_install() && is_main_site() )
  81. $blog_prefix = '/blog';
  82. if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
  83. check_admin_referer('update-permalink');
  84. if ( isset( $_POST['permalink_structure'] ) ) {
  85. if ( isset( $_POST['selection'] ) && 'custom' != $_POST['selection'] )
  86. $permalink_structure = $_POST['selection'];
  87. else
  88. $permalink_structure = $_POST['permalink_structure'];
  89. if ( ! empty( $permalink_structure ) ) {
  90. $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );
  91. if ( $prefix && $blog_prefix )
  92. $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
  93. else
  94. $permalink_structure = $blog_prefix . $permalink_structure;
  95. }
  96. $wp_rewrite->set_permalink_structure( $permalink_structure );
  97. }
  98. if ( isset( $_POST['category_base'] ) ) {
  99. $category_base = $_POST['category_base'];
  100. if ( ! empty( $category_base ) )
  101. $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
  102. $wp_rewrite->set_category_base( $category_base );
  103. }
  104. if ( isset( $_POST['tag_base'] ) ) {
  105. $tag_base = $_POST['tag_base'];
  106. if ( ! empty( $tag_base ) )
  107. $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
  108. $wp_rewrite->set_tag_base( $tag_base );
  109. }
  110. }
  111. $permalink_structure = get_option('permalink_structure');
  112. $category_base = get_option('category_base');
  113. $tag_base = get_option( 'tag_base' );
  114. if ( $iis7_permalinks ) {
  115. if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') )
  116. $writable = true;
  117. else
  118. $writable = false;
  119. } else {
  120. if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') )
  121. $writable = true;
  122. else
  123. $writable = false;
  124. }
  125. if ( $wp_rewrite->using_index_permalinks() )
  126. $usingpi = true;
  127. else
  128. $usingpi = false;
  129. $wp_rewrite->flush_rules();
  130. if (isset($_POST['submit'])) : ?>
  131. <div id="message" class="updated"><p><?php
  132. if ( ! is_multisite() ) {
  133. if ( $iis7_permalinks ) {
  134. if ( $permalink_structure && ! $usingpi && ! $writable )
  135. _e('You should update your web.config now');
  136. else if ( $permalink_structure && ! $usingpi && $writable )
  137. _e('Permalink structure updated. Remove write access on web.config file now!');
  138. else
  139. _e('Permalink structure updated');
  140. } else {
  141. if ( $permalink_structure && ! $usingpi && ! $writable )
  142. _e('You should update your .htaccess now.');
  143. else
  144. _e('Permalink structure updated.');
  145. }
  146. } else {
  147. _e('Permalink structure updated.');
  148. }
  149. ?>
  150. </p></div>
  151. <?php endif; ?>
  152. <div class="wrap">
  153. <?php screen_icon(); ?>
  154. <h2><?php echo esc_html( $title ); ?></h2>
  155. <form name="form" action="options-permalink.php" method="post">
  156. <?php wp_nonce_field('update-permalink') ?>
  157. <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>
  158. <?php
  159. if ( is_multisite() && !is_subdomain_install() && is_main_site() ) {
  160. $permalink_structure = preg_replace( '|^/?blog|', '', $permalink_structure );
  161. $category_base = preg_replace( '|^/?blog|', '', $category_base );
  162. $tag_base = preg_replace( '|^/?blog|', '', $tag_base );
  163. }
  164. $structures = array(
  165. '',
  166. $prefix . '/%year%/%monthnum%/%day%/%postname%/',
  167. $prefix . '/%year%/%monthnum%/%postname%/',
  168. $prefix . '/archives/%post_id%'
  169. );
  170. ?>
  171. <h3><?php _e('Common settings'); ?></h3>
  172. <table class="form-table">
  173. <tr>
  174. <th><label><input name="selection" type="radio" value="" class="tog" <?php checked('', $permalink_structure); ?> /> <?php _e('Default'); ?></label></th>
  175. <td><code><?php echo get_option('home'); ?>/?p=123</code></td>
  176. </tr>
  177. <tr>
  178. <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>
  179. <td><code><?php echo get_option('home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/sample-post/'; ?></code></td>
  180. </tr>
  181. <tr>
  182. <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>
  183. <td><code><?php echo get_option('home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/sample-post/'; ?></code></td>
  184. </tr>
  185. <tr>
  186. <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>
  187. <td><code><?php echo get_option('home') . $blog_prefix . $prefix; ?>/archives/123</code></td>
  188. </tr>
  189. <tr>
  190. <th>
  191. <label><input name="selection" id="custom_selection" type="radio" value="custom" class="tog" <?php checked( !in_array($permalink_structure, $structures) ); ?> />
  192. <?php _e('Custom Structure'); ?>
  193. </label>
  194. </th>
  195. <td>
  196. <?php echo $blog_prefix; ?>
  197. <input name="permalink_structure" id="permalink_structure" type="text" value="<?php echo esc_attr($permalink_structure); ?>" class="regular-text code" />
  198. </td>
  199. </tr>
  200. </table>
  201. <h3><?php _e('Optional'); ?></h3>
  202. <?php if ( $is_apache || $iis7_permalinks ) : ?>
  203. <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>
  204. <?php else : ?>
  205. <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>
  206. <?php endif; ?>
  207. <table class="form-table">
  208. <tr>
  209. <th><label for="category_base"><?php /* translators: prefix for category permalinks */ _e('Category base'); ?></label></th>
  210. <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>
  211. </tr>
  212. <tr>
  213. <th><label for="tag_base"><?php _e('Tag base'); ?></label></th>
  214. <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>
  215. </tr>
  216. <?php do_settings_fields('permalink', 'optional'); ?>
  217. </table>
  218. <?php do_settings_sections('permalink'); ?>
  219. <p class="submit">
  220. <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
  221. </p>
  222. </form>
  223. <?php if ( !is_multisite() ) { ?>
  224. <?php if ( $iis7_permalinks ) :
  225. if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) :
  226. if ( file_exists($home_path . 'web.config') ) : ?>
  227. <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&#8217;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>/&lt;configuration&gt;/&lt;system.webServer&gt;/&lt;rewrite&gt;/&lt;rules&gt;</code> element in <code>web.config</code> file.') ?></p>
  228. <form action="options-permalink.php" method="post">
  229. <?php wp_nonce_field('update-permalink') ?>
  230. <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>
  231. </form>
  232. <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>
  233. <?php else : ?>
  234. <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&#8217;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>
  235. <form action="options-permalink.php" method="post">
  236. <?php wp_nonce_field('update-permalink') ?>
  237. <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>
  238. </form>
  239. <p><?php _e('If you temporarily make your site&#8217;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>
  240. <?php endif; ?>
  241. <?php endif; ?>
  242. <?php else :
  243. if ( $permalink_structure && ! $usingpi && ! $writable ) : ?>
  244. <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&#8217;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>
  245. <form action="options-permalink.php" method="post">
  246. <?php wp_nonce_field('update-permalink') ?>
  247. <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>
  248. </form>
  249. <?php endif; ?>
  250. <?php endif; ?>
  251. <?php } // multisite ?>
  252. </div>
  253. <?php require('./admin-footer.php'); ?>