function views_atom_rules_action_add_nids_to_feed in Views Atom 6
Rule implementation callback for adding multiple nodes to a feed.
Parameters
$nids: An array of nids that we want to push using the configured view.
$settings: Configuration specified by the user.
File
- ./
views_atom.rules.inc, line 149
Code
function views_atom_rules_action_add_nids_to_feed($nids, $settings) {
if ($nids) {
// The $nids array will be broken into smaller chunks.
if (is_numeric($settings['max_push_size']) && $settings['max_push_size'] >= 1) {
$chunk_size = $settings['max_push_size'];
}
else {
$chunk_size = count($nids);
}
// Break the array of nids into smaller pieces so that
// push_hub_notify() doesn't get overly large packages.
$chunked_array = array_chunk($nids, $chunk_size);
// Loop through each chunk to render it as atom and send it with push_hub.
foreach ($chunked_array as $nids_chunk) {
$view = views_get_view($settings['view']);
$view
->set_display($settings['view_display']);
if ($view
->access($settings['view_display'])) {
$nid_string = implode(',', $nids_chunk);
// If these nodes existed in the system prior to this page request, there is a chance
// that they need to be reloaded and thus node_load() needs to be reset.
node_load($param = array(), $revision = NULL, $reset = TRUE);
// Get the atom-formatted-data for these nodes.
$result = $view
->preview($settings['view_display'], array(
$nid_string,
));
// Only PuSH the feed if there is actual data. The view may have filtered
// our nids down to 0, in which case we don't want to send anything. Because
// normal View requests (Pull-based) are unaffected, Atom subscriptions still
// work as normal.
if (!empty($view->result)) {
$topic_url = url($view->display[$view->current_display]->display_options['path'], array(
'absolute' => TRUE,
));
// This uses the Drupal Queue module to actually send notifications later.
push_hub_notify($topic_url, $result);
}
}
}
}
}