diff --git a/_js/character/character-select.js b/_js/character/character-select.js index 143d5315f..ca4d9c464 100644 --- a/_js/character/character-select.js +++ b/_js/character/character-select.js @@ -34,7 +34,7 @@ function initializeCharacterSelect(numChars){ }); //adding from the bottom - /*$(".add_on").click(function(){ + $(".add_on").click(function(){ var currUrl = $(this).next().attr("href"); //secondary are set to 2 or 3 @@ -43,7 +43,7 @@ function initializeCharacterSelect(numChars){ currUrl = currUrl.replace("n=","n"+(charsSelected+1)+"="); updateCharIcons(getCollectedCharUrls() + currUrl); - });*/ + }); } //get the urls of the primary and secondary chars @@ -89,7 +89,7 @@ function getCollectedCharUrls(){ //send ajax request to update characters and reload page function updateCharIcons(charUrls){ - /* + $.ajax({ type: "GET", url: 'character-select-submit.xml?' + charUrls, @@ -101,14 +101,134 @@ function updateCharIcons(charUrls){ error: function(msg){ window.location.reload(); //refresh page } - });*/ + }); +} + +char_arr = new Array(); +realm_arr = new Array(); +var lastfield, ajaxinit, default_realm +function add_rss_char(somefield) +{ var char_req = ochar_req = $("#character"+somefield).val() + + if(char_req == '') { if(char_arr[somefield-1] && char_arr[somefield-1].length > 0) + { addchar_error(str_removed+" "+char_req,somefield); + char_arr[somefield-1] = realm_arr[somefield-1] = null; + refresh_rss_url() + //$(".ajax_error:eq("+(somefield-1)+")").html('') + } + else addchar_error(str_err_char,somefield); + return; + } + if(char_req.indexOf("@") < 0 && (!default_realm || default_realm=='')) { addchar_error(str_err_realm,somefield); return } + + char_req = char_req.split("@") + if(!char_req[1] && default_realm) char_req[1] = default_realm + char_req[0] = jQuery.trim(char_req[0]) + char_req[1] = jQuery.trim(char_req[1]).replace(/\s/g,"+") + var char_req_url = "character-feed.xml?r="+char_req[1]+"&cn="+char_req[0]+"&skipCache" + + lastfield = somefield; + + $.get(char_req_url, {}, + function(data,textStatus){ + //alert("Data Loaded: " + data + "\nStatus:"+textStatus); + if(textStatus=="success") + { char_arr[somefield-1] = char_req[0] + realm_arr[somefield-1] = char_req[1] + refresh_rss_url() + $(".ajax_error:eq("+(somefield-1)+")").html('') + $(".character_row:eq("+(somefield-1)+") > a").hide(); + $(".character_row:eq("+(somefield-1)+")").addClass("ok"); + if(somefield<6) $(".character_row:eq("+(somefield)+")").fadeIn("fast",function(){ $("#character"+(Number(somefield)+1)).focus();}) + var charattr = {} + var charInfo = data.getElementsByTagName("character")[0] + var charLvl = Number(charInfo.getAttribute("level")) + var charLvlRg = (charLvl < 60)?"-default":(charLvl < 70)?"":(charLvl < 80)?"-70":"-80" + var charimg = '' + $(".character_row:eq("+(somefield-1)+") > .rss_port").html(charimg) + bindToolTips() + } + }); + if(!ajaxinit) { bind_ajax_error(); ajaxinit = true } + +} + +function rss_remove(somefield) +{ $("#character"+somefield).val('') + add_rss_char(somefield) + } + +function bind_ajax_error() +{ + $(".custom_rss_container").ajaxError(function(event, request, settings){ + if(ochar_req.indexOf("@")==-1){ ochar_req += " on " + default_realm} + addchar_error(str_cantfind.replace('XXX'," " + ochar_req + ""),lastfield); + }); } +function addchar_error(some_err,somefield) +{ var err_field = $(".ajax_error:eq("+(somefield-1)+")") + err_field.parent().removeClass("ok"); + err_field.html(some_err); + err_field.stop(); + err_field.animate({color:"red"},"fast").animate({color:"black"},3000) + +} + +var focusval +function char_check(targ,option) +{ if(!option) + { focusval = targ.value + } + else + { if(targ.value != focusval){ add_rss_char(targ.id.slice(-1)) } + } + +} + +function check_action() +{ $(this).toggleClass('checked'); + if($(this).parent().hasClass('sub')){ $(this).parent().toggleClass('deselected'); } + refresh_rss_url() +} + +var base_rss_url = location.href.split("custom-rss.xml")[0]+ "character-feed.atom" +function refresh_rss_url() +{ var opt_arr = new Array() + var achieve_arr = new Array() + var opt = $(".check_box.checked").each(function(){ if($(this).parent().hasClass("sub")) achieve_arr.push(this.id); + else opt_arr.push(this.id.toUpperCase()); + }) + var feed_url = base_rss_url + "?r="+realm_arr.join(",").replace(/(,+$)+|(^,+)+/g,'')+"&cn="+char_arr.join(",").replace(/(,+$)+|(^,+)/g,'') + if(opt_arr.length > 0 && opt_arr.length != $(".top_level > .check_box").length) feed_url += "&filters="+opt_arr.join(",") + if(achieve_arr.length > 0 && $('#achievement').hasClass('checked') && achieve_arr.length != $(".sub > .check_box").length) + feed_url += "&achCategories="+achieve_arr.join(",") + if(achieve_arr.length == 0 && $('#achievement').hasClass('checked')) $('#achievement').removeClass('checked') + if($('#loot').hasClass('checked')){ + item_qual = $('#loot_rarity').val(); if(item_qual!='') feed_url += "&itemQuality="+ item_qual.toUpperCase(); + item_level = $('#loot_ilvl').val(); if(item_level!='') feed_url += "&itemLevel="+ item_level + } + feed_url = feed_url.replace(/(,+)/g,',')+"&locale="+lang; + if(char_arr.length > 0 && char_arr.join('') != '') $("#customfeed_url").val(feed_url) + if(char_arr.join('') == '') $("#customfeed_url").val('') + //$("#rss_link_copy").attr("href",feed_url) +} + + +function check_default_char() +{ + if((armory_query.n || armory_query.cn) && armory_query.r){ + def_chr = armory_query.n||armory_query.cn + def_rlm = armory_query.r.replace(/\+/g," ") + $("#character1").val(def_chr+"@"+def_rlm); + $(".character_row:first > a").click() + + $("#feed_return").html(backhtml.replace("default_chr",def_chr)).attr('href',"character-sheet.xml?r="+armory_query.r+"&cn="+def_chr); + } +} -//boolean for displaying dual tooltips or not -function setDualTooltipCookie() { - if (document.getElementById('checkboxDualTooltip').checked) - setcookie("armory.cookieDualTooltip", 1); - else - setcookie("armory.cookieDualTooltip", 0); +function toggle_subfilter(which, targ) +{ $(targ).toggleClass('less') + $('#'+which).toggle(); } +//Moved setDualTooltipCookie to common.js diff --git a/cache/_debug/index.php b/cache/_debug/index.php new file mode 100644 index 000000000..8da41334f --- /dev/null +++ b/cache/_debug/index.php @@ -0,0 +1,32 @@ +WoWArmory Debug Log'; +@include('tmp.dbg'); +echo ''; +?> \ No newline at end of file diff --git a/cache/_debug/tmp.dbg b/cache/_debug/tmp.dbg new file mode 100644 index 000000000..e69de29bb diff --git a/character-achievements.php b/character-achievements.php index 0c09be270..8f3ec9e98 100644 --- a/character-achievements.php +++ b/character-achievements.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 203 + * @revision 208 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -223,19 +223,21 @@ // root $xml->XMLWriter()->startElement('rootCategories'); $root_categories = $achievements->BuildCategoriesTree(); -foreach($root_categories as $category) { - $xml->XMLWriter()->startElement('category'); - $xml->XMLWriter()->writeAttribute('id', $category['id']); - $xml->XMLWriter()->writeAttribute('name', $category['name']); - if(isset($category['child']) && is_array($category['child'])) { - foreach($category['child'] as $category_child) { - $xml->XMLWriter()->startElement('category'); - $xml->XMLWriter()->writeAttribute('name', $category_child['name']); - $xml->XMLWriter()->writeAttribute('id', $category_child['id']); - $xml->XMLWriter()->endElement(); //category +if($root_categories && is_array($root_categories)) { + foreach($root_categories as $category) { + $xml->XMLWriter()->startElement('category'); + $xml->XMLWriter()->writeAttribute('id', $category['id']); + $xml->XMLWriter()->writeAttribute('name', $category['name']); + if(isset($category['child']) && is_array($category['child'])) { + foreach($category['child'] as $category_child) { + $xml->XMLWriter()->startElement('category'); + $xml->XMLWriter()->writeAttribute('name', $category_child['name']); + $xml->XMLWriter()->writeAttribute('id', $category_child['id']); + $xml->XMLWriter()->endElement(); //category + } } + $xml->XMLWriter()->endElement(); //category } - $xml->XMLWriter()->endElement(); //category } $xml->XMLWriter()->endElement(); //rootCategories $xml->XMLWriter()->endElement(); //achievements diff --git a/includes/classes/class.achievements.php b/includes/classes/class.achievements.php index 2f644e043..1bd73555f 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 198 + * @revision 208 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -54,6 +54,7 @@ public function CalculateAchievementPoints($guid = null) { $guid = $this->guid; } if(!$guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } $pts = $this->aDB->selectCell(" @@ -91,6 +92,7 @@ public function getAchievementProgressBar($sum) { **/ public function CountCharacterAchievements() { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } return $this->cDB->selectCell("SELECT COUNT(`achievement`) FROM `character_achievement` WHERE `guid`=?", $this->guid); @@ -98,6 +100,7 @@ public function CountCharacterAchievements() { public function GetSummaryAchievementData($category) { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } $achievement_data = array('categoryId' => $category); @@ -192,10 +195,12 @@ public function GetSummaryAchievementData($category) { **/ public function GetLastAchievements() { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } $achievements = $this->cDB->select("SELECT `achievement`, `date` FROM `character_achievement` WHERE `guid`=? ORDER BY `date` DESC LIMIT 5", $this->guid); if(!$achievements) { + $this->Log()->writeError('%s : unable to get data from character_achievement (player %d does not have achievements?)', __METHOD__, $this->guid); return false; } $aCount = count($achievements); @@ -220,6 +225,7 @@ public function GetAchievementDate($guid = null, $achId = null) { } $achievement_date = $this->cDB->selectCell("SELECT `date` FROM `character_achievement` WHERE `achievement`=? AND `guid`=? LIMIT 1", $achId, $guid); if(!$achievement_date) { + $this->Log()->writeError('%s : unable to find completion date for achievement %d, player %d', __METHOD__, $achId, $guid); return false; } return date('Y-m-d\TH:i:s+02:00', $achievement_date); @@ -274,6 +280,10 @@ public function CountAchievementPercent($sum, $achType) { **/ public function BuildCategoriesTree() { $categoryIds = $this->aDB->select("SELECT `id`, `name_".$this->_locale."` AS `name` FROM `armory_achievement_category` WHERE `parentCategory`=-1 AND `id` <> 1"); + if(!$categoryIds) { + $this->Log()->writeError('%s : unable to get categories names (current locale: %s, locId: %d)', __METHOD__, $this->_locale, $this->_loc); + return false; + } $root_tree = array(); $i = 0; foreach($categoryIds as $cat) { @@ -321,10 +331,12 @@ public function BuildStatisticsCategoriesTree() { **/ public function GetAchievementInfo(&$achievementData) { if(!is_array($achievementData)) { + $this->Log()->writeError('%s : achievementData must be an array!', __METHOD__); return false; } $achievementinfo = $this->aDB->selectRow("SELECT `id`, `name_".$this->_locale."` AS `title`, `description_".$this->_locale."` AS `desc`, `points`, `categoryId`, `iconname` AS `icon` FROM `armory_achievement` WHERE `id`=? LIMIT 1", $achievementData['achievement']); if(!$achievementinfo) { + $this->Log()->writeError('%s : unable to get data for achievement %d (current locale: %s; locId: %d)', __METHOD__, $achievementData['achievement'], $this->_locale, $this->_loc); return false; } if($achievementinfo['points'] == 0) { @@ -346,15 +358,18 @@ public function GetDateFormat($timestamp) { public function IsAchievementCompleted($achId) { if(!$this->guid || !$achId) { + $this->Log()->writeError('%s : player guid or achievement id not provided', __METHOD__); return false; } if($achId == 0 || $achId == -1 || !$this->IsAchievementExists($achId)) { + $this->Log()->writeError('%s : achievement %u not exists', __METHOD__, $achId); return false; } $date = $this->cDB->selectCell("SELECT `date` FROM `character_achievement` WHERE `guid`=? AND `achievement`=?", $this->guid, $achId); if($date) { return true; } + $this->Log()->writeError('%s : unable to get completion date for achievement %d, player %d', __METHOD__, $achId, $this->guid); return false; } @@ -368,6 +383,7 @@ public function IsAchievementExists($achId) { public function LoadAchievementPage($page_id, $faction) { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not provided', __METHOD__); return false; } $achievements_data = $this->aDB->select( @@ -375,6 +391,7 @@ public function LoadAchievementPage($page_id, $faction) { FROM `armory_achievement` WHERE `categoryId`=? AND `factionFlag` IN (?, -1) ORDER BY `OrderInCategory`", $page_id, $faction); if(!$achievements_data) { + $this->Log()->writeError('%s : unable to get data (page_id: %u, faction: %u, locale: %s, locId: %d)', __METHOD__, $page_id, $faction, $this->_locale, $this->_loc); return false; } $return_data = array(); @@ -447,10 +464,12 @@ public function LoadAchievementPage($page_id, $faction) { public function BuildAchievementCriteriaTable() { if(!$this->guid || !$this->achId) { + $this->Log()->writeError('%s : player guid or achievement id not defiend', __METHOD__); return false; } $data = $this->aDB->select("SELECT * FROM `armory_achievement_criteria` WHERE `referredAchievement`=? ORDER BY `order`", $this->achId); if(!$data) { + $this->Log()->writeError('%s : achievement criteria for achievement #%d not found', __METHOD__, $this->achId); return false; } $i = 0; @@ -486,17 +505,20 @@ public function BuildAchievementCriteriaTable() { public function GetCriteriaData($criteria_id) { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } $criteria_data = $this->cDB->selectRow("SELECT * FROM `character_achievement_progress` WHERE `guid`=? AND `criteria`=?", $this->guid, $criteria_id); if($criteria_data) { return $criteria_data; } + $this->Log()->writeError('%s : progress for criteria %d and player %d not found in character_achievement_progress table', __METHOD__, $criteria_id, $this->guid); return false; } public function LoadStatisticsPage($page_id, $faction) { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } $achievements_data = $this->aDB->select( @@ -504,6 +526,7 @@ public function LoadStatisticsPage($page_id, $faction) { FROM `armory_achievement` WHERE `categoryId`=? AND `factionFlag` IN (?, -1)", $page_id, $faction); if(!$achievements_data) { + $this->Log()->writeError('%s : unable to get data for page_id %d, faction %d (current locale: %s, locId: %d)', __METHOD__, $page_id, $faction, $this->_locale, $this->_loc); return false; } $return_data = array(); @@ -520,10 +543,12 @@ public function LoadStatisticsPage($page_id, $faction) { public function GetCriteriaValue() { if(!$this->guid || !$this->achId) { + $this->Log()->writeError('%s : player guid or achievement id not defined', __METHOD__); return false; } $criteria_ids = $this->aDB->select("SELECT `id` FROM `armory_achievement_criteria` WHERE `referredAchievement`=?", $this->achId); if(!$criteria_ids) { + $this->Log()->writeError('%s : unable to get criterias for achievement %d', __METHOD__, $this->achId); return false; } $tmp_criteria_value = 0; @@ -537,6 +562,7 @@ public function GetCriteriaValue() { } } if(!$tmp_criteria_value) { + $this->Log()->writeError('%s : criteria value not found (id: %d)', __METHOD__, $this->achId); return 0; } return $tmp_criteria_value; diff --git a/includes/classes/class.characters.php b/includes/classes/class.characters.php index 2a4cef516..dead23b26 100644 --- a/includes/classes/class.characters.php +++ b/includes/classes/class.characters.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 207 + * @revision 208 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -159,6 +159,7 @@ public function IsCharacter() { } public function BuildCharacter($name) { + $this->Log()->writeLog('Prepare data build for player %s', $name); if(!is_string($name)) { return false; } @@ -188,6 +189,7 @@ public function BuildCharacter($name) { LEFT JOIN `guild` AS `guild` ON `guild`.`guildid`=`guild_member`.`guildid` WHERE `characters`.`name`=? LIMIT 1", $name); if(!$player_data || !is_array($player_data)) { + $this->Log()->writeError('%s: unable to get data from characters DB for player %s', __METHOD__, $name); return false; } // Is character allowed to be displayed in Armory? @@ -197,10 +199,12 @@ public function BuildCharacter($name) { if($gmLevel_mangos && $gmLevel_trinity) { // MaNGOS doesn't have `account_access` table in `realmd` DB if($this->currentRealmInfo['type'] == 'trinity') { + $this->Log()->writeLog('Detected MaNGOS AND Trinity data in realmd DB, using Trinity (by armoryconfig[type])'); $gmLevel = $gmLevel_trinity; } else { // error? + $this->Log()->writeLog('Detected MaNGOS AND Trinity data in realmd DB, using MaNGOS (by armoryconfig[type])'); $gmLevel = $gmLevel_mangos; } } @@ -212,32 +216,38 @@ public function BuildCharacter($name) { } if(!$gmLevel) { unset($player_data); + $this->Log()->writeError('Unable to find gmlevel for account #%d (character: %d, %s)', $player_data['account'], $player_data['guid'], $player_data['name']); // Unknown account return false; } $allowed = ($gmLevel <= $this->armoryconfig['minGmLevelToShow']) ? true : false; if(!$allowed || $player_data['level'] < $this->armoryconfig['minlevel']) { + $this->Log()->writeLog('Player %d (%s) is not allowed to be displayed in Armory!', $player_data['guid'], $player_data['name']); unset($player_data); return false; } // Class/race/faction checks if($player_data['class'] >= MAX_CLASSES) { // Unknown class + $this->Log()->writeError('Player %d (%s) have incorrect data in DB: class %d not found.', $player_data['guid'], $player_data['name'], $player_data['class']); unset($player_data); return false; } elseif($player_data['race'] >= MAX_RACES) { // Unknown race + $this->Log()->writeError('Player %d (%s) have incorrect data in DB: race %d not found.', $player_data['guid'], $player_data['name'], $player_data['race']); unset($player_data); return false; } $this->faction = Utils::GetFactionId($player_data['race']); if($this->faction != 0 && $this->faction != 1) { // Unknown faction + $this->Log()->writeError('Player %d (%s) have incorrect faction in DB: faction %d not found (race: %d).', $player_data['guid'], $player_data['name'], $this->faction, $player_data['class']); unset($player_data); return false; } // Everything correct, build class + $this->Log()->writeLog('All correct, player %s builded', $name); foreach($player_data as $pData_key => $pData_value) { $this->{$pData_key} = $pData_value; } @@ -266,6 +276,7 @@ public function BuildCharacter($name) { private function __GetTitleInfo() { $title_data = $this->aDB->selectRow("SELECT `title_F_".$this->_locale."` AS `titleF`, `title_M_".$this->_locale."` AS `titleM`, `place` FROM `armory_titles` WHERE `id`=?d", $this->chosenTitle); if(!$title_data) { + $this->Log()->writeError('Player %d (%s) have wrong chosenTitle id: %d', $this->guid, $this->name, $this->chosenTitle); return true; } switch($this->gender) { @@ -558,56 +569,6 @@ public function GetSecondBar() { return $data; } - /***************** - Function from MBA - ******************/ - - public function talentCounting($tab, $dualSpec = false, $spec = null) { - if(!$this->guid) { - return false; - } - $pt = 0; - if($dualSpec == true) { - $resSpell = $this->cDB->select(" - SELECT `spell` - FROM `character_talent` - WHERE `guid`=? AND `spec`=?", $this->guid, $spec); - } - else { - $resSpell = $this->cDB->select(" - SELECT `spell` - FROM `character_spell` - WHERE `guid`=? AND `disabled`=0", $this->guid); - } - if(!$resSpell) { - return false; - } - foreach($resSpell as $getSpell) { - $spells[] = $getSpell['spell']; - } - $resTal = $this->aDB->select(" - SELECT `Rank_1`, `Rank_2`, `Rank_3`, `Rank_4`, `Rank_5` - FROM `armory_talents` - WHERE `TalentTab` = ?", $tab); - foreach($resTal as $row) { - $ranks[] = $row; - } - foreach($ranks as $key => $val) { - foreach($spells as $k => $v) { - if(in_array($v, $val)) { - switch(array_search($v, $val)) { - case 'Rank_1': $pt += 1; break; - case 'Rank_2': $pt += 2; break; - case 'Rank_3': $pt += 3; break; - case 'Rank_4': $pt += 4; break; - case 'Rank_5': $pt += 5; break; - } - } - } - } - return $pt; - } - /** * Returns item id from $slot (head, neck, shoulder, etc.). Requires $this->guid! * @category Character class @@ -616,6 +577,7 @@ public function talentCounting($tab, $dualSpec = false, $spec = null) { **/ public function getCharacterEquip($slot) { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } switch($slot) { @@ -677,6 +639,7 @@ public function getCharacterEquip($slot) { return $this->GetDataField(PLAYER_VISIBLE_ITEM_19_ENTRYID); break; default: + $this->Log()->writeError('%s : wrong item slot query: %s', __METHOD__, $slot); return 0; break; } @@ -684,6 +647,7 @@ public function getCharacterEquip($slot) { public function GetCharacterEquipBySlot($slotID) { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } return $this->cDB->selectCell("SELECT `item_template` FROM `character_inventory` WHERE `guid`=? AND `slot`=? LIMIT 1", $this->guid, $slotID); @@ -761,6 +725,7 @@ public function getCharacterEnchant($slot, $guid = null) { return $this->GetDataField(PLAYER_VISIBLE_ITEM_19_ENCHANTMENT, $guid); break; default: + $this->Log()->writeError('%s : wrong item slot query: %s', __METHOD__, $slot); return 0; break; } @@ -820,12 +785,14 @@ public function GetTalentTab($tab_count = -1) { **/ public function CalculateCharacterTalents() { if(!$this->class || !$this->guid) { + $this->Log()->writeError('%s : player class or guid not defined', __METHOD__); return false; } $talentTree = array(); $tab_class = self::GetTalentTab(); $character_talents = $this->cDB->select("SELECT * FROM `character_talent` WHERE `guid`=?", $this->guid); if(!$character_talents) { + $this->Log()->writeError('%s : unable to get data from DB for player %d (%s)', __METHOD__, $this->guid, $this->name); return false; } $class_talents = $this->aDB->select("SELECT * FROM `armory_talents` WHERE `TalentTab` IN (?a) ORDER BY `TalentTab`, `Row`, `Col`", $tab_class); @@ -879,6 +846,7 @@ public function CalculateCharacterTalents() { public function CalculateCharacterTalentBuild() { if(!$this->guid || !$this->class) { + $this->Log()->writeError('%s : player class or guid not defined', __METHOD__); return false; } $build_tree = array(1 => null, 2 => null); @@ -887,6 +855,7 @@ public function CalculateCharacterTalentBuild() { $character_talents = $this->cDB->select("SELECT * FROM `character_talent` WHERE `guid`=?", $this->guid); $talent_data = array(0 => null, 1 => null); // Talent build if(!$character_talents) { + $this->Log()->writeError('%s : unable to get data from DB for player %d (%s)', __METHOD__, $this->guid, $this->name); return false; } foreach($character_talents as $_tal) { @@ -949,17 +918,6 @@ public function CalculateCharacterTalentBuild() { } } break; - case 'trinity': - $current_tab = $this->aDB->select("SELECT * FROM `armory_talents` WHERE `TalentTab`=? ORDER BY `TalentTab`, `Row`, `Col`", $tab_class[$i]); - if(!$current_tab) { - continue; - } - foreach($current_tab as $tab) { - for($j=0;$j<2;$j++) { - //if(isset($specs_talents[$j])) - } - } - break; } } } @@ -974,6 +932,7 @@ public function CalculateCharacterTalentBuild() { **/ public function GetCharacterGlyphs($spec = -1) { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } switch($this->currentRealmInfo['type']) { @@ -1071,16 +1030,6 @@ public function ReturnTalentTreeIcon($tree) { return false; } - /** - * Returns character lifetime honorable kills. Requires $this->guid! - * @category Character class - * @example Characters::getCharacterHonorKills() - * @return int - **/ - public function getCharacterHonorKills() { - return $this->GetDataField(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS); - } - /** * Returns array with character's professions (name, icon & current skill value) * @category Character class @@ -1153,6 +1102,7 @@ public function GetDataField($fieldNum, $guid = null) { $guid = $this->guid; } if(!$guid) { + $this->Log()->writeError('%s : guid not provided', __METHOD__); return false; } $dataField = $fieldNum+1; @@ -1165,22 +1115,22 @@ public function GetDataField($fieldNum, $guid = null) { // Health value public function GetMaxHealth() { - return $this->cDB->selectCell("SELECT `health` FROM `characters` WHERE `guid`=? LIMIT 1", $this->guid); + return $this->health; } // Mana value public function GetMaxMana() { - return $this->cDB->selectCell("SELECT `power1` FROM `characters` WHERE `guid`=? LIMIT 1", $this->guid); + return $this->power1; } // Rage value public function GetMaxRage() { - return $this->cDB->selectCell("SELECT `power2` FROM `characters` WHERE `guid`=? LIMIT 1", $this->guid); + return $this->power2; } // Energy (or Runic power for DK) value public function GetMaxEnergy() { - return $this->cDB->selectCell("SELECT `power3` FROM `characters` WHERE `guid`=? LIMIT 1", $this->guid); + return $this->power3; } public function SetRating() { @@ -1916,6 +1866,7 @@ public function getCharacterSkill($skill, $guid=false) { $this->guid = $guid; } if(!$this->guid) { + $this->Log()->writeError('%s : guid not provided', __METHOD__); return false; } $skillInfo = $this->cDB->selectRow("SELECT * FROM `character_skill` WHERE `guid`=? AND `skill`=?", $this->guid, $skill); @@ -1930,6 +1881,7 @@ public function getCharacterSkill($skill, $guid=false) { **/ public function getCharacterArenaTeamInfo($check = false) { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } $arenaTeamInfo = array(); @@ -1991,6 +1943,7 @@ public function getCharacterArenaTeamInfo($check = false) { **/ public function GetCharacterFeed($full = false) { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } if($full) { @@ -2000,6 +1953,7 @@ public function GetCharacterFeed($full = false) { $data = $this->cDB->select("SELECT * FROM `character_feed_log` WHERE `guid`=? ORDER BY `date` DESC LIMIT 10", $this->guid); } if(!$data) { + $this->Log()->writeLog('%s : feed data for player %d (%s) not found!', __METHOD__, $this->guid, $this->name); return false; } $feed_data = array(); @@ -2007,6 +1961,7 @@ public function GetCharacterFeed($full = false) { // Strings $feed_strings = $this->aDB->select("SELECT `id`, `string_".$this->_locale."` AS `string` FROM `armory_string` WHERE `id` IN (13, 14, 15, 16, 17, 18)"); if(!$feed_strings) { + $this->Log()->writeError('%s : unable to load strings from armory_string (current locale: %s; locId: %d)', __METHOD__, $this->_locale, $this->_loc); return false; } $_strings = array(); @@ -2189,10 +2144,12 @@ public function GetCharacterFeed($full = false) { **/ public function GetCharacterItemInfo($slot) { if(!$this->guid) { + $this->Log()->writeError('%s : player guid not provided', __METHOD__); return false; } $item_id = $this->getCharacterEquip($slot['slot']); if(!$item_id) { + $this->Log()->writeError('%s : unable to get item_id for player %d (%s); slotid is %s', __METHOD__, $this->guid, $this->name, $slot['slot']); return false; } $durability = Items::getItemDurability($this->guid, $item_id); @@ -2250,6 +2207,7 @@ public function ModifyMoney($amount, $type) { public function LookupActiveLots() { if(!$this->guid || !isset($_SESSION['accountId'])) { + $this->Log()->writeError('%s : player guid not defined or unable to find active session', __METHOD__); return false; } return AuctionHouseHandler::LookupActiveLotsByGUID($this->guid); @@ -2257,8 +2215,10 @@ public function LookupActiveLots() { public function CreateAuction(&$data) { if(!$this->guid || !isset($_SESSION['accountId'])) { + $this->Log()->writeError('%s : player guid not defined or unable to find active session', __METHOD__); return false; } + $this->Log()->writeLog('%s : Add auction (guid: %d, faction: %d, houseId: %d, item: %d, seed: %d, count: %d, price1: %d, price2: %d)', __METHOD__, $this->guid, $this->faction, $data['house_id'], $data['item_id'], $data['item_guid'], $data['count'], $data['price1'], $data['price2']); return AuctionHouseHandler::CreateAuction($this->guid, $this->faction, $data['house_id'], $data['item_id'], $data['item_guid'], $data['count'], $data['price1'], $data['price2']); } } diff --git a/includes/classes/class.connector.php b/includes/classes/class.connector.php index 7cc246a2c..18b115044 100644 --- a/includes/classes/class.connector.php +++ b/includes/classes/class.connector.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 200 + * @revision 208 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -57,10 +57,13 @@ public $connectionData; public $currentRealmInfo; + /** Debug handler **/ + private $debugHandler; + /** - * Initialize database & template handlers, sets up sql/site configs + * Initialize database handlers, debug handler, sets up sql/site configs * @category Main system functions - * @example Connector::__construct() + * @example Connector::Connector() * @return bool **/ public function Connector() { @@ -69,9 +72,13 @@ public function Connector() { } if(!@require_once('libs/DbSimple/Generic.php')) { die('Error: unable to load database class!'); - } + } + if(!@require_once('class.debug.php')) { + die('Error: unable to load debug class!'); + } $this->mysqlconfig = $ArmoryConfig['mysql']; $this->armoryconfig = $ArmoryConfig['settings']; + $this->debugHandler = new ArmoryDebug(array('useDebug' => $this->armoryconfig['useDebug'], 'logLevel' => $this->armoryconfig['logLevel'])); $this->realmData = $ArmoryConfig['multiRealm']; $this->aDB = DbSimple_Generic::connect('mysql://'.$this->mysqlconfig['user_armory'].':'.$this->mysqlconfig['pass_armory'].'@'.$this->mysqlconfig['host_armory'].'/'.$this->mysqlconfig['name_armory']); $this->aDB->query("SET NAMES ?", $this->mysqlconfig['charset_armory']); @@ -163,6 +170,12 @@ public function Connector() { } } + /** + * Checks browser language from HTTP_ACCEPT_LANGUAGE + * @category Main system functions + * @example Connector::IsAllowedLocale('ru'); + * @return mixed + **/ private function IsAllowedLocale($locale) { switch($locale) { case 'de': @@ -185,5 +198,12 @@ private function IsAllowedLocale($locale) { break; } } + + /** + * Returns debug log handler + **/ + public function Log() { + return $this->debugHandler; + } } ?> \ No newline at end of file diff --git a/includes/classes/class.debug.php b/includes/classes/class.debug.php new file mode 100644 index 000000000..3e4d9eb22 --- /dev/null +++ b/includes/classes/class.debug.php @@ -0,0 +1,91 @@ +config = $config; + if($file) { + $this->file = $file; + } + } + + public function writeLog($logtext) { + if($this->config['useDebug'] == false || $this->config['logLevel'] == 1) { + return; + } + $args = func_get_args(); + $debug_log = self::AddStyle('debug'); + $debug_log .= call_user_func_array('sprintf', $args); + $debug_log .= '
+'; + self::__writeFile($debug_log); + return; + } + + public function writeError($errorText) { + if($this->config['useDebug'] == false) { + return; + } + $args = func_get_args(); + $error_log = self::AddStyle('error'); + $error_log .= call_user_func_array('sprintf', $args); + $error_log .= '
+'; + self::__writeFile($error_log); + return; + } + + private function AddStyle($type) { + if($this->config['useDebug'] == false) { + return; + } + switch($type) { + case 'debug': + $log = sprintf('DEBUG [%s]: ', date('d-m-Y H:i:s')); + break; + case 'error': + $log = sprintf('ERROR [%s]: ', date('d-m-Y H:i:s')); + break; + } + return $log; + } + + private function __writeFile($data) { + file_put_contents($this->file, $data, FILE_APPEND); + } +} +?> \ No newline at end of file diff --git a/includes/classes/configuration.php.default b/includes/classes/configuration.php.default index b02d351c6..97df99a8c 100644 --- a/includes/classes/configuration.php.default +++ b/includes/classes/configuration.php.default @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 200 + * @revision 208 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -70,6 +70,8 @@ $ArmoryConfig['settings']['minGmLevelToShow'] = 3; // Show characters : 0 - onl $ArmoryConfig['settings']['defaultLocale'] = 'ru_ru'; // Can be 'ru_ru' or 'en_gb' $ArmoryConfig['settings']['showScriptInfo'] = true; // Display script info (generation time, etc.) ? (true/false) (not used now) $ArmoryConfig['settings']['maintenance'] = false; // Disable site? (true/false) +$ArmoryConfig['settings']['useDebug'] = false; // Use debug? (true/false). STRONGLY not recommended on live server! +$ArmoryConfig['settings']['logLevel'] = 1; // 1 - only errors, 2 - debug mode /* Multirealms info