2020-08-31 04:08:39 +00:00
< ? php
2021-12-03 03:01:39 +00:00
2022-02-16 04:08:28 +00:00
namespace Code\Module ;
2020-08-31 04:08:39 +00:00
2022-02-26 08:36:05 +00:00
use App ;
2022-02-16 04:08:28 +00:00
use Code\Lib\Libzotdir ;
use Code\Lib\LibBlock ;
use Code\Web\Controller ;
use Code\Render\Theme ;
2022-02-12 20:43:29 +00:00
2020-08-31 04:08:39 +00:00
2022-03-18 19:38:08 +00:00
class Communities extends Controller
2021-12-02 23:02:31 +00:00
{
public function get ()
{
2022-02-26 08:36:05 +00:00
if ( ! ( isset ( $_REQUEST [ 'aj' ]) && $_REQUEST [ 'aj' ])) {
$_SESSION [ 'return_url' ] = App :: $query_string ;
}
2021-12-02 23:02:31 +00:00
$sql_extra = (( $_REQUEST [ 'project' ]) ? " and site_project = ' " . escape_tags ( protect_sprintf ( dbesc ( $_REQUEST [ 'project' ]))) . " ' " : " " );
2022-03-07 21:54:11 +00:00
if ( isset ( $_REQUEST [ 'search' ])) {
$sql_extra .= " " ; //@TODO
}
2022-03-18 19:45:53 +00:00
$desc = t ( 'This page provides information about affiliated website communities which are currently known to this website. These are a small fraction of the thousands of websites and dozens of projects and providers which participate in this communications network.' );
2021-12-02 23:02:31 +00:00
2022-09-01 20:50:26 +00:00
$blocked = ( local_channel ()) ? LibBlock :: fetch ( App :: $channel [ 'channel_id' ], BLOCKTYPE_SERVER ) : [];
2022-02-26 08:36:05 +00:00
2021-12-02 23:02:31 +00:00
$j = [];
2022-02-26 08:36:05 +00:00
$total = 0 ;
$r = q (
" select count(site_url) as total from site
where site_flags != 256 and site_dead = 0 $sql_extra
order by site_update desc "
);
if ( $r ) {
App :: set_pager_total ( $r [ 0 ][ 'total' ]);
$total = $r [ 0 ][ 'total' ];
}
2021-12-02 23:02:31 +00:00
2022-02-26 08:36:05 +00:00
$r = q (
" select * from site
where site_flags != 256 and site_dead = 0 $sql_extra
order by site_update desc LIMIT % d OFFSET % d " ,
intval ( App :: $pager [ 'itemspage' ]),
intval ( App :: $pager [ 'start' ])
);
2021-12-02 23:02:31 +00:00
if ( $r ) {
foreach ( $r as $rr ) {
$found_block = false ;
if ( $blocked ) {
foreach ( $blocked as $b ) {
if ( strpos ( $rr [ 'site_url' ], $b [ 'block_entity' ]) !== false ) {
$found_block = true ;
break ;
}
}
if ( $found_block ) {
continue ;
}
}
if ( ! check_siteallowed ( $rr [ 'site_url' ])) {
continue ;
}
2021-12-03 03:01:39 +00:00
if ( $rr [ 'site_access' ] == ACCESS_FREE ) {
2021-12-02 23:02:31 +00:00
$access = t ( 'free' );
2021-12-03 03:01:39 +00:00
} elseif ( $rr [ 'site_access' ] == ACCESS_PAID ) {
2021-12-02 23:02:31 +00:00
$access = t ( 'subscription' );
2021-12-03 03:01:39 +00:00
} elseif ( $rr [ 'site_access' ] == ACCESS_TIERED ) {
2021-12-02 23:02:31 +00:00
$access = t ( 'tiered service plans' );
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$access = 'private' ;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
2021-12-03 03:01:39 +00:00
if ( $rr [ 'site_register' ] == REGISTER_OPEN ) {
2021-12-02 23:02:31 +00:00
$register = t ( 'Register' );
2021-12-03 03:01:39 +00:00
} elseif ( $rr [ 'site_register' ] == REGISTER_APPROVE ) {
2021-12-02 23:02:31 +00:00
$register = t ( 'Register (requires approval)' );
2021-12-03 03:01:39 +00:00
} else {
2021-12-02 23:02:31 +00:00
$register = 'closed' ;
2021-12-03 03:01:39 +00:00
}
2021-12-02 23:02:31 +00:00
$sitename = get_sconfig ( $rr [ 'site_url' ], 'system' , 'sitename' , $rr [ 'site_url' ]);
if ( $sitename !== $rr [ 'site_url' ]) {
$sitename .= ' (' . $rr [ 'site_url' ] . ')' ;
}
$disabled = (( $access === 'private' || $register === 'closed' ) ? true : false );
$logo = get_sconfig ( $rr [ 'site_url' ], 'system' , 'logo' );
$about = get_sconfig ( $rr [ 'site_url' ], 'system' , 'about' );
if ( ! $logo && file_exists ( 'images/' . strtolower ( $rr [ 'site_project' ]) . '.png' )) {
$logo = 'images/' . strtolower ( $rr [ 'site_project' ]) . '.png' ;
}
if ( ! $logo ) {
if ( intval ( $rr [ 'site_type' ]) != 0 ) {
$logo = 'images/activitypub-300.png' ;
} else {
$logo = 'images/default_profile_photos/red_koala_trans/300.png' ;
}
}
if ( $rr [ 'site_sellpage' ]) {
$register_link = $rr [ 'site_sellpage' ];
} else {
$register_link = $rr [ 'site_url' ] . '/register' ;
}
$j [] = [
'profile_link' => $rr [ 'site_url' ],
'name' => $sitename ,
'register' => $register_link ,
'sellpage' => $rr [ 'site_sellpage' ],
2022-03-21 21:29:13 +00:00
'location_label' => t ( 'Location:' ),
2021-12-02 23:02:31 +00:00
'location' => $rr [ 'site_location' ],
'project' => $rr [ 'site_project' ],
'version' => $rr [ 'site_version' ],
'photo' => $logo ,
'about' => bbcode ( $about ),
'hash' => substr ( hash ( 'sha256' , $rr [ 'site_url' ]), 0 , 16 ),
2022-03-21 21:29:13 +00:00
'network_label' => t ( 'Type:' ),
2021-12-02 23:02:31 +00:00
'network' => $rr [ 'site_project' ],
2022-03-21 21:29:13 +00:00
'version_label' => t ( 'Version:' ),
2021-12-02 23:02:31 +00:00
'private' => $disabled ,
'connect' => (( $disabled ) ? '' : $register_link ),
'connect_label' => $register ,
'access' => (( $access === 'private' ) ? '' : $access ),
2022-03-21 21:29:13 +00:00
'access_label' => t ( 'Access type:' ),
2021-12-02 23:02:31 +00:00
];
}
}
2022-02-26 08:36:05 +00:00
if ( $_REQUEST [ 'aj' ]) {
if ( $j ) {
2022-09-01 20:50:26 +00:00
$output = replace_macros ( Theme :: get_template ( 'sitesajax.tpl' ), [ '$entries' => $j ]);
2022-02-26 08:36:05 +00:00
}
else {
2022-09-01 20:50:26 +00:00
$output = '<div id="content-complete"></div>' ;
2022-02-26 08:36:05 +00:00
}
2022-09-01 20:50:26 +00:00
echo $output ;
2022-02-26 08:36:05 +00:00
killme ();
}
else {
2022-09-01 20:50:26 +00:00
$output = " <script> var page_query = ' " . escape_tags ( urlencode ( $_GET [ 'req' ])) . " '; var extra_args = ' " . extra_query_args () . " ' ; </script> " ;
2021-12-02 23:02:31 +00:00
2022-09-01 20:50:26 +00:00
$output .= replace_macros ( Theme :: get_template ( 'sitentry_header.tpl' ), [
2022-03-07 00:03:26 +00:00
'$dirlbl' => t ( 'Communities' ),
2022-02-26 08:36:05 +00:00
'$desc' => $desc ,
'$entries' => $j ,
]);
if ( ! $j ) {
2022-09-01 20:50:26 +00:00
$output .= '<div id="content-complete"></div>' ;
2022-02-26 08:36:05 +00:00
}
}
2021-12-02 23:02:31 +00:00
2022-09-01 20:50:26 +00:00
return $output ;
2021-12-02 23:02:31 +00:00
}
public function sort_sites ( $a )
{
$ret = [];
if ( $a ) {
foreach ( $a as $e ) {
$projectname = explode ( ' ' , $e [ 'project' ]);
$ret [ $projectname [ 0 ]][] = $e ;
}
}
$projects = array_keys ( $ret );
2022-03-18 19:38:08 +00:00
sort ( $projects );
2021-12-02 23:02:31 +00:00
$newret = [];
foreach ( $projects as $p ) {
$newret [ $p ] = $ret [ $p ];
}
return $newret ;
}
public function sort_versions ( $a , $b )
{
return version_compare ( $b [ 'version' ], $a [ 'version' ]);
}
2020-08-31 04:08:39 +00:00
}