From d3557f9bd3206abf075c1714215ab2dbf3e563e6 Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Thu, 1 Jul 2010 19:01:24 -0700 Subject: [PATCH] template editing, major editing to index file --- index.php | 83 ++++++++++--------- lib/data.php | 30 +++++-- lib/output.php | 4 +- lib/template.php | 10 ++- templates/about.html.tpl | 2 +- templates/code.html.tpl | 46 ++++------ .../{index.html.tpl => default.html.tpl} | 9 +- .../{index.json.tpl => default.json.tpl} | 0 templates/entry.html.tpl | 2 +- templates/index.html | 18 ---- templates/links.html.tpl | 8 +- templates/log.html.tpl | 51 ++++-------- 12 files changed, 119 insertions(+), 144 deletions(-) rename templates/{index.html.tpl => default.html.tpl} (67%) rename templates/{index.json.tpl => default.json.tpl} (100%) delete mode 100644 templates/index.html diff --git a/index.php b/index.php index 7df8b0b..9058549 100644 --- a/index.php +++ b/index.php @@ -4,55 +4,56 @@ $url_parts = get_url(); -// print_r($url_parts); - -// echo "

"; - list($response_format, $response_mime_type) = parse_format($url_parts['extension'], 'html'); $t = get_template_instance(); - - $view = isset($_GET['v']) ? $_GET['v'] : 'inline'; - - if (is_string($url_parts['basename'])) - { - - # base content folder - if (is_dir ( CONTENT_DIR . DIRECTORY_SEPARATOR . $url_parts['basename'])) { - - list($items, $total) = get_data(array($url_parts['basename'])); - $t->assign('items', $items); - $t->assign('total', $total); - $t->assign('view', $view); - $t->render($url_parts['basename'] . '.' . $response_format . '.tpl'); - exit; - } + $t->response_format = $response_format; - # single entry - else if ($url_parts['dirname'] != '.' && is_dir(CONTENT_DIR . $url_parts['dirname'])) { + $t->assign('view', $_GET['v']); + + + # content folder + if (is_dir(CONTENT_DIR . DIRECTORY_SEPARATOR . $url_parts['url']) && $url_parts['basename']) { + list($data, $total) = get_data(array($url_parts['basename'])); + $t->assign('data', $data); + $template = $url_parts['basename'] . '.' . $response_format . '.tpl'; + } - $t->assign('single', true); - $t->assign('item', parse_config(CONTENT_DIR . $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename'])); - $t->assign('content', $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename']); - - $t->render($url_parts['dirname'] . '.' . $response_format . '.tpl'); - exit; - } + + # single file + else if (is_file( CONTENT_DIR . $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename'])) { + $t->assign('single', true); + $t->assign('data', parse_config(CONTENT_DIR . $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename'])); + $t->assign('content', $url_parts['dirname'] . DIRECTORY_SEPARATOR . $url_parts['filename']); + $template = $url_parts['dirname'] . '.' . $response_format . '.tpl'; + } + + + # direct template + else if (is_file( TEMPLATE_DIR . DIRECTORY_SEPARATOR . $url_parts['filename'] .'.'. $response_format . '.tpl')) + { + $template = $url_parts['filename'] . '.' . $response_format . '.tpl'; + } - # not found - else { - $t->render('404.'.$response_format.'.tpl'); - exit; - } - } + # 404 + else if ($url_parts['basename']) { + $template = '404.'.$response_format.'.tpl'; + } - # render all entries inline - list($entries, $total) = get_inline_entries(array('log', 'code')); + # default (index) + else { + list($data, $total) = get_data(); + $t->assign('data', $data); + $template = 'default.'.$response_format.'.tpl'; + } - $t->assign('entries', $entries); - $t->assign('total', $total); - $t->render('index.'.$response_format.'.tpl'); - + + + + # render template + $t->assign('total', $total); + header("Content-Type: {$response_mime_type}; charset=UTF-8"); + $t->render($template); ?> diff --git a/lib/data.php b/lib/data.php index 20ecec1..bd8d3d3 100644 --- a/lib/data.php +++ b/lib/data.php @@ -1,15 +1,24 @@ $row) { - $time[$key] = $row['date']; + $time[$key] = $row['timestamp']; } - array_multisort($time, SORT_DESC, $result); + if ($time) + array_multisort($time, SORT_DESC, $result); return array($result, $result_total); } - function list_content($path, $args="") { list($list, $total) = get_content($path, $args); @@ -105,7 +117,7 @@ function parse_config ($config_file) } if ($break) { - $config['inline_content'] .= $c; + $config['inline_content'] .= $c . "\n"; } else { $conf = explode("=", $c); diff --git a/lib/output.php b/lib/output.php index 112c083..caf3ce1 100644 --- a/lib/output.php +++ b/lib/output.php @@ -61,7 +61,9 @@ function get_url() { - return pathinfo($_SERVER['SCRIPT_URL']); //substr($_SERVER['SCRIPT_URL'], strlen(get_base_dir() . '/')); + $path_info = pathinfo($_SERVER['SCRIPT_URL']); + $path_info['url'] = $_SERVER['SCRIPT_URL']; + return $path_info; //substr($_SERVER['SCRIPT_URL'], strlen(get_base_dir() . '/')); } diff --git a/lib/template.php b/lib/template.php index 5be035b..31598da 100644 --- a/lib/template.php +++ b/lib/template.php @@ -3,6 +3,7 @@ class Template { var $template_dir = 'templates'; + var $response_format = 'html'; var $_tpl_vars = array(); @@ -35,8 +36,13 @@ class Template public function render( $template ) { - extract( $this->_tpl_vars ); - include( $this->template_dir . DIRECTORY_SEPARATOR . $template ); + extract( $this->_tpl_vars ); + + if (is_file($this->template_dir . DIRECTORY_SEPARATOR . $template)) + include( $this->template_dir . DIRECTORY_SEPARATOR . $template ); + else + include( $this->template_dir . DIRECTORY_SEPARATOR . 'default.'.$this->response_format.'.tpl' ); + } } diff --git a/templates/about.html.tpl b/templates/about.html.tpl index 21784ec..341913c 100644 --- a/templates/about.html.tpl +++ b/templates/about.html.tpl @@ -2,7 +2,7 @@ - + include_template( 'head-inc.html.tpl' ); ?> <?php echo SITE_TITLE ?> - about diff --git a/templates/code.html.tpl b/templates/code.html.tpl index 2502d79..852a18a 100644 --- a/templates/code.html.tpl +++ b/templates/code.html.tpl @@ -1,33 +1,19 @@ -basename($url_string))); - $items = $items[0]; - $single = true; - } - - $inline = isset($_GET['inline']) ? true : false; - - $page = "code"; - - -?> - - - - <?php echo SITE_TITLE; ?> - code<?php if (sizeof($items) > 0 ) : ?>: <?echo strtolower($items['title']); ?> [<?php echo $items['medium']; ?>]<?php endif; ?> + + include_template('head-inc.html.tpl') ?> + + <?=SITE_TITLE; ?> + <? if ($single): ?> + - code: <?= $data['title']; ?> + [<?=date("Y M d", strtotime($data['date']));?>] + <? else: ?> + - code + <? endif; ?> + + @@ -40,11 +26,11 @@ -

[]

+

[]

@@ -53,7 +39,7 @@
list