feat: replace POT Query Builder to Eloquent ORM (#230)

* wip

* wip

* wip

* wip

* wip

* fix: reusing pdo connection from pot

* wip

* wip

* wip

* wip

* move files

In future, all classes will be in src/ folder

* Replace namespace name, for future

* Remove duplicated exception

* Fix towns from db

* Fix spells page

* Add default FAQ question + FAQ model

* feat: reset colors in menus

* Add confirm + save button at the top (menus)

* Do not insert duplicated FAQ on install

* Refactor install menus

* Fix changelogs showing

* Fix menu update, only with specified template name

* Fix account create -> missing compat

* Fix bans_per_page

* banned_by is player_id. type = 2 is namelock in tfs 0.3

* Add getPlayerNameById, fix getPlayerNameByAccount

* Change link name

* Order by lastlogin

* fix: query optimize

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* Refactor notepad.php, class was useless

* This is showing error, if the updated rows = 0

* Fix success & error class (bootstrap)

* Uncomment require migrate.php

* Some distro have owner_id

* Update Player.php

---------

Co-authored-by: slawkens <slawkens@gmail.com>
This commit is contained in:
Gabriel Pedro
2023-08-21 04:16:58 -04:00
committed by GitHub
parent b72e7a3d96
commit a692607c5e
95 changed files with 1809 additions and 933 deletions

View File

@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\Player;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Change Comment';
@@ -17,36 +20,36 @@ if(!$logged) {
return;
}
$player = null;
$player_name = isset($_REQUEST['name']) ? stripslashes(urldecode($_REQUEST['name'])) : null;
$new_comment = isset($_POST['comment']) ? htmlspecialchars(stripslashes(substr($_POST['comment'],0,2000))) : NULL;
$new_hideacc = isset($_POST['accountvisible']) ? (int)$_POST['accountvisible'] : NULL;
if($player_name != null) {
if (Validator::characterName($player_name)) {
$player = new OTS_Player();
$player->find($player_name);
if ($player->isLoaded()) {
$player_account = $player->getAccount();
if ($account_logged->getId() == $player_account->getId()) {
if ($player->isDeleted()) {
$errors[] = 'This character is deleted.';
$player = null;
}
$player = Player::query()
->where('name', $player_name)
->where('account_id', $account_logged->getId())
->first();
if (isset($_POST['changecommentsave']) && $_POST['changecommentsave'] == 1) {
if(empty($errors)) {
$player->setCustomField("hidden", $new_hideacc);
$player->setCustomField("comment", $new_comment);
$account_logged->logAction('Changed comment for character <b>' . $player->getName() . '</b>.');
$twig->display('success.html.twig', array(
'title' => 'Character Information Changed',
'description' => 'The character information has been changed.'
));
$show_form = false;
}
if ($player) {
if ($player->is_deleted) {
$errors[] = 'This character is deleted.';
$player = null;
}
if (isset($_POST['changecommentsave']) && $_POST['changecommentsave'] == 1) {
if(empty($errors)) {
$player->hidden = $new_hideacc;
$player->comment = $new_comment;
$player->save();
$account_logged->logAction('Changed comment for character <b>' . $player->name . '</b>.');
$twig->display('success.html.twig', array(
'title' => 'Character Information Changed',
'description' => 'The character information has been changed.'
));
$show_form = false;
}
} else {
$errors[] = 'Error. Character <b>' . $player_name . '</b> is not on your account.';
}
} else {
$errors[] = "Error. Character with this name doesn't exist.";
@@ -64,9 +67,9 @@ if($show_form) {
$twig->display('error_box.html.twig', array('errors' => $errors));
}
if(isset($player) && $player->isLoaded()) {
if(isset($player) && $player) {
$twig->display('account.change_comment.html.twig', array(
'player' => $player
'player' => $player->toArray()
));
}
}

View File

@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\Account;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Change Info';
@@ -20,6 +23,8 @@ if(!$logged) {
if($config['account_country'])
require SYSTEM . 'countries.conf.php';
$account = Account::find($account_logged->getId());
$show_form = true;
$new_rlname = isset($_POST['info_rlname']) ? htmlspecialchars(stripslashes($_POST['info_rlname'])) : NULL;
$new_location = isset($_POST['info_location']) ? htmlspecialchars(stripslashes($_POST['info_location'])) : NULL;
@@ -30,9 +35,10 @@ if(isset($_POST['changeinfosave']) && $_POST['changeinfosave'] == 1) {
if(empty($errors)) {
//save data from form
$account_logged->setCustomField("rlname", $new_rlname);
$account_logged->setCustomField("location", $new_location);
$account_logged->setCustomField("country", $new_country);
$account->rlname = $new_rlname;
$account->location = $new_location;
$account->country = $new_country;
$account->save();
$account_logged->logAction('Changed Real Name to <b>' . $new_rlname . '</b>, Location to <b>' . $new_location . '</b> and Country to <b>' . $config['countries'][$new_country] . '</b>.');
$twig->display('success.html.twig', array(
'title' => 'Public Information Changed',
@@ -47,10 +53,10 @@ if(isset($_POST['changeinfosave']) && $_POST['changeinfosave'] == 1) {
//show form
if($show_form) {
$account_rlname = $account_logged->getCustomField("rlname");
$account_location = $account_logged->getCustomField("location");
$account_rlname = $account->rlname;
$account_location = $account->location;
if ($config['account_country']) {
$account_country = $account_logged->getCustomField("country");
$account_country = $account->country;
$countries = array();
foreach (array('pl', 'se', 'br', 'us', 'gb',) as $country)

View File

@@ -7,6 +7,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\Account;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Confirm Email';
@@ -17,14 +20,12 @@ if(empty($hash)) {
return;
}
$res = $db->query('SELECT `email_hash` FROM `accounts` WHERE `email_hash` = ' . $db->quote($hash));
if(!$res->rowCount()) {
if(!Account::where('email_hash', $hash)->exists()) {
note("Your email couldn't be verified. Please contact staff to do it manually.");
}
else
{
$query = $db->query('SELECT id FROM accounts WHERE email_hash = ' . $db->quote($hash) . ' AND email_verified = 0');
if ($query->rowCount() == 1) {
if (Account::where('email_hash', $hash)->where('email_verified', 0)->exists()) {
$query = $query->fetch(PDO::FETCH_ASSOC);
$account = new OTS_Account();
$account->load($query['id']);
@@ -33,7 +34,7 @@ else
}
}
$db->update('accounts', array('email_verified' => '1'), array('email_hash' => $hash));
Account::where('email_hash', $hash)->update('email_verified', 1);
success('You have now verified your e-mail, this will increase the security of your account. Thank you for doing this.');
}
?>

View File

@@ -11,8 +11,8 @@
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Bans list';
$configBansPerPage = config('bans_per_page');
$_page = isset($_GET['page']) ? $_GET['page'] : 1;
$configBansPerPage = setting('core.bans_per_page');
$_page = $_GET['page'] ?? 1;
if(!is_numeric($_page) || $_page < 1 || $_page > PHP_INT_MAX) {
$_page = 1;

View File

@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\BugTracker;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Bug tracker';
@@ -29,10 +32,10 @@ $showed = $post = $reply = false;
if(admin() and isset($_REQUEST['control']) && $_REQUEST['control'] == "true")
{
if(empty($_REQUEST['id']) and empty($_REQUEST['acc']) or !is_numeric($_REQUEST['acc']) or !is_numeric($_REQUEST['id']) )
$bug[1] = $db->query('SELECT * FROM '.$db->tableName(TABLE_PREFIX . 'bugtracker').' where `type` = 1 order by `uid` desc');
$bug[1] = BugTracker::where('type', 1)->orderByDesc('uid')->get()->toArray();
if(!empty($_REQUEST['id']) and is_numeric($_REQUEST['id']) and !empty($_REQUEST['acc']) and is_numeric($_REQUEST['acc']))
$bug[2] = $db->query('SELECT * FROM '.$db->tableName(TABLE_PREFIX . 'bugtracker').' where `account` = '.$_REQUEST['acc'].' and `id` = '.$_REQUEST['id'].' and `type` = 1')->fetch();
$bug[2] = BugTracker::where('type', 1)->where('account', $_REQUEST['acc'])->where('id', $_REQUEST['id'])->get()->toArray();
if(!empty($_REQUEST['id']) and is_numeric($_REQUEST['id']) and !empty($_REQUEST['acc']) and is_numeric($_REQUEST['acc']))
{
@@ -67,7 +70,7 @@ $showed = $post = $reply = false;
echo '<TR BGCOLOR="'.$light.'"><td colspan=2>'.nl2br($bug[2]['text']).'</td></tr>';
echo '</TABLE>';
$answers = $db->query('SELECT * FROM '.$db->tableName(TABLE_PREFIX . 'bugtracker').' where `account` = '.$_REQUEST['acc'].' and `id` = '.$_REQUEST['id'].' and `type` = 2 order by `reply`');
$answers = BugTracker::where('account', $_REQUEST['acc'])->where('id', $_REQUEST['id'])->where('type', 2)->orderBy('reply')->get()->toArray();
foreach($answers as $answer)
{
if($answer['who'] == 1)
@@ -88,9 +91,9 @@ $showed = $post = $reply = false;
{
if($bug[2]['status'] != 3)
{
$reply = $db->query('SELECT MAX(reply) FROM `' . TABLE_PREFIX . 'bugtracker` where `account` = '.$_REQUEST['acc'].' and `id` = '.$_REQUEST['id'].' and `type` = 2')->fetch();
$reply = $reply[0] + 1;
$iswho = $db->query('SELECT * FROM `' . TABLE_PREFIX . 'bugtracker` where `account` = '.$_REQUEST['acc'].' and `id` = '.$_REQUEST['id'].' and `type` = 2 order by `reply` desc limit 1')->fetch();
$reply = BugTracker::where('account', $_REQUEST['acc'])->where('id', $_REQUEST['id'])->where('type', 2)->max('reply');
$reply = $reply + 1;
$iswho = BugTracker::where('account', $_REQUEST['acc'])->where('id', $_REQUEST['id'])->where('type', 2)->orderByDesc('reply')->first()->toArray();
if(isset($_POST['finish']))
{
@@ -109,8 +112,17 @@ $showed = $post = $reply = false;
else
{
$type = 2;
$INSERT = $db->query('INSERT INTO `' . TABLE_PREFIX . 'bugtracker` (`account`,`id`,`text`,`reply`,`type`, `who`) VALUES ('.$db->quote($_REQUEST['acc']).','.$db->quote($_REQUEST['id']).','.$db->quote($_POST['text']).','.$db->quote($reply).','.$db->quote($type).','.$db->quote(1).')');
$UPDATE = $db->query('UPDATE `' . TABLE_PREFIX . 'bugtracker` SET `status` = '.$_POST['status'].' where `account` = '.$_REQUEST['acc'].' and `id` = '.$_REQUEST['id'].'');
$INSERT = BugTracker::create([
'account' => $_REQUEST['aac'],
'id' => $_REQUEST['id'],
'text' => $_POST['text'],
'reply' => $reply,
'type' => $type,
'who' => 1,
]);
$UPDATE = Bugtracker::where('id', $_REQUEST['id'])->where('account', $_REQUEST['acc'])->update([
'status' => $_POST['status']
]);
header('Location: ?subtopic=bugtracker&control=true&id='.$_REQUEST['id'].'&acc='.$_REQUEST['acc'].'');
}
}
@@ -159,10 +171,10 @@ $showed = $post = $reply = false;
$id = addslashes(htmlspecialchars(trim($_REQUEST['id'])));
if(empty($_REQUEST['id']))
$bug[1] = $db->query('SELECT * FROM '.$db->tableName(TABLE_PREFIX . 'bugtracker').' where `account` = '.$account_logged->getId().' and `type` = 1 order by `id` desc');
$bug[1] = BugTracker::where('account', $account_logged->getId())->where('type', 1)->orderBy('id')->get()->toArray();
if(!empty($_REQUEST['id']) and is_numeric($_REQUEST['id']))
$bug[2] = $db->query('SELECT * FROM '.$db->tableName(TABLE_PREFIX . 'bugtracker').' where `account` = '.$account_logged->getId().' and `id` = '.$id.' and `type` = 1')->fetch();
$bug[2] = BugTracker::where('account', $account_logged->getId())->where('type', 1)->where('id', $id)->get()->toArray();
else
$bug[2] = NULL;
@@ -186,7 +198,7 @@ $showed = $post = $reply = false;
echo '<TR BGCOLOR="'.$dark.'"><td colspan=2>'.nl2br($bug[2]['text']).'</td></tr>';
echo '</TABLE>';
$answers = $db->query('SELECT * FROM '.$db->tableName('myaac_bugtracker').' where `account` = '.$account_logged->getId().' and `id` = '.$id.' and `type` = 2 order by `reply`');
$answers = Bugtracker::where('account', $account_logged->getId())->where('id', $id)->where('type', 2)->orderBy('reply')->get()->toArray();
foreach($answers as $answer)
{
if($answer['who'] == 1)
@@ -207,9 +219,9 @@ $showed = $post = $reply = false;
{
if($bug[2]['status'] != 3)
{
$reply = $db->query('SELECT MAX(reply) FROM `' . TABLE_PREFIX . 'bugtracker` where `account` = '.$acc.' and `id` = '.$id.' and `type` = 2')->fetch();
$reply = $reply[0] + 1;
$iswho = $db->query('SELECT * FROM `myaac_bugtracker` where `account` = '.$acc.' and `id` = '.$id.' and `type` = 2 order by `reply` desc limit 1')->fetch();
$reply = BugTracker::where('account', $aac)->where('id', $id)->where('type', 2)->max('reply');
$reply = $reply + 1;
$iswho = BugTracker::where('account', $acc)->where('id', $id)->where('type', 2)->orderByDesc('reply')->first()->toArray();
if(isset($_POST['finish']))
{
@@ -228,8 +240,16 @@ $showed = $post = $reply = false;
else
{
$type = 2;
$INSERT = $db->query('INSERT INTO `myaac_bugtracker` (`account`,`id`,`text`,`reply`,`type`) VALUES ('.$db->quote($acc).','.$db->quote($id).','.$db->quote($_POST['text']).','.$db->quote($reply).','.$db->quote($type).')');
$UPDATE = $db->query('UPDATE `myaac_bugtracker` SET `status` = 1 where `account` = '.$acc.' and `id` = '.$id.'');
$INSERT = BugTracker::create([
'account' => $acc,
'id' => $id,
'text' => $_POST['text'],
'reply' => $reply,
'type' => $type
]);
$UPDATE = BugTracker::where('id', $id)->where('account', $acc)->update([
'status' => 1
]);
header('Location: ?subtopic=bugtracker&id='.$id.'');
}
}
@@ -289,9 +309,9 @@ $showed = $post = $reply = false;
}
elseif(isset($_REQUEST['add']) && $_REQUEST['add'] == TRUE)
{
$thread = $db->query('SELECT * FROM `' . TABLE_PREFIX . 'bugtracker` where `account` = '.$acc.' and `type` = 1 order by `id` desc')->fetch();
$id_next = $db->query('SELECT MAX(id) FROM `' . TABLE_PREFIX . 'bugtracker` where `account` = '.$acc.' and `type` = 1')->fetch();
$id_next = $id_next[0] + 1;
$thread = BugTracker::where('account', $acc)->where('type', 1)->orderByDesc('id')->get()->toArray();
$id_next = BugTracker::where('account', $acc)->where('type', 1)->max('id');
$id_next = $id_next + 1;
if(empty($thread))
$thread['status'] = 3;
@@ -318,7 +338,16 @@ $showed = $post = $reply = false;
{
$type = 1;
$status = 1;
$INSERT = $db->query('INSERT INTO `' . TABLE_PREFIX . 'bugtracker` (`account`,`id`,`text`,`type`,`subject`, `reply`,`status`,`tag`) VALUES ('.$db->quote($acc).','.$db->quote($id_next).','.$db->quote($_POST['text']).','.$db->quote($type).','.$db->quote($_POST['subject']).', 0,'.$db->quote($status).','.$db->quote($_POST['tags']).')');
$INSERT = BugTracker::create([
'account' => $acc,
'id' => $id_next,
'text' => $_POST['text'],
'type' => $type,
'subject' => $_POST['subject'],
'reply' => 0,
'status' => $status,
'tag' => $_POST['tags']
]);
header('Location: ?subtopic=bugtracker&id='.$id_next.'');
}

View File

@@ -10,6 +10,8 @@
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Changelog';
use MyAAC\Models\Changelog;
$_page = isset($_GET['page']) ? (int)$_GET['page'] : 0;
$limit = 30;
$offset = $_page * $limit;
@@ -17,7 +19,7 @@ $next_page = false;
$canEdit = hasFlag(FLAG_CONTENT_NEWS) || superAdmin();
$changelogs = $db->query('SELECT * FROM `' . TABLE_PREFIX . 'changelog` ' . ($canEdit ? '' : 'WHERE `hidden` = 0').' ORDER BY `id` DESC LIMIT ' . ($limit + 1) . ' OFFSET ' . $offset)->fetchAll();
$changelogs = Changelog::isPublic()->orderByDesc('id')->limit($limit + 1)->offset($offset)->get()->toArray();
$i = 0;
foreach($changelogs as $key => &$log)

View File

@@ -9,13 +9,18 @@
* @copyright 2020 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\Monster;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Creatures';
if (empty($_REQUEST['name'])) {
// display list of monsters
$preview = config('monsters_images_preview');
$creatures = $db->query('SELECT * FROM `' . TABLE_PREFIX . 'monsters` WHERE `hidden` != 1 '.(empty($_REQUEST['boss']) ? '': 'AND `rewardboss` = 1').' ORDER BY name asc')->fetchAll();
$creatures = Monster::where('hidden', '!=', 1)->when(!empty($_REQUEST['boss']), function ($query) {
$query->where('rewardboss', 1);
})->get()->toArray();
if ($preview) {
foreach($creatures as $key => &$creature)
@@ -34,9 +39,7 @@ if (empty($_REQUEST['name'])) {
// display monster
$creature_name = urldecode(stripslashes(ucwords(strtolower($_REQUEST['name']))));
$prep = $db->prepare('SELECT * FROM `' . TABLE_PREFIX . 'monsters` WHERE `hidden` != 1 AND `name` = ? LIMIT 1;');
$prep->execute([$creature_name]);
$creature = $prep->fetch();
$creature = Monster::where('hidden', '!=', 1)->where('name', $creature_name)->first()->toArray();
if (isset($creature['name'])) {
function sort_by_chance($a, $b)

View File

@@ -7,6 +7,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\FAQ as ModelsFAQ;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Frequently Asked Questions';
@@ -68,21 +71,23 @@ if($canEdit)
));
}
$faqs =
$db->query('SELECT `id`, `question`, `answer`' .
($canEdit ? ', `hidden`, `ordering`' : '') .
' FROM `' . TABLE_PREFIX . 'faq`' .
(!$canEdit ? ' WHERE `hidden` != 1' : '') .
' ORDER BY `ordering`;');
$faqs = ModelsFAQ::select('id', 'question', 'answer')->when(!$canEdit, function ($query) {
$query->where('hidden', '!=', 1);
})->orderBy('ordering');
if(!$faqs->rowCount())
if ($canEdit) {
$faqs->addSelect(['hidden', 'ordering']);
}
$faqs = $faqs->get()->toArray();
if(!count($faqs))
{
?>
There are no questions added yet.
<?php
}
$last = $faqs->rowCount();
$last = count($faqs);
$twig->display('faq.html.twig', array(
'faqs' => $faqs,
'last' => $last,
@@ -93,26 +98,17 @@ class FAQ
{
static public function add($question, $answer, &$errors)
{
global $db;
if(isset($question[0]) && isset($answer[0]))
{
$query = $db->select(TABLE_PREFIX . 'faq', array('question' => $question));
if($query === false)
$row = ModelsFAQ::where('question', $question)->first();
if(!$row)
{
$query =
$db->query(
'SELECT ' . $db->fieldName('ordering') .
' FROM ' . $db->tableName(TABLE_PREFIX . 'faq') .
' ORDER BY ' . $db->fieldName('ordering') . ' DESC LIMIT 1'
);
$ordering = 0;
if($query->rowCount() > 0) {
$query = $query->fetch();
$ordering = $query['ordering'] + 1;
}
$db->insert(TABLE_PREFIX . 'faq', array('question' => $question, 'answer' => $answer, 'ordering' => $ordering));
$ordering = ModelsFAQ::max('ordering') ?? 0;
ModelsFAQ::create([
'question' => $question,
'answer' => $answer,
'ordering' => $ordering
]);
}
else
$errors[] = 'FAQ with this question already exists.';
@@ -124,22 +120,23 @@ class FAQ
}
static public function get($id) {
global $db;
return $db->select(TABLE_PREFIX . 'faq', array('id' => $id));
return ModelsFAQ::find($id)->toArray();
}
static public function update($id, $question, $answer) {
global $db;
$db->update(TABLE_PREFIX . 'faq', array('question' => $question, 'answer' => $answer), array('id' => $id));
ModelsFAQ::where('id', $id)->update([
'question' => $question,
'answer' => $answer
]);
}
static public function delete($id, &$errors)
{
global $db;
if(isset($id))
{
if(self::get($id) !== false)
$db->delete(TABLE_PREFIX . 'faq', array('id' => $id));
$row = ModelsFAQ::find($id);
if($row)
$row->delete();
else
$errors[] = 'FAQ with id ' . $id . ' does not exists.';
}
@@ -151,14 +148,15 @@ class FAQ
static public function toggleHidden($id, &$errors)
{
global $db;
if(isset($id))
{
$query = self::get($id);
if($query !== false)
$db->update(TABLE_PREFIX . 'faq', array('hidden' => ($query['hidden'] == 1 ? 0 : 1)), array('id' => $id));
else
$row = ModelsFAQ::find($id);
if ($row) {
$row->hidden = ($row->hidden == 1 ? 0 : 1);
$row->save();
} else {
$errors[] = 'FAQ with id ' . $id . ' does not exists.';
}
}
else
$errors[] = 'id not set';
@@ -169,15 +167,18 @@ class FAQ
static public function move($id, $i, &$errors)
{
global $db;
$query = self::get($id);
if($query !== false)
$row = ModelsFAQ::find($id);
if($row)
{
$ordering = $query['ordering'] + $i;
$old_record = $db->select(TABLE_PREFIX . 'faq', array('ordering' => $ordering));
if($old_record !== false)
$db->update(TABLE_PREFIX . 'faq', array('ordering' => $query['ordering']), array('ordering' => $ordering));
$ordering = $row->ordering + $i;
$old_record = ModelsFAQ::where('ordering', $ordering)->first();
if($old_record) {
$old_record->ordering = $row->ordering;
$old_record->save();
}
$db->update(TABLE_PREFIX . 'faq', array('ordering' => $ordering), array('id' => $id));
$row->ordering = $ordering;
$row->save();
}
else
$errors[] = 'FAQ with id ' . $id . ' does not exists.';

View File

@@ -7,6 +7,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\Gallery as ModelsGallery;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Gallery';
@@ -164,22 +167,19 @@ class Gallery
}
static public function get($id) {
global $db;
return $db->select(TABLE_PREFIX . 'gallery', array('id' => $id));
return ModelsGallery::find($id)->toArray();
}
static public function update($id, $comment, $image, $author) {
global $db;
$pathinfo = pathinfo($image);
$extension = strtolower($pathinfo['extension']);
$filename = GALLERY_DIR . $pathinfo['filename'] . '.' . $extension;
if($db->update(TABLE_PREFIX . 'gallery', array(
if(ModelsGallery::where('id', $id)->update([
'comment' => $comment,
'image' => $filename, 'author' => $author),
array('id' => $id)
)) {
'image' => $filename,
'author' => $author
])) {
if(self::generateThumb($id, $image, $errors))
self::resize($image, 650, 500, $filename, $errors);
}
@@ -187,11 +187,13 @@ class Gallery
static public function delete($id, &$errors)
{
global $db;
if(isset($id))
{
if(self::get($id) !== false)
$db->delete(TABLE_PREFIX . 'gallery', array('id' => $id));
$row = ModelsGallery::find($id);
if($row)
if (!$row->delete()) {
$errors[] = 'Fail during delete Gallery';
}
else
$errors[] = 'Image with id ' . $id . ' does not exists.';
}
@@ -203,13 +205,15 @@ class Gallery
static public function toggleHidden($id, &$errors)
{
global $db;
if(isset($id))
{
$query = self::get($id);
if($query !== false)
$db->update(TABLE_PREFIX . 'gallery', array('hidden' => ($query['hidden'] == 1 ? 0 : 1)), array('id' => $id));
else
$row = ModelsGallery::find($id);
if($row) {
$row->hidden = $row->hidden == 1 ? 0 : 1;
if (!$row->save()) {
$errors[] = 'Fail during toggle hidden Gallery';
}
} else
$errors[] = 'Image with id ' . $id . ' does not exists.';
}
else
@@ -226,10 +230,15 @@ class Gallery
{
$ordering = $query['ordering'] + $i;
$old_record = $db->select(TABLE_PREFIX . 'gallery', array('ordering' => $ordering));
if($old_record !== false)
$db->update(TABLE_PREFIX . 'gallery', array('ordering' => $query['ordering']), array('ordering' => $ordering));
if($old_record !== false) {
ModelsGallery::where('ordering', $ordering)->update([
'ordering' => $query['ordering'],
]);
}
$db->update(TABLE_PREFIX . 'gallery', array('ordering' => $ordering), array('id' => $id));
ModelsGallery::where('id', $id)->update([
'ordering' => $ordering,
]);
}
else
$errors[] = 'Image with id ' . $id . ' does not exists.';
@@ -297,13 +306,13 @@ class Gallery
if(!self::resize($file, 170, 110, $thumb_filename, $errors))
return false;
global $db;
if(isset($id))
{
$query = self::get($id);
if($query !== false)
$db->update(TABLE_PREFIX . 'gallery', array('thumb' => $thumb_filename), array('id' => $id));
else
$row = ModelsGallery::find($id);
if($row) {
$row->thumb = $thumb_filename;
$row->save();
} else
$errors[] = 'Image with id ' . $id . ' does not exists.';
}
else

View File

@@ -8,6 +8,11 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\Player;
use MyAAC\Models\PlayerDeath;
use MyAAC\Models\PlayerKillers;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Highscores';
@@ -23,7 +28,7 @@ if(!is_numeric($page) || $page < 1 || $page > PHP_INT_MAX) {
$page = 1;
}
$add_sql = '';
$query = Player::query();
$settingHighscoresVocationBox = setting('core.highscores_vocation_box');
$configVocations = config('vocations');
@@ -41,7 +46,7 @@ if($settingHighscoresVocationBox && $vocation !== 'all')
$i += $configVocationsAmount;
}
$add_sql = 'AND `vocation` IN (' . implode(', ', $add_vocs) . ')';
$query->whereIn('players.vocation', $add_vocs);
break;
}
}
@@ -112,15 +117,7 @@ else
$promotion = '';
if($db->hasColumn('players', 'promotion'))
$promotion = ',promotion';
$online = '';
if($db->hasColumn('players', 'online'))
$online = ',online';
$deleted = 'deleted';
if($db->hasColumn('players', 'deletion'))
$deleted = 'deletion';
$promotion = ',players.promotion';
$outfit_addons = false;
$outfit = '';
@@ -151,6 +148,16 @@ if ($cache->enabled()) {
}
$offset = ($page - 1) * $configHighscoresPerPage;
$query->join('accounts', 'accounts.id', '=', 'players.account_id')
->withOnlineStatus()
->whereNotIn('players.id', setting('core.highscores_ids_hidden'))
->notDeleted()
->where('players.group_id', '<', setting('core.highscores_groups_hidden'))
->limit($limit)
->offset($offset)
->selectRaw('accounts.country, players.id, players.name, players.account_id, players.level, players.vocation' . $outfit . $promotion)
->orderByDesc('value');
if (!isset($highscores) || empty($highscores)) {
if ($skill >= POT::SKILL_FIRST && $skill <= POT::SKILL_LAST) { // skills
if ($db->hasColumn('players', 'skill_fist')) {// tfs 1.0
@@ -164,66 +171,51 @@ if (!isset($highscores) || empty($highscores)) {
POT::SKILL_FISH => 'skill_fishing',
);
$highscores = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',level,vocation' . $promotion . $outfit . ', ' . $skill_ids[$skill] . ' as value FROM accounts,players WHERE players.id NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 AND players.group_id < ' . setting('core.highscores_groups_hidden') . ' ' . $add_sql . ' AND accounts.id = players.account_id ORDER BY ' . $skill_ids[$skill] . ' DESC LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
} else
$highscores = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',value,level,vocation' . $promotion . $outfit . ' FROM accounts,players,player_skills WHERE players.id NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 AND players.group_id < ' . setting('core.highscores_groups_hidden') . ' ' . $add_sql . ' AND players.id = player_skills.player_id AND player_skills.skillid = ' . $skill . ' AND accounts.id = players.account_id ORDER BY value DESC, count DESC LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$query->addSelect($skill_ids[$skill] . ' as value');
} else {
$query
->join('player_skills', 'player_skills.player_id', '=', 'players.id')
->where('skillid', $skill)
->addSelect('player_skills.skillid as value');
}
} else if ($skill == SKILL_FRAGS) // frags
{
if ($db->hasTable('player_killers')) {
$highscores = $db->query('SELECT accounts.country, players.id, players.name' . $online . ',level, vocation' . $promotion . $outfit . ', COUNT(`player_killers`.`player_id`) as value' .
' FROM `accounts`, `players`, `player_killers` ' .
' WHERE players.id NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 AND players.group_id < ' . setting('core.highscores_groups_hidden') . ' ' . $add_sql . ' AND players.id = player_killers.player_id AND accounts.id = players.account_id' .
' GROUP BY `player_id`' .
' ORDER BY value DESC' .
' LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$query->addSelect(['value' => PlayerKillers::where('player_killers.player_id', 'players.id')->selectRaw('COUNT(*)')]);
} else {
$db->query("SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));");
$highscores = $db->query('SELECT `a`.country, `p`.id, `p`.name' . $online . ',`p`.level, vocation' . $promotion . $outfit . ', COUNT(`pd`.`killed_by`) as value
FROM `players` p
LEFT JOIN `accounts` a ON `a`.`id` = `p`.`account_id`
LEFT JOIN `player_deaths` pd ON `pd`.`killed_by` = `p`.`name`
WHERE `p`.id NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ')
AND `p`.' . $deleted . ' = 0
AND `p`.group_id < ' . setting('core.highscores_groups_hidden') . ' ' . $add_sql . '
AND `pd`.`unjustified` = 1
GROUP BY `killed_by`
ORDER BY value DESC
LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$query->addSelect(['value' => PlayerDeath::unjustified()->where('player_deaths.killed_by', 'players.name')->selectRaw('COUNT(*)')]);
}
} else if ($skill == SKILL_BALANCE) // balance
{
$highscores = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',level,balance as value,vocation' . $promotion . $outfit . ' FROM accounts,players WHERE players.id NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 AND players.group_id < ' . setting('core.highscores_groups_hidden') . ' ' . $add_sql . ' AND accounts.id = players.account_id ORDER BY value DESC LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$query
->addSelect('players.balance as value');
} else {
if ($skill == POT::SKILL__MAGLEVEL) {
$highscores = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',maglevel,level,vocation' . $promotion . $outfit . ' FROM accounts, players WHERE players.id NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 ' . $add_sql . ' AND players.group_id < ' . setting('core.highscores_groups_hidden') . ' AND accounts.id = players.account_id ORDER BY maglevel DESC, manaspent DESC LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$query
->addSelect('players.maglevel as value', 'players.maglevel')
->orderBy('manaspent');
} else { // level
$highscores = $db->query('SELECT accounts.country, players.id,players.name' . $online . ',level,experience,vocation' . $promotion . $outfit . ' FROM accounts, players WHERE players.id NOT IN (' . implode(', ', setting('core.highscores_ids_hidden')) . ') AND players.' . $deleted . ' = 0 ' . $add_sql . ' AND players.group_id < ' . setting('core.highscores_groups_hidden') . ' AND accounts.id = players.account_id ORDER BY level DESC, experience DESC LIMIT ' . $limit . ' OFFSET ' . $offset)->fetchAll();
$query
->addSelect('players.level as value', 'players.experience')
->orderBy('experience');
$list = 'experience';
}
}
}
$highscores = $query->get()->map(function($row) {
$tmp = $row->toArray();
$tmp['online'] = $row->online_status;
$tmp['vocation'] = $row->vocation_name;
unset($tmp['online_table']);
return $tmp;
})->toArray();
if ($cache->enabled() && $needReCache) {
$cache->set($cacheKey, serialize($highscores), setting('core.highscores_cache_ttl') * 60);
}
$online_exist = false;
if($db->hasColumn('players', 'online'))
$online_exist = true;
$players = array();
foreach($highscores as $player) {
$players[] = $player['id'];
}
if($db->hasTable('players_online') && count($players) > 0) {
$query = $db->query('SELECT `player_id`, 1 FROM `players_online` WHERE `player_id` IN (' . implode(', ', $players) . ')')->fetchAll();
foreach($query as $t) {
$is_online[$t['player_id']] = true;
}
}
$show_link_to_next_page = false;
$i = 0;
@@ -231,14 +223,6 @@ $settingHighscoresVocation = setting('core.highscores_vocation');
foreach($highscores as $id => &$player)
{
if(isset($is_online)) {
$player['online'] = (isset($is_online[$player['id']]) ? 1 : 0);
} else {
if(!isset($player['online'])) {
$player['online'] = 0;
}
}
if(++$i <= $configHighscoresPerPage)
{
if($skill == POT::SKILL__MAGIC)
@@ -248,22 +232,10 @@ foreach($highscores as $id => &$player)
$player['experience'] = number_format($player['experience']);
}
if($settingHighscoresVocation) {
if(isset($player['promotion'])) {
if((int)$player['promotion'] > 0) {
$player['vocation'] += ($player['promotion'] * $configVocationsAmount);
}
}
$tmp = 'Unknown';
if(isset($configVocations[$player['vocation']])) {
$tmp = $configVocations[$player['vocation']];
}
$player['vocation'] = $tmp;
if(!$settingHighscoresVocation) {
unset($player['vocation']);
}
$player['link'] = getPlayerLink($player['name'], false);
$player['flag'] = getFlagImage($player['country']);
if($settingHighscoresOutfit) {

View File

@@ -8,6 +8,10 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\ServerConfig;
use MyAAC\Models\ServerRecord;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Who is online?';
@@ -98,21 +102,19 @@ foreach($playersOnline as $player) {
$record = '';
if($players > 0) {
if($config['online_record']) {
$result = null;
$timestamp = false;
if($db->hasTable('server_record')) {
$query =
$db->query(
'SELECT `record`, `timestamp` FROM `server_record` WHERE `world_id` = ' . (int)$config['lua']['worldId'] .
' ORDER BY `record` DESC LIMIT 1');
$timestamp = true;
$result = ServerRecord::where('world_id', $config['lua']['worldId'])->orderByDesc('record')->first()->toArray();
} else if($db->hasTable('server_config')) { // tfs 1.0
$query = $db->query('SELECT `value` as `record` FROM `server_config` WHERE `config` = ' . $db->quote('players_record'));
} else {
$query = NULL;
$row = ServerConfig::where('config', 'players_record')->first();
if ($row) {
$result = ['record' => $row->value];
}
}
if(isset($query) && $query->rowCount() > 0) {
$result = $query->fetch();
if($record) {
$record = 'The maximum on this game world was ' . $result['record'] . ' players' . ($timestamp ? ' on ' . date("M d Y, H:i:s", $result['timestamp']) . '.' : '.');
}
}

View File

@@ -8,10 +8,18 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\ServerRecord;
defined('MYAAC') or die('Direct access not allowed!');
$title = "Players Online Records";
if(!$db->hasTable('server_record')) {
echo 'Record History is not supported in your distribution.';
return;
}
echo '
<b><div style="text-align:center">Players online records on '.$config['lua']['serverName'].'</div></b>
<TABLE BORDER=0 CELLSPACING=1 CELLPADDING=4 WIDTH=100%>
@@ -21,7 +29,7 @@ echo '
</TR>';
$i = 0;
$records_query = $db->query('SELECT * FROM `server_record` ORDER BY `record` DESC LIMIT 50;');
$records_query = ServerRecord::limit(50)->orderByDesc('record')->get();
foreach($records_query as $data)
{
echo '<TR BGCOLOR=' . getStyle(++$i) . '>
@@ -31,4 +39,4 @@ echo '
}
echo '</TABLE>';
?>
?>

View File

@@ -8,6 +8,9 @@
* @copyright 2019 MyAAC
* @link https://my-aac.org
*/
use MyAAC\Models\Spell;
defined('MYAAC') or die('Direct access not allowed!');
$title = 'Spells';
@@ -34,10 +37,10 @@ else {
$order = 'name';
$spells = array();
$spells_db = $db->query('SELECT * FROM `' . TABLE_PREFIX . 'spells` WHERE `hidden` != 1 AND `type` < 4 ORDER BY ' . $order . '');
$spells_db = Spell::where('hidden', '!=', 1)->where('type', '<', 4)->orderBy($order)->get();
if((string)$vocation_id != 'all') {
foreach($spells_db->fetchAll() as $spell) {
foreach($spells_db as $spell) {
$spell_vocations = json_decode($spell['vocations'], true);
if(in_array($vocation_id, $spell_vocations) || count($spell_vocations) == 0) {
$spell['vocations'] = null;
@@ -46,7 +49,7 @@ if((string)$vocation_id != 'all') {
}
}
else {
foreach($spells_db->fetchAll() as $spell) {
foreach($spells_db as $spell) {
$vocations = json_decode($spell['vocations'], true);
foreach($vocations as &$tmp_vocation) {