mirror of
https://github.com/Sarjuuk/aowow.git
synced 2025-11-29 15:58:16 +08:00
AjaxHandler
* separated into appropriate subclasses * unified sanitizing of $_GET and $_POST data using build in filter_input() * index now always tries to resolve page calls with ajaxHandler first and as a page last minor bug-fixes to bugs that wre not reported yet, because they didn't occur yet (e.g.: nobody tried to compose a comment with >7500 characters yet)
This commit is contained in:
File diff suppressed because it is too large
Load Diff
80
includes/ajaxHandler/account.class.php
Normal file
80
includes/ajaxHandler/account.class.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
if (!defined('AOWOW_REVISION'))
|
||||
die('invalid access');
|
||||
|
||||
class AjaxAccount extends AjaxHandler
|
||||
{
|
||||
protected $validParams = ['exclude', 'weightscales'];
|
||||
protected $_post = array(
|
||||
// 'groups' => [FILTER_CALLBACK, ['options' => 'AjaxHandler::checkInt']],
|
||||
'save' => [FILTER_SANITIZE_NUMBER_INT, null],
|
||||
'delete' => [FILTER_SANITIZE_NUMBER_INT, null],
|
||||
'id' => [FILTER_CALLBACK, ['options' => 'AjaxHandler::checkInt']],
|
||||
'name' => [FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW],
|
||||
'scale' => [FILTER_CALLBACK, ['options' => 'AjaxAccount::checkScale']],
|
||||
);
|
||||
protected $_get = array(
|
||||
'locale' => [FILTER_CALLBACK, ['options' => 'AjaxHandler::checkLocale']]
|
||||
);
|
||||
|
||||
public function __construct(array $params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (is_numeric($this->_get['locale']))
|
||||
User::useLocale($this->_get['locale']);
|
||||
|
||||
if (!$this->params || !User::$id)
|
||||
return;
|
||||
|
||||
// select handler
|
||||
if ($this->params[0] == 'exclude')
|
||||
$this->handler = 'handleExclude';
|
||||
else if ($this->params[0] == 'weightscales')
|
||||
$this->handler = 'handleWeightscales';
|
||||
}
|
||||
|
||||
protected function handleExclude()
|
||||
{
|
||||
// profiler completion exclude handler
|
||||
// $this->_post['groups'] = bitMask of excludeGroupIds when using .. excludeGroups .. duh
|
||||
// should probably occur in g_user.excludegroups (dont forget to also set g_users.settings = {})
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function handleWeightscales()
|
||||
{
|
||||
if ($this->_post['save'])
|
||||
{
|
||||
if (!$this->_post['scale'])
|
||||
return 0;
|
||||
|
||||
if (!$this->_post['id'])
|
||||
{
|
||||
$res = DB::Aowow()->selectRow('SELECT MAX(id) AS max, count(id) AS num FROM ?_account_weightscales WHERE userId = ?d', User::$id);
|
||||
if ($res['num'] < 5) // more or less hard-defined in LANG.message_weightscalesaveerror
|
||||
$this->post['id'] = ++$res['max'];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (DB::Aowow()->query('REPLACE INTO ?_account_weightscales VALUES (?d, ?d, ?, ?)', $this->_post['id'], User::$id, $this->_post['name'], $this->_post['scale']))
|
||||
return $this->_post['id'];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
else if ($this->_post['delete'] && $this->_post['id'])
|
||||
DB::Aowow()->query('DELETE FROM ?_account_weightscales WHERE id = ?d AND userId = ?d', $this->_post['id'], User::$id);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function checkScale($val)
|
||||
{
|
||||
if (preg_match('/^((\w+:\d+)(,\w+:\d+)*)$/', $val))
|
||||
return $val;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
341
includes/ajaxHandler/admin.class.php
Normal file
341
includes/ajaxHandler/admin.class.php
Normal file
@@ -0,0 +1,341 @@
|
||||
<?php
|
||||
|
||||
if (!defined('AOWOW_REVISION'))
|
||||
die('invalid access');
|
||||
|
||||
class AjaxAdmin extends AjaxHandler
|
||||
{
|
||||
protected $validParams = ['screenshots', 'siteconfig'];
|
||||
protected $_get = array(
|
||||
'action' => [FILTER_SANITIZE_STRING, 0xC], // FILTER_FLAG_STRIP_LOW | *_HIGH
|
||||
'id' => [FILTER_CALLBACK, ['options' => 'AjaxAdmin::checkId']],
|
||||
'all' => [FILTER_UNSAFE_RAW, null],
|
||||
'type' => [FILTER_CALLBACK, ['options' => 'AjaxHandler::checkInt']],
|
||||
'typeid' => [FILTER_CALLBACK, ['options' => 'AjaxHandler::checkInt']],
|
||||
'user' => [FILTER_CALLBACK, ['options' => 'AjaxAdmin::checkUser']],
|
||||
'val' => [FILTER_UNSAFE_RAW, null]
|
||||
);
|
||||
protected $_post = array(
|
||||
'alt' => [FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW],
|
||||
);
|
||||
|
||||
public function __construct(array $params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
// requires 'action' parameter in any case
|
||||
if (!$this->_get['action'] || !$this->params)
|
||||
return;
|
||||
|
||||
if ($this->params[0] == 'screenshots')
|
||||
{
|
||||
if (!User::isInGroup(U_GROUP_STAFF | U_GROUP_SCREENSHOT)) // comment_mod, handleSSmod, vi_mod ?
|
||||
return;
|
||||
|
||||
if ($this->_get['action'] == 'list')
|
||||
$this->handler = 'ssList';
|
||||
else if ($this->_get['action'] == 'manage')
|
||||
$this->handler = 'ssManage';
|
||||
else if ($this->_get['action'] == 'editalt')
|
||||
$this->handler = 'ssEditAlt';
|
||||
else if ($this->_get['action'] == 'approve')
|
||||
$this->handler = 'ssApprove';
|
||||
else if ($this->_get['action'] == 'sticky')
|
||||
$this->handler = 'ssSticky';
|
||||
else if ($this->_get['action'] == 'delete')
|
||||
$this->handler = 'ssDelete';
|
||||
else if ($this->_get['action'] == 'relocate')
|
||||
$this->handler = 'ssRelocate';
|
||||
}
|
||||
else if ($this->params[0] == 'siteconfig')
|
||||
{
|
||||
if (!User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN))
|
||||
return;
|
||||
|
||||
if ($this->_get['action'] == 'add')
|
||||
$this->handler = 'confAdd';
|
||||
else if ($this->_get['action'] == 'remove')
|
||||
$this->handler = 'confRemove';
|
||||
else if ($this->_get['action'] == 'update')
|
||||
$this->handler = 'confUpdate';
|
||||
}
|
||||
}
|
||||
|
||||
// get all => null (optional)
|
||||
// evaled response .. UNK
|
||||
protected function ssList()
|
||||
{
|
||||
// ssm_screenshotPages
|
||||
// ssm_numPagesFound
|
||||
|
||||
$pages = CommunityContent::getScreenshotPagesForManager($this->_get['all'], $nPages);
|
||||
$buff = 'ssm_screenshotPages = '.Util::toJSON($pages).";\n";
|
||||
$buff .= 'ssm_numPagesFound = '.$nPages.';';
|
||||
|
||||
return $buff;
|
||||
}
|
||||
|
||||
// get: [type => type, typeId => typeId] || [user => username]
|
||||
// evaled response .. UNK
|
||||
protected function ssManage()
|
||||
{
|
||||
$res = [];
|
||||
|
||||
if ($this->_get['type'] && $this->_get['type'] && $this->_get['typeid'] && $this->_get['typeid'])
|
||||
$res = CommunityContent::getScreenshotsForManager($this->_get['type'], $this->_get['typeid']);
|
||||
else if ($this->_get['user'])
|
||||
if ($uId = DB::Aowow()->selectCell('SELECT id FROM ?_account WHERE displayName = ?', $this->_get['user']))
|
||||
$res = CommunityContent::getScreenshotsForManager(0, 0, $uId);
|
||||
|
||||
return 'ssm_screenshotData = '.Util::toJSON($res);
|
||||
}
|
||||
|
||||
// get: id => SSid
|
||||
// resp: ''
|
||||
protected function ssEditAlt()
|
||||
{
|
||||
// doesn't need to be htmlEscaped, ths javascript does that
|
||||
if ($this->_get['id'] && $this->_post['alt'] !== null)
|
||||
DB::Aowow()->query('UPDATE ?_screenshots SET caption = ? WHERE id = ?d', trim($this->_post['alt']), $this->_get['id'][0]);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
// get: id => comma-separated SSids
|
||||
// resp: ''
|
||||
protected function ssApprove()
|
||||
{
|
||||
if (!$this->_get['id'])
|
||||
return '';
|
||||
|
||||
// create resized and thumb version of screenshot
|
||||
$resized = [772, 618];
|
||||
$thumb = [150, 150];
|
||||
$path = 'static/uploads/screenshots/%s/%d.jpg';
|
||||
|
||||
foreach ($this->_get['id'] as $id)
|
||||
{
|
||||
// must not be already approved
|
||||
if ($_ = DB::Aowow()->selectRow('SELECT userIdOwner, date FROM ?_screenshots WHERE (status & ?d) = 0 AND id = ?d', CC_FLAG_APPROVED, $id))
|
||||
{
|
||||
// should also error-log
|
||||
if (!file_exists(sprintf($path, 'pending', $id)))
|
||||
continue;
|
||||
|
||||
$srcImg = imagecreatefromjpeg(sprintf($path, 'pending', $id));
|
||||
$srcW = imagesx($srcImg);
|
||||
$srcH = imagesy($srcImg);
|
||||
|
||||
// write thumb
|
||||
$scale = min(1.0, min($thumb[0] / $srcW, $thumb[1] / $srcH));
|
||||
$destW = $srcW * $scale;
|
||||
$destH = $srcH * $scale;
|
||||
$destImg = imagecreatetruecolor($destW, $destH);
|
||||
|
||||
imagefill($destImg, 0, 0, imagecolorallocate($destImg, 255, 255, 255));
|
||||
imagecopyresampled($destImg, $srcImg, 0, 0, 0, 0, $destW, $destH, $srcW, $srcH);
|
||||
|
||||
imagejpeg($destImg, sprintf($path, 'thumb', $id), 100);
|
||||
|
||||
// write resized (only if required)
|
||||
if ($srcW > $resized[0] || $srcH > $resized[1])
|
||||
{
|
||||
$scale = min(1.0, min($resized[0] / $srcW, $resized[1] / $srcH));
|
||||
$destW = $srcW * $scale;
|
||||
$destH = $srcH * $scale;
|
||||
$destImg = imagecreatetruecolor($destW, $destH);
|
||||
|
||||
imagefill($destImg, 0, 0, imagecolorallocate($destImg, 255, 255, 255));
|
||||
imagecopyresampled($destImg, $srcImg, 0, 0, 0, 0, $destW, $destH, $srcW, $srcH);
|
||||
|
||||
imagejpeg($destImg, sprintf($path, 'resized', $id), 100);
|
||||
}
|
||||
|
||||
imagedestroy($srcImg);
|
||||
|
||||
// move screenshot from pending to normal
|
||||
rename(sprintf($path, 'pending', $id), sprintf($path, 'normal', $id));
|
||||
|
||||
// set as approved in DB and gain rep (once!)
|
||||
DB::Aowow()->query('UPDATE ?_screenshots SET status = ?d, userIdApprove = ?d WHERE id = ?d', CC_FLAG_APPROVED, User::$id, $id);
|
||||
Util::gainSiteReputation($_['userIdOwner'], SITEREP_ACTION_UPLOAD, ['id' => $id, 'what' => 1, 'date' => $_['date']]);
|
||||
}
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
// get: id => comma-separated SSids
|
||||
// resp: ''
|
||||
protected function ssSticky()
|
||||
{
|
||||
if (!$this->_get['id'])
|
||||
return '';
|
||||
|
||||
// this one is a bit strange: as far as i've seen, the only thing a 'sticky' screenshot does is show up in the infobox
|
||||
// this also means, that only one screenshot per page should be sticky
|
||||
// so, handle it one by one and the last one affecting one particular type/typId-key gets the cake
|
||||
foreach ($this->_get['id'] as $id)
|
||||
{
|
||||
// reset all others
|
||||
DB::Aowow()->query('UPDATE ?_screenshots a, ?_screenshots b SET a.status = a.status & ~?d WHERE a.type = b.type AND a.typeId = b.typeId AND a.id <> b.id AND b.id = ?d', CC_FLAG_STICKY, $id);
|
||||
|
||||
// approve this one (if not already)
|
||||
$this->ssApprove([$id]);
|
||||
|
||||
// toggle sticky status
|
||||
DB::Aowow()->query('UPDATE ?_screenshots SET `status` = IF(`status` & ?d, `status` & ~?d, `status` | ?d) WHERE id = ?d AND `status` & ?d', CC_FLAG_STICKY, CC_FLAG_STICKY, CC_FLAG_STICKY, $id, CC_FLAG_APPROVED);
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
// get: id => comma-separated SSids
|
||||
// resp: ''
|
||||
// 2 steps: 1) remove from sight, 2) remove from disk
|
||||
protected function ssDelete()
|
||||
{
|
||||
if (!$this->_get['id'])
|
||||
return '';
|
||||
|
||||
$path = 'static/uploads/screenshots/%s/%d.jpg';
|
||||
|
||||
foreach ($this->_get['id'] as $id)
|
||||
{
|
||||
// irrevocably remove already deleted files
|
||||
if (DB::Aowow()->selectCell('SELECT 1 FROM ?_screenshots WHERE status & ?d AND id = ?d', CC_FLAG_DELETED, $id))
|
||||
{
|
||||
DB::Aowow()->query('DELETE FROM ?_screenshots WHERE id = ?d', $id);
|
||||
if (file_exists(sprintf($path, 'pending', $id)))
|
||||
unlink(sprintf($path, 'pending', $id));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// move pending or normal to pending
|
||||
if (file_exists(sprintf($path, 'normal', $id)))
|
||||
rename(sprintf($path, 'normal', $id), sprintf($path, 'pending', $id));
|
||||
|
||||
// remove resized and thumb
|
||||
if (file_exists(sprintf($path, 'thumb', $id)))
|
||||
unlink(sprintf($path, 'thumb', $id));
|
||||
|
||||
if (file_exists(sprintf($path, 'resized', $id)))
|
||||
unlink(sprintf($path, 'resized', $id));
|
||||
}
|
||||
|
||||
// flag as deleted if not aready
|
||||
DB::Aowow()->query('UPDATE ?_screenshots SET status = ?d, userIdDelete = ?d WHERE id IN (?a)', CC_FLAG_DELETED, User::$id, $ids);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
// get: id => ssId, typeid => typeId (but not type..?)
|
||||
// resp: ''
|
||||
protected function ssRelocate()
|
||||
{
|
||||
if (!$this->_get['id'] || !$this->_get['typeid'])
|
||||
return '';
|
||||
|
||||
$type = DB::Aowow()->selectCell('SELECT type FROM ?_screenshots WHERE id = ?d', $this->_get['id']);
|
||||
$typeId = (int)$this->_get['typeid'];
|
||||
|
||||
if (!(new Util::$typeClasses[$type]([['id', $typeId]]))->error)
|
||||
DB::Aowow()->query('UPDATE ?_screenshots SET typeId = ?d WHERE id = ?d', $typeId, $this->_get['id'][0]);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function confAdd()
|
||||
{
|
||||
$key = $this->_get['id'];
|
||||
$val = $this->_get['val'];
|
||||
|
||||
if ($key === null)
|
||||
return 'empty option name given';
|
||||
|
||||
if (!strlen($key))
|
||||
return 'invalid chars in option name: [a-z 0-9 _ . -] are allowed';
|
||||
|
||||
if (ini_get($key) === false || ini_set($key, $val) === false)
|
||||
return 'this configuration option cannot be set';
|
||||
|
||||
if (DB::Aowow()->selectCell('SELECT 1 FROM ?_config WHERE `flags` & ?d AND `key` = ?', CON_FLAG_PHP, $key))
|
||||
return 'this configuration option is already in use';
|
||||
|
||||
DB::Aowow()->query('INSERT IGNORE INTO ?_config (`key`, `value`, `flags`) VALUES (?, ?, ?d)', $key, $val, CON_FLAG_TYPE_STRING | CON_FLAG_PHP);
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function confRemove()
|
||||
{
|
||||
if (!$this->_get['id'])
|
||||
return 'invalid configuration option given';
|
||||
|
||||
if (DB::Aowow()->query('DELETE FROM ?_config WHERE `key` = ? AND (`flags` & ?d) = 0', $this->_get['id'], CON_FLAG_PERSISTENT))
|
||||
return '';
|
||||
else
|
||||
return 'option name is either protected or was not found';
|
||||
}
|
||||
|
||||
protected function confUpdate()
|
||||
{
|
||||
$key = trim($this->_get['id']);
|
||||
$val = trim($this->_get['val']);
|
||||
|
||||
if (!strlen($key))
|
||||
return 'empty option name given';
|
||||
|
||||
$flags = DB::Aowow()->selectCell('SELECT `flags` FROM ?_config WHERE `key` = ?', $key);
|
||||
if (!$flags)
|
||||
return 'configuration option not found';
|
||||
|
||||
if (!($flags & CON_FLAG_TYPE_STRING) && !strlen($val))
|
||||
return 'empty value given';
|
||||
else if ($flags & CON_FLAG_TYPE_INT && !preg_match('/^-?\d+$/i', $val))
|
||||
return "value must be integer";
|
||||
else if ($flags & CON_FLAG_TYPE_FLOAT && !preg_match('/^-?\d*(,|.)?\d+$/i', $val))
|
||||
return "value must be float";
|
||||
else if ($flags & CON_FLAG_TYPE_BOOL)
|
||||
$val = (int)!!$val; // *snort* bwahahaa
|
||||
|
||||
DB::Aowow()->query('UPDATE ?_config SET `value` = ? WHERE `key` = ?', $val, $key);
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function checkId($val)
|
||||
{
|
||||
if (!$this->params)
|
||||
return null;
|
||||
|
||||
// expecting id-list
|
||||
if ($this->params[0] == 'screenshots')
|
||||
{
|
||||
if (preg_match('/\d+(,\d+)*/', $val))
|
||||
return array_map('intVal', explode(', ', $val));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// expecting string
|
||||
if ($this->params[0] == 'siteconfig')
|
||||
{
|
||||
if (preg_match('/[^a-z0-9_\.\-]/i', $val))
|
||||
return '';
|
||||
|
||||
return strtolower($val);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function checkUser($val)
|
||||
{
|
||||
$n = Util::lower(trim(urldecode($val)));
|
||||
|
||||
if (User::isValidName($n))
|
||||
return $n;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
398
includes/ajaxHandler/comment.class.php
Normal file
398
includes/ajaxHandler/comment.class.php
Normal file
@@ -0,0 +1,398 @@
|
||||
<?php
|
||||
|
||||
if (!defined('AOWOW_REVISION'))
|
||||
die('invalid access');
|
||||
|
||||
class AjaxComment extends AjaxHandler
|
||||
{
|
||||
const COMMENT_LENGTH_MIN = 10;
|
||||
const COMMENT_LENGTH_MAX = 7500;
|
||||
const REPLY_LENGTH_MIN = 15;
|
||||
const REPLY_LENGTH_MAX = 600;
|
||||
|
||||
protected $_post = array(
|
||||
'id' => [FILTER_CALLBACK, ['options' => 'AjaxComment::checkId']],
|
||||
'body' => [FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES],
|
||||
'commentbody' => [FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES],
|
||||
'response' => [FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES],
|
||||
'reason' => [FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES],
|
||||
'remove' => [FILTER_SANITIZE_NUMBER_INT, null],
|
||||
'commentId' => [FILTER_SANITIZE_NUMBER_INT, null],
|
||||
'replyId' => [FILTER_SANITIZE_NUMBER_INT, null],
|
||||
// 'username' => [FILTER_SANITIZE_STRING, 0xC] // FILTER_FLAG_STRIP_LOW | *_HIGH
|
||||
);
|
||||
|
||||
protected $_get = array(
|
||||
'id' => [FILTER_CALLBACK, ['options' => 'AjaxHandler::checkInt']],
|
||||
'type' => [FILTER_CALLBACK, ['options' => 'AjaxHandler::checkInt']],
|
||||
'typeid' => [FILTER_CALLBACK, ['options' => 'AjaxHandler::checkInt']],
|
||||
);
|
||||
|
||||
public function __construct(array $params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (!$this->params || count($this->params) != 1)
|
||||
return;
|
||||
|
||||
// note: return values must be formated as STRICT json!
|
||||
|
||||
// select handler
|
||||
if ($this->params[0] == 'add')
|
||||
$this->handler = 'handleCommentAdd';
|
||||
else if ($this->params[0] == 'edit')
|
||||
$this->handler = 'handleCommentEdit';
|
||||
else if ($this->params[0] == 'delete')
|
||||
$this->handler = 'handleCommentDelete';
|
||||
else if ($this->params[0] == 'undelete')
|
||||
$this->handler = 'handleCommentUndelete';
|
||||
else if ($this->params[0] == 'rating') // up/down - distribution
|
||||
$this->handler = 'handleCommentRating';
|
||||
else if ($this->params[0] == 'vote') // up, down and remove
|
||||
$this->handler = 'handleCommentVote';
|
||||
else if ($this->params[0] == 'sticky') // toggle flag
|
||||
$this->handler = 'handleCommentSticky';
|
||||
else if ($this->params[0] == 'out-of-date') // toggle flag
|
||||
$this->handler = 'handleCommentOutOfDate';
|
||||
else if ($this->params[0] == 'show-replies')
|
||||
$this->handler = 'handleCommentShowReplies';
|
||||
else if ($this->params[0] == 'add-reply') // also returns all replies on success
|
||||
$this->handler = 'handleReplyAdd';
|
||||
else if ($this->params[0] == 'edit-reply') // also returns all replies on success
|
||||
$this->handler = 'handleReplyEdit';
|
||||
else if ($this->params[0] == 'detach-reply')
|
||||
$this->handler = 'handleReplyDetach';
|
||||
else if ($this->params[0] == 'delete-reply')
|
||||
$this->handler = 'handleReplyDelete';
|
||||
else if ($this->params[0] == 'flag-reply')
|
||||
$this->handler = 'handleReplyFlag';
|
||||
else if ($this->params[0] == 'upvote-reply')
|
||||
$this->handler = 'handleReplyUpvote';
|
||||
else if ($this->params[0] == 'downvote-reply')
|
||||
$this->handler = 'handleReplyDownvote';
|
||||
}
|
||||
|
||||
// i .. have problems believing, that everything uses nifty ajax while adding comments requires a brutal header(Loacation: <wherever>), yet, thats how it is
|
||||
protected function handleCommentAdd()
|
||||
{
|
||||
if (!$this->_get['typeid'] || !$this->_get['type'] || !isset(Util::$typeStrings[$this->_get['type']]))
|
||||
return; // whatever, we cant even send him back
|
||||
|
||||
// trim to max length
|
||||
if (!User::isInGroup(U_GROUP_MODERATOR) && mb_strlen($this->_post['commentbody']) > (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1)))
|
||||
$this->post['commentbody'] = mb_substr($this->_post['commentbody'], 0, (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1)));
|
||||
|
||||
if (User::canComment() && !empty($this->_post['commentbody']) && mb_strlen($this->_post['commentbody']) >= self::COMMENT_LENGTH_MIN)
|
||||
{
|
||||
if ($postIdx = DB::Aowow()->query('INSERT INTO ?_comments (type, typeId, userId, roles, body, date) VALUES (?d, ?d, ?d, ?d, ?, UNIX_TIMESTAMP())', $this->_get['type'], $this->_get['typeid'], User::$id, User::$groups, $this->_post['commentbody']))
|
||||
{
|
||||
Util::gainSiteReputation(User::$id, SITEREP_ACTION_COMMENT, ['id' => $postIdx]);
|
||||
|
||||
// every comment starts with a rating of +1 and i guess the simplest thing to do is create a db-entry with the system as owner
|
||||
DB::Aowow()->query('INSERT INTO ?_comments_rates (commentId, userId, value) VALUES (?d, 0, 1)', $postIdx);
|
||||
|
||||
// flag target with hasComment (if filtrable)
|
||||
if ($tbl = Util::getCCTableParent($this->_get['type']))
|
||||
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags | ?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $this->_get['typeid']);
|
||||
}
|
||||
}
|
||||
|
||||
$this->doRedirect = true;
|
||||
return '?'.Util::$typeStrings[$this->_get['type']].'='.$this->_get['typeid'].'#comments';
|
||||
}
|
||||
|
||||
protected function handleCommentEdit()
|
||||
{
|
||||
if ((!User::canComment() && !User::isInGroup(U_GROUP_MODERATOR)) || !$this->_get['id'] || !$this->_post['body'])
|
||||
return;
|
||||
|
||||
if (mb_strlen($this->_post['body']) < self::COMMENT_LENGTH_MIN)
|
||||
return;
|
||||
|
||||
// trim to max length
|
||||
if (!User::isInGroup(U_GROUP_MODERATOR) && mb_strlen($this->_post['body']) > (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1)))
|
||||
$this->post['body'] = mb_substr($this->_post['body'], 0, (self::COMMENT_LENGTH_MAX * (User::isPremium() ? 3 : 1)));
|
||||
|
||||
$update = array(
|
||||
'body' => $this->_post['body'],
|
||||
'editUserId' => User::$id,
|
||||
'editDate' => time()
|
||||
);
|
||||
|
||||
if (User::isInGroup(U_GROUP_MODERATOR))
|
||||
{
|
||||
$update['responseBody'] = !$this->_post['response'] ? '' : $this->_post['response'];
|
||||
$update['responseUserId'] = !$this->_post['response'] ? 0 : User::$id;
|
||||
$update['responseRoles'] = !$this->_post['response'] ? 0 : User::$groups;
|
||||
}
|
||||
|
||||
DB::Aowow()->query('UPDATE ?_comments SET editCount = editCount + 1, ?a WHERE id = ?d', $update, $this->_get['id']);
|
||||
}
|
||||
|
||||
protected function handleCommentDelete()
|
||||
{
|
||||
if (!$this->_post['id'] || !User::$id)
|
||||
return;
|
||||
|
||||
// in theory, there is a username passed alongside... lets just use the current user (see user.js)
|
||||
$ok = DB::Aowow()->query('UPDATE ?_comments SET flags = flags | ?d, deleteUserId = ?d, deleteDate = UNIX_TIMESTAMP() WHERE id IN (?a){ AND userId = ?d}',
|
||||
CC_FLAG_DELETED,
|
||||
User::$id,
|
||||
$this->_post['id'],
|
||||
User::isInGroup(U_GROUP_MODERATOR) ? DBSIMPLE_SKIP : User::$id
|
||||
);
|
||||
|
||||
// deflag hasComment (if filtrable)
|
||||
if ($ok)
|
||||
{
|
||||
$coInfo = DB::Aowow()->selectRow('SELECT IF(BIT_OR(~b.flags) & ?d, 1, 0) as hasMore, b.type, b.typeId FROM ?_comments a JOIN ?_comments b ON a.type = b.type AND a.typeId = b.typeId WHERE a.id = ?d',
|
||||
CC_FLAG_DELETED,
|
||||
$this->_post['id']
|
||||
);
|
||||
|
||||
if (!$coInfo['hasMore'] && ($tbl = Util::getCCTableParent($coInfo['type'])))
|
||||
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags & ~?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $coInfo['typeId']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleCommentUndelete()
|
||||
{
|
||||
if (!$this->_post['id'] || !User::$id)
|
||||
return;
|
||||
|
||||
// in theory, there is a username passed alongside... lets just use the current user (see user.js)
|
||||
$ok = DB::Aowow()->query('UPDATE ?_comments SET flags = flags & ~?d WHERE id IN (?a){ AND userId = deleteUserId AND deleteUserId = ?d}',
|
||||
CC_FLAG_DELETED,
|
||||
$this->_post['id'],
|
||||
User::isInGroup(U_GROUP_MODERATOR) ? DBSIMPLE_SKIP : User::$id
|
||||
);
|
||||
|
||||
// reflag hasComment (if filtrable)
|
||||
if ($ok)
|
||||
{
|
||||
$coInfo = DB::Aowow()->selectRow('SELECT type, typeId FROM ?_comments WHERE id = ?d', $this->_post['id']);
|
||||
if ($tbl = Util::getCCTableParent($coInfo['type']))
|
||||
DB::Aowow()->query('UPDATE '.$tbl.' SET cuFlags = cuFlags | ?d WHERE id = ?d', CUSTOM_HAS_COMMENT, $coInfo['typeId']);
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleCommentRating()
|
||||
{
|
||||
if (!$this->_get['id'])
|
||||
return Util::toJSON(['success' => 0]);
|
||||
|
||||
if ($votes = DB::Aowow()->selectRow('SELECT 1 AS success, SUM(IF(value > 0, value, 0)) AS up, SUM(IF(value < 0, -value, 0)) AS down FROM ?_comments_rates WHERE commentId = ?d GROUP BY commentId', $this->_get['id']))
|
||||
return Util::toJSON($votes);
|
||||
else
|
||||
return Util::toJSON(['success' => 1, 'up' => 0, 'down' => 0]);
|
||||
}
|
||||
|
||||
protected function handleCommentVote()
|
||||
{
|
||||
if (!User::$id || !$this->_get['id'] || !$this->_get['rating'])
|
||||
return Util::toJSON(['error' => 1, 'message' => Lang::main('genericError')]);
|
||||
|
||||
$target = DB::Aowow()->selectRow('SELECT c.userId AS owner, cr.value FROM ?_comments c LEFT JOIN ?_comments_rates cr ON cr.commentId = c.id AND cr.userId = ?d WHERE c.id = ?d', User::$id, $this->_get['id']);
|
||||
$val = User::canSupervote() ? 2 : 1;
|
||||
if ($this->_get['rating'] < 0)
|
||||
$val *= -1;
|
||||
|
||||
if (User::getCurDailyVotes() <= 0)
|
||||
return Util::toJSON(['error' => 1, 'message' => Lang::main('tooManyVotes')]);
|
||||
else if (!$target || $val != $this->_get['rating'])
|
||||
return Util::toJSON(['error' => 1, 'message' => Lang::main('genericError')]);
|
||||
else if (($val > 0 && !User::canUpvote()) || ($val < 0 && !User::canDownvote()))
|
||||
return Util::toJSON(['error' => 1, 'message' => Lang::main('bannedRating')]);
|
||||
|
||||
$ok = false;
|
||||
// old and new have same sign; undo vote (user may have gained/lost access to superVote in the meantime)
|
||||
if ($target['value'] && ($target['value'] < 0) == ($val < 0))
|
||||
$ok = DB::Aowow()->query('DELETE FROM ?_comments_rates WHERE commentId = ?d AND userId = ?d', $this->_get['id'], User::$id);
|
||||
else // replace, because we may be overwriting an old, opposing vote
|
||||
if ($ok = DB::Aowow()->query('REPLACE INTO ?_comments_rates (commentId, userId, value) VALUES (?d, ?d, ?d)', (int)$this->_get['id'], User::$id, $val))
|
||||
User::decrementDailyVotes(); // do not refund retracted votes!
|
||||
|
||||
if (!$ok)
|
||||
return Util::toJSON(['error' => 1, 'message' => Lang::main('genericError')]);
|
||||
|
||||
if ($val > 0) // gain rep
|
||||
Util::gainSiteReputation($target['owner'], SITEREP_ACTION_UPVOTED, ['id' => $this->_get['id'], 'voterId' => User::$id]);
|
||||
else if ($val < 0)
|
||||
Util::gainSiteReputation($target['owner'], SITEREP_ACTION_DOWNVOTED, ['id' => $this->_get['id'], 'voterId' => User::$id]);
|
||||
|
||||
return Util::toJSON(['error' => 0]);
|
||||
}
|
||||
|
||||
protected function handleCommentSticky()
|
||||
{
|
||||
if (!$this->_post['id'] || !User::isInGroup(U_GROUP_MODERATOR))
|
||||
return;
|
||||
|
||||
if ($this->_post['sticky'])
|
||||
DB::Aowow()->query('UPDATE ?_comments SET flags = flags | ?d WHERE id = ?d', CC_FLAG_STICKY, $this->_post['id'][0]);
|
||||
else
|
||||
DB::Aowow()->query('UPDATE ?_comments SET flags = flags & ~?d WHERE id = ?d', CC_FLAG_STICKY, $this->_post['id'][0]);
|
||||
}
|
||||
|
||||
protected function handleCommentOutOfDate()
|
||||
{
|
||||
if (!$this->_post['id'])
|
||||
return 'The comment does not exist.';
|
||||
|
||||
$ok = false;
|
||||
if (User::isInGroup(U_GROUP_MODERATOR)) // directly mark as outdated
|
||||
{
|
||||
if (!$this->_post['remove'])
|
||||
$ok = DB::Aowow()->query('UPDATE ?_comments SET flags = flags | 0x4 WHERE id = ?d', $this->_post['id'][0]);
|
||||
else
|
||||
$ok = DB::Aowow()->query('UPDATE ?_comments SET flags = flags & ~0x4 WHERE id = ?d', $this->_post['id'][0]);
|
||||
}
|
||||
else if (User::$id && !$this->_post['reason'] || mb_strlen($this->_post['reason']) < self::REPLY_LENGTH_MIN)
|
||||
return 'Your message is too short.';
|
||||
else if (User::$id) // only report as outdated
|
||||
{
|
||||
$ok = DB::Aowow()->query(
|
||||
'INSERT INTO ?_reports (userId, mode, reason, subject, ip, description, userAgent, appName) VALUES (?d, 1, 17, ?d, ?, "<automated comment report>", ?, ?)',
|
||||
User::$id,
|
||||
$this->_post['id'][0],
|
||||
User::$ip,
|
||||
$_SERVER['HTTP_USER_AGENT'],
|
||||
get_browser(null, true)['browser']
|
||||
);
|
||||
}
|
||||
|
||||
if ($ok) // this one is very special; as in: completely retarded
|
||||
return 'ok'; // the script expects the actual characters 'ok' not some string like "ok"
|
||||
|
||||
return Lang::main('genericError');
|
||||
}
|
||||
|
||||
protected function handleCommentShowReplies()
|
||||
{
|
||||
return Util::toJSON(!$this->_get['id'] ? [] : CommunityContent::getCommentReplies($this->_get['id']));
|
||||
}
|
||||
|
||||
protected function handleReplyAdd()
|
||||
{
|
||||
if (!User::canComment())
|
||||
return 'You are not allowed to reply.';
|
||||
|
||||
else if (!$this->_post['commentId'] || !DB::Aowow()->selectCell('SELECT 1 FROM ?_comments WHERE id = ?d', $this->_post['commentId']))
|
||||
return Lang::main('genericError');
|
||||
|
||||
else if (!$this->_post['body'] || mb_strlen($this->_post['body']) < self::REPLY_LENGTH_MIN || mb_strlen($this->_post['body']) > self::REPLY_LENGTH_MAX)
|
||||
return 'Your reply has '.mb_strlen($this->_post['body']).' characters and must have at least '.self::REPLY_LENGTH_MIN.' and at most '.self::REPLY_LENGTH_MAX.'.';
|
||||
|
||||
else if (DB::Aowow()->query('INSERT INTO ?_comments (`userId`, `roles`, `body`, `date`, `replyTo`) VALUES (?d, ?d, ?, UNIX_TIMESTAMP(), ?d)', User::$id, User::$groups, $this->_post['body'], $this->_post['commentId']))
|
||||
return Util::toJSON(CommunityContent::getCommentReplies($this->_post['commentId']));
|
||||
|
||||
else
|
||||
return Lang::main('genericError');
|
||||
}
|
||||
|
||||
protected function handleReplyEdit()
|
||||
{
|
||||
if (!User::canComment())
|
||||
return 'You are not allowed to reply.';
|
||||
|
||||
else if (!$this->_post['replyId'] || !$this->_post['commentId'])
|
||||
return Lang::main('genericError');
|
||||
|
||||
else if (!$this->_post['body'] || mb_strlen($this->_post['body']) < self::REPLY_LENGTH_MIN || mb_strlen($this->_post['body']) > self::REPLY_LENGTH_MAX)
|
||||
return 'Your reply has '.mb_strlen($this->_post['body']).' characters and must have at least '.self::REPLY_LENGTH_MIN.' and at most '.self::REPLY_LENGTH_MAX.'.';
|
||||
|
||||
if (DB::Aowow()->query('UPDATE ?_comments SET body = ?, editUserId = ?d, editDate = UNIX_TIMESTAMP(), editCount = editCount + 1 WHERE id = ?d AND replyTo = ?d{ AND userId = ?d}',
|
||||
$this->_post['body'], User::$id, $this->_post['replyId'], $this->_post['commentId'], User::isInGroup(U_GROUP_MODERATOR) ? DBSIMPLE_SKIP : User::$id))
|
||||
return Util::toJSON(CommunityContent::getCommentReplies($this->_post['commentId']));
|
||||
else
|
||||
return Lang::main('genericError');
|
||||
}
|
||||
|
||||
protected function handleReplyDetach()
|
||||
{
|
||||
if (!User::isInGroup(U_GROUP_MODERATOR) || !$this->_post['id'])
|
||||
return;
|
||||
|
||||
DB::Aowow()->query('UPDATE ?_comments c1, ?_comments c2 SET c1.replyTo = 0, c1.type = c2.type, c1.typeId = c2.typeId WHERE c1.replyTo = c2.id AND c1.id = ?d', $this->_post['id'][0]);
|
||||
}
|
||||
|
||||
protected function handleReplyDelete()
|
||||
{
|
||||
if (!User::$id || !$this->_post['id'])
|
||||
return;
|
||||
|
||||
if (DB::Aowow()->query('DELETE FROM ?_comments WHERE id = ?d{ AND userId = ?d}', $this->_post['id'][0], User::isInGroup(U_GROUP_MODERATOR) ? DBSIMPLE_SKIP : User::$id))
|
||||
DB::Aowow()->query('DELETE FROM ?_comments_rates WHERE commentId = ?d', $this->_post['id'][0]);
|
||||
}
|
||||
|
||||
protected function handleReplyFlag()
|
||||
{
|
||||
if (!User::$id || !$this->_post['id'])
|
||||
return;
|
||||
|
||||
DB::Aowow()->query(
|
||||
'INSERT INTO ?_reports (userId, mode, reason, subject, ip, description, userAgent, appName) VALUES (?d, 1, 19, ?d, ?, "<automated commentreply report>", ?, ?)',
|
||||
User::$id,
|
||||
$this->_post['id'][0],
|
||||
User::$ip,
|
||||
$_SERVER['HTTP_USER_AGENT'],
|
||||
get_browser(null, true)['browser']
|
||||
);
|
||||
}
|
||||
|
||||
protected function handleReplyUpvote()
|
||||
{
|
||||
if (!$this->_post['id'] || !User::canUpvote())
|
||||
return;
|
||||
|
||||
$owner = DB::Aowow()->selectCell('SELECT userId FROM ?_comments WHERE id = ?d', $this->_post['id'][0]);
|
||||
if (!$owner)
|
||||
return;
|
||||
|
||||
$ok = DB::Aowow()->query(
|
||||
'INSERT INTO ?_comments_rates (commentId, userId, value) VALUES (?d, ?d, ?d)',
|
||||
$this->_post['id'][0],
|
||||
User::$id,
|
||||
User::canSupervote() ? 2 : 1
|
||||
);
|
||||
|
||||
if ($ok)
|
||||
{
|
||||
Util::gainSiteReputation($owner, SITEREP_ACTION_UPVOTED, ['id' => $this->_post['id'][0], 'voterId' => User::$id]);
|
||||
User::decrementDailyVotes();
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleReplyDownvote()
|
||||
{
|
||||
if (!$this->_post['id'] || !User::canDownvote())
|
||||
return;
|
||||
|
||||
$owner = DB::Aowow()->selectCell('SELECT userId FROM ?_comments WHERE id = ?d', $this->_post['id'][0]);
|
||||
if (!$owner)
|
||||
return;
|
||||
|
||||
$ok = DB::Aowow()->query(
|
||||
'INSERT INTO ?_comments_rates (commentId, userId, value) VALUES (?d, ?d, ?d)',
|
||||
$this->_post['id'][0],
|
||||
User::$id,
|
||||
User::canSupervote() ? -2 : -1
|
||||
);
|
||||
|
||||
if ($ok)
|
||||
{
|
||||
Util::gainSiteReputation($owner, SITEREP_ACTION_DOWNVOTED, ['id' => $this->_post['id'][0], 'voterId' => User::$id]);
|
||||
User::decrementDailyVotes();
|
||||
}
|
||||
}
|
||||
|
||||
protected function checkId($val)
|
||||
{
|
||||
// expecting id-list
|
||||
if (preg_match('/\d+(,\d+)*/', $val))
|
||||
return array_map('intVal', explode(', ', $val));
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
?>
|
||||
100
includes/ajaxHandler/contactus.class.php
Normal file
100
includes/ajaxHandler/contactus.class.php
Normal file
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
if (!defined('AOWOW_REVISION'))
|
||||
die('invalid access');
|
||||
|
||||
class AjaxContactus extends AjaxHandler
|
||||
{
|
||||
protected $_post = array(
|
||||
'mode' => [FILTER_SANITIZE_NUMBER_INT, null],
|
||||
'reason' => [FILTER_SANITIZE_NUMBER_INT, null],
|
||||
'ua' => [FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW],
|
||||
'appname' => [FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW],
|
||||
'page' => [FILTER_SANITIZE_URL, null],
|
||||
'desc' => [FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW],
|
||||
'id' => [FILTER_SANITIZE_NUMBER_INT, null],
|
||||
'relatedurl' => [FILTER_SANITIZE_URL, null],
|
||||
'email' => [FILTER_SANITIZE_EMAIL, null]
|
||||
);
|
||||
|
||||
public function __construct(array $params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
// always this one
|
||||
$this->handler = 'handleContactUs';
|
||||
}
|
||||
|
||||
/* responses
|
||||
0: success
|
||||
1: captcha invalid
|
||||
2: description too long
|
||||
3: reason missing
|
||||
7: already reported
|
||||
$: prints response
|
||||
*/
|
||||
protected function handleContactUs()
|
||||
{
|
||||
$mode = $this->_post['mode'];
|
||||
$rsn = $this->_post['reason'];
|
||||
$ua = $this->_post['ua'];
|
||||
$app = $this->_post['appname'];
|
||||
$url = $this->_post['page'];
|
||||
$desc = $this->_post['desc'];
|
||||
|
||||
$contexts = array(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8],
|
||||
[15, 16, 17, 18, 19, 20],
|
||||
[30, 31, 32, 33, 34, 35, 36, 37],
|
||||
[45, 46, 47, 48],
|
||||
[60, 61],
|
||||
[45, 46, 47, 48],
|
||||
[45, 46, 48]
|
||||
);
|
||||
|
||||
if ($mode === null || $rsn === null || $ua === null || $app === null || $url === null)
|
||||
return 'required field missing';
|
||||
|
||||
if (!isset($contexts[$mode]) || !in_array($rsn, $contexts[$mode]))
|
||||
return 'mode invalid';
|
||||
|
||||
if (!$desc)
|
||||
return 3;
|
||||
|
||||
if (mb_strlen($desc) > 500)
|
||||
return 2;
|
||||
|
||||
if (!User::$id && !User::$ip)
|
||||
return 'your ip could not be determined';
|
||||
|
||||
// check already reported
|
||||
$field = User::$id ? 'userId' : 'ip';
|
||||
if (DB::Aowow()->selectCell('SELECT 1 FROM ?_reports WHERE `mode` = ?d AND `reason`= ?d AND `subject` = ?d AND ?# = ?', $mode, $rsn, $this->_post['id'], $field, User::$id ?: User::$ip))
|
||||
return 7;
|
||||
|
||||
$update = array(
|
||||
'userId' => User::$id,
|
||||
'mode' => $mode,
|
||||
'reason' => $rsn,
|
||||
'ip' => User::$ip,
|
||||
'description' => $desc,
|
||||
'userAgent' => $ua,
|
||||
'appName' => $app,
|
||||
'url' => $url
|
||||
);
|
||||
|
||||
if ($_ = $this->_post['id'])
|
||||
$update['subject'] = $_;
|
||||
|
||||
if ($_ = $this->_post['relatedurl'])
|
||||
$update['relatedurl'] = $_;
|
||||
|
||||
if ($_ = $this->_post['email'])
|
||||
$update['email'] = $_;
|
||||
|
||||
if (DB::Aowow()->query('INSERT INTO ?_reports (?#) VALUES (?a)', array_keys($update), array_values($update)))
|
||||
return 0;
|
||||
|
||||
return 'save to db unsuccessful';
|
||||
}
|
||||
}
|
||||
37
includes/ajaxHandler/cookie.class.php
Normal file
37
includes/ajaxHandler/cookie.class.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
if (!defined('AOWOW_REVISION'))
|
||||
die('invalid access');
|
||||
|
||||
class AjaxCookie extends AjaxHandler
|
||||
{
|
||||
public function __construct(array $params)
|
||||
{
|
||||
// note that parent::__construct has to come after this
|
||||
if (!$params || !User::$id)
|
||||
return;
|
||||
|
||||
$this->_get = array(
|
||||
this->params[0] => [FILTER_SANITIZE_STRING, 0xC], // FILTER_FLAG_STRIP_LOW | *_HIGH
|
||||
);
|
||||
|
||||
// NOW we know, what to expect and sanitize
|
||||
parent::__construct($params);
|
||||
|
||||
// always this one
|
||||
$this->handler = 'handleCookie';
|
||||
}
|
||||
|
||||
/* responses
|
||||
0: success
|
||||
$: silent error
|
||||
*/
|
||||
protected function handleCookie()
|
||||
{
|
||||
if (User::$id && $this->params && $this->_get[$this->params[0]])
|
||||
if (DB::Aowow()->query('REPLACE INTO ?_account_cookies VALUES (?d, ?, ?)', User::$id, $this->params[0], $this->_get[$this->params[0]]))
|
||||
return 0;
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
138
includes/ajaxHandler/data.class.php
Normal file
138
includes/ajaxHandler/data.class.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
if (!defined('AOWOW_REVISION'))
|
||||
die('invalid access');
|
||||
|
||||
class AjaxData extends AjaxHandler
|
||||
{
|
||||
protected $_get = array(
|
||||
'locale' => [FILTER_CALLBACK, ['options' => 'AjaxHandler::checkLocale']],
|
||||
't' => [FILTER_SANITIZE_STRING, 0xC], // FILTER_FLAG_STRIP_LOW | *_HIGH
|
||||
'catg' => [FILTER_SANITIZE_NUMBER_INT, null],
|
||||
'skill' => [FILTER_CALLBACK, ['options' => 'AjaxData::checkSkill']],
|
||||
'class' => [FILTER_SANITIZE_NUMBER_INT, null],
|
||||
'callback' => [FILTER_CALLBACK, ['options' => 'AjaxData::checkCallback']]
|
||||
);
|
||||
|
||||
public function __construct(array $params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (is_numeric($this->_get['locale']))
|
||||
User::useLocale($this->_get['locale']);
|
||||
|
||||
// always this one
|
||||
$this->handler = 'handleData';
|
||||
}
|
||||
|
||||
/* responses
|
||||
<string>
|
||||
*/
|
||||
protected function handleData()
|
||||
{
|
||||
$result = '';
|
||||
|
||||
// different data can be strung together
|
||||
foreach ($this->params as $set)
|
||||
{
|
||||
// requires valid token to hinder automated access
|
||||
if ($set != 'item-scaling')
|
||||
if (!$this->_get['t'] || empty($_SESSION['dataKey']) || $this->_get['t'] != $_SESSION['dataKey'])
|
||||
continue;
|
||||
|
||||
switch ($set)
|
||||
{
|
||||
/* issue on no initial data:
|
||||
when we loadOnDemand, the jScript tries to generate the catg-tree before it is initialized
|
||||
it cant be initialized, without loading the data as empty catg are omitted
|
||||
loading the data triggers the generation of the catg-tree
|
||||
*/
|
||||
case 'factions':
|
||||
$result .= $this->loadProfilerData($set);
|
||||
break;
|
||||
case 'companions':
|
||||
$result .= $this->loadProfilerData($set, '778');
|
||||
break;
|
||||
case 'mounts':
|
||||
$result .= $this->loadProfilerData($set, '777');
|
||||
break;
|
||||
case 'quests':
|
||||
// &partial: im not doing this right
|
||||
// it expects a full quest dump on first lookup but will query subCats again if clicked..?
|
||||
// for now omiting the detail clicks with empty results and just set catg update
|
||||
$catg = $this->_get['catg'] ?: 'null';
|
||||
if ($catg == 'null')
|
||||
$result .= $this->loadProfilerData($set);
|
||||
else if ($this->_get['callback'])
|
||||
$result .= "\n\$WowheadProfiler.loadOnDemand('quests', ".$catg.");\n";
|
||||
|
||||
break;
|
||||
case 'recipes':
|
||||
if (!$this->_get['callback'] || !$this->_get['skill'])
|
||||
break;
|
||||
|
||||
foreach ($this->_get['skill'] as $s)
|
||||
Util::loadStaticFile('p-recipes-'.$s, $result, true);
|
||||
|
||||
Util::loadStaticFile('p-recipes-sec', $result, true);
|
||||
$result .= "\n\$WowheadProfiler.loadOnDemand('recipes', null);\n";
|
||||
|
||||
break;
|
||||
// locale independant
|
||||
case 'quick-excludes': // generated per character in profiler
|
||||
case 'zones':
|
||||
case 'weight-presets':
|
||||
case 'item-scaling':
|
||||
case 'realms':
|
||||
case 'statistics':
|
||||
if (!Util::loadStaticFile($set, $result) && CFG_DEBUG)
|
||||
$result .= "alert('could not fetch static data: ".$set."');";
|
||||
|
||||
$result .= "\n\n";
|
||||
break;
|
||||
// localized
|
||||
case 'talents':
|
||||
if ($_ = $this->_get['class'])
|
||||
$set .= "-".$_;
|
||||
case 'pet-talents':
|
||||
case 'glyphs':
|
||||
case 'gems':
|
||||
case 'enchants':
|
||||
case 'itemsets':
|
||||
case 'pets':
|
||||
if (!Util::loadStaticFile($set, $result, true) && CFG_DEBUG)
|
||||
$result .= "alert('could not fetch static data: ".$set." for locale: ".User::$localeString."');";
|
||||
|
||||
$result .= "\n\n";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function checkSkill($val)
|
||||
{
|
||||
return array_intersect([171, 164, 333, 202, 182, 773, 755, 165, 186, 393, 197, 185, 129, 356], explode(',', $val));
|
||||
}
|
||||
|
||||
private function checkCallback($val)
|
||||
{
|
||||
return substr($val, 0, 29) == '$WowheadProfiler.loadOnDemand';
|
||||
}
|
||||
|
||||
private function loadProfilerData($file, $catg = 'null')
|
||||
{
|
||||
$result = '';
|
||||
if ($this->_get['callback'])
|
||||
if (Util::loadStaticFile('p-'.$file, $result, true))
|
||||
$result .= "\n\$WowheadProfiler.loadOnDemand('".$file."', ".$catg.");\n";
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
36
includes/ajaxHandler/gotocomment.class.php
Normal file
36
includes/ajaxHandler/gotocomment.class.php
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
if (!defined('AOWOW_REVISION'))
|
||||
die('invalid access');
|
||||
|
||||
class AjaxGotocomment extends AjaxHandler
|
||||
{
|
||||
protected $_get = array(
|
||||
'id' => [FILTER_CALLBACK, ['options' => 'AjaxHandler::checkInt']]
|
||||
);
|
||||
|
||||
public function __construct(array $params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
// always this one
|
||||
$this->handler = 'handleGoToComment';
|
||||
$this->doRedirect = true;
|
||||
}
|
||||
|
||||
/* responses
|
||||
header()
|
||||
*/
|
||||
protected function handleGoToComment()
|
||||
{
|
||||
if (!$this->_get['id'])
|
||||
exit; // just be blank
|
||||
|
||||
if ($_ = DB::Aowow()->selectRow('SELECT IFNULL(c2.id, c1.id) AS id, IFNULL(c2.type, c1.type) AS type, IFNULL(c2.typeId, c1.typeId) AS typeId FROM ?_comments c1 LEFT JOIN ?_comments c2 ON c1.replyTo = c2.id WHERE c1.id = ?d', $this->_get['id']))
|
||||
return '?'.Util::$typeStrings[$_['type']].'='.$_['typeId'].'#comments:id='.$_['id'].($_['id'] != $this->_get['id'] ? ':reply='.$this->_get['id'] : null);
|
||||
else
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
33
includes/ajaxHandler/locale.class.php
Normal file
33
includes/ajaxHandler/locale.class.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
if (!defined('AOWOW_REVISION'))
|
||||
die('invalid access');
|
||||
|
||||
class AjaxLocale extends AjaxHandler
|
||||
{
|
||||
protected $_get = array(
|
||||
'locale' => [FILTER_CALLBACK, ['options' => 'AjaxHandler::checkLocale']]
|
||||
);
|
||||
|
||||
public function __construct(array $params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
// always this one
|
||||
$this->handler = 'handleLocale';
|
||||
$this->doRedirect = true;
|
||||
}
|
||||
|
||||
/* responses
|
||||
header()
|
||||
*/
|
||||
protected function handleLocale()
|
||||
{
|
||||
User::setLocale($this->_get['locale']);
|
||||
User::save();
|
||||
|
||||
return isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '.';
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
323
includes/ajaxHandler/profile.class.php
Normal file
323
includes/ajaxHandler/profile.class.php
Normal file
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
|
||||
if (!defined('AOWOW_REVISION'))
|
||||
die('invalid access');
|
||||
|
||||
class AjaxProfile extends AjaxHandler
|
||||
{
|
||||
protected $validParams = ['link', 'unlink', 'pin', 'unpin', 'public', 'private', 'avatar', 'resync', 'status', 'delete', 'purge', 'summary', 'load'];
|
||||
protected $_get = array(
|
||||
'id' => [FILTER_CALLBACK, ['options' => 'AjaxProfile::checkId']],
|
||||
// 'items' => [FILTER_CALLBACK, ['options' => 'AjaxProfile::checkItems']],
|
||||
'size' => [FILTER_SANITIZE_STRING, 0xC], // FILTER_FLAG_STRIP_LOW | *_HIGH
|
||||
);
|
||||
|
||||
public function __construct(array $params)
|
||||
{
|
||||
parent::__construct($params);
|
||||
|
||||
if (!$this->params)
|
||||
return;
|
||||
|
||||
switch ($this->params[0])
|
||||
{
|
||||
case 'link':
|
||||
case 'unlink':
|
||||
$this->handler = 'handleLink'; // always returns null
|
||||
break;
|
||||
case 'pin':
|
||||
case 'unpin':
|
||||
$this->handler = 'handlePin'; // always returns null
|
||||
break;
|
||||
case 'public':
|
||||
case 'private':
|
||||
$this->handler = 'handlePrivacy'; // always returns null
|
||||
break;
|
||||
case 'avatar':
|
||||
$this->handler = 'handleAvatar'; // sets an image header
|
||||
break; // so it has to die here or another header will be set
|
||||
case 'resync':
|
||||
case 'status':
|
||||
$this->handler = 'handleResync';
|
||||
break;
|
||||
case 'save':
|
||||
$this->handler = 'handleSave';
|
||||
break;
|
||||
case 'delete':
|
||||
$this->handler = 'handleDelete';
|
||||
break;
|
||||
case 'purge':
|
||||
$this->handler = 'handlePurge';
|
||||
break;
|
||||
case 'summary': // page is generated by jScript
|
||||
die(); // just be empty
|
||||
case 'load':
|
||||
$this->handler = 'handleLoad';
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleLink($id, $mode) // links char with account
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
user: <string> [optional]
|
||||
return: null
|
||||
*/
|
||||
}
|
||||
|
||||
protected function handlePin($id, $mode) // (un)favorite
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
user: <string> [optional]
|
||||
return: null
|
||||
*/
|
||||
}
|
||||
|
||||
protected function handlePrivacy($id, $mode) // public visibility
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
user: <string> [optional]
|
||||
return: null
|
||||
*/
|
||||
}
|
||||
|
||||
protected function handleAvatar() // image
|
||||
{
|
||||
// something happened in the last years: those textures do not include tiny icons
|
||||
$sizes = [/* 'tiny' => 15, */'small' => 18, 'medium' => 36, 'large' => 56];
|
||||
$aPath = 'uploads/avatars/%d.jpg';
|
||||
$s = $this->_get['size'] ?: 'medium';
|
||||
|
||||
if (!$this->_get['id'] || !preg_match('/^([0-9]+)\.(jpg|gif)$/', $this->_get['id'][0], $matches) || !in_array($s, array_keys($sizes)))
|
||||
return;
|
||||
|
||||
$this->contentType = 'image/'.$matches[2];
|
||||
|
||||
$id = $matches[1];
|
||||
$dest = imageCreateTruecolor($sizes[$s], $sizes[$s]);
|
||||
|
||||
if (file_exists(sprintf($aPath, $id)))
|
||||
{
|
||||
$offsetX = $offsetY = 0;
|
||||
|
||||
switch ($s)
|
||||
{
|
||||
case 'tiny':
|
||||
$offsetX += $sizes['small'];
|
||||
case 'small':
|
||||
$offsetY += $sizes['medium'];
|
||||
case 'medium':
|
||||
$offsetX += $sizes['large'];
|
||||
}
|
||||
|
||||
$src = imageCreateFromJpeg(printf($aPath, $id));
|
||||
imagecopymerge($dest, $src, 0, 0, $offsetX, $offsetY, $sizes[$s], $sizes[$s], 100);
|
||||
}
|
||||
|
||||
if ($matches[2] == 'gif')
|
||||
imageGif($dest);
|
||||
else
|
||||
imageJpeg($dest);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
protected function handleResync() // resync init and status requests
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
user: <string> [optional]
|
||||
return
|
||||
null [onOK]
|
||||
int or str [onError]
|
||||
*/
|
||||
|
||||
if ($this->params[0] == 'resync')
|
||||
return '1';
|
||||
else // $this->params[0] == 'status'
|
||||
{
|
||||
/*
|
||||
not all fields are required, if zero they are omitted
|
||||
statusCode:
|
||||
0: end the request
|
||||
1: waiting
|
||||
2: working...
|
||||
3: ready; click to view
|
||||
4: error / retry
|
||||
errorCode:
|
||||
0: unk error
|
||||
1: char does not exist
|
||||
2: armory gone
|
||||
|
||||
[
|
||||
processId,
|
||||
[StatusCode, timeToRefresh, iCount, errorCode, iNResyncs],
|
||||
[<anotherStatus>]...
|
||||
]
|
||||
*/
|
||||
return '[0, [4, 10000, 1, 2]]';
|
||||
}
|
||||
}
|
||||
|
||||
protected function handleSave() // unKill a profile
|
||||
{
|
||||
/* params GET
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
params POST
|
||||
name, level, class, race, gender, nomodel, talenttree1, talenttree2, talenttree3, activespec, talentbuild1, glyphs1, talentbuild2, glyphs2, gearscore, icon, public [always]
|
||||
description, source, copy, inv { inventory: array containing itemLinks } [optional]
|
||||
}
|
||||
return
|
||||
int > 0 [profileId, if we came from an armoryProfile create a new one]
|
||||
int < 0 [onError]
|
||||
str [onError]
|
||||
*/
|
||||
|
||||
return 'NYI';
|
||||
}
|
||||
|
||||
protected function handleDelete() // kill a profile
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
return
|
||||
null
|
||||
*/
|
||||
|
||||
return 'NYI';
|
||||
}
|
||||
|
||||
protected function handlePurge() // removes certain saved information but not the entire character
|
||||
{
|
||||
/* params
|
||||
id: <prId1,prId2,..,prIdN>
|
||||
data: <mode> [string, tabName?]
|
||||
return
|
||||
null
|
||||
*/
|
||||
|
||||
return 'NYI';
|
||||
}
|
||||
|
||||
protected function handleLoad()
|
||||
{
|
||||
/* params
|
||||
id: profileId
|
||||
items: string [itemIds.join(':')]
|
||||
unnamed: unixtime [only to force the browser to reload instead of cache]
|
||||
return
|
||||
lots...
|
||||
*/
|
||||
|
||||
// titles, achievements, characterData, talents (, pets)
|
||||
// and some onLoad-hook to .. load it registerProfile($data)
|
||||
// everything else goes through data.php .. strangely enough
|
||||
|
||||
if (!$this->_get['id'])
|
||||
return;
|
||||
|
||||
$char = new ProfileList(array(['id', $this->_get['id'][0]])); // or string or whatever
|
||||
|
||||
$buff = '';
|
||||
|
||||
if ($it = array_column($char->getField('inventory'), 0))
|
||||
{
|
||||
$itemz = new ItemList(array(['id', $it, CFG_SQL_LIMIT_NONE]));
|
||||
$data = $itemz->getListviewData(ITEMINFO_JSON | ITEMINFO_SUBITEMS);
|
||||
|
||||
// get and apply inventory
|
||||
foreach ($itemz->iterate() as $iId => $__)
|
||||
$buff .= 'g_items.add('.$iId.', {name_'.User::$localeString.":'".Util::jsEscape($itemz->getField('name', true))."', quality:".$itemz->getField('quality').", icon:'".$itemz->getField('iconString')."', jsonequip:".Util::toJSON($data[$iId])."});\n";
|
||||
|
||||
$buff .= "\n";
|
||||
}
|
||||
|
||||
if ($au = $char->getField('auras'))
|
||||
{
|
||||
$auraz = new SpellList(array(['id', $char->getField('auras')], CFG_SQL_LIMIT_NONE));
|
||||
$dataz = $auraz->getListviewData();
|
||||
$modz = $auraz->getProfilerMods();
|
||||
|
||||
// get and apply aura-mods
|
||||
foreach ($dataz as $id => $data)
|
||||
{
|
||||
$mods = [];
|
||||
if (!empty($modz[$id]))
|
||||
{
|
||||
foreach ($modz[$id] as $k => $v)
|
||||
{
|
||||
if (is_array($v))
|
||||
$mods[] = $v;
|
||||
else if ($str = @Util::$itemMods[$k])
|
||||
$mods[$str] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
$buff .= 'g_spells.add('.$id.", {id:".$id.", name:'".Util::jsEscape(mb_substr($data['name'], 1))."', icon:'".$data['icon']."', modifier:".Util::toJSON($mods)."});\n";
|
||||
}
|
||||
$buff .= "\n";
|
||||
}
|
||||
|
||||
/* depending on progress-achievements
|
||||
// required by progress in JScript move to handleLoad()?
|
||||
Util::$pageTemplate->extendGlobalIds(TYPE_NPC, [29120, 31134, 29306, 29311, 23980, 27656, 26861, 26723, 28923, 15991]);
|
||||
*/
|
||||
|
||||
// load available titles
|
||||
Util::loadStaticFile('p-titles-'.$char->getField('gender'), $buff, true);
|
||||
|
||||
// load available achievements
|
||||
if (!Util::loadStaticFile('p-achievements', $buff, true))
|
||||
{
|
||||
$buff .= "\n\ng_achievement_catorder = [];";
|
||||
$buff .= "\n\ng_achievement_points = [0];";
|
||||
}
|
||||
|
||||
// excludes; structure UNK type => [maskBit => [typeIds]] ?
|
||||
/*
|
||||
g_user.excludes = [type:[typeIds]]
|
||||
g_user.includes = [type:[typeIds]]
|
||||
g_user.excludegroups = groupMask // requires g_user.settings != null
|
||||
|
||||
maskBit are matched against fieldId from excludeGroups
|
||||
id: 1, label: LANG.dialog_notavail
|
||||
id: 2, label: LANG.dialog_tcg
|
||||
id: 4, label: LANG.dialog_collector
|
||||
id: 8, label: LANG.dialog_promo
|
||||
id: 16, label: LANG.dialog_nonus
|
||||
id: 96, label: LANG.dialog_faction
|
||||
id: 896, label: LANG.dialog_profession
|
||||
id: 1024, label: LANG.dialog_noexalted
|
||||
*/
|
||||
// $buff .= "\n\ng_excludes = {};";
|
||||
|
||||
// add profile to buffer
|
||||
$buff .= "\n\n\$WowheadProfiler.registerProfile(".Util::toJSON($char->getEntry(2)).");"; // can't use JSON_NUMERIC_CHECK or the talent-string becomes a float
|
||||
|
||||
return $buff."\n";
|
||||
}
|
||||
|
||||
protected function checkId($val)
|
||||
{
|
||||
// expecting id-list
|
||||
if (preg_match('/\d+(,\d+)*/', $val))
|
||||
return array_map('intVal', explode(', ', $val));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected function checkItems($val)
|
||||
{
|
||||
// expecting item-list
|
||||
if (preg_match('/\d+(:\d+)*/', $val))
|
||||
return array_map('intVal', explode(': ', $val));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -14,7 +14,6 @@ mb_internal_encoding('UTF-8');
|
||||
require_once 'includes/defines.php';
|
||||
require_once 'includes/libs/DbSimple/Generic.php'; // Libraray: http://en.dklab.ru/lib/DbSimple (using variant: https://github.com/ivan1986/DbSimple/tree/master)
|
||||
require_once 'includes/utilities.php'; // misc™ data 'n func
|
||||
require_once 'includes/ajaxHandler.class.php'; // handles ajax and jsonp requests
|
||||
require_once 'includes/user.class.php';
|
||||
require_once 'includes/markup.class.php'; // manipulate markup text
|
||||
require_once 'includes/database.class.php'; // wrap DBSimple
|
||||
@@ -34,18 +33,29 @@ spl_autoload_register(function ($class) {
|
||||
if (preg_match('/[^\w]/i', $class)) // name should contain only letters
|
||||
return;
|
||||
|
||||
if (strpos($class, 'list'))
|
||||
if (stripos($class, 'list'))
|
||||
{
|
||||
if (!class_exists('BaseType'))
|
||||
require_once 'includes/types/basetype.class.php';
|
||||
require_once 'includes/basetype.class.php';
|
||||
|
||||
if (file_exists('includes/types/'.strtr($class, ['list' => '']).'.class.php'))
|
||||
require_once 'includes/types/'.strtr($class, ['list' => '']).'.class.php';
|
||||
else
|
||||
throw new Exception('could not register type class: '.$class);
|
||||
|
||||
return;
|
||||
}
|
||||
else if (stripos($class, 'ajax') === 0)
|
||||
{
|
||||
require_once 'includes/ajaxHandler.class.php'; // handles ajax and jsonp requests
|
||||
|
||||
if (file_exists('pages/'.strtr($class, ['page' => '']).'.php'))
|
||||
if (file_exists('includes/ajaxHandler/'.strtr($class, ['ajax' => '']).'.class.php'))
|
||||
require_once 'includes/ajaxHandler/'.strtr($class, ['ajax' => '']).'.class.php';
|
||||
else
|
||||
throw new Exception('could not register ajaxHandler class: '.$class);
|
||||
|
||||
return;
|
||||
}
|
||||
else if (file_exists('pages/'.strtr($class, ['page' => '']).'.php'))
|
||||
require_once 'pages/'.strtr($class, ['page' => '']).'.php';
|
||||
});
|
||||
|
||||
|
||||
49
index.php
49
index.php
@@ -75,17 +75,40 @@ switch ($pageCall)
|
||||
case 'video':
|
||||
case 'zone':
|
||||
case 'zones':
|
||||
if (in_array($pageCall, ['admin', 'account', 'profile']))
|
||||
/* called by script */
|
||||
case 'data': // tool: dataset-loader
|
||||
case 'cookie': // lossless cookies and user settings
|
||||
case 'contactus':
|
||||
case 'comment':
|
||||
// case 'filter': // just a note: this would be accessed from filtrable pages as ?filter=typeStr (with POST-data) and forwards back to page with GET-data .. why? Hell if i know..
|
||||
case 'go-to-comment': // find page the comment is on and forward
|
||||
case 'locale': // subdomain-workaround, change the language
|
||||
$cleanName = str_replace(['-', '_'], '', ucFirst($altClass ?: $pageCall));
|
||||
try // can it be handled as ajax?
|
||||
{
|
||||
if (($_ = (new AjaxHandler($pageParam))->handle($pageCall)) !== null)
|
||||
$class = 'Ajax'.$cleanName;
|
||||
$ajax = new $class(explode('.', $pageParam));
|
||||
if ($ajax->handle($out))
|
||||
{
|
||||
header('Content-type: application/x-javascript; charset=utf-8');
|
||||
die((string)$_);
|
||||
Util::sendNoCacheHeader();
|
||||
|
||||
if ($ajax->doRedirect)
|
||||
header('Location: '.$out, true, 302);
|
||||
else
|
||||
{
|
||||
header('Content-type: '.$ajax->getContentType());
|
||||
die($out);
|
||||
}
|
||||
}
|
||||
else
|
||||
throw new Exception('not handled as ajax');
|
||||
}
|
||||
catch (Exception $e) // no, apparently not..
|
||||
{
|
||||
$class = $cleanName.'Page';
|
||||
(new $class($pageCall, $pageParam))->display();
|
||||
}
|
||||
|
||||
$_ = ($altClass ?: $pageCall).'Page';
|
||||
(new $_($pageCall, $pageParam))->display();
|
||||
break;
|
||||
/* other pages */
|
||||
case 'whats-new':
|
||||
@@ -108,20 +131,6 @@ switch ($pageCall)
|
||||
case 'random':
|
||||
(new UtilityPage($pageCall, $pageParam))->display();
|
||||
break;
|
||||
/* called by script */
|
||||
case 'data': // tool: dataset-loader
|
||||
case 'cookie': // lossless cookies and user settings
|
||||
case 'contactus':
|
||||
case 'comment':
|
||||
// case 'filter': // just a note: this would be accessed from filtrable pages as ?filter=typeStr (with POST-data) and forwards back to page with GET-data .. why? Hell if i know..
|
||||
case 'go-to-comment': // find page the comment is on and forward
|
||||
case 'locale': // subdomain-workaround, change the language
|
||||
if (($_ = (new AjaxHandler($pageParam))->handle($pageCall)) !== null)
|
||||
{
|
||||
header('Content-type: application/x-javascript; charset=utf-8');
|
||||
die((string)$_);
|
||||
}
|
||||
break;
|
||||
default: // unk parameter given -> ErrorPage
|
||||
if (isset($_GET['power']))
|
||||
die('$WowheadPower.register(0, '.User::$localeId.', {})');
|
||||
|
||||
@@ -277,13 +277,13 @@ class ScreenshotPage extends GenericPage
|
||||
{
|
||||
case 1:
|
||||
trigger_error('validateScreenshot - the file exceeds the maximum size of '.ini_get('upload_max_filesize'), E_USER_WARNING);
|
||||
return Lang::screenshot('error', 'selectSS');
|
||||
return Lang::screenshot('error', 'selectSS');
|
||||
case 3:
|
||||
trigger_error('validateScreenshot - upload was interrupted');
|
||||
return Lang::screenshot('error', 'selectSS');
|
||||
trigger_error('validateScreenshot - upload was interrupted', E_USER_WARNING);
|
||||
return Lang::screenshot('error', 'selectSS');
|
||||
case 4:
|
||||
trigger_error('validateScreenshot() - no file was received', E_USER_WARNING);
|
||||
return Lang::screenshot('error', 'selectSS');
|
||||
return Lang::screenshot('error', 'selectSS');
|
||||
case 6:
|
||||
trigger_error('validateScreenshot - temporary upload directory is not set', E_USER_WARNING);
|
||||
return Lang::main('intError');
|
||||
|
||||
Reference in New Issue
Block a user