]> git.mxchange.org Git - friendica.git/blob - src/Module/Friendica.php
cleanup namespace usages for L10n
[friendica.git] / src / Module / Friendica.php
1 <?php
2
3 namespace Friendica\Module;
4
5 use Friendica\BaseModule;
6 use Friendica\Core\Addon;
7 use Friendica\Core\Hook;
8 use Friendica\Core\Renderer;
9 use Friendica\DI;
10 use Friendica\Model\User;
11
12 /**
13  * Prints information about the current node
14  * Either in human readable form or in JSON
15  */
16 class Friendica extends BaseModule
17 {
18         public static function content(array $parameters = [])
19         {
20                 $config = DI::config();
21
22                 $visibleAddonList = Addon::getVisibleList();
23                 if (!empty($visibleAddonList)) {
24
25                         $sorted = $visibleAddonList;
26                         sort($sorted);
27
28                         $sortedAddonList = '';
29
30                         foreach ($sorted as $addon) {
31                                 if (strlen($addon)) {
32                                         if (strlen($sortedAddonList)) {
33                                                 $sortedAddonList .= ', ';
34                                         }
35                                         $sortedAddonList .= $addon;
36                                 }
37                         }
38                         $addon = [
39                                 'title' => DI::l10n()->t('Installed addons/apps:'),
40                                 'list'  => $sortedAddonList,
41                         ];
42                 } else {
43                         $addon = [
44                                 'title' => DI::l10n()->t('No installed addons/apps'),
45                         ];
46                 }
47
48                 $tos = ($config->get('system', 'tosdisplay')) ?
49                         DI::l10n()->t('Read about the <a href="%1$s/tos">Terms of Service</a> of this node.', DI::baseUrl()->get()) :
50                         '';
51
52                 $blockList = $config->get('system', 'blocklist');
53
54                 if (!empty($blockList)) {
55                         $blocked = [
56                                 'title'  => DI::l10n()->t('On this server the following remote servers are blocked.'),
57                                 'header' => [
58                                         DI::l10n()->t('Blocked domain'),
59                                         DI::l10n()->t('Reason for the block'),
60                                 ],
61                                 'list'   => $blockList,
62                         ];
63                 } else {
64                         $blocked = null;
65                 }
66
67                 $hooked = '';
68
69                 Hook::callAll('about_hook', $hooked);
70
71                 $tpl = Renderer::getMarkupTemplate('friendica.tpl');
72
73                 return Renderer::replaceMacros($tpl, [
74                         'about'     => DI::l10n()->t('This is Friendica, version %s that is running at the web location %s. The database version is %s, the post update version is %s.',
75                                 '<strong>' . FRIENDICA_VERSION . '</strong>',
76                                 DI::baseUrl()->get(),
77                                 '<strong>' . DB_UPDATE_VERSION . '</strong>',
78                                 '<strong>' . $config->get('system', 'post_update_version') . '</strong>'),
79                         'friendica' => DI::l10n()->t('Please visit <a href="https://friendi.ca">Friendi.ca</a> to learn more about the Friendica project.'),
80                         'bugs'      => DI::l10n()->t('Bug reports and issues: please visit') . ' ' . '<a href="https://github.com/friendica/friendica/issues?state=open">' . DI::l10n()->t('the bugtracker at github') . '</a>',
81                         'info'      => DI::l10n()->t('Suggestions, praise, etc. - please email "info" at "friendi - dot - ca'),
82
83                         'visible_addons' => $addon,
84                         'tos'            => $tos,
85                         'block_list'     => $blocked,
86                         'hooked'         => $hooked,
87                 ]);
88         }
89
90         public static function rawContent(array $parameters = [])
91         {
92                 $app = DI::app();
93
94                 // @TODO: Replace with parameter from router
95                 if ($app->argc <= 1 || ($app->argv[1] !== 'json')) {
96                         return;
97                 }
98
99                 $config = DI::config();
100
101                 $register_policies = [
102                         Register::CLOSED  => 'REGISTER_CLOSED',
103                         Register::APPROVE => 'REGISTER_APPROVE',
104                         Register::OPEN    => 'REGISTER_OPEN'
105                 ];
106
107                 $register_policy_int = intval($config->get('config', 'register_policy'));
108                 if ($register_policy_int !== Register::CLOSED && $config->get('config', 'invitation_only')) {
109                         $register_policy = 'REGISTER_INVITATION';
110                 } else {
111                         $register_policy = $register_policies[$register_policy_int];
112                 }
113
114                 $condition = [];
115                 $admin = false;
116                 if (!empty($config->get('config', 'admin_nickname'))) {
117                         $condition['nickname'] = $config->get('config', 'admin_nickname');
118                 }
119                 if (!empty($config->get('config', 'admin_email'))) {
120                         $adminList = explode(',', str_replace(' ', '', $config->get('config', 'admin_email')));
121                         $condition['email'] = $adminList[0];
122                         $administrator = User::getByEmail($adminList[0], ['username', 'nickname']);
123                         if (!empty($administrator)) {
124                                 $admin = [
125                                         'name'    => $administrator['username'],
126                                         'profile' => DI::baseUrl()->get() . '/profile/' . $administrator['nickname'],
127                                 ];
128                         }
129                 }
130
131                 $visible_addons = Addon::getVisibleList();
132
133                 $config->load('feature_lock');
134                 $locked_features = [];
135                 $featureLocks = $config->get('config', 'feature_lock');
136                 if (isset($featureLocks)) {
137                         foreach ($featureLocks as $feature => $lock) {
138                                 if ($feature === 'config_loaded') {
139                                         continue;
140                                 }
141
142                                 $locked_features[$feature] = intval($lock);
143                         }
144                 }
145
146                 $data = [
147                         'version'          => FRIENDICA_VERSION,
148                         'url'              => DI::baseUrl()->get(),
149                         'addons'           => $visible_addons,
150                         'locked_features'  => $locked_features,
151                         'explicit_content' => intval($config->get('system', 'explicit_content', 0)),
152                         'language'         => $config->get('system', 'language'),
153                         'register_policy'  => $register_policy,
154                         'admin'            => $admin,
155                         'site_name'        => $config->get('config', 'sitename'),
156                         'platform'         => strtolower(FRIENDICA_PLATFORM),
157                         'info'             => $config->get('config', 'info'),
158                         'no_scrape_url'    => DI::baseUrl()->get() . '/noscrape',
159                 ];
160
161                 header('Content-type: application/json; charset=utf-8');
162                 echo json_encode($data);
163                 exit();
164         }
165 }