From dee1f0ecba19765f688ea42ac419231e8e785dea Mon Sep 17 00:00:00 2001 From: Awilum Date: Mon, 21 Jan 2019 18:58:44 +0300 Subject: [PATCH] Flextype Core: Shortcodes Changes and Refactoring - Move Snippets and Images shortcodes to Shortocodes::addDefaultShortcodes() --- flextype/Flextype.php | 3 -- flextype/Images.php | 86 ---------------------------------- flextype/Shortcodes.php | 101 ++++++++++++++++++++++++++++++++++++++++ flextype/Snippets.php | 78 ------------------------------- 4 files changed, 101 insertions(+), 167 deletions(-) diff --git a/flextype/Flextype.php b/flextype/Flextype.php index ed86dad9..c5ae892c 100755 --- a/flextype/Flextype.php +++ b/flextype/Flextype.php @@ -99,9 +99,6 @@ class Flextype // Get Images Instance Images::getInstance(); - // Get Snippets Instance - Snippets::getInstance(); - // Get Themes Instance Themes::getInstance(); diff --git a/flextype/Images.php b/flextype/Images.php index 3d303d4c..8f361d9b 100644 --- a/flextype/Images.php +++ b/flextype/Images.php @@ -15,92 +15,6 @@ namespace Flextype; use Flextype\Component\Http\Http; use Flextype\Component\Event\Event; use Flextype\Component\Html\Html; -use Thunder\Shortcode\Shortcode\ShortcodeInterface; - -// Event: onShortcodesInitialized -Event::addListener('onShortcodesInitialized', function () { - - // Shortcode: [image path="home/image.jpg"] - // Result: Display image - Entries::shortcode()->addHandler('image', function(ShortcodeInterface $s) { - $params = []; - $attributes = []; - - // API - // http://glide.thephpleague.com/1.0/api/quick-reference/ - ($s->getParameter('or')) and $params['or'] = $s->getParameter('or'); - ($s->getParameter('flip')) and $params['flip'] = $s->getParameter('flip'); - ($s->getParameter('crop')) and $params['crop'] = $s->getParameter('crop'); - ($s->getParameter('w')) and $params['w'] = $s->getParameter('w'); - ($s->getParameter('h')) and $params['h'] = $s->getParameter('h'); - ($s->getParameter('fit')) and $params['fit'] = $s->getParameter('fit'); - ($s->getParameter('dpr')) and $params['dpr'] = $s->getParameter('dpr'); - ($s->getParameter('bri')) and $params['bri'] = $s->getParameter('bri'); - ($s->getParameter('con')) and $params['con'] = $s->getParameter('con'); - ($s->getParameter('gam')) and $params['gam'] = $s->getParameter('gam'); - ($s->getParameter('sharp')) and $params['sharp'] = $s->getParameter('sharp'); - ($s->getParameter('blur')) and $params['blur'] = $s->getParameter('blur'); - ($s->getParameter('pixel')) and $params['pixel'] = $s->getParameter('pixel'); - ($s->getParameter('filt')) and $params['filt'] = $s->getParameter('filt'); - ($s->getParameter('mark')) and $params['mark'] = $s->getParameter('mark'); - ($s->getParameter('markw')) and $params['markw'] = $s->getParameter('markw'); - ($s->getParameter('markh')) and $params['markh'] = $s->getParameter('markh'); - ($s->getParameter('markx')) and $params['markx'] = $s->getParameter('markx'); - ($s->getParameter('marky')) and $params['marky'] = $s->getParameter('marky'); - ($s->getParameter('markpad')) and $params['markpad'] = $s->getParameter('markpad'); - ($s->getParameter('markpos')) and $params['markpos'] = $s->getParameter('markpos'); - ($s->getParameter('markalpha')) and $params['markalpha'] = $s->getParameter('markalpha'); - ($s->getParameter('bg')) and $params['bg'] = $s->getParameter('bg'); - ($s->getParameter('border')) and $params['border'] = $s->getParameter('border'); - ($s->getParameter('q')) and $params['q'] = $s->getParameter('q'); - ($s->getParameter('fm')) and $params['fm'] = $s->getParameter('fm'); - - ($s->getParameter('width')) and $attributes['width'] = $s->getParameter('width'); - ($s->getParameter('height')) and $attributes['height'] = $s->getParameter('height'); - ($s->getParameter('class')) and $attributes['class'] = $s->getParameter('class'); - ($s->getParameter('id')) and $attributes['id'] = $s->getParameter('id'); - ($s->getParameter('alt')) and $attributes['alt'] = $s->getParameter('alt'); - - return Images::getImage($s->getParameter('path'), $params, $attributes); - }); - - // Shortcode: [image_url path="home/image.jpg"] - // Result: Display image url - Entries::shortcode()->addHandler('image_url', function(ShortcodeInterface $s) { - $params = []; - - // API - // http://glide.thephpleague.com/1.0/api/quick-reference/ - ($s->getParameter('or')) and $params['or'] = $s->getParameter('or'); - ($s->getParameter('flip')) and $params['flip'] = $s->getParameter('flip'); - ($s->getParameter('crop')) and $params['crop'] = $s->getParameter('crop'); - ($s->getParameter('w')) and $params['w'] = $s->getParameter('w'); - ($s->getParameter('h')) and $params['h'] = $s->getParameter('h'); - ($s->getParameter('fit')) and $params['fit'] = $s->getParameter('fit'); - ($s->getParameter('dpr')) and $params['dpr'] = $s->getParameter('dpr'); - ($s->getParameter('bri')) and $params['bri'] = $s->getParameter('bri'); - ($s->getParameter('con')) and $params['con'] = $s->getParameter('con'); - ($s->getParameter('gam')) and $params['gam'] = $s->getParameter('gam'); - ($s->getParameter('sharp')) and $params['sharp'] = $s->getParameter('sharp'); - ($s->getParameter('blur')) and $params['blur'] = $s->getParameter('blur'); - ($s->getParameter('pixel')) and $params['pixel'] = $s->getParameter('pixel'); - ($s->getParameter('filt')) and $params['filt'] = $s->getParameter('filt'); - ($s->getParameter('mark')) and $params['mark'] = $s->getParameter('mark'); - ($s->getParameter('markw')) and $params['markw'] = $s->getParameter('markw'); - ($s->getParameter('markh')) and $params['markh'] = $s->getParameter('markh'); - ($s->getParameter('markx')) and $params['markx'] = $s->getParameter('markx'); - ($s->getParameter('marky')) and $params['marky'] = $s->getParameter('marky'); - ($s->getParameter('markpad')) and $params['markpad'] = $s->getParameter('markpad'); - ($s->getParameter('markpos')) and $params['markpos'] = $s->getParameter('markpos'); - ($s->getParameter('markalpha')) and $params['markalpha'] = $s->getParameter('markalpha'); - ($s->getParameter('bg')) and $params['bg'] = $s->getParameter('bg'); - ($s->getParameter('border')) and $params['border'] = $s->getParameter('border'); - ($s->getParameter('q')) and $params['q'] = $s->getParameter('q'); - ($s->getParameter('fm')) and $params['fm'] = $s->getParameter('fm'); - - return Images::getImageUrl($s->getParameter('path'), $params); - }); -}); class Images { diff --git a/flextype/Shortcodes.php b/flextype/Shortcodes.php index fafa6d18..78c50a81 100644 --- a/flextype/Shortcodes.php +++ b/flextype/Shortcodes.php @@ -73,6 +73,9 @@ class Shortcodes { // Create Shortcode Parser object Shortcodes::$shortcode = new ShortcodeFacade(); + // Add Default Shorcodes! + Shortcodes::addDefaultShortcodes(); + // Event: Shortcodes initialized Event::dispatch('onShortcodesInitialized'); } @@ -102,6 +105,104 @@ class Shortcodes { return Shortcodes::shortcode()->process($content); } + /** + * Add default shortcodes! + * + * @access private + * @return void + */ + private static function addDefaultShortcodes() : void + { + // Snippets + // Shortcode: [snippet name=snippet-name] + Shortcodes::shortcode()->addHandler('snippet', function(ShortcodeInterface $s) { + return Snippets::get($s->getParameter('name')); + }); + + // Images + // Shortcode: [image path="home/image.jpg"] + // Result: Display image + Shortcodes::shortcode()->addHandler('image', function(ShortcodeInterface $s) { + $params = []; + $attributes = []; + + // API + // http://glide.thephpleague.com/1.0/api/quick-reference/ + ($s->getParameter('or')) and $params['or'] = $s->getParameter('or'); + ($s->getParameter('flip')) and $params['flip'] = $s->getParameter('flip'); + ($s->getParameter('crop')) and $params['crop'] = $s->getParameter('crop'); + ($s->getParameter('w')) and $params['w'] = $s->getParameter('w'); + ($s->getParameter('h')) and $params['h'] = $s->getParameter('h'); + ($s->getParameter('fit')) and $params['fit'] = $s->getParameter('fit'); + ($s->getParameter('dpr')) and $params['dpr'] = $s->getParameter('dpr'); + ($s->getParameter('bri')) and $params['bri'] = $s->getParameter('bri'); + ($s->getParameter('con')) and $params['con'] = $s->getParameter('con'); + ($s->getParameter('gam')) and $params['gam'] = $s->getParameter('gam'); + ($s->getParameter('sharp')) and $params['sharp'] = $s->getParameter('sharp'); + ($s->getParameter('blur')) and $params['blur'] = $s->getParameter('blur'); + ($s->getParameter('pixel')) and $params['pixel'] = $s->getParameter('pixel'); + ($s->getParameter('filt')) and $params['filt'] = $s->getParameter('filt'); + ($s->getParameter('mark')) and $params['mark'] = $s->getParameter('mark'); + ($s->getParameter('markw')) and $params['markw'] = $s->getParameter('markw'); + ($s->getParameter('markh')) and $params['markh'] = $s->getParameter('markh'); + ($s->getParameter('markx')) and $params['markx'] = $s->getParameter('markx'); + ($s->getParameter('marky')) and $params['marky'] = $s->getParameter('marky'); + ($s->getParameter('markpad')) and $params['markpad'] = $s->getParameter('markpad'); + ($s->getParameter('markpos')) and $params['markpos'] = $s->getParameter('markpos'); + ($s->getParameter('markalpha')) and $params['markalpha'] = $s->getParameter('markalpha'); + ($s->getParameter('bg')) and $params['bg'] = $s->getParameter('bg'); + ($s->getParameter('border')) and $params['border'] = $s->getParameter('border'); + ($s->getParameter('q')) and $params['q'] = $s->getParameter('q'); + ($s->getParameter('fm')) and $params['fm'] = $s->getParameter('fm'); + + ($s->getParameter('width')) and $attributes['width'] = $s->getParameter('width'); + ($s->getParameter('height')) and $attributes['height'] = $s->getParameter('height'); + ($s->getParameter('class')) and $attributes['class'] = $s->getParameter('class'); + ($s->getParameter('id')) and $attributes['id'] = $s->getParameter('id'); + ($s->getParameter('alt')) and $attributes['alt'] = $s->getParameter('alt'); + + return Images::getImage($s->getParameter('path'), $params, $attributes); + }); + + // Images + // Shortcode: [image_url path="home/image.jpg"] + // Result: Display image url + Shortcodes::shortcode()->addHandler('image_url', function(ShortcodeInterface $s) { + $params = []; + + // API + // http://glide.thephpleague.com/1.0/api/quick-reference/ + ($s->getParameter('or')) and $params['or'] = $s->getParameter('or'); + ($s->getParameter('flip')) and $params['flip'] = $s->getParameter('flip'); + ($s->getParameter('crop')) and $params['crop'] = $s->getParameter('crop'); + ($s->getParameter('w')) and $params['w'] = $s->getParameter('w'); + ($s->getParameter('h')) and $params['h'] = $s->getParameter('h'); + ($s->getParameter('fit')) and $params['fit'] = $s->getParameter('fit'); + ($s->getParameter('dpr')) and $params['dpr'] = $s->getParameter('dpr'); + ($s->getParameter('bri')) and $params['bri'] = $s->getParameter('bri'); + ($s->getParameter('con')) and $params['con'] = $s->getParameter('con'); + ($s->getParameter('gam')) and $params['gam'] = $s->getParameter('gam'); + ($s->getParameter('sharp')) and $params['sharp'] = $s->getParameter('sharp'); + ($s->getParameter('blur')) and $params['blur'] = $s->getParameter('blur'); + ($s->getParameter('pixel')) and $params['pixel'] = $s->getParameter('pixel'); + ($s->getParameter('filt')) and $params['filt'] = $s->getParameter('filt'); + ($s->getParameter('mark')) and $params['mark'] = $s->getParameter('mark'); + ($s->getParameter('markw')) and $params['markw'] = $s->getParameter('markw'); + ($s->getParameter('markh')) and $params['markh'] = $s->getParameter('markh'); + ($s->getParameter('markx')) and $params['markx'] = $s->getParameter('markx'); + ($s->getParameter('marky')) and $params['marky'] = $s->getParameter('marky'); + ($s->getParameter('markpad')) and $params['markpad'] = $s->getParameter('markpad'); + ($s->getParameter('markpos')) and $params['markpos'] = $s->getParameter('markpos'); + ($s->getParameter('markalpha')) and $params['markalpha'] = $s->getParameter('markalpha'); + ($s->getParameter('bg')) and $params['bg'] = $s->getParameter('bg'); + ($s->getParameter('border')) and $params['border'] = $s->getParameter('border'); + ($s->getParameter('q')) and $params['q'] = $s->getParameter('q'); + ($s->getParameter('fm')) and $params['fm'] = $s->getParameter('fm'); + + return Images::getImageUrl($s->getParameter('path'), $params); + }); + } + /** * Get the Shortcodes instance. * diff --git a/flextype/Snippets.php b/flextype/Snippets.php index 6c46762b..341fa3b8 100644 --- a/flextype/Snippets.php +++ b/flextype/Snippets.php @@ -14,72 +14,9 @@ namespace Flextype; use Flextype\Component\Filesystem\Filesystem; use Flextype\Component\Event\Event; -use Thunder\Shortcode\Shortcode\ShortcodeInterface; - -// Event: onShortcodesInitialized -Event::addListener('onShortcodesInitialized', function () { - - // Shortcode: [snippet name=snippet-name] - Entries::shortcode()->addHandler('snippet', function(ShortcodeInterface $s) { - return Snippets::get($s->getParameter('name')); - }); -}); class Snippets { - /** - * An instance of the Snippets class - * - * @var object - */ - private static $instance = null; - - /** - * Images Server - * - * @var - */ - protected static $server; - - /** - * 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() - { - Snippets::init(); - } - - /** - * Init Snippets - * - * @access private - * @return void - */ - private static function init() : void - { - - } - /** * Get snippet * @@ -108,19 +45,4 @@ class Snippets throw new \RuntimeException("Snippet {$snippet_name} does not exist."); } } - - /** - * Get the Snippets instance. - * - * @access public - * @return object - */ - public static function getInstance() - { - if (is_null(Snippets::$instance)) { - Snippets::$instance = new self; - } - - return Snippets::$instance; - } }