CREATE TABLE IF NOT EXISTS dns_permissions (
permissionID INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
- permission VARCHAR(255) NOT NULL,
+ permission VARCHAR(255) NOT NULL
) ENGINE=InnoDB;
CREATE TABLE IF NOT EXISTS dns_permissions_to_user (
id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
userID INT(10) NOT NULL,
- permissionID VARCHAR(255) NOT NULL,
+ permissionID VARCHAR(255) NOT NULL
+) ENGINE=InnoDB;
+
+CREATE TABLE IF NOT EXISTS dns_language (
+ id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
+ languageID INT(10) NOT NULL,
+ languageItem VARCHAR(255) NOT NULL,
+ languageValue VARCHAR(255) NOT NULL
) ENGINE=InnoDB;
* @copyright 2014-2015 Jan Altensen (Stricted)
*/
class DNS {
+ /**
+ * module name
+ *
+ * @var string
+ */
+ protected static $module = '';
+
/**
* database object
*
/**
* init main system
*/
- public function __construct() {
+ public function __construct($module = '') {
+ self::$module = $module;
spl_autoload_register(array('dns\system\DNS', 'autoload'));
set_exception_handler(array('dns\system\DNS', 'handleException'));
set_error_handler(array('dns\system\DNS', 'handleError'), E_ALL);
$this->initSession();
$this->initLanguage();
$this->initTPL();
- new RequestHandler();
+ new RequestHandler(self::$module);
}
/*
* init language system
*/
protected function initLanguage () {
+ /*
+ * @TODO: activate this later
+ * self::buildlanguage();
+ */
$availableLanguages = array("de", "en");
$languageCode = 'de';
- $basedir = DNS_DIR.'/lang/';
+
if (isset($_GET['l'])) {
$code = strtolower($_GET['l']);
if (in_array($code, $availableLanguages)) {
}
}
+ // @TODO: remove this later
+ /* try to load module language files */
+ if (!empty(self::$module)) {
+ $basedir = DNS_DIR.'/'.self::$module.'/lang/';
+ $file = $basedir.$languageCode.'.lang.php';
+ self::getSession()->register('language', $languageCode);
+
+ if (file_exists($file)) {
+ require_once($file);
+ if (isset($lang) && !empty($lang) && is_array($lang)) {
+ $this->language = array_merge($this->language, $lang);
+ }
+ }
+ }
+
+ /* load default language files */
+ $basedir = DNS_DIR.'/lang/';
$file = $basedir.$languageCode.'.lang.php';
self::getSession()->register('language', $languageCode);
require_once(DNS_DIR.'/lib/system/api/smarty/libs/Smarty.class.php');
self::$tplObj = new \Smarty;
- self::getTPL()->setTemplateDir(DNS_DIR."/templates/".$tpl);
- self::getTPL()->setCompileDir(DNS_DIR."/templates/compiled/".$tpl);
+ self::getTPL()->setTemplateDir(DNS_DIR.(empty(self::$module) ? '' : '/'.self::$module)."/templates/".$tpl);
+ self::getTPL()->setCompileDir(DNS_DIR.(empty(self::$module) ? '' : '/'.self::$module)."/templates/compiled/".$tpl);
self::getTPL()->setPluginsDir(array(
DNS_DIR."/lib/system/api/smarty/libs/plugins",
DNS_DIR."/lib/template/plugins"
require_once($file);
}
+
+ /**
+ * build language files from database
+ *
+ * @param boolean $force
+ */
+ public static function buildlanguage ($force = false) {
+ $availableLanguages = array("de", "en");
+ foreach ($availableLanguages as $languageID => $languageCode) {
+
+ $file = DNS_DIR."/lang/".$languageCode.".lang.php";
+ if (!file_exists($file) || (filemtime($file) + 86400) < time() || $force === true) {
+ if (file_exists($file)) {
+ @unlink($file);
+ }
+
+ @touch($file);
+
+ $items = self::getDB()->query("select * from dns_language where languageID = ?", array($languageID));
+ $content = "<?php\n/**\n* language: ".$languageCode."\n* encoding: UTF-8\n* generated at ".gmdate("r")."\n* \n* DO NOT EDIT THIS FILE\n*/\n";
+ $content .= "\$lang = array();\n";
+ while ($row = self::getDB()->fetch_array($items)) {
+ print_r($row);
+ $content .= "\$lang['".$row['languageItem']."'] = '".str_replace("\$", '$', $row['languageValue'])."';\n";
+ }
+
+ $handler = fOpen($file, "a+");
+ fWrite($handler, $content);
+ fClose($handler);
+ }
+ }
+ }
}
/**
* init RequestHandler
*/
- public function __construct () {
+ public function __construct ($module = '') {
$className = "";
- $pages = glob(DNS_DIR.'/lib/page/*Page.class.php');
+ $pages = glob(DNS_DIR.'/lib/'.(empty($module) ? '' : $module.'/').'page/*Page.class.php');
if (isset($_GET["page"]) && !empty($_GET["page"])) {
if (strtolower($_GET["page"]) != "abstract") {
foreach ($pages as $page) {
$page = str_replace('Page.class.php', '', basename($page));
if (strtolower($_GET["page"]) == strtolower($page)) {
- $class = "\\dns\\page\\".$page."Page";
+ $class = "\\dns".(empty($module) ? '' : "\\".$module)."\\page\\".$page."Page";
if (class_exists($class) && is_subclass_of($class, '\\dns\\page\\AbstractPage')) {
$className = $class;
}
}
}
else {
- $className = '\\dns\\page\\IndexPage';
+ $className = '\\dns'.(empty($module) ? '' : '\\'.$module).'\\page\\IndexPage';
}
if (!User::isLoggedIn() && $className != '\dns\page\LoginPage' && $className != '\dns\page\ApiPage') {