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