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-comment.php

    r840 r885  
    11<?php
     2
     3// Default filters for these functions
     4add_filter('comment_author', 'remove_slashes', 5);
     5add_filter('comment_author', 'wptexturize');
     6add_filter('comment_author', 'convert_chars');
     7
     8add_filter('comment_email', 'remove_slashes', 5);
     9add_filter('comment_email', 'antispambot', 5);
     10
     11add_filter('comment_url', 'clean_url');
     12
     13add_filter('comment_text', 'convert_chars');
     14add_filter('comment_text', 'make_clickable');
     15add_filter('comment_text', 'wpautop');
     16add_filter('comment_text', 'balanceTags');
     17add_filter('comment_text', 'convert_smilies', 20);
     18   
     19function clean_url($url) {
     20    $url = str_replace('http://url', '', $url);
     21    $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $url);
     22    $url = str_replace(';//', '://', $url);
     23    $url = (!strstr($url, '://')) ? 'http://'.$url : $url;
     24    $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
     25    return $url;
     26}
    227
    328function comments_number($zero='No Comments', $one='1 Comment', $more='% Comments', $number='') {
     
    7196
    7297function comment_ID() {
    73     global $comment;
    74     echo $comment->comment_ID;
     98    global $comment;
     99    echo $comment->comment_ID;
    75100}
    76101
    77102function comment_author() {
    78     global $comment;
    79     $author = stripslashes(stripslashes($comment->comment_author));
    80     $author = apply_filters('comment_auther', $author);
    81     $author = convert_chars($author);
    82     if (!empty($author)) {
    83         echo $comment->comment_author;
    84     }
    85     else {
    86         echo "Anonymous";
    87     }
     103    global $comment;
     104    $author = apply_filters('comment_author', $comment->comment_author);
     105    if (empty($author)) {
     106        echo 'Anonymous';
     107    } else {
     108        echo $author;
     109    }
    88110}
    89111
    90112function comment_author_email() {
    91     global $comment;
    92     $email = stripslashes(stripslashes($comment->comment_author_email));
    93    
    94     echo antispambot(stripslashes($comment->comment_author_email));
     113    global $comment;
     114    echo apply_filters('author_email', $comment->comment_author_email);
    95115}
    96116
    97117function comment_author_link() {
    98     global $comment;
    99     $url = trim(stripslashes($comment->comment_author_url));
    100     $email = stripslashes($comment->comment_author_email);
    101     $author = stripslashes($comment->comment_author);
    102     $author = convert_chars($author);
    103     $author = wptexturize($author);
    104     if (empty($author)) {
    105         $author = "Anonymous";
    106     }
    107 
    108     $url = str_replace('http://url', '', $url);
    109     $url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $url);
    110     if (empty($url) && empty($email)) {
    111         echo $author;
    112         return;
    113         }
    114     echo '<a href="';
    115     if ($url) {
    116         $url = str_replace(';//', '://', $url);
    117         $url = (!strstr($url, '://')) ? 'http://'.$url : $url;
    118         $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
    119         echo $url;
    120     } else {
    121         echo 'mailto:'.antispambot($email);
    122     }
    123     echo '" rel="external">' . $author . '</a>';
     118    global $comment;
     119    $url = apply_filters('comment_url', $comment->comment_author_url);
     120    $email = apply_filters('comment_email', $comment->comment_author_email);
     121    $author = apply_filters('comment_author', $comment->comment_author);
     122
     123    if (empty($url) && empty($email)) {
     124        echo 'Anonymous';
     125        return;
     126    }
     127
     128    echo '<a href="';
     129    if ($url) {
     130        echo $url;
     131    } else {
     132        echo 'mailto:'.antispambot($email);
     133    }
     134    echo '" rel="external">' . $author . '</a>';
    124135}
    125136
    126137function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
    127     global $comment;
    128     if (preg_match('|<trackback />|', $comment->comment_content)) echo $trackbacktxt;
    129     elseif (preg_match('|<pingback />|', $comment->comment_content)) echo $pingbacktxt;
    130     else echo $commenttxt;
     138    global $comment;
     139    if (preg_match('|<trackback />|', $comment->comment_content))
     140        echo $trackbacktxt;
     141    elseif (preg_match('|<pingback />|', $comment->comment_content))
     142        echo $pingbacktxt;
     143    else
     144        echo $commenttxt;
    131145}
    132146
    133147function comment_author_url() {
    134     global $comment;
    135     $url = trim(stripslashes($comment->comment_author_url));
    136     $url = str_replace(';//', '://', $url);
    137     $url = (!strstr($url, '://')) ? 'http://'.$url : $url;
    138     // convert & into &amp;
    139     $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
    140     $url = preg_replace('|[^a-z0-9-_.,/:]|i', '', $url);
    141     if ($url != 'http://url') {
    142         echo $url;
    143     }
     148    global $comment;
     149    echo apply_filters('comment_url', $comment->comment_author_url);
    144150}
    145151
    146152function comment_author_email_link($linktext='', $before='', $after='') {
    147     global $comment;
    148     $email = $comment->comment_author_email;
    149     if ((!empty($email)) && ($email != '@')) {
    150         $display = ($linktext != '') ? $linktext : antispambot(stripslashes($email));
    151         echo $before;
    152         echo '<a href="mailto:'.antispambot(stripslashes($email)).'">'.$display.'</a>';
    153         echo $after;
    154     }
     153    global $comment;
     154    $email = apply_filters('comment_email', $comment->comment_author_email);
     155    if ((!empty($email)) && ($email != '@')) {
     156    $display = ($linktext != '') ? $linktext : antispambot(stripslashes($email));
     157        echo $before;
     158        echo "<a href='mailto:$email'>$display</a>";
     159        echo $after;
     160    }
    155161}
    156162
    157163function comment_author_url_link($linktext='', $before='', $after='') {
    158     global $comment;
    159     $url = trim(stripslashes($comment->comment_author_url));
    160     $url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
    161     $url = (!stristr($url, '://')) ? 'http://'.$url : $url;
    162     $url = preg_replace('|[^a-z0-9-_.,/:]|i', '', $url);
    163     if ((!empty($url)) && ($url != 'http://') && ($url != 'http://url')) {
    164         $display = ($linktext != '') ? $linktext : stripslashes($url);
    165         echo $before;
    166         echo '<a href="'.stripslashes($url).'" rel="external">'.$display.'</a>';
    167         echo $after;
    168     }
     164    global $comment;
     165    $url = apply_filters('comment_url', $comment->comment_author_url);
     166
     167    if ((!empty($url)) && ($url != 'http://') && ($url != 'http://url')) {
     168    $display = ($linktext != '') ? $linktext : stripslashes($url);
     169        echo $before;
     170        echo "<a href='$url' rel='external'>$display</a>";
     171        echo $after;
     172    }
    169173}
    170174
    171175function comment_author_IP() {
    172     global $comment;
    173     echo stripslashes($comment->comment_author_IP);
     176    global $comment;
     177    echo $comment->comment_author_IP;
    174178}
    175179
    176180function comment_text() {
    177     global $comment;
    178     $comment_text = stripslashes($comment->comment_content);
    179     $comment_text = str_replace('<trackback />', '', $comment_text);
    180     $comment_text = str_replace('<pingback />', '', $comment_text);
    181     $comment_text = convert_chars($comment_text);
    182     $comment_text = convert_bbcode($comment_text);
    183     $comment_text = convert_gmcode($comment_text);
    184     $comment_text = make_clickable($comment_text);
    185     $comment_text = balanceTags($comment_text,1);
    186     $comment_text = apply_filters('comment_text', $comment_text);
    187     $comment_text = convert_smilies($comment_text);
    188     echo $comment_text;
     181    global $comment;
     182    $comment_text = str_replace('<trackback />', '', $comment->comment_content);
     183    $comment_text = str_replace('<pingback />', '', $comment_text);
     184    echo apply_filters('comment_text', $comment_text);
    189185}
    190186
    191187function comment_date($d='') {
    192     global $comment, $dateformat;
    193     if ($d == '') {
    194         echo mysql2date($dateformat, $comment->comment_date);
    195     } else {
    196         echo mysql2date($d, $comment->comment_date);
    197     }
     188    global $comment;
     189    if ('' == $d) {
     190        echo mysql2date(get_settings('date_format'), $comment->comment_date);
     191    } else {
     192        echo mysql2date($d, $comment->comment_date);
     193    }
    198194}
    199195
    200196function comment_time($d='') {
    201     global $comment, $timeformat;
    202     if ($d == '') {
    203         echo mysql2date($timeformat, $comment->comment_date);
    204     } else {
    205         echo mysql2date($d, $comment->comment_date);
    206     }
     197    global $comment;
     198    if ($d == '') {
     199        echo mysql2date(get_settings('time_format'), $comment->comment_date);
     200    } else {
     201        echo mysql2date($d, $comment->comment_date);
     202    }
    207203}
    208204
    209205function comments_rss_link($link_text='Comments RSS', $commentsrssfilename = 'wp-commentsrss2.php') {
    210     global $id;
    211     global $querystring_start, $querystring_equal, $querystring_separator, $siteurl;
    212 
    213     if ('' != get_settings('permalink_structure')) {
    214         $url = trailingslashit(get_permalink()) . 'rss2/';
    215     } else {
    216         $url = $siteurl.'/'.$commentsrssfilename.$querystring_start.'p'.$querystring_equal.$id;
    217     }
    218 
    219     $url = '<a href="'.$url.'">'.$link_text.'</a>';
    220     echo $url;
     206    global $id;
     207    global $querystring_start, $querystring_equal, $querystring_separator, $siteurl;
     208
     209    if ('' != get_settings('permalink_structure')) {
     210        $url = trailingslashit(get_permalink()) . 'rss2/';
     211    } else {
     212        $url = $siteurl.'/'.$commentsrssfilename.$querystring_start.'p'.$querystring_equal.$id;
     213    }
     214
     215    echo "<a href='$url'>$link_text</a>";
    221216}
    222217
    223218function comment_author_rss() {
    224     global $comment;
    225     if (!empty($comment->comment_author)) {
    226         echo htmlspecialchars(strip_tags(stripslashes($comment->comment_author)));
    227     }
    228     else {
    229         echo "Anonymous";
    230     }
     219    global $comment;
     220    if (empty($comment->comment_author)) {
     221        echo 'Anonymous';
     222    } else {
     223        echo htmlspecialchars(apply_filters('comment_author', $comment->comment_author));
     224    }
    231225}
    232226
    233227function comment_text_rss() {
    234     global $comment;
    235     $comment_text = stripslashes($comment->comment_content);
    236     $comment_text = str_replace('<trackback />', '', $comment_text);
    237     $comment_text = str_replace('<pingback />', '', $comment_text);
    238     $comment_text = convert_chars($comment_text);
    239     $comment_text = convert_bbcode($comment_text);
    240     $comment_text = convert_gmcode($comment_text);
    241     $comment_text = convert_smilies($comment_text);
    242     $comment_text = apply_filters('comment_text', $comment_text);
    243     $comment_text = strip_tags($comment_text);
    244     $comment_text = htmlspecialchars($comment_text);
    245     echo $comment_text;
     228    global $comment;
     229    $comment_text = str_replace('<trackback />', '', $comment->comment_content);
     230    $comment_text = str_replace('<pingback />', '', $comment_text);
     231    $comment_text = apply_filters('comment_text', $comment_text);
     232    $comment_text = strip_tags($comment_text);
     233    $comment_text = htmlspecialchars($comment_text);
     234    echo $comment_text;
    246235}
    247236
    248237function comment_link_rss() {
    249     global $comment;
    250     echo get_permalink($comment->comment_post_ID).'#comments';
     238    global $comment;
     239    echo get_permalink($comment->comment_post_ID).'#comments';
    251240}
    252241
    253242function permalink_comments_rss() {
    254     global $comment;
    255     echo get_permalink($comment->comment_post_ID);
     243    global $comment;
     244    echo get_permalink($comment->comment_post_ID);
    256245}
    257246
    258247function trackback_url($display = true) {
    259     global $siteurl, $id;
    260     $tb_url = $siteurl.'/wp-trackback.php/'.$id;
    261 
    262     if ('' != get_settings('permalink_structure')) {
    263         $tb_url = trailingslashit(get_permalink()) . 'trackback/';
    264     }
    265 
    266     if ($display) {
    267         echo $tb_url;
    268     } else {
    269         return $tb_url;
    270     }
     248    global $id;
     249    $tb_url = get_settings('siteurl') . '/wp-trackback.php/' . $id;
     250   
     251    if ('' != get_settings('permalink_structure')) {
     252        $tb_url = trailingslashit(get_permalink()) . 'trackback/';
     253    }
     254   
     255    if ($display) {
     256        echo $tb_url;
     257    } else {
     258        return $tb_url;
     259    }
    271260}
    272261
    273262
    274263function trackback_rdf($timezone = 0) {
    275     global $siteurl, $id, $HTTP_SERVER_VARS;
    276     if (!stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'W3C_Validator')) {
    277         echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" '."\n";
    278         echo '    xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
    279         echo '    xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n";
    280         echo '<rdf:Description'."\n";
    281         echo '    rdf:about="';
    282         permalink_single();
    283         echo '"'."\n";
    284         echo '    dc:identifier="';
    285         permalink_single();
    286         echo '"'."\n";
    287         echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', addslashes(strip_tags(get_the_title()))).'"'."\n";
    288         echo '    trackback:ping="'.trackback_url(0).'"'." />\n";
    289         echo '</rdf:RDF>';
    290     }
     264    global $siteurl, $id, $HTTP_SERVER_VARS;
     265    if (!stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'W3C_Validator')) {
     266    echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     267        xmlns:dc="http://purl.org/dc/elements/1.1/"
     268        xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
     269        <rdf:Description rdf:about="';
     270    permalink_single();
     271    echo '"'."\n";
     272    echo '    dc:identifier="';
     273    permalink_single();
     274    echo '"'."\n";
     275    echo '    dc:title="'.str_replace('--', '&#x2d;&#x2d;', addslashes(strip_tags(get_the_title()))).'"'."\n";
     276    echo '    trackback:ping="'.trackback_url(0).'"'." />\n";
     277    echo '</rdf:RDF>';
     278    }
    291279}
    292280
Note: See TracChangeset for help on using the changeset viewer.