-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.php
325 lines (274 loc) · 5.79 KB
/
init.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
<?php
/**
* Initialize admin theme
*
* @package Configure 8 Admin
* @subpackage Functions
* @since 1.0.0
*/
namespace CFE_Admin_Theme;
// Stop if accessed directly.
if ( ! defined( 'BLUDIT' ) ) {
die();
}
/**
* Restore the default admin theme if the
* Configure 8 frontend theme is not active.
*/
if ( 'configureight' != $site->theme() ) {
restore_default_theme();
return;
}
if ( ! class_exists( 'Bootstrap' ) ) {
include( 'includes/classes/class-bootstrap.php' );
}
/**
* Constant: plugin class
*
* The class of the companion plugin.
*
* @since 1.0.0
*/
define( 'THEME_PLUGIN', 'configureight' );
/**
* Get theme plugin
*
* @since 1.0.0
* @return mixed Returns the companion plugin object or false.
*/
function plugin() {
// Access global variables.
global $site;
$plugin = false;
if ( getPlugin( $site->theme() ) ) {
$plugin = getPlugin( $site->theme() );
}
return $plugin;
}
/**
* Current language
*
* The language from site settings.
*
* @since 1.0.0
* @global object $L The Language class.
* @return string
*/
function current_lang() {
// Access global variables.
global $L;
return $L->currentLanguageShortVersion();
}
/**
* Is RTL language
*
* @since 1.0.0
* @return boolean Returns true if site is in RTL language.
*/
function is_rtl() {
$rtl = [
'ar',
'fa',
'he',
'ks',
'ku',
'pa',
'ps',
'sd',
'ug',
'ur'
];
$lang = current_lang();
if ( in_array( $lang, $rtl ) ) {
return true;
}
return false;
}
/**
* Favicon tag
*
* Returns the site icon meta tag.
*
* @since 1.0.0
* @return mixed Returns the icon tag or null.
*/
function favicon_tag() {
// If plugin has icon URL.
if ( plugin() && plugin()->favicon_src() ) {
// Get icon src.
$favicon = plugin()->favicon_src();
// Get the image file extension.
$info = pathinfo( $favicon );
$type = $info['extension'];
return sprintf(
'<link rel="icon" href="%s" type="image/%s">',
$favicon,
$type
);
}
return null;
}
/**
* Body classes
*
* @since 1.0.0
* @return string Returns various classes.
*/
function body_classes() {
// Access global variables.
global $url;
$classes = [
'bl-admin',
'admin-page-' . strtok( $url->slug(), '/' )
];
if ( str_contains( $url->slug(), '/' ) ) {
$classes[] = 'admin-' . str_replace( '/', '-', $url->slug() );
}
// User toolbar.
if ( plugin() && (
'enabled' == plugin()->user_toolbar() ||
'backend' == plugin()->user_toolbar()
)
) {
$classes[] = 'toolbar-active';
}
echo implode( ' ', $classes );
}
/**
* Get SVG files
*
* @since 1.0.0
* @param string $filename Name of the SVG file.
* @return mixed Returns the contents of the SVG file or
* returns null if the filename is not found.
*/
function get_svg_icon( $filename = '' ) {
// Access global variables.
global $site;
$path = PATH_ROOT . 'bl-kernel/admin/themes/' . $site->adminTheme() . '/assets/images/svg/' . $filename . '.svg';
$args = [
'svg',
'g',
'path'
];
if ( is_file( $path ) && is_readable( $path ) ) {
$file = strip_tags( $path, $args );
return file_get_contents( $file );
} else {
return $path;
}
}
/**
* SVG icon
*
* Prints the contents of a given SVG file.
*
* @since 1.0.0
* @param string $filename Name of the SVG file.
* @param boolean $wrap Wraps the icon in HTML if true.
* @param string $class Additional class names for the wrapper.
* @param string $title Contents of the title attribute if
* $wrap is true.
* @return void
*/
function svg_icon( $filename, $wrap = true, $class = '' ) {
if ( ! empty( $class ) ) {
$class = ' ' . $class;
}
if ( true == $wrap ) {
printf(
'<span class="svg-icon%s">%s</span>',
$class,
get_svg_icon( $filename )
);
} else {
echo get_svg_icon( $filename );
}
}
/**
* Plugin sidebars count
*
* This counts plugins with the `adminSidebar()`
* method implemented. Theme options plugin is
* excluded from the count because this theme
* adds a link for theme options if a theme plugin
* is available. So if the theme options plugin
* is the only plugin activated with a sidebar link
* then the plugin links section is not printed.
*
* @since 1.0.0
* @global array $plugins Array of active plugins.
* @return integer Returns a number of plugins.
*/
function plugin_sidebars_count() {
// Access global variables.
global $plugins;
if ( empty( $plugins['adminSidebar'] ) ) {
return 0;
}
$count = 0;
foreach ( $plugins['adminSidebar'] as $link ) {
if ( 'theme' != $link->type() ) {
$count++;
}
}
return $count;
}
/**
* Default theme
*
* Restore admin theme to default in the site database.
*
* @since 1.0.0
* @return void
*/
function restore_default_theme() {
// Access global variables.
global $site;
// Define database file.
$db_file = DB_SITE;
// Get current admin theme.
$current = '"adminTheme":"' . $site->adminTheme() . '"';
if ( DEBUG_MODE ) {
$current = '"adminTheme": "' . $site->adminTheme() . '"';
}
// Get database content.
$content = file_get_contents( $db_file );
$replace = '"adminTheme":"booty"';
if ( DEBUG_MODE ) {
$replace = '"adminTheme": "booty"';
}
// Change admin theme to default.
$content = str_replace( $current, $replace, $content );
// Write theme into the database file.
file_put_contents ( $db_file, $content );
}
/**
* Menu link
*
* Prints an `<a>` element for use in the
* admin menu. Adds a current page class.
*
* @since 1.0.0
* @return void
*/
function menu_link( $slug = '', $classes = '' ) {
// Access global variables.
global $url;
$tag = '<a>';
if ( ! empty( $slug ) ) {
$class = 'nav-link';
if ( ! empty( $classes ) ) {
$class .= ' ' . $classes;
}
if ( $slug === $url->slug() ) {
$class .= ' current-link';
}
$tag = sprintf(
'<a class="%s" href="%s">',
$class,
DOMAIN_ADMIN . $slug
);
}
echo $tag;
}