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: http://svn.automattic.com/wordpress/trunk@885 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2004-02-17 04:56:29 +00:00
parent d1a3b1b896
commit 77421739db
8 changed files with 267 additions and 316 deletions

View File

@ -88,8 +88,6 @@ if (!isset($posts_per_page) || $posts_per_page == 0)
$posts_per_page = get_settings('posts_per_page');
$what_to_show = get_settings('what_to_show');
$archive_mode = get_settings('archive_mode');
$dateformat = stripslashes(get_settings('date_format'));
$timeformat = stripslashes(get_settings('time_format'));
$time_difference = get_settings('time_difference');
$use_gzipcompression = get_settings('gzipcompression');

View File

@ -268,17 +268,18 @@ function get_settings($setting) {
if (strstr($_SERVER['REQUEST_URI'], 'install.php')) {
return false;
}
if ((empty($cache_settings)) OR (!$use_cache)) {
$settings = get_alloptions();
$cache_settings = $settings;
} else {
$settings = $cache_settings;
}
if (!isset($settings->$setting)) {
return false;
}
else {
return $settings->$setting;
} else {
return stripslashes($settings->$setting);
}
}
@ -287,6 +288,9 @@ function get_alloptions() {
$options = $wpdb->get_results("SELECT option_name, option_value FROM $tableoptions");
if ($options) {
foreach ($options as $option) {
// "When trying to design a foolproof system,
// never underestimate the ingenuity of the fools :)"
if ('siteurl' == $option->option_name) $option->option_value = preg_replace('|/+$|', '', $option->option_value);
$all_options->{$option->option_name} = $option->option_value;
}
}
@ -1461,4 +1465,8 @@ function rewrite_rules($matches = '') {
return $rewrite;
}
function remove_slashes($string) {
return stripslashes(stripslashes($string));
}
?>

View File

@ -103,18 +103,13 @@ function the_category_rss($type = 'rss') {
foreach ($categories as $category) {
$category->cat_name = stripslashes(convert_chars($category->cat_name));
if ('rdf' == $type) {
echo "\n<dc:subject>$category->cat_name</dc:subject>";
echo "\n\t<dc:subject>$category->cat_name</dc:subject>";
} else {
echo "\n<category>$category->cat_name</category>";
echo "\n\t<category>$category->cat_name</category>";
}
}
}
function the_category_unicode() {
$category = get_the_category();
$category = apply_filters('the_category_unicode', $category);
echo convert_chars($category, 'unicode');
}
function get_the_category_by_ID($cat_ID) {
global $tablecategories, $cache_categories, $use_cache, $wpdb;
@ -148,7 +143,7 @@ function get_category_parents($id, $link=FALSE, $separator=' / ', $nicename=FALS
function get_category_children($id, $before = '/', $after = '') {
global $tablecategories, $cache_categories;
$c_cache = $cache_categories; // Can't do recursive foreach on a global, have to make a copy
$chain = "";
$chain = '';
foreach ($c_cache as $category){
if ($category->category_parent == $id){
$chain .= $before.$category->cat_ID.$after;

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'");
@ -76,46 +101,32 @@ function 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";
$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));
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";
}
$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;
echo 'Anonymous';
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);
@ -125,82 +136,67 @@ function comment_author_link() {
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;
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;
}
echo apply_filters('comment_url', $comment->comment_author_url);
}
function comment_author_email_link($linktext='', $before='', $after='') {
global $comment;
$email = $comment->comment_author_email;
$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:'.antispambot(stripslashes($email)).'">'.$display.'</a>';
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);
$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="'.stripslashes($url).'" rel="external">'.$display.'</a>';
echo "<a href='$url' rel='external'>$display</a>";
echo $after;
}
}
function comment_author_IP() {
global $comment;
echo stripslashes($comment->comment_author_IP);
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('<trackback />', '', $comment->comment_content);
$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;
echo apply_filters('comment_text', $comment_text);
}
function comment_date($d='') {
global $comment, $dateformat;
if ($d == '') {
echo mysql2date($dateformat, $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;
global $comment;
if ($d == '') {
echo mysql2date($timeformat, $comment->comment_date);
echo mysql2date(get_settings('time_format'), $comment->comment_date);
} else {
echo mysql2date($d, $comment->comment_date);
}
@ -216,29 +212,22 @@ function comments_rss_link($link_text='Comments RSS', $commentsrssfilename = 'wp
$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";
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('<trackback />', '', $comment->comment_content);
$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);
@ -256,8 +245,8 @@ function permalink_comments_rss() {
}
function trackback_url($display = true) {
global $siteurl, $id;
$tb_url = $siteurl.'/wp-trackback.php/'.$id;
global $id;
$tb_url = get_settings('siteurl') . '/wp-trackback.php/' . $id;
if ('' != get_settings('permalink_structure')) {
$tb_url = trailingslashit(get_permalink()) . 'trackback/';
@ -274,11 +263,10 @@ function trackback_url($display = true) {
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="';
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="';

View File

@ -204,7 +204,7 @@ function get_archives_link($url, $text, $format = "html", $before = "", $after =
}
function get_archives($type='', $limit='', $format='html', $before = "", $after = "", $show_post_count = false) {
global $tableposts, $dateformat, $time_difference, $siteurl, $blogfilename;
global $tableposts, $time_difference, $siteurl, $blogfilename;
global $querystring_start, $querystring_equal, $querystring_separator, $month, $wpdb, $start_of_week;
if ('' == $type) {
@ -234,9 +234,9 @@ function get_archives($type='', $limit='', $format='html', $before = "", $after
$archive_week_end_date_format = 'Y/m/d';
if (!$archive_date_format_over_ride) {
$archive_day_date_format = $dateformat;
$archive_week_start_date_format = $dateformat;
$archive_week_end_date_format = $dateformat;
$archive_day_date_format = get_settings('date_format');
$archive_week_start_date_format = get_settings('date_format');
$archive_week_end_date_format = get_settings('date_format');
}
$now = date('Y-m-d H:i:s',(time() + ($time_difference * 3600)));
@ -502,12 +502,12 @@ function the_date_xml() {
}
function the_date($d='', $before='', $after='', $echo = true) {
global $id, $post, $day, $previousday, $dateformat, $newday;
global $id, $post, $day, $previousday, $newday;
$the_date = '';
if ($day != $previousday) {
$the_date .= $before;
if ($d=='') {
$the_date .= mysql2date($dateformat, $post->post_date);
$the_date .= mysql2date(get_settings('date_format'), $post->post_date);
} else {
$the_date .= mysql2date($d, $post->post_date);
}
@ -523,9 +523,9 @@ function the_date($d='', $before='', $after='', $echo = true) {
}
function the_time($d='', $echo = true) {
global $id, $post, $timeformat;
global $id, $post;
if ($d=='') {
$the_time = mysql2date($timeformat, $post->post_date);
$the_time = mysql2date(get_settings('time_format'), $post->post_date);
} else {
$the_time = mysql2date($d, $post->post_date);
}

View File

@ -1,5 +1,19 @@
<?php
// Default filters
add_filter('the_title', 'convert_chars');
add_filter('the_title', 'trim');
add_filter('the_title_rss', 'strip_tags');
add_filter('the_content', 'convert_smilies');
add_filter('the_content', 'convert_chars');
add_filter('the_content', 'wpautop');
add_filter('the_excerpt', 'convert_smilies');
add_filter('the_excerpt', 'autop');
add_filter('the_excerpt', 'convert_chars');
add_filter('the_excerpt', 'wpautop');
function get_the_password_form() {
$output = "<form action='" . get_settings('siteurl') . "/wp-pass.php' method='post'>
@ -17,33 +31,22 @@ function the_ID() {
function the_title($before = '', $after = '', $echo = true) {
$title = get_the_title();
$title = convert_smilies($title);
if (!empty($title)) {
$title = convert_chars($before.$title.$after);
$title = apply_filters('the_title', $title);
$title = apply_filters('the_title', $before . $title . $after);
if ($echo)
echo $title;
else
return $title;
}
}
function the_title_rss() {
$title = get_the_title();
$title = strip_tags($title);
if (trim($title)) {
echo convert_chars($title, 'unicode');
}
}
function the_title_unicode($before='',$after='') {
$title = get_the_title();
$title = convert_bbcode($title);
$title = convert_gmcode($title);
if ($title) {
$title = convert_chars($before.$title.$after);
$title = apply_filters('the_title_unicode', $title);
$title = apply_filters('the_title', $title);
$title = apply_filters('the_title_rss', $title):
echo $title;
}
}
function get_the_title() {
global $post;
$output = stripslashes($post->post_title);
@ -55,19 +58,13 @@ function get_the_title() {
function the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = convert_bbcode($content);
$content = convert_gmcode($content);
$content = convert_smilies($content);
$content = convert_chars($content, 'html');
$content = apply_filters('the_content', $content);
echo $content;
}
function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file='', $cut = 0, $encode_html = 0) {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = convert_bbcode($content);
$content = convert_gmcode($content);
$content = convert_chars($content, 'unicode');
$content = apply_filters('the_content', $content);
if ($cut && !$encode_html) {
$encode_html = 2;
}
@ -97,25 +94,14 @@ function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file
echo $content;
}
function the_content_unicode($more_link_text='(more...)', $stripteaser=0, $more_file='') {
$content = get_the_content($more_link_text, $stripteaser, $more_file);
$content = convert_bbcode($content);
$content = convert_gmcode($content);
$content = convert_smilies($content);
$content = convert_chars($content, 'unicode');
$content = apply_filters('the_content_unicode', $content);
echo $content;
}
function get_the_content($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
global $id, $post, $more, $single, $withcomments, $page, $pages, $multipage, $numpages;
global $HTTP_SERVER_VARS, $HTTP_COOKIE_VARS, $preview, $cookiehash;
global $querystring_start, $querystring_equal, $querystring_separator;
global $HTTP_SERVER_VARS, $preview, $cookiehash;
global $pagenow;
$output = '';
if (!empty($post->post_password)) { // if there's a password
if ($HTTP_COOKIE_VARS['wp-postpass_'.$cookiehash] != $post->post_password) { // and it doesn't match the cookie
if ($_COOKIE['wp-postpass_'.$cookiehash] != $post->post_password) { // and it doesn't match the cookie
$output = get_the_password_form();
return $output;
}
@ -148,20 +134,13 @@ function get_the_content($more_link_text='(more...)', $stripteaser=0, $more_file
}
function the_excerpt() {
$excerpt = get_the_excerpt();
$excerpt = convert_bbcode($excerpt);
$excerpt = convert_gmcode($excerpt);
$excerpt = convert_smilies($excerpt);
$excerpt = convert_chars($excerpt, 'html');
$excerpt = apply_filters('the_excerpt', $excerpt);
echo $excerpt;
echo apply_filters('the_excerpt', get_the_excerpt());
}
function the_excerpt_rss($cut = 0, $encode_html = 0) {
$output = get_the_excerpt(true);
$output = convert_bbcode($output);
$output = convert_gmcode($output);
$output = convert_chars($output, 'unicode');
$output = convert_chars($output);
if ($cut && !$encode_html) {
$encode_html = 2;
}
@ -192,23 +171,13 @@ function the_excerpt_rss($cut = 0, $encode_html = 0) {
echo $output;
}
function the_excerpt_unicode() {
$excerpt = get_the_excerpt();
$excerpt = convert_bbcode($excerpt);
$excerpt = convert_gmcode($excerpt);
$excerpt = convert_smilies($excerpt);
$excerpt = convert_chars($excerpt, 'unicode');
$excerpt = apply_filters('the_excerpt_unicode', $excerpt);
echo $excerpt;
}
function get_the_excerpt($fakeit = true) {
global $id, $post;
global $HTTP_SERVER_VARS, $HTTP_COOKIE_VARS, $preview, $cookiehash;
global $HTTP_SERVER_VARS, $preview, $cookiehash;
$output = '';
$output = stripslashes($post->post_excerpt);
if (!empty($post->post_password)) { // if there's a password
if ($HTTP_COOKIE_VARS['wp-postpass_'.$cookiehash] != $post->post_password) { // and it doesn't match the cookie
if ($_COOKIE['wp-postpass_'.$cookiehash] != $post->post_password) { // and it doesn't match the cookie
$output = "There is no excerpt because this is a protected post.";
return $output;
}

View File

@ -268,9 +268,6 @@ foreach($wpsmiliestrans as $smiley => $img) {
// Some default filters
add_filter('all', 'wptexturize');
add_filter('the_content', 'wpautop');
add_filter('comment_text', 'wpautop');
add_filter('the_excerpt', 'wpautop');
// Uncomment the following for Textile support
// include_once('textile.php');

View File

@ -49,10 +49,6 @@ require_once (ABSPATH . WPINC . '/kses.php');
// accessing a single global $all_settings var
if (!strstr($_SERVER['REQUEST_URI'], 'install.php') && !strstr($_SERVER['REQUEST_URI'], 'wp-admin/import')) {
$siteurl = get_settings('siteurl');
// "When trying to design a foolproof system,
// never underestimate the ingenuity of the fools :)"
$siteurl = preg_replace('|/+$|', '', $siteurl);
$blogfilename = get_settings('blogfilename');
$blogname = get_settings('blogname');
$blogdescription = get_settings('blogdescription');