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