by Berdir: Fixed the remaining test failures because of renamed admin block selects
[project/privatemsg.git] / privatemsg.theme.inc
CommitLineData
7e6c77e9
OT
1<?php
2// $Id$
3
4/**
5 * @file
6 * Theme functions for privatemsg.
7 */
8
f1825cc1
OT
9/**
10 * @defgroup theming Theming documentation
11 *
12 * It is possible to theme every aspect of privatemsg with theme functions.
13 *
14 * For the thread list, so called theme patterns are used to allow flexible
15 * theming of the table and its columns (including columns added by other
16 * modules).
17 *
18 * Three requirements have to be fulfilled so a new column, with data, is
19 * displayed in the private message list:
20 * - A field needs to be returned by the list query, see @link sql Query Builder @endlink.
21 * - A header theme pattern needs to exist for the field.
22 * - A field theme pattern needs to exist for the field.
23 *
24 * For each field in the query, Privatemsg will try to call a theme pattern for
25 * the header. That theme function can return a table header definition and
7ca7bfe6 26 * has the following structure: theme_privatemsg_list_header_fieldname.
f1825cc1
OT
27 * @see theme_privatemsg_list_header()
28 *
29 * Privatemsg will then do the same for each row, with the field theme pattern.
30 * That theme function should return a table field compatible structure, either
31 * just a string or an array. The theme function has to have the following
7ca7bfe6 32 * name: theme_privatemsg_list_field_fieldname.
f1825cc1
OT
33 * @see theme_privatemsg_list_field()
34 *
35 * To override an already existing theme function, use the following structure:
36 * themename_privatemsg_list_field_fieldname. It is not necessary to
37 * overwrite the header theme function unless that information needs to be
38 * changed too.
39 *
40 * Modules can use the hook_form_alter() hook to alter the data. The form with
41 * id "privatemsg_list" will contain the header, raw and themed field data in
42 * the following form:
43 * @code
44 * $form['#headers']['field_name'] = $header // Array with the header defintion;
45 * $form['#data']['thread_id'] = $data // Raw data of that thread
46 * $form['#rows']['thread_id'] = $row // Themed fields of that thread
47 * @endcode
48 *
49 * Note that the information in #data can be used to populate #rows, but it will
50 * not be used by the default theme function theme_privatemsg_list().
51 *
52 */
53
54/**
55 * @addtogroup theming
56 * @{
57 */
58
59/**
60 * Default theme function for field theme.
61 *
62 * To hide all fields that don't have an explicit theme pattern defined, this
63 * theme doesn't return anything.
64 *
65 * @param $thread
66 * Thread row returned by the list query.
67 *
68 * @return
69 * A theme_table() compatible field definition.
70 */
7e6c77e9
OT
71function theme_privatemsg_list_field($thread) {
72}
73
f1825cc1
OT
74/**
75 * Theme the participants field.
76 *
77 * @see theme_privatemsg_list_field()
78 */
7ca7bfe6
SG
79function theme_privatemsg_list_field__participants($variables) {
80 $thread = $variables['thread'];
68847a38 81 $participants = _privatemsg_generate_user_array($thread['participants'], -4);
7e6c77e9 82 $field = array();
c277e471 83 $field['data'] = _privatemsg_format_participants($participants, 3, TRUE);
befd5d6e 84 $field['class'][] = 'privatemsg-list-participants';
7e6c77e9
OT
85 return $field;
86}
87
f1825cc1
OT
88/**
89 * Theme the subject of the thread.
90 *
91 * @see theme_privatemsg_list_field()
92 */
7ca7bfe6
SG
93function theme_privatemsg_list_field__subject($variables) {
94 $thread = $variables['thread'];
7e6c77e9 95 $field = array();
6aad28b8
OT
96 $options = array();
97 $is_new = '';
98 if (!empty($thread['is_new'])) {
7ca7bfe6 99 $is_new = theme('mark', array('type' => MARK_NEW));
6aad28b8
OT
100 $options['fragment'] = 'new';
101 }
102 $field['data'] = l($thread['subject'], 'messages/view/' . $thread['thread_id'], $options) . $is_new;
befd5d6e 103 $field['class'][] = 'privatemsg-list-subject';
7e6c77e9
OT
104 return $field;
105}
106
f1825cc1
OT
107/**
108 * Theme the replies field.
109 *
110 * @see theme_privatemsg_list_field()
111 */
7ca7bfe6
SG
112function theme_privatemsg_list_field__count($variables) {
113 $thread = $variables['thread'];
7e6c77e9 114 $field = array();
6aad28b8
OT
115 $field['data'] = $thread['count'];
116 $options = array();
117 if (!empty($thread['is_new']) && $thread['is_new'] < $thread['count']) {
118 $options['fragment'] = 'new';
119 $field['data'] .= '<br />' . l((format_plural($thread['is_new'], '(1 new)', '(@count new)')),'messages/view/' . $thread['thread_id'], $options);
120 }
befd5d6e 121 $field['class'][] = 'privatemsg-list-count';
7e6c77e9
OT
122 return $field;
123}
124
f1825cc1
OT
125/**
126 * Theme the last updated column.
127 *
128 * @see theme_privatemsg_list_field()
129 */
7ca7bfe6
SG
130function theme_privatemsg_list_field__last_updated($variables) {
131 $thread = $variables['thread'];
7e6c77e9 132 $field['data'] = format_date($thread['last_updated'], 'small');
befd5d6e 133 $field['class'][] = 'privatemsg-list-date';
7e6c77e9
OT
134 return $field;
135}
136
f1825cc1
OT
137/**
138 * Theme the thread started column.
139 *
140 * @see theme_privatemsg_list_field()
141 */
7ca7bfe6
SG
142function theme_privatemsg_list_field__thread_started($variables) {
143 $thread = $variables['thread'];
7e6c77e9
OT
144 $field = array();
145 $field['data'] = format_date($thread['thread_started'], 'small');
befd5d6e 146 $field['class'][] = 'privatemsg-list-date-started';
7e6c77e9
OT
147 return $field;
148}
149
f1825cc1
OT
150/**
151 * Define the table header for a specific column.
152 *
153 * This default theme function is used to ignore columns that should not be
154 * displayed. Only columns with a specific theme pattern function are displayed.
155 *
156 * @return
157 * A theme_table() compatible table header definition. Additionally, the key
158 * "key" should be used to specify which row column should be displayed in
159 * this column.
160 */
7e6c77e9 161function theme_privatemsg_list_header() {
7e6c77e9
OT
162}
163
f1825cc1
OT
164/**
165 * Define the subject header.
166 *
167 * @see theme_privatemsg_list_header()
168 */
7ca7bfe6 169function theme_privatemsg_list_header__subject() {
7e6c77e9
OT
170 return array(
171 'data' => t('Subject'),
172 'field' => 'subject',
befd5d6e 173 'class' => array('privatemsg-header-subject'),
7e6c77e9
OT
174 '#weight' => -40,
175 );
176}
177
f1825cc1
OT
178/**
179 * Define the answers column.
180 *
181 * @see theme_privatemsg_list_header()
182 */
7ca7bfe6 183function theme_privatemsg_list_header__count() {
7e6c77e9 184 return array(
6aad28b8 185 'data' => t('Messages'),
befd5d6e 186 'class' => array('privatemsg-header-count'),
7e6c77e9
OT
187 '#weight' => -25,
188 );
189}
190
f1825cc1
OT
191/**
192 * Define the participants column.
193 *
194 * @see theme_privatemsg_list_header()
195 */
7ca7bfe6 196function theme_privatemsg_list_header__participants() {
7e6c77e9 197 return array(
c277e471 198 'data' => t('Participants'),
befd5d6e 199 'class' => array('privatemsg-header-participants'),
22107330 200 '#weight' => -30,
7e6c77e9
OT
201 );
202}
203
f1825cc1
OT
204/**
205 * Define the last updated column.
206 *
207 * @see theme_privatemsg_list_header()
208 */
7ca7bfe6 209function theme_privatemsg_list_header__last_updated() {
7e6c77e9
OT
210 return array(
211 'data' => t('Last Updated'),
212 'field' => 'last_updated',
6391fb81 213 'sort' => 'desc',
befd5d6e 214 'class' => array('privatemsg-header-lastupdated'),
7e6c77e9
OT
215 '#weight' => -20,
216 );
217}
218
f1825cc1
OT
219/**
220 * Define the thread started column.
221 *
222 * @see theme_privatemsg_list_header()
223 */
7ca7bfe6 224function theme_privatemsg_list_header__thread_started() {
7e6c77e9
OT
225 return array(
226 'data' => t('Started'),
227 'field' => 'thread_started',
befd5d6e 228 'class' => array('privatemsg-header-threadstarted'),
7e6c77e9
OT
229 '#weight' => -15,
230 );
231}
232
233/**
f1825cc1
OT
234 * Theme a block which displays the number of new messages a user has.
235 */
7e6c77e9 236function theme_privatemsg_new_block($count) {
716dd98e 237 $count = $count['count'];
73fb3fd6
SG
238 if ($count == 0) {
239 $text = t('Click here to go to your messages.');
240 }
241 else {
bd39fcee
SG
242 $text = format_plural($count, 'You have a new message! Click here to read it.',
243 'You have @count new messages! Click here to read them.');
73fb3fd6 244 }
7e6c77e9
OT
245
246 return l($text, 'messages', array('attributes' => array('id' => 'privatemsg-new-link')));
f1825cc1
OT
247}
248
249/**
250 * @}
251 */