diff --git a/flextype/Entries.php b/flextype/Entries.php index 8427e9e5..036dc660 100755 --- a/flextype/Entries.php +++ b/flextype/Entries.php @@ -17,8 +17,6 @@ use Flextype\Component\Http\Http; use Flextype\Component\Filesystem\Filesystem; use Flextype\Component\Event\Event; use Flextype\Component\Registry\Registry; -use Thunder\Shortcode\ShortcodeFacade; -use Thunder\Shortcode\Shortcode\ShortcodeInterface; class Entries { @@ -30,14 +28,6 @@ class Entries */ private static $instance = null; - /** - * Shortcode object - * - * @var object - * @access private - */ - private static $shortcode = null; - /** * Current entry data array * @@ -96,12 +86,6 @@ class Entries // Event: The entry is not processed and not sent to the display. Event::dispatch('onCurrentEntryBeforeProcessed'); - // Init Parsers - Entries::initParsers(); - - // Event: The entry has been not loaded. - Event::dispatch('onCurrentEntryBeforeLoaded'); - // Set current requested entry data to global $entry array Entries::$entry = Entries::getEntry(Http::getUriString()); @@ -328,17 +312,6 @@ class Entries return $entry; } - /** - * Returns $shortcode object - * - * @access public - * @return object - */ - public static function shortcode() : ShortcodeFacade - { - return Entries::$shortcode; - } - /** * Process entry * @@ -369,7 +342,7 @@ class Entries $_entry = []; // Process $entry_frontmatter with YAML and Shortcodes parsers - $_entry = YamlParser::decode(Entries::processShortcodes($entry_frontmatter)); + $_entry = YamlParser::decode(Shortcodes::process($entry_frontmatter)); // Create entry url item $url = str_replace(PATH['entries'], Http::getBaseUrl(), $file_path); @@ -402,7 +375,7 @@ class Entries if ($ignore_content) { $_entry['content'] = $entry_content; } else { - $_entry['content'] = Entries::processContent($entry_content); + $_entry['content'] = Shortcodes::process($entry_content); } // Return entry @@ -410,61 +383,6 @@ class Entries } } - /** - * Process shortcodes - * - * $content = Entries::processShortcodes($content); - * - * @access public - * @param string $content Content to parse - * @return string - */ - public static function processShortcodes(string $content) : string - { - return Entries::shortcode()->process($content); - } - - /** - * Process content with markdown and shortcodes processors - * - * $content = Entries::processContent($content); - * - * @access public - * @param string $content Content to parse - * @return string - */ - public static function processContent(string $content) : string - { - return Entries::processShortcodes($content); - } - - /** - * Init Parsers - * - * @access private - * @return void - */ - private static function initParsers() : void - { - // Init Shortcodes - Entries::initShortcodes(); - } - - /** - * Init Shortcodes - * - * @access private - * @return void - */ - private static function initShortcodes() : void - { - // Create Shortcode Parser object - Entries::$shortcode = new ShortcodeFacade(); - - // Event: Shortcodes initialized and now we can add our custom shortcodes - Event::dispatch('onShortcodesInitialized'); - } - /** * Display current entry * diff --git a/flextype/Flextype.php b/flextype/Flextype.php index 91f04317..ed86dad9 100755 --- a/flextype/Flextype.php +++ b/flextype/Flextype.php @@ -93,6 +93,9 @@ class Flextype // Get Cache Instance Cache::getInstance(); + // Init Shortcodes + Shortcodes::getInstance(); + // Get Images Instance Images::getInstance(); diff --git a/flextype/Shortcodes.php b/flextype/Shortcodes.php new file mode 100644 index 00000000..fafa6d18 --- /dev/null +++ b/flextype/Shortcodes.php @@ -0,0 +1,119 @@ + + * @link http://flextype.org + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Flextype; + +use Flextype\Component\Event\Event; +use Thunder\Shortcode\ShortcodeFacade; +use Thunder\Shortcode\Shortcode\ShortcodeInterface; + +class Shortcodes { + + /** + * An instance of the Shortcodes class + * + * @var object + * @access private + */ + private static $instance = null; + + /** + * Shortcode object + * + * @var object + * @access private + */ + private static $shortcode = null; + + /** + * Private clone method to enforce singleton behavior. + * + * @access private + */ + private function __clone() + { + } + + /** + * Private wakeup method to enforce singleton behavior. + * + * @access private + */ + private function __wakeup() + { + } + + /** + * Private construct method to enforce singleton behavior. + * + * @access private + */ + private function __construct() + { + Shortcodes::init(); + } + + /** + * Init Shortcodes + * + * @access private + * @return void + */ + private static function init() : void + { + // Create Shortcode Parser object + Shortcodes::$shortcode = new ShortcodeFacade(); + + // Event: Shortcodes initialized + Event::dispatch('onShortcodesInitialized'); + } + + /** + * Returns $shortcode object + * + * @access public + * @return object + */ + public static function shortcode() : ShortcodeFacade + { + return Shortcodes::$shortcode; + } + + /** + * Process shortcodes + * + * $content = Shortcodes::proccess($content); + * + * @access public + * @param string $content Content to parse + * @return string + */ + public static function process(string $content) : string + { + return Shortcodes::shortcode()->process($content); + } + + /** + * Get the Shortcodes instance. + * + * @access public + * @return object + */ + public static function getInstance() + { + if (is_null(Shortcodes::$instance)) { + Shortcodes::$instance = new self; + } + + return Shortcodes::$instance; + } +}