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
This commit is contained in:
Sarjuuk
2017-01-20 18:10:31 +01:00
parent 8fd52835a6
commit d0f64fe66c
8 changed files with 89 additions and 50 deletions

View File

@@ -1,6 +1,6 @@
<?php <?php
define('AOWOW_REVISION', 20); define('AOWOW_REVISION', 21);
define('CLI', PHP_SAPI === 'cli'); define('CLI', PHP_SAPI === 'cli');

View File

@@ -1014,8 +1014,8 @@ class Util
return $data; return $data;
} }
else
return htmlspecialchars(trim($data), ENT_QUOTES, 'utf-8'); return htmlspecialchars(trim($data), ENT_QUOTES, 'utf-8');
} }
public static function jsEscape($data) public static function jsEscape($data)
@@ -1027,14 +1027,32 @@ class Util
return $data; return $data;
} }
else
return strtr(trim($data), array( return strtr(trim($data), array(
'\\' => '\\\\', '\\' => '\\\\',
"'" => "\\'", "'" => "\\'",
'"' => '\\"', '"' => '\\"',
"\r" => '\\r', "\r" => '\\r',
"\n" => '\\n' "\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(
'<script' => '<scr"+"ipt',
'script>' => 'scr"+"ipt>',
'HOST_URL' => HOST_URL,
'STATIC_URL' => STATIC_URL
));
} }
// default back to enUS if localization unavailable // default back to enUS if localization unavailable

View File

@@ -103,6 +103,8 @@ class GenericPage
private $memcached = null; private $memcached = null;
private $mysql = ['time' => 0, 'count' => 0]; private $mysql = ['time' => 0, 'count' => 0];
private $headerLogo = '';
private $lvTemplates = array( private $lvTemplates = array(
'achievement' => ['template' => 'achievement', 'id' => 'achievements', 'parent' => 'lv-generic', 'data' => [], 'name' => '$LANG.tab_achievements' ], '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' ], 'calendar' => ['template' => 'holidaycal', 'id' => 'calendar', 'parent' => 'lv-generic', 'data' => [], 'name' => '$LANG.tab_calendar' ],
@@ -158,6 +160,10 @@ class GenericPage
$this->mode = CACHE_TYPE_XML; $this->mode = CACHE_TYPE_XML;
else 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->gUser = User::getUserGlobals();
$this->pageTemplate['pageName'] = strtolower($pageCall); $this->pageTemplate['pageName'] = strtolower($pageCall);
@@ -325,15 +331,8 @@ class GenericPage
foreach ($article as $text) foreach ($article as $text)
(new Markup($text))->parseGlobalsFromText($this->jsgBuffer); (new Markup($text))->parseGlobalsFromText($this->jsgBuffer);
$replace = array(
'<script' => '<scr"+"ipt',
'script>' => 'scr"+"ipt>',
'HOST_URL' => HOST_URL,
'STATIC_URL' => STATIC_URL
);
$this->article = array( $this->article = array(
'text' => strtr($article['article'], $replace), 'text' => Util::defStatic($article['article']),
'params' => [] 'params' => []
); );
@@ -374,22 +373,17 @@ class GenericPage
{ {
if ($t = Util::localizedString($v, 'text')) if ($t = Util::localizedString($v, 'text'))
{ {
$replace = array(
'HOST_URL' => HOST_URL,
'STATIC_URL' => STATIC_URL
);
$_ = array( $_ = array(
'parent' => 'announcement-'.$k, 'parent' => 'announcement-'.$k,
'id' => $v['id'], 'id' => $v['id'],
'mode' => $v['mode'], 'mode' => $v['mode'],
'status' => $v['status'], 'status' => $v['status'],
'name' => $v['name'], 'name' => $v['name'],
'text' => strtr($t, $replace) 'text' => Util::defStatic($t)
); );
if ($v['style']) // may be empty if ($v['style']) // may be empty
$_['style'] = strtr($v['style'], $replace); $_['style'] = Util::defStatic($v['style']);
$this->announcements[$k] = $_; $this->announcements[$k] = $_;
} }

View File

@@ -10,8 +10,8 @@ class HomePage extends GenericPage
protected $js = ['home.js']; protected $js = ['home.js'];
protected $css = [['path' => 'home.css']]; protected $css = [['path' => 'home.css']];
protected $news = []; protected $featuredBox = [];
protected $oneliner = ''; protected $oneliner = '';
public function __construct() public function __construct()
{ {
@@ -26,27 +26,27 @@ class HomePage extends GenericPage
if ($_ = DB::Aowow()->selectRow('SELECT * FROM ?_home_oneliner WHERE active = 1 LIMIT 1')) if ($_ = DB::Aowow()->selectRow('SELECT * FROM ?_home_oneliner WHERE active = 1 LIMIT 1'))
$this->oneliner = Util::jsEscape(Util::localizedString($_, 'text')); $this->oneliner = Util::jsEscape(Util::localizedString($_, 'text'));
// load news // load featuredBox (user web server time)
$this->news = DB::Aowow()->selectRow('SELECT id as ARRAY_KEY, n.* FROM ?_home_featuredbox n WHERE active = 1 ORDER BY id DESC LIMIT 1'); $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->news) if (!$this->featuredBox)
return; 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($_); $this->extendGlobalData($_);
if (empty($this->news['bgImgUrl'])) if (empty($this->featuredBox['boxBG']))
$this->news['bgImgUrl'] = STATIC_URL.'/images/'.User::$localeString.'/mainpage-bg-news.jpg'; $this->featuredBox['boxBG'] = 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]);
// load overlay links // load overlay links
$this->news['overlays'] = DB::Aowow()->select('SELECT * FROM ?_home_featuredbox_overlay WHERE featureId = ?d', $this->news['id']); $this->featuredBox['overlays'] = DB::Aowow()->select('SELECT * FROM ?_home_featuredbox_overlay WHERE featureId = ?d', $this->featuredBox['id']);
foreach ($this->news['overlays'] as &$o) foreach ($this->featuredBox['overlays'] as &$o)
{ {
$o['title'] = Util::localizedString($o, 'title', true); $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']);
} }
} }

View File

@@ -758,9 +758,12 @@ CREATE TABLE `aowow_home_featuredbox` (
`id` smallint(5) unsigned NOT NULL, `id` smallint(5) unsigned NOT NULL,
`editorId` int(10) unsigned DEFAULT NULL, `editorId` int(10) unsigned DEFAULT NULL,
`editDate` int(10) unsigned NOT 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', `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_loc0` text NOT NULL,
`text_loc2` text NOT NULL, `text_loc2` text NOT NULL,
`text_loc3` text NOT NULL, `text_loc3` text NOT NULL,
@@ -2520,7 +2523,7 @@ UNLOCK TABLES;
LOCK TABLES `aowow_home_featuredbox` WRITE; LOCK TABLES `aowow_home_featuredbox` WRITE;
/*!40000 ALTER TABLE `aowow_home_featuredbox` DISABLE KEYS */; /*!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 */; /*!40000 ALTER TABLE `aowow_home_featuredbox` ENABLE KEYS */;
UNLOCK TABLES; UNLOCK TABLES;

View File

@@ -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`;

View File

@@ -6,6 +6,14 @@
<body<?=(User::isPremium() ? ' class="premium-logo"' : null); ?>> <body<?=(User::isPremium() ? ' class="premium-logo"' : null); ?>>
<div id="layers"></div> <div id="layers"></div>
<?php if ($this->headerLogo): ?>
<style type="text/css">
.header-logo {
background: url(<?=$this->headerLogo; ?>) no-repeat center 0 !important;
margin-bottom: 1px !important;
}
</style>
<?php endif; ?>
<div class="layout nosidebar" id="layout"> <div class="layout nosidebar" id="layout">
<div class="layout-inner" id="layout-inner"> <div class="layout-inner" id="layout-inner">
<div class="header" id="header"> <div class="header" id="header">

View File

@@ -6,6 +6,14 @@
</head> </head>
<body class="home<?=(User::isPremium() ? ' premium-logo' : null); ?>"> <body class="home<?=(User::isPremium() ? ' premium-logo' : null); ?>">
<div id="layers"></div> <div id="layers"></div>
<?php if (!empty($this->featuredBox['altHomeLogo'])): ?>
<style type="text/css">
.home-logo {
background: url(<?=$this->featuredBox['altHomeLogo'];?>) no-repeat center 0 !important;
margin-bottom: 1px !important;
}
</style>
<?php endif; ?>
<div class="home-wrapper"> <div class="home-wrapper">
<h1>Aowow</h1> <h1>Aowow</h1>
<div class="home-logo" id="home-logo"></div> <div class="home-logo" id="home-logo"></div>
@@ -26,18 +34,18 @@
<script type="text/javascript">//<![CDATA[ <script type="text/javascript">//<![CDATA[
Markup.printHtml('<?=$this->oneliner;?>', 'home-oneliner'); Markup.printHtml('<?=$this->oneliner;?>', 'home-oneliner');
//]]></script> //]]></script>
<?php elseif ($this->news): ?> <?php elseif ($this->featuredBox): ?>
<div class="pad"></div> <div class="pad"></div>
<?php <?php
endif; endif;
if ($this->news): if ($this->featuredBox):
?> ?>
<div class="home-featuredbox<?=(empty($this->news['extraWide']) ? null : ' home-featuredbox-extended'); ?>" style="background-image: url(<?=$this->news['bgImgUrl']; ?>);" id="home-featuredbox"> <div class="home-featuredbox<?=(empty($this->featuredBox['extraWide']) ? null : ' home-featuredbox-extended'); ?>" style="background-image: url(<?=$this->featuredBox['boxBG']; ?>);" id="home-featuredbox">
<?php if ($this->news['overlays']): ?> <?php if ($this->featuredBox['overlays']): ?>
<div class="home-featuredbox-links"> <div class="home-featuredbox-links">
<?php <?php
foreach ($this->news['overlays'] as $o): foreach ($this->featuredBox['overlays'] as $o):
echo ' <a href="'.$o['url'].'" title="'.$o['title'].'" style="left: '.$o['left'].'px; top: 18px; width:'.$o['width'].'px; height: 160px"></a>'."\n"; echo ' <a href="'.$o['url'].'" title="'.$o['title'].'" style="left: '.$o['left'].'px; top: 18px; width:'.$o['width'].'px; height: 160px"></a>'."\n";
echo ' <var style="left: '.$o['left'].'px; top: 18px; width:'.$o['width'].'px; height: 160px"></var>'."\n"; echo ' <var style="left: '.$o['left'].'px; top: 18px; width:'.$o['width'].'px; height: 160px"></var>'."\n";
endforeach; endforeach;
@@ -57,8 +65,8 @@ if (User::$localeId):
endif; endif;
echo $this->writeGlobalVars(); echo $this->writeGlobalVars();
if ($this->news): if ($this->featuredBox):
echo " Markup.printHtml(".Util::toJSON($this->news['text']).", 'news-generic', { allow: Markup.CLASS_ADMIN });\n"; echo " Markup.printHtml(".Util::toJSON($this->featuredBox['text']).", 'news-generic', { allow: Markup.CLASS_ADMIN });\n";
endif; endif;
?> ?>
//]]></script> //]]></script>