-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathAdminUtils.php
More file actions
140 lines (121 loc) · 4.43 KB
/
Copy pathAdminUtils.php
File metadata and controls
140 lines (121 loc) · 4.43 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/**
* Copyright (C) 2015-2019 FeatherBB
* based on code by (C) 2008-2015 FluxBB
* and Rickard Andersson (C) 2002-2008 PunBB
* License: http://www.gnu.org/licenses/gpl.html GPL version 2 or higher
*/
namespace FeatherBB\Core;
use FeatherBB\Core\Interfaces\Cache;
use FeatherBB\Core\Interfaces\Container;
use FeatherBB\Core\Interfaces\Lang;
use FeatherBB\Core\Interfaces\View;
use FeatherBB\Core\Interfaces\Hooks;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
class AdminUtils
{
public static function generateAdminMenu($page = '')
{
Lang::load('admin/common');
View::setPageInfo([
'page' => $page,
'menu_items' => Hooks::fire('admin.menu', self::loadDefaultMenu()),
'plugins' => self::adminPluginsMenu() // See if there are any plugins that want to be displayed in the menu
]
)->addTemplate('admin/menu.php');
}
/**
* Add plugin options to menu if needed
*/
public static function adminPluginsMenu()
{
$menuItems = [];
$menuItems = Hooks::fire('admin.plugin.menu', $menuItems);
return $menuItems;
}
/**
* Generate breadcrumbs from an array of name and URLs
*/
public static function breadcrumbsAdmin(array $links)
{
$tmp = [];
foreach ($links as $name => $url) {
if ($name != '' && $url != '') {
$tmp[] = '<span><a href="' . $url . '">'.Utils::escape($name).'</a></span>';
} else {
$tmp[] = '<span>'.__('Deleted').'</span>';
return implode(' » ', $tmp);
}
}
return implode(' » ', $tmp);
}
/**
* Delete a folder and all its content
*/
public static function deleteFolder($dirPath)
{
$it = new RecursiveDirectoryIterator($dirPath, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it,
RecursiveIteratorIterator::CHILD_FIRST);
foreach ($files as $file) {
if ($file->isDir()) {
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}
rmdir($dirPath);
}
/**
* Fetch admin IDs
*/
public static function getAdminIds()
{
if (!Cache::isCached('admin_ids')) {
Cache::store('admin_ids', \FeatherBB\Model\Cache::getAdminIds());
}
return Cache::retrieve('admin_ids');
}
/**
* Wrapper for cURL
*/
public static function getContent($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, "FeatherBB Marketplace");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$content = curl_exec($ch);
$httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpStatus != 200) {
return false;
}
return $content;
}
protected static function loadDefaultMenu()
{
return [
'mod.index' => ['title' => 'Index', 'url' => 'adminIndex'],
'mod.users' => ['title' => 'Users', 'url' => 'adminUsers'],
'mod.bans' => ['title' => 'Bans', 'url' => 'adminBans'],
'mod.reports' => ['title' => 'Reports', 'url' => 'adminReports'],
'board.options' => ['title' => 'Admin options', 'url' => 'adminOptions'],
'board.permissions' => ['title' => 'Permissions', 'url' => 'adminPermissions'],
'board.categories' => ['title' => 'Categories', 'url' => 'adminCategories'],
'board.forums' => ['title' => 'Forums', 'url' => 'adminForums'],
'board.groups' => ['title' => 'User groups', 'url' => 'adminGroups'],
'board.plugins' => ['title' => 'Plugins', 'url' => 'adminPlugins'],
'board.censoring' => ['title' => 'Censoring', 'url' => 'adminCensoring'],
'board.parser' => ['title' => 'Parser', 'url' => 'adminParser'],
'board.maintenance' => ['title' => 'Maintenance', 'url' => 'adminMaintenance'],
'board.updates' => ['title' => 'Updates', 'url' => 'adminUpdates']
];
}
}