khanat-opennel-code/code/ryzom/tools/server/ryzom_ams/ams_lib/autoload/helpers.php

148 lines
5.5 KiB
PHP
Raw Normal View History

2013-06-06 06:04:46 +00:00
<?php
2013-06-06 06:39:33 +00:00
class Helpers{
static public function loadTemplate( $template, $vars = array (), $forcelibrender = false )
2013-06-06 06:39:33 +00:00
{
global $AMS_LIB;
global $SITEBASE;
global $AMS_TRANS;
global $INGAME_LAYOUT;
require_once $AMS_LIB . '/smarty/libs/Smarty.class.php';
$smarty = new Smarty;
// turn smarty debugging on/off
2013-06-15 22:13:13 +00:00
$smarty -> debugging = false;
// caching must be disabled for multi-language support
$smarty -> caching = false;
$smarty -> cache_lifetime = 120;
2013-06-13 21:33:23 +00:00
helpers :: create_folders ();
if ( helpers::check_if_game_client() or $forcelibrender = false ){
$smarty -> template_dir = $AMS_LIB . '/ingame_templates/';
$smarty -> setConfigDir( $AMS_LIB . '/configs' );
$variables = parse_ini_file( $AMS_LIB . '/configs/ingame_layout.ini', true );
foreach ( $variables[$INGAME_LAYOUT] as $key => $value ){
$smarty -> assign( $key, $value );
}
}else{
$smarty -> template_dir = $SITEBASE . '/templates/';
$smarty -> setConfigDir( $SITEBASE . '/configs' );
}
foreach ( $vars as $key => $value ){
$smarty -> assign( $key, $value );
}
$variables = Helpers::handle_language();
foreach ( $variables[$template] as $key => $value ){
$smarty -> assign( $key, $value );
}
if( isset($vars['permission']) && $vars['permission'] == 3 ){
$inherited = "extends:layout_admin.tpl|";
}else if( isset($vars['permission']) && $vars['permission'] == 2){
$inherited = "extends:layout_mod.tpl|";
}else if( isset($vars['permission']) && $vars['permission'] == 1){
$inherited = "extends:layout_user.tpl|";
}else{
$inherited ="";
}
// extends:' . $inherited .'|register.tpl
$smarty -> display( $inherited . $template . '.tpl' );
2013-06-06 06:39:33 +00:00
}
static public function create_folders(){
2013-06-13 21:41:58 +00:00
global $AMS_LIB;
global $SITEBASE;
$arr = array( $AMS_LIB . '/ingame_templates/',
$AMS_LIB . '/configs',
//$AMS_LIB . '/cache',
$SITEBASE . '/cache/',
$SITEBASE . '/templates/',
$SITEBASE . '/templates_c/',
$SITEBASE . '/configs'
);
foreach ( $arr as & $value ){
2013-06-13 21:33:23 +00:00
if ( !file_exists( $value ) ){
echo $value;
mkdir( $value);
2013-06-13 21:33:23 +00:00
}
}
2013-06-13 21:33:23 +00:00
}
static public function check_if_game_client()
2013-06-06 06:39:33 +00:00
{
// if HTTP_USER_AGENT is not set then its ryzom core
if ( strpos($_SERVER['HTTP_USER_AGENT'],"Ryzom") === 0){
2013-06-06 06:39:33 +00:00
return true;
}else{
2013-06-06 06:39:33 +00:00
return false;
}
}
static public function handle_language(){
global $DEFAULT_LANGUAGE;
global $AMS_TRANS;
//if language get param is given = set cookie
//else if no get param is given and a cookie is set, use that language, else use default.
if ( isset( $_GET['language'] ) ) {
//check if the language is supported
if ( file_exists( $AMS_TRANS . '/' . $_GET['language'] . '.ini' ) ){
//if it's supported, set cookie!
setcookie( 'language',$_GET['language'], time() + 60*60*24*30 );
$language = $_GET['language'];
}else{
//the language is not supported, use the default.
$language = $DEFAULT_LANGUAGE;
}
}else{
//if no get param is given, check if a cookie value for language is set
if ( isset( $_COOKIE['language'] ) ) {
$language = $_COOKIE['language'];
}
//else use the default
else{
$language = $DEFAULT_LANGUAGE;
}
}
return parse_ini_file( $AMS_TRANS . '/' . $language . '.ini', true );
}
//Time output function for handling the time display function.
2013-08-20 00:08:12 +00:00
static public function outputTime($time, $str = 1){
global $TIME_FORMAT;
2013-08-20 00:08:12 +00:00
if($str){
return date($TIME_FORMAT,strtotime($time));
}else{
return date($TIME_FORMAT,$time);
}
}
static public function check_login_ingame(){
if ( helpers :: check_if_game_client () or $forcelibrender = false ){
$dbr = new DBLayer("ring");
if (isset($_GET['UserId']) && isset($_COOKIE['ryzomId'])){
$id = $_GET['UserId'];
$statement = $dbr->execute("SELECT * FROM ring_users WHERE user_id=:id AND cookie =:cookie", array('id' => $id, 'cookie' => $_COOKIE['ryzomId']));
if ($statement->rowCount() ){
$entry = $statement->fetch();
2013-07-31 22:08:35 +00:00
//print_r($entry);
return array('id' => $entry['user_id'], 'name' => $entry['user_name']);
}else{
return "FALSE";
}
}else{
return "FALSE";
}
}else{
return "FALSE";
}
}
}