forked from pressbooks/pressbooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpressbooks.php
More file actions
139 lines (104 loc) · 5.06 KB
/
Copy pathpressbooks.php
File metadata and controls
139 lines (104 loc) · 5.06 KB
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
<?php
/*
Plugin Name: PressBooks
Plugin URI: http://www.pressbooks.com
Description: Simple Book Production
Version: 2.0.3
Author: BookOven Inc.
Author URI: http://www.pressbooks.com
Text Domain: pressbooks
License: GPLv2
*/
if ( ! defined( 'ABSPATH' ) )
return;
// -------------------------------------------------------------------------------------------------------------------
// Turn on $_SESSION
// -------------------------------------------------------------------------------------------------------------------
function _pb_session_start() {
if ( ! session_id() ) {
ini_set( 'session.use_only_cookies', true );
session_start();
}
}
function _pb_session_kill() {
$_SESSION = array();
session_destroy();
}
add_action( 'init', '_pb_session_start', 1 );
add_action( 'wp_logout', '_pb_session_kill' );
add_action( 'wp_login', '_pb_session_kill' );
// -------------------------------------------------------------------------------------------------------------------
// Minimum requirements
// -------------------------------------------------------------------------------------------------------------------
$pb_minimum_wp = '3.5.1';
if ( ! is_multisite() || ! version_compare( get_bloginfo( 'version' ), $pb_minimum_wp, '>=' ) ) {
add_action( 'admin_notices', function () use ( $pb_minimum_wp ) {
echo '<div id="message" class="error fade"><p>';
printf( __( 'PressBooks will not work with your version of WordPress. PressBooks requires a dedicated install of WordPress Multi-Site, version %s or greater. Please upgrade WordPress if you would like to use PressBooks.', 'pressbooks' ), $pb_minimum_wp );
echo '</p></div>';
} );
return;
}
// -------------------------------------------------------------------------------------------------------------------
// Setup some defaults
// -------------------------------------------------------------------------------------------------------------------
if ( ! defined( 'PB_PLUGIN_DIR' ) )
define ( 'PB_PLUGIN_DIR', __DIR__ . '/' ); // Must have trailing slash!
if ( ! defined( 'PB_PLUGIN_URL' ) )
define ( 'PB_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); // Must have trailing slash!
// -------------------------------------------------------------------------------------------------------------------
// Class autoloader
// -------------------------------------------------------------------------------------------------------------------
function _pressbooks_autoload( $class_name ) {
$look_for_class = array();
$parts = explode( '\\', strtolower( $class_name ) );
if ( ! preg_match( '/^pressbooks/', @$parts[0] ) ) {
// Ignore classes not in our namespace
return;
}
if ( count( $parts ) > 1 && 'pressbooks' == @$parts[0] ) {
// Namespaced, Ie. PressBooks\Export\Prince\Pdf()
array_shift( $parts );
$class_file = 'class-pb-' . str_replace( '_', '-', array_pop( $parts ) ) . '.php';
$sub_path = count( $parts ) ? implode( '/', $parts ) . '/' : '';
$look_for_class[] = PB_PLUGIN_DIR . $sub_path . $class_file;
$look_for_class[] = PB_PLUGIN_DIR . "includes/modules/" . $sub_path . $class_file;
} else {
// Classic, Ie. PressBooks_Export()
$class_file = 'class-' . str_replace( '_', '-', str_replace( 'pressbooks', 'pb', end( $parts ) ) ) . '.php';
}
$look_for_class[] = PB_PLUGIN_DIR . "admin/$class_file";
array_unshift( $look_for_class, PB_PLUGIN_DIR . "includes/$class_file" ); // Most probable first
foreach ( $look_for_class as $file ) {
if ( is_file( $file ) ) {
require_once( $file );
if ( class_exists( $class_name ) ) {
break;
}
}
}
}
spl_autoload_register( '_pressbooks_autoload' );
// -------------------------------------------------------------------------------------------------------------------
// Configure root site
// -------------------------------------------------------------------------------------------------------------------
register_activation_hook( __FILE__, function () {
$activate = new \PressBooks\Activation();
$activate->registerActivationHook();
} );
// -------------------------------------------------------------------------------------------------------------------
// Initialize
// -------------------------------------------------------------------------------------------------------------------
$GLOBALS['pressbooks'] = new \PressBooks\PressBooks();
// -------------------------------------------------------------------------------------------------------------------
// Hooks
// -------------------------------------------------------------------------------------------------------------------
require_once ( PB_PLUGIN_DIR . 'hooks.php' );
if ( is_admin() ) {
require_once ( PB_PLUGIN_DIR . 'hooks-admin.php' );
}
// --------------------------------------------------------------------------------------------------------------------
// Shortcuts to help template designers who don't use real namespaces...
// --------------------------------------------------------------------------------------------------------------------
require_once ( PB_PLUGIN_DIR . 'functions.php' );
/* The distinction between "the internet" & "books" will disappear in 5 years. Start adjusting now. */