WP-Paginate - Version 1.2.4

Version Description

  • Ensure pagination of posts when wp_paginate() is called Github pull request via whacao
  • Support loading on https pages (plugin now requires WordPress 2.6+) Github pull request via hadvig
Download this release

Release Info

Developer emartin24
Plugin Icon 128x128 WP-Paginate
Version 1.2.4
Comparing to
See all releases

Code changes from version 1.2.3 to 1.2.4

Files changed (2) hide show
  1. readme.txt +31 -6
  2. wp-paginate.php +431 -430
readme.txt CHANGED
@@ -2,9 +2,9 @@
2
Contributors: emartin24
3
Donate link: http://www.ericmmartin.com/donate/
4
Tags: paginate, pagination, navigation, page, wp-paginate, comments, rtl, seo, usability
5
- Requires at least: 2.2.0 (2.7.0 for comments pagination)
6
- Tested up to: 3.1
7
- Stable tag: 1.2.3
8
9
WP-Paginate is a simple and flexible pagination plugin which provides users with better navigation on your WordPress site.
10
@@ -29,7 +29,7 @@ Translations: http://plugins.svn.wordpress.org/wp-paginate/I18n (check the versi
29
*Implement*
30
31
For posts pagination:
32
- 1) Open the theme files where you'd like pagination to be used. Usually this is the `loop.php` file. For older version of WordPress, you may need to update the `index.php`, `archive.php` and `search.php` files.
33
34
2) Replace your existing `previous_posts_link()` and `next_posts_link()` code block with the following:
35
@@ -37,6 +37,25 @@ For posts pagination:
37
wp_paginate();
38
} ?>
39
40
41
For comments pagination:
42
1) Open the theme file(s) where you'd like comments pagination to be used. Usually this is the `comments.php` file.
@@ -64,7 +83,7 @@ For comments pagination:
64
65
To 1.1.1+:
66
67
- * Update WP-Paginate settings, change `Before Markup` to <div class="navigation">
68
* Update `wp-paginate.css`, change `.wp-paginate ol` to `.wp-paginate`
69
70
== Frequently Asked Questions ==
@@ -95,7 +114,6 @@ Example (also applies to `wp_paginate_comments()`):
95
} ?>
96
97
98
-
99
= How can I style the comments pagination differently than the posts pagination? =
100
101
When calling `wp_paginate_comments()`, WP-Paginate adds an extra class to the `ol` element, `wp-paginate-comments`.
@@ -114,8 +132,15 @@ N/A
114
115
== Changelog ==
116
117
= 1.2.3 =
118
* Fixed deprecated parameter to the WordPress add_options_page() function
119
120
= 1.2.2 =
121
* Fixed a XSS vulnerability reported by Andreas Schobel (@aschobel)
2
Contributors: emartin24
3
Donate link: http://www.ericmmartin.com/donate/
4
Tags: paginate, pagination, navigation, page, wp-paginate, comments, rtl, seo, usability
5
+ Requires at least: 2.6.0 (2.7.0 for comments pagination)
6
+ Tested up to: 3.2.1
7
+ Stable tag: 1.2.4
8
9
WP-Paginate is a simple and flexible pagination plugin which provides users with better navigation on your WordPress site.
10
29
*Implement*
30
31
For posts pagination:
32
+ 1) Open the theme files where you'd like pagination to be used. Depending on your theme, this may be the `loop.php` file or the `index.php`, `archive.php` and `search.php` files. The `twentyeleven` theme places the pagination code in `functions.php` in the `twentyeleven_content_nav()` function.
33
34
2) Replace your existing `previous_posts_link()` and `next_posts_link()` code block with the following:
35
37
wp_paginate();
38
} ?>
39
40
+ For the `twentyeleven_content_nav` theme, the new function would look like:
41
+
42
+ function twentyeleven_content_nav( $nav_id ) {
43
+ global $wp_query;
44
+
45
+ if ( function_exists( 'wp_paginate' ) ) {
46
+ wp_paginate();
47
+ }
48
+ else {
49
+ if ( $wp_query->max_num_pages > 1 ) : ?>
50
+ <nav id="<?php echo $nav_id; ?>">
51
+ <h3 class="assistive-text"><?php _e( 'Post navigation', 'twentyeleven' ); ?></h3>
52
+ <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&larr;</span> Older posts', 'twentyeleven' ) ); ?></div>
53
+ <div class="nav-next"><?php previous_posts_link( __( 'Newer posts <span class="meta-nav">&rarr;</span>', 'twentyeleven' ) ); ?></div>
54
+ </nav><!-- #nav-above -->
55
+ <?php endif;
56
+ }
57
+ }
58
+
59
60
For comments pagination:
61
1) Open the theme file(s) where you'd like comments pagination to be used. Usually this is the `comments.php` file.
83
84
To 1.1.1+:
85
86
+ * Update WP-Paginate settings, change `Before Markup` to `<div class="navigation">`
87
* Update `wp-paginate.css`, change `.wp-paginate ol` to `.wp-paginate`
88
89
== Frequently Asked Questions ==
114
} ?>
115
116
117
= How can I style the comments pagination differently than the posts pagination? =
118
119
When calling `wp_paginate_comments()`, WP-Paginate adds an extra class to the `ol` element, `wp-paginate-comments`.
132
133
== Changelog ==
134
135
+ = 1.2.4 =
136
+ * Ensure pagination of posts when wp_paginate() is called
137
+ Github pull request via whacao
138
+ * Support loading on https pages (plugin now requires WordPress 2.6+)
139
+ Github pull request via hadvig
140
+
141
= 1.2.3 =
142
* Fixed deprecated parameter to the WordPress add_options_page() function
143
+ Github pull request via alexwybraniec
144
145
= 1.2.2 =
146
* Fixed a XSS vulnerability reported by Andreas Schobel (@aschobel)
wp-paginate.php CHANGED
@@ -1,431 +1,432 @@
1
- <?php
2
- /*
3
- Plugin Name: WP-Paginate
4
- Plugin URI: http://www.ericmmartin.com/projects/wp-paginate/
5
- Description: A simple and flexible pagination plugin for WordPress posts and comments.
6
- Author: Eric Martin
7
- Version: 1.2.3
8
- Author URI: http://www.ericmmartin.com
9
- Revision: $Id: wp-paginate.php 358882 2011-03-11 18:39:08Z emartin24 $
10
- */
11
-
12
- /* Copyright 2011 Eric Martin (eric@ericmmartin.com)
13
-
14
- This program is free software; you can redistribute it and/or modify
15
- it under the terms of the GNU General Public License as published by
16
- the Free Software Foundation; either version 2 of the License, or
17
- (at your option) any later version.
18
-
19
- This program is distributed in the hope that it will be useful,
20
- but WITHOUT ANY WARRANTY; without even the implied warranty of
21
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
- GNU General Public License for more details.
23
-
24
- You should have received a copy of the GNU General Public License
25
- along with this program; if not, write to the Free Software
26
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
- */
28
-
29
- /**
30
- * Set the wp-content and plugin urls/paths
31
- */
32
- if (!defined('WP_CONTENT_URL'))
33
- define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
34
- if (!defined('WP_CONTENT_DIR'))
35
- define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
36
- if (!defined('WP_PLUGIN_URL') )
37
- define('WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins');
38
- if (!defined('WP_PLUGIN_DIR') )
39
- define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins');
40
-
41
- if (!class_exists('WPPaginate')) {
42
- class WPPaginate {
43
- /**
44
- * @var string The plugin version
45
- */
46
- var $version = '1.2.3';
47
-
48
- /**
49
- * @var string The options string name for this plugin
50
- */
51
- var $optionsName = 'wp_paginate_options';
52
-
53
- /**
54
- * @var string $localizationDomain Domain used for localization
55
- */
56
- var $localizationDomain = 'wp-paginate';
57
-
58
- /**
59
- * @var string $pluginurl The url to this plugin
60
- */
61
- var $pluginurl = '';
62
- /**
63
- * @var string $pluginpath The path to this plugin
64
- */
65
- var $pluginpath = '';
66
-
67
- /**
68
- * @var array $options Stores the options for this plugin
69
- */
70
- var $options = array();
71
-
72
- var $type = 'posts';
73
-
74
- /**
75
- * PHP 4 Compatible Constructor
76
- */
77
- function WPPaginate() {$this->__construct();}
78
-
79
- /**
80
- * PHP 5 Constructor
81
- */
82
- function __construct() {
83
- $name = dirname(plugin_basename(__FILE__));
84
-
85
- //Language Setup
86
- load_plugin_textdomain($this->localizationDomain, false, "$name/I18n/");
87
-
88
- //"Constants" setup
89
- $this->pluginurl = WP_PLUGIN_URL . "/$name/";
90
- $this->pluginpath = WP_PLUGIN_DIR . "/$name/";
91
-
92
- //Initialize the options
93
- $this->get_options();
94
-
95
- //Actions
96
- add_action('admin_menu', array(&$this, 'admin_menu_link'));
97
-
98
- if ($this->options['css'])
99
- add_action('wp_print_styles', array(&$this, 'wp_paginate_css'));
100
- }
101
-
102
- /**
103
- * Pagination based on options/args
104
- */
105
- function paginate($args = false) {
106
- if ($this->type === 'comments' && !get_option('page_comments'))
107
- return;
108
-
109
- $r = wp_parse_args($args, $this->options);
110
- extract($r, EXTR_SKIP);
111
-
112
- if (!isset($page) && !isset($pages)) {
113
- global $wp_query;
114
-
115
- if ($this->type === 'posts') {
116
- $page = get_query_var('paged');
117
- $posts_per_page = intval(get_query_var('posts_per_page'));
118
- $pages = intval(ceil($wp_query->found_posts / $posts_per_page));
119
- }
120
- else {
121
- $page = get_query_var('cpage');
122
- $comments_per_page = get_option('comments_per_page');
123
- $pages = get_comment_pages_count();
124
- }
125
- $page = !empty($page) ? intval($page) : 1;
126
- }
127
-
128
- $prevlink = ($this->type === 'posts')
129
- ? esc_url(get_pagenum_link($page - 1))
130
- : get_comments_pagenum_link($page - 1);
131
- $nextlink = ($this->type === 'posts')
132
- ? esc_url(get_pagenum_link($page + 1))
133
- : get_comments_pagenum_link($page + 1);
134
-
135
- $output = stripslashes($before);
136
- if ($pages > 1) {
137
- $output .= sprintf('<ol class="wp-paginate%s">', ($this->type === 'posts') ? '' : ' wp-paginate-comments');
138
- $output .= sprintf('<li><span class="title">%s</span></li>', stripslashes($title));
139
- $ellipsis = "<li><span class='gap'>...</span></li>";
140
-
141
- if ($page > 1 && !empty($previouspage)) {
142
- $output .= sprintf('<li><a href="%s" class="prev">%s</a></li>', $prevlink, stripslashes($previouspage));
143
- }
144
-
145
- $min_links = $range * 2 + 1;
146
- $block_min = min($page - $range, $pages - $min_links);
147
- $block_high = max($page + $range, $min_links);
148
- $left_gap = (($block_min - $anchor - $gap) > 0) ? true : false;
149
- $right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false;
150
-
151
- if ($left_gap && !$right_gap) {
152
- $output .= sprintf('%s%s%s',
153
- $this->paginate_loop(1, $anchor),
154
- $ellipsis,
155
- $this->paginate_loop($block_min, $pages, $page)
156
- );
157
- }
158
- else if ($left_gap && $right_gap) {
159
- $output .= sprintf('%s%s%s%s%s',
160
- $this->paginate_loop(1, $anchor),
161
- $ellipsis,
162
- $this->paginate_loop($block_min, $block_high, $page),
163
- $ellipsis,
164
- $this->paginate_loop(($pages - $anchor + 1), $pages)
165
- );
166
- }
167
- else if ($right_gap && !$left_gap) {
168
- $output .= sprintf('%s%s%s',
169
- $this->paginate_loop(1, $block_high, $page),
170
- $ellipsis,
171
- $this->paginate_loop(($pages - $anchor + 1), $pages)
172
- );
173
- }
174
- else {
175
- $output .= $this->paginate_loop(1, $pages, $page);
176
- }
177
-
178
- if ($page < $pages && !empty($nextpage)) {
179
- $output .= sprintf('<li><a href="%s" class="next">%s</a></li>', $nextlink, stripslashes($nextpage));
180
- }
181
- $output .= "</ol>";
182
- }
183
- $output .= stripslashes($after);
184
-
185
- if ($pages > 1 || $empty) {
186
- echo $output;
187
- }
188
- }
189
-
190
- /**
191
- * Helper function for pagination which builds the page links.
192
- */
193
- function paginate_loop($start, $max, $page = 0) {
194
- $output = "";
195
- for ($i = $start; $i <= $max; $i++) {
196
- $p = ($this->type === 'posts') ? esc_url(get_pagenum_link($i)) : get_comments_pagenum_link($i);
197
- $output .= ($page == intval($i))
198
- ? "<li><span class='page current'>$i</span></li>"
199
- : "<li><a href='$p' title='$i' class='page'>$i</a></li>";
200
- }
201
- return $output;
202
- }
203
-
204
- function wp_paginate_css() {
205
- $name = "wp-paginate.css";
206
- if (false !== @file_exists(TEMPLATEPATH . "/$name")) {
207
- $css = get_template_directory_uri() . "/$name";
208
- }
209
- else {
210
- $css = $this->pluginurl . $name;
211
- }
212
- wp_enqueue_style('wp-paginate', $css, false, $this->version, 'screen');
213
-
214
- if (function_exists('is_rtl') && is_rtl()) {
215
- $name = "wp-paginate-rtl.css";
216
- if (false !== @file_exists(TEMPLATEPATH . "/$name")) {
217
- $css = get_template_directory_uri() . "/$name";
218
- }
219
- else {
220
- $css = $this->pluginurl . $name;
221
- }
222
- wp_enqueue_style('wp-paginate-rtl', $css, false, $this->version, 'screen');
223
- }
224
- }
225
-
226
- /**
227
- * Retrieves the plugin options from the database.
228
- * @return array
229
- */
230
- function get_options() {
231
- if (!$options = get_option($this->optionsName)) {
232
- $options = array(
233
- 'title' => 'Pages:',
234
- 'nextpage' => '&raquo;',
235
- 'previouspage' => '&laquo;',
236
- 'css' => true,
237
- 'before' => '<div class="navigation">',
238
- 'after' => '</div>',
239
- 'empty' => true,
240
- 'range' => 3,
241
- 'anchor' => 1,
242
- 'gap' => 3
243
- );
244
- update_option($this->optionsName, $options);
245
- }
246
- $this->options = $options;
247
- }
248
- /**
249
- * Saves the admin options to the database.
250
- */
251
- function save_admin_options(){
252
- return update_option($this->optionsName, $this->options);
253
- }
254
-
255
- /**
256
- * @desc Adds the options subpanel
257
- */
258
- function admin_menu_link() {
259
- add_options_page('WP-Paginate', 'WP-Paginate', 'manage_options', basename(__FILE__), array(&$this, 'admin_options_page'));
260
- add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'filter_plugin_actions'), 10, 2 );
261
- }
262
-
263
- /**
264
- * @desc Adds the Settings link to the plugin activate/deactivate page
265
- */
266
- function filter_plugin_actions($links, $file) {
267
- $settings_link = '<a href="options-general.php?page=' . basename(__FILE__) . '">' . __('Settings', $this->localizationDomain) . '</a>';
268
- array_unshift($links, $settings_link); // before other links
269
-
270
- return $links;
271
- }
272
-
273
- /**
274
- * Adds settings/options page
275
- */
276
- function admin_options_page() {
277
- if (isset($_POST['wp_paginate_save'])) {
278
- if (wp_verify_nonce($_POST['_wpnonce'], 'wp-paginate-update-options')) {
279
- $this->options['title'] = $_POST['title'];
280
- $this->options['previouspage'] = $_POST['previouspage'];
281
- $this->options['nextpage'] = $_POST['nextpage'];
282
- $this->options['before'] = $_POST['before'];
283
- $this->options['after'] = $_POST['after'];
284
- $this->options['empty'] = (isset($_POST['empty']) && $_POST['empty'] === 'on') ? true : false;
285
- $this->options['css'] = (isset($_POST['css']) && $_POST['css'] === 'on') ? true : false;
286
- $this->options['range'] = intval($_POST['range']);
287
- $this->options['anchor'] = intval($_POST['anchor']);
288
- $this->options['gap'] = intval($_POST['gap']);
289
-
290
- $this->save_admin_options();
291
-
292
- echo '<div class="updated"><p>' . __('Success! Your changes were successfully saved!', $this->localizationDomain) . '</p></div>';
293
- }
294
- else {
295
- echo '<div class="error"><p>' . __('Whoops! There was a problem with the data you posted. Please try again.', $this->localizationDomain) . '</p></div>';
296
- }
297
- }
298
- ?>
299
-
300
- <div class="wrap">
301
- <div class="icon32" id="icon-options-general"><br/></div>
302
- <h2>WP-Paginate</h2>
303
- <form method="post" id="wp_paginate_options">
304
- <?php wp_nonce_field('wp-paginate-update-options'); ?>
305
- <table class="form-table">
306
- <tr valign="top">
307
- <th scope="row"><?php _e('Pagination Label:', $this->localizationDomain); ?></th>
308
- <td><input name="title" type="text" id="title" size="40" value="<?php echo stripslashes(htmlspecialchars($this->options['title'])); ?>"/>
309
- <span class="description"><?php _e('The text/HTML to display before the list of pages.', $this->localizationDomain); ?></span></td>
310
- </tr>
311
- <tr valign="top">
312
- <th scope="row"><?php _e('Previous Page:', $this->localizationDomain); ?></th>
313
- <td><input name="previouspage" type="text" id="previouspage" size="40" value="<?php echo stripslashes(htmlspecialchars($this->options['previouspage'])); ?>"/>
314
- <span class="description"><?php _e('The text/HTML to display for the previous page link.', $this->localizationDomain); ?></span></td>
315
- </tr>
316
- <tr valign="top">
317
- <th scope="row"><?php _e('Next Page:', $this->localizationDomain); ?></th>
318
- <td><input name="nextpage" type="text" id="nextpage" size="40" value="<?php echo stripslashes(htmlspecialchars($this->options['nextpage'])); ?>"/>
319
- <span class="description"><?php _e('The text/HTML to display for the next page link.', $this->localizationDomain); ?></span></td>
320
- </tr>
321
- </table>
322
- <p>&nbsp;</p>
323
- <h3><?php _e('Advanced Settings', $this->localizationDomain); ?></h3>
324
- <table class="form-table">
325
- <tr valign="top">
326
- <th scope="row"><?php _e('Before Markup:', $this->localizationDomain); ?></th>
327
- <td><input name="before" type="text" id="before" size="40" value="<?php echo stripslashes(htmlspecialchars($this->options['before'])); ?>"/>
328
- <span class="description"><?php _e('The HTML markup to display before the pagination code.', $this->localizationDomain); ?></span></td>
329
- </tr>
330
- <tr valign="top">
331
- <th scope="row"><?php _e('After Markup:', $this->localizationDomain); ?></th>
332
- <td><input name="after" type="text" id="after" size="40" value="<?php echo stripslashes(htmlspecialchars($this->options['after'])); ?>"/>
333
- <span class="description"><?php _e('The HTML markup to display after the pagination code.', $this->localizationDomain); ?></span></td>
334
- </tr>
335
- <tr valign="top">
336
- <th scope="row"><?php _e('Markup Display:', $this->localizationDomain); ?></th>
337
- <td><label for="empty">
338
- <input type="checkbox" id="empty" name="empty" <?php echo ($this->options['empty'] === true) ? "checked='checked'" : ""; ?>/> <?php _e('Show Before Markup and After Markup, even if the page list is empty?', $this->localizationDomain); ?></label></td>
339
- </tr>
340
- <tr valign="top">
341
- <th scope="row"><?php _e('WP-Paginate CSS File:', $this->localizationDomain); ?></th>
342
- <td><label for="css">
343
- <input type="checkbox" id="css" name="css" <?php echo ($this->options['css'] === true) ? "checked='checked'" : ""; ?>/> <?php printf(__('Include the default stylesheet wp-paginate.css? WP-Paginate will first look for <code>wp-paginate.css</code> in your theme directory (<code>themes/%s</code>).', $this->localizationDomain), get_template()); ?></label></td>
344
- </tr>
345
- <tr valign="top">
346
- <th scope="row"><?php _e('Page Range:', $this->localizationDomain); ?></th>
347
- <td>
348
- <select name="range" id="range">
349
- <?php for ($i=1; $i<=10; $i++) : ?>
350
- <option value="<?php echo $i; ?>" <?php echo ($i == $this->options['range']) ? "selected='selected'" : ""; ?>><?php echo $i; ?></option>
351
- <?php endfor; ?>
352
- </select>
353
- <span class="description"><?php _e('The number of page links to show before and after the current page. Recommended value: 3', $this->localizationDomain); ?></span></td>
354
- </tr>
355
- <tr valign="top">
356
- <th scope="row"><?php _e('Page Anchors:', $this->localizationDomain); ?></th>
357
- <td>
358
- <select name="anchor" id="anchor">
359
- <?php for ($i=1; $i<=10; $i++) : ?>
360
- <option value="<?php echo $i; ?>" <?php echo ($i == $this->options['anchor']) ? "selected='selected'" : ""; ?>><?php echo $i; ?></option>
361
- <?php endfor; ?>
362
- </select>
363
- <span class="description"><?php _e('The number of links to always show at beginning and end of pagination. Recommended value: 1', $this->localizationDomain); ?></span></td>
364
- </tr>
365
- <tr valign="top">
366
- <th scope="row"><?php _e('Page Gap:', $this->localizationDomain); ?></th>
367
- <td>
368
- <select name="gap" id="gap">
369
- <?php for ($i=1; $i<=10; $i++) : ?>
370
- <option value="<?php echo $i; ?>" <?php echo ($i == $this->options['gap']) ? "selected='selected'" : ""; ?>><?php echo $i; ?></option>
371
- <?php endfor; ?>
372
- </select>
373
- <span class="description"><?php _e('The minimum number of pages in a gap before an ellipsis (...) is added. Recommended value: 3', $this->localizationDomain); ?></span></td>
374
- </tr>
375
- </table>
376
- <p class="submit">
377
- <input type="submit" value="Save Changes" name="wp_paginate_save" class="button-primary" />
378
- </p>
379
- </form>
380
- <h2><?php _e('Need Support?', $this->localizationDomain); ?></h2>
381
- <p><?php printf(__('For questions, issues or feature requests, please post them in the %s and make sure to tag the post with wp-paginate.', $this->localizationDomain), '<a href="http://wordpress.org/tags/wp-paginate?forum_id=10#postform">WordPress Forum</a>'); ?></p>
382
- <h2><?php _e('Like To Contribute?', $this->localizationDomain); ?></h2>
383
- <p><?php _e('If you would like to contribute, the following is a list of ways you can help:', $this->localizationDomain); ?></p>
384
- <ul>
385
- <li>&raquo; <?php _e('Translate WP-Paginate into your language', $this->localizationDomain); ?></li>
386
- <li>&raquo; <?php _e('Blog about or link to WP-Paginate so others can find out about it', $this->localizationDomain); ?></li>
387
- <li>&raquo; <?php _e('Report issues, provide feedback, request features, etc.', $this->localizationDomain); ?></li>
388
- <li>&raquo; <a href="http://wordpress.org/extend/plugins/wp-paginate/"><?php _e('Rate WP-Paginate on the WordPress Plugins Page', $this->localizationDomain); ?></a></li>
389
- <li>&raquo; <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=KUL9VQ6U5VYCE&lc=US&item_name=Eric%20Martin%20%28ericmmartin%2ecom%29&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"><?php _e('Make a donation', $this->localizationDomain); ?></a></li>
390
- </ul>
391
- <h2><?php _e('Other Links', $this->localizationDomain); ?></h2>
392
- <ul>
393
- <li>&raquo; <a href="http://twitter.com/ericmmartin">@ericmmartin</a> on Twitter</li>
394
- <li>&raquo; <a href="http://www.ericmmartin.com">EricMMartin.com</a></li>
395
- <li>&raquo; <a href="http://www.ericmmartin.com/projects/smcf/">SimpleModal Contact Form (SMCF) - WordPress Plugin</a></li>
396
- <li>&raquo; <a href="http://www.ericmmartin.com/projects/simplemodal-login/">SimpleModal Login - WordPress Plugin</a></li>
397
- </ul>
398
- </div>
399
-
400
- <?php
401
- }
402
- }
403
- }
404
-
405
- //instantiate the class
406
- if (class_exists('WPPaginate')) {
407
- $wp_paginate = new WPPaginate();
408
- }
409
-
410
- /**
411
- * Pagination function to use for posts
412
- */
413
- function wp_paginate($args = false) {
414
- global $wp_paginate;
415
- return $wp_paginate->paginate($args);
416
- }
417
-
418
- /**
419
- * Pagination function to use for post comments
420
- */
421
- function wp_paginate_comments($args = false) {
422
- global $wp_paginate;
423
- $wp_paginate->type = 'comments';
424
- return $wp_paginate->paginate($args);
425
- }
426
-
427
- /*
428
- * The format of this plugin is based on the following plugin template:
429
- * http://pressography.com/plugins/wordpress-plugin-template/
430
- */
431
?>
1
+ <?php
2
+ /*
3
+ Plugin Name: WP-Paginate
4
+ Plugin URI: http://www.ericmmartin.com/projects/wp-paginate/
5
+ Description: A simple and flexible pagination plugin for WordPress posts and comments.
6
+ Author: Eric Martin
7
+ Version: 1.2.4
8
+ Author URI: http://www.ericmmartin.com
9
+ Revision: $Id: wp-paginate.php 467949 2011-11-26 20:03:29Z emartin24 $
10
+ */
11
+
12
+ /* Copyright 2011 Eric Martin (eric@ericmmartin.com)
13
+
14
+ This program is free software; you can redistribute it and/or modify
15
+ it under the terms of the GNU General Public License as published by
16
+ the Free Software Foundation; either version 2 of the License, or
17
+ (at your option) any later version.
18
+
19
+ This program is distributed in the hope that it will be useful,
20
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
21
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
+ GNU General Public License for more details.
23
+
24
+ You should have received a copy of the GNU General Public License
25
+ along with this program; if not, write to the Free Software
26
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
27
+ */
28
+
29
+ /**
30
+ * Set the wp-content and plugin urls/paths
31
+ */
32
+ if (!defined('WP_CONTENT_URL'))
33
+ define('WP_CONTENT_URL', get_option('siteurl') . '/wp-content');
34
+ if (!defined('WP_CONTENT_DIR'))
35
+ define('WP_CONTENT_DIR', ABSPATH . 'wp-content');
36
+ if (!defined('WP_PLUGIN_URL') )
37
+ define('WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins');
38
+ if (!defined('WP_PLUGIN_DIR') )
39
+ define('WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins');
40
+
41
+ if (!class_exists('WPPaginate')) {
42
+ class WPPaginate {
43
+ /**
44
+ * @var string The plugin version
45
+ */
46
+ var $version = '1.2.4';
47
+
48
+ /**
49
+ * @var string The options string name for this plugin
50
+ */
51
+ var $optionsName = 'wp_paginate_options';
52
+
53
+ /**
54
+ * @var string $localizationDomain Domain used for localization
55
+ */
56
+ var $localizationDomain = 'wp-paginate';
57
+
58
+ /**
59
+ * @var string $pluginurl The url to this plugin
60
+ */
61
+ var $pluginurl = '';
62
+ /**
63
+ * @var string $pluginpath The path to this plugin
64
+ */
65
+ var $pluginpath = '';
66
+
67
+ /**
68
+ * @var array $options Stores the options for this plugin
69
+ */
70
+ var $options = array();
71
+
72
+ var $type = 'posts';
73
+
74
+ /**
75
+ * PHP 4 Compatible Constructor
76
+ */
77
+ function WPPaginate() {$this->__construct();}
78
+
79
+ /**
80
+ * PHP 5 Constructor
81
+ */
82
+ function __construct() {
83
+ $name = dirname(plugin_basename(__FILE__));
84
+
85
+ //Language Setup
86
+ load_plugin_textdomain($this->localizationDomain, false, "$name/I18n/");
87
+
88
+ //"Constants" setup
89
+ $this->pluginurl = plugins_url($name) . "/";
90
+ $this->pluginpath = WP_PLUGIN_DIR . "/$name/";
91
+
92
+ //Initialize the options
93
+ $this->get_options();
94
+
95
+ //Actions
96
+ add_action('admin_menu', array(&$this, 'admin_menu_link'));
97
+
98
+ if ($this->options['css'])
99
+ add_action('wp_print_styles', array(&$this, 'wp_paginate_css'));
100
+ }
101
+
102
+ /**
103
+ * Pagination based on options/args
104
+ */
105
+ function paginate($args = false) {
106
+ if ($this->type === 'comments' && !get_option('page_comments'))
107
+ return;
108
+
109
+ $r = wp_parse_args($args, $this->options);
110
+ extract($r, EXTR_SKIP);
111
+
112
+ if (!isset($page) && !isset($pages)) {
113
+ global $wp_query;
114
+
115
+ if ($this->type === 'posts') {
116
+ $page = get_query_var('paged');
117
+ $posts_per_page = intval(get_query_var('posts_per_page'));
118
+ $pages = intval(ceil($wp_query->found_posts / $posts_per_page));
119
+ }
120
+ else {
121
+ $page = get_query_var('cpage');
122
+ $comments_per_page = get_option('comments_per_page');
123
+ $pages = get_comment_pages_count();
124
+ }
125
+ $page = !empty($page) ? intval($page) : 1;
126
+ }
127
+
128
+ $prevlink = ($this->type === 'posts')
129
+ ? esc_url(get_pagenum_link($page - 1))
130
+ : get_comments_pagenum_link($page - 1);
131
+ $nextlink = ($this->type === 'posts')
132
+ ? esc_url(get_pagenum_link($page + 1))
133
+ : get_comments_pagenum_link($page + 1);
134
+
135
+ $output = stripslashes($before);
136
+ if ($pages > 1) {
137
+ $output .= sprintf('<ol class="wp-paginate%s">', ($this->type === 'posts') ? '' : ' wp-paginate-comments');
138
+ $output .= sprintf('<li><span class="title">%s</span></li>', stripslashes($title));
139
+ $ellipsis = "<li><span class='gap'>...</span></li>";
140
+
141
+ if ($page > 1 && !empty($previouspage)) {
142
+ $output .= sprintf('<li><a href="%s" class="prev">%s</a></li>', $prevlink, stripslashes($previouspage));
143
+ }
144
+
145
+ $min_links = $range * 2 + 1;
146
+ $block_min = min($page - $range, $pages - $min_links);
147
+ $block_high = max($page + $range, $min_links);
148
+ $left_gap = (($block_min - $anchor - $gap) > 0) ? true : false;
149
+ $right_gap = (($block_high + $anchor + $gap) < $pages) ? true : false;
150
+
151
+ if ($left_gap && !$right_gap) {
152
+ $output .= sprintf('%s%s%s',
153
+ $this->paginate_loop(1, $anchor),
154
+ $ellipsis,
155
+ $this->paginate_loop($block_min, $pages, $page)
156
+ );
157
+ }
158
+ else if ($left_gap && $right_gap) {
159
+ $output .= sprintf('%s%s%s%s%s',
160
+ $this->paginate_loop(1, $anchor),
161
+ $ellipsis,
162
+ $this->paginate_loop($block_min, $block_high, $page),
163
+ $ellipsis,
164
+ $this->paginate_loop(($pages - $anchor + 1), $pages)
165
+ );
166
+ }
167
+ else if ($right_gap && !$left_gap) {
168
+ $output .= sprintf('%s%s%s',
169
+ $this->paginate_loop(1, $block_high, $page),
170
+ $ellipsis,
171
+ $this->paginate_loop(($pages - $anchor + 1), $pages)
172
+ );
173
+ }
174
+ else {
175
+ $output .= $this->paginate_loop(1, $pages, $page);
176
+ }
177
+
178
+ if ($page < $pages && !empty($nextpage)) {
179
+ $output .= sprintf('<li><a href="%s" class="next">%s</a></li>', $nextlink, stripslashes($nextpage));
180
+ }
181
+ $output .= "</ol>";
182
+ }
183
+ $output .= stripslashes($after);
184
+
185
+ if ($pages > 1 || $empty) {
186
+ echo $output;
187
+ }
188
+ }
189
+
190
+ /**
191
+ * Helper function for pagination which builds the page links.
192
+ */
193
+ function paginate_loop($start, $max, $page = 0) {
194
+ $output = "";
195
+ for ($i = $start; $i <= $max; $i++) {
196
+ $p = ($this->type === 'posts') ? esc_url(get_pagenum_link($i)) : get_comments_pagenum_link($i);
197
+ $output .= ($page == intval($i))
198
+ ? "<li><span class='page current'>$i</span></li>"
199
+ : "<li><a href='$p' title='$i' class='page'>$i</a></li>";
200
+ }
201
+ return $output;
202
+ }
203
+
204
+ function wp_paginate_css() {
205
+ $name = "wp-paginate.css";
206
+ if (false !== @file_exists(TEMPLATEPATH . "/$name")) {
207
+ $css = get_template_directory_uri() . "/$name";
208
+ }
209
+ else {
210
+ $css = $this->pluginurl . $name;
211
+ }
212
+ wp_enqueue_style('wp-paginate', $css, false, $this->version, 'screen');
213
+
214
+ if (function_exists('is_rtl') && is_rtl()) {
215
+ $name = "wp-paginate-rtl.css";
216
+ if (false !== @file_exists(TEMPLATEPATH . "/$name")) {
217
+ $css = get_template_directory_uri() . "/$name";
218
+ }
219
+ else {
220
+ $css = $this->pluginurl . $name;
221
+ }
222
+ wp_enqueue_style('wp-paginate-rtl', $css, false, $this->version, 'screen');
223
+ }
224
+ }
225
+
226
+ /**
227
+ * Retrieves the plugin options from the database.
228
+ * @return array
229
+ */
230
+ function get_options() {
231
+ if (!$options = get_option($this->optionsName)) {
232
+ $options = array(
233
+ 'title' => 'Pages:',
234
+ 'nextpage' => '&raquo;',
235
+ 'previouspage' => '&laquo;',
236
+ 'css' => true,
237
+ 'before' => '<div class="navigation">',
238
+ 'after' => '</div>',
239
+ 'empty' => true,
240
+ 'range' => 3,
241
+ 'anchor' => 1,
242
+ 'gap' => 3
243
+ );
244
+ update_option($this->optionsName, $options);
245
+ }
246
+ $this->options = $options;
247
+ }
248
+ /**
249
+ * Saves the admin options to the database.
250
+ */
251
+ function save_admin_options(){
252
+ return update_option($this->optionsName, $this->options);
253
+ }
254
+
255
+ /**
256
+ * @desc Adds the options subpanel
257
+ */
258
+ function admin_menu_link() {
259
+ add_options_page('WP-Paginate', 'WP-Paginate', 'manage_options', basename(__FILE__), array(&$this, 'admin_options_page'));
260
+ add_filter('plugin_action_links_' . plugin_basename(__FILE__), array(&$this, 'filter_plugin_actions'), 10, 2 );
261
+ }
262
+
263
+ /**
264
+ * @desc Adds the Settings link to the plugin activate/deactivate page
265
+ */
266
+ function filter_plugin_actions($links, $file) {
267
+ $settings_link = '<a href="options-general.php?page=' . basename(__FILE__) . '">' . __('Settings', $this->localizationDomain) . '</a>';
268
+ array_unshift($links, $settings_link); // before other links
269
+
270
+ return $links;
271
+ }
272
+
273
+ /**
274
+ * Adds settings/options page
275
+ */
276
+ function admin_options_page() {
277
+ if (isset($_POST['wp_paginate_save'])) {
278
+ if (wp_verify_nonce($_POST['_wpnonce'], 'wp-paginate-update-options')) {
279
+ $this->options['title'] = $_POST['title'];
280
+ $this->options['previouspage'] = $_POST['previouspage'];
281
+ $this->options['nextpage'] = $_POST['nextpage'];
282
+ $this->options['before'] = $_POST['before'];
283
+ $this->options['after'] = $_POST['after'];
284
+ $this->options['empty'] = (isset($_POST['empty']) && $_POST['empty'] === 'on') ? true : false;
285
+ $this->options['css'] = (isset($_POST['css']) && $_POST['css'] === 'on') ? true : false;
286
+ $this->options['range'] = intval($_POST['range']);
287
+ $this->options['anchor'] = intval($_POST['anchor']);
288
+ $this->options['gap'] = intval($_POST['gap']);
289
+
290
+ $this->save_admin_options();
291
+
292
+ echo '<div class="updated"><p>' . __('Success! Your changes were successfully saved!', $this->localizationDomain) . '</p></div>';
293
+ }
294
+ else {
295
+ echo '<div class="error"><p>' . __('Whoops! There was a problem with the data you posted. Please try again.', $this->localizationDomain) . '</p></div>';
296
+ }
297
+ }
298
+ ?>
299
+
300
+ <div class="wrap">
301
+ <div class="icon32" id="icon-options-general"><br/></div>
302
+ <h2>WP-Paginate</h2>
303
+ <form method="post" id="wp_paginate_options">
304
+ <?php wp_nonce_field('wp-paginate-update-options'); ?>
305
+ <table class="form-table">
306
+ <tr valign="top">
307
+ <th scope="row"><?php _e('Pagination Label:', $this->localizationDomain); ?></th>
308
+ <td><input name="title" type="text" id="title" size="40" value="<?php echo stripslashes(htmlspecialchars($this->options['title'])); ?>"/>
309
+ <span class="description"><?php _e('The text/HTML to display before the list of pages.', $this->localizationDomain); ?></span></td>
310
+ </tr>
311
+ <tr valign="top">
312
+ <th scope="row"><?php _e('Previous Page:', $this->localizationDomain); ?></th>
313
+ <td><input name="previouspage" type="text" id="previouspage" size="40" value="<?php echo stripslashes(htmlspecialchars($this->options['previouspage'])); ?>"/>
314
+ <span class="description"><?php _e('The text/HTML to display for the previous page link.', $this->localizationDomain); ?></span></td>
315
+ </tr>
316
+ <tr valign="top">
317
+ <th scope="row"><?php _e('Next Page:', $this->localizationDomain); ?></th>
318
+ <td><input name="nextpage" type="text" id="nextpage" size="40" value="<?php echo stripslashes(htmlspecialchars($this->options['nextpage'])); ?>"/>
319
+ <span class="description"><?php _e('The text/HTML to display for the next page link.', $this->localizationDomain); ?></span></td>
320
+ </tr>
321
+ </table>
322
+ <p>&nbsp;</p>
323
+ <h3><?php _e('Advanced Settings', $this->localizationDomain); ?></h3>
324
+ <table class="form-table">
325
+ <tr valign="top">
326
+ <th scope="row"><?php _e('Before Markup:', $this->localizationDomain); ?></th>
327
+ <td><input name="before" type="text" id="before" size="40" value="<?php echo stripslashes(htmlspecialchars($this->options['before'])); ?>"/>
328
+ <span class="description"><?php _e('The HTML markup to display before the pagination code.', $this->localizationDomain); ?></span></td>
329
+ </tr>
330
+ <tr valign="top">
331
+ <th scope="row"><?php _e('After Markup:', $this->localizationDomain); ?></th>
332
+ <td><input name="after" type="text" id="after" size="40" value="<?php echo stripslashes(htmlspecialchars($this->options['after'])); ?>"/>
333
+ <span class="description"><?php _e('The HTML markup to display after the pagination code.', $this->localizationDomain); ?></span></td>
334
+ </tr>
335
+ <tr valign="top">
336
+ <th scope="row"><?php _e('Markup Display:', $this->localizationDomain); ?></th>
337
+ <td><label for="empty">
338
+ <input type="checkbox" id="empty" name="empty" <?php echo ($this->options['empty'] === true) ? "checked='checked'" : ""; ?>/> <?php _e('Show Before Markup and After Markup, even if the page list is empty?', $this->localizationDomain); ?></label></td>
339
+ </tr>
340
+ <tr valign="top">
341
+ <th scope="row"><?php _e('WP-Paginate CSS File:', $this->localizationDomain); ?></th>
342
+ <td><label for="css">
343
+ <input type="checkbox" id="css" name="css" <?php echo ($this->options['css'] === true) ? "checked='checked'" : ""; ?>/> <?php printf(__('Include the default stylesheet wp-paginate.css? WP-Paginate will first look for <code>wp-paginate.css</code> in your theme directory (<code>themes/%s</code>).', $this->localizationDomain), get_template()); ?></label></td>
344
+ </tr>
345
+ <tr valign="top">
346
+ <th scope="row"><?php _e('Page Range:', $this->localizationDomain); ?></th>
347
+ <td>
348
+ <select name="range" id="range">
349
+ <?php for ($i=1; $i<=10; $i++) : ?>
350
+ <option value="<?php echo $i; ?>" <?php echo ($i == $this->options['range']) ? "selected='selected'" : ""; ?>><?php echo $i; ?></option>
351
+ <?php endfor; ?>
352
+ </select>
353
+ <span class="description"><?php _e('The number of page links to show before and after the current page. Recommended value: 3', $this->localizationDomain); ?></span></td>
354
+ </tr>
355
+ <tr valign="top">
356
+ <th scope="row"><?php _e('Page Anchors:', $this->localizationDomain); ?></th>
357
+ <td>
358
+ <select name="anchor" id="anchor">
359
+ <?php for ($i=0; $i<=10; $i++) : ?>
360
+ <option value="<?php echo $i; ?>" <?php echo ($i == $this->options['anchor']) ? "selected='selected'" : ""; ?>><?php echo $i; ?></option>
361
+ <?php endfor; ?>
362
+ </select>
363
+ <span class="description"><?php _e('The number of links to always show at beginning and end of pagination. Recommended value: 1', $this->localizationDomain); ?></span></td>
364
+ </tr>
365
+ <tr valign="top">
366
+ <th scope="row"><?php _e('Page Gap:', $this->localizationDomain); ?></th>
367
+ <td>
368
+ <select name="gap" id="gap">
369
+ <?php for ($i=1; $i<=10; $i++) : ?>
370
+ <option value="<?php echo $i; ?>" <?php echo ($i == $this->options['gap']) ? "selected='selected'" : ""; ?>><?php echo $i; ?></option>
371
+ <?php endfor; ?>
372
+ </select>
373
+ <span class="description"><?php _e('The minimum number of pages in a gap before an ellipsis (...) is added. Recommended value: 3', $this->localizationDomain); ?></span></td>
374
+ </tr>
375
+ </table>
376
+ <p class="submit">
377
+ <input type="submit" value="Save Changes" name="wp_paginate_save" class="button-primary" />
378
+ </p>
379
+ </form>
380
+ <h2><?php _e('Need Support?', $this->localizationDomain); ?></h2>
381
+ <p><?php printf(__('For questions, issues or feature requests, please post them in the %s and make sure to tag the post with wp-paginate.', $this->localizationDomain), '<a href="http://wordpress.org/tags/wp-paginate?forum_id=10#postform">WordPress Forum</a>'); ?></p>
382
+ <h2><?php _e('Like To Contribute?', $this->localizationDomain); ?></h2>
383
+ <p><?php _e('If you would like to contribute, the following is a list of ways you can help:', $this->localizationDomain); ?></p>
384
+ <ul>
385
+ <li>&raquo; <?php _e('Translate WP-Paginate into your language', $this->localizationDomain); ?></li>
386
+ <li>&raquo; <?php _e('Blog about or link to WP-Paginate so others can find out about it', $this->localizationDomain); ?></li>
387
+ <li>&raquo; <?php _e('Report issues, provide feedback, request features, etc.', $this->localizationDomain); ?></li>
388
+ <li>&raquo; <a href="http://wordpress.org/extend/plugins/wp-paginate/"><?php _e('Rate WP-Paginate on the WordPress Plugins Page', $this->localizationDomain); ?></a></li>
389
+ <li>&raquo; <a href="https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=KUL9VQ6U5VYCE&lc=US&item_name=Eric%20Martin%20%28ericmmartin%2ecom%29&currency_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted"><?php _e('Make a donation', $this->localizationDomain); ?></a></li>
390
+ </ul>
391
+ <h2><?php _e('Other Links', $this->localizationDomain); ?></h2>
392
+ <ul>
393
+ <li>&raquo; <a href="http://twitter.com/ericmmartin">@ericmmartin</a> on Twitter</li>
394
+ <li>&raquo; <a href="http://www.ericmmartin.com">EricMMartin.com</a></li>
395
+ <li>&raquo; <a href="http://www.ericmmartin.com/projects/smcf/">SimpleModal Contact Form (SMCF) - WordPress Plugin</a></li>
396
+ <li>&raquo; <a href="http://www.ericmmartin.com/projects/simplemodal-login/">SimpleModal Login - WordPress Plugin</a></li>
397
+ </ul>
398
+ </div>
399
+
400
+ <?php
401
+ }
402
+ }
403
+ }
404
+
405
+ //instantiate the class
406
+ if (class_exists('WPPaginate')) {
407
+ $wp_paginate = new WPPaginate();
408
+ }
409
+
410
+ /**
411
+ * Pagination function to use for posts
412
+ */
413
+ function wp_paginate($args = false) {
414
+ global $wp_paginate;
415
+ $wp_paginate->type = 'posts';
416
+ return $wp_paginate->paginate($args);
417
+ }
418
+
419
+ /**
420
+ * Pagination function to use for post comments
421
+ */
422
+ function wp_paginate_comments($args = false) {
423
+ global $wp_paginate;
424
+ $wp_paginate->type = 'comments';
425
+ return $wp_paginate->paginate($args);
426
+ }
427
+
428
+ /*
429
+ * The format of this plugin is based on the following plugin template:
430
+ * http://pressography.com/plugins/wordpress-plugin-template/
431
+ */
432
?>