コード例 #1
0
 private static function HandleFeed()
 {
     if (!self::IsFeedsLoaded()) {
         if (!self::LoadFeed()) {
             WoW_Log::WriteError('%s : unable to handle feeds without any data.', __METHOD__);
             return false;
         }
     }
     $feeds_data = array();
     $periods = array(WoW_Locale::GetString('template_feed_sec'), WoW_Locale::GetString('template_feed_min'), WoW_Locale::GetString('template_feed_hour'));
     $today = date('d.m.Y');
     $lengths = array(60, 60, 24);
     $feed_count = 0;
     foreach (self::$feed_data as $event) {
         if ($feed_count >= 50) {
             break;
         }
         $date_string = date('d.m.Y', $event['date']);
         if ($date_string == $today) {
             $diff = time() - $event['date'];
             for ($i = 0; $diff >= $lengths[$i]; $i++) {
                 $diff /= $lengths[$i];
             }
             $diff = round($diff);
             $date_string = sprintf('%s %s %s', $diff, $periods[$i], WoW_Locale::GetString('template_feed_ago'));
         }
         $feed = array();
         switch ($event['type']) {
             case TYPE_ACHIEVEMENT_FEED:
                 $achievement = WoW_Achievements::GetAchievementInfo($event['data']);
                 if (!$achievement) {
                     WoW_Log::WriteLog('%s : wrong feed data (TYPE_ACHIEVEMENT_FEED, achievement ID: %d), ignore.', __METHOD__, $event['data']);
                     continue;
                 }
                 $feed = array('type' => TYPE_ACHIEVEMENT_FEED, 'date' => $date_string, 'id' => $event['data'], 'points' => $achievement['points'], 'name' => $achievement['name'], 'desc' => $achievement['desc'], 'icon' => $achievement['iconname'], 'category' => $achievement['categoryId']);
                 break;
             case TYPE_ITEM_FEED:
                 $item = WoW_Items::GetItemInfo($event['data']);
                 if (!$item) {
                     WoW_Log::WriteLog('%s : wrong feed data (TYPE_ITEM_FEED, item ID: %d), ignore.', __METHOD__, $event['data']);
                     continue;
                 }
                 $item_icon = WoW_Items::GetItemIcon($item['entry'], $item['displayid']);
                 $data_item = null;
                 $slot = self::IsItemEquipped($item['entry']);
                 if ($slot > 0) {
                     $equipped_info = self::GetEquippedItemInfo($slot);
                     if ($equipped_info) {
                         $data_item = $equipped_info['data-item'];
                     }
                 }
                 $feed = array('type' => TYPE_ITEM_FEED, 'date' => $date_string, 'id' => $event['data'], 'name' => WoW_Locale::GetLocale() == 'en' ? $item['name'] : WoW_Items::GetItemName($item['entry']), 'data-item' => $data_item, 'quality' => $item['Quality'], 'icon' => $item_icon);
                 break;
             case TYPE_BOSS_FEED:
                 $difficultyEntry = 0;
                 $achievement_ids = array();
                 if ($event['difficulty'] <= 0) {
                     $difficultyEntry = $event['data'];
                 } else {
                     // Search for difficulty_entry_X
                     $difficultyEntry = DB::World()->selectCell("SELECT `entry` FROM `creature_template` WHERE `difficulty_entry_%d` = %d", $event['difficulty'], $event['data']);
                     if (!$difficultyEntry || $difficultyEntry == 0) {
                         $difficultyEntry = $event['data'];
                     }
                 }
                 $criterias = DB::WoW()->select("SELECT `referredAchievement` FROM `DBPREFIX_achievement_criteria` WHERE `data` = %d", $difficultyEntry);
                 if (!$criterias) {
                     continue;
                 }
                 foreach ($criterias as $criteria) {
                     $achievement_ids[] = $criteria['referredAchievement'];
                 }
                 if (!$achievement_ids) {
                     continue;
                 }
                 $achievement = DB::WoW()->selectRow("SELECT `id`, `name_%s` AS `name` FROM `DBPREFIX_achievement` WHERE `id` IN (%s) AND `flags` = 1 AND `dungeonDifficulty` = %d", WoW_Locale::GetLocale(), $achievement_ids, $event['difficulty']);
                 if (!$achievement) {
                     continue;
                 }
                 $feed = array('type' => TYPE_BOSS_FEED, 'date' => $date_string, 'id' => $event['data'], 'name' => $achievement['name'], 'count' => $event['counter']);
                 break;
             default:
                 WoW_Log::WriteError('%s : unknown feed type (%d)!', __METHOD__, $event['type']);
                 continue;
                 break;
         }
         $feeds_data[] = $feed;
         $feed_count++;
     }
     self::$feeds = $feeds_data;
     return true;
 }