From 644da1e1d72438165a557911af5c6a93bf7fb48d Mon Sep 17 00:00:00 2001 From: jumpin-banana Date: Tue, 12 Jan 2010 16:54:23 +0100 Subject: [PATCH] a simple framework --- simple-framework/README | 10 ++ simple-framework/conf/README | 1 + simple-framework/conf/db.php | 7 + simple-framework/conf/main.php | 24 ++++ simple-framework/index.php | 138 +++++++++++++++++++ simple-framework/lib/function.library.php | 39 ++++++ simple-framework/lib/smarty/README | 3 + simple-framework/site/script/README | 2 + simple-framework/site/script/start.php | 9 ++ simple-framework/site/template/css/style.css | 1 + simple-framework/site/template/img/test.gif | 0 simple-framework/site/template/main.html | 10 ++ simple-framework/site/template/start.html | 4 + simple-framework/tmp/error/.keep | 0 simple-framework/tmp/session/.keep | 0 15 files changed, 248 insertions(+) create mode 100644 simple-framework/README create mode 100644 simple-framework/conf/README create mode 100644 simple-framework/conf/db.php create mode 100644 simple-framework/conf/main.php create mode 100644 simple-framework/index.php create mode 100644 simple-framework/lib/function.library.php create mode 100644 simple-framework/lib/smarty/README create mode 100644 simple-framework/site/script/README create mode 100644 simple-framework/site/script/start.php create mode 100644 simple-framework/site/template/css/style.css create mode 100644 simple-framework/site/template/img/test.gif create mode 100644 simple-framework/site/template/main.html create mode 100644 simple-framework/site/template/start.html create mode 100644 simple-framework/tmp/error/.keep create mode 100644 simple-framework/tmp/session/.keep diff --git a/simple-framework/README b/simple-framework/README new file mode 100644 index 0000000..e450f5f --- /dev/null +++ b/simple-framework/README @@ -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 index 0000000..eb24135 --- /dev/null +++ b/simple-framework/conf/README @@ -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 index 0000000..cace352 --- /dev/null +++ b/simple-framework/conf/db.php @@ -0,0 +1,7 @@ + diff --git a/simple-framework/conf/main.php b/simple-framework/conf/main.php new file mode 100644 index 0000000..b780cd5 --- /dev/null +++ b/simple-framework/conf/main.php @@ -0,0 +1,24 @@ + diff --git a/simple-framework/index.php b/simple-framework/index.php new file mode 100644 index 0000000..751ea78 --- /dev/null +++ b/simple-framework/index.php @@ -0,0 +1,138 @@ +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 index 0000000..6d2aa9c --- /dev/null +++ b/simple-framework/lib/function.library.php @@ -0,0 +1,39 @@ + diff --git a/simple-framework/lib/smarty/README b/simple-framework/lib/smarty/README new file mode 100644 index 0000000..0f390d0 --- /dev/null +++ b/simple-framework/lib/smarty/README @@ -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 index 0000000..83fd759 --- /dev/null +++ b/simple-framework/site/script/README @@ -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 index 0000000..92c9840 --- /dev/null +++ b/simple-framework/site/script/start.php @@ -0,0 +1,9 @@ + diff --git a/simple-framework/site/template/css/style.css b/simple-framework/site/template/css/style.css new file mode 100644 index 0000000..061a71c --- /dev/null +++ b/simple-framework/site/template/css/style.css @@ -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 index 0000000..e69de29 diff --git a/simple-framework/site/template/main.html b/simple-framework/site/template/main.html new file mode 100644 index 0000000..2dbea22 --- /dev/null +++ b/simple-framework/site/template/main.html @@ -0,0 +1,10 @@ + + +Example framework + + + +
{inlcude file=$template}
+ + + diff --git a/simple-framework/site/template/start.html b/simple-framework/site/template/start.html new file mode 100644 index 0000000..e623674 --- /dev/null +++ b/simple-framework/site/template/start.html @@ -0,0 +1,4 @@ + +{$data.test} + +

some nice html data

diff --git a/simple-framework/tmp/error/.keep b/simple-framework/tmp/error/.keep new file mode 100644 index 0000000..e69de29 diff --git a/simple-framework/tmp/session/.keep b/simple-framework/tmp/session/.keep new file mode 100644 index 0000000..e69de29 -- 2.39.5