diff --git a/includes/config.example.php b/includes/config.example.php index 3370379..e4d7af9 100644 --- a/includes/config.example.php +++ b/includes/config.example.php @@ -39,6 +39,7 @@ define( 'OPENSIM_DB_HOST', 'localhost' ); define( 'OPENSIM_DB_NAME', 'opensim' ); define( 'OPENSIM_DB_USER', 'opensim' ); define( 'OPENSIM_DB_PASS', 'password' ); +define( 'SEARCH_TABLE_EVENTS', 'events' ); /** * Search database credentials and settings. diff --git a/includes/functions.php b/includes/functions.php index a3c8ed5..58e19d1 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -81,14 +81,23 @@ function opensim_sanitize_uri( $url, $gatekeeperURL = null, $array_outout = fals } else { $port = 8002; } - } else { + $region = preg_replace( ':^/*:', '', @$split[0] ); + } else if(function_exists('w4os_grid_login_uri')) { $host = parse_url( w4os_grid_login_uri(), PHP_URL_HOST ); $port = parse_url( w4os_grid_login_uri(), PHP_URL_HOST ); if ( preg_match( '/^[0-9]+$/', $split[0] ) ) { array_shift( $split ); } + $region = preg_replace( ':^/*:', '', @$split[0] ); + } else { + if( empty($gatekeeperURL)) { + return false; + } + $region = $split[2]; + $split = explode( ':', preg_replace( '#.*://([^/]+)/?.*#', '$1', $gatekeeperURL ) ); + $host = $split[0]; + $port = $split[1]; } - $region = preg_replace( ':^/*:', '', @$split[0] ); } if ( empty( $host ) & ! empty( $gatekeeperURL ) ) { $split = explode( ':', preg_replace( '#.*://([^/]+)/?.*#', '$1', $gatekeeperURL ) ); @@ -99,7 +108,7 @@ function opensim_sanitize_uri( $url, $gatekeeperURL = null, $array_outout = fals $port = 80; } $host = strtolower( trim( $host ) ); - $region = trim( $region ); + $region = trim(str_replace("_", " ", $region )); if ( is_numeric( $region ) ) { $pos = "$region/$pos"; $region = ''; @@ -225,6 +234,7 @@ function opensim_link_region( $args, $var = null ) { $link_region = oxXmlRequest( $gatekeeper, 'link_region', array( 'region_name' => "$region" ) ); $OSSEARCH_CACHE['link_region'][ $key ] = $link_region; } + if ( $link_region ) { if ( $var ) { return $link_region[ $var ]; @@ -232,21 +242,37 @@ function opensim_link_region( $args, $var = null ) { return $link_region; } } + return array(); } +/** + * Build region URL from array + * + * @param array $region sanitized region array + * @return string + */ +function opensim_region_url($region) { + if(!is_array($region)) { + return false; + } + return $region['gatekeeper'] . ( empty($region['region']) ? '' : ':' . $region['region']) . ( empty($region['pos']) ? '' : '/' . $region['pos'] ); +} + function opensim_get_region( $region_uri, $var = null ) { if ( empty( $region_uri ) ) { return array(); } global $OSSEARCH_CACHE; - $region = opensim_sanitize_uri( $region_uri, '', true ); + $gatekeeper = $region['gatekeeper']; $link_region = opensim_link_region( $region ); + $uuid = @$link_region['uuid']; if ( ! opensim_isuuid( $uuid ) ) { + // error_log( "opensim_get_region $region_uri invalid uuid $uuid" ); return array(); } @@ -379,6 +405,42 @@ function osXmlDie( $message = '' ) { die; } +function osNotice( $message ) { + echo $message . "\n"; +} + +function osAdminNotice( $message, $error_code = 0, $die = false) { + // get calling function and file + $trace = debug_backtrace(); + + + if(isset($trace[1])) { + $caller = $trace[1]; + } else { + $caller = $trace[0]; + } + $file = empty($caller['file']) ? '' : $caller['file']; + $function = $caller['function'] . "()" ?? 'main'; + $line = $caller['line'] ?? 0; + $class = $caller['class'] ?? 'main'; + $type = $caller['type'] ?? '::'; + if($class != 'main') { + $function = $class . $type . $function; + } + $file = $file . ':' . $line; + $message = sprintf( + '%s%s: %s in %s', + $function, + empty($error_code) ? '' : " Error $error_code", + $message, + $file, + ); + error_log( $message ); + if($die == true) { + die( $error_code ); + } +} + /** * Flush output and free client so following commands are executed in background *