| 1 | | <?php |
| 2 | | // $Id: aggregator.pages.inc,v 1.22 2008/10/20 12:57:35 dries Exp $ |
| 3 | | |
| 4 | | /** |
| 5 | | * @file |
| 6 | | * User page callbacks for the aggregator module. |
| 7 | | */ |
| 8 | | |
| 9 | | /** |
| 10 | | * Menu callback; displays the most recent items gathered from any feed. |
| 11 | | * |
| 12 | | * @return |
| 13 | | * The items HTML. |
| 14 | | */ |
| 15 | 12 | function aggregator_page_last() { |
| 16 | 0 | drupal_add_feed(url('aggregator/rss'), variable_get('site_name',
'Drupal') . ' ' . t('aggregator')); |
| 17 | | |
| 18 | 0 | $items = aggregator_feed_items_load('sum'); |
| 19 | | |
| 20 | 0 | return _aggregator_page_list($items, arg(1)); |
| 21 | 0 | } |
| 22 | | |
| 23 | | /** |
| 24 | | * Menu callback; displays all the items captured from a particular feed. |
| 25 | | * |
| 26 | | * If there are two arguments then this function is the categorize form. |
| 27 | | * |
| 28 | | * @param $arg1 |
| 29 | | * If there are two arguments then $arg1 is $form_state. Otherwise, $arg1
is $feed. |
| 30 | | * @param $arg2 |
| 31 | | * If there are two arguments then $arg2 is feed. |
| 32 | | * @return |
| 33 | | * The item's HTML. |
| 34 | | */ |
| 35 | 12 | function aggregator_page_source($arg1, $arg2 = NULL) { |
| 36 | | // If there are two arguments then this function is the categorize form,
and |
| 37 | | // $arg1 is $form_state and $arg2 is $feed. Otherwise, $arg1 is $feed. |
| 38 | 2 | $feed = is_array($arg2) ? $arg2 : $arg1; |
| 39 | 2 | $feed = (object)$feed; |
| 40 | 2 | drupal_set_title($feed->title); |
| 41 | 2 | $feed_source = theme('aggregator_feed_source', $feed); |
| 42 | | |
| 43 | | // It is safe to include the fid in the query because it's loaded from
the |
| 44 | | // database by aggregator_feed_load. |
| 45 | 2 | $items = aggregator_feed_items_load('source', $feed); |
| 46 | | |
| 47 | 2 | return _aggregator_page_list($items, arg(3), $feed_source); |
| 48 | 0 | } |
| 49 | | |
| 50 | | /** |
| 51 | | * Menu callback; displays all the items aggregated in a particular
category. |
| 52 | | * |
| 53 | | * If there are two arguments then this function is called as a form. |
| 54 | | * |
| 55 | | * @param $arg1 |
| 56 | | * If there are two arguments then $arg1 is $form_state. Otherwise, $arg1
is $category. |
| 57 | | * @param $arg2 |
| 58 | | * If there are two arguments then $arg2 is $category. |
| 59 | | * @return |
| 60 | | * The items HTML. |
| 61 | | */ |
| 62 | 12 | function aggregator_page_category($arg1, $arg2 = NULL) { |
| 63 | | // If there are two arguments then we are called as a form, $arg1 is |
| 64 | | // $form_state and $arg2 is $category. Otherwise, $arg1 is $category. |
| 65 | 0 | $category = is_array($arg2) ? $arg2 : $arg1; |
| 66 | | |
| 67 | 0 | drupal_add_feed(url('aggregator/rss/' . $category['cid']),
variable_get('site_name', 'Drupal') . ' ' . t('aggregator - @title',
array('@title' => $category['title']))); |
| 68 | | |
| 69 | | // It is safe to include the cid in the query because it's loaded from
the |
| 70 | | // database by aggregator_category_load. |
| 71 | 0 | $items = aggregator_feed_items_load('category', $category); |
| 72 | | |
| 73 | 0 | return _aggregator_page_list($items, arg(3)); |
| 74 | 0 | } |
| 75 | | |
| 76 | | /** |
| 77 | | * Load feed items |
| 78 | | * |
| 79 | | * @param $type |
| 80 | | * The filter for the items. Possible values: 'sum', 'source', 'category' |
| 81 | | * @param $data |
| 82 | | * Feed or category data for filtering |
| 83 | | * @return |
| 84 | | * An array of the feed items. |
| 85 | | */ |
| 86 | 12 | function aggregator_feed_items_load($type, $data = NULL) { |
| 87 | 2 | $items = array(); |
| 88 | 2 | $range_limit = 20; |
| 89 | | switch ($type) { |
| 90 | 2 | case 'sum': |
| 91 | 0 | $result = db_query_range('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', 0, $range_limit); |
| 92 | 0 | break; |
| 93 | 2 | case 'source': |
| 94 | 2 | $result = db_query_range('SELECT * FROM {aggregator_item} WHERE fid =
:fid ORDER BY timestamp DESC, iid DESC', array(':fid' => $data->fid), 0,
$range_limit); |
| 95 | 2 | break; |
| 96 | 0 | case 'category': |
| 97 | 0 | $result = db_query_range('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 =
:cid ORDER BY timestamp DESC, i.iid DESC', array(':cid' => $data['cid']),
0, $range_limit); |
| 98 | 0 | break; |
| 99 | 0 | } |
| 100 | | |
| 101 | 2 | foreach ($result as $item) { |
| 102 | 0 | $item->categories = 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 = :iid ORDER BY c.title', array(':iid' =>
$item->iid))->fetchAll(); |
| 103 | 0 | $items[] = $item; |
| 104 | 0 | } |
| 105 | | |
| 106 | 2 | return $items; |
| 107 | 0 | } |
| 108 | | |
| 109 | | /** |
| 110 | | * Prints an aggregator page listing a number of feed items. |
| 111 | | * |
| 112 | | * Various menu callbacks use this function to print their feeds. |
| 113 | | * |
| 114 | | * @param $items |
| 115 | | * The items to be listed. |
| 116 | | * @param $op |
| 117 | | * Which form should be added to the items. Only 'categorize' is now
recognized. |
| 118 | | * @param $feed_source |
| 119 | | * The feed source URL. |
| 120 | | * @return |
| 121 | | * The items HTML. |
| 122 | | */ |
| 123 | 12 | function _aggregator_page_list($items, $op, $feed_source = '') { |
| 124 | 2 | if (user_access('administer news feeds') && ($op == 'categorize')) { |
| 125 | | // Get form data. |
| 126 | 0 | $output = aggregator_categorize_items($items, $feed_source); |
| 127 | 0 | } |
| 128 | | else { |
| 129 | | // Assemble themed output. |
| 130 | 2 | $output = $feed_source; |
| 131 | 2 | foreach ($items as $item) { |
| 132 | 0 | $output .= theme('aggregator_item', $item); |
| 133 | 0 | } |
| 134 | 2 | $output = theme('aggregator_wrapper', $output); |
| 135 | | } |
| 136 | | |
| 137 | 2 | return $output; |
| 138 | 0 | } |
| 139 | | |
| 140 | | /** |
| 141 | | * Form builder; build the page list form. |
| 142 | | * |
| 143 | | * @param $items |
| 144 | | * An array of the feed items. |
| 145 | | * @param $feed_source |
| 146 | | * The feed source URL. |
| 147 | | * @return |
| 148 | | * The form structure. |
| 149 | | * @ingroup forms |
| 150 | | * @see aggregator_categorize_items_validate() |
| 151 | | * @see aggregator_categorize_items_submit() |
| 152 | | */ |
| 153 | 12 | function aggregator_categorize_items($items, $feed_source = '') { |
| 154 | 0 | $form['#submit'][] = 'aggregator_categorize_items_submit'; |
| 155 | 0 | $form['#validate'][] = 'aggregator_categorize_items_validate'; |
| 156 | 0 | $form['#theme'] = 'aggregator_categorize_items'; |
| 157 | 0 | $form['feed_source'] = array( |
| 158 | 0 | '#value' => $feed_source, |
| 159 | | ); |
| 160 | 0 | $categories = array(); |
| 161 | 0 | $done = FALSE; |
| 162 | 0 | $form['items'] = array(); |
| 163 | 0 | $form['categories'] = array( |
| 164 | 0 | '#tree' => TRUE, |
| 165 | | ); |
| 166 | 0 | foreach ($items as $item) { |
| 167 | 0 | $form['items'][$item->iid] = array('#markup' =>
theme('aggregator_item', $item)); |
| 168 | 0 | $form['categories'][$item->iid] = array(); |
| 169 | 0 | $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 = :iid', array(':iid' => $item->iid)); |
| 170 | 0 | $selected = array(); |
| 171 | 0 | foreach ($categories_result as $category) { |
| 172 | 0 | if (!$done) { |
| 173 | 0 | $categories[$category->cid] = check_plain($category->title); |
| 174 | 0 | } |
| 175 | 0 | if ($category->iid) { |
| 176 | 0 | $selected[] = $category->cid; |
| 177 | 0 | } |
| 178 | 0 | } |
| 179 | 0 | $done = TRUE; |
| 180 | 0 | $form['categories'][$item->iid] = array( |
| 181 | 0 | '#type' => variable_get('aggregator_category_selector',
'checkboxes'), |
| 182 | 0 | '#default_value' => $selected, |
| 183 | 0 | '#options' => $categories, |
| 184 | 0 | '#size' => 10, |
| 185 | | '#multiple' => TRUE |
| 186 | 0 | ); |
| 187 | 0 | } |
| 188 | 0 | $form['submit'] = array('#type' => 'submit', '#value' => t('Save
categories')); |
| 189 | | |
| 190 | 0 | return $form; |
| 191 | 0 | } |
| 192 | | |
| 193 | | /** |
| 194 | | * Validate aggregator_categorize_items() form submissions. |
| 195 | | */ |
| 196 | 12 | function aggregator_categorize_items_validate($form, &$form_state) { |
| 197 | 0 | if (!user_access('administer news feeds')) { |
| 198 | 0 | form_error($form, t('You are not allowed to categorize this feed
item.')); |
| 199 | 0 | } |
| 200 | 0 | } |
| 201 | | |
| 202 | | /** |
| 203 | | * Process aggregator_categorize_items() form submissions. |
| 204 | | */ |
| 205 | 12 | function aggregator_categorize_items_submit($form, &$form_state) { |
| 206 | 0 | if (!empty($form_state['values']['categories'])) { |
| 207 | 0 | foreach ($form_state['values']['categories'] as $iid => $selection) { |
| 208 | 0 | db_delete('aggregator_category_item') |
| 209 | 0 | ->condition('iid', $iid) |
| 210 | 0 | ->execute(); |
| 211 | 0 | $insert = db_insert('aggregator_category_item')->fields(array('iid',
'cid')); |
| 212 | 0 | $has_values = FALSE; |
| 213 | 0 | foreach ($selection as $cid) { |
| 214 | 0 | if ($cid && $iid) { |
| 215 | 0 | $has_values = TRUE; |
| 216 | 0 | $insert->values(array( |
| 217 | 0 | 'iid' => $iid, |
| 218 | 0 | 'cid' => $cid, |
| 219 | 0 | )); |
| 220 | 0 | } |
| 221 | 0 | } |
| 222 | 0 | if ($has_values) { |
| 223 | 0 | $insert->execute(); |
| 224 | 0 | } |
| 225 | 0 | } |
| 226 | 0 | } |
| 227 | 0 | drupal_set_message(t('The categories have been saved.')); |
| 228 | 0 | } |
| 229 | | |
| 230 | | /** |
| 231 | | * Theme the page list form for assigning categories. |
| 232 | | * |
| 233 | | * @param $form |
| 234 | | * An associative array containing the structure of the form. |
| 235 | | * @return |
| 236 | | * The output HTML. |
| 237 | | * @ingroup themeable |
| 238 | | */ |
| 239 | 12 | function theme_aggregator_categorize_items($form) { |
| 240 | 0 | $output = drupal_render($form['feed_source']); |
| 241 | 0 | $rows = array(); |
| 242 | 0 | if ($form['items']) { |
| 243 | 0 | foreach (element_children($form['items']) as $key) { |
| 244 | 0 | if (is_array($form['items'][$key])) { |
| 245 | 0 | $rows[] = array( |
| 246 | 0 | drupal_render($form['items'][$key]), |
| 247 | 0 | array('data' => drupal_render($form['categories'][$key]), 'class'
=> 'categorize-item'), |
| 248 | | ); |
| 249 | 0 | } |
| 250 | 0 | } |
| 251 | 0 | } |
| 252 | 0 | $output .= theme('table', array('', t('Categorize')), $rows); |
| 253 | 0 | $output .= drupal_render($form['submit']); |
| 254 | 0 | $output .= drupal_render($form); |
| 255 | | |
| 256 | 0 | return theme('aggregator_wrapper', $output); |
| 257 | 0 | } |
| 258 | | |
| 259 | | /** |
| 260 | | * Process variables for aggregator-wrapper.tpl.php. |
| 261 | | * |
| 262 | | * @see aggregator-wrapper.tpl.php |
| 263 | | */ |
| 264 | 12 | function template_preprocess_aggregator_wrapper(&$variables) { |
| 265 | 2 | $variables['pager'] = theme('pager', NULL, 20, 0); |
| 266 | 2 | } |
| 267 | | |
| 268 | | /** |
| 269 | | * Process variables for aggregator-item.tpl.php. |
| 270 | | * |
| 271 | | * @see aggregator-item.tpl.php |
| 272 | | */ |
| 273 | 12 | function template_preprocess_aggregator_item(&$variables) { |
| 274 | 0 | $item = $variables['item']; |
| 275 | | |
| 276 | 0 | $variables['feed_url'] = check_url($item->link); |
| 277 | 0 | $variables['feed_title'] = check_plain($item->title); |
| 278 | 0 | $variables['content'] = aggregator_filter_xss($item->description); |
| 279 | | |
| 280 | 0 | $variables['source_url'] = ''; |
| 281 | 0 | $variables['source_title'] = ''; |
| 282 | 0 | if (isset($item->ftitle) && isset($item->fid)) { |
| 283 | 0 | $variables['source_url'] = url("aggregator/sources/$item->fid"); |
| 284 | 0 | $variables['source_title'] = check_plain($item->ftitle); |
| 285 | 0 | } |
| 286 | 0 | if (date('Ymd', $item->timestamp) == date('Ymd')) { |
| 287 | 0 | $variables['source_date'] = t('%ago ago', array('%ago' =>
format_interval(REQUEST_TIME - $item->timestamp))); |
| 288 | 0 | } |
| 289 | | else { |
| 290 | 0 | $variables['source_date'] = format_date($item->timestamp, 'custom',
variable_get('date_format_medium', 'D, m/d/Y - H:i')); |
| 291 | | } |
| 292 | | |
| 293 | 0 | $variables['categories'] = array(); |
| 294 | 0 | foreach ($item->categories as $category) { |
| 295 | 0 | $variables['categories'][$category->cid] = l($category->title,
'aggregator/categories/' . $category->cid); |
| 296 | 0 | } |
| 297 | 0 | } |
| 298 | | |
| 299 | | /** |
| 300 | | * Menu callback; displays all the feeds used by the aggregator. |
| 301 | | */ |
| 302 | 12 | function aggregator_page_sources() { |
| 303 | 0 | $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'); |
| 304 | | |
| 305 | 0 | $output = ''; |
| 306 | 0 | foreach ($result as $feed) { |
| 307 | | // Most recent items: |
| 308 | 0 | $summary_items = array(); |
| 309 | 0 | if (variable_get('aggregator_summary_items', 3)) { |
| 310 | 0 | $items = db_query_range('SELECT i.title, i.timestamp, i.link FROM
{aggregator_item} i WHERE i.fid = :fid ORDER BY i.timestamp DESC',
array(':fid' => $feed->fid), 0, variable_get('aggregator_summary_items',
3)); |
| 311 | 0 | foreach ($items as $item) { |
| 312 | 0 | $summary_items[] = theme('aggregator_summary_item', $item); |
| 313 | 0 | } |
| 314 | 0 | } |
| 315 | 0 | $feed->url = url('aggregator/sources/' . $feed->fid); |
| 316 | 0 | $output .= theme('aggregator_summary_items', $summary_items, $feed); |
| 317 | 0 | } |
| 318 | 0 | $output .= theme('feed_icon', url('aggregator/opml'), t('OPML feed')); |
| 319 | | |
| 320 | 0 | return theme('aggregator_wrapper', $output); |
| 321 | 0 | } |
| 322 | | |
| 323 | | /** |
| 324 | | * Menu callback; displays all the categories used by the aggregator. |
| 325 | | */ |
| 326 | 12 | function aggregator_page_categories() { |
| 327 | 0 | $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'); |
| 328 | | |
| 329 | 0 | $output = ''; |
| 330 | 0 | foreach ($result as $category) { |
| 331 | 0 | if (variable_get('aggregator_summary_items', 3)) { |
| 332 | 0 | $summary_items = array(); |
| 333 | 0 | $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 = :cid ORDER BY i.timestamp DESC', array(':cid'
=> $category->cid), 0, variable_get('aggregator_summary_items', 3)); |
| 334 | 0 | foreach ($items as $item) { |
| 335 | 0 | $summary_items[] = theme('aggregator_summary_item', $item); |
| 336 | 0 | } |
| 337 | 0 | } |
| 338 | 0 | $category->url = url('aggregator/categories/' . $category->cid); |
| 339 | 0 | $output .= theme('aggregator_summary_items', $summary_items,
$category); |
| 340 | 0 | } |
| 341 | | |
| 342 | 0 | return theme('aggregator_wrapper', $output); |
| 343 | 0 | } |
| 344 | | |
| 345 | | /** |
| 346 | | * Menu callback; generate an RSS 0.92 feed of aggregator items or
categories. |
| 347 | | */ |
| 348 | 12 | function aggregator_page_rss() { |
| 349 | 0 | $result = NULL; |
| 350 | | // arg(2) is the passed cid, only select for that category. |
| 351 | 0 | if (arg(2)) { |
| 352 | 0 | $category = db_query('SELECT cid, title FROM {aggregator_category}
WHERE cid = :cid', array(':cid' => arg(2)))->fetchObject(); |
| 353 | 0 | $result = db_query_range('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 =
:cid ORDER BY timestamp DESC, i.iid DESC', array(':cid' => $category->cid),
0, variable_get('feed_default_items', 10)); |
| 354 | 0 | } |
| 355 | | // Or, get the default aggregator items. |
| 356 | | else { |
| 357 | 0 | $category = NULL; |
| 358 | 0 | $result = db_query_range('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', 0,
variable_get('feed_default_items', 10)); |
| 359 | | } |
| 360 | | |
| 361 | 0 | $feeds = $result->fetchAll(); |
| 362 | 0 | return theme('aggregator_page_rss', $feeds, $category); |
| 363 | 0 | } |
| 364 | | |
| 365 | | /** |
| 366 | | * Theme the RSS output. |
| 367 | | * |
| 368 | | * @param $feeds |
| 369 | | * An array of the feeds to theme. |
| 370 | | * @param $category |
| 371 | | * A common category, if any, for all the feeds. |
| 372 | | * @ingroup themeable |
| 373 | | */ |
| 374 | 12 | function theme_aggregator_page_rss($feeds, $category = NULL) { |
| 375 | 0 | drupal_set_header('Content-Type: application/rss+xml; charset=utf-8'); |
| 376 | | |
| 377 | 0 | $items = ''; |
| 378 | 0 | $feed_length = variable_get('feed_item_length', 'teaser'); |
| 379 | 0 | foreach ($feeds as $feed) { |
| 380 | | switch ($feed_length) { |
| 381 | 0 | case 'teaser': |
| 382 | 0 | $teaser = node_teaser($feed->description); |
| 383 | 0 | if ($teaser != $feed->description) { |
| 384 | 0 | $teaser .= '<p><a href="' . check_url($feed->link) . '">' .
t('read more') . "</a></p>\n"; |
| 385 | 0 | } |
| 386 | 0 | $feed->description = $teaser; |
| 387 | 0 | break; |
| 388 | 0 | case 'title': |
| 389 | 0 | $feed->description = ''; |
| 390 | 0 | break; |
| 391 | 0 | } |
| 392 | 0 | $items .= format_rss_item($feed->ftitle . ': ' . $feed->title,
$feed->link, $feed->description, array('pubDate' => date('r',
$feed->timestamp))); |
| 393 | 0 | } |
| 394 | | |
| 395 | 0 | $site_name = variable_get('site_name', 'Drupal'); |
| 396 | 0 | $url = url((isset($category) ? 'aggregator/categories/' . $category->cid
: 'aggregator'), array('absolute' => TRUE)); |
| 397 | 0 | $description = isset($category) ? t('@site_name - aggregated feeds in
category @title', array('@site_name' => $site_name, '@title' =>
$category->title)) : t('@site_name - aggregated feeds', array('@site_name'
=> $site_name)); |
| 398 | | |
| 399 | 0 | $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; |
| 400 | 0 | $output .= "<rss version=\"2.0\">\n"; |
| 401 | 0 | $output .= format_rss_channel(t('@site_name aggregator',
array('@site_name' => $site_name)), $url, $description, $items); |
| 402 | 0 | $output .= "</rss>\n"; |
| 403 | | |
| 404 | 0 | print $output; |
| 405 | 0 | } |
| 406 | | |
| 407 | | /** |
| 408 | | * Menu callback; generates an OPML representation of all feeds. |
| 409 | | * |
| 410 | | * @param $cid |
| 411 | | * If set, feeds are exported only from a category with this ID.
Otherwise, all feeds are exported. |
| 412 | | * @return |
| 413 | | * The output XML. |
| 414 | | */ |
| 415 | 12 | function aggregator_page_opml($cid = NULL) { |
| 416 | 0 | if ($cid) { |
| 417 | 0 | $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 = :cid ORDER
BY title', array(':cid' => $cid)); |
| 418 | 0 | } |
| 419 | | else { |
| 420 | 0 | $result = db_query('SELECT * FROM {aggregator_feed} ORDER BY title'); |
| 421 | | } |
| 422 | | |
| 423 | 0 | $feeds = $result->fetchAll(); |
| 424 | 0 | return theme('aggregator_page_opml', $feeds); |
| 425 | 0 | } |
| 426 | | |
| 427 | | /** |
| 428 | | * Theme the OPML feed output. |
| 429 | | * |
| 430 | | * @param $feeds |
| 431 | | * An array of the feeds to theme. |
| 432 | | * @ingroup themeable |
| 433 | | */ |
| 434 | 12 | function theme_aggregator_page_opml($feeds) { |
| 435 | 0 | drupal_set_header('Content-Type: text/xml; charset=utf-8'); |
| 436 | | |
| 437 | 0 | $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; |
| 438 | 0 | $output .= "<opml version=\"1.1\">\n"; |
| 439 | 0 | $output .= "<head>\n"; |
| 440 | 0 | $output .= '<title>' . check_plain(variable_get('site_name', 'Drupal')) .
"</title>\n"; |
| 441 | 0 | $output .= '<dateModified>' . gmdate('r') . "</dateModified>\n"; |
| 442 | 0 | $output .= "</head>\n"; |
| 443 | 0 | $output .= "<body>\n"; |
| 444 | 0 | foreach ($feeds as $feed) { |
| 445 | 0 | $output .= '<outline text="' . check_plain($feed->title) . '" xmlUrl="'
. check_url($feed->url) . "\" />\n"; |
| 446 | 0 | } |
| 447 | 0 | $output .= "</body>\n"; |
| 448 | 0 | $output .= "</opml>\n"; |
| 449 | | |
| 450 | 0 | print $output; |
| 451 | 0 | } |
| 452 | | |
| 453 | | /** |
| 454 | | * Process variables for aggregator-summary-items.tpl.php. |
| 455 | | * |
| 456 | | * @see aggregator-summary-item.tpl.php |
| 457 | | */ |
| 458 | 12 | function template_preprocess_aggregator_summary_items(&$variables) { |
| 459 | 0 | $variables['title'] = check_plain($variables['source']->title); |
| 460 | 0 | $variables['summary_list'] = theme('item_list',
$variables['summary_items']); |
| 461 | 0 | $variables['source_url'] = $variables['source']->url; |
| 462 | 0 | } |
| 463 | | |
| 464 | | /** |
| 465 | | * Process variables for aggregator-summary-item.tpl.php. |
| 466 | | * |
| 467 | | * @see aggregator-summary-item.tpl.php |
| 468 | | */ |
| 469 | 12 | function template_preprocess_aggregator_summary_item(&$variables) { |
| 470 | 0 | $item = $variables['item']; |
| 471 | | |
| 472 | 0 | $variables['feed_url'] = check_url($item->link); |
| 473 | 0 | $variables['feed_title'] = check_plain($item->title); |
| 474 | 0 | $variables['feed_age'] = t('%age old', array('%age' =>
format_interval(REQUEST_TIME - $item->timestamp))); |
| 475 | | |
| 476 | 0 | $variables['source_url'] = ''; |
| 477 | 0 | $variables['source_title'] = ''; |
| 478 | 0 | if (!empty($item->feed_link)) { |
| 479 | 0 | $variables['source_url'] = check_url($item->feed_link); |
| 480 | 0 | $variables['source_title'] = check_plain($item->feed_title); |
| 481 | 0 | } |
| 482 | 0 | } |
| 483 | | |
| 484 | | /** |
| 485 | | * Process variables for aggregator-feed-source.tpl.php. |
| 486 | | * |
| 487 | | * @see aggregator-feed-source.tpl.php |
| 488 | | */ |
| 489 | 12 | function template_preprocess_aggregator_feed_source(&$variables) { |
| 490 | 2 | $feed = $variables['feed']; |
| 491 | | |
| 492 | 2 | $variables['source_icon'] = theme('feed_icon', $feed->url, t('!title
feed', array('!title' => $feed->title))); |
| 493 | 2 | $variables['source_image'] = $feed->image; |
| 494 | 2 | $variables['source_description'] =
aggregator_filter_xss($feed->description); |
| 495 | 2 | $variables['source_url'] = check_url(url($feed->link, array('absolute' =>
TRUE))); |
| 496 | | |
| 497 | 2 | if ($feed->checked) { |
| 498 | 0 | $variables['last_checked'] = t('@time ago', array('@time' =>
format_interval(REQUEST_TIME - $feed->checked))); |
| 499 | 0 | } |
| 500 | | else { |
| 501 | 2 | $variables['last_checked'] = t('never'); |
| 502 | | } |
| 503 | | |
| 504 | 2 | if (user_access('administer news feeds')) { |
| 505 | 2 | $variables['last_checked'] = l($variables['last_checked'],
'admin/content/aggregator'); |
| 506 | 2 | } |
| 507 | 2 | } |
| 508 | 12 | |