/** * Register service provider, Twig extensions, and alias facade. */ public function boot() { // Service provider App::register('\\Sensory5\\Shortcode\\Classes\\ServiceProvider'); // Register alias $alias = AliasLoader::getInstance(); $alias->alias('Shortcode', '\\Sensory5\\Shortcode\\Classes\\Facade'); // Enable shortcodes on all pages if requested if (Settings::get('enable_on_render', false)) { Event::listen('cms.page.postprocess', function ($controller, $url, $page, $dataHolder) { // Only parse strings, so that we don't interrupt // ajax responses that are in object or array form if (is_string($dataHolder->content)) { $dataHolder->content = \Shortcode::parse($dataHolder->content); } }); } }
/** * Content Parser * * @param string $content Content to parse * @return string $content Formatted content */ protected static function parseContent($content) { // Add {site_url} shortcode Shortcode::add('site_url', function () { return Morfy::$site['url']; }); // Add {block name=block-name} shortcode Shortcode::add('block', function ($attributes) { if (isset($attributes['name'])) { if (File::exists($block_file = BLOCKS_PATH . '/' . $attributes['name'] . '.md')) { return file_get_contents($block_file); } else { return 'Block ' . $attributes['name'] . ' is not found!'; } } }); // Parse Shortcodes $content = Shortcode::parse($content); // Parsedown $content = static::parsedown($content); // Parse page for summary <!--more--> if (($pos = strpos($content, "<!--more-->")) === false) { $content = static::applyFilter('content', $content); } else { $content = explode("<!--more-->", $content); $content['summary'] = static::applyFilter('content', $content[0]); $content['content'] = static::applyFilter('content', $content[0] . $content[1]); } // Return content return $content; }
public function beforeSiteLoad() { global $Page, $Post, $Url, $posts; // Better with instance() no? # Add Shortcode class require_once dirname(__FILE__) . DS . 'Shortcode.class.php'; # Add great extras shorcode! include_once dirname(__FILE__) . DS . 'shortcodes.php'; # include shortcodes in themes # $this->addons_shortcode_themes(); // FEATURES // Filter then build it! switch ($Url->whereAmI()) { case 'post': $content = $Post->content(); // Parse Shortcodes $content = Shortcode::parse($content); $Post->setField('content', $content, true); break; case 'page': $content = $Page->content(); // Parse Shortcodes $content = Shortcode::parse($content); $Page->setField('content', $content, true); break; default: // Homepage (Thx Diego for this tip) foreach ($posts as $key => $Post) { // Full content parsed by Parsedown $content = $Post->content(); // Parse with Shortcode $content = Shortcode::parse($content); // Set full content $Post->setField('content', $content, true); // Set page break content $explode = explode(PAGE_BREAK, $content); $Post->setField('breakContent', $explode[0], true); $Post->setField('readMore', !empty($explode[1]), true); } } }