| 1 |
<?php |
<?php |
| 2 |
|
|
| 3 |
/* $Id: news_page.module,v 1.12.2.2 2007/01/14 03:22:34 MegaGrunt Exp $ */ |
/* $Id: news_page.module,v 1.14 2007/07/24 00:54:07 MegaGrunt Exp $ */ |
| 4 |
|
|
| 5 |
|
|
| 6 |
// Implementation of hook_help(). |
// Implementation of hook_help(). |
| 19 |
// Implementation of hook_node_info(). |
// Implementation of hook_node_info(). |
| 20 |
function news_page_node_info() { |
function news_page_node_info() { |
| 21 |
return array('news_page' => array( |
return array('news_page' => array( |
| 22 |
'name' => t('News page'), |
'name' => t('News Page'), |
| 23 |
'module' => 'news_page'), |
'module' => 'news_page', |
| 24 |
'description' => 'Enables creation of pages displaying filtered syndicated news items from aggregator categories.' |
'description' => 'Enables creation of pages displaying filtered syndicated news items from aggregator categories.', |
| 25 |
|
) |
| 26 |
); |
); |
| 27 |
} |
} |
| 28 |
|
|
| 57 |
return array('access news page', 'access news page feed', 'create news page', 'edit own news page'); |
return array('access news page', 'access news page feed', 'create news page', 'edit own news page'); |
| 58 |
} |
} |
| 59 |
|
|
|
|
|
|
// Implementation of hook_link(). |
|
|
function news_page_link($type, $node = 0, $main) { |
|
|
$links = array(); |
|
|
|
|
|
if ($type == 'node' && $node->type == 'news_page') { |
|
|
if (news_page_access('update', $node) && !user_access('administer nodes')) { |
|
|
$links['news_page_edit_page_node'] = array ( |
|
|
'title' => t('edit this news page node'), |
|
|
'href' => 'node/'. $node->nid . '/edit', |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
return $links; |
|
|
} |
|
|
|
|
|
|
|
| 60 |
// Implementation of hook_menu(). |
// Implementation of hook_menu(). |
| 61 |
function news_page_menu($may_cache) { |
function news_page_menu($may_cache) { |
| 62 |
$items = array(); |
$items = array(); |
| 63 |
|
|
| 64 |
if ($may_cache) { |
if ($may_cache) { |
| 65 |
$items[] = array('path' => 'node/add/news_page', |
$items[] = array( |
| 66 |
'title' => t('news page'), |
'path' => 'admin/content/news_page', |
| 67 |
'access' => user_access('create news page')); |
'title' => t('News Page'), |
| 68 |
} |
'description' => t('News Page settings'), |
| 69 |
|
'callback' => 'drupal_get_form', |
| 70 |
if ( is_numeric( arg(2) ) ) { |
'callback arguments' => 'news_page_admin_settings', |
| 71 |
|
'access' => user_access('administer site configuration'), |
| 72 |
|
'type' => MENU_NORMAL_ITEM, |
| 73 |
|
); |
| 74 |
|
|
| 75 |
|
} |
| 76 |
|
else { |
| 77 |
|
|
| 78 |
$account = NULL; |
if (is_numeric(arg(2))) { |
| 79 |
|
|
| 80 |
// Check if an external source wants to read this feed. The url must containe authentication information. |
$account = NULL; |
|
if ( arg(3) && arg(4) ) { |
|
| 81 |
|
|
| 82 |
// Authenticate user |
// Check if an external source wants to read this feed. The url must containe authentication information. |
| 83 |
$account = user_load(array('name' => arg(3), 'pass' => arg(4), 'status' => 1)); |
if (arg(3) && arg(4)) { |
|
if ( $account === FALSE ) { |
|
|
$account = NULL; |
|
|
} |
|
|
} |
|
| 84 |
|
|
| 85 |
$items[] = array('path' => 'news_page/feed', |
// Authenticate user |
| 86 |
'title' => t('News page feed'), |
$account = user_load(array('name' => arg(3), 'pass' => arg(4), 'status' => 1)); |
| 87 |
'callback' => '_news_page_feed', |
if ($account === FALSE) { |
| 88 |
'callback arguments' => array('nid' => arg(2)), |
$account = NULL; |
| 89 |
'access' => user_access('access news page feed', $account), |
} |
| 90 |
'type' => MENU_CALLBACK); |
} |
| 91 |
} |
|
| 92 |
|
$items[] = array('path' => 'news_page/feed', |
| 93 |
$items[] = array( |
'title' => t('News page feed'), |
| 94 |
'path' => 'admin/content/news_page', |
'callback' => '_news_page_feed', |
| 95 |
'title' => t('News Page'), |
'callback arguments' => array('nid' => arg(2)), |
| 96 |
'description' => t('News Page settings'), |
'access' => user_access('access news page feed', $account), |
| 97 |
'callback' => 'drupal_get_form', |
'type' => MENU_CALLBACK); |
| 98 |
'callback arguments' => 'news_page_admin_settings', |
} |
| 99 |
'access' => user_access('administer site configuration'), |
} |
|
'type' => MENU_NORMAL_ITEM, |
|
|
); |
|
| 100 |
|
|
| 101 |
return $items; |
return $items; |
| 102 |
} |
} |
| 112 |
'#required' => TRUE, |
'#required' => TRUE, |
| 113 |
); |
); |
| 114 |
|
|
|
/* CRUFT ?? |
|
|
$form['validate'] = array( |
|
|
'#type' => 'hidden', |
|
|
'#value' => 'validate', |
|
|
); |
|
|
|
|
|
*/ |
|
|
|
|
| 115 |
$form['body_filter']['body'] = array( |
$form['body_filter']['body'] = array( |
| 116 |
'#type' => 'textarea', |
'#type' => 'textarea', |
| 117 |
'#title' => t('Body'), |
'#title' => t('Body'), |
| 154 |
'#maxlength' => 128, |
'#maxlength' => 128, |
| 155 |
'#description' => t('Keywords that must be included in a news item for it to be displayed - e.g. "iPhone, +battery, -problem"'), |
'#description' => t('Keywords that must be included in a news item for it to be displayed - e.g. "iPhone, +battery, -problem"'), |
| 156 |
'#attributes' => '', |
'#attributes' => '', |
|
'#required' => TRUE, |
|
| 157 |
); |
); |
| 158 |
|
|
| 159 |
$form['max_items'] = array( |
$form['max_items'] = array( |
| 264 |
// Implementation of hook_insert(). |
// Implementation of hook_insert(). |
| 265 |
function news_page_insert($node) { |
function news_page_insert($node) { |
| 266 |
$search = news_page_search_criteria($node->include, $node->cid); |
$search = news_page_search_criteria($node->include, $node->cid); |
| 267 |
db_query("INSERT INTO {news_page} (nid, include, search, cid, max_items) VALUES (%d, '%s', '%s', %d, %d)", $node->nid, $node->include, $search, $node->cid, $node->max_items); |
db_query("INSERT INTO {news_page} (nid, include, search, cid, max_items) VALUES (%d, '%s', '%s', %d, %d)", $node->nid, $node->include, serialize($search), $node->cid, $node->max_items); |
| 268 |
} |
} |
| 269 |
|
|
| 270 |
|
|
| 271 |
// Implementation of hook_update(). |
// Implementation of hook_update(). |
| 272 |
function news_page_update($node) { |
function news_page_update($node) { |
| 273 |
$search = news_page_search_criteria($node->include, $node->cid); |
$search = news_page_search_criteria($node->include, $node->cid); |
| 274 |
db_query("UPDATE {news_page} SET include = '%s', search = '%s', cid = %d, max_items = %d WHERE nid = %d", $node->include, $search, $node->cid, $node->max_items, $node->nid); |
db_query("UPDATE {news_page} SET include = '%s', search = '%s', cid = %d, max_items = %d WHERE nid = %d", $node->include, serialize($search), $node->cid, $node->max_items, $node->nid); |
| 275 |
} |
} |
| 276 |
|
|
| 277 |
// Implementation of hook_delete(). |
// Implementation of hook_delete(). |
| 283 |
// Implementation of hook_load(). |
// Implementation of hook_load(). |
| 284 |
function news_page_load($node) { |
function news_page_load($node) { |
| 285 |
$additions = db_fetch_object(db_query('SELECT include, search, cid, max_items FROM {news_page} WHERE nid = %d', $node->nid)); |
$additions = db_fetch_object(db_query('SELECT include, search, cid, max_items FROM {news_page} WHERE nid = %d', $node->nid)); |
| 286 |
|
$additions->search = unserialize($additions->search); |
| 287 |
return $additions; |
return $additions; |
| 288 |
} |
} |
| 289 |
|
|
| 292 |
|
|
| 293 |
if (isset($node->max_items) == FALSE OR $node->max_items == 0) $node->max_items = 25; |
if (isset($node->max_items) == FALSE OR $node->max_items == 0) $node->max_items = 25; |
| 294 |
|
|
| 295 |
if ($node->include && $node->cid) { |
if ($node->cid) { |
| 296 |
$search = ($node->search) ? $node->search : news_page_search_criteria($node->include, $node->cid); |
$search = ($node->search) ? $node->search : news_page_search_criteria($node->include, $node->cid); |
| 297 |
$result = db_query_range($search, 0, $node->max_items); |
$result = db_query_range($search->sql, $search->arguments, 0, $node->max_items); |
| 298 |
} |
} |
| 299 |
|
|
| 300 |
return $result; |
return $result; |
| 334 |
|
|
| 335 |
function news_page_search_criteria($keywords, $cid) { |
function news_page_search_criteria($keywords, $cid) { |
| 336 |
|
|
| 337 |
$words = explode(",", $keywords); |
$arguments = array($cid); |
|
|
|
|
foreach ($words as $word) { |
|
|
$word = trim($word); |
|
|
if (preg_match("/^-/", $word)) { |
|
|
$word = preg_replace('/^-/','', $word); |
|
|
$not_title_filter[] = "lower(i.title) NOT LIKE '%%" . $word . "%%'"; |
|
|
$not_content_filter[] = "lower(i.description) NOT LIKE '%%" . $word . "%%'"; |
|
|
$not_filter_query = implode(" AND ", $not_title_filter) . ' AND ' . implode(" AND ", $not_content_filter); |
|
|
} elseif (preg_match("/^\+/", $word)) { |
|
|
$word = preg_replace('/^\+/','', $word); |
|
|
$and_title_filter[] = "lower(i.title) LIKE '%%" . $word . "%%'"; |
|
|
$and_content_filter[] = "lower(i.description) LIKE '%%" . $word . "%%'"; |
|
|
$and_filter_query = implode(" AND ", $and_title_filter) . ' OR ' . implode(" AND ", $and_content_filter); |
|
|
} else { |
|
|
$title_filter[] = "lower(i.title) LIKE '%%" . $word . "%%'"; |
|
|
$content_filter[] = "lower(i.description) LIKE '%%" . $word . "%%'"; |
|
|
$filter_query = implode(" OR ", $title_filter) . ' OR ' . implode(" OR ", $content_filter); |
|
|
} |
|
|
} |
|
|
$news_queries = array($not_filter_query, $and_filter_query, $filter_query); |
|
|
$i = 0; |
|
|
foreach ($news_queries as $query) { |
|
|
if ($i>0 && drupal_strlen($query) > 0) { |
|
|
$news_query .= "AND " ; |
|
|
} |
|
|
if (drupal_strlen($query)) { |
|
|
$news_query .= "(". $query .")"; |
|
|
$i++; |
|
|
} |
|
|
} |
|
| 338 |
|
|
| 339 |
$filter_query = |
if (!empty($keywords)) { |
| 340 |
"SELECT i.*, f.link AS flink, f.title AS ftitle |
$words = explode(",", $keywords); |
| 341 |
FROM {aggregator_item} i |
|
| 342 |
LEFT JOIN {aggregator_feed} f |
foreach ($words as $word) { |
| 343 |
ON i.fid = f.fid |
|
| 344 |
LEFT JOIN {aggregator_category_feed} c |
$word = trim($word); |
| 345 |
ON c.fid = f.fid |
|
| 346 |
WHERE c.cid = '$cid' |
if (preg_match("/^-/", $word)) { |
| 347 |
AND ( $news_query ) |
|
| 348 |
ORDER BY timestamp DESC"; |
$word = preg_replace('/^-/','', $word); |
| 349 |
|
$not_title_filter[] = "lower(i.title) NOT LIKE '%%%s%%'"; |
| 350 |
return $filter_query; |
$arguments[] = $word; |
| 351 |
|
$not_content_filter[] = "lower(i.description) NOT LIKE '%%%s%%'"; |
| 352 |
|
$arguments[] = $word; |
| 353 |
|
$not_filter_query = implode(" AND ", $not_title_filter) . ' AND ' . implode(" AND ", $not_content_filter); |
| 354 |
|
|
| 355 |
|
} elseif (preg_match("/^\+/", $word)) { |
| 356 |
|
|
| 357 |
|
$word = preg_replace('/^\+/','', $word); |
| 358 |
|
$and_title_filter[] = "lower(i.title) LIKE '%%%s%%'"; |
| 359 |
|
$arguments[] = $word; |
| 360 |
|
$and_content_filter[] = "lower(i.description) LIKE '%%%s%%'"; |
| 361 |
|
$arguments[] = $word; |
| 362 |
|
$and_filter_query = implode(" AND ", $and_title_filter) . ' OR ' . implode(" AND ", $and_content_filter); |
| 363 |
|
|
| 364 |
|
} else { |
| 365 |
|
|
| 366 |
|
$title_filter[] = "lower(i.title) LIKE '%%%s%%'"; |
| 367 |
|
$arguments[] = $word; |
| 368 |
|
$content_filter[] = "lower(i.description) LIKE '%%%s%%'"; |
| 369 |
|
$arguments[] = $word; |
| 370 |
|
$filter_query = implode(" OR ", $title_filter) . ' OR ' . implode(" OR ", $content_filter); |
| 371 |
|
} |
| 372 |
|
} |
| 373 |
|
|
| 374 |
|
$news_queries = array($filter_query, $and_filter_query, $not_filter_query); |
| 375 |
|
$i = 0; |
| 376 |
|
|
| 377 |
|
foreach ($news_queries as $query) { |
| 378 |
|
if ($i > 0 && drupal_strlen($query) > 0) { |
| 379 |
|
$news_query .= "AND " ; |
| 380 |
|
} |
| 381 |
|
|
| 382 |
|
if (drupal_strlen($query)) { |
| 383 |
|
$news_query .= "(". $query .")"; |
| 384 |
|
$i++; |
| 385 |
|
} |
| 386 |
|
} |
| 387 |
|
} |
| 388 |
|
|
| 389 |
|
$search->sql = 'SELECT i.*, f.link AS flink, f.title AS ftitle |
| 390 |
|
FROM {aggregator_item} i |
| 391 |
|
LEFT JOIN {aggregator_feed} f ON i.fid = f.fid |
| 392 |
|
LEFT JOIN {aggregator_category_feed} c ON c.fid = f.fid |
| 393 |
|
WHERE c.cid = %d'; |
| 394 |
|
|
| 395 |
|
if (!empty($news_query)) $search->sql .= " AND ($news_query)"; |
| 396 |
|
|
| 397 |
|
$search->sql .= ' ORDER BY timestamp DESC'; |
| 398 |
|
|
| 399 |
|
$search->arguments = $arguments; |
| 400 |
|
|
| 401 |
|
return $search; |
| 402 |
} |
} |
| 403 |
|
|
| 404 |
// A custom theme function. |
// A custom theme function. |
| 413 |
$output .= '<div class="feed-item">'; |
$output .= '<div class="feed-item">'; |
| 414 |
|
|
| 415 |
if ($item->title) { |
if ($item->title) { |
| 416 |
$output .= '<h3 class="feed-item-title">' . check_plain($item->title) . '</h3>'; |
$output .= '<h3 class="feed-item-title">' . filter_xss($item->title, array()) . '</h3>'; |
| 417 |
} |
} |
| 418 |
|
|
| 419 |
$output .= '<p>'; |
$output .= '<p>'; |
| 421 |
if ($item->description) { |
if ($item->description) { |
| 422 |
$output .= '<span class="feed-item-body">' . aggregator_filter_xss($item->description) . '</span>'; |
$output .= '<span class="feed-item-body">' . aggregator_filter_xss($item->description) . '</span>'; |
| 423 |
} |
} |
| 424 |
|
/** |
| 425 |
|
* @todo convert these links to just use an l() |
| 426 |
|
*/ |
| 427 |
if ($blogit) { |
if ($blogit) { |
| 428 |
$blog_icon = '<a href="' . url('node/add/blog', "iid=$item->iid") . '"><img src="'. base_path() .'/misc/blog.png" alt="'. t('Blog this') . '" title="' . t('blog it') . '" class="blog-it"/></a>' ; |
$blog_icon = '<a href="' . url('node/add/blog', "iid=$item->iid") . '"><img src="'. '/misc/blog.png" alt="'. t('Blog this') . '" title="' . t('blog it') . '" class="blog-it"/></a>' ; |
| 429 |
} |
} |
| 430 |
|
|
| 431 |
$output .= '<br /><span class="feed-item-link"><a href="' . check_url($item->link) . '">' .t('Read more') . '</a></span> <span class="feed-item-source">[<a href="' . check_url($item->flink) . '">' . check_plain($item->ftitle) . '</a>] ' . $blog_icon . '</span>'; |
$output .= '<br /><span class="feed-item-link"><a href="' . check_url($item->link) . '">' .t('Read more') . '</a></span> <span class="feed-item-source">[<a href="' . check_url($item->flink) . '">' . check_plain($item->ftitle) . '</a>] ' . $blog_icon . '</span>'; |
| 440 |
|
|
| 441 |
// Output RSS feed |
// Output RSS feed |
| 442 |
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; |
$output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"; |
|
$output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\n"; |
|
| 443 |
$output .= "<rss version=\"". $channel["version"] . "\" xml:base=\"". $base_url ."\">\n"; |
$output .= "<rss version=\"". $channel["version"] . "\" xml:base=\"". $base_url ."\">\n"; |
| 444 |
$output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']); |
$output .= format_rss_channel($channel['title'], $channel['link'], $channel['description'], $items, $channel['language']); |
| 445 |
$output .= "</rss>\n"; |
$output .= "</rss>\n"; |