- reformatted source code

- added model to emoticons module
- use better bootstrap styling for the sidebars
parent 43acaaac
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -8,97 +8,101 @@ namespace ACP3\Core;
*/
abstract class Cache
{
/**
*
* @var string
*/
private static $cache_dir = 'uploads/cache/';
/**
*
* @var string
*/
private static $sql_cache_dir = 'uploads/cache/sql/';
/**
*
* @var string
*/
private static $cache_dir = 'uploads/cache/';
/**
*
* @var string
*/
private static $sql_cache_dir = 'uploads/cache/sql/';
/**
* Überprüft, ob der Cache für eine bestimmte Abfrage schon erstellt wurde
*
* @param string $filename
* Der Name der Datei, welcher auf Existenz und Gültigkeit geprüft werden soll
* @return boolean
*/
public static function check($filename, $cache_id = '')
{
$cache_id.= $cache_id !== '' ? '_' : '';
return is_file(ACP3_ROOT_DIR . self::$sql_cache_dir . $cache_id . md5($filename) . '.php');
}
/**
* Erstellt den Cache
*
* @param string $filename
* Gewünschter Dateiname des Caches
* @param array $data
* Daten, für welche der Cache erstellt werden sollen
* @return boolean
*/
public static function create($filename, $data, $cache_id = '')
{
if (!empty($data)) {
$cache_id.= $cache_id !== '' ? '_' : '';
$bool = @file_put_contents(ACP3_ROOT_DIR . self::$sql_cache_dir . $cache_id . md5($filename) . '.php', serialize($data), LOCK_EX);
/**
* Überprüft, ob der Cache für eine bestimmte Abfrage schon erstellt wurde
*
* @param string $filename
* Der Name der Datei, welcher auf Existenz und Gültigkeit geprüft werden soll
* @return boolean
*/
public static function check($filename, $cache_id = '')
{
$cache_id .= $cache_id !== '' ? '_' : '';
return is_file(ACP3_ROOT_DIR . self::$sql_cache_dir . $cache_id . md5($filename) . '.php');
}
return $bool !== false ? true : false;
} elseif (self::check($filename, $cache_id) === true) {
return self::delete($filename, $cache_id);
}
return false;
}
/**
* Löscht eine bestimmte gecachete Datei
*
* @param string $filename
* Zu löschende Datei
* @return boolean
*/
public static function delete($filename, $cache_id = '')
{
$cache_id.= $cache_id !== '' ? '_' : '';
return @unlink(ACP3_ROOT_DIR . self::$sql_cache_dir . $cache_id . md5($filename) . '.php');
}
/**
* Ausgabe der gecacheten Aktion
*
* @param string $filename
* Auszugebende Datei
* @return mixed
*/
public static function output($filename, $cache_id = '')
{
$cache_id.= $cache_id !== '' ? '_' : '';
$data = @file_get_contents(ACP3_ROOT_DIR . self::$sql_cache_dir . $cache_id . md5($filename) . '.php');
return $data === false ? array() : unserialize($data);
}
/**
* Löscht den gesamten Cache
*
* @param string $dir
* Einen Unterordner des Cache-Ordners löschen
*/
public static function purge($dir = '', $cache_id = '')
{
$path = ACP3_ROOT_DIR . self::$cache_dir . (!empty($dir) && !preg_match('=/=', $dir) ? $dir . '/' : 'sql/');
if (is_dir($path)) {
$cache_id.= $cache_id !== '' ? '_' : '';
/**
* Erstellt den Cache
*
* @param string $filename
* Gewünschter Dateiname des Caches
* @param array $data
* Daten, für welche der Cache erstellt werden sollen
* @return boolean
*/
public static function create($filename, $data, $cache_id = '')
{
if (!empty($data)) {
$cache_id .= $cache_id !== '' ? '_' : '';
$bool = @file_put_contents(ACP3_ROOT_DIR . self::$sql_cache_dir . $cache_id . md5($filename) . '.php', serialize($data), LOCK_EX);
$cache_dir = scandir($path);
foreach ($cache_dir as $row) {
if (is_file($path . $row) && $row !== '.htaccess') {
// Wenn eine $cache_id gesetzt wurde, nur diese Dateien löschen
if ($cache_id !== '' && strpos($row, $cache_id) !== 0)
continue;
@unlink($path . $row);
}
}
}
return;
}
return $bool !== false ? true : false;
} elseif (self::check($filename, $cache_id) === true) {
return self::delete($filename, $cache_id);
}
return false;
}
/**
* Löscht eine bestimmte gecachete Datei
*
* @param string $filename
* Zu löschende Datei
* @return boolean
*/
public static function delete($filename, $cache_id = '')
{
$cache_id .= $cache_id !== '' ? '_' : '';
return @unlink(ACP3_ROOT_DIR . self::$sql_cache_dir . $cache_id . md5($filename) . '.php');
}
/**
* Ausgabe der gecacheten Aktion
*
* @param string $filename
* Auszugebende Datei
* @return mixed
*/
public static function output($filename, $cache_id = '')
{
$cache_id .= $cache_id !== '' ? '_' : '';
$data = @file_get_contents(ACP3_ROOT_DIR . self::$sql_cache_dir . $cache_id . md5($filename) . '.php');
return $data === false ? array() : unserialize($data);
}
/**
* Löscht den gesamten Cache
*
* @param string $dir
* Einen Unterordner des Cache-Ordners löschen
*/
public static function purge($dir = '', $cache_id = '')
{
$path = ACP3_ROOT_DIR . self::$cache_dir . (!empty($dir) && !preg_match('=/=', $dir) ? $dir . '/' : 'sql/');
if (is_dir($path)) {
$cache_id .= $cache_id !== '' ? '_' : '';
$cache_dir = scandir($path);
foreach ($cache_dir as $row) {
if (is_file($path . $row) && $row !== '.htaccess') {
// Wenn eine $cache_id gesetzt wurde, nur diese Dateien löschen
if ($cache_id !== '' && strpos($row, $cache_id) !== 0)
continue;
@unlink($path . $row);
}
}
}
return;
}
}
\ No newline at end of file
......@@ -8,73 +8,78 @@ use \ACP3\Core\Cache;
*
* @author Tino Goratsch
*/
abstract class Config {
abstract class Config
{
/**
* Gibt die Systemeinstellungen aus
*/
public static function getSystemSettings() {
$settings = self::getSettings('system');
foreach ($settings as $key => $value) {
define('CONFIG_' . strtoupper($key), $value);
}
return;
}
/**
* Gibt die Systemeinstellungen aus
*/
public static function getSystemSettings()
{
$settings = self::getSettings('system');
foreach ($settings as $key => $value) {
define('CONFIG_' . strtoupper($key), $value);
}
return;
}
/**
* Erstellt/Verändert die Konfigurationsdateien für die Module
*
* @param string $module
* @param array $data
* @return boolean
*/
public static function setSettings($module, $data) {
$bool = $bool2 = false;
$mod_id = Registry::get('Db')->fetchColumn('SELECT id FROM ' . DB_PRE . 'modules WHERE name = ?', array($module));
if (!empty($mod_id)) {
foreach ($data as $key => $value) {
$bool = Registry::get('Db')->executeUpdate('UPDATE ' . DB_PRE . 'settings SET value = ? WHERE module_id = ? AND name = ?', array($value, (int) $mod_id, $key));
}
$bool2 = self::setModuleCache($module);
}
/**
* Erstellt/Verändert die Konfigurationsdateien für die Module
*
* @param string $module
* @param array $data
* @return boolean
*/
public static function setSettings($module, $data)
{
$bool = $bool2 = false;
$mod_id = Registry::get('Db')->fetchColumn('SELECT id FROM ' . DB_PRE . 'modules WHERE name = ?', array($module));
if (!empty($mod_id)) {
foreach ($data as $key => $value) {
$bool = Registry::get('Db')->executeUpdate('UPDATE ' . DB_PRE . 'settings SET value = ? WHERE module_id = ? AND name = ?', array($value, (int)$mod_id, $key));
}
$bool2 = self::setModuleCache($module);
}
return $bool !== false && $bool2 !== false ? true : false;
}
return $bool !== false && $bool2 !== false ? true : false;
}
/**
* Gibt den Inhalt der Konfigurationsdateien der Module aus
*
* @param string $module
* @return array
*/
public static function getSettings($module) {
if (Cache::check($module, 'settings') === false)
self::setModuleCache($module);
/**
* Gibt den Inhalt der Konfigurationsdateien der Module aus
*
* @param string $module
* @return array
*/
public static function getSettings($module)
{
if (Cache::check($module, 'settings') === false)
self::setModuleCache($module);
return Cache::output($module, 'settings');
}
return Cache::output($module, 'settings');
}
/**
* Setzt den Cache für die Einstellungen eines Moduls
*
* @param string $module
* @return boolean
*/
private static function setModuleCache($module) {
$settings = Registry::get('Db')->executeQuery('SELECT s.name, s.value FROM ' . DB_PRE . 'settings AS s JOIN ' . DB_PRE . 'modules AS m ON(m.id = s.module_id) WHERE m.name = ?', array($module))->fetchAll();
$c_settings = count($settings);
/**
* Setzt den Cache für die Einstellungen eines Moduls
*
* @param string $module
* @return boolean
*/
private static function setModuleCache($module)
{
$settings = Registry::get('Db')->executeQuery('SELECT s.name, s.value FROM ' . DB_PRE . 'settings AS s JOIN ' . DB_PRE . 'modules AS m ON(m.id = s.module_id) WHERE m.name = ?', array($module))->fetchAll();
$c_settings = count($settings);
$cache_ary = array();
for ($i = 0; $i < $c_settings; ++$i) {
if (is_int($settings[$i]['value']))
$cache_ary[$settings[$i]['name']] = (int) $settings[$i]['value'];
elseif (is_float($settings[$i]['value']))
$cache_ary[$settings[$i]['name']] = (float) $settings[$i]['value'];
else
$cache_ary[$settings[$i]['name']] = $settings[$i]['value'];
}
$cache_ary = array();
for ($i = 0; $i < $c_settings; ++$i) {
if (is_int($settings[$i]['value']))
$cache_ary[$settings[$i]['name']] = (int)$settings[$i]['value'];
elseif (is_float($settings[$i]['value']))
$cache_ary[$settings[$i]['name']] = (float)$settings[$i]['value'];
else
$cache_ary[$settings[$i]['name']] = $settings[$i]['value'];
}
return Cache::create($module, $cache_ary, 'settings');
}
return Cache::create($module, $cache_ary, 'settings');
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -6,6 +6,7 @@ namespace ACP3\Core\Exceptions;
*
* @author goratsch
*/
class InvalidFormToken extends \Exception {
class InvalidFormToken extends \Exception
{
}
......@@ -7,6 +7,7 @@ namespace ACP3\Core\Exceptions;
*
* @author goratsch
*/
class ValidationFailed extends \Exception {
class ValidationFailed extends \Exception
{
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -7,59 +7,65 @@ namespace ACP3\Core;
*
* @author Tino Goratsch
*/
class Model {
class Model
{
protected $db;
protected $prefix = DB_PRE;
protected $db;
protected $prefix = DB_PRE;
const TABLE_NAME = '';
const TABLE_NAME = '';
public function __construct(\Doctrine\DBAL\Connection $db) {
$this->db = $db;
}
public function __construct(\Doctrine\DBAL\Connection $db)
{
$this->db = $db;
}
protected function _buildLimitStmt($limitStart = '', $resultsPerPage = '') {
if (Validate::isNumber($limitStart) === true && Validate::isNumber($resultsPerPage) === true) {
return ' LIMIT ' . $limitStart . ',' . $resultsPerPage;
} elseif (Validate::isNumber($limitStart) === true) {
return ' LIMIT ' . $limitStart;
} else {
return '';
}
}
protected function _buildLimitStmt($limitStart = '', $resultsPerPage = '')
{
if (Validate::isNumber($limitStart) === true && Validate::isNumber($resultsPerPage) === true) {
return ' LIMIT ' . $limitStart . ',' . $resultsPerPage;
} elseif (Validate::isNumber($limitStart) === true) {
return ' LIMIT ' . $limitStart;
} else {
return '';
}
}
public function insert($params) {
$this->db->beginTransaction();
try {
$this->db->insert($this->prefix . static::TABLE_NAME, $params);
$lastId = $this->db->lastInsertId();
$this->db->commit();
return $lastId;
} catch (\Exception $e) {
$this->db->rollback();
}
}
public function insert($params)
{
$this->db->beginTransaction();
try {
$this->db->insert($this->prefix . static::TABLE_NAME, $params);
$lastId = $this->db->lastInsertId();
$this->db->commit();
return $lastId;
} catch (\Exception $e) {
$this->db->rollback();
}
}
public function delete($id, $field = 'id') {
$this->db->beginTransaction();
try {
$bool = $this->db->delete($this->prefix . static::TABLE_NAME, is_array($id) ? $id : array($field => (int) $id));
$this->db->commit();
return $bool;
} catch (\Exception $e) {
$this->db->rollback();
}
}
public function delete($id, $field = 'id')
{
$this->db->beginTransaction();
try {
$bool = $this->db->delete($this->prefix . static::TABLE_NAME, is_array($id) ? $id : array($field => (int)$id));
$this->db->commit();
return $bool;
} catch (\Exception $e) {
$this->db->rollback();
}
}
public function update($params, $id) {
$this->db->beginTransaction();
try {
$bool = $this->db->update($this->prefix . static::TABLE_NAME, $params, array('id' => $id));
$this->db->commit();
return $bool;
} catch (\Exception $e) {
$this->db->rollback();
}
}
public function update($params, $id)
{
$this->db->beginTransaction();
try {
$bool = $this->db->update($this->prefix . static::TABLE_NAME, $params, array('id' => $id));
$this->db->commit();
return $bool;
} catch (\Exception $e) {
$this->db->rollback();
}
}
}
This diff is collapsed.
......@@ -9,27 +9,30 @@ use ACP3\Core;
*
* @author goratsch
*/
class AdminController extends Controller {
class AdminController extends Controller
{
public function __construct() {
parent::__construct();
}
public function __construct()
{
parent::__construct();
}
protected function _deleteItem($moduleConfirmUrl = '', $moduleIndexUrl = '') {
if (isset($_POST['entries']) && is_array($_POST['entries']) === true) {
$entries = $_POST['entries'];
} elseif (Core\Validate::deleteEntries($this->uri->entries) === true) {
$entries = $this->uri->entries;
}
protected function _deleteItem($moduleConfirmUrl = '', $moduleIndexUrl = '')
{
if (isset($_POST['entries']) && is_array($_POST['entries']) === true) {
$entries = $_POST['entries'];
} elseif (Core\Validate::deleteEntries($this->uri->entries) === true) {
$entries = $this->uri->entries;
}
if (!isset($entries)) {
$this->view->setContent(Core\Functions::errorBox($this->lang->t('system', 'no_entries_selected')));
} elseif (is_array($entries) === true) {
$marked_entries = implode('|', $entries);
$this->view->setContent(Core\Functions::confirmBox($this->lang->t('system', 'confirm_delete'), $this->uri->route($moduleConfirmUrl) . 'entries_' . $marked_entries . '/action_confirmed/', $this->uri->route($moduleIndexUrl)));
} else {
return $entries;
}
}
if (!isset($entries)) {
$this->view->setContent(Core\Functions::errorBox($this->lang->t('system', 'no_entries_selected')));
} elseif (is_array($entries) === true) {
$marked_entries = implode('|', $entries);
$this->view->setContent(Core\Functions::confirmBox($this->lang->t('system', 'confirm_delete'), $this->uri->route($moduleConfirmUrl) . 'entries_' . $marked_entries . '/action_confirmed/', $this->uri->route($moduleIndexUrl)));
} else {
return $entries;
}
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -6,26 +6,31 @@ namespace ACP3\Core;
*
* @author Tino Goratsch
*/
abstract class Registry {
private static $registry = array();
abstract class Registry
{
private static $registry = array();
public static function set($key, $value) {
if (isset(self::$registry[$key]) === false) {
self::$registry[$key] = $value;
}
}
public static function set($key, $value)
{
if (isset(self::$registry[$key]) === false) {
self::$registry[$key] = $value;
}
}
public static function get($class) {