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