]> 91.132.146.200 Git - dolphin.git/commitdiff
a simple framework
authorjumpin-banana <jumpin.banana@gmail.com>
Tue, 12 Jan 2010 15:54:23 +0000 (16:54 +0100)
committerjumpin-banana <jumpin.banana@gmail.com>
Tue, 12 Jan 2010 15:54:23 +0000 (16:54 +0100)
15 files changed:
simple-framework/README [new file with mode: 0644]
simple-framework/conf/README [new file with mode: 0644]
simple-framework/conf/db.php [new file with mode: 0644]
simple-framework/conf/main.php [new file with mode: 0644]
simple-framework/index.php [new file with mode: 0644]
simple-framework/lib/function.library.php [new file with mode: 0644]
simple-framework/lib/smarty/README [new file with mode: 0644]
simple-framework/site/script/README [new file with mode: 0644]
simple-framework/site/script/start.php [new file with mode: 0644]
simple-framework/site/template/css/style.css [new file with mode: 0644]
simple-framework/site/template/img/test.gif [new file with mode: 0644]
simple-framework/site/template/main.html [new file with mode: 0644]
simple-framework/site/template/start.html [new file with mode: 0644]
simple-framework/tmp/error/.keep [new file with mode: 0644]
simple-framework/tmp/session/.keep [new file with mode: 0644]

diff --git a/simple-framework/README b/simple-framework/README
new file mode 100644 (file)
index 0000000..e450f5f
--- /dev/null
@@ -0,0 +1,10 @@
+This is a very simple but yet working framework.
+Using smarty as template management
+
+All requests are going with the $_GET variable.
+The values are checked and validated. If successfull the right php and template file will be loaded.
+
+eg.
+index.php?p=start
+
+will load the start.php and start.html file as template and display all via the main.html file 
diff --git a/simple-framework/conf/README b/simple-framework/conf/README
new file mode 100644 (file)
index 0000000..eb24135
--- /dev/null
@@ -0,0 +1 @@
+Alter the files to match your configuration
diff --git a/simple-framework/conf/db.php b/simple-framework/conf/db.php
new file mode 100644 (file)
index 0000000..cace352
--- /dev/null
@@ -0,0 +1,7 @@
+<?php
+define('DB_TYPE','mysqli'); // Pdo_mysql has a bug with '?'
+define('DB_HOST','localhost');
+define('DB_DATABASE','db-name');
+define('DB_USER','user');
+define('DB_PASSWORD','test');
+?>
diff --git a/simple-framework/conf/main.php b/simple-framework/conf/main.php
new file mode 100644 (file)
index 0000000..b780cd5
--- /dev/null
@@ -0,0 +1,24 @@
+<?php
+
+// to get the system messages make it true
+define('DEBUG',true);
+
+// path settings
+define('PATH_ABSOLUTE',str_replace('/conf','',dirname(__FILE__)));
+if(dirname($_SERVER['SCRIPT_NAME']) === '/') {
+       define('WEBROOT_PATH','');
+}
+else {
+       define('WEBROOT_PATH',dirname($_SERVER['SCRIPT_NAME']));
+}
+define('TMP_DIR',PATH_ABSOLUTE.'/tmp');
+define('PATH_LIB','lib');
+
+// time settings
+date_default_timezone_set('Europe/Berlin');
+
+// session
+define("SESSION_LIFETIME",43200); // 8 hours
+define("SESSION_NAME","your-session-name");
+define("SESSION_SAVE_PATH",TMP_DIR.'/session');
+?>
diff --git a/simple-framework/index.php b/simple-framework/index.php
new file mode 100644 (file)
index 0000000..751ea78
--- /dev/null
@@ -0,0 +1,138 @@
+<?php
+/**
+ *                   |                                 |             |
+ *  __ \   _ \   __| __| |   |  __|    __|  _ \  __ \  __|  __| _ \  |
+ *  |   | (   | |    |   |   |\__ \   (    (   | |   | |   |   (   | |
+ * _|  _|\___/ _|   \__|\__, |____/_)\___|\___/ _|  _|\__|_|  \___/ _|
+ *                      ____/
+ *
+ * nortys.control
+ * Websiten Statistik Tool
+ *
+ * Copyright (C) 2010 Johannes Keßler
+ * nortys Gmbh
+ * E3, 13
+ * 68159 Mannheim
+ *
+ * @version: $Id: index.php 11 2010-01-12 14:31:05Z jk $
+ */
+
+mb_internal_encoding("UTF-8");
+
+if(ini_get("magic_quotes_gpc") == 1)
+    die('Magic quotes is set to "on", and system is not able to change it. Please update Your php.ini file');
+
+ /**
+ * load the main configuration
+ */
+require('conf/main.php');
+
+/**
+ * require the function.library.inc.php
+ * this holds global functions
+ */
+require(PATH_LIB.'/function.library.php');
+
+/**
+ * set the error reporting
+ */
+if(DEBUG === true) {
+       ini_set('error_reporting',8191); // E_ALL & E_STRICT
+       ini_set('display_errors',true);
+}
+else {
+       ini_set('error_reporting',8191); // E_ALL & E_STRICT
+       ini_set('display_errors',false);
+       ini_set('log_errors',true);
+       ini_set('log_errors_max_len',"10M");
+       ini_set('error_log',TMP_DIR.'/error/error.file');
+}
+
+/**
+ * inlcude check and process before we output any content
+ */
+$includeFile = false;
+if(!empty($_GET['p'])) {
+       $check = validateString($_GET['p']);
+       $check1 = file_exists('./site/script/'.$_GET['p'].'.php');
+       if($check === true && $check1 === true) {
+               $includeFile = './site/script/'.$_GET['p'].'.php';
+               $template = $_GET['p'].'.html';
+       }
+       else {
+               $includeFile = './site/script/error.php';
+               $template = 'error.html';
+       }
+}
+else {
+       if(file_exists('./site/script/start.php')) {
+               $includeFile = './site/script/start.php';
+       }
+       $template = 'start.html';
+}
+
+/**
+ * setup smarty
+ */
+require_once(PATH_LIB.'/smarty/Smarty.class.php');
+$smarty = new Smarty();
+$smarty->caching = 0;
+$smarty->template_dir = 'site/template';
+$smarty->compile_dir = 'site/cache/';
+$smarty->cache_dir = 'site/cache/';
+
+/**
+ * start a session
+ * we only use cookies and do not allow the overwrite via get or post
+ */
+if(ini_set('session.use_only_cookies',true) === false ||
+               ini_set('session.cookie_httponly',true) === false ||
+               ini_set('session.use_cookies',true) === false) {
+       die('Cant use session cookies');
+}
+$garbage_timeout = SESSION_LIFETIME + 300;
+ini_set('session.gc_maxlifetime', $garbage_timeout);
+// the % rate how often the session.gc is run
+// http://de.php.net/manual/en/session.configuration.php#ini.session.gc-probability
+ini_set('session.gc_probability',10); // 100 = everytime = 100%
+
+session_save_path(TMP_DIR.'/session');
+session_set_cookie_params(SESSION_LIFETIME);
+session_name(SESSION_NAME);
+session_start();
+session_regenerate_id(true);
+
+/**
+ * database connection
+ * wihtout it it would be not working
+ */
+require('./conf/db.php');
+$mysql_con = mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) OR die('Datenbankserver nicht erreichbar');
+$mysql_sel = mysql_select_db(DB_DATABASE,$mysql_con) OR die('Datenbank konnte nicht selektiert werden');
+mysql_query("SET NAMES 'utf8'");
+
+// the main varible to store the data for the template
+$data = array();
+
+// load the script file
+if($includeFile !== false) {
+       require($includeFile);
+}
+
+// the template we are using now to load the css and stuff correctly
+$smarty->assign(array('template_dir' => WEBROOT_PATH.'/site/template',
+                                               'img_path' => WEBROOT_PATH.'/site/template/img',
+                                               'template' => $template,
+                                               'data' => $data));
+
+if(!empty($data['_setHeader'])) {
+       // this comes from the individual pages
+       header($data['_setHeader']);
+}
+
+header('Content-type: text/html; charset=UTF-8');
+header("Date: ".gmdate("D, d M Y H:i:s", time())." GMT");
+header("Last-Modified: ".gmdate("D, d M Y H:i:s", time())." GMT");
+$smarty->display('main.html');
+
+?>
diff --git a/simple-framework/lib/function.library.php b/simple-framework/lib/function.library.php
new file mode 100644 (file)
index 0000000..6d2aa9c
--- /dev/null
@@ -0,0 +1,39 @@
+<?php
+/**
+ * validate given string if it is in given format
+ *
+ * @param string $str
+ * @param string $mode
+ * @return bool
+ */
+function validateString($str,$mode='alnum') {
+       $ret = false;
+       if(!empty($str)) {
+               $check = '';
+               switch($mode) {
+                       case 'alnumWhitespace':
+                               $check = preg_replace('/[^\p{L}\p{N}\p{P}\s]/u','',$str);
+                               if($str === $check) {
+                                       $ret = true;
+                               }
+                       break;
+
+                       case 'digit':
+                               $check = preg_replace('/[\p{^N}]/u','',$str);
+                               if($str === $check) {
+                                       $ret = true;
+                               }
+                       break;
+
+                       case 'alnum':
+                       default:
+                               $check = preg_replace('/[^\p{L}\p{N}\p{P}]/u','',$str);
+                               if($str === $check) {
+                                       $ret = true;
+                               }
+               }
+       }
+
+       return $ret;
+}
+?>
diff --git a/simple-framework/lib/smarty/README b/simple-framework/lib/smarty/README
new file mode 100644 (file)
index 0000000..0f390d0
--- /dev/null
@@ -0,0 +1,3 @@
+Place the smarty package here
+
+http://smarty.net
diff --git a/simple-framework/site/script/README b/simple-framework/site/script/README
new file mode 100644 (file)
index 0000000..83fd759
--- /dev/null
@@ -0,0 +1,2 @@
+Place all the php actions in the correct files here.
+this files will be included befor sending the header();
diff --git a/simple-framework/site/script/start.php b/simple-framework/site/script/start.php
new file mode 100644 (file)
index 0000000..92c9840
--- /dev/null
@@ -0,0 +1,9 @@
+<?php
+
+// do something:
+$var = 1;
+$var-new = $var+1;
+
+// fill the $data variable
+$data['test'] = "hallo";
+?>
diff --git a/simple-framework/site/template/css/style.css b/simple-framework/site/template/css/style.css
new file mode 100644 (file)
index 0000000..061a71c
--- /dev/null
@@ -0,0 +1 @@
+/* place your css stuff here */
diff --git a/simple-framework/site/template/img/test.gif b/simple-framework/site/template/img/test.gif
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/simple-framework/site/template/main.html b/simple-framework/site/template/main.html
new file mode 100644 (file)
index 0000000..2dbea22
--- /dev/null
@@ -0,0 +1,10 @@
+<html>
+<head>
+<title>Example framework</title>
+</head>
+<body>
+<div id="menu">Place the menu here</div>
+<div id="content">{inlcude file=$template}</div>
+<div id="footer">the footer text</div>
+</body>
+</html>
diff --git a/simple-framework/site/template/start.html b/simple-framework/site/template/start.html
new file mode 100644 (file)
index 0000000..e623674
--- /dev/null
@@ -0,0 +1,4 @@
+<!-- all the data are in the $data varibale -->
+{$data.test}
+
+<p>some nice html data</p>
diff --git a/simple-framework/tmp/error/.keep b/simple-framework/tmp/error/.keep
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/simple-framework/tmp/session/.keep b/simple-framework/tmp/session/.keep
new file mode 100644 (file)
index 0000000..e69de29