/[drupal]/contributions/modules/feedparser/feedaggregator_item.module
ViewVC logotype

Contents of /contributions/modules/feedparser/feedaggregator_item.module

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


Revision 1.1 - (show annotations) (download) (as text)
Thu Dec 14 01:57:49 2006 UTC (2 years, 11 months ago) by budda
Branch: MAIN
CVS Tags: DRUPAL-5--0-1-dev, HEAD
Branch point for: DRUPAL-5, DRUPAL-4-7
File MIME type: text/x-php
Updated module descriptions to make them more clear about what function they provide in the FeedParser package.
1 <?php
2 // $Id: feedaggregator.module,v 1.7 2006/11/28 23:29:39 budda Exp $
3
4 /**
5 *
6 * @todo
7 * Make this module work. At present its a dump of the required bits of aggregator.module
8 * @file
9 * Used to aggregate syndicated content (RSS, RDF, and Atom).
10 */
11
12 /**
13 * Implementation of hook_help().
14 */
15 function feedaggregator_item_help($section) {
16 switch ($section) {
17 case 'admin/modules#description':
18 return t('<strong>Feed Processor</strong>: Creates traditional Drupal aggregator items from feed items. *DO NOT USE*');
19 }
20 }
21
22 /**
23 * Implementation of hook_menu().
24 */
25 function feedaggregator_item_menu($may_cache) {
26 $items = array();
27 $edit = user_access('administer news feeds');
28 $view = user_access('access news feeds');
29
30 if ($may_cache) {
31 $items[] = array('path' => 'aggregator',
32 'title' => t('news aggregator'),
33 'callback' => 'feedaggregator_page_last',
34 'access' => $view,
35 'weight' => 5);
36 $items[] = array('path' => 'aggregator/categories',
37 'title' => t('categories'),
38 'callback' => 'feedaggregator_page_categories',
39 'access' => $view,
40 'type' => MENU_ITEM_GROUPING);
41 $items[] = array('path' => 'aggregator/rss',
42 'title' => t('RSS feed'),
43 'callback' => 'feedaggregator_page_rss',
44 'access' => $view,
45 'type' => MENU_CALLBACK);
46 $items[] = array('path' => 'aggregator/opml',
47 'title' => t('OPML feed'),
48 'callback' => 'feedaggregator_page_opml',
49 'access' => $view,
50 'type' => MENU_CALLBACK);
51
52 $result = db_query('SELECT title, cid FROM {aggregator_category} ORDER BY title');
53 while ($category = db_fetch_array($result)) {
54 $items[] = array('path' => 'aggregator/categories/'. $category['cid'],
55 'title' => $category['title'],
56 'callback' => 'feedaggregator_page_category',
57 'access' => $view);
58 }
59 }
60 else {
61 if (arg(0) == 'aggregator' && is_numeric(arg(2))) {
62 if (arg(1) == 'sources') {
63 $feed = feedmanager_get_feed(arg(2));
64 if ($feed) {
65 $items[] = array('path' => 'aggregator/sources/'. $feed['fid'] .'/view',
66 'title' => t('view'),
67 'type' => MENU_DEFAULT_LOCAL_TASK,
68 'weight' => -10);
69 $items[] = array('path' => 'aggregator/sources/'. $feed['fid'] .'/categorize',
70 'title' => t('categorize'),
71 'callback' => 'feedaggregator_page_source',
72 'access' => $edit,
73 'type' => MENU_LOCAL_TASK);
74 $items[] = array('path' => 'aggregator/sources/'. $feed['fid'] .'/configure',
75 'title' => t('configure'),
76 'callback' => 'feedaggregator_form_feed',
77 'callback arguments' => array($feed),
78 'access' => $edit,
79 'type' => MENU_LOCAL_TASK,
80 'weight' => 1);
81 }
82 }
83 else if (arg(1) == 'categories') {
84 $category = feedaggregator_get_category(arg(2));
85 if ($category) {
86 $items[] = array('path' => 'aggregator/categories/'. $category['cid'] .'/view',
87 'title' => t('view'),
88 'type' => MENU_DEFAULT_LOCAL_TASK,
89 'weight' => -10);
90 $items[] = array('path' => 'aggregator/categories/'. $category['cid'] .'/categorize',
91 'title' => t('categorize'),
92 'callback' => 'feedaggregator_page_category',
93 'access' => $edit,
94 'type' => MENU_LOCAL_TASK);
95 $items[] = array('path' => 'aggregator/categories/'. $category['cid'] .'/configure',
96 'title' => t('configure'),
97 'callback' => 'feedaggregator_form_category',
98 'callback arguments' => array($category),
99 'access' => $edit,
100 'type' => MENU_LOCAL_TASK,
101 'weight' => 1);
102 }
103 }
104 }
105 }
106
107 return $items;
108 }
109
110
111 function feedaggregator_item_feedapi($feed, $op, $item = NULL) {
112 switch($op) {
113 case 'processor_name':
114 return array('feedaggregator' => t('Aggregator Items'));
115
116 case 'item_count':
117 $total_items = db_result(db_query('SELECT COUNT(iid) FROM {aggregator_item} WHERE fid = %d', $feed['fid']));
118 return array('item_count' => $total_items);
119
120 case 'item_save':
121 if($feed['processor'] == 'feedaggregator') {
122 //feedaggregator_save_item($item);
123 }
124 break;
125
126 case 'expire_items':
127 // Unpublish any old nodes
128 break;
129
130 case 'remove':
131 feedaggregator_remove($feed);
132 break;
133 }
134
135 }
136
137
138
139 /**
140 * Implementation of hook_block().
141 *
142 * Generates blocks for the latest news items in each category and feed.
143 */
144 function feedaggregator_item_block($op, $delta = 0, $edit = array()) {
145 if (user_access('access news feeds')) {
146 if ($op == 'list') {
147 $result = db_query('SELECT cid, title FROM {aggregator_category} ORDER BY title');
148 while ($category = db_fetch_object($result)) {
149 $block['category-'. $category->cid]['info'] = t('%title category latest items', array('%title' => theme('placeholder', $category->title)));
150 }
151 $result = db_query('SELECT fid, title FROM {aggregator_feed} ORDER BY fid');
152 while ($feed = db_fetch_object($result)) {
153 $block['feed-'. $feed->fid]['info'] = t('%title feed latest items', array('%title' => theme('placeholder', $feed->title)));
154 }
155 }
156 else if ($op == 'configure') {
157 list($type, $id) = explode('-', $delta);
158 if ($type == 'category') {
159 $value = db_result(db_query('SELECT block FROM {aggregator_category} WHERE cid = %d', $id));
160 }
161 else {
162 $value = db_result(db_query('SELECT block FROM {aggregator_feed} WHERE fid = %d', $id));
163 }
164 $form['block'] = array('#type' => 'select', '#title' => t('Number of news items in block'), '#default_value' => $value, '#options' => drupal_map_assoc(array(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20)));
165 return $form;
166 }
167 else if ($op == 'save') {
168 list($type, $id) = explode('-', $delta);
169 if ($type == 'category') {
170 $value = db_query('UPDATE {aggregator_category} SET block = %d WHERE cid = %d', $edit['block'], $id);
171 }
172 else {
173 $value = db_query('UPDATE {aggregator_feed} SET block = %d WHERE fid = %d', $edit['block'], $id);
174 }
175 }
176 else if ($op == 'view') {
177 list($type, $id) = explode('-', $delta);
178 switch ($type) {
179 case 'feed':
180 if ($feed = db_fetch_object(db_query('SELECT fid, title, block FROM {aggregator_feed} WHERE fid = %d', $id))) {
181 $block['subject'] = check_plain($feed->title);
182 $result = db_query_range('SELECT * FROM {aggregator_item} WHERE fid = %d ORDER BY timestamp DESC, iid DESC', $feed->fid, 0, $feed->block);
183 $block['content'] = '<div class="more-link">'. l(t('more'), 'aggregator/sources/'. $feed->fid, array('title' => t('View this feed\'s recent news.'))) .'</div>';
184 }
185 break;
186
187 case 'category':
188 if ($category = db_fetch_object(db_query('SELECT cid, title, block FROM {aggregator_category} WHERE cid = %d', $id))) {
189 $block['subject'] = check_plain($category->title);
190 $result = db_query_range('SELECT i.* FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON ci.iid = i.iid WHERE ci.cid = %d ORDER BY i.timestamp DESC, i.iid DESC', $category->cid, 0, $category->block);
191 $block['content'] = '<div class="more-link">'. l(t('more'), 'aggregator/categories/'. $category->cid, array('title' => t('View this category\'s recent news.'))) .'</div>';
192 }
193 break;
194 }
195 $items = array();
196 while ($item = db_fetch_object($result)) {
197 $items[] = theme('feedaggregator_block_item', $item);
198 }
199 $block['content'] = theme('item_list', $items) . $block['content'];
200 }
201 return $block;
202 }
203 }
204
205 /*
206 * Remove all items belonging to the feed
207 */
208 function feedaggregator_item_remove($feed) {
209 /*
210 $result = db_query('SELECT iid FROM {aggregator_item} WHERE fid = %d', $feed['fid']);
211 while ($item = db_fetch_object($result)) {
212 $items[] = "iid = $item->iid";
213 }
214 if ($items) {
215 db_query('DELETE FROM {aggregator_category_item} WHERE '. implode(' OR ', $items));
216 }
217 db_query('DELETE FROM {aggregator_item} WHERE fid = %d', $feed['fid']);
218 db_query("UPDATE {aggregator_feed} SET checked = 0, etag = '', modified = 0 WHERE fid = %d", $feed['fid']);
219 drupal_set_message(t('The news items from %site have been removed.', array('%site' => theme('placeholder', $feed['title']))));
220 */
221 }
222
223
224 function feedaggregator_item_save_item($edit) {
225 if ($edit['iid'] && $edit['title']) {
226 db_query("UPDATE {aggregator_item} SET title = '%s', link = '%s', author = '%s', description = '%s' WHERE iid = %d", $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['iid']);
227 }
228 else if ($edit['iid']) {
229 db_query('DELETE FROM {aggregator_item} WHERE iid = %d', $edit['iid']);
230 db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $edit['iid']);
231 }
232 else if ($edit['title'] && $edit['link']) {
233 $edit['iid'] = db_next_id('{aggregator_item}_iid');
234 db_query("INSERT INTO {aggregator_item} (iid, fid, title, link, author, description, timestamp) VALUES (%d, %d, '%s', '%s', '%s', '%s', %d)", $edit['iid'], $edit['fid'], $edit['title'], $edit['link'], $edit['author'], $edit['description'], $edit['timestamp']);
235 // file the items in the categories indicated by the feed
236 $categories = db_query('SELECT cid FROM {aggregator_category_feed} WHERE fid = %d', $edit['fid']);
237 while ($category = db_fetch_object($categories)) {
238 db_query('INSERT INTO {aggregator_category_item} (cid, iid) VALUES (%d, %d)', $category->cid, $edit['iid']);
239 }
240 }
241 }
242
243
244 function feedaggregator_item_get_category($cid) {
245 return db_fetch_array(db_query('SELECT * FROM {aggregator_category} WHERE cid = %d', $cid));
246 }
247
248
249 function feedaggregator_item_view() {
250 $result = db_query('SELECT f.*, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.etag, f.modified, f.image, f.block ORDER BY f.title');
251
252 $output .= '<h3>'. t('Feed overview') .'</h3>';
253
254 $header = array(t('Title'), t('Items'), t('Last update'), t('Next update'), array('data' => t('Operations'), 'colspan' => '3'));
255 $rows = array();
256 while ($feed = db_fetch_object($result)) {
257 $rows[] = array(l($feed->title, "aggregator/sources/$feed->fid"), format_plural($feed->items, '1 item', '%count items'), ($feed->checked ? t('%time ago', array('%time' => format_interval(time() - $feed->checked))) : t('never')), ($feed->checked ? t('%time left', array('%time' => format_interval($feed->checked + $feed->refresh - time()))) : t('never')), l(t('edit'), "admin/aggregator/edit/feed/$feed->fid"), l(t('remove items'), "admin/aggregator/remove/$feed->fid"), l(t('update items'), "admin/aggregator/update/$feed->fid"));
258 }
259 $output .= theme('table', $header, $rows);
260
261 $result = db_query('SELECT c.cid, c.title, count(ci.iid) as items FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid GROUP BY c.cid, c.title ORDER BY title');
262
263 $output .= '<h3>'. t('Category overview') .'</h3>';
264
265 $header = array(t('Title'), t('Items'), t('Operations'));
266 $rows = array();
267 while ($category = db_fetch_object($result)) {
268 $rows[] = array(l($category->title, "aggregator/categories/$category->cid"), format_plural($category->items, '1 item', '%count items'), l(t('edit'), "admin/aggregator/edit/category/$category->cid"));
269 }
270 $output .= theme('table', $header, $rows);
271
272 return $output;
273 }
274
275
276 /**
277 * Menu callback; displays the most recent items gathered from any feed.
278 */
279 function feedaggregator_item_page_last() {
280 return _feedaggregator_page_list('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC', arg(1));
281 }
282
283
284 /**
285 * Menu callback; displays all the items captured from a particular feed.
286 */
287 function feedaggregator_item_page_source() {
288 $feed = db_fetch_object(db_query('SELECT * FROM {aggregator_feed} WHERE fid = %d', arg(2)));
289 $info = theme('feedaggregator_feed', $feed);
290
291 return _feedaggregator_page_list('SELECT * FROM {aggregator_item} WHERE fid = '. $feed->fid .' ORDER BY timestamp DESC, iid DESC', arg(3), $info);
292 }
293
294
295 /**
296 * Menu callback; displays all the items aggregated in a particular category.
297 */
298 function feedaggregator_item_page_category() {
299 $category = db_fetch_object(db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = %d', arg(2)));
300
301 return _feedaggregator_page_list('SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = '. $category->cid .' ORDER BY timestamp DESC, iid DESC', arg(3));
302 }
303
304
305 /**
306 * Prints an aggregator page listing a number of feed items. Various
307 * menu callbacks use this function to print their feeds.
308 */
309 function _feedaggregator_page_list($sql, $op, $header = '') {
310 $categorize = (user_access('administer news feeds') && ($op == 'categorize'));
311
312 $output = '<div id="aggregator">';
313
314 $form['header'] = array('#value' => $header);
315 $output .= $form['header']['#value'];
316
317 $result = pager_query($sql, 20);
318 $categories = array();
319 while ($item = db_fetch_object($result)) {
320 $form['items'][$item->iid] = array('#value' => theme('feedaggregator_page_item', $item));
321 $output .= $form['items'][$item->iid]['#value'];
322 $form['categories'][$item->iid] = array();
323
324 if ($categorize) {
325
326 $categories_result = db_query('SELECT c.cid, c.title, ci.iid FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid AND ci.iid = %d', $item->iid);
327 $selected = array();
328 while ($category = db_fetch_object($categories_result)) {
329 if (!$done) {
330 $categories[$category->cid] = check_plain($category->title);
331 }
332 if ($category->iid) {
333 $selected[] = $category->cid;
334 }
335 }
336 $done = true;
337 $form['categories'][$item->iid] = array(
338 '#type' => variable_get('feedaggregator_category_selector', 'checkboxes'),
339 '#default_value' => $selected, '#options' => $categories,
340 '#size' => 10, '#multiple' => true
341 );
342 }
343 }
344 $output .= '</div>';
345 $form['submit'] = array('#type' => 'submit', '#value' => t('Save categories'));
346 $form['pager'] = array('#value' => theme('pager', NULL, 20, 0));
347 $output .= $form['pager']['#value'];
348
349 // arg(1) is undefined if we are at the top aggregator URL
350 // is there a better way to do this?
351 if (!arg(1)) {
352 $form['feed_icon'] = array('#value' => theme('feed_icon', url('aggregator/rss')));
353 }
354 elseif (arg(1) == 'categories' && arg(2) && !arg(3)) {
355 $form['feed_icon'] = array('#value' => theme('feed_icon', url('aggregator/rss/' . arg(2))));
356 }
357 $output .= $form['feed_icon']['#value'];
358
359 return ($categorize) ? drupal_get_form('feedaggregator_page_list', $form) : $output;
360 }
361
362 function theme_feedaggregator_page_list($form) {
363 $output = '<div id="aggregator">';
364 $output .= form_render($form['header']);
365 $rows = array();
366 if ($form['items']) {
367 foreach (element_children($form['items']) as $key) {
368 if (is_array($form['items'][$key])) {
369 $rows[] = array(form_render($form['items'][$key]), array('data' => form_render($form['categories'][$key]), 'class' => 'categorize-item'));
370 }
371 }
372 }
373 $output .= theme('table', array('', t('Categorize')), $rows);
374 $output .= form_render($form['submit']);
375 $output .= '</div>';
376 $output .= form_render($form);
377 return $output;
378 }
379
380 function feedaggregator_item_page_list_validate($form_id, &$form) {
381 if (!user_access('administer news feeds')) {
382 form_error($form, t('You are not allowed to categorize this feed item.'));
383 }
384 }
385
386 function feedaggregator_item_page_list_submit($form_id, $form_values) {
387 foreach ($form_values as $iid => $selection) {
388 db_query('DELETE FROM {aggregator_category_item} WHERE iid = %d', $iid);
389 foreach ($selection as $cid) {
390 if ($cid) {
391 db_query('INSERT INTO {aggregator_category_item} (cid, iid) VALUES (%d, %d)', $cid, $iid);
392 }
393 }
394 }
395 drupal_set_message(t('The categories have been saved.'));
396 }
397
398 /**
399 * Menu callback; displays all the feeds used by the aggregator.
400 */
401 function feedaggregator_item_page_sources() {
402 $result = db_query('SELECT f.fid, f.title, f.description, f.image, MAX(i.timestamp) AS last FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.description, f.image ORDER BY last DESC, f.title');
403 $output = "<div id=\"aggregator\">\n";
404 while ($feed = db_fetch_object($result)) {
405 $output .= '<h2>'. check_plain($feed->title) ."</h2>\n";
406
407 // Most recent items:
408 $list = array();
409 if (variable_get('feedaggregator_summary_items', 3)) {
410 $items = db_query_range('SELECT i.title, i.timestamp, i.link FROM {aggregator_item} i WHERE i.fid = %d ORDER BY i.timestamp DESC', $feed->fid, 0, variable_get('feedaggregator_summary_items', 3));
411 while ($item = db_fetch_object($items)) {
412 $list[] = theme('feedaggregator_summary_item', $item);
413 }
414 }
415 $output .= theme('item_list', $list);
416 $output .= '<div class="links">'. theme('links', array(l(t('more'), 'aggregator/sources/'. $feed->fid))) ."</div>\n";
417 }
418 $output .= theme('xml_icon', url('aggregator/opml'));
419 $output .= '</div>';
420 return $output;
421 }
422
423 /**
424 * Menu callback; generate an RSS 0.92 feed of aggregator items or categories.
425 */
426 function feedaggregator_item_page_rss() {
427 global $base_url;
428
429 // arg(2) is the passed cid, only select for that category
430 $result = NULL;
431 if (arg(2)) {
432 $category = db_fetch_object(db_query('SELECT cid, title FROM {aggregator_category} WHERE cid = %d', arg(2)));
433 $url = '/categories/' . $category->cid;
434 $title = ' ' . t('in category') . ' ' . $category->title;
435 $sql = 'SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_category_item} c LEFT JOIN {aggregator_item} i ON c.iid = i.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE cid = %d ORDER BY timestamp DESC, iid DESC';
436 $result = db_query_range($sql, $category->cid, 0, variable_get('feed_default_items', 10));
437 }
438 // or, get the default aggregator items
439 else {
440 $sql = 'SELECT i.*, f.title AS ftitle, f.link AS flink FROM {aggregator_item} i INNER JOIN {aggregator_feed} f ON i.fid = f.fid ORDER BY i.timestamp DESC, i.iid DESC';
441 $result = db_query_range($sql, 0, variable_get('feed_default_items', 10));
442 }
443
444 while ($item = db_fetch_object($result)) {
445 switch (variable_get('feed_item_length', 'teaser')) {
446 case 'teaser':
447 $teaser = node_teaser($item->description);
448 if ($teaser != $item_description) {
449 $teaser .= '<p><a href="'. check_url($item->link) .'">'. t('read more') ."</a></p>\n";
450 }
451 $item->description = $teaser;
452 break;
453 case 'title':
454 $item->description = '';
455 break;
456 }
457 $items .= format_rss_item($item->ftitle . ': ' . $item->title, $item->link, $item->description, array('pubDate' => date('r', $item->timestamp)));
458 }
459
460 $output .= "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
461 $output .= "<rss version=\"2.0\">\n";
462 $output .= format_rss_channel(variable_get('site_name', t('Drupal')) . ' ' . t('aggregator'), $base_url . '/' . url('aggregator' . $url), variable_get('site_name', t('Drupal')) . ' - ' . t('aggregated feeds') . $title, $items, 'en');
463 $output .= "</rss>\n";
464
465 drupal_set_header('Content-Type: text/xml; charset=utf-8');
466 print $output;
467 }
468
469 /**
470 * Menu callback; generates an OPML representation of all feeds.
471 */
472 function feedaggregator_item_page_opml($cid = NULL) {
473 if ($cid) {
474 $result = db_query('SELECT f.title, f.url FROM {aggregator_feed} f LEFT JOIN {aggregator_category_feed} c on f.fid = c.fid WHERE c.cid = %d ORDER BY title', $cid);
475 }
476 else {
477 $result = db_query('SELECT * FROM {aggregator_feed} ORDER BY title');
478 }
479
480 $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
481 $output .= "<opml version=\"1.1\">\n";
482 $output .= "<head>\n";
483 $output .= '<title>'. check_plain(variable_get('site_name', 'Drupal')) ."</title>\n";
484 $output .= '<dateModified>'. gmdate('r') ."</dateModified>\n";
485 $output .= "</head>\n";
486 $output .= "<body>\n";
487
488 while ($feed = db_fetch_object($result)) {
489 $output .= '<outline text="'. check_plain($feed->title) .'" xmlUrl="'. check_url($feed->url) ."\" />\n";
490 }
491
492 $output .= "</body>\n";
493 $output .= "</opml>\n";
494
495 drupal_set_header('Content-Type: text/xml; charset=utf-8');
496 print $output;
497 }
498
499 /**
500 * Menu callback; displays all the categories used by the aggregator.
501 */
502 function feedaggregator_item_page_categories() {
503 $result = db_query('SELECT c.cid, c.title, c.description FROM {aggregator_category} c LEFT JOIN {aggregator_category_item} ci ON c.cid = ci.cid LEFT JOIN {aggregator_item} i ON ci.iid = i.iid GROUP BY c.cid, c.title, c.description');
504 $output = "<div id=\"aggregator\">\n";
505
506 while ($category = db_fetch_object($result)) {
507 $output .= '<h2>'. check_plain($category->title) ."</h2>\n";
508 if (variable_get('feedaggregator_summary_items', 3)) {
509 $list = array();
510 $items = db_query_range('SELECT i.title, i.timestamp, i.link, f.title as feed_title, f.link as feed_link FROM {aggregator_category_item} ci LEFT JOIN {aggregator_item} i ON i.iid = ci.iid LEFT JOIN {aggregator_feed} f ON i.fid = f.fid WHERE ci.cid = %d ORDER BY i.timestamp DESC', $category->cid, 0, variable_get('feedaggregator_summary_items', 3));
511 while ($item = db_fetch_object($items)) {
512 $list[] = theme('feedaggregator_summary_item', $item);
513 }
514 $output .= theme('item_list', $list);
515 }
516 $output .= '<div class="links">'. theme('links', array(l(t('more'), 'aggregator/categories/'. $category->cid))) ."</div>\n";
517 }
518 $output .= '</div>';
519
520 return $output;
521 }
522
523 /**
524 * Format a news feed.
525 *
526 * @ingroup themeable
527 */
528 function theme_feedaggregator_feed($feed) {
529 $output = '<div class="feed-source">';
530 $output .= theme('feed_icon', $feed->url) ."\n";
531 $output .= $feed->image;
532 $output .= '<div class="feed-description">'. feedmanager_filter_xss($feed->description) ."</div>\n";
533 $output .= '<div class="feed-url"><em>'. t('URL:') .'</em> '. l($feed->link, $feed->link, array(), NULL, NULL, TRUE) ."</div>\n";
534
535 $updated = t('%time ago', array('%time' => format_interval(time() - $feed->checked)));
536 if (user_access('administer news feeds')) {
537 $updated = l($updated, 'admin/aggregator');
538 }
539
540 $output .= '<div class="feed-updated"><em>'. t('Updated:') . "</em> $updated</div>";
541 $output .= "</div>\n";
542
543 return $output;
544 }
545
546 /**
547 * Format an individual feed item for display in the block.
548 *
549 * @ingroup themeable
550 */
551 function theme_feedaggregator_block_item($item, $feed = 0) {
552 global $user;
553
554 if ($user->uid && module_exist('blog') && user_access('edit own blog')) {
555 if ($image = theme('image', 'misc/blog.png', t('blog it'), t('blog it'))) {
556 $output .= '<div class="icon">'. l($image, 'node/add/blog', array('title' => t('Comment on this news item in your personal blog.'), 'class' => 'blog-it'), "iid=$item->iid", NULL, FALSE, TRUE) .'</div>';
557 }
558 }
559
560 // Display the external link to the item.
561 $output .= '<a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a>\n";
562
563 return $output;
564 }
565
566 /**
567 * Return a themed item heading for summary pages located at "aggregator/sources"
568 * and "aggregator/categories".
569 *
570 * @param $item The item object from the aggregator module.
571 * @return A string containing the output.
572 *
573 * @ingroup themeable
574 */
575 function theme_feedaggregator_summary_item($item) {
576 $output = '<a href="'. check_url($item->link) .'">'. check_plain($item->title) .'</a> <span class="age">'. t('%age old', array('%age' => format_interval(time() - $item->timestamp))) .'</span>';
577 if ($item->feed_link) {
578 $output .= ', <span class="source"><a href="'. check_url($item->feed_link) .'">'. check_plain($item->feed_title) .'</a></span>';
579 }
580 return $output ."\n";
581 }
582
583 /**
584 * Format an individual feed item for display on the aggregator page.
585 *
586 * @ingroup themeable
587 */
588 function theme_feedaggregator_page_item($item) {
589
590 $source = '';
591 if ($item->ftitle && $item->fid) {
592 $source = l($item->ftitle, "aggregator/sources/$item->fid", array('class' => 'feed-item-source')) . ' -';
593 }
594
595 if (date('Ymd', $item->timestamp) == date('Ymd')) {
596 $source_date = t('%ago ago', array('%ago' => format_interval(time() - $item->timestamp)));
597 }
598 else {
599 $source_date = format_date($item->timestamp, 'custom', variable_get('date_format_medium', 'D, Y-m-d H:i'));
600 }
601
602 $output .= "<div class=\"feed-item\">\n";
603 $output .= '<h3 class="feed-item-title"><a href="'. check_url($item->link) .'">'. check_plain($item->title) ."</a></h3>\n";
604 $output .= "<div class=\"feed-item-meta\">$source <span class=\"feed-item-date\">$source_date</span></div>\n";
605
606 if ($item->description) {
607 $output .= '<div class="feed-item-body">'. feedmanager_filter_xss($item->description) ."</div>\n";
608 }
609
610 $result = db_query('SELECT c.title, c.cid FROM {aggregator_category_item} ci LEFT JOIN {aggregator_category} c ON ci.cid = c.cid WHERE ci.iid = %d ORDER BY c.title', $item->iid);
611 $categories = array();
612 while ($category = db_fetch_object($result)) {
613 $categories[] = l($category->title, 'aggregator/categories/'. $category->cid);
614 }
615 if ($categories) {
616 $output .= '<div class="feed-item-categories">'. t('Categories') .': '. implode(', ', $categories) ."</div>\n";
617 }
618
619 $output .= "</div>\n";
620
621 return $output;
622 }
623
624 /**
625 * Helper function for drupal_map_assoc.
626 */
627 function _feedaggregator_items($count) {
628 return format_plural($count, '1 item', '%count items');
629 }

  ViewVC Help
Powered by ViewVC 1.1.2