prev_next_views.module in Previous/Next API 7
File
prev_next_views.module
View source
<?php
function prev_next_views_prev_next_nid($nid, $op = 'next') {
if (isset($_SESSION['prev_next_views'])) {
$index = array_search($nid, $_SESSION['prev_next_views']);
if ($index !== FALSE) {
$ret = $index;
if ($op == 'prev') {
$ret--;
}
elseif ($op == 'next') {
$ret++;
}
if ($ret >= 0 && $ret < count($_SESSION['prev_next_views'])) {
return $_SESSION['prev_next_views'][$ret];
}
else {
return 0;
}
}
}
return FALSE;
}
function prev_next_views_permission() {
return array(
'administer prev_next_views' => array(
'title' => t('Administer Prev/Next for Views'),
'description' => t('Perform administration tasks for Prev/Next for Views module.'),
),
);
}
function prev_next_views_menu() {
$items = array();
$items['admin/config/system/prev_next/views'] = array(
'title' => 'Views',
'page callback' => 'drupal_get_form',
'page arguments' => array(
'prev_next_views_settings',
),
'access arguments' => array(
'administer prev_next_views',
),
'type' => MENU_LOCAL_TASK,
'weight' => 10,
'file' => 'prev_next_views.admin.inc',
);
return $items;
}
function prev_next_views_node_load($nodes, $types) {
if (isset($_SESSION['prev_next_views']) && is_array($_SESSION['prev_next_views'])) {
foreach ($nodes as $node) {
if (array_search($node->nid, $_SESSION['prev_next_views']) === FALSE) {
unset($_SESSION['prev_next_views']);
break;
}
}
}
}
function prev_next_views_views_api() {
return array(
'api' => 2,
);
}
function prev_next_views_views_pre_execute(&$view) {
if (in_array($view->name, variable_get('prev_next_views_enabled', array()))) {
$result = $view->build_info['query']
->execute();
$nids = array();
foreach ($result as $item) {
$nids[] = $item->nid;
}
$_SESSION['prev_next_views'] = $nids;
}
}