From c9555fb9bba6a96b6a3daabafac36df1daeb29bc Mon Sep 17 00:00:00 2001 From: Shadez Date: Sun, 22 Aug 2010 18:18:36 +0900 Subject: [PATCH] [369] Display all available achievements in Feats of Strength category (comparison), use unique cache ID for comparison cases. phpDoc documentations for missed classes were updated. --- character-achievements.php | 38 ++- includes/classes/class.achievements.php | 76 ++++- includes/classes/class.arenateams.php | 109 ++++++- includes/classes/class.guilds.php | 70 +++-- includes/classes/class.mangos.php | 119 ++++++-- includes/classes/class.utils.php | 368 +++++++++++++++++++++--- includes/revision_nr.php | 2 +- 7 files changed, 669 insertions(+), 113 deletions(-) diff --git a/character-achievements.php b/character-achievements.php index 03bddf77b..4ec69e14a 100644 --- a/character-achievements.php +++ b/character-achievements.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 366 + * @revision 369 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -78,10 +78,20 @@ // Get page cache if($characters->GetGUID() > 0 && $isCharacter && $armory->armoryconfig['useCache'] == true && !isset($_GET['skipCache'])) { if($achievement_category > 0) { - $cache_id = $utils->GenerateCacheId('character-achievements-c'.$achievement_category, $characters->GetName(), $armory->currentRealmInfo['name']); + if(is_array($comparisonData)) { + $cache_id = $utils->GenerateCacheId('character-achievements-c'.$achievement_category, $utils->GenerateCacheIdForComparisons($comparisonData)); + } + else { + $cache_id = $utils->GenerateCacheId('character-achievements-c'.$achievement_category, $characters->GetName(), $armory->currentRealmInfo['name']); + } } else { - $cache_id = $utils->GenerateCacheId('character-achievements', $characters->GetName(), $armory->currentRealmInfo['name']); + if(is_array($comparisonData)) { + $cache_id = $utils->GenerateCacheId('character-achievements', $utils->GenerateCacheIdForComparisons($comparisonData)); + } + else { + $cache_id = $utils->GenerateCacheId('character-achievements', $characters->GetName(), $armory->currentRealmInfo['name']); + } } if($cache_data = $utils->GetCache($cache_id)) { echo $cache_data; @@ -106,18 +116,20 @@ $pages_count = count($pages); $achievements_page = $achievements->LoadAchievementPage($achievement_category, ($characters->GetFaction() == 1) ? 0 : 1); $i = 0; + if($achievement_category == 81) { + // Generate all available achievements + $owner_fos = $achievements->BuildFoSListForComparison($pages); + $pages = $owner_fos; + $achievements_page = $owner_fos[0]; + } if(isset($achievements_page['completed'])) { foreach($achievements_page['completed'] as $achievement) { - if($achievement['display'] == 0) { + if(isset($achievement['display']) && $achievement['display'] == 0) { continue; } if($utils->IsWriteRaw()) { if(is_array($pages)) { - $xml->XMLWriter()->writeRaw(' $a_data_value) { - $xml->XMLWriter()->writeRaw(' ' . $a_data_key . '="' . $a_data_value . '"'); - } - $xml->XMLWriter()->writeRaw('>'); //achievement + $xml->XMLWriter()->writeRaw(''); for($aCount = 0; $aCount < $pages_count; $aCount++) { $tmp = $pages[$aCount]; $xml->XMLWriter()->writeRaw('XMLWriter()->startElement('achievement'); - foreach($achievement['data'] as $a_data_key => $a_data_value) { - $xml->XMLWriter()->writeAttribute($a_data_key, $a_data_value); - } + $xml->XMLWriter()->writeAttribute('desc', $achievement['data']['desc']); + $xml->XMLWriter()->writeAttribute('icon', $achievement['data']['icon']); + $xml->XMLWriter()->writeAttribute('title', $achievement['data']['title']); for($aCount = 0; $aCount < $pages_count; $aCount++) { $tmp = $pages[$aCount]; $xml->XMLWriter()->startElement('c'); - if(isset($tmp['completed'][$achievement['data']['id']])) { + if(isset($tmp['completed'][$achievement['data']['id']]['data']['dateCompleted']) && $tmp['completed'][$achievement['data']['id']]['data']['dateCompleted'] != null) { $xml->XMLWriter()->writeAttribute('dateCompleted', $tmp['completed'][$achievement['data']['id']]['data']['dateCompleted']); } $xml->XMLWriter()->endElement(); //c diff --git a/includes/classes/class.achievements.php b/includes/classes/class.achievements.php index 6f24c1c7b..09b8302f7 100644 --- a/includes/classes/class.achievements.php +++ b/includes/classes/class.achievements.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 367 + * @revision 369 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -110,6 +110,12 @@ public function GetAchievementPoints() { return $this->pts; } + /** + * Returns completed achievements count + * @category Achievements class + * @access public + * @return int + **/ public function GetAchievementsCount() { return $this->m_count; } @@ -153,6 +159,13 @@ public function CountCharacterAchievements() { return $this->m_count; } + /** + * Returns summary data for completed achievements in selected category. + * @category Achievements class + * @access public + * @param int $category + * @return array + **/ public function GetSummaryAchievementData($category) { if(!$this->guid) { $this->Log()->writeError('%s : player guid not defined', __METHOD__); @@ -272,7 +285,7 @@ public function GetLastAchievements() { } /** - * Returns achievement date. If $guid not provided, function will use $this->guid. + * Returns achievement date. * @category Achievements class * @access public * @param int $achId = 0 @@ -427,7 +440,7 @@ public function LoadAchievementPage($page_id, $faction) { return false; } $return_data = array(); - $i=0; + $i = 0; $hide_id = array(); foreach($achievements_data as $achievement) { $this->achId = $achievement['id']; @@ -495,7 +508,13 @@ public function LoadAchievementPage($page_id, $faction) { return $return_data; } - public function BuildAchievementCriteriaTable() { + /** + * Builds criterias table for current (this->achId) achievement + * @category Achievements class + * @access private + * @return array + **/ + private function BuildAchievementCriteriaTable() { if($this->GetLocale() == 'es_es' || $this->GetLocale() == 'es_mx') { $locale = 'en_gb'; } @@ -517,7 +536,7 @@ public function BuildAchievementCriteriaTable() { if($criteria['completionFlag']&ACHIEVEMENT_CRITERIA_FLAG_HIDE_CRITERIA) { continue; } - $m_data = $this->GetCriteriaData($criteria['id']); + $m_data = self::GetCriteriaData($criteria['id']); if(!isset($m_data['counter']) || !$m_data['counter']) { $m_data['counter'] = 0; } @@ -544,7 +563,14 @@ public function BuildAchievementCriteriaTable() { return $achievement_criteria; } - public function GetCriteriaData($criteria_id) { + /** + * Returns criteria ($criteria_id) data + * @category Achievements class + * @access private + * @param int $criteria_id + * @return array + **/ + private function GetCriteriaData($criteria_id) { if(!$this->guid) { $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; @@ -552,6 +578,14 @@ public function GetCriteriaData($criteria_id) { return $this->db->selectRow("SELECT * FROM `character_achievement_progress` WHERE `guid`=%d AND `criteria`=%d", $this->guid, $criteria_id); } + /** + * Generates statistics page + * @category Achievements class + * @access public + * @param int $page_id + * @param int $faction + * @return array + **/ public function LoadStatisticsPage($page_id, $faction) { if(!$this->guid) { $this->Log()->writeError('%s : player guid not defined', __METHOD__); @@ -577,7 +611,13 @@ public function LoadStatisticsPage($page_id, $faction) { return $return_data; } - public function GetCriteriaValue() { + /** + * Returns criteria value for current achievement (this->achId) + * @category Achievements class + * @access private + * @return int + **/ + private function GetCriteriaValue() { if(!$this->guid || !$this->achId) { $this->Log()->writeError('%s : player guid or achievement id not defined', __METHOD__); return false; @@ -601,5 +641,27 @@ public function GetCriteriaValue() { } return $tmp_criteria_value; } + + /** + * Generates Feats of Strength list for achievements comparison. + * @category Achievements class + * @access public + * @param array $pages + * @return array + **/ + public function BuildFoSListForComparison($pages) { + if(!is_array($pages)) { + return false; + } + foreach($pages as $char) { + foreach($char['completed'] as $achList) { + if(!isset($pages[0]['completed'][$achList['data']['id']])) { + $pages[0]['completed'][$achList['data']['id']] = $achList; + $pages[0]['completed'][$achList['data']['id']]['data']['dateCompleted'] = null; + } + } + } + return $pages; + } } ?> \ No newline at end of file diff --git a/includes/classes/class.arenateams.php b/includes/classes/class.arenateams.php index a38288eac..1d54906f2 100644 --- a/includes/classes/class.arenateams.php +++ b/includes/classes/class.arenateams.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 365 + * @revision 369 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -37,6 +37,12 @@ public $guid; private $gameid = false; + /** + * Builds team info + * @category Arenateams class + * @access public + * @return bool + **/ public function InitTeam() { if(!$this->teamname && !$this->arenateamid) { $this->Log()->writeError('%s : teamname and arenateamid are not defined', __METHOD__); @@ -62,6 +68,12 @@ public function InitTeam() { self::GetTeamList(); } + /** + * Returns array with team info, member list and stats + * @category Arenateams class + * @access public + * @return array + **/ public function GetArenaTeamInfo() { if(!$this->arenateamid) { $this->Log()->writeError('%s : arenateamid not defined', __METHOD__); @@ -103,6 +115,12 @@ public function GetArenaTeamInfo() { return $arenateaminfo; } + /** + * Checks is arena team exists + * @category Arenateams class + * @access public + * @return bool + **/ public function IsTeam() { if(!$this->teamname && !$this->arenateamid) { $this->Log()->writeError('%s : teamname and arenateamid are not defined', __METHOD__); @@ -118,6 +136,12 @@ public function IsTeam() { return $check; } + /** + * Generates and returns info about character's (this->guid) arena teams. + * @category Arenateams class + * @access public + * @return array + **/ public function GetCharacterArenaTeamInfo() { if(!$this->guid) { $this->Log()->writeError('%s : player guid not defined', __METHOD__); @@ -125,7 +149,6 @@ public function GetCharacterArenaTeamInfo() { } $team_names = $this->cDB->select("SELECT `name` FROM `arena_team` WHERE `arenateamid` IN (SELECT `arenateamid` FROM `arena_team_member` WHERE `guid`=%d)", $this->guid); if(!$team_names) { - $this->Log()->writeLog('%s : player %d does not have any arena teams', __METHOD__, $this->guid); return false; } $count_teams = count($team_names); @@ -138,6 +161,12 @@ public function GetCharacterArenaTeamInfo() { return $teams_result; } + /** + * Generates arena team member list + * @category Arenateams class + * @access public + * @return array + **/ public function GetTeamList() { $this->players = $this->cDB->select(" SELECT @@ -169,6 +198,16 @@ public function GetTeamList() { } } + /** + * Builds arena ladder list + * @category Arenateams class + * @access public + * @param int $type + * @param bool $num = false + * @param string $order = 'rating' + * @param string $sort = 'ASC' + * @return array + **/ public function BuildArenaLadderList($type, $page, $num = false, $order = 'rating', $sort = 'ASC') { if($num == true) { $summary = 0; @@ -258,11 +297,19 @@ public function BuildArenaLadderList($type, $page, $num = false, $order = 'ratin return $result_areanteams; } - public function GetArenaTeamEmblem($teamId = null, $db = false) { - if($teamId == null) { + /** + * Returns arena team emblem info. + * @category Arenateams class + * @access public + * @param int $teamId = 0 + * @param object $db = null + * @return array + **/ + public function GetArenaTeamEmblem($teamId = 0, $db = null) { + if($teamId == 0) { $teamId = $this->arenateamid; } - if($db == false) { + if($db == null) { $arenaTeamEmblem = $this->cDB->selectRow(" SELECT `BackgroundColor` AS `background`, `BorderColor` AS `borderColor`, `BorderStyle` AS `borderStyle`, `EmblemColor` AS `iconColor`, `EmblemStyle` AS `iconStyle` FROM `arena_team` @@ -284,6 +331,13 @@ public function GetArenaTeamEmblem($teamId = null, $db = false) { } } + /** + * Count all arena teams (by type) in all available realms. + * @category Arenateams class + * @access public + * @param int $type + * @return int + **/ public function CountArenaTeams($type) { $summary = 0; foreach($this->realmData as $realm_info) { @@ -294,12 +348,26 @@ public function CountArenaTeams($type) { return $summary; } + /** + * Returns number of pages (arena ladder) + * @category Arenateams class + * @access public + * @param int $type + * @return int + **/ public function CountPageNum($type) { $all_teams = self::CountArenaTeams($type); $result = round($all_teams/20); return $result; } + /** + * Sets game id (arena chart) + * @category Arenateams class + * @access public + * @param int $gameid + * @return bool + **/ public function SetGameID($gameid) { if($gameid > 0) { $this->gameid = $gameid; @@ -307,10 +375,22 @@ public function SetGameID($gameid) { return true; } + /** + * Returns game id (arena ladder) + * @category Arenateams class + * @access public + * @return int + **/ public function GetGameID() { return $this->gameid; } + /** + * Generates game info (by ID (this->gameid)) + * @category Arenateams class + * @access public + * @return array + **/ public function GetGameInfo() { if(!$this->gameid || $this->gameid === 0) { $this->Log()->writeError('%s : gameid not provided', __METHOD__); @@ -396,10 +476,23 @@ public function GetGameInfo() { return $chart_teams; } + /** + * Checks is team exists + * @category Arenateams class + * @access public + * @param int $teamId + * @return bool + **/ public function TeamExists($teamId) { return $this->cDB->selectCell("SELECT 1 FROM `arena_team` WHERE `arenateamid`=%d LIMIT 1", $teamId); } + /** + * Builds game list for current arena team + * @category Arenateams class + * @access public + * @return array + **/ public function BuildGameChart() { if(!$this->arenateamid) { $this->Log()->writeError('%s : arenateamid not provided', __METHOD__); @@ -459,6 +552,12 @@ public function BuildGameChart() { return $chart_data; } + /** + * Build opponents list for current arena team + * @category Arenateams class + * @access public + * @return array + **/ public function BuildOpposingTeamList() { if(!$this->arenateamid) { $this->Log()->writeError('%s : arenateamid not provided', __METHOD__); diff --git a/includes/classes/class.guilds.php b/includes/classes/class.guilds.php index acc4f7f47..acc387e0c 100644 --- a/includes/classes/class.guilds.php +++ b/includes/classes/class.guilds.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 365 + * @revision 369 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -30,21 +30,29 @@ /** * Player guid + * @category Guilds class + * @access public **/ public $guid; /** - * Guild id + * Guild ID + * @category Guilds class + * @access public **/ public $guildId; /** * Guild name + * @category Guilds class + * @access public **/ public $guildName; /** * Guild tabard style + * @category Guilds class + * @access public **/ public $guildtabard; public $emblemstyle; @@ -54,12 +62,16 @@ public $bgcolor; /** - * Guild leader guid + * Guild Leader GUID + * @category Guilds class + * @access public **/ public $guildleaderguid; /** * Guild faction + * @category Guilds class + * @access public **/ public $guildFaction; @@ -110,7 +122,7 @@ public function InitGuild() { return false; } /** - * Set $this->guildId of selected player ($this->guid) + * Assign guild ID by player GUID * @category Guilds class * @access private * @return bool @@ -130,10 +142,10 @@ private function GetGuildIDByPlayerGUID($guid = false) { } /** - * Counts guild members count + * Return guild members count * @category Guilds class - * @example Guilds::countGuildMembers() - * @return int + * @access public + * @return int **/ public function CountGuildMembers() { if(!$this->guildId) { @@ -144,7 +156,7 @@ public function CountGuildMembers() { } /** - * Sets $this->guildFaction as $this->guildleaderguid's faction + * Assign guild faction by player faction ID * @category Guilds class * @access private * @return bool @@ -160,10 +172,10 @@ private function GetGuildFaction() { } /** - * Returns array with guild members list. If $gm == true, returns his/her data only. + * Returns array with guild members list. * @category Guilds class - * @example Guilds::buildGuildList(false) - * @return array + * @access public + * @return array **/ public function BuildGuildList() { if(!$this->guildId) { @@ -184,7 +196,7 @@ public function BuildGuildList() { LEFT JOIN `guild` AS `guild` ON `guild`.`guildid`=%d WHERE `guild`.`guildid`=%d AND `characters`.`level`>=%d AND `guild_member`.`guid`=`characters`.`guid`", $this->guildId, $this->guildId, $this->guildId, $this->armoryconfig['minlevel']); $countMembers = count($memberListTmp); - for($i=0;$i<$countMembers;$i++) { + for($i = 0; $i < $countMembers; $i++) { $pl = new Characters; $pl->BuildCharacter($memberListTmp[$i]['name'], $this->currentRealmInfo['id'], false); $memberListTmp[$i]['achPoints'] = $pl->GetAchievementMgr()->GetAchievementPoints(); @@ -195,16 +207,13 @@ public function BuildGuildList() { } /** - * Returns array with guild members info for guild-stats.php page + * Returns array with guild members statistics * @category Guilds class - * @example Guilds::BuildStatsList() - * @return array + * @access public + * @return array **/ public function BuildStatsList() { - return $this->cDB->select(" - SELECT `race`, `class`, `level`, `gender` - FROM `characters` - WHERE `guid` IN (SELECT `guid` FROM `guild_member` WHERE `guildid`=%d) AND `level`>=%d", $this->guildId, $this->armoryconfig['minlevel']); + return $this->cDB->select("SELECT `race`, `class`, `level`, `gender` FROM `characters` uid` IN (SELECT `guid` FROM `guild_member` WHERE `guildid`=%d) AND `level`>=%d", $this->guildId, $this->armoryconfig['minlevel']); } /** @@ -224,8 +233,8 @@ public function GetGuildInfo() { /** * Returns guild bank tabs info (name, icon) * @category Guilds class - * @example Guilds::getGuildBankTabs() - * @return array + * @access public + * @return array **/ public function GetGuildBankTabs() { if(!$this->guildId) { @@ -234,7 +243,7 @@ public function GetGuildBankTabs() { } $tabs = $this->cDB->select("SELECT `TabId` AS `id`, `TabName` AS `name`, LOWER(`TabIcon`) AS `icon` FROM `guild_bank_tab` WHERE `guildid`=%d", $this->guildId); $count_tabs = count($tabs); - for($i=0;$i<$count_tabs;$i++) { + for($i = 0; $i < $count_tabs; $i++) { $tabs[$i]['viewable'] = 'true'; } return $tabs; @@ -243,8 +252,8 @@ public function GetGuildBankTabs() { /** * Returns guild bank money * @category Guilds class - * @example Guilds::GetGuildBankMoney() - * @return int + * @access public + * @return int **/ public function GetGuildBankMoney() { if(!$this->guildBankMoney) { @@ -255,10 +264,11 @@ public function GetGuildBankMoney() { } /** - * Returns list of items that stored in guild bank + * Returns guild bank items * @category Guilds class - * @example Guilds::BuildGuildBankItemList() - * @return array + * @category Guilds class + * @access public + * @return array **/ public function BuildGuildBankItemList() { if(!$this->guildId) { @@ -292,10 +302,10 @@ public function BuildGuildBankItemList() { } /** - * Returns array with guild ranks id (not titles). Requires $this->guildId! + * Returns array with guild rank IDs. * @category Guilds class - * @example Guilds::GetGuildRanks() - * @return array + * @access public + * @return array **/ public function GetGuildRanks() { diff --git a/includes/classes/class.mangos.php b/includes/classes/class.mangos.php index ed56640f1..26ab8631f 100644 --- a/includes/classes/class.mangos.php +++ b/includes/classes/class.mangos.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 365 + * @revision 369 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -28,34 +28,70 @@ Class Mangos extends Armory { - /* CSWOWD */ + /** + * Returns skill ID that required for item $id + * @category Mangos class + * @access public + * @param int $id + * @return int + **/ public function GetSkillIDFromItemID($id) { if($id == 0) { return SKILL_UNARMED; } $item = $this->wDB->selectRow("SELECT `class`, `subclass` FROM `item_template` WHERE `entry`=%d LIMIT 1", $id); - if(empty($item)) { + if(!$item) { return SKILL_UNARMED; } if($item['class'] != 2) { return SKILL_UNARMED; } - switch ($item['subclass']) { - case 0: return SKILL_AXES; - case 1: return SKILL_TWO_HANDED_AXE; - case 2: return SKILL_BOWS; - case 3: return SKILL_GUNS; - case 4: return SKILL_MACES; - case 5: return SKILL_TWO_HANDED_MACES; - case 6: return SKILL_POLEARMS; - case 7: return SKILL_SWORDS; - case 8: return SKILL_TWO_HANDED_SWORDS; - case 10: return SKILL_STAVES; - case 13: return SKILL_FIST_WEAPONS; - case 15: return SKILL_DAGGERS; - case 16: return SKILL_THROWN; - case 18: return SKILL_CROSSBOWS; - case 19: return SKILL_WANDS; + switch($item['subclass']) { + case 0: + return SKILL_AXES; + break; + case 1: + return SKILL_TWO_HANDED_AXE; + break; + case 2: + return SKILL_BOWS; + break; + case 3: + return SKILL_GUNS; + break; + case 4: + return SKILL_MACES; + break; + case 5: + return SKILL_TWO_HANDED_MACES; + break; + case 6: + return SKILL_POLEARMS; + break; + case 7: + return SKILL_SWORDS; + break; + case 8: + return SKILL_TWO_HANDED_SWORDS; + break; + case 10: + return SKILL_STAVES; + break; + case 13: + return SKILL_FIST_WEAPONS; + break; + case 15: + return SKILL_DAGGERS; + break; + case 16: + return SKILL_THROWN; + break; + case 18: + return SKILL_CROSSBOWS; + break; + case 19: + return SKILL_WANDS; + break; } return SKILL_UNARMED; } @@ -173,8 +209,9 @@ public function GetGameObjectInfo($entry, $infoType) { /** * Returns NPC name (according with current locale) * @category Mangos class - * @example Mangos::GetNPCName(32078) - * @return string + * @access public + * @param int $npc + * @return string **/ public function GetNPCName($npc) { if($this->GetLocale() == 'en_gb' || $this->GetLocale() == 'en_us') { @@ -213,8 +250,10 @@ public function GetNPCName($npc) { /** * Returns NPC info (infoType) * @category Mangos class - * @example Mangos::GetNPCInfo(32078, 'level') - * @return mixed + * @access public + * @param int $npc + * @param string $infoType + * @return mixed **/ public function GetNpcInfo($npc, $infoType) { $info = null; @@ -399,7 +438,9 @@ public function GetNpcInfo($npc, $infoType) { /** * Generates money value * @category Mangos class - * @return array + * @access public + * @param int $money + * @return array **/ public function GetMoney($money) { $getMoney['gold'] = floor($money/(100*100)); @@ -410,6 +451,13 @@ public function GetMoney($money) { return $getMoney; } + /** + * Returns extended cost info for $costId cost. + * @category Mangos class + * @access public + * @param int $costId + * @return array + **/ public function GetExtendedCost($costId) { if($costId == 0) { return false; @@ -433,6 +481,13 @@ public function GetExtendedCost($costId) { return $extended_cost; } + /** + * Is PvP extended cost required? + * @category Mangos class + * @access public + * @param int $costId + * @return array + **/ public function GetPvPExtendedCost($costId) { $costInfo = $this->aDB->selectRow("SELECT `arenaPoints` AS `arena`, `honorPoints` AS `honor` FROM `ARMORYDBPREFIX_extended_cost` WHERE `id`=%d", $costId); if(!$costInfo || ($costInfo['arena'] == 0 && $costInfo['honor'] == 0)) { @@ -441,6 +496,15 @@ public function GetPvPExtendedCost($costId) { return $costInfo; } + /** + * Generates drop percent for $boss_id boss and $item_id item. + * @category Mangos class + * @access public + * @param int $boss_id + * @param string $db_table + * @param int $item_id + * @return int + **/ public function GenerateLootPercent($boss_id, $db_table, $item_id) { // CSWOWD code $allowed_tables = array( @@ -483,6 +547,13 @@ public function GenerateLootPercent($boss_id, $db_table, $item_id) { return $percent; } + /** + * Returns ExtendedCost for item $itemID + * @category Mangos class + * @access public + * @param int $itemID + * @return int + **/ public function GetVendorExtendedCost($itemID) { $costId = $this->wDB->selectCell("SELECT `ExtendedCost` FROM `npc_vendor` WHERE `item`=%d LIMIT 1", $itemID); if($costId < 0) { diff --git a/includes/classes/class.utils.php b/includes/classes/class.utils.php index d1836c8fc..4069a22ca 100644 --- a/includes/classes/class.utils.php +++ b/includes/classes/class.utils.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 368 + * @revision 369 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -28,11 +28,40 @@ Class Utils extends Armory { + /** + * Account ID + * @category Utils class + * @access public + **/ public $accountId; + + /** + * Username + * @category Utils class + * @access public + **/ public $username; + + /** + * Password + * @category Utils class + * @access public + **/ public $password; + + /** + * Login-password hash (SHA1) + * @category Utils class + * @access public + **/ public $shaHash; + /** + * User authorization + * @category Utils class + * @access public + * @return bool + **/ public function AuthUser() { if(!$this->username || !$this->password) { $this->Log()->writeError('%s : username or password not defined', __METHOD__); @@ -56,6 +85,12 @@ public function AuthUser() { } } + /** + * Close session for current user + * @category Utils class + * @access public + * @return bool + **/ public function CloseSession() { unset($_SESSION['wow_login']); unset($_SESSION['username']); @@ -63,6 +98,14 @@ public function CloseSession() { return true; } + /** + * Checks if account have any character that can browse guild bank. + * @category Utils class + * @access public + * @param int $guildId + * @param int $realmId + * @return bool + **/ public function IsAllowedToGuildBank($guildId, $realmId) { if(!isset($_SESSION['accountId'])) { return false; @@ -91,6 +134,14 @@ public function IsAllowedToGuildBank($guildId, $realmId) { return true; } + /** + * Is account have current character? :D + * @category Utils class + * @access public + * @param int $guid + * @param int $realmId + * @return bool + **/ public function IsAccountHaveCurrentCharacter($guid, $realmId) { if(!isset($_SESSION['accountId'])) { return false; @@ -112,6 +163,12 @@ public function IsAccountHaveCurrentCharacter($guid, $realmId) { return true; } + /** + * Counts all selected characters. + * @category Utils class + * @access public + * @return int + **/ public function CountSelectedCharacters() { if(!isset($_SESSION['accountId'])) { return false; @@ -119,6 +176,12 @@ public function CountSelectedCharacters() { return $this->aDB->selectCell("SELECT COUNT(`guid`) FROM `ARMORYDBPREFIX_login_characters` WHERE `account`=%d", $_SESSION['accountId']); } + /** + * Counts all characters. + * @category Utils class + * @access public + * @return int + **/ public function CountAllCharacters() { if(!isset($_SESSION['accountId'])) { return false; @@ -133,6 +196,12 @@ public function CountAllCharacters() { return $count_all; } + /** + * Returns array with all characters. + * @category Utils class + * @access public + * @return array + **/ public function GetAllCharacters() { if(!isset($_SESSION['accountId'])) { return false; @@ -197,6 +266,12 @@ public function GetAllCharacters() { return false; } + /** + * Returns active (selected) character info + * @category Utils class + * @access public + * @return array + **/ public function GetActiveCharacter() { if(!isset($_SESSION['accountId'])) { return false; @@ -214,6 +289,12 @@ public function GetActiveCharacter() { ", $_SESSION['accountId']); } + /** + * Returns array with user bookmarks. + * @category Utils class + * @access public + * @return array + **/ public function GetBookmarks() { if(!isset($_SESSION['accountId'])) { return false; @@ -249,6 +330,14 @@ public function GetBookmarks() { return $result; } + /** + * Creates new bookmark + * @category Utils class + * @access public + * @param string $name + * @param string $realmName + * @return bool + **/ public function AddBookmark($name, $realmName) { if(!isset($_SESSION['accountId'])) { return false; @@ -278,6 +367,14 @@ public function AddBookmark($name, $realmName) { return true; } + /** + * Delete bookmark. + * @category Utils class + * @access public + * @param string $name + * @param string $realmName + * @return bool + **/ public function DeleteBookmark($name, $realmName) { if(!isset($_SESSION['accountId'])) { return false; @@ -286,6 +383,12 @@ public function DeleteBookmark($name, $realmName) { return true; } + /** + * Returns bookmarks count. + * @category Utils class + * @access public + * @return int + **/ public function GetBookmarksCount() { if(!isset($_SESSION['accountId'])) { return false; @@ -297,6 +400,12 @@ public function GetBookmarksCount() { return $count; } + /** + * Generates SHA1 hash. + * @category Utils class + * @access public + * @return string + **/ public function GenerateShaHash() { if(!$this->username || !$this->password) { $this->Log()->writeError('%s : username or password not defined', __METHOD__); @@ -306,6 +415,14 @@ public function GenerateShaHash() { return strtoupper($this->shaHash); } + /** + * Calculates pet bonus for some stats. + * @category Utils class + * @access public + * @param int $stat + * @param int $value + * @param int $unitClass + **/ public function ComputePetBonus($stat, $value, $unitClass) { $hunter_pet_bonus = array(0.22, 0.1287, 0.3, 0.4, 0.35, 0.0, 0.0, 0.0); $warlock_pet_bonus = array(0.0, 0.0, 0.3, 0.4, 0.35, 0.15, 0.57, 0.3); @@ -328,11 +445,27 @@ public function ComputePetBonus($stat, $value, $unitClass) { return 0; } + /** + * Returns float value. + * @category Utils class + * @access public + * @param int $value + * @param int $num + * @return float + **/ public function GetFloatValue($value, $num) { $txt = unpack('f', pack('L', $value)); return round($txt[1], $num); } + /** + * Returns rating coefficient for rating $id. + * @category Utils class + * @access public + * @param array $rating + * @param int $id + * @return int + **/ public function GetRatingCoefficient($rating, $id) { $ratingkey = array_keys($rating); if(!isset($ratingkey[44+$id]) || !isset($rating[$ratingkey[44+$id]])) { @@ -345,14 +478,36 @@ public function GetRatingCoefficient($rating, $id) { return $c; } + /** + * Loads rating info from DB. + * @category Utils class + * @access public + * @param int $level + * @return array + **/ public function GetRating($level) { return $this->aDB->selectRow("SELECT * FROM `ARMORYDBPREFIX_rating` WHERE `level`=%d", $level); } + /** + * Add slashes to string. + * @category Utils class + * @access public + * @param string $string + * @return string + **/ public function escape($string) { return !get_magic_quotes_gpc() ? addslashes($string) : $string; } + /** + * Returns percent value. + * @category Utils class + * @access public + * @param int $max + * @param int $min + * @return int + **/ public function GetPercent($max, $min) { $percent = $max / 100; if($percent == 0) { @@ -365,6 +520,13 @@ public function GetPercent($max, $min) { return $progressPercent; } + /** + * Returns max. array value index. + * @category Utils class + * @access public + * @param array $arr + * @return array + **/ public function GetMaxArray($arr) { if(!is_array($arr)) { $this->Log()->writeError('%s : arr must be in array', __METHOD__); @@ -383,6 +545,15 @@ public function GetMaxArray($arr) { return $index_max; } + /** + * Returns spell bonus damage. + * @category Utils class + * @access public + * @param int $school + * @param int $guid + * @param object $db + * @return int + **/ public function GetSpellBonusDamage($school, $guid, $db) { $field_done_pos = PLAYER_FIELD_MOD_DAMAGE_DONE_POS+$school+1; $field_done_neg = PLAYER_FIELD_MOD_DAMAGE_DONE_NEG+$school+1; @@ -482,6 +653,15 @@ public function GetRealmFirsts() { return $achievements_data; } + /** + * Calculates attack power for different classes by stat mods + * @category Utils class + * @access public + * @param int $statIndex + * @param float $effectiveStat + * @param int $class + * @return float + **/ public function GetAttackPowerForStat($statIndex, $effectiveStat, $class) { $ap = 0; if($statIndex == STAT_STRENGTH) { @@ -514,6 +694,15 @@ public function GetAttackPowerForStat($statIndex, $effectiveStat, $class) { return $ap; } + /** + * Calculates crit chance from agility stat. + * @category Utils class + * @access public + * @param array $rating + * @param int $class + * @param float $agility + * @return float + **/ public function GetCritChanceFromAgility($rating, $class, $agility) { $base = array(3.1891, 3.2685, -1.532, -0.295, 3.1765, 3.1890, 2.922, 3.454, 2.6222, 20, 7.4755); $ratingkey = array_keys($rating); @@ -522,6 +711,15 @@ public function GetCritChanceFromAgility($rating, $class, $agility) { } } + /** + * Calculates spell crit chance from intellect stat. + * @category Utils class + * @access public + * @param array $rating + * @param int $class + * @param float $intellect + * @return float + **/ public function GetSpellCritChanceFromIntellect($rating, $class, $intellect) { $base = array(0, 3.3355, 3.602, 0, 1.2375, 0, 2.201, 0.9075, 1.7, 20, 1.8515); $ratingkey = array_keys($rating); @@ -530,6 +728,14 @@ public function GetSpellCritChanceFromIntellect($rating, $class, $intellect) { } } + /** + * Calculates health regeneration coefficient. + * @category Utils class + * @access public + * @param array $rating + * @param int $class + * @return float + **/ public function GetHRCoefficient($rating, $class) { $ratingkey = array_keys($rating); if(!isset($ratingkey[22+$class]) || !isset($rating[$ratingkey[22+$class]])) { @@ -542,6 +748,14 @@ public function GetHRCoefficient($rating, $class) { return $c; } + /** + * Calculates mana regenerating coefficient + * @category Utils class + * @access public + * @param array $rating + * @param int $class + * @return float + **/ public function GetMRCoefficient($rating, $class) { $ratingkey = array_keys($rating); if(!isset($ratingkey[33+$class]) || !isset($rating[$ratingkey[33+$class]])) { @@ -554,6 +768,13 @@ public function GetMRCoefficient($rating, $class) { return $c; } + /** + * Returns Skill ID that required for Item $id + * @category Utils class + * @access public + * @param int $id + * @return int + **/ public function GetSkillIDFromItemID($id) { if($id == 0) { return SKILL_UNARMED; @@ -585,6 +806,14 @@ public function GetSkillIDFromItemID($id) { return SKILL_UNARMED; } + /** + * Returns skill info for skill $id + * @category Utils class + * @access public + * @param int $id + * @param array $char_data + * @return array + **/ public function GetSkillInfo($id, $char_data) { $skillInfo = array(0,0,0,0,0,0); for ($i=0;$i<128;$i++) { @@ -604,10 +833,28 @@ public function GetSkillInfo($id, $char_data) { return $skillInfo; } - public function GenerateCacheId($page, $att1=0, $att2=0, $att3=0) { + /** + * Generates cache ID (md5 hash) + * @category Utils class + * @access public + * @param string $page + * @param int $att1 = 0 + * @param int $att2 = 0 + * @param int $att3 = 0 + * @return string + **/ + public function GenerateCacheId($page, $att1 = 0, $att2 = 0, $att3 = 0) { return md5($page.':'.ARMORY_REVISION.':'.$att1.':'.$att2.':'.$att3.':'.$this->GetLocale()); } + /** + * Loads cache by $file_id hash (md5). + * @category Utils class + * @access public + * @param string $file_id + * @param string $file_dir = 'characters' + * @return string + **/ public function GetCache($file_id, $file_dir = 'characters') { if($this->armoryconfig['useCache'] != true) { return false; @@ -617,6 +864,10 @@ public function GetCache($file_id, $file_dir = 'characters') { if(file_exists($data_path)) { $data_contents = @file_get_contents($data_path); $data_explode = explode(':', $data_contents); + if(!is_array($data_explode)) { + $this->Log()->writeError('%s : wrong cache data!', __METHOD__); + return false; + } $cache_timestamp = $data_explode[0]; $cache_revision = $data_explode[1]; $name_or_itemid = $data_explode[2]; @@ -630,7 +881,7 @@ public function GetCache($file_id, $file_dir = 'characters') { else { if(file_exists($cache_path)) { $cache_contents = @file_get_contents($cache_path); - if(sizeof($cache_contents) > 0x00) { + if($cache_contents != null) { return $cache_contents; } else { @@ -642,7 +893,15 @@ public function GetCache($file_id, $file_dir = 'characters') { return false; } - public function DeleteCache($file_id, $file_dir) { + /** + * Delete cache by $file_id hash (md5) from $file_dir directory. + * @category Utils class + * @access private + * @param string $file_id + * @param string $file_dir + * @return bool + **/ + private function DeleteCache($file_id, $file_dir) { $data_path = sprintf('cache/%s/%s.data', $file_dir, $file_id); $cache_path = sprintf('cache/%s/%s.cache', $file_dir, $file_id); if(file_exists($data_path)) { @@ -654,7 +913,17 @@ public function DeleteCache($file_id, $file_dir) { return; } - public function WriteCache($file_id, $filedata, $filecontents, $filedir='characters') { + /** + * Write data to cache. + * @category Utils class + * @access public + * @param string $file_id + * @param string $filedata + * @param string $filecontents + * @param string $filedir = 'characters' + * @return bool + **/ + public function WriteCache($file_id, $filedata, $filecontents, $filedir = 'characters') { if($this->armoryconfig['useCache'] != true) { return false; } @@ -674,16 +943,39 @@ public function WriteCache($file_id, $filedata, $filecontents, $filedir='charact return 0x01; } - public function GenerateCacheData($nameOrItemID, $charGuid, $page=null) { + /** + * Generates cache data (creation date, revisions, etc.). + * @category Utils class + * @access public + * @param string $nameOrItemID + * @param int $charGuid + * @param $page = null + * @return string + **/ + public function GenerateCacheData($nameOrItemID, $charGuid, $page = null) { return sprintf('%d:%d:%s:%d:%s:%s', time(), ARMORY_REVISION, $nameOrItemID, $charGuid, $page, $this->GetLocale()); } + /** + * Replace special symbols in $text. + * @category Utils class + * @access public + * @param string $text. + * @return string + **/ public function ValidateSpellText($text) { $letter = array("'",'"' ,"<" ,">" ,">" ,"\r","\n" , "\n" , "\n" ); $values = array("`",'"',"<",">",">","" ,"
", "
", "
"); return str_replace($letter, $values, $text); } + /** + * Converts seconds to day/hour/minutes format. + * @category Utils class + * @access public + * @param int $seconds + * @return string + **/ public function GetTimeText($seconds) { $strings_array = array( 'en_gb' => array( @@ -724,6 +1016,13 @@ public function GetTimeText($seconds) { return $text; } + /** + * Returns spell radius. + * @category Utils class + * @access public + * @param int $index + * @return string + **/ public function GetRadius($index) { $gSpellRadiusIndex = array( '7'=>array(2,0,2), @@ -794,7 +1093,7 @@ public function GetArmoryString($id) { } /** - * Returns player class ID + * Returns player class ID (by class name) * @category Utils class * @access public * @param string $class_string @@ -1028,6 +1327,13 @@ public function CheckConfigRealmData() { return true; } + /** + * Returns true if script should use XMLWriter::WriteRaw() instead of special methods. + * Required for fr/de/es locales. + * @category Utils class + * @access public + * @retunr bool + **/ public function IsWriteRaw() { if($this->GetLocale() == 'en_gb' || $this->GetLocale() == 'en_us' || $this->GetLocale() == 'ru_ru') { return false; @@ -1035,6 +1341,13 @@ public function IsWriteRaw() { return true; } + /** + * Checks $_GET variable for multiply realms/names in it (for achievement/statistics comparison). + * @category Utils class + * @access public + * @param bool $returnFirstRealmName = false + * @return mixed + **/ public function IsAchievementsComparison($returnFirstRealmName = false) { if(!isset($_GET['r']) || (!isset($_GET['cn']) && !isset($_GET['n']))) { return false; @@ -1073,32 +1386,6 @@ public function IsAchievementsComparison($returnFirstRealmName = false) { return $data; } - public function GetAchievementsComparisonDB($realms) { - if(!is_array($realms)) { - $this->Log()->writeError('%s : realms must be in array!', __METHOD__); - return false; - } - $countRealms = count($realms); - $db = array(); - for($i = 0; $i < $countRealms; $i++) { - $rID = self::GetRealmIdByName($realms[$i]['realm']); - if(!$rID) { - $this->Log()->writeError('%s : unable to find realm ID for name "%s", ignore.', __METHOD__, $realms[$i]['realm']); - continue; - } - if(!isset($this->realmData[$rID])) { - $this->Log()->writeError('%s : connection info for realm id %d (name: "%s") not found, ignore.', __METHOD__, $rID, $realms[$i]['realm']); - continue; - } - $realm_info = $this->realmData[$i]; - $db[$i] = new ArmoryDatabaseHandler($realm_info['host_characters'], $realm_info['user_characters'], $realm_info['pass_characters'], $realm_info['name_characters'], $realm_info['charset_characters'], $this->Log()); - if(!$db[$i]) { - unset($db[$i]); - } - } - return $db; - } - /** * Returns bit mask for class ID * @category Utils class @@ -1216,5 +1503,20 @@ public function GetRealmType($realm_id) { unset($realm_id, $realm_info, $this->realmData[$realm_id], $db); return false; } + + /** + * Generate cache ID (md5 hash) for comparison cases (achievements/statistics). + * @category Utils class + * @access public + * @param array $comparison_data + * @return string + **/ + public function GenerateCacheIdForComparisons($comparison_data) { + $characters = ''; + foreach($comparison_data as $char) { + $characters .= $char['name'].'_'.$char['realm']; + } + return md5($characters); + } } ?> \ No newline at end of file diff --git a/includes/revision_nr.php b/includes/revision_nr.php index 61ddf8b54..cf0259086 100644 --- a/includes/revision_nr.php +++ b/includes/revision_nr.php @@ -1,5 +1,5 @@ \ No newline at end of file