From 0b94ad6d1efb9c942e26da76acbb931d8f11d160 Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 5 Mar 2018 00:22:55 +0300 Subject: [PATCH] #431 general structure changes --- composer.json | 24 +- index.php | 16 +- monstra/Action.php | 113 --------- monstra/Blocks.php | 102 -------- monstra/Cache.php | 3 +- monstra/Config.php | 71 ++---- monstra/Filter.php | 22 +- monstra/Markdown.php | 39 --- monstra/Monstra.php | 111 +++++---- monstra/MonstraTrait.php | 31 +++ monstra/Page.php | 124 ++++++++++ monstra/Pages.php | 297 ++--------------------- monstra/{boot/filters.php => Plugin.php} | 20 +- monstra/Plugins.php | 101 ++------ monstra/Theme.php | 9 - monstra/Themes.php | 44 ++++ monstra/Yaml.php | 59 ----- monstra/boot/actions.php | 15 -- monstra/boot/shortcodes.php | 22 -- 19 files changed, 390 insertions(+), 833 deletions(-) delete mode 100755 monstra/Action.php delete mode 100755 monstra/Blocks.php delete mode 100755 monstra/Markdown.php create mode 100755 monstra/MonstraTrait.php create mode 100755 monstra/Page.php rename monstra/{boot/filters.php => Plugin.php} (52%) delete mode 100755 monstra/Theme.php create mode 100644 monstra/Themes.php delete mode 100755 monstra/Yaml.php delete mode 100755 monstra/boot/actions.php delete mode 100755 monstra/boot/shortcodes.php diff --git a/composer.json b/composer.json index ef56d0d..1eaa000 100755 --- a/composer.json +++ b/composer.json @@ -16,16 +16,21 @@ "issues": "https://github.com/monstra-cms/monstra/issues" }, "require": { - "php": ">=5.5.9", - "erusev/parsedown-extra": "0.7.*", - "mustangostang/spyc" : "0.5.*", - "doctrine/cache": "1.6.*", - "doctrine/collections": "1.3", + "php": ">=7.1.3", + "erusev/parsedown": "1.7.0", + "erusev/parsedown-extra": "0.7.1", + "doctrine/cache": "1.7.1", + "symfony/yaml": "4.0.4", + "symfony/console": "4.0.4", + "symfony/filesystem": "4.0.4", + "symfony/finder": "4.0.4", + "symfony/event-dispatcher": "4.0.5", + "pimple/pimple": "3.2.3", "force/session" : "*", - "force/filesystem" : "*", + "force/shortcode" : "*", "force/arr" : "*", "force/http" : "*", - "force/shortcode" : "*", + "force/filesystem" : "*", "force/token" : "*", "force/url" : "*" }, @@ -34,10 +39,7 @@ "Monstra" ], "files": [ - "Monstra/boot/defines.php", - "Monstra/boot/shortcodes.php", - "Monstra/boot/filters.php", - "Monstra/boot/actions.php" + "monstra/boot/defines.php" ] } } diff --git a/index.php b/index.php index 02b97c3..7b4df47 100755 --- a/index.php +++ b/index.php @@ -1,10 +1,14 @@ PHP %s to run.', $ver, $req)); + +// Get Monstra Instance +$app = Monstra::instance(); + +// Run Monstra Application +$app->run(); diff --git a/monstra/Action.php b/monstra/Action.php deleted file mode 100755 index 6b7ac38..0000000 --- a/monstra/Action.php +++ /dev/null @@ -1,113 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -class Action -{ - /** - * Actions - * - * @var array - * @access protected - */ - protected static $actions = []; - - /** - * Protected constructor since this is a static class. - * - * @access protected - */ - protected function __construct() - { - // Nothing here - } - - /** - * Hooks a function on to a specific action. - * - * - * // Hooks a function "newLink" on to a "footer" action. - * Action::add('footer', 'newLink', 10); - * - * function newLink() { - * echo 'My link'; - * } - * - * - * @access public - * @param string $action_name Action name - * @param mixed $added_function Added function - * @param integer $priority Priority. Default is 10 - * @param array $args Arguments - */ - public static function add($action_name, $added_function, $priority = 10, array $args = null) - { - // Hooks a function on to a specific action. - static::$actions[] = array( - 'action_name' => (string) $action_name, - 'function' => $added_function, - 'priority' => (int) $priority, - 'args' => $args - ); - } - - /** - * Run functions hooked on a specific action hook. - * - * - * // Run functions hooked on a "footer" action hook. - * Action::run('footer'); - * - * - * @access public - * @param string $action_name Action name - * @param array $args Arguments - * @param boolean $return Return data or not. Default is false - * @return mixed - */ - public static function run($action_name, $args = [], $return = false) - { - // Redefine arguments - $action_name = (string) $action_name; - $return = (bool) $return; - - // Run action - if (count(static::$actions) > 0) { - - // Sort actions by priority - $actions = Arr::subvalSort(static::$actions, 'priority'); - - // Loop through $actions array - foreach ($actions as $action) { - - // Execute specific action - if ($action['action_name'] == $action_name) { - - // isset arguments ? - if (isset($args)) { - - // Return or Render specific action results ? - if ($return) { - return call_user_func_array($action['function'], $args); - } else { - call_user_func_array($action['function'], $args); - } - } else { - if ($return) { - return call_user_func_array($action['function'], $action['args']); - } else { - call_user_func_array($action['function'], $action['args']); - } - } - } - } - } - } -} diff --git a/monstra/Blocks.php b/monstra/Blocks.php deleted file mode 100755 index 783d49d..0000000 --- a/monstra/Blocks.php +++ /dev/null @@ -1,102 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -class Blocks -{ - /** - * An instance of the Blocks class - * - * @var object - * @access protected - */ - protected static $instance = null; - - /** - * Protected clone method to enforce singleton behavior. - * - * @access protected - */ - protected function __clone() - { - // Nothing here. - } - - /** - * Constructor. - * - * @access protected - */ - protected function __construct() - { - $blocks_cache_id = ''; - - $blocks = File::scan(CONTENT_PATH . '/blocks', 'md'); - - if ($blocks) { - foreach ($blocks as $block) { - $blocks_cache_id .= filemtime($block); - } - - // Create Unique Cache ID for Block - $blocks_cache_id = md5('blocks' . ROOT_DIR . $blocks_cache_id); - } - - if (Cache::driver()->contains($blocks_cache_id)) { - Cache::driver()->fetch($blocks_cache_id); - } else { - Config::set('site.pages.flush_cache', true); - Cache::driver()->save($blocks_cache_id, $blocks_cache_id); - } - } - - /** - * Get Page Block - * - * - * $block = Blocks::get('my-block'); - * - * - * @access public - * @param string $name Block name - * @return string Formatted Block content - */ - public static function get($name) - { - if (File::exists($block_path = CONTENT_PATH .'/blocks/' . $name . '.md')) { - - // Create Unique Cache ID for Block - $block_cache_id = md5('block' . ROOT_DIR . $block_path . filemtime($block_path)); - - if (Cache::driver()->contains($block_cache_id)) { - return Cache::driver()->fetch($block_cache_id); - } else { - Cache::driver()->save($block_cache_id, $block = Filter::apply('content', file_get_contents($block_path))); - return $block; - } - } else { - return 'Block '.$name.' is not found!'; - } - } - - /** - * Initialize Monstra Blocks - * - * - * Blocks::init(); - * - * - * @access public - */ - public static function init() - { - return !isset(self::$instance) and self::$instance = new Blocks(); - } -} diff --git a/monstra/Cache.php b/monstra/Cache.php index 964d76f..3a6a5ac 100755 --- a/monstra/Cache.php +++ b/monstra/Cache.php @@ -67,7 +67,7 @@ class Cache static::$now = time(); // Cache key allows us to invalidate all cache on configuration changes. - static::$key = (Config::get('site.cache.prefix') ? Config::get('site.cache.prefix') : 'Monstra') . '-' . md5(ROOT_DIR . Monstra::VERSION); + static::$key = (Config::get('site.cache.prefix') ? Config::get('site.cache.prefix') : 'monstra') . '-' . md5(ROOT_DIR . Monstra::VERSION); // Get Cache Driver static::$driver = static::getCacheDriver(); @@ -196,6 +196,7 @@ class Cache public static function clear() { Dir::delete(CACHE_PATH . '/doctrine/'); + Dir::delete(CACHE_PATH . '/fenom/'); } /** diff --git a/monstra/Config.php b/monstra/Config.php index 8b1fc43..e8bae7f 100755 --- a/monstra/Config.php +++ b/monstra/Config.php @@ -1,4 +1,8 @@ monstra = $c; + + if ($this->monstra['filesystem']->exists($site_config = CONFIG_PATH . '/' . 'site.yml')) { + self::$config['site'] = Yaml::parse(file_get_contents($site_config)); + } else { + throw new RuntimeException("Monstra site config file does not exist."); + } } /** * Set new or update existing config variable * - * - * Config::set('site.title', 'value'); - * - * * @access public * @param string $key Key * @param mixed $value Value */ - public static function set($key, $value) + public function set($key, $value) { - Arr::set(static::$config, $key, $value); + Arr::set(self::$config, $key, $value); } /** * Get config variable * - * - * Config::get('site'); - * Config::get('site.title'); - * Config::get('site.title', 'Default title'); - * - * * @access public * @param string $key Key * @param mixed $default Default value * @return mixed */ - public static function get($key, $default = null) + public function get($key, $default = null) { - return Arr::get(static::$config, $key, $default); + return Arr::get(self::$config, $key, $default); } /** * Get config array * - * - * $config = Config::getConfig(); - * - * * @access public * @return array */ - public static function getConfig() + public function getConfig() { - return static::$config; - } - - /** - * Initialize Monstra Config - * - * - * Config::init(); - * - * - * @access public - */ - public static function init() - { - return !isset(self::$instance) and self::$instance = new Config(); + return self::$config; } } diff --git a/monstra/Filter.php b/monstra/Filter.php index 1222bb8..7d4da98 100755 --- a/monstra/Filter.php +++ b/monstra/Filter.php @@ -1,4 +1,5 @@ monstra = $c; } /** @@ -41,7 +47,7 @@ class Filter * @param mixed $value The value on which the filters hooked. * @return mixed */ - public static function apply($filter_name, $value) + public function dispatch($filter_name, $value) { // Redefine arguments $filter_name = (string) $filter_name; @@ -93,7 +99,7 @@ class Filter * @param integer $accepted_args The number of arguments the function accept default is 1. * @return boolean */ - public static function add($filter_name, $function_to_add, $priority = 10, $accepted_args = 1) + public function addListener($filter_name, $function_to_add, $priority = 10, $accepted_args = 1) { // Redefine arguments $filter_name = (string) $filter_name; @@ -101,6 +107,8 @@ class Filter $priority = (int) $priority; $accepted_args = (int) $accepted_args; + //die($function_to_add); + // Check that we don't already have the same filter at the same priority. Thanks to WP :) if (isset(static::$filters[$filter_name]["$priority"])) { foreach (static::$filters[$filter_name]["$priority"] as $filter) { diff --git a/monstra/Markdown.php b/monstra/Markdown.php deleted file mode 100755 index 76fe918..0000000 --- a/monstra/Markdown.php +++ /dev/null @@ -1,39 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -class Markdown -{ - /** - * Parsedown Extra Object - * - * @var object - * @access protected - */ - protected static $markdown; - - /** - * Markdown parser - * - * - * $content = Markdown::parse($content); - * - * - * @access public - * @param string $content Content to parse - * @return string Formatted content - */ - public static function parse($content) - { - !static::$markdown and static::$markdown = new ParsedownExtra(); - - return static::$markdown->text($content); - } -} diff --git a/monstra/Monstra.php b/monstra/Monstra.php index 5daf943..71b153c 100755 --- a/monstra/Monstra.php +++ b/monstra/Monstra.php @@ -1,6 +1,14 @@ init(); + + $container['pages'] = function ($c) { + return new Pages($c); + }; + + + $container['themes'] = function ($c) { + return new Themes($c); + }; + + return $container; } /** - * Constructor. - * - * @access protected + * Run Monstra Application */ - protected function __construct() + public function run() { - // Init Config - Config::init(); - // Turn on output buffering ob_start(); // Display Errors - Config::get('site.errors.display') and error_reporting(-1); + $this['config']->get('site.errors.display') and error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_USER_DEPRECATED); // Set internal encoding function_exists('mb_language') and mb_language('uni'); - function_exists('mb_regex_encoding') and mb_regex_encoding(Config::get('site.charset')); - function_exists('mb_internal_encoding') and mb_internal_encoding(Config::get('site.charset')); + function_exists('mb_regex_encoding') and mb_regex_encoding($this['config']->get('site.charset')); + function_exists('mb_internal_encoding') and mb_internal_encoding($this['config']->get('site.charset')); // Set default timezone - date_default_timezone_set(Config::get('site.timezone')); + date_default_timezone_set($this['config']->get('site.timezone')); - // Start the session - Session::start(); - - // Init Cache - Cache::init(); - - // Init Plugins - Plugins::init(); - - // Init Blocks - Blocks::init(); - - // Init Pages - Pages::init(); + $this['themes']->renderTemplate($this['pages']->getPage(\Url::getUriString())); // Flush (send) the output buffer and turn off output buffering ob_end_flush(); } /** - * Initialize Monstra Application - * - * - * Monstra::init(); - * + * Get Monstra Application Instance * * @access public * @return object */ - public static function init() + public static function instance() { - return !isset(self::$instance) and self::$instance = new Monstra(); + if (!self::$instance) { + self::$instance = static::init(); + MonstraTrait::setMonstra(self::$instance); + } + return self::$instance; } } diff --git a/monstra/MonstraTrait.php b/monstra/MonstraTrait.php new file mode 100755 index 0000000..1c36666 --- /dev/null +++ b/monstra/MonstraTrait.php @@ -0,0 +1,31 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +class Page +{ + /** + * @var Monstra + */ + protected $monstra; + + /** + * __construct + */ + public function __construct(Monstra $c) + { + $this->monstra = $c; + } + + /** + * Get page + */ + public function getPage($url = '', $raw = false, $url_abs = false) + { + $file = $this->finder($url, $url_abs); + + if ($raw) { + $page = trim(file_get_contents($file)); + } else { + $page = $this->parse($file); + + $page_frontmatter = $page['frontmatter']; + $page_content = $page['content']; + + $page = $page_frontmatter; + + // Parse page for summary + if (($pos = strpos($page_content, "")) === false) { + $page_content = $this->monstra['filters']->dispatch('content', $page_content); + } else { + $page_content = explode("", $page_content); + $page['summary'] = $this->monstra['filters']->dispatch('content', $page_content[0]); + $page['content'] = $this->monstra['filters']->dispatch('content', $page_content[0].$page_content[1]); + } + + if (is_array($page_content)) { + $page['summary'] = $page['summary']; + $page['content'] = $page['content']; + } else { + $page['content'] = $page_content; + } + } + + return $page; + } + + /** + * Page finder + */ + public function finder($url = '', $url_abs = false) + { + + // If url is empty that its a homepage + if ($url_abs) { + if ($url) { + $file = $url; + } else { + $file = CONTENT_PATH . '/pages/' . $this->monstra['config']->get('site.pages.main') . '/' . 'index.md'; + } + } else { + if ($url) { + $file = CONTENT_PATH . '/pages/' . $url . '/index.md'; + } else { + $file = CONTENT_PATH . '/pages/' . $this->monstra['config']->get('site.pages.main') . '/' . 'index.md'; + } + } + + // Get 404 page if file not exists + if ($this->monstra['filesystem']->exists($file)) { + $file = $file; + } else { + $file = CONTENT_PATH . '/pages/404/index.md'; + Response::status(404); + } + + return $file; + } + + /** + * Page parser + */ + public function parse($file) + { + $page = trim(file_get_contents($file)); + + $page = explode('---', $page, 3); + + $frontmatter = Yaml::parse($page[1]); + $content = $page[2]; + + $url = str_replace(CONTENT_PATH . '/pages', Url::getBase(), $file); + $url = str_replace('index.md', '', $url); + $url = str_replace('.md', '', $url); + $url = str_replace('\\', '/', $url); + $url = rtrim($url, '/'); + + $frontmatter['url'] = $url; + $frontmatter['slug'] = basename($file, '.md'); + + return ['frontmatter' => $frontmatter, 'content' => $content]; + } +} diff --git a/monstra/Pages.php b/monstra/Pages.php index 3707120..45da85f 100755 --- a/monstra/Pages.php +++ b/monstra/Pages.php @@ -1,4 +1,7 @@ monstra = $c; } /** - * Constructor. - * - * @access protected + * getPage */ - protected function __construct() + public function getPages($url = '', $raw = false, $order_by = 'date', $order_type = 'DESC', $ignore = ['404', 'index'], $limit = null) { - // Get Current Page - static::$current_page = static::getPage(Url::getUriString()); + // Get pages list for current $url + $pages_list = $this->monstra['finder']->files()->name('*.md')->in(CONTENT_PATH . '/pages/' . $url); - // Get Theme Templates - static::$current_template = ((!empty(static::$current_page['template'])) ? static::$current_page['template'] : 'index'); - - // Send default header - header('Content-Type: text/html; charset='.Config::get('site.charset')); - - // Run actions before page rendered - Action::run('before_page_rendered'); - - // Display page for current requested url - static::display(static::$current_page); - - // Run actions after page rendered - Action::run('after_page_rendered'); - } - - /** - * Get pages - * - * - * $pages = Pages::getPages('blog'); - * - * - * @access public - * @param string $url Url - * @param string $order_by Order by - * @param string $order_type Order type - * @param array $ignore Pages to ignore - * @param int $limit Limit of pages - * @return array - */ - public static function getPages($url = '', $order_by = 'date', $order_type = 'DESC', $ignore = array('404'), $limit = null) - { - $pages = File::scan(CONTENT_PATH . '/pages/' . $url, 'md'); - - if ($pages) { - foreach ($pages as $page) { - $pages_cache_id .= filemtime($page); - } - - // Create Unique Cache ID for Pages - $pages_cache_id = md5('pages' . ROOT_DIR . $url . $order_by . $order_type . implode(",", $ignore) . (($limit === null) ? 'null' : $limit) . $pages_cache_id); + // Go trough pages list + foreach ($pages_list as $key => $page) { + $pages[$key] = $this->getPage($page->getPathname(), $raw, true); } - if (Cache::driver()->contains($pages_cache_id)) { - return Cache::driver()->fetch($pages_cache_id); - } else { - foreach ($pages as $key => $page) { - if (!in_array(basename($page, '.md'), $ignore)) { - $content = file_get_contents($page); - - $_page = explode('---', $content, 3); - - $_pages[$key] = Yaml::parse($_page[1]); - - $url = str_replace(CONTENT_PATH . '/pages', Url::getBase(), $page); - $url = str_replace('index.md', '', $url); - $url = str_replace('.md', '', $url); - $url = str_replace('\\', '/', $url); - $url = rtrim($url, '/'); - $_pages[$key]['url'] = $url; - - $_content = $_page[2]; - - // Parse page for summary - if (($pos = strpos($_content, "")) === false) { - $_content = Filter::apply('content', $_content); - } else { - $_content = explode("", $_content); - $_content['summary'] = Filter::apply('content', $_content[0]); - $_content['content'] = Filter::apply('content', $_content[0].$_content[1]); - } - - if (is_array($_content)) { - $_pages[$key]['summary'] = $_content['summary']; - $_pages[$key]['content'] = $_content['content']; - } else { - $_pages[$key]['summary'] = $_content; - $_pages[$key]['content'] = $_content; - } - - $_pages[$key]['slug'] = basename($page, '.md'); - } - } - - $_pages = Arr::subvalSort($_pages, $order_by, $order_type); + // Sort and Slice pages if !$raw + if (!$raw) { + $pages = Arr::subvalSort($pages, $order_by, $order_type); if ($limit != null) { - $_pages = array_slice($_pages, null, $limit); + $pages = array_slice($_pages, null, $limit); } - - Cache::driver()->save($pages_cache_id, $_pages); - return $_pages; - } - } - - /** - * Get page - * - * - * $page = Pages::getPage('downloads'); - * - * - * @access public - * @param string $url Url - * @return array - */ - public static function getPage($url) - { - - // If url is empty then its a homepage - if ($url) { - $file = CONTENT_PATH . '/pages/' . $url; - } else { - $file = CONTENT_PATH . '/pages/' . Config::get('site.pages.main') . '/' . 'index'; } - // Select the file - if (is_dir($file)) { - $file = CONTENT_PATH . '/pages/' . $url .'/index.md'; - } else { - $file .= '.md'; - } - - // Get 404 page if file not exists - if (!file_exists($file)) { - $file = CONTENT_PATH . '/pages/404/' . 'index.md'; - Response::status(404); - } - - // Create Unique Cache ID for requested page - $page_cache_id = md5('page' . ROOT_DIR . $file . filemtime($file)); - - if (Cache::driver()->contains($page_cache_id) && Config::get('site.pages.flush_cache') == false) { - return Cache::driver()->fetch($page_cache_id); - } else { - $content = file_get_contents($file); - - $_page = explode('---', $content, 3); - - $page = Yaml::parse($_page[1]); - - $url = str_replace(CONTENT_PATH . '/pages', Url::getBase(), $file); - $url = str_replace('index.md', '', $url); - $url = str_replace('.md', '', $url); - $url = str_replace('\\', '/', $url); - $url = rtrim($url, '/'); - $page['url'] = $url; - - $_content = $_page[2]; - - // Parse page for summary - if (($pos = strpos($_content, "")) === false) { - $_content = Filter::apply('content', $_content); - } else { - $_content = explode("", $_content); - $_content['summary'] = Filter::apply('content', $_content[0]); - $_content['content'] = Filter::apply('content', $_content[0].$_content[1]); - } - - if (is_array($_content)) { - $page['summary'] = $_content['summary']; - $page['content'] = $_content['content']; - } else { - $page['content'] = $_content; - } - - $page['slug'] = basename($file, '.md'); - - // Overload page title, keywords and description if needed - empty($page['title']) and $page['title'] = Config::get('site.title'); - empty($page['keywords']) and $page['keywords'] = Config::get('site.keywords'); - empty($page['description']) and $page['description'] = Config::get('site.description'); - - Cache::driver()->save($page_cache_id, $page); - return $page; - } - } - - /** - * Get Current Page - * - * - * $page = Pages::getCurrentPage(); - * - * - * @return array - */ - public static function getCurrentPage() - { - return static::$current_page; - } - - /** - * Update Current Page - * - * - * Pages::updateCurrentPage('title', 'My new Page Title'); - * - * - * @return array - */ - public static function updateCurrentPage($path, $value) - { - Arr::set(static::$current_page, $path, $value); - } - - /** - * Display Page - * - * - * Pages::display($page); - * - * - * @access public - * @param array $page Page array - * @return string - */ - public static function display($page) - { - Theme::getTemplate(((!empty($page['template'])) ? $page['template'] : 'index')); - } - - /** - * Get Current Template - * - * - * $template = Pages::getCurrentTemplate(); - * - * - * @access public - * @return object - */ - public static function getCurrentTemplate() - { - return static::$current_template; - } - - /** - * Initialize Monstra Pages - * - * - * Pages::init(); - * - * - * @access public - */ - public static function init() - { - return !isset(self::$instance) and self::$instance = new Pages(); + return $pages; } } diff --git a/monstra/boot/filters.php b/monstra/Plugin.php similarity index 52% rename from monstra/boot/filters.php rename to monstra/Plugin.php index 60bc3a0..9e814e2 100755 --- a/monstra/boot/filters.php +++ b/monstra/Plugin.php @@ -1,4 +1,5 @@ monstra = $c; + } +} diff --git a/monstra/Plugins.php b/monstra/Plugins.php index 776fc8f..14e16f6 100755 --- a/monstra/Plugins.php +++ b/monstra/Plugins.php @@ -1,4 +1,7 @@ monstra = $c; - /** - * Constructor. - * - * @access protected - */ - protected function __construct() - { - $plugins_cache_id = ''; + $monstra = $this->monstra; $plugin_manifest = []; - $plugin_settings = []; // Get Plugins List - $plugins_list = Config::get('site.plugins'); + $plugins_list = $this->monstra['config']->get('site.plugins'); - // If Plugins List isnt empty then create plugin cache ID + // @TODO THIS with cache then + // If Plugins List isnt empty if (is_array($plugins_list) && count($plugins_list) > 0) { // Go through... foreach ($plugins_list as $plugin) { - if (File::exists($_plugin = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) { - $plugins_cache_id .= filemtime($_plugin); - } - } - - // Create Unique Cache ID for Plugins - $plugins_cache_id = md5('plugins' . ROOT_DIR . PLUGINS_PATH . $plugins_cache_id); - } - - // Get plugins list from cache or scan plugins folder and create new plugins cache item - if (Cache::driver()->contains($plugins_cache_id)) { - Config::set('plugins', Cache::driver()->fetch($plugins_cache_id)); - } else { - - // If Plugins List isnt empty - if (is_array($plugins_list) && count($plugins_list) > 0) { - - // Go through... - foreach ($plugins_list as $plugin) { - if (File::exists($_plugin_manifest = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) { - $plugin_manifest = Yaml::parseFile($_plugin_manifest); - } - - if (File::exists($_plugin_settings = PLUGINS_PATH . '/' . $plugin . '/settings.yml')) { - $plugin_settings = Yaml::parseFile($_plugin_settings); - } - - $_plugins_config[File::name($_plugin_manifest)] = array_merge($plugin_manifest, $plugin_settings); + if (file_exists($_plugin_manifest = PLUGINS_PATH . '/' . $plugin . '/' . $plugin . '.yml')) { + $plugin_manifest = Yaml::parse(file_get_contents($_plugin_manifest)); } - Config::set('plugins', $_plugins_config); - Cache::driver()->save($plugins_cache_id, $_plugins_config); + $_plugins_config[basename($_plugin_manifest)] = array_merge($plugin_manifest, $plugin_settings); } } - // Include enabled plugins - if (is_array(Config::get('plugins')) && count(Config::get('plugins')) > 0) { - foreach (Config::get('plugins') as $plugin_name => $plugin) { - if (Config::get('plugins.'.$plugin_name.'.enabled')) { - include_once PLUGINS_PATH .'/'. $plugin_name .'/'. $plugin_name . '.php'; - } + if (is_array($this->monstra['config']->get('site.plugins')) && count($this->monstra['config']->get('site.plugins')) > 0) { + foreach ($this->monstra['config']->get('site.plugins') as $plugin_id => $plugin_name) { + //echo '@@@'.$plugins; + //if ($this->monstra['config']->get('plugins.'.$plugin_name.'.enabled')) { +//echo $plugin_name; + include_once PLUGINS_PATH .'/'. $plugin_name .'/'. $plugin_name . '.php'; + } } - - // Run Actions on plugins_loaded - Action::run('plugins_loaded'); } - /** - * Initialize Monstra Plugins - * - * - * Plugins::init(); - * - * - * @access public - */ - public static function init() - { - if (! isset(self::$instance)) { - self::$instance = new Plugins(); - } - return self::$instance; + public function init() { + } } diff --git a/monstra/Theme.php b/monstra/Theme.php deleted file mode 100755 index 3b9eea4..0000000 --- a/monstra/Theme.php +++ /dev/null @@ -1,9 +0,0 @@ - + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +class Themes +{ + /** + * @var Monstra + */ + protected $monstra; + + /** + * __construct + */ + public function __construct(Monstra $c) + { + $this->monstra = $c; + } + + public function renderTemplate($page) + { + if (empty($page['template'])) { + $template_name = 'index'; + } else { + $template_name = $page['template']; + } + + $template_ext = '.php'; + + include THEMES_PATH . '/' . $this->monstra['config']->get('site.theme') . '/' . $template_name . $template_ext; + } + +} diff --git a/monstra/Yaml.php b/monstra/Yaml.php deleted file mode 100755 index bdc8126..0000000 --- a/monstra/Yaml.php +++ /dev/null @@ -1,59 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -class Yaml -{ - /** - * Parses YAML to array. - * - * - * $array = Yaml::parseFile('file.yml'); - * - * - * @access public - * @param string $file Path to YAML file. - * @return array - */ - public static function parseFile($file) - { - return Spyc::YAMLLoad($file); - } - - /** - * Parses YAML to array. - * - * - * $array = Yaml::parse('title: My title'); - * - * - * @param string $string YAML string. - * @return array - */ - public static function parse($string) - { - return Spyc::YAMLLoadString($string); - } - - /** - * Dumps array to YAML. - * - * - * $yaml = Yaml::dump($data); - * - * - * @param array $data Array. - * @return string - */ - public static function dump($data) - { - return Spyc::YAMLDump($data, false, false, true); - } -} diff --git a/monstra/boot/actions.php b/monstra/boot/actions.php deleted file mode 100755 index b405b66..0000000 --- a/monstra/boot/actions.php +++ /dev/null @@ -1,15 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -// Set Monstra Meta Generator -Action::add('theme_meta', function () { - echo(''); -}); diff --git a/monstra/boot/shortcodes.php b/monstra/boot/shortcodes.php deleted file mode 100755 index c2a1211..0000000 --- a/monstra/boot/shortcodes.php +++ /dev/null @@ -1,22 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -// Add {block name=block-name} shortcode -Shortcode::add('block', function ($attributes) { - if (isset($attributes['name'])) { - return Blocks::get($attributes['name']); - } -}); - -// Add {site_url} shortcode -Shortcode::add('site_url', function () { - return Url::getBase(); -});