roe-pressbooks/roe-pressbooks.php

93 lines
3.7 KiB
PHP
Raw Normal View History

2019-03-25 20:31:05 +00:00
<?php
/*
Plugin Name: River of Ebooks for Pressbooks
2019-03-26 03:49:06 +00:00
Plugin URI: https://github.com/villa7/roe-pressbooks
2019-03-25 20:31:05 +00:00
Description: RoE integration with Pressbooks
2019-03-26 03:12:34 +00:00
Version: 1.0.0
2019-03-26 03:49:06 +00:00
Author: Free Ebook Foundation
Author URI: https://ebookfoundation.org/
2019-03-25 20:31:05 +00:00
Requires PHP: 7.0
Pressbooks tested up to: 5.4.1
Text Domain: roe-pressbooks
License: GPL v3 or later
Network: True
*/
2019-03-26 03:12:34 +00:00
define ('ROE_BASE_URL', 'http://ec2-18-219-223-27.us-east-2.compute.amazonaws.com');
2019-03-25 20:31:05 +00:00
// -------------------------------------------------------------------------------------------------------------------
// Check requirements
// -------------------------------------------------------------------------------------------------------------------
if ( ! function_exists( 'pb_meets_minimum_requirements' ) && ! @include_once( WP_PLUGIN_DIR . '/pressbooks/compatibility.php' ) ) { // @codingStandardsIgnoreLine
add_action('admin_notices', function () {
2019-03-25 22:02:16 +00:00
echo '<div id="message" class="error fade"><p>' . __( 'Cannot find Pressbooks install.', 'roe-pressbooks' ) . '</p></div>';
2019-03-25 20:31:05 +00:00
});
return;
} elseif ( ! pb_meets_minimum_requirements() ) {
return;
}
// -------------------------------------------------------------------------------------------------------------------
// Class autoloader
// -------------------------------------------------------------------------------------------------------------------
2019-03-25 22:02:16 +00:00
\HM\Autoloader\register_class_path( 'ROE', __DIR__ . '/inc' );
2019-03-25 20:31:05 +00:00
// -------------------------------------------------------------------------------------------------------------------
// Composer autoloader
// -------------------------------------------------------------------------------------------------------------------
2019-03-25 22:02:16 +00:00
if ( ! class_exists( '\ROE\ROEIntegration' ) ) {
2019-03-25 20:31:05 +00:00
if ( file_exists( __DIR__ . '/vendor/autoload.php' ) ) {
require_once __DIR__ . '/vendor/autoload.php';
} else {
$title = __( 'Dependencies Missing', 'roe-pressbooks' );
$body = __( 'Please run <code>composer install</code> from the root of the River of Ebooks for Pressbooks plugin directory.', 'roe-pressbooks' );
$message = "<h1>{$title}</h1><p>{$body}</p>";
wp_die( $message, $title );
}
}
// -------------------------------------------------------------------------------------------------------------------
// Check for updates
// -------------------------------------------------------------------------------------------------------------------
if ( ! \Pressbooks\Book::isBook() ) {
2019-03-25 22:02:16 +00:00
$updater = Puc_v4_Factory::buildUpdateChecker(
'https://github.com/villa7/roe-pressbooks/',
__FILE__,
'roe-pressbooks'
2019-03-25 20:31:05 +00:00
);
$updater->setBranch( 'master' );
}
2019-03-26 03:12:34 +00:00
function _roe_show_set_config () {
echo '<div class="notice notice-warning"><p style="display:inline-block;height:40px;line-height:40px">';
_e('Please configure your site\'s publisher id and secret. It is required to publish to the River of Ebooks.', 'roe-pressbooks');
echo '</p><a class="button" style="float:right;height:30px;margin:15px 0;" href="'. get_admin_url() .'network/settings.php?page=roe-pressbooks">';
2019-03-26 03:12:34 +00:00
_e('Settings', 'roe-pressbooks');
echo '</a></div>';
}
if ( is_plugin_active('roe-pressbooks/roe-pressbooks.php') && is_network_admin() ) {
if ( ! \ROE\ROEIntegration::is_active() ) {
add_action( 'network_admin_notices', '_roe_show_set_config' );
}
}
2019-03-26 03:12:34 +00:00
add_filter( 'pb_active_export_modules', function ( $modules ) {
if ( isset( $_POST['export_formats']['roe'] ) && \ROE\ROEIntegration::is_active() ) {
$modules[] = '\ROE\ROEIntegration';
}
return $modules;
} );
add_filter( 'pb_export_formats', function ( $formats ) {
if (\ROE\ROEIntegration::is_active()) {
2019-03-26 03:49:06 +00:00
$formats['exotic']['roe'] = __( 'Send to River of Ebooks', 'pressbooks' );
2019-03-26 03:12:34 +00:00
}
return $formats;
} );
if (is_network_admin()) {
new \ROE\Admin\ROEAdmin;
}