From 4e23a6ad0adaf98c06a1305d97660c5781b9f55a Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Mon, 3 Oct 2011 16:15:57 +0530 Subject: [PATCH] Working on Local install --- index.php | 58 +++++++++++++++++----------------- lib/init.php | 15 ++++++--- lib/model.php | 9 ++++++ lib/output.php | 15 +-------- lib/{template.php => view.php} | 25 +++++++-------- 5 files changed, 61 insertions(+), 61 deletions(-) create mode 100644 lib/model.php rename lib/{template.php => view.php} (62%) diff --git a/index.php b/index.php index 181841a..b4179b3 100644 --- a/index.php +++ b/index.php @@ -1,55 +1,55 @@ response_format = $response_format; -$t->assign('view', isset($_GET['v']) ? $_GET['v'] : null); +$v = new View ( $request ); +$m = new Model ( $request ); -$content_request = LOCAL_ROOT. '/' . CONTENT_DIR . '/' . $url['dirname'] . '/' . $url['filename']; -$page_request = LOCAL_ROOT . '/' . PAGE_DIR . '/' . $url['filename']; -$total = 0; +list($response_format, $response_mime_type) = parse_format($request['extension'], 'html'); +echo '
';
+exit(print_r($request));
 
-if ($url['filename'] == 'index')
-{
-    $template = 'index.html.tpl';
-}
-else if (is_dir($content_request)) {
+$content_request = join(array(LOCAL_ROOT, CONTENT_DIR, $request['dirname'], $request['filename']), DIRECTORY_SEPARATOR );
+$page_request = join(array(LOCAL_ROOT, PAGE_DIR, $request['filename']), DIRECTORY_SEPARATOR );
+
+# multiple entries
+if (is_dir($content_request)) {
     # get config in folder, if exists
     if (is_file($content_request . '/' . CONFIG_FILE )) {
         $config = parse_entry(new SplFileInfo($content_request . '/' . CONFIG_FILE));
         $template = $config['config']['template'] . '.' . $response_format . '.tpl' ;
     }
-    list($data, $total) = get_entries($url['dirname'] . '/' . $url['filename']);
-    $t->assign('data', $data);
-    $t->assign('page_title', preg_replace('{^/|/$}', '', $url['url']));
+    list($data, $total) = get_entries($request['dirname'] . '/' . $request['filename']);
+    $v->assign('data', $data);
+    $v->assign('page_title', preg_replace('{^/|/$}', '', $request['url']));
 }
 
-# content exists, and is a single entry
+# single entry
 else if (is_file($content_request)) {
-    $t->assign('data', parse_entry(new SplFileInfo($content_request)));
-    $t->assign('single', true);
+    $v->assign('data', parse_entry(new SplFileInfo($content_request)));
+    $v->assign('single', true);
     $template = 'single.'.$response_format.'.tpl';
 }
 
-# content exists, and is a page
+# page
 else if (is_file($page_request)) {
     $page = parse_entry(new SplFileInfo($page_request), 1);
-    $t->assign('data', $page);
+    $v->assign('data', $page);
     $template = $page['config']['template'] ? $page['config']['template'] . '.' . $response_format . '.tpl' : 'page.' . $response_format . '.tpl';
 }
-
-# 404
+else if ($request['filename'] == 'index')
+{
+    $template = 'index.html.tpl';
+}
 else {
     $template = '404.html.tpl';
 }
 
-# render
-$t->assign('total', $total);
-header("Content-Type: {$response_mime_type}; charset=UTF-8");
-$t->render($template);
+$v->assign( 'total', isset($total) ? $total : 0 );
+
+header("Content-Type: {$response_mime_type}; charset=UTF-8"); 
+$v->render( $template ); 
diff --git a/lib/init.php b/lib/init.php
index 6f0205a..a09cb34 100644
--- a/lib/init.php
+++ b/lib/init.php
@@ -1,7 +1,13 @@
 ');
 define ('TITLE_DELIMITER', 	': ');
 define ('CONFIG_FILE', 		'config');
 
-
-
 # includes
 require_once 'data.php';
 require_once 'output.php';
 require_once 'markdown.php';
-require_once 'template.php';
+require_once 'model.php';
+require_once 'view.php';
diff --git a/lib/model.php b/lib/model.php
new file mode 100644
index 0000000..24680d5
--- /dev/null
+++ b/lib/model.php
@@ -0,0 +1,9 @@
+template_dir = join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', TEMPLATE_DIR));
-    $t->template_cache_dir = join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', TEMPLATE_DIR, 'cache'));
-
-    return $t;
-}
-
 /**
  *	@param format
  *  @param default format
@@ -169,7 +156,7 @@ function get_url_parts()
 }
 
 
-function get_url()
+function get_request()
 {
     $path_info = pathinfo( $_SERVER['SCRIPT_NAME'] );
     $path_info['url'] = preg_match("/\.\.\//", $_SERVER['SCRIPT_NAME']) ? '/' : $_SERVER['SCRIPT_NAME'];
diff --git a/lib/template.php b/lib/view.php
similarity index 62%
rename from lib/template.php
rename to lib/view.php
index c3f379c..bbd8e17 100644
--- a/lib/template.php
+++ b/lib/view.php
@@ -1,18 +1,21 @@
 template_dir = join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', TEMPLATE_DIR));
+    	$this->template_cache_dir = join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', TEMPLATE_DIR, 'cache'));		
 	}
 	
 	
@@ -32,18 +35,14 @@ class Template
 	public function include_template ($template, $vars = array())
 	{
 		$this->_tpl_vars = array_merge($this->_tpl_vars, $vars);
-		$this->render($template);
+		$this->render( $template );
 	}
 	
 
-	public function render( $template )
+	public function render( $template ) 
 	{
 		extract( $this->_tpl_vars );
-
-		if (is_file( $this->template_dir . DIRECTORY_SEPARATOR . $template ))
-			include( $this->template_dir . DIRECTORY_SEPARATOR . $template );
-		else
-			include( $this->template_dir . DIRECTORY_SEPARATOR . 'default.' . $this->response_format . '.tpl');
+		include( $this->template_dir . DIRECTORY_SEPARATOR . $template );
 	}
 	
 	
-- 
2.34.1