From d0f64fe66c0fb382fa35028060c856881e09f0b0 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Fri, 20 Jan 2017 18:10:31 +0100 Subject: [PATCH] Home/Featuredbox * allow defining a time span during which the box should be displayed * added fields optional fields to point to diffenret header and home logos for the duration --- includes/shared.php | 2 +- includes/utilities.php | 38 ++++++++++++++++++++++++--------- pages/genericPage.class.php | 24 ++++++++------------- pages/home.php | 28 ++++++++++++------------ setup/db_structure.sql | 9 +++++--- setup/updates/1484926142_01.sql | 8 +++++++ template/bricks/header.tpl.php | 8 +++++++ template/pages/home.tpl.php | 22 +++++++++++++------ 8 files changed, 89 insertions(+), 50 deletions(-) create mode 100644 setup/updates/1484926142_01.sql diff --git a/includes/shared.php b/includes/shared.php index b07e7466..ab5b1cec 100644 --- a/includes/shared.php +++ b/includes/shared.php @@ -1,6 +1,6 @@ '\\\\', - "'" => "\\'", - '"' => '\\"', - "\r" => '\\r', - "\n" => '\\n' - )); + + return strtr(trim($data), array( + '\\' => '\\\\', + "'" => "\\'", + '"' => '\\"', + "\r" => '\\r', + "\n" => '\\n' + )); + } + + public static function defStatic($data) + { + if (is_array($data)) + { + foreach ($data as &$v) + $v = self::defStatic($v); + + return $data; + } + + return strtr($data, array( + ' '' => 'scr"+"ipt>', + 'HOST_URL' => HOST_URL, + 'STATIC_URL' => STATIC_URL + )); } // default back to enUS if localization unavailable diff --git a/pages/genericPage.class.php b/pages/genericPage.class.php index 8b312f84..373f7e13 100644 --- a/pages/genericPage.class.php +++ b/pages/genericPage.class.php @@ -103,6 +103,8 @@ class GenericPage private $memcached = null; private $mysql = ['time' => 0, 'count' => 0]; + private $headerLogo = ''; + private $lvTemplates = array( 'achievement' => ['template' => 'achievement', 'id' => 'achievements', 'parent' => 'lv-generic', 'data' => [], 'name' => '$LANG.tab_achievements' ], 'calendar' => ['template' => 'holidaycal', 'id' => 'calendar', 'parent' => 'lv-generic', 'data' => [], 'name' => '$LANG.tab_calendar' ], @@ -158,6 +160,10 @@ class GenericPage $this->mode = CACHE_TYPE_XML; else { + // get alt header logo + if ($ahl = DB::Aowow()->selectCell('SELECT altHeaderLogo FROM ?_home_featuredbox WHERE ?d BETWEEN startDate AND endDate ORDER BY id DESC', time())) + $this->headerLogo = Util::defStatic($ahl); + $this->gUser = User::getUserGlobals(); $this->pageTemplate['pageName'] = strtolower($pageCall); @@ -325,15 +331,8 @@ class GenericPage foreach ($article as $text) (new Markup($text))->parseGlobalsFromText($this->jsgBuffer); - $replace = array( - ' '' => 'scr"+"ipt>', - 'HOST_URL' => HOST_URL, - 'STATIC_URL' => STATIC_URL - ); - $this->article = array( - 'text' => strtr($article['article'], $replace), + 'text' => Util::defStatic($article['article']), 'params' => [] ); @@ -374,22 +373,17 @@ class GenericPage { if ($t = Util::localizedString($v, 'text')) { - $replace = array( - 'HOST_URL' => HOST_URL, - 'STATIC_URL' => STATIC_URL - ); - $_ = array( 'parent' => 'announcement-'.$k, 'id' => $v['id'], 'mode' => $v['mode'], 'status' => $v['status'], 'name' => $v['name'], - 'text' => strtr($t, $replace) + 'text' => Util::defStatic($t) ); if ($v['style']) // may be empty - $_['style'] = strtr($v['style'], $replace); + $_['style'] = Util::defStatic($v['style']); $this->announcements[$k] = $_; } diff --git a/pages/home.php b/pages/home.php index f954641a..47feffb4 100644 --- a/pages/home.php +++ b/pages/home.php @@ -10,8 +10,8 @@ class HomePage extends GenericPage protected $js = ['home.js']; protected $css = [['path' => 'home.css']]; - protected $news = []; - protected $oneliner = ''; + protected $featuredBox = []; + protected $oneliner = ''; public function __construct() { @@ -26,27 +26,27 @@ class HomePage extends GenericPage if ($_ = DB::Aowow()->selectRow('SELECT * FROM ?_home_oneliner WHERE active = 1 LIMIT 1')) $this->oneliner = Util::jsEscape(Util::localizedString($_, 'text')); - // load news - $this->news = DB::Aowow()->selectRow('SELECT id as ARRAY_KEY, n.* FROM ?_home_featuredbox n WHERE active = 1 ORDER BY id DESC LIMIT 1'); - if (!$this->news) + // load featuredBox (user web server time) + $this->featuredBox = DB::Aowow()->selectRow('SELECT id as ARRAY_KEY, n.* FROM ?_home_featuredbox n WHERE ?d BETWEEN startDate AND endDate ORDER BY id DESC LIMIT 1', time()); + if (!$this->featuredBox) return; - $this->news['text'] = Util::localizedString($this->news, 'text', true); + $this->featuredBox = Util::defStatic($this->featuredBox); - if ($_ = (new Markup($this->news['text']))->parseGlobalsFromText()) + $this->featuredBox['text'] = Util::localizedString($this->featuredBox, 'text', true); + + if ($_ = (new Markup($this->featuredBox['text']))->parseGlobalsFromText()) $this->extendGlobalData($_); - if (empty($this->news['bgImgUrl'])) - $this->news['bgImgUrl'] = STATIC_URL.'/images/'.User::$localeString.'/mainpage-bg-news.jpg'; - else - $this->news['bgImgUrl'] = strtr($this->news['bgImgUrl'], ['HOST_URL' => HOST_URL, 'STATIC_URL' => STATIC_URL]); + if (empty($this->featuredBox['boxBG'])) + $this->featuredBox['boxBG'] = STATIC_URL.'/images/'.User::$localeString.'/mainpage-bg-news.jpg'; // load overlay links - $this->news['overlays'] = DB::Aowow()->select('SELECT * FROM ?_home_featuredbox_overlay WHERE featureId = ?d', $this->news['id']); - foreach ($this->news['overlays'] as &$o) + $this->featuredBox['overlays'] = DB::Aowow()->select('SELECT * FROM ?_home_featuredbox_overlay WHERE featureId = ?d', $this->featuredBox['id']); + foreach ($this->featuredBox['overlays'] as &$o) { $o['title'] = Util::localizedString($o, 'title', true); - $o['title'] = strtr($o['title'], ['HOST_URL' => HOST_URL, 'STATIC_URL' => STATIC_URL]); + $o['title'] = Util::defStatic($o['title']); } } diff --git a/setup/db_structure.sql b/setup/db_structure.sql index 79ff95c8..b61d5f8b 100644 --- a/setup/db_structure.sql +++ b/setup/db_structure.sql @@ -758,9 +758,12 @@ CREATE TABLE `aowow_home_featuredbox` ( `id` smallint(5) unsigned NOT NULL, `editorId` int(10) unsigned DEFAULT NULL, `editDate` int(10) unsigned NOT NULL, - `active` tinyint(1) unsigned NOT NULL, + `startDate` int(10) unsigned NOT NULL DEFAULT '0', + `endDate` int(10) unsigned NOT NULL DEFAULT '0', `extraWide` tinyint(3) unsigned NOT NULL DEFAULT '0', - `bgImgUrl` varchar(150) NOT NULL DEFAULT '', + `boxBG` varchar(150) NULL DEFAULT NULL, + `altHomeLogo` varchar(150) NULL DEFAULT NULL, + `altHeaderLogo` varchar(150) NULL DEFAULT NULL, `text_loc0` text NOT NULL, `text_loc2` text NOT NULL, `text_loc3` text NOT NULL, @@ -2520,7 +2523,7 @@ UNLOCK TABLES; LOCK TABLES `aowow_home_featuredbox` WRITE; /*!40000 ALTER TABLE `aowow_home_featuredbox` DISABLE KEYS */; -INSERT INTO `aowow_home_featuredbox` VALUES (1,NULL,0,1,0,'','[pad]Welcome to [b][span class=q5]AoWoW[/span][/b]!','[pad]Bienvenue à [b][span class=q5]AoWoW[/span][/b]!','[pad]Willkommen bei [b][span class=q5]AoWoW[/span][/b]!','','Добро[pad] пожаловать на [b][span class=q5]AoWoW[/span][/b]!'),(2,NULL,0,0,1,'STATIC_URL/images/logos/newsbox-explained.png','[ul]\n[li][i]just demoing the newsbox here..[/i][/li]\n[li][b][url=http://www.example.com]..with urls[/url][/b][/li]\n[li][b]..typeLinks [item=45533][/b][/li]\n[li][b]..also, over there to the right is an overlay-trigger =>[/b][/li]\n[/ul]\n\n[ul]\n[li][tooltip name=demotip]hey, it hints you stuff![/tooltip][b][span class=tip tooltip=demotip]..hover me[/span][/b][/li]\n[/ul]','','','',''); +INSERT INTO `aowow_home_featuredbox` VALUES (1,NULL,0,0,0,0,'',NULL,NULL,'[pad]Welcome to [b][span class=q5]AoWoW[/span][/b]!','[pad]Bienvenue à [b][span class=q5]AoWoW[/span][/b]!','[pad]Willkommen bei [b][span class=q5]AoWoW[/span][/b]!','','Добро[pad] пожаловать на [b][span class=q5]AoWoW[/span][/b]!'),(2,NULL,0,0,0,1,'STATIC_URL/images/logos/newsbox-explained.png',NULL,NULL,'[ul]\n[li][i]just demoing the newsbox here..[/i][/li]\n[li][b][url=http://www.example.com]..with urls[/url][/b][/li]\n[li][b]..typeLinks [item=45533][/b][/li]\n[li][b]..also, over there to the right is an overlay-trigger =>[/b][/li]\n[/ul]\n\n[ul]\n[li][tooltip name=demotip]hey, it hints you stuff![/tooltip][b][span class=tip tooltip=demotip]..hover me[/span][/b][/li]\n[/ul]','','','',''); /*!40000 ALTER TABLE `aowow_home_featuredbox` ENABLE KEYS */; UNLOCK TABLES; diff --git a/setup/updates/1484926142_01.sql b/setup/updates/1484926142_01.sql new file mode 100644 index 00000000..5f34728c --- /dev/null +++ b/setup/updates/1484926142_01.sql @@ -0,0 +1,8 @@ +ALTER TABLE `aowow_home_featuredbox` + CHANGE COLUMN `active` `startDate` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `editDate`, + ADD COLUMN `endDate` INT(10) UNSIGNED NOT NULL DEFAULT '0' AFTER `startDate`; + +ALTER TABLE `aowow_home_featuredbox` + CHANGE COLUMN `bgImgUrl` `boxBG` VARCHAR(150) NULL DEFAULT NULL AFTER `extraWide`, + ADD COLUMN `altHomeLogo` VARCHAR(150) NULL DEFAULT NULL AFTER `boxBG`, + ADD COLUMN `altHeaderLogo` VARCHAR(150) NULL DEFAULT NULL AFTER `altHomeLogo`; diff --git a/template/bricks/header.tpl.php b/template/bricks/header.tpl.php index 4c5d34ee..1c91a72e 100644 --- a/template/bricks/header.tpl.php +++ b/template/bricks/header.tpl.php @@ -6,6 +6,14 @@