template.theme-overrides.inc 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /**
  3. * Allow themable wrapping of all comments (from garland).
  4. */
  5. function clameurs_comment_wrapper($content, $node) {
  6. if (!$content || $node->type == 'forum') {
  7. return '<div id="comments">'. $content .'</div>';
  8. }
  9. else {
  10. return '<div id="comments"><h2 class="comments">'. t('Comments :') .'</h2>'. $content .'</div>';
  11. }
  12. }
  13. /**
  14. * Theme output of user signature.
  15. *
  16. * @ingroup themeable
  17. */
  18. function clameurs_user_signature($signature) {
  19. return '<div class="user-signature">'.$signature.'</div>';
  20. }
  21. /**
  22. * Returns a formatted list of recent comments to be displayed in the comment block.
  23. *
  24. * @return
  25. * The comment list HTML.
  26. * @ingroup themeable
  27. */
  28. function clameurs_comment_block() {
  29. $items = array();
  30. foreach (comment_get_recent() as $comment) {
  31. $items[] = l($comment->subject, 'node/'. $comment->nid, array('fragment' => 'comment-'. $comment->cid)) .'<br />'. t('@time ago', array('@time' => format_interval(time() - $comment->timestamp)));
  32. }
  33. if ($items) {
  34. return theme('item_list', $items);
  35. }
  36. }
  37. /**
  38. * Themes a single comment and related items.
  39. *
  40. * @param $comment
  41. * The comment object.
  42. * @param $node
  43. * The comment node.
  44. * @param $links
  45. * An associative array containing control links suitable for passing into
  46. * theme_links(). These are generated by modules implementing hook_link() with
  47. * $type='comment'. Typical examples are links for editing and deleting
  48. * comments.
  49. * @param $visible
  50. * Switches between folded/unfolded view. If TRUE the comments are visible, if
  51. * FALSE the comments are folded.
  52. * @ingroup themeable
  53. */
  54. function clameurs_comment_view($comment, $node, $links = array(), $visible = TRUE) {
  55. static $first_new = TRUE;
  56. $output = '';
  57. $comment->new = node_mark($comment->nid, $comment->timestamp);
  58. if ($first_new && $comment->new != MARK_READ) {
  59. // Assign the anchor only for the first new comment. This avoids duplicate
  60. // id attributes on a page.
  61. $first_new = FALSE;
  62. $output .= "<a id=\"new\"></a>\n";
  63. }
  64. $output .= "<a id=\"comment-$comment->cid\"></a>\n";
  65. // Switch to folded/unfolded view of the comment
  66. if ($visible) {
  67. $comment->comment = check_markup($comment->comment, $comment->format, FALSE);
  68. // Comment API hook
  69. comment_invoke_comment($comment, 'view');
  70. $output .= theme('comment', $comment, $node, $links);
  71. }
  72. else {
  73. $output .= theme('comment_folded', $comment);
  74. }
  75. return $output;
  76. }
  77. /**
  78. * Theme comment controls box where the user can change the default display mode and display order of comments.
  79. *
  80. * @param $form
  81. * The form structure.
  82. * @ingroup themeable
  83. */
  84. function clameurs_comment_controls($form) {
  85. $output = '<div class="container-inline">';
  86. $output .= drupal_render($form);
  87. $output .= '</div>';
  88. $output .= '<div class="description">'. t('Select your preferred way to display the comments and click "Save settings" to activate your changes.') .'</div>';
  89. return theme('box', t('Comment viewing options'), $output);
  90. }
  91. /**
  92. * Theme comment flat collapsed view.
  93. *
  94. * @param $comment
  95. * The comment to be themed.
  96. * @param $node
  97. * The comment node.
  98. * @ingroup themeable
  99. */
  100. function clameurs_comment_flat_collapsed($comment, $node) {
  101. return theme('comment_view', $comment, $node, '', 0);
  102. }
  103. /**
  104. * Theme comment flat expanded view.
  105. *
  106. * @param $comment
  107. * The comment to be themed.
  108. * @param $node
  109. * The comment node.
  110. * @ingroup themeable
  111. */
  112. function clameurs_comment_flat_expanded($comment, $node) {
  113. $links = module_invoke_all('link', 'comment', $comment, 0);
  114. drupal_alter('link', $links, $node, $comment);
  115. return theme('comment_view', $comment, $node, $links);
  116. }
  117. /**
  118. * Theme comment thread collapsed view.
  119. *
  120. * @param $comment
  121. * The comment to be themed.
  122. * @param $node
  123. * The comment node.
  124. * @ingroup themeable
  125. */
  126. function clameurs_comment_thread_collapsed($comment, $node) {
  127. return theme('comment_view', $comment, $node, '', 0);
  128. }
  129. /**
  130. * Theme comment thread expanded view.
  131. *
  132. * @param $comment
  133. * The comment to be themed.
  134. * @param $node
  135. * The comment node.
  136. * @ingroup themeable
  137. */
  138. function clameurs_comment_thread_expanded($comment, $node) {
  139. $links = module_invoke_all('link', 'comment', $comment, 0);
  140. drupal_alter('link', $links, $node, $comment);
  141. return theme('comment_view', $comment, $node, $links);
  142. }
  143. /**
  144. * Theme a "you can't post comments" notice.
  145. *
  146. * @param $node
  147. * The comment node.
  148. * @ingroup themeable
  149. */
  150. function clameurs_comment_post_forbidden($node) {
  151. global $user;
  152. static $authenticated_post_comments;
  153. if (!$user->uid) {
  154. if (!isset($authenticated_post_comments)) {
  155. // We only output any link if we are certain, that users get permission
  156. // to post comments by logging in. We also locally cache this information.
  157. $authenticated_post_comments = array_key_exists(DRUPAL_AUTHENTICATED_RID, user_roles(TRUE, 'post comments') + user_roles(TRUE, 'post comments without approval'));
  158. }
  159. if ($authenticated_post_comments) {
  160. // We cannot use drupal_get_destination() because these links
  161. // sometimes appear on /node and taxonomy listing pages.
  162. if (variable_get('comment_form_location_'. $node->type, COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) {
  163. $destination = 'destination='. rawurlencode("comment/reply/$node->nid#comment-form");
  164. }
  165. else {
  166. $destination = 'destination='. rawurlencode("node/$node->nid#comment-form");
  167. }
  168. if (variable_get('user_register', 1)) {
  169. // Users can register themselves.
  170. return t('<a href="@login">Login</a> or <a href="@register">register</a> to post comments', array('@login' => url('user/login', array('query' => $destination)), '@register' => url('user/register', array('query' => $destination))));
  171. }
  172. else {
  173. // Only admins can add new users, no public registration.
  174. return t('<a href="@login">Login</a> to post comments', array('@login' => url('user/login', array('query' => $destination))));
  175. }
  176. }
  177. }
  178. }
  179. /**
  180. * Theme a "Submitted by ..." notice.
  181. *
  182. * @param $comment
  183. * The comment.
  184. * @ingroup themeable
  185. */
  186. function clameurs_comment_submitted($comment) {
  187. return t('Submitted by !username on @datetime.',
  188. array(
  189. '!username' => theme('username', $comment),
  190. '@datetime' => format_date($comment->timestamp)
  191. ));
  192. }