prev_next_views.module in Previous/Next API 6
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_perm() {
return array(
'administer prev_next_views',
);
}
function prev_next_views_menu() {
$items = array();
$items['admin/settings/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_nodeapi(&$node, $op) {
if (isset($_SESSION['prev_next_views']) && array_search($node->nid, $_SESSION['prev_next_views']) === FALSE) {
unset($_SESSION['prev_next_views']);
}
}
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()))) {
$query = db_rewrite_sql($view->build_info['query'], $view->base_table, $view->base_field, array(
'view' => &$view,
));
$args = $view->build_info['query_args'];
$result = db_query($query, $args);
$nids = array();
while ($item = db_fetch_array($result)) {
$nids[] = $item['nid'];
}
$_SESSION['prev_next_views'] = $nids;
}
}