Fixed %post_id% token handling. Fixed pingback link detection.

git-svn-id: http://svn.automattic.com/wordpress/trunk@640 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
emc3 2003-12-22 23:00:45 +00:00
parent 75f9641bb1
commit c8604702fc
3 changed files with 20 additions and 9 deletions

View File

@ -104,19 +104,22 @@ $rewritecode = array(
'%year%', '%year%',
'%monthnum%', '%monthnum%',
'%day%', '%day%',
'%postname%' '%postname%',
'%post_id%'
); );
$rewritereplace = array( $rewritereplace = array(
'([0-9]{4})?', '([0-9]{4})?',
'([0-9]{1,2})?', '([0-9]{1,2})?',
'([0-9]{1,2})?', '([0-9]{1,2})?',
'([0-9a-z-]+)?' '([0-9a-z-]+)?',
'([0-9]+)?'
); );
$queryreplace = array ( $queryreplace = array (
'year=', 'year=',
'monthnum=', 'monthnum=',
'day=', 'day=',
'name=' 'name=',
'p='
); );

View File

@ -493,13 +493,15 @@ function url_to_postid($url = '') {
'%year%', '%year%',
'%monthnum%', '%monthnum%',
'%day%', '%day%',
'%postname%' '%postname%',
'%post_id%'
); );
$rewritereplace = array( $rewritereplace = array(
'([0-9]{4})?', '([0-9]{4})?',
'([0-9]{1,2})?', '([0-9]{1,2})?',
'([0-9]{1,2})?', '([0-9]{1,2})?',
'([0-9a-z-]+)?' '([0-9a-z-]+)?',
'([0-9]+)?'
); );
// Turn the structure into a regular expression // Turn the structure into a regular expression
@ -516,18 +518,23 @@ function url_to_postid($url = '') {
$name = $tokens[1][$i]; $name = $tokens[1][$i];
$value = $values[$i+1]; $value = $values[$i+1];
// Create a variable named $year, $monthnum, $day, or $postname: // Create a variable named $year, $monthnum, $day, $postname, or $post_id:
$$name = $value; $$name = $value;
} }
// Build a WHERE clause, making the values safe along the way: // If using %post_id%, we're done:
if (intval($post_id)) return intval($post_id);
// Otherwise, build a WHERE clause, making the values safe along the way:
if ($year) $where .= " AND YEAR(post_date) = " . intval($year); if ($year) $where .= " AND YEAR(post_date) = " . intval($year);
if ($monthnum) $where .= " AND MONTH(post_date) = " . intval($monthnum); if ($monthnum) $where .= " AND MONTH(post_date) = " . intval($monthnum);
if ($day) $where .= " AND DAYOFMONTH(post_date) = " . intval($day); if ($day) $where .= " AND DAYOFMONTH(post_date) = " . intval($day);
if ($postname) $where .= " AND post_name = '" . $wpdb->escape($postname) . "' "; if ($postname) $where .= " AND post_name = '" . $wpdb->escape($postname) . "' ";
// Run the query to get the post ID: // Run the query to get the post ID:
return intval($wpdb->get_var("SELECT ID FROM $tableposts WHERE 1 = 1 " . $where)); $id = intval($wpdb->get_var("SELECT ID FROM $tableposts WHERE 1 = 1 " . $where));
return $id;
} }

View File

@ -419,7 +419,8 @@ function get_permalink($id=false) {
date('Y', $unixtime), date('Y', $unixtime),
date('n', $unixtime), date('n', $unixtime),
date('j', $unixtime), date('j', $unixtime),
$post->post_name $post->post_name,
$post->ID
); );
return $siteurl . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure')); return $siteurl . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure'));
} else { // if they're not using the fancy permalink option } else { // if they're not using the fancy permalink option