PageRenderTime 67ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-includes/comment-template.php

https://bitbucket.org/cisash/fananeen
PHP | 1592 lines | 738 code | 172 blank | 682 comment | 184 complexity | 1707c9d7758eef6fc40340b54d1a1de3 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Comment template functions
  4. *
  5. * These functions are meant to live inside of the WordPress loop.
  6. *
  7. * @package WordPress
  8. * @subpackage Template
  9. */
  10. /**
  11. * Retrieve the author of the current comment.
  12. *
  13. * If the comment has an empty comment_author field, then 'Anonymous' person is
  14. * assumed.
  15. *
  16. * @since 1.5.0
  17. * @uses apply_filters() Calls 'get_comment_author' hook on the comment author
  18. *
  19. * @param int $comment_ID The ID of the comment for which to retrieve the author. Optional.
  20. * @return string The comment author
  21. */
  22. function get_comment_author( $comment_ID = 0 ) {
  23. $comment = get_comment( $comment_ID );
  24. if ( empty($comment->comment_author) ) {
  25. if (!empty($comment->user_id)){
  26. $user=get_userdata($comment->user_id);
  27. $author=$user->user_login;
  28. } else {
  29. $author = __('Anonymous');
  30. }
  31. } else {
  32. $author = $comment->comment_author;
  33. }
  34. return apply_filters('get_comment_author', $author);
  35. }
  36. /**
  37. * Displays the author of the current comment.
  38. *
  39. * @since 0.71
  40. * @uses apply_filters() Calls 'comment_author' on comment author before displaying
  41. *
  42. * @param int $comment_ID The ID of the comment for which to print the author. Optional.
  43. */
  44. function comment_author( $comment_ID = 0 ) {
  45. $author = apply_filters('comment_author', get_comment_author( $comment_ID ) );
  46. echo $author;
  47. }
  48. /**
  49. * Retrieve the email of the author of the current comment.
  50. *
  51. * @since 1.5.0
  52. * @uses apply_filters() Calls the 'get_comment_author_email' hook on the comment author email
  53. * @uses $comment
  54. *
  55. * @param int $comment_ID The ID of the comment for which to get the author's email. Optional.
  56. * @return string The current comment author's email
  57. */
  58. function get_comment_author_email( $comment_ID = 0 ) {
  59. $comment = get_comment( $comment_ID );
  60. return apply_filters('get_comment_author_email', $comment->comment_author_email);
  61. }
  62. /**
  63. * Display the email of the author of the current global $comment.
  64. *
  65. * Care should be taken to protect the email address and assure that email
  66. * harvesters do not capture your commentors' email address. Most assume that
  67. * their email address will not appear in raw form on the blog. Doing so will
  68. * enable anyone, including those that people don't want to get the email
  69. * address and use it for their own means good and bad.
  70. *
  71. * @since 0.71
  72. * @uses apply_filters() Calls 'author_email' hook on the author email
  73. *
  74. * @param int $comment_ID The ID of the comment for which to print the author's email. Optional.
  75. */
  76. function comment_author_email( $comment_ID = 0 ) {
  77. echo apply_filters('author_email', get_comment_author_email( $comment_ID ) );
  78. }
  79. /**
  80. * Display the html email link to the author of the current comment.
  81. *
  82. * Care should be taken to protect the email address and assure that email
  83. * harvesters do not capture your commentors' email address. Most assume that
  84. * their email address will not appear in raw form on the blog. Doing so will
  85. * enable anyone, including those that people don't want to get the email
  86. * address and use it for their own means good and bad.
  87. *
  88. * @since 0.71
  89. * @uses apply_filters() Calls 'comment_email' hook for the display of the comment author's email
  90. * @uses get_comment_author_email_link() For generating the link
  91. * @global object $comment The current Comment row object
  92. *
  93. * @param string $linktext The text to display instead of the comment author's email address
  94. * @param string $before The text or HTML to display before the email link.
  95. * @param string $after The text or HTML to display after the email link.
  96. */
  97. function comment_author_email_link($linktext='', $before='', $after='') {
  98. if ( $link = get_comment_author_email_link( $linktext, $before, $after ) )
  99. echo $link;
  100. }
  101. /**
  102. * Return the html email link to the author of the current comment.
  103. *
  104. * Care should be taken to protect the email address and assure that email
  105. * harvesters do not capture your commentors' email address. Most assume that
  106. * their email address will not appear in raw form on the blog. Doing so will
  107. * enable anyone, including those that people don't want to get the email
  108. * address and use it for their own means good and bad.
  109. *
  110. * @since 2.7
  111. * @uses apply_filters() Calls 'comment_email' hook for the display of the comment author's email
  112. * @global object $comment The current Comment row object
  113. *
  114. * @param string $linktext The text to display instead of the comment author's email address
  115. * @param string $before The text or HTML to display before the email link.
  116. * @param string $after The text or HTML to display after the email link.
  117. */
  118. function get_comment_author_email_link($linktext='', $before='', $after='') {
  119. global $comment;
  120. $email = apply_filters('comment_email', $comment->comment_author_email);
  121. if ((!empty($email)) && ($email != '@')) {
  122. $display = ($linktext != '') ? $linktext : $email;
  123. $return = $before;
  124. $return .= "<a href='mailto:$email'>$display</a>";
  125. $return .= $after;
  126. return $return;
  127. } else {
  128. return '';
  129. }
  130. }
  131. /**
  132. * Retrieve the html link to the url of the author of the current comment.
  133. *
  134. * @since 1.5.0
  135. * @uses apply_filters() Calls 'get_comment_author_link' hook on the complete link HTML or author
  136. *
  137. * @param int $comment_ID The ID of the comment for which to get the author's link. Optional.
  138. * @return string Comment Author name or HTML link for author's URL
  139. */
  140. function get_comment_author_link( $comment_ID = 0 ) {
  141. /** @todo Only call these functions when they are needed. Include in if... else blocks */
  142. $url = get_comment_author_url( $comment_ID );
  143. $author = get_comment_author( $comment_ID );
  144. if ( empty( $url ) || 'http://' == $url )
  145. $return = $author;
  146. else
  147. $return = "<a href='$url' rel='external nofollow' class='url'>$author</a>";
  148. return apply_filters('get_comment_author_link', $return);
  149. }
  150. /**
  151. * Display the html link to the url of the author of the current comment.
  152. *
  153. * @since 0.71
  154. * @see get_comment_author_link() Echoes result
  155. *
  156. * @param int $comment_ID The ID of the comment for which to print the author's link. Optional.
  157. */
  158. function comment_author_link( $comment_ID = 0 ) {
  159. echo get_comment_author_link( $comment_ID );
  160. }
  161. /**
  162. * Retrieve the IP address of the author of the current comment.
  163. *
  164. * @since 1.5.0
  165. * @uses $comment
  166. * @uses apply_filters()
  167. *
  168. * @param int $comment_ID The ID of the comment for which to get the author's IP address. Optional.
  169. * @return string The comment author's IP address.
  170. */
  171. function get_comment_author_IP( $comment_ID = 0 ) {
  172. $comment = get_comment( $comment_ID );
  173. return apply_filters('get_comment_author_IP', $comment->comment_author_IP);
  174. }
  175. /**
  176. * Display the IP address of the author of the current comment.
  177. *
  178. * @since 0.71
  179. * @see get_comment_author_IP() Echoes Result
  180. *
  181. * @param int $comment_ID The ID of the comment for which to print the author's IP address. Optional.
  182. */
  183. function comment_author_IP( $comment_ID = 0 ) {
  184. echo get_comment_author_IP( $comment_ID );
  185. }
  186. /**
  187. * Retrieve the url of the author of the current comment.
  188. *
  189. * @since 1.5.0
  190. * @uses apply_filters() Calls 'get_comment_author_url' hook on the comment author's URL
  191. *
  192. * @param int $comment_ID The ID of the comment for which to get the author's URL. Optional.
  193. * @return string
  194. */
  195. function get_comment_author_url( $comment_ID = 0 ) {
  196. $comment = get_comment( $comment_ID );
  197. $url = ('http://' == $comment->comment_author_url) ? '' : $comment->comment_author_url;
  198. $url = esc_url( $url, array('http', 'https') );
  199. return apply_filters('get_comment_author_url', $url);
  200. }
  201. /**
  202. * Display the url of the author of the current comment.
  203. *
  204. * @since 0.71
  205. * @uses apply_filters()
  206. * @uses get_comment_author_url() Retrieves the comment author's URL
  207. *
  208. * @param int $comment_ID The ID of the comment for which to print the author's URL. Optional.
  209. */
  210. function comment_author_url( $comment_ID = 0 ) {
  211. echo apply_filters('comment_url', get_comment_author_url( $comment_ID ));
  212. }
  213. /**
  214. * Retrieves the HTML link of the url of the author of the current comment.
  215. *
  216. * $linktext parameter is only used if the URL does not exist for the comment
  217. * author. If the URL does exist then the URL will be used and the $linktext
  218. * will be ignored.
  219. *
  220. * Encapsulate the HTML link between the $before and $after. So it will appear
  221. * in the order of $before, link, and finally $after.
  222. *
  223. * @since 1.5.0
  224. * @uses apply_filters() Calls the 'get_comment_author_url_link' on the complete HTML before returning.
  225. *
  226. * @param string $linktext The text to display instead of the comment author's email address
  227. * @param string $before The text or HTML to display before the email link.
  228. * @param string $after The text or HTML to display after the email link.
  229. * @return string The HTML link between the $before and $after parameters
  230. */
  231. function get_comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
  232. $url = get_comment_author_url();
  233. $display = ($linktext != '') ? $linktext : $url;
  234. $display = str_replace( 'http://www.', '', $display );
  235. $display = str_replace( 'http://', '', $display );
  236. if ( '/' == substr($display, -1) )
  237. $display = substr($display, 0, -1);
  238. $return = "$before<a href='$url' rel='external'>$display</a>$after";
  239. return apply_filters('get_comment_author_url_link', $return);
  240. }
  241. /**
  242. * Displays the HTML link of the url of the author of the current comment.
  243. *
  244. * @since 0.71
  245. * @see get_comment_author_url_link() Echoes result
  246. *
  247. * @param string $linktext The text to display instead of the comment author's email address
  248. * @param string $before The text or HTML to display before the email link.
  249. * @param string $after The text or HTML to display after the email link.
  250. */
  251. function comment_author_url_link( $linktext = '', $before = '', $after = '' ) {
  252. echo get_comment_author_url_link( $linktext, $before, $after );
  253. }
  254. /**
  255. * Generates semantic classes for each comment element
  256. *
  257. * @since 2.7.0
  258. *
  259. * @param string|array $class One or more classes to add to the class list
  260. * @param int $comment_id An optional comment ID
  261. * @param int $post_id An optional post ID
  262. * @param bool $echo Whether comment_class should echo or return
  263. */
  264. function comment_class( $class = '', $comment_id = null, $post_id = null, $echo = true ) {
  265. // Separates classes with a single space, collates classes for comment DIV
  266. $class = 'class="' . join( ' ', get_comment_class( $class, $comment_id, $post_id ) ) . '"';
  267. if ( $echo)
  268. echo $class;
  269. else
  270. return $class;
  271. }
  272. /**
  273. * Returns the classes for the comment div as an array
  274. *
  275. * @since 2.7.0
  276. *
  277. * @param string|array $class One or more classes to add to the class list
  278. * @param int $comment_id An optional comment ID
  279. * @param int $post_id An optional post ID
  280. * @return array Array of classes
  281. */
  282. function get_comment_class( $class = '', $comment_id = null, $post_id = null ) {
  283. global $comment_alt, $comment_depth, $comment_thread_alt;
  284. $comment = get_comment($comment_id);
  285. $classes = array();
  286. // Get the comment type (comment, trackback),
  287. $classes[] = ( empty( $comment->comment_type ) ) ? 'comment' : $comment->comment_type;
  288. // If the comment author has an id (registered), then print the log in name
  289. if ( $comment->user_id > 0 && $user = get_userdata($comment->user_id) ) {
  290. // For all registered users, 'byuser'
  291. $classes[] = 'byuser';
  292. $classes[] = 'comment-author-' . sanitize_html_class($user->user_nicename, $comment->user_id);
  293. // For comment authors who are the author of the post
  294. if ( $post = get_post($post_id) ) {
  295. if ( $comment->user_id === $post->post_author )
  296. $classes[] = 'bypostauthor';
  297. }
  298. }
  299. if ( empty($comment_alt) )
  300. $comment_alt = 0;
  301. if ( empty($comment_depth) )
  302. $comment_depth = 1;
  303. if ( empty($comment_thread_alt) )
  304. $comment_thread_alt = 0;
  305. if ( $comment_alt % 2 ) {
  306. $classes[] = 'odd';
  307. $classes[] = 'alt';
  308. } else {
  309. $classes[] = 'even';
  310. }
  311. $comment_alt++;
  312. // Alt for top-level comments
  313. if ( 1 == $comment_depth ) {
  314. if ( $comment_thread_alt % 2 ) {
  315. $classes[] = 'thread-odd';
  316. $classes[] = 'thread-alt';
  317. } else {
  318. $classes[] = 'thread-even';
  319. }
  320. $comment_thread_alt++;
  321. }
  322. $classes[] = "depth-$comment_depth";
  323. if ( !empty($class) ) {
  324. if ( !is_array( $class ) )
  325. $class = preg_split('#\s+#', $class);
  326. $classes = array_merge($classes, $class);
  327. }
  328. $classes = array_map('esc_attr', $classes);
  329. return apply_filters('comment_class', $classes, $class, $comment_id, $post_id);
  330. }
  331. /**
  332. * Retrieve the comment date of the current comment.
  333. *
  334. * @since 1.5.0
  335. * @uses apply_filters() Calls 'get_comment_date' hook with the formatted date and the $d parameter respectively
  336. * @uses $comment
  337. *
  338. * @param string $d The format of the date (defaults to user's config)
  339. * @param int $comment_ID The ID of the comment for which to get the date. Optional.
  340. * @return string The comment's date
  341. */
  342. function get_comment_date( $d = '', $comment_ID = 0 ) {
  343. $comment = get_comment( $comment_ID );
  344. if ( '' == $d )
  345. $date = mysql2date(get_option('date_format'), $comment->comment_date);
  346. else
  347. $date = mysql2date($d, $comment->comment_date);
  348. return apply_filters('get_comment_date', $date, $d);
  349. }
  350. /**
  351. * Display the comment date of the current comment.
  352. *
  353. * @since 0.71
  354. *
  355. * @param string $d The format of the date (defaults to user's config)
  356. * @param int $comment_ID The ID of the comment for which to print the date. Optional.
  357. */
  358. function comment_date( $d = '', $comment_ID = 0 ) {
  359. echo get_comment_date( $d, $comment_ID );
  360. }
  361. /**
  362. * Retrieve the excerpt of the current comment.
  363. *
  364. * Will cut each word and only output the first 20 words with '...' at the end.
  365. * If the word count is less than 20, then no truncating is done and no '...'
  366. * will appear.
  367. *
  368. * @since 1.5.0
  369. * @uses $comment
  370. * @uses apply_filters() Calls 'get_comment_excerpt' on truncated comment
  371. *
  372. * @param int $comment_ID The ID of the comment for which to get the excerpt. Optional.
  373. * @return string The maybe truncated comment with 20 words or less
  374. */
  375. function get_comment_excerpt( $comment_ID = 0 ) {
  376. $comment = get_comment( $comment_ID );
  377. $comment_text = strip_tags($comment->comment_content);
  378. $blah = explode(' ', $comment_text);
  379. if (count($blah) > 20) {
  380. $k = 20;
  381. $use_dotdotdot = 1;
  382. } else {
  383. $k = count($blah);
  384. $use_dotdotdot = 0;
  385. }
  386. $excerpt = '';
  387. for ($i=0; $i<$k; $i++) {
  388. $excerpt .= $blah[$i] . ' ';
  389. }
  390. $excerpt .= ($use_dotdotdot) ? '...' : '';
  391. return apply_filters('get_comment_excerpt', $excerpt);
  392. }
  393. /**
  394. * Display the excerpt of the current comment.
  395. *
  396. * @since 1.2.0
  397. * @uses apply_filters() Calls 'comment_excerpt' hook before displaying excerpt
  398. *
  399. * @param int $comment_ID The ID of the comment for which to print the excerpt. Optional.
  400. */
  401. function comment_excerpt( $comment_ID = 0 ) {
  402. echo apply_filters('comment_excerpt', get_comment_excerpt($comment_ID) );
  403. }
  404. /**
  405. * Retrieve the comment id of the current comment.
  406. *
  407. * @since 1.5.0
  408. * @uses $comment
  409. * @uses apply_filters() Calls the 'get_comment_ID' hook for the comment ID
  410. *
  411. * @return int The comment ID
  412. */
  413. function get_comment_ID() {
  414. global $comment;
  415. return apply_filters('get_comment_ID', $comment->comment_ID);
  416. }
  417. /**
  418. * Displays the comment id of the current comment.
  419. *
  420. * @since 0.71
  421. * @see get_comment_ID() Echoes Result
  422. */
  423. function comment_ID() {
  424. echo get_comment_ID();
  425. }
  426. /**
  427. * Retrieve the link to a given comment.
  428. *
  429. * @since 1.5.0
  430. * @uses $comment
  431. *
  432. * @param object|string|int $comment Comment to retrieve.
  433. * @param array $args Optional args.
  434. * @return string The permalink to the given comment.
  435. */
  436. function get_comment_link( $comment = null, $args = array() ) {
  437. global $wp_rewrite, $in_comment_loop;
  438. $comment = get_comment($comment);
  439. // Backwards compat
  440. if ( !is_array($args) ) {
  441. $page = $args;
  442. $args = array();
  443. $args['page'] = $page;
  444. }
  445. $defaults = array( 'type' => 'all', 'page' => '', 'per_page' => '', 'max_depth' => '' );
  446. $args = wp_parse_args( $args, $defaults );
  447. if ( '' === $args['per_page'] && get_option('page_comments') )
  448. $args['per_page'] = get_option('comments_per_page');
  449. if ( empty($args['per_page']) ) {
  450. $args['per_page'] = 0;
  451. $args['page'] = 0;
  452. }
  453. if ( $args['per_page'] ) {
  454. if ( '' == $args['page'] )
  455. $args['page'] = ( !empty($in_comment_loop) ) ? get_query_var('cpage') : get_page_of_comment( $comment->comment_ID, $args );
  456. if ( $wp_rewrite->using_permalinks() )
  457. $link = user_trailingslashit( trailingslashit( get_permalink( $comment->comment_post_ID ) ) . 'comment-page-' . $args['page'], 'comment' );
  458. else
  459. $link = add_query_arg( 'cpage', $args['page'], get_permalink( $comment->comment_post_ID ) );
  460. } else {
  461. $link = get_permalink( $comment->comment_post_ID );
  462. }
  463. return apply_filters( 'get_comment_link', $link . '#comment-' . $comment->comment_ID, $comment, $args );
  464. }
  465. /**
  466. * Retrieves the link to the current post comments.
  467. *
  468. * @since 1.5.0
  469. *
  470. * @param int $post_id Optional post id
  471. * @return string The link to the comments
  472. */
  473. function get_comments_link($post_id = 0) {
  474. return get_permalink($post_id) . '#comments';
  475. }
  476. /**
  477. * Displays the link to the current post comments.
  478. *
  479. * @since 0.71
  480. *
  481. * @param string $deprecated Not Used
  482. * @param bool $deprecated_2 Not Used
  483. */
  484. function comments_link( $deprecated = '', $deprecated_2 = '' ) {
  485. if ( !empty( $deprecated ) )
  486. _deprecated_argument( __FUNCTION__, '0.72' );
  487. if ( !empty( $deprecated_2 ) )
  488. _deprecated_argument( __FUNCTION__, '1.3' );
  489. echo get_comments_link();
  490. }
  491. /**
  492. * Retrieve the amount of comments a post has.
  493. *
  494. * @since 1.5.0
  495. * @uses apply_filters() Calls the 'get_comments_number' hook on the number of comments
  496. *
  497. * @param int $post_id The Post ID
  498. * @return int The number of comments a post has
  499. */
  500. function get_comments_number( $post_id = 0 ) {
  501. $post_id = absint( $post_id );
  502. if ( !$post_id )
  503. $post_id = get_the_ID();
  504. $post = get_post($post_id);
  505. if ( ! isset($post->comment_count) )
  506. $count = 0;
  507. else
  508. $count = $post->comment_count;
  509. return apply_filters('get_comments_number', $count, $post_id);
  510. }
  511. /**
  512. * Display the language string for the number of comments the current post has.
  513. *
  514. * @since 0.71
  515. * @uses apply_filters() Calls the 'comments_number' hook on the output and number of comments respectively.
  516. *
  517. * @param string $zero Text for no comments
  518. * @param string $one Text for one comment
  519. * @param string $more Text for more than one comment
  520. * @param string $deprecated Not used.
  521. */
  522. function comments_number( $zero = false, $one = false, $more = false, $deprecated = '' ) {
  523. if ( !empty( $deprecated ) )
  524. _deprecated_argument( __FUNCTION__, '1.3' );
  525. $number = get_comments_number();
  526. if ( $number > 1 )
  527. $output = str_replace('%', number_format_i18n($number), ( false === $more ) ? __('% Comments') : $more);
  528. elseif ( $number == 0 )
  529. $output = ( false === $zero ) ? __('No Comments') : $zero;
  530. else // must be one
  531. $output = ( false === $one ) ? __('1 Comment') : $one;
  532. echo apply_filters('comments_number', $output, $number);
  533. }
  534. /**
  535. * Retrieve the text of the current comment.
  536. *
  537. * @since 1.5.0
  538. * @uses $comment
  539. *
  540. * @param int $comment_ID The ID of the comment for which to get the text. Optional.
  541. * @return string The comment content
  542. */
  543. function get_comment_text( $comment_ID = 0 ) {
  544. $comment = get_comment( $comment_ID );
  545. return apply_filters( 'get_comment_text', $comment->comment_content, $comment );
  546. }
  547. /**
  548. * Displays the text of the current comment.
  549. *
  550. * @since 0.71
  551. * @uses apply_filters() Passes the comment content through the 'comment_text' hook before display
  552. * @uses get_comment_text() Gets the comment content
  553. *
  554. * @param int $comment_ID The ID of the comment for which to print the text. Optional.
  555. */
  556. function comment_text( $comment_ID = 0 ) {
  557. $comment = get_comment( $comment_ID );
  558. echo apply_filters( 'comment_text', get_comment_text( $comment_ID ), $comment );
  559. }
  560. /**
  561. * Retrieve the comment time of the current comment.
  562. *
  563. * @since 1.5.0
  564. * @uses $comment
  565. * @uses apply_filter() Calls 'get_comment_time' hook with the formatted time, the $d parameter, and $gmt parameter passed.
  566. *
  567. * @param string $d Optional. The format of the time (defaults to user's config)
  568. * @param bool $gmt Whether to use the GMT date
  569. * @param bool $translate Whether to translate the time (for use in feeds)
  570. * @return string The formatted time
  571. */
  572. function get_comment_time( $d = '', $gmt = false, $translate = true ) {
  573. global $comment;
  574. $comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
  575. if ( '' == $d )
  576. $date = mysql2date(get_option('time_format'), $comment_date, $translate);
  577. else
  578. $date = mysql2date($d, $comment_date, $translate);
  579. return apply_filters('get_comment_time', $date, $d, $gmt, $translate);
  580. }
  581. /**
  582. * Display the comment time of the current comment.
  583. *
  584. * @since 0.71
  585. *
  586. * @param string $d Optional. The format of the time (defaults to user's config)
  587. */
  588. function comment_time( $d = '' ) {
  589. echo get_comment_time($d);
  590. }
  591. /**
  592. * Retrieve the comment type of the current comment.
  593. *
  594. * @since 1.5.0
  595. * @uses $comment
  596. * @uses apply_filters() Calls the 'get_comment_type' hook on the comment type
  597. *
  598. * @param int $comment_ID The ID of the comment for which to get the type. Optional.
  599. * @return string The comment type
  600. */
  601. function get_comment_type( $comment_ID = 0 ) {
  602. $comment = get_comment( $comment_ID );
  603. if ( '' == $comment->comment_type )
  604. $comment->comment_type = 'comment';
  605. return apply_filters('get_comment_type', $comment->comment_type);
  606. }
  607. /**
  608. * Display the comment type of the current comment.
  609. *
  610. * @since 0.71
  611. *
  612. * @param string $commenttxt The string to display for comment type
  613. * @param string $trackbacktxt The string to display for trackback type
  614. * @param string $pingbacktxt The string to display for pingback type
  615. */
  616. function comment_type($commenttxt = false, $trackbacktxt = false, $pingbacktxt = false) {
  617. if ( false === $commenttxt ) $commenttxt = _x( 'Comment', 'noun' );
  618. if ( false === $trackbacktxt ) $trackbacktxt = __( 'Trackback' );
  619. if ( false === $pingbacktxt ) $pingbacktxt = __( 'Pingback' );
  620. $type = get_comment_type();
  621. switch( $type ) {
  622. case 'trackback' :
  623. echo $trackbacktxt;
  624. break;
  625. case 'pingback' :
  626. echo $pingbacktxt;
  627. break;
  628. default :
  629. echo $commenttxt;
  630. }
  631. }
  632. /**
  633. * Retrieve The current post's trackback URL.
  634. *
  635. * There is a check to see if permalink's have been enabled and if so, will
  636. * retrieve the pretty path. If permalinks weren't enabled, the ID of the
  637. * current post is used and appended to the correct page to go to.
  638. *
  639. * @since 1.5.0
  640. * @uses apply_filters() Calls 'trackback_url' on the resulting trackback URL
  641. *
  642. * @return string The trackback URL after being filtered
  643. */
  644. function get_trackback_url() {
  645. if ( '' != get_option('permalink_structure') ) {
  646. $tb_url = trailingslashit(get_permalink()) . user_trailingslashit('trackback', 'single_trackback');
  647. } else {
  648. $tb_url = get_option('siteurl') . '/wp-trackback.php?p=' . get_the_ID();
  649. }
  650. return apply_filters('trackback_url', $tb_url);
  651. }
  652. /**
  653. * Displays the current post's trackback URL.
  654. *
  655. * @since 0.71
  656. * @uses get_trackback_url() Gets the trackback url for the current post
  657. *
  658. * @param bool $deprecated_echo Remove backwards compat in 2.5
  659. * @return void|string Should only be used to echo the trackback URL, use get_trackback_url() for the result instead.
  660. */
  661. function trackback_url( $deprecated_echo = true ) {
  662. if ( $deprecated_echo !== true )
  663. _deprecated_argument( __FUNCTION__, '2.5', __('Use <code>get_trackback_url()</code> instead if you do not want the value echoed.') );
  664. if ( $deprecated_echo )
  665. echo get_trackback_url();
  666. else
  667. return get_trackback_url();
  668. }
  669. /**
  670. * Generates and displays the RDF for the trackback information of current post.
  671. *
  672. * Deprecated in 3.0.0, and restored in 3.0.1.
  673. *
  674. * @since 0.71
  675. *
  676. * @param int $deprecated Not used (Was $timezone = 0)
  677. */
  678. function trackback_rdf( $deprecated = '' ) {
  679. if ( !empty( $deprecated ) )
  680. _deprecated_argument( __FUNCTION__, '2.5' );
  681. if ( false !== stripos($_SERVER['HTTP_USER_AGENT'], 'W3C_Validator') )
  682. return;
  683. echo '<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  684. xmlns:dc="http://purl.org/dc/elements/1.1/"
  685. xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  686. <rdf:Description rdf:about="';
  687. the_permalink();
  688. echo '"'."\n";
  689. echo ' dc:identifier="';
  690. the_permalink();
  691. echo '"'."\n";
  692. echo ' dc:title="'.str_replace('--', '&#x2d;&#x2d;', wptexturize(strip_tags(get_the_title()))).'"'."\n";
  693. echo ' trackback:ping="'.get_trackback_url().'"'." />\n";
  694. echo '</rdf:RDF>';
  695. }
  696. /**
  697. * Whether the current post is open for comments.
  698. *
  699. * @since 1.5.0
  700. * @uses $post
  701. *
  702. * @param int $post_id An optional post ID to check instead of the current post.
  703. * @return bool True if the comments are open
  704. */
  705. function comments_open( $post_id = null ) {
  706. $_post = get_post($post_id);
  707. $open = ( 'open' == $_post->comment_status );
  708. return apply_filters( 'comments_open', $open, $post_id );
  709. }
  710. /**
  711. * Whether the current post is open for pings.
  712. *
  713. * @since 1.5.0
  714. * @uses $post
  715. *
  716. * @param int $post_id An optional post ID to check instead of the current post.
  717. * @return bool True if pings are accepted
  718. */
  719. function pings_open( $post_id = null ) {
  720. $_post = get_post($post_id);
  721. $open = ( 'open' == $_post->ping_status );
  722. return apply_filters( 'pings_open', $open, $post_id );
  723. }
  724. /**
  725. * Displays form token for unfiltered comments.
  726. *
  727. * Will only display nonce token if the current user has permissions for
  728. * unfiltered html. Won't display the token for other users.
  729. *
  730. * The function was backported to 2.0.10 and was added to versions 2.1.3 and
  731. * above. Does not exist in versions prior to 2.0.10 in the 2.0 branch and in
  732. * the 2.1 branch, prior to 2.1.3. Technically added in 2.2.0.
  733. *
  734. * Backported to 2.0.10.
  735. *
  736. * @since 2.1.3
  737. * @uses $post Gets the ID of the current post for the token
  738. */
  739. function wp_comment_form_unfiltered_html_nonce() {
  740. global $post;
  741. $post_id = 0;
  742. if ( !empty($post) )
  743. $post_id = $post->ID;
  744. if ( current_user_can( 'unfiltered_html' ) ) {
  745. wp_nonce_field( 'unfiltered-html-comment_' . $post_id, '_wp_unfiltered_html_comment_disabled', false );
  746. echo "<script>(function(){if(window===window.parent){document.getElementById('_wp_unfiltered_html_comment_disabled').name='_wp_unfiltered_html_comment';}})();</script>\n";
  747. }
  748. }
  749. /**
  750. * Loads the comment template specified in $file.
  751. *
  752. * Will not display the comments template if not on single post or page, or if
  753. * the post does not have comments.
  754. *
  755. * Uses the WordPress database object to query for the comments. The comments
  756. * are passed through the 'comments_array' filter hook with the list of comments
  757. * and the post ID respectively.
  758. *
  759. * The $file path is passed through a filter hook called, 'comments_template'
  760. * which includes the TEMPLATEPATH and $file combined. Tries the $filtered path
  761. * first and if it fails it will require the default comment template from the
  762. * default theme. If either does not exist, then the WordPress process will be
  763. * halted. It is advised for that reason, that the default theme is not deleted.
  764. *
  765. * @since 1.5.0
  766. * @global array $comment List of comment objects for the current post
  767. * @uses $wpdb
  768. * @uses $post
  769. * @uses $withcomments Will not try to get the comments if the post has none.
  770. *
  771. * @param string $file Optional, default '/comments.php'. The file to load
  772. * @param bool $separate_comments Optional, whether to separate the comments by comment type. Default is false.
  773. * @return null Returns null if no comments appear
  774. */
  775. function comments_template( $file = '/comments.php', $separate_comments = false ) {
  776. global $wp_query, $withcomments, $post, $wpdb, $id, $comment, $user_login, $user_ID, $user_identity, $overridden_cpage;
  777. if ( !(is_single() || is_page() || $withcomments) || empty($post) )
  778. return;
  779. if ( empty($file) )
  780. $file = '/comments.php';
  781. $req = get_option('require_name_email');
  782. /**
  783. * Comment author information fetched from the comment cookies.
  784. *
  785. * @uses wp_get_current_commenter()
  786. */
  787. $commenter = wp_get_current_commenter();
  788. /**
  789. * The name of the current comment author escaped for use in attributes.
  790. */
  791. $comment_author = $commenter['comment_author']; // Escaped by sanitize_comment_cookies()
  792. /**
  793. * The email address of the current comment author escaped for use in attributes.
  794. */
  795. $comment_author_email = $commenter['comment_author_email']; // Escaped by sanitize_comment_cookies()
  796. /**
  797. * The url of the current comment author escaped for use in attributes.
  798. */
  799. $comment_author_url = esc_url($commenter['comment_author_url']);
  800. /** @todo Use API instead of SELECTs. */
  801. if ( $user_ID) {
  802. $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND (comment_approved = '1' OR ( user_id = %d AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, $user_ID));
  803. } else if ( empty($comment_author) ) {
  804. $comments = get_comments( array('post_id' => $post->ID, 'status' => 'approve', 'order' => 'ASC') );
  805. } else {
  806. $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND ( comment_approved = '1' OR ( comment_author = %s AND comment_author_email = %s AND comment_approved = '0' ) ) ORDER BY comment_date_gmt", $post->ID, wp_specialchars_decode($comment_author,ENT_QUOTES), $comment_author_email));
  807. }
  808. // keep $comments for legacy's sake
  809. $wp_query->comments = apply_filters( 'comments_array', $comments, $post->ID );
  810. $comments = &$wp_query->comments;
  811. $wp_query->comment_count = count($wp_query->comments);
  812. update_comment_cache($wp_query->comments);
  813. if ( $separate_comments ) {
  814. $wp_query->comments_by_type = &separate_comments($comments);
  815. $comments_by_type = &$wp_query->comments_by_type;
  816. }
  817. $overridden_cpage = false;
  818. if ( '' == get_query_var('cpage') && get_option('page_comments') ) {
  819. set_query_var( 'cpage', 'newest' == get_option('default_comments_page') ? get_comment_pages_count() : 1 );
  820. $overridden_cpage = true;
  821. }
  822. if ( !defined('COMMENTS_TEMPLATE') || !COMMENTS_TEMPLATE)
  823. define('COMMENTS_TEMPLATE', true);
  824. $include = apply_filters('comments_template', STYLESHEETPATH . $file );
  825. if ( file_exists( $include ) )
  826. require( $include );
  827. elseif ( file_exists( TEMPLATEPATH . $file ) )
  828. require( TEMPLATEPATH . $file );
  829. else // Backward compat code will be removed in a future release
  830. require( ABSPATH . WPINC . '/theme-compat/comments.php');
  831. }
  832. /**
  833. * Displays the JS popup script to show a comment.
  834. *
  835. * If the $file parameter is empty, then the home page is assumed. The defaults
  836. * for the window are 400px by 400px.
  837. *
  838. * For the comment link popup to work, this function has to be called or the
  839. * normal comment link will be assumed.
  840. *
  841. * @since 0.71
  842. * @global string $wpcommentspopupfile The URL to use for the popup window
  843. * @global int $wpcommentsjavascript Whether to use JavaScript. Set when function is called
  844. *
  845. * @param int $width Optional. The width of the popup window
  846. * @param int $height Optional. The height of the popup window
  847. * @param string $file Optional. Sets the location of the popup window
  848. */
  849. function comments_popup_script($width=400, $height=400, $file='') {
  850. global $wpcommentspopupfile, $wpcommentsjavascript;
  851. if (empty ($file)) {
  852. $wpcommentspopupfile = ''; // Use the index.
  853. } else {
  854. $wpcommentspopupfile = $file;
  855. }
  856. $wpcommentsjavascript = 1;
  857. $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";
  858. echo $javascript;
  859. }
  860. /**
  861. * Displays the link to the comments popup window for the current post ID.
  862. *
  863. * Is not meant to be displayed on single posts and pages. Should be used on the
  864. * lists of posts
  865. *
  866. * @since 0.71
  867. * @uses $wpcommentspopupfile
  868. * @uses $wpcommentsjavascript
  869. * @uses $post
  870. *
  871. * @param string $zero The string to display when no comments
  872. * @param string $one The string to display when only one comment is available
  873. * @param string $more The string to display when there are more than one comment
  874. * @param string $css_class The CSS class to use for comments
  875. * @param string $none The string to display when comments have been turned off
  876. * @return null Returns null on single posts and pages.
  877. */
  878. function comments_popup_link( $zero = false, $one = false, $more = false, $css_class = '', $none = false ) {
  879. global $wpcommentspopupfile, $wpcommentsjavascript;
  880. $id = get_the_ID();
  881. if ( false === $zero ) $zero = __( 'No Comments' );
  882. if ( false === $one ) $one = __( '1 Comment' );
  883. if ( false === $more ) $more = __( '% Comments' );
  884. if ( false === $none ) $none = __( 'Comments Off' );
  885. $number = get_comments_number( $id );
  886. if ( 0 == $number && !comments_open() && !pings_open() ) {
  887. echo '<span' . ((!empty($css_class)) ? ' class="' . esc_attr( $css_class ) . '"' : '') . '>' . $none . '</span>';
  888. return;
  889. }
  890. if ( post_password_required() ) {
  891. echo __('Enter your password to view comments.');
  892. return;
  893. }
  894. echo '<a href="';
  895. if ( $wpcommentsjavascript ) {
  896. if ( empty( $wpcommentspopupfile ) )
  897. $home = home_url();
  898. else
  899. $home = get_option('siteurl');
  900. echo $home . '/' . $wpcommentspopupfile . '?comments_popup=' . $id;
  901. echo '" onclick="wpopen(this.href); return false"';
  902. } else { // if comments_popup_script() is not in the template, display simple comment link
  903. if ( 0 == $number )
  904. echo get_permalink() . '#respond';
  905. else
  906. comments_link();
  907. echo '"';
  908. }
  909. if ( !empty( $css_class ) ) {
  910. echo ' class="'.$css_class.'" ';
  911. }
  912. $title = the_title_attribute( array('echo' => 0 ) );
  913. echo apply_filters( 'comments_popup_link_attributes', '' );
  914. echo ' title="' . esc_attr( sprintf( __('Comment on %s'), $title ) ) . '">';
  915. comments_number( $zero, $one, $more );
  916. echo '</a>';
  917. }
  918. /**
  919. * Retrieve HTML content for reply to comment link.
  920. *
  921. * The default arguments that can be override are 'add_below', 'respond_id',
  922. * 'reply_text', 'login_text', and 'depth'. The 'login_text' argument will be
  923. * used, if the user must log in or register first before posting a comment. The
  924. * 'reply_text' will be used, if they can post a reply. The 'add_below' and
  925. * 'respond_id' arguments are for the JavaScript moveAddCommentForm() function
  926. * parameters.
  927. *
  928. * @since 2.7.0
  929. *
  930. * @param array $args Optional. Override default options.
  931. * @param int $comment Optional. Comment being replied to.
  932. * @param int $post Optional. Post that the comment is going to be displayed on.
  933. * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
  934. */
  935. function get_comment_reply_link($args = array(), $comment = null, $post = null) {
  936. global $user_ID;
  937. $defaults = array('add_below' => 'comment', 'respond_id' => 'respond', 'reply_text' => __('Reply'),
  938. 'login_text' => __('Log in to Reply'), 'depth' => 0, 'before' => '', 'after' => '');
  939. $args = wp_parse_args($args, $defaults);
  940. if ( 0 == $args['depth'] || $args['max_depth'] <= $args['depth'] )
  941. return;
  942. extract($args, EXTR_SKIP);
  943. $comment = get_comment($comment);
  944. if ( empty($post) )
  945. $post = $comment->comment_post_ID;
  946. $post = get_post($post);
  947. if ( !comments_open($post->ID) )
  948. return false;
  949. $link = '';
  950. if ( get_option('comment_registration') && !$user_ID )
  951. $link = '<a rel="nofollow" class="comment-reply-login" href="' . esc_url( wp_login_url( get_permalink() ) ) . '">' . $login_text . '</a>';
  952. else
  953. $link = "<a class='comment-reply-link' href='" . esc_url( add_query_arg( 'replytocom', $comment->comment_ID ) ) . "#" . $respond_id . "' onclick='return addComment.moveForm(\"$add_below-$comment->comment_ID\", \"$comment->comment_ID\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
  954. return apply_filters('comment_reply_link', $before . $link . $after, $args, $comment, $post);
  955. }
  956. /**
  957. * Displays the HTML content for reply to comment link.
  958. *
  959. * @since 2.7.0
  960. * @see get_comment_reply_link() Echoes result
  961. *
  962. * @param array $args Optional. Override default options.
  963. * @param int $comment Optional. Comment being replied to.
  964. * @param int $post Optional. Post that the comment is going to be displayed on.
  965. * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
  966. */
  967. function comment_reply_link($args = array(), $comment = null, $post = null) {
  968. echo get_comment_reply_link($args, $comment, $post);
  969. }
  970. /**
  971. * Retrieve HTML content for reply to post link.
  972. *
  973. * The default arguments that can be override are 'add_below', 'respond_id',
  974. * 'reply_text', 'login_text', and 'depth'. The 'login_text' argument will be
  975. * used, if the user must log in or register first before posting a comment. The
  976. * 'reply_text' will be used, if they can post a reply. The 'add_below' and
  977. * 'respond_id' arguments are for the JavaScript moveAddCommentForm() function
  978. * parameters.
  979. *
  980. * @since 2.7.0
  981. *
  982. * @param array $args Optional. Override default options.
  983. * @param int|object $post Optional. Post that the comment is going to be displayed on. Defaults to current post.
  984. * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
  985. */
  986. function get_post_reply_link($args = array(), $post = null) {
  987. global $user_ID;
  988. $defaults = array('add_below' => 'post', 'respond_id' => 'respond', 'reply_text' => __('Leave a Comment'),
  989. 'login_text' => __('Log in to leave a Comment'), 'before' => '', 'after' => '');
  990. $args = wp_parse_args($args, $defaults);
  991. extract($args, EXTR_SKIP);
  992. $post = get_post($post);
  993. if ( !comments_open($post->ID) )
  994. return false;
  995. if ( get_option('comment_registration') && !$user_ID ) {
  996. $link = '<a rel="nofollow" href="' . wp_login_url( get_permalink() ) . '">' . $login_text . '</a>';
  997. } else {
  998. $link = "<a rel='nofollow' class='comment-reply-link' href='" . get_permalink($post->ID) . "#$respond_id' onclick='return addComment.moveForm(\"$add_below-$post->ID\", \"0\", \"$respond_id\", \"$post->ID\")'>$reply_text</a>";
  999. }
  1000. return apply_filters('post_comments_link', $before . $link . $after, $post);
  1001. }
  1002. /**
  1003. * Displays the HTML content for reply to post link.
  1004. * @since 2.7.0
  1005. * @see get_post_reply_link()
  1006. *
  1007. * @param array $args Optional. Override default options.
  1008. * @param int|object $post Optional. Post that the comment is going to be displayed on.
  1009. * @return string|bool|null Link to show comment form, if successful. False, if comments are closed.
  1010. */
  1011. function post_reply_link($args = array(), $post = null) {
  1012. echo get_post_reply_link($args, $post);
  1013. }
  1014. /**
  1015. * Retrieve HTML content for cancel comment reply link.
  1016. *
  1017. * @since 2.7.0
  1018. *
  1019. * @param string $text Optional. Text to display for cancel reply link.
  1020. */
  1021. function get_cancel_comment_reply_link($text = '') {
  1022. if ( empty($text) )
  1023. $text = __('Click here to cancel reply.');
  1024. $style = isset($_GET['replytocom']) ? '' : ' style="display:none;"';
  1025. $link = esc_html( remove_query_arg('replytocom') ) . '#respond';
  1026. return apply_filters('cancel_comment_reply_link', '<a rel="nofollow" id="cancel-comment-reply-link" href="' . $link . '"' . $style . '>' . $text . '</a>', $link, $text);
  1027. }
  1028. /**
  1029. * Display HTML content for cancel comment reply link.
  1030. *
  1031. * @since 2.7.0
  1032. *
  1033. * @param string $text Optional. Text to display for cancel reply link.
  1034. */
  1035. function cancel_comment_reply_link($text = '') {
  1036. echo get_cancel_comment_reply_link($text);
  1037. }
  1038. /**
  1039. * Retrieve hidden input HTML for replying to comments.
  1040. *
  1041. * @since 3.0.0
  1042. *
  1043. * @return string Hidden input HTML for replying to comments
  1044. */
  1045. function get_comment_id_fields( $id = 0 ) {
  1046. if ( empty( $id ) )
  1047. $id = get_the_ID();
  1048. $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
  1049. $result = "<input type='hidden' name='comment_post_ID' value='$id' id='comment_post_ID' />\n";
  1050. $result .= "<input type='hidden' name='comment_parent' id='comment_parent' value='$replytoid' />\n";
  1051. return apply_filters('comment_id_fields', $result, $id, $replytoid);
  1052. }
  1053. /**
  1054. * Output hidden input HTML for replying to comments.
  1055. *
  1056. * @since 2.7.0
  1057. * @see get_comment_id_fields() Echoes result
  1058. */
  1059. function comment_id_fields( $id = 0 ) {
  1060. echo get_comment_id_fields( $id );
  1061. }
  1062. /**
  1063. * Display text based on comment reply status. Only affects users with Javascript disabled.
  1064. *
  1065. * @since 2.7.0
  1066. *
  1067. * @param string $noreplytext Optional. Text to display when not replying to a comment.
  1068. * @param string $replytext Optional. Text to display when replying to a comment. Accepts "%s" for the author of the comment being replied to.
  1069. * @param string $linktoparent Optional. Boolean to control making the author's name a link to their comment.
  1070. */
  1071. function comment_form_title( $noreplytext = false, $replytext = false, $linktoparent = true ) {
  1072. global $comment;
  1073. if ( false === $noreplytext ) $noreplytext = __( 'Leave a Reply' );
  1074. if ( false === $replytext ) $replytext = __( 'Leave a Reply to %s' );
  1075. $replytoid = isset($_GET['replytocom']) ? (int) $_GET['replytocom'] : 0;
  1076. if ( 0 == $replytoid )
  1077. echo $noreplytext;
  1078. else {
  1079. $comment = get_comment($replytoid);
  1080. $author = ( $linktoparent ) ? '<a href="#comment-' . get_comment_ID() . '">' . get_comment_author() . '</a>' : get_comment_author();
  1081. printf( $replytext, $author );
  1082. }
  1083. }
  1084. /**
  1085. * HTML comment list class.
  1086. *
  1087. * @package WordPress
  1088. * @uses Walker
  1089. * @since 2.7.0
  1090. */
  1091. class Walker_Comment extends Walker {
  1092. /**
  1093. * @see Walker::$tree_type
  1094. * @since 2.7.0
  1095. * @var string
  1096. */
  1097. var $tree_type = 'comment';
  1098. /**
  1099. * @see Walker::$db_fields
  1100. * @since 2.7.0
  1101. * @var array
  1102. */
  1103. var $db_fields = array ('parent' => 'comment_parent', 'id' => 'comment_ID');
  1104. /**
  1105. * @see Walker::start_lvl()
  1106. * @since 2.7.0
  1107. *
  1108. * @param string $output Passed by reference. Used to append additional content.
  1109. * @param int $depth Depth of comment.
  1110. * @param array $args Uses 'style' argument for type of HTML list.
  1111. */
  1112. function start_lvl( &$output, $depth = 0, $args = array() ) {
  1113. $GLOBALS['comment_depth'] = $depth + 1;
  1114. switch ( $args['style'] ) {
  1115. case 'div':
  1116. break;
  1117. case 'ol':
  1118. echo "<ol class='children'>\n";
  1119. break;
  1120. default:
  1121. case 'ul':
  1122. echo "<ul class='children'>\n";
  1123. break;
  1124. }
  1125. }
  1126. /**
  1127. * @see Walker::end_lvl()
  1128. * @since 2.7.0
  1129. *
  1130. * @param string $output Passed by reference. Used to append additional content.
  1131. * @param int $depth Depth of comment.
  1132. * @param array $args Will only append content if style argument value is 'ol' or 'ul'.
  1133. */
  1134. function end_lvl( &$output, $depth = 0, $args = array() ) {
  1135. $GLOBALS['comment_depth'] = $depth + 1;
  1136. switch ( $args['style'] ) {
  1137. case 'div':
  1138. break;
  1139. case 'ol':
  1140. echo "</ol>\n";
  1141. break;
  1142. default:
  1143. case 'ul':
  1144. echo "</ul>\n";
  1145. break;
  1146. }
  1147. }
  1148. /**
  1149. * This function is designed to enhance Walker::display_element() to
  1150. * display children of higher nesting levels than selected inline on
  1151. * the highest depth level displayed. This prevents them being orphaned
  1152. * at the end of the comment list.
  1153. *
  1154. * Example: max_depth = 2, with 5 levels of nested content.
  1155. * 1
  1156. * 1.1
  1157. * 1.1.1
  1158. * 1.1.1.1
  1159. * 1.1.1.1.1
  1160. * 1.1.2
  1161. * 1.1.2.1
  1162. * 2
  1163. * 2.2
  1164. *
  1165. */
  1166. function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) {
  1167. if ( !$element )
  1168. return;
  1169. $id_field = $this->db_fields['id'];
  1170. $id = $element->$id_field;
  1171. parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
  1172. // If we're at the max depth, and the current element still has children, loop over those and display them at this level
  1173. // This is to prevent them being orphaned to the end of the list.
  1174. if ( $max_depth <= $depth + 1 && isset( $children_elements[$id]) ) {
  1175. foreach ( $children_elements[ $id ] as $child )
  1176. $this->display_element( $child, $children_elements, $max_depth, $depth, $args, $output );
  1177. unset( $children_elements[ $id ] );
  1178. }
  1179. }
  1180. /**
  1181. * @see Walker::start_el()
  1182. * @since 2.7.0
  1183. *
  1184. * @param string $output Passed by reference. Used to append additional content.
  1185. * @param object $comment Comment data object.
  1186. * @param int $depth Depth of comment in reference to parents.
  1187. * @param array $args
  1188. */
  1189. function start_el( &$output, $comment, $depth, $args, $id = 0 ) {
  1190. $depth++;
  1191. $GLOBALS['comment_depth'] = $depth;
  1192. if ( !empty($args['callback']) ) {
  1193. call_user_func($args['callback'], $comment, $args, $depth);
  1194. return;
  1195. }
  1196. $GLOBALS['comment'] = $comment;
  1197. extract($args, EXTR_SKIP);
  1198. if ( 'div' == $args['style'] ) {
  1199. $tag = 'div';
  1200. $add_below = 'comment';
  1201. } else {
  1202. $tag = 'li';
  1203. $add_below = 'div-comment';
  1204. }
  1205. ?>
  1206. <<?php echo $tag ?> <?php comment_class(empty( $args['has_children'] ) ? '' : 'parent') ?> id="comment-<?php comment_ID() ?>">
  1207. <?php if ( 'div' != $args['style'] ) : ?>
  1208. <div id="div-comment-<?php comment_ID() ?>" class="comment-body">
  1209. <?php endif; ?>
  1210. <div class="comment-author vcard">
  1211. <?php if ($args['avatar_size'] != 0) echo get_avatar( $comment, $args['avatar_size'] ); ?>
  1212. <?php printf(__('<cite class="fn">%s</cite> <span class="says">says:</span>'), get_comment_author_link()) ?>
  1213. </div>
  1214. <?php if ($comment->comment_approved == '0') : ?>
  1215. <em class="comment-awaiting-moderation"><?php _e('Your comment is awaiting moderation.') ?></em>
  1216. <br />
  1217. <?php endif; ?>
  1218. <div class="comment-meta commentmetadata"><a href="<?php echo htmlspecialchars( get_comment_link( $comment->comment_ID ) ) ?>">
  1219. <?php
  1220. /* translators: 1: date, 2: time */
  1221. printf( __('%1$s at %2$s'), get_comment_date(), get_comment_time()) ?></a><?php edit_comment_link(__('(Edit)'),'&nbsp;&nbsp;','' );
  1222. ?>
  1223. </div>
  1224. <?php comment_text() ?>
  1225. <div class="reply">
  1226. <?php comment_reply_link(array_merge( $args, array('add_below' => $add_below, 'depth' => $depth, 'max_depth' => $args['max_depth']))) ?>
  1227. </div>
  1228. <?php if ( 'div' != $args['style'] ) : ?>
  1229. </div>
  1230. <?php endif; ?>
  1231. <?php
  1232. }
  1233. /**
  1234. * @see Walker::end_el()
  1235. * @since 2.7.0
  1236. *
  1237. * @param string $output Passed by reference. Used to append additional content.
  1238. * @param object $comment
  1239. * @param int $depth Depth of comment.
  1240. * @param array $args
  1241. */
  1242. function end_el(&$output, $comment, $depth = 0, $args = array() ) {
  1243. if ( !empty($args['end-callback']) ) {
  1244. call_user_func($args['end-callback'], $comment, $args, $depth);
  1245. return;
  1246. }
  1247. if ( 'div' == $args['style'] )
  1248. echo "</div>\n";
  1249. else
  1250. echo "</li>\n";
  1251. }
  1252. }
  1253. /**
  1254. * List comments
  1255. *
  1256. * Used in the comments.php template to list comments for a particular post
  1257. *
  1258. * @since 2.7.0
  1259. * @uses Walker_Comment
  1260. *
  1261. * @param string|array $args Formatting options
  1262. * @param array $comments Optional array of comment objects. Defaults to $wp_query->comments
  1263. */
  1264. function wp_list_comments($args = array(), $comments = null ) {
  1265. global $wp_query, $comment_alt, $comment_depth, $comment_thread_alt, $overridden_cpage, $in_comment_loop;
  1266. $in_comment_loop = true;
  1267. $comment_alt = $comment_thread_alt = 0;
  1268. $comment_depth = 1;
  1269. $defaults = array('walker' => null, 'max_depth' => '', 'style' => 'ul', 'callback' => null, 'end-callback' => null, 'type' => 'all',
  1270. 'page' => '', 'per_page' => '', 'avatar_size' => 32, 'reverse_top_level' => null, 'reverse_children' => '');
  1271. $r = wp_parse_args( $args, $defaults );
  1272. // Figure out what comments we'll be looping through ($_comments)
  1273. if ( null !== $comments ) {
  1274. $comments = (array) $comments;
  1275. if ( empty($comments) )
  1276. return;
  1277. if ( 'all' != $r['type'] ) {
  1278. $comments_by_type = &separate_comments($comments);
  1279. if ( empty($comments_by_type[$r['type']]) )
  1280. return;
  1281. $_comments = $comments_by_type[$r['type']];
  1282. } else {
  1283. $_comments = $comments;
  1284. }
  1285. } else {
  1286. if ( empty($wp_query->comments) )
  1287. return;
  1288. if ( 'all' != $r['type'] ) {
  1289. if ( empty($wp_query->comments_by_type) )
  1290. $wp_query->comments_by_type = &separate_comments($wp_query->comments);
  1291. if ( empty($wp_query->comments_by_type[$r['type']]) )
  1292. return;
  1293. $_comments = $wp_query->comments_by_type[$r['type']];
  1294. } else {
  1295. $_comments = $wp_query->comments;
  1296. }
  1297. }
  1298. if ( '' === $r['per_page'] && get_option('page_comments') )
  1299. $r['per_page'] = get_query_var('comments_per_page');
  1300. if ( empty($r['per_page']) ) {
  1301. $r['per_page'] = 0;
  1302. $r['page'] = 0;
  1303. }
  1304. if ( '' === $r['max_depth'] ) {
  1305. if ( get_option('thread_comments') )
  1306. $r['max_depth'] = get_option('thread_comments_depth');
  1307. else
  1308. $r['max_depth'] = -1;
  1309. }
  1310. if ( '' === $r['page'] ) {
  1311. if ( empty($overridden_cpage) ) {
  1312. $r['page'] = get_query_var('cpage');
  1313. } else {
  1314. $threaded = ( -1 != $r['max_depth'] );
  1315. $r['page'] = ( 'newest' == get_option('default_comments_page') ) ? get_comment_pages_count($_comments, $r['per_page'], $threaded) : 1;
  1316. set_query_var( 'cpage', $r['page'] );
  1317. }
  1318. }
  1319. // Validation check
  1320. $r['page'] = intval($r['page']);
  1321. if ( 0 == $r['page'] && 0 != $r['per_page'] )
  1322. $r['page'] = 1;
  1323. if ( null === $r['reverse_top_level'] )
  1324. $r['reverse_top_level'] = ( 'desc' == get_option('comment_order') );
  1325. extract( $r, EXTR_SKIP );
  1326. if ( empty($walker) )
  1327. $walker = new Walker_Comment;
  1328. $walker->paged_walk($_comments, $max_depth, $page, $per_page, $r);
  1329. $wp_query->max_num_comment_pages = $walker->max_pages;
  1330. $in_comment_loop = false;
  1331. }
  1332. /**
  1333. * Outputs a complete commenting form for use within a template.
  1334. * Most strings and form fields may be controlled through the $args array passed
  1335. * into the function, while you may also choose to use the comment_form_default_fields
  1336. * filter to modify the array of default fields if you'd just like to add a new
  1337. * one or remove a single field. All fields are also individually passed through
  1338. * a filter of the form comment_form_field_$name where $name is the key used
  1339. * in the array of fields.
  1340. *
  1341. * @since 3.0.0
  1342. * @param array $args Options for strings, fields etc in the form
  1343. * @param mixed $post_id Post ID to generate the form for, uses the current post if null
  1344. * @return void
  1345. */
  1346. function comment_form( $args = array(), $post_id = null ) {
  1347. global $id;
  1348. if ( null === $post_id )
  1349. $post_id = $

Large files files are truncated, but you can click here to view the full file