mirror of
https://github.com/GuduleLapointe/opensim-helpers.git
synced 2026-08-14 08:52:11 +00:00
* new OpenSim_Grid clas
This commit is contained in:
@@ -0,0 +1,228 @@
|
||||
<?php
|
||||
/**
|
||||
* Grid class for OpenSimulator Helpers
|
||||
*/
|
||||
if( ! defined( 'OSHELPERS' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class OpenSim_Grid {
|
||||
private $grid_status;
|
||||
private $grid_info;
|
||||
private $grid_info_card;
|
||||
private $grid_status_card;
|
||||
|
||||
public function __construct() {
|
||||
// $this->grid_status = $this->get_grid_status();
|
||||
// $this->grid_info = $this->get_grid_info();
|
||||
// $this->grid_info_card = $this->get_grid_info_card();
|
||||
// $this->grid_status_card = $this->get_grid_status_card();
|
||||
}
|
||||
|
||||
public static function get_grid_info( $grid_uri = false, $args = array() ) {
|
||||
$info = array();
|
||||
|
||||
if( ! $grid_uri ) {
|
||||
$info = array_filter( array_merge(
|
||||
$info,
|
||||
array(
|
||||
OpenSim::get_option( 'GridInfoService.gridname' ),
|
||||
'Login URI' => OpenSim::hop( OpenSim::get_option( 'Hypergrid.HomeURI' ) ),
|
||||
)
|
||||
) );
|
||||
// $info = OpenSim::get_option( 'GridInfoService' );
|
||||
// $login_uri = OpenSim::get_option( 'Hypergrid.HomeURI' );
|
||||
} else {
|
||||
$info = array(
|
||||
'Grid Name' => 'External Grid, not implemented.',
|
||||
);
|
||||
}
|
||||
|
||||
$info = array_filter( $info );
|
||||
try {
|
||||
if( empty( $info ) ) {
|
||||
throw new Exception( 'No grid info found.' );
|
||||
}
|
||||
} catch( Exception $e ) {
|
||||
return $e;
|
||||
}
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get grid information as a card
|
||||
*/
|
||||
public static function grid_info_card( $grid_uri = false, $args = array() ) {
|
||||
$info = self::get_grid_info( $grid_uri, $args );
|
||||
if( ! $info || OpenSim::is_error( $info ) ) {
|
||||
return false;
|
||||
}
|
||||
$title = false;
|
||||
if( ! empty( $args['title'])) {
|
||||
$title = $args['title'] === true ? _( 'Grid Information' ) : $args['title'];
|
||||
}
|
||||
if( empty( $info ) ) {
|
||||
return;
|
||||
}
|
||||
$html = '<div class="block grid-info card">';
|
||||
$title = empty( $title ) ? array_shift( $info ) : $title;
|
||||
// $html .= '<h5 class="card-title">' . $title . '</h5>';
|
||||
$html .= '<ul class="list-group list-group-flush">';
|
||||
$html .= sprintf(
|
||||
'<li class="list-group-item active">
|
||||
<h5 class="card-title p-0 m-0">%s</h5>
|
||||
</li>',
|
||||
$title,
|
||||
'Now that\'s something else',
|
||||
);
|
||||
foreach( $info as $key => $value ) {
|
||||
$html .= sprintf(
|
||||
'<li class="list-group-item">%s %s</li>',
|
||||
is_numeric( $key ) ? '' : $key . ':',
|
||||
$value
|
||||
);
|
||||
$class="";
|
||||
}
|
||||
$html .= '</ul>';
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
// public function get_grid_status() {
|
||||
// $status = OpenSim::get_grid_status();
|
||||
// return $status;
|
||||
// }
|
||||
|
||||
// public function get_grid_info() {
|
||||
// $info = OpenSim::get_grid_info();
|
||||
// return $info;
|
||||
// }
|
||||
|
||||
// public function get_grid_info_card() {
|
||||
// $info = $this->get_grid_info();
|
||||
// $html = '';
|
||||
// if( ! empty( $info ) ) {
|
||||
// $html .= '<div class="card">';
|
||||
// $html .= '<div class="card-header">';
|
||||
// $html .= '<h5 class="card-title">' . _('Grid Info') . '</h5>';
|
||||
// $html .= '</div>';
|
||||
// $html .= '<div class="card-body">';
|
||||
// $html .= OpenSim::array2table( $info, 'gridinfo' );
|
||||
// $html .= '</div>';
|
||||
// $html .= '</div>';
|
||||
// }
|
||||
// return $html;
|
||||
// }
|
||||
|
||||
// public function get_grid_status_card() {
|
||||
// $status = $this->get_grid_status();
|
||||
// $html = '';
|
||||
// if( ! empty( $status ) ) {
|
||||
// $html .= '<div class="card">';
|
||||
// $html .= '<div class="card-header">';
|
||||
// $html .= '<h5 class="card-title">' . _('Grid Status') . '</h5>';
|
||||
// $html .= '</div>';
|
||||
// $html .= '<div class="card-body">';
|
||||
// $html .= OpenSim::array2table( $status, 'gridstatus' );
|
||||
// $html .= '</div>';
|
||||
// $html .= '</div>';
|
||||
// }
|
||||
// return $html;
|
||||
// }
|
||||
|
||||
function opensim_grid_status( $grid_url = null ) {
|
||||
global $OpenSimDB;
|
||||
// If db is not yet configured, calls to $OpenSimDB would crash otherwise
|
||||
if ( ! $OpenSimDB ) {
|
||||
return false;
|
||||
}
|
||||
return 'got a db';
|
||||
|
||||
// $status = wp_cache_get( 'gridstatus', 'w4os' );
|
||||
// if ( false === $status ) {
|
||||
// // $cached="uncached";
|
||||
// if ( $OpenSimDB->check_connection() ) {
|
||||
// $lastmonth = time() - 30 * 86400;
|
||||
|
||||
// // $urlinfo = explode( ':', get_option( 'w4os_login_uri' ) );
|
||||
// // $host = $urlinfo['0'];
|
||||
// // $port = $urlinfo['1'];
|
||||
// // $fp = @fsockopen( $host, $port, $errno, $errstr, 1.0 );
|
||||
// $gridonline = w4os_grid_status();
|
||||
|
||||
// // if ($fp) {
|
||||
// // $gridonline = __("Yes", 'w4os' );
|
||||
// // } else {
|
||||
// // $gridonline = __("No", 'w4os' );
|
||||
// // }
|
||||
// $filter = '';
|
||||
// if ( get_option( 'w4os_exclude_models' ) ) {
|
||||
// $filter .= "u.FirstName != '" . get_option( 'w4os_model_firstname' ) . "'
|
||||
// AND u.LastName != '" . get_option( 'w4os_model_lastname' ) . "'";
|
||||
// }
|
||||
// if ( get_option( 'w4os_exclude_nomail' ) ) {
|
||||
// $filter .= " AND u.Email != ''";
|
||||
// }
|
||||
// if ( ! empty( $filter ) ) {
|
||||
// $filter = "$filter AND ";
|
||||
// }
|
||||
// }
|
||||
// $status = array(
|
||||
// __( 'Status', 'w4os' ) => $gridonline,
|
||||
// __( 'Members', 'w4os' ) => number_format_i18n(
|
||||
// $OpenSimDB->get_var(
|
||||
// "SELECT COUNT(*)
|
||||
// FROM UserAccounts as u WHERE $filter active=1"
|
||||
// )
|
||||
// ),
|
||||
// __( 'Active members (30 days)', 'w4os' ) => number_format_i18n(
|
||||
// $OpenSimDB->get_var(
|
||||
// "SELECT COUNT(*)
|
||||
// FROM GridUser as g, UserAccounts as u WHERE $filter PrincipalID = UserID AND g.Login > $lastmonth"
|
||||
// )
|
||||
// ),
|
||||
// );
|
||||
// $status[ __( 'Members in world', 'w4os' ) ] = number_format_i18n(
|
||||
// $OpenSimDB->get_var(
|
||||
// "SELECT COUNT(*)
|
||||
// FROM Presence AS p, UserAccounts AS u
|
||||
// WHERE $filter RegionID != '00000000-0000-0000-0000-000000000000'
|
||||
// AND p.UserID = u.PrincipalID;"
|
||||
// )
|
||||
// );
|
||||
// // 'Active citizens (30 days)' => number_format_i18n($OpenSimDB->get_var("SELECT COUNT(*)
|
||||
// // FROM GridUser as g, UserAccounts as u WHERE g.UserID = u.PrincipalID AND Login > $lastmonth" )),
|
||||
// if ( ! get_option( 'w4os_exclude_hypergrid' ) ) {
|
||||
// $status[ __( 'Active users (30 days)', 'w4os' ) ] = number_format_i18n(
|
||||
// $OpenSimDB->get_var(
|
||||
// "SELECT COUNT(*)
|
||||
// FROM GridUser WHERE Login > $lastmonth"
|
||||
// )
|
||||
// );
|
||||
// $status[ __( 'Total users in world', 'w4os' ) ] = number_format_i18n(
|
||||
// $OpenSimDB->get_var(
|
||||
// "SELECT COUNT(*)
|
||||
// FROM Presence
|
||||
// WHERE RegionID != '00000000-0000-0000-0000-000000000000'; "
|
||||
// )
|
||||
// );
|
||||
// }
|
||||
// $status[ __( 'Regions', 'w4os' ) ] = number_format_i18n(
|
||||
// $OpenSimDB->get_var(
|
||||
// 'SELECT COUNT(*)
|
||||
// FROM regions'
|
||||
// )
|
||||
// );
|
||||
// $status[ __( 'Total area', 'w4os' ) ] = number_format_i18n(
|
||||
// $OpenSimDB->get_var(
|
||||
// 'SELECT round(sum(sizex * sizey / 1000000),2)
|
||||
// FROM regions'
|
||||
// ),
|
||||
// 2
|
||||
// ) . ' km²';
|
||||
// wp_cache_add( 'gridstatus', $status, 'w4os' );
|
||||
// }
|
||||
// return $status;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
class OpenSim_Page {
|
||||
protected $page_title;
|
||||
protected $content;
|
||||
@@ -21,7 +22,7 @@ class OpenSim_Page {
|
||||
|
||||
public function get_sidebar_right() {
|
||||
$html = '';
|
||||
$html .= OpenSim::grid_info_card();
|
||||
$html .= OpenSim_Grid::grid_info_card();
|
||||
if( ! empty( $html ) ) {
|
||||
$html = '<div class="sidebar sidebar-right">' . $html . '</div>';
|
||||
}
|
||||
|
||||
+4
-53
@@ -31,6 +31,8 @@ class OpenSim {
|
||||
public function init() {
|
||||
$this->constants();
|
||||
$this->includes();
|
||||
|
||||
$this->grid = new OpenSim_Grid();
|
||||
}
|
||||
|
||||
public function constants() {
|
||||
@@ -47,6 +49,8 @@ class OpenSim {
|
||||
public function includes() {
|
||||
require_once( OSHELPERS_DIR . 'includes/functions.php' );
|
||||
require_once( OSHELPERS_DIR . 'classes/class-locale.php' );
|
||||
require_once( OSHELPERS_DIR . 'classes/class-ini.php' );
|
||||
require_once( OSHELPERS_DIR . 'classes/class-grid.php' );
|
||||
}
|
||||
|
||||
public function get_helpers_url() {
|
||||
@@ -614,59 +618,6 @@ class OpenSim {
|
||||
return $config[$option] ?? $default;
|
||||
}
|
||||
|
||||
public static function grid_info_card( $grid_uri = false, $args = array() ) {
|
||||
$info = array();
|
||||
$title = false;
|
||||
if( ! empty( $args['title'])) {
|
||||
$title = $args['title'] === true ? _( 'Grid Information' ) : $args['title'];
|
||||
}
|
||||
if( ! $grid_uri ) {
|
||||
$info = array_filter( array_merge(
|
||||
$info,
|
||||
array(
|
||||
self::get_option( 'GridInfoService.gridname' ),
|
||||
'Login URI' => self::hop( self::get_option( 'Hypergrid.HomeURI' ) ),
|
||||
)
|
||||
) );
|
||||
// $info = self::get_option( 'GridInfoService' );
|
||||
// $login_uri = self::get_option( 'Hypergrid.HomeURI' );
|
||||
} else {
|
||||
$info = array(
|
||||
'Grid Name' => 'External Grid, not implemented.',
|
||||
);
|
||||
$title = false;
|
||||
if( ! empty( $args['title'])) {
|
||||
$title = $args['title'] === true ? _( 'Grid Information' ) : $args['title'];
|
||||
}
|
||||
}
|
||||
if( empty( $info ) ) {
|
||||
return;
|
||||
}
|
||||
$html = '<div class="block grid-info card">';
|
||||
$title = empty( $title ) ? array_shift( $info ) : $title;
|
||||
// $html .= '<h5 class="card-title">' . $title . '</h5>';
|
||||
$html .= '<ul class="list-group list-group-flush">';
|
||||
$html .= sprintf(
|
||||
'<li class="list-group-item active">
|
||||
<h5 class="card-title p-0 m-0">%s</h5>
|
||||
</li>',
|
||||
$title,
|
||||
'Now that\'s something else',
|
||||
);
|
||||
foreach( $info as $key => $value ) {
|
||||
$html .= sprintf(
|
||||
'<li class="list-group-item %s">%s %s</li>',
|
||||
$class,
|
||||
is_numeric( $key ) ? '' : $key . ':',
|
||||
$value
|
||||
);
|
||||
$class="";
|
||||
}
|
||||
$html .= '</ul>';
|
||||
$html .= '</div>';
|
||||
return $html;
|
||||
}
|
||||
|
||||
static function hop( $url = null, $string = null, $format = true ) {
|
||||
if ( empty( $url ) ) {
|
||||
// $url = get_option( 'w4os_login_uri' );
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
require_once( __DIR__ . '/classes/init.php' );
|
||||
require_once( __DIR__ . '/classes/class-page.php' );
|
||||
require_once( __DIR__ . '/classes/class-ini.php' );
|
||||
require_once( __DIR__ . '/classes/class-form.php' );
|
||||
|
||||
class OpenSim_Install extends OpenSim_Page {
|
||||
|
||||
Reference in New Issue
Block a user