<?php /** * @package JMP Modal & Popup * @version 1.0.0 * @copyright Copyright (C) 2021 JoomHelper.com * @license GNU 2 or later * @author JoomHelper */ // No direct access. defined('_JEXEC') or die; jimport('joomla.filesystem.folder'); class plgContentJMPModal extends JPlugin { public function __construct(& $subject, $config) { parent::__construct($subject, $config ); $this->loadLanguage(); } public function onContentPrepare($context, &$row, &$params, $page = 0) { $app = JFactory::getApplication(); $doc = JFactory::getDocument(); if($app->isClient('administrator')) return; $pattern = '/\{modal(.+?)?\}/m'; $count = 0; $row->text = preg_replace_callback($pattern, array( $this, 'replace_content' ), $row->text, -1, $count); $row->text = str_replace('{/modal}', '</div>', $row->text); if($count>0) { JHtml::_('jquery.framework'); $assets = JUri::base(true).'/plugins/content/jmpmodal/assets'; $doc->addStylesheet($assets.'/style.css'); $doc->addScript($assets.'/script.js'); } } public function replace_content($matches) { $params = []; if(isset($matches[1])) { $params = preg_split("/[\s]+/", $matches[1]); } $h='<div class="jmpModal hidden"'; if(!empty($params)) { foreach($params as $param) { $param = trim($param); if($param=='') continue; $h.=' data-'.$param; } } $h.=' data-close="'.$this->params->get('close', 'Close me!').'"'; $h.='>'; return $h; } }