converted some more modules to use the new ModuleController

parent 3f5d565a
......@@ -11,12 +11,12 @@ function smarty_function_include_js($params)
(bool) preg_match('=/=', $params['module']) === false &&
(bool) preg_match('=/=', $params['file']) === false) {
$script = '<script type="text/javascript" src="%s"></script>';
$module = $params['module'];
$module = ucfirst($params['module']);
$file = $params['file'];
if (is_file(DESIGN_PATH_INTERNAL . $module . '/' . $file . '.js') === true) {
return sprintf($script, DESIGN_PATH . $module . '/' . $file . '.js');
} elseif (is_file(MODULES_DIR . $module . '/templates/' . $file . '.js') === true) {
return sprintf($script, ROOT_DIR . 'modules/' . $module . '/templates/' . $file . '.js');
return sprintf($script, ROOT_DIR . 'ACP3/Modules/' . $module . '/templates/' . $file . '.js');
}
} else {
return 'Not all necessary arguments for the function ' . __FUNCTION__ . ' were passed!';
......
This diff is collapsed.
<?php
namespace ACP3\Modules\Articles;
use ACP3\Core;
/**
* Description of ArticlesFrontend
*
* @author Tino
*/
class ArticlesFrontend extends Core\ModuleController {
public function __construct($injector)
{
parent::__construct($injector);
}
public function actionList()
{
$period = 'start = end AND start <= :time OR start != end AND :time BETWEEN start AND end';
$time = $this->injector['Date']->getCurrentDateTime();
$articles = $this->injector['Db']->fetchAll('SELECT id, start, end, title FROM ' . DB_PRE . 'articles WHERE ' . $period . ' ORDER BY title ASC LIMIT ' . POS . ',' . $this->injector['Auth']->entries, array('time' => $time));
$c_articles = count($articles);
if ($c_articles > 0) {
$this->injector['View']->assign('pagination', Core\Functions::pagination($this->injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'articles WHERE ' . $period, array('time' => $time))));
for ($i = 0; $i < $c_articles; ++$i) {
$articles[$i]['date_formatted'] = $this->injector['Date']->format($articles[$i]['start']);
$articles[$i]['date_iso'] = $this->injector['Date']->format($articles[$i]['start'], 'c');
}
$this->injector['View']->assign('articles', $articles);
}
}
public function actionDetails()
{
$period = ' AND (start = end AND start <= :time OR start != end AND :time BETWEEN start AND end)';
if (Core\Validate::isNumber($this->injector['URI']->id) === true &&
$this->injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'articles WHERE id = :id' . $period, array('id' => $this->injector['URI']->id, 'time' => $this->injector['Date']->getCurrentDateTime())) == 1) {
$page = ArticlesFunctions::getArticlesCache($this->injector['URI']->id);
$this->injector['Breadcrumb']->replaceAnchestor($page['title'], 0, true);
$this->injector['View']->assign('page', splitTextIntoPages(Core\Functions::rewriteInternalUri($page['text']), $this->injector['URI']->getCleanQuery()));
} else {
$this->injector['URI']->redirect('errors/404');
}
}
}
\ No newline at end of file
<?php
/**
* Articles
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
namespace ACP3\Modules\Articles;
use ACP3\Core;
class ArticlesFunctions {
/**
* Erstellt den Cache eines Artikels anhand der angegebenen ID
*
* @param integer $id
* Die ID der statischen Seite
* @return boolean
*/
public static function setArticlesCache($id)
{
$data = ACP3\CMS::$injector['Db']->fetchAssoc('SELECT start, end, title, text FROM ' . DB_PRE . 'articles WHERE id = ?', array($id));
return Core\Cache::create('list_id_' . $id, $data, 'articles');
}
/**
* Bindet den gecacheten Artikel ein
*
* @param integer $id
* Die ID der statischen Seite
* @return array
*/
public static function getArticlesCache($id)
{
if (Core\Cache::check('list_id_' . $id, 'articles') === false)
self::setArticlesCache($id);
return Core\Cache::output('list_id_' . $id, 'articles');
}
/**
* Gibt alle angelegten Artikel zurück
*
* @param integer $id
* @return array
*/
public static function articlesList($id = '')
{
$articles = ACP3\CMS::$injector['Db']->fetchAll('SELECT id, start, end, title, text FROM ' . DB_PRE . 'articles ORDER BY title ASC');
$c_articles = count($articles);
if ($c_articles > 0) {
for ($i = 0; $i < $c_articles; ++$i) {
$articles[$i]['selected'] = Core\Functions::selectEntry('articles', $articles[$i]['id'], $id);
}
}
return $articles;
}
}
<?php
/**
* Articles
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ADM') === false)
exit;
$access_to_menus = ACP3\Core\Modules::check('menus', 'acp_create_item');
if ($access_to_menus === true)
require_once MODULES_DIR . 'menus/functions.php';
if (isset($_POST['submit']) === true) {
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['title'] = ACP3\CMS::$injector['Lang']->t('articles', 'title_to_short');
if (strlen($_POST['text']) < 3)
$errors['text'] = ACP3\CMS::$injector['Lang']->t('articles', 'text_to_short');
if ($access_to_menus === true && isset($_POST['create']) === true) {
if ($_POST['create'] == 1) {
if (ACP3\Core\Validate::isNumber($_POST['block_id']) === false)
$errors['block-id'] = ACP3\CMS::$injector['Lang']->t('menus', 'select_menu_bar');
if (!empty($_POST['parent']) && ACP3\Core\Validate::isNumber($_POST['parent']) === false)
$errors['parent'] = ACP3\CMS::$injector['Lang']->t('menus', 'select_superior_page');
if (!empty($_POST['parent']) && ACP3\Core\Validate::isNumber($_POST['parent']) === true) {
// Überprüfen, ob sich die ausgewählte übergeordnete Seite im selben Block befindet
$parent_block = ACP3\CMS::$injector['Db']->fetchColumn('SELECT block_id FROM ' . DB_PRE . 'menu_items WHERE id = ?', array($_POST['parent']));
if (!empty($parent_block) && $parent_block != $_POST['block_id'])
$errors['parent'] = ACP3\CMS::$injector['Lang']->t('menus', 'superior_page_not_allowed');
}
if ($_POST['display'] != 0 && $_POST['display'] != 1)
$errors[] = ACP3\CMS::$injector['Lang']->t('menus', 'select_item_visibility');
}
}
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 {
$insert_values = array(
'id' => '',
'start' => ACP3\CMS::$injector['Date']->toSQL($_POST['start']),
'end' => ACP3\CMS::$injector['Date']->toSQL($_POST['end']),
'title' => ACP3\Core\Functions::str_encode($_POST['title']),
'text' => ACP3\Core\Functions::str_encode($_POST['text'], true),
'user_id' => ACP3\CMS::$injector['Auth']->getUserId(),
);
ACP3\CMS::$injector['Db']->beginTransaction();
$bool = ACP3\CMS::$injector['Db']->insert(DB_PRE . 'articles', $insert_values);
$last_id = ACP3\CMS::$injector['Db']->lastInsertId();
if ((bool) CONFIG_SEO_ALIASES === true && !empty($_POST['alias']))
ACP3\Core\SEO::insertUriAlias('articles/details/id_' . $last_id, $_POST['alias'], $_POST['seo_keywords'], $_POST['seo_description'], (int) $_POST['seo_robots']);
ACP3\CMS::$injector['Db']->commit();
if (isset($_POST['create']) === true && $access_to_menus === true) {
$insert_values = array(
'id' => '',
'mode' => 4,
'block_id' => $_POST['block_id'],
'parent_id' => (int) $_POST['parent'],
'display' => $_POST['display'],
'title' => ACP3\Core\Functions::str_encode($_POST['title']),
'uri' => 'articles/details/id_' . $last_id . '/',
'target' => 1,
);
$nestedSet = new ACP3\Core\NestedSet('menu_items', true);
$bool = $nestedSet->insertNode((int) $_POST['parent'], $insert_values);
setMenuItemsCache();
}
ACP3\CMS::$injector['Session']->unsetFormToken();
ACP3\Core\Functions::setRedirectMessage($bool, ACP3\CMS::$injector['Lang']->t('system', $bool !== false ? 'create_success' : 'create_error'), 'acp/articles');
}
}
if (isset($_POST['submit']) === false || isset($errors) === true && is_array($errors) === true) {
if ($access_to_menus === true) {
$lang_options = array(ACP3\CMS::$injector['Lang']->t('articles', 'create_menu_item'));
ACP3\CMS::$injector['View']->assign('options', ACP3\Core\Functions::selectGenerator('create', array(1), $lang_options, 0, 'checked'));
// Block
ACP3\CMS::$injector['View']->assign('blocks', menusDropdown());
$lang_display = array(ACP3\CMS::$injector['Lang']->t('system', 'yes'), ACP3\CMS::$injector['Lang']->t('system', 'no'));
ACP3\CMS::$injector['View']->assign('display', ACP3\Core\Functions::selectGenerator('display', array(1, 0), $lang_display, 1, 'checked'));
ACP3\CMS::$injector['View']->assign('pages_list', menuItemsList());
}
ACP3\CMS::$injector['View']->assign('publication_period', ACP3\CMS::$injector['Date']->datepicker(array('start', 'end')));
$defaults = array(
'title' => '',
'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();
}
<?php
/**
* Articles
*
* @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/articles/delete/entries_' . $marked_entries . '/action_confirmed/'), ACP3\CMS::$injector['URI']->route('acp/articles')));
} elseif (ACP3\CMS::$injector['URI']->action === 'confirmed') {
$marked_entries = explode('|', $entries);
$bool = false;
$nestedSet = new ACP3\Core\NestedSet('menu_items', true);
foreach ($marked_entries as $entry) {
$bool = ACP3\CMS::$injector['Db']->delete(DB_PRE . 'articles', array('id' => $entry));
$nestedSet->deleteNode(ACP3\CMS::$injector['Db']->fetchColumn('SELECT id FROM ' . DB_PRE . 'menu_items WHERE uri = ?', array('articles/details/id_' . $entry . '/')));
ACP3\Core\Cache::delete('list_id_' . $entry, 'articles');
ACP3\Core\SEO::deleteUriAlias('articles/details/id_' . $entry);
}
if (ACP3\Core\Modules::isInstalled('menus') === true) {
require_once MODULES_DIR . 'menus/functions.php';
setMenuItemsCache();
}
ACP3\Core\Functions::setRedirectMessage($bool, ACP3\CMS::$injector['Lang']->t('system', $bool !== false ? 'delete_success' : 'delete_error'), 'acp/articles');
} else {
ACP3\CMS::$injector['URI']->redirect('errors/404');
}
<?php
/**
* Articles
*
* @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 . 'articles WHERE id = ?', array(ACP3\CMS::$injector['URI']->id)) == 1) {
require_once MODULES_DIR . 'articles/functions.php';
if (isset($_POST['submit']) === true) {
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['title'] = ACP3\CMS::$injector['Lang']->t('articles', 'title_to_short');
if (strlen($_POST['text']) < 3)
$errors['text'] = ACP3\CMS::$injector['Lang']->t('articles', 'text_to_short');
if ((bool) CONFIG_SEO_ALIASES === true && !empty($_POST['alias']) &&
(ACP3\Core\Validate::isUriSafe($_POST['alias']) === false || ACP3\Core\Validate::uriAliasExists($_POST['alias'], 'articles/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 {
$update_values = array(
'start' => ACP3\CMS::$injector['Date']->toSQL($_POST['start']),
'end' => ACP3\CMS::$injector['Date']->toSQL($_POST['end']),
'title' => ACP3\Core\Functions::str_encode($_POST['title']),
'text' => ACP3\Core\Functions::str_encode($_POST['text'], true),
'user_id' => ACP3\CMS::$injector['Auth']->getUserId(),
);
$bool = ACP3\CMS::$injector['Db']->update(DB_PRE . 'articles', $update_values, array('id' => ACP3\CMS::$injector['URI']->id));
if ((bool) CONFIG_SEO_ALIASES === true && !empty($_POST['alias']))
ACP3\Core\SEO::insertUriAlias('articles/details/id_' . ACP3\CMS::$injector['URI']->id, $_POST['alias'], $_POST['seo_keywords'], $_POST['seo_description'], (int) $_POST['seo_robots']);
setArticlesCache(ACP3\CMS::$injector['URI']->id);
// Aliase in der Navigation aktualisieren
require_once MODULES_DIR . 'menus/functions.php';
setMenuItemsCache();
ACP3\CMS::$injector['Session']->unsetFormToken();
ACP3\Core\Functions::setRedirectMessage($bool, ACP3\CMS::$injector['Lang']->t('system', $bool !== false ? 'edit_success' : 'edit_error'), 'acp/articles');
}
}
if (isset($_POST['submit']) === false || isset($errors) === true && is_array($errors) === true) {
$page = getArticlesCache(ACP3\CMS::$injector['URI']->id);
// Datumsauswahl
ACP3\CMS::$injector['View']->assign('publication_period', ACP3\CMS::$injector['Date']->datepicker(array('start', 'end'), array($page['start'], $page['end'])));
ACP3\CMS::$injector['View']->assign('SEO_FORM_FIELDS', ACP3\Core\SEO::formFields('articles/details/id_' . ACP3\CMS::$injector['URI']->id));
ACP3\CMS::$injector['View']->assign('form', isset($_POST['submit']) ? $_POST : $page);
ACP3\CMS::$injector['Session']->generateFormToken();
}
} else {
ACP3\CMS::$injector['URI']->redirect('errors/404');
}
<?php
/**
* Articles
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ADM') === false)
exit;
ACP3\Core\Functions::getRedirectMessage();
$articles = ACP3\CMS::$injector['Db']->fetchAll('SELECT id, start, end, title FROM ' . DB_PRE . 'articles ORDER BY title ASC');
$c_articles = count($articles);
if ($c_articles > 0) {
$can_delete = ACP3\Core\Modules::check('articles', 'acp_delete');
$config = array(
'element' => '#acp-table',
'sort_col' => $can_delete === true ? 2 : 1,
'sort_dir' => 'asc',
'hide_col_sort' => $can_delete === true ? 0 : ''
);
ACP3\CMS::$injector['View']->appendContent(ACP3\Core\Functions::datatable($config));
for ($i = 0; $i < $c_articles; ++$i) {
$articles[$i]['period'] = ACP3\CMS::$injector['Date']->formatTimeRange($articles[$i]['start'], $articles[$i]['end']);
}
ACP3\CMS::$injector['View']->assign('articles', $articles);
ACP3\CMS::$injector['View']->assign('can_delete', $can_delete);
}
\ No newline at end of file
<?php
/**
* Articles
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ACP3') === false)
exit;
$period = ' AND (start = end AND start <= :time OR start != end AND :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 . 'articles WHERE id = :id' . $period, array('id' => ACP3\CMS::$injector['URI']->id, 'time' => ACP3\CMS::$injector['Date']->getCurrentDateTime())) == 1) {
require_once MODULES_DIR . 'articles/functions.php';
$page = getArticlesCache(ACP3\CMS::$injector['URI']->id);
ACP3\CMS::$injector['Breadcrumb']->replaceAnchestor($page['title'], 0, true);
ACP3\CMS::$injector['View']->assign('page', splitTextIntoPages(ACP3\Core\Functions::rewriteInternalUri($page['text']), ACP3\CMS::$injector['URI']->getCleanQuery()));
} else {
ACP3\CMS::$injector['URI']->redirect('errors/404');
}
\ No newline at end of file
<?php
/**
* Articles
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
/**
* Erstellt den Cache einer statischen Seite anhand der angegebenen ID
*
* @param integer $id
* Die ID der statischen Seite
* @return boolean
*/
function setArticlesCache($id)
{
$data = ACP3\CMS::$injector['Db']->fetchAssoc('SELECT start, end, title, text FROM ' . DB_PRE . 'articles WHERE id = ?', array($id));
return ACP3\Core\Cache::create('list_id_' . $id, $data, 'articles');
}
/**
* Bindet die gecachete statische Seite ein
*
* @param integer $id
* Die ID der statischen Seite
* @return array
*/
function getArticlesCache($id)
{
if (ACP3\Core\Cache::check('list_id_' . $id, 'articles') === false)
setArticlesCache($id);
return ACP3\Core\Cache::output('list_id_' . $id, 'articles');
}
/**
* Liest alle statischen Seiten ein
*
* @param integer $id
* @return array
*/
function articlesList($id = '')
{
$articles = ACP3\CMS::$injector['Db']->fetchAll('SELECT id, start, end, title, text FROM ' . DB_PRE . 'articles ORDER BY title ASC');
$c_articles = count($articles);
if ($c_articles > 0) {
for ($i = 0; $i < $c_articles; ++$i) {
$articles[$i]['selected'] = ACP3\Core\Functions::selectEntry('articles', $articles[$i]['id'], $id);
}
}
return $articles;
}
\ No newline at end of file
<?php
/**
* Articles
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ACP3') === false)
exit;
$period = 'start = end AND start <= :time OR start != end AND :time BETWEEN start AND end';
$time = ACP3\CMS::$injector['Date']->getCurrentDateTime();
$articles = ACP3\CMS::$injector['Db']->fetchAll('SELECT id, start, end, title FROM ' . DB_PRE . 'articles WHERE ' . $period . ' ORDER BY title ASC LIMIT ' . POS . ',' . ACP3\CMS::$injector['Auth']->entries, array('time' => $time));
$c_articles = count($articles);
if ($c_articles > 0) {
ACP3\CMS::$injector['View']->assign('pagination', ACP3\Core\Functions::pagination(ACP3\CMS::$injector['Db']->fetchColumn('SELECT COUNT(*) FROM ' . DB_PRE . 'articles WHERE ' . $period, array('time' => $time))));
for ($i = 0; $i < $c_articles; ++$i) {
$articles[$i]['date_formatted'] = ACP3\CMS::$injector['Date']->format($articles[$i]['start']);
$articles[$i]['date_iso'] = ACP3\CMS::$injector['Date']->format($articles[$i]['start'], 'c');
}
ACP3\CMS::$injector['View']->assign('articles', $articles);
}
\ No newline at end of file
<?php
/**
* Captcha
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
namespace ACP3\Modules\Captcha;
use ACP3\Core;
/**
* Description of CaptchaAdmin
*
* @author Tino
*/
class CaptchaFrontend extends Core\ModuleController {
public function __construct($injector)
{
parent::__construct($injector);
}
public function actionImage()
{
if (!empty($_SESSION['captcha'])) {
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-Type: image/gif');
$captcha = $_SESSION['captcha'];
$captchaLength = strlen($captcha);
$width = $captchaLength * 25;
$height = 30;
$im = imagecreate($width, $height);
// Hintergrundfarbe
imagecolorallocate($im, 255, 255, 255);
$textColor = imagecolorallocate($im, 0, 0, 0);
for ($i = 0; $i < $captchaLength; ++$i) {
$font = mt_rand(2, 5);
$posLeft = 22 * $i + 10;
$posTop = mt_rand(1, $height - imagefontheight($font) - 3);
imagestring($im, $font, $posLeft, $posTop, $captcha[$i], $textColor);
}
imagegif($im);
imagedestroy($im);
exit;
}
}
}
\ No newline at end of file
<?php
/**
* Captcha
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
namespace ACP3\Modules\Captcha;
use ACP3\Core;
class CaptchaFunctions {
/**
* Erzeugt das Captchafeld für das Template
*
* @param integer $captcha_length
* Anzahl der Zeichen, welche das Captcha haben soll
* @return string
*/
public static function captcha($captcha_length = 5)
{
// Wenn man als User angemeldet ist, Captcha nicht anzeigen
if (\ACP3\CMS::$injector['Auth']->isUser() === false) {
$_SESSION['captcha'] = Core\Functions::salt($captcha_length);
$captcha = array();
$captcha['width'] = $captcha_length * 25;
$captcha['height'] = 30;
\ACP3\CMS::$injector['View']->assign('captcha', $captcha);
return \ACP3\CMS::$injector['View']->fetchTemplate('captcha/captcha.tpl');
}
return '';
}
}
<?php
/**
* Captcha
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
/**
* Erzeugt das Captchafeld für das Template
*
* @param integer $captcha_length
* Anzahl der Zeichen, welche das Captcha haben soll
* @return string
*/
function captcha($captcha_length = 5)
{
// Wenn man als User angemeldet ist, Captcha nicht anzeigen
if (ACP3\CMS::$injector['Auth']->isUser() === false) {
$_SESSION['captcha'] = ACP3\Core\Functions::salt($captcha_length);
$captcha = array();
$captcha['width'] = $captcha_length * 25;
$captcha['height'] = 30;
ACP3\CMS::$injector['View']->assign('captcha', $captcha);
return ACP3\CMS::$injector['View']->fetchTemplate('captcha/captcha.tpl');
}
return '';
}
\ No newline at end of file
<?php
/**
* Captcha
*
* @author Tino Goratsch
* @package ACP3
* @subpackage Modules
*/
if (defined('IN_ACP3') === false)
exit();
if (!empty($_SESSION['captcha'])) {
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-Type: image/gif');
$captcha = $_SESSION['captcha'];
$captchaLength = strlen($captcha);
$width = $captchaLength * 25;
$height = 30;
$im = imagecreate($width, $height);
// Hintergrundfarbe
imagecolorallocate($im, 255, 255, 255);
$textColor = imagecolorallocate($im, 0, 0, 0);
for ($i = 0; $i < $captchaLength; ++$i) {
$font = mt_rand(2, 5);
$posLeft = 22 * $i + 10;
$posTop = mt_rand(1, $height - imagefontheight($font) - 3);
imagestring($im, $font, $posLeft, $posTop, $captcha[$i], $textColor);
}
imagegif($im);
imagedestroy($im);
exit;
}
\ No newline at end of file