]> git.mxchange.org Git - friendica.git/blob - src/Module/Friendica.php
Merge pull request #13110 from anubis2814/develop
[friendica.git] / src / Module / Friendica.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2023, 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\App;
25 use Friendica\BaseModule;
26 use Friendica\Core\Addon;
27 use Friendica\Core\Hook;
28 use Friendica\Core\Renderer;
29 use Friendica\Core\System;
30 use Friendica\Database\PostUpdate;
31 use Friendica\DI;
32 use Friendica\Model\User;
33 use Friendica\Network\HTTPException;
34 use Friendica\Protocol\ActivityPub;
35
36 /**
37  * Prints information about the current node
38  * Either in human readable form or in JSON
39  */
40 class Friendica extends BaseModule
41 {
42         protected function content(array $request = []): string
43         {
44                 $config = DI::config();
45                 $keyValue = DI::keyValue();
46
47                 $visibleAddonList = Addon::getVisibleList();
48                 if (!empty($visibleAddonList)) {
49
50                         $sorted = $visibleAddonList;
51                         sort($sorted);
52
53                         $sortedAddonList = '';
54
55                         foreach ($sorted as $addon) {
56                                 if (strlen($addon)) {
57                                         if (strlen($sortedAddonList)) {
58                                                 $sortedAddonList .= ', ';
59                                         }
60                                         $sortedAddonList .= $addon;
61                                 }
62                         }
63                         $addon = [
64                                 'title' => DI::l10n()->t('Installed addons/apps:'),
65                                 'list'  => $sortedAddonList,
66                         ];
67                 } else {
68                         $addon = [
69                                 'title' => DI::l10n()->t('No installed addons/apps'),
70                         ];
71                 }
72
73                 $tos = ($config->get('system', 'tosdisplay')) ?
74                         DI::l10n()->t('Read about the <a href="%1$s/tos">Terms of Service</a> of this node.', DI::baseUrl()) :
75                         '';
76
77                 $blockList = $config->get('system', 'blocklist');
78
79                 if (!empty($blockList)) {
80                         $blocked = [
81                                 'title'    => DI::l10n()->t('On this server the following remote servers are blocked.'),
82                                 'header'   => [
83                                         DI::l10n()->t('Blocked domain'),
84                                         DI::l10n()->t('Reason for the block'),
85                                 ],
86                                 'download' => DI::l10n()->t('Download this list in CSV format'),
87                                 'list'     => $blockList,
88                         ];
89                 } else {
90                         $blocked = null;
91                 }
92
93                 $hooked = '';
94
95                 Hook::callAll('about_hook', $hooked);
96
97                 $tpl = Renderer::getMarkupTemplate('friendica.tpl');
98
99                 return Renderer::replaceMacros($tpl, [
100                         '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.',
101                                 '<strong>' . App::VERSION . '</strong>',
102                                 DI::baseUrl(),
103                                 '<strong>' . $config->get('system', 'build') . '/' . DB_UPDATE_VERSION . '</strong>',
104                                 '<strong>' . $keyValue->get('post_update_version') . '/' . PostUpdate::VERSION . '</strong>'),
105                         'friendica' => DI::l10n()->t('Please visit <a href="https://friendi.ca">Friendi.ca</a> to learn more about the Friendica project.'),
106                         '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>',
107                         'info'      => DI::l10n()->t('Suggestions, praise, etc. - please email "info" at "friendi - dot - ca'),
108
109                         'visible_addons' => $addon,
110                         'tos'            => $tos,
111                         'block_list'     => $blocked,
112                         'hooked'         => $hooked,
113                 ]);
114         }
115
116         protected function rawContent(array $request = [])
117         {
118                 // @TODO: Replace with parameter from router
119                 if (DI::args()->getArgc() <= 1 || (DI::args()->getArgv()[1] !== 'json')) {
120                         if (!ActivityPub::isRequest()) {
121                                 return;
122                         }
123
124                         try {
125                                 $data = ActivityPub\Transmitter::getProfile(0);
126                                 header('Access-Control-Allow-Origin: *');
127                                 header('Cache-Control: max-age=23200, stale-while-revalidate=23200');
128                                 System::jsonExit($data, 'application/activity+json');
129                         } catch (HTTPException\NotFoundException $e) {
130                                 System::jsonError(404, ['error' => 'Record not found']);
131                         }
132                 }
133
134                 $config = DI::config();
135
136                 $register_policies = [
137                         Register::CLOSED  => 'REGISTER_CLOSED',
138                         Register::APPROVE => 'REGISTER_APPROVE',
139                         Register::OPEN    => 'REGISTER_OPEN'
140                 ];
141
142                 $register_policy_int = intval($config->get('config', 'register_policy'));
143                 if ($register_policy_int !== Register::CLOSED && $config->get('config', 'invitation_only')) {
144                         $register_policy = 'REGISTER_INVITATION';
145                 } else {
146                         $register_policy = $register_policies[$register_policy_int];
147                 }
148
149                 $admin = [];
150                 $administrator = User::getFirstAdmin(['username', 'nickname']);
151                 if (!empty($administrator)) {
152                         $admin = [
153                                 'name'    => $administrator['username'],
154                                 'profile' => DI::baseUrl() . '/profile/' . $administrator['nickname'],
155                         ];
156                 }
157
158                 $visible_addons = Addon::getVisibleList();
159
160                 $config->reload();
161                 $locked_features = [];
162                 $featureLocks = $config->get('config', 'feature_lock');
163                 if (isset($featureLocks)) {
164                         foreach ($featureLocks as $feature => $lock) {
165                                 if ($feature === 'config_loaded') {
166                                         continue;
167                                 }
168
169                                 $locked_features[$feature] = intval($lock);
170                         }
171                 }
172
173                 $data = [
174                         'version'          => App::VERSION,
175                         'url'              => (string)DI::baseUrl(),
176                         'addons'           => $visible_addons,
177                         'locked_features'  => $locked_features,
178                         'explicit_content' => intval($config->get('system', 'explicit_content', 0)),
179                         'language'         => $config->get('system', 'language'),
180                         'register_policy'  => $register_policy,
181                         'admin'            => $admin,
182                         'site_name'        => $config->get('config', 'sitename'),
183                         'platform'         => strtolower(App::PLATFORM),
184                         'info'             => $config->get('config', 'info'),
185                         'no_scrape_url'    => DI::baseUrl() . '/noscrape',
186                 ];
187
188                 System::jsonExit($data);
189         }
190 }