mirror of
https://github.com/slawkens/myaac.git
synced 2025-10-14 09:44:55 +02:00
Move commands and downloads pages into database
Available under "Pages" in Admin Panel
This commit is contained in:
37
system/migrations/27.php
Normal file
37
system/migrations/27.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
$query = $db->query("SELECT `id` FROM `" . TABLE_PREFIX . "pages` WHERE `name` LIKE " . $db->quote('downloads') . " LIMIT 1;");
|
||||
if($query->rowCount() === 0) {
|
||||
$db->exec("INSERT INTO `myaac_pages` (`id`, `name`, `title`, `body`, `date`, `player_id`, `php`, `access`, `hidden`) VALUES
|
||||
(null, 'downloads', 'Downloads', '<p> </p>
|
||||
<p> </p>
|
||||
<div style=\"text-align: center;\">We''re using official Tibia Client <strong>{{ config.client / 100 }}</strong><br />
|
||||
<p>Download Tibia Client <strong>{{ config.client / 100 }}</strong> for Windows <a href=\"https://drive.google.com/drive/folders/0B2-sMQkWYzhGSFhGVlY2WGk5czQ\" target=\"_blank\" rel=\"noopener\">HERE</a>.</p>
|
||||
<h2>IP Changer:</h2>
|
||||
<a href=\"https://static.otland.net/ipchanger.exe\" target=\"_blank\" rel=\"noopener\">HERE</a></div>', 0, 1, 0, 1, 0);");
|
||||
}
|
||||
|
||||
$query = $db->query("SELECT `id` FROM `" . TABLE_PREFIX . "pages` WHERE `name` LIKE " . $db->quote('commands') . " LIMIT 1;");
|
||||
if($query->rowCount() === 0) {
|
||||
$db->exec("INSERT INTO `myaac_pages` (`id`, `name`, `title`, `body`, `date`, `player_id`, `php`, `access`, `hidden`) VALUES
|
||||
(null, 'commands', 'Commands', '<table style=\"border-collapse: collapse; width: 87.8471%; height: 57px;\" border=\"1\">
|
||||
<tbody>
|
||||
<tr style=\"height: 18px;\">
|
||||
<td style=\"width: 33.3333%; background-color: #505050; height: 18px;\"><span style=\"color: #ffffff;\"><strong>Words</strong></span></td>
|
||||
<td style=\"width: 33.3333%; background-color: #505050; height: 18px;\"><span style=\"color: #ffffff;\"><strong>Description</strong></span></td>
|
||||
</tr>
|
||||
<tr style=\"height: 18px; background-color: #f1e0c6;\">
|
||||
<td style=\"width: 33.3333%; height: 18px;\"><em>!example</em></td>
|
||||
<td style=\"width: 33.3333%; height: 18px;\">This is just an example</td>
|
||||
</tr>
|
||||
<tr style=\"height: 18px; background-color: #d4c0a1;\">
|
||||
<td style=\"width: 33.3333%; height: 18px;\"><em>!buyhouse</em></td>
|
||||
<td style=\"width: 33.3333%; height: 18px;\">Buy house you are looking at</td>
|
||||
</tr>
|
||||
<tr style=\"height: 18px; background-color: #f1e0c6;\">
|
||||
<td style=\"width: 33.3333%; height: 18px;\"><em>!aol</em></td>
|
||||
<td style=\"width: 33.3333%; height: 18px;\">Buy AoL</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>', 0, 1, 0, 1, 0);");
|
||||
}
|
@@ -1,193 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Commands
|
||||
*
|
||||
* @package MyAAC
|
||||
* @author Slawkens <slawkens@gmail.com>
|
||||
* @copyright 2019 MyAAC
|
||||
* @link https://my-aac.org
|
||||
*/
|
||||
defined('MYAAC') or die('Direct access not allowed!');
|
||||
$title = 'Commands';
|
||||
|
||||
if($config['otserv_version'] == TFS_03):
|
||||
?>
|
||||
List of all your commands, you can check in game, by writing - <b>/commands</b>.<br/><br/>
|
||||
<?php
|
||||
endif;
|
||||
?>
|
||||
<!--
|
||||
To get info ingame about specified command, you can write - <b>/man commandName</b> or <b>commandName man</b>. Example: <b>/man serverinfo</b>, <b>/man !sellhouse</b>, <b>!deathlist man</b>, <b>!buypremium man</b>.
|
||||
<br/><br/>
|
||||
-->
|
||||
|
||||
<?php
|
||||
$canEdit = hasFlag(FLAG_CONTENT_COMMANDS) || superAdmin();
|
||||
if($canEdit)
|
||||
{
|
||||
if(!empty($action))
|
||||
{
|
||||
if($action == 'delete' || $action == 'edit' || $action == 'hide' || $action == 'moveup' || $action == 'movedown')
|
||||
$id = $_REQUEST['id'];
|
||||
|
||||
if(isset($_REQUEST['words']))
|
||||
$words = $_REQUEST['words'];
|
||||
|
||||
if(isset($_REQUEST['description']))
|
||||
$description = stripslashes($_REQUEST['description']);
|
||||
|
||||
$errors = array();
|
||||
|
||||
if($action == 'add') {
|
||||
if(Commands::add($words, $description, $errors))
|
||||
$words = $description = '';
|
||||
}
|
||||
else if($action == 'delete') {
|
||||
Commands::delete($id, $errors);
|
||||
}
|
||||
else if($action == 'edit')
|
||||
{
|
||||
if(isset($id) && !isset($words)) {
|
||||
$command = Commands::get($id);
|
||||
$words = $command['words'];
|
||||
$description = $command['description'];
|
||||
}
|
||||
else {
|
||||
Commands::update($id, $words, $description);
|
||||
$action = $words = $description = '';
|
||||
}
|
||||
}
|
||||
else if($action == 'hide') {
|
||||
Commands::toggleHidden($id, $errors);
|
||||
}
|
||||
else if($action == 'moveup') {
|
||||
Commands::move($id, -1, $errors);
|
||||
}
|
||||
else if($action == 'movedown') {
|
||||
Commands::move($id, 1, $errors);
|
||||
}
|
||||
|
||||
if(!empty($errors))
|
||||
$twig->display('error_box.html.twig', array('errors' => $errors));
|
||||
}
|
||||
|
||||
$twig->display('commands.form.html.twig', array(
|
||||
'link' => getLink('commands/' . ($action == 'edit' ? 'edit' : 'add')),
|
||||
'action' => $action,
|
||||
'id' => isset($id) ? $id : null,
|
||||
'words' => isset($words) ? $words : null,
|
||||
'description' => isset($description) ? $description : null
|
||||
));
|
||||
}
|
||||
|
||||
$commands =
|
||||
$db->query('SELECT `id`, `words`, `description`' .
|
||||
($canEdit ? ', `hidden`, `ordering`' : '') .
|
||||
' FROM `' . TABLE_PREFIX . 'commands`' .
|
||||
(!$canEdit ? ' WHERE `hidden` != 1' : '') .
|
||||
' ORDER BY `ordering`;');
|
||||
|
||||
$last = $commands->rowCount();
|
||||
$twig->display('commands.html.twig', array(
|
||||
'commands' => $commands,
|
||||
'last' => $last,
|
||||
'canEdit' => $canEdit
|
||||
));
|
||||
|
||||
class Commands
|
||||
{
|
||||
static public function add($words, $description, &$errors)
|
||||
{
|
||||
global $db;
|
||||
if(isset($words[0]) && isset($description[0]))
|
||||
{
|
||||
$query = $db->select(TABLE_PREFIX . 'commands', array('words' => $words));
|
||||
|
||||
if($query === false)
|
||||
{
|
||||
$query =
|
||||
$db->query(
|
||||
'SELECT ' . $db->fieldName('ordering') .
|
||||
' FROM ' . $db->tableName(TABLE_PREFIX . 'commands') .
|
||||
' 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 . 'commands', array('words' => $words, 'description' => $description, 'ordering' => $ordering));
|
||||
}
|
||||
else
|
||||
$errors[] = 'Command with this words already exists.';
|
||||
}
|
||||
else
|
||||
$errors[] = 'Please fill all inputs.';
|
||||
|
||||
return !count($errors);
|
||||
}
|
||||
|
||||
static public function get($id) {
|
||||
global $db;
|
||||
return $db->select(TABLE_PREFIX . 'commands', array('id' => $id));
|
||||
}
|
||||
|
||||
static public function update($id, $words, $description) {
|
||||
global $db;
|
||||
$db->update(TABLE_PREFIX . 'commands', array('words' => $words, 'description' => $description), array('id' => $id));
|
||||
}
|
||||
|
||||
static public function delete($id, &$errors)
|
||||
{
|
||||
global $db;
|
||||
if(isset($id))
|
||||
{
|
||||
if(self::get($id) !== false)
|
||||
$db->delete(TABLE_PREFIX . 'commands', array('id' => $id));
|
||||
else
|
||||
$errors[] = 'Command with id ' . $id . ' does not exists.';
|
||||
}
|
||||
else
|
||||
$errors[] = 'id not set';
|
||||
|
||||
return !count($errors);
|
||||
}
|
||||
|
||||
static public function toggleHidden($id, &$errors)
|
||||
{
|
||||
global $db;
|
||||
if(isset($id))
|
||||
{
|
||||
$query = self::get($id);
|
||||
if($query !== false)
|
||||
$db->update(TABLE_PREFIX . 'commands', array('hidden' => ($query['hidden'] == 1 ? 0 : 1)), array('id' => $id));
|
||||
else
|
||||
$errors[] = 'Command with id ' . $id . ' does not exists.';
|
||||
}
|
||||
else
|
||||
$errors[] = 'id not set';
|
||||
|
||||
return !count($errors);
|
||||
}
|
||||
|
||||
static public function move($id, $i, &$errors)
|
||||
{
|
||||
global $db;
|
||||
$query = self::get($id);
|
||||
if($query !== false)
|
||||
{
|
||||
$ordering = $query['ordering'] + $i;
|
||||
$old_record = $db->select(TABLE_PREFIX . 'commands', array('ordering' => $ordering));
|
||||
if($old_record !== false)
|
||||
$db->update(TABLE_PREFIX . 'commands', array('ordering' => $query['ordering']), array('ordering' => $ordering));
|
||||
|
||||
$db->update(TABLE_PREFIX . 'commands', array('ordering' => $ordering), array('id' => $id));
|
||||
}
|
||||
else
|
||||
$errors[] = 'Command with id ' . $id . ' does not exists.';
|
||||
|
||||
return !count($errors);
|
||||
}
|
||||
}
|
||||
?>
|
@@ -1,13 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Downloads
|
||||
*
|
||||
* @package MyAAC
|
||||
* @author Slawkens <slawkens@gmail.com>
|
||||
* @copyright 2019 MyAAC
|
||||
* @link https://my-aac.org
|
||||
*/
|
||||
$title = 'Downloads';
|
||||
|
||||
$twig->display('downloads.html.twig');
|
||||
?>
|
@@ -1,10 +0,0 @@
|
||||
<br/><br/>
|
||||
<div style="text-align:center">
|
||||
We're using official Tibia Client <strong>{{ config.client / 100 }}</strong><br/>
|
||||
<p>Download Tibia client {{ config.client / 100 }} for windows <a href="{{ config.client_download }}">HERE</a>.</p>
|
||||
<p>Download Tibia client {{ config.client / 100 }} for linux <a href="{{ config.client_download_linux }}">HERE</a>.</p>
|
||||
|
||||
<h2>IP Changer:</h2>
|
||||
|
||||
<a href="https://static.otland.net/ipchanger.exe" target="_blank">HERE</a>
|
||||
</div>
|
Reference in New Issue
Block a user