Projet

Général

Profil

Paste
Télécharger (7,82 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / privatemsg / privatemsg.theme.inc @ a5572547

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 every 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
 * Three requirements have to be fulfilled so a new column, with data, is
18
 * displayed in the private message list:
19
 *  - A field needs to be returned by the list query, see @link sql Query Builder @endlink.
20
 *  - A header theme pattern needs to exist for the field.
21
 *  - A field theme pattern needs to exist for the field.
22
 *
23
 * For each field in the query, Privatemsg will try to call a theme pattern for
24
 * the header. That theme function can return a table header definition and
25
 * has the following structure: theme_privatemsg_list_header_fieldname.
26
 * @see theme_privatemsg_list_header()
27
 *
28
 * Privatemsg will then do the same for each row, with the field theme pattern.
29
 * That theme function should return a table field compatible structure, either
30
 * just a string or an array. The theme function has to have the following
31
 * name: theme_privatemsg_list_field_fieldname.
32
 * @see theme_privatemsg_list_field()
33
 *
34
 * To override an already existing theme function, use the following structure:
35
 * themename_privatemsg_list_field_fieldname. It is not necessary to
36
 * overwrite the header theme function unless that information needs to be
37
 * changed too.
38
 *
39
 * Modules can use the hook_form_alter() hook to alter the data. The form with
40
 * id "privatemsg_list" will contain the header, raw and themed field data in
41
 * the following form:
42
 * @code
43
 * $form['#headers']['field_name'] = $header // Array with the header definition;
44
 * $form['#data']['thread_id'] = $data // Raw data of that thread
45
 * $form['#rows']['thread_id'] = $row // Themed fields of that thread
46
 * @endcode
47
 *
48
 * Note that the information in #data can be used to populate #rows, but it will
49
 * not be used by the default theme function theme_privatemsg_list().
50
 *
51
 */
52

    
53
/**
54
 * @addtogroup theming
55
 * @{
56
 */
57

    
58
/**
59
 * Default theme function for field theme.
60
 *
61
 * To hide all fields that don't have an explicit theme pattern defined, this
62
 * theme doesn't return anything.
63
 *
64
 * @param $thread
65
 *   Thread row returned by the list query.
66
 *
67
 * @return
68
 *   A theme_table() compatible field definition.
69
 */
70
function theme_privatemsg_list_field($thread) {
71
}
72

    
73
/**
74
 * Theme the participants field.
75
 *
76
 * @see theme_privatemsg_list_field()
77
 */
78
function theme_privatemsg_list_field__participants($variables) {
79
  $thread = $variables['thread'];
80
  $participants = _privatemsg_generate_user_array($thread['participants'], -4);
81
  $field = array();
82
  $field['data'] = _privatemsg_format_participants($participants, 3, TRUE);
83
  $field['class'][] = 'privatemsg-list-participants';
84
  return $field;
85
}
86

    
87
/**
88
 * Theme the subject of the thread.
89
 *
90
 * @see theme_privatemsg_list_field()
91
 */
92
function theme_privatemsg_list_field__subject($variables) {
93
  $thread = $variables['thread'];
94
  $field = array();
95
  $options = array();
96
  $is_new = '';
97
  if (!empty($thread['is_new'])) {
98
    $is_new = theme('mark', array('type' => MARK_NEW));
99
    $options['fragment'] = 'new';
100
  }
101
  $subject = $thread['subject'];
102
  if ($thread['has_tokens']) {
103
    $message = privatemsg_message_load($thread['thread_id']);
104
    $subject = privatemsg_token_replace($subject, array('privatemsg_message' => $message), array('sanitize' => TRUE, 'privatemsg-show-span' => FALSE));
105
  }
106
  $field['data'] = l($subject, 'messages/view/' . $thread['thread_id'], $options) . $is_new;
107
  $field['class'][] = 'privatemsg-list-subject';
108
  return $field;
109
}
110

    
111
/**
112
 * Theme the replies field.
113
 *
114
 * @see theme_privatemsg_list_field()
115
 */
116
function theme_privatemsg_list_field__count($variables) {
117
  $thread = $variables['thread'];
118
  $field = array();
119
  $field['data'] = $thread['count'];
120
  $options = array();
121
  if (!empty($thread['is_new']) && $thread['is_new'] < $thread['count']) {
122
    $options['fragment'] = 'new';
123
    $field['data'] .= '<br />' . l((format_plural($thread['is_new'], '(1 new)', '(@count new)')), 'messages/view/' . $thread['thread_id'], $options);
124
  }
125
  $field['class'][] = 'privatemsg-list-count';
126
  return $field;
127
}
128

    
129
/**
130
 * Theme the last updated column.
131
 *
132
 * @see theme_privatemsg_list_field()
133
 */
134
function theme_privatemsg_list_field__last_updated($variables) {
135
  $thread = $variables['thread'];
136
  $field['data'] = privatemsg_format_date($thread['last_updated']);
137
  $field['class'][] = 'privatemsg-list-date';
138
  return $field;
139
}
140

    
141
/**
142
 * Theme the thread started column.
143
 *
144
 * @see theme_privatemsg_list_field()
145
 */
146
function theme_privatemsg_list_field__thread_started($variables) {
147
  $thread = $variables['thread'];
148
  $field = array();
149
  $field['data'] = privatemsg_format_date($thread['thread_started']);
150
  $field['class'][] = 'privatemsg-list-date-started';
151
  return $field;
152
}
153

    
154
/**
155
 * Define the table header for a specific column.
156
 *
157
 * This default theme function is used to ignore columns that should not be
158
 * displayed. Only columns with a specific theme pattern function are displayed.
159
 *
160
 * @return
161
 *   A theme_table() compatible table header definition. Additionally, the key
162
 *   "key" should be used to specify which row column should be displayed in
163
 *   this column.
164
 */
165
function theme_privatemsg_list_header() {
166
}
167

    
168
/**
169
 * Define the subject header.
170
 *
171
 * @see theme_privatemsg_list_header()
172
 */
173
function theme_privatemsg_list_header__subject() {
174
  return array(
175
    'data'    => t('Subject'),
176
    'field'   => 'subject',
177
    'class'   => array('privatemsg-header-subject'),
178
    '#weight' => -40,
179
  );
180
}
181

    
182
/**
183
 * Define the answers column.
184
 *
185
 * @see theme_privatemsg_list_header()
186
 */
187
function theme_privatemsg_list_header__count() {
188
  return array(
189
    'data'    => t('Messages'),
190
    'class'   => array('privatemsg-header-count'),
191
    '#weight' => -25,
192
  );
193
}
194

    
195
/**
196
 * Define the participants column.
197
 *
198
 * @see theme_privatemsg_list_header()
199
 */
200
function theme_privatemsg_list_header__participants() {
201
  return array(
202
    'data'    => t('Participants'),
203
    'class'   => array('privatemsg-header-participants'),
204
    '#weight' => -30,
205
  );
206
}
207

    
208
/**
209
 * Define the last updated column.
210
 *
211
 * @see theme_privatemsg_list_header()
212
 */
213
function theme_privatemsg_list_header__last_updated() {
214
  return array(
215
    'data'    => t('Last Updated'),
216
    'field'   => 'last_updated',
217
    'sort'    => 'desc',
218
    'class'   => array('privatemsg-header-lastupdated'),
219
    '#weight' => -20,
220
  );
221
}
222

    
223
/**
224
 * Define the thread started column.
225
 *
226
 * @see theme_privatemsg_list_header()
227
 */
228
function theme_privatemsg_list_header__thread_started() {
229
  return array(
230
    'data'    => t('Started'),
231
    'field'   => 'thread_started',
232
    'class'   => array('privatemsg-header-threadstarted'),
233
    '#weight' => -15,
234
  );
235
}
236

    
237
/**
238
 * Theme a block which displays the number of new messages a user has.
239
 */
240
function theme_privatemsg_new_block($count) {
241
  $count = $count['count'];
242
  if ($count == 0) {
243
    $text = t('Click here to go to your messages.');
244
  }
245
  else {
246
    $text = format_plural($count, 'You have a new message! Click here to read it.',
247
                        'You have @count new messages! Click here to read them.');
248
  }
249

    
250
  return l($text, 'messages', array('attributes' => array('id' => 'privatemsg-new-link')));
251
}
252

    
253
/**
254
 * Used to theme and display user recipients.
255
 *
256
 * Wrapper for theme_username() with a few additional options.
257
 */
258
function theme_privatemsg_username($variables) {
259
  $recipient = $variables['recipient'];
260
  $options = $variables['options'];
261
  if (!isset($recipient->uid)) {
262
    $recipient->uid = $recipient->recipient;
263
  }
264
  if (!empty($options['plain'])) {
265
    $name = strip_tags(format_username($recipient));
266
    if (!empty($options['unique'])) {
267
      $name .= ' [user]';
268
    }
269
    return $name;
270
  }
271
  else {
272
    return theme('username', array('account' => $recipient));
273
  }
274
}
275

    
276
/**
277
 * @}
278
 */