Merge pull request #6694 from Quix0r/rewrites/added-missing-var-init
[friendica.git/.git] / mod / friendica.php
1 <?php
2 /**
3  * @file mod/friendica.php
4  */
5
6 use Friendica\App;
7 use Friendica\Core\Addon;
8 use Friendica\Core\Config;
9 use Friendica\Core\Hook;
10 use Friendica\Core\L10n;
11 use Friendica\Core\System;
12 use Friendica\Database\DBA;
13 use Friendica\Module\Register;
14
15 function friendica_init(App $a)
16 {
17         if (!empty($a->argv[1]) && ($a->argv[1] == "json")) {
18                 $register_policies = [
19                         Register::CLOSED  => 'REGISTER_CLOSED',
20                         Register::APPROVE => 'REGISTER_APPROVE',
21                         Register::OPEN    => 'REGISTER_OPEN'
22                 ];
23
24                 $register_policy_int = intval(Config::get('config', 'register_policy'));
25                 if ($register_policy_int !== Register::CLOSED && Config::get('config', 'invitation_only')) {
26                         $register_policy = 'REGISTER_INVITATION';
27                 } else {
28                         $register_policy = $register_policies[$register_policy_int];
29                 }
30
31                 $condition = [];
32                 $admin = false;
33                 if (!empty(Config::get('config', 'admin_nickname'))) {
34                         $condition['nickname'] = Config::get('config', 'admin_nickname');
35                 }
36                 if (!empty(Config::get('config', 'admin_email'))) {
37                         $adminlist = explode(",", str_replace(" ", "", Config::get('config', 'admin_email')));
38                         $condition['email'] = $adminlist[0];
39                         $administrator = DBA::selectFirst('user', ['username', 'nickname'], $condition);
40                         if (DBA::isResult($administrator)) {
41                                 $admin = [
42                                         'name' => $administrator['username'],
43                                         'profile'=> System::baseUrl() . '/profile/' . $administrator['nickname'],
44                                 ];
45                         }
46                 }
47
48                 $visible_addons = Addon::getVisibleList();
49
50                 Config::load('feature_lock');
51                 $locked_features = [];
52                 $featureLock = Config::get('config', 'feature_lock');
53                 if (isset($featureLock)) {
54                         foreach ($featureLock as $k => $v) {
55                                 if ($k === 'config_loaded') {
56                                         continue;
57                                 }
58
59                                 $locked_features[$k] = intval($v);
60                         }
61                 }
62
63                 $data = [
64                         'version'          => FRIENDICA_VERSION,
65                         'url'              => System::baseUrl(),
66                         'addons'           => $visible_addons,
67                         'locked_features'  => $locked_features,
68                         'explicit_content' => (int)Config::get('system', 'explicit_content', false),
69                         'language'         => Config::get('system','language'),
70                         'register_policy'  => $register_policy,
71                         'admin'            => $admin,
72                         'site_name'        => Config::get('config', 'sitename'),
73                         'platform'         => FRIENDICA_PLATFORM,
74                         'info'             => Config::get('config', 'info'),
75                         'no_scrape_url'    => System::baseUrl().'/noscrape'
76                 ];
77
78                 header('Content-type: application/json; charset=utf-8');
79                 echo json_encode($data);
80                 exit();
81         }
82 }
83
84 function friendica_content(App $a)
85 {
86         $o = '<h1>Friendica</h1>' . PHP_EOL;
87         $o .= '<p>';
88         $o .= 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.',
89                 '<strong>' . FRIENDICA_VERSION . '</strong>', System::baseUrl(), '<strong>' . DB_UPDATE_VERSION . '</strong>',
90                 '<strong>' . Config::get("system", "post_update_version") . '</strong>');
91         $o .= '</p>' . PHP_EOL;
92
93         $o .= '<p>';
94         $o .= L10n::t('Please visit <a href="https://friendi.ca">Friendi.ca</a> to learn more about the Friendica project.') . PHP_EOL;
95         $o .= '</p>' . PHP_EOL;
96
97         $o .= '<p>';
98         $o .= 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>';
99         $o .= '</p>' . PHP_EOL;
100         $o .= '<p>';
101         $o .= L10n::t('Suggestions, praise, etc. - please email "info" at "friendi - dot - ca');
102         $o .= '</p>' . PHP_EOL;
103
104         $visible_addons = Addon::getVisibleList();
105         if (count($visible_addons)) {
106                 $o .= '<p>' . L10n::t('Installed addons/apps:') . '</p>' . PHP_EOL;
107                 $sorted = $visible_addons;
108                 $s = '';
109                 sort($sorted);
110                 foreach ($sorted as $p) {
111                         if (strlen($p)) {
112                                 if (strlen($s)) {
113                                         $s .= ', ';
114                                 }
115                                 $s .= $p;
116                         }
117                 }
118                 $o .= '<div style="margin-left: 25px; margin-right: 25px; margin-bottom: 25px;">' . $s . '</div>' . PHP_EOL;
119         } else {
120                 $o .= '<p>' . L10n::t('No installed addons/apps') . '</p>' . PHP_EOL;
121         }
122
123         if (Config::get('system', 'tosdisplay'))
124         {
125                 $o .= '<p>'.L10n::t('Read about the <a href="%1$s/tos">Terms of Service</a> of this node.', System::baseurl()).'</p>';
126         }
127
128         $blocklist = Config::get('system', 'blocklist', []);
129         if (!empty($blocklist)) {
130                 $o .= '<div id="about_blocklist"><p>' . L10n::t('On this server the following remote servers are blocked.') . '</p>' . PHP_EOL;
131                 $o .= '<table class="table"><thead><tr><th>' . L10n::t('Blocked domain') . '</th><th>' . L10n::t('Reason for the block') . '</th></thead><tbody>' . PHP_EOL;
132                 foreach ($blocklist as $b) {
133                         $o .= '<tr><td>' . $b['domain'] .'</td><td>' . $b['reason'] . '</td></tr>' . PHP_EOL;
134                 }
135                 $o .= '</tbody></table></div>' . PHP_EOL;
136         }
137
138         Hook::callAll('about_hook', $o);
139
140         return $o;
141 }