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