From bc3fd61bde33e45f7bd01f705734e77be653e2b1 Mon Sep 17 00:00:00 2001 From: tobi132 Date: Tue, 3 Dec 2019 05:18:48 +0100 Subject: [PATCH] Move commands and downloads pages into database Available under "Pages" in Admin Panel --- common.php | 2 +- config.php | 8 +- install/steps/5-database.php | 6 +- install/tools/7-finish.php | 3 + system/migrations/27.php | 37 +++++ system/pages/commands.php | 193 --------------------------- system/pages/downloads.php | 13 -- system/templates/downloads.html.twig | 10 -- 8 files changed, 43 insertions(+), 229 deletions(-) create mode 100644 system/migrations/27.php delete mode 100644 system/pages/commands.php delete mode 100644 system/pages/downloads.php delete mode 100644 system/templates/downloads.html.twig diff --git a/common.php b/common.php index 2411b518..5267aeff 100644 --- a/common.php +++ b/common.php @@ -27,7 +27,7 @@ session_start(); define('MYAAC', true); define('MYAAC_VERSION', '0.8-dev'); -define('DATABASE_VERSION', 26); +define('DATABASE_VERSION', 27); define('TABLE_PREFIX', 'myaac_'); define('START_TIME', microtime(true)); define('MYAAC_OS', stripos(PHP_OS, 'WIN') === 0 ? 'WINDOWS' : (strtoupper(PHP_OS) === 'DARWIN' ? 'MAC' : 'LINUX')); diff --git a/config.php b/config.php index 5a7f9c60..67ed19d5 100644 --- a/config.php +++ b/config.php @@ -273,10 +273,4 @@ $config = array( 'monsters' => array(), 'npc' => array() -); - -// download link to client. -$config['client_download'] = 'http://tibia-clients.com/clients/download/'. $config['client'] .'/exe/windows'; -$config['client_download_linux'] = 'http://tibia-clients.com/clients/download/'. $config['client'] .'/tar/linux'; - -?> +); \ No newline at end of file diff --git a/install/steps/5-database.php b/install/steps/5-database.php index 945a6cd5..081a9aad 100644 --- a/install/steps/5-database.php +++ b/install/steps/5-database.php @@ -52,7 +52,7 @@ if(!$error) { $locale['step_database_importing'] = str_replace('$DATABASE_NAME$', config('database_name'), $locale['step_database_importing']); success($locale['step_database_importing']); - + if(isset($database_error)) { // we failed connect to the database error($database_error); } @@ -72,10 +72,6 @@ if(!$error) { $error = true; } - $content .= '$config[\'client_download\'] = \'http://tibia-clients.com/clients/download/\'. $config[\'client\'] . \'/exe/windows\';'; - $content .= PHP_EOL; - $content .= '$config[\'client_download_linux\'] = \'http://tibia-clients.com/clients/download/\'. $config[\'client\'] . \'/tar/linux\';'; - $content .= PHP_EOL; $content .= '$config[\'session_prefix\'] = \'myaac_' . generateRandomString(8, true, false, true, false) . '_\';'; $content .= PHP_EOL; $content .= '$config[\'cache_prefix\'] = \'myaac_' . generateRandomString(8, true, false, true, false) . '_\';'; diff --git a/install/tools/7-finish.php b/install/tools/7-finish.php index 1b49d3eb..8cad06ab 100644 --- a/install/tools/7-finish.php +++ b/install/tools/7-finish.php @@ -89,6 +89,9 @@ if(!databaseMigration20($content)) { // add z_polls tables require_once SYSTEM . 'migrations/22.php'; +// add myaac_pages pages +require_once SYSTEM . 'migrations/27.php'; + $locale['step_finish_desc'] = str_replace('$ADMIN_PANEL$', generateLink(str_replace('tools/', '',ADMIN_URL), $locale['step_finish_admin_panel'], true), $locale['step_finish_desc']); $locale['step_finish_desc'] = str_replace('$HOMEPAGE$', generateLink(str_replace('tools/', '', BASE_URL), $locale['step_finish_homepage'], true), $locale['step_finish_desc']); $locale['step_finish_desc'] = str_replace('$LINK$', generateLink('https://my-aac.org', 'https://my-aac.org', true), $locale['step_finish_desc']); diff --git a/system/migrations/27.php b/system/migrations/27.php new file mode 100644 index 00000000..330e7085 --- /dev/null +++ b/system/migrations/27.php @@ -0,0 +1,37 @@ +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', '

 

+

 

+
We''re using official Tibia Client {{ config.client / 100 }}
+

Download Tibia Client {{ config.client / 100 }} for Windows HERE.

+

IP Changer:

+HERE
', 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', ' + + + + + + + + + + + + + + + + + + +
WordsDescription
!exampleThis is just an example
!buyhouseBuy house you are looking at
!aolBuy AoL
', 0, 1, 0, 1, 0);"); +} \ No newline at end of file diff --git a/system/pages/commands.php b/system/pages/commands.php deleted file mode 100644 index db0fc637..00000000 --- a/system/pages/commands.php +++ /dev/null @@ -1,193 +0,0 @@ - - * @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 - /commands.

- - - -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); - } -} -?> \ No newline at end of file diff --git a/system/pages/downloads.php b/system/pages/downloads.php deleted file mode 100644 index 75851376..00000000 --- a/system/pages/downloads.php +++ /dev/null @@ -1,13 +0,0 @@ - - * @copyright 2019 MyAAC - * @link https://my-aac.org - */ -$title = 'Downloads'; - -$twig->display('downloads.html.twig'); -?> \ No newline at end of file diff --git a/system/templates/downloads.html.twig b/system/templates/downloads.html.twig deleted file mode 100644 index 1f39775e..00000000 --- a/system/templates/downloads.html.twig +++ /dev/null @@ -1,10 +0,0 @@ -

-
- We're using official Tibia Client {{ config.client / 100 }}
-

Download Tibia client {{ config.client / 100 }} for windows HERE.

-

Download Tibia client {{ config.client / 100 }} for linux HERE.

- -

IP Changer:

- - HERE -
\ No newline at end of file