Template/Update (Part 2)

* convert landing (home) page
This commit is contained in:
Sarjuuk
2025-08-06 01:04:10 +02:00
parent e943e27b5b
commit 5713834f90
3 changed files with 98 additions and 84 deletions

75
endpoints/home/home.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
class HomeBaseResponse extends TemplateResponse
{
protected string $template = 'home';
protected string $pageName = 'home';
protected array $scripts = array(
[SC_JS_FILE, 'js/home.js'],
[SC_CSS_FILE, 'css/home.css'],
[SC_CSS_STRING, '.announcement { margin: auto; max-width: 1200px; padding: 0px 15px 15px 15px }']
);
public array $featuredBox = [];
public ?Markup $oneliner = null;
public string $homeTitle = '';
public ?string $altHomeLogo = null;
protected function generate() : void
{
// set <title> element
if ($_ = DB::Aowow()->selectCell('SELECT `title` FROM ?_home_titles WHERE `active` = 1 AND `locale` = ?d ORDER BY RAND()', Lang::getLocale()->value))
$this->homeTitle = Util::jsEscape(Cfg::get('NAME').Lang::main('colon').$_);
// load oneliner
if ($_ = DB::Aowow()->selectRow('SELECT * FROM ?_home_oneliner WHERE `active` = 1 ORDER BY RAND() LIMIT 1'))
$this->oneliner = new Markup(new LocString($_, 'text'), [], 'home-oneliner');
if ($_ = $this->oneliner?->getJsGlobals())
$this->extendGlobalData($_);
// load featuredBox (user web server time)
if ($box = DB::Aowow()->selectRow('SELECT * FROM ?_home_featuredbox WHERE ?d BETWEEN `startDate` AND `endDate` ORDER BY `id` DESC', time()))
{
// define text constants for all fields (STATIC_URL, HOST_URL, etc.)
$box = Util::defStatic($box);
if ($box['altHomeLogo'])
$this->altHomeLogo = $box['altHomeLogo'];
$this->featuredBox = array(
'markup' => new Markup(new LocString($box, 'text'), ['allow' => Markup::CLASS_ADMIN], 'news-generic'),
'extended' => $box['extraWide'],
'boxBG' => $box['boxBG'] ?? Cfg::get('STATIC_URL').'/images/'.Lang::getLocale()->json().'/mainpage-bg-news.jpg',
'overlays' => []
);
if ($_ = $this->featuredBox['markup']->getJsGlobals())
$this->extendGlobalData($_);
// load overlay links
foreach (DB::Aowow()->select('SELECT * FROM ?_home_featuredbox_overlay WHERE `featureId` = ?d', $box['id']) as $ovl)
{
$ovl = Util::defStatic($ovl);
$this->featuredBox['overlays'][] = array(
'url' => $ovl['url'],
'left' => $ovl['left'],
'width' => $ovl['width'],
'title' => new LocString($ovl, 'title')
);
}
}
parent::generate();
}
}
?>

View File

@@ -1,66 +0,0 @@
<?php
namespace Aowow;
if (!defined('AOWOW_REVISION'))
die('illegal access');
class HomePage extends GenericPage
{
protected $tpl = 'home';
protected $scripts = array(
[SC_JS_FILE, 'js/home.js'],
[SC_CSS_FILE, 'css/home.css'],
[SC_CSS_STRING, '.announcement { margin: auto; max-width: 1200px; padding: 0px 15px 15px 15px }']
);
protected $featuredBox = [];
protected $oneliner = '';
protected $homeTitle = '';
public function __construct()
{
parent::__construct('home');
}
protected function generateContent()
{
// load oneliner
if ($_ = DB::Aowow()->selectRow('SELECT * FROM ?_home_oneliner WHERE active = 1 LIMIT 1'))
$this->oneliner = Util::jsEscape(Util::localizedString($_, 'text'));
// 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->featuredBox = Util::defStatic($this->featuredBox);
$this->featuredBox['text'] = Util::localizedString($this->featuredBox, 'text', true);
if ($_ = Markup::parseTags($this->featuredBox['text']))
$this->extendGlobalData($_);
if (empty($this->featuredBox['boxBG']))
$this->featuredBox['boxBG'] = Cfg::get('STATIC_URL').'/images/'.Lang::getLocale()->json().'/mainpage-bg-news.jpg';
// load overlay links
$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'] = Util::defStatic($o['title']);
}
}
protected function generateTitle()
{
if ($_ = DB::Aowow()->selectCell('SELECT title FROM ?_home_titles WHERE active = 1 AND locale = ?d ORDER BY RAND() LIMIT 1', Lang::getLocale()->value))
$this->homeTitle = Cfg::get('NAME').Lang::main('colon').$_;
}
protected function generatePath() {}
}
?>

View File

@@ -1,29 +1,32 @@
<?php namespace Aowow; ?> <?php
namespace Aowow\Template;
use \Aowow\Lang;
?>
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
<?php $this->brick('head'); ?> <?php $this->brick('head'); ?>
</head> </head>
<body class="home<?=(User::isPremium() ? ' premium-logo' : null); ?>"> <body class="home<?=($this->user::isPremium() ? ' premium-logo' : ''); ?>">
<div id="layers"></div> <div id="layers"></div>
<?php <?php
if ($this->homeTitle): if ($this->homeTitle):
echo " <script>document.title = '".$this->homeTitle."';</script>\n"; echo " <script>document.title = '".$this->homeTitle."';</script>\n";
endif; endif;
if (!empty($this->featuredBox['altHomeLogo'])): if ($this->altHomeLogo):
?> ?>
<style type="text/css"> <style type="text/css">
.home-logo { .home-logo {
background: url(<?=$this->featuredBox['altHomeLogo'];?>) no-repeat center 0 !important; background: url(<?=$this->altHomeLogo; ?>) no-repeat center 0 !important;
margin-bottom: 1px !important; margin-bottom: 1px !important;
} }
</style> </style>
<?php endif; ?> <?php endif; ?>
<div class="home-wrapper"> <div class="home-wrapper">
<h1>Aowow</h1> <h1><?=$this->concat('title'); ?></h1>
<div class="home-logo" id="home-logo"></div> <div class="home-logo" id="home-logo"></div>
<?php $this->brick('announcement'); ?> <?php $this->brick('announcement'); ?>
@@ -37,11 +40,11 @@ if (!empty($this->featuredBox['altHomeLogo'])):
<div class="home-menu" id="home-menu"></div> <div class="home-menu" id="home-menu"></div>
<?php if ($this->oneliner): ?> <?php if ($this->oneliner): ?>
<p class="home-oneliner text" id="home-oneliner"></p> <p class="home-oneliner text" id="home-oneliner"></p>
<script type="text/javascript">//<![CDATA[
<?=$this->oneliner; ?>
//]]></script>
<script type="text/javascript">//<![CDATA[
Markup.printHtml('<?=$this->oneliner;?>', 'home-oneliner');
//]]></script>
<?php elseif ($this->featuredBox): ?> <?php elseif ($this->featuredBox): ?>
<div class="pad"></div> <div class="pad"></div>
<?php <?php
@@ -49,13 +52,13 @@ endif;
if ($this->featuredBox): if ($this->featuredBox):
?> ?>
<div class="home-featuredbox<?=(empty($this->featuredBox['extraWide']) ? null : ' home-featuredbox-extended'); ?>" style="background-image: url(<?=$this->featuredBox['boxBG']; ?>);" id="home-featuredbox"> <div class="home-featuredbox<?=$this->featuredBox['extended'] ? ' home-featuredbox-extended' : ''; ?>" style="background-image: url(<?=$this->featuredBox['boxBG']; ?>);" id="home-featuredbox">
<?php if ($this->featuredBox['overlays']): ?> <?php if ($this->featuredBox['overlays']): ?>
<div class="home-featuredbox-links"> <div class="home-featuredbox-links">
<?php <?php
foreach ($this->featuredBox['overlays'] as $o): foreach ($this->featuredBox['overlays'] as ['url' => $u, 'title' => $t, 'left' => $l, 'width' => $w]):
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="'.$u.'" title="'.$t.'" style="left: '.$l.'px; top: 18px; width:'.$w.'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: '.$l.'px; top: 18px; width:'.$w.'px; height: 160px"></var>'."\n";
endforeach; endforeach;
?> ?>
</div> </div>
@@ -68,13 +71,13 @@ endif;
?> ?>
<script type="text/javascript">//<![CDATA[ <script type="text/javascript">//<![CDATA[
<?php <?php
if (Lang::getLocale()->value): if ($this->locale->value):
echo " Locale.set(".Lang::getLocale()->value.");\n"; echo " Locale.set(".$this->locale->value.");\n";
endif; endif;
echo $this->writeGlobalVars(); echo $this->renderGlobalVars(12);
if ($this->featuredBox): if ($this->featuredBox):
echo " Markup.printHtml(".Util::toJSON($this->featuredBox['text']).", 'news-generic', { allow: Markup.CLASS_ADMIN });\n"; echo " ".$this->featuredBox['markup'];
endif; endif;
?> ?>
//]]></script> //]]></script>
@@ -93,6 +96,8 @@ endif;
<?php $this->brick('pageTemplate'); ?> <?php $this->brick('pageTemplate'); ?>
<?php $this->localizedBrickIf($this->consentFooter, 'consent'); ?>
<noscript><div id="noscript-bg"></div><div id="noscript-text"><b><?=Lang::main('jsError'); ?></b></div></noscript> <noscript><div id="noscript-bg"></div><div id="noscript-text"><b><?=Lang::main('jsError'); ?></b></div></noscript>
</body> </body>
</html> </html>