PageRenderTime 55ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/branches/2.2/wp-includes/comment-template.php

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