1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
<?php
namespace Bitweaver\Plugins;
/**
* Smarty {libertypagination} function plugin
*
* This provides a means of paging through longer lists of data using an up and down arrow.
* In addition, if the 'site_direct_pagination' feature is enabled, then a direct page number can be entered jump directly to
*
* Type: function<br>
* Name: libertypagination<br>
* Input:<br>
* - numPages Number of pages in total<br>
* - page current page<br>
* - pgnName (optional) parameter name used by script to find page you're on. defaults to page<br>
* - ianchor (optional) set an anchor<br>
* - ihash (optional) you can pass in all the above as an array called ihash or secondary * items common to all links<br>
* The ihash option allow the inclusion of additional link values as provided for smartlink navigation<br>
* Output: url of the form: $REQUEST_URI?attribute1=value1&attribute2=value2
*
* @package Smarty
* @subpackage plugins
* @link https://www.bitweaver.org/wiki/function_libertypagination function.libertypagination
*/
/**
* Smarty {libertypagination} function plugin
*/
function smarty_function_libertypagination($params, &$gSmartyTemplate) {
global $gBitSmarty;
if( isset( $params['ihash'] ) && is_array( $params['ihash'] ) ) {
$params = array_merge( $params['ihash'], $params );
$params['ihash'] = NULL;
}
if( isset( $params['url'] ) ) {
$urlParams = '';
parse_str( preg_replace( "/.*\?/", "", $params['url'] ), $urlParams );
$params = array_merge( $urlParams, $params );
}
$pgnName = $params['pgnName'] ?? ( isset( $params['curPage'] ) ? 'curPage' : 'page' );
$pgnVars = '';
$omitParams = [ 'numPages', 'url', $pgnName, 'pgnName', 'ianchor', 'ajaxId' ];
foreach( $params as $form_param => $form_val ) {
if ( !empty( $form_val ) && !in_array( $form_param, $omitParams ) ) {
$pgnVars .= ( !empty( $params['ajaxId'] ) ? "&" : "&" ).$form_param."=".$form_val;
$pgnHidden[$form_param] = $form_val;
}
}
$pgnVars .= !empty( $params['ianchor'] ) ? '#'.$params['ianchor'] : '';
if( !empty( $params['numPages'] ) ) {
for( $pageCount = 1; $pageCount < $params['numPages']+1; $pageCount++ ) {
$pages[] = $pageCount != $params[$pgnName]
? ( !empty( $params['ajaxId'] )
? '<a href="javascript:void(0);" onclick="BitAjax.updater(\''.$params['ajaxId']."','".$_SERVER['REQUEST_URI']."','".$pgnName.'='.$pageCount.$pgnVars.'\')'.'">'. $pageCount .'</a>'
: '<a href="'.$_SERVER['SCRIPT_NAME'].'?'.$pgnName.'='.$pageCount.$pgnVars.'">'. $pageCount .'</a>')
: '<strong>'.$pageCount.'</strong>';
}
$gBitSmarty->assign( 'pgnPage', $params[$pgnName] );
$gBitSmarty->assign( 'pgnName', $pgnName );
$gBitSmarty->assign( 'pgnVars', $pgnVars );
$gBitSmarty->assign( 'pgnHidden', $pgnHidden );
$gBitSmarty->assign( 'pgnPages', $pages );
$gBitSmarty->assign( 'numPages', $params['numPages'] );
if( !empty( $params['ajaxId'] ) ) {
$gBitSmarty->assign( 'ajaxId', $params['ajaxId'] );
}
return $gBitSmarty->fetch( 'bitpackage:liberty/libertypagination.tpl' );
}
}
|