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

git-svn-id: https://develop.svn.wordpress.org/trunk@885 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Matt Mullenweg
2004-02-17 04:56:29 +00:00
parent 1c58817681
commit d6a30cc0e8
8 changed files with 267 additions and 316 deletions

View File

@@ -1,5 +1,30 @@
<?php
// Default filters for these functions
add_filter('comment_author', 'remove_slashes', 5);
add_filter('comment_author', 'wptexturize');
add_filter('comment_author', 'convert_chars');
add_filter('comment_email', 'remove_slashes', 5);
add_filter('comment_email', 'antispambot', 5);
add_filter('comment_url', 'clean_url');
add_filter('comment_text', 'convert_chars');
add_filter('comment_text', 'make_clickable');
add_filter('comment_text', 'wpautop');
add_filter('comment_text', 'balanceTags');
add_filter('comment_text', 'convert_smilies', 20);
function clean_url($url) {
$url = str_replace('http://url', '', $url);
$url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $url);
$url = str_replace(';//', '://', $url);
$url = (!strstr($url, '://')) ? 'http://'.$url : $url;
$url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
return $url;
}
function comments_number($zero='No Comments', $one='1 Comment', $more='% Comments', $number='') {
global $id, $comment, $tablecomments, $wpdb;
if ('' == $number) $number = $wpdb->get_var("SELECT COUNT(*) FROM $tablecomments WHERE comment_post_ID = $id AND comment_approved = '1'");
@@ -70,224 +95,187 @@ function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Com
}
function comment_ID() {
global $comment;
echo $comment->comment_ID;
global $comment;
echo $comment->comment_ID;
}
function comment_author() {
global $comment;
$author = stripslashes(stripslashes($comment->comment_author));
$author = apply_filters('comment_auther', $author);
$author = convert_chars($author);
if (!empty($author)) {
echo $comment->comment_author;
}
else {
echo "Anonymous";
}
global $comment;
$author = apply_filters('comment_author', $comment->comment_author);
if (empty($author)) {
echo 'Anonymous';
} else {
echo $author;
}
}
function comment_author_email() {
global $comment;
$email = stripslashes(stripslashes($comment->comment_author_email));
echo antispambot(stripslashes($comment->comment_author_email));
global $comment;
echo apply_filters('author_email', $comment->comment_author_email);
}
function comment_author_link() {
global $comment;
$url = trim(stripslashes($comment->comment_author_url));
$email = stripslashes($comment->comment_author_email);
$author = stripslashes($comment->comment_author);
$author = convert_chars($author);
$author = wptexturize($author);
if (empty($author)) {
$author = "Anonymous";
}
global $comment;
$url = apply_filters('comment_url', $comment->comment_author_url);
$email = apply_filters('comment_email', $comment->comment_author_email);
$author = apply_filters('comment_author', $comment->comment_author);
$url = str_replace('http://url', '', $url);
$url = preg_replace('|[^a-z0-9-~+_.?#=&;,/:]|i', '', $url);
if (empty($url) && empty($email)) {
echo $author;
return;
}
echo '<a href="';
if ($url) {
$url = str_replace(';//', '://', $url);
$url = (!strstr($url, '://')) ? 'http://'.$url : $url;
$url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
echo $url;
} else {
echo 'mailto:'.antispambot($email);
}
echo '" rel="external">' . $author . '</a>';
if (empty($url) && empty($email)) {
echo 'Anonymous';
return;
}
echo '<a href="';
if ($url) {
echo $url;
} else {
echo 'mailto:'.antispambot($email);
}
echo '" rel="external">' . $author . '</a>';
}
function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') {
global $comment;
if (preg_match('|<trackback />|', $comment->comment_content)) echo $trackbacktxt;
elseif (preg_match('|<pingback />|', $comment->comment_content)) echo $pingbacktxt;
else echo $commenttxt;
global $comment;
if (preg_match('|<trackback />|', $comment->comment_content))
echo $trackbacktxt;
elseif (preg_match('|<pingback />|', $comment->comment_content))
echo $pingbacktxt;
else
echo $commenttxt;
}
function comment_author_url() {
global $comment;
$url = trim(stripslashes($comment->comment_author_url));
$url = str_replace(';//', '://', $url);
$url = (!strstr($url, '://')) ? 'http://'.$url : $url;
// convert & into &amp;
$url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
$url = preg_replace('|[^a-z0-9-_.,/:]|i', '', $url);
if ($url != 'http://url') {
echo $url;
}
global $comment;
echo apply_filters('comment_url', $comment->comment_author_url);
}
function comment_author_email_link($linktext='', $before='', $after='') {
global $comment;
$email = $comment->comment_author_email;
if ((!empty($email)) && ($email != '@')) {
$display = ($linktext != '') ? $linktext : antispambot(stripslashes($email));
echo $before;
echo '<a href="mailto:'.antispambot(stripslashes($email)).'">'.$display.'</a>';
echo $after;
}
global $comment;
$email = apply_filters('comment_email', $comment->comment_author_email);
if ((!empty($email)) && ($email != '@')) {
$display = ($linktext != '') ? $linktext : antispambot(stripslashes($email));
echo $before;
echo "<a href='mailto:$email'>$display</a>";
echo $after;
}
}
function comment_author_url_link($linktext='', $before='', $after='') {
global $comment;
$url = trim(stripslashes($comment->comment_author_url));
$url = preg_replace('/&([^#])(?![a-z]{2,8};)/', '&#038;$1', $url);
$url = (!stristr($url, '://')) ? 'http://'.$url : $url;
$url = preg_replace('|[^a-z0-9-_.,/:]|i', '', $url);
if ((!empty($url)) && ($url != 'http://') && ($url != 'http://url')) {
$display = ($linktext != '') ? $linktext : stripslashes($url);
echo $before;
echo '<a href="'.stripslashes($url).'" rel="external">'.$display.'</a>';
echo $after;
}
global $comment;
$url = apply_filters('comment_url', $comment->comment_author_url);
if ((!empty($url)) && ($url != 'http://') && ($url != 'http://url')) {
$display = ($linktext != '') ? $linktext : stripslashes($url);
echo $before;
echo "<a href='$url' rel='external'>$display</a>";
echo $after;
}
}
function comment_author_IP() {
global $comment;
echo stripslashes($comment->comment_author_IP);
global $comment;
echo $comment->comment_author_IP;
}
function comment_text() {
global $comment;
$comment_text = stripslashes($comment->comment_content);
$comment_text = str_replace('<trackback />', '', $comment_text);
$comment_text = str_replace('<pingback />', '', $comment_text);
$comment_text = convert_chars($comment_text);
$comment_text = convert_bbcode($comment_text);
$comment_text = convert_gmcode($comment_text);
$comment_text = make_clickable($comment_text);
$comment_text = balanceTags($comment_text,1);
$comment_text = apply_filters('comment_text', $comment_text);
$comment_text = convert_smilies($comment_text);
echo $comment_text;
global $comment;
$comment_text = str_replace('<trackback />', '', $comment->comment_content);
$comment_text = str_replace('<pingback />', '', $comment_text);
echo apply_filters('comment_text', $comment_text);
}
function comment_date($d='') {
global $comment, $dateformat;
if ($d == '') {
echo mysql2date($dateformat, $comment->comment_date);
} else {
echo mysql2date($d, $comment->comment_date);
}
global $comment;
if ('' == $d) {
echo mysql2date(get_settings('date_format'), $comment->comment_date);
} else {
echo mysql2date($d, $comment->comment_date);
}
}
function comment_time($d='') {
global $comment, $timeformat;
if ($d == '') {
echo mysql2date($timeformat, $comment->comment_date);
} else {
echo mysql2date($d, $comment->comment_date);
}
global $comment;
if ($d == '') {
echo mysql2date(get_settings('time_format'), $comment->comment_date);
} else {
echo mysql2date($d, $comment->comment_date);
}
}
function comments_rss_link($link_text='Comments RSS', $commentsrssfilename = 'wp-commentsrss2.php') {
global $id;
global $querystring_start, $querystring_equal, $querystring_separator, $siteurl;
global $id;
global $querystring_start, $querystring_equal, $querystring_separator, $siteurl;
if ('' != get_settings('permalink_structure')) {
$url = trailingslashit(get_permalink()) . 'rss2/';
} else {
$url = $siteurl.'/'.$commentsrssfilename.$querystring_start.'p'.$querystring_equal.$id;
}
if ('' != get_settings('permalink_structure')) {
$url = trailingslashit(get_permalink()) . 'rss2/';
} else {
$url = $siteurl.'/'.$commentsrssfilename.$querystring_start.'p'.$querystring_equal.$id;
}
$url = '<a href="'.$url.'">'.$link_text.'</a>';
echo $url;
echo "<a href='$url'>$link_text</a>";
}
function comment_author_rss() {
global $comment;
if (!empty($comment->comment_author)) {
echo htmlspecialchars(strip_tags(stripslashes($comment->comment_author)));
}
else {
echo "Anonymous";
}
global $comment;
if (empty($comment->comment_author)) {
echo 'Anonymous';
} else {
echo htmlspecialchars(apply_filters('comment_author', $comment->comment_author));
}
}
function comment_text_rss() {
global $comment;
$comment_text = stripslashes($comment->comment_content);
$comment_text = str_replace('<trackback />', '', $comment_text);
$comment_text = str_replace('<pingback />', '', $comment_text);
$comment_text = convert_chars($comment_text);
$comment_text = convert_bbcode($comment_text);
$comment_text = convert_gmcode($comment_text);
$comment_text = convert_smilies($comment_text);
$comment_text = apply_filters('comment_text', $comment_text);
$comment_text = strip_tags($comment_text);
$comment_text = htmlspecialchars($comment_text);
echo $comment_text;
global $comment;
$comment_text = str_replace('<trackback />', '', $comment->comment_content);
$comment_text = str_replace('<pingback />', '', $comment_text);
$comment_text = apply_filters('comment_text', $comment_text);
$comment_text = strip_tags($comment_text);
$comment_text = htmlspecialchars($comment_text);
echo $comment_text;
}
function comment_link_rss() {
global $comment;
echo get_permalink($comment->comment_post_ID).'#comments';
global $comment;
echo get_permalink($comment->comment_post_ID).'#comments';
}
function permalink_comments_rss() {
global $comment;
echo get_permalink($comment->comment_post_ID);
global $comment;
echo get_permalink($comment->comment_post_ID);
}
function trackback_url($display = true) {
global $siteurl, $id;
$tb_url = $siteurl.'/wp-trackback.php/'.$id;
if ('' != get_settings('permalink_structure')) {
$tb_url = trailingslashit(get_permalink()) . 'trackback/';
}
if ($display) {
echo $tb_url;
} else {
return $tb_url;
}
global $id;
$tb_url = get_settings('siteurl') . '/wp-trackback.php/' . $id;
if ('' != get_settings('permalink_structure')) {
$tb_url = trailingslashit(get_permalink()) . 'trackback/';
}
if ($display) {
echo $tb_url;
} else {
return $tb_url;
}
}
function trackback_rdf($timezone = 0) {
global $siteurl, $id, $HTTP_SERVER_VARS;
if (!stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'W3C_Validator')) {
echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" '."\n";
echo ' xmlns:dc="http://purl.org/dc/elements/1.1/"'."\n";
echo ' xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">'."\n";
echo '<rdf:Description'."\n";
echo ' rdf:about="';
permalink_single();
echo '"'."\n";
echo ' dc:identifier="';
permalink_single();
echo '"'."\n";
echo ' dc:title="'.str_replace('--', '&#x2d;&#x2d;', addslashes(strip_tags(get_the_title()))).'"'."\n";
echo ' trackback:ping="'.trackback_url(0).'"'." />\n";
echo '</rdf:RDF>';
}
global $siteurl, $id, $HTTP_SERVER_VARS;
if (!stristr($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'W3C_Validator')) {
echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
<rdf:Description rdf:about="';
permalink_single();
echo '"'."\n";
echo ' dc:identifier="';
permalink_single();
echo '"'."\n";
echo ' dc:title="'.str_replace('--', '&#x2d;&#x2d;', addslashes(strip_tags(get_the_title()))).'"'."\n";
echo ' trackback:ping="'.trackback_url(0).'"'." />\n";
echo '</rdf:RDF>';
}
}
?>
?>