Bunch of whitespace and coding standardization.

git-svn-id: http://svn.automattic.com/wordpress/trunk@4626 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
markjaquith 2006-12-07 03:57:23 +00:00
parent 010379dd52
commit 0aa19529f9
5 changed files with 217 additions and 186 deletions

View File

@ -3,7 +3,8 @@
function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $comment_type) {
global $wpdb;
if (1 == get_option('comment_moderation')) return false; // If moderation is set to manual
if ( 1 == get_option('comment_moderation') )
return false; // If moderation is set to manual
if ( preg_match_all("|(href\t*?=\t*?['\"]?)?(https?:)?//|i", $comment, $out) >= get_option('comment_max_links') )
return false; // Check # of external links
@ -16,7 +17,8 @@ function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $
$word = trim($word);
// Skip empty lines
if (empty($word)) { continue; }
if ( empty($word) )
continue;
// Do some escaping magic so that '#' chars in the
// spam words don't break things:
@ -54,10 +56,10 @@ function check_comment($author, $email, $url, $comment, $user_ip, $user_agent, $
return false;
}
}
return true;
}
function get_approved_comments($post_id) {
global $wpdb;
@ -65,6 +67,7 @@ function get_approved_comments($post_id) {
return $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post_id' AND comment_approved = '1' ORDER BY comment_date");
}
// Retrieves comment data given a comment ID or comment object.
// Handles comment caching.
function &get_comment(&$comment, $output = OBJECT) {
@ -97,14 +100,14 @@ function &get_comment(&$comment, $output = OBJECT) {
}
}
// Deprecate in favor of get_comment()?
function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = false ) { // less flexible, but saves DB queries
global $postc, $id, $commentdata, $wpdb;
if ( $no_cache ) {
$query = "SELECT * FROM $wpdb->comments WHERE comment_ID = '$comment_ID'";
if (false == $include_unapproved) {
if ( false == $include_unapproved )
$query .= " AND comment_approved = '1'";
}
$myrow = $wpdb->get_row($query, ARRAY_A);
} else {
$myrow['comment_ID'] = $postc->comment_ID;
@ -122,6 +125,7 @@ function get_commentdata( $comment_ID, $no_cache = 0, $include_unapproved = fals
return $myrow;
}
function get_lastcommentmodified($timezone = 'server') {
global $cache_lastcommentmodified, $pagenow, $wpdb;
$add_seconds_blog = get_option('gmt_offset') * 3600;
@ -146,6 +150,7 @@ function get_lastcommentmodified($timezone = 'server') {
return $lastcommentmodified;
}
function sanitize_comment_cookies() {
if ( isset($_COOKIE['comment_author_'.COOKIEHASH]) ) {
$comment_author = apply_filters('pre_comment_author_name', $_COOKIE['comment_author_'.COOKIEHASH]);
@ -169,6 +174,7 @@ function sanitize_comment_cookies() {
}
}
function wp_allow_comment($commentdata) {
global $wpdb;
extract($commentdata);
@ -198,13 +204,11 @@ function wp_allow_comment($commentdata) {
$post_author = $wpdb->get_var("SELECT post_author FROM $wpdb->posts WHERE ID = '$comment_post_ID' LIMIT 1");
}
// The author and the admins get respect.
if ( $userdata && ( $user_id == $post_author || $user->has_cap('level_9') ) ) {
// The author and the admins get respect.
$approved = 1;
}
} else {
// Everyone else's comments will be checked.
else {
if ( check_comment($comment_author, $comment_author_email, $comment_author_url, $comment_content, $comment_author_IP, $comment_agent, $comment_type) )
$approved = 1;
else
@ -217,13 +221,14 @@ function wp_allow_comment($commentdata) {
return $approved;
}
function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) {
global $wpdb;
do_action('wp_blacklist_check', $author, $email, $url, $comment, $user_ip, $user_agent);
if ( preg_match_all('/&#(\d+);/', $comment . $author . $url, $chars) ) {
foreach ($chars[1] as $char) {
foreach ( (array) $chars[1] as $char ) {
// If it's an encoded char in the normal ASCII set, reject
if ( 38 == $char )
continue; // Unless it's &
@ -237,7 +242,7 @@ function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_age
return false; // If moderation keys are empty
$words = explode("\n", $mod_keys );
foreach ($words as $word) {
foreach ( (array) $words as $word ) {
$word = trim($word);
// Skip empty lines
@ -248,17 +253,20 @@ function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_age
$word = preg_quote($word, '#');
$pattern = "#$word#i";
if ( preg_match($pattern, $author ) ) return true;
if ( preg_match($pattern, $email ) ) return true;
if ( preg_match($pattern, $url ) ) return true;
if ( preg_match($pattern, $comment ) ) return true;
if ( preg_match($pattern, $user_ip ) ) return true;
if ( preg_match($pattern, $user_agent) ) return true;
if (
preg_match($pattern, $author)
|| preg_match($pattern, $email)
|| preg_match($pattern, $url)
|| preg_match($pattern, $comment)
|| preg_match($pattern, $user_ip)
|| preg_match($pattern, $user_agent)
)
return true;
}
return false;
}
function wp_delete_comment($comment_id) {
global $wpdb;
do_action('delete_comment', $comment_id);
@ -276,22 +284,24 @@ function wp_delete_comment($comment_id) {
return true;
}
function wp_get_comment_status($comment_id) {
global $wpdb;
$result = $wpdb->get_var("SELECT comment_approved FROM $wpdb->comments WHERE comment_ID='$comment_id' LIMIT 1");
if ($result == NULL) {
if ( $result == NULL )
return 'deleted';
} else if ($result == '1') {
elseif ( $result == '1' )
return 'approved';
} else if ($result == '0') {
elseif ( $result == '0' )
return 'unapproved';
} else if ($result == 'spam') {
elseif ( $result == 'spam' )
return 'spam';
} else {
else
return false;
}
}
function wp_get_current_commenter() {
// Cookies should already be sanitized.
@ -311,6 +321,7 @@ function wp_get_current_commenter() {
return compact('comment_author', 'comment_author_email', 'comment_author_url');
}
function wp_insert_comment($commentdata) {
global $wpdb;
extract($commentdata);
@ -342,6 +353,7 @@ function wp_insert_comment($commentdata) {
return $id;
}
function wp_filter_comment($commentdata) {
$commentdata['user_id'] = apply_filters('pre_user_id', $commentdata['user_ID']);
$commentdata['comment_agent'] = apply_filters('pre_comment_user_agent', $commentdata['comment_agent']);
@ -354,6 +366,7 @@ function wp_filter_comment($commentdata) {
return $commentdata;
}
function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment) {
if ( $block ) // a plugin has already blocked... we'll let that decision stand
return $block;
@ -362,6 +375,7 @@ function wp_throttle_comment_flood($block, $time_lastcomment, $time_newcomment)
return false;
}
function wp_new_comment( $commentdata ) {
$commentdata = apply_filters('preprocess_comment', $commentdata);
@ -374,7 +388,6 @@ function wp_new_comment( $commentdata ) {
$commentdata['comment_date'] = current_time('mysql');
$commentdata['comment_date_gmt'] = current_time('mysql', 1);
$commentdata = wp_filter_comment($commentdata);
$commentdata['comment_approved'] = wp_allow_comment($commentdata);
@ -396,6 +409,7 @@ function wp_new_comment( $commentdata ) {
return $comment_ID;
}
function wp_set_comment_status($comment_id, $comment_status) {
global $wpdb;
@ -430,6 +444,7 @@ function wp_set_comment_status($comment_id, $comment_status) {
}
}
function wp_update_comment($commentarr) {
global $wpdb;
@ -437,7 +452,7 @@ function wp_update_comment($commentarr) {
$comment = get_comment($commentarr['comment_ID'], ARRAY_A);
// Escape data pulled from DB.
foreach ($comment as $key => $value)
foreach ( (array) $comment as $key => $value )
$comment[$key] = $wpdb->escape($value);
// Merge old and new fields with new fields overwriting old ones.
@ -461,14 +476,12 @@ function wp_update_comment($commentarr) {
WHERE comment_ID = $comment_ID" );
$rval = $wpdb->rows_affected;
wp_update_comment_count($comment_post_ID);
do_action('edit_comment', $comment_ID);
return $rval;
}
function wp_update_comment_count($post_id) {
global $wpdb, $comment_count_cache;
$post_id = (int) $post_id;
@ -480,6 +493,7 @@ function wp_update_comment_count($post_id) {
return true;
}
//
// Ping and trackback functions.
//
@ -497,10 +511,8 @@ function discover_pingback_server_uri($url, $timeout_bytes = 2048) {
extract(parse_url($url));
if (!isset($host)) {
// Not an URL. This should never happen.
if ( !isset($host) ) // Not an URL. This should never happen.
return false;
}
$path = ( !isset($path) ) ? '/' : $path;
$path .= ( isset($query) ) ? '?' . $query : '';
@ -508,10 +520,8 @@ function discover_pingback_server_uri($url, $timeout_bytes = 2048) {
// Try to connect to the server at $host
$fp = @fsockopen($host, $port, $errno, $errstr, 2);
if (!$fp) {
// Couldn't open a connection to $host;
if ( !$fp ) // Couldn't open a connection to $host
return false;
}
// Send the GET request
$request = "GET $path HTTP/1.1\r\nHost: $host\r\nUser-Agent: WordPress/$wp_version \r\n\r\n";
@ -521,9 +531,8 @@ function discover_pingback_server_uri($url, $timeout_bytes = 2048) {
// Let's check for an X-Pingback header first
while ( !feof($fp) ) {
$line = fgets($fp, 512);
if (trim($line) == '') {
if ( trim($line) == '' )
break;
}
$headers .= trim($line)."\n";
$x_pingback_header_offset = strpos(strtolower($headers), $x_pingback_str);
if ( $x_pingback_header_offset ) {
@ -538,10 +547,8 @@ function discover_pingback_server_uri($url, $timeout_bytes = 2048) {
}
}
if (preg_match('#(image|audio|video|model)/#is', $content_type)) {
// Not an (x)html, sgml, or xml page, no use going further
if ( preg_match('#(image|audio|video|model)/#is', $content_type) ) // Not an (x)html, sgml, or xml page, no use going further
return false;
}
while ( !feof($fp) ) {
$line = fgets($fp, 1024);
@ -557,11 +564,9 @@ function discover_pingback_server_uri($url, $timeout_bytes = 2048) {
$pingback_server_url_len = $pingback_href_end - $pingback_href_start;
$pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
// We may find rel="pingback" but an incomplete pingback URL
if ($pingback_server_url_len > 0) {
// We got it!
if ( $pingback_server_url_len > 0 ) // We got it!
return $pingback_server_url;
}
}
$byte_count += strlen($line);
if ( $byte_count > $timeout_bytes ) {
// It's no use going further, there probably isn't any pingback
@ -574,6 +579,7 @@ function discover_pingback_server_uri($url, $timeout_bytes = 2048) {
return false;
}
function do_all_pings() {
global $wpdb;
@ -592,10 +598,9 @@ function do_all_pings() {
// Do Trackbacks
$trackbacks = $wpdb->get_results("SELECT ID FROM $wpdb->posts WHERE CHAR_LENGTH(TRIM(to_ping)) > 7 AND post_status = 'publish'");
if ( is_array($trackbacks) ) {
foreach ( $trackbacks as $trackback ) {
foreach ( $trackbacks as $trackback )
do_trackbacks($trackback->ID);
}
}
//Do Update Services/Generic Pings
generic_ping();
@ -626,7 +631,8 @@ function do_trackbacks($post_id) {
$post_title = apply_filters('the_title', $post->post_title);
$post_title = strip_tags($post_title);
if ($to_ping) : foreach ($to_ping as $tb_ping) :
if ( $to_ping ) {
foreach ( (array) $to_ping as $tb_ping ) {
$tb_ping = trim($tb_ping);
if ( !in_array($tb_ping, $pinged) ) {
trackback($tb_ping, $post_title, $excerpt, $post_id);
@ -634,8 +640,10 @@ function do_trackbacks($post_id) {
} else {
$wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_ping', '')) WHERE ID = '$post_id'");
}
endforeach; endif;
}
}
}
function generic_ping($post_id = 0) {
$services = get_option('ping_sites');
@ -643,14 +651,14 @@ function generic_ping($post_id = 0) {
$services = trim($services);
if ( '' != $services ) {
$services = explode("\n", $services);
foreach ($services as $service) {
foreach ( (array) $services as $service )
weblog_ping($service);
}
}
return $post_id;
}
function pingback($content, $post_ID) {
global $wp_version, $wpdb;
include_once(ABSPATH . WPINC . '/class-IXR.php');
@ -700,7 +708,7 @@ function pingback($content, $post_ID) {
do_action_ref_array('pre_ping', array(&$post_links, &$pung));
foreach ($post_links as $pagelinkedto){
foreach ( (array) $post_links as $pagelinkedto ) {
debug_fwrite($log, "Processing -- $pagelinkedto\n");
$pingback_server_url = discover_pingback_server_uri($pagelinkedto, 2048);
@ -731,6 +739,7 @@ function pingback($content, $post_ID) {
debug_fclose($log);
}
function privacy_ping_filter($sites) {
if ( '0' != get_option('blog_public') )
return $sites;
@ -780,6 +789,7 @@ function trackback($trackback_url, $title, $excerpt, $ID) {
return $wpdb->query("UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, '$tb_url', '')) WHERE ID = '$ID'");
}
function weblog_ping($server = '', $path = '') {
global $wp_version;
include_once(ABSPATH . WPINC . '/class-IXR.php');

View File

@ -5,10 +5,12 @@ function get_bloginfo_rss($show = '') {
return apply_filters('bloginfo_rss', convert_chars($info));
}
function bloginfo_rss($show = '') {
echo get_bloginfo_rss($show);
}
function get_the_title_rss() {
$title = get_the_title();
$title = apply_filters('the_title', $title);
@ -16,10 +18,12 @@ function get_the_title_rss() {
return $title;
}
function the_title_rss() {
echo get_the_title_rss();
}
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 = apply_filters('the_content_rss', $content);
@ -42,9 +46,8 @@ function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file
$k = count($blah);
$use_dotdotdot = 0;
}
for ( $i=0; $i<$k; $i++ ) {
for ( $i=0; $i<$k; $i++ )
$excerpt .= $blah[$i].' ';
}
$excerpt .= ($use_dotdotdot) ? '...' : '';
$content = $excerpt;
}
@ -52,37 +55,46 @@ function the_content_rss($more_link_text='(more...)', $stripteaser=0, $more_file
echo $content;
}
function the_excerpt_rss() {
$output = get_the_excerpt(true);
echo apply_filters('the_excerpt_rss', $output);
}
function permalink_single_rss($file = '') {
echo get_permalink();
}
function comment_link() {
echo get_comment_link();
}
function get_comment_author_rss() {
return apply_filters('comment_author_rss', get_comment_author() );
}
function comment_author_rss() {
echo get_comment_author_rss();
}
function comment_text_rss() {
$comment_text = get_comment_text();
$comment_text = apply_filters('comment_text_rss', $comment_text);
echo $comment_text;
}
function comments_rss_link($link_text = 'Comments RSS', $commentsrssfilename = '') {
$url = comments_rss($commentsrssfilename);
echo "<a href='$url'>$link_text</a>";
}
function comments_rss($commentsrssfilename = '') {
global $id;
@ -94,6 +106,7 @@ function comments_rss($commentsrssfilename = '') {
return apply_filters('post_comments_feed_link', $url);
}
function get_author_rss_link($echo = false, $author_id, $author_nicename) {
$auth_ID = $author_id;
$permalink_structure = get_option('permalink_structure');
@ -112,6 +125,7 @@ function get_author_rss_link($echo = false, $author_id, $author_nicename) {
return $link;
}
function get_category_rss_link($echo = false, $cat_ID, $category_nicename) {
$permalink_structure = get_option('permalink_structure');
@ -129,6 +143,7 @@ function get_category_rss_link($echo = false, $cat_ID, $category_nicename) {
return $link;
}
function get_the_category_rss($type = 'rss') {
$categories = get_the_category();
$the_list = '';
@ -142,10 +157,12 @@ function get_the_category_rss($type = 'rss') {
return apply_filters('the_category_rss', $the_list, $type);
}
function the_category_rss($type = 'rss') {
echo get_the_category_rss($type);
}
function rss_enclosure() {
global $id, $post;
if ( !empty($post->post_password) && ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) )

View File

@ -10,12 +10,14 @@ function username_exists( $username ) {
return null;
}
function email_exists( $email ) {
global $wpdb;
$email = addslashes( $email );
return $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_email = '$email'");
}
function validate_username( $username ) {
$name = sanitize_user($username, true);
$valid = true;
@ -26,6 +28,7 @@ function validate_username( $username ) {
return apply_filters('validate_username', $valid, $username);
}
function wp_insert_user($userdata) {
global $wpdb;
@ -123,6 +126,7 @@ function wp_insert_user($userdata) {
return $user_id;
}
function wp_update_user($userdata) {
global $wpdb;
@ -156,6 +160,7 @@ function wp_update_user($userdata) {
return $user_id;
}
function wp_create_user($username, $password, $email = '') {
global $wpdb;
@ -172,5 +177,4 @@ function create_user( $username, $password, $email ) {
return wp_create_user($username, $password, $email);
}
?>

View File

@ -3,7 +3,7 @@
// On which page are we ?
if ( preg_match('#([^/]+\.php)$#', $PHP_SELF, $self_matches) ) {
$pagenow = $self_matches[1];
} else if (strstr($PHP_SELF, '?')) {
} elseif ( strpos($PHP_SELF, '?') !== false ) {
$pagenow = explode('/', $PHP_SELF);
$pagenow = trim($pagenow[(sizeof($pagenow)-1)]);
$pagenow = explode('?', $pagenow);
@ -13,22 +13,23 @@ if (preg_match('#([^/]+\.php)$#', $PHP_SELF, $self_matches)) {
}
// Simple browser detection
// We should probably be doing true/false instead of 1/0 here ~ Mark
$is_lynx = 0; $is_gecko = 0; $is_winIE = 0; $is_macIE = 0; $is_opera = 0; $is_NS4 = 0;
if (preg_match('/Lynx/', $_SERVER['HTTP_USER_AGENT'])) {
if ( preg_match('/Lynx/', $_SERVER['HTTP_USER_AGENT']) )
$is_lynx = 1;
} elseif (preg_match('/Gecko/', $_SERVER['HTTP_USER_AGENT'])) {
elseif ( preg_match('/Gecko/', $_SERVER['HTTP_USER_AGENT']) )
$is_gecko = 1;
} elseif ((preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) && (preg_match('/Win/', $_SERVER['HTTP_USER_AGENT']))) {
elseif ( preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']) && preg_match('/Win/', $_SERVER['HTTP_USER_AGENT']) )
$is_winIE = 1;
} elseif ((preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT'])) && (preg_match('/Mac/', $_SERVER['HTTP_USER_AGENT']))) {
elseif ( preg_match('/MSIE/', $_SERVER['HTTP_USER_AGENT']) && preg_match('/Mac/', $_SERVER['HTTP_USER_AGENT']) )
$is_macIE = 1;
} elseif (preg_match('/Opera/', $_SERVER['HTTP_USER_AGENT'])) {
elseif ( preg_match('/Opera/', $_SERVER['HTTP_USER_AGENT']) )
$is_opera = 1;
} elseif ((preg_match('/Nav/', $_SERVER['HTTP_USER_AGENT']) ) || (preg_match('/Mozilla\/4\./', $_SERVER['HTTP_USER_AGENT']))) {
elseif ( preg_match('/Nav/', $_SERVER['HTTP_USER_AGENT']) || preg_match('/Mozilla\/4\./', $_SERVER['HTTP_USER_AGENT']) )
$is_NS4 = 1;
}
$is_IE = (($is_macIE) || ($is_winIE));
$is_IE = ( $is_macIE || $is_winIE );
// Server detection
$is_apache = ( strstr($_SERVER['SERVER_SOFTWARE'], 'Apache') || strstr($_SERVER['SERVER_SOFTWARE'], 'LiteSpeed') ) ? 1 : 0;
@ -84,9 +85,8 @@ if (!isset($wpsmiliestrans)) {
);
}
// generates smilies' search & replace arrays
foreach($wpsmiliestrans as $smiley => $img) {
foreach ( (array) $wpsmiliestrans as $smiley => $img ) {
$wp_smiliessearch[] = '/(\s|^)'.preg_quote($smiley, '/').'(\s|$)/';
$smiley_masked = htmlspecialchars(trim($smiley), ENT_QUOTES);
$wp_smiliesreplace[] = " <img src='" . get_option('siteurl') . "/wp-includes/images/smilies/$img' alt='$smiley_masked' class='wp-smiley' /> ";