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