PHP Cross Reference of WordPress Subversion HEAD

[ Index ]     [ Classes ]     [ Functions ]     [ Variables ]     [ Constants ]

title

Body

[close]

/wp-admin/ -> options-permalink.php (source)

   1  <?php
   2  require_once ('admin.php');
   3  
   4  $title = __('Permalink Options');
   5  $parent_file = 'options-general.php';
   6  
   7  function add_js() {
   8  ?>
   9  <script type="text/javascript">
  10  //<![CDATA[
  11  function GetElementsWithClassName(elementName, className) {
  12  var allElements = document.getElementsByTagName(elementName);
  13  var elemColl = new Array();
  14  for (i = 0; i < allElements.length; i++) {
  15  if (allElements[i].className == className) {
  16  elemColl[elemColl.length] = allElements[i];
  17  }
  18  }
  19  return elemColl;
  20  }
  21  
  22  function upit() {
  23  var inputColl = GetElementsWithClassName('input', 'tog');
  24  var structure = document.getElementById('permalink_structure');
  25  var inputs = '';
  26  for (i = 0; i < inputColl.length; i++) {
  27  if ( inputColl[i].checked && inputColl[i].value != '') {
  28  inputs += inputColl[i].value + ' ';
  29  }
  30  }
  31  inputs = inputs.substr(0,inputs.length - 1);
  32  if ( 'custom' != inputs )
  33  structure.value = inputs;
  34  }
  35  
  36  function blurry() {
  37  if (!document.getElementById) return;
  38  
  39  var structure = document.getElementById('permalink_structure');
  40  structure.onfocus = function () { document.getElementById('custom_selection').checked = 'checked'; }
  41  
  42  var aInputs = document.getElementsByTagName('input');
  43  
  44  for (var i = 0; i < aInputs.length; i++) {
  45  aInputs[i].onclick = aInputs[i].onkeyup = upit;
  46  }
  47  }
  48  
  49  window.onload = blurry;
  50  //]]>
  51  </script>
  52  <?php
  53  }
  54  add_filter('admin_head', 'add_js');
  55  
  56  include ('admin-header.php');
  57  
  58  $home_path = get_home_path();
  59  
  60  if ( isset($_POST['permalink_structure']) || isset($_POST['category_base']) ) {
  61      check_admin_referer('update-permalink');
  62  
  63      if ( isset($_POST['permalink_structure']) ) {
  64          $permalink_structure = $_POST['permalink_structure'];
  65          if (! empty($permalink_structure) )
  66              $permalink_structure = preg_replace('#/+#', '/', '/' . $_POST['permalink_structure']);
  67          $wp_rewrite->set_permalink_structure($permalink_structure);
  68      }
  69  
  70      if ( isset($_POST['category_base']) ) {
  71          $category_base = $_POST['category_base'];
  72          if (! empty($category_base) )
  73              $category_base = preg_replace('#/+#', '/', '/' . $_POST['category_base']);
  74          $wp_rewrite->set_category_base($category_base);
  75      }
  76  
  77      if ( isset($_POST['tag_base']) ) {
  78          $tag_base = $_POST['tag_base'];
  79          if (! empty($tag_base) )
  80              $tag_base = preg_replace('#/+#', '/', '/' . $_POST['tag_base']);
  81          $wp_rewrite->set_tag_base($tag_base);
  82      }
  83  }
  84  
  85  $permalink_structure = get_option('permalink_structure');
  86  $category_base = get_option('category_base');
  87  $tag_base = get_option( 'tag_base' );
  88  
  89  if ( (!file_exists($home_path.'.htaccess') && is_writable($home_path)) || is_writable($home_path.'.htaccess') )
  90      $writable = true;
  91  else
  92      $writable = false;
  93  
  94  if ($wp_rewrite->using_index_permalinks())
  95      $usingpi = true;
  96  else
  97      $usingpi = false;
  98  
  99  $wp_rewrite->flush_rules();
 100  ?>
 101  
 102  <?php if (isset($_POST['submit'])) : ?>
 103  <div id="message" class="updated fade"><p><?php
 104  if ( $permalink_structure && !$usingpi && !$writable )
 105      _e('You should update your .htaccess now.');
 106  else
 107      _e('Permalink structure updated.');
 108  ?></p></div>
 109  <?php endif; ?>
 110  
 111  <div class="wrap">
 112    <h2><?php _e('Customize Permalink Structure') ?></h2>
 113  <form name="form" action="options-permalink.php" method="post">
 114  <?php wp_nonce_field('update-permalink') ?>
 115  <p class="submit"><input type="submit" name="submit" value="<?php _e('Update Permalink Structure &raquo;') ?>" /></p>
 116    <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>
 117  
 118  <?php
 119  $prefix = '';
 120  
 121  if ( ! got_mod_rewrite() )
 122      $prefix = '/index.php';
 123  
 124  $structures = array(
 125      '',
 126      $prefix . '/%year%/%monthnum%/%day%/%postname%/',
 127      $prefix . '/archives/%post_id%'
 128      );
 129  ?>
 130  <h3><?php _e('Common options:'); ?></h3>
 131  <p>
 132      <label>
 133  <input name="selection" type="radio" value="" class="tog" <?php checked('', $permalink_structure); ?> />
 134  <?php _e('Default'); ?><br /> <span> <?php echo _c('&raquo;|Used as a list bullet'); ?> <code><?php echo get_option('home'); ?>/?p=123</code></span>
 135     </label>
 136  </p>
 137  <p>
 138      <label>
 139  <input name="selection" type="radio" value="<?php echo $structures[1]; ?>" class="tog" <?php checked($structures[1], $permalink_structure); ?> />
 140  <?php _e('Date and name based'); ?><br /> <span> <?php echo _c('&raquo;|Used as a list bullet'); ?> <code><?php echo get_option('home') . $prefix . '/' . date('Y') . '/' . date('m') . '/' . date('d') . '/sample-post/'; ?></code></span>
 141     </label>
 142  </p>
 143  <p>
 144      <label>
 145  <input name="selection" type="radio" value="<?php echo $structures[2]; ?>" class="tog" <?php checked($structures[2], $permalink_structure); ?> />
 146  <?php _e('Numeric'); ?><br /> <span> <?php echo _c('&raquo;|Used as a list bullet'); ?> <code><?php echo get_option('home') . $prefix  ; ?>/archives/123</code></span>
 147     </label>
 148  </p>
 149  <p>
 150  <label>
 151  <input name="selection" id="custom_selection" type="radio" value="custom" class="tog"
 152  <?php if ( !in_array($permalink_structure, $structures) ) { ?>
 153  checked="checked"
 154  <?php } ?>
 155   />
 156  <?php _e('Custom, specify below'); ?>
 157  </label>
 158  <br />
 159  </p>
 160  <p id="customstructure"><?php _e('Custom structure'); ?>: <input name="permalink_structure" id="permalink_structure" type="text" class="code" style="width: 60%;" value="<?php echo attribute_escape($permalink_structure); ?>" size="50" /></p>
 161  
 162  <h3><?php _e('Optional'); ?></h3>
 163  <?php if ($is_apache) : ?>
 164      <p><?php _e('If you like, you may enter custom bases 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/topics/uncategorized/</code>. If you leave these blank the defaults will be used.') ?></p>
 165  <?php else : ?>
 166      <p><?php _e('If you like, you may enter custom bases 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>
 167  <?php endif; ?>
 168      <p>
 169    <?php _e('Category base'); ?>: <input name="category_base" id="category_base" type="text" class="code"  value="<?php echo attribute_escape($category_base); ?>" size="30" />
 170       </p>
 171        <p>
 172        <?php _e('Tag base'); ?>: <input name="tag_base" id="tag_base" type="text" class="code"  value="<?php echo attribute_escape($tag_base); ?>" size="30" />
 173       </p>
 174      <p class="submit">
 175        <input type="submit" name="submit" value="<?php _e('Update Permalink Structure &raquo;') ?>" />
 176      </p>
 177    </form>
 178  <?php if ( $permalink_structure && !$usingpi && !$writable ) : ?>
 179    <p><?php _e('If your <code>.htaccess</code> file were <a href="http://codex.wordpress.org/Make_a_Directory_Writable">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>
 180  <form action="options-permalink.php" method="post">
 181  <?php wp_nonce_field('update-permalink') ?>
 182      <p><textarea rows="5" style="width: 98%;" name="rules" id="rules"><?php echo wp_specialchars($wp_rewrite->mod_rewrite_rules()); ?></textarea></p>
 183  </form>
 184  <?php endif; ?>
 185  
 186  </div>
 187  
 188  <?php require ('./admin-footer.php'); ?>


Generated Thu Dec 6 06:47:08 2007 for RedAlt XRefs Cross-referenced by PHPXref 0.6 and RedAlt