1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Widget to display page links |
5
|
|
|
* |
6
|
|
|
* @extends GravityView_Widget |
7
|
|
|
*/ |
8
|
|
|
class GravityView_Widget_Page_Links extends \GV\Widget { |
9
|
|
|
|
10
|
|
|
protected $show_on_single = false; |
11
|
|
|
|
12
|
2 |
|
function __construct() { |
|
|
|
|
13
|
|
|
|
14
|
2 |
|
$this->widget_description = __('Links to multiple pages of results.', 'gravityview' ); |
|
|
|
|
15
|
|
|
|
16
|
2 |
|
$default_values = array( 'header' => 1, 'footer' => 1 ); |
17
|
2 |
|
$settings = array( 'show_all' => array( |
|
|
|
|
18
|
2 |
|
'type' => 'checkbox', |
19
|
2 |
|
'label' => __( 'Show each page number', 'gravityview' ), |
20
|
2 |
|
'desc' => __('Show every page number instead of summary (eg: 1 2 3 ... 8 »)', 'gravityview'), |
|
|
|
|
21
|
|
|
'value' => false |
|
|
|
|
22
|
|
|
)); |
23
|
2 |
|
parent::__construct( __( 'Page Links', 'gravityview' ) , 'page_links', $default_values, $settings ); |
24
|
|
|
|
25
|
2 |
|
} |
26
|
|
|
|
27
|
1 |
|
public function render_frontend( $widget_args, $content = '', $context = '') { |
28
|
1 |
|
$gravityview_view = GravityView_View::getInstance(); |
29
|
|
|
|
30
|
1 |
|
if( !$this->pre_render_frontend() ) { |
|
|
|
|
31
|
|
|
return; |
32
|
|
|
} |
33
|
|
|
|
34
|
1 |
|
$atts = shortcode_atts( array( |
35
|
1 |
|
'page_size' => \GV\Utils::get( $gravityview_view->paging, 'page_size' ), |
|
|
|
|
36
|
1 |
|
'total' => $gravityview_view->total_entries, |
|
|
|
|
37
|
1 |
|
'show_all' => !empty( $this->settings['show_all']['default'] ), |
|
|
|
|
38
|
1 |
|
'current' => (int) \GV\Utils::_GET( 'pagenum', 1 ), |
39
|
1 |
|
), $widget_args, 'gravityview_widget_page_links' ); |
40
|
|
|
|
41
|
|
|
$page_link_args = array( |
42
|
1 |
|
'base' => add_query_arg('pagenum','%#%', gv_directory_link() ), |
|
|
|
|
43
|
1 |
|
'format' => '&pagenum=%#%', |
44
|
|
|
'add_args' => array(), // |
45
|
1 |
|
'prev_text' => '«', |
46
|
1 |
|
'next_text' => '»', |
47
|
1 |
|
'type' => 'list', |
48
|
1 |
|
'end_size' => 1, |
49
|
1 |
|
'mid_size' => 2, |
50
|
1 |
|
'total' => empty( $atts['page_size'] ) ? 0 : ceil( $atts['total'] / $atts['page_size'] ), |
51
|
1 |
|
'current' => $atts['current'], |
52
|
1 |
|
'show_all' => !empty( $atts['show_all'] ), // to be available at backoffice |
|
|
|
|
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @filter `gravityview_page_links_args` Filter the pagination options |
57
|
|
|
* @since 1.1.4 |
58
|
|
|
* @param array $page_link_args Array of arguments for the `paginate_links()` function. [Read more about `paginate_links()`](http://developer.wordpress.org/reference/functions/paginate_links/) |
59
|
|
|
*/ |
60
|
1 |
|
$page_link_args = apply_filters('gravityview_page_links_args', $page_link_args ); |
|
|
|
|
61
|
|
|
|
62
|
1 |
|
$page_links = paginate_links( $page_link_args ); |
63
|
|
|
|
64
|
1 |
|
if( !empty( $page_links )) { |
|
|
|
|
65
|
1 |
|
$class = !empty( $widget_args['custom_class'] ) ? $widget_args['custom_class'] : ''; |
|
|
|
|
66
|
1 |
|
$class = gravityview_sanitize_html_class( 'gv-widget-page-links ' . $class ); |
67
|
1 |
|
echo '<div class="'.$class.'">'. $page_links .'</div>'; |
|
|
|
|
68
|
|
|
} else { |
69
|
|
|
gravityview()->log->debug( 'No page links; paginate_links() returned empty response.' ); |
70
|
|
|
} |
71
|
|
|
|
72
|
1 |
|
} |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
new GravityView_Widget_Page_Links; |
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.