--- /dev/null
+
+
+
+# clean urls
+
+
+# <IfModule mod_rewrite.c>
+# RewriteEngine On
+# RewriteBase /
+# RewriteCond %{REQUEST_FILENAME} !-f
+# RewriteCond %{REQUEST_FILENAME} !-d
+# RewriteRule . index.php [L]
+# </IfModule>
+
+
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 );
}
-/**
- * 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
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
}
return $f;
-}
+}
\ No newline at end of file
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);
+ }
}