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