mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-27 17:59:22 +02:00

* Fix alert class name * feature: csrf protection * Cosmetics * Fix token generate * Admin Panel: changelogs csrf protection * news/id route * Refactor admin newses + add csrf * Use admin.links instead * Admin panel: Pages csrf * Menus: better csrf + add success message on reset colors * Plugins csrf * Move definitions * add info function, same as note($message) * Update mailer.php * Fix new page/news links * clear_cache & maintenance csrf * Formatting * Fix news type * Fix changelog link * Add new changelog link * More info to confirm dialog * This is always true
148 lines
2.7 KiB
PHP
148 lines
2.7 KiB
PHP
<?php
|
|
|
|
use MyAAC\Models\Changelog as ModelsChangelog;
|
|
|
|
class Changelog
|
|
{
|
|
static public function verify($body,$date, &$errors)
|
|
{
|
|
if(!isset($date) || !isset($body[0])) {
|
|
$errors[] = 'Please fill all inputs.';
|
|
return false;
|
|
}
|
|
|
|
if(strlen($body) > 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)
|
|
{
|
|
if(!self::verify($body,$cdate, $errors))
|
|
return false;
|
|
|
|
$row = new ModelsChangelog;
|
|
$row->body = $body;
|
|
$row->type = $type;
|
|
$row->date = $cdate;
|
|
$row->where = $where;
|
|
$row->player_id = $player_id ?? 0;
|
|
if ($row->save()) {
|
|
self::clearCache();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static public function get($id) {
|
|
return ModelsChangelog::find($id);
|
|
}
|
|
|
|
static public function update($id, $body, $type, $where, $player_id, $date, &$errors)
|
|
{
|
|
if(!self::verify($body,$date, $errors))
|
|
return false;
|
|
|
|
if (ModelsChangelog::where('id', '=', $id)->update([
|
|
'body' => $body,
|
|
'type' => $type,
|
|
'where' => $where,
|
|
'player_id' => $player_id ?? 0,
|
|
'date' => $date
|
|
])) {
|
|
self::clearCache();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
static public function delete($id, &$errors)
|
|
{
|
|
if(isset($id))
|
|
{
|
|
$row = ModelsChangelog::find($id);
|
|
if ($row) {
|
|
if (!$row->delete()) {
|
|
$errors[] = 'Fail during delete Changelog.';
|
|
}
|
|
} 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)
|
|
{
|
|
if(isset($id))
|
|
{
|
|
$row = ModelsChangelog::find($id);
|
|
if ($row) {
|
|
$row->hidden = $row->hidden == 1 ? 0 : 1;
|
|
if (!$row->save()) {
|
|
$errors[] = 'Fail during toggle hidden Changelog.';
|
|
}
|
|
$status = $row->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);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|