|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Dappur\TwigExtension; |
| 4 | + |
| 5 | +/** |
| 6 | + * Cloudinary twig extension. |
| 7 | + * |
| 8 | + * adapted from @author Stefan Gotre <[email protected]> |
| 9 | + */ |
| 10 | +class Cloudinary extends \Twig_Extension |
| 11 | +{ |
| 12 | + public function getName() |
| 13 | + { |
| 14 | + return 'cloudinary'; |
| 15 | + } |
| 16 | + |
| 17 | + public function getFunctions() |
| 18 | + { |
| 19 | + return array( |
| 20 | + 'clUploadUrl' => new \Twig_SimpleFunction( |
| 21 | + 'clUploadUrl', |
| 22 | + [$this, 'clUploadUrl'] |
| 23 | + ), |
| 24 | + 'clImageTag' => new \Twig_SimpleFunction( |
| 25 | + 'clImageTag', |
| 26 | + [$this, 'clImageTag'], |
| 27 | + array('is_safe' => array('html')) |
| 28 | + ), |
| 29 | + 'cloudinaryJsConfig' => new \Twig_SimpleFunction( |
| 30 | + 'cloudinaryJsConfig', |
| 31 | + [$this, 'cloudinaryJsConfig'], |
| 32 | + array('is_safe' => array('html', 'js')) |
| 33 | + ), |
| 34 | + 'clUrl' => new \Twig_SimpleFunction( |
| 35 | + 'clUrl', |
| 36 | + [$this, 'clUrl'] |
| 37 | + ), |
| 38 | + 'clVideoPath' => new \Twig_SimpleFunction( |
| 39 | + 'clVideoPath', |
| 40 | + [$this, 'clVideoPath'] |
| 41 | + ), |
| 42 | + 'clVideoThumb' => new \Twig_SimpleFunction( |
| 43 | + 'clVideoThumb', |
| 44 | + [$this, 'clVideoThumb'] |
| 45 | + ), |
| 46 | + 'clVideoTag' => new \Twig_SimpleFunction( |
| 47 | + 'clVideoTag', |
| 48 | + [$this, 'clVideoTag'], |
| 49 | + array('is_safe' => array('html')) |
| 50 | + ), |
| 51 | + new \Twig_SimpleFunction('tinymce_init', [$this, 'tinymceInit'], array('is_safe' => array('html'))) |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + public function clUploadUrl($options = array()) |
| 56 | + { |
| 57 | + return cl_upload_url($options); |
| 58 | + } |
| 59 | + |
| 60 | + public function clImageTag($source, $options = array()) |
| 61 | + { |
| 62 | + return cl_image_tag($source, $options); |
| 63 | + } |
| 64 | + |
| 65 | + public function cloudinaryJsConfig() |
| 66 | + { |
| 67 | + return cloudinary_js_config(); |
| 68 | + } |
| 69 | + |
| 70 | + public function clUrl($source, $options = array()) |
| 71 | + { |
| 72 | + return cloudinary_url($source, $options); |
| 73 | + } |
| 74 | + |
| 75 | + public function clVideoPath($source, $options = array()) |
| 76 | + { |
| 77 | + return cl_video_path($source, $options = array()); |
| 78 | + } |
| 79 | + |
| 80 | + public function clVideoThumb($source, $options = array()) |
| 81 | + { |
| 82 | + return cl_video_thumbnail_path($source, $options); |
| 83 | + } |
| 84 | + |
| 85 | + public function clVideoTag($source, $options = array()) |
| 86 | + { |
| 87 | + return cl_video_tag($source, $options); |
| 88 | + } |
| 89 | +} |
0 commit comments