-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApplication.php
executable file
·107 lines (99 loc) · 3.32 KB
/
Application.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
<?php
/**
* @brief Application Application Class
* @author -storm_author-
* @copyright -storm_copyright-
* @package IPS Social Suite
* @subpackage toolbox
* @since 5.1.1
* @version -storm_version-
*/
namespace IPS\toolbox;
use IPS\Output;
use IPS\Theme;
use IPS\toolbox\ApplicationOG;
use function array_merge;
use function array_combine;
use function strrev;
use function dechex;
use function crc32;
use function mb_substr;
use function mb_strlen;
use function str_pad;
use function random_int;
use function floor;
use const STR_PAD_LEFT;
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) ) {
header( ( $_SERVER[ 'SERVER_PROTOCOL' ] ?? 'HTTP/1.0' ) . ' 403 Forbidden' );
exit;
}
/**
* Application Class
* @mixin \IPS\toolbox\Application
*/
class _Application extends ApplicationOG
{
/**
* @param array $files an array of js files to load, without .js, eg ['front_myjs','front_myjs2'],
* will use the app it is called from, but you can load other apps js if need be by adding the app
* to the value in the array, eg ['core_front_somejs','front_myjs','front_myjs2'], the first
* value will load from core, the next 2 will load from your app.
* @return void
*/
public static function addJs(array $files): void
{
$app = 'toolbox';
$jsFiles[] = Output::i()->jsFiles;
foreach ($files as $f) {
$v = explode('_', $f);
//determine if we need to change the $app
if(\count($v) === 2){
[$loc, $file] = explode('_',$f);
}
else {
[$app, $loc, $file] = explode('_',$f);
}
$file = $loc . '_' . $file . '.js';
//add to local variable for merging
$jsFiles[] = Output::i()->js($file, $app, $loc);
}
//merges $jsFiles into Output::i()->jsFiles
Output::i()->jsFiles = array_merge(...$jsFiles);
}
/**
* @param array $files an array of css files to load, without .css, eg ['front_mycss','front_mycss2'],
* will use the app it is called from, but you can load other apps css if need be by adding the app
* to the value in the array, eg ['core_front_somecss','front_mycss','front_mycss2'], the first
* value will load from core, the next 2 will load from your app.
* @return void
*/
public static function addCss(array $files): void
{
$app = 'toolbox';
$cssFiles[] = Output::i()->cssFiles;
foreach ($files as $f) {
$v = explode('_', $f);
//determine if we need to change the $app
if(\count($v) === 2){
[$loc, $file] = explode('_',$f);
}
else {
[$app, $loc, $file] = explode('_',$f);
}
$file = $loc . '_' . $file . '.css';
$cssFiles[] = Theme::i()->css($file, $app, $loc);
}
//merges $cssFiles into Output::i()->cssFiles
Output::i()->cssFiles = array_merge(...$cssFiles);
}
/**
* @param array $jsVars a key/value array of jsVars to add, ['mykey' => 'value']
* @return void
*/
public static function addJsVar(array $jsVars): void
{
foreach ($jsVars as $key => $jsVar) {
Output::i()->jsVars[$key] = $jsVar;
}
}
}