public function wow_ss($realm = 0, $display = 0, $region = 0, $update_timer = 0, $data_path = 0, $image_type = 0) { $wowss = modRealmStatus::wow_ss_global(); $realm_status = array(); if ($realm) { $realm_status['realm'] = $realm; } else { $realm_status['realm'] = $wowss['realm']; } if ($region) { $realm_status['region'] = $region; } else { $realm_status['region'] = $wowss['region']; } ## Overide default values from script call foreach ($wowss['get_array'] as $value) { if (${$value}) { $wowss[$value] = ${$value}; } } $realm_status['script_errors'] = array(); if (strtolower($wowss['region']) == 'us') { $realm_status['language'] = 'us'; } ## Verify data path /* if(is_dir($wowss['data_path'])) { if(!isset($wowss['xml_url'])) $wowss['xml_url'] = $wowss[strtolower($wowss['region']).'_xml']; $xml_file = 'wowss-'. modRealmStatus::wow_ss_sfn($wowss['region']) .'-'. substr(md5(''),0,16) .'.xml'; ## Check if we need to update XML cache clearstatcache(); if(file_exists($wowss['data_path'].$xml_file)) { if(time()-($wowss['update_timer']*60) > filemtime($wowss['data_path'].$xml_file)) $update = true; } else $update = true; ## Fetch XML if(isset($update) && $update) { $data = @file_get_contents($wowss['xml_url']); if(strlen($data) > 300) { ## Don't write data unless it is there $handle = fopen($wowss['data_path'].$xml_file,"w"); fwrite($handle,$data); fclose($handle); } else $realm_status['script_errors'][] = 'Unable to access remote XML file.'; } $xml = @strtolower(@file_get_contents($wowss['data_path'].$xml_file)); ## Parse XML if($xml) { $xml = str_replace('�','e',$xml); ## Parse US XML if(strtolower($wowss['region']) == 'us') { preg_match('/<r n="'. strtolower(str_replace("'",''',$wowss['realm'])) .'" t="([0-9])" s="([0-9])" l="([0-9])"\/>/',$xml,$status_array); ## [1] = type, [2] = status, [3] = population if(count($status_array) == 4) { $realm_status['type'] = $wowss['us_codes']['type'][$status_array[1]]; $realm_status['status'] = $wowss['us_codes']['status'][$status_array[2]]; $realm_status['population'] = $wowss['us_codes']['population'][$status_array[3]]; } } ## Parse EU XML if(strtolower($wowss['region']) == 'eu') { preg_match('/<title>\s*'. strtolower($wowss['realm']). '\s*<\/title>.*<\/item>/msU',$xml,$match); preg_match('/domain="population">(.*)</',$match[0],$status_array); if(!$status_array[1]) $realm_status['population'] = 'medium'; else $realm_status['population'] = $wowss['eu_codes']['population'][$status_array[1]]; preg_match('/domain="status">(.*)<.*domain="language">(.*)<.*domain="type">(.*)<.*domain="queue">(.*)</msU',$match[0],$status_array); $realm_status['status'] = $wowss['eu_codes']['status'][$status_array[1]]; $realm_status['language'] = $status_array[2]; $realm_status['type'] = $wowss['eu_codes']['type'][$status_array[3]]; if($status_array[4] != 'false') $realm_status['population'] = 'max'; } if(!$realm_status['status']) $realm_status['status'] = 'error'; if(!$realm_status['population']) $realm_status['population'] = 'error'; if(!$realm_status['type']) $realm_status['type'] = 'error'; if($realm_status['status'] == 'down') $realm_status['population'] = 'offline'; } else $realm_status['script_errors'][] = 'Unable to access XML file.'; } else $realm_status['script_errors'][] = 'Data Path Error.'; */ ##New Status Code if (is_dir($wowss['data_path'])) { if (!isset($wowss['xml_url'])) { $wowss['xml_url'] = $wowss[strtolower($wowss['region']) . '_xml']; } $xml_file = 'wowss-' . modRealmStatus::wow_ss_sfn($wowss['region']) . '-' . substr(md5(''), 0, 16) . '.xml'; ## Check if we need to update XML cache clearstatcache(); if (file_exists($wowss['data_path'] . $xml_file)) { if (time() - $wowss['update_timer'] * 60 > filemtime($wowss['data_path'] . $xml_file)) { $update = true; } } else { $update = true; } if (isset($update) && $update) { $realmname = $realm_status['realm']; if ($realm_status['region'] == 'eu') { $region = "http://eu.battle.net/wow/en/status"; } else { $region = "http://us.battle.net/wow/en/status"; } $fp = fopen($region, "r"); $inrealm = 0; $output = ""; while (!feof($fp)) { $line = fgets($fp); if (preg_match("/{$realmname}/i", $line)) { $inrealm = 1; } if ($inrealm && preg_match("/<\\/tr>/i", $line)) { $inrealm = 0; } if ($inrealm) { $output .= trim($line); } } fclose($fp); $output = preg_replace("/<span class=\"filter-text\">[^<]*<\\/span>/", "", $output); $output = preg_replace("/<span[^>]*>/i", "", $output); $output = preg_replace("/<\\/span>/i", "", $output); $output = preg_replace("/<\\/td><td[^>]*>/i", "|", $output); $output = preg_replace("/<\\/td>/i", "", $output); $rs = explode("|", $output); if ($rs[2] != "N/A") { $realm_status['status'] = 'up'; } else { $realm_status['status'] = 'down'; } if ($rs[1] == '(PvE)') { $realm_status['type'] = 'pve'; } elseif ($rs[1] == "(PvP)") { $realm_status['type'] = 'pvp'; } elseif ($rs[1] == "(RP)") { $realm_status['type'] = 'rp'; } else { $realm_status['type'] = 'error'; } if ($rs[2] == 'Low') { $realm_status['population'] = 'low'; } elseif ($rs[2] == 'Medium') { $realm_status['population'] = 'medium'; } elseif ($rs[2] == 'High') { $realm_status['population'] = 'high'; } elseif ($rs[2] == 'N/A') { $realm_status['population'] = 'offline'; } else { $realm_status['population'] = 'error'; } } } else { $realm_status['script_errors'][] = 'Data Path Error.'; } if ($wowss['display'] == 'full') { unset($update); clearstatcache(); if (file_exists($wowss['data_path'] . strtolower(modRealmStatus::wow_ss_sfn($realm_status['realm'] . ' ' . $wowss['region'])) . '.' . $wowss['image_type'])) { if (time() - $wowss['update_timer'] * 60 > filemtime($wowss['data_path'] . strtolower(modRealmStatus::wow_ss_sfn($realm_status['realm'] . ' ' . $wowss['region'])) . '.' . $wowss['image_type'])) { $update = true; } } else { $update = true; } if (isset($update) && $update) { ## Write image if (isset($wowss['show_language']) && $wowss['show_language'] == 'yes') { $wowss[$realm_status['type']] .= ' ' . trim(strtoupper($realm_status['language'])); } if (strtolower($wowss['region']) == 'eu' and !$realm_status['show_language']) { $wowss[$realm_status['type']] .= ' ' . trim(strtoupper($realm_status['language'])); } modRealmStatus::wow_ss_image($realm_status, $wowss); } /* if(!headers_sent()) { ## Write headers and image if script is called from img tag if($wowss['image_type'] == 'png') { header("Content-type: image/png"); $image = imagecreatefrompng($wowss['data_path'].strtolower(wow_ss_sfn($realm_status['realm'].' '.$wowss['region'])).'.'.$wowss['image_type']); imagepng($image); } elseif($wowss['image_type'] == 'gif') { header("Content-type: image/gif"); $image = imagecreatefromgif($wowss['data_path'].strtolower(wow_ss_sfn($realm_status['realm'].' '.$wowss['region'])).'.'.$wowss['image_type']); imagegif($image); } } else */ //echo '<img alt="WoW Server Status for '. $realm_status['realm'] .'" src="'. $wowss['data_path'].strtolower(modRealmStatus::wow_ss_sfn($realm_status['realm'].' '.$wowss['region'])).'.'.$wowss['image_type'] .'" />'; return array('realm' => $realm_status['realm'], 'imageurl' => $wowss['data_path'] . strtolower(modRealmStatus::wow_ss_sfn($realm_status['realm'] . ' ' . $wowss['region'])) . '.' . $wowss['image_type']); } if ($wowss['display'] == 'half') { if (count($realm_status['script_errors']) or $realm_status['status'] == 'error') { $realm_status['status'] = 'unknown'; } /* if(!headers_sent()) { ## Write headers and image if script is called from img tag if($wowss['image_type'] == 'png') { header("Content-type: image/png"); $image = imagecreatefrompng($wowss['data_path'].$realm_status['status'].'.'.$wowss['image_type']); imagepng($image); } elseif($wowss['image_type'] == 'gif') { header("Content-type: image/gif"); $image = imagecreatefromgif($wowss['data_path'].$realm_status['status'].'.'.$wowss['image_type']); imagegif($image); } } else */ //echo '<img alt="WoW Server Status for '. $realm_status['realm'] .'" src="'. $wowss['data_path'].$realm_status['status'].'.'.$wowss['image_type'] .'" />'; return array('realm' => $realm_status['realm'], 'imageurl' => $wowss['data_path'] . strtolower(modRealmStatus::wow_ss_sfn($realm_status['realm'] . ' ' . $wowss['region'])) . '.' . $wowss['image_type']); } if ($wowss['display'] == 'text') { if (isset($wowss['show_language']) && $wowss['show_language'] == 'yes') { $wowss[$realm_status['type']] .= ' (' . trim(strtoupper($realm_status['language'])) . ')'; } if (strtolower($wowss['region']) == 'eu' and !$realm_status['show_language']) { $wowss[$realm_status['type']] .= ' (' . trim(strtoupper($realm_status['language'])) . ')'; } if (count($realm_status['script_errors'])) { echo '<u>' . $realm_status['realm'] . '</u>'; foreach ($realm_status['script_errors'] as $value) { echo ' ' . $value; } } else { if ($realm_status['status'] != 'error') { echo '<u>' . $realm_status['realm'] . '</u> ' . $wowss[$realm_status['type']] . ': <b>' . $wowss[$realm_status['status']] . ' | ' . $wowss[$realm_status['population']] . '</b>'; } else { echo '<u>' . $realm_status['realm'] . '</u> Error contacting server.'; } } } if ($wowss['display'] == 'none') { return $realm_status; } }