-
-
Notifications
You must be signed in to change notification settings - Fork 455
/
Text.php
108 lines (94 loc) · 3.3 KB
/
Text.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
<?php
/**
* This file is part of the Froxlor project.
* Copyright (c) 2010 the Froxlor Team (see authors).
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you can also view it online at
* https://files.froxlor.org/misc/COPYING.txt
*
* @copyright the authors
* @author Froxlor team <team@froxlor.org>
* @license https://files.froxlor.org/misc/COPYING.txt GPLv2
*/
namespace Froxlor\UI\Callbacks;
use Froxlor\Froxlor;
use Froxlor\PhpHelper;
use Froxlor\UI\Panel\UI;
use Froxlor\User;
class Text
{
public static function boolean(array $attributes): array
{
return [
'macro' => 'boolean',
'data' => (bool)$attributes['data']
];
}
public static function customerfullname(array $attributes): string
{
return User::getCorrectFullUserDetails($attributes['fields'], true);
}
public static function size(array $attributes): string
{
return PhpHelper::sizeReadable($attributes['data'], null, 'bi');
}
public static function timestamp(array $attributes): string
{
return (int)$attributes['data'] > 0 ? date('d.m.Y H:i', (int)$attributes['data']) : lng('panel.never');
}
public static function timestampUntil(array $attributes): string
{
return (int)$attributes['data'] > 0 ? date('d.m.Y H:i', (int)$attributes['data']) : lng('panel.unlimited');
}
public static function crondesc(array $attributes): string
{
return lng('crondesc.' . $attributes['data']);
}
public static function shorten(array $attributes): string
{
return substr($attributes['data'], 0, 20) . '...';
}
public static function wordwrap(array $attributes): string
{
return wordwrap($attributes['data'], 100, '<br>', true);
}
public static function customerNoteDetailModal(array $attributes): array
{
$note = $attributes['fields']['custom_notes'] ?? '';
return [
'entry' => $attributes['fields']['id'],
'id' => 'cnModal' . $attributes['fields']['id'],
'title' => lng('usersettings.custom_notes.title') . ': ' . ($attributes['fields']['loginname'] ?? $attributes['fields']['adminname']),
'body' => nl2br($note)
];
}
public static function apikeyDetailModal(array $attributes): array
{
$linker = UI::getLinker();
$result = $attributes['fields'];
$apikey_data = include Froxlor::getInstallDir() . '/lib/formfields/formfield.api_key.php';
$body = UI::twig()->render(UI::validateThemeTemplate('/user/inline-form.html.twig'), [
'formaction' => $linker->getLink(['section' => 'index', 'page' => 'apikeys']),
'formdata' => $apikey_data['apikey'],
'editid' => $attributes['fields']['id']
]);
return [
'entry' => $attributes['fields']['id'],
'id' => 'akModal' . $attributes['fields']['id'],
'title' => 'API-key ' . ($attributes['fields']['loginname'] ?? $attributes['fields']['adminname']),
'action' => 'apikeys',
'body' => $body
];
}
}