This repository has been archived by the owner on Sep 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpagebar2.php
263 lines (232 loc) · 10.3 KB
/
pagebar2.php
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
/*
Plugin Name: Pagebar2
Plugin URI: http://www.elektroelch.de/hacks/wp/pagebar
Description: Adds an advanced page navigation to Wordpress.
Version: 2.65
Requires at least: 3.3
Tested up to: 3.7
Tags: navigation, pagination
Stable tag: trunk
Author: Lutz Schröer
Author URI: http://elektroelch.de/blog
*/
/* This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* ------------------------------------------------------------------------------- */
// determine the path of the plugin
// stolen from Commentmix
if (!defined('PLUGIN_URL'))
define('PLUGIN_URL', get_option('siteurl').'/wp-content/plugins/');
if (!defined('PLUGIN_PATH'))
define('PLUGIN_PATH', ABSPATH.'wp-content/plugins/');
define('PAGEBAR_URL', PLUGIN_URL . dirname(plugin_basename(__FILE__)).'/');
define('PAGEBAR_PATH', PLUGIN_PATH . dirname(plugin_basename(__FILE__)).'/');
/* -------------------------------------------------------------------------- */
function is_main_loop() {
global $wp_query, $wp_the_query;
if ($wp_the_query === $wp_query) {
return true;
}
return false;
}
/* -------------------------------------------------------------------------- */
function automagic_postbar($query) {
global $paged, $wp_query, $pbOptions;
// no automagic insertion if we're not in the main loop
if ( $pbOptions['auto'] && ! ($wp_query->is_main_query()) )
return;
postbar();
}
/* ------------------------------------------------------------------------------- */
function postbar() {
global $paged, $wp_query, $pbOptions;
require_once('class-postbar.php');
$pagebar = new Postbar($paged, intval($wp_query->max_num_pages));
}
/* ------------------------------------------------------------------------------- */
function pagebar() { // for compatibility with pagebar v2.21
postbar();
}
/* ------------------------------------------------------------------------------- */
function wp_pagebar() { // for compatibility with pagebar v2.21
postbar();
}
/* ------------------------------------------------------------------------------- */
function multipagebar () {
global $page, $numpages;
require_once('class-multipagebar.php');
$multipagebar = new Multipagebar($page, $numpages);
} //multipagebar()
/* ------------------------------------------------------------------------------- */
function commentbar() {
global $wp_query;
require_once('class-commentbar.php');
$paged = intval(get_query_var('cpage'));
$max_page = intval($wp_query->max_num_comment_pages);
$commentbar = new Commentbar($paged, $max_page);
}
function pagebar_registerStylesheet($url, $handle, $pluginurl = "") {
wp_register_style($handle, $pluginurl . $url);
wp_enqueue_style($handle);
wp_print_styles();
}
/* -------------------------------------------------------------------------- */
function pagebar_addUserStylesheet() {
global $pbOptions;
// use default style for default themes
$stylesheet = get_stylesheet();
if (in_array($stylesheet, array('twentyten', 'twentyeleven', 'twentytwelve', 'twentythirteen', 'twentyfourteen')))
pagebar_registerStylesheet(plugin_dir_url(__FILE__) . 'css/' . $stylesheet . '.css', 'preset_css');
if ($pbOptions["stylesheet"] != "styleCss")
pagebar_registerStylesheet(get_bloginfo('stylesheet_directory')
. '/' . $pbOptions["cssFilename"],
'pagebar-stylesheet');
}
/* -------------------------------------------------------------------------- */
function pagebar_activate() {
require_once "activate.php";
} //pagebar_activate()
/* -------------------------------------------------------------------------- */
/* add Settings link to plugin page */
function pagebar_addConfigureLink( $links ) { // add Settings link to plugin page
$settings_link = '<a href="options-general.php?page=pagebar_options.php">'. __('Settings').'</a>';
array_unshift( $links, $settings_link );
return $links;
} //addConfigureLink()
/* -------------------------------------------------------------------------- */
// pagebar >= v2.5 requires PHP>=5 and WP>=2.7, check and disable update if
// necessary.
function pagebar_plugin_prevent_upgrade($opt) {
global $wp_version, $min_wp, $min_php;
$min_php = '5.0.0';
$min_wp = '2.7';
if ( (version_compare(PHP_VERSION, $min_php, '<')) || (version_compare($wp_version, $min_wp, '<')) ) {
$plugin = plugin_basename(__FILE__);
if ( $opt && isset($opt->response[$plugin]) ) {
//Theres an update. Remove automatic upgrade:
$opt->response[$plugin]->package = '';
//Now we've prevented the upgrade taking place, It might be worth to give users a note that theres an update available:
add_action("after_plugin_row_$plugin", 'pagebar_plugin_update_disabled_notice');
} //if
} //if
return $opt;
} //plugin_prevent_update()
/* -------------------------------------------------------------------------- */
function pagebar_plugin_update_disabled_notice() {
global $wp_version, $min_wp, $min_php;
echo '<tr><td class="plugin-update" colspan="5">';
echo 'There is an update available for this plugin. However the plugin requires';
if (version_compare(PHP_VERSION, $min_php, '<'))
echo ' PHP v'.$min_php.' or newer';
if ( (version_compare(PHP_VERSION, $min_php, '<')) && (version_compare($wp_version, $min_wp, '<')) )
echo ' and';
if (version_compare($wp_version, $min_wp, '<'))
echo ' WordPress v'.$min_wp.' or newer.';
echo '</td></tr>';
} //plugin_update_disabled_notice()
/* -------------------------------------------------------------------------- */
// add filter for displaying complete paged page
add_filter('the_content', 'pb_allpage_show', 0);
function pb_allpage_show($content) {
global $multipage, $page, $posts, $numpages, $page_comments, $wp_query;
if ($multipage && $all_page = get_query_var('all')) {
$content = $posts[0]->post_content;
}
return $content;
}
/* -------------------------------------------------------------------------- */
// add filter to override the paging of comments if the user
// clicked "all comments"
//add_filter('pre_option_page_comments','override_page_comments');
//function override_page_comments() {
// return (is_singular() && $all_page = get_query_var('all')) ? 0 : 1;
//}
/* -------------------------------------------------------------------------- */
// add filter to allow URL parameter "all"
add_action('init', 'pb_allpage_permalink', 99);
function pb_allpage_permalink() {
global $wp_rewrite;
$wp_rewrite->add_endpoint("all", EP_ALL);
$wp_rewrite->flush_rules(false);
}
/* -------------------------------------------------------------------------- */
function pb_remove_nav() {
if (! is_single ())
echo "\n<style type=\"text/css\">.navigation{display: none;}</style>\n";
echo "\n<style type=\"text/css\">#nav-below{display: none;}</style>\n";
}
/* -------------------------------------------------------------------------- */
// add filter to allow URL parameter "all"
add_filter('query_vars', 'pb_AllPageEndpointQueryVarsFilter');
function pb_AllPageEndpointQueryVarsFilter($vars){
$vars[] = 'all';
return $vars;
}
/* -------------------------------------------------------------------------- */
function register_pagebar_settings() {
register_setting('pagebar-options', 'postbar');
register_setting('pagebar-options', 'multipagebar');
register_setting('pagebar-options', 'commentbar');
}/* -------------------------------------------------------------------------- */
function detect_theme() {
// $stylesheet = get_stylesheet();
// if ($stylesheet = "twentyten") {
//
// $handle = 'detected_css';
// wp_register_style($handle, plugin_dir_url(__FILE__) . 'css/' . $stylesheet . '.css');
// wp_enqueue_style($handle);
// wp_print_styles();
//
//// pagebar_registerStylesheet('preset_css', plugin_dir_url(__FILE__) . 'css/' . $stylesheet . '.css');
// }
}
/* -------------------------------------------------------------------------- */
/* main() */
// load language file
$pagebar_dir = trailingslashit(WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__)));
$locale = get_locale();
$mofile = $pagebar_dir.'language/pagebar-'.$locale.'.mo';
load_textdomain('pagebar', $mofile);
if (is_admin()) {
require ('pagebar_options.php');
add_action ( 'admin_print_scripts', array(&$pagebaroptions, 'pb_load_jquery'));
//$pagebaroptions->pb_load_jquery();
$plugin = plugin_basename(__FILE__);
add_filter("plugin_action_links_$plugin", 'pagebar_addConfigureLink' );
add_action('admin_init', 'register_pagebar_settings');
}
// add filter to prevent updates if PHP<5 and Wp<2.7
if (in_array($pagenow, array("plugins.php")))
add_filter('option_update_plugins', 'pagebar_plugin_prevent_upgrade');
// we need to load the postbar option outside the classes since the actions
// need to be started. There may be an different solution but I did not find one.
if (! $pbOptions = get_option ( 'postbar' )) {
pagebar_activate();
$pbOptions = get_option('postbar');
};
// add_action ( 'activate_'.dirname(plugin_basename(__FILE__)).'/pagebar.php', 'pagebar_activate' );
// register_activation_hook( __FILE__, 'pagebar_activate' );
add_action ( 'wp_head', 'pagebar_addUserStylesheet');
// add_action ( 'wp_print_styles', 'detect_theme');
//add_action ( 'wp_print_styles', 'pagebar_addUserStylesheet');
if ($pbOptions ['auto'] && in_array($pagenow, array("index.php"))) {
if ($pbOptions ["bef_loop"] == "on")
add_action ( 'loop_start', 'automagic_postbar' );
if ($pbOptions ["aft_loop"] == "on")
add_action ( 'loop_end', 'automagic_postbar' );
if ($pbOptions ["footer"] == "on")
add_action ( 'wp_footer', 'automagic_postbar' );
if ($pbOptions ["remove"] == "on")
add_action ( 'wp_head', 'pb_remove_nav' );
} //if