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