home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 104 / MacAddict_104_2005-04.iso / Software / Internet & Communication / WordPress 1.2.2 freeware.dmg / wordpress / wp-includes / template-functions-links.php < prev    next >
Encoding:
PHP Script  |  2004-05-18  |  5.5 KB  |  155 lines

  1. <?php
  2.  
  3. function the_permalink() {
  4.     echo get_permalink();
  5. }
  6.  
  7. function permalink_link() { // For backwards compatibility
  8.     echo get_permalink();
  9. }
  10.  
  11. function permalink_anchor($mode = 'id') {
  12.     global $id, $post;
  13.     switch(strtolower($mode)) {
  14.         case 'title':
  15.             $title = sanitize_title($post->post_title) . '-' . $id;
  16.             echo '<a id="'.$title.'"></a>';
  17.             break;
  18.         case 'id':
  19.         default:
  20.             echo '<a id="post-'.$id.'"></a>';
  21.             break;
  22.     }
  23. }
  24.  
  25. function permalink_single_rss($file = '') {
  26.     echo get_permalink();
  27. }
  28.  
  29. function get_permalink($id=false) {
  30.     global $post, $wpdb, $tableposts;
  31.     global $querystring_start, $querystring_equal;
  32.  
  33.     $rewritecode = array(
  34.         '%year%',
  35.         '%monthnum%',
  36.         '%day%',
  37.         '%hour%',
  38.         '%minute%',
  39.         '%second%',
  40.         '%postname%',
  41.         '%post_id%'
  42.     );
  43.     if (!$id) {
  44.         if ('' != get_settings('permalink_structure')) {
  45.         $unixtime = strtotime($post->post_date);
  46.             $rewritereplace = array(
  47.                 date('Y', $unixtime),
  48.                 date('m', $unixtime),
  49.                 date('d', $unixtime),
  50.                 date('H', $unixtime),
  51.                 date('i', $unixtime),
  52.                 date('s', $unixtime),
  53.                 $post->post_name,
  54.                 $post->ID
  55.             );
  56.             return get_settings('home') . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure'));
  57.         } else { // if they're not using the fancy permalink option
  58.             return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$post->ID;
  59.         }
  60.     } else { // if an ID is given
  61.         $idpost = $wpdb->get_row("SELECT post_date, post_name FROM $tableposts WHERE ID = $id");
  62.         if ('' != get_settings('permalink_structure')) {
  63.         $unixtime = strtotime($idpost->post_date);
  64.             $rewritereplace = array(
  65.                 date('Y', $unixtime),
  66.                 date('m', $unixtime),
  67.                 date('d', $unixtime),
  68.                 date('H', $unixtime),
  69.                 date('i', $unixtime),
  70.                 date('s', $unixtime),
  71.                 $idpost->post_name,
  72.                 $id
  73.             );
  74.             return get_settings('home') . str_replace($rewritecode, $rewritereplace, get_settings('permalink_structure'));
  75.         } else {
  76.             return get_settings('home') . '/' . get_settings('blogfilename').$querystring_start.'p'.$querystring_equal.$id;
  77.         }
  78.     }
  79. }
  80.  
  81. function get_month_link($year, $month) {
  82.     global $querystring_start, $querystring_equal;
  83.     if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
  84.     if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
  85.     if ('' != get_settings('permalink_structure')) {
  86.         $off = strpos(get_settings('permalink_structure'), '%monthnum%');
  87.         $offset = $off + 11;
  88.         $monthlink = substr(get_settings('permalink_structure'), 0, $offset);
  89.         if ('/' != substr($monthlink, -1)) $monthlink = substr($monthlink, 0, -1);
  90.         $monthlink = str_replace('%year%', $year, $monthlink);
  91.         $monthlink = str_replace('%monthnum%', zeroise(intval($month), 2), $monthlink);
  92.         $monthlink = str_replace('%post_id%', '', $monthlink);
  93.         return get_settings('home') . $monthlink;
  94.     } else {
  95.         return get_settings('home') .'/'. get_settings('blogfilename') .$querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2);
  96.     }
  97. }
  98.  
  99. function get_day_link($year, $month, $day) {
  100.     global $querystring_start, $querystring_equal;
  101.     if (!$year) $year = gmdate('Y', time()+(get_settings('gmt_offset') * 3600));
  102.     if (!$month) $month = gmdate('m', time()+(get_settings('gmt_offset') * 3600));
  103.     if (!$day) $day = gmdate('j', time()+(get_settings('gmt_offset') * 3600));
  104.     if ('' != get_settings('permalink_structure')) {
  105.         $off = strpos(get_settings('permalink_structure'), '%day%');
  106.         $offset = $off + 6;
  107.         $daylink = substr(get_settings('permalink_structure'), 0, $offset);
  108.         if ('/' != substr($daylink, -1)) $daylink = substr($daylink, 0, -1);
  109.         $daylink = str_replace('%year%', $year, $daylink);
  110.         $daylink = str_replace('%monthnum%', zeroise(intval($month), 2), $daylink);
  111.         $daylink = str_replace('%day%', zeroise(intval($day), 2), $daylink);
  112.         $daylink = str_replace('%post_id%', '', $daylink);
  113.         return get_settings('home') . $daylink;
  114.     } else {
  115.         return get_settings('home') .'/'. get_settings('blogfilename') .$querystring_start.'m'.$querystring_equal.$year.zeroise($month, 2).zeroise($day, 2);
  116.     }
  117. }
  118.  
  119. function edit_post_link($link = 'Edit This', $before = '', $after = '') {
  120.     global $user_level, $post;
  121.  
  122.     get_currentuserinfo();
  123.  
  124.     if ($user_level > 0) {
  125.         $authordata = get_userdata($post->post_author);
  126.         if ($user_level < $authordata->user_level) {
  127.             return;
  128.         }
  129.     } else {
  130.         return;
  131.     }
  132.  
  133.     $location = get_settings('siteurl') . "/wp-admin/post.php?action=edit&post=$post->ID";
  134.     echo "$before <a href=\"$location\">$link</a> $after";
  135. }
  136.  
  137. function edit_comment_link($link = 'Edit This', $before = '', $after = '') {
  138.     global $user_level, $post, $comment;
  139.  
  140.     get_currentuserinfo();
  141.  
  142.     if ($user_level > 0) {
  143.         $authordata = get_userdata($post->post_author);
  144.         if ($user_level < $authordata->user_level) {
  145.             return;
  146.         }
  147.     } else {
  148.         return;
  149.     }
  150.  
  151.     $location = get_settings('siteurl') . "/wp-admin/post.php?action=editcomment&comment=$comment->comment_ID";
  152.     echo "$before <a href='$location'>$link</a> $after";
  153. }
  154.  
  155. ?>