Commit 6a78d0ea authored by fettesvieh's avatar fettesvieh

modules::check() is a bit more finer grained now with its return values

parent 5a58727d
......@@ -16,14 +16,15 @@
class modules
{
/**
* Überpüft, ob ein Modul überhaupt existiert, bzw. der Benutzer auf ein Modul Zugriff hat
* Überpüft, ob ein Modul überhaupt existiert,
* bzw. der Benutzer auf ein Modul Zugriff hat
*
* @param string $module
* Zu überprüfendes Modul
* @param string $page
* Zu überprüfende Moduldatei
*
* @return boolean
* @return integer
*/
public static function check($module = 0, $page = 0) {
global $auth, $db, $uri;
......@@ -36,7 +37,8 @@ class modules
$xml = simplexml_load_file(ACP3_ROOT . 'modules/' . $module . '/module.xml');
if ((string) $xml->info->active == '1') {
// Falls die einzelnen Zugriffslevel auf die Module noch nicht gesetzt sind, diese aus der Datenbank selektieren
// Falls die einzelnen Zugriffslevel auf die Module noch nicht
// gesetzt sind, diese aus der Datenbank selektieren
if (!isset($access_level[$module])) {
// Zugriffslevel für Gäste
$access_id = 2;
......@@ -69,15 +71,17 @@ class modules
}
}
// User hat Zugriff auf die aktuelle Seite
return true;
return 1;
}
}
}
return 0;
}
return false;
return -1;
}
/**
* Gibt ein alphabetisch sortiertes Array mit allen gefundenen Modulen des ACP3 mitsamt Modulinformationen aus
* Gibt ein alphabetisch sortiertes Array mit allen gefundenen
* Modulen des ACP3 mitsamt Modulinformationen aus
*
* @return array
*/
......
......@@ -9,21 +9,28 @@
define('ACP3_ROOT', './');
require ACP3_ROOT . 'includes/common.php';
if (modules::check()) {
include ACP3_ROOT . 'modules/' . $uri->mod . '/' . $uri->page . '.php';
if (!$auth->isUser() && defined('IN_ADM') && $uri->mod != 'users' && $uri->page != 'login') {
redirect('acp/users/login');
}
// Evtl. gesetzten Content-Type des Servers überschreiben
header('Content-Type: ' . (defined('CUSTOM_CONTENT_TYPE') ? CUSTOM_CONTENT_TYPE : 'text/html') . '; charset=UTF-8');
switch (modules::check()) {
case 1:
include ACP3_ROOT . 'modules/' . $uri->mod . '/' . $uri->page . '.php';
$tpl->assign('TITLE', breadcrumb::output(2));
$tpl->assign('BREADCRUMB', breadcrumb::output());
$tpl->assign('CONTENT', !empty($content) ? $content : '');
// Evtl. gesetzten Content-Type des Servers überschreiben
header('Content-Type: ' . (defined('CUSTOM_CONTENT_TYPE') ? CUSTOM_CONTENT_TYPE : 'text/html') . '; charset=UTF-8');
// Falls ein Modul ein eigenes Layout verwenden möchte, dieses auch verwenden
$tpl->display(defined('CUSTOM_LAYOUT') ? CUSTOM_LAYOUT : 'layout.html');
} elseif (!$auth->isUser() && defined('IN_ADM') && $uri->mod != 'users' && $uri->page != 'login') {
redirect('acp/users/login');
} else {
redirect('errors/404');
$tpl->assign('TITLE', breadcrumb::output(2));
$tpl->assign('BREADCRUMB', breadcrumb::output());
$tpl->assign('CONTENT', !empty($content) ? $content : '');
// Falls ein Modul ein eigenes Layout verwenden möchte, dieses auch verwenden
$tpl->display(defined('CUSTOM_LAYOUT') ? CUSTOM_LAYOUT : 'layout.html');
break;
case 0:
redirect('errors/403');
break;
default:
redirect('errors/404');
}
?>
\ No newline at end of file
......@@ -18,7 +18,7 @@ $mods = array();
foreach ($mod_list as $name => $info) {
$dir = $info['dir'];
if (modules::check($dir, 'adm_list') && $dir != 'acp' && $dir != 'system' && $dir != 'home') {
if (modules::check($dir, 'adm_list') == 1 && $dir != 'acp' && $dir != 'system' && $dir != 'home') {
$mods[$name]['name'] = $name;
$mods[$name]['dir'] = $dir;
}
......@@ -26,7 +26,7 @@ foreach ($mod_list as $name => $info) {
$tpl->assign('modules', $mods);
//Server Infos
if (modules::check('system', 'server_config')) {
if (modules::check('system', 'server_config') == 1) {
$server_info[0]['col_left'] = $lang->t('system', 'architecture');
$server_info[0]['col_right'] = @php_uname('m');
$server_info[1]['col_left'] = $lang->t('system', 'operating_system');
......
......@@ -36,7 +36,7 @@ if (empty($module) || !empty($module) && $db->countRows('*', 'comments', 'module
$emoticons = false;
// Emoticons einbinden
if (modules::check('emoticons', 'functions')) {
if (modules::check('emoticons', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/emoticons/functions.php';
$emoticons = true;
}
......
......@@ -42,7 +42,7 @@ if (validate::isNumber($uri->id) && $db->countRows('*', 'comments', 'id = \'' .
}
}
if (!isset($_POST['submit']) || isset($errors) && is_array($errors)) {
if (modules::check('emoticons', 'functions')) {
if (modules::check('emoticons', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/emoticons/functions.php';
// Emoticons im Formular anzeigen
......
......@@ -55,7 +55,7 @@ function comments($module, $entry_id)
$errors[] = $lang->t('common', 'name_to_short');
if (strlen($form['message']) < 3)
$errors[] = $lang->t('common', 'message_to_short');
if (!modules::check($db->escape($form['module'], 2), 'list') || !validate::isNumber($form['entry_id']))
if (!modules::check($db->escape($form['module'], 2), 'list') == 1 || !validate::isNumber($form['entry_id']))
$errors[] = $lang->t('comments', 'module_doesnt_exist');
if (!$auth->isUser() && !validate::captcha($form['captcha'], $form['hash']))
$errors[] = $lang->t('captcha', 'invalid_captcha_entered');
......@@ -86,7 +86,7 @@ function comments($module, $entry_id)
// Emoticons einbinden, falls diese aktiv sind
$emoticons = false;
if (modules::check('emoticons', 'functions')) {
if (modules::check('emoticons', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/emoticons/functions.php';
$emoticons = true;
......
......@@ -2,7 +2,7 @@
if (!defined('IN_ACP3'))
exit;
if (modules::check($uri->feed, 'extensions/feeds')) {
if (modules::check($uri->feed, 'extensions/feeds') == 1) {
$module = $uri->feed;
$link = 'http://' . htmlentities($_SERVER['HTTP_HOST'], ENT_QUOTES);
......
......@@ -83,7 +83,7 @@ if (!isset($_POST['submit']) || isset($errors) && is_array($errors)) {
$tpl->assign('units', $units);
// Formularelemente
if (modules::check('categories', 'functions')) {
if (modules::check('categories', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/categories/functions.php';
$tpl->assign('categories', categoriesList('files', '', true));
}
......
......@@ -37,7 +37,7 @@ if (validate::isNumber($uri->id) && $db->countRows('*', 'files', 'id = \'' . $ur
$file[0]['date'] = $date->format($file[0]['start']);
$tpl->assign('file', $file[0]);
if (modules::check('comments', 'functions')) {
if (modules::check('comments', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/comments/functions.php';
$tpl->assign('comments', comments('files', $uri->id));
......
......@@ -102,7 +102,7 @@ if (validate::isNumber($uri->id) && $db->countRows('*', 'files', 'id = \'' . $ur
$dl[0]['filesize'] = substr($dl[0]['size'], 0, strpos($dl[0]['size'], ' '));
// Formularelemente
if (modules::check('categories', 'functions')) {
if (modules::check('categories', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/categories/functions.php';
$tpl->assign('categories', categoriesList('files', $dl[0]['category_id'], true));
}
......
......@@ -10,7 +10,7 @@
if (!defined('IN_ACP3'))
exit;
if (modules::check('categories', 'functions')) {
if (modules::check('categories', 'functions') == 1) {
$tpl->assign('categories', getCategoriesCache('files'));
}
......
......@@ -34,7 +34,7 @@ if (validate::isNumber($uri->id) && $db->select('COUNT(g.id)', 'gallery AS g, '
if (count($picture_next) > 0)
$tpl->assign('picture_next', $picture_next[0]);
if (modules::check('comments', 'functions')) {
if (modules::check('comments', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/comments/functions.php';
$tpl->assign('comments', comments('gallery', $uri->id));
......
......@@ -18,7 +18,7 @@ if ($c_guestbook > 0) {
$emoticons = false;
// Emoticons einbinden
if (modules::check('emoticons', 'functions')) {
if (modules::check('emoticons', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/emoticons/functions.php';
$emoticons = true;
}
......
......@@ -56,7 +56,7 @@ if (isset($_POST['submit'])) {
}
if (!isset($_POST['submit']) || isset($errors) && is_array($errors)) {
// Emoticons einbinden
if (modules::check('emoticons', 'functions')) {
if (modules::check('emoticons', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/emoticons/functions.php';
$tpl->assign('emoticons', emoticonsList());
}
......
......@@ -35,7 +35,7 @@ if (validate::isNumber($uri->id) && $db->countRows('*', 'guestbook', 'id = \'' .
if (!isset($_POST['submit']) || isset($errors) && is_array($errors)) {
$guestbook = $db->select('name, message', 'guestbook', 'id = \'' . $uri->id . '\'');
if (modules::check('emoticons', 'functions')) {
if (modules::check('emoticons', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/emoticons/functions.php';
//Emoticons im Formular anzeigen
......
......@@ -18,7 +18,7 @@ if ($c_guestbook > 0) {
$emoticons = false;
// Emoticons einbinden
if (modules::check('emoticons', 'functions')) {
if (modules::check('emoticons', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/emoticons/functions.php';
$emoticons = true;
}
......
......@@ -56,7 +56,7 @@ if (!isset($_POST['submit']) || isset($errors) && is_array($errors)) {
$tpl->assign('end_date', datepicker('end'));
// Kategorien
if (modules::check('categories', 'functions')) {
if (modules::check('categories', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/categories/functions.php';
$tpl->assign('categories', categoriesList('news', '', true));
}
......
......@@ -33,7 +33,7 @@ if (validate::isNumber($uri->id) && $db->countRows('*', 'news', 'id = \'' . $uri
$settings = config::output('news');
if ($settings['comments'] == 1 && $news[0]['comments'] == 1 && modules::check('comments', 'functions')) {
if ($settings['comments'] == 1 && $news[0]['comments'] == 1 && modules::check('comments', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/comments/functions.php';
$tpl->assign('comments', comments('news', $uri->id));
......
......@@ -60,7 +60,7 @@ if (validate::isNumber($uri->id) && $db->countRows('*', 'news', 'id = \'' . $uri
$tpl->assign('end_date', datepicker('end', $news[0]['end']));
// Kategorien
if (modules::check('categories', 'functions')) {
if (modules::check('categories', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/categories/functions.php';
$tpl->assign('categories', categoriesList('news', $news[0]['category_id'], true));
}
......
......@@ -19,7 +19,7 @@ if (isset($_POST['form']['cat']) && validate::isNumber($_POST['form']['cat'])) {
}
// Kategorien auflisten
if (modules::check('categories', 'functions')) {
if (modules::check('categories', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/categories/functions.php';
$tpl->assign('categories', categoriesList('news', $cat));
}
......@@ -34,7 +34,7 @@ $c_news = count($news);
if ($c_news > 0) {
// Überprüfen, ob das Kommentare Modul aktiv ist
if (modules::check('comments', 'functions')) {
if (modules::check('comments', 'functions') == 1) {
include_once ACP3_ROOT . 'modules/comments/functions.php';
$comment_check = true;
}
......
......@@ -31,7 +31,7 @@ if (isset($_POST['submit'])) {
$form['sort'] = strtoupper($form['sort']);
$results_mods = array();
foreach ($form['mods'] as $module) {
if (modules::check($module, 'extensions/search')) {
if (modules::check($module, 'extensions/search') == 1) {
include ACP3_ROOT . 'modules/' . $module . '/extensions/search.php';
}
}
......@@ -51,7 +51,7 @@ if (!isset($_POST['submit']) || isset($errors) && is_array($errors)) {
$search_mods = array();
for ($i = 0; $i < $c_mods; ++$i) {
if (modules::check($mods[$i], 'extensions/search')) {
if (modules::check($mods[$i], 'extensions/search') == 1) {
$info = modules::parseInfo($mods[$i]);
$name = $info['name'];
$search_mods[$name]['dir'] = $mods[$i];
......
......@@ -19,7 +19,7 @@ if (isset($_POST['submit'])) {
$errors[] = $lang->t('static_pages', 'title_to_short');
if (strlen($form['text']) < 3)
$errors[] = $lang->t('static_pages', 'text_to_short');
if (modules::check('menu_items', 'create')) {
if (modules::check('menu_items', 'create') == 1) {
if ($form['create'] != 1 && $form['create'] != '0')
$errors[] = $lang->t('static_page', 'select_create_menu_item');
if ($form['create'] == 1) {
......@@ -57,7 +57,7 @@ if (isset($_POST['submit'])) {
$last_id = $db->link->lastInsertId();
$db->link->commit();
if ($form['create'] == '1' && modules::check('menu_items', 'create')) {
if ($form['create'] == '1' && modules::check('menu_items', 'create') == 1) {
$insert_values = array(
'id' => '',
'start' => $time_start,
......@@ -78,7 +78,7 @@ if (isset($_POST['submit'])) {
}
}
if (!isset($_POST['submit']) || isset($errors) && is_array($errors)) {
if (modules::check('menu_items', 'create')) {
if (modules::check('menu_items', 'create') == 1) {
$create[0]['value'] = 1;
$create[0]['selected'] = selectEntry('create', '1', '0', 'checked');
$create[0]['lang'] = $lang->t('common', 'yes');
......
......@@ -18,7 +18,7 @@ if ($auth->isUser()) {
foreach ($mod_list as $name => $info) {
$dir = $info['dir'];
if (modules::check($dir, 'adm_list') && $dir != 'acp') {
if (modules::check($dir, 'adm_list') == 1 && $dir != 'acp') {
if ($dir == 'system') {
$access_system = true;
} elseif ($dir == 'home') {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment