first commit
This commit is contained in:
162
plugins/content/quantummanagercontent/quantummanagercontent.php
Normal file
162
plugins/content/quantummanagercontent/quantummanagercontent.php
Normal file
@@ -0,0 +1,162 @@
|
||||
<?php
|
||||
/**
|
||||
* @package quantummanagercontent
|
||||
* @author Dmitry Tsymbal <cymbal@delo-design.ru>
|
||||
* @copyright Copyright © 2019 Delo Design & NorrNext. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see license.txt
|
||||
* @link https://www.norrnext.com
|
||||
*/
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Layout\FileLayout;
|
||||
use Joomla\CMS\Object\CMSObject;
|
||||
use Joomla\CMS\Plugin\CMSPlugin;
|
||||
use Joomla\CMS\Session\Session;
|
||||
|
||||
class PlgContentQuantummanagercontent extends CMSPlugin
|
||||
{
|
||||
/**
|
||||
* Load the language file on instantiation.
|
||||
*
|
||||
* @var boolean
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
protected $autoloadLanguage = true;
|
||||
|
||||
|
||||
/**
|
||||
* @param $context
|
||||
* @param $item
|
||||
* @param $params
|
||||
* @param int $page
|
||||
*
|
||||
*
|
||||
* @since version
|
||||
*/
|
||||
public function onContentPrepare($context, &$item, &$params, $page = 0)
|
||||
{
|
||||
// Prepare the text
|
||||
if (isset($item->text))
|
||||
{
|
||||
$item->text = $this->prepare($item->text, $context, $item);
|
||||
}
|
||||
|
||||
// Prepare the intro text
|
||||
if (isset($item->introtext))
|
||||
{
|
||||
$item->introtext = $this->prepare($item->introtext, $context, $item);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $string
|
||||
* @param $context
|
||||
* @param $item
|
||||
*
|
||||
* @return string|string[]|null
|
||||
*
|
||||
* @since version
|
||||
*/
|
||||
private function prepare($string, $context, $item)
|
||||
{
|
||||
|
||||
if(strpos($string, '[qmcontent]') === false)
|
||||
{
|
||||
return $string;
|
||||
}
|
||||
|
||||
JLoader::register('QuantummanagerbuttonHelper', JPATH_ROOT . '/plugins/editors-xtd/quantummanagerbutton/helper.php');
|
||||
$regex = "/\[qmcontent\](.*?)\[\/qmcontent\]/i";
|
||||
$string = preg_replace_callback($regex, static function ($matches) {
|
||||
$output = '';
|
||||
$content = &$matches[1];
|
||||
$before = '';
|
||||
$variables = '';
|
||||
$item = '';
|
||||
$after = '';
|
||||
|
||||
preg_replace_callback("/\[before\](.*?)\[\/before\]/i", function ($matchesBefore) use (&$before, &$output) {
|
||||
if(preg_match("#^\{\{.*?\}\}$#isu", $matchesBefore[1]))
|
||||
{
|
||||
$before = str_replace(['{', '}'], '', $matchesBefore[1]);
|
||||
$output .= QuantummanagerbuttonHelper::renderLayout($before);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= $before;
|
||||
}
|
||||
|
||||
}, $content);
|
||||
|
||||
preg_replace_callback("/\[template\](.*?)\[\/template\]/i", function ($matchesBefore) use (&$item) {
|
||||
if(preg_match("#^\{\{.*?\}\}$#isu", $matchesBefore[1]))
|
||||
{
|
||||
$item = str_replace(['{', '}'], '', $matchesBefore[1]);
|
||||
$item = QuantummanagerbuttonHelper::renderLayout($item);
|
||||
}
|
||||
else
|
||||
{
|
||||
$item = $matchesBefore[1];
|
||||
}
|
||||
}, $content);
|
||||
|
||||
preg_replace_callback("/\[variables\](.*?)\[\/variables\]/i", function ($matchesBefore) use (&$variables) {
|
||||
$variables = $matchesBefore[1];
|
||||
}, $content);
|
||||
|
||||
|
||||
if(!empty($variables) && !empty($item))
|
||||
{
|
||||
|
||||
$variables = json_decode($variables, JSON_OBJECT_AS_ARRAY);
|
||||
|
||||
if(is_array($variables) && count($variables) > 0)
|
||||
{
|
||||
foreach ($variables as $variable)
|
||||
{
|
||||
$outputItem = $item;
|
||||
$variablesFind = [];
|
||||
$variablesReplace = [];
|
||||
|
||||
foreach ($variable as $key => $value)
|
||||
{
|
||||
$variablesFind[] = $key;
|
||||
$variablesReplace[] = $value;
|
||||
}
|
||||
|
||||
$outputItem = str_replace($variablesFind, $variablesReplace, $outputItem);
|
||||
$outputItem = preg_replace("#[a-zA-Z]{1,}\=\"\"#isu", '', $outputItem);
|
||||
$output .= $outputItem;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
preg_replace_callback("/\[after\](.*?)\[\/after\]/i", function ($matchesBefore) use (&$after, &$output) {
|
||||
if(preg_match("#^\{\{.*?\}\}$#isu", $matchesBefore[1]))
|
||||
{
|
||||
$after = str_replace(['{', '}'], '', $matchesBefore[1]);
|
||||
$output .= QuantummanagerbuttonHelper::renderLayout($after);
|
||||
}
|
||||
else
|
||||
{
|
||||
$output .= $after;
|
||||
}
|
||||
|
||||
}, $content);
|
||||
|
||||
return $output;
|
||||
}, $string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<extension version="3.9" type="plugin" group="content" method="upgrade">
|
||||
<name>PLG_CONTENT_QUANTUMMANAGERCONTENT</name>
|
||||
<author>Tsymbal</author>
|
||||
<creationDate>18.09.2019</creationDate>
|
||||
<copyright>Copyright © 2020 Delo Design & NorrNext. All rights reserved.</copyright>
|
||||
<license>https://www.gnu.org/copyleft/gpl.html GNU/GPL</license>
|
||||
<authorEmail>cymbal@delo-design.ru</authorEmail>
|
||||
<authorUrl>https://www.norrnext.com</authorUrl>
|
||||
<version>1.4</version>
|
||||
<description>PLG_CONTENT_QUANTUMMANAGERCONTENT_DESCRIPTION</description>
|
||||
<scriptfile>script.php</scriptfile>
|
||||
<languages folder="language">
|
||||
<language tag="en-GB">en-GB/en-GB.plg_content_quantummanagercontent.ini</language>
|
||||
<language tag="en-GB">en-GB/en-GB.plg_content_quantummanagercontent.sys.ini</language>
|
||||
<language tag="ru-RU">ru-RU/ru-RU.plg_content_quantummanagercontent.ini</language>
|
||||
<language tag="ru-RU">ru-RU/ru-RU.plg_content_quantummanagercontent.sys.ini</language>
|
||||
</languages>
|
||||
<files>
|
||||
<filename plugin="quantummanagercontent">quantummanagercontent.php</filename>
|
||||
</files>
|
||||
</extension>
|
||||
52
plugins/content/quantummanagercontent/script.php
Normal file
52
plugins/content/quantummanagercontent/script.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* @package quantummanagercontent
|
||||
* @author Dmitry Tsymbal <cymbal@delo-design.ru>
|
||||
* @copyright Copyright © 2019 Delo Design & NorrNext. All rights reserved.
|
||||
* @license GNU General Public License version 3 or later; see license.txt
|
||||
* @link https://www.norrnext.com
|
||||
*/
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Installer\InstallerAdapter;
|
||||
|
||||
class plgContentQuantummanagercontentInstallerScript
|
||||
{
|
||||
/**
|
||||
* Runs right after any installation action.
|
||||
*
|
||||
* @param string $type Type of PostFlight action. Possible values are:
|
||||
* @param InstallerAdapter $parent Parent object calling object.
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
function postflight($type, $parent)
|
||||
{
|
||||
// Enable plugin
|
||||
if ($type == 'install')
|
||||
{
|
||||
$this->enablePlugin($parent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable plugin after installation.
|
||||
*
|
||||
* @param InstallerAdapter $parent Parent object calling object.
|
||||
*
|
||||
* @since 1.1.0
|
||||
*/
|
||||
protected function enablePlugin($parent)
|
||||
{
|
||||
// Prepare plugin object
|
||||
$plugin = new stdClass();
|
||||
$plugin->type = 'plugin';
|
||||
$plugin->element = $parent->getElement();
|
||||
$plugin->folder = (string) $parent->getParent()->manifest->attributes()['group'];
|
||||
$plugin->enabled = 1;
|
||||
|
||||
// Update record
|
||||
Factory::getDbo()->updateObject('#__extensions', $plugin, array('type', 'element', 'folder'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user