mirror of
https://github.com/slawkens/myaac.git
synced 2025-04-26 17:29:21 +02:00

-Admin menu updates -Moved getchangelogtype/where to functions file and added to twig -Added changelog editor to admin panel and updated changelog page -Renamed the changelog md reader to clmd and edited the version file.
126 lines
2.8 KiB
PHP
126 lines
2.8 KiB
PHP
<?php
|
|
|
|
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)
|
|
{
|
|
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);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|