Skip to content

Commit

Permalink
fix import bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bdolor committed Apr 11, 2019
1 parent fc99eab commit a922f4e
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 122 deletions.
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
],
"standards": [
"vendor/bin/phpcs --standard=phpcs.ruleset.xml ."
],
"standards-beautify": [
"vendor/bin/phpcbf --standard=phpcs.ruleset.xml ."
]
}
}
103 changes: 72 additions & 31 deletions inc/admin/class-textbookadmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@
* @copyright Brad Payne
*
*/

namespace PBT\Admin;

use PBT;
use \Pressbooks\Book;

class TextbookAdmin {

class TextbookAdmin extends PBT\Textbook {
protected $plugin_slug = 'pressbooks-textbook';
const VERSION = '4.2.3';
protected static $instance = null;

/**
* Initialize the plugin by loading admin scripts & styles and adding a
Expand All @@ -23,37 +28,65 @@ class TextbookAdmin extends PBT\Textbook {
*/
function __construct() {

parent::get_instance();

// Add the options page and menu item.
add_action( 'admin_menu', [ &$this, 'adminMenuAdjuster' ] );
add_action( 'admin_init', [ &$this, 'adminSettings' ] );
add_action( 'init', '\PBT\Modules\Search\ApiSearch::formSubmit', 50 );
add_action( 'admin_enqueue_scripts', [ &$this, 'enqueueAdminStyles' ] );
add_filter( 'tiny_mce_before_init', [ &$this, 'modForSchemaOrg' ] );
add_action( 'admin_menu', [ $this, 'adminMenuAdjuster' ] );
add_action( 'admin_init', [ $this, 'adminSettings' ] );
add_action( 'init', '\PBT\Modules\Search\ApiSearch::formSubmit', 51 );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueueAdminStyles' ] );
add_filter( 'tiny_mce_before_init', [ $this, 'modForSchemaOrg' ] );

// needs to be delayed to come after PB
add_action( 'wp_dashboard_setup', [ &$this, 'addOtbNewsFeed' ], 11 );
add_action( 'wp_dashboard_setup', [ $this, 'addOtbNewsFeed' ], 11 );

// Add an action link pointing to the options page.
$plugin_basename = plugin_basename( plugin_dir_path( __DIR__ ) . $this->plugin_slug . '.php' );
add_filter( 'plugin_action_links_' . $plugin_basename, [ $this, 'addActionLinks' ] );
}

public static function get_instance() {

// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}

return self::$instance;
}

/**
* Adds and Removes some admin buttons
*
* @since 1.0.1
*/
function adminMenuAdjuster() {
if ( \Pressbooks\Book::isBook() ) {
add_menu_page( __( 'Import', 'pressbooks-textbook' ), __( 'Import', 'pressbooks-textbook' ), 'edit_posts', 'pb_import', '\Pressbooks\Admin\Laf\display_import', 'dashicons-upload', 15 );
add_options_page( __( 'Textbooks for Pressbooks Settings', 'pressbooks-textbook' ), __( 'Textbooks for PB', 'pressbooks-textbook' ), 'manage_options', $this->plugin_slug . '-settings', [ $this, 'displayPluginAdminPage' ] );
add_menu_page( __( 'Textbooks for Pressbooks', 'pressbooks-textbook' ), __( 'Textbooks for PB', 'pressbooks-textbook' ), 'edit_posts', $this->plugin_slug, [ $this, 'displayPBTPage' ], 'dashicons-tablet', 64 );
if ( Book::isBook() ) {
add_options_page(
__( 'Textbooks for Pressbooks Settings', 'pressbooks-textbook' ), __( 'Textbooks for PB', 'pressbooks-textbook' ), 'manage_options', $this->plugin_slug . '-settings', [
$this,
'displayPluginAdminPage',
]
);
add_menu_page(
__( 'Textbooks for Pressbooks', 'pressbooks-textbook' ), __( 'Textbooks for PB', 'pressbooks-textbook' ), 'edit_posts', $this->plugin_slug, [
$this,
'displayPBTPage',
], 'dashicons-tablet', 64
);
// check if the functionality we need is available
if ( class_exists( '\Pressbooks\Modules\Api_v1\Api' ) ) {
add_submenu_page( $this->plugin_slug, __( 'Search and Import', 'pressbooks-textbook' ), __( 'Search and Import', 'pressbooks-textbook' ), 'edit_posts', 'api_search_import', [ $this, 'displayApiSearchPage' ], '', 65 );
add_submenu_page(
$this->plugin_slug, __( 'Search and Import', 'pressbooks-textbook' ), __( 'Search and Import', 'pressbooks-textbook' ), 'edit_posts', 'api_search_import', [
$this,
'displayApiSearchPage',
]
);
}
add_submenu_page( $this->plugin_slug, __( 'Download Textbooks', 'pressbooks-textbook' ), __( 'Download Textbooks', 'pressbooks-textbook' ), 'edit_posts', 'download_textbooks', [ $this, 'displayDownloadTextbooks' ], '', 66 );
add_submenu_page(
$this->plugin_slug, __( 'Download Textbooks', 'pressbooks-textbook' ), __( 'Download Textbooks', 'pressbooks-textbook' ), 'edit_posts', 'download_textbooks', [
$this,
'displayDownloadTextbooks',
]
);
if ( version_compare( PB_PLUGIN_VERSION, '2.7' ) >= 0 ) {
remove_menu_page( 'pb_publish' );
} else {
Expand Down Expand Up @@ -88,9 +121,11 @@ function enqueueAdminStyles() {
* This reverses that brilliance
*
* @TODO - make this better.
* @since 1.1.5
*
* @param array $init
*
* @return array $init
* @since 1.1.5
*/
function modForSchemaOrg( $init ) {

Expand All @@ -110,7 +145,12 @@ function addOtbNewsFeed() {
// remove PB news from their blog
remove_meta_box( 'pb_dashboard_widget_metadata', 'dashboard', 'side' );
// add our own
add_meta_box( 'pbt_news_feed', __( 'Open Textbook News', 'pressbooks-textbook' ), [ $this, 'displayOtbFeed' ], 'dashboard', 'side', 'high' );
add_meta_box(
'pbt_news_feed', __( 'Open Textbook News', 'pressbooks-textbook' ), [
$this,
'displayOtbFeed',
], 'dashboard', 'side', 'high'
);
}

/**
Expand All @@ -121,12 +161,12 @@ function addOtbNewsFeed() {
function displayOtbFeed() {
wp_widget_rss_output(
[
'url' => 'https://open.bccampus.ca/feed/',
'title' => __( 'Open Textbook News', 'pressbooks-textbook' ),
'items' => 5,
'url' => 'https://open.bccampus.ca/feed/',
'title' => __( 'Open Textbook News', 'pressbooks-textbook' ),
'items' => 5,
'show_summary' => 1,
'show_author' => 0,
'show_date' => 1,
'show_author' => 0,
'show_date' => 1,
]
);
}
Expand Down Expand Up @@ -186,17 +226,17 @@ function allowedPostTags() {
global $allowedposttags;

$microdata_atts = [
'itemprop' => true,
'itemprop' => true,
'itemscope' => true,
'itemtype' => true,
'itemtype' => true,
];

$allowedposttags['iframe'] = [
'src' => true,
'height' => true,
'width' => true,
'src' => true,
'height' => true,
'width' => true,
'allowfullscreen' => true,
'name' => true,
'name' => true,
];

$allowedposttags['div'] += $microdata_atts;
Expand Down Expand Up @@ -231,6 +271,7 @@ function displayPBTPage() {

include_once( PBT_PLUGIN_DIR . 'admin/views/pbt-home.php' );
}

/**
* Render the downloand textbooks page for editors
*
Expand All @@ -254,11 +295,11 @@ function displayApiSearchPage() {
/**
* Add settings action link to the plugins page.
*
* @since 1.0.1
*
* @param array $links
*
* @return array
* @since 1.0.1
*
*/
function addActionLinks( $links ) {

Expand Down
57 changes: 4 additions & 53 deletions inc/class-textbook.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

namespace PBT;

use \Pressbooks\Book;

class Textbook {

/**
Expand Down Expand Up @@ -51,18 +53,12 @@ private function __construct() {
// Load translations
add_action( 'init', [ $this, 'loadPluginTextDomain' ] );

// Setup our activation and deactivation hooks
register_activation_hook( __FILE__, [ $this, 'activate' ] );
register_deactivation_hook( __FILE__, [ $this, 'deactivate' ] );

// Hook in our pieces
add_action( 'plugins_loaded', [ $this, 'includes' ] );
add_action( 'pressbooks_register_theme_directory', [ $this, 'pbtInit' ] );
add_action( 'wp_enqueue_style', [ $this, 'registerChildThemes' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'enqueueScriptsnStyles' ] );
add_filter( 'allowed_themes', [ $this, 'filterChildThemes' ], 11 );
add_action( 'pressbooks_new_blog', [ $this, 'newBook' ] );
add_filter( 'pb_publisher_catalog_query_args', [ $this, 'rootThemeQuery' ] );

$this->update();

Expand Down Expand Up @@ -218,39 +214,11 @@ function pbtInit() {
register_theme_directory( PBT_PLUGIN_DIR . 'themes-book' );
}

/**
* Fired when the plugin is activated.
*
* @since 1.0.0
*/
function activate() {
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}
// @TODO - update timezone and tagline
// update_option('blogdescription', 'The Open Textbook Project provides flexible and affordable access to higher education resources');

add_site_option( 'pressbooks-textbook-activated', true );
}

/**
* Fired when the plugin is deactivated.
*
* @since 1.0.0
*/
function deactivate() {
if ( ! current_user_can( 'activate_plugins' ) ) {
return;
}

delete_site_option( 'pressbooks-textbook-activated' );
}

/**
* Return the plugin slug.
*
* @since 1.0.0
* @return Plugin slug variable.
* @return string slug variable.
*/
function getPluginSlug() {
return $this->plugin_slug;
Expand Down Expand Up @@ -291,7 +259,7 @@ function registerChildThemes() {
function filterChildThemes( $themes ) {
$pbt_themes = [];

if ( \Pressbooks\Book::isBook() ) {
if ( Book::isBook() ) {
$registered_themes = search_theme_directories();

foreach ( $registered_themes as $key => $val ) {
Expand All @@ -308,11 +276,6 @@ function filterChildThemes( $themes ) {
}
}

function enqueueScriptsnStyles() {
wp_enqueue_style( 'jquery-ui', '//code.jquery.com/ui/1.12.0/themes/base/jquery-ui.css', '', self::VERSION, 'screen, print' );
wp_enqueue_script( 'jquery-ui-tabs', '/wp-includes/js/jquery/ui/jquery.ui.tabs.min.js' );
}

/**
* This function is added to the PB hook 'pressbooks_new_blog' to add some time
* saving customizations
Expand Down Expand Up @@ -378,18 +341,6 @@ function newBook() {
update_option( 'pressbooks_theme_options_web', $web_options );
}

/**
* Pass additional arguments to Publisher Root theme catalogue page
* @return array
*/
function rootThemeQuery() {
return [
'number' => 150,
'orderby' => 'last_updated',
'order' => 'DESC',
];
}

/**
* Perform site and network option updates
* to keep up with a moving target
Expand Down
4 changes: 0 additions & 4 deletions inc/modules/import/class-remoteimport.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@
use Pressbooks\Book;
use Pressbooks\Modules\Import\Html;

if ( ! isset( $GLOBALS['pressbooks'] ) ) {
require_once \WP_PLUGIN_DIR . '/pressbooks/pressbooks.php';
}

class RemoteImport extends Html\Xhtml {

/**
Expand Down
Loading

0 comments on commit a922f4e

Please sign in to comment.