From c3ee1f19cdb3464008d183652156abfbd9a7388a Mon Sep 17 00:00:00 2001 From: Gabriel Dunne Date: Sat, 10 Jul 2010 19:01:16 -0700 Subject: [PATCH] added testing content, and ability to add config files at root level --- content/cat1/anothertest | 3 +++ content/cat2/another_test | 2 +- content/cat2/test_post | 2 ++ lib/data.php | 2 +- lib/init.php | 6 ++++-- lib/template.php | 7 ++----- public/index.php | 40 ++++++++++++++++++++++++-------------- templates/404.html.tpl | 23 ++++++++++++++++++++++ templates/default.html.tpl | 2 +- templates/index.html.tpl | 22 +++++++++++++++++++++ templates/test.html.tpl | 22 +++++++++++++++++++++ 11 files changed, 106 insertions(+), 25 deletions(-) create mode 100644 content/cat1/anothertest create mode 100644 templates/404.html.tpl create mode 100644 templates/index.html.tpl create mode 100644 templates/test.html.tpl diff --git a/content/cat1/anothertest b/content/cat1/anothertest new file mode 100644 index 0000000..de453e6 --- /dev/null +++ b/content/cat1/anothertest @@ -0,0 +1,3 @@ +title = another test +-- +yeah some more content for another test post in category1 \ No newline at end of file diff --git a/content/cat2/another_test b/content/cat2/another_test index 399940c..80672cc 100644 --- a/content/cat2/another_test +++ b/content/cat2/another_test @@ -1,3 +1,3 @@ title = another test post -- -this is some content yo yo yo \ No newline at end of file +this is some content yo yo yo CATEGORY 2 in DA HIZ \ No newline at end of file diff --git a/content/cat2/test_post b/content/cat2/test_post index 63f03f9..b568930 100644 --- a/content/cat2/test_post +++ b/content/cat2/test_post @@ -6,3 +6,5 @@ tags = with different tags this is an older test post! `some code` + +CAT 222 in DA HIZ \ No newline at end of file diff --git a/lib/data.php b/lib/data.php index 05bb081..9bee7ea 100644 --- a/lib/data.php +++ b/lib/data.php @@ -22,7 +22,7 @@ function get_entries( $path = "", $args = array()) $entries = array(); foreach ($dir_iterator as $file => $info) { - if (!$info->isDir()) { + if (!$info->isDir() && $info->getFilename() != CONFIG_FILE) { $entries[] = parse_entry($info); } } diff --git a/lib/init.php b/lib/init.php index 51fa8f6..7d57256 100644 --- a/lib/init.php +++ b/lib/init.php @@ -5,13 +5,15 @@ ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . dirname(realpath(__FILE__))); define ('SITE_TITLE', 'plog'); - define ('LOCAL_ROOT', '/local/root/to/plog/'); - define ('WEB_ROOT', 'http://www.webroot.com/'); + define ('LOCAL_ROOT', '/home/quilime/plog/plog/'); + define ('WEB_ROOT', 'http://dev.quilime.com/'); define ('CONTENT_DIR', 'content'); define ('TEMPLATE_DIR', 'templates'); define ('PAGE_DIR', 'pages'); define ('CONFIG_DELIMITER', '--'); + define ('TITLE_DELIMITER', ': '); + define ('CONFIG_FILE', 'config'); require_once 'data.php'; require_once 'output.php'; diff --git a/lib/template.php b/lib/template.php index a4558e9..c470488 100644 --- a/lib/template.php +++ b/lib/template.php @@ -39,20 +39,17 @@ class Template public function render( $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'); - - } public function page_title($delim) { - return SITE_TITLE . (isset($this->_tpl_vars['page_title']) ? $delim . $this->_tpl_vars['page_title'] : ""); + return isset($this->_tpl_vars['page_title']) ? $delim . $this->_tpl_vars['page_title'] : ""; } } diff --git a/public/index.php b/public/index.php index 70f2550..fbb2931 100644 --- a/public/index.php +++ b/public/index.php @@ -2,37 +2,47 @@ require_once '../lib/init.php'; - $url_parts = get_url(); + $url = get_url(); - list($response_format, $response_mime_type) = parse_format($url_parts['extension'], 'html'); + list($response_format, $response_mime_type) = parse_format($url['extension'], 'html'); # setup template $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']); + $content_request = LOCAL_ROOT . CONTENT_DIR . $url['dirname'] . '/' . $url['filename']; + $page_request = LOCAL_ROOT . PAGE_DIR . DIRECTORY_SEPARATOR . $url['filename']; + + # content exists, and is a folder + 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($url['dirname'] . '/' . $url['filename']); $t->assign('data', $data); - $t->assign('page_title', preg_replace('{^/|/$}', '', $url_parts['url'])); + $t->assign('page_title', preg_replace('{^/|/$}', '', $url['url'])); } - # is file - 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']))); + + # content exists, and is a single entry + else if (is_file($content_request)) { + $t->assign('data', parse_entry(new SplFileInfo($content_request))); $t->assign('single', true); $template = 'single.'.$response_format.'.tpl'; } - # is page - else if (is_file( LOCAL_ROOT . PAGE_DIR . DIRECTORY_SEPARATOR . $url_parts['filename'])) { - $page = parse_entry(new SplFileInfo(LOCAL_ROOT . PAGE_DIR . DIRECTORY_SEPARATOR . $url_parts['filename']), 1); + + # content exists, and is a page + else if (is_file($page_request)) { + $page = parse_entry(new SplFileInfo($page_request), 1); $t->assign('data', $page); $template = $page['config']['template'] ? $page['config']['template'] . '.' . $response_format . '.tpl' : 'page.' . $response_format . '.tpl'; } - # default (all entries) + + # 404 else { - list($data, $total) = get_entries(); - $t->assign('data', $data); + $template = '404.html.tpl'; } # render diff --git a/templates/404.html.tpl b/templates/404.html.tpl new file mode 100644 index 0000000..a0ed8af --- /dev/null +++ b/templates/404.html.tpl @@ -0,0 +1,23 @@ + + + + include_template('head-inc.html.tpl') ?> + + <?=SITE_TITLE?>: 404 + + + + + include_template('nav.html.tpl') ?> + +
+ + oops

+ 404 + +
+ + include_template('footer.html.tpl') ?> + + + diff --git a/templates/default.html.tpl b/templates/default.html.tpl index f353bb4..7972f03 100644 --- a/templates/default.html.tpl +++ b/templates/default.html.tpl @@ -3,7 +3,7 @@ include_template('head-inc.html.tpl') ?> - <?=$this->page_title(TITLE_DELIMITER);?> + <?=SITE_TITLE?><?=$this->page_title(TITLE_DELIMITER);?> diff --git a/templates/index.html.tpl b/templates/index.html.tpl new file mode 100644 index 0000000..964b92d --- /dev/null +++ b/templates/index.html.tpl @@ -0,0 +1,22 @@ + + + + include_template('head-inc.html.tpl') ?> + + <?=SITE_TITLE?> + + + + + include_template('nav.html.tpl') ?> + +
+ + this is the index template + +
+ + include_template('footer.html.tpl') ?> + + + diff --git a/templates/test.html.tpl b/templates/test.html.tpl new file mode 100644 index 0000000..d71de86 --- /dev/null +++ b/templates/test.html.tpl @@ -0,0 +1,22 @@ + + + + include_template('head-inc.html.tpl') ?> + + <?=SITE_TITLE?><?=$this->page_title(TITLE_DELIMITER);?> + + + + + include_template('nav.html.tpl') ?> + +
+ + this is the TEST TEST TEST template + +
+ + include_template('footer.html.tpl') ?> + + + -- 2.34.1