diff --git a/flextype/Images.php b/flextype/Images.php index ca6f49ce..2a0b2789 100644 --- a/flextype/Images.php +++ b/flextype/Images.php @@ -14,18 +14,21 @@ 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 = []; + $params = []; + $attributes = []; // API // http://glide.thephpleague.com/1.0/api/quick-reference/ - ($s->getParameter('or')) and $params['w'] = $s->getParameter('or'); + ($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'); @@ -52,7 +55,50 @@ Event::addListener('onShortcodesInitialized', function () { ($s->getParameter('q')) and $params['q'] = $s->getParameter('q'); ($s->getParameter('fm')) and $params['fm'] = $s->getParameter('fm'); - return Images::get($s->getParameter('path'), $params); + ($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); }); }); @@ -160,9 +206,9 @@ class Images } /** - * Get image + * Get image url * - * Images::get('page-name/image.jpg', [w => '200']); + * Images::getImageUrl('page-name/image.jpg', [w => '200']); * http://glide.thephpleague.com/1.0/api/quick-reference/ * * @access public @@ -170,9 +216,25 @@ class Images * @param array $params Image params * @return string Returns the image url */ - public static function get($path, array $params) + public static function getImageUrl($path, array $params) { - return Http::getBaseUrl().'/site/cache/glide/'.Images::$server->makeImage($path, $params); + return Http::getBaseUrl() . '/site/cache/glide/' . Images::$server->makeImage($path, $params); + } + + /** + * Get image + * + * Images::getImage('page-name/image.jpg', [w => '200']); + * http://glide.thephpleague.com/1.0/api/quick-reference/ + * + * @access public + * @param string $path Image path + * @param array $params Image params + * @return string Returns the image url + */ + public static function getImage($path, array $params, array $attributes = []) + { + return ''; } /**