Files
aowow/pages/more.php
Sarjuuk 85e1accebc Privileges
* add individual pages and corresponding articles
 * yes the sql-update was forgotten
2017-03-20 23:44:41 +01:00

169 lines
5.9 KiB
PHP

<?php
if (!defined('AOWOW_REVISION'))
die('illegal access');
// the actual text is an article accessed by type + typeId
// menuId 2: More g_initPath()
// tabid 2: More g_initHeader()
class MorePage extends GenericPage
{
protected $tpl = 'list-page-generic';
protected $path = [];
protected $tabId = 0;
protected $mode = CACHE_TYPE_NONE;
protected $js = ['swfobject.js'];
private $page = [];
private $req2priv = array(
1 => CFG_REP_REQ_COMMENT, // write comments
2 => 0, // NYI post external links
4 => 0, // NYI no captcha
5 => CFG_REP_REQ_SUPERVOTE, // votes count for more
9 => CFG_REP_REQ_VOTEMORE_BASE, // more votes per day
10 => CFG_REP_REQ_UPVOTE, // can upvote
11 => CFG_REP_REQ_DOWNVOTE, // can downvote
12 => CFG_REP_REQ_REPLY, // can reply
13 => 0, // avatar border [NYI: checked by js, avatars not in use]
14 => 0, // avatar border [NYI: checked by js, avatars not in use]
15 => 0, // avatar border [NYI: checked by js, avatars not in use]
16 => 0, // avatar border [NYI: checked by js, avatars not in use]
17 => CFG_REP_REQ_PREMIUM // premium status
);
private $validPages = array( // [tabId, path[, subPaths]]
'whats-new' => [2, [2, 7]],
'searchbox' => [2, [2, 16]],
'tooltips' => [2, [2, 10]],
'faq' => [2, [2, 3]],
'aboutus' => [2, [2, 0]],
'searchplugins' => [2, [2, 8]],
'help' => [2, [2, 13], ['commenting-and-you', 'modelviewer', 'screenshots-tips-tricks', 'stat-weighting', 'talent-calculator', 'item-comparison', 'profiler', 'markup-guide', 'markup-guide-ext']],
'reputation' => [1, [3, 10]],
'privilege' => [1, [3, 10], [1, 2, 4, 5, 9, 10, 11, 12, 13, 14, 15, 16, 17]],
'privileges' => [1, [3, 10, 0]],
);
public function __construct($pageCall, $subPage)
{
parent::__construct($pageCall, $subPage);
// chack if page is valid
if (isset($this->validPages[$pageCall]))
{
$pageData = $this->validPages[$pageCall];
$this->tab = $pageData[0];
$this->path = $pageData[1];
$this->page = [$pageCall, $subPage];
if ($subPage && isset($pageData[2]))
{
$exists = array_search($subPage, $pageData[2]);
if ($exists === false)
$this->error();
if (is_numeric($subPage))
$this->articleUrl = $pageCall.'='.$subPage;
else
$this->articleUrl = $subPage;
$this->path[] = $subPage;
$this->name = Lang::main('moreTitles', $pageCall, $subPage);
}
else
{
$this->articleUrl = $pageCall;
$this->name = Lang::main('moreTitles', $pageCall);
}
}
else
$this->error();
// order by requirement ASC
asort($this->req2priv);
}
protected function generateContent()
{
switch ($this->page[0])
{
case 'reputation':
$this->handleReputationPage();
return;
case 'privileges':
$this->handlePrivilegesPage();
return;
case 'privilege':
$this->tpl = 'privilege';
$this->privReqPoints = sprintf(Lang::privileges('reqPoints'), Lang::nf($this->req2priv[$this->page[1]]));
return;
default:
return;
}
}
protected function postArticle()
{
if ($this->page[0] != 'reputation' &&
$this->page[0] != 'privileges' &&
$this->page[0] != 'privilege')
return;
$txt = &$this->article['text'];
$consts = get_defined_constants(true);
foreach ($consts['user'] as $k => $v)
{
if (strstr($k, 'CFG_REP_'))
$txt = str_replace($k, Lang::nf($v), $txt);
else if ($k == 'CFG_USER_MAX_VOTES' || $k == 'CFG_BOARD_URL')
$txt = str_replace($k, $v, $txt);
}
}
protected function generatePath() { }
protected function generateTitle()
{
array_unshift($this->title, $this->name);
}
private function handleReputationPage()
{
if (!User::$id)
return;
if ($repData = DB::Aowow()->select('SELECT action, amount, date AS \'when\', IF(action IN (3, 4, 5), sourceA, 0) AS param FROM ?_account_reputation WHERE userId = ?d', User::$id))
{
foreach ($repData as &$r)
$r['when'] = date(Util::$dateFormatInternal, $r['when']);
$this->tabsTitle = Lang::main('yourRepHistory');
$this->forceTabs = true;
$this->lvTabs[] = ['reputationhistory', array(
'id' => 'reputation-history',
'name' => '$LANG.reputationhistory',
'data' => $repData
)];
}
}
private function handlePrivilegesPage()
{
$this->tpl = 'privileges';
$this->privileges = [];
foreach ($this->req2priv as $id => $val)
if ($val)
$this->privileges[$id] = array(
User::getReputation() >= $val,
Lang::privileges('_privileges', $id),
$val
);
}
}
?>