converted some more modules to the new layout

beware: there are some bugs to fix
parent 8ca07cf4
......@@ -70,10 +70,10 @@ class Date {
{
$dateformat = array();
$dateformat[0]['value'] = 'short';
$dateformat[0]['selected'] = selectEntry('dateformat', 'short', $format);
$dateformat[0]['selected'] = Functions::selectEntry('dateformat', 'short', $format);
$dateformat[0]['lang'] = \ACP3\CMS::$injector['Lang']->t('system', 'date_format_short');
$dateformat[1]['value'] = 'long';
$dateformat[1]['selected'] = selectEntry('dateformat', 'long', $format);
$dateformat[1]['selected'] = Functions::selectEntry('dateformat', 'long', $format);
$dateformat[1]['lang'] = \ACP3\CMS::$injector['Lang']->t('system', 'date_format_long');
return $dateformat;
......
......@@ -9,7 +9,7 @@ class FeedGenerator extends AbstractRenderer {
require_once LIBRARIES_DIR . 'feedcreator/FeedWriter.php';
require_once LIBRARIES_DIR . 'feedcreator/FeedItem.php';
$this->renderer = new FeedWriter($this->config['feed_type']);
$this->renderer = new \FeedWriter($this->config['feed_type']);
$this->generateChannel();
}
......
......@@ -22,7 +22,7 @@ class AcpAdmin extends Core\ModuleController {
$mods = array();
foreach ($mod_list as $name => $info) {
$dir = $info['dir'];
$dir = strtolower($info['dir']);
if (Core\Modules::check($dir, 'acp_list') === true && $dir !== 'acp') {
$mods[$name]['name'] = $name;
$mods[$name]['dir'] = $dir;
......
......@@ -160,8 +160,6 @@ class ArticlesAdmin extends Core\ModuleController {
{
if (Core\Validate::isNumber($this->injector['URI']->id) === true &&
$this->injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'articles WHERE id = ?', array($this->injector['URI']->id)) == 1) {
require_once MODULES_DIR . 'articles/functions.php';
if (isset($_POST['submit']) === true) {
if (Core\Validate::date($_POST['start'], $_POST['end']) === false)
$errors[] = $this->injector['Lang']->t('system', 'select_date');
......
This diff is collapsed.
<?php
/**
* Categories
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
namespace ACP3\Modules\Categories;
use ACP3\Core;
class CategoriesFunctions {
/**
* Erstellt den Cache für die Kategorien eines Moduls
*
* @param string $module
* Das Modul, für welches der Kategorien-Cache erstellt werden soll
* @return boolean
*/
public static function setCategoriesCache($module) {
$data = \ACP3\CMS::$injector['Db']->fetchAll('SELECT c.id, c.title, c.picture, c.description FROM ' . DB_PRE . 'categories AS c JOIN ' . DB_PRE . 'modules AS m ON(m.id = c.module_id) WHERE m.name = ? ORDER BY c.title ASC', array($module));
return Core\Cache::create($module, $data, 'categories');
}
/**
* Gibt die gecacheten Kategorien des jeweiligen Moduls zurück
*
* @param string $module
* Das jeweilige Modul, für welches die Kategorien geholt werden sollen
* @return array
*/
public static function getCategoriesCache($module) {
if (Core\Cache::check($module, 'categories') === false)
self::setCategoriesCache($module);
return Core\Cache::output($module, 'categories');
}
/**
* Überprüft, ob eine Kategorie existiert
*
* @param integer $category_id
* @return boolean
*/
public static function categoriesCheck($category_id) {
return \ACP3\CMS::$injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'categories WHERE id = ?', array($category_id)) == 1 ? true : false;
}
/**
* Überprüft, ob bereits eine Kategorie mit dem selben Namen existiert
*
* @param string $title
* @param string $module
* @param integer $category_id
* @return boolean
*/
public static function categoriesCheckDuplicate($title, $module, $category_id = '') {
return \ACP3\CMS::$injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'categories AS c JOIN ' . DB_PRE . 'modules AS m ON(m.id = c.module_id) WHERE c.title = ? AND m.name = ? AND c.id != ?', array($title, $module, $category_id)) != 0 ? true : false;
}
/**
* Erzeugt eine neue Kategorie und gibt ihre ID zurück
*
* @param string $title
* @param string $module
* @return integer
*/
public static function categoriesCreate($title, $module) {
if (self::categoriesCheckDuplicate($title, $module) === false) {
$mod_id = \ACP3\CMS::$injector['Db']->fetchColumn('SELECT id FROM ' . DB_PRE . 'modules WHERE name = ?', array($module));
$insert_values = array(
'id' => '',
'title' => Core\Functions::str_encode($title),
'picture' => '',
'description' => '',
'module_id' => $mod_id,
);
\ACP3\CMS::$injector['Db']->beginTransaction();
try {
\ACP3\CMS::$injector['Db']->insert(DB_PRE . 'categories', $insert_values);
$last_id = \ACP3\CMS::$injector['Db']->lastInsertId();
\ACP3\CMS::$injector['Db']->commit();
setCategoriesCache($module);
return $last_id;
} catch (\Exception $e) {
\ACP3\CMS::$injector['Db']->rollback();
}
}
return 0;
}
/**
* Listet alle Kategorien eines Moduls auf
*
* @param string $module
* @param string $category_id
* @param boolean $category_create
* @param string $form_field_name
* @return string
*/
public static function categoriesList($module, $category_id = '', $category_create = false, $form_field_name = 'cat', $custom_text = '') {
$categories = array();
$data = self::getCategoriesCache($module);
$c_data = count($data);
$categories['custom_text'] = !empty($custom_text) ? $custom_text : \ACP3\CMS::$injector['Lang']->t('system', 'pls_select');
$categories['name'] = $form_field_name;
if ($c_data > 0) {
for ($i = 0; $i < $c_data; ++$i) {
$data[$i]['selected'] = Core\Functions::selectEntry('cat', $data[$i]['id'], $category_id);
}
$categories['categories'] = $data;
} else {
$categories['categories'] = array();
}
if ($category_create === true && Core\Modules::check('categories', 'acp_create') === true) {
$categories['create']['name'] = $form_field_name . '_create';
$categories['create']['value'] = isset($_POST[$categories['create']['name']]) ? $_POST[$categories['create']['name']] : '';
}
\ACP3\CMS::$injector['View']->assign('categories', $categories);
return \ACP3\CMS::$injector['View']->fetchTemplate('categories/create_list.tpl');
}
}
\ No newline at end of file
<?php
/**
* Categories
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ADM') === false)
exit;
require_once MODULES_DIR . 'categories/functions.php';
if (isset($_POST['submit']) === true) {
if (!empty($_FILES['picture']['name'])) {
$file['tmp_name'] = $_FILES['picture']['tmp_name'];
$file['name'] = $_FILES['picture']['name'];
$file['size'] = $_FILES['picture']['size'];
}
$settings = ACP3\Core\Config::getSettings('categories');
if (strlen($_POST['title']) < 3)
$errors['title'] = ACP3\CMS::$injector['Lang']->t('categories', 'title_to_short');
if (strlen($_POST['description']) < 3)
$errors['description'] = ACP3\CMS::$injector['Lang']->t('categories', 'description_to_short');
if (!empty($file) &&
(empty($file['tmp_name']) ||
empty($file['size']) ||
ACP3\Core\Validate::isPicture($file['tmp_name'], $settings['width'], $settings['height'], $settings['filesize']) === false ||
$_FILES['picture']['error'] !== UPLOAD_ERR_OK))
$errors['picture'] = ACP3\CMS::$injector['Lang']->t('categories', 'invalid_image_selected');
if (empty($_POST['module']))
$errors['module'] = ACP3\CMS::$injector['Lang']->t('categories', 'select_module');
if (strlen($_POST['title']) >= 3 && categoriesCheckDuplicate($_POST['title'], $_POST['module']))
$errors['title'] = ACP3\CMS::$injector['Lang']->t('categories', 'category_already_exists');
if (isset($errors) === true) {
ACP3\CMS::$injector['View']->assign('error_msg', Core\Functions::errorBox($errors));
} elseif (ACP3\Core\Validate::formToken() === false) {
ACP3\CMS::$injector['View']->setContent(Core\Functions::errorBox(ACP3\CMS::$injector['Lang']->t('system', 'form_already_submitted')));
} else {
$file_sql = null;
if (!empty($file)) {
$result = moveFile($file['tmp_name'], $file['name'], 'categories');
$file_sql = array('picture' => $result['name']);
}
$mod_id = ACP3\CMS::$injector['Db']->fetchColumn('SELECT id FROM ' . DB_PRE . 'modules WHERE name = ?', array($_POST['module']));
$insert_values = array(
'id' => '',
'title' => ACP3\Core\Functions::str_encode($_POST['title']),
'description' => ACP3\Core\Functions::str_encode($_POST['description']),
'module_id' => $mod_id,
);
if (is_array($file_sql) === true) {
$insert_values = array_merge($insert_values, $file_sql);
}
$bool = ACP3\CMS::$injector['Db']->insert(DB_PRE . 'categories', $insert_values);
setCategoriesCache($_POST['module']);
ACP3\CMS::$injector['Session']->unsetFormToken();
ACP3\Core\Functions::setRedirectMessage($bool, ACP3\CMS::$injector['Lang']->t('system', $bool !== false ? 'create_success' : 'create_error'), 'acp/categories');
}
}
if (isset($_POST['submit']) === false || isset($errors) === true && is_array($errors) === true) {
ACP3\CMS::$injector['View']->assign('form', isset($_POST['submit']) ? $_POST : array('title' => '', 'description' => ''));
$mod_list = ACP3\Core\Modules::getActiveModules();
foreach ($mod_list as $name => $info) {
if ($info['active'] && in_array('categories', $info['dependencies']) === true) {
$mod_list[$name]['selected'] = ACP3\Core\Functions::selectEntry('module', $info['dir']);
} else {
unset($mod_list[$name]);
}
}
ACP3\CMS::$injector['View']->assign('mod_list', $mod_list);
ACP3\CMS::$injector['Session']->generateFormToken();
}
<?php
/**
* Categories
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ADM') === false)
exit;
if (isset($_POST['entries']) && is_array($_POST['entries']) === true)
$entries = $_POST['entries'];
elseif (ACP3\Core\Validate::deleteEntries(ACP3\CMS::$injector['URI']->entries) === true)
$entries = ACP3\CMS::$injector['URI']->entries;
if (!isset($entries)) {
ACP3\CMS::$injector['View']->setContent(Core\Functions::errorBox(ACP3\CMS::$injector['Lang']->t('system', 'no_entries_selected')));
} elseif (is_array($entries) === true) {
$marked_entries = implode('|', $entries);
ACP3\CMS::$injector['View']->setContent(confirmBox(ACP3\CMS::$injector['Lang']->t('system', 'confirm_delete'), ACP3\CMS::$injector['URI']->route('acp/categories/delete/entries_' . $marked_entries . '/action_confirmed/'), ACP3\CMS::$injector['URI']->route('acp/categories')));
} elseif (ACP3\CMS::$injector['URI']->action === 'confirmed') {
require_once MODULES_DIR . 'categories/functions.php';
$marked_entries = explode('|', $entries);
$bool = false;
$in_use = false;
foreach ($marked_entries as $entry) {
if (!empty($entry) && ACP3\CMS::$injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'categories WHERE id = ?', array($entry)) == 1) {
$category = ACP3\CMS::$injector['Db']->fetchAssoc('SELECT c.picture, m.name AS module FROM ' . DB_PRE . 'categories AS c JOIN ' . DB_PRE . 'modules AS m ON(m.id = c.module_id) WHERE c.id = ?', array($entry));
if (ACP3\CMS::$injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . $category['module'] . ' WHERE category_id = ?', array($entry)) > 0) {
$in_use = true;
} else {
// Kategoriebild ebenfalls löschen
removeUploadedFile('categories', $category['picture']);
$bool = ACP3\CMS::$injector['Db']->delete(DB_PRE . 'categories', array('id' => $entry));
}
}
}
ACP3\Core\Cache::purge('sql', 'categories');
if ($in_use === true) {
$text = ACP3\CMS::$injector['Lang']->t('categories', 'category_is_in_use');
$bool = false;
} else {
$text = ACP3\CMS::$injector['Lang']->t('system', $bool !== false ? 'delete_success' : 'delete_error');
}
ACP3\Core\Functions::setRedirectMessage($bool, $text, 'acp/categories');
} else {
ACP3\CMS::$injector['URI']->redirect('errors/404');
}
<?php
/**
* Categories
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ADM') === false)
exit;
if (ACP3\Core\Validate::isNumber(ACP3\CMS::$injector['URI']->id) === true &&
ACP3\CMS::$injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'categories WHERE id = ?', array(ACP3\CMS::$injector['URI']->id)) == 1) {
require_once MODULES_DIR . 'categories/functions.php';
if (isset($_POST['submit']) === true) {
if (!empty($_FILES['picture']['name'])) {
$file['tmp_name'] = $_FILES['picture']['tmp_name'];
$file['name'] = $_FILES['picture']['name'];
$file['size'] = $_FILES['picture']['size'];
}
$settings = ACP3\Core\Config::getSettings('categories');
$module = ACP3\CMS::$injector['Db']->fetchAssoc('SELECT m.name FROM ' . DB_PRE . 'modules AS m JOIN ' . DB_PRE . 'categories AS c ON(m.id = c.module_id) WHERE c.id = ?', array(ACP3\CMS::$injector['URI']->id));
if (strlen($_POST['title']) < 3)
$errors['title'] = ACP3\CMS::$injector['Lang']->t('categories', 'title_to_short');
if (strlen($_POST['description']) < 3)
$errors['description'] = ACP3\CMS::$injector['Lang']->t('categories', 'description_to_short');
if (!empty($file) &&
(empty($file['tmp_name']) ||
empty($file['size']) ||
ACP3\Core\Validate::isPicture($file['tmp_name'], $settings['width'], $settings['height'], $settings['filesize']) === false ||
$_FILES['file']['error'] !== UPLOAD_ERR_OK))
$errors['picture'] = ACP3\CMS::$injector['Lang']->t('categories', 'invalid_image_selected');
if (strlen($_POST['title']) >= 3 && categoriesCheckDuplicate($_POST['title'], $module['name'], ACP3\CMS::$injector['URI']->id))
$errors['title'] = ACP3\CMS::$injector['Lang']->t('categories', 'category_already_exists');
if (isset($errors) === true) {
ACP3\CMS::$injector['View']->assign('error_msg', Core\Functions::errorBox($errors));
} elseif (ACP3\Core\Validate::formToken() === false) {
ACP3\CMS::$injector['View']->setContent(Core\Functions::errorBox(ACP3\CMS::$injector['Lang']->t('system', 'form_already_submitted')));
} else {
$new_file_sql = null;
if (isset($file) && is_array($file)) {
$result = moveFile($file['tmp_name'], $file['name'], 'categories');
$new_file_sql['picture'] = $result['name'];
}
$update_values = array(
'title' => ACP3\Core\Functions::str_encode($_POST['title']),
'description' => ACP3\Core\Functions::str_encode($_POST['description']),
);
if (is_array($new_file_sql) === true) {
$old_file = ACP3\CMS::$injector['Db']->fetchColumn('SELECT picture FROM ' . DB_PRE . 'categories WEHRE id = ?', array(ACP3\CMS::$injector['URI']->id));
removeUploadedFile('categories', $old_file);
$update_values = array_merge($update_values, $new_file_sql);
}
$bool = ACP3\CMS::$injector['Db']->update(DB_PRE . 'categories', $update_values, array('id' => ACP3\CMS::$injector['URI']->id));
setCategoriesCache($module['name']);
ACP3\CMS::$injector['Session']->unsetFormToken();
ACP3\Core\Functions::setRedirectMessage($bool, ACP3\CMS::$injector['Lang']->t('system', $bool !== false ? 'edit_success' : 'edit_error'), 'acp/categories');
}
}
if (isset($_POST['submit']) === false || isset($errors) === true && is_array($errors) === true) {
$category = ACP3\CMS::$injector['Db']->fetchAssoc('SELECT title, description FROM ' . DB_PRE . 'categories WHERE id = ?', array(ACP3\CMS::$injector['URI']->id));
ACP3\CMS::$injector['View']->assign('form', isset($_POST['submit']) ? $_POST : $category);
ACP3\CMS::$injector['Session']->generateFormToken();
}
} else {
ACP3\CMS::$injector['URI']->redirect('errors/404');
}
<?php
/**
* Categories
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ADM') === false)
exit;
ACP3\Core\Functions::getRedirectMessage();
$categories = ACP3\CMS::$injector['Db']->fetchAll('SELECT c.id, c.title, c.description, m.name AS module FROM ' . DB_PRE . 'categories AS c JOIN ' . DB_PRE . 'modules AS m ON(m.id = c.module_id) ORDER BY m.name ASC, c.title DESC, c.id DESC');
$c_categories = count($categories);
if ($c_categories > 0) {
$can_delete = ACP3\Core\Modules::check('categories', 'acp_delete');
$config = array(
'element' => '#acp-table',
'sort_col' => $can_delete === true ? 1 : 0,
'sort_dir' => 'desc',
'hide_col_sort' => $can_delete === true ? 0 : ''
);
ACP3\CMS::$injector['View']->appendContent(ACP3\Core\Functions::datatable($config));
for ($i = 0; $i < $c_categories; ++$i) {
$categories[$i]['module'] = ACP3\CMS::$injector['Lang']->t($categories[$i]['module'], $categories[$i]['module']);
}
ACP3\CMS::$injector['View']->assign('categories', $categories);
ACP3\CMS::$injector['View']->assign('can_delete', $can_delete);
}
\ No newline at end of file
<?php
/**
* Categories
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ADM') === false)
exit;
if (isset($_POST['submit']) === true) {
if (ACP3\Core\Validate::isNumber($_POST['width']) === false)
$errors['width'] = ACP3\CMS::$injector['Lang']->t('categories', 'invalid_image_width_entered');
if (ACP3\Core\Validate::isNumber($_POST['height']) === false)
$errors['height'] = ACP3\CMS::$injector['Lang']->t('categories', 'invalid_image_height_entered');
if (ACP3\Core\Validate::isNumber($_POST['filesize']) === false)
$errors['filesize'] = ACP3\CMS::$injector['Lang']->t('categories', 'invalid_image_filesize_entered');
if (isset($errors) === true) {
ACP3\CMS::$injector['View']->assign('error_msg', Core\Functions::errorBox($errors));
} elseif (ACP3\Core\Validate::formToken() === false) {
ACP3\CMS::$injector['View']->setContent(Core\Functions::errorBox(ACP3\CMS::$injector['Lang']->t('system', 'form_already_submitted')));
} else {
$data = array(
'width' => (int) $_POST['width'],
'height' => (int) $_POST['height'],
'filesize' => (int) $_POST['filesize'],
);
$bool = ACP3\Core\Config::setSettings('categories', $data);
ACP3\CMS::$injector['Session']->unsetFormToken();
ACP3\Core\Functions::setRedirectMessage($bool, ACP3\CMS::$injector['Lang']->t('system', $bool === true ? 'settings_success' : 'settings_error'), 'acp/categories');
}
}
if (isset($_POST['submit']) === false || isset($errors) === true && is_array($errors) === true) {
$settings = ACP3\Core\Config::getSettings('categories');
ACP3\CMS::$injector['View']->assign('form', isset($_POST['submit']) ? $_POST : $settings);
ACP3\CMS::$injector['Session']->generateFormToken();
}
<?php
/**
* Categories
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
/**
* Erstellt den Cache für die Kategorien eines Moduls
*
* @param string $module
* Das Modul, für welches der Kategorien-Cache erstellt werden soll
* @return boolean
*/
function setCategoriesCache($module)
{
$data = ACP3\CMS::$injector['Db']->fetchAll('SELECT c.id, c.title, c.picture, c.description FROM ' . DB_PRE . 'categories AS c JOIN ' . DB_PRE . 'modules AS m ON(m.id = c.module_id) WHERE m.name = ? ORDER BY c.title ASC', array($module));
return ACP3\Core\Cache::create($module, $data, 'categories');
}
/**
* Bindet die gecacheten Kategorien des jeweiligen Moduls ein
*
* @param string $module
* Das jeweilige Modul, für welches die Kategorien geholt werden sollen
* @return array
*/
function getCategoriesCache($module)
{
if (ACP3\Core\Cache::check($module, 'categories') === false)
setCategoriesCache($module);
return ACP3\Core\Cache::output($module, 'categories');
}
/**
* Überprüft, ob eine Kategorie überhaupt existiert
*
* @param integer $category_id
* @return boolean
*/
function categoriesCheck($category_id)
{
return ACP3\CMS::$injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'categories WHERE id = ?', array($category_id)) == 1 ? true : false;
}
/**
* Überprüft, ob bereits eine Kategorie mit dem selben Namen existiert
*
* @param string $title
* @param string $module
* @param integer $category_id
* @return boolean
*/
function categoriesCheckDuplicate($title, $module, $category_id = '')
{
return ACP3\CMS::$injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'categories AS c JOIN ' . DB_PRE . 'modules AS m ON(m.id = c.module_id) WHERE c.title = ? AND m.name = ? AND c.id != ?', array($title, $module, $category_id)) != 0 ? true : false;
}
/**
* Erzeugt eine neue Kategorie und gibt ihre ID zurück
*
* @param string $title
* @param string $module
* @return integer
*/
function categoriesCreate($title, $module)
{
if (categoriesCheckDuplicate($title, $module) === false) {
$mod_id = ACP3\CMS::$injector['Db']->fetchColumn('SELECT id FROM ' . DB_PRE . 'modules WHERE name = ?', array($module));
$insert_values = array(
'id' => '',
'title' => ACP3\Core\Functions::str_encode($title),
'picture' => '',
'description' => '',
'module_id' => $mod_id,
);
ACP3\CMS::$injector['Db']->beginTransaction();
try {
ACP3\CMS::$injector['Db']->insert(DB_PRE . 'categories', $insert_values);
$last_id = ACP3\CMS::$injector['Db']->lastInsertId();
ACP3\CMS::$injector['Db']->commit();
setCategoriesCache($module);
return $last_id;
} catch (\Exception $e) {
ACP3\CMS::$injector['Db']->rollback();
}
}
return 0;
}
/**
* Listet alle Kategorien eines Moduls auf
*
* @param string $module
* @param string $category_id
* @param boolean $category_create
* @param string $form_field_name
* @return string
*/
function categoriesList($module, $category_id = '', $category_create = false, $form_field_name = 'cat', $custom_text = '') {
$categories = array();
$data = getCategoriesCache($module);
$c_data = count($data);
$categories['custom_text'] = !empty($custom_text) ? $custom_text : ACP3\CMS::$injector['Lang']->t('system', 'pls_select');
$categories['name'] = $form_field_name;
if ($c_data > 0) {
for ($i = 0; $i < $c_data; ++$i) {
$data[$i]['selected'] = ACP3\Core\Functions::selectEntry('cat', $data[$i]['id'], $category_id);
}
$categories['categories'] = $data;
} else {
$categories['categories'] = array();
}
if ($category_create === true && ACP3\Core\Modules::check('categories', 'acp_create') === true) {
$categories['create']['name'] = $form_field_name . '_create';
$categories['create']['value'] = isset($_POST[$categories['create']['name']]) ? $_POST[$categories['create']['name']] : '';
}
ACP3\CMS::$injector['View']->assign('categories', $categories);
return ACP3\CMS::$injector['View']->fetchTemplate('categories/create_list.tpl');
}
\ No newline at end of file
This diff is collapsed.
<?php
namespace ACP3\Modules\Comments;
use ACP3\Core;
/**
* Description of CommentsFrontend
*
* @author Tino
*/
class CommentsFrontend extends Core\ModuleController {
public function __construct($injector) {
parent::__construct($injector);
}
public function actionCreate($module, $entry_id) {
$captchaAccess = Core\Modules::check('captcha', 'image');
// Formular für das Eintragen von Kommentaren
if (isset($_POST['submit']) === true) {
$ip = $_SERVER['REMOTE_ADDR'];
// Flood Sperre
$flood = $this->injector['Db']->fetchColumn('SELECT MAX(date) FROM ' . DB_PRE . 'comments WHERE ip = ?', array($ip));
if (!empty($flood)) {
$flood_time = $this->injector['Date']->timestamp($flood) + CONFIG_FLOOD;
}
$time = $this->injector['Date']->timestamp();
if (isset($flood_time) && $flood_time > $time)
$errors[] = sprintf($this->injector['Lang']->t('system', 'flood_no_entry_possible'), $flood_time - $time);
if (empty($_POST['name']))
$errors['name'] = $this->injector['Lang']->t('system', 'name_to_short');
if (strlen($_POST['message']) < 3)
$errors['message'] = $this->injector['Lang']->t('system', 'message_to_short');
if (Core\Modules::check($_POST['module'], 'list') === false || Core\Validate::isNumber($_POST['entry_id']) === false)
$errors[] = $this->injector['Lang']->t('comments', 'module_doesnt_exist');
if ($captchaAccess === true && $this->injector['Auth']->isUser() === false && Core\Validate::captcha($_POST['captcha']) === false)
$errors['captcha'] = $this->injector['Lang']->t('captcha', 'invalid_captcha_entered');
if (isset($errors) === true) {
$this->injector['View']->assign('error_msg', Core\Functions::errorBox($errors));
} elseif (Core\Validate::formToken() === false) {
return Core\Functions::errorBox($this->injector['Lang']->t('system', 'form_already_submitted'));
} else {
$mod_id = $this->injector['Db']->fetchColumn('SELECT id FROM ' . DB_PRE . 'modules WHERE name = ?', array($_POST['module']));
$insert_values = array(
'id' => '',
'date' => $this->injector['Date']->getCurrentDateTime(),
'ip' => $ip,
'name' => Core\Functions::str_encode($_POST['name']),
'user_id' => $this->injector['Auth']->isUser() === true && Core\Validate::isNumber($this->injector['Auth']->getUserId() === true) ? $this->injector['Auth']->getUserId() : '',
'message' => Core\Functions::str_encode($_POST['message']),
'module_id' => $mod_id,
'entry_id' => $_POST['entry_id'],
);
$bool = $this->injector['Db']->insert(DB_PRE . 'comments', $insert_values);
$this->injector['Session']->unsetFormToken();
Core\Functions::setRedirectMessage($bool, $this->injector['Lang']->t('system', $bool !== false ? 'create_success' : 'create_error'), $this->injector['URI']->query);
}
}
if (isset($_POST['submit']) === false || isset($errors) === true && is_array($errors) === true) {
$settings = Core\Config::getSettings('comments');
// Emoticons einbinden, falls diese aktiv sind
if (Core\Modules::check('emoticons', 'functions') === true && $settings['emoticons'] == 1) {
require_once MODULES_DIR . 'emoticons/functions.php';