Some style cleanup. Category base and additional URI options from Jay McCarthy.

git-svn-id: http://svn.automattic.com/wordpress/trunk@1227 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2004-05-05 07:34:41 +00:00
parent 9e9589e6f9
commit 5a391b5bc8
6 changed files with 135 additions and 48 deletions

View File

@ -25,8 +25,12 @@ require_once('./optionhandler.php');
if ($_POST['submit']) {
update_option('permalink_structure', $_POST['permalink_structure']);
$permalink_structure = $_POST['permalink_structure'];
update_option('category_base', $_POST['category_base']);
$category_base = $_POST['category_base'];
} else {
$permalink_structure = get_settings('permalink_structure');
$category_base = get_settings('category_base');
}
@ -43,13 +47,42 @@ if ($_POST['submit']) {
<div class="wrap">
<h2><?php _e('Edit Permalink Structure') ?></h2>
<?php _e('<p>WordPress offers you the ability to create a custom URI structure for your permalinks and archives. The following &#8220;tags&#8221; are available:</p>')?>
<ul>
<li><code>%year%</code> --- <?php _e('The year of the post, 4 digits, for example <code>2004</code>') ?> </li>
<li><code>%monthnum%</code> --- <?php _e('Month of the year, for example <code>05</code>') ?></li>
<li><code>%day% </code>--- <?php _e('Day of the month, for example <code>28</code>') ?></li>
<li><code>%postname%</code> --- <?php _e('A sanitized version of the title of the post. So &#8220;This Is A Great Post!&#8221; becomes &#8220;<code>this-is-a-great-post</code>&#8221; in the URI') ?> </li>
<li><code>%post_id%</code> --- <?php _e('The unique ID # of the post, for example <code>423</code>') ?></li>
</ul>
<dl>
<dt><code>%year%</code></dt>
<dd>
<?php _e('The year of the post, 4 digits, for example <code>2004</code>') ?>
</dd>
<dt><code>%monthnum%</code></dt>
<dd>
<?php _e('Month of the year, for example <code>05</code>') ?>
</dd>
<dt><code>%day%</code></dt>
<dd>
<?php _e('Day of the month, for example <code>28</code>') ?>
</dd>
<dt><code>%hour%</code></dt>
<dd>
<?php _e('Hour of the day, for example <code>15</code>') ?>
</dd>
<dt><code>%minute%</code></dt>
<dd>
<?php _e('Minute of the hour, for example <code>43</code>') ?>
</dd>
<dt><code>%second%</code></dt>
<dd>
<?php _e('Second of the minute, for example <code>33</code>') ?>
</dd>
<dt><code>%postname%</code></dt>
<dd>
<?php _e('A sanitized version of the title of the post. So &#8220;This Is A Great Post!&#8221; becomes &#8220;<code>this-is-a-great-post</code>&#8221; in the URI') ?>
</dd>
<dt><code>%post_id%</code></dt>
<dd>
<?php _e('The unique ID # of the post, for example <code>423</code>') ?>
</dd>
</dl>
<?php _e('<p>So for example a value like:</p>
<p><code>/archives/%year%/%monthnum%/%day%/%postname%/</code> </p>
<p>would give you a permalink like:</p>
@ -58,9 +91,13 @@ if ($_POST['submit']) {
<p><code>/index.php/archives/%year%/%monthnum%/%day%/%postname%/</code> </p>
<p>If you use this option you can ignore the mod_rewrite rules. </p>') ?>
<form name="form" action="options-permalink.php" method="post">
<?php _e('<p>Use the template tags above to create a virtual site structure:</p>') ?>
<p><?php _e('Use the template tags above to create a virtual site structure:') ?></p>
<p>
<input name="permalink_structure" type="text" style="width: 98%;" value="<?php echo $permalink_structure; ?>" />
</p>
<p><?php _e('Enter a path without templates for your categories:') ?> FIXME[THIS WORDING MAKES NO SENSE]</p>
<p>
<input name="category_base" type="text" style="width: 98%;" value="<?php echo $category_base; ?>" />
</p>
<p class="submit">
<input type="submit" name="submit" value="<?php _e('Update Permalink Structure &raquo;') ?>">

View File

@ -803,6 +803,11 @@ function upgrade_110() {
$wpdb->query("INSERT INTO $tableoptions (option_name, option_type, option_value, option_admin_level) VALUES ('home', 3, '', 8)");
}
// Option for category base
if(!$wpdb->get_var("SELECT option_id FROM $tableoptions WHERE option_name = 'category_base'")) {
$wpdb->query("INSERT INTO $tableoptions (option_name, option_type, option_value, option_admin_level) VALUES ('category_base', 3, '', 8)");
}
// Delete unused options
$unusedoptions = array ('blodotgsping_url', 'bodyterminator', 'emailtestonly', 'phoneemail_separator', 'smilies_directory', 'subjectprefix', 'use_bbcode', 'use_blodotgsping', 'use_phoneemail', 'use_quicktags', 'use_weblogsping', 'weblogs_cache_file');
foreach ($unusedoptions as $option) :

View File

@ -50,7 +50,7 @@ if (! empty($_SERVER['PATH_INFO'])) {
}
}
$wpvarstoreset = array('m','p','posts','w', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'year', 'monthnum', 'day', 'name', 'category_name', 'feed', 'author_name');
$wpvarstoreset = array('m','p','posts','w', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'year', 'monthnum', 'day', 'hour', 'minute', 'second', 'name', 'category_name', 'feed', 'author_name');
for ($i=0; $i<count($wpvarstoreset); $i += 1) {
$wpvar = $wpvarstoreset[$i];
@ -132,44 +132,58 @@ $add_hours = intval(get_settings('gmt_offset'));
$add_minutes = intval(60 * (get_settings('gmt_offset') - $add_hours));
$wp_posts_post_date_field = "post_date"; // "DATE_ADD(post_date, INTERVAL '$add_hours:$add_minutes' HOUR_MINUTE)";
// if a month is specified in the querystring, load that month
if ($m != '') {
$m = ''.intval($m);
// If a month is specified in the querystring, load that month
if ('' != $m) {
$m = '' . preg_replace('|[^0-9]|', '', $m);
$where .= ' AND YEAR(post_date)=' . substr($m, 0, 4);
if (strlen($m)>5)
$where .= ' AND MONTH(post_date)=' . substr($m, 4, 2);
if (strlen($m)>7)
$where .= ' AND DAYOFMONTH(post_date)=' . substr($m, 6, 2);
if (strlen($m)>9)
$where .= ' AND HOUR(post_date.)='.substr($m,8,2);
$where .= ' AND HOUR(post_date)=' . substr($m, 8, 2);
if (strlen($m)>11)
$where .= ' AND MINUTE(post_date)=' . substr($m, 10, 2);
if (strlen($m)>13)
$where .= ' AND SECOND(post_date)=' . substr($m, 12, 2);
}
if ($year != '') {
if ('' != $hour) {
$hour = '' . intval($hour);
$where .= " AND HOUR(post_date)='$hour'";
}
if ('' != $minute) {
$minute = '' . intval($minute);
$where .= " AND MINUTE(post_date)='$minute'";
}
if ('' != $second) {
$second = '' . intval($second);
$where .= " AND SECOND(post_date)='$second'";
}
if ('' != $year) {
$year = '' . intval($year);
$where .= " AND YEAR(post_date)='$year'";
}
if ($monthnum != '') {
if ('' != $monthnum) {
$monthnum = '' . intval($monthnum);
$where .= " AND MONTH(post_date)='$monthnum'";
}
if ($day != '') {
if ('' != $day) {
$day = '' . intval($day);
$where .= " AND DAYOFMONTH(post_date)='$day'";
}
if ($name != '') {
if ('' != $name) {
$name = preg_replace('/[^a-z0-9-]/', '', $name);
$where .= " AND post_name = '$name'";
}
if ($w != '') {
if ('' != $w) {
$w = ''.intval($w);
$where .= " AND WEEK(post_date, 1)='$w'";
}

View File

@ -246,6 +246,9 @@ function url_to_postid($url = '') {
'%year%',
'%monthnum%',
'%day%',
'%hour%',
'%minute%',
'%second%',
'%postname%',
'%post_id%'
);
@ -253,6 +256,9 @@ function url_to_postid($url = '') {
'([0-9]{4})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([_0-9a-z-]+)?',
'([0-9]+)?'
);
@ -282,6 +288,9 @@ function url_to_postid($url = '') {
if ($year) $where .= " AND YEAR(post_date) = '" . intval($year) . "'";
if ($monthnum) $where .= " AND MONTH(post_date) = '" . intval($monthnum) . "'";
if ($day) $where .= " AND DAYOFMONTH(post_date) = '" . intval($day) . "'";
if ($hour) $where .= " AND HOUR(post_date) = '" . intval($hour) . "'";
if ($minute) $where .= " AND MINUTE(post_date) = '" . intval($minute) . "'";
if ($second) $where .= " AND SECOND(post_date) = '" . intval($second) . "'";
if ($postname) $where .= " AND post_name = '" . $wpdb->escape($postname) . "' ";
// Run the query to get the post ID:
@ -1187,26 +1196,38 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
}
}
$rewritecode = array(
$rewritecode =
array(
'%year%',
'%monthnum%',
'%day%',
'%hour%',
'%minute%',
'%second%',
'%postname%',
'%post_id%'
);
$rewritereplace = array(
$rewritereplace =
array(
'([0-9]{4})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([0-9]{1,2})?',
'([_0-9a-z-]+)?',
'([0-9]+)?'
);
$queryreplace = array (
$queryreplace =
array (
'year=',
'monthnum=',
'day=',
'hour=',
'minute=',
'second=',
'name=',
'p='
);
@ -1263,7 +1284,7 @@ function rewrite_rules($matches = '', $permalink_structure = '') {
// Code for nice categories and authors, currently not very flexible
$front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
$catmatch = $front . 'category/';
$catmatch = get_settings( 'category_base' ) . '/';
$catmatch = preg_replace('|^/+|', '', $catmatch);
$catfeedmatch = $catmatch . '(.*)/' . $feedregex;

View File

@ -24,7 +24,8 @@ function get_category_link($echo = false, $category_id, $category_nicename) {
$file = get_settings('home') . '/' . get_settings('blogfilename');
$link = $file.$querystring_start.'cat'.$querystring_equal.$cat_ID;
} else {
if ('' == $category_nicename) $category_nicename = $cache_categories[$category_id]->category_nicename;
$category_nicename = $cache_categories[$category_id]->cat_name;
$category_nicename = preg_replace( '|[^a-z0-9-]|i', '', $category_nicename );
// Get any static stuff from the front
$front = substr($permalink_structure, 0, strpos($permalink_structure, '%'));
$link = get_settings('home') . $front . 'category/';

View File

@ -50,6 +50,9 @@ function get_permalink($id=false) {
'%year%',
'%monthnum%',
'%day%',
'%hour%',
'%minute%',
'%second%',
'%postname%',
'%post_id%'
);
@ -60,6 +63,9 @@ function get_permalink($id=false) {
date('Y', $unixtime),
date('m', $unixtime),
date('d', $unixtime),
date('H', $unixtime),
date('i', $unixtime),
date('s', $unixtime),
$post->post_name,
$post->ID
);
@ -75,6 +81,9 @@ function get_permalink($id=false) {
date('Y', $unixtime),
date('m', $unixtime),
date('d', $unixtime),
date('H', $unixtime),
date('i', $unixtime),
date('s', $unixtime),
$idpost->post_name,
$id
);