2019-05-04 04:05:21 -04:00
< ? php
2020-02-09 09:45:36 -05:00
/**
2023-01-01 09:36:24 -05:00
* @ copyright Copyright ( C ) 2010 - 2023 , the Friendica project
2020-02-09 09:45:36 -05: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-05-04 04:05:21 -04:00
namespace Friendica\Module ;
2022-10-17 06:37:48 -04:00
use Friendica\App ;
2019-05-04 04:05:21 -04:00
use Friendica\BaseModule ;
use Friendica\Core\Addon ;
use Friendica\Core\Hook ;
use Friendica\Core\Renderer ;
2020-08-22 10:48:09 -04:00
use Friendica\Core\System ;
2020-10-04 16:46:42 -04:00
use Friendica\Database\PostUpdate ;
2019-12-15 16:34:11 -05:00
use Friendica\DI ;
2019-05-04 04:05:21 -04:00
use Friendica\Model\User ;
2021-07-20 13:04:25 -04:00
use Friendica\Network\HTTPException ;
2020-08-22 10:48:09 -04:00
use Friendica\Protocol\ActivityPub ;
2019-05-04 04:05:21 -04:00
2019-05-04 04:18:41 -04:00
/**
* Prints information about the current node
* Either in human readable form or in JSON
*/
2019-05-04 04:05:21 -04:00
class Friendica extends BaseModule
{
2021-11-20 09:38:03 -05:00
protected function content ( array $request = []) : string
2019-05-04 04:05:21 -04:00
{
2019-12-15 17:44:33 -05:00
$config = DI :: config ();
2022-12-29 14:18:13 -05:00
$keyValue = DI :: keyValue ();
2019-05-04 04:05:21 -04:00
$visibleAddonList = Addon :: getVisibleList ();
if ( ! empty ( $visibleAddonList )) {
$sorted = $visibleAddonList ;
sort ( $sorted );
$sortedAddonList = '' ;
foreach ( $sorted as $addon ) {
if ( strlen ( $addon )) {
if ( strlen ( $sortedAddonList )) {
$sortedAddonList .= ', ' ;
}
$sortedAddonList .= $addon ;
}
}
$addon = [
2020-01-18 14:52:34 -05:00
'title' => DI :: l10n () -> t ( 'Installed addons/apps:' ),
2019-05-04 04:05:21 -04:00
'list' => $sortedAddonList ,
];
} else {
$addon = [
2020-01-18 14:52:34 -05:00
'title' => DI :: l10n () -> t ( 'No installed addons/apps' ),
2019-05-04 04:05:21 -04:00
];
}
$tos = ( $config -> get ( 'system' , 'tosdisplay' )) ?
2020-01-18 14:52:34 -05:00
DI :: l10n () -> t ( 'Read about the <a href="%1$s/tos">Terms of Service</a> of this node.' , DI :: baseUrl () -> get ()) :
2019-05-04 04:05:21 -04:00
'' ;
$blockList = $config -> get ( 'system' , 'blocklist' );
if ( ! empty ( $blockList )) {
$blocked = [
2022-07-27 11:54:50 -04:00
'title' => DI :: l10n () -> t ( 'On this server the following remote servers are blocked.' ),
'header' => [
2020-01-18 14:52:34 -05:00
DI :: l10n () -> t ( 'Blocked domain' ),
DI :: l10n () -> t ( 'Reason for the block' ),
2019-05-04 04:05:21 -04:00
],
2022-07-27 11:54:50 -04:00
'download' => DI :: l10n () -> t ( 'Download this list in CSV format' ),
'list' => $blockList ,
2019-05-04 04:05:21 -04:00
];
} else {
$blocked = null ;
}
$hooked = '' ;
Hook :: callAll ( 'about_hook' , $hooked );
$tpl = Renderer :: getMarkupTemplate ( 'friendica.tpl' );
return Renderer :: replaceMacros ( $tpl , [
2020-01-18 14:52:34 -05:00
'about' => DI :: 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.' ,
2022-10-17 06:37:48 -04:00
'<strong>' . App :: VERSION . '</strong>' ,
2019-12-15 19:05:15 -05:00
DI :: baseUrl () -> get (),
2022-06-08 05:46:09 -04:00
'<strong>' . $config -> get ( 'system' , 'build' ) . '/' . DB_UPDATE_VERSION . '</strong>' ,
2022-12-29 14:18:13 -05:00
'<strong>' . $keyValue -> get ( 'post_update_version' ) . '/' . PostUpdate :: VERSION . '</strong>' ),
2020-01-18 14:52:34 -05:00
'friendica' => DI :: l10n () -> t ( 'Please visit <a href="https://friendi.ca">Friendi.ca</a> to learn more about the Friendica project.' ),
'bugs' => DI :: l10n () -> t ( 'Bug reports and issues: please visit' ) . ' ' . '<a href="https://github.com/friendica/friendica/issues?state=open">' . DI :: l10n () -> t ( 'the bugtracker at github' ) . '</a>' ,
'info' => DI :: l10n () -> t ( 'Suggestions, praise, etc. - please email "info" at "friendi - dot - ca' ),
2019-05-04 04:05:21 -04:00
'visible_addons' => $addon ,
'tos' => $tos ,
'block_list' => $blocked ,
'hooked' => $hooked ,
]);
}
2021-11-20 09:38:03 -05:00
protected function rawContent ( array $request = [])
2019-05-04 04:05:21 -04:00
{
2022-03-28 09:12:45 -04:00
// @TODO: Replace with parameter from router
if ( DI :: args () -> getArgc () <= 1 || ( DI :: args () -> getArgv ()[ 1 ] !== 'json' )) {
if ( ! ActivityPub :: isRequest ()) {
return ;
}
2021-07-20 13:04:25 -04:00
try {
$data = ActivityPub\Transmitter :: getProfile ( 0 );
2020-08-22 10:48:09 -04:00
header ( 'Access-Control-Allow-Origin: *' );
header ( 'Cache-Control: max-age=23200, stale-while-revalidate=23200' );
System :: jsonExit ( $data , 'application/activity+json' );
2021-07-20 13:04:25 -04:00
} catch ( HTTPException\NotFoundException $e ) {
System :: jsonError ( 404 , [ 'error' => 'Record not found' ]);
2020-08-22 10:48:09 -04:00
}
}
2019-12-15 17:44:33 -05:00
$config = DI :: config ();
2019-05-04 04:05:21 -04:00
$register_policies = [
Register :: CLOSED => 'REGISTER_CLOSED' ,
Register :: APPROVE => 'REGISTER_APPROVE' ,
Register :: OPEN => 'REGISTER_OPEN'
];
$register_policy_int = intval ( $config -> get ( 'config' , 'register_policy' ));
if ( $register_policy_int !== Register :: CLOSED && $config -> get ( 'config' , 'invitation_only' )) {
$register_policy = 'REGISTER_INVITATION' ;
} else {
$register_policy = $register_policies [ $register_policy_int ];
}
2020-07-29 01:12:16 -04:00
$admin = [];
$administrator = User :: getFirstAdmin ([ 'username' , 'nickname' ]);
if ( ! empty ( $administrator )) {
$admin = [
'name' => $administrator [ 'username' ],
'profile' => DI :: baseUrl () -> get () . '/profile/' . $administrator [ 'nickname' ],
];
2019-05-04 04:05:21 -04:00
}
$visible_addons = Addon :: getVisibleList ();
2022-12-27 20:07:38 -05:00
$config -> reload ();
2019-05-04 04:05:21 -04:00
$locked_features = [];
$featureLocks = $config -> get ( 'config' , 'feature_lock' );
if ( isset ( $featureLocks )) {
foreach ( $featureLocks as $feature => $lock ) {
if ( $feature === 'config_loaded' ) {
continue ;
}
$locked_features [ $feature ] = intval ( $lock );
}
}
$data = [
2022-10-17 06:37:48 -04:00
'version' => App :: VERSION ,
2019-12-15 19:05:15 -05:00
'url' => DI :: baseUrl () -> get (),
2019-05-04 04:05:21 -04:00
'addons' => $visible_addons ,
'locked_features' => $locked_features ,
'explicit_content' => intval ( $config -> get ( 'system' , 'explicit_content' , 0 )),
'language' => $config -> get ( 'system' , 'language' ),
'register_policy' => $register_policy ,
'admin' => $admin ,
'site_name' => $config -> get ( 'config' , 'sitename' ),
2022-10-17 06:37:48 -04:00
'platform' => strtolower ( App :: PLATFORM ),
2019-05-04 04:05:21 -04:00
'info' => $config -> get ( 'config' , 'info' ),
2019-12-15 19:05:15 -05:00
'no_scrape_url' => DI :: baseUrl () -> get () . '/noscrape' ,
2019-05-04 04:05:21 -04:00
];
2022-04-09 07:58:01 -04:00
System :: jsonExit ( $data );
2019-05-04 04:05:21 -04:00
}
}