-
Notifications
You must be signed in to change notification settings - Fork 0
/
brainpress.php
335 lines (285 loc) · 9.33 KB
/
brainpress.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
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<?php
/**
* Plugin Name: BrainPress
* Version: 2.3.8
* Description: BrainPress vereinfacht die Online-Ausbildung mit Kursseiten, Paywalls, Social Sharing und einer interaktiven Lernumgebung, mit der mehr Schüler miteinander verbunden werden können.
* Author: PSOURCE
* Author URI: https://github.com/cp-psource
* Plugin URI: https://cp-psource.github.io/brainpress/
* License: GPL2
* License URI: https://www.gnu.org/licenses/gpl-2.0.html
* Text Domain: brainpress
* Domain Path: /languages
* @package BrainPress
*/
/**
* Copyright notice.
*
* @copyright PSOURCE (https://github.com/cp-psource)
*
* Authors: PSOURCE
* Contributors: DerN3rd (PSOURCE)
*
* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (GPL-2.0)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
*
* 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
*/
if ( ! defined( 'ABSPATH' ) ) { exit; }
/**
* @@@@@@@@@@@@@@@@@ PS UPDATER 1.3 @@@@@@@@@@@
**/
require 'psource/psource-plugin-update/plugin-update-checker.php';
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;
$myUpdateChecker = PucFactory::buildUpdateChecker(
'https://github.com/cp-psource/brainpress',
__FILE__,
'brainpress'
);
//Set the branch that contains the stable release.
$myUpdateChecker->setBranch('master');
/**
* @@@@@@@@@@@@@@@@@ ENDE PS UPDATER 1.3 @@@@@@@@@@@
**/
// Launch BrainPress.
BrainPress::init();
/**
* Main plugin class. Main purpose is to load all required files.
*/
class BrainPress {
/**
* Current plugin version, must match the version in the header comment.
*
* @var string
*/
public static $version = '2.3.8';
/**
* Plugin name, this reflects the Pro/Standard version.
*
* @var string
*/
public static $name = 'BrainPress'; // Translated by grunt.
/**
* Absolut path to this file (main plugin file).
*
* @var string
*/
public static $file = '';
/**
* Absolut path to the plugin files base-dir.
*
* @var string
*/
public static $path = '';
/**
* Dir-name of this plugin (relative to wp-content/plugins).
*
* @var string
*/
public static $dir = '';
/**
* Absolute URL to plugin folder.
*
* @var string
*/
public static $url = '';
/**
* Initialize the plugin!
*
* @since 2.0.0
*/
public static function init() {
/**
* Translate plugin name
*/
self::$name = _x( 'BrainPress', 'plugin name', 'brainpress' ); // Translated by grunt.
// Initialise the autoloader.
spl_autoload_register( array( __CLASS__, 'class_loader' ) );
// Prepare BrainPress Core parameters.
self::$file = __FILE__;
self::$path = plugin_dir_path( __FILE__ );
self::$dir = dirname( self::$path );
self::$url = plugin_dir_url( __FILE__ );
// Allow WP to load other plugins before we continue!
add_action( 'plugins_loaded', array( 'BrainPress_Core', 'init' ), 10 );
// Load additional features if available.
if ( file_exists( self::$path . '/premium/init.php' ) ) {
include_once self::$path . '/premium/init.php';
}
if ( file_exists( self::$path . '/campus/init.php' ) ) {
include_once self::$path . '/campus/init.php';
}
/**
* update plugin if needed
*/
$db_version = get_site_option( 'brainpress_version', '0.0.0' );
if ( 0 > version_compare( $db_version, self::$version ) ) {
update_site_option( 'brainpress_version', self::$version );
}
/**
* Add sample courses when CP is activated.
**/
add_action( 'brainpress_activate', array( 'BrainPress_Admin_SampleCourses', 'add_sample_courses' ) );
/**
register_activation_hook * register_activation_hook
*/
register_activation_hook( __FILE__, array( __CLASS__, 'register_activation_hook' ) );
/**
* Clean up when this plugin is deactivated.
**/
register_deactivation_hook( __FILE__, array( __CLASS__, 'deactivate_brainpress' ) );
// Define custom theme directory for BrainPress theme
self::register_cp_theme_directory();
}
/**
* Handler for spl_autoload_register (autoload classes on demand).
*
* Note how the folder structure is build:
* 'core' + namespace + classpath
* classpath = class name, while each _ is actually a subfolder separator.
*
* @since 2.0.0
* @param string $class Class name.
* @return bool True if the class-file was found and loaded.
*/
private static function class_loader( $class ) {
$namespaces = array(
'BrainPressPro' => array(
'namespace_folder' => 'premium/include', // Base folder for classes.
'filename_prefix' => 'class-', // Prefix filenames.
),
'BrainPressCampus' => array(
'namespace_folder' => 'campus/include', // Base folder for classes.
'filename_prefix' => 'class-', // Prefix filenames.
),
'BrainPress' => array(
'namespace_folder' => 'include/brainpress', // Base folder for classes.
'filename_prefix' => 'class-', // Prefix filenames.
),
'CP_TCPDF' => array(
'namespace_folder' => 'include/tcpdf', // Base folder for classes.
'filename_prefix' => false, // No prefix for filenames.
),
);
$class = trim( $class );
foreach ( $namespaces as $namespace => $options ) {
// Continue if the class name is prefixed with <namespace>.
if ( substr( $class, 0, strlen( $namespace ) ) === $namespace ) {
if ( empty( $options['namespace_folder'] ) ) {
continue;
} else {
$namespace_folder = $options['namespace_folder'];
}
// Get the class-filename.
$class_path = explode( '_', $class );
$class_file = strtolower( array_pop( $class_path ) ) . '.php';
if ( ! empty( $options['filename_prefix'] ) ) {
$class_file = $options['filename_prefix'] . $class_file;
}
// Build the path to the class file.
array_shift( $class_path ); // Remove the first element (namespace-string).
array_unshift( $class_path, $namespace_folder );
$class_folder = self::$path . strtolower(
implode( DIRECTORY_SEPARATOR, $class_path )
);
$dir_folder = dirname( __FILE__ ) . strtolower(
DIRECTORY_SEPARATOR . implode( DIRECTORY_SEPARATOR, $class_path )
);
$filename = $class_folder . DIRECTORY_SEPARATOR . $class_file;
// Override filename via filter.
$filename = apply_filters(
'brainpress_class_file_override',
$filename,
$class_folder,
$class_file,
$class,
$namespace
);
if ( is_readable( $filename ) ) {
include_once $filename;
return true;
} elseif ( is_readable( $dir_folder ) ) {
include_once $dir_folder . DIRECTORY_SEPARATOR . $class_file;
return true;
}
} // End of namespace condition.
} // End of foreach loop.
// Check new location
$class_path = explode( '_', strtolower( $class ) );
$namespace = array_shift( $class_path );
if ( 'brainpress' == $namespace ) {
$class_filename = array_pop( $class_path );
$class_location = implode( DIRECTORY_SEPARATOR, $class_path );
$class_filename = self::$path . $class_location . DIRECTORY_SEPARATOR . 'class-' . $class_filename . '.php';
if ( is_readable( $class_filename ) ) {
include_once $class_filename;
return true;
}
}
}
/**
* Redirect to Guide page semaphore and reset schedule.
*
* @since 2.0.0
*/
public static function register_activation_hook() {
add_option( 'brainpress_activate', true );
// Reset the schedule during activation.
wp_clear_scheduled_hook( 'brainpress_schedule-email_task' );
/**
* Fire whenever this plugin is activated.
*
* @since 2.0.7
**/
do_action( 'brainpress_activate' );
}
/**
* Clean up.
*
* @since 2.0.0
**/
public static function deactivate_brainpress() {
delete_option( 'brainpress_activate' );
// Reset the schedule during deactivation.
wp_clear_scheduled_hook( 'brainpress_schedule-email_task' );
/**
* Fire whenever this plugin is deactivated.
*
* @since 2.0.7
**/
do_action( 'brainpress_deactivate' );
}
/**
* Registering CP Theme
*
* @since 2.0.0
**/
private static function register_cp_theme_directory() {
$theme_directories = apply_filters( 'brainpress_theme_directory_array', array(
self::$path . 'themes'
)
);
foreach ( $theme_directories as $theme_directory ) {
register_theme_directory( $theme_directory );
}
}
public static function get_file() {
return self::$file;
}
}
// Load brainpress-reorder-pages plugin
function load_brainpress_reorder_pages() {
require_once( plugin_dir_path( __FILE__ ) . 'include/brainpress-reorder-pages/brainpress-reorder-pages.php' );
}
add_action( 'plugins_loaded', 'load_brainpress_reorder_pages' );