* unify accessing &_GET and &_POST data
 * properly calc and display diffTime
This commit is contained in:
Sarjuuk
2022-03-17 10:14:58 +01:00
parent 3cb02f2204
commit a8edf6c912
6 changed files with 74 additions and 38 deletions

View File

@@ -55,7 +55,7 @@ class CommunityContent
';
private static string $ssQuery = '
SELECT s.id, a.displayName AS user, s.date, s.width, s.height, s.caption, IF(s.status & ?d, 1, 0) AS "sticky", s.type, s.typeId
SELECT s.id AS ARRAY_KEY, s.id, a.displayName AS user, s.date, s.width, s.height, s.caption, IF(s.status & ?d, 1, 0) AS "sticky", s.type, s.typeId
FROM ?_screenshots s
LEFT JOIN ?_account a ON s.userIdOwner = a.id
WHERE {s.userIdOwner = ?d AND }{s.type = ? AND }{s.typeId = ? AND }s.status & ?d AND (s.status & ?d) = 0
@@ -64,7 +64,7 @@ class CommunityContent
';
private static string $viQuery = '
SELECT v.id, a.displayName AS user, v.date, v.videoId, v.caption, IF(v.status & ?d, 1, 0) AS "sticky", v.type, v.typeId
SELECT v.id AS ARRAY_KEY, v.id, a.displayName AS user, v.date, v.videoId, v.caption, IF(v.status & ?d, 1, 0) AS "sticky", v.type, v.typeId
FROM ?_videos v
LEFT JOIN ?_account a ON v.userIdOwner = a.id
WHERE {v.userIdOwner = ?d AND }{v.type = ? AND }{v.typeId = ? AND }v.status & ?d AND (v.status & ?d) = 0
@@ -78,7 +78,6 @@ class CommunityContent
c.body AS preview,
c.date,
c.replyTo AS commentid,
UNIX_TIMESTAMP() - c.date AS elapsed,
IF(c.flags & ?d, 1, 0) AS deleted,
IF(c.type <> 0, c.type, c2.type) AS type,
IF(c.typeId <> 0, c.typeId, c2.typeId) AS typeId,
@@ -151,7 +150,7 @@ class CommunityContent
}
}
public static function getCommentPreviews(array $params = [], int &$nFound = 0) : array
public static function getCommentPreviews(array $params = [], int &$nFound = 0, bool $dateFmt = true) : array
{
/*
purged:0, <- doesnt seem to be used anymore
@@ -184,7 +183,7 @@ class CommunityContent
$c['subject'] = self::$subjCache[$c['type']][$c['typeId']];
// format date
$c['date'] = date(Util::$dateFormatInternal, $c['date']);
$c['date'] = $dateFmt ? date(Util::$dateFormatInternal, $c['date']) : intVal($c['date']);
// remove commentid if not looking for replies
if (empty($params['replies']))
@@ -418,7 +417,7 @@ class CommunityContent
return $comments;
}
public static function getVideos(int $typeOrUser = 0, int $typeId = 0, int &$nFound = 0) : array
public static function getVideos(int $typeOrUser = 0, int $typeId = 0, int &$nFound = 0, bool $dateFmt = true) : array
{
$videos = DB::Aowow()->selectPage($nFound, self::$viQuery,
CC_FLAG_STICKY,
@@ -450,7 +449,7 @@ class CommunityContent
$v['subject'] = Lang::user('removed');
}
$v['date'] = date(Util::$dateFormatInternal, $v['date']);
$v['date'] = $dateFmt ? date(Util::$dateFormatInternal, $v['date']) : intVal($v['date']);
$v['videoType'] = 1; // always youtube
if (!$v['sticky'])
@@ -463,7 +462,7 @@ class CommunityContent
return $videos;
}
public static function getScreenshots(int $typeOrUser = 0, int $typeId = 0, int &$nFound = 0) : array
public static function getScreenshots(int $typeOrUser = 0, int $typeId = 0, int &$nFound = 0, bool $dateFmt = true) : array
{
$screenshots = DB::Aowow()->selectPage($nFound, self::$ssQuery,
CC_FLAG_STICKY,
@@ -495,7 +494,7 @@ class CommunityContent
$s['subject'] = Lang::user('removed');
}
$s['date'] = date(Util::$dateFormatInternal, $s['date']);
$s['date'] = $dateFmt ? date(Util::$dateFormatInternal, $s['date']) : intVal($s['date']);
if (!$s['sticky'])
unset($s['sticky']);

View File

@@ -9,7 +9,7 @@ if (!defined('AOWOW_REVISION'))
define('E_AOWOW', E_ALL & ~(E_DEPRECATED | E_USER_DEPRECATED | E_STRICT));
define('JSON_AOWOW_POWER', JSON_PRETTY_PRINT | JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
define('FILTER_FLAG_STRIP_AOWOW', FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_STRIP_BACKTICK);
define('FILTER_FLAG_STRIP_AOWOW', FILTER_FLAG_STRIP_LOW | FILTER_FLAG_STRIP_HIGH | FILTER_FLAG_STRIP_BACKTICK);
define('MIME_TYPE_TEXT', 'Content-Type: text/plain; charset=utf-8');
define('MIME_TYPE_XML', 'Content-Type: text/xml; charset=utf-8');

View File

@@ -25,24 +25,43 @@ trait TrRequestData
if ($this->filtered)
return;
// php bug? If INPUT_X is empty, filter_input_array returns null/fails
// only really relevant for INPUT_POST
// manuall set everything null in this case
if (isset($this->_post) && gettype($this->_post) == 'array')
$this->_post = filter_input_array(INPUT_POST, $this->_post);
{
if ($_POST)
$this->_post = filter_input_array(INPUT_POST, $this->_post);
else
$this->_post = array_fill_keys(array_keys($this->_post), null);
}
if (isset($this->_get) && gettype($this->_get) == 'array')
$this->_get = filter_input_array(INPUT_GET, $this->_get);
{
if ($_GET)
$this->_get = filter_input_array(INPUT_GET, $this->_get);
else
$this->_get = array_fill_keys(array_keys($this->_get), null);
}
if (isset($this->_cookie) && gettype($this->_cookie) == 'array')
$this->_cookie = filter_input_array(INPUT_COOKIE, $this->_cookie);
{
if ($_COOKIE)
$this->_cookie = filter_input_array(INPUT_COOKIE, $this->_cookie);
else
$this->_cookie = array_fill_keys(array_keys($this->_cookie), null);
}
$this->filtered = true;
}
protected static function checkEmptySet(string $val) : bool
private static function checkEmptySet(string $val) : bool
{
return $val === ''; // parameter is expected to be empty
}
protected static function checkInt(string $val) : int
public static function checkInt(string $val) : int
{
if (preg_match('/^-?\d+$/', $val))
return intVal($val);
@@ -50,7 +69,7 @@ trait TrRequestData
return 0;
}
protected static function checkLocale(string $val) : int
private static function checkLocale(string $val) : int
{
if (preg_match('/^'.implode('|', array_keys(array_filter(Util::$localeStrings))).'$/', $val))
return intVal($val);
@@ -58,7 +77,7 @@ trait TrRequestData
return -1;
}
protected static function checkDomain(string $val) : string
private static function checkDomain(string $val) : string
{
if (preg_match('/^'.implode('|', array_filter(Util::$subDomains)).'$/i', $val))
return strtolower($val);
@@ -66,7 +85,7 @@ trait TrRequestData
return '';
}
protected static function checkIdList(string $val) : array
private static function checkIdList(string $val) : array
{
if (preg_match('/^-?\d+(,-?\d+)*$/', $val))
return array_map('intVal', explode(',', $val));
@@ -74,7 +93,7 @@ trait TrRequestData
return [];
}
protected static function checkIntArray(string $val) : array
private static function checkIntArray(string $val) : array
{
if (preg_match('/^-?\d+(:-?\d+)*$/', $val))
return array_map('intVal', explode(':', $val));
@@ -82,7 +101,7 @@ trait TrRequestData
return [];
}
protected static function checkIdListUnsigned(string $val) : array
private static function checkIdListUnsigned(string $val) : array
{
if (preg_match('/\d+(,\d+)*/', $val))
return array_map('intVal', explode(',', $val));
@@ -90,7 +109,7 @@ trait TrRequestData
return [];
}
protected static function checkFulltext(string $val) : string
private static function checkFulltext(string $val) : string
{
// trim non-printable chars
return preg_replace('/[\p{Cf}\p{Co}\p{Cs}\p{Cn}]/ui', '', $val);
@@ -654,6 +673,24 @@ class Util
}
}
public static function formatTimeDiff(int $sec) : string
{
$delta = time() - $sec;
[, $s, $m, $h, $d] = self::parseTime($delta * 1000);
if ($delta > (1 * MONTH)) // use absolute
return date(Lang::main('dateFmtLong'), $sec);
else if ($delta > (2 * DAY)) // days ago
return Lang::main('timeAgo', [$d . ' ' . Lang::timeUnits('pl', 3)]);
else if ($h) // hours, minutes ago
return Lang::main('timeAgo', [$h . ' ' . Lang::timeUnits('ab', 4) . ' ' . $m . ' ' . Lang::timeUnits('ab', 5)]);
else if ($m) // minutes, seconds ago
return Lang::main('timeAgo', [$m . ' ' . Lang::timeUnits('ab', 5) . ' ' . $m . ' ' . Lang::timeUnits('ab', 6)]);
else // seconds ago
return Lang::main('timeAgo', [$s . ' ' . Lang::timeUnits($s == 1 ? 'sg' : 'pl', 6)]);
}
// pageText for Books (Item or GO) and questText
public static function parseHtmlText(string $text, bool $markdown = false) : string
{