2019-04-22 12:00:17 +00:00
< ? php
2020-02-09 14:45:36 +00:00
/**
2022-01-02 07:27:47 +00:00
* @ copyright Copyright ( C ) 2010 - 2022 , the Friendica project
2020-02-09 14:45:36 +00:00
*
* @ 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 12:00:17 +00:00
namespace Friendica\Model ;
use Friendica\Core\Addon ;
2022-06-18 23:10:50 +00:00
use Friendica\Core\Config\Capability\IManageConfigValues ;
2019-04-22 12:00:17 +00:00
use Friendica\Database\DBA ;
2019-12-15 21:34:11 +00:00
use Friendica\DI ;
2022-09-12 21:12:11 +00:00
use Friendica\Model\Item ;
2020-07-13 09:45:45 +00:00
use stdClass ;
2019-04-22 12:00:17 +00:00
/**
* Model interaction for the nodeinfo
*/
2019-12-15 22:28:01 +00:00
class Nodeinfo
2019-04-22 12:00:17 +00:00
{
/**
* Updates the info about the current node
*
* @ throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function update ()
{
2019-12-15 22:44:33 +00:00
$config = DI :: config ();
2019-12-15 22:46:56 +00:00
$logger = DI :: logger ();
2019-04-22 12:00:17 +00:00
// If the addon 'statistics_json' is enabled then disable it and activate nodeinfo.
if ( Addon :: isEnabled ( 'statistics_json' )) {
$config -> set ( 'system' , 'nodeinfo' , true );
2020-03-09 23:28:37 +00:00
Addon :: uninstall ( 'statistics_json' );
2019-04-22 12:00:17 +00:00
}
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' ]);
2020-07-12 21:53:17 +00:00
$config -> set ( 'nodeinfo' , 'active_users_weekly' , $userStats [ 'active_users_weekly' ]);
2019-04-22 12:00:17 +00:00
2021-02-20 20:07:25 +00:00
$logger -> info ( 'user statistics' , $userStats );
2022-09-24 17:56:07 +00:00
$posts = DBA :: count ( 'post-thread' , [ " `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE NOT `deleted` AND `origin`) " ]);
2022-09-12 21:12:11 +00:00
$comments = DBA :: count ( 'post' , [ " NOT `deleted` AND `gravity` = ? AND `uri-id` IN (SELECT `uri-id` FROM `post-user` WHERE `origin`) " , Item :: GRAVITY_COMMENT ]);
$config -> set ( 'nodeinfo' , 'local_posts' , $posts );
2021-02-20 20:07:25 +00:00
$config -> set ( 'nodeinfo' , 'local_comments' , $comments );
$logger -> info ( 'User actitivy' , [ 'posts' => $posts , 'comments' => $comments ]);
2019-04-22 12:00:17 +00:00
}
2020-07-13 09:45:45 +00:00
/**
* Return the supported services
*
* @ return Object with supported services
*/
public static function getUsage ( bool $version2 = false )
{
$config = DI :: config ();
$usage = new stdClass ();
2022-11-19 15:48:07 +00:00
$usage -> users = new \stdClass ;
2020-07-13 09:45:45 +00:00
if ( ! empty ( $config -> get ( 'system' , 'nodeinfo' ))) {
2022-11-19 15:48:07 +00:00
$usage -> users -> total = intval ( $config -> get ( 'nodeinfo' , 'total_users' ));
$usage -> users -> activeHalfyear = intval ( $config -> get ( 'nodeinfo' , 'active_users_halfyear' ));
$usage -> users -> activeMonth = intval ( $config -> get ( 'nodeinfo' , 'active_users_monthly' ));
2020-07-13 09:45:45 +00:00
$usage -> localPosts = intval ( $config -> get ( 'nodeinfo' , 'local_posts' ));
$usage -> localComments = intval ( $config -> get ( 'nodeinfo' , 'local_comments' ));
if ( $version2 ) {
2022-11-19 15:48:07 +00:00
$usage -> users -> activeWeek = intval ( $config -> get ( 'nodeinfo' , 'active_users_weekly' ));
2020-07-13 09:45:45 +00:00
}
}
return $usage ;
}
/**
* Return the supported services
*
* @ return array with supported services
*/
2022-06-18 15:56:01 +00:00
public static function getServices () : array
2020-07-13 09:45:45 +00:00
{
$services = [
'inbound' => [],
'outbound' => [],
];
if ( Addon :: isEnabled ( 'blogger' )) {
$services [ 'outbound' ][] = 'blogger' ;
}
if ( Addon :: isEnabled ( 'dwpost' )) {
$services [ 'outbound' ][] = 'dreamwidth' ;
}
if ( Addon :: isEnabled ( 'statusnet' )) {
$services [ 'inbound' ][] = 'gnusocial' ;
$services [ 'outbound' ][] = 'gnusocial' ;
}
if ( Addon :: isEnabled ( 'ijpost' )) {
$services [ 'outbound' ][] = 'insanejournal' ;
}
if ( Addon :: isEnabled ( 'libertree' )) {
$services [ 'outbound' ][] = 'libertree' ;
}
if ( Addon :: isEnabled ( 'buffer' )) {
$services [ 'outbound' ][] = 'linkedin' ;
}
if ( Addon :: isEnabled ( 'ljpost' )) {
$services [ 'outbound' ][] = 'livejournal' ;
}
if ( Addon :: isEnabled ( 'buffer' )) {
$services [ 'outbound' ][] = 'pinterest' ;
}
if ( Addon :: isEnabled ( 'posterous' )) {
$services [ 'outbound' ][] = 'posterous' ;
}
if ( Addon :: isEnabled ( 'pumpio' )) {
$services [ 'inbound' ][] = 'pumpio' ;
$services [ 'outbound' ][] = 'pumpio' ;
}
$services [ 'outbound' ][] = 'smtp' ;
if ( Addon :: isEnabled ( 'tumblr' )) {
$services [ 'outbound' ][] = 'tumblr' ;
}
if ( Addon :: isEnabled ( 'twitter' ) || Addon :: isEnabled ( 'buffer' )) {
$services [ 'outbound' ][] = 'twitter' ;
}
if ( Addon :: isEnabled ( 'wppost' )) {
$services [ 'outbound' ][] = 'wordpress' ;
}
return $services ;
}
2022-06-18 23:10:50 +00:00
/**
* Gathers organization information and returns it as an array
*
* @ param IManageConfigValues $config Configuration instance
* @ return array Organization information
2022-11-12 17:01:22 +00:00
* @ throws \Exception
2022-06-18 23:10:50 +00:00
*/
public static function getOrganization ( IManageConfigValues $config ) : array
2020-07-13 09:45:45 +00:00
{
2022-11-12 17:01:22 +00:00
$administrator = User :: getFirstAdmin ([ 'username' , 'email' , 'nickname' ]);
2020-07-13 09:45:45 +00:00
2022-11-12 17:01:22 +00:00
return [
'name' => $administrator [ 'username' ] ? ? null ,
'contact' => $administrator [ 'email' ] ? ? null ,
'account' => $administrator [ 'nickname' ] ? ? '' ? DI :: baseUrl () -> get () . '/profile/' . $administrator [ 'nickname' ] : null ,
];
2020-07-13 09:45:45 +00:00
}
2019-04-22 12:00:17 +00:00
}