/[drupal]/contributions/modules/submitted_by/submitted_by.module
ViewVC logotype

Contents of /contributions/modules/submitted_by/submitted_by.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.16 - (show annotations) (download) (as text)
Sat Oct 10 18:23:23 2009 UTC (6 weeks, 5 days ago) by nancyw
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-7--1
Changes since 1.15: +3 -3 lines
File MIME type: text/x-php
7.x support
1 <?php
2 // $Id: submitted_by.module,v 1.15 2009/10/05 23:34:09 nancyw Exp $
3
4 /**
5 * @file
6 * Take over the "Submitted by" theme function to allow different
7 * content types to have different strings.
8 */
9
10 /**
11 * An implementation of hook_theme_registry_alter()
12 *
13 * Swap in our own replacement for theme_node_submitted(), allowing the
14 * site admin to configure the string on a per-nodetype basis.
15 **/
16 function submitted_by_theme_registry_alter(&$theme_registry) {
17 if (!empty($theme_registry['form_element'])) {
18 $theme_registry['node_submitted']['function'] = 'submitted_by_node_submitted';
19 $theme_registry['comment_submitted']['function'] = 'submitted_by_comment_submitted';
20 }
21 }
22
23 /**
24 * Implementation of hook_form_alter().
25 *
26 * Add the pattern field to the node edit form for comments.
27 */
28 function submitted_by_form_alter(&$form, $form_state, $form_id) {
29 switch ($form_id) {
30 case 'node_type_form':
31 if (isset($form['comment'])) {
32 $form['comment']['comment']['#weight'] = -5;
33 $type = isset($form['#node_type']->type) ? $form['#node_type']->type : 'default';
34 $default = variable_get('submitted_by_comment_'. $type, NULL);
35 $form['comment']['appearance'] = array(
36 '#type' => 'fieldset',
37 '#collapsible' => TRUE,
38 '#collapsed' => empty($default),
39 '#title' => t('"Submitted by" Appearance'),
40 );
41 $form['comment']['appearance']['#weight'] = -1;
42
43 $form['comment']['appearance']['submitted_by']['submitted_by_comment'] = array(
44 '#type' => 'textfield',
45 '#maxlength' => 255,
46 '#title' => t("'Submitted by...' text"),
47 '#default_value' => $default,
48 '#description' => t("When a comment is displayed, text in this box will be used to override the normal attribution and date-posted text."),
49 );
50
51 if ($def_default = variable_get('submitted_by_comment_default', NULL)) {
52 $form['comment']['appearance']['submitted_by']['submitted_by_comment']['#description'] .= ' '. t('The system default value is "%deflt."', array('%deflt' => $def_default));
53 }
54
55 $form['comment']['appearance']['submitted_by']['help'] = array(
56 '#type' => 'fieldset',
57 '#collapsible' => TRUE,
58 '#collapsed' => TRUE,
59 '#title' => t('Replacement tokens'),
60 '#description' => t("The following tokens can be used in the Submitted By... text. They will be replaced with the appropriate values."),
61 );
62
63 $form['comment']['appearance']['submitted_by']['help']['tokens'] = array(
64 '#value' => theme('token_help', 'comment'),
65 );
66 }
67 break;
68
69 case 'node_configure':
70 // Admin > Content > Post settings.
71 // Would this be better in system_theme_settings? ['node_info'], system_theme_settings_submit.
72 $node_default = variable_get('submitted_by_default', NULL);
73 $form['appearance'] = array(
74 '#type' => 'fieldset',
75 '#collapsible' => TRUE,
76 '#collapsed' => empty($node_default),
77 '#title' => t('"Submitted by" Appearance'),
78 );
79 $form['appearance']['submitted_by']['#weight'] = -1;
80 // Note: node module will add "_type" to the variable name.
81 $form['appearance']['submitted_by']['submitted_by_default'] = array(
82 '#type' => 'textfield',
83 '#maxlength' => 255,
84 '#title' => t("Node 'Submitted by...' text"),
85 '#default_value' => $node_default,
86 '#description' => t("When a node is displayed, text in this box will be used to override the normal attribution and date-posted text."),
87 );
88 $form['appearance']['submitted_by']['help'] = array(
89 '#type' => 'fieldset',
90 '#collapsible' => TRUE,
91 '#collapsed' => TRUE,
92 '#title' => t('Replacement tokens'),
93 '#description' => t("The following tokens can be used in the Submitted By... text. They will be replaced with the appropriate values."),
94 );
95
96 $form['appearance']['submitted_by']['help']['tokens'] = array(
97 '#value' => theme('token_help', 'node'),
98 );
99
100 if (module_exists('comment')) {
101 $com_default = variable_get('submitted_by_comment_default', NULL);
102 $form['comment']['appearance'] = array(
103 '#type' => 'fieldset',
104 '#collapsible' => TRUE,
105 '#collapsed' => empty($com_default),
106 '#title' => t('Comment "Submitted by" Appearance'),
107 '#weight' => -1,
108 );
109 $form['comment']['appearance']['submitted_by']['submitted_by_comment_default'] = array(
110 '#type' => 'textfield',
111 '#maxlength' => 255,
112 '#title' => t("'Submitted by...' text"),
113 '#default_value' => $com_default,
114 '#description' => t("When a comment is displayed, text in this box will be used to override the normal attribution and date-posted text."),
115 );
116 $form['comment']['appearance']['submitted_by']['help'] = array(
117 '#type' => 'fieldset',
118 '#collapsible' => TRUE,
119 '#collapsed' => TRUE,
120 '#title' => t('Replacement tokens'),
121 '#description' => t("The following tokens can be used in the Submitted By... text. They will be replaced with the appropriate values."),
122 );
123
124 $form['comment']['appearance']['submitted_by']['help']['tokens'] = array(
125 '#value' => theme('token_help', 'comment'),
126 );
127
128 $form['buttons']['#weight'] = 99;
129 // drupal_set_message(show_array($form));
130 break;
131 }
132 }
133 }
134
135 /**
136 * Implementation of hook_form_FORM_ID_alter().
137 *
138 * Add the pattern field to the node edit form.
139 */
140 function submitted_by_form_node_type_form_alter(&$form, &$form_state) {
141 $type = isset($form['#node_type']->type) ? $form['#node_type']->type : '';
142 $current_value = variable_get('submitted_by_' . $type, NULL);
143 $form['appearance'] = array(
144 '#type' => 'fieldset',
145 '#collapsible' => TRUE,
146 '#collapsed' => !$current_value,
147 '#title' => t('"Submitted by" Appearance'),
148 );
149 $form['appearance']['submitted_by']['#weight'] = -1;
150
151 // Note: node module will add "_type" to the variable name.
152 $form['appearance']['submitted_by']['submitted_by'] = array(
153 '#type' => 'textfield',
154 '#maxlength' => 255,
155 '#title' => t("'Submitted by...' text"),
156 '#default_value' => variable_get('submitted_by_' . $type, NULL),
157 '#description' => t("When a node is displayed, text in this box will be used to override the normal attribution and date-posted text."),
158 );
159
160 if ($def_default = variable_get('submitted_by_default', NULL)) {
161 $form['appearance']['submitted_by']['submitted_by']['#description'] .= ' '. t('The system default value is "%deflt."', array('%deflt' => $def_default));
162 }
163
164 $form['appearance']['submitted_by']['help'] = array(
165 '#type' => 'fieldset',
166 '#collapsible' => TRUE,
167 '#collapsed' => TRUE,
168 '#title' => t('Replacement tokens'),
169 '#description' => t("The following tokens can be used in the Submitted By... text. They will be replaced with the appropriate values."),
170 );
171
172 $form['appearance']['submitted_by']['help']['tokens'] = array(
173 '#value' => theme('token_help', 'node'),
174 );
175 }
176
177 /**
178 * Format the "Submitted by username on date/time" for each comment.
179 * varying the results by node type.
180 */
181 function submitted_by_comment_submitted($comment) {
182 $type = db_result(db_query(db_rewrite_sql("SELECT n.type FROM {node} n WHERE n.nid=%d"), $comment->nid));
183 if (variable_get('submitted_by_comment_'. $type, NULL)) {
184 $submitted = variable_get('submitted_by_comment_'. $type, NULL);
185 }
186 else {
187 $submitted = variable_get('submitted_by_comment_default', NULL);
188 }
189 if ($submitted) {
190 return filter_xss_admin(token_replace($submitted, 'comment', $comment));
191 }
192 else {
193 return t('Submitted by !username on @datetime',
194 array(
195 '!username' => theme('username', $comment),
196 '@datetime' => format_date($comment->timestamp),
197 )
198 );
199 }
200 }
201
202 /**
203 * Format the "Submitted by username on date/time" for each node,
204 * varying the results by node type.
205 */
206 function submitted_by_node_submitted($node) {
207 if (variable_get('submitted_by_'. $node->type, NULL)) {
208 $submitted = variable_get('submitted_by_'. $node->type, NULL);
209 }
210 else {
211 $submitted = variable_get('submitted_by_default', NULL);
212 }
213 if ($submitted) {
214 return filter_xss_admin(token_replace($submitted, 'node', $node));
215 }
216 else {
217 return t('Submitted by !username on @datetime',
218 array(
219 '!username' => theme('username', $node),
220 '@datetime' => format_date($node->created),
221 )
222 );
223 }
224 }
225
226 /**
227 * Because the normal submission line offers a quick and easy link to the
228 * user's account page, we'll provide a token for that. Token should
229 * probably have this built in.
230 */
231 function submitted_by_token_values($type, $object = NULL, $options = array()) {
232 $tokens = array();
233 switch ($type) {
234 case 'node':
235 $node = $object;
236 $tokens['author-link'] = theme('username', $node);
237 $tokens['created-since'] = format_interval(time() - $node->created);
238
239 // Conditional last edit tokens. See http://drupal.org/node/377726
240 $editor_uid = db_result(db_query("SELECT uid FROM {node_revisions} WHERE vid=%d", $object->vid));
241 $editor = user_load(array('uid' => $editor_uid));
242 $tokens['last-editor'] = theme('username', $editor);
243
244 if ($object->changed > $object->created) {
245 $last_edit_date = $object->changed;
246 $last_edit_type = t('changed');
247 $tokens['created-updated'] = t('created !created, updated !updated',
248 array('!created' => format_date($object->created, 'small'), '!updated' => format_date($object->changed, 'small')));
249 }
250 else {
251 $last_edit_date = $object->created;
252 $last_edit_type = t('created');
253 $tokens['created-updated'] = t('created !created',
254 array('!created' => format_date($object->created, 'small')));
255 }
256
257 $tokens['last-edit-type'] = $last_edit_type;
258
259 $tokens += _submitted_by_token_date($last_edit_date, 'last-edit');
260 break;
261
262 case 'comment':
263 $tokens['comment-since'] = $object->timestamp ? format_interval(time() - $object->timestamp) : t('Never');
264 $tokens['author-link'] = theme('username', $object);
265 break;
266
267 }
268 return $tokens;
269 }
270
271 function submitted_by_token_list($type = 'all') {
272 $tokens = array();
273 if ($type == 'node') {
274 $tokens['node']['author-link'] = t('Link to author.');
275 $tokens['node']['created-since'] = t('Node created date - interval.');
276 // Conditional last edit tokens. See http://drupal.org/node/377726
277 $tokens['node']['last-editor'] = t('The last user to edit the node.');
278 $tokens['node']['last-edit-type'] = t('The last edit type (created, changed) for the node.');
279 $tokens['node']['last-edit-small'] = t('Node last edit - small');
280 $tokens['node']['last-edit-medium'] = t('Node last edit - medium');
281 $tokens['node']['last-edit-large'] = t('Node last edit - large');
282 $tokens['node']['last-edit-since'] = t('Node last edit - interval');
283 $tokens['node']['last-edit-yyyy'] = t('Node last edit year (four digit)');
284 $tokens['node']['last-edit-yy'] = t('Node last edit year (two digit)');
285 $tokens['node']['last-edit-month'] = t('Node last edit month (full word)');
286 $tokens['node']['last-edit-mon'] = t('Node last edit month (abbreviated)');
287 $tokens['node']['last-edit-mm'] = t('Node last edit month (two digit, zero padded)');
288 $tokens['node']['last-edit-m'] = t('Node last edit month (one or two digit)');
289 $tokens['node']['last-edit-ww'] = t('Node last edit week (two digit)');
290 // ISO-8601 numeric representation of the day of the week (added in PHP 5.1.0)
291 if (version_compare(PHP_VERSION, '5.1.0', '>')) {
292 $tokens['node']['last-edit-date'] = t('Node last edit date (day of week)');
293 }
294 $tokens['node']['last-edit-day'] = t('Node last edit day (full word)');
295 $tokens['node']['last-edit-ddd'] = t('Node last edit day (abbreviation)');
296 $tokens['node']['last-edit-dd'] = t('Node last edit day (two digit, zero-padded)');
297 $tokens['node']['last-edit-d'] = t('Node last edit day (one or two digit)');
298 $tokens['node']['last-edit-hh'] = t('Node last edit hour in 12-hour format(two digit, zero-padded)');
299 $tokens['node']['last-edit-ii'] = t('Node last edit minute (two digit, zero-padded)');
300 $tokens['node']['last-edit-ss'] = t('Node last edit second (two digit, zero-padded)');
301 $tokens['node']['created-updated'] = t('Node created and updated dates (system small date)');
302 }
303 else {
304 if ($type == 'comment') {
305 $tokens['comment']['comment-since'] = t('Comment create date - interval');
306 $tokens['comment']['author-link'] = t('Link to author.');
307 }
308 }
309 return $tokens;
310 }
311
312 function _submitted_by_token_date($date, $prefix = NULL) {
313 $date = (int)$date;
314 if ($prefix) {
315 $prefix .= '-';
316 }
317 $values = array(
318 $prefix .'small' => format_date($date, 'small'),
319 $prefix .'medium' => format_date($date, 'medium'),
320 $prefix .'large' => format_date($date, 'large'),
321 $prefix .'since' => $date ? format_interval(time() - $date) : t('Never'),
322 $prefix .'yyyy' => date('Y', $date),
323 $prefix .'yy' => date('y', $date),
324 $prefix .'month' => format_date($date, 'custom', 'F'),
325 $prefix .'mon' => format_date($date, 'custom', 'M'),
326 $prefix .'mm' => date('m', $date),
327 $prefix .'m' => date('n', $date),
328 $prefix .'ww' => date('W', $date),
329 $prefix .'date' => date('N', $date),
330 $prefix .'day' => format_date($date, 'custom', 'l'),
331 $prefix .'ddd' => format_date($date, 'custom', 'D'),
332 $prefix .'dd' => date('d', $date),
333 $prefix .'d' => date('j', $date),
334 $prefix .'hh' => date('h', $date),
335 $prefix .'ii' => date('i', $date),
336 $prefix .'ss' => date('s', $date),
337 );
338
339 return $values;
340 }

  ViewVC Help
Powered by ViewVC 1.1.2