| [ Index ] |
WordPress Source Cross Reference |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Comment template functions. 4 */ 5 6 function get_comment_author() { 7 global $comment; 8 if ( empty($comment->comment_author) ) 9 $author = __('Anonymous'); 10 else 11 $author = $comment->comment_author; 12 return apply_filters('get_comment_author', $author); 13 } 14 15 function comment_author() { 16 $author = apply_filters('comment_author', get_comment_author() ); 17 echo $author; 18 } 19 20 function get_comment_author_email() { 21 global $comment; 22 return apply_filters('get_comment_author_email', $comment->comment_author_email); 23 } 24 25 function comment_author_email() { 26 echo apply_filters('author_email', get_comment_author_email() ); 27 } 28 29 function comment_author_email_link($linktext='', $before='', $after='') { 30 global $comment; 31 $email = apply_filters('comment_email', $comment->comment_author_email); 32 if ((!empty($email)) && ($email != '@')) { 33 $display = ($linktext != '') ? $linktext : $email; 34 echo $before; 35 echo "<a href='mailto:$email'>$display</a>"; 36 echo $after; 37 } 38 } 39 40 function get_comment_author_link() { 41 global $comment; 42 $url = get_comment_author_url(); 43 $author = get_comment_author(); 44 45 if ( empty( $url ) || 'http://' == $url ) 46 $return = $author; 47 else 48 $return = "<a href='$url' rel='external nofollow'>$author</a>"; 49 return apply_filters('get_comment_author_link', $return); 50 } 51 52 function comment_author_link() { 53 echo get_comment_author_link(); 54 } 55 56 function get_comment_author_IP() { 57 global $comment; 58 return apply_filters('get_comment_author_IP', $comment->comment_author_IP); 59 } 60 61 function comment_author_IP() { 62 echo get_comment_author_IP(); 63 } 64 65 function get_comment_author_url() { 66 global $comment; 67 return apply_filters('get_comment_author_url', $comment->comment_author_url); 68 } 69 70 function comment_author_url() { 71 echo apply_filters('comment_url', get_comment_author_url()); 72 } 73 74 function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) { 75 global $comment; 76 $url = get_comment_author_url(); 77 $display = ($linktext != '') ? $linktext : $url; 78 $display = str_replace( 'http://www.', '', $display ); 79 $display = str_replace( 'http://', '', $display ); 80 if ( '/' == substr($display, -1) ) 81 $display = substr($display, 0, -1); 82 $return = "$before<a href='$url' rel='external'>$display</a>$after"; 83 return apply_filters('get_comment_author_url_link', $return); 84 } 85 86 function comment_author_url_link( $linktext = '', $before = '', $after = '' ) { 87 echo get_comment_author_url_link( $linktext, $before, $after ); 88 } 89 90 function get_comment_date( $d = '' ) { 91 global $comment; 92 if ( '' == $d ) 93 $date = mysql2date( get_settings('date_format'), $comment->comment_date); 94 else 95 $date = mysql2date($d, $comment->comment_date); 96 return apply_filters('get_comment_date', $date); 97 } 98 99 function comment_date( $d = '' ) { 100 echo get_comment_date( $d ); 101 } 102 103 function get_comment_excerpt() { 104 global $comment; 105 $comment_text = strip_tags($comment->comment_content); 106 $blah = explode(' ', $comment_text); 107 if (count($blah) > 20) { 108 $k = 20; 109 $use_dotdotdot = 1; 110 } else { 111 $k = count($blah); 112 $use_dotdotdot = 0; 113 } 114 $excerpt = ''; 115 for ($i=0; $i<$k; $i++) { 116 $excerpt .= $blah[$i] . ' '; 117 } 118 $excerpt .= ($use_dotdotdot) ? '...' : ''; 119 return apply_filters('get_comment_excerpt', $excerpt); 120 } 121 122 function comment_excerpt() { 123 echo apply_filters('comment_excerpt', get_comment_excerpt() ); 124 } 125 126 function get_comment_ID() { 127 global $comment; 128 return apply_filters('get_comment_ID', $comment->comment_ID); 129 } 130 131 function comment_ID() { 132 echo get_comment_ID(); 133 } 134 135 function get_comment_link() { 136 global $comment; 137 return get_permalink( $comment->comment_post_ID ) . '#comment-' . $comment->comment_ID; 138 } 139 140 function get_comments_link() { 141 return get_permalink() . '#comments'; 142 } 143 144 function comments_link( $file = '', $echo = true ) { 145 echo get_comments_link(); 146 } 147 148 function get_comments_number( $post_id = 0 ) { 149 global $wpdb, $id; 150 $post_id = (int) $post_id; 151 152 if ( !$post_id ) 153 $post_id = $id; 154 155 $post = get_post($post_id); 156 if ( ! isset($post->comment_count) ) 157 $count = 0; 158 else 159 $count = $post->comment_count; 160 161 return apply_filters('get_comments_number', $count); 162 } 163 164 function comments_number( $zero = 'No Comments', $one = '1 Comment', $more = '% Comments', $number = '' ) { 165 global $id, $comment; 166 $number = get_comments_number( $id ); 167 if ($number == 0) { 168 $blah = $zero; 169 } elseif ($number == 1) { 170 $blah = $one; 171 } elseif ($number > 1) { 172 $blah = str_replace('%', $number, $more); 173 } 174 echo apply_filters('comments_number', $blah); 175 } 176 177 function get_comment_text() { 178 global $comment; 179 return apply_filters('get_comment_text', $comment->comment_content); 180 } 181 182 function comment_text() { 183 echo apply_filters('comment_text', get_comment_text() ); 184 } 185 186 function get_comment_time( $d = '', $gmt = false ) { 187 global $comment; 188 $comment_date = $gmt? $comment->comment_date_gmt : $comment->comment_date; 189 if ( '' == $d ) 190 $date = mysql2date(get_settings('time_format'), $comment_date); 191 else 192 $date = mysql2date($d, $comment_date); 193 return apply_filters('get_comment_time', $date); 194 } 195 196 function comment_time( $d = '' ) { 197 echo get_comment_time($d); 198 } 199 200 function get_comment_type() { 201 global $comment; 202 203 if ( '' == $comment->comment_type ) 204 $comment->comment_type = 'comment'; 205 206 return apply_filters('get_comment_type', $comment->comment_type); 207 } 208 209 function comment_type($commenttxt = 'Comment', $trackbacktxt = 'Trackback', $pingbacktxt = 'Pingback') { 210 $type = get_comment_type(); 211 switch( $type ) { 212 case 'trackback' : 213 echo $trackbacktxt; 214 break; 215 case 'pingback' : 216 echo $pingbacktxt; 217 break; 218 default : 219 echo $commenttxt; 220 } 221 } 222 223 function get_trackback_url() { 224 global $id; 225 $tb_url = get_settings('siteurl') . '/wp-trackback.php?p=' . $id; 226 227 if ( '' != get_settings('permalink_structure') ) 228 $tb_url = trailingslashit(get_permalink()) . 'trackback/'; 229 230 return $tb_url; 231 } 232 function trackback_url( $display = true ) { 233 if ( $display) 234 echo get_trackback_url(); 235 else 236 return get_trackback_url(); 237 } 238 239 function trackback_rdf($timezone = 0) { 240 global $id; 241 if (!stristr($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator')) { 242 echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 243 xmlns:dc="http://purl.org/dc/elements/1.1/" 244 xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> 245 <rdf:Description rdf:about="'; 246 the_permalink(); 247 echo '"'."\n"; 248 echo ' dc:identifier="'; 249 the_permalink(); 250 echo '"'."\n"; 251 echo ' dc:title="'.str_replace('--', '--', wptexturize(strip_tags(get_the_title()))).'"'."\n"; 252 echo ' trackback:ping="'.trackback_url(0).'"'." />\n"; 253 echo '</rdf:RDF>'; 254 } 255 } 256 257 function comments_open() { 258 global $post; 259 if ( 'open' == $post->comment_status ) 260 return true; 261 else 262 return false; 263 } 264 265 function pings_open() { 266 global $post; 267 if ( 'open' == $post->ping_status ) 268 return true; 269 else 270 return false; 271 } 272 273 function comments_template( $file = '/comments.php' ) { 274 global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity; 275 276 if ( ! (is_single() || is_page() || $withcomments) ) 277 return; 278 279 $req = get_settings('require_name_email'); 280 $commenter = wp_get_current_commenter(); 281 extract($commenter); 282 283 // TODO: Use API instead of SELECTs. 284 if ( empty($comment_author) ) { 285 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_approved = '1' ORDER BY comment_date"); 286 } else { 287 $author_db = $wpdb->escape($comment_author); 288 $email_db = $wpdb->escape($comment_author_email); 289 $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND ( comment_approved = '1' OR ( comment_author = '$author_db' AND comment_author_email = '$email_db' AND comment_approved = '0' ) ) ORDER BY comment_date"); 290 } 291 292 define('COMMENTS_TEMPLATE', true); 293 $include = apply_filters('comments_template', TEMPLATEPATH . $file ); 294 if ( file_exists( $include ) ) 295 require( $include ); 296 else 297 require ( ABSPATH . 'wp-content/themes/default/comments.php'); 298 } 299 300 function comments_popup_script($width=400, $height=400, $file='') { 301 global $wpcommentspopupfile, $wptrackbackpopupfile, $wppingbackpopupfile, $wpcommentsjavascript; 302 303 if (empty ($file)) { 304 $wpcommentspopupfile = ''; // Use the index. 305 } else { 306 $wpcommentspopupfile = $file; 307 } 308 309 $wpcommentsjavascript = 1; 310 $javascript = "<script type='text/javascript'>\nfunction wpopen (macagna) {\n window.open(macagna, '_blank', 'width=$width,height=$height,scrollbars=yes,status=yes');\n}\n</script>\n"; 311 echo $javascript; 312 } 313 314 function comments_popup_link($zero='No Comments', $one='1 Comment', $more='% Comments', $CSSclass='', $none='Comments Off') { 315 global $id, $wpcommentspopupfile, $wpcommentsjavascript, $post, $wpdb; 316 317 if ( is_single() || is_page() ) 318 return; 319 320 $number = get_comments_number($id); 321 322 if ( 0 == $number && 'closed' == $post->comment_status && 'closed' == $post->ping_status ) { 323 echo $none; 324 return; 325 } 326 327 if ( !empty($post->post_password) ) { // if there's a password 328 if ($_COOKIE['wp-postpass_'.COOKIEHASH] != $post->post_password) { // and it doesn't match the cookie 329 echo(__('Enter your password to view comments')); 330 return; 331 } 332 } 333 334 echo '<a href="'; 335 if ($wpcommentsjavascript) { 336 if ( empty($wpcommentspopupfile) ) 337 $home = get_settings('home'); 338 else 339 $home = get_settings('siteurl'); 340 echo $home . '/' . $wpcommentspopupfile.'?comments_popup='.$id; 341 echo '" onclick="wpopen(this.href); return false"'; 342 } else { // if comments_popup_script() is not in the template, display simple comment link 343 if ( 0 == $number ) 344 echo get_permalink() . '#respond'; 345 else 346 comments_link(); 347 echo '"'; 348 } 349 350 if (!empty($CSSclass)) { 351 echo ' class="'.$CSSclass.'"'; 352 } 353 $title = wp_specialchars(apply_filters('the_title', get_the_title()), true); 354 echo ' title="' . sprintf( __('Comment on %s'), $title ) .'">'; 355 comments_number($zero, $one, $more, $number); 356 echo '</a>'; 357 } 358 359 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sat Jul 15 11:57:04 2006 | Courtesy of Taragana |