Make WordPress Core


Ignore:
Timestamp:
02/17/2004 04:56:29 AM (22 years ago)
Author:
saxmatt
Message:

Refactoring of template tags to use filters, use TABS (!!!), and general cleanliness, which is next to godliness. Some get_settings improvements, less globals.

File:
1 edited

Legend:

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

    r841 r885  
    11<?php
    22
     3// Default filters
     4add_filter('the_title', 'convert_chars');
     5add_filter('the_title', 'trim');
     6
     7add_filter('the_title_rss', 'strip_tags');
     8
     9add_filter('the_content', 'convert_smilies');
     10add_filter('the_content', 'convert_chars');
     11add_filter('the_content', 'wpautop');
     12
     13add_filter('the_excerpt', 'convert_smilies');
     14add_filter('the_excerpt', 'autop');
     15add_filter('the_excerpt', 'convert_chars');
     16add_filter('the_excerpt', 'wpautop');
    317
    418function get_the_password_form() {
     
    822    </form>
    923    ";
    10     return $output;
     24    return $output;
    1125}
    1226
    1327function the_ID() {
    14     global $id;
    15     echo $id;
     28    global $id;
     29    echo $id;
    1630}
    1731
    1832function the_title($before = '', $after = '', $echo = true) {
    19     $title = get_the_title();
    20     $title = convert_smilies($title);
    21     if (!empty($title)) {
    22         $title = convert_chars($before.$title.$after);
    23         $title = apply_filters('the_title', $title);
    24         if ($echo)
    25             echo $title;
    26         else
    27             return $title;
    28     }
    29 }
     33    $title = get_the_title();
     34    if (!empty($title)) {
     35        $title = apply_filters('the_title', $before . $title . $after);
     36        if ($echo)
     37            echo $title;
     38        else
     39            return $title;
     40    }
     41}
     42
    3043function the_title_rss() {
    31     $title = get_the_title();
    32     $title = strip_tags($title);
    33     if (trim($title)) {
    34         echo convert_chars($title, 'unicode');
    35     }
    36 }
    37 function the_title_unicode($before='',$after='') {
    38     $title = get_the_title();
    39     $title = convert_bbcode($title);
    40     $title = convert_gmcode($title);
    41     if ($title) {
    42         $title = convert_chars($before.$title.$after);
    43         $title = apply_filters('the_title_unicode', $title);
    44         echo $title;
    45     }
    46 }
     44    $title = get_the_title();
     45    $title = apply_filters('the_title', $title);
     46    $title = apply_filters('the_title_rss', $title):
     47    echo $title;
     48}
     49
    4750function get_the_title() {
    48     global $post;
    49     $output = stripslashes($post->post_title);
    50     if (!empty($post->post_password)) { // if there's a password
    51         $output = 'Protected: ' . $output;
    52     }
    53     return $output;
    54 }
    55 
    56 function the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') {
     51    global $post;
     52    $output = stripslashes($post->post_title);
     53    if (!empty($post->post_password)) { // if there's a password
     54        $output = 'Protected: ' . $output;
     55    }
     56    return $output;
     57}
     58
     59function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
    5760    $content = get_the_content($more_link_text, $stripteaser, $more_file);
    58     $content = convert_bbcode($content);
    59     $content = convert_gmcode($content);
    60     $content = convert_smilies($content);
    61     $content = convert_chars($content, 'html');
    6261    $content = apply_filters('the_content', $content);
    6362    echo $content;
     
    6564
    6665function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) {
    67     $content = get_the_content($more_link_text, $stripteaser, $more_file);
    68     $content = convert_bbcode($content);
    69     $content = convert_gmcode($content);
    70     $content = convert_chars($content, 'unicode');
    71     if ($cut && !$encode_html) {
    72         $encode_html = 2;
    73     }
    74     if ($encode_html == 1) {
    75         $content = htmlspecialchars($content);
    76         $cut = 0;
    77     } elseif ($encode_html == 0) {
    78         $content = make_url_footnote($content);
    79     } elseif ($encode_html == 2) {
    80         $content = strip_tags($content);
    81     }
    82     if ($cut) {
    83         $blah = explode(' ', $content);
    84         if (count($blah) > $cut) {
    85             $k = $cut;
    86             $use_dotdotdot = 1;
    87         } else {
    88             $k = count($blah);
    89             $use_dotdotdot = 0;
    90         }
    91         for ($i=0; $i<$k; $i++) {
    92             $excerpt .= $blah[$i].' ';
    93         }
    94         $excerpt .= ($use_dotdotdot) ? '...' : '';
    95         $content = $excerpt;
    96     }
    97     echo $content;
    98 }
    99 
    100 function the_content_unicode($more_link_text='(more...)', $stripteaser=0, $more_file='') {
    101     $content = get_the_content($more_link_text, $stripteaser, $more_file);
    102     $content = convert_bbcode($content);
    103     $content = convert_gmcode($content);
    104     $content = convert_smilies($content);
    105     $content = convert_chars($content, 'unicode');
    106     $content = apply_filters('the_content_unicode', $content);
    107     echo $content;
    108 }
    109 
    110 function get_the_content($more_link_text='(more...)', $stripteaser=0, $more_file='') {
     66    $content = get_the_content($more_link_text, $stripteaser, $more_file);
     67    $content = apply_filters('the_content', $content);
     68    if ($cut && !$encode_html) {
     69        $encode_html = 2;
     70    }
     71    if ($encode_html == 1) {
     72        $content = htmlspecialchars($content);
     73        $cut = 0;
     74    } elseif ($encode_html == 0) {
     75        $content = make_url_footnote($content);
     76    } elseif ($encode_html == 2) {
     77        $content = strip_tags($content);
     78    }
     79    if ($cut) {
     80        $blah = explode(' ', $content);
     81        if (count($blah) > $cut) {
     82            $k = $cut;
     83            $use_dotdotdot = 1;
     84        } else {
     85            $k = count($blah);
     86            $use_dotdotdot = 0;
     87        }
     88        for ($i=0; $i<$k; $i++) {
     89            $excerpt .= $blah[$i].' ';
     90        }
     91        $excerpt .= ($use_dotdotdot) ? '...' : '';
     92        $content = $excerpt;
     93    }
     94    echo $content;
     95}
     96
     97function get_the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
    11198    global $id, $post, $more, $single, $withcomments, $page, $pages, $multipage, $numpages;
    112     global $HTTP_SERVER_VARS, $HTTP_COOKIE_VARS, $preview, $cookiehash;
    113     global $querystring_start, $querystring_equal, $querystring_separator;
     99    global $HTTP_SERVER_VARS, $preview, $cookiehash;
    114100    global $pagenow;
    115101    $output = '';
    116102
    117103    if (!empty($post->post_password)) { // if there's a password
    118         if ($HTTP_COOKIE_VARS['wp-postpass_'.$cookiehash] != $post->post_password) {  // and it doesn't match the cookie
     104        if ($_COOKIE['wp-postpass_'.$cookiehash] != $post->post_password) {  // and it doesn't match the cookie
    119105            $output = get_the_password_form();
    120106            return $output;
     
    149135
    150136function the_excerpt() {
    151     $excerpt = get_the_excerpt();
    152     $excerpt = convert_bbcode($excerpt);
    153     $excerpt = convert_gmcode($excerpt);
    154     $excerpt = convert_smilies($excerpt);
    155     $excerpt = convert_chars($excerpt, 'html');
    156     $excerpt = apply_filters('the_excerpt', $excerpt);
    157     echo $excerpt;
     137    echo apply_filters('the_excerpt', get_the_excerpt());
    158138}
    159139
    160140function the_excerpt_rss($cut = 0, $encode_html = 0) {
    161141    $output = get_the_excerpt(true);
    162     $output = convert_bbcode($output);
    163     $output = convert_gmcode($output);
    164     $output = convert_chars($output, 'unicode');
     142
     143    $output = convert_chars($output);
    165144    if ($cut && !$encode_html) {
    166145        $encode_html = 2;
     
    193172}
    194173
    195 function the_excerpt_unicode() {
    196     $excerpt = get_the_excerpt();
    197     $excerpt = convert_bbcode($excerpt);
    198     $excerpt = convert_gmcode($excerpt);
    199     $excerpt = convert_smilies($excerpt);
    200     $excerpt = convert_chars($excerpt, 'unicode');
    201     $excerpt = apply_filters('the_excerpt_unicode', $excerpt);
    202     echo $excerpt;
    203 }
    204 
    205174function get_the_excerpt($fakeit = true) {
    206175    global $id, $post;
    207     global $HTTP_SERVER_VARS, $HTTP_COOKIE_VARS, $preview, $cookiehash;
     176    global $HTTP_SERVER_VARS, $preview, $cookiehash;
    208177    $output = '';
    209178    $output = stripslashes($post->post_excerpt);
    210179    if (!empty($post->post_password)) { // if there's a password
    211         if ($HTTP_COOKIE_VARS['wp-postpass_'.$cookiehash] != $post->post_password) {  // and it doesn't match the cookie
     180        if ($_COOKIE['wp-postpass_'.$cookiehash] != $post->post_password) {  // and it doesn't match the cookie
    212181            $output = "There is no excerpt because this is a protected post.";
    213182            return $output;
Note: See TracChangeset for help on using the changeset viewer.