Make WordPress Core


Ignore:
Timestamp:
11/19/2004 08:54:16 PM (22 years ago)
Author:
rboren
Message:

Permalink love. Wrap mod_rewrite rules in a conditional. Make sure date permalinks are sane. Add get_year_link().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/template-functions-links.php

    r1860 r1868  
    106106}
    107107
     108function get_year_link($year) {
     109    global $querystring_start, $querystring_equal;
     110    if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
     111        $yearlink = get_year_permastruct();
     112    if (!empty($yearlink)) {
     113        $yearlink = str_replace('%year%', $year, $yearlink);
     114        return get_settings('home') . $yearlink;
     115    } else {
     116        return get_settings('home') .'/'. get_settings('blogfilename') .$querystring_start.'m'.$querystring_equal.$year;
     117    }
     118}
     119
    108120function get_month_link($year, $month) {
    109121    global $querystring_start, $querystring_equal;
    110122    if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
    111123    if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
    112     if ('' != get_settings('permalink_structure')) {
    113         $permalink = get_settings('permalink_structure');
    114 
    115         // If the permalink structure does not contain year and month, make
    116         // one that does.
    117         if (! (strstr($permalink, '%year%') && strstr($permalink, '%monthnum%'))
    118             || preg_match('/%category%.*(%year%|%monthnum%|%day%)/', $permalink)) {
    119             $front = substr($permalink, 0, strpos($permalink, '%'));
    120             $permalink = $front . '%year%/%monthnum%/';
    121         }
    122 
    123         $off = strpos($permalink, '%monthnum%');
    124         $offset = $off + 11;
    125         $monthlink = substr($permalink, 0, $offset);
    126         if ('/' != substr($monthlink, -1)) $monthlink = substr($monthlink, 0, -1);
     124        $monthlink = get_month_permastruct();
     125    if (!empty($monthlink)) {
    127126        $monthlink = str_replace('%year%', $year, $monthlink);
    128127        $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
    129         $monthlink = str_replace('%post_id%', '', $monthlink);
    130         $monthlink = str_replace('%category%', '', $monthlink);
    131128        return get_settings('home') . $monthlink;
    132129    } else {
     
    140137    if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
    141138    if (!$day) $day = gmdate('j', time()+(get_settings('gmt_offset') * 3600));
    142     if ('' != get_settings('permalink_structure')) {
    143         $permalink = get_settings('permalink_structure');
    144 
    145         // If the permalink structure does not contain year, month, and day,
    146         // make one that does.
    147         if (! (strstr($permalink, '%year%') && strstr($permalink, '%monthnum%')&& strstr($permalink, '%day%'))
    148             || preg_match('/%category%.*(%year%|%monthnum%|%day%)/', $permalink)) {
    149             $front = substr($permalink, 0, strpos($permalink, '%'));
    150             $permalink = $front . '%year%/%monthnum%/%day%/';
    151         }
    152 
    153         $off = strpos($permalink, '%day%');
    154         $offset = $off + 6;
    155         $daylink = substr($permalink, 0, $offset);
    156         if ('/' != substr($daylink, -1)) $daylink = substr($daylink, 0, -1);
     139
     140        $daylink = get_day_permastruct();
     141    if (!empty($daylink)) {
    157142        $daylink = str_replace('%year%', $year, $daylink);
    158143        $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
    159144        $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
    160         $daylink = str_replace('%post_id%', '', $daylink);
    161         $daylink = str_replace('%category%', '', $daylink);
    162145        return get_settings('home') . $daylink;
    163146    } else {
Note: See TracChangeset for help on using the changeset viewer.