| 12 |
define("AGGREGATION_FAILED", 5); |
define("AGGREGATION_FAILED", 5); |
| 13 |
define("EMPTY_IMAGE", 6); |
define("EMPTY_IMAGE", 6); |
| 14 |
define("COULD_NOT_WRITE_TO_FILE", 7); |
define("COULD_NOT_WRITE_TO_FILE", 7); |
| 15 |
|
define("INCORRECT_IMAGE_FORMAT", 8); |
| 16 |
|
|
| 17 |
// These two variables are needed to get the etag and/or last modified |
// These two variables are needed to get the etag and/or last modified |
| 18 |
|
|
| 22 |
/** |
/** |
| 23 |
* Implementation of hook_help |
* Implementation of hook_help |
| 24 |
*/ |
*/ |
| 25 |
function aggregation_help($section) |
function aggregation_help($path, $arg) |
| 26 |
{ |
{ |
| 27 |
switch ($section) |
switch ($path) |
| 28 |
{ |
{ |
| 29 |
case 'admin/help#aggregation': |
case 'admin/help#aggregation': |
| 30 |
$output = '<p>'. t('The aggregation module is a module that is responsible for aggregating any XML feed, custom feeds need a feed_handler. Check the accompanying readme file.') .'</p>'; |
$output = '<p>'. t('The aggregation module is a module that is responsible for aggregating any XML feed, custom feeds need a feed_handler. Check the accompanying readme file.') .'</p>'; |
| 58 |
* Implementation of hook_menu(). |
* Implementation of hook_menu(). |
| 59 |
* |
* |
| 60 |
*/ |
*/ |
| 61 |
function aggregation_menu($may_cache) |
function aggregation_menu() |
| 62 |
{ |
{ |
| 63 |
$items = array(); |
$items = array(); |
| 64 |
|
|
| 65 |
if (!$may_cache) |
$items['admin/settings/aggregation'] = array( |
| 66 |
{ |
'title' => 'Aggregation', |
| 67 |
$items[] = array( |
'description' => 'These options control the general behavior of the aggregation module.', |
| 68 |
'path' => 'admin/settings/aggregation', |
'page callback' => 'drupal_get_form', |
| 69 |
'title' => t('Aggregation'), |
'page arguments' => array('aggregation_admin_settings'), |
| 70 |
'description' => t('These options control the general behavior of the aggregation module.'), |
'access callback' => 'user_access', |
| 71 |
'callback' => 'drupal_get_form', |
'access arguments' => array('administer site configuration'), |
| 72 |
'callback arguments' => array('aggregation_admin_settings'), |
'type' => MENU_NORMAL_ITEM); |
|
'access' => user_access('administer site configuration'), |
|
|
'type' => MENU_NORMAL_ITEM); |
|
|
} |
|
| 73 |
|
|
| 74 |
return $items; |
return $items; |
| 75 |
} |
} |
| 184 |
set_time_limit(20 * 60); |
set_time_limit(20 * 60); |
| 185 |
|
|
| 186 |
$feeds = db_query("SELECT n.nid FROM {aggregation_feed} af, {node} n ". |
$feeds = db_query("SELECT n.nid FROM {aggregation_feed} af, {node} n ". |
| 187 |
"WHERE af.nid = n.nid AND (UNIX_TIMESTAMP() - af.last_refreshed) >= af.refresh_interval * 60 ORDER BY af.last_refreshed"); |
"WHERE af.nid = n.nid AND (%d - af.last_refreshed) >= af.refresh_interval * 60 ORDER BY af.last_refreshed", time()); |
| 188 |
|
|
| 189 |
$feed_counter = 0; |
$feed_counter = 0; |
| 190 |
|
|
| 211 |
throw new Exception('Something wrong occured during the aggregation process!', AGGREGATION_FAILED); |
throw new Exception('Something wrong occured during the aggregation process!', AGGREGATION_FAILED); |
| 212 |
|
|
| 213 |
if (variable_get('aggregation_enable_logging', TRUE)) |
if (variable_get('aggregation_enable_logging', TRUE)) |
| 214 |
watchdog('aggregation', 'aggregation has finished aggregating items from '.$feed->title); |
watchdog('aggregation', 'aggregation has finished aggregating items from '.check_plain($feed->title)); |
| 215 |
|
|
| 216 |
// using this instead of node_save for performance reasons |
// using this instead of node_save for performance reasons |
| 217 |
db_query("UPDATE {aggregation_feed} SET etag = '%s', ". |
db_query("UPDATE {aggregation_feed} SET etag = '%s', ". |
| 230 |
} |
} |
| 231 |
} |
} |
| 232 |
catch (Exception $e) { |
catch (Exception $e) { |
| 233 |
watchdog('aggregation', $e->getMessage(), WATCHDOG_ERROR, l(t('view'), "node/$feed->nid")); |
watchdog('aggregation', check_plain($e->getMessage()), NULL, WATCHDOG_ERROR, l(t('view'), "node/$feed->nid")); |
| 234 |
} |
} |
| 235 |
} |
} |
| 236 |
|
|
| 244 |
* Implementation of hook_access(). |
* Implementation of hook_access(). |
| 245 |
*/ |
*/ |
| 246 |
|
|
| 247 |
function aggregation_feed_access($op, $node) |
function aggregation_feed_access($op, $node, $account) |
| 248 |
{ |
{ |
| 249 |
return user_access('manage aggregation feeds'); |
return user_access('manage aggregation feeds'); |
| 250 |
} |
} |
| 481 |
|
|
| 482 |
$fakeform = array(); |
$fakeform = array(); |
| 483 |
$fakeform['#node'] = new stdClass(); |
$fakeform['#node'] = new stdClass(); |
| 484 |
|
$fakeform_state = array(); |
| 485 |
|
|
| 486 |
if ($node->item_categories) |
if ($node->item_categories) { |
| 487 |
$fakeform['#node']->taxonomy = $node->item_categories; |
$fakeform['#node']->taxonomy = $node->item_categories; |
| 488 |
|
$fakeform_state['values']['taxonomy'] = $node->item_categories; |
| 489 |
|
} |
| 490 |
|
|
| 491 |
// This part will trick taxonomy into believing it's dealing with an aggregation_item |
// This part will trick taxonomy into believing it's dealing with an aggregation_item |
| 492 |
$fakeform['type']['#value'] = 'aggregation_item'; |
$fakeform['type']['#value'] = 'aggregation_item'; |
| 493 |
$fakeform['#node']->type = 'aggregation_item'; |
$fakeform['#node']->type = 'aggregation_item'; |
| 494 |
|
|
| 495 |
taxonomy_form_alter('aggregation_item_node_form', $fakeform); |
taxonomy_form_alter(&$fakeform, $fakeform_state, 'aggregation_item_node_form'); |
| 496 |
|
|
| 497 |
$form['item_taxonomies']['item_categories'] = $fakeform['taxonomy']; |
$form['item_taxonomies']['item_categories'] = $fakeform['taxonomy']; |
| 498 |
|
|
| 499 |
|
//$form['#submit'] = array('aggregation_feed_submit_handler'); |
| 500 |
|
|
| 501 |
return $form; |
return $form; |
| 502 |
} |
} |
| 521 |
|
|
| 522 |
/** |
/** |
| 523 |
* Implementation of hook_submit(). |
* Implementation of hook_submit(). |
| 524 |
|
* |
| 525 |
|
* In drupal 6.x, hook_submit() has been removed. We call this function |
| 526 |
|
* through the 'presave' op in _nodeapi function. |
| 527 |
*/ |
*/ |
|
|
|
| 528 |
function aggregation_feed_submit(&$node) |
function aggregation_feed_submit(&$node) |
| 529 |
{ |
{ |
| 530 |
$node->title = $node->title; |
$node->title = $node->title; |
| 597 |
|
|
| 598 |
function aggregation_feed_insert($node) |
function aggregation_feed_insert($node) |
| 599 |
{ |
{ |
| 600 |
db_query("INSERT INTO {aggregation_feed} VALUES ". |
db_query("INSERT INTO {aggregation_feed} (nid, original_author, url, username, password, refresh_interval, title_as_guid_interval, promote_to_frontpage, time_to_live, item_categories, aggregation_feed_options, etag, last_modified, last_refreshed) VALUES ". |
| 601 |
"(%d, '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', %d, %d)", |
"(%d, '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', %d, %d)", |
| 602 |
$node->nid, $node->original_author, $node->url, $node->username, $node->password, $node->refresh_interval, |
$node->nid, $node->original_author, $node->url, $node->username, $node->password, $node->refresh_interval, |
| 603 |
$node->title_as_guid_interval, $node->promote_to_frontpage, $node->time_to_live, $node->item_categories, |
$node->title_as_guid_interval, $node->promote_to_frontpage, $node->time_to_live, $node->item_categories, |
| 610 |
|
|
| 611 |
function aggregation_feed_update($node) |
function aggregation_feed_update($node) |
| 612 |
{ |
{ |
| 613 |
db_query("UPDATE {aggregation_feed} SET original_author = '%s', url = '%s', ". |
$params = array($node->original_author, $node->url, $node->username); |
| 614 |
"username = '%s', ".(trim($node->password) != '' ? "password = '{$node->password}'," : '')." refresh_interval = %d, title_as_guid_interval = %d, ". |
|
| 615 |
"promote_to_frontpage = %d, item_categories = '%s', time_to_live = %d, aggregation_feed_options = '%s', ". |
if (trim($node->password) != '') |
| 616 |
"etag = '%s', last_modified = %d, last_refreshed = %d WHERE nid = %d", |
$params[] = $node->password; |
| 617 |
$node->original_author, $node->url, $node->username, $node->refresh_interval, |
|
| 618 |
$node->title_as_guid_interval, $node->promote_to_frontpage, $node->item_categories, $node->time_to_live, |
$params += array(count($params) => $node->refresh_interval, |
| 619 |
$node->aggregation_feed_options, ($node->etag && $node->etag != '') ? $node->etag : '', |
$node->title_as_guid_interval, $node->promote_to_frontpage, $node->item_categories, $node->time_to_live, $node->aggregation_feed_options, ($node->etag && $node->etag != '') ? $node->etag : '', |
| 620 |
($node->last_modified && $node->last_modified != 0) ? $node->last_modified : 0, |
($node->last_modified && $node->last_modified != 0) ? $node->last_modified : 0, |
| 621 |
0, $node->nid); |
0, $node->nid); |
| 622 |
|
|
| 623 |
|
db_query("UPDATE {aggregation_feed} SET original_author = '%s', url = '%s', ". |
| 624 |
|
"username = '%s', ".(trim($node->password) != '' ? "password = '%s'," : '')." refresh_interval = %d, title_as_guid_interval = %d, ". |
| 625 |
|
"promote_to_frontpage = %d, item_categories = '%s', time_to_live = %d, aggregation_feed_options = '%s', ". |
| 626 |
|
"etag = '%s', last_modified = %d, last_refreshed = %d WHERE nid = %d", $params); |
| 627 |
} |
} |
| 628 |
|
|
| 629 |
/** |
/** |
| 646 |
* Implementation of hook_access(). |
* Implementation of hook_access(). |
| 647 |
*/ |
*/ |
| 648 |
|
|
| 649 |
function aggregation_item_access($op, $node) |
function aggregation_item_access($op, $node, $account) |
| 650 |
{ |
{ |
| 651 |
global $user; |
$allowed = NULL; |
| 652 |
|
|
| 653 |
if ($op == 'create') return user_access('manage aggregation items'); |
if ($op == 'create') return user_access('manage aggregation items'); |
| 654 |
|
|
| 655 |
if ($op == 'update' || $op == 'delete') |
if ($op == 'update' || $op == 'delete') |
| 656 |
{ |
{ |
| 657 |
if (user_access('manage feed items')) return TRUE; |
if (user_access('manage feed items')) |
| 658 |
return (user_access('manage own feed items') && ($user->uid == $node->uid)); |
$allowed = TRUE; |
| 659 |
|
else if (user_access('manage own feed items') && ($account->uid == $node->uid)) |
| 660 |
|
$allowed = TRUE; |
| 661 |
} |
} |
| 662 |
if ($op == 'view') return user_access('view aggregation items'); |
else if ($op == 'view' && user_access('view aggregation items')) |
| 663 |
|
$allowed = TRUE; |
| 664 |
|
|
| 665 |
|
return $allowed; |
| 666 |
} |
} |
| 667 |
|
|
| 668 |
/** |
/** |
| 684 |
'#type' => 'textfield', |
'#type' => 'textfield', |
| 685 |
'#default_value' => $node->title, |
'#default_value' => $node->title, |
| 686 |
'#required' => TRUE, |
'#required' => TRUE, |
| 687 |
'#title' => t(node_get_types('type', 'aggregation_item')->title_label), |
'#title' => t(check_plain(node_get_types('type', 'aggregation_item')->title_label)), |
| 688 |
'#description' => t('The title of your feed item.') |
'#description' => t('The title of your feed item.') |
| 689 |
); |
); |
| 690 |
|
|
| 780 |
$feeds = db_query('SELECT n.nid, n.title FROM {node} n, {aggregation_feed} af '. |
$feeds = db_query('SELECT n.nid, n.title FROM {node} n, {aggregation_feed} af '. |
| 781 |
'WHERE n.nid = af.nid'); |
'WHERE n.nid = af.nid'); |
| 782 |
|
|
|
if (db_num_rows($feeds) != 0) |
|
|
{ |
|
| 783 |
$feed_array = array(); |
$feed_array = array(); |
|
|
|
|
$feed_array[0] = '<none>'; |
|
|
|
|
| 784 |
while ($feed = db_fetch_object($feeds)) |
while ($feed = db_fetch_object($feeds)) |
| 785 |
$feed_array[$feed->nid] = $feed->title; |
$feed_array[$feed->nid] = $feed->title; |
| 786 |
|
|
| 787 |
|
if (count($feed_array)) |
| 788 |
|
{ |
| 789 |
|
$feed_array = array_merge (array(0 => '<none>'), $feed_array); |
| 790 |
|
|
| 791 |
$form['fid'] = array ( |
$form['fid'] = array ( |
| 792 |
'#type' => 'select', |
'#type' => 'select', |
| 793 |
'#default_value' => $node->fid, |
'#default_value' => $node->fid, |
| 796 |
'#description' => t('Provide the source feed if valid for this item.'), |
'#description' => t('Provide the source feed if valid for this item.'), |
| 797 |
'#options' => $feed_array |
'#options' => $feed_array |
| 798 |
); |
); |
| 799 |
} |
} |
| 800 |
|
|
| 801 |
|
//$form['#submit'] = array('aggregation_item_submit_handler'); |
| 802 |
|
|
| 803 |
return $form; |
return $form; |
| 804 |
} |
} |
| 805 |
|
|
| 806 |
/** |
/** |
| 822 |
|
|
| 823 |
/** |
/** |
| 824 |
* Implementation of hook_submit(). |
* Implementation of hook_submit(). |
| 825 |
|
* |
| 826 |
|
* In drupal 6.x, hook_submit() has been removed. We call this function |
| 827 |
|
* through the 'presave' op in _nodeapi function. |
| 828 |
*/ |
*/ |
|
|
|
| 829 |
function aggregation_item_submit(&$node) |
function aggregation_item_submit(&$node) |
| 830 |
{ |
{ |
| 831 |
$node->title = $node->title; |
$node->title = $node->title; |
| 845 |
else |
else |
| 846 |
$node->story_guid = ''; |
$node->story_guid = ''; |
| 847 |
|
|
| 848 |
$node->aggregation_item_options = serialize($node->aggregation_item_options); |
$node->aggregation_item_options = serialize($node->aggregation_item_options); |
| 849 |
} |
} |
| 850 |
|
|
| 851 |
/** |
/** |
| 883 |
|
|
| 884 |
function aggregation_item_update($node) |
function aggregation_item_update($node) |
| 885 |
{ |
{ |
| 886 |
|
$params = array($node->url, $node->original_author); |
| 887 |
|
|
| 888 |
|
if (!($node->story_guid === '')) |
| 889 |
|
$params[] = $node->story_guid; |
| 890 |
|
|
| 891 |
|
$params += array(count($params) => $node->fid, $node->image_id, $node->image_guid ? $node->image_guid : 0, $node->aggregation_item_options); |
| 892 |
|
|
| 893 |
|
if (!(trim($node->original_comments) == '')) |
| 894 |
|
$params[] = trim($node->original_comments); |
| 895 |
|
|
| 896 |
|
$params[] = $node->nid; |
| 897 |
|
|
| 898 |
db_query("UPDATE {aggregation_item} SET url = '%s', original_author = '%s', ". |
db_query("UPDATE {aggregation_item} SET url = '%s', original_author = '%s', ". |
| 899 |
($node->story_guid === '' ? '' : "story_guid = '{$node->story_guid}',")." fid = %d, image_id = %d, image_guid = '%s', aggregation_item_options = '%s' ".(trim($node->original_comments) == '' ? '' : ", original_comments = '".trim($node->original_comments)."'")." ". |
($node->story_guid === '' ? '' : "story_guid = '%s',")." fid = %d, image_id = %d, image_guid = '%s', aggregation_item_options = '%s' ".(trim($node->original_comments) == '' ? '' : ", original_comments = '%s'")." ". |
| 900 |
"WHERE nid = %d", $node->url, $node->original_author, $node->fid, $node->image_id, $node->image_guid ? $node->image_guid : 0, $node->aggregation_item_options, $node->nid); |
"WHERE nid = %d", $params); |
| 901 |
} |
} |
| 902 |
|
|
| 903 |
/** |
/** |
| 1003 |
|
|
| 1004 |
function theme_aggregation_image_render($image) |
function theme_aggregation_image_render($image) |
| 1005 |
{ |
{ |
| 1006 |
return '<div class="aggregation_item_image"><img src="'.base_path().'/'. |
return '<div class="aggregation_item_image"><img src="'.base_path().file_directory_path().'/'. |
| 1007 |
$image->images[variable_get('aggregation_image_to_display', 'preview')]. |
$image->images[variable_get('aggregation_image_to_display', 'preview')]. |
| 1008 |
'" />'.'</div>'; |
'" />'.'</div>'; |
| 1009 |
} |
} |
| 1202 |
|
|
| 1203 |
if ($data === FALSE) |
if ($data === FALSE) |
| 1204 |
{ |
{ |
| 1205 |
watchdog('aggregation', t("Feed \"%s\" was not modified since last refresh", array('%s' => $feed->title))); |
watchdog('aggregation', 'Feed "@feed-title" was not modified since last refresh', array('@feed-title' => $feed->title)); |
| 1206 |
return NULL; |
return NULL; |
| 1207 |
} |
} |
| 1208 |
|
|
| 1271 |
$guid = sprintf('%u', crc32($guid)); |
$guid = sprintf('%u', crc32($guid)); |
| 1272 |
if (!$interval_check) |
if (!$interval_check) |
| 1273 |
{ |
{ |
| 1274 |
$nid = db_query("SELECT nid FROM {aggregation_item} WHERE ". |
$result = db_query("SELECT nid FROM {aggregation_item} WHERE ". |
| 1275 |
"story_guid = '%s' AND fid = %d", $guid, $feed->nid); |
"story_guid = '%s' AND fid = %d", $guid, $feed->nid); |
| 1276 |
|
if ($r = db_fetch_object($result)) |
| 1277 |
if (db_num_rows($nid) > 0) |
$nid = $r->nid; |
|
$nid = db_fetch_object($nid)->nid; |
|
| 1278 |
else |
else |
| 1279 |
$nid = 0; |
$nid = 0; |
| 1280 |
|
|
| 1281 |
} |
} |
| 1282 |
else // since no real guid is available (neither unique guid nor url), we resort to checking the title or body |
else // since no real guid is available (neither unique guid nor url), we resort to checking the title or body |
| 1283 |
{ |
{ |
| 1284 |
$nid = db_query("SELECT n.nid AS nid FROM {node} n, {aggregation_item} ai ". |
$result = db_query("SELECT n.nid AS nid FROM {node} n, {aggregation_item} ai ". |
| 1285 |
"WHERE ai.nid = n.nid AND ai.story_guid = %s AND UNIX_TIMESTAMP() - n.created ". |
"WHERE ai.nid = n.nid AND ai.story_guid = %s AND %d - n.created ". |
| 1286 |
($feed->title_as_guid_interval == 0 ? ">=" : "<=")." %d", |
($feed->title_as_guid_interval == 0 ? ">=" : "<=")." %d", |
| 1287 |
$guid, $feed->title_as_guid_interval * 60 * 60); |
$guid, time(), $feed->title_as_guid_interval * 60 * 60); |
| 1288 |
|
|
| 1289 |
if (db_num_rows($nid) > 0) |
if ($r = db_fetch_object($result)) |
| 1290 |
$nid = db_fetch_object($nid)->nid; |
$nid = $r->nid; |
| 1291 |
else |
else |
| 1292 |
$nid = 0; |
$nid = 0; |
| 1293 |
} |
} |
| 1294 |
|
|
| 1295 |
if ($nid > 0) |
if ($nid > 0) |
| 1296 |
{ |
{ |
| 1297 |
$item_object = node_load(array('nid' => $nid)); |
$item_object = node_load(array('nid' => $nid)); |
| 1313 |
$item_object->aggregation_item_options['link_to_original_url'] = $feed->aggregation_feed_options['link_items_to_original_urls'] ? 1 : 0; |
$item_object->aggregation_item_options['link_to_original_url'] = $feed->aggregation_feed_options['link_items_to_original_urls'] ? 1 : 0; |
| 1314 |
$item_object->aggregation_item_options['link_to_original_comment'] = $feed->aggregation_feed_options['link_items_to_original_comments'] ? 1 : 0; |
$item_object->aggregation_item_options['link_to_original_comment'] = $feed->aggregation_feed_options['link_items_to_original_comments'] ? 1 : 0; |
| 1315 |
unset($item_object->nid); |
unset($item_object->nid); |
| 1316 |
|
unset($item_object->vid); |
| 1317 |
|
|
| 1318 |
$item_object->taxonomy = $item_object->item_categories; |
$item_object->taxonomy = $item_object->item_categories; |
| 1319 |
} |
} |
| 1367 |
$image_result_array = _aggregation_create_image($image, $title, $feed, $item_object); |
$image_result_array = _aggregation_create_image($image, $title, $feed, $item_object); |
| 1368 |
if ($image_result_array === FALSE) |
if ($image_result_array === FALSE) |
| 1369 |
{ |
{ |
| 1370 |
watchdog('aggregation',"Image with URL \"".$image_array['url']."\" from feed \"{$feed->title}\"". |
watchdog('aggregation', 'Image with URL "@image_url" from feed "@feed_title" was not retrieved.', array('@image_url' => $image_array['url'], '@feed_title' => $feed->title)); |
| 1371 |
" was not retrieved."); |
|
| 1372 |
$image_nid = 0; |
$image_nid = 0; |
| 1373 |
$image_guid = 0; |
$image_guid = 0; |
| 1374 |
} else |
} else |
| 1400 |
foreach ($other AS $key => $val) |
foreach ($other AS $key => $val) |
| 1401 |
$item_object->$key = $val; |
$item_object->$key = $val; |
| 1402 |
|
|
|
aggregation_item_submit($item_object); |
|
|
|
|
| 1403 |
// this will undo the corruption that happened in the submit call |
// this will undo the corruption that happened in the submit call |
| 1404 |
$item_object->story_guid = (!is_null($guid) && !empty($guid)) ? $guid : ''; |
// set this to make the submit call to set story_guid to this value |
| 1405 |
|
$item_object->feed_guid = (!is_null($guid) && !empty($guid)) ? $guid : ''; |
| 1406 |
node_save($item_object); |
|
| 1407 |
|
node_save($item_object); |
| 1408 |
if (variable_get('aggregation_enable_logging', TRUE)) |
if (variable_get('aggregation_enable_logging', TRUE)) |
| 1409 |
if (!$prexisting) watchdog('aggregation', "Added item \"$item_object->title\" from feed \"$feed->title\"", WATCHDOG_NOTICE, l(t('view'), "node/$item_object->nid")); |
if (!$prexisting) watchdog('aggregation', 'Added item "@item-title" from feed "@feed-title"', array('@item-title' => $item_object->title, '@feed-title' => $feed->title), WATCHDOG_NOTICE, l(t('view'), "node/$item_object->nid")); |
| 1410 |
else watchdog('aggregation', "Updated item \"$item_object->title\" from feed \"$feed->title\"", WATCHDOG_NOTICE, l(t('view'), "node/$item_object->nid")); |
else watchdog('aggregation', 'Updated item "@item-title" from feed "@feed-title"', array('@item-title' => $item_object->title, '@feed-title' => $feed->title), WATCHDOG_NOTICE, l(t('view'), "node/$item_object->nid")); |
| 1411 |
if (variable_get('aggregation_feed_refresh_cooldown', 0) > 0) |
if (variable_get('aggregation_feed_refresh_cooldown', 0) > 0) |
| 1412 |
sleep(variable_get('aggregation_feed_refresh_cooldown', 0)); |
sleep(variable_get('aggregation_feed_refresh_cooldown', 0)); |
| 1413 |
} |
} |
| 1431 |
|
|
| 1432 |
$image_exists = |
$image_exists = |
| 1433 |
db_query("SELECT ai.image_id FROM {aggregation_item} ai WHERE ai.image_guid = %s", $numeric_guid); |
db_query("SELECT ai.image_id FROM {aggregation_item} ai WHERE ai.image_guid = %s", $numeric_guid); |
| 1434 |
if (db_num_rows($image_exists) > 0) return array(db_fetch_object($image_exists)->image_id, $numeric_guid); |
|
| 1435 |
|
if ($r = db_fetch_object($image_exists)) |
| 1436 |
|
return array($r->image_id, $numeric_guid); |
| 1437 |
|
|
| 1438 |
|
$newfile = substr($image_array['url'], strrpos($image_array['url'], '/') + 1); |
| 1439 |
|
|
| 1440 |
|
$extension = explode('.', $newfile); |
| 1441 |
|
$extension = strtolower($extension[count($extension) - 1]); |
| 1442 |
|
|
| 1443 |
$filename = substr($image_array['url'], strrpos($image_array['url'], '/') + 1); |
$filename = $numeric_guid.".".$extension; |
| 1444 |
|
|
| 1445 |
$newfile = _image_filename($filename, NULL, TRUE); |
$newfile = _image_filename($filename, NULL, TRUE); |
| 1446 |
|
|
| 1447 |
try { |
try { |
| 1448 |
|
if (!($extension == 'jpg' || $extension == 'jpeg' || $extension == 'gif' || $extension == 'png')) |
| 1449 |
|
throw new Exception('Invalid image extension', INCORRECT_IMAGE_FORMAT); |
| 1450 |
|
|
| 1451 |
$data = aggregation_get_URL($image_array['url'], $image_array['username'] ? $image_array['username'] : NULL, $image_array['password'] ? $image_array['password'] : NULL, $feed); |
$data = aggregation_get_URL($image_array['url'], $image_array['username'] ? $image_array['username'] : NULL, $image_array['password'] ? $image_array['password'] : NULL, $feed); |
| 1452 |
|
|
| 1453 |
if ($data == '') throw new Exception('Image appears to be empty?!', EMPTY_IMAGE); |
if ($data == '') throw new Exception('Image appears to be empty?!', EMPTY_IMAGE); |
| 1454 |
|
|
| 1455 |
if (file_put_contents($newfile, $data) == 0) |
if (file_put_contents(file_directory_path().'/'.$newfile, $data) == 0) |
| 1456 |
throw new Exception('Could not write to file! Maybe permissions?', COULD_NOT_WRITE_TO_FILE); |
throw new Exception('Could not write to file! Maybe permissions?', COULD_NOT_WRITE_TO_FILE); |
| 1457 |
} |
} |
| 1458 |
catch (Exception $e) { |
catch (Exception $e) { |
| 1459 |
watchdog('aggregation', $e->getMessage(), WATCHDOG_ERROR); |
watchdog('aggregation', check_plain($e->getMessage()), NULL, WATCHDOG_ERROR); |
| 1460 |
return 0; |
return 0; |
| 1461 |
} |
} |
| 1462 |
|
|
| 1489 |
function _aggregation_add_vocab($name) |
function _aggregation_add_vocab($name) |
| 1490 |
{ |
{ |
| 1491 |
$vid = db_query("SELECT vid FROM {vocabulary} WHERE name = '%s'", $name); |
$vid = db_query("SELECT vid FROM {vocabulary} WHERE name = '%s'", $name); |
| 1492 |
if (db_num_rows($vid) != 0) |
if ($r = db_fetch_object($vid)) |
| 1493 |
return db_fetch_object($vid)->vid; |
return $r->vid; |
| 1494 |
|
|
| 1495 |
$vocab = array(); |
$vocab = array(); |
| 1496 |
|
|
| 1518 |
function _aggregation_add_term($vid, $name) |
function _aggregation_add_term($vid, $name) |
| 1519 |
{ |
{ |
| 1520 |
$tid = db_query("SELECT tid FROM {term_data} WHERE vid = %d AND name = '%s'", $vid, $name); |
$tid = db_query("SELECT tid FROM {term_data} WHERE vid = %d AND name = '%s'", $vid, $name); |
| 1521 |
if (db_num_rows($tid) != 0) |
if ($r = db_fetch_object($tid)) |
| 1522 |
return db_fetch_object($tid)->tid; |
return $r->tid; |
| 1523 |
|
|
| 1524 |
$term = array(); |
$term = array(); |
| 1525 |
|
|
| 1531 |
taxonomy_save_term($term); |
taxonomy_save_term($term); |
| 1532 |
|
|
| 1533 |
return $term['tid']; |
return $term['tid']; |
| 1534 |
|
} |
| 1535 |
|
|
| 1536 |
|
/** |
| 1537 |
|
* Implementation of hook_theme() |
| 1538 |
|
*/ |
| 1539 |
|
function aggregation_theme() { |
| 1540 |
|
return array( |
| 1541 |
|
'aggregation_image_render' => array( |
| 1542 |
|
'arguments' => array('image'), |
| 1543 |
|
), |
| 1544 |
|
'aggregation_body_render' => array( |
| 1545 |
|
'arguments' => array('body'), |
| 1546 |
|
), |
| 1547 |
|
'aggregation_item_render' => array( |
| 1548 |
|
'arguments' => array('image_render', 'body_render'), |
| 1549 |
|
), |
| 1550 |
|
); |
| 1551 |
|
} |
| 1552 |
|
|
| 1553 |
|
function aggregation_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) |
| 1554 |
|
{ |
| 1555 |
|
if ($op == 'presave') |
| 1556 |
|
{ |
| 1557 |
|
if ($node->type == 'aggregation_item') |
| 1558 |
|
aggregation_item_submit($node); |
| 1559 |
|
else if ($node->type == 'aggregation_feed') |
| 1560 |
|
aggregation_feed_submit($node); |
| 1561 |
|
} |
| 1562 |
} |
} |