Guest User

comments.php

a guest
Nov 30th, 2011
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.60 KB | None | 0 0
  1. <?php
  2. /* ----------------------- */
  3. /* -- comments template -- */
  4. /* ----------------------- */
  5.  
  6.  
  7. /* set up data */
  8. // get numbers of pings and comments
  9. $ping_count = $comment_count = 0;
  10. foreach ( $comments as $comment )
  11. get_comment_type() == "comment" ? ++$comment_count : ++$ping_count;
  12.  
  13. // pull in correct author data
  14. global $authordata;
  15.  
  16. // post id
  17. $post_id = get_the_ID();
  18.  
  19. // post permalink
  20. $the_permalink = apply_filters( 'the_permalink', get_permalink() );
  21.  
  22. // active class, added to comments header when there are comments, and comments shown
  23. $active_class = p3_comments_header_active_class( $comment_count + $ping_count );
  24.  
  25. // extra div markup for boxy layout
  26. $boxy_open_extra_divs = ( p3_test( 'comments_layout', 'boxy' ) ) ? "<div class=\"comments-header-inner\">\n\t\t<div class=\"comments-header-inner-inner\">\n" : '';
  27. $boxy_close_extra_divs = ( p3_test( 'comments_layout', 'boxy' ) ) ? "</div>\n\t\t</div>\n" : '';
  28.  
  29. // cursor pointer when comments present
  30. $cursor_style = ( ( $comment_count + $ping_count ) > 0 ) ? ' style="cursor:pointer;"' : '';
  31.  
  32. // author link markup
  33. $author_link = p3_get_option( 'translate_by' ) . ' <a class="url fn n" href="' . get_author_posts_url( $authordata->ID, $authordata->user_nicename ) . '" title="View all posts by ' . $authordata->display_name . '">' . get_the_author() . '</a>';
  34. $post_author = ( p3_test( 'comments_show_postauthor', 'true' ) ) ? "<p class='postedby'>$author_link</p>" : '';
  35.  
  36.  
  37. // special class used by minima layout
  38. $minima_addclass = ( p3_test( 'comments_layout', 'minima' ) AND ( $comment_count + $ping_count ) == 0 ) ? ' class="no-comments"' : '';
  39.  
  40. // show/hide comments button
  41. $minima_show_hide_button = ( p3_test( 'comments_layout', 'minima' ) AND p3_test( 'comments_show_hide_method', 'button' ) )
  42. ? "<div id='show-hide-button'></div>"
  43. : '';
  44.  
  45. // formatted and filtered comment count
  46. $comments_count = p3_get_comments_count();
  47.  
  48. // "add a comment" post-interact link markup
  49. $add_a_comment = ( is_single() OR is_page() )
  50. ? ''
  51. : '<div class="addacomment post-interact-div"><div class="button-outer"><div class="button-inner"><a class="pi-link" href="' . $the_permalink . '#addcomment">' . p3_get_option( 'comments_addacomment_text' ) . '</a></div></div></div>';
  52.  
  53. // "link to this post" post-interact link markup
  54. $link_to_this_post = ( ( !p3_test( 'comments_post_interact_display', 'custom' ) AND p3_test( 'comments_linktothispost', 'yes' ) ) OR ( p3_test( 'comments_post_interact_display', 'custom' ) AND p3_image_exists( 'comments_linktothispost_image' ) ) )
  55. ? '<div class="linktothispost post-interact-div"><div class="button-outer"><div class="button-inner"><a class="pi-link" href="' . $the_permalink . '" title="Permalink to ' . get_the_title() . '">' . p3_get_option( 'comments_linktothispost_text' ) . '</a></div></div></div>'
  56. : '';
  57.  
  58. // "email a friend" post-interact link markup
  59. $email_a_friend = ( ( !p3_test( 'comments_post_interact_display', 'custom' ) AND p3_test( 'comments_emailafriend', 'yes' ) ) OR ( p3_test( 'comments_post_interact_display', 'custom' ) AND p3_image_exists( 'comments_emailafriend_image' ) ) )
  60. ? '<div class="emailafriend post-interact-div"><div class="button-outer"><div class="button-inner"><a class="pi-link" href="mailto:?subject=' .
  61. p3_encode_url_for_email( p3_get_option( 'comments_emailafriend_subject' ) ) .
  62. '&amp;body=' .
  63. p3_encode_url_for_email( p3_get_option( 'comments_emailafriend_body' ) ) .
  64. '%20' .
  65. p3_encode_url_for_email( $the_permalink ) .
  66. '">' .
  67. p3_get_option( 'comments_emailafriend_text' ) .
  68. '</a></div></div></div>'
  69. : '';
  70.  
  71. // inline css display style for comments body
  72. $comments_body_display = p3_comments_body_display();
  73.  
  74. // sort newest comment on top, if specified
  75. if ( p3_test( 'reverse_comments', 'true' ) ) $comments = array_reverse( $comments );
  76.  
  77. $open_class = ( comments_open() ) ? 'accepting-comments' : 'not-accepting-comments';
  78.  
  79. /* comments markup */
  80. echo <<<HTML
  81. <div id="entry-comments-{$post_id}" class="entry-comments {$open_class}{$active_class}">
  82. <div class="comments-header self-clear">
  83. $boxy_open_extra_divs
  84. <div class="comments-header-left-side-wrap self-clear">
  85. $post_author
  86. <div class="comments-count" id="comments-count-{$post_id}"{$cursor_style}>
  87. <div>
  88. <p{$minima_addclass}>
  89. $comments_count
  90. </p>
  91. $minima_show_hide_button
  92. </div>
  93. </div>
  94. </div>
  95. <div class="post-interact">
  96. $add_a_comment
  97. $link_to_this_post
  98. $email_a_friend
  99. </div>
  100. $boxy_close_extra_divs
  101. </div>
  102. <div id="comments-body-{$post_id}" class="comments-body"{$comments_body_display}>
  103. HTML;
  104.  
  105. // only print this inner stuff if we have at least one comment/ping
  106. if ( $comment_count OR $ping_count ) { ?>
  107. <div class="comments-body-inner-wrap">
  108. <div class="comments-body-inner">
  109. <?php
  110. // standard comments
  111. if ( $comment_count ) {
  112. foreach ( $comments as $comment ) {
  113. if ( get_comment_type() == "comment" ) p3_print_a_comment();
  114. }
  115. }
  116.  
  117. // pings
  118. if ( $ping_count ) {
  119. foreach ( $comments as $comment ) {
  120. if ( get_comment_type() != "comment" ) p3_print_a_comment();
  121. }
  122. }
  123. ?>
  124. </div> <!-- .comments-body-inner -->
  125. </div> <!-- .comments-body-inner-wrap -->
  126. <?php } ?>
  127. </div><!-- .comments-body -->
  128. </div><!-- .entry-comments -->
  129. <div id='addcomment-holder-<?php echo $post_id ?>' class='addcomment-holder'></div>
  130. <?php
  131.  
  132.  
  133.  
  134.  
  135. /* set up data for add a comment form */
  136. // WordPress url
  137. $p3_wpurl = P3_WPURL;
  138.  
  139. // shown to user who is logged in
  140. $logged_in_link = '<p id="login"><span class="loggedin">Logged in as <a href="' . $p3_url . '/wp-admin/profile.php">' . wp_specialchars( $user_identity, TRUE ) . '</a>.</span> <span class="logout"><a href="' . wp_logout_url( get_permalink() ) . '" title="Log out of this account">Log out?</a></span></p>';
  141.  
  142. // comment form top custom message
  143. $commentform_message = p3_translate( 'commentform_message', NO_ECHO );
  144.  
  145. // explanation of required comment fields, if needed ( $req is a WordPress global var )
  146. $req_explain = ( $req ) ? p3_translate( 'comments_required', NO_ECHO ) . ' <span class="required">*</span>' : '';
  147.  
  148. // visual indicator of required field, if needed
  149. $req_indicator = ( $req ) ? '<span class="required">*</span>' : '';
  150.  
  151. // comment form field labels
  152. $comments_name = p3_translate( 'comments_name', NO_ECHO );
  153. $comments_email = p3_translate( 'comments_email', NO_ECHO );
  154. $comments_website = p3_translate( 'comments_website', NO_ECHO );
  155. $comments_comment = p3_translate( 'comments_comment', NO_ECHO );
  156. $comments_button = p3_translate( 'comments_button', NO_ECHO );
  157.  
  158.  
  159. /* add a comment form markup */
  160. // if appropriate, display the add comment form
  161. if ( comments_open() && ( is_single() ) || ( is_page() ) ) {
  162. echo <<<HTML
  163.  
  164. <div class="formcontainer" id="addcomment">
  165.  
  166. <form id="commentform" action="{$p3_wpurl}/wp-comments-post.php" method="post">
  167.  
  168. HTML;
  169.  
  170. // user is logged in
  171. if ( $user_ID ) {
  172. echo $logged_in_link;
  173.  
  174. // not logged in
  175. } else {
  176. echo <<<HTML
  177.  
  178. <p id="comment-notes">$commentform_message $req_explain</p>
  179.  
  180. <div class="cmt-name"><p><label for="author">$comments_name</label> $req_indicator</p></div>
  181. <div class="cmt-name">
  182. <input id="author" name="author" type="text" value="$comment_author" size="40" maxlength="60" tabindex="3" />
  183. </div>
  184.  
  185. <div class="cmt-email"><p><label for="email">$comments_email</label> $req_indicator</p></div>
  186. <div class="cmt-email">
  187. <input id="email" name="email" type="text" value="$comment_author_email" size="40" maxlength="60" tabindex="4" />
  188. </div>
  189.  
  190. <div class="cmt-url"><p><label for="url">$comments_website</label></p></div>
  191. <div class="cmt-url">
  192. <input id="url" name="url" type="text" value="$comment_author_url" size="40" maxlength="60" tabindex="5" />
  193. </div>
  194.  
  195. HTML;
  196. }
  197.  
  198. // logged in and not logged in users both see this
  199. $comments_error_message = p3_get_option( 'translate_comments_error_message' );
  200. echo <<<HTML
  201. <div id="addcomment-error"><span>$comments_error_message</span></div>
  202. <div class="cmt-comment"><p><label for="comment">$comments_comment</label></p></div>
  203. <div class="cmt-comment">
  204. <textarea id="comment" name="comment" cols="65" rows="12" tabindex="6"></textarea>
  205. </div>
  206.  
  207. <div class="cmt-submit">
  208. <input id="submit" name="submit" type="submit" value="$comments_button" tabindex="7" accesskey="P" />
  209. <input type="hidden" name="comment_post_ID" value="$post_id" />
  210. </div>
  211. HTML;
  212. do_action( 'comment_form', $post->ID ); ?>
  213. </form><!-- #commentform -->
  214.  
  215. </div><!-- .formcontainer -->
  216. <?php
  217. }
  218. ?>
  219.  
Advertisement
Add Comment
Please, Sign In to add comment