Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Edited Files:
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- - styles/default/sidebar.php
- <!-- Arena Stats -->
- <!-- if(TopArena) -->
- {HTML}
- <!-- else(TopArena) -->
- <!-- endif(TopArena) -->
- <!-- Arena Stats.End -->
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- - Added File
- - js/toparena.js
- //Top Arena Teams javascript handlers by ChoMPi
- function resolveFaction(elementId, captain, realm)
- {
- var $elementId = elementId;
- var $captain = captain;
- var $realm = realm;
- var $cont = $('#'+elementId);
- //prepare the ajax error handlers
- $.ajaxSetup({
- error:function(x,e){
- if(x.status==500){
- resolveFaction($elementId, $captain, $realm);
- }else if(e=='parsererror'){
- resolveFaction($elementId, $captain, $realm);
- }else if(e=='timeout'){
- resolveFaction($elementId, $captain, $realm);
- }else{
- resolveFaction($elementId, $captain, $realm);
- }
- }
- });
- $.post(
- "ajax_top_arena.php",
- {
- resolveFaction: true,
- realm: $realm,
- guid: $captain,
- },
- function(data){
- //if error
- if (data == '0')
- {
- $cont.html('Unknown');
- }
- else
- {
- if (data == 'Horde')
- {
- $cont.html('<font color="#9d261d">Horde</font>');
- }
- else if (data == 'Alliance')
- {
- $cont.html('<font color="#1b5183">Alliance</font>');
- }
- else
- {
- $cont.html('Unknown');
- }
- }
- }
- );
- }
- $(document).ready(function()
- {
- var $a_tooltips = 1;
- //Select all anchor tag with rel set to tooltip
- $('a[rel=top-arena-tooltip]').mouseover(function(e)
- {
- var $realm = $(this).attr('realm');
- var $teamid = $(this).attr('teamid');
- //get the element data in order to find our tooltip
- var data = $(this).data('top-arena-tooltip-id');
- //check if the data is not yet set
- if (typeof data == 'undefined')
- {
- data = $a_tooltips;
- $(this).data('top-arena-tooltip-id', data);
- //Append the tooltip template and its value
- $('body').append('<div class="top-arena-tooltip" id="top-arena-tooltip-'+data+'"><div class="tipHeader"></div><div class="tipBody">Loading...</div><div class="tipFooter"></div></div>');
- //get the Tooltip HTML with ajax
- $.post(
- 'ajax_top_arena.php',
- {
- lookupArenaTeam: true,
- realm: $realm,
- arenateamid: $teamid,
- },
- function(dataResponse, textStatus)
- {
- var cont = $('#top-arena-tooltip-'+data).find('.tipBody');
- //check for error
- if (dataResponse == '0')
- {
- $(cont).html('Failed to load HTML data.');
- }
- else
- {
- $(cont).html(dataResponse);
- }
- }
- );
- $a_tooltips = $a_tooltips + 1;
- }
- //find our tooltip element
- var tooltip = $('#top-arena-tooltip-'+data);
- //Set the X and Y axis of the tooltip
- $(tooltip).css('top', e.pageY + 10 - 200);
- $(tooltip).css('left', e.pageX + 20 );
- //Show the tooltip with faceIn effect
- $(tooltip).fadeIn(200);
- }).mousemove(function(e)
- {
- var data = $(this).data('top-arena-tooltip-id');
- var tooltip = $('#top-arena-tooltip-'+data);
- //Keep changing the X and Y axis for the tooltip, thus, the tooltip move along with the mouse
- $(tooltip).css('top', e.pageY + 10 );
- $(tooltip).css('left', e.pageX + 20 );
- }).mouseout(function()
- {
- var data = $(this).data('top-arena-tooltip-id');
- var tooltip = $('#top-arena-tooltip-'+data);
- //hide the tooltip
- $(tooltip).fadeOut(100);
- });
- });
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- - Added File
- - ajax_top_arena.js
- <?php
- require("config.php");
- if ($server_core=='')
- $server_core='trinity';
- require_once './include/dblayer/common_db.php';
- require_once './include/core/'.$server_core.'.php';
- //check if we want to resolve faction of character
- if (isset($_POST['resolveFaction']))
- {
- $error = false;
- //check if the realm and character are passed
- if (isset($_POST['realm']) and isset($_POST['guid']))
- {
- $realmid = (int)$_POST['realm'];
- $guid = (int)$_POST['guid'];
- $teams = new TopArenaTeams();
- //open database connection
- $REALM_DB = newRealmPDO($realmid);
- //check if we got realm database connection
- if ($REALM_DB)
- {
- $teams->setDatabase($REALM_DB);
- $faction = $teams->resolveFaction($guid);
- //check if the faction resolve has failed
- if (!$faction)
- {
- $error = true;
- }
- }
- else
- {
- $error = true;
- }
- unset($REALM_DB);
- unset($teams);
- }
- else
- {
- $error = true;
- }
- //if the faction is resolved
- if (!$error)
- {
- //only first letter capital
- echo ucfirst(strtolower($faction));
- die;
- }
- else
- {
- echo '0';
- die;
- }
- }
- //check if we need to lookup arena team
- if (isset($_POST['lookupArenaTeam']))
- {
- $error = false;
- //check if the realm and arenateamid are passed
- if (isset($_POST['realm']) and isset($_POST['arenateamid']))
- {
- $realmid = (int)$_POST['realm'];
- $teamid = (int)$_POST['arenateamid'];
- $teams = new TopArenaTeams();
- //open database connection
- $REALM_DB = newRealmPDO($realmid);
- //check if we got realm database connection
- if ($REALM_DB)
- {
- $teams->setDatabase($REALM_DB);
- //get team details
- $info = $teams->getTeamInfo($teamid);
- if (!$info)
- {
- $error = true;
- }
- else
- {
- //get the team captain
- $captain = $teams->getTeamCaptain($teamid);
- //get team members
- $membersRes = $teams->getTeamMembers($teamid);
- //predefined variables
- $captainHTML = false;
- $membersHTML = false;
- //if we got team members
- if ($membersRes)
- {
- $membersHTML = '';
- $i = 1;
- while ($row = $membersRes->fetch(PDO::FETCH_ASSOC))
- {
- //check if the current members is the captain
- if ($row['guid'] == $captain)
- {
- $captainHTML = '<ul>
- <li class="col-title">Team Captain:</li>
- <li class="col-info">'.$row['name'].'</li>
- </ul>';
- }
- else
- {
- $membersHTML .= '<ul>
- <li class="col-title">Member '.$i.':</li>
- <li class="col-info">'.$row['name'].'</li>
- </ul>';
- $i++;
- }
- }
- unset($membersRes);
- }
- }
- }
- else
- {
- $error = true;
- }
- unset($REALM_DB);
- unset($teams);
- }
- else
- {
- $error = true;
- }
- if (!$error)
- {
- $html = '<ul>
- <li class="team-name">'.$info['name'].'</li>
- </ul>
- <ul>
- <li class="col-title">Games:</li>
- <li class="games-won">'.$info['wins'].' Won</li>
- <li class="games-lost">'.$info['lost'].' Lost</li>
- </ul>
- <ul>
- <li class="col-title">Type:</li>
- <li class="col-info">'.$info['type'].'</li>
- </ul>
- <ul>
- <li class="col-title">Rating:</li>
- <li class="col-info">'.$info['rating'].'</li>
- </ul>';
- //if we have team captain
- if ($captainHTML)
- {
- $html .= $captainHTML;
- }
- //if we have team members
- if ($membersHTML)
- {
- $html .= $membersHTML;
- }
- echo $html;
- die;
- }
- else
- {
- echo '0';
- die;
- }
- }
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- - styles/default/style.css
- /* Top Arena Teams */
- .top-arena-tooltip {
- position: absolute !important;
- color:#fff;
- z-index: 9999;
- font-size:10px;
- min-width:150px;
- background: #131516;
- display: none;
- opacity: 0.9;
- -moz-box-shadow:0 0 6px rgba(255,255,255,.3), inset 0 0 3px rgba(0,0,0,.4);
- -webkit-box-shadow:0 0 6px rgba(255,255,255,.3), inset 0 0 3px rgba(0,0,0,.4);
- box-shadow:0 0 6px rgba(255,255,255,.3), inset 0 0 3px rgba(0,0,0,.4);
- -webkit-border-radius: 4px;
- -moz-border-radius: 4px;
- border-radius: 4px;
- }
- .top-arena-tooltip .tipHeader {
- }
- /* IE hack */
- *html .top-arena-tooltip .tipHeader {margin-bottom:-6px;}
- .top-arena-tooltip .tipBody {
- padding:15px;
- color: #4e4e4e;
- font-size: 12px;
- font-family: Arial, Helvetica, sans-serif;
- text-shadow: 0 1px 2px rgba(0,0,0,1), 1px 0 2px rgba(0,0,0,1);
- }
- .top-arena-tooltip .tipBody ul {
- display: block;
- list-style: none;
- margin-bottom: 2px;
- }
- .top-arena-tooltip .tipBody ul:last-child {
- margin-bottom: 0px;
- }
- .top-arena-tooltip .tipBody ul li {
- display: inline-block;
- margin-right: 4px;
- }
- .top-arena-tooltip .tipBody ul li.team-name {
- font-size: 18px;
- margin-bottom: 7px;
- top: -5px;
- }
- .top-arena-tooltip .tipBody ul li.games-won {
- color: #1b5183;
- }
- .top-arena-tooltip .tipBody ul li.games-lost {
- color: #9d261d;
- }
- .top-arena-tooltip .tipBody ul li.col-info {
- color: #908074;
- }
- .top-arena-tooltip .tipFooter {
- }
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- - index.php
- ###############################################
- ## TOP ARENA TEAMS by ChoMPi
- ###############################################
- $teams = new TopArenaTeams();
- //loop the realms
- foreach ($TopArenaTeams as $data)
- {
- $REALM_DB = newRealmPDO($id);
- if ($REALM_DB)
- {
- $teams->setDatabase($REALM_DB);
- //get the team resources
- $res = $teams->getTeams($data['limit']);
- //if we have resources
- if ($res)
- {
- $html = '
- <div class="sidebar_box">
- <div class="sidebar_box_head"><p>TOP '.$data['limit'].' ARENA ('.$realm[$data['realmid']]['name'].')</p><span></span></div>
- <div class="sidebar_box_cont arena_top_teams">
- <ul>
- <li id="head">
- <span class="number">N</span>
- <span class="t_name">Team Name</span>
- <span class="t_rating">Rating</span>
- <span class="t_faction">Faction</span>
- </li>';
- $i = 1;
- while ($row = $res->fetch(PDO::FETCH_ASSOC))
- {
- $html .= '
- <li>
- <span class="number">'.$i.'</span>
- <span class="t_name">
- <a style="cursor: pointer;" rel="top-arena-tooltip" realm="'.$data['realmid'].'" teamid="'.$row['arenateamid'].'">
- '.$row['name'].'
- </a>
- </span>
- <span class="t_rating">'.$row['rating'].'</span>
- <span class="t_faction" id="'.$data['realmid'].'-'.$i.'">
- Loading...
- <script type="text/javascript">
- $(document).ready(function()
- {
- resolveFaction(\''.$data['realmid'].'-'.$i.'\', \''.$row['captain'].'\', \''.$data['realmid'].'\');
- });
- </script>
- </span>
- </li>';
- $i++;
- }
- unset($res);
- $html .= '
- </ul>
- </div>
- </div>';
- $tpl_sidebar->gotoNext("TopArena");
- $tpl_sidebar->setVar("TopArena.HTML", $html);
- }
- }
- unset($REALM_DB);
- }
- unset($teams);
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- - include/core/trinity_ra.php
- - include/core/trinity.php
- - include/core/mangos.php
- /***************************************
- * TOP ARENA FUNCTIONS
- ***************************************/
- class TopArenaTeams
- {
- private $db = false;
- private $translate = NULL;
- public function __construct()
- {
- global $db_translation;
- $this->translate = $db_translation;
- return true;
- }
- public function setDatabase($db)
- {
- $this->db = $db;
- return true;
- }
- /**
- ** function getTeams(count) designed to get database resources by specified count
- **
- ** Parameters:
- ** ------------------------------------------------------
- ** $count - limit the resources gethered from the database
- **
- ** Returns:
- ** ------------------------------------------------------
- ** PDO Statement executed and ready for fetching or false if there are no records
- ** - Columns:
- ** `arenateamid`
- ** `rating`
- ** `rank`
- ** `name`
- ** `captain`
- ** `type`
- **
- **/
- public function getTeams($count = 5)
- {
- //make sure the count param is digit
- if (!ctype_digit($count))
- {
- $count = 5;
- }
- $res = $this->db->prepare("
- SELECT
- `arena_team_stats`.`arenateamid` AS arenateamid,
- `arena_team_stats`.`rating` AS rating,
- `arena_team_stats`.`rank` AS rank,
- `arena_team`.`name` AS name,
- `arena_team`.`captainguid` AS captain,
- `arena_team`.`type` AS type
- FROM `arena_team_stats`
- LEFT JOIN `arena_team` ON `arena_team_stats`.`arenateamid` = `arena_team`.`arenateamid`
- ORDER BY rating DESC
- LIMIT " . $count);
- $res->execute();
- if ($res->rowCount() > 0)
- {
- return $res;
- }
- else
- {
- unset($res);
- return false;
- }
- }
- /**
- ** function getTeamMembers(team) designed to get database resources about specifed team
- **
- ** Parameters:
- ** ------------------------------------------------------
- ** $team - the arena team id
- **
- ** Returns:
- ** ------------------------------------------------------
- ** PDO Statement executed and ready for fetching or false if there are no records
- ** - Columns:
- ** `arenateamid`
- ** `guid`
- ** `name`
- **
- **/
- public function getTeamMembers($team)
- {
- $res = $this->db->prepare("
- SELECT
- `arena_team_member`.`arenateamid` AS arenateamid,
- `arena_team_member`.`guid` AS guid,
- `".$this->translate['characters']."`.`".$this->translate['characters_name']."` AS name
- FROM `arena_team_member`
- RIGHT JOIN `".$this->translate['characters']."` ON `".$this->translate['characters']."`.`".$this->translate['characters_guid']."` = `arena_team_member`.`guid`
- WHERE `arena_team_member`.`arenateamid` = :team ORDER BY guid ASC");
- $res->bindParam(':team', $team, PDO::PARAM_INT);
- $res->execute();
- if ($res->rowCount() > 0)
- {
- return $res;
- }
- else
- {
- unset($res);
- return false;
- }
- }
- public function getTeamCaptain($team)
- {
- $res = $this->db->prepare("SELECT `captainguid` FROM `arena_team` WHERE `arenateamid` = :team LIMIT 1");
- $res->bindParam(':team', $team, PDO::PARAM_INT);
- $res->execute();
- if ($res->rowCount() > 0)
- {
- $row = $res->fetch(PDO::FETCH_ASSOC);
- unset($res);
- return $row['captainguid'];
- }
- else
- {
- unset($res);
- return false;
- }
- }
- /**
- ** function getTeamInfo(team) designed to get database resources, fetch and parse
- **
- ** Parameters:
- ** ------------------------------------------------------
- ** $team - the arena team id
- **
- ** Returns:
- ** ------------------------------------------------------
- ** false (bool) - on failure
- ** Columns:
- ** `arenateamid`
- ** `rating`
- ** `rank`
- ** `games`
- ** `wins`
- ** `lost`
- ** `name`
- ** `type`
- **
- **/
- public function getTeamInfo($team)
- {
- $res = $this->db->prepare("SELECT
- `arena_team_stats`.`arenateamid` AS arenateamid,
- `arena_team_stats`.`rating` AS rating,
- `arena_team_stats`.`rank` AS rank,
- `arena_team_stats`.`played` AS games,
- `arena_team_stats`.`wins2` AS wins,
- `arena_team`.`name` AS name,
- `arena_team`.`type` AS type
- FROM `arena_team_stats`
- LEFT JOIN `arena_team` ON `arena_team_stats`.`arenateamid` = `arena_team`.`arenateamid`
- WHERE `arena_team_stats`.`arenateamid` = :team
- ORDER BY rating DESC
- LIMIT 1");
- $res->bindParam(':team', $team, PDO::PARAM_INT);
- $res->execute();
- if ($res->rowCount() > 0)
- {
- $arr = $res->fetch(PDO::FETCH_ASSOC);
- //define array
- $row = array();
- $row['arenateamid'] = $arr['arenateamid'];
- $row['rating'] = $arr['rating'];
- $row['rank'] = $arr['rank'];
- $row['games'] = $arr['games'];
- $row['wins'] = $arr['wins'];
- $row['lost'] = $arr['games'] - $arr['wins'];
- $row['name'] = $arr['name'];
- //transalte the arena type
- if ($arr['type'] == 2)
- {
- $row['type'] = '2v2';
- }
- else if ($arr['type'] == 3)
- {
- $row['type'] = '3v3';
- }
- else
- {
- $row['type'] = '5v5';
- }
- unset($arr);
- return $row;
- }
- else
- {
- unset($res);
- return false;
- }
- }
- /**
- ** function resolveFaction finds out from wich faction the team is by looking at the team's captain record
- **
- ** Parameters:
- ** ----------------------------------------------
- ** $captain - character GUID of the team's captain
- **
- ** Returns:
- ** ----------------------------------------------
- ** alliance (string) - for alliance
- ** horde (string) - for horde
- ** false (bool) - on failure
- **
- **/
- public function resolveFaction($captain)
- {
- $res = $this->db->prepare("SELECT ".$this->translate['characters_guid'].", ".$this->translate['characters_race']." FROM `".$this->translate['characters']."` WHERE `".$this->translate['characters_guid']."` = :guid LIMIT 1");
- $res->bindParam(':guid', $captain, PDO::PARAM_INT);
- $res->execute();
- if ($res->rowCount() > 0)
- {
- $row = $res->fetch(PDO::FETCH_ASSOC);
- $race = $row[$this->translate['characters_race']];
- //check if the faction is alliance
- if ($race == 1 or $race == 3 or $race == 4 or $race == 7 or $race == 11 or $race == 22)
- {
- unset($res);
- return 'alliance';
- }
- else
- {
- unset($res);
- return 'horde';
- }
- }
- else
- {
- unset($res);
- return false;
- }
- }
- public function __destruct()
- {
- unset($this->db);
- }
- }
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- --------------------------------------------------------------------------
- - config.php
- //Top Arena Teams config
- $TopArenaTeams = array(
- array('realmid' => 1, 'limit' => 5),
- array('realmid' => 2, 'limit' => 5),
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement