function pagination_nodeapi in Pagination (Node) 6
@desc Implementation of hook_nodeapi()
File
- ./
pagination.module, line 274 - pagination.module @desc Allow for arbitrary nodes to be paginated. administrators can set which nodes they wish to paginate, and the length of content required to split a node into pages. Alternatively, content creators can set manual break points…
Code
function pagination_nodeapi(&$node, $op, $teaser = null, $page = null) {
switch ($op) {
case 'delete':
// Fall through
case 'presave':
$pg =& Pagination::getInstance();
$style = $pg
->getStyle($node->type);
$paging = $pg
->getValue($node->type);
if ($paging > PAGINATION_AUTO and $style > PAGINATION_DEFAULT) {
$query = "DELETE FROM {node_pagination} WHERE nid = %d";
db_query($query, $node->nid);
if ($op == 'presave' and $node->pagination_headers) {
$headers = explode("\n", str_replace("\r\n", "\n", $node->pagination_headers));
$query = "INSERT INTO {node_pagination} (nid, headers) VALUES (%d, '%s')";
db_query($query, $node->nid, serialize($headers));
}
}
break;
case 'validate':
$pg =& Pagination::getInstance();
$style = $pg
->getStyle($node->type);
$paging = $pg
->getValue($node->type);
// Add javascript for validation failure cases.
if ($paging > PAGINATION_AUTO and $style > PAGINATION_DEFAULT) {
drupal_add_js(drupal_get_path('module', 'pagination') . '/pagination.js');
}
break;
case 'view':
// Main pagination fun.
$pg =& Pagination::getInstance();
$page = $pg
->getPageVar();
$paging = $pg
->getValue($node->type);
$style = $pg
->getStyle($node->type);
$ignore = array_map('trim', explode(',', variable_get('pagination_ignore', '')));
$build = $node->build_mode === NODE_BUILD_NORMAL;
if (!$teaser and $paging and $page !== 'show' and $build and !in_array($node->nid, $ignore, true)) {
$pg
->paginate($node->content['body']['#value'], $paging);
$node->content['body']['#value'] = $pg
->getPage($page);
if ($style < PAGINATION_TOC) {
$node->content['pagination_pager'] = array(
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'pagination_pager') : 50,
'#value' => $pg
->getPager(),
);
}
if ($style > PAGINATION_DEFAULT and $pg
->getPageCount() > 1) {
$node->content['pagination_toc'] = array(
'#weight' => module_exists('content') ? content_extra_field_weight($node->type, 'pagination_toc') : -50,
'#value' => $pg
->getToc($node->nid),
'#total_pages' => $pg
->getPageCount(),
);
}
}
break;
}
}