forked from juek/Colorbox-Extender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColorboxExtender_Admin.php
179 lines (151 loc) · 5.95 KB
/
ColorboxExtender_Admin.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
<?php
/*
######################################################################
PHP class for Typesetter CMS - 'Colorbox Extender' plugin - Admin Page
Author: J. Krausz
Date: 2016-12-22
Version 1.1
######################################################################
*/
defined('is_running') or die('Not an entry point...');
class ColorboxExtender_Admin{
public static $config;
public static $components;
public static $debug = true;
public static function Settings(){
global $page, $addonRelativeCode, $langmessage;
$page->head_js[] = $addonRelativeCode . "/ColorboxExtender_Admin.js";
//$page->css_admin[] = $addonRelativeCode . "/ColorboxExtender_Admin.css";
if( isset($_POST['save']) ){
msg(self::SaveConfig());
}
self::LoadConfig();
self::GetComponents();
// msg("Config: " . pre(self::$config));
// msg("Components: " . pre(self::$components));
$admin_url = \gp\tool::GetUrl('Admin_ColorboxExtender');
echo '<h2 class="hqmargin">Colorbox Extender » Settings</h2>';
echo '<form id="cbe_config_form" data-values-changed="0" action="' . $admin_url . '" method="post">';
echo '<table class="bordered" style="width:100%;">';
echo '<tr>';
echo '<th style="width:40%;">' . $langmessage['Settings'] . '</th>';
echo '<th style="width:60%;">' . $langmessage['Current_Value'] . '</th>';
echo '</tr>';
$checked = self::$config['always_load_cbox'] == '1' ? ' checked="checked" ' : '';
echo '<tr>';
echo '<td>Load Colorbox</td>';
echo '<td>';
echo '<label class="all_checkbox">';
echo '<input type="checkbox" name="cbe_config[always_load_cbox]" value="1" ' . $checked . '/>';
echo '<span>' . $langmessage['All Pages'] . '</span>';
echo '</label>';
echo '</td>';
echo '</tr>';
$value = self::$config['extension'];
echo '<tr>';
echo '<td>Extension</td>';
echo '<td>';
echo '<select class="gpselect" name="cbe_config[extension]">';
echo '<option value="none">none</option>';
foreach( self::$components['extensions'] as $extension ){
$label = $extension['label'];
$dir = $extension['dir'];
$selected = $dir == $value ? ' selected="selected" ' : '';
echo '<option value="' . $dir . '" ' . $selected . '>' . $label . '</option>';
}
echo '</select>';
echo '</td>';
echo '</tr>';
$value = self::$config['style'];
echo '<tr>';
echo '<td>Style</td>';
echo '<td>';
echo '<select id="cbe_style_select" class="gpselect" name="cbe_config[style]">';
echo '<option value="none">Use System Setting</option>';
foreach( self::$components['styles'] as $style ){
$label = $style['label'];
$dir = $style['dir'];
$selected = $dir == $value ? ' selected="selected" ' : '';
echo '<option value="' . $dir . '" ' . $selected . '>' . $label . '</option>';
}
echo '</select> ';
echo '<a id="cbe_system_settings_link" style="display:none;" ';
echo 'href="' . \gp\tool::GetUrl('Admin/Configuration') . '">';
// echo $langmessage['Settings'] . '»';
// echo $langmessage['configuration'] . '»';
// echo $langmessage['Interface'] . '»';
echo $langmessage['colorbox_style'] . '</a>';
echo '</td>';
echo '</tr>';
echo '</table>';
// SAVE / CANCEL
echo '<br/>';
echo '<input type="submit" id="cbe_config_submit" name="save" value="' . $langmessage['save'] . '" class="gpsubmit" /> ';
echo '<input type="button" onClick="location.href=\'' .$admin_url . '\'" value="' . $langmessage['cancel'] . '" class="gpcancel" />';
echo '</form>';
}
public static function GetComponents(){
global $page, $addonPathCode;
$types = array(
'styles' => array(),
'extensions' => array(),
);
self::$components = $types;
foreach( $types as $type => $val ){
$dirs = \gp\tool\Files::ReadDir($addonPathCode . '/' . $type. '/', 1);
foreach( $dirs as $component ){
$component_config_file = $addonPathCode . '/' . $type. '/' . $component . '/config.php';
if( file_exists($component_config_file) && strpos($type, '!') !== 0 ){
include $component_config_file;
if( isset($config) ){
self::$components[$type][] = array(
'label' => $config['label'],
'dir' => $component,
);
}
unset($config);
}elseif( self::$debug ){
msg("Component config file " . $component_config_file . " was not found.");
}
}
}
}
public static function LoadConfig(){
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;
}
public static function SaveConfig(){
global $addonPathData, $langmessage;
$config = array (
'always_load_cbox' => '0',
'extension' => 'none',
'style' => 'none',
);
foreach ($_POST['cbe_config'] as $key => $value) {
switch($key){
case 'always_load_cbox':
$config['always_load_cbox'] = '1';
break;
case 'extension':
$config['extension'] = basename(trim($value));
break;
case 'style':
$config['style'] = basename(trim($value));
break;
default:
}
}
$config_file = $addonPathData . '/config.php';
if( \gp\tool\Files::SaveData($config_file, 'config', $config) ){
msg($langmessage['SAVED']);
}else{
msg($langmessage['OOPS']);
}
}
}