From 7c482e9319039fc74e0635c34185a1576dc0dae8 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Mon, 11 Mar 2013 00:13:32 +0100 Subject: [PATCH] WorldEvents: initial implementation - hm. should i move the (SERVERSIDE) to db to be searchable? - detail-page is nyi - some static data should be moved to install scripts and some point .. e.g. when install scripts come to existance - calendar is commented in pages/events.php as it's not really working yet --- includes/class.worldevent.php | 218 +++++++++++++++++++++++++- includes/utilities.php | 22 ++- localization/locale_dede.php | 7 +- localization/locale_enus.php | 5 +- localization/locale_eses.php | 41 +++-- localization/locale_frfr.php | 3 + localization/locale_ruru.php | 5 +- pages/events.php | 64 ++++++++ search.php | 44 ++++-- template/bricks/allholidays_table.tpl | 9 ++ template/bricks/calendar_table.tpl | 32 ++++ template/bricks/event_table.tpl | 32 ++++ template/events.tpl | 29 ++++ template/header.tpl | 1 + 14 files changed, 474 insertions(+), 38 deletions(-) create mode 100644 pages/events.php create mode 100644 template/bricks/allholidays_table.tpl create mode 100644 template/bricks/calendar_table.tpl create mode 100644 template/bricks/event_table.tpl create mode 100644 template/events.tpl diff --git a/includes/class.worldevent.php b/includes/class.worldevent.php index 6c9b088a..5bed8f48 100644 --- a/includes/class.worldevent.php +++ b/includes/class.worldevent.php @@ -3,16 +3,228 @@ if (!defined('AOWOW_REVISION')) die('illegal access'); -class WorldEvent extends BaseType +class WorldEventList extends BaseType { + private static $holidayIcons = [ + 141 => 'calendar_winterveilstart', + 327 => 'calendar_lunarfestivalstart', + 335 => 'calendar_loveintheairstart', + 423 => 'calendar_loveintheairstart', + 181 => 'calendar_noblegardenstart', + 201 => 'calendar_childrensweekstart', + 341 => 'calendar_midsummerstart', + 62 => 'inv_misc_missilelarge_red', + 321 => 'calendar_harvestfestivalstart', + 398 => 'calendar_piratesdaystart', + 372 => 'calendar_brewfeststart', + 324 => 'calendar_hallowsendstart', + 409 => 'calendar_dayofthedeadstart', + 404 => 'calendar_harvestfestivalstart', + 283 => 'inv_jewelry_necklace_21', + 284 => 'inv_misc_rune_07', + 400 => 'achievement_bg_winsoa', + 420 => 'achievement_bg_winwsg', + 285 => 'inv_jewelry_amulet_07', + 353 => 'spell_nature_eyeofthestorm', + 301 => 'calendar_fishingextravaganzastart', + 424 => 'calendar_fishingextravaganzastart', + 374 => 'calendar_darkmoonfaireelwynnstart', + 375 => 'calendar_darkmoonfairemulgorestart', + 376 => 'calendar_darkmoonfaireterokkarstart' + ]; + + protected $setupQuery = 'SELECT *, -e.id AS ARRAY_KEY, -e.id as id FROM ?_events e LEFT JOIN ?_holidays h ON e.holidayId = h.id WHERE [cond] ORDER BY -e.id ASC'; + protected $matchQuery = 'SELECT COUNT(1) FROM ?_events e LEFT JOIN ?_holidays h ON e.holidayId = h.id WHERE [cond]'; + + public function __construct($data) + { + parent::__construct($data); + + // unseting elements while we iterate over the array will cause the pointer to reset + $replace = []; + + // post processing + while ($this->iterate()) + { + // emulate category + $sT = $this->curTpl['scheduleType']; + if (!$this->curTpl['holidayId']) + $this->curTpl['category'] = 0; + else if ($sT == 2) + $this->curTpl['category'] = 3; + else if (in_array($sT, [0, 1])) + $this->curTpl['category'] = 2; + else if ($sT == -1) + $this->curTpl['category'] = 1; + + // change Ids if holiday is set + if ($this->curTpl['holidayId'] > 0) + { + // template + $this->curTpl['id'] = $this->curTpl['holidayId']; + unset($this->curTpl['description']); + $replace[$this->id] = $this->curTpl; + + // names + unset($this->names[$this->id]); + $this->names[$this->curTpl['id']] = Util::localizedString($this->curTpl, 'name'); + } + else // set a name if holiday is missing + { + // template + $this->curTpl['name_loc0'] = $this->curTpl['description']; + $this->curTpl['iconString'] = 'INV_Misc_QuestionMark'; + $replace[$this->id] = $this->curTpl; + + // names + $this->names[$this->id] = '(SERVERSIDE) '.$this->curTpl['description']; + } + } + + foreach ($replace as $old => $data) + { + unset($this->templates[$old]); + $this->templates[$data['id']] = $data; + } + $this->reset(); + } public static function getName($id) { - $row = DB::Aowow()->SelectRow('SELECT * FROM ?_holidays WHERE Id = ?d', intVal($id)); + if ($id > 0) + $row = DB::Aowow()->SelectRow('SELECT * FROM ?_holidays WHERE Id = ?d', intVal($id)); + else + $row = DB::Aowow()->SelectRow('SELECT description as name FROM ?_events WHERE Id = ?d', intVal(-$id)); return Util::localizedString($row, 'name'); } + + public static function updateDates($start, $end, $occurence, $final = 5000000000) // in the far far FAR future.. + { + // Convert everything to seconds + $start = intVal($start); + $end = intVal($end); + $occurence = intVal($occurence); + $final = intVal($final); + + $now = time(); + $year = date("Y", $now); + + $curStart = $start; + $curEnd = $end; + $nextStart = $curStart + $occurence; + $nextEnd = $curEnd + $occurence; + + while ($nextEnd <= $final && date("Y", $nextEnd) <= $year && $curEnd <= $now) + { + $curStart = $nextStart; + $curEnd = $nextEnd; + $nextStart = $curStart + $occurence; + $nextEnd = $curEnd + $occurence; + } + + return array( + 'start' => $curStart, + 'end' => $curEnd, + 'nextStart' => $nextStart, + 'nextEnd' => $nextEnd + ); + } + + public function getListviewData() + { + $data = []; + + while ($this->iterate()) + { + $data[$this->id] = array( + 'category' => $this->curTpl['category'], + 'id' => $this->id, + 'name' => $this->names[$this->id], + 'rec' => $this->curTpl['occurence'], + 'startDate' => $this->curTpl['startTime'], + 'endDate' => $this->curTpl['startTime'] + $this->curTpl['length'] + ); + } + + return $data; + } + + public function setup() + { + foreach (self::$holidayIcons as $id => $s) + DB::Aowow()->Query('UPDATE ?_holidays SET iconString = ?s WHERE id = ?', $s, $id); + } + + public function addGlobalsToJScript(&$refs) + { + if (!isset($refs['gHolidays'])) + $refs['gHolidays'] = []; + + while ($this->iterate()) + { + $refs['gHolidays'][$this->id] = array( + 'name' => $this->names[$this->id], + 'icon' => $this->curTpl['iconString'] + ); + } + } + + public function addRewardsToJScript(&$ref) { } + public function renderTooltip() { } } +/* -?> \ No newline at end of file +function event_name($events) +{ + global $DB; + if (!$events || !is_array($events) || count($events) == 0) + return array(); + + $entries = arraySelectKey($events, 'entry'); + + $rows = $DB->select(' + SELECT eventEntry AS entry, description AS name + FROM game_event + WHERE eventEntry IN (?a)', + $entries + ); + + // Merge original array with new information + $result = array(); + foreach ($events as $event) + if (isset($event['entry'])) + $result[$event['entry']] = $event; + + if ($rows) + { + foreach ($rows as $event) + $result[$event['entry']] = array_merge($result[$event['entry']], $event); + } + + return $result; +} + +function event_description($entry) +{ + global $DB; + + $result = event_infoline(array(array('entry' => $entry))); + if (is_array($result) && count($result) > 0) + $result = reset($result); + else + return NULL; + + $result['period'] = sec_to_time(intval($result['occurence'])*60); + + $result['npcs_guid'] = $DB->selectCol('SELECT guid FROM game_event_creature WHERE eventEntry=?d OR eventEntry=?d', $entry, -$entry); + $result['objects_guid'] = $DB->selectCol('SELECT guid FROM game_event_gameobject WHERE eventEntry=?d OR eventEntry=?d', $entry, -$entry); + $result['creatures_quests_id'] = $DB->select('SELECT id AS creature, quest FROM game_event_creature_quest WHERE eventEntry=?d OR eventEntry=?d GROUP BY quest', $entry, -$entry); + + return $result; +} + +*/ + +?> diff --git a/includes/utilities.php b/includes/utilities.php index 19e81d51..f769f4f9 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -162,6 +162,22 @@ abstract class BaseType return $this->curTpl[$field]; } + public function filterGetJs() + { + if ($this->filter && isset($this->filter->fiData['c']['cr'])) + return "fi_setCriteria([".@implode(',',$this->filter->fiData['c']['cr'])."], [".@implode(',',$this->filter->fiData['c']['crs'])."], ['".@implode('\', \'',$this->filter->fiData['c']['crv'])."']);"; + else + return null; + } + + public function filterGetForm() + { + if ($this->filter) + return $this->filter->form; + else + return []; + } + // should return data required to display a listview of any kind // this is a rudimentary example, that will not suffice for most Types abstract public function getListviewData(); @@ -188,12 +204,13 @@ class Lang public static $account; public static $achievement; public static $compare; + public static $event; public static $item; public static $maps; public static $spell; public static $talent; - public static $zone; public static $title; + public static $zone; public static function load($loc) { @@ -417,6 +434,9 @@ class Util 'clothChestArmor', 'leatherChestArmor', 'mailChestArmor', 'plateChestArmor' ); + public static $dateFormatShort = "Y/m/d"; + public static $dateFormatLong = "Y/m/d H:i:s"; + public static $changeLevelString = '%s'; public static $filterResultString = 'sprintf(%s, %s, %s) + LANG.dash + LANG.lvnote_tryfiltering.replace(\'\', \'\')'; diff --git a/localization/locale_dede.php b/localization/locale_dede.php index 15f3baf6..790421d1 100644 --- a/localization/locale_dede.php +++ b/localization/locale_dede.php @@ -127,7 +127,7 @@ $lang = array( 'eventShort' => "Ereignis", 'event' => "Weltereigniss", 'events' => "Weltereignisse", - 'cooldown' => "%s Cooldown", + 'cooldown' => "%s Abklingzeit", 'requires' => "Benötigt", 'reqLevel' => "Benötigt Stufe %s", 'reqLevelHlm' => "Benötigt Stufe %s", @@ -206,7 +206,7 @@ $lang = array( 'myAccount' => "Mein Account", 'editAccount' => "Benutze die folgenden Formulare um deine Account-Informationen zu aktualisieren", 'publicDesc' => "Öffentliche Beschreibung", - 'viewPublicDesc' => "Die Beschreibung in deinem öffetnlichen Profil ansehen", + 'viewPubDesc' => "Die Beschreibung in deinem öffentlichen Profil ansehen", // Please_enter_your_confirm_password = Bitte das Passwort bestätigen @@ -214,6 +214,9 @@ $lang = array( // Please_enter_your_password = Gib bitte dein Kennwort ein // Remember_me_on_this_computer = Auf diesem Computer merken ), + 'event' => array( + 'category' => array("Nicht kategorisiert", "Feiertage", "Wiederkehrend", "Spieler vs. Spieler") + ), 'achievement' => array( 'achievements' => "Erfolge", 'criteria' => "Kriterien", diff --git a/localization/locale_enus.php b/localization/locale_enus.php index 9f603ff7..e46f07ce 100644 --- a/localization/locale_enus.php +++ b/localization/locale_enus.php @@ -208,7 +208,7 @@ $lang = array( 'myAccount' => "My Account", 'editAccount' => "Simply use the forms below to update your account information", 'publicDesc' => "Public Description", - 'viewPublicDesc' => "View your Public Description in your Profile Page", + 'viewPubDesc' => "View your Public Description in your Profile Page", // Please_enter_your_username = Enter your username (account) @@ -216,6 +216,9 @@ $lang = array( // Sign_in_to_your_Game_Account = Enter your game account: // Please_enter_your_confirm_password = Please enter your confirm password ), + 'event' => array( + 'category' => array("Uncategorized", "Holidays", "Recurring", "Player vs. Player") + ), 'achievement' => array( 'achievements' => "achievements", 'criteria' => "Criteria", diff --git a/localization/locale_eses.php b/localization/locale_eses.php index 9e923a79..db4dd456 100644 --- a/localization/locale_eses.php +++ b/localization/locale_eses.php @@ -68,7 +68,6 @@ $lang = array( 'eventShort' => "Evento", 'event' => "Suceso mundial ", 'events' => "Eventos del mundo", - 'cooldown' => "%s cooldown", 'cooldown' => "%s de reutilización", 'requires' => "Requiere", 'reqLevel' => "Necesitas ser de nivel %s", @@ -109,8 +108,31 @@ $lang = array( 'resetForm' => "Reiniciar formulario", 'refineSearch' => "Sugerencia: Refina tu búsqueda llendo a una subcategoría.", ), - 'error' => [], + 'error' => array( + 'errNotFound' => "Page not found", + 'errPage' => "What? How did you... nevermind that!\n
\n
\nIt appears that the page you have requested cannot be found. At least, not in this dimension.\n
\n
\nPerhaps a few tweaks to the [WH-799 Major Confabulation Engine] may result in the page suddenly making an appearance!\n
\n
\nOr, you can try \ncontacting us\n- the stability of the WH-799 is debatable, and we wouldn't want another accident...", + 'goStart' => "Return to the homepage", + 'goForum' => "Feedback forum", + ), 'account' => [], + 'event' => array( + 'category' => array("Sin categoría", "Vacacionales", "Periódicos", "Jugador contra Jugador") + ), + 'achievement' => array( + 'achievements' => "logros", + 'criteria' => "Requisitos", + 'achievement' => "logro", + 'points' => "Puntos", + 'series' => "Serie", + 'outOf' => "de", + 'criteriaType' => "Criterium Type-Id:", + 'itemReward' => "Recibirás:", + 'titleReward' => "Deberías obtener el título \"%s\"", + 'slain' => "matado", + ), + 'compare' => array( + 'compare' => "Herramienta de comparación de objetos", + ), 'talent' => array( 'talentCalc' => "Calculadora de talentos", 'petCalc' => "Calculadora de mascotas", @@ -134,21 +156,6 @@ $lang = array( 'Azeroth' => "Azeroth", 'CosmicMap' => "Mapa cósmico", ), - 'achievement' => array( - 'achievements' => "logros", - 'criteria' => "Requisitos", - 'achievement' => "logro", - 'points' => "Puntos", - 'series' => "Serie", - 'outOf' => "de", - 'criteriaType' => "Criterium Type-Id:", - 'itemReward' => "Recibirás:", - 'titleReward' => "Deberías obtener el título \"%s\"", - 'slain' => "matado", - ), - 'compare' => array( - 'compare' => "Herramienta de comparación de objetos", - ), 'zone' => array( 'zone' => "Zone", 'zonePartOf' => "Cette zone fait partie de la zone", diff --git a/localization/locale_frfr.php b/localization/locale_frfr.php index fd3e7b57..755199b5 100644 --- a/localization/locale_frfr.php +++ b/localization/locale_frfr.php @@ -115,6 +115,9 @@ $lang = array( 'goForum' => "Feedback forum", ), 'account' => [], + 'event' => array( + 'category' => array("Non classés", "Vacances", "Récurrent", "Joueur ctr. Joueur") + ), 'achievement' => array( 'achievements' => "hauts faits", 'criteria' => "Critères", diff --git a/localization/locale_ruru.php b/localization/locale_ruru.php index 7e988502..1fc25eda 100644 --- a/localization/locale_ruru.php +++ b/localization/locale_ruru.php @@ -44,8 +44,8 @@ $lang = array( 'minutesAbbr' => "мин", 'secondsAbbr' => "сек.", 'millisecsAbbr' => "[ms]", - 'name' => "Название", + 'disabled' => "[Disabled]", 'disabledHint' => "[Cannot be attained or completed]", 'serverside' => "[Serverside]", @@ -115,6 +115,9 @@ $lang = array( 'goForum' => "Feedback forum", ), 'account' => [], + 'event' => array( + 'category' => array("Разное", "Праздники", "Периодические", "PvP") + ), 'achievement' => array( 'achievements' => "достижения", 'criteria' => "Критерий", diff --git a/pages/events.php b/pages/events.php new file mode 100644 index 00000000..d458d5c0 --- /dev/null +++ b/pages/events.php @@ -0,0 +1,64 @@ +loadCache($cacheKeyPage, $pageData)) +{ + switch ($cat) + { + case 1: + $condition[] = ['h.scheduleType', -1]; + break; + case 2: + $condition[] = ['h.scheduleType', [0, 1]]; + break; + case 3: + $condition[] = ['h.scheduleType', 2]; + break; + } + + $events = new WorldEventList($condition); + + $pageData = array( + 'page' => $events->getListviewData(), + 'params' => array( + 'tabs' => '$myTabs' + ) + ); + + $events->addGlobalsToJScript($pageData); + + $smarty->saveCache($cacheKeyPage, $pageData); +} + +// recalculate dates with now(); can't be cached, obviously +foreach ($pageData['page'] as &$data) +{ + $updated = WorldEventList::updateDates($data['startDate'], $data['endDate'], $data['rec']); + $data['startDate'] = date(Util::$dateFormatLong, $updated['start']); + $data['endDate'] = date(Util::$dateFormatLong, $updated['end']); +} + +$page = array( + 'tab' => 0, // for g_initHeader($tab) + 'title' => ($cat ? Lang::$event['category'][$cat].' - ' : null) . Lang::$game['events'], + 'path' => json_encode($path, JSON_NUMERIC_CHECK), +); + + +$smarty->updatePageVars($page); +$smarty->assign('lang', Lang::$main); +$smarty->assign('mysql', DB::Aowow()->getStatistics()); +$smarty->assign('data', $pageData); +$smarty->display('events.tpl'); + +?> diff --git a/search.php b/search.php index eefa1406..0daf1c22 100644 --- a/search.php +++ b/search.php @@ -9,7 +9,7 @@ Util::execTime(true); if &json => search by compare or profiler else if &opensearch - => suche aus der suchbox oben rechts, bzw Startseite + => suggestions when typing into searchboxes array:[ str, // search str[10], // found @@ -189,21 +189,39 @@ if ($searchMask & 0x4) } // 4 World Events: -// if ($searchMask & 0x8) +if ($searchMask & 0x8) { - // /* custom data :( - // */ + /* custom data :( + icons: data/interface/calendar/calendar_[a-z]start.blp + */ - // $wEvents = new WorldEventList(array(['name_loc'.User::$localeId, $query])); + // limited by my own system.. >.< + // cant construct a query like: name = X OR (desc = X AND holidayId = 0) + $wEvents1 = new WorldEventList(array(['h.name_loc'.User::$localeId, $query])); + $wEvents2 = new WorldEventList(array(['e.description', $query], ['e.holidayId', 0], 'AND')); - // if (!empty($data)) - // { - // $found[] = array( - // 'type' => TYPE_WORLDEVENT, - // 'appendix' => ' (World Event)', - // 'data' => $data - // ); - // } + $data = $wEvents1->getListviewData(); + $data += $wEvents2->getListviewData(); + + if ($data) + { + $wEvents1->addGlobalsToJscript($jsGlobals); + $wEvents2->addGlobalsToJscript($jsGlobals); + + foreach ($data as &$d) + { + $updated = WorldEventList::updateDates($d['startDate'], $d['endDate'], $d['rec']); + $d['startDate'] = date(Util::$dateFormatLong, $updated['start']); + $d['endDate'] = date(Util::$dateFormatLong, $updated['end']); + } + + $found['event'] = array( + 'type' => TYPE_WORLDEVENT, + 'appendix' => ' (World Event)', + 'data' => $data, + 'params' => ['tabs' => '$myTabs'] + ); + } } // 5 Currencies diff --git a/template/bricks/allholidays_table.tpl b/template/bricks/allholidays_table.tpl new file mode 100644 index 00000000..649254ef --- /dev/null +++ b/template/bricks/allholidays_table.tpl @@ -0,0 +1,9 @@ +var _ = g_holidays; +{strip} +{foreach from=$data key=id item=item} + _[{$id}]={ldelim} + name_{$user.language}:'{$item.name|escape:"javascript"}', + icon:'{$item.icon|escape:"javascript"}' + {rdelim}; +{/foreach} +{/strip} diff --git a/template/bricks/calendar_table.tpl b/template/bricks/calendar_table.tpl new file mode 100644 index 00000000..dbf0fbf8 --- /dev/null +++ b/template/bricks/calendar_table.tpl @@ -0,0 +1,32 @@ +{strip} + new Listview({ldelim} + template:'holidaycal', + {if !isset($params.id)}id:'calendar',{/if} + {if !isset($params.tabs)}tabs:tabsRelated,{/if} + {if !isset($params.name)}name:LANG.tab_calendar,{/if} + {if !isset($params.parent)}parent:'listview-generic',{/if} + {if isset($params.note)}_truncated: 1,{/if} + {foreach from=$params key=k item=v} + {if $v[0] == '$'} + {$k}:{$v|substr:1}, + {else if $v} + {$k}:'{$v}', + {/if} + {/foreach} + data:[ + {foreach name=i from=$data item=curr} + {ldelim} + {if $curr.rec} + rec:{$curr.rec}, + {/if} + category:{$curr.category}, + id:{$curr.id}, + name:'{$curr.name|escape:"javascript"}', + startDate:'{$curr.startDate}', + endDate:'{$curr.endDate}' + {rdelim} + {if $smarty.foreach.i.last}{else},{/if} + {/foreach} + ] + {rdelim}); +{/strip} \ No newline at end of file diff --git a/template/bricks/event_table.tpl b/template/bricks/event_table.tpl new file mode 100644 index 00000000..8c9a467d --- /dev/null +++ b/template/bricks/event_table.tpl @@ -0,0 +1,32 @@ +{strip} + new Listview({ldelim} + template:'holiday', + {if !isset($params.id)}id:'holidays',{/if} + {if !isset($params.tabs)}tabs:tabsRelated,{/if} + {if !isset($params.name)}name:LANG.tab_holidays,{/if} + {if !isset($params.parent)}parent:'listview-generic',{/if} + {if isset($params.note)}_truncated: 1,{/if} + {foreach from=$params key=k item=v} + {if $v[0] == '$'} + {$k}:{$v|substr:1}, + {else if $v} + {$k}:'{$v}', + {/if} + {/foreach} + data:[ + {foreach name=i from=$data item=curr} + {ldelim} + {if $curr.rec} + rec:{$curr.rec}, + {/if} + category:{$curr.category}, + id:{$curr.id}, + name:'{$curr.name|escape:"javascript"}', + startDate:'{$curr.startDate}', + endDate:'{$curr.endDate}' + {rdelim} + {if $smarty.foreach.i.last}{else},{/if} + {/foreach} + ] + {rdelim}); +{/strip} diff --git a/template/events.tpl b/template/events.tpl new file mode 100644 index 00000000..4c6d2c49 --- /dev/null +++ b/template/events.tpl @@ -0,0 +1,29 @@ +{include file='header.tpl'} + +
+
+
+{if !empty($announcements)} + {foreach from=$announcements item=item} + {include file='bricks/announcement.tpl' an=$item} + {/foreach} +{/if} + + +
+
+ + + +
+
+
+ +{include file='footer.tpl'} diff --git a/template/header.tpl b/template/header.tpl index 7d33030c..317c004c 100644 --- a/template/header.tpl +++ b/template/header.tpl @@ -34,6 +34,7 @@ {if isset($data.gAchievements)} { include file='bricks/allachievements_table.tpl' data=$data.gAchievements }{/if} {if isset($data.gClasses)} { include file='bricks/allclasses_table.tpl' data=$data.gClasses }{/if} {if isset($data.gCurrencies)} { include file='bricks/allcurrencies_table.tpl' data=$data.gCurrencies }{/if} + {if isset($data.gHolidays)} { include file='bricks/allholidays_table.tpl' data=$data.gHolidays }{/if} {if isset($data.gItems)} { include file='bricks/allitems_table.tpl' data=$data.gItems }{/if} {if isset($data.gRaces)} { include file='bricks/allraces_table.tpl' data=$data.gRaces }{/if} {if isset($data.gSpells)} { include file='bricks/allspells_table.tpl' data=$data.gSpells }{/if}