-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.php
More file actions
executable file
·118 lines (97 loc) · 3.87 KB
/
helpers.php
File metadata and controls
executable file
·118 lines (97 loc) · 3.87 KB
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
<?php
if (!function_exists('save_config_var')) {
function save_config_var($setting, $value, $env = null)
{
$configModel = new \Cms\Modules\Core\Models\DBConfig();
$settingInfo = $configModel->explodeSetting($setting);
if (empty($env)) {
$env = $settingInfo['environment'];
}
// check to see if we already have this setting going
$DBConfig = with(new $configModel())->where('environment', $env);
if (isset($settingInfo['group'])) {
$DBConfig->where('group', $settingInfo['group']);
}
if (isset($settingInfo['item'])) {
$DBConfig->where('item', $settingInfo['item']);
}
if (isset($settingInfo['namespace'])) {
$DBConfig->where('namespace', $settingInfo['namespace']);
}
$DBConfig = $DBConfig->get()->first();
$saved = false;
// if we have a config row already, update the value
if (count($DBConfig)) {
$DBConfig->value = $value;
$saved = $DBConfig->save();
// else create a new one
} else {
// if no value exists and this value is empty, dont bother :)
if (empty($value)) {
return true;
}
$DBConfig = with(new $configModel());
$saved = $DBConfig->set($setting, $value);
}
return $saved;
}
}
if (!function_exists('convertUnits')) {
function convertUnits($size)
{
$units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$power = $size > 0 ? floor(log($size, 1024)) : 0;
return number_format($size / pow(1024, $power), 2, '.', ',').' '.$units[$power];
}
}
if (!function_exists('build_helper_button')) {
function build_helper_button(array $btn)
{
// check for permissions
$perm = array_pull($btn, 'hasPermission', null);
if ($perm !== null && !hasPermission($perm)) {
return;
}
// the button structure, basic text, tooltip or just icon
if (isset($btn['btn-text'])) {
$tpl = '<span class="btn-label"><i class="%s fa-fw"></i></span> <span>%s</span>';
$label = sprintf($tpl, array_get($btn, 'btn-icon'), array_get($btn, 'btn-text', null));
} elseif (isset($btn['btn-title'])) {
$tpl = '<span title="%2$s" data-toggle="tooltip"><i class="%1$s fa-fw"></i></span>';
$label = sprintf($tpl, array_get($btn, 'btn-icon'), array_get($btn, 'btn-title', null));
} else {
$tpl = '<i class="%s fa-fw"></i>';
$label = sprintf($tpl, array_get($btn, 'btn-icon'));
}
$extras = [];
// check for ujs method
if (isset($btn['btn-method'])) {
$extras[] = 'data-method="'.array_get($btn, 'btn-method', 'GET').'"';
}
// check for extras key, this will just be a html string
if (isset($btn['btn-extras'])) {
$extras[] = array_get($btn, 'btn-extras');
}
// figure out where to link this to
$url = '#';
if (($route = array_get($btn, 'btn-route', null)) !== null) {
// if its an array throw it at route()
if (is_array($route)) {
list($route, $arguments) = $route;
$url = route($route, transform_button_args($arguments));
} else {
// else just call it normally
$url = route($route);
}
} elseif (($direct = array_get($btn, 'btn-link', null)) !== null) {
$url = $direct;
}
// build the template
$tpl = '<a class="%1$s" href="%2$s">%3$s</a>';
if (!empty($extras)) {
$tpl = '<a class="%1$s" href="%2$s" '.implode(' ', $extras).'>%3$s</a>';
}
// build the button wrapper
return sprintf($tpl, array_get($btn, 'btn-class'), $url, $label);
}
}