+title = index
\ No newline at end of file
*/
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);
}
$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);
}
}
$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());
$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
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/');
define ('TITLE_DELIMITER', ': ');
define ('CONFIG_FILE', 'config');
+# ignores
+$_FILE_IGNORES = array(CONFIG_FILE, '.DS_Store');
+
# includes
require_once 'data.php';
require_once 'output.php';
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;
{
$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';
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
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 '<pre>';
+ // print_r($path_info);
+ // exit;
+
return $path_info; //substr($_SERVER['HTTP_HOST'], strlen(get_base_dir() . '/'));
}
<div id="content">
- <? foreach($data as $entry): ?>
+ <? foreach($entries as $entry): ?>
<?
- if ($entry['content_short'])
+ if (isset($entry['content_short']))
$entry['content'] = $entry['content_short'] . '<br /><a class="more" href="'.$entry['url'].'">more →</a><br /><br />';
-
-
- $this->include_template('entry.html.tpl', array('data' => $entry));
-
-
+ $this->include_template('entry.html.tpl', array('data' => $entry));
?>
<? endforeach; ?>
<div id="content">
- this is the index template
+ hello world
</div>
<ul class="nav">
- <li><h2><a href="/"><?=SITE_TITLE;?></a></h2></li>
+ <li><h2><a href="<?=WEB_ROOT;?>"><?=SITE_TITLE;?></a></h2></li>
<br />