privatemsg.theme.inc

  1. 1 privatemsg.theme.inc
  2. 7-1 privatemsg.theme.inc
  3. 7-2 privatemsg.theme.inc
  4. 6-2 privatemsg.theme.inc

Theme functions for privatemsg.

File

privatemsg.theme.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Theme functions for privatemsg.
  5. */
  6. /**
  7. * @defgroup theming Theming documentation
  8. *
  9. * It is possible to theme many aspect of privatemsg with theme functions.
  10. *
  11. * For the thread list, so called theme patterns are used to allow flexible
  12. * theming of the table and its columns (including columns added by other
  13. * modules).
  14. *
  15. * Columns are defined with hook_privatemsg_header_info(). The default weight
  16. * and if they are enabled or not can by set by default but can be overridden in
  17. * the admin user interface.
  18. *
  19. * Additionally, a theme function needs to be defined that defaults to the name
  20. * 'privatemsg_list_field__$key', where $key is the name of the header/column.
  21. *
  22. * Every theme function will receive the $thread array as single argument, which
  23. * is everything that has been returned by the query built in
  24. * privatemsg_sql_list(). The theme function should return either a string or a
  25. * theme_table() compatible array.
  26. *
  27. * To change what information is available in that array, it is possible to
  28. * either implement hook_privatemsg_sql_list_alter() or alter $form['#data'] of
  29. * privatemsg_list(). See privatemsg_filter_form_privatemsg_list_alter() for an
  30. * example.
  31. *
  32. * To override an already existing theme function, use the following structure:
  33. * themename_privatemsg_list_field_fieldname. It is possible to change the
  34. * header definition with hook_privatemsg_header_info_alter() but that is often
  35. * not necessary.
  36. *
  37. */
  38. /**
  39. * @addtogroup theming
  40. * @{
  41. */
  42. /**
  43. * Theme the participants field.
  44. */
  45. function theme_privatemsg_list_field__participants($variables) {
  46. $thread = $variables['thread'];
  47. $participants = _privatemsg_generate_user_array($thread['participants'], -4);
  48. $field = array();
  49. $field['data'] = _privatemsg_format_participants($participants, 3, TRUE);
  50. $field['class'][] = 'privatemsg-list-participants';
  51. return $field;
  52. }
  53. /**
  54. * Theme the subject of the thread.
  55. */
  56. function theme_privatemsg_list_field__subject($variables) {
  57. $thread = $variables['thread'];
  58. $field = array();
  59. $options = array();
  60. $is_new = '';
  61. if (!empty($thread['is_new'])) {
  62. $is_new = theme('mark', array('type' => MARK_NEW));
  63. $options['fragment'] = 'new';
  64. }
  65. $subject = $thread['subject'];
  66. if ($thread['has_tokens']) {
  67. $message = privatemsg_message_load($thread['thread_id']);
  68. $subject = privatemsg_token_replace($subject, array('privatemsg_message' => $message), array('sanitize' => TRUE, 'privatemsg-show-span' => FALSE));
  69. }
  70. $field['data'] = l($subject, 'messages/view/' . $thread['thread_id'], $options) . $is_new;
  71. $field['class'][] = 'privatemsg-list-subject';
  72. return $field;
  73. }
  74. /**
  75. * Theme the replies field.
  76. */
  77. function theme_privatemsg_list_field__count($variables) {
  78. $thread = $variables['thread'];
  79. $field = array();
  80. $field['data'] = $thread['count'];
  81. $options = array();
  82. if (!empty($thread['is_new']) && $thread['is_new'] < $thread['count']) {
  83. $options['fragment'] = 'new';
  84. $field['data'] .= '<br />' . l((format_plural($thread['is_new'], '(1 new)', '(@count new)')), 'messages/view/' . $thread['thread_id'], $options);
  85. }
  86. $field['class'][] = 'privatemsg-list-count';
  87. return $field;
  88. }
  89. /**
  90. * Theme the last updated column.
  91. */
  92. function theme_privatemsg_list_field__last_updated($variables) {
  93. $thread = $variables['thread'];
  94. $field['data'] = privatemsg_format_date($thread['last_updated']);
  95. $field['class'][] = 'privatemsg-list-date';
  96. return $field;
  97. }
  98. /**
  99. * Theme the thread started column.
  100. */
  101. function theme_privatemsg_list_field__thread_started($variables) {
  102. $thread = $variables['thread'];
  103. $field = array();
  104. $field['data'] = privatemsg_format_date($thread['thread_started']);
  105. $field['class'][] = 'privatemsg-list-date-started';
  106. return $field;
  107. }
  108. /**
  109. * Theme a block which displays the number of unread messages a user has.
  110. */
  111. function theme_privatemsg_new_block($count) {
  112. $count = $count['count'];
  113. if ($count == 0) {
  114. $text = t('Click here to go to your messages.');
  115. }
  116. else {
  117. $text = format_plural($count, 'You have an unread message! Click here to read it.',
  118. 'You have @count unread messages! Click here to read them.');
  119. }
  120. return l($text, 'messages', array('attributes' => array('id' => 'privatemsg-new-link')));
  121. }
  122. /**
  123. * Used to theme and display user recipients.
  124. *
  125. * Wrapper for theme_username() with a few additional options.
  126. */
  127. function theme_privatemsg_username($variables) {
  128. $recipient = $variables['recipient'];
  129. $options = $variables['options'];
  130. if (!isset($recipient->uid)) {
  131. $recipient->uid = $recipient->recipient;
  132. }
  133. if (!empty($options['plain'])) {
  134. $name = strip_tags(format_username($recipient));
  135. if (!empty($options['unique'])) {
  136. $name .= ' [user]';
  137. }
  138. return $name;
  139. }
  140. else {
  141. return theme('username', array('account' => $recipient));
  142. }
  143. }
  144. /**
  145. * Output the admin settings display fields and weight settings as a
  146. * drag and drop sortable table.
  147. */
  148. function theme_privatemsg_admin_settings_display_fields($variables) {
  149. $element = $variables['element'];
  150. $header = array(
  151. array('data' => t('Field'), 'class' => array('field')),
  152. array('data' => t('Enable'), 'class' => array('enable')),
  153. array('data' => t('Weight'), 'class' => array('weight')),
  154. );
  155. $rows = array();
  156. foreach (element_children($element['privatemsg_display_fields']) as $child) {
  157. $row = array();
  158. // Title.
  159. $row[] = array('data' => $element['privatemsg_display_fields'][$child]['#title'], 'class' => array('field'));
  160. unset($element['privatemsg_display_fields'][$child]['#title']);
  161. // Enable checkbox.
  162. $row[] = array('data' => drupal_render($element['privatemsg_display_fields'][$child]), 'class' => array('enable'));
  163. // Weight selector.
  164. unset($element['privatemsg_display_fields_weights'][$child]['#title']);
  165. $element['privatemsg_display_fields_weights'][$child]['#attributes']['class'] = array('privatemsg-display-fields-weight');
  166. $row[] = array(
  167. 'data' => drupal_render($element['privatemsg_display_fields_weights'][$child]),
  168. 'class' => array('weight'),
  169. );
  170. $rows[] = array('data' => $row, 'class' => array('draggable'));
  171. }
  172. if (!empty($rows)) {
  173. drupal_add_tabledrag('privatemsg-list-display-fields', 'order', 'sibling', 'privatemsg-display-fields-weight');
  174. return theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'privatemsg-list-display-fields'))) . drupal_render_children($element);
  175. }
  176. else {
  177. return drupal_render_children($element);
  178. }
  179. }
  180. /**
  181. * @}
  182. */

Functions

Namesort descending Description
theme_privatemsg_admin_settings_display_fields Output the admin settings display fields and weight settings as a drag and drop sortable table.
theme_privatemsg_list_field__count Theme the replies field.
theme_privatemsg_list_field__last_updated Theme the last updated column.
theme_privatemsg_list_field__participants Theme the participants field.
theme_privatemsg_list_field__subject Theme the subject of the thread.
theme_privatemsg_list_field__thread_started Theme the thread started column.
theme_privatemsg_new_block Theme a block which displays the number of unread messages a user has.
theme_privatemsg_username Used to theme and display user recipients.