]> git.mxchange.org Git - friendica.git/blob - src/Module/Friendica.php
c5a66fa3d5038ffc0e23f6caa22a95899a4250f9
[friendica.git] / src / Module / Friendica.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU Affero General Public License as
9  * published by the Free Software Foundation, either version 3 of the
10  * License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU Affero General Public License for more details.
16  *
17  * You should have received a copy of the GNU Affero General Public License
18  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
19  *
20  */
21
22 namespace Friendica\Module;
23
24 use Friendica\BaseModule;
25 use Friendica\Core\Addon;
26 use Friendica\Core\Hook;
27 use Friendica\Core\Renderer;
28 use Friendica\Core\System;
29 use Friendica\Database\PostUpdate;
30 use Friendica\DI;
31 use Friendica\Model\User;
32 use Friendica\Network\HTTPException;
33 use Friendica\Protocol\ActivityPub;
34
35 /**
36  * Prints information about the current node
37  * Either in human readable form or in JSON
38  */
39 class Friendica extends BaseModule
40 {
41         protected function content(array $request = []): string
42         {
43                 $config = DI::config();
44
45                 $visibleAddonList = Addon::getVisibleList();
46                 if (!empty($visibleAddonList)) {
47
48                         $sorted = $visibleAddonList;
49                         sort($sorted);
50
51                         $sortedAddonList = '';
52
53                         foreach ($sorted as $addon) {
54                                 if (strlen($addon)) {
55                                         if (strlen($sortedAddonList)) {
56                                                 $sortedAddonList .= ', ';
57                                         }
58                                         $sortedAddonList .= $addon;
59                                 }
60                         }
61                         $addon = [
62                                 'title' => DI::l10n()->t('Installed addons/apps:'),
63                                 'list'  => $sortedAddonList,
64                         ];
65                 } else {
66                         $addon = [
67                                 'title' => DI::l10n()->t('No installed addons/apps'),
68                         ];
69                 }
70
71                 $tos = ($config->get('system', 'tosdisplay')) ?
72                         DI::l10n()->t('Read about the <a href="%1$s/tos">Terms of Service</a> of this node.', DI::baseUrl()->get()) :
73                         '';
74
75                 $blockList = $config->get('system', 'blocklist');
76
77                 if (!empty($blockList)) {
78                         $blocked = [
79                                 'title'  => DI::l10n()->t('On this server the following remote servers are blocked.'),
80                                 'header' => [
81                                         DI::l10n()->t('Blocked domain'),
82                                         DI::l10n()->t('Reason for the block'),
83                                 ],
84                                 'list'   => $blockList,
85                         ];
86                 } else {
87                         $blocked = null;
88                 }
89
90                 $hooked = '';
91
92                 Hook::callAll('about_hook', $hooked);
93
94                 $tpl = Renderer::getMarkupTemplate('friendica.tpl');
95
96                 return Renderer::replaceMacros($tpl, [
97                         '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.',
98                                 '<strong>' . FRIENDICA_VERSION . '</strong>',
99                                 DI::baseUrl()->get(),
100                                 '<strong>' . DB_UPDATE_VERSION . '/' . $config->get('system', 'build') .'</strong>',
101                                 '<strong>' . PostUpdate::VERSION . '/' . $config->get('system', 'post_update_version') . '</strong>'),
102                         'friendica' => DI::l10n()->t('Please visit <a href="https://friendi.ca">Friendi.ca</a> to learn more about the Friendica project.'),
103                         '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>',
104                         'info'      => DI::l10n()->t('Suggestions, praise, etc. - please email "info" at "friendi - dot - ca'),
105
106                         'visible_addons' => $addon,
107                         'tos'            => $tos,
108                         'block_list'     => $blocked,
109                         'hooked'         => $hooked,
110                 ]);
111         }
112
113         protected function rawContent(array $request = [])
114         {
115                 // @TODO: Replace with parameter from router
116                 if (DI::args()->getArgc() <= 1 || (DI::args()->getArgv()[1] !== 'json')) {
117                         if (!ActivityPub::isRequest()) {
118                                 return;
119                         }
120
121                         try {
122                                 $data = ActivityPub\Transmitter::getProfile(0);
123                                 header('Access-Control-Allow-Origin: *');
124                                 header('Cache-Control: max-age=23200, stale-while-revalidate=23200');
125                                 System::jsonExit($data, 'application/activity+json');
126                         } catch (HTTPException\NotFoundException $e) {
127                                 System::jsonError(404, ['error' => 'Record not found']);
128                         }
129                 }
130
131                 $config = DI::config();
132
133                 $register_policies = [
134                         Register::CLOSED  => 'REGISTER_CLOSED',
135                         Register::APPROVE => 'REGISTER_APPROVE',
136                         Register::OPEN    => 'REGISTER_OPEN'
137                 ];
138
139                 $register_policy_int = intval($config->get('config', 'register_policy'));
140                 if ($register_policy_int !== Register::CLOSED && $config->get('config', 'invitation_only')) {
141                         $register_policy = 'REGISTER_INVITATION';
142                 } else {
143                         $register_policy = $register_policies[$register_policy_int];
144                 }
145
146                 $admin = [];
147                 $administrator = User::getFirstAdmin(['username', 'nickname']);
148                 if (!empty($administrator)) {
149                         $admin = [
150                                 'name'    => $administrator['username'],
151                                 'profile' => DI::baseUrl()->get() . '/profile/' . $administrator['nickname'],
152                         ];
153                 }
154
155                 $visible_addons = Addon::getVisibleList();
156
157                 $config->load('feature_lock');
158                 $locked_features = [];
159                 $featureLocks = $config->get('config', 'feature_lock');
160                 if (isset($featureLocks)) {
161                         foreach ($featureLocks as $feature => $lock) {
162                                 if ($feature === 'config_loaded') {
163                                         continue;
164                                 }
165
166                                 $locked_features[$feature] = intval($lock);
167                         }
168                 }
169
170                 $data = [
171                         'version'          => FRIENDICA_VERSION,
172                         'url'              => DI::baseUrl()->get(),
173                         'addons'           => $visible_addons,
174                         'locked_features'  => $locked_features,
175                         'explicit_content' => intval($config->get('system', 'explicit_content', 0)),
176                         'language'         => $config->get('system', 'language'),
177                         'register_policy'  => $register_policy,
178                         'admin'            => $admin,
179                         'site_name'        => $config->get('config', 'sitename'),
180                         'platform'         => strtolower(FRIENDICA_PLATFORM),
181                         'info'             => $config->get('config', 'info'),
182                         'no_scrape_url'    => DI::baseUrl()->get() . '/noscrape',
183                 ];
184
185                 System::jsonExit($data);
186         }
187 }