add module system
authorStricted <info@stricted.de>
Thu, 4 Jun 2015 13:31:43 +0000 (15:31 +0200)
committerStricted <info@stricted.de>
Thu, 4 Jun 2015 13:31:43 +0000 (15:31 +0200)
api/index.php [new file with mode: 0644]
database.sql
lib/api/page/IndexPage.class.php [new file with mode: 0644]
lib/system/DNS.class.php
lib/system/RequestHandler.class.php

diff --git a/api/index.php b/api/index.php
new file mode 100644 (file)
index 0000000..2e4c734
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+namespace dns;
+use dns\system\DNS;
+
+session_start();
+
+/**
+ * @author      Jan Altensen (Stricted)
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @copyright   2014-2015 Jan Altensen (Stricted)
+ */
+define("DNS_DIR", dirname(dirname(__FILE__)));
+require_once("../lib/system/DNS.class.php");
+new DNS('api');
index f755c519c4cfc0e4b08e2a3e77b55386ca3e6248..5a80033c010939947ca9005564724e36a1e746fb 100644 (file)
@@ -81,13 +81,20 @@ CREATE TABLE IF NOT EXISTS dns_session (
 
 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;
 
 
diff --git a/lib/api/page/IndexPage.class.php b/lib/api/page/IndexPage.class.php
new file mode 100644 (file)
index 0000000..6ab2ad2
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+namespace dns\api\page;
+use dns\page\AbstractPage;
+
+/**
+ * @author      Jan Altensen (Stricted)
+ * @license     GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @copyright   2013-2015 Jan Altensen (Stricted)
+ */
+class IndexPage extends AbstractPage {
+    public function prepare () {
+               /* we have no index page */
+       exit;
+    }
+}
\ No newline at end of file
index 03e87ac0302c8be50130117ae13d233ceb1ec1a5..cd7c8a4bd0dfb915cc41a61c1498788d3b9895c3 100644 (file)
@@ -9,6 +9,13 @@ if (!defined('DNS_VERSION')) define('DNS_VERSION', '3.0.0 Beta');
  * @copyright   2014-2015 Jan Altensen (Stricted)
  */
 class DNS {
+       /**
+        * module name
+        *
+        * @var string
+        */
+       protected static $module = '';
+       
        /**
         * database object
         *
@@ -40,7 +47,8 @@ class DNS {
        /**
         * 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);
@@ -51,7 +59,7 @@ class DNS {
                $this->initSession();
                $this->initLanguage();
                $this->initTPL();
-               new RequestHandler();
+               new RequestHandler(self::$module);
        }
        
        /*
@@ -173,9 +181,13 @@ class DNS {
         * 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)) {
@@ -205,6 +217,23 @@ class DNS {
                        }
                }
                
+               // @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);
                
@@ -263,8 +292,8 @@ class DNS {
                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"
@@ -338,4 +367,36 @@ class DNS {
                
                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);
+                       }
+               }
+       }
 }
index 9e0b66096f453cdeb4f79dd86841953a9aeb162f..8109afa90ca3489bab25b35a377beb6305468ce3 100644 (file)
@@ -10,15 +10,15 @@ class RequestHandler {
        /**
         * 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;
                                                }
@@ -28,7 +28,7 @@ class RequestHandler {
                        }
                }
                else {
-                       $className = '\\dns\\page\\IndexPage';
+                       $className = '\\dns'.(empty($module) ? '' : '\\'.$module).'\\page\\IndexPage';
                }
                
                if (!User::isLoggedIn() && $className != '\dns\page\LoginPage' && $className != '\dns\page\ApiPage') {