- converted files and gallery module to the new structure

- some fixes
parent fd528294
......@@ -392,7 +392,7 @@ class Functions {
* @param string $dir
* Ordner, in den die Datei verschoben werden soll
* @return array
* Gibt ein Array mit dem Namen und der Größe der neuen Datei aus
* Gibt ein Array mit dem Namen und der Größe der neuen Datei zurück
*/
public static function moveFile($tmp_filename, $filename, $dir)
{
......@@ -411,7 +411,7 @@ class Functions {
} else {
$new_file = array();
$new_file['name'] = $new_name . $ext;
$new_file['size'] = calcFilesize(filesize($path . $new_file['name']));
$new_file['size'] = self::calcFilesize(filesize($path . $new_file['name']));
return $new_file;
}
......
......@@ -283,8 +283,8 @@ class SEO
public static function insertUriAlias($path, $alias, $keywords = '', $description = '', $robots = 0)
{
$path.= !preg_match('/\/$/', $path) ? '/' : '';
$keywords = str_encode($keywords);
$description = str_encode($description);
$keywords = Functions::str_encode($keywords);
$description = Functions::str_encode($description);
// Vorhandenen Alias aktualisieren
if (\ACP3\CMS::$injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'seo WHERE uri = ?', array($path)) == 1) {
......
This diff is collapsed.
<?php
namespace ACP3\Modules\Files;
use ACP3\Core;
/**
* Description of FilesFrontend
*
* @author Tino
*/
class FilesFrontend extends Core\ModuleController {
public function __construct($injector) {
parent::__construct($injector);
}
public function actionList() {
if (Core\Modules::isActive('categories') === true) {
$categories = \ACP3\Modules\Categories\CategoriesFunctions::getCategoriesCache('files');
if (count($categories) > 0) {
$this->injector['View']->assign('categories', $categories);
}
}
}
public function actionDetails() {
$period = ' AND (start = end AND start <= :time OR :time BETWEEN start AND end)';
if (Core\Validate::isNumber($this->injector['URI']->id) === true &&
$this->injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'files WHERE id = :id' . $period, array('id' => $this->injector['URI']->id, 'time' => $this->injector['Date']->getCurrentDateTime())) == 1) {
$file = FilesFunctions::getFilesCache($this->injector['URI']->id);
if ($this->injector['URI']->action === 'download') {
$path = UPLOADS_DIR . 'files/';
if (is_file($path . $file['file'])) {
// Schönen Dateinamen generieren
$ext = strrchr($file['file'], '.');
$filename = Core\Functions::makeStringUrlSafe($file['title']) . $ext;
header('Content-Type: application/force-download');
header('Content-Transfer-Encoding: binary');
header('Content-Length:' . filesize($path . $file['file']));
header('Content-Disposition: attachment; filename="' . $filename . '"');
readfile($path . $file['file']);
exit;
// Externe Datei
} elseif (preg_match('/^([a-z]+):\/\//', $file['file'])) {
$this->injector['URI']->redirect(0, $file['file']);
} else {
$this->injector['URI']->redirect('errors/404');
}
} else {
// Brotkrümelspur
$this->injector['Breadcrumb']->append($this->injector['Lang']->t('files', 'files'), $this->injector['URI']->route('files'))
->append($file['category_name'], $this->injector['URI']->route('files/files/cat_' . $file['category_id']))
->append($file['title']);
$settings = Core\Config::getSettings('files');
$file['size'] = !empty($file['size']) ? $file['size'] : $this->injector['Lang']->t('files', 'unknown_filesize');
$file['date_formatted'] = $this->injector['Date']->format($file['start'], $settings['dateformat']);
$file['date_iso'] = $this->injector['Date']->format($file['start'], 'c');
$this->injector['View']->assign('file', $file);
if ($settings['comments'] == 1 && $file['comments'] == 1 && Core\Modules::check('comments', 'functions') === true) {
require_once MODULES_DIR . 'comments/functions.php';
$this->injector['View']->assign('comments', commentsList('files', $this->injector['URI']->id));
}
}
} else {
$this->injector['URI']->redirect('errors/404');
}
}
public function actionFiles() {
if (Core\Validate::isNumber($this->injector['URI']->cat) &&
$this->injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'categories WHERE id = ?', array($this->injector['URI']->cat)) == 1) {
$category = $this->injector['Db']->fetchColumn('SELECT title FROM ' . DB_PRE . 'categories WHERE id = ?', array($this->injector['URI']->cat));
$this->injector['Breadcrumb']
->append($this->injector['Lang']->t('files', 'files'), $this->injector['URI']->route('files'))
->append($category);
$period = ' AND (start = end AND start <= :time OR start != end AND :time BETWEEN start AND end)';
$files = $this->injector['Db']->fetchAll('SELECT id, start, file, size, title FROM ' . DB_PRE . 'files WHERE category_id = :cat_id' . $period . ' ORDER BY start DESC, end DESC, id DESC', array('cat_id' => $this->injector['URI']->cat, 'time' => $this->injector['Date']->getCurrentDateTime()));
$c_files = count($files);
if ($c_files > 0) {
$settings = Core\Config::getSettings('files');
for ($i = 0; $i < $c_files; ++$i) {
$files[$i]['size'] = !empty($files[$i]['size']) ? $files[$i]['size'] : $this->injector['Lang']->t('files', 'unknown_filesize');
$files[$i]['date_formatted'] = $this->injector['Date']->format($files[$i]['start'], $settings['dateformat']);
$files[$i]['date_iso'] = $this->injector['Date']->format($files[$i]['start'], 'c');
}
$this->injector['View']->assign('files', $files);
}
} else {
$this->injector['URI']->redirect('errors/404');
}
}
public function actionSidebar() {
$settings = Core\Config::getSettings('files');
$where = 'start = end AND start <= :time OR start != end AND :time BETWEEN start AND end';
$files = $this->injector['Db']->fetchAll('SELECT id, start, title FROM ' . DB_PRE . 'files WHERE ' . $where . ' ORDER BY start DESC LIMIT ' . $settings['sidebar'], array('time' => $this->injector['Date']->getCurrentDateTime()));
$c_files = count($files);
if ($c_files > 0) {
for ($i = 0; $i < $c_files; ++$i) {
$files[$i]['start'] = $this->injector['Date']->format($files[$i]['start']);
$files[$i]['title_short'] = Core\Functions::shortenEntry($files[$i]['title'], 30, 5, '...');
}
$this->injector['View']->assign('sidebar_files', $files);
}
$this->injector['View']->displayTemplate('files/sidebar.tpl');
}
}
\ No newline at end of file
<?php
/**
* Files
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
namespace ACP3\Modules\Files;
use ACP3\Core\Cache;
class FilesFunctions {
/**
* Setzt das Cache für einen Download
*
* @param integer $id
* Die ID des zu cachenden Download
* @return boolean
*/
public static function setFilesCache($id) {
$data = \ACP3\CMS::$injector['Db']->fetchAssoc('SELECT f.id, f.start, f.category_id, f.file, f.size, f.title, f.text, f.comments, c.title AS category_name FROM ' . DB_PRE . 'files AS f, ' . DB_PRE . 'categories AS c WHERE f.id = ? AND f.category_id = c.id', array($id));
return Cache::create('details_id_' . $id, $data, 'files');
}
/**
* Gibt den Cache eines Downloads aus
*
* @param integer $id
* ID des Downloads
* @return array
*/
public static function getFilesCache($id) {
if (Cache::check('details_id_' . $id, 'files') === false)
self::setFilesCache($id);
return Cache::output('details_id_' . $id, 'files');
}
}
\ No newline at end of file
<?php
/**
* Files
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ADM') === false)
exit;
require_once MODULES_DIR . 'categories/functions.php';
$settings = ACP3\Core\Config::getSettings('files');
if (isset($_POST['submit']) === true) {
if (isset($_POST['external'])) {
$file = $_POST['file_external'];
} else {
$file['tmp_name'] = $_FILES['file_internal']['tmp_name'];
$file['name'] = $_FILES['file_internal']['name'];
$file['size'] = $_FILES['file_internal']['size'];
}
if (ACP3\Core\Validate::date($_POST['start'], $_POST['end']) === false)
$errors[] = ACP3\CMS::$injector['Lang']->t('system', 'select_date');
if (strlen($_POST['title']) < 3)
$errors['link-title'] = ACP3\CMS::$injector['Lang']->t('files', 'type_in_title');
if (isset($_POST['external']) && (empty($file) || empty($_POST['filesize']) || empty($_POST['unit'])))
$errors['external'] = ACP3\CMS::$injector['Lang']->t('files', 'type_in_external_resource');
if (!isset($_POST['external']) &&
(empty($file['tmp_name']) || empty($file['size']) || $_FILES['file_internal']['error'] !== UPLOAD_ERR_OK))
$errors['file-internal'] = ACP3\CMS::$injector['Lang']->t('files', 'select_internal_resource');
if (strlen($_POST['text']) < 3)
$errors['text'] = ACP3\CMS::$injector['Lang']->t('files', 'description_to_short');
if (strlen($_POST['cat_create']) < 3 && categoriesCheck($_POST['cat']) === false)
$errors['cat'] = ACP3\CMS::$injector['Lang']->t('files', 'select_category');
if (strlen($_POST['cat_create']) >= 3 && categoriesCheckDuplicate($_POST['cat_create'], 'files') === true)
$errors['cat-create'] = ACP3\CMS::$injector['Lang']->t('categories', 'category_already_exists');
if ((bool) CONFIG_SEO_ALIASES === true && !empty($_POST['alias']) && (ACP3\Core\Validate::isUriSafe($_POST['alias']) === false || ACP3\Core\Validate::uriAliasExists($_POST['alias']) === true))
$errors['alias'] = ACP3\CMS::$injector['Lang']->t('system', 'uri_alias_unallowed_characters_or_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 {
if (is_array($file) === true) {
$result = Core\Functions::moveFile($file['tmp_name'], $file['name'], 'files');
$new_file = $result['name'];
$filesize = $result['size'];
} else {
$_POST['filesize'] = (float) $_POST['filesize'];
$new_file = $file;
$filesize = $_POST['filesize'] . ' ' . $_POST['unit'];
}
$insert_values = array(
'id' => '',
'start' => ACP3\CMS::$injector['Date']->toSQL($_POST['start']),
'end' => ACP3\CMS::$injector['Date']->toSQL($_POST['end']),
'category_id' => strlen($_POST['cat_create']) >= 3 ? categoriesCreate($_POST['cat_create'], 'files') : $_POST['cat'],
'file' => $new_file,
'size' => $filesize,
'title' => ACP3\Core\Functions::str_encode($_POST['title']),
'text' => ACP3\Core\Functions::str_encode($_POST['text'], true),
'comments' => $settings['comments'] == 1 && isset($_POST['comments']) ? 1 : 0,
'user_id' => ACP3\CMS::$injector['Auth']->getUserId(),
);
$bool = ACP3\CMS::$injector['Db']->insert(DB_PRE . 'files', $insert_values);
if ((bool) CONFIG_SEO_ALIASES === true && !empty($_POST['alias']))
ACP3\Core\SEO::insertUriAlias('files/details/id_' . ACP3\CMS::$injector['Db']->lastInsertId(), $_POST['alias'], $_POST['seo_keywords'], $_POST['seo_description'], (int) $_POST['seo_robots']);
ACP3\CMS::$injector['Session']->unsetFormToken();
ACP3\Core\Functions::setRedirectMessage($bool, ACP3\CMS::$injector['Lang']->t('system', $bool !== false ? 'create_success' : 'create_error'), 'acp/files');
}
}
if (isset($_POST['submit']) === false || isset($errors) === true && is_array($errors) === true) {
// Datumsauswahl
ACP3\CMS::$injector['View']->assign('publication_period', ACP3\CMS::$injector['Date']->datepicker(array('start', 'end')));
$units = array('Byte', 'KiB', 'MiB', 'GiB', 'TiB');
ACP3\CMS::$injector['View']->assign('units', ACP3\Core\Functions::selectGenerator('units', $units, $units, ''));
// Formularelemente
ACP3\CMS::$injector['View']->assign('categories', categoriesList('files', '', true));
if (ACP3\Core\Modules::check('comments', 'functions') === true && $settings['comments'] == 1) {
$options = array();
$options[0]['name'] = 'comments';
$options[0]['checked'] = ACP3\Core\Functions::selectEntry('comments', '1', '0', 'checked');
$options[0]['lang'] = ACP3\CMS::$injector['Lang']->t('system', 'allow_comments');
ACP3\CMS::$injector['View']->assign('options', $options);
}
ACP3\CMS::$injector['View']->assign('checked_external', isset($_POST['external']) ? ' checked="checked"' : '');
$defaults = array(
'title' => '',
'file_internal' => '',
'file_external' => '',
'filesize' => '',
'text' => '',
'alias' => '',
'seo_keywords' => '',
'seo_description' => '',
);
ACP3\CMS::$injector['View']->assign('SEO_FORM_FIELDS', ACP3\Core\SEO::formFields());
ACP3\CMS::$injector['View']->assign('form', isset($_POST['submit']) ? $_POST : $defaults);
ACP3\CMS::$injector['Session']->generateFormToken();
}
\ No newline at end of file
<?php
/**
* Files
*
* @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/files/delete/entries_' . $marked_entries . '/action_confirmed/'), ACP3\CMS::$injector['URI']->route('acp/files')));
} elseif (ACP3\CMS::$injector['URI']->action === 'confirmed') {
require_once MODULES_DIR . 'files/functions.php';
$marked_entries = explode('|', $entries);
$bool = false;
$commentsInstalled = ACP3\Core\Modules::isInstalled('comments');
foreach ($marked_entries as $entry) {
if (!empty($entry) && ACP3\CMS::$injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'files WHERE id = ?', array($entry)) == 1) {
// Datei ebenfalls löschen
$file = ACP3\CMS::$injector['Db']->fetchColumn('SELECT file FROM ' . DB_PRE . 'files WHERE id = ?', array($entry));
Core\Functions::removeUploadedFile('files', $file);
$bool = ACP3\CMS::$injector['Db']->delete(DB_PRE . 'files', array('id' => $entry));
if ($commentsInstalled === true)
ACP3\CMS::$injector['Db']->delete(DB_PRE . 'comments', array('module' => 'files', 'entry_id' => $entry));
ACP3\Core\Cache::delete('details_id_' . $entry, 'files');
ACP3\Core\SEO::deleteUriAlias('files/details/id_' . $entry);
}
}
ACP3\Core\Functions::setRedirectMessage($bool, ACP3\CMS::$injector['Lang']->t('system', $bool !== false ? 'delete_success' : 'delete_error'), 'acp/files');
} else {
ACP3\CMS::$injector['URI']->redirect('errors/404');
}
<?php
/**
* Files
*
* @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 . 'files WHERE id = ?', array(ACP3\CMS::$injector['URI']->id)) == 1) {
require_once MODULES_DIR . 'categories/functions.php';
$settings = ACP3\Core\Config::getSettings('files');
if (isset($_POST['submit']) === true) {
if (isset($_POST['external'])) {
$file = $_POST['file_external'];
} elseif (!empty($_FILES['file_internal']['name'])) {
$file['tmp_name'] = $_FILES['file_internal']['tmp_name'];
$file['name'] = $_FILES['file_internal']['name'];
$file['size'] = $_FILES['file_internal']['size'];
}
if (ACP3\Core\Validate::date($_POST['start'], $_POST['end']) === false)
$errors[] = ACP3\CMS::$injector['Lang']->t('system', 'select_date');
if (strlen($_POST['title']) < 3)
$errors['link-title'] = ACP3\CMS::$injector['Lang']->t('files', 'type_in_title');
if (isset($_POST['external']) && (empty($file) || empty($_POST['filesize']) || empty($_POST['unit'])))
$errors['external'] = ACP3\CMS::$injector['Lang']->t('files', 'type_in_external_resource');
if (!isset($_POST['external']) && isset($file) && is_array($file) &&
(empty($file['tmp_name']) || empty($file['size']) || $_FILES['file_internal']['error'] !== UPLOAD_ERR_OK))
$errors['file-internal'] = ACP3\CMS::$injector['Lang']->t('files', 'select_internal_resource');
if (strlen($_POST['text']) < 3)
$errors['text'] = ACP3\CMS::$injector['Lang']->t('files', 'description_to_short');
if (strlen($_POST['cat_create']) < 3 && categoriesCheck($_POST['cat']) === false)
$errors['cat'] = ACP3\CMS::$injector['Lang']->t('files', 'select_category');
if (strlen($_POST['cat_create']) >= 3 && categoriesCheckDuplicate($_POST['cat_create'], 'files') === true)
$errors['cat-create'] = ACP3\CMS::$injector['Lang']->t('categories', 'category_already_exists');
if ((bool) CONFIG_SEO_ALIASES === true && !empty($_POST['alias']) &&
(ACP3\Core\Validate::isUriSafe($_POST['alias']) === false || ACP3\Core\Validate::uriAliasExists($_POST['alias'], 'files/details/id_' . ACP3\CMS::$injector['URI']->id) === true))
$errors['alias'] = ACP3\CMS::$injector['Lang']->t('system', 'uri_alias_unallowed_characters_or_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;
// Falls eine neue Datei angegeben wurde, Änderungen durchführen
if (isset($file)) {
if (is_array($file) === true) {
$result = Core\Functions::moveFile($file['tmp_name'], $file['name'], 'files');
$new_file = $result['name'];
$filesize = $result['size'];
} else {
$_POST['filesize'] = (float) $_POST['filesize'];
$new_file = $file;
$filesize = $_POST['filesize'] . ' ' . $_POST['unit'];
}
// SQL Query für die Änderungen
$new_file_sql = array(
'file' => $new_file,
'size' => $filesize,
);
}
$update_values = array(
'start' => ACP3\CMS::$injector['Date']->toSQL($_POST['start']),
'end' => ACP3\CMS::$injector['Date']->toSQL($_POST['end']),
'category_id' => strlen($_POST['cat_create']) >= 3 ? categoriesCreate($_POST['cat_create'], 'files') : $_POST['cat'],
'title' => ACP3\Core\Functions::str_encode($_POST['title']),
'text' => ACP3\Core\Functions::str_encode($_POST['text'], true),
'comments' => $settings['comments'] == 1 && isset($_POST['comments']) ? 1 : 0,
'user_id' => ACP3\CMS::$injector['Auth']->getUserId(),
);
if (is_array($new_file_sql) === true) {
$old_file = ACP3\CMS::$injector['Db']->fetchColumn('SELECT file FROM ' . DB_PRE . 'files WHERE id = ?', array(ACP3\CMS::$injector['URI']->id));
Core\Functions::removeUploadedFile('files', $old_file);
$update_values = array_merge($update_values, $new_file_sql);
}
$bool = ACP3\CMS::$injector['Db']->update(DB_PRE . 'files', $update_values, array('id' => ACP3\CMS::$injector['URI']->id));
if ((bool) CONFIG_SEO_ALIASES === true && !empty($_POST['alias']))
ACP3\Core\SEO::insertUriAlias('files/details/id_' . ACP3\CMS::$injector['URI']->id, $_POST['alias'], $_POST['seo_keywords'], $_POST['seo_description'], (int) $_POST['seo_robots']);
require_once MODULES_DIR . 'files/functions.php';
setFilesCache(ACP3\CMS::$injector['URI']->id);
ACP3\CMS::$injector['Session']->unsetFormToken();
ACP3\Core\Functions::setRedirectMessage($bool, ACP3\CMS::$injector['Lang']->t('system', $bool !== false ? 'edit_success' : 'edit_error'), 'acp/files');
}
}
if (isset($_POST['submit']) === false || isset($errors) === true && is_array($errors) === true) {
$dl = ACP3\CMS::$injector['Db']->fetchAssoc('SELECT start, end, category_id, file, size, title, text, comments FROM ' . DB_PRE . 'files WHERE id = ?', array(ACP3\CMS::$injector['URI']->id));
// Datumsauswahl
ACP3\CMS::$injector['View']->assign('publication_period', ACP3\CMS::$injector['Date']->datepicker(array('start', 'end'), array($dl['start'], $dl['end'])));
$units = array('Byte', 'KiB', 'MiB', 'GiB', 'TiB');
ACP3\CMS::$injector['View']->assign('units', ACP3\Core\Functions::selectGenerator('units', $units, $units, trim(strrchr($dl['size'], ' '))));
$dl['filesize'] = substr($dl['size'], 0, strpos($dl['size'], ' '));
// Formularelemente
ACP3\CMS::$injector['View']->assign('categories', categoriesList('files', $dl['category_id'], true));
if (ACP3\Core\Modules::check('comments', 'functions') === true && $settings['comments'] == 1) {
$options = array();
$options[0]['name'] = 'comments';
$options[0]['checked'] = ACP3\Core\Functions::selectEntry('comments', '1', $dl['comments'], 'checked');
$options[0]['lang'] = ACP3\CMS::$injector['Lang']->t('system', 'allow_comments');
ACP3\CMS::$injector['View']->assign('options', $options);
}
ACP3\CMS::$injector['View']->assign('checked_external', isset($_POST['external']) ? ' checked="checked"' : '');
ACP3\CMS::$injector['View']->assign('current_file', $dl['file']);
ACP3\CMS::$injector['View']->assign('SEO_FORM_FIELDS', ACP3\Core\SEO::formFields('files/details/id_' . ACP3\CMS::$injector['URI']->id));
ACP3\CMS::$injector['View']->assign('form', isset($_POST['submit']) ? $_POST : $dl);
ACP3\CMS::$injector['Session']->generateFormToken();
}
} else {
ACP3\CMS::$injector['URI']->redirect('errors/403');
}
<?php
/**
* Files
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ADM') === false)
exit;
ACP3\Core\Functions::getRedirectMessage();
$files = ACP3\CMS::$injector['Db']->fetchAll('SELECT id, start, end, file, size, title FROM ' . DB_PRE . 'files ORDER BY start DESC, end DESC, id DESC');
$c_files = count($files);
if ($c_files > 0) {
$can_delete = ACP3\Core\Modules::check('files', '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_files; ++$i) {
$files[$i]['period'] = ACP3\CMS::$injector['Date']->formatTimeRange($files[$i]['start'], $files[$i]['end']);
$files[$i]['size'] = !empty($files[$i]['size']) ? $files[$i]['size'] : ACP3\CMS::$injector['Lang']->t('files', 'unknown_filesize');
}
ACP3\CMS::$injector['View']->assign('files', $files);
ACP3\CMS::$injector['View']->assign('can_delete', $can_delete);
}
\ No newline at end of file
<?php
/**
* Files
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ADM') === false)
exit;
$comments_active = ACP3\Core\Modules::isActive('comments');
if (isset($_POST['submit']) === true) {
if (empty($_POST['dateformat']) || ($_POST['dateformat'] !== 'long' && $_POST['dateformat'] !== 'short'))
$errors['dateformat'] = ACP3\CMS::$injector['Lang']->t('system', 'select_date_format');
if (ACP3\Core\Validate::isNumber($_POST['sidebar']) === false)
$errors['sidebar'] = ACP3\CMS::$injector['Lang']->t('system', 'select_sidebar_entries');
if ($comments_active === true && (!isset($_POST['comments']) || $_POST['comments'] != 1 && $_POST['comments'] != 0))
$errors[] = ACP3\CMS::$injector['Lang']->t('files', 'select_allow_comments');
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(
'dateformat' => ACP3\Core\Functions::str_encode($_POST['dateformat']),
'sidebar' => (int) $_POST['sidebar'],
'comments' => $_POST['comments']
);
$bool = ACP3\Core\Config::setSettings('files', $data);
ACP3\CMS::$injector['Session']->unsetFormToken();
ACP3\Core\Functions::setRedirectMessage($bool, ACP3\CMS::$injector['Lang']->t('system', $bool === true ? 'settings_success' : 'settings_error'), 'acp/files');
}
}
if (isset($_POST['submit']) === false || isset($errors) === true && is_array($errors) === true) {
$settings = ACP3\Core\Config::getSettings('files');
if ($comments_active === true) {
$lang_comments = array(ACP3\CMS::$injector['Lang']->t('system', 'yes'), ACP3\CMS::$injector['Lang']->t('system', 'no'));
ACP3\CMS::$injector['View']->assign('comments', ACP3\Core\Functions::selectGenerator('comments', array(1, 0), $lang_comments, $settings['comments'], 'checked'));
}
ACP3\CMS::$injector['View']->assign('dateformat', ACP3\CMS::$injector['Date']->dateformatDropdown($settings['dateformat']));
ACP3\CMS::$injector['View']->assign('sidebar_entries', ACP3\Core\Functions::recordsPerPage((int) $settings['sidebar'], 1, 10));
ACP3\CMS::$injector['Session']->generateFormToken();
}
\ No newline at end of file
<?php
/**
* Files
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ACP3') === false)
exit;
$period = ' AND (start = end AND start <= :time OR :time BETWEEN start AND end)';
if (ACP3\Core\Validate::isNumber(ACP3\CMS::$injector['URI']->id) === true &&
ACP3\CMS::$injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'files WHERE id = :id' . $period, array('id' => ACP3\CMS::$injector['URI']->id, 'time' => ACP3\CMS::$injector['Date']->getCurrentDateTime())) == 1) {
require_once MODULES_DIR . 'files/functions.php';
$file = getFilesCache(ACP3\CMS::$injector['URI']->id);
if (ACP3\CMS::$injector['URI']->action === 'download') {
$path = UPLOADS_DIR . 'files/';
if (is_file($path . $file['file'])) {
// Schönen Dateinamen generieren
$ext = strrchr($file['file'], '.');
$filename = makeStringUrlSafe($file['title']) . $ext;
header('Content-Type: application/force-download');
header('Content-Transfer-Encoding: binary');
header('Content-Length:' . filesize($path . $file['file']));
header('Content-Disposition: attachment; filename="' . $filename . '"');
readfile($path . $file['file']);
exit;
// Externe Datei
} elseif (preg_match('/^([a-z]+):\/\//', $file['file'])) {
ACP3\CMS::$injector['URI']->redirect(0, $file['file']);
} else {
ACP3\CMS::$injector['URI']->redirect('errors/404');
}
} else {
// Brotkrümelspur
ACP3\CMS::$injector['Breadcrumb']->append(ACP3\CMS::$injector['Lang']->t('files', 'files'), ACP3\CMS::$injector['URI']->route('files'))
->append($file['category_name'], ACP3\CMS::$injector['URI']->route('files/files/cat_' . $file['category_id']))
->append($file['title']);
$settings = ACP3\Core\Config::getSettings('files');
$file['size'] = !empty($file['size']) ? $file['size'] : ACP3\CMS::$injector['Lang']->t('files', 'unknown_filesize');
$file['date_formatted'] = ACP3\CMS::$injector['Date']->format($file['start'], $settings['dateformat']);
$file['date_iso'] = ACP3\CMS::$injector['Date']->format($file['start'], 'c');
ACP3\CMS::$injector['View']->assign('file', $file);
if ($settings['comments'] == 1 && $file['comments'] == 1 && ACP3\Core\Modules::check('comments', 'functions') === true) {
require_once MODULES_DIR . 'comments/functions.php';
ACP3\CMS::$injector['View']->assign('comments', commentsList('files', ACP3\CMS::$injector['URI']->id));
}
}
} else {
ACP3\CMS::$injector['URI']->redirect('errors/404');
}
\ No newline at end of file
<?php
/**
* Files
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/