1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
|
4
|
|
|
/** |
5
|
|
|
* Widget to display pagination info |
6
|
|
|
* |
7
|
|
|
* @extends GravityView_Widget |
8
|
|
|
*/ |
9
|
|
|
class GravityView_Widget_Pagination_Info extends \GV\Widget { |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Does this get displayed on a single entry? |
13
|
|
|
* @var boolean |
14
|
|
|
*/ |
15
|
|
|
protected $show_on_single = false; |
16
|
|
|
|
17
|
2 |
|
function __construct() { |
|
|
|
|
18
|
|
|
|
19
|
2 |
|
$this->widget_description = __('Summary of the number of visible entries out of the total results.', 'gravityview' ); |
|
|
|
|
20
|
|
|
|
21
|
|
|
$default_values = array( |
22
|
2 |
|
'header' => 1, |
23
|
|
|
'footer' => 1, |
24
|
|
|
); |
25
|
|
|
|
26
|
2 |
|
$settings = array(); |
27
|
|
|
|
28
|
2 |
|
parent::__construct( __( 'Show Pagination Info', 'gravityview' ) , 'page_info', $default_values, $settings ); |
29
|
2 |
|
} |
30
|
|
|
|
31
|
1 |
|
public function render_frontend( $widget_args, $content = '', $context = '') { |
32
|
1 |
|
$gravityview_view = GravityView_View::getInstance(); |
33
|
|
|
|
34
|
1 |
|
if( !$this->pre_render_frontend() ) { |
|
|
|
|
35
|
|
|
return; |
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
if( !empty( $widget_args['title'] ) ) { |
|
|
|
|
39
|
|
|
echo $widget_args['title']; |
|
|
|
|
40
|
|
|
} |
41
|
|
|
|
42
|
1 |
|
$pagination_counts = $gravityview_view->getPaginationCounts(); |
43
|
|
|
|
44
|
1 |
|
$total = $first = $last = null; |
45
|
|
|
|
46
|
1 |
|
$output = ''; |
47
|
|
|
|
48
|
1 |
|
if( ! empty( $pagination_counts ) ) { |
49
|
|
|
|
50
|
1 |
|
$first = $pagination_counts['first']; |
51
|
1 |
|
$last = $pagination_counts['last']; |
52
|
1 |
|
$total = $pagination_counts['total']; |
53
|
|
|
|
54
|
1 |
|
$class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : ''; |
|
|
|
|
55
|
1 |
|
$class = gravityview_sanitize_html_class( $class ); |
56
|
|
|
|
57
|
1 |
|
$output = '<div class="gv-widget-pagination '.$class.'"><p>'. sprintf(__( 'Displaying %1$s - %2$s of %3$s', 'gravityview' ), number_format_i18n( $first ), number_format_i18n( $last ), number_format_i18n( $total ) ) . '</p></div>'; |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @filter `gravityview_pagination_output` Modify the pagination widget output |
62
|
|
|
* @param string $output HTML output |
63
|
|
|
* @param int $first First entry # |
64
|
|
|
* @param int $last Last entry # |
65
|
|
|
* @param int $total Total entries # |
66
|
|
|
*/ |
67
|
1 |
|
echo apply_filters( 'gravityview_pagination_output', $output, $first, $last, $total ); |
|
|
|
|
68
|
|
|
|
69
|
1 |
|
} |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
new GravityView_Widget_Pagination_Info; |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.