├── language └── en-GB │ ├── en-GB.plg_content_plg_ccclottieplayer.sys.ini │ └── en-GB.plg_content_plg_ccclottieplayer.ini ├── ccclottieplayer.xml ├── script.php └── ccclottieplayer.php /language/en-GB/en-GB.plg_content_plg_ccclottieplayer.sys.ini: -------------------------------------------------------------------------------- 1 | ; 2 | ; Plg_ccclottieplayer language file 3 | ; 4 | 5 | PLG_CONTENT_PLG_CCCLOTTIEPLAYER="CCC Lottie Player" 6 | PLG_CONTENT_PLG_CCCLOTTIEPLAYER_XML_DESCRIPTION="Plugin to display Lottie animations in a webcomponent" 7 | -------------------------------------------------------------------------------- /language/en-GB/en-GB.plg_content_plg_ccclottieplayer.ini: -------------------------------------------------------------------------------- 1 | ; 2 | ; Plg_ccclottieplayer language file 3 | ; 4 | 5 | PLG_CONTENT_PLG_CCCLOTTIEPLAYER="CCC Lottie Player" 6 | PLG_CONTENT_PLG_CCCLOTTIEPLAYER_XML_DESCRIPTION="Plugin to display Lottie animations in a webcomponent" 7 | PLG_CONTENT_PLG_CCCLOTTIEPLAYER_SAMPLE_LABEL="Sample parameter" 8 | PLG_CONTENT_PLG_CCCLOTTIEPLAYER_SAMPLE_DESCRIPTION="Sample description" 9 | -------------------------------------------------------------------------------- /ccclottieplayer.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | PLG_CONTENT_PLG_CCCLOTTIEPLAYER 4 | 24.04.22 5 | Elisa Foltyn 6 | mail@coolcat-creations.com 7 | https://coolcat-creations.com 8 | coolcat-creation.com 9 | GNU General Public License version 2 or later; see LICENSE.txt 10 | 1.0 11 | PLG_CONTENT_PLG_CCCLOTTIEPLAYER_XML_DESCRIPTION 12 | 13 | 14 | 15 | 16 | 17 | 18 | en-GB/en-GB.plg_content_plg_ccclottieplayer.ini 19 | en-GB/en-GB.plg_content_plg_ccclottieplayer.sys.ini 20 | 21 | 22 | 23 | 24 | ccclottieplayer.php 25 | language 26 | js 27 | 28 | 29 | 30 | 31 | 32 |
33 | 40 |
41 |
42 |
43 | 44 | 45 | 46 | https://www.example.com/ccclottieplayer.xml 47 | 48 |
49 | -------------------------------------------------------------------------------- /script.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright A copyright 7 | * @license GNU General Public License version 2 or later; see LICENSE.txt 8 | * @link http://your.url.com 9 | */ 10 | 11 | defined('_JEXEC') or die; 12 | 13 | /** 14 | * Plg_ccclottieplayer script file. 15 | * 16 | * @package plg_ccclottieplayer 17 | * @since 1.0.0 18 | */ 19 | class plgSystemPlg_ccclottieplayerInstallerScript 20 | { 21 | /** 22 | * Constructor 23 | * 24 | * @param JAdapterInstance $adapter The object responsible for running this script 25 | */ 26 | public function __construct(JAdapterInstance $adapter) {} 27 | 28 | /** 29 | * Called before any type of action 30 | * 31 | * @param string $route Which action is happening (install|uninstall|discover_install|update) 32 | * @param JAdapterInstance $adapter The object responsible for running this script 33 | * 34 | * @return boolean True on success 35 | */ 36 | public function preflight($route, JAdapterInstance $adapter) {} 37 | 38 | /** 39 | * Called after any type of action 40 | * 41 | * @param string $route Which action is happening (install|uninstall|discover_install|update) 42 | * @param JAdapterInstance $adapter The object responsible for running this script 43 | * 44 | * @return boolean True on success 45 | */ 46 | public function postflight($route, JAdapterInstance $adapter) {} 47 | 48 | /** 49 | * Called on installation 50 | * 51 | * @param JAdapterInstance $adapter The object responsible for running this script 52 | * 53 | * @return boolean True on success 54 | */ 55 | public function install(JAdapterInstance $adapter) {} 56 | 57 | /** 58 | * Called on update 59 | * 60 | * @param JAdapterInstance $adapter The object responsible for running this script 61 | * 62 | * @return boolean True on success 63 | */ 64 | public function update(JAdapterInstance $adapter) {} 65 | 66 | /** 67 | * Called on uninstallation 68 | * 69 | * @param JAdapterInstance $adapter The object responsible for running this script 70 | */ 71 | public function uninstall(JAdapterInstance $adapter) {} 72 | } 73 | -------------------------------------------------------------------------------- /ccclottieplayer.php: -------------------------------------------------------------------------------- 1 | 6 | * @copyright A copyright 7 | * @license GNU General Public License version 2 or later; see LICENSE.txt 8 | * @link http://your.url.com 9 | */ 10 | 11 | defined('_JEXEC') or die; 12 | 13 | use Joomla\CMS\Application\CMSApplication; 14 | use Joomla\CMS\HTML\HTMLHelper; 15 | use Joomla\CMS\Plugin\CMSPlugin; 16 | 17 | /** 18 | * ccclottieplayer plugin. 19 | * 20 | * @package ccclottieplayer 21 | * @since 1.0.0 22 | */ 23 | class PlgContentccclottieplayer extends CMSPlugin 24 | { 25 | /** 26 | * Application object 27 | * 28 | * @var CMSApplication 29 | * @since 1.0.0 30 | */ 31 | protected $app; 32 | 33 | const LOTTIEPLAYER_REGEX_PATTERN = '#{lottieplayer (.*?)}#s'; 34 | 35 | /** 36 | * Database object 37 | * 38 | * @var JDatabaseDriver 39 | * @since 1.0.0 40 | */ 41 | protected $db; 42 | 43 | /** 44 | * Affects constructor behavior. If true, language files will be loaded automatically. 45 | * 46 | * @var boolean 47 | * @since 1.0.0 48 | */ 49 | protected $autoloadLanguage = true; 50 | 51 | 52 | /** 53 | * oncontentprepare event handler. 54 | * 55 | * @return void 56 | * 57 | * @since 1.0.0 58 | */ 59 | 60 | public function onContentPrepare($context, &$article, &$params) 61 | { 62 | 63 | // Don't run this plugin when the content is being indexed 64 | if ($context === 'com_finder.indexer') 65 | { 66 | return; 67 | } 68 | 69 | // Simple performance check to determine whether bot should process further 70 | if (str_contains($article->text, 'lottieplayer') === false) 71 | { 72 | return; 73 | } 74 | 75 | // Check if LOTTIEPLAYER_REGEX is contained in $article->text 76 | 77 | if (preg_match_all(self::LOTTIEPLAYER_REGEX_PATTERN, $article->text, $matches, PREG_SET_ORDER)) 78 | { 79 | echo HTMLHelper::_('script', 'plg_content_ccclottieplayer/lottie-player.js', array('version' => 'auto', 'relative' => true)); 80 | 81 | $lottie = []; 82 | $count = 1; 83 | 84 | foreach ($matches as $match) 85 | { 86 | $playerparams = explode('|', $match[1]); 87 | 88 | $lottie[$count]['loop'] = str_contains($match[1], 'loop') !== false ? 'loop' : false; 89 | $lottie[$count]['autoplay'] = str_contains($match[1], 'autoplay') !== false ? 'autoplay' : false; 90 | $lottie[$count]['controls'] = str_contains($match[1], 'controls') !== false ? 'controls' : false; 91 | $lottie[$count]['hover'] = str_contains($match[1], 'hover') !== false ? 'preload' : false; 92 | $lottie[$count]['bounce'] = str_contains($match[1], 'bounce') !== false ? 'bounce' : false; 93 | $lottie[$count]['count'] = $count; 94 | 95 | foreach ($playerparams as $playerparam) 96 | { 97 | 98 | if (str_contains($playerparam, 'src') !== false) 99 | { 100 | $src = explode('=', $playerparam); 101 | $lottie[$count]['src'] = $src[1]; 102 | } 103 | 104 | if (str_contains($playerparam, 'background') !== false) 105 | { 106 | $background = explode('=', $playerparam); 107 | $lottie[$count]['background'] = $background[1]; 108 | } 109 | 110 | if (str_contains($playerparam, 'width') !== false) 111 | { 112 | $width = explode('=', $playerparam); 113 | $lottie[$count]['width'] = $width[1]; 114 | } 115 | 116 | if (str_contains($playerparam, 'height') !== false) 117 | { 118 | $height = explode('=', $playerparam); 119 | $lottie[$count]['height'] = $height[1]; 120 | } 121 | 122 | 123 | } 124 | 125 | 126 | $count++; 127 | 128 | $lottieplayer = []; 129 | 130 | foreach ($lottie as $player) 131 | { 132 | $lottieplayer = $this->getLottiePlayer($player); 133 | } 134 | 135 | $article->text = str_replace($match, $lottieplayer, $article->text); 136 | 137 | } 138 | 139 | 140 | } 141 | 142 | } 143 | 144 | 145 | /** 146 | * 147 | * 148 | * @param array $player The match array 149 | * 150 | * @return string $lottieplayer The replace code 151 | * 152 | * @since 1.0.0 153 | */ 154 | 155 | protected function getLottieplayer(array $player) : string 156 | { 157 | 158 | $lottiefile = false; 159 | 160 | if ($player['src']) 161 | { 162 | $file = JUri::root() . $player['src']; 163 | $filepath = JPATH_ROOT . '/' . $player['src']; 164 | 165 | if ($file && is_file($filepath) && pathinfo($filepath, PATHINFO_EXTENSION) === 'json') 166 | { 167 | $lottiefile = $file; 168 | } 169 | 170 | else 171 | { 172 | return false; 173 | } 174 | } 175 | 176 | $controls = $player['controls']; 177 | $autoplay = $player['autoplay']; 178 | $loop = $player['loop']; 179 | $hover = $player['hover']; 180 | $count = $player['count']; 181 | 182 | if ($player['bounce'] == 'bounce') { 183 | $bounce = 'mode="bounce"'; 184 | } else { 185 | $bounce = ''; 186 | } 187 | 188 | 189 | $style = ""; 190 | $width = ""; 191 | $height = ""; 192 | 193 | if ($player['width']) 194 | { 195 | $width = "width:" . $player['width'] . '; '; 196 | } 197 | 198 | if ($player['height']) 199 | { 200 | $height = "height:" . $player['height'] . '; '; 201 | } 202 | 203 | if ($player['width'] || $player['height']) 204 | { 205 | $style = 'style="' . $width . ' ' . $height . '"'; 206 | } 207 | 208 | 209 | $lottieplayer = ' 214 | 215 | '; 216 | 217 | return $lottieplayer; 218 | 219 | } 220 | 221 | } 222 | --------------------------------------------------------------------------------