]> git.mxchange.org Git - friendica.git/blob - src/Module/BaseAdminModule.php
Replace deprecated $a->page with DI::page()
[friendica.git] / src / Module / BaseAdminModule.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\BaseModule;
6 use Friendica\Core\Addon;
7 use Friendica\Core\L10n;
8 use Friendica\Core\Renderer;
9 use Friendica\Core\Session;
10 use Friendica\DI;
11 use Friendica\Network\HTTPException\ForbiddenException;
12
13 require_once 'boot.php';
14
15 /**
16  * This abstract module is meant to be extended by all modules that are reserved to administrator users.
17  *
18  * It performs a blanket permission check in all the module methods as long as the relevant `parent::method()` is
19  * called in the inheriting module.
20  *
21  * Additionally, it puts together the administration page aside with all the administration links.
22  *
23  * @package Friendica\Module
24  */
25 abstract class BaseAdminModule extends BaseModule
26 {
27         public static function post(array $parameters = [])
28         {
29                 if (!is_site_admin()) {
30                         return;
31                 }
32
33                 // do not allow a page manager to access the admin panel at all.
34                 if (!empty($_SESSION['submanage'])) {
35                         return;
36                 }
37         }
38
39         public static function rawContent(array $parameters = [])
40         {
41                 if (!is_site_admin()) {
42                         return '';
43                 }
44
45                 if (!empty($_SESSION['submanage'])) {
46                         return '';
47                 }
48
49                 return '';
50         }
51
52         public static function content(array $parameters = [])
53         {
54                 if (!is_site_admin()) {
55                         notice(L10n::t('Please login to continue.'));
56                         Session::set('return_path', DI::args()->getQueryString());
57                         DI::baseUrl()->redirect('login');
58                 }
59
60                 if (!empty($_SESSION['submanage'])) {
61                         throw new ForbiddenException(L10n::t('Submanaged account can\'t access the administation pages. Please log back in as the master account.'));
62                 }
63
64                 // Header stuff
65                 DI::page()['htmlhead'] .= Renderer::replaceMacros(Renderer::getMarkupTemplate('admin/settings_head.tpl'), []);
66
67                 /*
68                  * Side bar links
69                  */
70
71                 // array(url, name, extra css classes)
72                 // not part of $aside to make the template more adjustable
73                 $aside_sub = [
74                         'information' => [L10n::t('Information'), [
75                                 'overview'     => ['admin'             , L10n::t('Overview')                , 'overview'],
76                                 'federation'   => ['admin/federation'  , L10n::t('Federation Statistics')   , 'federation']
77                         ]],
78                         'configuration' => [L10n::t('Configuration'), [
79                                 'site'         => ['admin/site'        , L10n::t('Site')                    , 'site'],
80                                 'users'        => ['admin/users'       , L10n::t('Users')                   , 'users'],
81                                 'addons'       => ['admin/addons'      , L10n::t('Addons')                  , 'addons'],
82                                 'themes'       => ['admin/themes'      , L10n::t('Themes')                  , 'themes'],
83                                 'features'     => ['admin/features'    , L10n::t('Additional features')     , 'features'],
84                                 'tos'          => ['admin/tos'         , L10n::t('Terms of Service')        , 'tos'],
85                         ]],
86                         'database' => [L10n::t('Database'), [
87                                 'dbsync'       => ['admin/dbsync'      , L10n::t('DB updates')              , 'dbsync'],
88                                 'deferred'     => ['admin/queue/deferred', L10n::t('Inspect Deferred Workers'), 'deferred'],
89                                 'workerqueue'  => ['admin/queue'       , L10n::t('Inspect worker Queue')    , 'workerqueue'],
90                         ]],
91                         'tools' => [L10n::t('Tools'), [
92                                 'contactblock' => ['admin/blocklist/contact', L10n::t('Contact Blocklist')  , 'contactblock'],
93                                 'blocklist'    => ['admin/blocklist/server' , L10n::t('Server Blocklist')   , 'blocklist'],
94                                 'deleteitem'   => ['admin/item/delete' , L10n::t('Delete Item')             , 'deleteitem'],
95                         ]],
96                         'logs' => [L10n::t('Logs'), [
97                                 'logsconfig'   => ['admin/logs/', L10n::t('Logs')                           , 'logs'],
98                                 'logsview'     => ['admin/logs/view'    , L10n::t('View Logs')              , 'viewlogs'],
99                         ]],
100                         'diagnostics' => [L10n::t('Diagnostics'), [
101                                 'phpinfo'      => ['admin/phpinfo'           , L10n::t('PHP Info')          , 'phpinfo'],
102                                 'probe'        => ['probe'             , L10n::t('probe address')           , 'probe'],
103                                 'webfinger'    => ['webfinger'         , L10n::t('check webfinger')         , 'webfinger'],
104                                 'itemsource'   => ['admin/item/source' , L10n::t('Item Source')             , 'itemsource'],
105                                 'babel'        => ['babel'             , L10n::t('Babel')                   , 'babel'],
106                         ]],
107                 ];
108
109                 $t = Renderer::getMarkupTemplate('admin/aside.tpl');
110                 DI::page()['aside'] .= Renderer::replaceMacros($t, [
111                         '$admin' => ['addons_admin' => Addon::getAdminList()],
112                         '$subpages' => $aside_sub,
113                         '$admtxt' => L10n::t('Admin'),
114                         '$plugadmtxt' => L10n::t('Addon Features'),
115                         '$h_pending' => L10n::t('User registrations waiting for confirmation'),
116                         '$admurl' => 'admin/'
117                 ]);
118
119                 return '';
120         }
121 }