From: Gabriel Dunne Date: Sun, 11 Jul 2010 06:51:56 +0000 (-0700) Subject: merged from master branch X-Git-Url: https://git.quilime.com/?a=commitdiff_plain;h=0e70bb6d2ba8e6d078b0eb36c87c10a5b8b9231e;p=plog.git merged from master branch --- diff --git a/lib/data.php b/lib/data.php index e20e402..9bee7ea 100644 --- a/lib/data.php +++ b/lib/data.php @@ -19,9 +19,10 @@ function get_entries( $path = "", $args = array()) else { $dir_iterator = new DirectoryIterator($path); } + $entries = array(); foreach ($dir_iterator as $file => $info) { - if (!$info->isDir()) { + if (!$info->isDir() && $info->getFilename() != CONFIG_FILE) { $entries[] = parse_entry($info); } } @@ -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/lib/init.php b/lib/init.php index ee4f194..34b72ec 100644 --- a/lib/init.php +++ b/lib/init.php @@ -4,7 +4,7 @@ ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . dirname(realpath(__FILE__))); - define ('SITE_TITLE', 'gabriel dunne'); + define ('SITE_TITLE', 'plog'); define ('LOCAL_ROOT', '/home/quilime/gabrieldunne-site/'); define ('WEB_ROOT', 'http://dev.gabrieldunne.com/'); @@ -12,6 +12,8 @@ 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/output.php b/lib/output.php index 6866c6c..a7e88e6 100644 --- a/lib/output.php +++ b/lib/output.php @@ -60,7 +60,7 @@ if( !function_exists('parse_ini_string') ) { /** - * removes double slashes + * removes double slashes in path * @param path */ function clean_slashes($path) @@ -69,6 +69,15 @@ function clean_slashes($path) } +/** + * makes sure path is valid + */ +function validate_path() +{ + +} + + /** * @param int $seconds Number of seconds to convert into a human-readable timestamp * @return tring Human-readable approximate timestamp like "2 hours" @@ -148,8 +157,8 @@ function get_url_parts() function get_url() { -$path_info = pathinfo($_SERVER['SCRIPT_URL']); -$path_info['url'] = $_SERVER['SCRIPT_URL']; + $path_info = pathinfo($_SERVER['SCRIPT_URL']); + $path_info['url'] = preg_match("/\.\.\//", $_SERVER['SCRIPT_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 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 ba03ff2..fbb2931 100644 --- a/public/index.php +++ b/public/index.php @@ -2,42 +2,52 @@ require_once '../lib/init.php'; - $url_parts = get_url(); + $url = get_url(); + + list($response_format, $response_mime_type) = parse_format($url['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); + + $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['url'])); } - # 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'; + + # 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 - $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 6994474..cd68910 100644 --- a/templates/entry.html.tpl +++ b/templates/entry.html.tpl @@ -2,23 +2,21 @@

- ">

-
- posted in
+ posted + in +
- -