diff --git a/.gitignore b/.gitignore index 41daada..c37b0e4 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,7 @@ themes/* !themes/default/* # User config -config.php \ No newline at end of file +config.php +*.iml +*.sublime-* +.idea diff --git a/changelog.txt b/changelog.txt index 1d944ee..133b63a 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,14 @@ *** Pico Changelog *** +2013.07.21 - version 0.7a2 + * [new] Added ability to use custom meta data + * [new] Added ability to choose custom template per page + * [changed] Removed closing php tags from files + * [changed] Now managing markdown parser via composer + * [changed] Updated Twig version + * [changed] get_files no longer gets dotfiles + * [fixed] Issues with updating Pico install once in use + 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 diff --git a/composer.json b/composer.json index 4747374..969e023 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "require": { - "twig/twig": "1.12.*", + "twig/twig": "1.*", "michelf/php-markdown": "1.3" } } diff --git a/config.php b/config.php.dist similarity index 91% rename from config.php rename to config.php.dist index 341539d..89d9483 100644 --- a/config.php +++ b/config.php.dist @@ -15,9 +15,12 @@ $config['twig_config'] = array( // Twig settings $config['pages_order_by'] = 'alpha'; // Order pages by "alpha" or "date" $config['pages_order'] = 'asc'; // Order pages "asc" or "desc" $config['excerpt_length'] = 50; // The pages excerpt length (in words) +$config['template_ext'] = '.html'; // Template file extension // To add a custom config setting: $config['custom_setting'] = 'Hello'; // Can be accessed by {{ config.custom_setting }} in a theme -*/ \ No newline at end of file +*/ + +// End of file \ No newline at end of file diff --git a/content/index.md b/content/index.md index 4642139..8edda63 100644 --- a/content/index.md +++ b/content/index.md @@ -1,6 +1,7 @@ /* Title: Welcome Description: This description will go in the meta description tag +keywords: Pico CMS */ ## Welcome to Pico @@ -43,6 +44,8 @@ At the top of text files you can place a block comment and specify certain attri Author: Joe Bloggs Date: 2013/01/01 Robots: noindex,nofollow + Keywords: keyword1, keyword2 + Foo: Bar */ These values will be contained in the `{{ meta }}` variable in themes (see below). @@ -65,13 +68,15 @@ All themes must include an `index.html` file to define the HTML structure of the * `{{ theme_dir }}` - The path to the Pico active theme direcotry * `{{ theme_url }}` - The URL to the Pico active theme direcotry * `{{ site_title }}` - Shortcut to the site title (defined in config.php) -* `{{ meta }}` - Contains the meta values from the current page +* `{{ meta }}` - Contains the meta values from the current page. Meta keys are always converted to lowercase. * `{{ meta.title }}` * `{{ meta.description }}` * `{{ meta.author }}` * `{{ meta.date }}` * `{{ meta.date_formatted }}` * `{{ meta.robots }}` + * `{{ meta.keywords }}` + * `{{ meta.foo }}` * `{{ content }}` - The content of the current page (after it has been processed through Markdown) * `{{ pages }}` - A collection of all the content in your site * `{{ page.title }}` diff --git a/index.php b/index.php index d89eed7..87c94ad 100644 --- a/index.php +++ b/index.php @@ -8,6 +8,10 @@ define('PLUGINS_DIR', ROOT_DIR .'plugins/'); define('THEMES_DIR', ROOT_DIR .'themes/'); define('CACHE_DIR', LIB_DIR .'cache/'); +date_default_timezone_set('UTC'); + require(ROOT_DIR .'vendor/autoload.php'); require(LIB_DIR .'pico.php'); $pico = new Pico(); + +// End of file \ No newline at end of file diff --git a/lib/FilePageDao.php b/lib/FilePageDao.php new file mode 100644 index 0000000..c00ffd8 --- /dev/null +++ b/lib/FilePageDao.php @@ -0,0 +1,86 @@ +pico = $pico; + } + + /** + * @inheritdoc + */ + function get_pages($base_url, $order_by = 'alpha', $order = 'asc', $meta_max_length = 2048, $excerpt_length = 50) + { + global $config; + + $pages = $this->pico->get_files(CONTENT_DIR, CONTENT_EXT); + $sorted_pages = array(); + $date_id = 0; + foreach ($pages as $key => $page) { + // Skip 404 + if (basename($page) == '404' . CONTENT_EXT) { + unset($pages[$key]); + continue; + } + + // Ignore Emacs (and Nano) temp files + if (in_array(substr($page, -1), array('~', '#'))) { + unset($pages[$key]); + continue; + } + // Get title and format $page + $page_content = file_get_contents($page, NULL, NULL, 0, $meta_max_length); + $page_meta = $this->pico->read_file_meta($page_content); + $page_content = $this->pico->parse_content($page_content); + $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'] : '', + 'url' => $url, + 'author' => isset($page_meta['author']) ? $page_meta['author'] : '', + 'date' => isset($page_meta['date']) ? $page_meta['date'] : '', + 'date_formatted' => isset($page_meta['date']) ? date($config['date_format'], strtotime($page_meta['date'])) : '', + 'content' => $page_content, + 'excerpt' => $this->limit_words(strip_tags($page_content), $excerpt_length), + 'last_modified' => new DateTime('@' . filemtime($page)) + ); + + // Extend the data provided with each page by hooking into the data array + $this->pico->run_hooks('get_page_data', array(&$data, $page_meta)); + + 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; + } + + /** + * 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); + return trim(implode(' ', array_splice($words, 0, $word_limit))) . '...'; + } + +} \ No newline at end of file diff --git a/lib/pico.php b/lib/pico.php index 259c05a..2e87af5 100644 --- a/lib/pico.php +++ b/lib/pico.php @@ -1,5 +1,21 @@ load_plugins(); + if (!isset($this->page_dao)) { + // If plugin not found - fallback to FilePageDao + @require_once(LIB_DIR . 'FilePageDao.php'); + $this->page_dao = new FilePageDao($this); + } - /** - * The constructor carries out all the processing in Pico. - * Does URL routing, Markdown processing and Twig processing. - */ - public function __construct() - { - // 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'] : ''; - $script_url = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : ''; + $this->run_hooks('plugins_loaded'); - // Get our url path and trim the / of the left and the right - if($request_url != $script_url) $url = trim(preg_replace('/'. str_replace('/', '\/', str_replace('index.php', '', $script_url)) .'/', '', $request_url, 1), '/'); - $url = preg_replace('/\?.*/', '', $url); // Strip query string - $this->run_hooks('request_url', array(&$url)); + // Get request url and script url + $url = ''; + $request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : ''; + $script_url = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : ''; - // Get the file path - if($url) $file = CONTENT_DIR . $url; - else $file = CONTENT_DIR .'index'; + // Get our url path and trim the / of the left and the right + if ($request_url != $script_url) $url = trim(preg_replace('/' . str_replace('/', '\/', str_replace('index.php', '', $script_url)) . '/', '', $request_url, 1), '/'); + $url = preg_replace('/\?.*/', '', $url); // Strip query string + $this->run_hooks('request_url', array(&$url)); - // Load the file - if(is_dir($file)) $file = CONTENT_DIR . $url .'/index'. CONTENT_EXT; - else $file .= CONTENT_EXT; + // Get the file path + if ($url) $file = CONTENT_DIR . $url; + else $file = CONTENT_DIR . 'index'; - $this->run_hooks('before_load_content', array(&$file)); - if(file_exists($file)){ - $content = file_get_contents($file); - } else { - $this->run_hooks('before_404_load_content', array(&$file)); - $content = file_get_contents(CONTENT_DIR .'404'. CONTENT_EXT); - header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found'); - $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)); + // Load the file + if (is_dir($file)) $file = CONTENT_DIR . $url . '/index' . CONTENT_EXT; + else $file .= CONTENT_EXT; - $meta = $this->read_file_meta($content); - $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(); - $current_page = array(); - $next_page = array(); - while($current_page = current($pages)){ - if((isset($meta['title'])) && ($meta['title'] == $current_page['title'])){ - break; - } - next($pages); - } - $prev_page = next($pages); - prev($pages); - $next_page = prev($pages); - $this->run_hooks('get_pages', array(&$pages, &$current_page, &$prev_page, &$next_page)); + $this->run_hooks('before_load_content', array(&$file)); + if (file_exists($file)) { + $content = file_get_contents($file); + } else { + $this->run_hooks('before_404_load_content', array(&$file)); + $content = file_get_contents(CONTENT_DIR . '404' . CONTENT_EXT); + header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found'); + $this->run_hooks('after_404_load_content', array(&$file, &$content)); + } + $this->run_hooks('after_load_content', array(&$file, &$content)); - // Load the theme - $this->run_hooks('before_twig_register'); - Twig_Autoloader::register(); - $loader = new Twig_Loader_Filesystem(THEMES_DIR . $settings['theme']); - $twig = new Twig_Environment($loader, $settings['twig_config']); - $twig->addExtension(new Twig_Extension_Debug()); - $twig_vars = array( - 'config' => $settings, - 'base_dir' => rtrim(ROOT_DIR, '/'), - 'base_url' => $settings['base_url'], - 'theme_dir' => THEMES_DIR . $settings['theme'], - 'theme_url' => $settings['base_url'] .'/'. basename(THEMES_DIR) .'/'. $settings['theme'], - 'site_title' => $settings['site_title'], - 'meta' => $meta, - 'content' => $content, - 'pages' => $pages, - 'prev_page' => $prev_page, - 'current_page' => $current_page, - '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); - $this->run_hooks('after_render', array(&$output)); - echo $output; - } - - /** - * Load any plugins - */ - private function load_plugins() - { - $this->plugins = array(); - $plugins = $this->get_files(PLUGINS_DIR, '.php'); - if(!empty($plugins)){ - foreach($plugins as $plugin){ - include_once($plugin); - $plugin_name = preg_replace("/\\.[^.\\s]{3}$/", '', basename($plugin)); - if(class_exists($plugin_name)){ - $obj = new $plugin_name; - $this->plugins[] = $obj; - } - } - } - } + // Load the settings + $settings = $this->get_config(); + $this->run_hooks('config_loaded', array(&$settings)); - /** - * Parses the content using Markdown - * - * @param string $content the raw txt content - * @return string $content the Markdown formatted content - */ - private function parse_content($content) - { - $content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta - $content = str_replace('%base_url%', $this->base_url(), $content); - $content = MarkdownExtra::defaultTransform($content); + $meta = $this->read_file_meta($content); + $this->run_hooks('file_meta', array(&$meta)); + $content = $this->parse_content($content); + $this->run_hooks('content_parsed', array(&$content)); - return $content; - } + // Get all the pages + $pages = $this->page_dao->get_pages( + $settings['base_url'], + $settings['pages_order_by'], + $settings['pages_order'], + $settings['excerpt_length']); + $prev_page = array(); + $current_page = array(); + $next_page = array(); + while ($current_page = current($pages)) { + if ((isset($meta['title'])) && ($meta['title'] == $current_page['title'])) { + break; + } + next($pages); + } + $prev_page = next($pages); + prev($pages); + $next_page = prev($pages); + $this->run_hooks('get_pages', array(&$pages, &$current_page, &$prev_page, &$next_page)); - /** - * Parses the file meta from the txt file header - * - * @param string $content the raw txt content - * @return array $headers an array of meta values - */ - private function read_file_meta($content) - { - global $config; - - $headers = array( - 'title' => 'Title', - 'description' => 'Description', - 'author' => 'Author', - 'date' => 'Date', - 'robots' => 'Robots' - ); + // Load the theme + $this->run_hooks('before_twig_register'); + Twig_Autoloader::register(); + $loader = new Twig_Loader_Filesystem(THEMES_DIR . $settings['theme']); + $twig = new Twig_Environment($loader, $settings['twig_config']); + $twig->addExtension(new Twig_Extension_Debug()); + $twig_vars = array( + 'config' => $settings, + 'base_dir' => rtrim(ROOT_DIR, '/'), + 'base_url' => $settings['base_url'], + 'theme_dir' => THEMES_DIR . $settings['theme'], + 'theme_url' => $settings['base_url'] . '/' . basename(THEMES_DIR) . '/' . $settings['theme'], + 'site_title' => $settings['site_title'], + 'meta' => $meta, + 'content' => $content, + 'pages' => $pages, + 'prev_page' => $prev_page, + 'current_page' => $current_page, + 'next_page' => $next_page, + 'is_front_page' => $url ? false : true, + ); + // use a custom template if specified Template: [filename] in page meta e.g. Template: spesh to try and use spesh.html in theme folder + $template = ((isset($meta['template']) && file_exists($twig_vars['theme_dir'] . '/' . $meta['template'] . $settings['template_ext'])) ? $meta['template'] . $settings['template_ext'] : 'index' . $settings['template_ext']); - // Add support for custom headers by hooking into the headers array - $this->run_hooks('before_read_file_meta', array(&$headers)); + $this->run_hooks('before_render', array(&$twig_vars, &$twig)); + $output = $twig->render($template, $twig_vars); + $this->run_hooks('after_render', array(&$output)); + echo $output; + } - foreach ($headers as $field => $regex){ - if (preg_match('/^[ \t\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $content, $match) && $match[1]){ - $headers[ $field ] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1])); - } else { - $headers[ $field ] = ''; - } - } - - if(isset($headers['date'])) $headers['date_formatted'] = date($config['date_format'], strtotime($headers['date'])); + /** + * Load any plugins + */ + private function load_plugins() + { + $this->plugins = array(); + $plugins = $this->get_files(PLUGINS_DIR, '.php'); + if (!empty($plugins)) { + foreach ($plugins as $plugin) { + include_once($plugin); + $plugin_name = preg_replace("/\\.[^.\\s]{3}$/", '', basename($plugin)); + if (class_exists($plugin_name)) { + $obj = new $plugin_name; + $this->plugins[] = $obj; - return $headers; - } + if ($obj instanceof PageDao) { + $this->page_dao = $obj; + } + } + } + } + } - /** - * Loads the config - * - * @return array $config an array of config values - */ - private function get_config() - { - global $config; - @include_once(ROOT_DIR .'config.php'); + /** + * 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 + */ + static function get_files($directory, $ext = '') + { + $array_items = array(); + if ($handle = opendir($directory)) { + while (false !== ($file = readdir($handle))) { + if (preg_match("/^(^\.)/", $file) === 0) { + if (is_dir($directory . "/" . $file)) { + $array_items = array_merge($array_items, self::get_files($directory . "/" . $file, $ext)); + } else { + $file = $directory . "/" . $file; + if (!$ext || strstr($file, $ext)) $array_items[] = preg_replace("/\/\//si", "/", $file); + } + } + } + closedir($handle); + } + return $array_items; + } - $defaults = array( - 'site_title' => 'Pico', - 'base_url' => $this->base_url(), - 'theme' => 'default', - 'date_format' => 'jS M Y', - 'twig_config' => array('cache' => false, 'autoescape' => false, 'debug' => false), - 'pages_order_by' => 'alpha', - 'pages_order' => 'asc', - 'excerpt_length' => 50 - ); + /** + * Processes any hooks and runs them + * + * @param string $hook_id the ID of the hook + * @param array $args optional arguments + */ + function run_hooks($hook_id, $args = array()) + { + if (!empty($this->plugins)) { + foreach ($this->plugins as $plugin) { + if (is_callable(array($plugin, $hook_id))) { + call_user_func_array(array($plugin, $hook_id), $args); + } + } + } + } - if(is_array($config)) $config = array_merge($defaults, $config); - else $config = $defaults; + /** + * Loads the config + * + * @return array $config an array of config values + */ + private function get_config() + { + global $config; + @include_once(ROOT_DIR . 'config.php'); - return $config; - } - - /** - * Get a list of pages - * - * @param string $base_url the base URL of the site - * @param string $order_by order by "alpha" or "date" - * @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) - { - global $config; - - $pages = $this->get_files(CONTENT_DIR, CONTENT_EXT); - $sorted_pages = array(); - $date_id = 0; - foreach($pages as $key=>$page){ - // Skip 404 - if(basename($page) == '404'. CONTENT_EXT){ - unset($pages[$key]); - continue; - } + $defaults = array( + 'site_title' => 'Pico', + 'base_url' => $this->base_url(), + 'theme' => 'default', + 'date_format' => 'jS M Y', + 'twig_config' => array('cache' => false, 'autoescape' => false, 'debug' => false), + 'pages_order_by' => 'alpha', + 'pages_order' => 'asc', + 'excerpt_length' => 50, + 'template_ext' => '.html' + ); - // Ignore Emacs (and Nano) temp files - 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); - $page_content = $this->parse_content($page_content); - $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'] : '', - 'url' => $url, - 'author' => isset($page_meta['author']) ? $page_meta['author'] : '', - 'date' => isset($page_meta['date']) ? $page_meta['date'] : '', - 'date_formatted' => isset($page_meta['date']) ? date($config['date_format'], strtotime($page_meta['date'])) : '', - 'content' => $page_content, - 'excerpt' => $this->limit_words(strip_tags($page_content), $excerpt_length) - ); + if (is_array($config)) $config = array_merge($defaults, $config); + else $config = $defaults; - // Extend the data provided with each page by hooking into the data array - $this->run_hooks('get_page_data', array(&$data, $page_meta)); + return $config; + } - 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 - * - * @param string $hook_id the ID of the hook - * @param array $args optional arguments - */ - private function run_hooks($hook_id, $args = array()) - { - if(!empty($this->plugins)){ - foreach($this->plugins as $plugin){ - if(is_callable(array($plugin, $hook_id))){ - call_user_func_array(array($plugin, $hook_id), $args); - } - } - } - } + /** + * Helper function to work out the base URL + * + * @return string the base url + */ + private function base_url() + { + global $config; + if (isset($config['base_url']) && $config['base_url']) return $config['base_url']; - /** - * Helper function to work out the base URL - * - * @return string the base url - */ - private function base_url() - { - global $config; - if(isset($config['base_url']) && $config['base_url']) return $config['base_url']; + $url = ''; + $request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : ''; + $script_url = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : ''; + if ($request_url != $script_url) $url = trim(preg_replace('/' . str_replace('/', '\/', str_replace('index.php', '', $script_url)) . '/', '', $request_url, 1), '/'); - $url = ''; - $request_url = (isset($_SERVER['REQUEST_URI'])) ? $_SERVER['REQUEST_URI'] : ''; - $script_url = (isset($_SERVER['PHP_SELF'])) ? $_SERVER['PHP_SELF'] : ''; - if($request_url != $script_url) $url = trim(preg_replace('/'. str_replace('/', '\/', str_replace('index.php', '', $script_url)) .'/', '', $request_url, 1), '/'); + $protocol = $this->get_protocol(); + return rtrim(str_replace($url, '', $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), '/'); + } - $protocol = $this->get_protocol(); - return rtrim(str_replace($url, '', $protocol . "://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']), '/'); - } + /** + * Tries to guess the server protocol. Used in base_url() + * + * @return string the current protocol + */ + private function get_protocol() + { + preg_match("|^HTTP[S]?|is", $_SERVER['SERVER_PROTOCOL'], $m); + return strtolower($m[0]); + } - /** - * Tries to guess the server protocol. Used in base_url() - * - * @return string the current protocol - */ - private function get_protocol() - { - 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(); - if($handle = opendir($directory)){ - while(false !== ($file = readdir($handle))){ - if(preg_match("/^(^\.)/", $file) === 0){ - if(is_dir($directory. "/" . $file)){ - $array_items = array_merge($array_items, $this->get_files($directory. "/" . $file, $ext)); - } else { - $file = $directory . "/" . $file; - if(!$ext || strstr($file, $ext)) $array_items[] = preg_replace("/\/\//si", "/", $file); - } - } - } - closedir($handle); - } - 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); - return trim(implode(' ', array_splice($words, 0, $word_limit))) .'...'; - } + /** + * Parses the file meta from the txt file header. + * Meta keys are converted to lowercase automatically. + * + * @param string $content the raw txt content + * @return array $headers an array of meta values + */ + function read_file_meta($content) + { + global $config; + $headers = array( + 'title' => 'Title', + 'description' => 'Description', + 'author' => 'Author', + 'date' => 'Date', + 'robots' => 'Robots' + ); + + // Add support for custom headers by hooking into the headers array + $this->run_hooks('before_read_file_meta', array(&$headers)); + + foreach ($headers as $field => $regex) { + if (preg_match('/^[ \t\/*#@]*' . preg_quote($regex, '/') . ':(.*)$/mi', $content, $match) && $match[1]) { + $headers[$field] = trim(preg_replace("/\s*(?:\*\/|\?>).*/", '', $match[1])); + } else { + $headers[$field] = ''; + } + } + + if (isset($headers['date'])) $headers['date_formatted'] = date($config['date_format'], strtotime($headers['date'])); + + return $headers; + } + + /** + * Parses the content using Markdown + * + * @param string $content the raw txt content + * @return string $content the Markdown formatted content + */ + function parse_content(&$content) + { + $content = preg_replace('#/\*.+?\*/#s', '', $content); // Remove comments and meta + $content = str_replace('%base_url%', $this->base_url(), $content); + $content = MarkdownExtra::defaultTransform($content); + + return $content; + } } + diff --git a/plugins/pico_plugin.php b/plugins/pico_plugin.php index a50ea05..7fe6d28 100644 --- a/plugins/pico_plugin.php +++ b/plugins/pico_plugin.php @@ -86,4 +86,4 @@ class Pico_Plugin { } -?> \ No newline at end of file +// End of file diff --git a/themes/default/index.html b/themes/default/index.html index 37cd9ba..ef4e60b 100644 --- a/themes/default/index.html +++ b/themes/default/index.html @@ -9,14 +9,15 @@ {% endif %}{% if meta.robots %} {% endif %} - +{% if meta.keywords %} + +{% endif %} -