]> git.mxchange.org Git - friendica.git/blob - src/Model/Nodeinfo.php
Remove next link when there aren't any introductions in Module\Api\Mastodon\FollowReq...
[friendica.git] / src / Model / Nodeinfo.php
1 <?php
2
3 namespace Friendica\Model;
4
5 use Friendica\Core\Addon;
6 use Friendica\Database\DBA;
7 use Friendica\DI;
8
9 /**
10  * Model interaction for the nodeinfo
11  */
12 class Nodeinfo
13 {
14         /**
15          * Updates the info about the current node
16          *
17          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
18          */
19         public static function update()
20         {
21                 $config = DI::config();
22                 $logger = DI::logger();
23
24                 // If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
25                 if (Addon::isEnabled('statistics_json')) {
26                         $config->set('system', 'nodeinfo', true);
27
28                         $addon = 'statistics_json';
29                         $addons = $config->get('system', 'addon');
30
31                         if ($addons) {
32                                 $addons_arr = explode(',', str_replace(' ', '', $addons));
33
34                                 $idx = array_search($addon, $addons_arr);
35                                 if ($idx !== false) {
36                                         unset($addons_arr[$idx]);
37                                         Addon::uninstall($addon);
38                                         $config->set('system', 'addon', implode(', ', $addons_arr));
39                                 }
40                         }
41                 }
42
43                 if (empty($config->get('system', 'nodeinfo'))) {
44                         return;
45                 }
46
47                 $userStats = User::getStatistics();
48
49                 $config->set('nodeinfo', 'total_users', $userStats['total_users']);
50                 $config->set('nodeinfo', 'active_users_halfyear', $userStats['active_users_halfyear']);
51                 $config->set('nodeinfo', 'active_users_monthly', $userStats['active_users_monthly']);
52
53                 $logger->debug('user statistics', $userStats);
54
55                 $items = DBA::p("SELECT COUNT(*) AS `total`, `gravity` FROM `item` WHERE `origin` AND NOT `deleted` AND `uid` != 0 AND `gravity` IN (?, ?) GROUP BY `gravity`",
56                         GRAVITY_PARENT, GRAVITY_COMMENT);
57                 while ($item = DBA::fetch($items)) {
58                         if ($item['gravity'] == GRAVITY_PARENT) {
59                                 $config->set('nodeinfo', 'local_posts', $item['total']);
60                         } elseif ($item['gravity'] == GRAVITY_COMMENT) {
61                                 $config->set('nodeinfo', 'local_comments', $item['total']);
62                         }
63                 }
64                 DBA::close($items);
65         }
66 }