2016-04-19 03:38:38 +00:00
< ? php
namespace Zotlabs\Module ;
2018-06-05 06:19:16 +00:00
use Zotlabs\Lib\Libzotdir ;
2016-04-19 03:38:38 +00:00
class Pubsites extends \Zotlabs\Web\Controller {
function get () {
2018-06-05 06:19:16 +00:00
2016-04-19 03:38:38 +00:00
$dirmode = intval ( get_config ( 'system' , 'directory_mode' ));
2019-05-16 00:27:33 +00:00
if (( $dirmode == DIRECTORY_MODE_PRIMARY ) || ( $dirmode == DIRECTORY_MODE_STANDALONE )) {
2016-04-19 03:38:38 +00:00
$url = z_root () . '/dirsearch' ;
}
2019-05-16 00:27:33 +00:00
if ( ! $url ) {
2018-06-05 06:19:16 +00:00
$directory = Libzotdir :: find_upstream_directory ( $dirmode );
2016-04-19 03:38:38 +00:00
$url = $directory [ 'url' ] . '/dirsearch' ;
}
2019-05-16 00:27:33 +00:00
2016-04-19 03:38:38 +00:00
$url .= '/sites' ;
2016-08-26 00:43:07 +00:00
2016-04-19 03:38:38 +00:00
$o .= '<div class="generic-content-wrapper">' ;
$o .= '<div class="section-title-wrapper"><h2>' . t ( 'Public Hubs' ) . '</h2></div>' ;
$o .= '<div class="section-content-tools-wrapper"><div class="descriptive-text">' .
t ( 'The listed hubs allow public registration for the $Projectname network. All hubs in the network are interlinked so membership on any of them conveys membership in the network as a whole. Some hubs may require subscription or provide tiered service plans. The hub itself <strong>may</strong> provide additional details.' ) . '</div>' . EOL ;
$ret = z_fetch_url ( $url );
if ( $ret [ 'success' ]) {
$j = json_decode ( $ret [ 'body' ], true );
if ( $j ) {
if ( $j [ 'sites' ]) {
2018-10-24 00:49:08 +00:00
$projects = $this -> sort_sites ( $j [ 'sites' ]);
foreach ( $projects as $p => $v ) {
2019-05-16 00:27:33 +00:00
if ( ucfirst ( $p ) === 'Osada' ) {
// deprecated
continue ;
}
2018-10-24 00:49:08 +00:00
$o .= '<strong>' . ucfirst ( $p ) . '</strong>' . EOL ;
2019-05-16 00:27:33 +00:00
$o .= '<table class="table table-striped table-hover"><tr><td>' . t ( 'Hub URL' ) . '</td><td>' . t ( 'Access Type' ) . '</td><td>' . t ( 'Registration Policy' ) . '</td><td>' . t ( 'Software' ) . '</td>' ;
2018-10-24 00:49:08 +00:00
$o .= '</tr>' ;
2019-05-16 00:27:33 +00:00
2019-05-22 05:04:53 +00:00
usort ( $v , [ $this , 'sort_versions' ]);
2019-05-16 00:27:33 +00:00
foreach ( $v as $jj ) {
2018-10-24 00:49:08 +00:00
if ( strpos ( $jj [ 'version' ], ' ' )) {
$x = explode ( ' ' , $jj [ 'version' ]);
if ( $x [ 1 ])
$jj [ 'version' ] = $x [ 1 ];
2016-04-19 03:38:38 +00:00
}
2018-10-24 00:49:08 +00:00
$m = parse_url ( $jj [ 'url' ]);
$host = strtolower ( substr ( $jj [ 'url' ], strpos ( $jj [ 'url' ], '://' ) + 3 ));
$location = '' ;
if ( ! empty ( $jj [ 'location' ])) {
$location = '<p title="' . t ( 'Location' ) . '" style="margin: 5px 5px 0 0; text-align: right"><i class="fa fa-globe"></i> ' . $jj [ 'location' ] . '</p>' ;
2016-04-19 03:38:38 +00:00
}
2018-10-24 00:49:08 +00:00
else {
$location = '<br /> ' ;
}
$urltext = str_replace ( array ( 'https://' ), '' , $jj [ 'url' ]);
2019-05-16 00:27:33 +00:00
$o .= '<tr><td><a href="' . (( $jj [ 'sellpage' ]) ? $jj [ 'sellpage' ] : $jj [ 'url' ] . '/register' ) . '" ><i class="fa fa-link"></i> ' . $urltext . '</a>' . $location . '</td><td>' . $jj [ 'access' ] . '</td><td>' . $jj [ 'register' ] . '</td><td>' . ucwords ( $jj [ 'project' ]) . (( $jj [ 'version' ]) ? ' ' . $jj [ 'version' ] : '' ) . '</td>' ;
2018-10-24 00:49:08 +00:00
$o .= '</tr>' ;
}
$o .= '</table>' ;
$o .= '<br><br>' ;
2016-04-19 03:38:38 +00:00
}
2018-10-24 00:49:08 +00:00
}
2016-04-19 03:38:38 +00:00
$o .= '</div></div>' ;
}
}
return $o ;
2018-10-24 00:49:08 +00:00
}
function sort_sites ( $a ) {
$ret = [];
if ( $a ) {
foreach ( $a as $e ) {
$projectname = explode ( ' ' , $e [ 'project' ]);
$ret [ $projectname [ 0 ]][] = $e ;
}
}
$projects = array_keys ( $ret );
2019-05-22 05:04:53 +00:00
2018-10-24 00:49:08 +00:00
$newret = [];
foreach ( $projects as $p ) {
2019-05-22 05:04:53 +00:00
2018-10-24 00:49:08 +00:00
$newret [ $p ] = $ret [ $p ];
}
2019-05-22 05:04:53 +00:00
2018-10-24 00:49:08 +00:00
return $newret ;
2016-04-19 03:38:38 +00:00
}
2019-05-16 00:27:33 +00:00
2019-05-22 05:04:53 +00:00
function sort_versions ( $a , $b ) {
return version_compare ( $b [ 'version' ], $a [ 'version' ]);
2019-05-16 00:27:33 +00:00
}
2016-04-19 03:38:38 +00:00
}