2019-04-22 14:00:17 +02:00
< ? php
2020-02-09 15:45:36 +01:00
/**
* @ copyright Copyright ( C ) 2020 , Friendica
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*
*/
2019-04-22 14:00:17 +02:00
namespace Friendica\Model ;
use Friendica\Core\Addon ;
use Friendica\Database\DBA ;
2019-12-15 22:34:11 +01:00
use Friendica\DI ;
2019-04-22 14:00:17 +02:00
/**
* Model interaction for the nodeinfo
*/
2019-12-15 23:28:01 +01:00
class Nodeinfo
2019-04-22 14:00:17 +02:00
{
/**
* Updates the info about the current node
*
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function update ()
{
2019-12-15 23:44:33 +01:00
$config = DI :: config ();
2019-12-15 23:46:56 +01:00
$logger = DI :: logger ();
2019-04-22 14:00:17 +02:00
// If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
if ( Addon :: isEnabled ( 'statistics_json' )) {
$config -> set ( 'system' , 'nodeinfo' , true );
$addon = 'statistics_json' ;
$addons = $config -> get ( 'system' , 'addon' );
if ( $addons ) {
$addons_arr = explode ( ',' , str_replace ( ' ' , '' , $addons ));
$idx = array_search ( $addon , $addons_arr );
if ( $idx !== false ) {
unset ( $addons_arr [ $idx ]);
Addon :: uninstall ( $addon );
$config -> set ( 'system' , 'addon' , implode ( ', ' , $addons_arr ));
}
}
}
if ( empty ( $config -> get ( 'system' , 'nodeinfo' ))) {
return ;
}
$userStats = User :: getStatistics ();
$config -> set ( 'nodeinfo' , 'total_users' , $userStats [ 'total_users' ]);
$config -> set ( 'nodeinfo' , 'active_users_halfyear' , $userStats [ 'active_users_halfyear' ]);
$config -> set ( 'nodeinfo' , 'active_users_monthly' , $userStats [ 'active_users_monthly' ]);
$logger -> debug ( 'user statistics' , $userStats );
2020-01-11 15:25:43 +01:00
$items = DBA :: p ( " SELECT COUNT(*) AS `total`, `gravity` FROM `item` WHERE `origin` AND NOT `deleted` AND `uid` != 0 AND `gravity` IN (?, ?) GROUP BY `gravity` " ,
GRAVITY_PARENT , GRAVITY_COMMENT );
while ( $item = DBA :: fetch ( $items )) {
if ( $item [ 'gravity' ] == GRAVITY_PARENT ) {
$config -> set ( 'nodeinfo' , 'local_posts' , $item [ 'total' ]);
} elseif ( $item [ 'gravity' ] == GRAVITY_COMMENT ) {
$config -> set ( 'nodeinfo' , 'local_comments' , $item [ 'total' ]);
}
}
DBA :: close ( $items );
2019-04-22 14:00:17 +02:00
}
}