From a8404ee884b85ee41fc576e319c3bf205d9a04d1 Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Sat, 10 Jul 2010 18:24:14 -0700 Subject: [PATCH] merges from master branch --- lib/data.php | 12 ++++++++---- public/index.php | 38 ++++++++++++++------------------------ templates/entry.html.tpl | 10 ++++------ 3 files changed, 26 insertions(+), 34 deletions(-) diff --git a/lib/data.php b/lib/data.php index e20e402..05bb081 100644 --- a/lib/data.php +++ b/lib/data.php @@ -19,6 +19,7 @@ function get_entries( $path = "", $args = array()) else { $dir_iterator = new DirectoryIterator($path); } + $entries = array(); foreach ($dir_iterator as $file => $info) { if (!$info->isDir()) { @@ -77,7 +78,10 @@ function get_dirs( $path = "", $args = array()) $dirs = array(); foreach ($dir_iterator as $dir => $info) { if ($info->isDir() && $info->getFilename() != '.' && $info->getFilename() != '..') { - $dirs[] = str_replace($path, "", $info->getRealPath()); + $d = array(); + $d['url'] = str_replace($path, "", $info->getRealPath()) . '/'; + $d['name'] = substr(str_replace($path, "", $info->getRealPath()),1); + $dirs[] = $d; } } return $dirs; @@ -108,14 +112,14 @@ function parse_entry($fileInfo, $page = 0) $file = array(); $file['config'] = parse_ini_string($config); - $file['title'] = $file['config']['title']; $file['timestamp'] = $file['config']['date'] ? date('U', strtotime( $file['config']['date'])) : $fileInfo->getCTime(); $file['tags'] = $file['config']['tags'] ? explode(" ", $file['config']['tags']) : null; $file['content'] = Markdown($content); - $file['cat'] = $page? null : substr(clean_slashes(str_replace(LOCAL_ROOT . CONTENT_DIR, "", $fileInfo->getPath())),1); + $cat = clean_slashes(str_replace(LOCAL_ROOT . CONTENT_DIR, "", $fileInfo->getPath())); + $file['cat'] = $page ? null : array('name' => substr($cat,1), 'url' => $cat.'/' ); $file['path'] = $fileInfo->getRealPath(); - $file['url'] = WEB_ROOT . ($page ? '' : $file['cat'] . '/' ) . $fileInfo->getFilename(); + $file['url'] = WEB_ROOT . ($page ? '' : substr($file['cat']['url'],1)) . $fileInfo->getFilename() . '/'; return $file; } diff --git a/public/index.php b/public/index.php index b942251..70f2550 100644 --- a/public/index.php +++ b/public/index.php @@ -4,33 +4,24 @@ $url_parts = get_url(); - list($response_format, $response_mime_type) = parse_format($url_parts['extension'], 'html'); - + list($response_format, $response_mime_type) = parse_format($url_parts['extension'], 'html'); + # setup template - $t = get_template_instance(); + $t = get_template_instance(); $t->response_format = $response_format; $t->assign('view', $_GET['v']); - + # 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); - - if ($url_parts['url'] == '/projects/') - $template = 'projects.' . $response_format . '.tpl'; + $t->assign('page_title', preg_replace('{^/|/$}', '', $url_parts['url'])); } # is file - else if (is_file( LOCAL_ROOT . CONTENT_DIR . $url_parts['url'])) { - $t->assign('single', true); - $entry = parse_entry(new SplFileInfo(LOCAL_ROOT . CONTENT_DIR . $url_parts['url'])); - $t->assign('data', $entry); - - - if ($entry['cat'] == 'projects') - $template = 'project.'.$response_format.'.tpl'; - else - $template = 'single.'.$response_format.'.tpl'; + else if (is_file( LOCAL_ROOT . CONTENT_DIR . $url_parts['dirname'] . '/' . $url_parts['filename'])) { + $t->assign('data', parse_entry(new SplFileInfo(LOCAL_ROOT . CONTENT_DIR . $url_parts['dirname'] . '/' . $url_parts['filename']))); + $t->assign('single', true); + $template = 'single.'.$response_format.'.tpl'; } # is page else if (is_file( LOCAL_ROOT . PAGE_DIR . DIRECTORY_SEPARATOR . $url_parts['filename'])) { @@ -38,16 +29,15 @@ $t->assign('data', $page); $template = $page['config']['template'] ? $page['config']['template'] . '.' . $response_format . '.tpl' : 'page.' . $response_format . '.tpl'; } - # default + # default (all entries) else { list($data, $total) = get_entries(); - $t->assign('data', $data); - $template = 'index.html.tpl'; + $t->assign('data', $data); } - + # render - $t->assign('total', $total); + $t->assign('total', $total); header("Content-Type: {$response_mime_type}; charset=UTF-8"); $t->render($template); - + ?> diff --git a/templates/entry.html.tpl b/templates/entry.html.tpl index a7b8813..cd68910 100644 --- a/templates/entry.html.tpl +++ b/templates/entry.html.tpl @@ -2,23 +2,21 @@

- ">

-
- posted in
+ posted + in +
- - -- 2.34.1