/[drupal]/contributions/modules/tribune/tribune.history.inc
ViewVC logotype

Contents of /contributions/modules/tribune/tribune.history.inc

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


Revision 1.9 - (show annotations) (download) (as text)
Fri Nov 28 12:59:32 2008 UTC (11 months, 4 weeks ago) by seeschloss
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-6--1
Changes since 1.8: +6 -6 lines
File MIME type: text/x-php
removed many old variable_gets
1 <?php
2 // vim:filetype=php expandtab tabstop=2 softtabstop=2 shiftwidth=2 autoindent smartindent
3 // $Id: tribune.history.inc,v 1.8 2008/11/28 10:22:53 seeschloss Exp $
4
5 function tribune_history_page($node) {
6 return drupal_get_form('tribune_history_form_date', $node).
7 drupal_get_form('tribune_history_form_user', $node).
8 drupal_get_form('tribune_history_form_string', $node);
9 }
10
11 function tribune_history_form_date($form_id, $node) {
12 $form = array();
13
14 $form['tribune_id'] = array(
15 '#type' => 'value',
16 '#value' => $node->nid,
17 );
18
19 $form['by-date'] = array(
20 '#type' => 'fieldset',
21 '#title' => t('Messages by date'),
22 '#description' => t('See all the messages posted at a specific date.'),
23 );
24 $form['by-date']['by-date-date'] = array(
25 '#type' => 'date',
26 );
27 $form['by-date']['by-date-submit'] = array(
28 '#type' => 'submit',
29 '#value' => t('By date'),
30 '#submit' => array('tribune_history_by_date_handler'),
31 );
32
33 return $form;
34 }
35
36 function tribune_history_form_user($form_id, $node) {
37 $form = array();
38
39 $form['tribune_id'] = array(
40 '#type' => 'value',
41 '#value' => $node->nid,
42 );
43
44 $form['by-user'] = array(
45 '#type' => 'fieldset',
46 '#title' => t('Messages by user'),
47 '#description' => t('See all the messages posted by an user.'),
48 );
49 $form['by-user']['by-user-user'] = array(
50 '#type' => 'textfield',
51 '#autocomplete_path' => 'user/autocomplete',
52 );
53 $form['by-user']['by-user-submit-registered'] = array(
54 '#prefix' => '<div class="container-inline">',
55 '#type' => 'submit',
56 '#value' => t('Registered user'),
57 '#submit' => array('tribune_history_by_user_registered_handler'),
58 );
59 $form['by-user']['by-user-submit-anonymous'] = array(
60 '#type' => 'submit',
61 '#value' => t('Anonymous user'),
62 '#suffix' => '</div>',
63 '#submit' => array('tribune_history_by_user_anonymous_handler'),
64 );
65
66 return $form;
67 }
68
69 function tribune_history_form_string($form_id, $node) {
70 $form = array();
71
72 $form['tribune_id'] = array(
73 '#type' => 'value',
74 '#value' => $node->nid,
75 );
76
77 $form['by-string'] = array(
78 '#type' => 'fieldset',
79 '#title' => t('Search messages'),
80 '#description' => t('Search messages containing a string.'),
81 );
82 $form['by-string']['by-string-string'] = array(
83 '#type' => 'textfield',
84 );
85 $form['by-string']['by-string-submit'] = array(
86 '#type' => 'submit',
87 '#value' => t('Search'),
88 '#submit' => array('tribune_history_by_string_handler'),
89 );
90
91 return $form;
92 }
93
94 function tribune_history_by_date_handler($form) {
95 $tribune_id = $form['tribune_id']['#value'];
96 $date = mktime(0, 0, 0, $form['#post']['by-date-date']['month'], $form['#post']['by-date-date']['day'], $form['#post']['by-date-date']['year']);
97
98 header("Location: ". url('node/'. $tribune_id .'/history/date/'. date("Ymd", $date)));
99 exit();
100 }
101
102 function tribune_history_by_user_registered_handler($form) {
103 $tribune_id = $form['tribune_id']['#value'];
104 header("Location: ". url('node/'. $tribune_id .'/history/user/'. $form['#post']['by-user-user']));
105 exit();
106 }
107
108 function tribune_history_by_user_anonymous_handler($form) {
109 $tribune_id = $form['tribune_id']['#value'];
110 header("Location: ". url('node/'. $tribune_id .'/history/anonymous/'. $form['#post']['by-user-user']));
111 exit();
112 }
113
114 function tribune_history_by_string_handler($form) {
115 $tribune_id = $form['tribune_id']['#value'];
116 header("Location: ". url('node/'. $tribune_id .'/history/search/'. $form['#post']['by-string-string']));
117 exit();
118 }
119
120 function tribune_history_show_posts($tribune_id, $posts, $node) {
121 drupal_add_css(drupal_get_path('module', 'tribune') .'/css/tribune.page.css');
122
123 $tribune_id = "tribune-page";
124 drupal_add_js(array(
125 "tribune" => array(
126 "tribunes" => array(
127 $tribune_id => array(
128 "reload_delay" => 0,
129 "block" => FALSE,
130 "path" => array(
131 "post" => url("tribune/post"),
132 "json_post" => url("tribune/post-json"),
133 "json_posts" => url("tribune/newposts-json"),
134 "filters" => url("tribune/filter"),
135 ),
136 ),
137 ),
138 ),
139 ), "setting");
140
141 drupal_add_js(drupal_get_path('module', 'tribune') .'/js/tribune.ajax.js');
142 drupal_add_js('misc/jquery.form.js');
143 foreach(_tribune_get_filters_help() as $filter => $function) {
144 $function();
145 }
146 $date = strtotime($date);
147
148 $contents = "<ul class='tribune-posts tribune-page' id='ul-". $tribune_id ."'>\n";
149
150 $user = user_load_self(array());
151 $login = $user[1]->name;
152
153 if (sizeof($posts) > 0) foreach ($posts as $post) {
154 if (!$post['moderated'] || tribune_access("moderate tribune", $node)) {
155 $contents .= theme("tribune_post", $post, $node) ."\n";
156
157 $_tribune_current_post_id = -1;
158 }
159 }
160
161 $contents .= "</ul>\n";
162
163 return $contents;
164 }
165
166 function tribune_history_select_posts($node, $where, $arguments) {
167 $history_size = $node->tribune_settings['history_size'];
168
169 $posts = array();
170
171 array_unshift($arguments, $node->nid);
172
173 $r = pager_query("SELECT *
174 FROM {tribune}
175 WHERE tribune_id = %d
176 AND ". $where,
177 $history_size,
178 0,
179 NULL,
180 $arguments
181 );
182
183 while ($row = db_fetch_array($r)) {
184 $posts[$row['post_id']] = tribune_post_from_row($row);
185 }
186
187 return $posts;
188 }
189
190 /**
191 * Returns all the posts for a day, in a formatted string
192 * @param $date Show the posts at this date
193 * @return String containing the posts in an HTML unordered list
194 */
195 function tribune_history_by_date($date, $node) {
196 $tribune_id = "tribune-history-date-". check_plain($date);
197
198 $posts = tribune_history_select_posts($node,
199 "SUBSTRING(post_time FROM 1 FOR 8) = '%s'
200 ORDER BY post_id ASC",
201 array(
202 $date
203 )
204 );
205
206 return tribune_history_show_posts($tribune_id, $posts, $node).theme("pager", array(), $history_size);
207 }
208
209 /**
210 * Returns all the posts for an user, in a formatted string
211 * @param $user Show the posts from this user
212 * @return String containing the posts in an HTML unordered list
213 */
214 function tribune_history_by_user($user, $node) {
215 $tribune_id = "tribune-history-user-". check_plain($user);
216 $history_size = $node->tribune_settings['history_size'];
217
218 $posts = tribune_history_select_posts($node,
219 "login = '%s'
220 ORDER BY post_id DESC",
221 array(
222 $user
223 )
224 );
225
226 return tribune_history_show_posts($tribune_id, $posts, $node).theme("pager", array(), $history_size);
227 }
228
229 function tribune_history_by_user_anonymous($user, $node) {
230 $tribune_id = "tribune-history-user-". check_plain($user);
231 $history_size = $node->tribune_settings['history_size'];
232
233 $user = '%'. str_replace('*', '%', $user) .'%';
234
235 $posts = tribune_history_select_posts($node,
236 "info LIKE '%s'
237 AND login = ''
238 ORDER BY post_id DESC",
239 array(
240 $user
241 )
242 );
243
244 return tribune_history_show_posts($tribune_id, $posts, $node).theme("pager", array(), $history_size);
245 }
246
247 function tribune_highlight_string($needle, $haystack) {
248 if (preg_match('/<a.*href=.*'. $needle .'.*>/iu', $haystack)) {
249 return $haystack;
250 }
251 else {
252 return preg_replace('/'. $needle .'/iu', '<strong>\0</strong>', $haystack);
253 }
254 }
255
256 function tribune_history_by_string($string, $node) {
257 $tribune_id = "tribune-history-string-". check_plain($string);
258 $history_size = $node->tribune_settings['history_size'];
259
260 $string_sql = '%'. str_replace('*', '%', $string) .'%';
261
262 $posts = tribune_history_select_posts($node,
263 "message LIKE '%s'
264 ORDER BY post_id DESC",
265 array(
266 $string_sql
267 )
268 );
269
270 $string_regexp = str_replace('*', '.*', $string);
271
272 foreach ($posts as $id => $post) {
273 $posts[$id]['parsed_message'] = tribune_highlight_string($string_regexp, $post['parsed_message']);
274 }
275
276 return tribune_history_show_posts($tribune_id, $posts, $node).theme("pager", array(), $history_size);
277 }
278
279 function tribune_history_search($node, $type, $argument) {
280 switch ($type) {
281 case 'date':
282 return tribune_history_by_date($argument, $node);
283 break;
284 case 'user':
285 return tribune_history_by_user($argument, $node);
286 break;
287 case 'anonymous':
288 return tribune_history_by_user_anonymous($argument, $node);
289 break;
290 case 'search':
291 return tribune_history_by_string($argument, $node);
292 break;
293 }
294 }
295

  ViewVC Help
Powered by ViewVC 1.1.2