|
@@ -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 {
|
|
|
|
|
@@ -19,15 +19,14 @@ class Pico {
|
|
|
*/
|
|
|
public function __construct()
|
|
|
{
|
|
|
+ // Load plugins
|
|
|
+ $this->load_plugins();
|
|
|
+ $this->run_hooks('plugins_loaded');
|
|
|
+
|
|
|
// Load the settings
|
|
|
$settings = $this->get_config();
|
|
|
$this->run_hooks('config_loaded', array(&$settings));
|
|
|
- global $config;
|
|
|
|
|
|
- // 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'] : '';
|
|
@@ -62,8 +61,11 @@ class Pico {
|
|
|
|
|
|
$meta = $this->read_file_meta($content);
|
|
|
$this->run_hooks('file_meta', array(&$meta));
|
|
|
+
|
|
|
+ $this->run_hooks('before_parse_content', array(&$content));
|
|
|
$content = $this->parse_content($content,$file);
|
|
|
- $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
|
|
|
|
|
|
// Get all the pages
|
|
|
$pages = $this->get_pages($settings['base_url'], $settings['pages_order_by'], $settings['pages_order'], $settings['excerpt_length']);
|
|
@@ -102,8 +104,10 @@ class Pico {
|
|
|
'next_page' => $next_page,
|
|
|
'is_front_page' => $url ? false : true,
|
|
|
);
|
|
|
- $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;
|
|
|
}
|
|
@@ -111,7 +115,7 @@ class Pico {
|
|
|
/**
|
|
|
* Load any plugins
|
|
|
*/
|
|
|
- private function load_plugins()
|
|
|
+ protected function load_plugins()
|
|
|
{
|
|
|
$this->plugins = array();
|
|
|
$plugins = $this->get_files(PLUGINS_DIR, '.php');
|
|
@@ -133,7 +137,7 @@ class Pico {
|
|
|
* @param string $content the raw txt content
|
|
|
* @return string $content the Markdown formatted content
|
|
|
*/
|
|
|
- private function parse_content($content,$page)
|
|
|
+ protected function parse_content($content,$page)
|
|
|
{
|
|
|
$content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta
|
|
|
$content = str_replace('%base_url%', $this->base_url(), $content);
|
|
@@ -149,7 +153,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;
|
|
|
|
|
@@ -158,7 +162,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
|
|
@@ -182,7 +187,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');
|
|
@@ -213,7 +218,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;
|
|
|
|
|
@@ -273,7 +278,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){
|
|
@@ -289,7 +294,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'];
|
|
@@ -308,10 +313,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;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -321,7 +329,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)){
|
|
@@ -347,10 +355,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;
|
|
|
}
|
|
|
|
|
|
}
|