Added the ability for custom metas to be exposed in the pages object.
/* Title: Sub Page Custom: Me So Custom */ the `Custom` property can be used in the pages foreach loop as `{{ page.custom }}`.
This commit is contained in:
parent
641f7c334d
commit
174434a567
1 changed files with 24 additions and 20 deletions
44
lib/pico.php
44
lib/pico.php
|
@ -21,7 +21,7 @@ class Pico {
|
|||
// Load plugins
|
||||
$this->load_plugins();
|
||||
$this->run_hooks('plugins_loaded');
|
||||
|
||||
|
||||
// Get request url and script url
|
||||
$url = '';
|
||||
$request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '';
|
||||
|
@ -50,7 +50,7 @@ class Pico {
|
|||
$this->run_hooks('after_404_load_content', array(&$file, &$content));
|
||||
}
|
||||
$this->run_hooks('after_load_content', array(&$file, &$content));
|
||||
|
||||
|
||||
// Load the settings
|
||||
$settings = $this->get_config();
|
||||
$this->run_hooks('config_loaded', array(&$settings));
|
||||
|
@ -59,7 +59,7 @@ class Pico {
|
|||
$this->run_hooks('file_meta', array(&$meta));
|
||||
$content = $this->parse_content($content);
|
||||
$this->run_hooks('content_parsed', array(&$content));
|
||||
|
||||
|
||||
// Get all the pages
|
||||
$pages = $this->get_pages($settings['base_url'], $settings['pages_order_by'], $settings['pages_order'], $settings['excerpt_length']);
|
||||
$prev_page = array();
|
||||
|
@ -105,7 +105,7 @@ class Pico {
|
|||
$this->run_hooks('after_render', array(&$output));
|
||||
echo $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load any plugins
|
||||
*/
|
||||
|
@ -162,9 +162,9 @@ class Pico {
|
|||
$headers[$field] = trim($matches[2][$m]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if($headers['date']) $headers['date_formatted'] = date($config['date_format'], strtotime($headers['date']));
|
||||
|
||||
|
||||
if(empty($headers['title'])){
|
||||
preg_match('/^(.+?)[ ]*\n(=+|-+)[ ]*\n+/imu',$content,$matches);
|
||||
if(count($matches) > 0){
|
||||
|
@ -206,7 +206,7 @@ class Pico {
|
|||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a list of pages
|
||||
*
|
||||
|
@ -218,7 +218,7 @@ class Pico {
|
|||
private function get_pages($base_url, $order_by = 'alpha', $order = 'asc', $excerpt_length = 50)
|
||||
{
|
||||
global $config;
|
||||
|
||||
|
||||
$pages = $this->get_files(CONTENT_DIR, CONTENT_EXT);
|
||||
$sorted_pages = array();
|
||||
$date_id = 0;
|
||||
|
@ -233,7 +233,7 @@ class Pico {
|
|||
if (in_array(substr($page, -1), array('~','#'))) {
|
||||
unset($pages[$key]);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Get title and format $page
|
||||
$page_content = file_get_contents($page);
|
||||
$page_meta = $this->read_file_meta($page_content);
|
||||
|
@ -242,28 +242,32 @@ class Pico {
|
|||
$url = str_replace(CONTENT_DIR, $base_url .'/', $page);
|
||||
$url = str_replace('index'. CONTENT_EXT, '', $url);
|
||||
$url = str_replace(CONTENT_EXT, '', $url);
|
||||
$data = array(
|
||||
'title' => isset($page_meta['title']) ? $page_meta['title'] : null,
|
||||
$data = array();
|
||||
// these are generic fields that are added
|
||||
foreach ($page_meta as $key => $value) {
|
||||
$data[$key] = isset($page_meta[$key]) ? $value : null;
|
||||
}
|
||||
// these are special fields and need to be overwritten
|
||||
$extras = array(
|
||||
'url' => $url,
|
||||
'author' => isset($page_meta['author']) ? $page_meta['author'] : null,
|
||||
'date' => isset($page_meta['date']) ? $page_meta['date'] : null,
|
||||
'date_formatted' => isset($page_meta['date']) ? date($config['date_format'], strtotime($page_meta['date'])) : null,
|
||||
'content' => $page_content,
|
||||
'excerpt' => $this->limit_words(strip_tags($page_content), $excerpt_length)
|
||||
);
|
||||
$data = array_merge($data, $extras);
|
||||
if($order_by == 'date' && isset($page_meta['date'])){
|
||||
$sorted_pages[$page_meta['date'].$date_id] = $data;
|
||||
$date_id++;
|
||||
}
|
||||
else $sorted_pages[] = $data;
|
||||
}
|
||||
|
||||
|
||||
if($order == 'desc') krsort($sorted_pages);
|
||||
else ksort($sorted_pages);
|
||||
|
||||
|
||||
return $sorted_pages;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Processes any hooks and runs them
|
||||
*
|
||||
|
@ -310,14 +314,14 @@ class Pico {
|
|||
preg_match("|^HTTP[S]?|is",$_SERVER['SERVER_PROTOCOL'],$m);
|
||||
return strtolower($m[0]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to recusively get all files in a directory
|
||||
*
|
||||
* @param string $directory start directory
|
||||
* @param string $ext optional limit to file extensions
|
||||
* @return array the matched files
|
||||
*/
|
||||
*/
|
||||
private function get_files($directory, $ext = '')
|
||||
{
|
||||
$array_items = array();
|
||||
|
@ -336,14 +340,14 @@ class Pico {
|
|||
}
|
||||
return $array_items;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to limit the words in a string
|
||||
*
|
||||
* @param string $string the given string
|
||||
* @param int $word_limit the number of words to limit to
|
||||
* @return string the limited string
|
||||
*/
|
||||
*/
|
||||
private function limit_words($string, $word_limit)
|
||||
{
|
||||
$words = explode(' ',$string);
|
||||
|
|
Loading…
Add table
Reference in a new issue