Commit cd888717 authored by fettesvieh's avatar fettesvieh

- separated the uri processing from the modules class

- fixed some bugs
parent 5a3a4c82
......@@ -63,22 +63,22 @@ class breadcrumb
*/
public static function output($mode = 1, $id = '')
{
global $modules, $tpl;
global $uri, $tpl;
$module = $modules->mod;
$page = $modules->page;
$module = $uri->mod;
$page = $uri->page;
// Brotkrümelspur für die Menüpunkte
if ($module == 'pages' && $page == 'list') {
global $db;
if (!validate::isNumber($id))
$id = $modules->item;
$id = $uri->item;
$page = $db->select('mode, parent, title', 'pages', 'id = \'' . $id . '\' AND (mode = \'1\' OR mode = \'2\')');
// Dynamische Seiten (ACP3 intern)
if ($id == $modules->item && $page[0]['mode'] == 2 && empty($page[0]['parent']) && !empty(self::$steps) && self::$end != '') {
if ($id == $uri->item && $page[0]['mode'] == 2 && empty($page[0]['parent']) && !empty(self::$steps) && self::$end != '') {
if ($mode == 1) {
$tpl->assign('breadcrumb', self::$steps);
$tpl->assign('end', self::$end);
......@@ -90,7 +90,7 @@ class breadcrumb
} else {
// Brotkrümelspur ausgeben
if ($mode == 1) {
if ($id == $modules->item) {
if ($id == $uri->item) {
self::$steps = array();
self::$end = '';
}
......
......@@ -15,94 +15,6 @@
*/
class modules
{
/**
* Array, welches die URI Parameter enthält
*
* @var array
* @access protected
*/
protected $params = array();
/**
* Die komplette übergebene URL
*
* @var string
*/
public $query = '';
/**
* Zerlegt u.a. die übergebenen Parameter in der URI in ihre Bestandteile
*
* @return modules
*/
function __construct()
{
$this->query = substr(str_replace(PHP_SELF, '', htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES)), 1);
if (!empty($this->query) && preg_match('/^(acp\/)/', $this->query)) {
// Definieren, dass man sich im Administrationsbereich befindet
define('IN_ADM', true);
// "acp/" entfernen
$this->query = substr($this->query, 4);
} else {
// Definieren, dass man sich im Frontend befindet
define('IN_ACP3', true);
// Query auf eine beutzerdefinierte Startseite setzen
if (!defined('IN_INSTALL') && empty($this->query) && CONFIG_HOMEPAGE != '') {
$this->query = CONFIG_HOMEPAGE;
}
}
$query = !empty($this->query) ? explode('/', $this->query) : 0;
$defaultModule = defined('IN_ADM') ? 'acp' : 'news';
$defaultPage = defined('IN_ADM') ? 'adm_list' : 'list';
$this->mod = !empty($query[0]) ? $query[0] : $defaultModule;
$this->page = !empty($query[1]) ? $query[1] : $defaultPage;
if (!empty($_POST['cat']))
$this->cat = $_POST['cat'];
if (!empty($_POST['action']))
$this->action = $_POST['action'];
if (!empty($query[2])) {
$c_query = count($query);
for ($i = 2; $i < $c_query; ++$i) {
if (!empty($query[$i])) {
if (!defined('POS') && preg_match('/^(pos_(\d+))$/', $query[$i])) {
define('POS', substr($query[$i], 4));
} elseif (preg_match('/^(([a-z0-9-]+)_(.+))$/', $query[$i])) {
$param = explode('_', $query[$i], 2);
$this->$param[0] = $param[1];
}
}
}
}
if (!defined('POS')) {
define('POS', '0');
}
}
/**
* Gibt alle URI Parameter aus
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
if (!empty($key) && array_key_exists($key, $this->params))
return $this->params[$key];
return null;
}
/**
* Setzt neue URI Parameter
*
* @param string $name
* @param mixed $value
*/
public function __set($name, $value)
{
$this->params[$name] = $value;
}
/**
* Überpüft, ob ein Modul überhaupt existiert, bzw. der Benutzer auf ein Modul Zugriff hat
*
......@@ -112,12 +24,12 @@ class modules
* Zu überprüfende Moduldatei
* @return boolean
*/
public function check($module = 0, $page = 0) {
global $auth, $db;
public static function check($module = 0, $page = 0) {
global $auth, $db, $uri;
static $access_level = array();
$module = !empty($module) ? $module : $this->mod;
$page = !empty($page) ? $page : $this->page;
$module = !empty($module) ? $module : $uri->mod;
$page = !empty($page) ? $page : $uri->page;
if (is_file(ACP3_ROOT . 'modules/' . $module . '/' . $page . '.php')) {
$xml = simplexml_load_file(ACP3_ROOT . 'modules/' . $module . '/module.xml');
......@@ -157,13 +69,13 @@ class modules
*
* @return array
*/
public function modulesList()
public static function modulesList()
{
$modules_dir = scandir(ACP3_ROOT . 'modules/');
$uri_dir = scandir(ACP3_ROOT . 'modules/');
$mod_list = array();
foreach ($modules_dir as $module) {
$info = $this->parseInfo($module);
foreach ($uri_dir as $module) {
$info = self::parseInfo($module);
if (is_array($info)) {
$mod_list[$info['name']] = $info;
}
......@@ -171,58 +83,6 @@ class modules
ksort($mod_list);
return $mod_list;
}
/**
* Gibt eine Seitenauswahl aus
*
* @param integer $rows
* Anzahl der Datensätze
* @return string
* Gibt die Seitenauswahl aus
*/
public function pagination($rows)
{
global $tpl;
if ($rows > CONFIG_ENTRIES) {
// Alle angegeben URL Parameter mit in die URL einbeziehen
$acp = defined('IN_ADM') ? 'acp/' : '';
$id = !empty($this->id) ? '/id_' . $this->id : '';
$cat = !empty($this->cat) ? '/cat_' . $this->cat : '';
$gen = '';
if (!empty($this->params)) {
foreach ($this->params as $key => $value) {
if ($key != 'mod' && $key != 'page' && $key != 'pos') {
$gen .= '/' . $key . '_' . $value;
}
}
}
$tpl->assign('uri', uri($acp . $this->mod . '/' . $this->page . $id . $cat . $gen));
// Seitenauswahl
$c_pages = ceil($rows / CONFIG_ENTRIES);
$recent = 0;
for ($i = 1; $i <= $c_pages; ++$i) {
$pages[$i]['selected'] = POS == $recent ? true : false;
$pages[$i]['page'] = $i;
$pages[$i]['pos'] = 'pos_' . $recent . '/';
$recent = $recent + CONFIG_ENTRIES;
}
$tpl->assign('pages', $pages);
// Vorherige Seite
$pos_prev = array('pos' => POS - CONFIG_ENTRIES >= 0 ? 'pos_' . (POS - CONFIG_ENTRIES) . '/' : '', 'selected' => POS == 0 ? true : false);
$tpl->assign('pos_prev', $pos_prev);
// Nächste Seite
$pos_next = array('pos' => 'pos_' . (POS + CONFIG_ENTRIES) . '/', 'selected' => POS + CONFIG_ENTRIES >= $rows ? true : false);
$tpl->assign('pos_next', $pos_next);
return $tpl->fetch('common/pagination.html');
}
}
/**
* Durchläuft für das angeforderte Modul den <info> Abschnitt in der
* module.xml und gibt die gefunden Informationen als Array zurück
......@@ -230,7 +90,7 @@ class modules
* @param string $module
* @return mixed
*/
public function parseInfo($module)
public static function parseInfo($module)
{
$mod_info = xml::parseXmlFile(ACP3_ROOT . 'modules/' . $module . '/module.xml', 'info');
......
<?php
/**
* URI
*
* @author Goratsch Webdesign
* @package ACP3
* @subpackage Core
*/
/**
* Verarbeitet die URI Query
*
* @author Goratsch Webdesign
* @package ACP3
* @subpackage Core
*/
class uri
{
/**
* Array, welches die URI Parameter enthält
*
* @var array
* @access protected
*/
public $params = array();
/**
* Die komplette übergebene URL
*
* @var string
*/
public $query = '';
/**
* Zerlegt u.a. die übergebenen Parameter in der URI in ihre Bestandteile
*
* @return modules
*/
function __construct()
{
$this->query = substr(str_replace(PHP_SELF, '', htmlentities($_SERVER['PHP_SELF'], ENT_QUOTES)), 1);
if (!empty($this->query) && preg_match('/^(acp\/)/', $this->query)) {
// Definieren, dass man sich im Administrationsbereich befindet
define('IN_ADM', true);
// "acp/" entfernen
$this->query = substr($this->query, 4);
} else {
// Definieren, dass man sich im Frontend befindet
define('IN_ACP3', true);
// Query auf eine beutzerdefinierte Startseite setzen
if (!defined('IN_INSTALL') && empty($this->query) && CONFIG_HOMEPAGE != '') {
$this->query = CONFIG_HOMEPAGE;
}
}
$query = !empty($this->query) ? explode('/', $this->query) : 0;
$defaultModule = defined('IN_ADM') ? 'acp' : 'news';
$defaultPage = defined('IN_ADM') ? 'adm_list' : 'list';
$this->mod = !empty($query[0]) ? $query[0] : $defaultModule;
$this->page = !empty($query[1]) ? $query[1] : $defaultPage;
if (!empty($_POST['cat']))
$this->cat = $_POST['cat'];
if (!empty($_POST['action']))
$this->action = $_POST['action'];
if (!empty($query[2])) {
$c_query = count($query);
for ($i = 2; $i < $c_query; ++$i) {
if (!empty($query[$i])) {
if (!defined('POS') && preg_match('/^(pos_(\d+))$/', $query[$i])) {
define('POS', substr($query[$i], 4));
} elseif (preg_match('/^(([a-z0-9-]+)_(.+))$/', $query[$i])) {
$param = explode('_', $query[$i], 2);
$this->$param[0] = $param[1];
}
}
}
}
if (!defined('POS')) {
define('POS', '0');
}
}
/**
* Gibt alle URI Parameter aus
*
* @param string $key
* @return mixed
*/
public function __get($key)
{
if (!empty($key) && array_key_exists($key, $this->params))
return $this->params[$key];
return null;
}
/**
* Setzt neue URI Parameter
*
* @param string $name
* @param mixed $value
*/
public function __set($name, $value)
{
$this->params[$name] = $value;
}
}
?>
\ No newline at end of file
......@@ -58,12 +58,10 @@ if (CONFIG_MAINTENANCE == '1' && defined('IN_ACP3')) {
exit;
}
// Klassen initialisieren
$db = new db();
$modules = new modules();
$db = new db;
$uri = new uri;
$tpl->assign('MODULES', $modules);
$tpl->assign('MODULES', new modules);
require_once ACP3_ROOT . 'includes/functions.php';
$auth = new auth();
?>
\ No newline at end of file
......@@ -221,6 +221,56 @@ function datepicker($name, $value = '')
return $tpl->fetch('common/date.html');
}
/**
* Gibt eine Seitenauswahl aus
*
* @param integer $rows
* Anzahl der Datensätze
* @return string
* Gibt die Seitenauswahl aus
*/
function pagination($rows)
{
global $tpl, $uri;
if ($rows > CONFIG_ENTRIES) {
// Alle angegeben URL Parameter mit in die URL einbeziehen
$acp = defined('IN_ADM') ? 'acp/' : '';
$params = '';
if (!empty($uri->params)) {
foreach ($uri->params as $key => $value) {
if ($key != 'mod' && $key != 'page' && $key != 'pos') {
$params.= '/' . $key . '_' . $value;
}
}
}
$tpl->assign('uri', uri($acp . $uri->mod . '/' . $uri->page . $params));
// Seitenauswahl
$c_pages = ceil($rows / CONFIG_ENTRIES);
$recent = 0;
for ($i = 1; $i <= $c_pages; ++$i) {
$pages[$i]['selected'] = POS == $recent ? true : false;
$pages[$i]['page'] = $i;
$pages[$i]['pos'] = 'pos_' . $recent . '/';
$recent = $recent + CONFIG_ENTRIES;
}
$tpl->assign('pages', $pages);
// Vorherige Seite
$pos_prev = array('pos' => POS - CONFIG_ENTRIES >= 0 ? 'pos_' . (POS - CONFIG_ENTRIES) . '/' : '', 'selected' => POS == 0 ? true : false);
$tpl->assign('pos_prev', $pos_prev);
// Nächste Seite
$pos_next = array('pos' => 'pos_' . (POS + CONFIG_ENTRIES) . '/', 'selected' => POS + CONFIG_ENTRIES >= $rows ? true : false);
$tpl->assign('pos_next', $pos_next);
return $tpl->fetch('common/pagination.html');
}
}
/**
* Umleitung auf andere URLs
*
......
<?php
function smarty_function_load_module($params, &$smarty)
{
global $auth, $db, $modules, $tpl;
global $auth, $db, $uri, $tpl;
$module = explode('|', $params['module']);
if ($modules->check($module[0], $module[1])) {
if (modules::check($module[0], $module[1])) {
include ACP3_ROOT . 'modules/' . $module[0] . '/' . $module[1] . '.php';
}
}
......
<?php
function smarty_function_navbar($params)
{
global $modules;
if ($modules->check('pages', 'functions')) {
global $uri;
if (modules::check('pages', 'functions')) {
include_once ACP3_ROOT . 'modules/pages/functions.php';
return processNavbar($params['block']);
}
......
<?php
function smarty_function_uri($params, &$smarty)
{
global $uri;
return uri(!empty($params['args']) ? $params['args'] : '');
}
/* vim: set expandtab: */
......
......@@ -13,13 +13,13 @@ function smarty_function_wysiwyg($params) {
return editor($params);
} else {
global $modules;
global $uri;
$out = '';
$id = substr($params['name'], 5, -1);
// Falls aktiv, die Emoticons einbinden
if ($modules->check('emoticons', 'functions')) {
if (modules::check('emoticons', 'functions')) {
include_once ACP3_ROOT . 'modules/emoticons/functions.php';
$out.= emoticonsList($id);
}
......
......@@ -12,10 +12,12 @@ ob_start();
define('ACP3_ROOT', './');
require ACP3_ROOT . 'includes/common.php';
if ($modules->check()) {
include ACP3_ROOT . 'modules/' . $modules->mod . '/' . $modules->page . '.php';
$auth = new auth;
if (modules::check()) {
include ACP3_ROOT . 'modules/' . $uri->mod . '/' . $uri->page . '.php';
$tpl->assign('CONTENT', !empty($content) ? $content : '');
} elseif (!$auth->isUser() && defined('IN_ADM') && $modules->mod != 'users' && $modules->page != 'login') {
} elseif (!$auth->isUser() && defined('IN_ADM') && $uri->mod != 'users' && $uri->page != 'login') {
redirect('users/login');
} else {
redirect('errors/404');
......
......@@ -19,14 +19,14 @@ function __autoload($className)
include ACP3_ROOT . 'installation/includes/functions.php';
$modules = new modules();
$uri = new uri;
if (empty($modules->query)) {
$modules->mod = 'overview';
$modules->page = 'welcome';
if (empty($uri->query)) {
$uri->mod = 'overview';
$uri->page = 'welcome';
}
$lang = !empty($_POST['lang']) ? $_POST['lang'] : $modules->lang;
define('LANG', !empty($lang) && is_file(ACP3_ROOT . 'languages/' . $lang . '/info.php') ? $lang : 'de');
$lang = !empty($_POST['lang']) ? $_POST['lang'] : $uri->lang;
define('LANG', !empty($lang) && is_file(ACP3_ROOT . 'languages/' . $lang . '/info.xml') ? $lang : 'de');
// Smarty einbinden
define('SMARTY_DIR', ACP3_ROOT . 'includes/smarty/');
......@@ -77,5 +77,5 @@ $pages = array(
),
),
);
$tpl->assign('currentModule', $modules->mod);
$tpl->assign('currentModule', $uri->mod);
?>
\ No newline at end of file
......@@ -10,10 +10,10 @@ require ACP3_ROOT . 'installation/includes/startup.php';
// Überprüfen, ob die angeforderte Seite überhaupt existiert
$i = 0;
$is_page = false;
if (array_key_exists($modules->mod, $pages)) {
foreach ($pages[$modules->mod]['pages'] as $row) {
if ($row['page'] == $modules->page) {
$pages[$modules->mod]['pages'][$i]['selected'] = ' class="selected"';
if (array_key_exists($uri->mod, $pages)) {
foreach ($pages[$uri->mod]['pages'] as $row) {
if ($row['page'] == $uri->page) {
$pages[$uri->mod]['pages'][$i]['selected'] = ' class="selected"';
$tpl->assign('title', lang('installation', $row['page']));
$is_page = true;
break;
......@@ -23,7 +23,7 @@ if (array_key_exists($modules->mod, $pages)) {
}
// Selektion eines Menüpunktes in der Navigation
$pages[$modules->mod]['selected'] = ' class="selected"';
$pages[$uri->mod]['selected'] = ' class="selected"';
$tpl->assign('pages', $pages);
// Sprachpakete
......@@ -31,9 +31,8 @@ $languages = array();
$directories = scandir(ACP3_ROOT . 'languages');
$count_dir = count($directories);
for ($i = 0; $i < $count_dir; ++$i) {
$lang_info = array();
if (is_file(ACP3_ROOT . 'languages/' . $directories[$i] . '/info.php')) {
include ACP3_ROOT . 'languages/' . $directories[$i] . '/info.php';
$lang_info = xml::parseXmlFile(ACP3_ROOT . 'languages/' . $directories[$i] . '/info.xml', '/language');
if (!empty($lang_info)) {
$languages[$i]['dir'] = $directories[$i];
$languages[$i]['selected'] = LANG == $directories[$i] ? ' selected="selected"' : '';
$languages[$i]['name'] = $lang_info['name'];
......@@ -43,7 +42,7 @@ $tpl->assign('languages', $languages);
if ($is_page) {
$content = '';
include ACP3_ROOT . 'installation/modules/' . $modules->mod . '/' . $modules->page . '.php';
include ACP3_ROOT . 'installation/modules/' . $uri->mod . '/' . $uri->page . '.php';
$tpl->assign('content', $content);
} else {
$tpl->assign('title', lang('errors', '404'));
......
<?xml version="1.0" encoding="UTF-8"?>
<language>
<name>Deutsch</name>
<name>English</name>
<description>Official english ACP3 language pack.</description>
<author>Goratsch Webdesign</author>
<version core="true"/>
......
......@@ -14,9 +14,9 @@ $access = $db->select('id, name, modules', 'access', 0, 'name ASC', POS, CONFIG_
$c_access = count($access);
if ($c_access > 0) {
$tpl->assign('pagination', $modules->pagination($db->select('id', 'access', 0, 0, 0, 0, 1)));
$tpl->assign('pagination', pagination($db->select('id', 'access', 0, 0, 0, 0, 1)));
$mod_list = $modules->modulesList();
$mod_list = modules::modulesList();
for ($i = 0; $i < $c_access; ++$i) {
// Modulnamen anzeigen
......
......@@ -39,7 +39,7 @@ if (isset($_POST['submit'])) {
if (!isset($_POST['submit']) || isset($errors) && is_array($errors)) {
$tpl->assign('form', isset($form) ? $form : array('name' => ''));
$mod_list = $modules->modulesList();
$mod_list = modules::modulesList();
foreach ($mod_list as $name => $info) {
if ($info['dir'] == 'errors' || !$info['active']) {
......
......@@ -12,15 +12,15 @@ if (!defined('IN_ADM'))
if (isset($_POST['entries']) && is_array($_POST['entries']))
$entries = $_POST['entries'];
elseif (preg_match('/^([\d|]+)$/', $modules->entries))
$entries = $modules->entries;
elseif (preg_match('/^([\d|]+)$/', $uri->entries))
$entries = $uri->entries;
if (!isset($entries)) {
$content = comboBox(array(lang('common', 'no_entries_selected')));
} elseif (is_array($entries)) {
$marked_entries = implode('|', $entries);
$content = comboBox(lang('access', 'confirm_delete'), uri('acp/access/delete/entries_' . $marked_entries), uri('acp/access'));
} elseif (preg_match('/^([\d|]+)$/', $entries) && $modules->confirmed) {
} elseif (preg_match('/^([\d|]+)$/', $entries) && $uri->confirmed) {
$marked_entries = explode('|', $entries);
$bool = 0;
$level_undeletable = 0;
......
......@@ -12,13 +12,13 @@ if (!defined('IN_ADM'))
include_once ACP3_ROOT . 'modules/access/functions.php';
if (validate::isNumber($modules->id) && $db->select('id', 'access', 'id = \'' . $modules->id . '\'', 0, 0, 0, 1) == '1') {
if (validate::isNumber($uri->id) && $db->select('id', 'access', 'id = \'' . $uri->id . '\'', 0, 0, 0, 1) == '1') {
if (isset($_POST['submit'])) {
$form = $_POST['form'];
if (empty($form['name']))
$errors[] = lang('common', 'name_to_short');
if (!empty($form['name']) && $db->select('id', 'access', 'id != \'' . $modules->id . '\' AND name = \'' . $db->escape($form['name']) . '\'', 0, 0, 0, 1) == '1')
if (!empty($form['name']) && $db->select('id', 'access', 'id != \'' . $uri->id . '\' AND name = \'' . $db->escape($form['name']) . '\'', 0, 0, 0, 1) == '1')
$errors[] = lang('access', 'access_level_already_exist');
if (emptyCheck($form['modules']))
$errors[] = lang('access', 'select_modules');
......@@ -31,17 +31,17 @@ if (validate::isNumber($modules->id) && $db->select('id', 'access', 'id = \'' .
'modules' => buildAccessLevel($form['modules']),
);
$bool = $db->update('access', $update_values, 'id = \'' . $modules->id . '\'');
$bool = $db->update('access', $update_values, 'id = \'' . $uri->id . '\'');
$content = comboBox($bool ? lang('access', 'edit_success') : lang('access', 'edit_error'), uri('acp/access'));
}
}
if (!isset($_POST['submit']) || isset($errors) && is_array($errors)) {
$access = $db->select('name, modules', 'access', 'id = \'' . $modules->id . '\'');
$access = $db->select('name, modules', 'access', 'id = \'' . $uri->id . '\'');
$tpl->assign('form', isset($form) ? $form : $access[0]);
$mod_list = $modules->modulesList();
$mod_list = modules::modulesList();
$mods_arr = explode(',', $access[0]['modules']);
$c_mods_arr = count($mods_arr);
......
......@@ -13,17 +13,17 @@ if (!defined('IN_ADM'))
/**
* Baut den String den zu erstellenden / verändernden Zugriffslevel zusammen
*
* @param array $modules
* @param array $uri
* @return string
*/
function buildAccessLevel($modules)
function buildAccessLevel($uri)
{
if (!empty($modules) && is_array($modules)) {
$modules['errors'] = '2';
ksort($modules);
if (!empty($uri) && is_array($uri)) {
$uri['errors'] = '2';
ksort($uri);
$access_level = '';
foreach ($modules as $module => $level) {
foreach ($uri as $module => $level) {
$access_level.= $module . ':' . $level . ',';