Skip to content

Commit

Permalink
Merge pull request #61 from bu-ist/release/1.2.21
Browse files Browse the repository at this point in the history
Release/1.2.21
  • Loading branch information
jdub233 authored Sep 4, 2020
2 parents d6f6e18 + 4f0c545 commit 12a494b
Show file tree
Hide file tree
Showing 14 changed files with 6,051 additions and 1,118 deletions.
180 changes: 118 additions & 62 deletions bu-navigation.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
<?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.20
Text Domain: bu-navigation
Domain Path: /languages
*/

/**
Copyright 2014 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
* 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.21
* Text Domain: bu-navigation
* Domain Path: /languages
* License: GPL2+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*
* @package BU_Navigation
*/

**/
/**
* Copyright 2014 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]>
Expand All @@ -37,41 +40,67 @@
@author Andrew Bauer <[email protected]>
*/

// Absolute server path to this plugin dir and file for use by included files
// 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
// Primary navigation max items to display per level.
define( 'BU_NAVIGATION_PRIMARY_MAX', 6 );

// Primary navigation maxium depth
// 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';

/**
* Convenience class to wrap loading and init functions.
*/
class BU_Navigation_Plugin {

// Admin object
/**
* Singleton object that handles loading and initialization for the Admin interface.
*
* @var object $admin Instance of the BU_Navigation_Admin class.
*/
public $admin;

// Plugin settings
/**
* Singleton object that handles settings that affect the entire plugin.
*
* @var object $settings Instance of the BU_Navigation_Settings class.
*/
public $settings;

const VERSION = '1.2.20';
/**
* Plugin version number.
*
* Useful for cache busting on enqueued assets.
*
* @var string
*/
const VERSION = '1.2.21';

/**
* Plugin class constructor.
*
* Instantiates the settings object and registers hooks.
*
* @return void
*/
public function __construct() {

$this->settings = new BU_Navigation_Settings( $this );

$this->register_hooks();

}

/**
* Attach WordPress hook callbacks
*
* @return void
*/
public function register_hooks() {

Expand All @@ -81,6 +110,14 @@ public function register_hooks() {

}

/**
* Calls wp_cache_add_non_persistent_groups()
*
* Calling wp_cache_add_non_persistent_groups() doesn't appear to do anything
* in modern WordPress?
*
* @return void
*/
public function add_cache_groups() {
if ( function_exists( 'wp_cache_add_non_persistent_groups' ) ) {
wp_cache_add_non_persistent_groups( array( 'bu-navigation' ) );
Expand All @@ -97,55 +134,63 @@ public function init() {

load_plugin_textdomain( 'bu-navigation', false, plugin_basename( dirname( __FILE__ ) ) . '/languages/' );

if( defined( 'BU_TS_IS_LOADED' ) ) {
if ( defined( 'BU_TS_IS_LOADED' ) ) {
require_once BU_NAV_PLUGIN_DIR . '/tests/lettuce/sandbox-setup.php';
}

$this->load_extras();

if( is_admin() ) {
if ( is_admin() ) {
$this->load_admin();
}

do_action('bu_navigation_init');
do_action( 'bu_navigation_init' );

}

/**
* Loads admin.php and instantiates the admin object.
*
* @return void
*/
public function load_admin() {

require_once(dirname(__FILE__) . '/admin/admin.php');
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() || !$this->supports( 'widget' ) )
if ( ! is_blog_installed() || ! $this->supports( 'widget' ) ) {
return;
}

require_once(dirname(__FILE__) . '/bu-navigation-widget.php'); // Content navigation widget
register_widget('BU_Widget_Pages');
require_once dirname( __FILE__ ) . '/bu-navigation-widget.php';
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);
$pattern = sprintf( '%s/extras/*.php', BU_NAV_PLUGIN_DIR );

$files = glob($pattern);
$files = glob( $pattern );

if ((is_array($files)) && (count($files) > 0)) {
foreach ($files as $filename) {
@include_once($filename);
if ( ( is_array( $files ) ) && ( count( $files ) > 0 ) ) {
foreach ( $files as $filename ) {
@include_once $filename;
}
}

Expand All @@ -160,25 +205,27 @@ public function load_extras() {
* 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)
* - 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)
* - 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)
*
* @return array Array of supported feature defaults.
*/
public function features() {

return array(
'manager' => true,
'widget' => true,
'links' => true,
'widget' => true,
'links' => true,
'primary' => false,
);
);

}

Expand All @@ -190,10 +237,13 @@ public function features() {
* 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)
*
* @param string $feature Name of the feature.
* @return boolean Whether or not the feature is supported.
*/
public function supports( $feature ) {

$feature = strtolower( $feature );
$feature = strtolower( $feature );
$defaults = $this->features();

if ( ! in_array( $feature, array_keys( $defaults ) ) ) {
Expand All @@ -203,8 +253,8 @@ public function supports( $feature ) {

$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];
$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 ) );
Expand All @@ -216,20 +266,26 @@ public function supports( $feature ) {
*
* @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)
* @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 = 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 )
if ( 'names' == $output ) {
$post_types[ BU_NAVIGATION_LINK_POST_TYPE ] = BU_NAVIGATION_LINK_POST_TYPE;
else
} else {
$post_types[ BU_NAVIGATION_LINK_POST_TYPE ] = get_post_type_object( BU_NAVIGATION_LINK_POST_TYPE );
}
}

return $post_types;
Expand All @@ -247,14 +303,14 @@ public function log() {
return;
}

$args = func_get_args();
$args = func_get_args();
$args[0] = sprintf( '[bu-navigation] %s', $args[0] );
error_log( call_user_func_array( 'sprintf', $args ) );
}

}

// Instantiate plugin (only once)
if( ! isset( $GLOBALS['bu_navigation_plugin'] ) ) {
// Instantiate plugin (only once).
if ( ! isset( $GLOBALS['bu_navigation_plugin'] ) ) {
$GLOBALS['bu_navigation_plugin'] = new BU_Navigation_Plugin();
}
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
"require": {},
"require-dev": {
"phpunit/phpunit": "4.3.*",
"codeclimate/php-test-reporter": "dev-master"
"codeclimate/php-test-reporter": "dev-master",
"dealerdirect/phpcodesniffer-composer-installer": "^0.4.3",
"squizlabs/php_codesniffer": "3.*",
"wp-coding-standards/wpcs": "^0.14.0"
}
}
Loading

0 comments on commit 12a494b

Please sign in to comment.