]> git.quilime.com - plog.git/commitdiff
Cleaned up model.php so it's closer to a typical MVC
authorGabriel Dunne <gdunne@quilime.com>
Mon, 3 Oct 2011 11:41:30 +0000 (17:11 +0530)
committerGabriel Dunne <gdunne@quilime.com>
Mon, 3 Oct 2011 11:41:30 +0000 (17:11 +0530)
.htaccess [new file with mode: 0644]
index.php
lib/data.php
lib/model.php

diff --git a/.htaccess b/.htaccess
new file mode 100644 (file)
index 0000000..89375db
--- /dev/null
+++ b/.htaccess
@@ -0,0 +1,15 @@
+
+
+
+# clean urls
+
+
+# <IfModule mod_rewrite.c>
+# RewriteEngine On
+# RewriteBase /
+# RewriteCond %{REQUEST_FILENAME} !-f
+# RewriteCond %{REQUEST_FILENAME} !-d
+# RewriteRule . index.php [L]
+# </IfModule>
+
+
index b4179b37a97c57af0edde7afabdc8800334874de..754dcb84e6c1a6f0eb9310739b341c2784373fdb 100644 (file)
--- a/index.php
+++ b/index.php
@@ -3,53 +3,14 @@
 require 'lib/init.php';
 
 $request = get_request();
-$template = 'default.html.tpl';
 
-$v = new View  ( $request );
-$m = new Model ( $request );
+$v = new View ($request);
+$m = new Model ($request);
 
-list($response_format, $response_mime_type) = parse_format($request['extension'], 'html');
+$v->assign('is_single', $m->is_single());
+$v->assign('is_page', $m->is_page());
+$v->assign('entries', $m->entries);
 
-echo '<pre>';
-exit(print_r($request));
+header("Content-Type: {$m->response_mime_type}; charset=UTF-8"); 
 
-$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($request['dirname'] . '/' . $request['filename']);
-    $v->assign('data', $data);
-    $v->assign('page_title', preg_replace('{^/|/$}', '', $request['url']));
-}
-
-# single entry
-else if (is_file($content_request)) {
-    $v->assign('data', parse_entry(new SplFileInfo($content_request)));
-    $v->assign('single', true);
-    $template = 'single.'.$response_format.'.tpl';
-}
-
-# page
-else if (is_file($page_request)) {
-    $page = parse_entry(new SplFileInfo($page_request), 1);
-    $v->assign('data', $page);
-    $template = $page['config']['template'] ? $page['config']['template'] . '.' . $response_format . '.tpl' : 'page.' . $response_format . '.tpl';
-}
-else if ($request['filename'] == 'index')
-{
-    $template = 'index.html.tpl';
-}
-else {
-    $template = '404.html.tpl';
-}
-
-$v->assign( 'total', isset($total) ? $total : 0 );
-
-header("Content-Type: {$response_mime_type}; charset=UTF-8"); 
-$v->render( $template ); 
+$v->render( $m->template ); 
index 1fb49ab3cf0207f6a94f1b4ac32ecb4772527afc..f536711c06d6b2adad39d4c191a8bfe2bb2c66d9 100644 (file)
@@ -38,24 +38,6 @@ function get_entries( $path = "", $args = array())
 }
 
 
-/**
- * get all pages
- */
-function get_pages()
-{
-       $path = LOCAL_ROOT . PAGE_DIR;
-       $dir_iterator = new DirectoryIterator($path);
-       $pages = array();
-       foreach($dir_iterator as $page) {
-               if ($page->isDir()) continue;
-               $arr = parse_entry($page, 1);
-               $arr['is_page'] = 1;
-               $pages[] = $arr;
-       }
-       return $pages;
-}
-
-
 /**
  *     returns directories of a folder
  *     @param path the path to search. defaults to the CONTENT_DIR
@@ -92,6 +74,23 @@ function get_dirs( $path = "", $args = array())
        return $dirs;
 }
 
+/**
+ * get all pages
+ */
+function get_pages()
+{
+       $path = LOCAL_ROOT . PAGE_DIR;
+       $dir_iterator = new DirectoryIterator($path);
+       $pages = array();
+       foreach($dir_iterator as $page) {
+               if ($page->isDir()) continue;
+               $arr = parse_entry($page, 1);
+               $arr['is_page'] = 1;
+               $pages[] = $arr;
+       }
+       return $pages;
+}
+
 
 /**
  * @param splFileInfo SPLFileInfo Object
@@ -142,4 +141,4 @@ function parse_entry($fileInfo, $page = 0)
     }  
 
        return $f;
-}
+}
\ No newline at end of file
index 24680d5c4b8958adf3fc70b821def589ca076e38..4c9557380ceeae32dcef507a70869fd17571d6f5 100644 (file)
@@ -2,8 +2,81 @@
 
 class Model
 {      
+       var $content_request = null;
+       var $page_request = null;
+       
+       var $response_format = 'html';
+       var $response_mime_type = 'text/html';
+       var $template = 'default.html.tpl';
+       var $page_title = null;
 
-       function __construct()
+       var $entries = null;
+       var $config = null;
+       var $total = 0; 
+
+       function __construct( $request )
+       {
+               $this->request = $request;
+               list($this->response_format, $this->response_mime_type) = parse_format($this->request['extension'], 'html');
+               $this->parse_request( $request );
+       }
+
+       function parse_request( $request )
+       {
+               $this->content_request = join(array( LOCAL_ROOT, CONTENT_DIR, $this->request['dirname'], $this->request['filename']), DIRECTORY_SEPARATOR );
+               $this->page_request    = join(array( LOCAL_ROOT, PAGE_DIR, $this->request['filename']), DIRECTORY_SEPARATOR );
+
+           # check if multiple entries (dir)
+           if ($this->is_multiple()) {
+                       # check if config file exists
+                   if ($this->has_config()) {
+                       $this->config = parse_entry(new SplFileInfo(join(array($content_request, CONFIG_FILE, DIRECTORY_SEPARATOR))));
+                       $this->template = $this->config['config']['template'] . '.' . $this->response_format . '.tpl' ;
+                   }
+               list($this->entries, $this->total) = get_entries(join(array($this->request['dirname'], $this->request['filename'], DIRECTORY_SEPARATOR)));
+               $this->page_title = preg_replace('{^/|/$}', '', $this->request['url']);
+               } 
+               # check if single
+               else if ($this->is_single())
+               {
+                       $this->entries = parse_entry(new SplFileInfo($this->content_request));
+                       $this->template = 'single.'.$this->response_format.'.tpl';
+               }
+               # check if page
+               else if ($this->is_page()) {
+               $this->entries = parse_entry(new SplFileInfo($this->page_request), 1);
+               $this->template = isset($page['config']['template']) ? 
+                                                       $this->entries['config']['template'] . '.' . $response_format . '.tpl' : 
+                                                       'page.' . $response_format . '.tpl';
+               }
+               # check if index
+               else if ($this->request['filename'] == 'index')
+               {
+               $this->template = 'index.html.tpl';
+               }
+               # poop 404
+               else {
+               $this->template = '404.html.tpl';
+               }
+       }
+
+       function has_config()
        {
+               return is_file($this->content_request . '/' . CONFIG_FILE );
        }
+
+       function is_multiple()
+       {
+               return is_dir($this->content_request);
+       }
+
+       function is_single()
+       {
+               return is_file($this->content_request);
+       }
+
+       function is_page()
+       {
+               return is_file($this->page_request);
+       }                       
 }