2018-10-14 09:20:56 -05:00
< ? php
// lib.php :: Common functions used throughout the program.
// Dragon Scourge
//
// Program authors: Jamin Blount
// Copyright (C) 2007 by renderse7en
// Script Version 1.0 Beta 5 Build 20
// You may not distribute this program in any manner, modified or
// otherwise, without the express, written consent from
// renderse7en.
//
// You may make modifications, but only for your own use and
// within the confines of the Dragon Scourge License Agreement
// (see our website for that).
//if (file_exists("install.php")) { die("Please remove the <b>install.php</b> and <b>install.sql</b> files from your game directory before continuing."); }
//if (file_exists("install.sql")) { die("Please remove the install.php file from your game directory before continuing."); }
2024-08-08 12:55:08 -05:00
require_once 'shim.php' ;
2018-10-14 09:20:56 -05:00
// Setup for superglobal stuff that can't go in globals.php.
$starttime = getmicrotime ();
$numqueries = 0 ;
$link = opendb ();
$version = " Beta 5 " ;
2024-08-08 12:55:08 -05:00
$bnumber = " 21 " ;
$bname = " Make Playable " ;
$bdate = " 8.8.2024 " ;
2018-10-14 09:20:56 -05:00
include ( " lib2.php " );
// Handling for servers with magic_quotes turned on.
$_POST = array_map ( 'uber_mres' , $_POST );
$_POST = array_map ( 'uber_hsc' , $_POST );
$_GET = array_map ( 'uber_mres' , $_GET );
$_GET = array_map ( 'uber_hsc' , $_GET );
$_COOKIE = array_map ( 'uber_mres' , $_COOKIE );
$_COOKIE = array_map ( 'uber_hsc' , $_COOKIE );
function uber_ss ( $value ) {
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
$value = is_array ( $value ) ?
array_map ( 'uber_ss' , $value ) :
stripslashes ( $value );
return $value ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
}
function uber_mres ( $value ) {
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
$value = is_array ( $value ) ?
array_map ( 'uber_mres' , $value ) :
mysql_real_escape_string ( $value );
return $value ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
}
function uber_hsc ( $value ) {
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
$value = is_array ( $value ) ?
array_map ( 'uber_hsc' , $value ) :
htmlspecialchars ( $value );
return $value ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
}
function opendb () { // Open database connection.
include ( " config.php " );
extract ( $dbsettings );
$link = mysql_connect ( $server , $user , $pass ) or err ( mysql_error (), true );
mysql_select_db ( $name ) or err ( mysql_error (), true );
return $link ;
}
function doquery ( $query ) { // Something of a tiny little database abstraction layer.
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
include ( 'config.php' );
global $numqueries , $controlrow ;
$sqlquery = mysql_query ( preg_replace ( '/<<([a-zA-Z0-9_\-]+)>>/' , $dbsettings [ " prefix " ] . '_$1' , $query ));
if ( $sqlquery == false ) {
if ( $controlrow [ " debug " ] == 1 ) { die ( mysql_error () . " <br /><br /> " . $query ); } else { die ( " A MySQL query error occurred. Please contact the game administrator for more help. " ); }
}
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
$numqueries ++ ;
return $sqlquery ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
}
function dorow ( $sqlquery , $force = " " ) { // Abstraction layer part deux.
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
switch ( mysql_num_rows ( $sqlquery )) {
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
case 0 :
$row = false ;
break ;
case 1 :
if ( $force == " " ) {
$row = mysql_fetch_assoc ( $sqlquery );
} else {
$temprow = mysql_fetch_assoc ( $sqlquery );
$row [ $temprow [ $force ]] = $temprow ;
}
break ;
default :
if ( $force == " " ) {
while ( $temprow = mysql_fetch_assoc ( $sqlquery )) {
$row [] = $temprow ;
}
} else {
while ( $temprow = mysql_fetch_assoc ( $sqlquery )) {
$row [ $temprow [ $force ]] = $temprow ;
}
}
break ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
}
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
return $row ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
}
function gettemplate ( $templatename ) { // SQL query for the template.
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
$filename = " templates/ " . $templatename . " .php " ;
include ( " $filename " );
return $template ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
}
function parsetemplate ( $template , $array ) { // Replace template with proper content. Also does languages.
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
foreach ( $array as $a => $b ) {
$template = str_replace ( " { { { $a } }} " , $b , $template );
}
return $template ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
}
function getmicrotime () { // Used for timing script operations.
2024-08-08 12:55:08 -05:00
list ( $usec , $sec ) = explode ( " " , microtime ());
return (( float ) $usec + ( float ) $sec );
2018-10-14 09:20:56 -05:00
}
function is_email ( $email ) { // Thanks to "mail(at)philipp-louis.de" from php.net!
return ( preg_match ( " /^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]]) \ .)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw) $ |(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]) \ .) { 3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])) $ /i " , $email ));
}
function mymail ( $to , $title , $body , $from = '' ) { // thanks to arto dot PLEASE dot DO dot NOT dot SPAM at artoaaltonen dot fi.
global $controlrow ;
extract ( $controlrow );
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
$from = trim ( $from );
if ( ! $from ) {
$from = " < $adminemail > " ;
}
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
$rp = $adminemail ;
$org = " $gameurl " ;
$mailer = " PHP " ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
$head = " " ;
$head .= " Content-Type: text/plain \r \n " ;
$head .= " Date: " . date ( 'r' ) . " \r \n " ;
$head .= " Return-Path: $rp \r \n " ;
$head .= " From: $from \r \n " ;
$head .= " Sender: $from \r \n " ;
$head .= " Reply-To: $from \r \n " ;
$head .= " Organization: $org \r \n " ;
$head .= " X-Sender: $from \r \n " ;
$head .= " X-Priority: 3 \r \n " ;
$head .= " X-Mailer: $mailer \r \n " ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
$body = str_replace ( " \r \n " , " \n " , $body );
$body = str_replace ( " \n " , " \r \n " , $body );
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
return mail ( $to , $title , $body , $head );
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
}
function err ( $error , $system = false , $panels = true ) { // Basic little error handler.
$errmsg = " One or more errors have occurred:<br /><br /><b> $error </b><br /><br />Please <a href= \" javascript:history.go(-1); \" >go back</a> and try again. " ;
display ( " Error " , $errmsg , $panels );
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
}
function display ( $title , $content , $panels = true ) { // Finalize page and output to browser.
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
include ( 'config.php' );
global $controlrow , $userrow , $worldrow , $numqueries , $starttime , $version , $build ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
if ( ! isset ( $controlrow )) {
$controlrow = dorow ( doquery ( " SELECT * FROM <<control>> WHERE id='1' LIMIT 1 " ));
}
// Make page tags for XHTML validation.
$page = " <?xml version= \" 1.0 \" encoding= \" ISO-8859-1 \" ?> \n "
. " <!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN \" \" DTD/xhtml1-transitional.dtd \" > \n "
. " <html xmlns= \" http://www.w3.org/1999/xhtml \" xml:lang= \" en \" lang= \" en \" > \n " ;
$page .= gettemplate ( " primary " );
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
// Setup for primary page array indexes.
$row = array ();
$row [ " gamename " ] = $controlrow [ " gamename " ];
$row [ " pagetitle " ] = $title ;
$row [ " background " ] = " background " . $userrow [ " world " ];
$row [ " version " ] = $version ;
$row [ " content " ] = $content ;
$row [ " moddedby " ] = $controlrow [ " moddedby " ];
if ( $controlrow [ " forumurl " ] != " " ) { $row [ " forumslink " ] = " <a href= \" " . $controlrow [ " forumurl " ] . " \" >Support Forums</a> " ; } else { $row [ " forumslink " ] = " " ; }
if ( $controlrow [ " debug " ] == 1 ) { $row [ " debug " ] = " / " . $numqueries . " Queries / " . round ( getmicrotime () - $starttime , 4 ) . " Seconds " ; } else { $row [ " debug " ] = " " ; }
if ( $row [ " moddedby " ] != " " ) {
$row [ " info " ] = $row [ " moddedby " ];
} else {
$row [ " info " ] = " Version <a href= \" index.php?do=version \" > " . $row [ " version " ] . " </a> " . $row [ " debug " ];
}
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
// Setup for side panels.
include ( " panels.php " );
2024-08-08 12:55:08 -05:00
if ( $panels == true ) {
$row [ " leftnav " ] = panelleft ();
2018-10-14 09:20:56 -05:00
$row [ " rightnav " ] = panelright ();
$row [ " topnav " ] = paneltop ( true );
$row [ " bottomnav " ] = panelbottom ();
$row [ " middlenav " ] = panelmiddle ();
2024-08-08 12:55:08 -05:00
} else {
$row [ " leftnav " ] = " " ;
2018-10-14 09:20:56 -05:00
$row [ " rightnav " ] = " " ;
$row [ " topnav " ] = paneltop ( false );
$row [ " bottomnav " ] = " " ;
}
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
$page = rtrim ( $page , " <-! " );
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
$page .= <<< THEVERYENDOFYOU
< table cellspacing = " 0 " cellpadding = " 3 " style = " width: 95px; color: #ffffff; border: solid 1px #ffffff; background-color: #000000; margin-top: 2px; " >
< tr >
< td width = " 40% " >
{{ info }}
</ td >
< td width = " 20% " style = " text-align: center; " >
{{ forumslink }}
</ td >
< td width = " 40% " style = " text-align:right; " >
< a href = " index.php?do=version " > Dragon Scourge </ a > & copy ; by < a href = " http://www.renderse7en.com " > renderse7en </ a >.
</ td >
</ tr >
</ table >
</ center ></ body >
</ html >
THEVERYENDOFYOU ;
2024-08-08 12:55:08 -05:00
2018-10-14 09:20:56 -05:00
// Finalize control array for output.
2024-08-08 12:55:08 -05:00
$page = parsetemplate ( $page , $row );
2018-10-14 09:20:56 -05:00
if ( $controlrow [ " compression " ] == 1 ) { ob_start ( " ob_gzhandler " ); }
echo $page ;
die ();
}
2024-08-08 12:55:08 -05:00
?>