From 4b3b22c41eb4f1450d081b5fb1bbb2182f1a5994 Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Fri, 9 Jul 2010 18:24:45 -0700 Subject: [PATCH] new index --- lib/static.php | 18 ------------------ lib/template.php | 10 ++-------- public/index.php | 38 ++++++++++++++++++-------------------- templates/default.html.tpl | 2 +- 4 files changed, 21 insertions(+), 47 deletions(-) delete mode 100644 lib/static.php diff --git a/lib/static.php b/lib/static.php deleted file mode 100644 index ea0082e..0000000 --- a/lib/static.php +++ /dev/null @@ -1,18 +0,0 @@ -'; - foreach ($entries as $e) - { - echo '
  • '.$e['title'].' - '.$e['date'].'
  • '; - } - echo ''; - - - - - -?> \ No newline at end of file diff --git a/lib/template.php b/lib/template.php index abbb3b7..a4558e9 100644 --- a/lib/template.php +++ b/lib/template.php @@ -50,15 +50,9 @@ class Template } - function ob_file_callback($buffer) + public function page_title($delim) { -// fwrite($this->cache_file, $buffer); - } - - - public function title() - { - return ""; + return SITE_TITLE . (isset($this->_tpl_vars['page_title']) ? $delim . $this->_tpl_vars['page_title'] : ""); } } diff --git a/public/index.php b/public/index.php index f73f29e..1eedad8 100644 --- a/public/index.php +++ b/public/index.php @@ -6,40 +6,38 @@ list($response_format, $response_mime_type) = parse_format($url_parts['extension'], 'html'); + # setup template $t = get_template_instance(); $t->response_format = $response_format; $t->assign('view', $_GET['v']); - # content folder - if (is_dir(LOCAL_ROOT . CONTENT_DIR . DIRECTORY_SEPARATOR . $url_parts['url']) && $url_parts['url'] != "/") { - list($data, $total) = get_data(array($url_parts['url'])); - $t->assign('page_title', preg_replace('{^/|/$}', '', $url_parts['url'])); + # is folder + if (is_dir(LOCAL_ROOT . CONTENT_DIR . $url_parts['url']) && $url_parts['url'] != "/") { + list($data, $total) = get_entries($url_parts['url']); + $t->assign('page_title', preg_replace('{^/|/$}', '', $url_parts['url'])); $t->assign('data', $data); } - # single file - else if (is_file( LOCAL_ROOT . CONTENT_DIR . $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename'])) { - $t->assign('single', true); - $t->assign('data', parse_file(LOCAL_ROOT . CONTENT_DIR . $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename'])); + # is file + else if (is_file( LOCAL_ROOT . CONTENT_DIR . $url_parts['url'])) { + $t->assign('single', true); + $t->assign('data', parse_entry(new SplFileInfo(LOCAL_ROOT . CONTENT_DIR . $url_parts['url']))); $template = 'single.'.$response_format.'.tpl'; } - # page - else if (is_file( LOCAL_ROOT . PAGE_DIR . DIRECTORY_SEPARATOR . $url_parts['filename'] )) { - $t->assign('data', parse_file(LOCAL_ROOT . PAGE_DIR . DIRECTORY_SEPARATOR . $url_parts['filename'])); - $template = 'page.' . $response_format . '.tpl'; + # is page + else if (is_file( LOCAL_ROOT . PAGE_DIR . $url_parts['url'])) { + $page = parse_entry(new SplFileInfo(LOCAL_ROOT . PAGE_DIR . $url_parts['url']), 1); + $t->assign('data', $page); + $template = $page['config']['template'] ? $page['config']['template'] . '.' . $response_format . '.tpl' : 'page.' . $response_format . '.tpl'; } - # direct template - else if (is_file( LOCAL_ROOT . TEMPLATE_DIR . DIRECTORY_SEPARATOR . $url_parts['filename'] .'.'. $response_format . '.tpl')) { - $template = $url_parts['filename'] . '.' . $response_format . '.tpl'; - } - # default (index) + # default (all entries) else { - list($data, $total) = get_data(); + list($data, $total) = get_entries(); $t->assign('data', $data); } - - # render template + # render $t->assign('total', $total); header("Content-Type: {$response_mime_type}; charset=UTF-8"); $t->render($template); + ?> diff --git a/templates/default.html.tpl b/templates/default.html.tpl index f5f9572..d366eb7 100644 --- a/templates/default.html.tpl +++ b/templates/default.html.tpl @@ -3,7 +3,7 @@ include_template('head-inc.html.tpl') ?> - <?=SITE_TITLE?>, <?=$page_title?> + <?=$this->page_title('; ');?> -- 2.34.1