diff --git a/admin/template/menus.php b/admin/template/menus.php
index 37a1c2df..12ffb85c 100644
--- a/admin/template/menus.php
+++ b/admin/template/menus.php
@@ -2,12 +2,25 @@
return [
['name' => 'Dashboard', 'icon' => 'tachometer-alt', 'link' => 'dashboard'],
- ['name' => 'News', 'icon' => 'newspaper', 'link' => 'news'],
+ ['name' => 'News', 'icon' => 'newspaper', 'link' =>
+ [
+ ['name' => 'View', 'link' => 'news'],
+ ['name' => 'Add news', 'link' => 'news&action=new&type=1'],
+ ['name' => 'Add ticker', 'link' => 'news&action=new&type=2'],
+ ['name' => 'Add article', 'link' => 'news&action=new&type=3'],
+ ],
+ ],
+ ['name' => 'Changelogs', 'icon' => 'newspaper', 'link' =>
+ [
+ ['name' => 'View', 'link' => 'changelog'],
+ ['name' => 'Add', 'link' => 'changelog&action=new'],
+ ],
+ ],
['name' => 'Mailer', 'icon' => 'envelope', 'link' => 'mailer', 'disabled' => !config('mail_enabled')],
['name' => 'Pages', 'icon' => 'book', 'link' =>
[
- ['name' => 'All Pages', 'link' => 'pages'],
- ['name' => 'Add new', 'link' => 'pages&action=new'],
+ ['name' => 'View', 'link' => 'pages'],
+ ['name' => 'Add', 'link' => 'pages&action=new'],
],
],
['name' => 'Menus', 'icon' => 'list', 'link' => 'menus'],
@@ -32,4 +45,4 @@ return [
['name' => 'Visitors', 'icon' => 'user', 'link' => 'visitors'],
],
],
-];
\ No newline at end of file
+];
diff --git a/system/functions.php b/system/functions.php
index 2a37536f..04aa2584 100644
--- a/system/functions.php
+++ b/system/functions.php
@@ -1299,6 +1299,33 @@ function getBanType($typeId)
return "Unknown Type";
}
+function getChangelogType($v)
+{
+ switch($v) {
+ case 1:
+ return 'added';
+ case 2:
+ return 'removed';
+ case 3:
+ return 'changed';
+ case 4:
+ return 'fixed';
+ }
+
+ return 'unknown';
+}
+
+function getChangelogWhere($v)
+{
+ switch($v) {
+ case 1:
+ return 'server';
+ case 2:
+ return 'website';
+ }
+
+ return 'unknown';
+}
function getPlayerNameByAccount($id)
{
global $vowels, $ots, $db;
diff --git a/system/libs/changelog.php b/system/libs/changelog.php
new file mode 100644
index 00000000..89f78bfc
--- /dev/null
+++ b/system/libs/changelog.php
@@ -0,0 +1,125 @@
+ CL_LIMIT) {
+ $errors[] = 'Changelog content cannot be longer than ' . CL_LIMIT . ' characters.';
+ return false;
+ }
+
+ return true;
+ }
+
+ static public function add($body, $type, $where, $player_id, $cdate, &$errors)
+ {
+ global $db;
+ if(!self::verify($body,$cdate, $errors))
+ return false;
+
+ $db->insert(TABLE_PREFIX . 'changelog', array('body' => $body, 'type' => $type, 'date' => $cdate, 'where' => $where, 'player_id' => isset($player_id) ? $player_id : 0));
+ self::clearCache();
+ return true;
+ }
+
+ static public function get($id) {
+ global $db;
+ return $db->select(TABLE_PREFIX . 'changelog', array('id' => $id));
+ }
+
+ static public function update($id, $body, $type, $where, $player_id, $date, &$errors)
+ {
+ global $db;
+ if(!self::verify($body,$date, $errors))
+ return false;
+
+ $db->update(TABLE_PREFIX . 'changelog', array('body' => $body, 'type' => $type, 'where' => $where, 'player_id' => isset($player_id) ? $player_id : 0, 'date' => $date), array('id' => $id));
+ self::clearCache();
+ return true;
+ }
+
+ static public function delete($id, &$errors)
+ {
+ global $db;
+ if(isset($id))
+ {
+ if($db->select(TABLE_PREFIX . 'changelog', array('id' => $id)) !== false)
+ $db->delete(TABLE_PREFIX . 'changelog', array('id' => $id));
+ else
+ $errors[] = 'Changelog with id ' . $id . ' does not exist.';
+ }
+ else
+ $errors[] = 'Changelog id not set.';
+
+ if(count($errors)) {
+ return false;
+ }
+
+ self::clearCache();
+ return true;
+ }
+
+ static public function toggleHidden($id, &$errors, &$status)
+ {
+ global $db;
+ if(isset($id))
+ {
+ $query = $db->select(TABLE_PREFIX . 'changelog', array('id' => $id));
+ if($query !== false)
+ {
+ $db->update(TABLE_PREFIX . 'changelog', array('hidden' => ($query['hidden'] == 1 ? 0 : 1)), array('id' => $id));
+ $status = $query['hidden'];
+ }
+ else
+ $errors[] = 'Changelog with id ' . $id . ' does not exists.';
+ }
+ else
+ $errors[] = 'Changelog id not set.';
+
+ if(count($errors)) {
+ return false;
+ }
+
+ self::clearCache();
+ return true;
+ }
+
+ static public function getCached($type)
+ {
+ global $template_name;
+
+ $cache = Cache::getInstance();
+ if ($cache->enabled())
+ {
+ $tmp = '';
+ if ($cache->fetch('changelog_' . $template_name, $tmp) && isset($tmp[0])) {
+ return $tmp;
+ }
+ }
+
+ return false;
+ }
+
+ static public function clearCache()
+ {
+ global $template_name;
+ $cache = Cache::getInstance();
+ if (!$cache->enabled()) {
+ return;
+ }
+
+ $tmp = '';
+ foreach (get_templates() as $template) {
+ if ($cache->fetch('changelog_' . $template_name, $tmp)) {
+ $cache->delete('changelog_' . $template_name);
+ }
+
+ }
+ }
+}
diff --git a/system/pages/admin/changelog.php b/system/pages/admin/changelog.php
index 0c58c6bc..a6e7d01c 100644
--- a/system/pages/admin/changelog.php
+++ b/system/pages/admin/changelog.php
@@ -1,26 +1,140 @@
- * @copyright 2019 MyAAC
+ * @author Lee
+ * @copyright 2020 MyAAC
* @link https://my-aac.org
*/
defined('MYAAC') or die('Direct access not allowed!');
-$title = 'MyAAC Changelog';
-if (!file_exists(BASE . 'CHANGELOG.md')) {
- echo 'File CHANGELOG.md doesn\'t exist.';
+if (!hasFlag(FLAG_CONTENT_PAGES) && !superAdmin()) {
+ echo 'Access denied.';
return;
}
-require LIBS . 'Parsedown.php';
+$title = 'Changelog';
+$use_datatable = true;
+define('CL_LIMIT', 600); // maximum changelog body length
+?>
-$changelog = file_get_contents(BASE . 'CHANGELOG.md');
+
+
+text($changelog); # prints:
Hello Parsedown!
+ $errors = array();
-echo '' . $changelog . '
';
+ if($action == 'add') {
+
+ if(Changelog::add($body, $type, $where, $player_id, $create_date, $errors)) {
+ $body = '';
+ $type = $where = $player_id = $create_date = 0;
+
+ success("Added successful.");
+ }
+ }
+ else if($action == 'delete') {
+ Changelog::delete($id, $errors);
+ success("Deleted successful.");
+ }
+ else if($action == 'edit')
+ {
+ if(isset($id) && !isset($body)) {
+ $cl = Changelog::get($id);
+ $body = $cl['body'];
+ $type = $cl['type'];
+ $where = $cl['where'];
+ $create_date = $cl['date'];
+ $player_id = $cl['player_id'];
+ }
+ else {
+ if(Changelog::update($id, $body, $type, $where, $player_id, $create_date,$errors)) {
+ $action = $body = '';
+ $type = $where = $player_id = $create_date = 0;
+
+ success("Updated successful.");
+ }
+ }
+ }
+ else if($action == 'hide') {
+ Changelog::toggleHidden($id, $errors, $status);
+ success(($status == 1 ? 'Show' : 'Hide') . " successful.");
+ }
+
+ if(!empty($errors))
+ error(implode(", ", $errors));
+}
+
+$changelogs = $db->query('SELECT * FROM `' . TABLE_PREFIX . 'changelog' . '` ORDER BY `id` DESC')->fetchAll();
+
+$i = 0;
+
+$log_type = [
+ ['id' => 1, 'icon' => 'added'],
+ ['id' => 2, 'icon' => 'removed'],
+ ['id' => 3, 'icon' => 'changed'],
+ ['id' => 4, 'icon' => 'fixed'],
+];
+
+$log_where = [
+ ['id' => 1, 'icon' => 'server'],
+ ['id' => 2, 'icon' => 'website'],
+];
+
+foreach($changelogs as $key => &$log)
+{
+ $log['type'] = getChangelogType($log['type']);
+ $log['where'] = getChangelogWhere($log['where']);
+}
+
+if($action == 'edit' || $action == 'new') {
+ if($action == 'edit') {
+ $player = new OTS_Player();
+ $player->load($player_id);
+ }
+
+ $account_players = $account_logged->getPlayersList();
+ $account_players->orderBy('group_id', POT::ORDER_DESC);
+ $twig->display('admin.changelog.form.html.twig', array(
+ 'action' => $action,
+ 'cl_link_form' => constant('ADMIN_URL').'?p=changelog&action=' . ($action == 'edit' ? 'edit' : 'add'),
+ 'cl_id' => isset($id) ? $id : null,
+ 'body' => isset($body) ? htmlentities($body, ENT_COMPAT, 'UTF-8') : '',
+ 'create_date' => isset($create_date) ? $create_date : '',
+ 'player' => isset($player) && $player->isLoaded() ? $player : null,
+ 'player_id' => isset($player_id) ? $player_id : null,
+ 'account_players' => $account_players,
+ 'type' => isset($type) ? $type : 0,
+ 'where' => isset($where) ? $where : 0,
+ 'log_type' => $log_type,
+ 'log_where' => $log_where,
+ ));
+}
+$twig->display('admin.changelog.html.twig', array(
+ 'changelogs' => $changelogs,
+));
+
+?>
+
diff --git a/system/pages/admin/clmd.php b/system/pages/admin/clmd.php
new file mode 100644
index 00000000..9d27f170
--- /dev/null
+++ b/system/pages/admin/clmd.php
@@ -0,0 +1,27 @@
+
+ * @author Lee
+ * @copyright 2020 MyAAC
+ * @link https://my-aac.org
+ */
+defined('MYAAC') or die('Direct access not allowed!');
+$title = 'MyAAC Changelog';
+
+if (!file_exists(BASE . 'CHANGELOG.md')) {
+ echo 'File CHANGELOG.md doesn\'t exist.';
+ return;
+}
+
+require LIBS . 'Parsedown.php';
+
+$changelog = file_get_contents(BASE . 'CHANGELOG.md');
+
+$Parsedown = new Parsedown();
+
+$changelog = $Parsedown->text($changelog); # prints: Hello Parsedown!
+
+echo '' . $changelog . '
';
diff --git a/system/pages/admin/version.php b/system/pages/admin/version.php
index ec9f4f64..e643e728 100644
--- a/system/pages/admin/version.php
+++ b/system/pages/admin/version.php
@@ -24,10 +24,10 @@ if (!$myaac_version) {
$version_compare = version_compare($myaac_version, MYAAC_VERSION);
if ($version_compare == 0) {
success('MyAAC latest version is ' . $myaac_version . '. You\'re using the latest version.
-
View CHANGELOG ' . generateLink(ADMIN_URL . '?p=changelog', 'here'));
+
View CHANGELOG ' . generateLink(ADMIN_URL . '?p=clmd', 'here'));
} else if ($version_compare < 0) {
success('Woah, seems you\'re using newer version as latest released one! MyAAC latest released version is ' . $myaac_version . ', and you\'re using version ' . MYAAC_VERSION . '.
-
View CHANGELOG ' . generateLink(ADMIN_URL . '?p=changelog', 'here'));
+
View CHANGELOG ' . generateLink(ADMIN_URL . '?p=clmd', 'here'));
} else {
warning('You\'re using outdated version.
Your version: ' . MYAAC_VERSION . '
diff --git a/system/pages/changelog.php b/system/pages/changelog.php
index 6b2adb86..541f9088 100644
--- a/system/pages/changelog.php
+++ b/system/pages/changelog.php
@@ -16,7 +16,9 @@ $limit = 30;
$offset = $_page * $limit;
$next_page = false;
-$changelogs = $db->query('SELECT * FROM `' . TABLE_PREFIX . 'changelog' . '` WHERE `hidden` = 0 ORDER BY `id` DESC LIMIT ' . ($limit + 1) . ' OFFSET ' . $offset)->fetchAll();
+$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();
$i = 0;
foreach($changelogs as $key => &$log)
@@ -39,33 +41,6 @@ $twig->display('changelog.html.twig', array(
'changelogs' => $changelogs,
'page' => $_page,
'next_page' => $next_page,
+ 'canEdit' => $canEdit,
));
-
-function getChangelogType($v)
-{
- switch($v) {
- case 1:
- return 'added';
- case 2:
- return 'removed';
- case 3:
- return 'changed';
- case 4:
- return 'fixed';
- }
-
- return 'unknown';
-}
-
-function getChangelogWhere($v)
-{
- switch($v) {
- case 1:
- return 'server';
- case 2:
- return 'website';
- }
-
- return 'unknown';
-}
?>
diff --git a/system/templates/admin.changelog.form.html.twig b/system/templates/admin.changelog.form.html.twig
new file mode 100644
index 00000000..e3ca5dab
--- /dev/null
+++ b/system/templates/admin.changelog.form.html.twig
@@ -0,0 +1,59 @@
+{% if action %}
+
+{% endif %}
diff --git a/system/templates/admin.changelog.html.twig b/system/templates/admin.changelog.html.twig
new file mode 100644
index 00000000..fe43982a
--- /dev/null
+++ b/system/templates/admin.changelog.html.twig
@@ -0,0 +1,55 @@
+
+
+
+
+
+
+
+ ID |
+ Date |
+ Description |
+ Type |
+ Where |
+ |
+
+
+
+ {% if changelogs|length > 0 %}
+ {% set i = 0 %}
+ {% for log in changelogs %}
+
+ {{ log.id }} |
+ {{ log.date|date("j.m.Y") }} |
+ {{ truncate(log.body|raw,20) }} |
+ {{ log.type|capitalize }} |
+ {{ log.where|capitalize }} |
+
+
+ |
+
+ {% set i = i + 1 %}
+ {% endfor %}
+ {% else %}
+
+ There are no changelogs for the moment. |
+
+ {% endif %}
+
+
+
+
diff --git a/system/templates/changelog.html.twig b/system/templates/changelog.html.twig
index 8ba6c627..d63a6a2a 100644
--- a/system/templates/changelog.html.twig
+++ b/system/templates/changelog.html.twig
@@ -1,23 +1,41 @@
-
+{% if canEdit %}
+ Add New
+{% endif %}
Type |
Where |
Date |
Description |
+ {% if canEdit %}
+ |
+ {% endif %}
{% if changelogs|length > 0%}
{% set i = 0 %}
{% for log in changelogs %}
-
+
|
-
+
|
{{ log.date|date("j.m.Y") }} |
- {{ log.body|raw }} |
+ {{ log.body|nl2br}} |
+ {% if canEdit %}
+
+
+ Edit
+
+
+ Delete
+
+
+ {{ (log.hidden != 1) ? 'Hide' : 'Show' }}
+
+ |
+ {% endif %}
{% set i = i + 1 %}
{% endfor %}
@@ -35,4 +53,4 @@
Next Page |
{% endif %}
-
\ No newline at end of file
+
diff --git a/system/twig.php b/system/twig.php
index 3a258843..e847f356 100644
--- a/system/twig.php
+++ b/system/twig.php
@@ -54,6 +54,20 @@ $function = new TwigFunction('getGuildLink', function ($s, $p) {
});
$twig->addFunction($function);
+$function = new TwigFunction('truncate', function ($s, $n) {
+ return truncate($s, $n);
+});
+$twig->addFunction($function);
+
+$function = new TwigFunction('getChangelogType', function ($n) {
+ return getChangelogType($n);
+});
+$twig->addFunction($function);
+
+$function = new TwigFunction('getChangelogWhere', function ($n) {
+ return getChangelogWhere($n);
+});
+$twig->addFunction($function);
$function = new TwigFunction('hook', function ($hook) {
global $hooks;