PageRenderTime 55ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 1ms

/wp-admin/options-permalink.php

https://gitlab.com/endomorphosis/reservationtelco
PHP | 285 lines | 235 code | 35 blank | 15 comment | 69 complexity | e531fa7b6039478a66473dc932661adb MD5 | raw file
  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 %, 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 %category% or %tag%.') . '</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 /topics/uncategorized instead of /category/uncategorized.') . '</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">Permalinks Settings Documentation</a>') . '</p>' .
  23. '<p>' . __('<a href="http://codex.wordpress.org/Using_Permalinks">Using Permalinks Documentation</a>') . '</p>' .
  24. '<p>' . __('<a href="http://wordpress.org/support/">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. $permalink_structure = $_POST['permalink_structure'];
  86. if ( ! empty( $permalink_structure ) ) {
  87. $permalink_structure = preg_replace( '#/+#', '/', '/' . str_replace( '#', '', $permalink_structure ) );
  88. if ( $prefix && $blog_prefix )
  89. $permalink_structure = $prefix . preg_replace( '#^/?index\.php#', '', $permalink_structure );
  90. else
  91. $permalink_structure = $blog_prefix . $permalink_structure;
  92. }
  93. $wp_rewrite->set_permalink_structure( $permalink_structure );
  94. }
  95. if ( isset( $_POST['category_base'] ) ) {
  96. $category_base = $_POST['category_base'];
  97. if ( ! empty( $category_base ) )
  98. $category_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $category_base ) );
  99. $wp_rewrite->set_category_base( $category_base );
  100. }
  101. if ( isset( $_POST['tag_base'] ) ) {
  102. $tag_base = $_POST['tag_base'];
  103. if ( ! empty( $tag_base ) )
  104. $tag_base = $blog_prefix . preg_replace('#/+#', '/', '/' . str_replace( '#', '', $tag_base ) );
  105. $wp_rewrite->set_tag_base( $tag_base );
  106. }
  107. }
  108. $permalink_structure = get_option('permalink_structure');
  109. $category_base = get_option('category_base');
  110. $tag_base = get_option( 'tag_base' );
  111. if ( $iis7_permalinks ) {
  112. if ( ( ! file_exists($home_path . 'web.config') && win_is_writable($home_path) ) || win_is_writable($home_path . 'web.config') )
  113. $writable = true;
  114. else
  115. $writable = false;
  116. } else {
  117. if ( ( ! file_exists($home_path . '.htaccess') && is_writable($home_path) ) || is_writable($home_path . '.htaccess') )
  118. $writable = true;
  119. else
  120. $writable = false;
  121. }
  122. if ( $wp_rewrite->using_index_permalinks() )
  123. $usingpi = true;
  124. else
  125. $usingpi = false;
  126. $wp_rewrite->flush_rules();
  127. if (isset($_POST['submit'])) : ?>
  128. <div id="message" class="updated"><p><?php
  129. if ( ! is_multisite() ) {
  130. if ( $iis7_permalinks ) {
  131. if ( $permalink_structure && ! $usingpi && ! $writable )
  132. _e('You should update your web.config now');
  133. else if ( $permalink_structure && ! $usingpi && $writable )
  134. _e('Permalink structure updated. Remove write access on web.config file now!');
  135. else
  136. _e('Permalink structure updated');
  137. } else {
  138. if ( $permalink_structure && ! $usingpi && ! $writable )
  139. _e('You should update your .htaccess now.');
  140. else
  141. _e('Permalink structure updated.');
  142. }
  143. } else {
  144. _e('Permalink structure updated.');
  145. }
  146. ?>
  147. </p></div>
  148. <?php endif; ?>
  149. <div class="wrap">
  150. <?php screen_icon(); ?>
  151. <h2><?php echo esc_html( $title ); ?></h2>
  152. <form name="form" action="options-permalink.php" method="post">
  153. <?php wp_nonce_field('update-permalink') ?>
  154. <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>
  155. <?php
  156. if ( is_multisite() && !is_subdomain_install() && is_main_site() ) {
  157. $permalink_structure = preg_replace( '|^/?blog|', '', $permalink_structure );
  158. $category_base = preg_replace( '|^/?blog|', '', $category_base );
  159. $tag_base = preg_replace( '|^/?blog|', '', $tag_base );
  160. }
  161. $structures = array(
  162. '',
  163. $prefix . '/%year%/%monthnum%/%day%/%postname%/',
  164. $prefix . '/%year%/%monthnum%/%postname%/',
  165. $prefix . '/archives/%post_id%'
  166. );
  167. ?>
  168. <h3><?php _e('Common settings'); ?></h3>
  169. <table class="form-table">
  170. <tr>
  171. <th><label><input name="selection" type="radio" value="" class="tog" <?php checked('', $permalink_structure); ?> /> <?php _e('Default'); ?></label></th>
  172. <td><code><?php echo get_option('home'); ?>/?p=123</code></td>
  173. </tr>
  174. <tr>
  175. <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>
  176. <td><code><?php echo get_option('home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/sample-post/'; ?></code></td>
  177. </tr>
  178. <tr>
  179. <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>
  180. <td><code><?php echo get_option('home') . $blog_prefix . $prefix . '/' . date('Y') . '/' . date('m') . '/sample-post/'; ?></code></td>
  181. </tr>
  182. <tr>
  183. <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>
  184. <td><code><?php echo get_option('home') . $blog_prefix . $prefix; ?>/archives/123</code></td>
  185. </tr>
  186. <tr>
  187. <th>
  188. <label><input name="selection" id="custom_selection" type="radio" value="custom" class="tog" <?php checked( !in_array($permalink_structure, $structures) ); ?> />
  189. <?php _e('Custom Structure'); ?>
  190. </label>
  191. </th>
  192. <td>
  193. <?php echo $blog_prefix; ?>
  194. <input name="permalink_structure" id="permalink_structure" type="text" value="<?php echo esc_attr($permalink_structure); ?>" class="regular-text code" />
  195. </td>
  196. </tr>
  197. </table>
  198. <h3><?php _e('Optional'); ?></h3>
  199. <?php if ( $is_apache || $iis7_permalinks ) : ?>
  200. <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>
  201. <?php else : ?>
  202. <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>
  203. <?php endif; ?>
  204. <table class="form-table">
  205. <tr>
  206. <th><label for="category_base"><?php /* translators: prefix for category permalinks */ _e('Category base'); ?></label></th>
  207. <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>
  208. </tr>
  209. <tr>
  210. <th><label for="tag_base"><?php _e('Tag base'); ?></label></th>
  211. <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>
  212. </tr>
  213. <?php do_settings_fields('permalink', 'optional'); ?>
  214. </table>
  215. <?php do_settings_sections('permalink'); ?>
  216. <p class="submit">
  217. <input type="submit" name="submit" class="button-primary" value="<?php esc_attr_e('Save Changes') ?>" />
  218. </p>
  219. </form>
  220. <?php if ( !is_multisite() ) { ?>
  221. <?php if ( $iis7_permalinks ) :
  222. if ( isset($_POST['submit']) && $permalink_structure && ! $usingpi && ! $writable ) :
  223. if ( file_exists($home_path . 'web.config') ) : ?>
  224. <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>
  225. <form action="options-permalink.php" method="post">
  226. <?php wp_nonce_field('update-permalink') ?>
  227. <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>
  228. </form>
  229. <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>
  230. <?php else : ?>
  231. <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>
  232. <form action="options-permalink.php" method="post">
  233. <?php wp_nonce_field('update-permalink') ?>
  234. <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>
  235. </form>
  236. <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>
  237. <?php endif; ?>
  238. <?php endif; ?>
  239. <?php else :
  240. if ( $permalink_structure && ! $usingpi && ! $writable ) : ?>
  241. <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>
  242. <form action="options-permalink.php" method="post">
  243. <?php wp_nonce_field('update-permalink') ?>
  244. <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>
  245. </form>
  246. <?php endif; ?>
  247. <?php endif; ?>
  248. <?php } // multisite ?>
  249. </div>
  250. <?php require('./admin-footer.php'); ?>