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