removing smarty - part IX

- readded search
- moved custom displayers (tooltip, xml) to subclasses
- added more info to footer
This commit is contained in:
Sarjuuk
2014-06-29 16:32:23 +02:00
parent f6b68a4092
commit 663597a7a0
16 changed files with 1009 additions and 638 deletions

View File

@@ -11,7 +11,7 @@ trait DetailPage
private $subject = null; // so it will not get cached
function generateCacheKey()
protected function generateCacheKey()
{
// mode, type, typeId, localeId, category, filter
$key = [$this->mode, $this->type, $this->typeId, User::$localeId, '-1', '-1'];
@@ -31,7 +31,7 @@ trait ListPage
protected $typeId = 0;
protected $filter = [];
function generateCacheKey()
protected function generateCacheKey()
{
// mode, type, typeId, localeId,
$key = [$this->mode, $this->type, '-1', User::$localeId];
@@ -62,6 +62,8 @@ class GenericPage
protected $css = [];
// private vars don't get cached
private $time = 0;
private $isCached = false;
private $cacheDir = 'cache/template/';
private $jsgBuffer = [];
private $gLocale = [];
@@ -71,6 +73,8 @@ class GenericPage
public function __construct()
{
$this->time = microtime(true);
// restricted access
if ($this->restrictedGroups && !User::isInGroup($this->restrictedGroups))
$this->error();
@@ -158,6 +162,8 @@ class GenericPage
$this->saveCache();
}
else
$this->isCached = true;
if (isset($this->type) && isset($this->typeId))
$this->gPageInfo = array( // varies slightly for special pages like maps, user-dashboard or profiler
@@ -172,6 +178,7 @@ class GenericPage
if (!empty($this->hasComContent)) // get comments, screenshots, videos
$this->community = CommunityContent::getAll($this->type, $this->typeId);
$this->time = microtime(true) - $this->time;
$this->mysql = DB::Aowow()->getStatistics();
}
@@ -271,7 +278,7 @@ class GenericPage
'status' => 1,
'name' => 'internal error',
'style' => 'padding-left: 40px; background-image: url(static/images/announcements/warn-small.png); background-size: 15px 15px; background-position: 12px center; border: dashed 2px #C03030;',
'text' => '[span id=inputbox-error]'.implode("<br>", $_).'[/span]',
'text' => '[span id=inputbox-error]'.implode("[br]", $_).'[/span]',
);
}
@@ -307,25 +314,11 @@ class GenericPage
/*******************/
public function notFound($typeStr) // unknown ID
{
if ($this->mode == CACHETYPE_TOOLTIP)
{
header('Content-type: application/x-javascript; charset=utf-8');
echo $this->generateTooltip(true);
}
else if ($this->mode == CACHETYPE_XML)
{
header('Content-type: text/xml; charset=utf-8');
echo $this->generateXML(true);
}
else
{
$this->typeStr = $typeStr;
$this->mysql = DB::Aowow()->getStatistics();
$this->display('text-page-generic');
}
exit();
}
@@ -363,28 +356,6 @@ class GenericPage
include('template/pages/'.$override.'.tpl.php');
die();
}
else if ($this->mode == CACHETYPE_TOOLTIP)
{
if (!$this->loadCache($tt))
{
$tt = $this->generateTooltip();
$this->saveCache($tt);
}
header('Content-type: application/x-javascript; charset=utf-8');
die($tt);
}
else if ($this->mode == CACHETYPE_XML)
{
if (!$this->loadCache($xml))
{
$xml = $this->generateXML();
$this->saveCache($xml);
}
header('Content-type: text/xml; charset=utf-8');
die($xml);
}
else
{
$this->prepareContent();

View File

@@ -22,7 +22,7 @@ class ItemList extends BaseType
private $vendors = [];
private $jsGlobals = []; // getExtendedCost creates some and has no access to template
protected $queryBase = 'SELECT i.*, `is`.*, i.id AS ARRAY_KEY FROM ?_items i';
protected $queryBase = 'SELECT i.*, `is`.*, i.id AS id, i.id AS ARRAY_KEY FROM ?_items i';
protected $queryOpts = array(
'is' => ['j' => ['?_item_stats AS `is` ON `is`.`id` = `i`.`id`', true]],
's' => ['j' => ['?_spell AS `s` ON s.effect1CreateItemId = i.id', true], 'g' => 'i.id'],
@@ -1291,24 +1291,34 @@ class ItemList extends BaseType
{
$jsonEquip = [];
$jsonText = [];
$enchIds = [];
for ($i = 1; $i < 6; $i++)
{
$enchId = $data['enchantId'.$i];
if ($enchId <= 0)
continue;
// subitems may share enchantmentIds
if (!isset($this->rndEnchIds[$enchId]))
if (isset($this->rndEnchIds[$enchId]))
continue;
$enchIds[] = $enchId;
}
foreach (Util::parseItemEnchantment($enchIds, false, $misc) as $eId => $stats)
{
$stats = Util::parseItemEnchantment($enchId, false, $misc);
$this->rndEnchIds[$enchId] = array(
'text' => $misc[$enchId]['name'],
$this->rndEnchIds[$eId] = array(
'text' => $misc[$eId]['name'],
'stats' => $stats
);
}
for ($i = 1; $i < 6; $i++)
{
$enchId = $data['enchantId'.$i];
if ($enchId <= 0)
continue;
if ($data['allocationPct'.$i] > 0) // RandomSuffix: scaling Enchantment; enchId < 0
{
$qty = intVal($data['allocationPct'.$i] * $this->generateEnchSuffixFactor());

View File

@@ -11,8 +11,8 @@ class WorldEventList extends BaseType
protected $queryBase = 'SELECT *, -e.id as id, -e.id AS ARRAY_KEY FROM ?_events e';
protected $queryOpts = array(
'e' => ['j' => ['?_holidays h2 ON e.holidayId = h2.id', true], 'o' => '-e.id ASC'],
'h' => ['j' => ['?_holidays h ON e.holidayId = h.id']]
'e' => [['h']],
'h' => ['j' => ['?_holidays h ON e.holidayId = h.id', true], 'o' => '-e.id ASC']
);
public function __construct($conditions = [])

View File

@@ -407,6 +407,31 @@ class AchievementPage extends GenericPage
return $x;
}
public function display($override = '')
{
if ($this->mode != CACHETYPE_TOOLTIP)
return parent::display($override);
if (!$this->loadCache($tt))
{
$tt = $this->generateTooltip();
$this->saveCache($tt);
}
header('Content-type: application/x-javascript; charset=utf-8');
die($tt);
}
public function notFound($typeStr)
{
if ($this->mode != CACHETYPE_TOOLTIP)
return parent::notFound($typeStr);
header('Content-type: application/x-javascript; charset=utf-8');
echo $this->generateTooltip(true);
exit();
}
}
?>

View File

@@ -1064,6 +1064,52 @@ class ItemPage extends genericPage
return $root->asXML();
}
public function display($override = '')
{
if ($this->mode == CACHETYPE_TOOLTIP)
{
if (!$this->loadCache($tt))
{
$tt = $this->generateTooltip();
$this->saveCache($tt);
}
header('Content-type: application/x-javascript; charset=utf-8');
die($tt);
}
else if ($this->mode == CACHETYPE_XML)
{
if (!$this->loadCache($xml))
{
$xml = $this->generateXML();
$this->saveCache($xml);
}
header('Content-type: text/xml; charset=utf-8');
die($xml);
}
else
return parent::display($override);
}
public function notFound($typeStr)
{
if ($this->mode == CACHETYPE_TOOLTIP)
{
header('Content-type: application/x-javascript; charset=utf-8');
echo $this->generateTooltip(true);
exit();
}
else if ($this->mode == CACHETYPE_XML)
{
header('Content-type: text/xml; charset=utf-8');
echo $this->generateXML(true);
exit();
}
else
return parent::notFound($typeStr);
}
}
?>

View File

@@ -94,6 +94,8 @@ class ItemsPage extends GenericPage
$this->addJS('?data=weight-presets&locale='.User::$localeId.'&t='.$_SESSION['dataKey']);
$this->hasGroupedTabs = false;
$conditions = [];
/*******************/
/* evaluate filter */
/*******************/
@@ -415,6 +417,9 @@ class ItemsPage extends GenericPage
{
array_unshift($this->title, $this->name);
if (!$this->category)
return;
if (isset($this->category[2]))
$tPart = Lang::$item['cat'][$this->category[0]][1][$this->category[1]][1][$this->category[2]];
else if (isset($this->category[1]))

View File

@@ -491,6 +491,31 @@ class ObjectPage extends GenericPage
return $x;
}
public function display($override = '')
{
if ($this->mode != CACHETYPE_TOOLTIP)
return parent::display($override);
if (!$this->loadCache($tt))
{
$tt = $this->generateTooltip();
$this->saveCache($tt);
}
header('Content-type: application/x-javascript; charset=utf-8');
die($tt);
}
public function notFound($typeStr)
{
if ($this->mode != CACHETYPE_TOOLTIP)
return parent::notFound($typeStr);
header('Content-type: application/x-javascript; charset=utf-8');
echo $this->generateTooltip(true);
exit();
}
}
?>

View File

@@ -51,12 +51,11 @@ class RacePage extends GenericPage
[7952, 33554], null, [16264, 33557], [17584, 33657]
);
/***********/
/* Infobox */
/***********/
$infobox = []; // unfortunately, all of this is custom data :/
$infobox = Lang::getInfoBoxForFlags($this->subject->getField('cuFlags'));
// side
if ($_ = $this->subject->getField('side'))

File diff suppressed because it is too large Load Diff

View File

@@ -4,6 +4,11 @@ if (!defined('AOWOW_REVISION'))
die('illegal access');
/*
icons: data/interface/calendar/calendar_[a-z]start.blp
*/
// menuId 10: Title g_initPath()
// tabId 0: Database g_initHeader()
class TitlePage extends GenericPage

View File

@@ -1,8 +1,22 @@
<div id="footer">
<?php
if (isset($this->mysql)):
echo Lang::$main['numSQL'] . Lang::$main['colon']. $this->mysql['count']."<br>\n";
echo Lang::$main['timeSQL']. Lang::$main['colon']. Util::formatTime($this->mysql['time'] * 1000)."\n";
if ($this->time || isset($this->mysql) || $this->isCached):
echo "<table style=\"margin:auto;\">\n";
if (isset($this->mysql)):
echo '<tr><td style="text-align:left;">'.Lang::$main['numSQL'] .'</td><td>'.$this->mysql['count']."</td></tr>\n";
echo '<tr><td style="text-align:left;">'.Lang::$main['timeSQL'].'</td><td>'.Util::formatTime($this->mysql['time'] * 1000, true)."</td></tr>\n";
endif;
if ($this->time):
echo '<tr><td style="text-align:left;">Page generated in</td><td>'.Util::formatTime($this->time * 1000, true)."</td></tr>\n";
endif;
if ($this->isCached):
echo "<tr><td style=\"text-align:left;\">(rebuild from cache)</td><td></td></tr>\n";
endif;
echo "</table>\n";
endif;
?>
</div>

View File

@@ -8,7 +8,7 @@ foreach ($vars as $id => $data):
'};';
endforeach;
if (isset($extra[$this->typeId])):
if (isset($this->typeId) && !empty($extra[$this->typeId])):
echo '_['.$extra[$this->typeId]['id'].'].tooltip_'.User::$localeString.' = \''.Util::jsEscape($extra[$this->typeId]['tooltip']).'\';';
echo '_['.$extra[$this->typeId]['id'].'].spells_'.User::$localeString.' = '.json_encode($extra[$this->typeId]['spells'], JSON_NUMERIC_CHECK).';';
endif;

View File

@@ -16,7 +16,7 @@
<div id="layers"></div>
<div id="home">
<?php $this->brick('announcements'); ?>
<?php $this->brick('announcement'); ?>
<span id="menu_buttons-generic" class="menu-buttons"></span>
<script type="text/javascript">

View File

@@ -15,7 +15,7 @@
<body>
<div class="maintenance">
<div>The website is currently closed for maintenance.</div>
<p>It will take a few minutes...</p>
<p>This will take a few minutes...</p>
</div>
</body>
</html>

View File

@@ -1,38 +0,0 @@
{include file='header.tpl'}
<div id="main">
<div id="main-precontents"></div>
<div class="main-contents" id="main-contents">
{if !empty($announcements)}
{foreach from=$announcements item=item}
{include file='bricks/announcement.tpl' an=$item}
{/foreach}
{/if}
<div class="text">
<a href="{$wowhead}" class="button-red"><em><b><i>Wowhead</i></b><span>Wowhead</span></em></a>
{if !empty($found)}
<h1>{$lang.foundResult} <i>{$search|escape:"html"}</i>{if $ignored}<span class="sub">{$lang.ignoredTerms|sprintf:$ignored}</span>{/if}</h1>
</div>
<div id="tabs-generic"></div>
<div id="lv-generic" class="listview"></div>
<script type="text/javascript">
var myTabs = new Tabs({ldelim}parent: $WH.ge('tabs-generic'){rdelim});
{foreach from=$found item="f"}
{include file="listviews/`$f.file`.tpl" data=$f.data params=$f.params}
{/foreach}
myTabs.flush();
</script>
{else}
<h1>{$lang.noResult} <i>{$search|escape:"html"}</i>{if $ignored}<span class="sub">{$lang.ignoredTerms|sprintf:$ignored}</span>{/if}</h1>
<div class="search-noresults"/></div>
{$lang.tryAgain}
{/if}
<div class="clear"></div>
</div>
</div>
{include file='footer.tpl'}

View File

@@ -0,0 +1,51 @@
<?php $this->brick('header'); ?>
<div id="main">
<div id="main-precontents"></div>
<div class="main-contents" id="main-contents">
<?php $this->brick('announcement'); ?>
<div class="text">
<a href="<?php echo Util::$wowheadLink; ?>" class="button-red"><em><b><i>Wowhead</i></b><span>Wowhead</span></em></a>
<?php
if ($this->lvData):
echo ' <h1>'.Lang::$search['foundResult'].' <i>'.Util::htmlEscape($this->search).'</i>';
if ($this->invalid):
echo '<span class="sub">'.sprintf(Lang::$search['ignoredTerms'], implode(', ', $this->invalid)).'</span>';
endif;
echo "</h1>\n";
?>
</div>
<div id="tabs-generic"></div>
<div id="lv-generic" class="listview"></div>
<script type="text/javascript">
var myTabs = new Tabs({parent: $WH.ge('tabs-generic')});
<?php
foreach ($this->lvData as $lv):
$this->lvBrick($lv['file'], ['data' => $lv['data'], 'params' => $lv['params']]);
endforeach;
?>
myTabs.flush();
</script>
<?php
else:
echo ' <h1>'.Lang::$search['noResult'].' <i>'.Util::htmlEscape($this->search).'</i>';
if ($this->invalid):
echo '<span class="sub">'.sprintf(Lang::$search['ignoredTerms'], implode(', ', $this->invalid)).'</span>';
endif;
echo "</h1>\n";
?>
<div class="search-noresults"/></div>
<?php
echo ' '.Lang::$search['tryAgain']."\n";
endif;
?>
<div class="clear"></div>
</div>
</div>
<?php $this->brick('footer'); ?>