forked from bu-ist/bu-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbu-navigation.php
241 lines (183 loc) · 6.76 KB
/
bu-navigation.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
<?php
/*
Plugin Name: BU Navigation
Plugin URI: http://developer.bu.edu/bu-navigation/
Author: Boston University (IS&T)
Author URI: http://sites.bu.edu/web/
Description: Provides alternative navigation elements designed for blogs with large page counts
Version: 1.2.1
Text Domain: bu-navigation
Domain Path: /languages
*/
/**
Copyright 2012 by Boston University
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
**/
/*
@author Niall Kavanagh <[email protected]>
@author Gregory Cornelius <[email protected]>
@author Mike Burns <[email protected]>
@author Tyler Wiest <[email protected]>
*/
// Absolute server path to this plugin dir and file for use by included files
define( 'BU_NAV_PLUGIN', __FILE__ );
define( 'BU_NAV_PLUGIN_DIR', dirname( __FILE__ ) );
// Primary navigation max items to display per level
define( 'BU_NAVIGATION_PRIMARY_MAX', 6 );
// Primary navigation maxium depth
define( 'BU_NAVIGATION_PRIMARY_DEPTH', 1 );
require_once BU_NAV_PLUGIN_DIR . '/includes/settings.php';
require_once BU_NAV_PLUGIN_DIR . '/includes/library.php';
require_once BU_NAV_PLUGIN_DIR . '/includes/class-tree-view.php';
require_once BU_NAV_PLUGIN_DIR . '/includes/class-reorder.php';
class BU_Navigation_Plugin {
// Admin object
public $admin;
// Plugin settings
public $settings;
const VERSION = '1.2.1';
public function __construct() {
$this->settings = new BU_Navigation_Settings( $this );
$this->register_hooks();
}
/**
* Attach WordPress hook callbacks
*/
public function register_hooks() {
add_action( 'plugins_loaded', array( $this, 'add_cache_groups' ) );
add_action( 'init', array( $this, 'init' ), 1 );
}
public function add_cache_groups() {
if ( function_exists( 'wp_cache_add_non_persistent_groups' ) ) {
wp_cache_add_non_persistent_groups( array( 'bu-navigation' ) );
}
}
/**
* Initialization function for navigation plugin
*
* @hook init
* @return void
*/
public function init() {
load_plugin_textdomain( 'bu-navigation', false, plugin_basename( dirname( __FILE__ ) ) . '/languages/' );
$this->load_extras();
if( is_admin() ) {
$this->load_admin();
}
if ( $this->supports( 'widget' ) )
$this->load_widget();
do_action('bu_navigation_init');
}
public function load_admin() {
require_once(dirname(__FILE__) . '/admin/admin.php');
$this->admin = new BU_Navigation_Admin( $this );
}
/**
* Initializes navigation widgets
* @return void
*/
public function load_widget() {
if ( !is_blog_installed() )
return;
require_once(dirname(__FILE__) . '/bu-navigation-widget.php'); // Content navigation widget
register_widget('BU_Widget_Pages');
}
/**
* Loads plugins for this... plugin
* Any .php file placed in the extras directory will be automatically loaded.
* @return void
*/
public function load_extras() {
$pattern = sprintf('%s/extras/*.php', BU_NAV_PLUGIN_DIR);
$files = glob($pattern);
if ((is_array($files)) && (count($files) > 0)) {
foreach ($files as $filename) {
@include_once($filename);
}
}
}
/**
* Navigation plugin features
*
* @todo discuss these open source defaults with BU
*
* The navigation plugin is configurable in a few different regards. This function returns an associative array
* of features, with the key representing the feature name and the value holding the default.
*
* bu-navigation-manager (on by default)
* - turn on or off the navigation management interfaces ("Edit Order" pages, "Navigation Attributes" metabox)
*
* bu-navigation-widget (on by default)
* - turn on or off the "Content Navigation" widget (on by default)
*
* bu-navigation-primary (off by default -- theme authors, use add_theme_support( 'bu-navigation-primary' ))
* - turn on or off the "Primary Navigation" appearance menu item
*
* bu-navigation-links
* - turn on or off the external link feature, include with 'page' post type nav menus (on by default)
*/
public function features() {
return array(
'manager' => true,
'widget' => true,
'links' => true,
'primary' => false,
);
}
/**
* Does the current install or theme support a navigation feature?
*
* There are two different ways to configure navigation features -- with PHP constants, or through the Theme Features API.
*
* These work as follows:
* 1. Define `BU_NAVIGATION_SUPPORTS_*` constant as true or false in wp-config.php or your theme's functions.php (highest priority)
* 2. Call add_theme_support( 'bu-navigation-*' ) within your theme's functions.php file (recommended for theme authors)
*/
public function supports( $feature ) {
$feature = strtolower( $feature );
$defaults = $this->features();
if ( ! in_array( $feature, array_keys( $defaults ) ) ) {
error_log( "[bu-navigation] Unknown feature: $feature" );
return false;
}
$supported_const = 'BU_NAVIGATION_SUPPORTS_' . strtoupper( $feature );
$disabled = ( defined( $supported_const ) && constant( $supported_const ) == false );
$supported = ( defined( $supported_const ) && constant( $supported_const ) == true ) || $defaults[$feature];
$theme_supported = current_theme_supports( 'bu-navigation-' . $feature );
return ( ! $disabled && ( $supported || $theme_supported ) );
}
/**
* Gets the supported post_types by the bu-navigation plugin.
*
* @todo needs-unit-test
*
* @param boolean $include_link true|false link post_type is something special, so we don't always need it
* @param string $output type of output (names|objects)
* @return array of post_type strings or objects depending on $output param
*/
public function supported_post_types( $include_link = false, $output = 'names' ) {
$post_types = get_post_types( array( 'show_ui' => true, 'hierarchical' => true ), $output );
$post_types = apply_filters( 'bu_navigation_post_types', $post_types );
if ( $this->supports( 'links' ) && $include_link ) {
if ( 'names' == $output )
$post_types[ BU_NAVIGATION_LINK_POST_TYPE ] = BU_NAVIGATION_LINK_POST_TYPE;
else
$post_types[ BU_NAVIGATION_LINK_POST_TYPE ] = get_post_type_object( BU_NAVIGATION_LINK_POST_TYPE );
}
return $post_types;
}
}
// Instantiate plugin (only once)
if( ! isset( $bu_navigation_plugin ) ) {
$bu_navigation_plugin = new BU_Navigation_Plugin();
}