Parent Directory
|
Revision Log
|
Revision Graph
|
Patch
| revision 1.4 by mistknight, Sat Feb 24 00:28:57 2007 UTC | revision 1.4.4.1 by mistknight, Sat Apr 19 23:36:08 2008 UTC | |
|---|---|---|
| # | Line 1 | Line 1 |
| 1 | <?php | <?php |
| 2 | ||
| 3 | // $Id: aggregation.module,v 1.3 2007/02/23 07:08:09 mistknight Exp $ | // $Id: aggregation.module,v 1.4.2.25 2008/04/18 23:53:26 mistknight Exp $ |
| 4 | ||
| 5 | /** | /** |
| 6 | * A number of defs to ease naming | * A number of defs to ease naming |
| # | Line 18 define("COULD_NOT_WRITE_TO_FILE", 7); | Line 18 define("COULD_NOT_WRITE_TO_FILE", 7); |
| 18 | static $etag; | static $etag; |
| 19 | static $last_modified; | static $last_modified; |
| 20 | ||
| $GLOBALS['aggregation_item_count'] = 0; | ||
| 21 | /** | /** |
| 22 | * Implementation of hook_help | * Implementation of hook_help |
| 23 | */ | */ |
| # | Line 34 function aggregation_help($section) | Line 32 function aggregation_help($section) |
| 32 | } | } |
| 33 | } | } |
| 34 | ||
| 35 | /** | /** |
| 36 | * Implementation of hook_perm(). | * Implementation of hook_perm(). |
| 37 | */ | */ |
| 38 | function aggregation_perm() | function aggregation_perm() |
| 39 | { | { |
| 40 | return array('manage aggregation feeds', 'manage aggregation items', 'view aggregation items', | return array('manage aggregation feeds', 'manage aggregation items', 'view aggregation items', |
| 41 | 'manage own feed items'); | 'manage own feed items', 'manage feed items'); |
| 42 | } | } |
| 43 | ||
| 44 | /** | /** |
| # | Line 51 function aggregation_node_info() | Line 48 function aggregation_node_info() |
| 48 | { | { |
| 49 | return array | return array |
| 50 | ( | ( |
| 51 | 'aggregation_feed' => array('name' => t('Feed'), 'module' => 'aggregation_feed', 'description' => t('Represents the feed the site aggregates from. Items are generated from feeds during cron runs.'), 'has_title' => TRUE, 'title_label' => t('Feed name'), 'has_body' => FALSE), | 'aggregation_feed' => array('name' => t('Feed'), 'module' => 'aggregation_feed', 'description' => t('Represents the feed the site aggregates from. Items are generated from feeds during cron runs.'), 'has_title' => TRUE, 'title_label' => t('Feed name'), 'has_body' => TRUE, 'body_label' => t('Description')), |
| 52 | 'aggregation_item' => array('name' => t('Feed Item'), 'module' => 'aggregation_item', 'description' => t('Items are usually auto-generated on cron runs, but this type exists in case you would like to manually add an item.')) | 'aggregation_item' => array('name' => t('Feed Item'), 'module' => 'aggregation_item', 'description' => t('Items are usually auto-generated on cron runs, but this type exists in case you would like to manually add an item.')) |
| 53 | ); | ); |
| 54 | } | } |
| # | Line 63 function aggregation_node_info() | Line 60 function aggregation_node_info() |
| 60 | function aggregation_menu($may_cache) | function aggregation_menu($may_cache) |
| 61 | { | { |
| 62 | $items = array(); | $items = array(); |
| 63 | ||
| 64 | if (!$may_cache) | if (!$may_cache) |
| 65 | { | { |
| 66 | $items[] = array( | $items[] = array( |
| # | Line 75 function aggregation_menu($may_cache) | Line 72 function aggregation_menu($may_cache) |
| 72 | 'access' => user_access('administer site configuration'), | 'access' => user_access('administer site configuration'), |
| 73 | 'type' => MENU_NORMAL_ITEM); | 'type' => MENU_NORMAL_ITEM); |
| 74 | } | } |
| 75 | ||
| 76 | return $items; | return $items; |
| 77 | } | } |
| 78 | ||
| # | Line 87 function aggregation_admin_settings() | Line 84 function aggregation_admin_settings() |
| 84 | $form = array(); | $form = array(); |
| 85 | ||
| 86 | $vocabs = taxonomy_get_vocabularies('aggregation_feed'); | $vocabs = taxonomy_get_vocabularies('aggregation_feed'); |
| 87 | ||
| 88 | foreach ($vocabs AS $vid => $vocab_object) | foreach ($vocabs AS $vid => $vocab_object) |
| 89 | $vocabs[$vid] = $vocab_object->name; | $vocabs[$vid] = $vocab_object->name; |
| 90 | ||
| 91 | $form['aggregation_current_vid'] = array( | $form['aggregation_current_vid'] = array( |
| 92 | '#type' => 'select', | '#type' => 'select', |
| 93 | '#title' => t('Please specify the aggregation feed vid to use as meta for aggregation types'), | '#title' => t('Aggregation feed types'), |
| 94 | '#default_value' => variable_get('aggregation_current_vid', -1), | '#default_value' => variable_get('aggregation_current_vid', -1), |
| 95 | '#options' => $vocabs, | '#options' => $vocabs, |
| 96 | '#description' => t('The vocabularies determine the aggregation\'s parsing types. So change this value if you want to switch from the default vocabulary.'), | '#description' => t('This vocabulary contains the XML types -as terms- that the module can aggregate from.'), |
| 97 | '#required' => TRUE | '#required' => TRUE |
| 98 | ); | ); |
| 99 | ||
| $form['aggregation_item_time_to_live'] = array( | ||
| '#type' => 'textfield', | ||
| '#default_value' => variable_get('aggregation_item_time_to_live', 30), | ||
| '#required' => TRUE, | ||
| '#title' => t('Please specify the number of DAYS an item will live'), | ||
| '#description' => t('If aggregation_feed is set to delete old items, this variable will determine the age after which an item will be deleted') | ||
| ); | ||
| 100 | $form['aggregation_enable_logging'] = array( | $form['aggregation_enable_logging'] = array( |
| 101 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 102 | '#default_value' => variable_get('aggregation_enable_logging', 1), | '#default_value' => variable_get('aggregation_enable_logging', 1), |
| 103 | '#title' => t('Log Operations'), | '#title' => t('Log Operations'), |
| 104 | '#description' => t('After moving to production, you may wish to disable this if you feel everything is stable enough. But it\'s recommended you keep it on. Fatal errors will ALWAYS be logged.') | '#description' => t('After moving to production, you may wish to disable this if you feel everything is stable enough. But it\'s recommended you keep it on. Fatal errors will ALWAYS be logged.') |
| 105 | ); | ); |
| 106 | ||
| 107 | $form['aggregation_image_to_display'] = array( | if (module_exists('image')) |
| 108 | '#type' => 'textfield', | { |
| 109 | '#default_value' => variable_get('aggregation_image_to_display', 'preview'), | foreach (_image_get_sizes() as $key => $size) |
| 110 | '#required' => TRUE, | $image_sizes[$key] = $size['label']; |
| 111 | '#title' => t('Image to display'), | |
| 112 | '#description' => t('This is the image size that will be displayed on aggregated items\' node page.') | $form['aggregation_image_to_display'] = array( |
| 113 | ); | '#type' => 'select', |
| 114 | '#default_value' => variable_get('aggregation_image_to_display', 'preview'), | |
| 115 | '#options' => $image_sizes, | |
| 116 | '#required' => TRUE, | |
| 117 | '#title' => t('Image to display'), | |
| 118 | '#description' => t('This is the image size that will be displayed on aggregated items\' node page for feeds that aggregate images.') | |
| 119 | ); | |
| 120 | } | |
| 121 | ||
| 122 | $form['aggregation_enable_cron'] = array( | $form['aggregation_enable_cron'] = array( |
| 123 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 124 | '#default_value' => variable_get('aggregation_enable_cron', 1), | '#default_value' => variable_get('aggregation_enable_cron', 1), |
| 125 | '#title' => t('Enable Cron'), | '#title' => t('Enable Cron'), |
| 126 | '#description' => t('Remove this check if you want to stop aggregation temporarily.') | '#description' => t('Remove this check if you want to stop aggregation cron temporarily.') |
| 127 | ); | ); |
| 128 | ||
| 129 | $form['aggregation_feeds_to_refresh_per_cron'] = array( | $form['aggregation_feeds_to_refresh_per_cron'] = array( |
| 130 | '#type' => 'textfield', | '#type' => 'textfield', |
| # | Line 136 function aggregation_admin_settings() | Line 132 function aggregation_admin_settings() |
| 132 | '#required' => TRUE, | '#required' => TRUE, |
| 133 | '#title' => t('The number of feeds to refresh every cron'), | '#title' => t('The number of feeds to refresh every cron'), |
| 134 | '#description' => t('This is important if you have many feeds that may slow the site.').'<br />'. | '#description' => t('This is important if you have many feeds that may slow the site.').'<br />'. |
| 135 | t('All feeds will eventually be processed, so this option will simply slow the process down to alleviate congestion') | t('All feeds will eventually be processed, so this option will simply slow the process down to minimize effects on the site. But it will delay the time needed for all feeds to refresh.') |
| 136 | ); | ); |
| 137 | ||
| 138 | $form['aggregation_feed_refresh_cooldown'] = array( | $form['aggregation_feed_refresh_cooldown'] = array( |
| 139 | '#type' => 'textfield', | '#type' => 'textfield', |
| 140 | '#default_value' => variable_get('aggregation_feed_refresh_cooldown', 0), | '#default_value' => variable_get('aggregation_feed_refresh_cooldown', 0), |
| # | Line 155 function aggregation_admin_settings() | Line 151 function aggregation_admin_settings() |
| 151 | */ | */ |
| 152 | function aggregation_validate_settings($form) | function aggregation_validate_settings($form) |
| 153 | { | { |
| if (!is_numeric($form['aggregation_item_time_to_live'])) | ||
| form_set_error('aggregation_item_time_to_live', t('This field must be numeric.')); | ||
| if ($form['aggregation_item_time_to_live'] <= 0) | ||
| form_set_error('aggregation_item_time_to_live', t('This field must be a positive number.')); | ||
| 154 | if (!is_numeric($form['aggregation_feeds_to_refresh_per_cron'])) | if (!is_numeric($form['aggregation_feeds_to_refresh_per_cron'])) |
| 155 | form_set_error('aggregation_feeds_to_refresh_per_cron', t('This field must be numeric.')); | form_set_error('aggregation_feeds_to_refresh_per_cron', t('This field must be numeric.')); |
| 156 | else if ($form['aggregation_feeds_to_refresh_per_cron'] <= 0) | |
| if ($form['aggregation_feeds_to_refresh_per_cron'] <= 0) | ||
| 157 | form_set_error('aggregation_feeds_to_refresh_per_cron', t('This field must be a positive number.')); | form_set_error('aggregation_feeds_to_refresh_per_cron', t('This field must be a positive number.')); |
| 158 | else if (!is_numeric($form['aggregation_feed_refresh_cooldown'])) | |
| if (!is_numeric($form['aggregation_feed_refresh_cooldown'])) | ||
| 159 | form_set_error('aggregation_feed_refresh_cooldown', t('This field must be numeric.')); | form_set_error('aggregation_feed_refresh_cooldown', t('This field must be numeric.')); |
| 160 | else if ($form['aggregation_feed_refresh_cooldown'] < 0) | |
| 161 | if ($form['aggregation_feed_refresh_cooldown'] < 0) | form_set_error('aggregation_feed_refresh_cooldown', t('This field must be positive or zero.')); |
| form_set_error('aggregation_feed_refresh_cooldown', t('This field must be positive or zero.')); | ||
| 162 | } | } |
| 163 | ||
| 164 | /** | /** |
| # | Line 191 function aggregation_cron() | Line 178 function aggregation_cron() |
| 178 | 'Try visiting aggregation\'s settings to set it!'); | 'Try visiting aggregation\'s settings to set it!'); |
| 179 | return; | return; |
| 180 | } | } |
| 181 | ||
| 182 | $max_exec_time = ini_get('max_execution_time'); | $max_exec_time = ini_get('max_execution_time'); |
| 183 | $max_exec_time = (int)$max_exec_time; | $max_exec_time = (int)$max_exec_time; |
| 184 | ||
| 185 | if (!ini_get('safe_mode')) | if (!ini_get('safe_mode')) |
| 186 | set_time_limit(20 * 60); | set_time_limit(20 * 60); |
| 187 | ||
| 188 | $feeds = db_query_range("SELECT n.nid FROM {aggregation_feed} af, {node} n ". | $feeds = db_query("SELECT n.nid FROM {aggregation_feed} af, {node} n ". |
| 189 | "WHERE af.nid = n.nid AND af.enabled = 'yes' AND (UNIX_TIMESTAMP() - af.last_refreshed) >= af.refresh_interval * 60 ORDER BY af.last_refreshed", 0, variable_get('aggregation_feeds_to_refresh_per_cron', 7)); | "WHERE af.nid = n.nid AND (UNIX_TIMESTAMP() - af.last_refreshed) >= af.refresh_interval * 60 ORDER BY af.last_refreshed"); |
| while ($feed_nid = db_fetch_object($feeds)->nid) | ||
| { | ||
| db_query("UPDATE {aggregation_feed} SET last_refreshed = %d WHERE nid = %d", time(), $feed_nid); | ||
| 190 | ||
| 191 | $feed_counter = 0; | |
| 192 | ||
| 193 | while ($feed_nid = db_fetch_object($feeds)->nid) | |
| 194 | { | |
| 195 | $feed = node_load($feed_nid); | $feed = node_load($feed_nid); |
| 196 | aggregation_feed_prepare($feed); | aggregation_feed_prepare($feed); |
| 197 | ||
| 198 | if ($feed->aggregation_feed_options['enabled']) | |
| 199 | $feed_counter++; | |
| 200 | else | |
| 201 | continue; | |
| 202 | ||
| 203 | if ($feed_counter > variable_get('aggregation_feeds_to_refresh_per_cron', 7)) break; | |
| 204 | ||
| 205 | db_query("UPDATE {aggregation_feed} SET last_refreshed = %d WHERE nid = %d", time(), $feed_nid); | |
| 206 | ||
| 207 | try { | try { |
| $GLOBALS['aggregation_item_count'] = $feed->promote_to_frontpage - 1; | ||
| 208 | $success = _aggregation_parse($feed, $vid); | $success = _aggregation_parse($feed, $vid); |
| 209 | ||
| $GLOBALS['aggregation_item_count'] = 0; | ||
| 210 | if (is_null($success)) continue; | if (is_null($success)) continue; |
| 211 | ||
| 212 | if (!$success) | if (!$success) |
| 213 | throw new Exception('Something wrong occured during the aggregation process!', AGGREGATION_FAILED); | throw new Exception('Something wrong occured during the aggregation process!', AGGREGATION_FAILED); |
| 214 | ||
| 215 | if (variable_get('aggregation_enable_logging', TRUE)) | if (variable_get('aggregation_enable_logging', TRUE)) |
| 216 | watchdog('aggregation', 'aggregation has finished aggregating items from '.$feed->title); | watchdog('aggregation', 'aggregation has finished aggregating items from '.$feed->title); |
| 217 | ||
| 218 | // using this instead of node_save for performance reasons | // using this instead of node_save for performance reasons |
| 219 | db_query("UPDATE {aggregation_feed} SET etag = '%s', ". | db_query("UPDATE {aggregation_feed} SET etag = '%s', ". |
| 220 | "last_modified = %d, last_refreshed = %d WHERE nid = %d", $feed->etag, | "last_modified = %d, last_refreshed = %d WHERE nid = %d", $feed->etag, |
| 221 | $feed->last_modified, time(), $feed->nid); | $feed->last_modified, time(), $feed->nid); |
| 222 | ||
| 223 | if ($feed->delete_old_items) | if ($feed->time_to_live > 0) |
| 224 | { | { |
| 225 | $items_to_be_deleted = db_query("SELECT n.nid FROM {node} n, ". | $items_to_be_deleted = db_query("SELECT n.nid FROM {node} n, ". |
| 226 | "{aggregation_item} ai WHERE n.nid = ai.nid AND ai.fid = %d AND ". | "{aggregation_item} ai WHERE n.nid = ai.nid AND ai.fid = %d AND ". |
| 227 | "(UNIX_TIMESTAMP() - n.created) >= %d", $feed->nid, | "(UNIX_TIMESTAMP() - n.created) >= %d", $feed->nid, |
| 228 | variable_get('aggregation_item_time_to_live', 30) * 24 * 60 * 60); | $feed->time_to_live * 24 * 60 * 60); |
| 229 | ||
| 230 | while ($item = db_fetch_object($items_to_be_deleted)) | while ($item = db_fetch_object($items_to_be_deleted)) |
| 231 | node_delete($item->nid); | node_delete($item->nid); |
| 232 | } | } |
| 233 | } | } |
| 234 | catch (Exception $e) { | catch (Exception $e) { |
| $GLOBALS['aggregation_item_count'] = 0; | ||
| 235 | watchdog('aggregation', $e->getMessage(), WATCHDOG_ERROR, l(t('view'), "node/$feed->nid")); | watchdog('aggregation', $e->getMessage(), WATCHDOG_ERROR, l(t('view'), "node/$feed->nid")); |
| 236 | } | } |
| 237 | } | } |
| 238 | ||
| 239 | if (!ini_get('safe_mode') && is_numeric($max_exec_time) && $max_exec_time > 0) | if (!ini_get('safe_mode') && is_numeric($max_exec_time) && $max_exec_time > 0) |
| 240 | set_time_limit($max_exec_time); | set_time_limit($max_exec_time); |
| 241 | } | } |
| # | Line 268 function aggregation_feed_form(&$node, & | Line 259 function aggregation_feed_form(&$node, & |
| 259 | { | { |
| 260 | $form = array(); | $form = array(); |
| 261 | ||
| 262 | $display_modes = array( | |
| 263 | 0 => t('Don\'t display'), | |
| 264 | 1 => t('In full node views'), | |
| 265 | 2 => t('In teaser node views'), | |
| 266 | 3 => t('In both teaser and full node views'), | |
| 267 | ); | |
| 268 | ||
| 269 | $form['title'] = array ( | $form['title'] = array ( |
| 270 | '#type' => 'textfield', | '#type' => 'textfield', |
| 271 | '#default_value' => $node->title, | '#default_value' => $node->title, |
| # | Line 276 function aggregation_feed_form(&$node, & | Line 274 function aggregation_feed_form(&$node, & |
| 274 | '#description' => t('Enter something descriptive to identify your feed.') | '#description' => t('Enter something descriptive to identify your feed.') |
| 275 | ); | ); |
| 276 | ||
| 277 | $form['body_filter']['body'] = array ( | |
| 278 | '#type' => 'textarea', | |
| 279 | '#default_value' => $node->body, | |
| 280 | '#required' => FALSE, | |
| 281 | '#title' => t(node_get_types('type', 'aggregation_feed')->body_label), | |
| 282 | '#description' => t('Any description for your feed.') | |
| 283 | ); | |
| 284 | ||
| 285 | $form['body_filter']['format'] = filter_form($node->format); | |
| 286 | ||
| 287 | $form['original_author'] = array( | $form['original_author'] = array( |
| 288 | '#type' => 'textfield', | '#type' => 'textfield', |
| 289 | '#default_value' => $node->original_author, | '#default_value' => $node->original_author, |
| 290 | '#required' => TRUE, | '#required' => TRUE, |
| 291 | '#title' => t('Original Author'), | '#title' => t('Original Author'), |
| 292 | '#description' => t('Please specify the original author for the items of this feed.') | '#description' => t('Please specify the original author for the items of this feed. '. |
| 293 | 'This is used when none is present in the feed itself.') | |
| 294 | ); | ); |
| 295 | ||
| 296 | $form['url'] = array ( | $form['url'] = array ( |
| # | Line 289 function aggregation_feed_form(&$node, & | Line 298 function aggregation_feed_form(&$node, & |
| 298 | '#default_value' => $node->url, | '#default_value' => $node->url, |
| 299 | '#required' => TRUE, | '#required' => TRUE, |
| 300 | '#title' => t('Feed URL'), | '#title' => t('Feed URL'), |
| 301 | '#description' => t('Please provide the feed URL.') | '#description' => t('Please provide the feed URL.'), |
| 302 | '#maxlength' => 250, | |
| 303 | ); | ); |
| 304 | ||
| 305 | $form['authentication'] = array ( | $form['authentication'] = array ( |
| # | Line 307 function aggregation_feed_form(&$node, & | Line 317 function aggregation_feed_form(&$node, & |
| 317 | '#description' => t('If your site uses authentication, please specify the username here.'), | '#description' => t('If your site uses authentication, please specify the username here.'), |
| 318 | '#title' => t('Enter Username') | '#title' => t('Enter Username') |
| 319 | ); | ); |
| 320 | ||
| 321 | $description = t('If your site uses authentication, please specify the password here.'); | $description = t('If your site uses authentication, please specify the password here.'); |
| 322 | ||
| 323 | // This indicates we're in edit mode, in which case I'd like to add an additional directive | // This indicates we're in edit mode, in which case I'd like to add an additional directive |
| # | Line 322 function aggregation_feed_form(&$node, & | Line 332 function aggregation_feed_form(&$node, & |
| 332 | '#description' => $description, | '#description' => $description, |
| 333 | '#title' => 'Enter Password' | '#title' => 'Enter Password' |
| 334 | ); | ); |
| 335 | ||
| 336 | $description = t('If your site uses authentication, please retype your password here.'); | $description = t('If your site uses authentication, please retype your password here.'); |
| 337 | ||
| 338 | // This indicates we're in edit mode, in which case I'd like to add an additional directive | // This indicates we're in edit mode, in which case I'd like to add an additional directive |
| # | Line 345 function aggregation_feed_form(&$node, & | Line 355 function aggregation_feed_form(&$node, & |
| 355 | '#title' => t('Refresh Interval'), | '#title' => t('Refresh Interval'), |
| 356 | '#description' => t('Please specify the refresh interval IN MINUTES.') | '#description' => t('Please specify the refresh interval IN MINUTES.') |
| 357 | ); | ); |
| 358 | ||
| 359 | $form['title_as_guid_interval'] = array( | $form['title_as_guid_interval'] = array( |
| 360 | '#type' => 'textfield', | '#type' => 'textfield', |
| 361 | '#default_value' => $node->title_as_guid_interval ? $node->title_as_guid_interval : 0, | '#default_value' => $node->title_as_guid_interval ? $node->title_as_guid_interval : 0, |
| # | Line 359 function aggregation_feed_form(&$node, & | Line 369 function aggregation_feed_form(&$node, & |
| 369 | 'any other article still in the feed with the same title will enter the system.') | 'any other article still in the feed with the same title will enter the system.') |
| 370 | ); | ); |
| 371 | ||
| 372 | $form['enabled'] = array( | $form['aggregation_feed_options'] = array( |
| 373 | '#type' => 'fieldset', | |
| 374 | '#title' => t('Options'), | |
| 375 | '#tree' => TRUE, | |
| 376 | ); | |
| 377 | ||
| 378 | $form['aggregation_feed_options']['enabled'] = array( | |
| 379 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 380 | '#default_value' => $node->enabled, | '#default_value' => $node->aggregation_feed_options['enabled'] ? $node->aggregation_feed_options['enabled'] : 1, |
| 381 | '#title' => t('Enabled'), | '#title' => t('Enabled'), |
| 382 | '#description' => t('Use this checkbox to enable/disable refreshing this feed.') | '#description' => t('Use this checkbox to enable/disable refreshing this feed.') |
| 383 | ); | ); |
| 384 | ||
| 385 | $form['publish_new_items'] = array( | $form['aggregation_feed_options']['publish_new_items'] = array( |
| 386 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 387 | '#default_value' => $node->publish_new_items, | '#default_value' => $node->aggregation_feed_options['publish_new_items'] ? $node->aggregation_feed_options['publish_new_items'] : 1, |
| 388 | '#description' => t('Use this checkbox to publish all aggregated feed items.'), | '#description' => t('Use this checkbox to publish all aggregated feed items.'), |
| 389 | '#title' => t('Publish items') | '#title' => t('Publish items') |
| 390 | ); | ); |
| 391 | ||
| 392 | $form['aggregate_to_moderation_queue'] = array( | $form['aggregation_feed_options']['aggregate_item_categories'] = array( |
| 393 | '#type' => 'checkbox', | |
| 394 | '#default_value' => $node->aggregation_feed_options['aggregate_item_categories'] ? $node->aggregation_feed_options['aggregate_item_categories'] : 1, | |
| 395 | '#description' => t('Use this checkbox to aggregate this feed item\'s internal categories as auto-generated taxonomies.'), | |
| 396 | '#title' => t('Aggregate categories') | |
| 397 | ); | |
| 398 | ||
| 399 | $form['aggregation_feed_options']['link_items_to_original_urls'] = array( | |
| 400 | '#type' => 'select', | |
| 401 | '#default_value' => $node->aggregation_feed_options['link_items_to_original_urls'], | |
| 402 | '#description' => t('Link items generated from this feed to original URLs.'), | |
| 403 | '#title' => t('Display links to original URLs'), | |
| 404 | '#options' => $display_modes, | |
| 405 | ); | |
| 406 | ||
| 407 | $form['aggregation_feed_options']['aggregate_to_moderation_queue'] = array( | |
| 408 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 409 | '#default_value' => $node->aggregate_to_moderation_queue, | '#default_value' => $node->aggregation_feed_options['aggregate_to_moderation_queue'], |
| 410 | '#description' => t('Use this checkbox to send aggregated items to the moderation queue. Weather they appear on the site or not depends on the \'publish items\', not weather they are on the moderation queue.'), | '#description' => t('Use this checkbox to send aggregated items to the moderation queue. Weather they appear on the site or not depends on the \'publish items\', not weather they are on the moderation queue.'), |
| 411 | '#title' => t('Add aggregated items to moderation queue') | '#title' => t('Add aggregated items to moderation queue') |
| 412 | ); | ); |
| 413 | ||
| 414 | $form['sticky_items'] = array( | $form['aggregation_feed_options']['sticky_items'] = array( |
| 415 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 416 | '#default_value' => $node->sticky_items, | '#default_value' => $node->aggregation_feed_options['sticky_items'], |
| 417 | '#description' => t('All items aggregated from this feed will be sticky.'), | '#description' => t('All items aggregated from this feed will be sticky.'), |
| 418 | '#title' => t('Sticky items') | '#title' => t('Sticky items') |
| 419 | ); | ); |
| 420 | ||
| 421 | $form['enable_comments_on_articles'] = array( | $form['aggregation_feed_options']['enable_comments_on_articles'] = array( |
| 422 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 423 | '#default_value' => $node->enable_comments_on_articles, | '#default_value' => $node->aggregation_feed_options['enable_comments_on_articles'], |
| 424 | '#description' => t('All aggregated articles will have commenting set to read/write.'), | '#description' => t('All aggregated articles will have commenting set to read/write.'), |
| 425 | '#title' => t('Aggregated article comments') | '#title' => t('Aggregated article comments') |
| ); | ||
| $form['enable_comments_on_images'] = array( | ||
| '#type' => 'checkbox', | ||
| '#default_value' => $node->enable_comments_on_images, | ||
| '#description' => t('All aggregated images will have commenting set to read/write.'), | ||
| '#title' => t('Aggregated images\' comments') | ||
| 426 | ); | ); |
| 427 | ||
| 428 | $form['delete_old_items'] = array( | $form['aggregation_feed_options']['update_existing_aggregation_items'] = array( |
| 429 | '#type' => 'checkbox', | '#type' => 'checkbox', |
| 430 | '#default_value' => $node->delete_old_items, | '#default_value' => $node->aggregation_feed_options['update_existing_aggregation_items'], |
| 431 | '#description' => t('Use this checkbox to delete items older than (n) days, change this value from the settings. Uncheck and items under this feed will never be deleted until this option is turned on.'), | '#description' => t('If the item is changed in the original feed, it will be updated. This may slow down aggregation considerably.'), |
| 432 | '#title' => t('Delete Old Items') | '#title' => t('Update existing aggregation items') |
| 433 | ); | ); |
| 434 | ||
| 435 | $form['aggregation_feed_options']['link_items_to_original_comments'] = array( | |
| 436 | '#type' => 'select', | |
| 437 | '#default_value' => $node->aggregation_feed_options['link_items_to_original_comments'], | |
| 438 | '#description' => t('All generated items will have a link to the original comments if one exists for that item.'), | |
| 439 | '#title' => t('Display links to original comments'), | |
| 440 | '#options' => $display_modes, | |
| 441 | ); | |
| 442 | ||
| 443 | if (module_exists('image')) | |
| 444 | { | |
| 445 | $form['aggregation_feed_options']['aggregate_images_as_image_nodes'] = array( | |
| 446 | '#type' => 'checkbox', | |
| 447 | '#default_value' => $node->aggregation_feed_options['aggregate_images_as_image_nodes'], | |
| 448 | '#description' => t('All aggregated image enclosures will become image nodes.'), | |
| 449 | '#title' => t('Aggregate image enclosures as image nodes') | |
| 450 | ); | |
| 451 | $form['aggregation_feed_options']['enable_comments_on_images'] = array( | |
| 452 | '#type' => 'checkbox', | |
| 453 | '#default_value' => $node->aggregation_feed_options['enable_comments_on_images'], | |
| 454 | '#description' => t('All aggregated images will have commenting set to read/write.'), | |
| 455 | '#title' => t('Aggregated images\' comments') | |
| 456 | ); | |
| 457 | } | |
| 458 | ||
| 459 | $form['promote_to_frontpage'] = array( | $form['promote_to_frontpage'] = array( |
| 460 | '#type' => 'textfield', | '#type' => 'textfield', |
| 461 | '#default_value' => $node->promote_to_frontpage ? $node->promote_to_frontpage : 0, | '#default_value' => $node->promote_to_frontpage ? $node->promote_to_frontpage : 0, |
| # | Line 416 function aggregation_feed_form(&$node, & | Line 464 function aggregation_feed_form(&$node, & |
| 464 | '#description' => t('Please specify the number of articles to promote to the frontpage.') | '#description' => t('Please specify the number of articles to promote to the frontpage.') |
| 465 | ); | ); |
| 466 | ||
| 467 | $form['time_to_live'] = array( | |
| 468 | '#type' => 'textfield', | |
| 469 | '#default_value' => $node->time_to_live ? $node->time_to_live : 0, | |
| 470 | '#required' => TRUE, | |
| 471 | '#title' => t('Time to live'), | |
| 472 | '#description' => t('Any items older than this number of days will be deleted (0 means keep forever).') | |
| 473 | ); | |
| 474 | ||
| 475 | $form['item_taxonomies'] = array ( | $form['item_taxonomies'] = array ( |
| 476 | '#type' => 'fieldset', | '#type' => 'fieldset', |
| 477 | '#title' => t('Item Taxonomies'), | '#title' => t('Item Taxonomies'), |
| # | Line 456 function aggregation_feed_validate(&$nod | Line 512 function aggregation_feed_validate(&$nod |
| 512 | form_set_error('promote_to_frontpage', 'The number of items to promote to the frontpage is a positive numeric or 0.'); | form_set_error('promote_to_frontpage', 'The number of items to promote to the frontpage is a positive numeric or 0.'); |
| 513 | else if ($node->password != $node->repeat_password) | else if ($node->password != $node->repeat_password) |
| 514 | form_set_error('password', 'Your passwords did not match.'); | form_set_error('password', 'Your passwords did not match.'); |
| 515 | else if (!is_numeric($node->time_to_live) || $node->time_to_live < 0) | |
| 516 | form_set_error('time_to_live', 'The time to live field can only be greater or equals to 0.'); | |
| 517 | } | } |
| 518 | ||
| 519 | /** | /** |
| # | Line 464 function aggregation_feed_validate(&$nod | Line 522 function aggregation_feed_validate(&$nod |
| 522 | ||
| 523 | function aggregation_feed_submit(&$node) | function aggregation_feed_submit(&$node) |
| 524 | { | { |
| 525 | $node->enabled = $node->enabled ? 'yes' : 'no'; | $node->title = $node->title; |
| 526 | $node->publish_new_items = $node->publish_new_items ? 'yes' : 'no'; | $node->original_author = $node->original_author; |
| 527 | $node->delete_old_items = $node->delete_old_items ? 'yes' : 'no'; | |
| $node->aggregate_to_moderation_queue = $node->aggregate_to_moderation_queue ? 'yes' : 'no'; | ||
| $node->sticky_items = $node->sticky_items ? 'yes' : 'no'; | ||
| $node->enable_comments_on_articles = $node->enable_comments_on_articles ? 'yes' : 'no'; | ||
| $node->enable_comments_on_images = $node->enable_comments_on_images ? 'yes' : 'no'; | ||
| 528 | $node->etag = ''; | $node->etag = ''; |
| 529 | $node->last_modified = 0; | $node->last_modified = 0; |
| 530 | ||
| 531 | $node->title = trim($node->title); | $node->title = trim($node->title); |
| 532 | $node->original_author = trim($node->original_author); | $node->original_author = trim($node->original_author); |
| 533 | $node->url = trim($node->url); | $node->url = trim($node->url); |
| 534 | $node->username = trim($node->username); | $node->username = trim($node->username); |
| 535 | $node->password = trim($node->password); | $node->password = trim($node->password); |
| 536 | ||
| 537 | $node->aggregation_feed_options = serialize($node->aggregation_feed_options); | |
| 538 | $node->item_categories = serialize($node->item_categories); | $node->item_categories = serialize($node->item_categories); |
| 539 | } | } |
| 540 | ||
| # | Line 491 function aggregation_feed_prepare(&$node | Line 546 function aggregation_feed_prepare(&$node |
| 546 | { | { |
| 547 | $node->refresh_interval = $node->refresh_interval ? $node->refresh_interval : 15; | $node->refresh_interval = $node->refresh_interval ? $node->refresh_interval : 15; |
| 548 | ||
| 549 | $node->enabled = $node->enabled ? ($node->enabled == 'yes' ? TRUE : FALSE) : TRUE; | $node->aggregation_feed_options = unserialize($node->aggregation_feed_options); |
| 550 | ||
| $node->publish_new_items = $node->publish_new_items ? | ||
| ($node->publish_new_items == 'yes' ? TRUE : FALSE) : TRUE; | ||
| $node->delete_old_items = $node->delete_old_items ? | ||
| ($node->delete_old_items == 'yes' ? TRUE : FALSE) : FALSE; | ||
| $node->aggregate_to_moderation_queue = $node->aggregate_to_moderation_queue ? | ||
| ($node->aggregate_to_moderation_queue == 'yes' ? TRUE : FALSE) : FALSE; | ||
| $node->sticky_items = $node->sticky_items ? ($node->sticky_items == 'yes' ? TRUE : FALSE) : FALSE; | ||
| $node->enable_comments_on_articles = $node->enable_comments_on_articles ? | ||
| ($node->enable_comments_on_articles == 'yes' ? TRUE : FALSE) : FALSE; | ||
| $node->enable_comments_on_images = $node->enable_comments_on_images ? | ||
| ($node->enable_comments_on_images == 'yes' ? TRUE : FALSE) : FALSE; | ||
| 551 | if ($node->item_categories && $node->item_categories != '') | if ($node->item_categories && $node->item_categories != '') |
| 552 | $node->item_categories = unserialize($node->item_categories); | $node->item_categories = unserialize($node->item_categories); |
| 553 | ||
| # | Line 534 function aggregation_feed_prepare(&$node | Line 572 function aggregation_feed_prepare(&$node |
| 572 | } | } |
| 573 | } | } |
| 574 | } | } |
| 575 | ||
| 576 | $node->item_categories = $formatted_item_categories; | $node->item_categories = $formatted_item_categories; |
| 577 | } | } |
| 578 | } | } |
| # | Line 545 function aggregation_feed_prepare(&$node | Line 583 function aggregation_feed_prepare(&$node |
| 583 | ||
| 584 | function aggregation_feed_load($node) | function aggregation_feed_load($node) |
| 585 | { | { |
| 586 | return db_fetch_object(db_query("SELECT original_author, url, username, password, ". | return db_fetch_object(db_query("SELECT * FROM {aggregation_feed} WHERE nid = %d", $node->nid)); |
| "refresh_interval, title_as_guid_interval, enabled, publish_new_items, aggregate_to_moderation_queue, ". | ||
| "sticky_items, enable_comments_on_articles, enable_comments_on_images, promote_to_frontpage, ". | ||
| "delete_old_items, item_categories, etag, last_modified FROM {aggregation_feed} WHERE nid = %d", $node->nid)); | ||
| 587 | } | } |
| 588 | ||
| 589 | /** | /** |
| # | Line 557 function aggregation_feed_load($node) | Line 592 function aggregation_feed_load($node) |
| 592 | ||
| 593 | function aggregation_feed_insert($node) | function aggregation_feed_insert($node) |
| 594 | { | { |
| 595 | db_query("INSERT INTO {aggregation_feed} (nid, original_author, url, username, password, ". | db_query("INSERT INTO {aggregation_feed} VALUES ". |
| 596 | "refresh_interval, title_as_guid_interval, enabled, publish_new_items, aggregate_to_moderation_queue, sticky_items, enable_comments_on_articles, enable_comments_on_images, promote_to_frontpage, delete_old_items, item_categories, etag, last_modified, last_refreshed) VALUES ". | "(%d, '%s', '%s', '%s', '%s', %d, %d, %d, %d, '%s', '%s', '%s', %d, %d)", |
| 597 | "(%d, '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d ,'%s', '%s', '%s', %d, %d)", | $node->nid, $node->original_author, $node->url, $node->username, $node->password, $node->refresh_interval, |
| 598 | $node->nid, $node->original_author, $node->url, $node->username, $node->password, | $node->title_as_guid_interval, $node->promote_to_frontpage, $node->time_to_live, $node->item_categories, |
| 599 | $node->refresh_interval, $node->title_as_guid_interval, $node->enabled, $node->publish_new_items, | $node->aggregation_feed_options, '', 0, 0); |
| $node->aggregate_to_moderation_queue, $node->sticky_items, $node->enable_comments_on_articles, | ||
| $node->enable_comments_on_images, $node->promote_to_frontpage, $node->delete_old_items, $node->item_categories, | ||
| '', 0, 0); | ||
| 600 | } | } |
| 601 | ||
| 602 | /** | /** |
| # | Line 573 function aggregation_feed_insert($node) | Line 605 function aggregation_feed_insert($node) |
| 605 | ||
| 606 | function aggregation_feed_update($node) | function aggregation_feed_update($node) |
| 607 | { | { |
| 608 | if (trim($node->password) != '') | db_query("UPDATE {aggregation_feed} SET original_author = '%s', url = '%s', ". |
| 609 | { | "username = '%s', ".(trim($node->password) != '' ? "password = '{$node->password}'," : '')." refresh_interval = %d, title_as_guid_interval = %d, ". |
| 610 | db_query("UPDATE {aggregation_feed} SET original_author = '%s', url = '%s', ". | "promote_to_frontpage = %d, item_categories = '%s', time_to_live = %d, aggregation_feed_options = '%s', ". |
| 611 | "username = '%s', password = '%s', refresh_interval = %d, title_as_guid_interval = %d, enabled = '%s', ". | "etag = '%s', last_modified = %d, last_refreshed = %d WHERE nid = %d", |
| 612 | "publish_new_items = '%s', aggregate_to_moderation_queue = '%s', sticky_items = '%s', enable_comments_on_articles = '%s', enable_comments_on_images = '%s', promote_to_frontpage = %d, delete_old_items = '%s', item_categories = '%s', ". | $node->original_author, $node->url, $node->username, $node->refresh_interval, |
| 613 | "last_modified = %d, last_refreshed = %d WHERE nid = %d", | $node->title_as_guid_interval, $node->promote_to_frontpage, $node->item_categories, $node->time_to_live, |
| 614 | $node->original_author, $node->url, $node->username, $node->password, | $node->aggregation_feed_options, ($node->etag && $node->etag != '') ? $node->etag : '', |
| 615 | $node->refresh_interval, $node->title_as_guid_interval, $node->enabled, $node->publish_new_items, | ($node->last_modified && $node->last_modified != 0) ? $node->last_modified : 0, |
| 616 | $node->aggregate_to_moderation_queue, $node->sticky_items, $node->enable_comments_on_articles, | 0, $node->nid); |
| $node->enable_comments_on_images, $node->promote_to_frontpage, | ||
| $node->delete_old_items, $node->item_categories, | ||
| ($node->etag && $node->etag != '') ? $node->etag : '', | ||
| ($node->last_modified && $node->last_modified != 0) ? $node->last_modified : 0, | ||
| 0, $node->nid); | ||
| } | ||
| else | ||
| { | ||
| db_query("UPDATE {aggregation_feed} SET original_author = '%s', url = '%s', ". | ||
| "username = '%s', refresh_interval = %d, title_as_guid_interval = %d, enabled = '%s', ". | ||
| "publish_new_items = '%s', aggregate_to_moderation_queue = '%s', sticky_items = '%s', enable_comments_on_articles = '%s', enable_comments_on_images = '%s', promote_to_frontpage = %d, delete_old_items = '%s', item_categories = '%s', ". | ||
| "etag = '%s', last_modified = %d, last_refreshed = %d WHERE nid = %d", | ||
| $node->original_author, $node->url, $node->username, | ||
| $node->refresh_interval, $node->title_as_guid_interval, $node->enabled, $node->publish_new_items, | ||
| $node->aggregate_to_moderation_queue, $node->sticky_items, $node->enable_comments_on_articles, | ||
| $node->enable_comments_on_images, $node->promote_to_frontpage, | ||
| $node->delete_old_items, $node->item_categories, | ||
| ($node->etag && $node->etag != '') ? $node->etag : '', | ||
| ($node->last_modified && $node->last_modified != 0) ? $node->last_modified : 0, | ||
| 0, $node->nid); | ||
| } | ||
| 617 | } | } |
| 618 | ||
| 619 | /** | /** |
| # | Line 632 function aggregation_item_access($op, $n | Line 642 function aggregation_item_access($op, $n |
| 642 | ||
| 643 | if ($op == 'create') return user_access('manage aggregation items'); | if ($op == 'create') return user_access('manage aggregation items'); |
| 644 | if ($op == 'update' || $op == 'delete') | if ($op == 'update' || $op == 'delete') |
| 645 | return (user_access('manage own feed items') && ($user->uid == $node->uid)); | { |
| 646 | if (user_access('manage feed items')) return TRUE; | |
| 647 | return (user_access('manage own feed items') && ($user->uid == $node->uid)); | |
| 648 | } | |
| 649 | if ($op == 'view') return user_access('view aggregation items'); | if ($op == 'view') return user_access('view aggregation items'); |
| 650 | } | } |
| 651 | ||
| # | Line 644 function aggregation_item_form(&$node, & | Line 657 function aggregation_item_form(&$node, & |
| 657 | { | { |
| 658 | $form = array(); | $form = array(); |
| 659 | ||
| 660 | $display_modes = array( | |
| 661 | 0 => t('Don\'t display'), | |
| 662 | 1 => t('In full node views'), | |
| 663 | 2 => t('In teaser node views'), | |
| 664 | 3 => t('In both teaser and full node views'), | |
| 665 | ); | |
| 666 | ||
| 667 | $form['title'] = array ( | $form['title'] = array ( |
| 668 | '#type' => 'textfield', | '#type' => 'textfield', |
| 669 | '#default_value' => $node->title, | '#default_value' => $node->title, |
| # | Line 657 function aggregation_item_form(&$node, & | Line 677 function aggregation_item_form(&$node, & |
| 677 | '#default_value' => $node->teaser, | '#default_value' => $node->teaser, |
| 678 | '#required' => FALSE, | '#required' => FALSE, |
| 679 | '#title' => t('Teaser'), | '#title' => t('Teaser'), |
| 680 | '#description' => t('This is the article\'s teaser.') | '#description' => t('This is the article\'s teaser.') |
| 681 | ); | ); |
| 682 | ||
| 683 | $form['body'] = array ( | $form['body_filter']['body'] = array ( |
| 684 | '#type' => 'textarea', | '#type' => 'textarea', |
| 685 | '#default_value' => $node->body, | '#default_value' => $node->body, |
| 686 | '#required' => FALSE, | '#required' => FALSE, |
| # | Line 668 function aggregation_item_form(&$node, & | Line 688 function aggregation_item_form(&$node, & |
| 688 | '#description' => t('This is the main body of your article.') | '#description' => t('This is the main body of your article.') |
| 689 | ); | ); |
| 690 | ||
| 691 | $form['body_filter']['format'] = filter_form($node->format); | |
| 692 | ||
| 693 | $form['original_author'] = array( | $form['original_author'] = array( |
| 694 | '#type' => 'textfield', | '#type' => 'textfield', |
| 695 | '#default_value' => $node->original_author, | '#default_value' => $node->original_author, |
| # | Line 681 function aggregation_item_form(&$node, & | Line 703 function aggregation_item_form(&$node, & |
| 703 | '#default_value' => $node->url, | '#default_value' => $node->url, |
| 704 | '#required' => FALSE, | '#required' => FALSE, |
| 705 | '#title' => t('Original URL'), | '#title' => t('Original URL'), |
| 706 | '#description' => t('Provide the URL of the original article if needed.') | '#description' => t('Provide the URL of the original article if needed.'), |
| 707 | '#maxlength' => 250, | |
| 708 | ); | ); |
| 709 | ||
| 710 | $form['aggregation_item_options'] = array( | |
| 711 | '#type' => 'fieldset', | |
| 712 | '#title' => t('Options'), | |
| 713 | '#tree' => TRUE, | |
| 714 | ); | |
| 715 | ||
| 716 | $form['aggregation_item_options']['link_to_original_url'] = array( | |
| 717 | '#type' => 'select', | |
| 718 | '#default_value' => $node->aggregation_item_options['link_to_original_url'], | |
| 719 | '#title' => t('Display link to original URL'), | |
| 720 | '#description' => t('Link this item to its original URL (if available).'), | |
| 721 | '#options' => $display_modes, | |
| 722 | ); | |
| 723 | ||
| 724 | $form['aggregation_item_options']['link_to_original_comment'] = array( | |
| 725 | '#type' => 'select', | |
| 726 | '#default_value' => $node->aggregation_item_options['link_to_original_comment'], | |
| 727 | '#description' => t('A link to the original comments will be placed in the feed item if one exists.'), | |
| 728 | '#title' => t('Display link to original comments'), | |
| 729 | '#options' => $display_modes, | |
| 730 | ); | |
| 731 | ||
| 732 | $form['original_comments'] = array ( | |
| 733 | '#type' => 'textfield', | |
| 734 | '#default_value' => $node->original_comments, | |
| 735 | '#required' => FALSE, | |
| 736 | '#title' => t('Original Comments'), | |
| 737 | '#description' => t('URL of the original comments if needed.') | |
| 738 | ); | |
| 739 | ||
| 740 | $form['image_id'] = array ( | $form['image_id'] = array ( |
| 741 | '#type' => 'textfield', | '#type' => 'textfield', |
| 742 | '#default_value' => $node->image_id, | '#default_value' => $node->image_id, |
| 743 | '#required' => FALSE, | '#required' => FALSE, |
| 744 | '#title' => t('Image ID'), | '#title' => t('Image ID'), |
| 745 | '#description' => t('Provide an image id to attach an image.') | '#description' => t('Provide an image id to attach an image.') |
| 746 | ); | ); |
| 747 | ||
| 748 | $description = t('The GUID is a unique string that distingishes your article from '. | $description = t('The GUID is a unique string that distingishes your article from '. |
| 749 | 'all others and prevents a second aggregation. Please provide it if available.'); | 'all others and prevents a second aggregation. Please provide it if available.'); |
| # | Line 699 function aggregation_item_form(&$node, & | Line 752 function aggregation_item_form(&$node, & |
| 752 | if ($node->story_guid) | if ($node->story_guid) |
| 753 | $description .= '<br />'. | $description .= '<br />'. |
| 754 | t('(leave empty to preserve value)'); | t('(leave empty to preserve value)'); |
| 755 | ||
| 756 | $form['story_guid'] = array ( | $form['story_guid'] = array ( |
| 757 | '#type' => 'textfield', | '#type' => 'textfield', |
| 758 | '#default_value' => '', | '#default_value' => '', |
| # | Line 707 function aggregation_item_form(&$node, & | Line 760 function aggregation_item_form(&$node, & |
| 760 | '#title' => t('GUID'), | '#title' => t('GUID'), |
| 761 | '#description' => $description | '#description' => $description |
| 762 | ); | ); |
| 763 | ||
| 764 | $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 '. |
| 765 | 'WHERE n.nid = af.nid'); | 'WHERE n.nid = af.nid'); |
| 766 | ||
| 767 | if (db_num_rows($feeds) != 0) | if (db_num_rows($feeds) != 0) |
| 768 | { | { |
| 769 | $feed_array = array(); | $feed_array = array(); |
| 770 | ||
| 771 | $feed_array[0] = '<none>'; | $feed_array[0] = '<none>'; |
| 772 | ||
| 773 | while ($feed = db_fetch_object($feeds)) | while ($feed = db_fetch_object($feeds)) |
| 774 | $feed_array[$feed->nid] = $feed->title; | $feed_array[$feed->nid] = $feed->title; |
| 775 | ||
| 776 | $form['fid'] = array ( | $form['fid'] = array ( |
| 777 | '#type' => 'select', | '#type' => 'select', |
| 778 | '#default_value' => $node->fid, | '#default_value' => $node->fid, |
| # | Line 729 function aggregation_item_form(&$node, & | Line 782 function aggregation_item_form(&$node, & |
| 782 | '#options' => $feed_array | '#options' => $feed_array |
| 783 | ); | ); |
| 784 | } | } |
| 785 | ||
| 786 | return $form; | return $form; |
| 787 | } | } |
| 788 | ||
| # | Line 756 function aggregation_item_validate(&$nod | Line 809 function aggregation_item_validate(&$nod |
| 809 | ||
| 810 | function aggregation_item_submit(&$node) | function aggregation_item_submit(&$node) |
| 811 | { | { |
| 812 | $node->title = $node->title; | |
| 813 | $node->teaser = $node->teaser; | |
| 814 | $node->original_author = $node->original_author; | |
| 815 | ||
| 816 | $node->original_comments = trim($node->original_comments); | |
| 817 | ||
| 818 | if (!$node->fid) | if (!$node->fid) |
| 819 | $node->fid = 0; | $node->fid = 0; |
| 820 | ||
| # | Line 763 function aggregation_item_submit(&$node) | Line 822 function aggregation_item_submit(&$node) |
| 822 | $node->image_id = 0; | $node->image_id = 0; |
| 823 | ||
| 824 | if (trim($node->story_guid) != '') | if (trim($node->story_guid) != '') |
| 825 | $node->story_guid = crc32($node->story_guid); | $node->story_guid = sprintf('%u', crc32($node->story_guid)); |
| 826 | else | else |
| 827 | $node->story_guid = ''; | $node->story_guid = ''; |
| 828 | ||
| 829 | $node->aggregation_item_options = serialize($node->aggregation_item_options); | |
| 830 | } | } |
| 831 | ||
| 832 | /** | /** |
| # | Line 774 function aggregation_item_submit(&$node) | Line 835 function aggregation_item_submit(&$node) |
| 835 | ||
| 836 | function aggregation_item_prepare(&$node) | function aggregation_item_prepare(&$node) |
| 837 | { | { |
| 838 | $node->aggregation_item_options = unserialize($node->aggregation_item_options); | |
| 839 | } | } |
| 840 | ||
| 841 | /** | /** |
| # | Line 783 function aggregation_item_prepare(&$node | Line 844 function aggregation_item_prepare(&$node |
| 844 | ||
| 845 | function aggregation_item_load($node) | function aggregation_item_load($node) |
| 846 | { | { |
| 847 | return db_fetch_object(db_query('SELECT url, original_author, story_guid, '. | return db_fetch_object(db_query('SELECT * FROM {aggregation_item} WHERE nid = %d', $node->nid)); |
| 'fid, image_id, image_guid FROM {aggregation_item} WHERE nid = %d', $node->nid)); | ||
| 848 | } | } |
| 849 | ||
| 850 | /** | /** |
| # | Line 793 function aggregation_item_load($node) | Line 853 function aggregation_item_load($node) |
| 853 | ||
| 854 | function aggregation_item_insert($node) | function aggregation_item_insert($node) |
| 855 | { | { |
| 856 | db_query("INSERT INTO {aggregation_item} (nid, url, original_author, ". | db_query("INSERT INTO {aggregation_item} (nid, url, aggregation_item_options, original_author, ". |
| 857 | "story_guid, fid, image_id, image_guid) VALUES (%d, '%s', '%s', %d, %d, ". | "story_guid, fid, image_id, image_guid, original_comments) VALUES (%d, '%s', '%s', '%s', '%s', %d, ". |
| 858 | "%d, %d)", $node->nid, $node->url, $node->original_author, $node->story_guid, $node->fid, $node->image_id, $node->image_guid ? $node->image_guid : 0); | "%d, '%s', '%s')", $node->nid, $node->url, $node->aggregation_item_options, $node->original_author, $node->story_guid, $node->fid, $node->image_id, $node->image_guid ? $node->image_guid : 0, $node->original_comments); |
| 859 | } | } |
| 860 | ||
| 861 | /** | /** |
| # | Line 804 function aggregation_item_insert($node) | Line 864 function aggregation_item_insert($node) |
| 864 | ||
| 865 | function aggregation_item_update($node) | function aggregation_item_update($node) |
| 866 | { | { |
| 867 | if ($node->story_guid === '') | db_query("UPDATE {aggregation_item} SET url = '%s', original_author = '%s', ". |
| 868 | db_query("UPDATE {aggregation_item} SET url = '%s', original_author = '%s', ". | ($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)."'")." ". |
| 869 | "fid = %d, image_id = %d, image_guid = %d ". | "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", $node->url, $node->original_author, $node->fid, $node->image_id, | ||
| $node->image_guid ? $node->image_guid : 0, $node->nid); | ||
| else | ||
| db_query("UPDATE {aggregation_item} SET url = '%s', original_author = '%s', ". | ||
| "story_guid = %d, fid = %d, image_id = %d, image_guid = %d ". | ||
| "WHERE nid = %d", $node->url, $node->original_author, $node->story_guid, $node->fid, | ||
| $node->image_id, $node->image_guid ? $node->image_guid : 0, $node->nid); | ||
| 870 | } | } |
| 871 | ||
| 872 | /** | /** |
| # | Line 827 function aggregation_item_delete(&$node) | Line 880 function aggregation_item_delete(&$node) |
| 880 | ->image_count == 1) node_delete($node->image_id); | ->image_count == 1) node_delete($node->image_id); |
| 881 | ||
| 882 | db_query("UPDATE {aggregation_feed} SET etag = '', last_modified = 0 WHERE nid = %d", $node->fid); | db_query("UPDATE {aggregation_feed} SET etag = '', last_modified = 0 WHERE nid = %d", $node->fid); |
| 883 | ||
| 884 | db_query('DELETE FROM {aggregation_item} WHERE nid = %d', $node->nid); | db_query('DELETE FROM {aggregation_item} WHERE nid = %d', $node->nid); |
| 885 | } | } |
| 886 | ||
| # | Line 837 function aggregation_item_delete(&$node) | Line 890 function aggregation_item_delete(&$node) |
| 890 | ||
| 891 | function aggregation_item_view(&$node, $teaser = FALSE, $page = FALSE) | function aggregation_item_view(&$node, $teaser = FALSE, $page = FALSE) |
| 892 | { | { |
| 893 | if ($node->image_id > 0) | $node = node_prepare($node, $teaser); |
| 894 | { | if (!$teaser) |
| $image = node_load($node->image_id); | ||
| $node->image = $image; | ||
| // theme image | ||
| $image_render = theme('aggregation_image_render', $image); | ||
| } | ||
| else | ||
| 895 | { | { |
| 896 | $node->image_nid = NULL; | if ($node->image_id > 0) |
| 897 | $node->image = NULL; | { |
| 898 | $image = node_load($node->image_id); | |
| 899 | $image_render = ''; | $node->image = $image; |
| 900 | ||
| 901 | // theme image | |
| 902 | $image_render = theme('aggregation_image_render', $image); | |
| 903 | } | |
| 904 | else | |
| 905 | { | |
| 906 | $node->image_nid = NULL; | |
| 907 | $node->image = NULL; | |
| 908 | ||
| 909 | $image_render = ''; | |
| 910 | } | |
| 911 | ||
| 912 | // theme body | |
| 913 | $body_render = theme('aggregation_body_render', $node->body); | |
| 914 | ||
| 915 | // theme the final item | |
| 916 | $node->content['body']['#value'] = theme('aggregation_item_render', $image_render, $body_render); | |
| 917 | } | } |
| 918 | ||
| // theme body | ||
| $body_render = theme('aggregation_body_render', $node->body); | ||
| // theme the final item | ||
| $node->content['body']['#value'] = theme('aggregation_item_render', $image_render, $body_render); | ||
| 919 | return $node; | return $node; |
| 920 | } | |
| 921 | ||
| 922 | /** | |
| 923 | * Implementation of hook_link | |
| 924 | * | |
| 925 | */ | |
| 926 | function aggregation_link($type, $node = NULL, $teaser = FALSE) | |
| 927 | { | |
| 928 | $links = array(); | |
| 929 | if ($type == 'node' && $node->type == 'aggregation_item') | |
| 930 | { | |
| 931 | aggregation_item_prepare($node); | |
| 932 | if (valid_url($node->url, TRUE)) | |
| 933 | { | |
| 934 | if (($node->aggregation_item_options['link_to_original_url']==3) || | |
| 935 | ($teaser && $node->aggregation_item_options['link_to_original_url']==2) || | |
| 936 | (!$teaser && $node->aggregation_item_options['link_to_original_url']==1)) | |
| 937 | { | |
| 938 | $links['agregation_original_url'] = array( | |
| 939 | 'href' => $node->url, | |
| 940 | 'title' => t('Original article'), | |
| 941 | 'attributes' => array('class' => 'aggregation-link') | |
| 942 | ); | |
| 943 | } | |
| 944 | } | |
| 945 | ||
| 946 | if (valid_url($node->original_comments, TRUE)) | |
| 947 | { | |
| 948 | if (($node->aggregation_item_options['link_to_original_comment']==3) || | |
| 949 | ($teaser && $node->aggregation_item_options['link_to_original_comment']==2) || | |
| 950 | (!$teaser && $node->aggregation_item_options['link_to_original_comment']==1)) | |
| 951 | { | |
| 952 | $links['agregation_original_comments'] = array( | |
| 953 | 'href' => $node->original_comments, | |
| 954 | 'title' => ($node->comment ? t('Original Comments') : t('Comments')), | |
| 955 | 'attributes' => array('class' => 'aggregation-link') | |
| 956 | ); | |
| 957 | } | |
| 958 | } | |
| 959 | } | |
| 960 | return $links; | |
| 961 | } | } |
| 962 | ||
| 963 | function theme_aggregation_item_render($image_render, $body_render) | function theme_aggregation_item_render($image_render, $body_render) |
| # | Line 875 function theme_aggregation_body_render($ | Line 972 function theme_aggregation_body_render($ |
| 972 | ||
| 973 | function theme_aggregation_image_render($image) | function theme_aggregation_image_render($image) |
| 974 | { | { |
| 975 | return '<div class="aggregation_item_image">'.'<img src="'.base_path().file_directory_path().'/'.$image->images[variable_get('aggregation_image_to_display', 'preview')].'" />'. | return '<div class="aggregation_item_image"><img src="'.base_path().'/'. |
| 976 | '</div>'; | $image->images[variable_get('aggregation_image_to_display', 'preview')]. |
| 977 | '" />'.'</div>'; | |
| 978 | } | } |
| 979 | ||
| 980 | /* Following are the module's private methods */ | /* Following are the module's private methods */ |
| 981 | ||
| 982 | /** | /** |
| 983 | * This function returns the feed items for a particular feed | * This function returns the feed items for a particular feed |
| 984 | */ | */ |
| 985 | ||
| 986 | function _aggregation_get_feed_items($fid) | function _aggregation_get_feed_items($fid) |
| 987 | { | { |
| # | Line 898 function read_etag_and_modified($ch, $he | Line 996 function read_etag_and_modified($ch, $he |
| 996 | { | { |
| 997 | global $etag; | global $etag; |
| 998 | global $last_modified; | global $last_modified; |
| 999 | ||
| 1000 | $length = strlen($header); | $length = strlen($header); |
| 1001 | if(strstr($header, "Last-Modified:")) | if(strstr($header, "Last-Modified:")) |
| 1002 | { | { |
| # | Line 914 function read_etag_and_modified($ch, $he | Line 1012 function read_etag_and_modified($ch, $he |
| 1012 | /** | /** |
| 1013 | * This function returns the data in a URL (XML, image, etc...) | * This function returns the data in a URL (XML, image, etc...) |
| 1014 | */ | */ |
| 1015 | function aggregation_get_URL($url, $username = NULL, $password = NULL, $feed = NULL, | function aggregation_get_URL($url, $username = NULL, $password = NULL, $feed = NULL, |
| 1016 | $feed_etag = NULL, $feed_last_modified = NULL) | $feed_etag = NULL, $feed_last_modified = NULL) |
| 1017 | { | { |
| 1018 | global $etag; | global $etag; |
| 1019 | global $last_modified; | global $last_modified; |
| 1020 | ||
| 1021 | if (trim($username) == '') $username = NULL; | if (trim($username) == '') $username = NULL; |
| 1022 | if (trim($password) == '') $password = NULL; | if (trim($password) == '') $password = NULL; |
| 1023 | ||
| 1024 | $headers = array(); | $headers = array(); |
| 1025 | ||
| 1026 | if (!is_null($feed_etag) && $feed_etag != '') | if (!is_null($feed_etag) && $feed_etag != '') |
| 1027 | $headers['If-None-Match'] = $feed_etag; | $headers['If-None-Match'] = $feed_etag; |
| 1028 | ||
| 1029 | if (!is_null($feed_last_modified) && $feed_last_modified != 0) | if (!is_null($feed_last_modified) && $feed_last_modified != 0) |
| 1030 | $headers['If-Modified-Since'] = gmdate('D, d M Y H:i:s', $feed_last_modified) .' GMT'; | $headers['If-Modified-Since'] = gmdate('D, d M Y H:i:s', $feed_last_modified) .' GMT'; |
| 1031 | ||
| 1032 | if(count($headers) > 0) | if(count($headers) > 0) |
| 1033 | { | { |
| 1034 | $temp = array(); | $temp = array(); |
| 1035 | ||
| 1036 | foreach ($headers as $header => $value) | foreach ($headers as $header => $value) |
| 1037 | $temp[] = $header .': '. $value; | $temp[] = $header .': '. $value; |
| 1038 | ||
| 1039 | $headers = $temp; | $headers = $temp; |
| 1040 | } | } |
| 1041 | ||
| 1042 | $ch = curl_init(); | $ch = curl_init(); |
| 1043 | ||
| 1044 | $is_ftp = FALSE; | $is_ftp = FALSE; |
| 1045 | ||
| 1046 | if (stripos($url, 'ftp://') !== FALSE) | if (stripos($url, 'ftp://') !== FALSE) |
| 1047 | $is_ftp = TRUE; | $is_ftp = TRUE; |
| 1048 | ||
| 1049 | if (!$is_ftp) | if (!$is_ftp) |
| 1050 | curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"); | curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)"); |
| 1051 | ||
| 1052 | if (is_array($headers) && count($headers) > 0 && !$is_ftp) | if (is_array($headers) && count($headers) > 0 && !$is_ftp) |
| 1053 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
| 1054 | ||
| 1055 | if (!$is_ftp) | if (!$is_ftp) |
| 1056 | curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_etag_and_modified'); | curl_setopt($ch, CURLOPT_HEADERFUNCTION, 'read_etag_and_modified'); |
| 1057 | ||
| 1058 | if (!$is_ftp) | if (!$is_ftp) |
| 1059 | { | { |
| 1060 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); |
| 1061 | curl_setopt($ch, CURLOPT_MAXREDIRS, 5); | curl_setopt($ch, CURLOPT_MAXREDIRS, 5); |
| 1062 | } | } |
| 1063 | ||
| 1064 | if (!is_null($username) && !is_null($password)) | if (!is_null($username) && !is_null($password)) |
| 1065 | { | { |
| 1066 | curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); | curl_setopt($ch, CURLOPT_USERPWD, "$username:$password"); |
| 1067 | if (!$is_ftp) | if (!$is_ftp) |
| 1068 | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); | curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); |
| 1069 | } | } |
| 1070 | curl_setopt($ch, CURLOPT_URL, $url); | curl_setopt($ch, CURLOPT_URL, $url); |
| 1071 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 1072 | if ($is_ftp) | if ($is_ftp) |
| 1073 | curl_setopt($ch, CURLOPT_FTP_USE_EPSV, FALSE); | curl_setopt($ch, CURLOPT_FTP_USE_EPSV, FALSE); |
| 1074 | curl_setopt($ch, CURLOPT_TIMEOUT, 15); | curl_setopt($ch, CURLOPT_TIMEOUT, 15); |
| # | Line 981 function aggregation_get_URL($url, $user | Line 1079 function aggregation_get_URL($url, $user |
| 1079 | ||
| 1080 | $error = curl_error($ch); | $error = curl_error($ch); |
| 1081 | ||
| 1082 | curl_close($ch); | curl_close($ch); |
| 1083 | unset($ch); | unset($ch); |
| 1084 | ||
| 1085 | if ($return_code != 304) | if ($return_code != 304) |
| # | Line 990 function aggregation_get_URL($url, $user | Line 1088 function aggregation_get_URL($url, $user |
| 1088 | if ($is_ftp && $return_code != 226) | if ($is_ftp && $return_code != 226) |
| 1089 | { | { |
| 1090 | $fragment = ''; | $fragment = ''; |
| 1091 | ||
| 1092 | if (!is_null($feed)) | if (!is_null($feed)) |
| 1093 | $fragment = " while processing feed \"$feed->title\""; | $fragment = " while processing feed \"$feed->title\""; |
| 1094 | ||
| 1095 | throw new Exception("FTP request returned error code \"$return_code\"". | throw new Exception("FTP request returned error code \"$return_code\"". |
| 1096 | "$fragment on \"$url\"", FTP_REQUEST_FAILED); | "$fragment on \"$url\"", FTP_REQUEST_FAILED); |
| 1097 | } | } |
| 1098 | ||
| 1099 | // It was an HTTP request but failed | // It was an HTTP request but failed |
| 1100 | if (!$is_ftp && $return_code != 200) | if (!$is_ftp && $return_code != 200) |
| 1101 | { | { |
| 1102 | $fragment = ''; | $fragment = ''; |
| 1103 | ||
| 1104 | if (!is_null($feed)) | if (!is_null($feed)) |
| 1105 | $fragment = " while processing feed \"$feed->title\""; | $fragment = " while processing feed \"$feed->title\""; |
| 1106 | ||
| 1107 | throw new Exception("HTTP request returned error code \"$return_code\"". | throw new Exception("HTTP request returned error code \"$return_code\"". |
| 1108 | "$fragment on \"$url\"", HTTP_REQUEST_FAILED); | "$fragment on \"$url\"", HTTP_REQUEST_FAILED); |
| 1109 | } | } |
| 1110 | } | } |
| 1111 | else | else |
| 1112 | return FALSE; | return FALSE; |
| 1113 | ||
| 1114 | if (!is_null($feed_etag) && !is_null($feed_last_modified)) | if (!is_null($feed_etag) && !is_null($feed_last_modified)) |
| 1115 | return array($data, $etag, $last_modified); | return array($data, $etag, $last_modified); |
| 1116 | ||
| 1117 | return $data; | return $data; |
| 1118 | } | } |
| 1119 | ||
| # | Line 1025 function aggregation_get_URL($url, $user | Line 1123 function aggregation_get_URL($url, $user |
| 1123 | */ | */ |
| 1124 | function aggregation_get_XML($string, $feed = NULL) | function aggregation_get_XML($string, $feed = NULL) |
| 1125 | { | { |
| 1126 | @ $xml = simplexml_load_string($string, NULL, LIBXML_NOERROR | LIBXML_NOWARNING); | // PHP versions earlier than 5.1 have different argument counts for simplexml_load_string, |
| 1127 | // this condition was added to check against this case | |
| 1128 | ||
| 1129 | if (!defined('LIBXML_VERSION') || (version_compare(phpversion(), '5.1.0', '<'))) | |
| 1130 | @ $xml = simplexml_load_string($string, NULL); | |
| 1131 | else | |
| 1132 | @ $xml = simplexml_load_string($string, NULL, LIBXML_NOERROR | LIBXML_NOWARNING); | |
| 1133 | ||
| 1134 | // We got a malformed XML | // We got a malformed XML |
| 1135 | if ($xml === FALSE) | if ($xml === FALSE) |
| 1136 | { | { |
| 1137 | $fragment = ''; | $fragment = ''; |
| 1138 | ||
| 1139 | if (!is_null($feed)) | if (!is_null($feed)) |
| 1140 | $fragment = " while processing feed \"$feed->title\""; | $fragment = " while processing feed \"$feed->title\""; |
| 1141 | ||
| 1142 | throw new Exception("XML malformed$fragment", MALFORMED_XML); | throw new Exception("XML malformed$fragment", MALFORMED_XML); |
| 1143 | } | } |
| 1144 | ||
| 1145 | return $xml; | return $xml; |
| 1146 | } | } |
| 1147 | ||
| # | Line 1050 function aggregation_get_XML($string, $f | Line 1154 function aggregation_get_XML($string, $f |
| 1154 | function _aggregation_parse($feed, $vid) | function _aggregation_parse($feed, $vid) |
| 1155 | { | { |
| 1156 | $handler_name = ''; | $handler_name = ''; |
| 1157 | ||
| 1158 | foreach ($feed->taxonomy AS $tid => $term_object) | foreach ($feed->taxonomy AS $tid => $term_object) |
| 1159 | if ($term_object->vid == $vid) | if ($term_object->vid == $vid) |
| 1160 | { | { |
| 1161 | $handler_name = $term_object->name; | $handler_name = $term_object->name; |
| 1162 | break; | break; |
| 1163 | } | } |
| 1164 | ||
| 1165 | if ($handler_name == '') | if ($handler_name == '') |
| 1166 | throw new Exception('Did you change the vocabulary name without re-assigning the feeds?', | throw new Exception('Did you change the vocabulary name without re-assigning the feeds?', |
| 1167 | FEEDS_ARENT_ASSIGNED_TERM_UNDER_ACTIVE_VOCABULARY); | FEEDS_ARENT_ASSIGNED_TERM_UNDER_ACTIVE_VOCABULARY); |
| 1168 | ||
| 1169 | $data = aggregation_get_URL($feed->url, $feed->username, $feed->password, $feed, | $data = aggregation_get_URL($feed->url, $feed->username, $feed->password, $feed, |
| 1170 | $feed->etag, $feed->last_modified); | $feed->etag, $feed->last_modified); |
| 1171 | ||
| 1172 | if ($data === FALSE) | if ($data === FALSE) |
| 1173 | { | { |
| 1174 | watchdog('aggregation', t("Feed \"%s\" was not modified since last refresh", array('%s' => $feed->title))); | watchdog('aggregation', t("Feed \"%s\" was not modified since last refresh", array('%s' => $feed->title))); |
| 1175 | return NULL; | return NULL; |
| 1176 | } | } |
| 1177 | ||
| 1178 | $feed->etag = $data[1]; | $feed->etag = $data[1]; |
| 1179 | $feed->last_modified = $data[2]; | $feed->last_modified = $data[2]; |
| 1180 | $data = $data[0]; | $data = $data[0]; |
| 1181 | ||
| 1182 | $feed_xml = aggregation_get_XML($data, $feed); | $feed_xml = aggregation_get_XML($data, $feed); |
| 1183 | ||
| 1184 | require_once(drupal_get_path('module', 'aggregation')."/feed_handlers/$handler_name.inc"); | require_once(drupal_get_path('module', 'aggregation')."/feed_handlers/$handler_name.inc"); |
| 1185 | ||
| 1186 | try { | try { |
| 1187 | call_user_func_array('_aggregation_'.$handler_name.'_parse', array($feed_xml, $feed)); | call_user_func_array('_aggregation_'.$handler_name.'_parse', array($feed_xml, $feed)); |
| 1188 | } catch (Exception $e) { | } catch (Exception $e) { |
| # | Line 1094 function _aggregation_parse($feed, $vid) | Line 1198 function _aggregation_parse($feed, $vid) |
| 1198 | /** | /** |
| 1199 | * This internal function is responsible for adding items | * This internal function is responsible for adding items |
| 1200 | */ | */ |
| 1201 | function _aggregation_add_item($title, $body, $teaser, $original_author, $feed, | function _aggregation_add_item($title, $body, $teaser, $original_author, $feed, |
| 1202 | $additional_taxonomies, $timestamp = NULL, $original_item_url = NULL, $guid = NULL, | $additional_taxonomies, $timestamp = NULL, $original_item_url = NULL, $guid = NULL, |
| 1203 | $image_array = NULL) | $image_array = NULL, $other = NULL) |
| 1204 | { | { |
| 1205 | if ($feed->time_to_live != 0 && time() - $timestamp >= $feed->time_to_live * 24 * 60 * 60) return; | |
| 1206 | if (!is_null($title)) $title = trim($title); | if (!is_null($title)) $title = trim($title); |
| 1207 | if (!is_null($body)) $body = trim($body); | if (!is_null($body)) $body = trim($body); |
| 1208 | if (!is_null($teaser)) $teaser = trim($teaser); | if (!is_null($teaser)) $teaser = trim($teaser); |
| 1209 | if (!is_null($original_author)) $original_author = trim($original_author); | if (!is_null($original_author)) $original_author = trim($original_author); |
| 1210 | if (!is_null($original_item_url)) $original_item_url = trim($original_item_url); | if (!is_null($original_item_url)) $original_item_url = trim($original_item_url); |
| 1211 | if (!is_null($guid)) $guid = trim($guid); | if (!is_null($guid)) $guid = trim($guid); |
| 1212 | ||
| 1213 | if (is_array($image_array)) | //setting guid |
| 1214 | { | $interval_check = FALSE; |
| 1215 | if (!is_null($image_array['url'])) $image_array['url'] = trim($image_array['url']); | if (is_null($guid) || empty($guid)) |
| 1216 | if (!$image_array['url'] || empty($image_array['url'])) | { |
| 1217 | $image_array = NULL; | if (!is_null($original_item_url) && !empty($original_item_url)) |
| 1218 | else | $guid = $original_item_url; |
| 1219 | elseif (!is_null($title) && !empty($title)) | |
| 1220 | { | { |
| 1221 | if (!is_null($image_array['title'])) $image_array['title'] = trim($image_array['title']); | $guid = $title; |
| 1222 | if (!is_null($image_array['guid'])) $image_array['guid'] = trim($image_array['guid']); | $interval_check = TRUE; |
| 1223 | if (!is_null($image_array['teaser'])) $image_array['teaser'] = trim($image_array['teaser']); | } |
| 1224 | if (!is_null($image_array['body'])) $image_array['body'] = trim($image_array['body']); | else |
| 1225 | if (!is_null($image_array['url'])) $image_array['url'] = trim($image_array['url']); | { |
| 1226 | $guid = $body; | |
| 1227 | if (is_null($image_array['title']) || empty($image_array['title'])) | $interval_check = TRUE; |
| $image_array['title'] = $title; | ||
| if (is_null($image_array['guid']) || empty($image_array['guid'])) | ||
| $image_array['guid'] = $image_array['url']; | ||
| if (is_null($image_array['body']) || empty($image_array['body'])) | ||
| $image_array['body'] = $image_array['title']; | ||
| if (is_null($image_array['teaser']) || empty($image_array['teaser'])) | ||
| $image_array['teaser'] = $image_array['title']; | ||
| if (is_null($image_array['timestamp'])) | ||
| $image_array['timestamp'] = time(); | ||
| if (is_null($guid) || empty($guid)) | ||
| $guid = $image_array['url']; | ||
| 1228 | } | } |
| 1229 | } | } |
| 1230 | ||
| 1231 | // Noticed that some feeds unexpectedly lack a title | |