Location: PHPKode > scripts > earthlead browser game (mmog) > earthlead_site_v1.2/functions.php
<?php
include $default_language_file;
global $site_reg_code;

session_start(); 
if (isset($_SESSION["user"]))
{
if(!isset($_SESSION["a".$site_reg_code])) session_destroy();  
} 



//replace text , mainly in reports to user language
function replace_text($string_to_check)
{
global $lang;

$new_string=$string_to_check;

$new_string=str_replace('[attacked]', $lang['attacked'] ,$new_string);
$new_string=str_replace('[army_send]', $lang['army_send']  ,$new_string);
$new_string=str_replace('[army_survived]', $lang['army_survived'] ,$new_string);
$new_string=str_replace('[defending_army]', $lang['defending_army'] ,$new_string);
$new_string=str_replace('[defender_army_survived]', $lang['defender_army_survived'] ,$new_string);
$new_string=str_replace('[total_renforcements]', $lang['total_renforcements'] ,$new_string);
$new_string=str_replace('[gold_taken]', $lang['gold_taken'] ,$new_string);
$new_string=str_replace('[you_have_receive_reinfo]', $lang['you_have_receive_reinfo'] ,$new_string);
$new_string=str_replace('[army_merged]', $lang['army_merged'] ,$new_string);
$new_string=str_replace('[send_reinforcements]', $lang['send_reinforcements'] ,$new_string);
$new_string=str_replace('[proposed_peace_pact]', $lang['proposed_peace_pact'] ,$new_string);
$new_string=str_replace('[click_here_to_cancel_proposal]', $lang['click_here_to_cancel_proposal'] ,$new_string);
$new_string=str_replace('[if_you_dont_have_permissions_this_will_fail]', $lang['if_you_dont_have_permissions_this_will_fail'] ,$new_string);
$new_string=str_replace('[declared_war]', $lang['declared_war'] ,$new_string);
$new_string=str_replace('[click_here_to_cancel_war_declaration]', $lang['click_here_to_cancel_war_declaration'] ,$new_string);
$new_string=str_replace('[view_alliance_diplomacy]', $lang['view_alliance_diplomacy'] ,$new_string);
$new_string=str_replace('[invited_to_alliance]', $lang['invited_to_alliance'] ,$new_string);
$new_string=str_replace('[click_here_to_cancel_invitation]', $lang['click_here_to_cancel_invitation'] ,$new_string);
$new_string=str_replace('[You_have_been_invited_to_alliance]', $lang['You_have_been_invited_to_alliance'] ,$new_string);
$new_string=str_replace('[breaked_peace_with]', $lang['breaked_peace_with'] ,$new_string);
$new_string=str_replace('[stoped_war]', $lang['stoped_war'] ,$new_string);
$new_string=str_replace('[has_removed_from_alliance]', $lang['has_removed_from_alliance'] ,$new_string);
$new_string=str_replace('[You_have_been_removed_from_alliance]', $lang['You_have_been_removed_from_alliance'] ,$new_string);
$new_string=str_replace('[structures_damaged]', $lang['structures_damaged'] ,$new_string);
$new_string=str_replace('[no_structures_damaged]', $lang['no_structures_damaged'] ,$new_string);
$new_string=str_replace('[population_loss]', $lang['population_loss'] ,$new_string);
$new_string=str_replace('[secret_funds_send]', $lang['Secret_Funds_Send'] ,$new_string);
$new_string=str_replace('[to_your_gold_vault]', $lang['to_your_Gold_Vault'] ,$new_string);
$new_string=str_replace('[secret_funds_received]', $lang['Secret_Funds_Received'] ,$new_string);
$new_string=str_replace('[to]', $lang['to'] ,$new_string);
$new_string=str_replace('[from]', $lang['from'] ,$new_string);
$new_string=str_replace('[Defense_Structure]', $lang['Defense_Structure'] ,$new_string);
$new_string=str_replace('[Culture_Structure]', $lang['Culture_Structure'] ,$new_string);
$new_string=str_replace('[Economy_Development]', $lang['Economy_Development'] ,$new_string);
$new_string=str_replace('[Transportation_Structure]', $lang['Transportation_Structure'] ,$new_string);
$new_string=str_replace('[Military_Structure]', $lang['Military_Structure'] ,$new_string);
$new_string=str_replace('[General_Infrastructure]', $lang['General_Infrastructure'] ,$new_string);


return $new_string;
}




function system_messages($message,$folder_level_from_root,$show_back,$message_type){
//if this functions is called from a different folder than the root $folder_level_from_root should have the path e.g. if the file calling is in folder  custom_modules/module/ , $folder_level_from_root should pass value ../../  . $message_type 0 is normal message $message_type 1 is errot message

global $default_template_folder,$lang;
require_once($default_template_folder."/header.php");
echo "<link rel='stylesheet' type='text/css' href='".$default_template_folder."/default.css'>"; 

if($message_type==1) echo "<font class='q_text_error'><br>".$message."<br><br></font>"; else echo "<font class='q_text_sm'><br>".$message."<br><br></font>";

if($show_back==1) echo "<a class='q_link_sm' href='javascript:history.go(-1)'>".$lang['back']."</a>"; 

require_once($default_template_folder."/footer.php");

die();
}



function clean($str)
{
 if (is_numeric($str)) $str=floor($str);
 $cleaned=strip_tags($str);
 $cleaned=htmlspecialchars($cleaned);
 $to_clean=array("%20", "\"", "'", "\\", "=", ";", ":");
 $cleaned=str_replace($to_clean, "", $cleaned);
 return $cleaned;
}

function erthld_version()
{
$version='1.2';
return $version;
}

function erthld_version_check()
{
global $lang;

if (@fopen('http://www.tecorange.com/tecorange_software_info.htm','r')) {

$version=erthld_version();
$chunk= file_get_contents('http://www.tecorange.com/tecorange_software_info.htm');
$pattern = "/#ERTHLD-Latest Version#<strong>(.*?)<\/strong>#Latest Version#/i";
preg_match($pattern, $chunk, $match);
$latest_version=$match[1];

$chunk1= file_get_contents('http://www.tecorange.com/tecorange_software_info.htm');
$pattern1 = "/#ERTHLD-Info URL#<strong>(.*?)<\/strong>#Info URL#/i";
preg_match($pattern1, $chunk1, $match1);
$info_url=$match1[1];

$output=$version."--".$lang['you_are_running_version']."<b> ".$version." </b>";

if($version==$match[1]) $output=$output."<br>".$lang['you_have_the_latest_version'];
if($version<$match[1]) $output=$output."<br>".$lang['there_is_a_newer_version']."<br><a href='".$info_url."'>".$info_url."</a>";

return $output;
}else return '0--No version info at the momment';
}

function site_leaders()
{
global $world_url,$site_reg_code;

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/site_leaders"));
	  
$outcome = $client->site_leaders($site_reg_code);

return $outcome;
}



function check_for_admin(){
global $world_url,$site_reg_code;

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/check_for_admin"));
	  
$outcome = $client->check_for_admin($site_reg_code);

return $outcome;
}


function get_unread_reports($id){
global $world_url;
if(!isset($_SESSION["user"]) || $id!=$_SESSION["user"][0]) system_messages("Request Failed",'',1,1);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/get_unread_reports"));
	  
$outcome = $client->get_unread_reports($_SESSION["user"][0]);

return $outcome;
}


function get_unread_messages($id){
global $world_url;
$id=clean($id);
if(!isset($_SESSION["user"]) || $id!=$_SESSION["user"][0]) system_messages("Request Failed",'',1,1);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/get_unread_messages"));
	  
$outcome = $client->get_unread_messages($_SESSION["user"][0]);

return $outcome;
}

function messages_reports($id,$type,$sw)
{
global $world_url;
$id=clean($id);
$type=clean($type);
$sw=clean($sw);
if(!isset($_SESSION["user"]) || $id!=$_SESSION["user"][0]) system_messages("Request Failed",'',1,1);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/messages_reports"));
	  
$outcome = $client->messages_reports($id,$type,$sw);
return $outcome;
}

function message_report($user_id,$msg_id,$type,$sw)
{
global $world_url;
$user_id=clean($user_id);
$msg_id=clean($msg_id);
$type=clean($type);
$sw=clean($sw);
if(!isset($_SESSION["user"]) || $user_id!=$_SESSION["user"][0]) system_messages("Request Failed",'',1,1);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/message_report"));
	  
$outcome = $client->message_report($user_id,$msg_id,$type,$sw);
return $outcome;
}

function mark_msg_rprt_read($user_id,$msg_id,$type,$sw)
{
global $world_url;
$user_id=clean($user_id);
$msg_id=clean($msg_id);
$type=clean($type);
$sw=clean($sw);
if(!isset($_SESSION["user"]) || $user_id!=$_SESSION["user"][0]) system_messages("Request Failed",'',1,1);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/mark_msg_rprt_read"));
	  
$outcome = $client->mark_msg_rprt_read($user_id,$msg_id,$type,$sw);
}


function user($id)
{
global $world_url;
$id=clean($id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/user"));
	  
$outcome = $client->user($id);
return $outcome;
}


function forums($user_id,$alliance)
{
global $world_url;
$user_id=clean($user_id);
$alliance=clean($alliance);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/forums"));
	  
$outcome = $client->forums($user_id,$alliance);
return $outcome;
}

function forum_threads($user_id,$alliance,$forum)
{
global $world_url;
$user_id=clean($user_id);
$alliance=clean($alliance);
$forum=clean($forum);


$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/forum_threads"));
	  
$outcome = $client->forum_threads($user_id,$alliance,$forum);
return $outcome;
}


function thread_posts($user_id, $alliance, $thread)
{
global $world_url;
$user_id=clean($user_id);
$alliance=clean($alliance);
$thread=clean($thread);


$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/thread_posts"));
	  
$outcome = $client->thread_posts($user_id,$alliance,$thread);
return $outcome;
}

function alliance_extended($id)
{
global $world_url;
$id=clean($id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/alliance_extended"));
	  
$outcome = $client->alliance_extended($id);
return $outcome;
}


function check_if_user_online($usr_id,$ally_usr_id)
{
global $world_url;
$usr_id=clean($usr_id);
$ally_usr_id=clean($ally_usr_id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/check_if_user_online"));
	  
$outcome = $client->check_if_user_online($usr_id,$ally_usr_id);
return $outcome;
}


function  user_status($id)
{
global $world_url;
$id=clean($id);
global $world_url,$site_reg_code,$site_reg_pass,$client_site_url,$lang;


$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/user_status"));
	  
$outcome = $client->user_status($id,$site_reg_code,md5($site_reg_pass),$client_site_url);

if($outcome==0) system_messages($lang['we_cant_find_user'],'','',1);

if($outcome==1) system_messages($lang['not_valid_site']."<br><img style='position:absolute; left:350; top:150;' src='template/site_not_active_img.png'>",'','',1);

return $outcome;
}


function server_time()
{
global $world_url;

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/server_time"));
	  
$outcome = $client->server_time();
return $outcome;
}

function alliance($id)
{
global $world_url;
$id=clean($id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/alliance"));
	  
$outcome = $client->alliance($id);
return $outcome;
}


function site($id)
{
global $world_url;
$id=clean($id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/site"));
	  
$outcome = $client->site($id);
return $outcome;
}


function forum($user_id,$forum)
{
global $world_url;
$user_id=clean($user_id);
$forum=clean($forum);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/forum"));
	  
$outcome = $client->forum($user_id,$forum);
return $outcome;
}


function thread($user_id,$thread)
{
global $world_url;
$user_id=clean($user_id);
$thread=clean($thread);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/thread"));
	  
$outcome = $client->thread($user_id,$thread);
return $outcome;
}


function post($user_id,$post)
{
global $world_url;
$user_id=clean($user_id);
$post=clean($post);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/post"));
	  
$outcome = $client->post($user_id,$post);
return $outcome;
}


function global_config()
{
global $world_url;

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/global_config"));
	  
$outcome = $client->global_config();
return $outcome;
}


function user_capital_coordinates($user_id)
{
global $world_url;
$user_id=clean($user_id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/user_capital_coordinates"));
	  
$outcome = $client->user_capital_coordinates($user_id);
return $outcome;
}



function training_queue($user_id)
{
global $world_url;
$user_id=clean($user_id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/training_queue"));
	  
$outcome = $client->training_queue($user_id);
return $outcome;
}



function developments_queue($user_id)
{
global $world_url;
$user_id=clean($user_id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/developments_queue"));
	  
$outcome = $client->developments_queue($user_id);
return $outcome;
}


function army_move_queue($user_id)
{
global $world_url;
$user_id=clean($user_id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/army_move_queue"));
	  
$outcome = $client->army_move_queue($user_id);
return $outcome;
}


function block_det_from_id($block_id,$user_id)
{
global $world_url;
$block_id=clean($block_id);
$user_id=clean($user_id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/block_det_from_id"));
	  
$outcome = $client->block_det_from_id($block_id,$user_id);
return $outcome;
}


function units()
{
global $world_url;
$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/units"));
	  
$outcome = $client->units();
return $outcome;
}


function reinforcements_in($user_id)
{
global $world_url;
$user_id=clean($user_id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/reinforcements_in"));
	  
$outcome = $client->reinforcements_in($user_id);
return $outcome;
}


function reinforcements_out($user_id)
{
global $world_url;
$user_id=clean($user_id);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/reinforcements_out"));
	  
$outcome = $client->reinforcements_out($user_id);
return $outcome;
}

function stats($op)
{
global $world_url;
if(!isset($_SESSION["user"])) system_messages("Request Failed",'',1,1);
$op=clean($op);

$client = new SoapClient(null, array(     'location' =>$world_url,
      'uri'      => "urn://earthlead/stats"));
	  
 
$outcome = $client->stats($_SESSION["user"][0],$op);
return $outcome;
}
?>
Return current item: earthlead browser game (mmog)