mp-wp_genesis 1 <?php
mp-wp_genesis 2 /**
mp-wp_genesis 3 * Permalink settings administration panel.
mp-wp_genesis 4 *
mp-wp_genesis 5 * @package WordPress
mp-wp_genesis 6 * @subpackage Administration
mp-wp_genesis 7 */
mp-wp_genesis 8
mp-wp_genesis 9 /** WordPress Administration Bootstrap */
mp-wp_genesis 10 require_once('admin.php');
mp-wp_genesis 11
mp-wp_genesis 12 $title = __('Permalink Settings');
mp-wp_genesis 13 $parent_file = 'options-general.php';
mp-wp_genesis 14
mp-wp_genesis 15 /**
mp-wp_genesis 16 * Display JavaScript on the page.
mp-wp_genesis 17 *
mp-wp_genesis 18 * @package WordPress
mp-wp_genesis 19 * @subpackage Permalink_Settings_Panel
mp-wp_genesis 20 */
mp-wp_genesis 21 function add_js() {
mp-wp_genesis 22 ?>
mp-wp_genesis 23 <script type="text/javascript">
mp-wp_genesis 24 //<![CDATA[
mp-wp_genesis 25 function GetElementsWithClassName(elementName, className) {
mp-wp_genesis 26 var allElements = document.getElementsByTagName(elementName);
mp-wp_genesis 27 var elemColl = new Array();
mp-wp_genesis 28 for (i = 0; i < allElements.length; i++) {
mp-wp_genesis 29 if (allElements[i].className == className) {
mp-wp_genesis 30 elemColl[elemColl.length] = allElements[i];
mp-wp_genesis 31 }
mp-wp_genesis 32 }
mp-wp_genesis 33 return elemColl;
mp-wp_genesis 34 }
mp-wp_genesis 35
mp-wp_genesis 36 function upit() {
mp-wp_genesis 37 var inputColl = GetElementsWithClassName('input', 'tog');
mp-wp_genesis 38 var structure = document.getElementById('permalink_structure');
mp-wp_genesis 39 var inputs = '';
mp-wp_genesis 40 for (i = 0; i < inputColl.length; i++) {
mp-wp_genesis 41 if ( inputColl[i].checked && inputColl[i].value != '') {
mp-wp_genesis 42 inputs += inputColl[i].value + ' ';
mp-wp_genesis 43 }
mp-wp_genesis 44 }
mp-wp_genesis 45 inputs = inputs.substr(0,inputs.length - 1);
mp-wp_genesis 46 if ( 'custom' != inputs )
mp-wp_genesis 47 structure.value = inputs;
mp-wp_genesis 48 }
mp-wp_genesis 49
mp-wp_genesis 50 function blurry() {
mp-wp_genesis 51 if (!document.getElementById) return;
mp-wp_genesis 52
mp-wp_genesis 53 var structure = document.getElementById('permalink_structure');
mp-wp_genesis 54 structure.onfocus = function () { document.getElementById('custom_selection').checked = 'checked'; }
mp-wp_genesis 55
mp-wp_genesis 56 var aInputs = document.getElementsByTagName('input');
mp-wp_genesis 57
mp-wp_genesis 58 for (var i = 0; i < aInputs.length; i++) {
mp-wp_genesis 59 aInputs[i].onclick = aInputs[i].onkeyup = upit;
mp-wp_genesis 60 }
mp-wp_genesis 61 }
mp-wp_genesis 62
mp-wp_genesis 63 window.onload = blurry;
mp-wp_genesis 64 //]]>
mp-wp_genesis 65 </script>
mp-wp_genesis 66 <?php
mp-wp_genesis 67 }
mp-wp_genesis 68 add_filter('admin_head', 'add_js');
mp-wp_genesis 69
mp-wp_genesis 70 include('admin-header.php');
mp-wp_genesis 71
mp-wp_genesis 72 $home_path = get_home_path();
mp-wp_genesis 73
mp-wp_genesis 74 if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
mp-wp_genesis 75 check_admin_referer('update-permalink');
mp-wp_genesis 76
mp-wp_genesis 77 if ( isset($_POST['permalink_structure']) ) {
mp-wp_genesis 78 $permalink_structure = $_POST['permalink_structure'];
mp-wp_genesis 79 if (! empty($permalink_structure) )
mp-wp_genesis 80 $permalink_structure = preg_replace('#/+#', '/', '/' . $_POST['permalink_structure']);
mp-wp_genesis 81 $wp_rewrite->set_permalink_structure($permalink_structure);
mp-wp_genesis 82 }
mp-wp_genesis 83
mp-wp_genesis 84 if ( isset($_POST['category_base']) ) {
mp-wp_genesis 85 $category_base = $_POST['category_base'];
mp-wp_genesis 86 if (! empty($category_base) )
mp-wp_genesis 87 $category_base = preg_replace('#/+#', '/', '/' . $_POST['category_base']);
mp-wp_genesis 88 $wp_rewrite->set_category_base($category_base);
mp-wp_genesis 89 }
mp-wp_genesis 90
mp-wp_genesis 91 if ( isset($_POST['tag_base']) ) {
mp-wp_genesis 92 $tag_base = $_POST['tag_base'];
mp-wp_genesis 93 if (! empty($tag_base) )
mp-wp_genesis 94 $tag_base = preg_replace('#/+#', '/', '/' . $_POST['tag_base']);
mp-wp_genesis 95 $wp_rewrite->set_tag_base($tag_base);
mp-wp_genesis 96 }
mp-wp_genesis 97 }
mp-wp_genesis 98
mp-wp_genesis 99 $permalink_structure = get_option('permalink_structure');
mp-wp_genesis 100 $category_base = get_option('category_base');
mp-wp_genesis 101 $tag_base = get_option( 'tag_base' );
mp-wp_genesis 102
mp-wp_genesis 103 if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') )
mp-wp_genesis 104 $writable = true;
mp-wp_genesis 105 else
mp-wp_genesis 106 $writable = false;
mp-wp_genesis 107
mp-wp_genesis 108 if ($wp_rewrite->using_index_permalinks())
mp-wp_genesis 109 $usingpi = true;
mp-wp_genesis 110 else
mp-wp_genesis 111 $usingpi = false;
mp-wp_genesis 112
mp-wp_genesis 113 $wp_rewrite->flush_rules();
mp-wp_genesis 114 ?>
mp-wp_genesis 115
mp-wp_genesis 116 <?php if (isset($_POST['submit'])) : ?>
mp-wp_genesis 117 <div id="message" class="updated fade"><p><?php
mp-wp_genesis 118 if ( $permalink_structure && !$usingpi && !$writable )
mp-wp_genesis 119 _e('You should update your .htaccess now.');
mp-wp_genesis 120 else
mp-wp_genesis 121 _e('Permalink structure updated.');
mp-wp_genesis 122 ?></p></div>
mp-wp_genesis 123 <?php endif; ?>
mp-wp_genesis 124
mp-wp_genesis 125 <div class="wrap">
mp-wp_genesis 126 <?php screen_icon(); ?>
mp-wp_genesis 127 <h2><?php echo wp_specialchars( $title ); ?></h2>
mp-wp_genesis 128
mp-wp_genesis 129 <form name="form" action="options-permalink.php" method="post">
mp-wp_genesis 130 <?php wp_nonce_field('update-permalink') ?>
mp-wp_genesis 131
mp-wp_genesis 132 <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>
mp-wp_genesis 133
mp-wp_genesis 134 <?php
mp-wp_genesis 135 $prefix = '';
mp-wp_genesis 136
mp-wp_genesis 137 if ( ! got_mod_rewrite() )
mp-wp_genesis 138 $prefix = '/index.php';
mp-wp_genesis 139
mp-wp_genesis 140 $structures = array(
mp-wp_genesis 141 '',
mp-wp_genesis 142 $prefix . '/%year%/%monthnum%/%day%/%postname%/',
mp-wp_genesis 143 $prefix . '/%year%/%monthnum%/%postname%/',
mp-wp_genesis 144 $prefix . '/archives/%post_id%'
mp-wp_genesis 145 );
mp-wp_genesis 146 ?>
mp-wp_genesis 147 <h3><?php _e('Common settings'); ?></h3>
mp-wp_genesis 148 <table class="form-table">
mp-wp_genesis 149 <tr>
mp-wp_genesis 150 <th><label><input name="selection" type="radio" value="" class="tog" <?php checked('', $permalink_structure); ?> /> <?php _e('Default'); ?></label></th>
mp-wp_genesis 151 <td><code><?php echo get_option('home'); ?>/?p=123</code></td>
mp-wp_genesis 152 </tr>
mp-wp_genesis 153 <tr>
mp-wp_genesis 154 <th><label><input name="selection" type="radio" value="<?php echo $structures[1]; ?>" class="tog" <?php checked($structures[1], $permalink_structure); ?> /> <?php _e('Day and name'); ?></label></th>
mp-wp_genesis 155 <td><code><?php echo get_option('home') . $prefix . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/sample-post/'; ?></code></td>
mp-wp_genesis 156 </tr>
mp-wp_genesis 157 <tr>
mp-wp_genesis 158 <th><label><input name="selection" type="radio" value="<?php echo $structures[2]; ?>" class="tog" <?php checked($structures[2], $permalink_structure); ?> /> <?php _e('Month and name'); ?></label></th>
mp-wp_genesis 159 <td><code><?php echo get_option('home') . $prefix . '/' . date('Y') . '/' . date('m') . '/sample-post/'; ?></code></td>
mp-wp_genesis 160 </tr>
mp-wp_genesis 161 <tr>
mp-wp_genesis 162 <th><label><input name="selection" type="radio" value="<?php echo $structures[3]; ?>" class="tog" <?php checked($structures[3], $permalink_structure); ?> /> <?php _e('Numeric'); ?></label></th>
mp-wp_genesis 163 <td><code><?php echo get_option('home') . $prefix ; ?>/archives/123</code></td>
mp-wp_genesis 164 </tr>
mp-wp_genesis 165 <tr>
mp-wp_genesis 166 <th>
mp-wp_genesis 167 <label><input name="selection" id="custom_selection" type="radio" value="custom" class="tog"
mp-wp_genesis 168 <?php if ( !in_array($permalink_structure, $structures) ) { ?>
mp-wp_genesis 169 checked="checked"
mp-wp_genesis 170 <?php } ?>
mp-wp_genesis 171 />
mp-wp_genesis 172 <?php _e('Custom Structure'); ?>
mp-wp_genesis 173 </label>
mp-wp_genesis 174 </th>
mp-wp_genesis 175 <td>
mp-wp_genesis 176 <input name="permalink_structure" id="permalink_structure" type="text" value="<?php echo attribute_escape($permalink_structure); ?>" class="regular-text code" />
mp-wp_genesis 177 </td>
mp-wp_genesis 178 </tr>
mp-wp_genesis 179 </table>
mp-wp_genesis 180
mp-wp_genesis 181 <h3><?php _e('Optional'); ?></h3>
mp-wp_genesis 182 <?php if ($is_apache) : ?>
mp-wp_genesis 183 <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>
mp-wp_genesis 184 <?php else : ?>
mp-wp_genesis 185 <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>
mp-wp_genesis 186 <?php endif; ?>
mp-wp_genesis 187
mp-wp_genesis 188 <table class="form-table">
mp-wp_genesis 189 <tr>
mp-wp_genesis 190 <th><label for="category_base"><?php _e('Category base'); ?></label></th>
mp-wp_genesis 191 <td><input name="category_base" id="category_base" type="text" value="<?php echo attribute_escape($category_base); ?>" class="regular-text code" /></td>
mp-wp_genesis 192 </tr>
mp-wp_genesis 193 <tr>
mp-wp_genesis 194 <th><label for="tag_base"><?php _e('Tag base'); ?></label></th>
mp-wp_genesis 195 <td><input name="tag_base" id="tag_base" type="text" value="<?php echo attribute_escape($tag_base); ?>" class="regular-text code" /></td>
mp-wp_genesis 196 </tr>
mp-wp_genesis 197 <?php do_settings_fields('permalink', 'optional'); ?>
mp-wp_genesis 198 </table>
mp-wp_genesis 199
mp-wp_genesis 200 <?php do_settings_sections('permalink'); ?>
mp-wp_genesis 201
mp-wp_genesis 202 <p class="submit">
mp-wp_genesis 203 <input type="submit" name="submit" class="button-primary" value="<?php _e('Save Changes') ?>" />
mp-wp_genesis 204 </p>
mp-wp_genesis 205 </form>
mp-wp_genesis 206 <?php if ( $permalink_structure && !$usingpi && !$writable ) : ?>
mp-wp_genesis 207 <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>
mp-wp_genesis 208 <form action="options-permalink.php" method="post">
mp-wp_genesis 209 <?php wp_nonce_field('update-permalink') ?>
mp-wp_genesis 210 <p><textarea rows="6" class="large-text readonly" name="rules" id="rules" readonly="readonly"><?php echo wp_specialchars($wp_rewrite->mod_rewrite_rules()); ?></textarea></p>
mp-wp_genesis 211 </form>
mp-wp_genesis 212 <?php endif; ?>
mp-wp_genesis 213
mp-wp_genesis 214 </div>
mp-wp_genesis 215
mp-wp_genesis 216 <?php require('./admin-footer.php'); ?>