Coding style
This commit is contained in:
parent
0799853a93
commit
2adbc8d19f
21 changed files with 151 additions and 33 deletions
|
@ -20,8 +20,10 @@ class Load extends Method
|
|||
$ipList = [];
|
||||
$banList = [];
|
||||
|
||||
$query = 'SELECT b.id, b.username, b.ip, b.email, b.message, b.expire
|
||||
FROM ::bans AS b';
|
||||
|
||||
$stmt = $this->c->DB->query('SELECT b.id, b.username, b.ip, b.email, b.message, b.expire FROM ::bans AS b');
|
||||
$stmt = $this->c->DB->query($query);
|
||||
while ($row = $stmt->fetch()) {
|
||||
$name = $this->model->trimToNull($row['username'], true);
|
||||
if (null !== $name) {
|
||||
|
|
|
@ -70,7 +70,7 @@ class Manager extends ManagerModel
|
|||
SET cat_name=?s:name, disp_position=?i:position
|
||||
WHERE id=?i:cid';
|
||||
|
||||
$this->c->DB->query($query, $vars); //????
|
||||
$this->c->DB->exec($query, $vars);
|
||||
}
|
||||
$this->modified = [];
|
||||
|
||||
|
@ -93,10 +93,9 @@ class Manager extends ManagerModel
|
|||
];
|
||||
$query = 'INSERT INTO ::categories (cat_name, disp_position)
|
||||
VALUES (?s:name, ?i:position)';
|
||||
$this->c->DB->query($query, $vars);
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$cid = $this->c->DB->lastInsertId();
|
||||
|
||||
parent::set($cid, ['cat_name' => $name, 'disp_position' => $pos]);
|
||||
|
||||
return $cid;
|
||||
|
|
|
@ -15,7 +15,10 @@ class Refresh extends Method
|
|||
*/
|
||||
public function refresh(): Censorship
|
||||
{
|
||||
$stmt = $this->c->DB->query('SELECT ce.id, ce.search_for, ce.replace_with FROM ::censoring AS ce');
|
||||
$query = 'SELECT ce.id, ce.search_for, ce.replace_with
|
||||
FROM ::censoring AS ce';
|
||||
|
||||
$stmt = $this->c->DB->query($query);
|
||||
$search = [];
|
||||
$replace = [];
|
||||
while ($row = $stmt->fetch()) {
|
||||
|
|
|
@ -16,7 +16,10 @@ class Load extends Method
|
|||
*/
|
||||
public function load(): Config
|
||||
{
|
||||
$config = $this->c->DB->query('SELECT cf.conf_name, cf.conf_value FROM ::config AS cf')->fetchAll(PDO::FETCH_KEY_PAIR);
|
||||
$query = 'SELECT cf.conf_name, cf.conf_value
|
||||
FROM ::config AS cf';
|
||||
|
||||
$config = $this->c->DB->query($query)->fetchAll(PDO::FETCH_KEY_PAIR);
|
||||
$this->model->setAttrs($config);
|
||||
$this->c->Cache->set('config', $config);
|
||||
|
||||
|
|
|
@ -101,7 +101,7 @@ class Save extends Action
|
|||
$query = 'INSERT INTO ::forums (' . \implode(', ', $set) . ')
|
||||
VALUES (' . \implode(', ', $set2) . ')';
|
||||
|
||||
$this->c->DB->query($query, $vars);
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$forum->id = $this->c->DB->lastInsertId();
|
||||
$forum->resModified();
|
||||
|
||||
|
|
|
@ -38,7 +38,11 @@ class Manager extends ManagerModel
|
|||
public function init(): self
|
||||
{
|
||||
if (empty($this->flag)) {
|
||||
$stmt = $this->c->DB->query('SELECT g.* FROM ::groups AS g ORDER BY g.g_id');
|
||||
$query = 'SELECT g.*
|
||||
FROM ::groups AS g
|
||||
ORDER BY g.g_id';
|
||||
|
||||
$stmt = $this->c->DB->query($query);
|
||||
while ($row = $stmt->fetch()) {
|
||||
$this->set($row['g_id'], $this->create($row));
|
||||
}
|
||||
|
|
|
@ -115,8 +115,11 @@ class Perm extends Action
|
|||
$list[] = 'group_id';
|
||||
$list[] = 'forum_id';
|
||||
$list2 = \array_fill(0, \count($list), '?i');
|
||||
$query = 'INSERT INTO ::forum_perms (' . \implode(', ', $list) . ')
|
||||
VALUES (' . \implode(', ', $list2) . ')';
|
||||
|
||||
$list = \implode(', ', $list);
|
||||
$list2 = \implode(', ', $list2);
|
||||
$query = "INSERT INTO ::forum_perms ({$list})
|
||||
VALUES ({$list2})";
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,13 @@ class Save extends Action
|
|||
return $group;
|
||||
}
|
||||
$vars[] = $group->g_id;
|
||||
$this->c->DB->query('UPDATE ::groups SET ' . \implode(', ', $set) . ' WHERE g_id=?i', $vars);
|
||||
|
||||
$set = \implode(', ', $set);
|
||||
$query = "UPDATE ::groups
|
||||
SET {$set}
|
||||
WHERE g_id=?i";
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$group->resModified();
|
||||
|
||||
return $group;
|
||||
|
@ -74,7 +80,12 @@ class Save extends Action
|
|||
if (empty($set)) {
|
||||
throw new RuntimeException('The model is empty');
|
||||
}
|
||||
$this->c->DB->query('INSERT INTO ::groups (' . \implode(', ', $set) . ') VALUES (' . \implode(', ', $set2) . ')', $vars);
|
||||
$set = \implode(', ', $set);
|
||||
$set2 = \implode(', ', $set2);
|
||||
$query = "INSERT INTO ::groups ({$set})
|
||||
VALUES ({$set2})";
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$group->g_id = $this->c->DB->lastInsertId();
|
||||
$group->resModified();
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ class Model extends ParentModel
|
|||
FROM ::online AS o
|
||||
ORDER BY o.logged';
|
||||
}
|
||||
|
||||
$stmt = $this->c->DB->query($query);
|
||||
|
||||
$query = 'UPDATE ::users
|
||||
|
@ -84,7 +85,7 @@ class Model extends ParentModel
|
|||
':id' => $cur['user_id'],
|
||||
];
|
||||
|
||||
$this->c->DB->exec($query, $vars); //????
|
||||
$this->c->DB->exec($query, $vars);
|
||||
}
|
||||
}
|
||||
continue;
|
||||
|
|
|
@ -40,7 +40,13 @@ class Save extends Action
|
|||
return $post;
|
||||
}
|
||||
$vars[] = $post->id;
|
||||
$this->c->DB->query('UPDATE ::posts SET ' . \implode(', ', $set) . ' WHERE id=?i', $vars);
|
||||
|
||||
$set = \implode(', ', $set);
|
||||
$query = "UPDATE ::posts
|
||||
SET {$set}
|
||||
WHERE id=?i";
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$post->resModified();
|
||||
|
||||
return $post;
|
||||
|
@ -74,7 +80,12 @@ class Save extends Action
|
|||
if (empty($set)) {
|
||||
throw new RuntimeException('The model is empty');
|
||||
}
|
||||
$this->c->DB->query('INSERT INTO ::posts (' . \implode(', ', $set) . ') VALUES (' . \implode(', ', $set2) . ')', $vars);
|
||||
$set = \implode(', ', $set);
|
||||
$set2 = \implode(', ', $set2);
|
||||
$query = "INSERT INTO ::posts ({$set})
|
||||
VALUES ({$set2})";
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$post->id = $this->c->DB->lastInsertId();
|
||||
$post->resModified();
|
||||
|
||||
|
|
|
@ -40,7 +40,13 @@ class Save extends Action
|
|||
return $report;
|
||||
}
|
||||
$vars[] = $report->id;
|
||||
$this->c->DB->query('UPDATE ::reports SET ' . \implode(', ', $set) . ' WHERE id=?i', $vars);
|
||||
|
||||
$set = \implode(', ', $set);
|
||||
$query = "UPDATE ::reports
|
||||
SET {$set}
|
||||
WHERE id=?i";
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$report->resModified();
|
||||
|
||||
return $report;
|
||||
|
@ -77,7 +83,12 @@ class Save extends Action
|
|||
if (empty($set)) {
|
||||
throw new RuntimeException('The model is empty');
|
||||
}
|
||||
$this->c->DB->query('INSERT INTO ::reports (' . \implode(', ', $set) . ') VALUES (' . \implode(', ', $set2) . ')', $vars);
|
||||
$set = \implode(', ', $set);
|
||||
$set2 = \implode(', ', $set2);
|
||||
$query = "INSERT INTO ::reports ({$set})
|
||||
VALUES ({$set2})";
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$report->id = $this->c->DB->lastInsertId();
|
||||
$report->resModified();
|
||||
|
||||
|
|
|
@ -79,8 +79,9 @@ class Index extends Method
|
|||
$newWords = \array_diff($allWords, $oldWords);
|
||||
|
||||
if (! empty($newWords)) {
|
||||
$query = 'INSERT INTO ::search_words (word) VALUES(?s:word)';
|
||||
$stmt = null;
|
||||
$query = 'INSERT INTO ::search_words (word)
|
||||
VALUES(?s:word)';
|
||||
$stmt = null;
|
||||
foreach ($newWords as $word) {
|
||||
if (null === $stmt) {
|
||||
$stmt = $this->c->DB->prepare($query, [':word' => $word]);
|
||||
|
|
|
@ -16,7 +16,11 @@ class Load extends Method
|
|||
*/
|
||||
public function load(): SmileyList
|
||||
{
|
||||
$list = $this->c->DB->query('SELECT sm.text, sm.image FROM ::smilies AS sm ORDER BY sm.disp_position')->fetchAll(PDO::FETCH_KEY_PAIR); //???? text уникальное?
|
||||
$query = 'SELECT sm.text, sm.image
|
||||
FROM ::smilies AS sm
|
||||
ORDER BY sm.disp_position';
|
||||
|
||||
$list = $this->c->DB->query($query)->fetchAll(PDO::FETCH_KEY_PAIR); //???? text уникальное?
|
||||
$this->model->list = $list;
|
||||
$this->c->Cache->set('smilies', $list);
|
||||
|
||||
|
|
|
@ -23,7 +23,10 @@ class Model extends ParentModel
|
|||
$this->userTotal = $list['total'];
|
||||
$this->userLast = $list['last'];
|
||||
|
||||
list($this->topicTotal, $this->postTotal) = $this->c->DB->query('SELECT SUM(f.num_topics), SUM(f.num_posts) FROM ::forums AS f')->fetch(PDO::FETCH_NUM);
|
||||
$query = 'SELECT SUM(f.num_topics), SUM(f.num_posts)
|
||||
FROM ::forums AS f';
|
||||
|
||||
list($this->topicTotal, $this->postTotal) = $this->c->DB->query($query)->fetch(PDO::FETCH_NUM);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
@ -402,7 +402,7 @@ class Model extends DataModel
|
|||
SET num_views=num_views+1
|
||||
WHERE id=?i:tid';
|
||||
|
||||
$this->c->DB->query($query, $vars);
|
||||
$this->c->DB->exec($query, $vars);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -40,7 +40,13 @@ class Save extends Action
|
|||
return $topic;
|
||||
}
|
||||
$vars[] = $topic->id;
|
||||
$this->c->DB->query('UPDATE ::topics SET ' . \implode(', ', $set) . ' WHERE id=?i', $vars);
|
||||
|
||||
$set = \implode(', ', $set);
|
||||
$query = "UPDATE ::topics
|
||||
SET {$set}
|
||||
WHERE id=?i";
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$topic->resModified();
|
||||
|
||||
return $topic;
|
||||
|
@ -74,7 +80,12 @@ class Save extends Action
|
|||
if (empty($set)) {
|
||||
throw new RuntimeException('The model is empty');
|
||||
}
|
||||
$this->c->DB->query('INSERT INTO ::topics (' . \implode(', ', $set) . ') VALUES (' . \implode(', ', $set2) . ')', $vars);
|
||||
$set = \implode(', ', $set);
|
||||
$set2 = \implode(', ', $set2);
|
||||
$query = "INSERT INTO ::topics ({$set})
|
||||
VALUES ({$set2})";
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$topic->id = $this->c->DB->lastInsertId();
|
||||
$topic->resModified();
|
||||
|
||||
|
|
|
@ -68,10 +68,28 @@ class Current extends Action
|
|||
$data = null;
|
||||
$ip = $this->getIp();
|
||||
if ($id > 1) {
|
||||
$data = $this->c->DB->query('SELECT u.*, g.*, o.logged FROM ::users AS u INNER JOIN ::groups AS g ON u.group_id=g.g_id LEFT JOIN ::online AS o ON o.user_id=u.id WHERE u.id=?i:id', [':id' => $id])->fetch();
|
||||
$vars = [
|
||||
':id' => $id,
|
||||
];
|
||||
$query = 'SELECT u.*, g.*, o.logged
|
||||
FROM ::users AS u
|
||||
INNER JOIN ::groups AS g ON u.group_id=g.g_id
|
||||
LEFT JOIN ::online AS o ON o.user_id=u.id
|
||||
WHERE u.id=?i:id';
|
||||
|
||||
$data = $this->c->DB->query($query, $vars)->fetch();
|
||||
}
|
||||
if (empty($data['id'])) {
|
||||
$data = $this->c->DB->query('SELECT u.*, g.*, o.logged, o.last_post, o.last_search FROM ::users AS u INNER JOIN ::groups AS g ON u.group_id=g.g_id LEFT JOIN ::online AS o ON (o.user_id=1 AND o.ident=?s:ip) WHERE u.id=1', [':ip' => $ip])->fetch();
|
||||
$vars = [
|
||||
':ip' => $ip,
|
||||
];
|
||||
$query = 'SELECT u.*, g.*, o.logged, o.last_post, o.last_search
|
||||
FROM ::users AS u
|
||||
INNER JOIN ::groups AS g ON u.group_id=g.g_id
|
||||
LEFT JOIN ::online AS o ON (o.user_id=1 AND o.ident=?s:ip)
|
||||
WHERE u.id=1';
|
||||
|
||||
$data = $this->c->DB->query($query, $vars)->fetch();
|
||||
if (empty($data['id'])) {
|
||||
throw new RuntimeException('Unable to fetch guest information. Your database must contain both a guest user and a guest user group');
|
||||
}
|
||||
|
|
|
@ -16,12 +16,16 @@ class IsUniqueName extends Action
|
|||
*/
|
||||
public function isUniqueName(User $user): bool
|
||||
{
|
||||
$vars = [
|
||||
$vars = [
|
||||
':id' => (int) $user->id,
|
||||
':name' => $user->username,
|
||||
':other' => \preg_replace('%[^\p{L}\p{N}]%u', '', $user->username), //???? что за бред :)
|
||||
];
|
||||
$result = $this->c->DB->query('SELECT u.username FROM ::users AS u WHERE (LOWER(u.username)=LOWER(?s:name) OR LOWER(u.username)=LOWER(?s:other)) AND u.id!=?i:id', $vars)->fetchAll();
|
||||
$query = 'SELECT u.username
|
||||
FROM ::users AS u
|
||||
WHERE (LOWER(u.username)=LOWER(?s:name) OR LOWER(u.username)=LOWER(?s:other)) AND u.id!=?i:id';
|
||||
|
||||
$result = $this->c->DB->query($query, $vars)->fetchAll();
|
||||
|
||||
return ! \count($result);
|
||||
}
|
||||
|
|
|
@ -63,7 +63,12 @@ class Save extends Action
|
|||
} else {
|
||||
$vars[] = $user->id;
|
||||
}
|
||||
$this->c->DB->query('UPDATE ::' . $table . ' SET ' . \implode(', ', $set) . ' WHERE ' . $where, $vars);
|
||||
$set = \implode(', ', $set);
|
||||
$query = "UPDATE ::{$table}
|
||||
SET {$set}
|
||||
WHERE {$where}";
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$user->resModified();
|
||||
|
||||
if ($grChange) {
|
||||
|
@ -102,7 +107,12 @@ class Save extends Action
|
|||
if (empty($set)) {
|
||||
throw new RuntimeException('The model is empty');
|
||||
}
|
||||
$this->c->DB->query('INSERT INTO ::users (' . \implode(', ', $set) . ') VALUES (' . \implode(', ', $set2) . ')', $vars);
|
||||
$set = \implode(', ', $set);
|
||||
$set2 = \implode(', ', $set2);
|
||||
$query = "INSERT INTO ::users ({$set})
|
||||
VALUES ({$set2})";
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$user->id = $this->c->DB->lastInsertId();
|
||||
$user->resModified();
|
||||
|
||||
|
|
|
@ -13,8 +13,19 @@ class Stats extends Action
|
|||
*/
|
||||
public function stats(): array
|
||||
{
|
||||
$total = $this->c->DB->query('SELECT COUNT(u.id)-1 FROM ::users AS u WHERE u.group_id!=0')->fetchColumn();
|
||||
$last = $this->c->DB->query('SELECT u.id, u.username FROM ::users AS u WHERE u.group_id!=0 ORDER BY u.registered DESC LIMIT 1')->fetch();
|
||||
$query = 'SELECT COUNT(u.id)-1
|
||||
FROM ::users AS u
|
||||
WHERE u.group_id!=0';
|
||||
|
||||
$total = $this->c->DB->query($query)->fetchColumn();
|
||||
|
||||
$query = 'SELECT u.id, u.username
|
||||
FROM ::users AS u
|
||||
WHERE u.group_id!=0
|
||||
ORDER BY u.registered DESC
|
||||
LIMIT 1';
|
||||
|
||||
$last = $this->c->DB->query($query)->fetch();
|
||||
|
||||
return [
|
||||
'total' => $total,
|
||||
|
|
|
@ -21,7 +21,15 @@ class UpdateLastVisit extends Action
|
|||
throw new RuntimeException('Expected user');
|
||||
}
|
||||
if ($user->logged > 0) {
|
||||
$this->c->DB->exec('UPDATE ::users SET last_visit=?i:loggid WHERE id=?i:id', [':loggid' => $user->logged, ':id' => $user->id]);
|
||||
$vars = [
|
||||
':loggid' => $user->logged,
|
||||
':id' => $user->id,
|
||||
];
|
||||
$query = 'UPDATE ::users
|
||||
SET last_visit=?i:loggid
|
||||
WHERE id=?i:id';
|
||||
|
||||
$this->c->DB->exec($query, $vars);
|
||||
$user->__last_visit = $user->logged;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue