mirror of
https://github.com/flextype/flextype.git
synced 2025-08-11 23:54:06 +02:00
Flextype Core: Shortcodes Changes and Refactoring
- Move Snippets and Images shortcodes to Shortocodes::addDefaultShortcodes()
This commit is contained in:
@@ -99,9 +99,6 @@ class Flextype
|
||||
// Get Images Instance
|
||||
Images::getInstance();
|
||||
|
||||
// Get Snippets Instance
|
||||
Snippets::getInstance();
|
||||
|
||||
// Get Themes Instance
|
||||
Themes::getInstance();
|
||||
|
||||
|
@@ -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
|
||||
{
|
||||
|
@@ -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.
|
||||
*
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user