$request = get_request();
-$v = new View ($request);
+$v = new View ($request);
$m = new Model ($request);
$v->assign('is_single', $m->is_single());
-$v->assign('is_page', $m->is_page());
-$v->assign('entries', $m->entries);
+$v->assign('is_page', $m->is_page());
+$v->assign('entries', $m->entries);
header("Content-Type: {$m->response_mime_type}; charset=UTF-8");
}
$entries = array();
foreach ($dir_iterator as $file => $info) {
- if (!$info->isDir() && !in_array($info->getFilename(), $_FILE_IGNORES)) {
- $entries[] = parse_entry($info);
+ if ( !$info->isDir() && !in_array( $info->getFilename(), $_FILE_IGNORES )) {
+ $entries[] = parse_entry( $info );
}
}
foreach ($entries as $key => $row)
$time[$key] = $row['timestamp'];
if ($time)
- array_multisort($time, $order, $entries);
+ array_multisort( $time, $order, $entries );
}
- return array($entries, sizeof($entries));
+ return $entries;
}
* @param splFileInfo SPLFileInfo Object
* @param page default is false
*/
-function parse_entry($fileInfo, $page = 0)
+function parse_entry($fileInfo, $page = false)
{
$config = "";
$content = "";
$config .= $line;
continue;
}
- if (trim($line) == MORE_DELIM) {
+ if (trim($line) == MORE_DELIM)
$passed_more = true;
- }
- if (!$passed_more) {
+ if (!$passed_more)
$content_short .= $line;
- }
$content .= $line;
}
$f['timestamp'] = $f['config']['date'] ? date('U', strtotime( $f['config']['date'])) : $fileInfo->getCTime();
$f['tags'] = isset($f['config']['tags']) ? explode(" ", $f['config']['tags']) : null;
$f['content'] = Markdown($content);
+
if ($passed_more)
$f['content_short'] = Markdown($content_short);
+
$cat = clean_slashes(str_replace(LOCAL_ROOT . CONTENT_DIR, "", $fileInfo->getPath()));
- $f['cat'] = $page ? null : array('name' => substr($cat,1), 'url' => $cat );
+ $clean_path = str_replace(LOCAL_ROOT . CONTENT_DIR, "", clean_slashes($fileInfo->getPath()));
+
+
+ $f['cat'] = $page ? null : array('name' => $clean_path, 'url' => $clean_path );
$f['path'] = $fileInfo->getRealPath();
- $f['url'] = ($page ? '' : substr($f['cat']['url'],1)) . $fileInfo->getFilename();
+ $f['url'] = ($page ? '' : $f['cat']['url']) . '/' . $fileInfo->getFilename();
if (!CLEAN_URLS) {
+ $f['cat']['url'] = WEB_ROOT . '?p=' . $f['cat']['url'];
$f['url'] = WEB_ROOT . '?p=' . $f['url'];
}
-
+
return $f;
}
-function parse_config ($location)
+function get_entry ( $relative_entry_path )
+{
+ return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, CONTENT_DIR, $relative_entry_path), DIRECTORY_SEPARATOR)));
+}
+
+function get_page ( $relative_page_path )
+{
+ return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, PAGE_DIR, $relative_page_path), DIRECTORY_SEPARATOR)));
+}
+
+function parse_config ( $relative_path )
{
- return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, CONTENT_DIR, $location, CONFIG_FILE, DIRECTORY_SEPARATOR))));
+ return parse_entry(new SplFileInfo(join(array(LOCAL_ROOT, CONTENT_DIR, $relative_path, CONFIG_FILE), DIRECTORY_SEPARATOR)));
}
\ No newline at end of file
class Model
{
+
var $content_request = null;
var $page_request = null;
var $entries = null;
var $config = null;
- var $total = 0;
+
function __construct( $request )
{
$this->parse_request( $this->request );
}
+
function parse_request( $request )
{
+
$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 multiple entries (dir in CONTENT dir)
if ($this->is_multiple()) {
# check if config file exists
if ($this->has_config()) {
- $this->config = parse_config($this->content_request);
+ $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($this->content_request);
+ $this->entries = get_entries( $this->content_request );
$this->page_title = preg_replace('{^/|/$}', '', $this->request['path']);
}
- # check if single
+
+
+ # if single entry (file in CONTENT dir)
else if ($this->is_single())
{
- $this->entries = parse_entry($this->content_request);
- $this->template = 'single.'.$this->response_format.'.tpl';
+ $this->entries = get_entry( $this->content_request );
+ $this->template = 'single.' . $this->response_format . '.tpl';
}
- # check if page
+
+
+ # if page (file in PAGES dir)
else if ($this->is_page()) {
- $this->entries = parse_entry($this->page_request, 1);
+ $this->entries = get_page( $this->page_request );
$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';
- // }
- # poop 404
+
+
+ # not found
else {
$this->template = '404.html.tpl';
}
function has_config()
{
- return is_file(join(array( LOCAL_ROOT, CONTENT_DIR, $this->content_request, CONFIG_FILE ), DIRECTORY_SEPARATOR ));
- }
-
- function get_config()
- {
-
+ return is_file(join(array( LOCAL_ROOT, CONTENT_DIR, $this->content_request, CONFIG_FILE ), DIRECTORY_SEPARATOR )) ? 1 : 0;
}
function is_multiple()
{
- return is_dir(join(array( LOCAL_ROOT, CONTENT_DIR, $this->content_request ), DIRECTORY_SEPARATOR ));
+ return is_dir(join(array( LOCAL_ROOT, CONTENT_DIR, $this->content_request ), DIRECTORY_SEPARATOR )) ? 1 : 0;
}
function is_single()
{
- return is_file(join(array( LOCAL_ROOT, CONTENT_DIR, $this->content_request ), DIRECTORY_SEPARATOR ));
+ return is_file(join(array( LOCAL_ROOT, CONTENT_DIR, $this->content_request ), DIRECTORY_SEPARATOR )) ? 1 : 0;
}
function is_page()
{
- return is_file(join(array( LOCAL_ROOT, PAGE_DIR, $this->page_request ), DIRECTORY_SEPARATOR ));
+ return is_file(join(array( LOCAL_ROOT, PAGE_DIR, $this->page_request ), DIRECTORY_SEPARATOR )) ? 1 : 0;
}
-}
\ No newline at end of file
+}
*/
function clean_slashes($path)
{
- return preg_replace('/\/+/', '/', $path);
+ return preg_replace('/\/+/', '/', $path);
}
-/**
- * makes sure path is valid
- */
-function validate_path()
-{
-
-}
-
/**
* @param int $seconds Number of seconds to convert into a human-readable timestamp
function get_url_parts()
{
$parts = explode('/', substr($_SERVER['HTTP_HOST'], strlen(get_base_dir() . '/')));
- return $parts[0] ? $parts : 0;
+ return $parts[0] ? $parts : 0;
}
$path_info = pathinfo( $path );
$path_info['path'] = preg_match("/\.\.\//", $path) ? '/' : $path;
$path_info['extension'] = null;
+ if ($path_info['dirname'] == '.')
+ $path_info['dirname'] = '';
- // echo '<pre>';
- // print_r($path_info);
- // exit;
-
- return $path_info; //substr($_SERVER['HTTP_HOST'], strlen(get_base_dir() . '/'));
+ return $path_info;
}
<?
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('entry' => $entry));
?>
<? endforeach; ?>
<div class="entry">
<h2>
- <a title="posted on <?=$data['date']?>" href="<?=$data['url']?>"><?=$data['title']?></a>
+ <a title="posted on <?=$entry['date']?>" href="<?=$entry['url']?>"><?=$entry['title']?></a>
</h2>
<div class="content">
- <?=$data['content']?>
+ <?=$entry['content']?>
</div>
<div class="metadata">
- posted <abbr title="<?=get_relative_time($data['timestamp']);?>"><?=date("F d, Y", $data['timestamp'])?></abbr>
- in <a href="<?=$data['cat']['url'];?>"><?=$data['cat']['name'];?></a>
+ posted <abbr title="<?=get_relative_time($entry['timestamp']);?>"><?=date("F d, Y", $entry['timestamp'])?></abbr>
+ in <a href="<?=$entry['cat']['url'];?>"><?=$entry['cat']['name'];?></a>
<br/>
<ul class="tags">
- <? if ($data['tags']) foreach($data['tags'] as $tag) : ?>
+ <? if ($entry['tags']) foreach($entry['tags'] as $tag) : ?>
<li>#<?=$tag?></li>
<? endforeach; ?>
</ul>
<? $this->include_template('head-inc.html.tpl') ?>
- <title><?=SITE_TITLE?><?=TITLE_DELIMITER?> <?=$data['title'];?></title>
+ <title><?=SITE_TITLE?><?=TITLE_DELIMITER?> <?=$entry['title'];?></title>
</head>
<body>
<? $this->include_template('nav.html.tpl') ?>
<div id="content">
- <? $this->include_template('entry.html.tpl', array('data' => $data)); ?>
+ <? $this->include_template('entry.html.tpl', array('entry' => $entries)); ?>
</div>
<? $this->include_template('footer.html.tpl') ?>