Alpha functionality of new permalink structure as per previous discussions.
git-svn-id: http://svn.automattic.com/wordpress/trunk@470 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8f63b6f171
commit
d9c1f28844
|
@ -1405,6 +1405,29 @@ function trackback_rdf($timezone = 0) {
|
||||||
|
|
||||||
|
|
||||||
/***** Permalink tags *****/
|
/***** Permalink tags *****/
|
||||||
|
function get_permalink($id=false) {
|
||||||
|
global $post;
|
||||||
|
if (!$id) {
|
||||||
|
if (get_settings('permalink_structure')) {
|
||||||
|
$unixtime = strtotime($post->post_date);
|
||||||
|
$rewritecode = array(
|
||||||
|
'%year%',
|
||||||
|
'%monthnum%',
|
||||||
|
'%day%',
|
||||||
|
'%postname%'
|
||||||
|
);
|
||||||
|
$rewritereplace = array(
|
||||||
|
date('Y', $unixtime),
|
||||||
|
date('n', $unixtime),
|
||||||
|
date('j', $unixtime),
|
||||||
|
$post->post_name
|
||||||
|
);
|
||||||
|
return str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure'));
|
||||||
|
} else { // if they're not using the fancy permalink option
|
||||||
|
return $file.$querystring_start.'p'.$querystring_equal.$post->ID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function permalink_anchor($mode = 'id') {
|
function permalink_anchor($mode = 'id') {
|
||||||
global $id, $post;
|
global $id, $post;
|
||||||
|
@ -1434,25 +1457,7 @@ function permalink_link($file='', $mode = 'id') {
|
||||||
$anchor = $id;
|
$anchor = $id;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$archive_mode = get_settings('archive_mode');
|
echo get_permalink();
|
||||||
switch($archive_mode) {
|
|
||||||
case 'daily':
|
|
||||||
echo $file.$querystring_start.'m'.$querystring_equal.substr($post->post_date,0,4).substr($post->post_date,5,2).substr($postdata['Date'],8,2).'#post-'.$anchor;
|
|
||||||
break;
|
|
||||||
case 'monthly':
|
|
||||||
echo $file.$querystring_start.'m'.$querystring_equal.substr($post->post_date,0,4).substr($post->post_date,5,2).'#post-'.$anchor;
|
|
||||||
break;
|
|
||||||
case 'weekly':
|
|
||||||
if((!isset($cacheweekly)) || (empty($cacheweekly[$postdata['Date']]))) {
|
|
||||||
$cacheweekly[$post->post_date] = $wpdb->get_var("SELECT WEEK('$post->post_date')");
|
|
||||||
++$querycount;
|
|
||||||
}
|
|
||||||
echo $file.$querystring_start.'m'.$querystring_equal.substr($post->post_date,0,4).$querystring_separator.'w'.$querystring_equal.$cacheweekly[$post->post_date].'#post-'.$anchor;
|
|
||||||
break;
|
|
||||||
case 'postbypost':
|
|
||||||
echo $file.$querystring_start.'p'.$querystring_equal.$id;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function permalink_single($file='') {
|
function permalink_single($file='') {
|
||||||
|
|
|
@ -13,7 +13,7 @@ require_once ($curpath.$b2inc.'/b2functions.php');
|
||||||
require_once ($curpath.$b2inc.'/xmlrpc.inc');
|
require_once ($curpath.$b2inc.'/xmlrpc.inc');
|
||||||
require_once ($curpath.$b2inc.'/xmlrpcs.inc');
|
require_once ($curpath.$b2inc.'/xmlrpcs.inc');
|
||||||
|
|
||||||
$b2varstoreset = array('m','p','posts','w','c', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby');
|
$b2varstoreset = array('m','p','posts','w','c', 'cat','withcomments','s','search','exact', 'sentence','poststart','postend','preview','debug', 'calendar','page','paged','more','tb', 'pb','author','order','orderby', 'monthnum');
|
||||||
|
|
||||||
for ($i=0; $i<count($b2varstoreset); $i += 1) {
|
for ($i=0; $i<count($b2varstoreset); $i += 1) {
|
||||||
$b2var = $b2varstoreset[$i];
|
$b2var = $b2varstoreset[$i];
|
||||||
|
@ -82,6 +82,26 @@ if ($m != '') {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($year != '') {
|
||||||
|
$year = '' . intval($year);
|
||||||
|
$where .= ' AND YEAR(post_date)=' . $year;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($monthnum != '') {
|
||||||
|
$monthnum = '' . intval($monthnum);
|
||||||
|
$where .= ' AND MONTH(post_date)=' . $monthnum;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($day != '') {
|
||||||
|
$hay = '' . intval($day);
|
||||||
|
$where .= ' AND DAYOFMONTH(post_date)=' . $day;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($name != '') {
|
||||||
|
$name = preg_replace('/[^a-z0-9-]/', '', $name);
|
||||||
|
$where .= " AND post_name = '$name'";
|
||||||
|
}
|
||||||
|
|
||||||
if ($w != '') {
|
if ($w != '') {
|
||||||
$w = ''.intval($w);
|
$w = ''.intval($w);
|
||||||
$where .= ' AND WEEK(post_date, 1)=' . $w;
|
$where .= ' AND WEEK(post_date, 1)=' . $w;
|
||||||
|
@ -206,7 +226,7 @@ if ((!$whichcat) && (!$m) && (!$p) && (!$w) && (!$s) && empty($poststart) && emp
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !empty($postend) && ($postend > $poststart) && (!$m) &&(!$w) && (!$whichcat) && (!$s) && (!$p)) {
|
if ( !empty($postend) && ($postend > $poststart) && (!$m) && !$month && !$year && !$day &&(!$w) && (!$whichcat) && (!$s) && (!$p)) {
|
||||||
if ($what_to_show == 'posts' || ($what_to_show == 'paged' && (!$paged))) {
|
if ($what_to_show == 'posts' || ($what_to_show == 'paged' && (!$paged))) {
|
||||||
$poststart = intval($poststart);
|
$poststart = intval($poststart);
|
||||||
$postend = intval($postend);
|
$postend = intval($postend);
|
||||||
|
@ -243,7 +263,7 @@ if ( !empty($postend) && ($postend > $poststart) && (!$m) &&(!$w) && (!$whichcat
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif (($m) || ($p) || ($w) || ($s) || ($whichcat) || ($author)) {
|
elseif (($m) || ($p) || ($w) || ($s) || ($whichcat) || ($author) || $month || $year || $day) {
|
||||||
$limits = '';
|
$limits = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -284,4 +304,8 @@ if ($preview) {
|
||||||
// error_log("$request");
|
// error_log("$request");
|
||||||
// echo $request;
|
// echo $request;
|
||||||
$posts = $wpdb->get_results($request);
|
$posts = $wpdb->get_results($request);
|
||||||
|
|
||||||
|
if (1 == count($posts)) {
|
||||||
|
$more = 1; $c = 1; $single = 1;
|
||||||
|
}
|
||||||
?>
|
?>
|
|
@ -55,8 +55,9 @@ require_once($abspath.'wp-links/links.php');
|
||||||
|
|
||||||
<?php include($abspath . 'b2comments.php'); ?>
|
<?php include($abspath . 'b2comments.php'); ?>
|
||||||
|
|
||||||
<?php } } // end foreach, end if any posts ?>
|
<?php } } else { // end foreach, end if any posts ?>
|
||||||
|
<p>Sorry, no posts matched your criteria.</p>
|
||||||
|
<?php } ?>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ require('wp-install-helper.php');
|
||||||
$step = $HTTP_GET_VARS['step'];
|
$step = $HTTP_GET_VARS['step'];
|
||||||
if (!$step) $step = 0;
|
if (!$step) $step = 0;
|
||||||
if (!step) $step = 0;
|
if (!step) $step = 0;
|
||||||
|
update_option('blogdescription', 'hahahah');
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||||
|
@ -76,6 +77,7 @@ foreach($posts as $post) {
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$wpdb->query("INSERT INTO `$tableoptions` (`option_id`, `blog_id`, `option_name`, `option_can_override`, `option_type`, `option_value`, `option_width`, `option_height`, `option_description`, `option_admin_level`) VALUES ('', '0', 'permalink_structure', 'Y', '3', '', '20', '8', 'How the permalinks for your site are constructed.', '8');");
|
||||||
?>
|
?>
|
||||||
<strong>Done.</strong> </p>
|
<strong>Done.</strong> </p>
|
||||||
<p>See, that didn’t hurt a bit. All done!</p>
|
<p>See, that didn’t hurt a bit. All done!</p>
|
||||||
|
|
|
@ -0,0 +1,143 @@
|
||||||
|
<?php
|
||||||
|
$title = 'Permalink Options';
|
||||||
|
$this_file = 'wp-options.php';
|
||||||
|
|
||||||
|
function add_magic_quotes($array) {
|
||||||
|
foreach ($array as $k => $v) {
|
||||||
|
if (is_array($v)) {
|
||||||
|
$array[$k] = add_magic_quotes($v);
|
||||||
|
} else {
|
||||||
|
$array[$k] = addslashes($v);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $array;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!get_magic_quotes_gpc()) {
|
||||||
|
$HTTP_GET_VARS = add_magic_quotes($HTTP_GET_VARS);
|
||||||
|
$HTTP_POST_VARS = add_magic_quotes($HTTP_POST_VARS);
|
||||||
|
$HTTP_COOKIE_VARS = add_magic_quotes($HTTP_COOKIE_VARS);
|
||||||
|
}
|
||||||
|
|
||||||
|
$b2varstoreset = array('action','standalone', 'option_group_id');
|
||||||
|
for ($i=0; $i<count($b2varstoreset); $i += 1) {
|
||||||
|
$b2var = $b2varstoreset[$i];
|
||||||
|
if (!isset($$b2var)) {
|
||||||
|
if (empty($HTTP_POST_VARS["$b2var"])) {
|
||||||
|
if (empty($HTTP_GET_VARS["$b2var"])) {
|
||||||
|
$$b2var = '';
|
||||||
|
} else {
|
||||||
|
$$b2var = $HTTP_GET_VARS["$b2var"];
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$$b2var = $HTTP_POST_VARS["$b2var"];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once('optionhandler.php');
|
||||||
|
|
||||||
|
if ($HTTP_POST_VARS['permalink_structure'] != '') {
|
||||||
|
update_option('permalink_structure', $HTTP_POST_VARS['permalink_structure']);
|
||||||
|
$permalink_structure = $HTTP_POST_VARS['permalink_structure'];
|
||||||
|
} else {
|
||||||
|
$permalink_structure = get_settings('permalink_structure');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
switch($action) {
|
||||||
|
|
||||||
|
default:
|
||||||
|
$standalone = 0;
|
||||||
|
include_once('b2header.php');
|
||||||
|
if ($user_level <= 3) {
|
||||||
|
die("You have no right to edit the options for this blog.<br>Ask for a promotion to your <a href=\"mailto:$admin_email\">blog admin</a> :)");
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
<ul id="adminmenu2">
|
||||||
|
<?php
|
||||||
|
//we need to iterate through the available option groups.
|
||||||
|
$option_groups = $wpdb->get_results("SELECT group_id, group_name, group_desc, group_longdesc FROM $tableoptiongroups ORDER BY group_id");
|
||||||
|
foreach ($option_groups as $option_group) {
|
||||||
|
if ($option_group->group_id == $option_group_id) {
|
||||||
|
$current_desc=$option_group->group_desc;
|
||||||
|
$current_long_desc = $option_group->group_longdesc;
|
||||||
|
echo(" <li><a id=\"current2\" href=\"$this_file?option_group_id={$option_group->group_id}\" title=\"{$option_group->group_desc}\">{$option_group->group_name}</a></li>\n");
|
||||||
|
} else {
|
||||||
|
echo(" <li><a href=\"$this_file?option_group_id={$option_group->group_id}\" title=\"{$option_group->group_desc}\">{$option_group->group_name}</a></li>\n");
|
||||||
|
}
|
||||||
|
} // end for each group
|
||||||
|
?>
|
||||||
|
<li><a href="wp-options-permalink.php">Permalinks</a></li>
|
||||||
|
</ul>
|
||||||
|
<br clear="all" />
|
||||||
|
<div class="wrap">
|
||||||
|
<h2>Edit Permalink Structure</h2>
|
||||||
|
<p>WordPress offers you the ability to create a custom URI structure for your permalinks and archives. The following “tags” are available:</p>
|
||||||
|
<ul>
|
||||||
|
<li><code>%year%</code> --- The year of the post, 4 digits, for example 2003 </li>
|
||||||
|
<li><code>%monthnum%</code> --- Two digit month, for example 05</li>
|
||||||
|
<li><code>%day% </code>--- Day of the month, for example 28</li>
|
||||||
|
<li><code>%postname%</code> --- A sanitized version of the title of the post. So "This Is A Great Post!" becomes "this-is-a-great-post" </li>
|
||||||
|
<li><code>%category%</code> --- Category name of the post. For example "general". <strong>Not done yet. </strong></li>
|
||||||
|
</ul>
|
||||||
|
<p>So for example a value like <code>/%year%/%monthnum%/%day%/%postname%</code> could give you a permalink like <code>/2003/05/23/my-cheese-sandwich</code> . For this to work you'll need mod_rewrite installed on your server for the rule generation rule to work below. In the future there may be other options. </p>
|
||||||
|
<form name="form" action="wp-options-permalink.php" method="post">
|
||||||
|
<p>Use the template tags above to create a virtual site structure:</p>
|
||||||
|
<p>
|
||||||
|
<input name="permalink_structure" type="text" style="width: 100%;" value="<?php echo $permalink_structure; ?>" />
|
||||||
|
</p>
|
||||||
|
<p>
|
||||||
|
<input type="submit" name="Submit" value="Update">
|
||||||
|
</p>
|
||||||
|
</form>
|
||||||
|
<p>Using the permalink structure value you currently have, <code><?php echo $permalink_structure; ?></code>, these are the mod_rewrite rules you should have in your <code>.htaccess</code> file.</p>
|
||||||
|
<?php
|
||||||
|
$site_root = str_replace('http://', '', trim(get_settings('siteurl')));
|
||||||
|
$site_root = preg_replace('|([^/]*)(.*)|i', '$2', $site_root);
|
||||||
|
if ('/' != substr($site_root, -1)) $site_root = $site_root . '/';
|
||||||
|
|
||||||
|
$rewritecode = array(
|
||||||
|
'%year%',
|
||||||
|
'%monthnum%',
|
||||||
|
'%day%',
|
||||||
|
'%postname%'
|
||||||
|
);
|
||||||
|
$rewritereplace = array(
|
||||||
|
'([0-9]{4})?',
|
||||||
|
'([0-9]{1,2})?',
|
||||||
|
'([0-3][0-9])?',
|
||||||
|
'([0-9a-z-]+)?'
|
||||||
|
);
|
||||||
|
$queryreplace = array (
|
||||||
|
'year=',
|
||||||
|
'monthnum=',
|
||||||
|
'day=',
|
||||||
|
'name='
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$match = str_replace('/', '/?', $permalink_structure);
|
||||||
|
$match = str_replace($rewritecode, $rewritereplace, $match);
|
||||||
|
|
||||||
|
preg_match_all('/%.+?%/', $permalink_structure, $tokens);
|
||||||
|
|
||||||
|
$query = '/index.php?';
|
||||||
|
for ($i = 0; $i < count($tokens[0]); ++$i) {
|
||||||
|
if (0 < $i) $query .= '&';
|
||||||
|
$query .= str_replace($rewritecode, $queryreplace, $tokens[0][$i]) . '$'. ($i + 1);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
<p><code>RewriteEngine On<br />
|
||||||
|
RewriteBase <?php echo $site_root; ?><br />
|
||||||
|
RewriteRule ^<?php echo $match; echo '$ ' . $query ?> [QSA]</code></p>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
include("b2footer.php") ?>
|
|
@ -119,6 +119,7 @@ default:
|
||||||
}
|
}
|
||||||
} // end for each group
|
} // end for each group
|
||||||
?>
|
?>
|
||||||
|
<li><a href="wp-options-permalink.php">Permalinks</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<br clear="all" />
|
<br clear="all" />
|
||||||
<div class="wrap">
|
<div class="wrap">
|
||||||
|
|
Loading…
Reference in New Issue