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