From 6952d618dc0d18df8b4176732181df10f2986830 Mon Sep 17 00:00:00 2001
From: Gabriel Dunne <gdunne@quilime.com>
Date: Mon, 3 Oct 2011 22:33:46 +0530
Subject: [PATCH] Pages working, entries vs entry working

---
 index.php                  | 10 +++++++---
 lib/data.php               |  4 ++--
 lib/model.php              | 10 +++++-----
 templates/default.html.tpl |  7 ++++---
 templates/page.html.tpl    |  2 +-
 templates/single.html.tpl  |  2 +-
 6 files changed, 20 insertions(+), 15 deletions(-)

diff --git a/index.php b/index.php
index 74c0a58..7b23f24 100644
--- a/index.php
+++ b/index.php
@@ -7,9 +7,13 @@ $request = get_request();
 $v = new View  ($request);
 $m = new Model ($request);
 
-$v->assign('is_single', $m->is_single());
-$v->assign('is_page',   $m->is_page());
-$v->assign('entries',   $m->entries);
+
+if ($m->is_single())
+	$v->assign('entry', $m->entry);
+else if ($m->is_page())
+	$v->assign('page', $m->page);
+else if ($m->is_multiple())
+	$v->assign('entries', $m->entries);
 
 header("Content-Type: {$m->response_mime_type}; charset=UTF-8"); 
 
diff --git a/lib/data.php b/lib/data.php
index 9efbdd5..59367a5 100644
--- a/lib/data.php
+++ b/lib/data.php
@@ -141,7 +141,7 @@ function parse_entry($fileInfo, $page = false)
 
 	$f['cat'] = $page ? null : array('name' => $clean_path, 'url' => $clean_path );
 	$f['path'] = $fileInfo->getRealPath();
-	$f['url'] = ($page ? '' : $f['cat']['url']) . '/' . $fileInfo->getFilename();
+	$f['url'] = ($page ? '' : $f['cat']['url'] . '/') . $fileInfo->getFilename();
 
     if (!CLEAN_URLS) {
     	$f['cat']['url'] = WEB_ROOT . '?p=' . $f['cat']['url'];
@@ -159,7 +159,7 @@ function get_entry ( $relative_entry_path )
 
 function get_page ( $relative_page_path )
 {
-	return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, PAGE_DIR, $relative_page_path), DIRECTORY_SEPARATOR)));
+	return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, PAGE_DIR, $relative_page_path), DIRECTORY_SEPARATOR)), 1);
 }
 
 function parse_config ( $relative_path )
diff --git a/lib/model.php b/lib/model.php
index e5e7e16..73a4ab9 100644
--- a/lib/model.php
+++ b/lib/model.php
@@ -47,17 +47,17 @@ class Model
 		# if single entry (file in CONTENT dir)
 		else if ($this->is_single())
 		{
-			$this->entries = get_entry( $this->content_request );
+			$this->entry = get_entry( $this->content_request );
 			$this->template = 'single.' . $this->response_format . '.tpl';
 		}
 
 
 		# if page (file in PAGES dir)
 		else if ($this->is_page()) {
-    		$this->entries = get_page( $this->page_request );
-    		$this->template = isset($page['config']['template']) ? 
-    							$this->entries['config']['template'] . '.' . $response_format . '.tpl' : 
-    							'page.' . $response_format . '.tpl';
+    		$this->page = get_page( $this->page_request );
+    		$this->template = isset($this->page['config']['template']) ? 
+    							$this->page['config']['template'] . '.' . $this->response_format . '.tpl' : 
+    							'page.' . $this->response_format . '.tpl';
 		}
 
 
diff --git a/templates/default.html.tpl b/templates/default.html.tpl
index e2e4d77..7b6927c 100644
--- a/templates/default.html.tpl
+++ b/templates/default.html.tpl
@@ -14,9 +14,10 @@
 
 	<? foreach($entries as $entry): ?>
 	<?  
-    if (isset($entry['content_short'])) 
-        $entry['content'] = $entry['content_short'] . '<br /><a class="more" href="'.$entry['url'].'">more &rarr;</a><br /><br />';
-    $this->include_template('entry.html.tpl', array('entry' => $entry)); 
+        if (isset($entry['content_short'])) 
+            $entry['content'] = $entry['content_short'] . '<br /><a class="more" href="'.$entry['url'].'">more &rarr;</a><br /><br />';
+
+        $this->include_template('entry.html.tpl', array('entry' => $entry)); 
     ?>
 	<? endforeach; ?>	
 	
diff --git a/templates/page.html.tpl b/templates/page.html.tpl
index 699aae9..137700c 100644
--- a/templates/page.html.tpl
+++ b/templates/page.html.tpl
@@ -12,7 +12,7 @@
     
 <div id="content">
 
-	<?=$data['content'];?>
+	<?=$page['content'];?>
 	
 </div>
 
diff --git a/templates/single.html.tpl b/templates/single.html.tpl
index 2af3963..a2fea66 100644
--- a/templates/single.html.tpl
+++ b/templates/single.html.tpl
@@ -11,7 +11,7 @@
     <? $this->include_template('nav.html.tpl') ?>
     
 	<div id="content">
-		<? $this->include_template('entry.html.tpl', array('entry' => $entries)); ?>	
+		<? $this->include_template('entry.html.tpl'); ?>	
 	</div>
 
 	<? $this->include_template('footer.html.tpl') ?>
-- 
2.34.1