From: Gabriel Dunne Date: Mon, 3 Oct 2011 13:12:14 +0000 (+0530) Subject: updated file ignores, and entries X-Git-Url: https://git.quilime.com/?a=commitdiff_plain;h=7489a7ac8f1795b9f6572d957d20a2fc90f59e08;p=plog.git updated file ignores, and entries --- diff --git a/content/config b/content/config index e69de29..f90d27c 100644 --- a/content/config +++ b/content/config @@ -0,0 +1 @@ +title = index \ No newline at end of file diff --git a/lib/data.php b/lib/data.php index f536711..648d546 100644 --- a/lib/data.php +++ b/lib/data.php @@ -7,10 +7,14 @@ */ function get_entries( $path = "", $args = array()) { + global $_FILE_IGNORES; + $recursive = isset($args['recursive']) ? $args['recursive'] : 1; $order_by = empty($args['order_by']) ? null : $args['order_by']; $order = empty($args['order']) ? SORT_DESC : $args['order']; - $path = LOCAL_ROOT . CONTENT_DIR . $path; + + $path = join(array( LOCAL_ROOT, CONTENT_DIR, $path ), DIRECTORY_SEPARATOR); + if ($recursive) { $iterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::KEY_AS_PATHNAME); $dir_iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST); @@ -20,7 +24,7 @@ function get_entries( $path = "", $args = array()) } $entries = array(); foreach ($dir_iterator as $file => $info) { - if (!$info->isDir() && $info->getFilename() != CONFIG_FILE) { + if (!$info->isDir() && !in_array($info->getFilename(), $_FILE_IGNORES)) { $entries[] = parse_entry($info); } } @@ -64,7 +68,7 @@ function get_dirs( $path = "", $args = array()) $d['url'] = str_replace($path, "", $info->getRealPath()); if (!CLEAN_URLS) { - $d['url'] = WEB_ROOT . '?c=' . $d['url']; + $d['url'] = WEB_ROOT . '?p=' . $d['url']; } $d['name'] = str_replace($path, "", $info->getRealPath()); @@ -134,11 +138,17 @@ function parse_entry($fileInfo, $page = 0) $cat = clean_slashes(str_replace(LOCAL_ROOT . CONTENT_DIR, "", $fileInfo->getPath())); $f['cat'] = $page ? null : array('name' => substr($cat,1), 'url' => $cat ); $f['path'] = $fileInfo->getRealPath(); - $f['url'] = ($page ? '' : substr($file['cat']['url'],1)) . $fileInfo->getFilename(); + $f['url'] = ($page ? '' : substr($f['cat']['url'],1)) . $fileInfo->getFilename(); if (!CLEAN_URLS) { $f['url'] = WEB_ROOT . '?p=' . $f['url']; - } - + } + return $f; +} + + +function parse_config ($location) +{ + return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, CONTENT_DIR, $location, CONFIG_FILE, DIRECTORY_SEPARATOR)))); } \ No newline at end of file diff --git a/lib/init.php b/lib/init.php index a09cb34..a6efdde 100644 --- a/lib/init.php +++ b/lib/init.php @@ -23,7 +23,7 @@ ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . dirname(realp define ('CLEAN_URLS', false); define ('SITE_TITLE', 'plog'); define ('LOCAL_ROOT', '/Users/gdunne/Sites/india/'); -define ('WEB_ROOT', 'http://localhost/~gdunne/india/'); +define ('WEB_ROOT', '/~gdunne/india/'); define ('CONTENT_DIR', 'content/'); define ('TEMPLATE_DIR', 'templates/'); define ('PAGE_DIR', 'pages/'); @@ -32,6 +32,9 @@ define ('MORE_DELIM', ''); define ('TITLE_DELIMITER', ': '); define ('CONFIG_FILE', 'config'); +# ignores +$_FILE_IGNORES = array(CONFIG_FILE, '.DS_Store'); + # includes require_once 'data.php'; require_once 'output.php'; diff --git a/lib/model.php b/lib/model.php index 4c95573..4a69874 100644 --- a/lib/model.php +++ b/lib/model.php @@ -7,8 +7,8 @@ class Model var $response_format = 'html'; var $response_mime_type = 'text/html'; - var $template = 'default.html.tpl'; var $page_title = null; + var $template = 'default.html.tpl'; var $entries = null; var $config = null; @@ -18,42 +18,44 @@ class Model { $this->request = $request; list($this->response_format, $this->response_mime_type) = parse_format($this->request['extension'], 'html'); - $this->parse_request( $request ); + $this->parse_request( $this->request ); } function parse_request( $request ) { - $this->content_request = join(array( LOCAL_ROOT, CONTENT_DIR, $this->request['dirname'], $this->request['filename']), DIRECTORY_SEPARATOR ); - $this->page_request = join(array( LOCAL_ROOT, PAGE_DIR, $this->request['filename']), DIRECTORY_SEPARATOR ); + $this->content_request = join(array($this->request['dirname'], $this->request['filename']), DIRECTORY_SEPARATOR ); + $this->page_request = $this->request['filename']; # check if multiple entries (dir) if ($this->is_multiple()) { # check if config file exists if ($this->has_config()) { - $this->config = parse_entry(new SplFileInfo(join(array($content_request, CONFIG_FILE, DIRECTORY_SEPARATOR)))); - $this->template = $this->config['config']['template'] . '.' . $this->response_format . '.tpl' ; + $this->config = parse_config($this->content_request); + if (isset($this->config['config']['template'])) { + $this->template = $this->config['config']['template'] . '.' . $this->response_format . '.tpl' ; + } } - list($this->entries, $this->total) = get_entries(join(array($this->request['dirname'], $this->request['filename'], DIRECTORY_SEPARATOR))); - $this->page_title = preg_replace('{^/|/$}', '', $this->request['url']); + list($this->entries, $this->total) = get_entries($this->content_request); + $this->page_title = preg_replace('{^/|/$}', '', $this->request['path']); } # check if single else if ($this->is_single()) { - $this->entries = parse_entry(new SplFileInfo($this->content_request)); + $this->entries = parse_entry($this->content_request); $this->template = 'single.'.$this->response_format.'.tpl'; } # check if page else if ($this->is_page()) { - $this->entries = parse_entry(new SplFileInfo($this->page_request), 1); + $this->entries = parse_entry($this->page_request, 1); $this->template = isset($page['config']['template']) ? $this->entries['config']['template'] . '.' . $response_format . '.tpl' : 'page.' . $response_format . '.tpl'; } - # check if index - else if ($this->request['filename'] == 'index') - { - $this->template = 'index.html.tpl'; - } + // # check if index + // else if ($this->request['filename'] == 'index') + // { + // $this->template = 'index.html.tpl'; + // } # poop 404 else { $this->template = '404.html.tpl'; @@ -62,21 +64,26 @@ class Model function has_config() { - return is_file($this->content_request . '/' . CONFIG_FILE ); + return is_file(join(array( LOCAL_ROOT, CONTENT_DIR, $this->content_request, CONFIG_FILE ), DIRECTORY_SEPARATOR )); + } + + function get_config() + { + } function is_multiple() { - return is_dir($this->content_request); + return is_dir(join(array( LOCAL_ROOT, CONTENT_DIR, $this->content_request ), DIRECTORY_SEPARATOR )); } function is_single() { - return is_file($this->content_request); + return is_file(join(array( LOCAL_ROOT, CONTENT_DIR, $this->content_request ), DIRECTORY_SEPARATOR )); } function is_page() { - return is_file($this->page_request); + return is_file(join(array( LOCAL_ROOT, PAGE_DIR, $this->page_request ), DIRECTORY_SEPARATOR )); } -} +} \ No newline at end of file diff --git a/lib/output.php b/lib/output.php index 6db7d4b..7ec4a73 100644 --- a/lib/output.php +++ b/lib/output.php @@ -151,16 +151,31 @@ function get_base_href() function get_url_parts() { - $parts = explode('/', substr($_SERVER['HTTP_HOST'], strlen(get_base_dir() . '/'))); + $parts = explode('/', substr($_SERVER['HTTP_HOST'], strlen(get_base_dir() . '/'))); return $parts[0] ? $parts : 0; } function get_request() -{ - $path_info = pathinfo( $_SERVER['SCRIPT_NAME'] ); - $path_info['url'] = preg_match("/\.\.\//", $_SERVER['SCRIPT_NAME']) ? '/' : $_SERVER['SCRIPT_NAME']; - //$path_info['extension'] = null; +{ + if (!CLEAN_URLS && isset($_GET['p'])) { + $path = $_GET['p']; + } else { + // TODO + // this is fudged + if ($_SERVER['REQUEST_URI'] == WEB_ROOT) { + $path = '/'; + } + } + + $path_info = pathinfo( $path ); + $path_info['path'] = preg_match("/\.\.\//", $path) ? '/' : $path; + $path_info['extension'] = null; + + // echo '
';
+    // print_r($path_info);
+    // exit;
+
     return $path_info; //substr($_SERVER['HTTP_HOST'], strlen(get_base_dir() . '/'));
 }
 
diff --git a/templates/default.html.tpl b/templates/default.html.tpl
index 1973392..c7b1c13 100644
--- a/templates/default.html.tpl
+++ b/templates/default.html.tpl
@@ -12,15 +12,11 @@
     
 
- + more →

'; - - - $this->include_template('entry.html.tpl', array('data' => $entry)); - - + $this->include_template('entry.html.tpl', array('data' => $entry)); ?> diff --git a/templates/index.html.tpl b/templates/index.html.tpl index 964b92d..88d0408 100644 --- a/templates/index.html.tpl +++ b/templates/index.html.tpl @@ -12,7 +12,7 @@
- this is the index template + hello world
diff --git a/templates/nav.html.tpl b/templates/nav.html.tpl index b17cb3a..b45a42a 100644 --- a/templates/nav.html.tpl +++ b/templates/nav.html.tpl @@ -1,6 +1,6 @@