$script)); if ($session['user']['loggedin']) { modulehook("everyheader-loggedin", array('script'=>$script)); } $runheaders[$script] = true; modulehook("header-$script"); } } $arguments = func_get_args(); if (!$arguments || count($arguments) == 0) { $arguments = array("Legend of the Green Dragon"); } $title = call_user_func_array("sprintf_translate", $arguments); $title = holidayize($title,'title'); $title = sanitize($title); calculate_buff_fields(); $header = $template['header']; $header=str_replace("{title}",$title,$header); $header.=tlbutton_pop(); } /** * Returns an output formatted popup link based on JavaScript * * @param string $page The URL to open * @param string $size The size of the popup window (Default: 550x300) * @return string */ function popup($page,$size="550x300"){ //$s = split("x",$size); $s = explode("x",$size); return "window.open('$page','".preg_replace("([^[:alnum:]])","",$page)."','scrollbars=yes,resizable=yes,width={$s[0]},height={$s[1]}').focus()"; } /** * Brings all the output elements together and terminates the rendering of the page. Saves the current user info and updates the rendering statistics * Hooks provided: * footer-{$script name} * everyfooter * */ function page_footer($saveuser=true){ global $output,$nestedtags,$header,$nav,$session,$REMOTE_ADDR, $REQUEST_URI,$pagestarttime,$quickkeys,$template,$y2,$z2, $logd_version,$copyright,$SCRIPT_NAME,$nopopups, $footer, $dbinfo; $z = $y2^$z2; $footer = $template['footer']; //page footer module hooks $script = substr($SCRIPT_NAME,0,strpos($SCRIPT_NAME,".")); $replacementbits = array(); $replacementbits = modulehook("footer-$script",$replacementbits); if ($script == "runmodule" && (($module = httpget('module'))) > "") { // This modulehook allows you to hook directly into any module without // the need to hook into footer-runmodule and then checking for the // required module. modulehook("footer-$module",$replacementbits); } // Pass the script file down into the footer so we can do something if // we need to on certain pages (much like we do on the header. // Problem is 'script' is a valid replacement token, so.. use an // invalid one which we can then blow away. $replacementbits['__scriptfile__'] = $script; $replacementbits = modulehook("everyfooter",$replacementbits); if ($session['user']['loggedin']) { $replacementbits = modulehook("everyfooter-loggedin", $replacementbits); } unset($replacementbits['__scriptfile__']); //output any template part replacements that above hooks need (eg, //advertising) reset($replacementbits); while (list($key,$val)=each($replacementbits)){ $header = str_replace("{".$key."}","{".$key."}".join($val,""),$header); $footer = str_replace("{".$key."}","{".$key."}".join($val,""),$footer); } $builtnavs = buildnavs(); restore_buff_fields(); calculate_buff_fields(); tlschema("common"); $charstats = charstats(); restore_buff_fields(); $sql = "SELECT motddate FROM " . db_prefix("motd") . " ORDER BY motditem DESC LIMIT 1"; $result = db_query($sql); $row = db_fetch_assoc($result); db_free_result($result); $headscript = ""; if (isset($session['user']['lastmotd']) && ($row['motddate']>$session['user']['lastmotd']) && (!isset($nopopup[$SCRIPT_NAME]) || $nopopups[$SCRIPT_NAME]!=1) && $session['user']['loggedin']){ $headscript.=popup("motd.php"); $session['needtoviewmotd']=true; }else{ $session['needtoviewmotd']=false; } $pre_headscript = ""; if ($headscript>""){ $header=str_replace("{headscript}",$pre_headscript."",$header); }else{ $header = str_replace("{headscript}",$pre_headscript,$header); } $script = ""; if (!isset($session['user']['name'])) $session['user']['name']=""; if (!isset($session['user']['login'])) $session['user']['login']=""; //clean up unclosed output tags. while (list($key,$val)=each($nestedtags)){ if ($nestedtags[$key] === true) $output.=""; unset($nestedtags[$key]); } //output keypress script $script.=""; //handle paypal if (strpos($footer,"{paypal}") || strpos($header,"{paypal}")){ $palreplace="{paypal}"; }else{ $palreplace="{stats}"; } //NOTICE | //NOTICE | Although under the license, you're not required to keep this //NOTICE | paypal link, I do request, as the author of this software //NOTICE | which I have made freely available to you, that you leave it in. //NOTICE | $paypalstr = '
'; $currency = getsetting("paypalcurrency", "USD"); if (!isset($_SESSION['logdnet']) || !isset($_SESSION['logdnet']['']) || $_SESSION['logdnet']['']=="" || !isset($session['user']['laston']) || date("Y-m-d H:i:s",strtotime("-1 hour"))>$session['user']['laston']){ $already_registered_logdnet = false; }else{ $already_registered_logdnet = true; } if (getsetting("logdnet",0) && $session['user']['loggedin'] && !$already_registered_logdnet){ //account counting, just for my own records, I don't use this in the calculation for server order. $sql = "SELECT count(*) AS c FROM " . db_prefix("accounts"); $result = db_query_cached($sql,"acctcount",600); $row = db_fetch_assoc($result); $c = $row['c']; $a = getsetting("serverurl","http://".$_SERVER['SERVER_NAME'].($_SERVER['SERVER_PORT'] == 80?"":":".$_SERVER['SERVER_PORT']).dirname($_SERVER['REQUEST_URI'])); if (!preg_match("/\\/$/", $a)) { $a = $a . "/"; savesetting("serverurl", $a); } $l = getsetting("defaultlanguage","en"); $d = getsetting("serverdesc","Another LoGD Server"); $e = getsetting("gameadminemail", "postmaster@localhost.com"); $u = getsetting("logdnetserver","http://logdnet.logd.com/"); if (!preg_match("/\\/$/", $u)) { $u = $u . "/"; savesetting("logdnetserver", $u); } global $logd_version; $v = $logd_version; $c = rawurlencode($c); $a = rawurlencode($a); $l = rawurlencode($l); $d = rawurlencode($d); $e = rawurlencode($e); $v = rawurlencode($v); $u = rawurlencode($u); $paypalstr .= ""; }else{ $paypalstr .= '
'; } // DP Donation button $paypalstr .= '
'; $paypalstr .= '
'; $paysite = getsetting("paypalemail", ""); if ($paysite != "") { $paypalstr .= '
'; $paypalstr .= '
'; if (file_exists("payment.php")) { $paypalstr .= ''; } $paypalstr .= '
'; } $paypalstr .= '
'; $footer=str_replace($palreplace,(strpos($palreplace,"paypal")?"":"{stats}").$paypalstr,$footer); $header=str_replace($palreplace,(strpos($palreplace,"paypal")?"":"{stats}").$paypalstr,$header); //NOTICE | //NOTICE | Although I will not deny you the ability to remove the above //NOTICE | paypal link, I do request, as the author of this software //NOTICE | which I made available for free to you that you leave it in. //NOTICE | //output the nav $footer = str_replace("{".($z)."}",$$z,$footer); $header=str_replace("{nav}",$builtnavs,$header); $footer=str_replace("{nav}",$builtnavs,$footer); //output the motd $header = str_replace("{motd}", motdlink(), $header); $footer = str_replace("{motd}", motdlink(), $footer); //output the mail link if (isset($session['user']['acctid']) && $session['user']['acctid']>0 && $session['user']['loggedin']) { $header=str_replace("{mail}",maillink(),$header); $footer=str_replace("{mail}",maillink(),$footer); }else{ $header=str_replace("{mail}","",$header); $footer=str_replace("{mail}","",$footer); } //output petition count $header=str_replace("{petition}","".translate_inline("Petition for Help")."",$header); $footer=str_replace("{petition}","".translate_inline("Petition for Help")."",$footer); if ($session['user']['superuser'] & SU_EDIT_PETITIONS){ $sql = "SELECT count(petitionid) AS c,status FROM " . db_prefix("petitions") . " GROUP BY status"; $result = db_query_cached($sql,"petition_counts"); $petitions=array(0=>0,1=>0,2=>0,3=>0,4=>0,5=>0,6=>0,7=>0); while ($row = db_fetch_assoc($result)) { $petitions[(int)$row['status']] = $row['c']; } $pet = translate_inline("`0`bPetitions:`b"); $ued = translate_inline("`0`bUser Editor`b"); db_free_result($result); if ($session['user']['superuser'] & SU_EDIT_USERS){ $p = "$ued|$pet"; addnav("", "user.php"); addnav("", "viewpetition.php"); } else { $p = "$pet"; addnav("", "viewpetition.php"); } $p .= " `\${$petitions[5]}`0|`^{$petitions[4]}`0|`b{$petitions[0]}`b|{$petitions[1]}|`!{$petitions[3]}`0|`#{$petitions[7]}`0|`%{$petitions[6]}`0|`i{$petitions[2]}`i"; $pcount = templatereplace("petitioncount", array("petitioncount"=>appoencode($p, true))); $footer = str_replace("{petitiondisplay}", $pcount, $footer); $header = str_replace("{petitiondisplay}", $pcount, $header); } else { $footer = str_replace("{petitiondisplay}", "", $footer); $header = str_replace("{petitiondisplay}", "", $header); } //output character stats $footer=str_replace("{stats}",$charstats,$footer); $header=str_replace("{stats}",$charstats,$header); //do something -- I don't know what $header=str_replace("{script}",$script,$header); //output view PHP source link $sourcelink = "source.php?url=".preg_replace("/[?].*/","",($_SERVER['REQUEST_URI'])); $footer=str_replace("{source}","".translate_inline("View PHP Source")."",$footer); $header=str_replace("{source}","".translate_inline("View PHP Source")."",$header); //output version $footer=str_replace("{version}", "Version: $logd_version", $footer); //output page generation time $gentime = getmicrotime()-$pagestarttime; $session['user']['gentime']+=$gentime; $session['user']['gentimecount']++; $footer=str_replace("{pagegen}","Page gen: ".round($gentime,3)."s / ".$dbinfo['queriesthishit']." queries (".round($dbinfo['querytime'],3)."s), Ave: ".round($session['user']['gentime']/$session['user']['gentimecount'],3)."s - ".round($session['user']['gentime'],3)."/".round($session['user']['gentimecount'],3)."",$footer); tlschema(); //clean up spare {fields}s from header and footer (in case they're not used) $footer = preg_replace("/{[^} \t\n\r]*}/i","",$footer); $header = preg_replace("/{[^} \t\n\r]*}/i","",$header); //finalize output $output=$header.$output.$footer; $session['user']['gensize']+=strlen($output); $session['output']=$output; if ($saveuser === true) { saveuser(); } unset($session['output']); //this somehow allows some frames to load before the user's navs say it can //session_write_close(); echo $output; exit(); } /** * Page header for popup windows. * * @param string $title The title of the popup window */ function popup_header($title="Legend of the Green Dragon"){ global $header, $template; translator_setup(); prepare_template(); modulehook("header-popup"); $arguments = func_get_args(); if (!$arguments || count($arguments) == 0) { $arguments = array("Legend of the Green Dragon"); } $title = call_user_func_array("sprintf_translate", $arguments); $title = holidayize($title,'title'); $header = $template['popuphead']; $header = str_replace("{title}", $title, $header); } /** * Ends page generation for popup windows. Saves the user account info - doesn't update page generation stats * */ function popup_footer(){ global $output,$nestedtags,$header,$session,$y2,$z2,$copyright, $template; while (list($key,$val)=each($nestedtags)){ if ($nestedtags[$key] === true) $output.=""; unset($nestedtags[$key]); } $footer = $template['popupfoot']; // Pass the script file down into the footer so we can do something if // we need to on certain pages (much like we do on the header. // Problem is 'script' is a valid replacement token, so.. use an // invalid one which we can then blow away. $replacementbits = modulehook("footer-popup",array()); //output any template part replacements that above hooks need reset($replacementbits); while (list($key,$val)=each($replacementbits)){ $header = str_replace("{".$key."}","{".$key."}".join($val,""),$header); $footer = str_replace("{".$key."}","{".$key."}".join($val,""),$footer); } $z = $y2^$z2; $footer = str_replace("{".($z)."}",$$z, $footer); //clean up spare {fields}s from header and footer (in case they're not used) $footer = preg_replace("/{[^} \t\n\r]*}/i","",$footer); $header = preg_replace("/{[^} \t\n\r]*}/i","",$header); $output=$header.$output.$footer; saveuser(); session_write_close(); echo $output; exit(); } $charstat_info = array(); $last_charstat_label = ""; /** * Resets the character stats array * */ function wipe_charstats(){ global $charstat_info, $last_charstat_label; $last_charstat_label = ""; $charstat_info = array(); } /** * Add a attribute and/or value to the character stats display * * @param string $label The label to use * @param mixed $value (optional) value to display */ function addcharstat($label, $value=false) { global $charstat_info, $last_charstat_label; if ($value === false) { if (!isset($charstat_info[$label])) $charstat_info[$label] = array(); $last_charstat_label=$label; } else { if ($last_charstat_label=="") { $last_charstat_label = "Other Info"; addcharstat($last_charstat_label); } $charstat_info[$last_charstat_label][$label]=$value; } } /** * Returns the character stat related to the category ($cat) and the label * * @param string $cat The relavent category for the stat * @param string $label The label of the character stat * @return mixed The value associated with the stat */ function getcharstat($cat, $label) { global $charstat_info; return $charstat_info[$cat][$label]; } /** * Sets a value to the passed category & label for character stats * * @param string $cat The category for the char stat * @param string $label The label associated with the value * @param mixed $val The value of the attribute */ function setcharstat($cat, $label, $val) { global $charstat_info, $last_charstat_label; if (!isset($charstat_info[$cat][$label])) { $oldlabel = $last_charstat_label; addcharstat($cat); addcharstat($label, $val); $last_charstat_label = $oldlabel; } else { $charstat_info[$cat][$label] = $val; } } /** * Returns output formatted character stats * * @param array $buffs * @return string */ function getcharstats($buffs){ //returns output formatted character statistics. global $charstat_info; $charstat_str = templatereplace("statstart"); reset($charstat_info); foreach ($charstat_info as $label=>$section) { if (count($section)) { $arr = array("title"=>translate_inline($label)); $sectionhead = templatereplace("stathead", $arr); reset($section); foreach ($section as $name=>$val) { if ($name==$label){ // when the section and stat name are equal, use // 'statbuff' template piece. $a2 = array("title"=>translate_inline("`0$name"), "value"=>"`^$val`0"); $charstat_str .= templatereplace("statbuff", $a2); }else{ $a2 = array("title"=>translate_inline("`&$name`0"), "value"=>"`^$val`0"); $charstat_str .= $sectionhead.templatereplace("statrow", $a2); $sectionhead = ""; } } } } $charstat_str .= templatereplace("statbuff", array("title"=>translate_inline("`0Buffs"),"value"=>$buffs)); $charstat_str .= templatereplace("statend"); return appoencode($charstat_str,true); } /** * Returns the value associated with the section & label. Returns an empty string if the stat isn't set * * @param string $section The character stat section * @param string $title The stat display label * @return mixed The value associated with the stat */ function getcharstat_value($section,$title){ global $charstat_info; if (isset($charstat_info[$section][$title])){ return $charstat_info[$section][$title]; }else{ return ""; } } /** * Returns the current character stats or (if the character isn't logged in) the currently online players * Hooks provided: * charstats * * @return array The current stats for this character or the list of online players */ function charstats(){ global $session, $playermount, $companions; wipe_charstats(); $u =& $session['user']; if ($session['loggedin']){ $u['hitpoints']=round($u['hitpoints'],0); $u['experience']=round($u['experience'],0); $u['maxhitpoints']=round($u['maxhitpoints'],0); $spirits=array(-6=>"Resurrected",-2=>"Very Low",-1=>"Low","0"=>"Normal",1=>"High",2=>"Very High"); if ($u['alive']){ }else{ $spirits[(int)$u['spirits']] = "DEAD"; } //calculate_buff_fields(); reset($session['bufflist']); $atk=$u['attack']; $def=$u['defense']; $buffcount = 0; $buffs = ""; while (list($key,$val)=each($session['bufflist'])){ if (isset($val['suspended']) && $val['suspended']) continue; if (isset($val['atkmod'])) { $atk *= $val['atkmod']; } if (isset($val['defmod'])) { $def *= $val['defmod']; } // Short circuit if the name is blank if ($val['name'] > "" || $session['user']['superuser'] & SU_DEBUG_OUTPUT){ tlschema($val['schema']); if ($val['name']=="") $val['name'] = "DEBUG: {$key}"; if (is_array($val['name'])) { $val['name'][0] = str_replace("`%","`%%",$val['name'][0]); $val['name']=call_user_func_array("sprintf_translate", $val['name']); } else { //in case it's a string $val['name']=translate_inline($val['name']); } if ($val['rounds']>=0){ // We're about to sprintf, so, let's makes sure that // `% is handled. //$n = translate_inline(str_replace("`%","`%%",$val['name'])); $b = translate_inline("`#%s `7(%s rounds left)`n","buffs"); $b = sprintf($b, $val['name'], $val['rounds']); $buffs.=appoencode($b, true); }else{ $buffs.= appoencode("`#{$val['name']}`n",true); } tlschema(); $buffcount++; } } if ($buffcount==0){ $buffs.=appoencode(translate_inline("`^None`0"),true); } $atk = round($atk, 2); $def = round($def, 2); if ($atk < $u['attack']){ $atk = round($u['attack'],1)."`\$".round($atk-$u['attack'],1); }else if($atk > $u['attack']){ $atk = round($u['attack'],1)."`@+".round($atk-$u['attack'],1); } else { // They are equal, display in the 1 signifigant digit format. $atk = round($atk,1); } if ($def < $u['defense']){ $def = round($u['defense'],1)."`\$".round($def-$u['defense'],1); }else if($def > $u['defense']){ $def = round($u['defense'],1)."`@+".round($def-$u['defense'],1); } else { // They are equal, display in the 1 signifigant digit format. $def = round($def, 1); } addcharstat("Vital Info"); addcharstat("Name", $u['name']); addcharstat("Level", "`b".$u['level'].check_temp_stat("level",1)."`b"); if ($u['alive']) { addcharstat("Hitpoints", $u['hitpoints'].check_temp_stat("hitpoints",1). "`0/".$u['maxhitpoints'].check_temp_stat("maxhitpoints",1)); addcharstat("Turns", $u['turns'].check_temp_stat("turns",1)); addcharstat("Attack", $atk.check_temp_stat("attack",1)); addcharstat("Defense", $def.check_temp_stat("defense",1)); } else { $maxsoul = $u['level'] * 5 + 50; addcharstat("Soulpoints", $u['soulpoints'].check_temp_stat("soulpoints",1)."`0/".$maxsoul); addcharstat("Torments", $u['gravefights'].check_temp_stat("gravefights",1)); addcharstat("Psyche", 10+round(($u['level']-1)*1.5)); addcharstat("Spirit", 10+round(($u['level']-1)*1.5)); } addcharstat("Spirits", translate_inline("`b".$spirits[(int)$u['spirits']]."`b")); if ($u['race'] != RACE_UNKNOWN) { addcharstat("Race", translate_inline($u['race'],"race")); }else { addcharstat("Race", translate_inline(RACE_UNKNOWN,"race")); } if (count($companions)>0) { addcharstat("Companions"); foreach ($companions as $name=>$companion) { if ($companion['hitpoints'] > 0 ||(isset($companion['cannotdie']) && $companion['cannotdie'] == true)) { if ($companion['hitpoints']<0) { $companion['hitpoints'] = 0; } if($companion['hitpoints']<$companion['maxhitpoints']) { $color = "`\$"; }else{ $color = "`@"; } if (isset($companion['suspended']) && $companion['suspended'] == true) { $suspcode = "`7 *"; } else { $suspcode = ""; } addcharstat($companion['name'], $color.($companion['hitpoints'])."`7/`&".($companion['maxhitpoints'])."$suspcode`0"); } } } addcharstat("Personal Info"); if ($u['alive']) { addcharstat("Gold", $u['gold'].check_temp_stat("gold",1)); } else { addcharstat("Favor", $u['deathpower'].check_temp_stat("deathpower",1)); } addcharstat("Gems", $u['gems'].check_temp_stat("gems",1)); addcharstat("Experience", $u['experience'].check_temp_stat("experience",1)); addcharstat("Equipment Info"); addcharstat("Weapon", $u['weapon']); addcharstat("Armor", $u['armor']); if ($u['hashorse']) addcharstat("Creature", $playermount['mountname'] . "`0"); modulehook("charstats"); $charstat = getcharstats($buffs); if (!is_array($session['bufflist'])) $session['bufflist']=array(); return $charstat; }else{ $ret = ""; if ($ret = datacache("charlisthomepage")){ }else{ $onlinecount=0; // If a module wants to do it's own display of the online chars, // let it. $list = modulehook("onlinecharlist", array()); if (isset($list['handled']) && $list['handled']) { $onlinecount = $list['count']; $ret = $list['list']; } else { $sql="SELECT name,alive,location,sex,level,laston,loggedin,lastip,uniqueid FROM " . db_prefix("accounts") . " WHERE locked=0 AND loggedin=1 AND laston>'".date("Y-m-d H:i:s",strtotime("-".getsetting("LOGINTIMEOUT",900)." seconds"))."' ORDER BY level DESC"; $result = db_query($sql); $ret.=appoencode(sprintf(translate_inline("`bOnline Characters (%s players):`b`n"),db_num_rows($result))); while ($row = db_fetch_assoc($result)) { $ret.=appoencode("`^{$row['name']}`n"); $onlinecount++; } db_free_result($result); if ($onlinecount==0) $ret.=appoencode(translate_inline("`iNone`i")); } savesetting("OnlineCount",$onlinecount); savesetting("OnlineCountLast",strtotime("now")); updatedatacache("charlisthomepage",$ret); } return $ret; } } /** * Loads the template into the current session. If the template doesn't * exist - uses the default (admin-defined) template, and then falls back * to jade.htm * * @param string $templatename The template name (minus the path) * @return array The template split into the sections defined by ")); if ($fieldname!=""){ $template[$fieldname]=substr($val,strpos($val,"-->")+3); modulehook("template-{$fieldname}", array("content"=>$template[$fieldname])); } } return $template; } /** * Returns a display formatted (and popup enabled) mail link - determines if unread mail exists and highlights the link if needed * * @return string The formatted mail link */ function maillink(){ global $session; $sql = "SELECT sum(if(seen=1,1,0)) AS seencount, sum(if(seen=0,1,0)) AS notseen FROM " . db_prefix("mail") . " WHERE msgto=\"".$session['user']['acctid']."\""; $result = db_query_cached($sql,"mail-{$session['user']['acctid']}",86400); $row = db_fetch_assoc($result); db_free_result($result); $row['seencount']=(int)$row['seencount']; $row['notseen']=(int)$row['notseen']; if ($row['notseen']>0){ return sprintf("".translate_inline("Ye Olde Mail: %s new, %s old", 'common')."",$row['notseen'],$row['seencount']); }else{ return sprintf("".translate_inline("Ye Olde Mail: %s new, %s old", 'common')."",$row['notseen'],$row['seencount']); } } /** * Returns a display formatted (and popup enabled) MOTD link - determines if unread MOTD items exist and highlights the link if needed * * @return string The formatted MOTD link */ function motdlink(){ global $session; if ($session['needtoviewmotd']){ return "".translate_inline("MoTD").""; }else{ return "".translate_inline("MoTD").""; } } ?>