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

Contents of /contributions/modules/author_taxonomy/author_taxonomy.module

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


Revision 1.3 - (show annotations) (download) (as text)
Fri Aug 1 18:30:29 2008 UTC (15 months, 3 weeks ago) by toddnienkerk
Branch: MAIN
CVS Tags: DRUPAL-6--1-0-RC, HEAD
Branch point for: DRUPAL-6--1
Changes since 1.2: +51 -16 lines
File MIME type: text/x-php
initial release candidate for drupal 6.x branch
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Identifies authors using terms from a vocabulary.
7 *
8 * This module supports displaying multiple authors per node with
9 * fully themable output.
10 */
11
12
13 /**
14 * Implementation of hook_menu().
15 */
16 function author_taxonomy_menu() {
17 $items = array();
18
19 $items['admin/settings/author_taxonomy'] = array(
20 'title' => 'Author taxonomy',
21 'page callback' => 'drupal_get_form',
22 'page arguments' => array('author_taxonomy_admin_settings'),
23 'access arguments' => array('administer site configuration'),
24 'description' => 'Change settings for Author taxonomy.',
25 );
26
27 return $items;
28 }
29
30
31 /**
32 * Provides the settings options for the module.
33 *
34 * @return array
35 * The settings form.
36 */
37 function author_taxonomy_admin_settings() {
38 $form = array();
39
40 // Get the list of vocabularies
41 $vocabs = taxonomy_get_vocabularies();
42 if (empty($vocabs)) {
43 drupal_set_message(t('You have not yet created any vocabularies. Please <a href="@taxonomy_url">create a vocabulary</a> and return to this page.', array('@taxonomy_url' => url('admin/content/taxonomy/add/vocabulary'))), 'error');
44 }
45 foreach ($vocabs as $vid => $obj) {
46 $vocabs[$vid] = $obj->name;
47 }
48
49 // Make list of available date formats
50 $date_formats = array(
51 'small' => 'Short',
52 'medium' => 'Medium',
53 'large' => 'Long',
54 'custom' => 'Custom (below)',
55 );
56
57 // Drop-down box to choose author vocabulary
58 $form['author_taxonomy_vocab'] = array(
59 '#type' => 'select',
60 '#title' => t('Author taxonomy'),
61 '#options' => $vocabs,
62 '#default_value' => variable_get('author_taxonomy_vocab', 1),
63 '#description' => t('The taxonomy to use for content authors.'),
64 );
65
66 $form['author_taxonomy_prepend_node'] = array(
67 '#type' => 'checkbox',
68 '#title' => t('Automatically add output to the beginning of the node'),
69 '#default_value' => variable_get('author_taxonomy_prepend_node', TRUE),
70 '#description' => t('Check this box if you want to automatically display the author and timestamp info above each node\'s body text. If you uncheck this box, you must manually add the following line to your theme\'s node.tpl.php file wherever you want this information to appear: <strong>!code</strong>.', array('!code' => '&lt;?php print author_taxonomy_output($node); ?&gt;')),
71 );
72
73 $form['author_taxonomy_link_authors'] = array(
74 '#type' => 'checkbox',
75 '#title' => t('Display authors\' names as links to their taxonomy pages'),
76 '#default_value' => variable_get('author_taxonomy_link_authors', TRUE),
77 '#description' => t('Checking this box will display each author\'s name as a link to his/her taxonomy page, effectively providing the user with a list of all nodes credited to that author.'),
78 );
79
80 $form['timestamp'] = array(
81 '#type' => 'fieldset',
82 '#title' => t('Timestamp display options'),
83 '#description' => t('Customize or disable the display of the timestamp (node creation time and date).'),
84 '#collapsible' => TRUE,
85 '#collapsed' => FALSE,
86 );
87
88 $form['timestamp']['author_taxonomy_timestamp_display'] = array(
89 '#type' => 'checkbox',
90 '#title' => t('Display timestamp'),
91 '#default_value' => variable_get('author_taxonomy_timestamp_display', TRUE),
92 '#description' => t('Checking this box will display the timestamp. If you turn it off, you can ignore the other timestamp-related settings below.'),
93 );
94
95 $form['timestamp']['author_taxonomy_timestamp_type'] = array(
96 '#type' => 'select',
97 '#title' => t('Date output type'),
98 '#options' => $date_formats,
99 '#default_value' => variable_get('author_taxonomy_timestamp_type', array('medium')),
100 '#description' => t('These options are defined on the !date_and_time settings page. If you choose "Custom," remember to enter the custom string below.', array('!date_and_time' => l(t('date and time'), 'admin/settings/date-time'))),
101 );
102
103 $form['timestamp']['author_taxonomy_timestamp_format'] = array(
104 '#type' => 'textfield',
105 '#title' => t('Custom date format'),
106 '#description' => t('Enter a custom date string using the PHP !date_link notation. Note: The "Custom" format must be selected above.', array('!date_link' => l('date() function', 'http://www.php.net/date'))),
107 '#default_value' => variable_get('author_taxonomy_timestamp_format', 'j F Y'),
108 '#maxlength' => 100,
109 '#size' => 20,
110 );
111
112 return system_settings_form($form);
113 }
114
115
116 /**
117 * Implementation of hook_nodeapi().
118 */
119 function author_taxonomy_nodeapi(&$node, $op, $teaser, $page) {
120 switch ($op) {
121 case 'view' :
122 $display = variable_get('author_taxonomy_prepend_node', TRUE);
123 if ($display && ($page || $teaser)) {
124 $node->content['body']['#value'] = author_taxonomy_output($node) ."\n". $node->content['body']['#value'];
125 }
126 break;
127 }
128 }
129
130
131 /**
132 * Creates array of authors' names and prepares output for the theme functions
133 */
134 function author_taxonomy_output($node) {
135 $author_tids = taxonomy_node_get_terms_by_vocabulary($node, variable_get('author_taxonomy_vocab', 1));
136 $author_names = array();
137 $author_links = variable_get('author_taxonomy_link_authors', TRUE);
138
139 if (!empty($author_tids)) {
140 foreach ($author_tids as $tid => $term) {
141 if ($author_links) {
142 $author_names[] = l($term->name, taxonomy_term_path($term), array('title' => t('See all stories by @author', array('@author' => $term->name))));
143 }
144 else {
145 $author_names[] = $term->name;
146 }
147 }
148 }
149
150 $show_timestamp = variable_get('author_taxonomy_timestamp_display', TRUE);
151
152 return theme('author_taxonomy_output', $node, $author_names, $show_timestamp);
153 }
154
155
156 /**
157 * Implementation of hook_theme().
158 */
159 function author_taxonomy_theme() {
160 return array(
161 'author_taxonomy_output' => array(
162 'arguments' => array(
163 'node' => NULL,
164 'author_names' => NULL,
165 'show_timestamp' => TRUE,
166 ),
167 ),
168 'author_taxonomy_authors' => array(
169 'arguments' => array(
170 'author_names' => NULL,
171 ),
172 ),
173 'author_taxonomy_timestamp' => array(
174 'arguments' => array(
175 'timestamp' => NULL,
176 ),
177 ),
178 );
179 }
180
181
182 /**
183 * Returns div containing authors and timestamp (themeable)
184 */
185 function theme_author_taxonomy_output($node, $author_names, $show_timestamp = TRUE) {
186 $output = '';
187
188 if ($show_timestamp) {
189 // Print timestamp
190 $output .= '<span class="timestamp">'. theme('author_taxonomy_timestamp', $node->created) .'</span>';
191 }
192
193 if ($show_timestamp && !empty($author_names)) {
194 // Print separator
195 $output .= ' | ';
196 }
197
198 if (!empty($author_names)) {
199 // Print authors
200 $output .= '<span class="authors">'. theme('author_taxonomy_authors', $author_names) .'</span>';
201 }
202
203 // Wrap everything in div.submitted and return it
204 return '<div class="submitted">'. $output .'</div>';
205 }
206
207
208 /**
209 * Returns serialized list of authors' names (themeable)
210 */
211 function theme_author_taxonomy_authors($author_names) {
212 $output = '';
213 $author_count = count($author_names);
214
215 switch ($author_count) {
216 case 0 : // No authors (theme_author_taxonomy_output() should have caught this)
217 break;
218
219 case 1 : // One author (output: "Name1")
220 $output .= implode('', $author_names);
221 break;
222
223 case 2 : // Two authors (output: "Name1 and Name2")
224 $output .= implode(' and ', $author_names);
225 break;
226
227 default : // More than two authors (output: "Name1, Name2, and Name3")
228 $i = 1;
229 foreach ($author_names as $author_name) {
230 // If this is the last author
231 if ($i == $author_count) {
232 $output .= 'and '. $author_name;
233 }
234 else {
235 $output .= $author_name .', ';
236 }
237 $i++;
238 }
239 break;
240 }
241
242 return $output;
243 }
244
245
246 /**
247 * Returns the timestamp in the format chosen on the admin settings page (themeable)
248 */
249 function theme_author_taxonomy_timestamp($timestamp) {
250 $type = variable_get('author_taxonomy_timestamp_type', array('medium'));
251 $format = variable_get('author_taxonomy_timestamp_format', 'j F Y');
252
253 return format_date($timestamp, $type, $format);
254 }

  ViewVC Help
Powered by ViewVC 1.1.2