Updated to 0.8

This commit is contained in:
msosvi 2013-11-09 16:29:39 +00:00
commit 1027ef0ca2
3 changed files with 56 additions and 31 deletions

View file

@ -1,5 +1,14 @@
*** Pico Changelog ***
2013.10.23 - version 0.8
* [New] Added ability to set template in content meta
* [New] Added before_parse_content and after_parse_content hooks
* [Changed] content_parsed hook is now depreciated
* [Changed] Moved loading the config to nearer the beginning of the class
* [Changed] Only append ellipsis in limit_words() when word count exceeds max
* [Changed] Made private methods protected for better inheritance
* [Fixed] Fixed get_protocol() method to work in more situations
2013.09.04 - version 0.7
* [New] Added before_read_file_meta and get_page_data plugin hooks to customize page meta data
* [Changed] Make get_files() ignore dotfiles

View file

@ -7,7 +7,7 @@ use \Michelf\MarkdownExtra;
* @author Gilbert Pellegrom
* @link http://pico.dev7studios.com
* @license http://opensource.org/licenses/MIT
* @version 0.7
* @version 0.8
*/
class Pico {
@ -22,7 +22,11 @@ class Pico {
// Load plugins
$this->load_plugins();
$this->run_hooks('plugins_loaded');
// Load the settings
$settings = $this->get_config();
$this->run_hooks('config_loaded', array(&$settings));
// Get request url and script url
$url = '';
$request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : '';
@ -57,14 +61,11 @@ 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));
$meta = $this->read_file_meta($content);
$this->run_hooks('file_meta', array(&$meta));
// Get all the pages
$pages = $this->get_pages($settings['base_url'], $settings['pages_order_by'], $settings['pages_order'], $settings['excerpt_length']);
$prev_page = array();
@ -98,8 +99,10 @@ class Pico {
'is_front_page' => $url ? false : true
);
$this->run_hooks('before_parse_content', array(&$content));
$content = $this->parse_content($content, $isTwigContent, $twig_vars);
$this->run_hooks('content_parsed', array(&$content));
$this->run_hooks('after_parse_content', array(&$content));
$this->run_hooks('content_parsed', array(&$content)); // Depreciated @ v0.8
// Load the theme
@ -111,8 +114,9 @@ class Pico {
$twig_vars['content'] = $content;
$this->run_hooks('before_render', array(&$twig_vars, &$twig));
$output = $twig->render('index.html', $twig_vars);
$template = (isset($meta['template']) && $meta['template']) ? $meta['template'] : 'index';
$this->run_hooks('before_render', array(&$twig_vars, &$twig, &$template));
$output = $twig->render($template .'.html', $twig_vars);
$this->run_hooks('after_render', array(&$output));
echo $output;
}
@ -120,7 +124,7 @@ class Pico {
/**
* Load any plugins
*/
private function load_plugins()
protected function load_plugins()
{
$this->plugins = array();
$plugins = $this->get_files(PLUGINS_DIR, '.php');
@ -142,7 +146,8 @@ class Pico {
* @param string $content the raw txt content
* @return string $content the Markdown or Twig formatted content
*/
private function parse_content($content, $isTwigContent, $twig_vars = null)
protected function parse_content($content, $isTwigContent = false, $twig_vars = null)
{
$content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta
@ -165,7 +170,7 @@ class Pico {
* @param string $content the raw txt content
* @return array $headers an array of meta values
*/
private function read_file_meta($content)
protected function read_file_meta($content)
{
global $config;
@ -174,7 +179,8 @@ class Pico {
'description' => 'Description',
'author' => 'Author',
'date' => 'Date',
'robots' => 'Robots'
'robots' => 'Robots',
'template' => 'Template'
);
// Add support for custom headers by hooking into the headers array
@ -198,7 +204,7 @@ class Pico {
*
* @return array $config an array of config values
*/
private function get_config()
protected function get_config()
{
global $config;
@include_once(ROOT_DIR .'config.php');
@ -228,7 +234,7 @@ class Pico {
* @param string $order order "asc" or "desc"
* @return array $sorted_pages an array of pages
*/
private function get_pages($base_url, $order_by = 'alpha', $order = 'asc', $excerpt_length = 50)
protected function get_pages($base_url, $order_by = 'alpha', $order = 'asc', $excerpt_length = 50)
{
global $config;
@ -297,7 +303,7 @@ class Pico {
* @param string $hook_id the ID of the hook
* @param array $args optional arguments
*/
private function run_hooks($hook_id, $args = array())
protected function run_hooks($hook_id, $args = array())
{
if(!empty($this->plugins)){
foreach($this->plugins as $plugin){
@ -313,7 +319,7 @@ class Pico {
*
* @return string the base url
*/
private function base_url()
protected function base_url()
{
global $config;
if(isset($config['base_url']) && $config['base_url']) return $config['base_url'];
@ -332,10 +338,13 @@ class Pico {
*
* @return string the current protocol
*/
private function get_protocol()
protected function get_protocol()
{
preg_match("|^HTTP[S]?|is",$_SERVER['SERVER_PROTOCOL'],$m);
return strtolower($m[0]);
$protocol = 'http';
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'){
$protocol = 'https';
}
return $protocol;
}
/**
@ -345,7 +354,7 @@ class Pico {
* @param string $ext optional limit to file extensions
* @return array the matched files
*/
private function get_files($directory, $ext = '')
protected function get_files($directory, $ext = '')
{
$array_items = array();
if($handle = opendir($directory)){
@ -371,10 +380,12 @@ class Pico {
* @param int $word_limit the number of words to limit to
* @return string the limited string
*/
private function limit_words($string, $word_limit)
protected function limit_words($string, $word_limit)
{
$words = explode(' ',$string);
return trim(implode(' ', array_splice($words, 0, $word_limit))) .'...';
$excerpt = trim(implode(' ', array_splice($words, 0, $word_limit)));
if(count($words) > $word_limit) $excerpt .= '…';
return $excerpt;
}
}

View file

@ -12,6 +12,11 @@ class Pico_Plugin {
public function plugins_loaded()
{
}
public function config_loaded(&$settings)
{
}
public function request_url(&$url)
@ -39,11 +44,6 @@ class Pico_Plugin {
}
public function config_loaded(&$settings)
{
}
public function before_read_file_meta(&$headers)
{
@ -52,9 +52,14 @@ class Pico_Plugin {
public function file_meta(&$meta)
{
}
public function before_parse_content(&$content)
{
}
public function content_parsed(&$content)
public function after_parse_content(&$content)
{
}
@ -74,7 +79,7 @@ class Pico_Plugin {
}
public function before_render(&$twig_vars, &$twig)
public function before_render(&$twig_vars, &$twig, &$template)
{
}