-
Notifications
You must be signed in to change notification settings - Fork 5
/
ColorboxExtender.php
105 lines (81 loc) · 3.02 KB
/
ColorboxExtender.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
<?php
/*
#########################################################
PHP class for Typesetter CMS - 'Colorbox Extender' plugin
Author: J. Krausz
Date: 2016-12-22
Version 1.1
#########################################################
*/
defined('is_running') or die('Not an entry point...');
class ColorboxExtender{
public static $config;
public static $debug = true; // report missing files/misconfigurations
public static function GetHead(){
global $page, $addonRelativeCode;
self::LoadPluginConfig();
if( self::$config['always_load_cbox'] == "1" ){
\gp\tool::AddColorBox();
$page->head_js[] = $addonRelativeCode . '/common/inits.js';
}
if( self::$config['extension'] != "none" ){
self::UseComponent('extension', self::$config['extension']);
}
if( self::$config['style'] != "none" ){
self::UseComponent('style', self::$config['style']);
}
}
public static function UseComponent($type, $dir){
global $page, $addonPathCode, $addonRelativeCode;
$component_path = $addonPathCode . '/' . $type . 's/' . $dir;
$component_base = $addonRelativeCode . '/' . $type . 's/' . $dir;
$config_file = $component_path . '/config.php';
if( !file_exists($config_file) ){
if( \gp\tool::LoggedIn() ){
msg('Colorbox Extender: Error loading the configured ' . $type . ' "' . $dir . '".');
}
return false;
}
include $config_file;
$css_files = !empty($config['stylesheets']) ? $config['stylesheets'] : false;
if( $css_files ){
if( is_array($css_files) ){
foreach($css_files as $css_file){
if( self::$debug && \gp\tool::LoggedIn() ){ self::CheckFile($component_path . '/' . $css_file); }
$page->css_user[] = $component_base . '/' . $css_file;
}
}else{
if( self::$debug && \gp\tool::LoggedIn() ){ self::CheckFile($component_path . '/' . $css_files); }
$page->css_user[] = $component_base . '/' . $css_files;
}
}
$js_files = !empty($config['scripts']) ? $config['scripts'] : false;
if( $js_files ){
if( is_array($js_files) ){
foreach($js_files as $js_file){
if( self::$debug && \gp\tool::LoggedIn() ){ self::CheckFile($component_path . '/' . $js_file); }
$page->head_js[] = $component_base . '/' . $js_file;
}
}else{
$page->head_js[] = $component_base . '/' . $js_files;
if( self::$debug && \gp\tool::LoggedIn() ){ self::CheckFile($component_path . '/' . $js_files); }
}
}
}
public static function CheckFile($file){
if( file_exists($file) ){
return true;
}
msg('Colorbox Extender: The file "' . $file . '" does not exist.');
}
public static function LoadPluginConfig(){
global $addonPathCode, $addonPathData;
$config_file = $addonPathData . '/config.php';
if( file_exists($config_file) ){
include $config_file ;
}else{
include $addonPathCode . '/defaults/config.php';
}
self::$config = $config;
}
} /* class ColorboxExtender --end */