first commit
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
/**
|
||||
* @package n3t Cookie Consent
|
||||
* @author Pavel Poles - n3t.cz
|
||||
* @copyright (C) 2021 - Pavel Poles - n3t.cz
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
**/
|
||||
|
||||
use Joomla\CMS\Application\ApplicationHelper;
|
||||
use Joomla\CMS\Form\FormHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Version;
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
defined( '_JEXEC' ) or die( 'Restricted access' );
|
||||
|
||||
FormHelper::loadFieldClass('subform');
|
||||
|
||||
class JFormFieldN3tCookieConsentBlocks extends JFormFieldSubform
|
||||
{
|
||||
protected $type = 'N3tCookieConsentBlocks';
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
$input = '';
|
||||
if (PluginHelper::isEnabled('system', 'n3tcookieconsent')) {
|
||||
Text::script('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_SCAN_INSTRUCTIONS');
|
||||
Text::script('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_SCAN_BTN');
|
||||
|
||||
$script = "const n3tCookieConsentScan = function() {" .
|
||||
" console.log('Starting scan');" .
|
||||
" let iframe = document.createElement('iframe');" .
|
||||
" let body = document.getElementsByTagName('body')[0];" .
|
||||
" iframe.src = '" . Route::link('site', 'index.php?n3tcc_scan=' . ApplicationHelper::getHash('plg_system_n3tcookiesconsent')) . "';" .
|
||||
" iframe.style = 'position: fixed; z-index: 10000; top: 0; left: 0; width: 100%; height: 100%; border: none;';" .
|
||||
" body.style = 'overflow: hidden';" .
|
||||
" body.appendChild(iframe);" .
|
||||
" window.addEventListener('message', function (e) {" .
|
||||
" if (e.data == 'n3t_cookie_consent_finish_scan') {" .
|
||||
" window.location.reload();" .
|
||||
" }" .
|
||||
" });" .
|
||||
"}";
|
||||
if (Version::MAJOR_VERSION < 4)
|
||||
Factory::getDocument()->addScriptDeclaration($script);
|
||||
else {
|
||||
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
|
||||
$wa->addInlineScript($script);
|
||||
}
|
||||
$input.= '<div class="text-right text-end">' .
|
||||
'<a href="' . Route::_('index.php?option=com_ajax&group=system&format=raw&plugin=N3tCookieConsentDefaults') . '" class="btn btn-danger" ' .
|
||||
'onclick="return confirm(\'' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_DEFAULTS_CONFIRM') . '\')">' .
|
||||
'<i class="icon-trash"></i> ' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_DEFAULTS_BTN') .
|
||||
'</a> ';
|
||||
$input.=
|
||||
'<a href="#" class="btn btn-primary" target="_blank " ' .
|
||||
'onclick="if (confirm(Joomla.JText._(\'PLG_SYSTEM_N3TCOOKIECONSENT_CFG_SCAN_INSTRUCTIONS\'))) {n3tCookieConsentScan()} return false;">' .
|
||||
'<i class="icon-search"></i> ' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_SCAN_BTN') .
|
||||
'</a>' .
|
||||
'</div>';
|
||||
} else
|
||||
$input.= '<p class="alert alert-warning">' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_COOKIES_ENABLE_PLUGIN_FIRST') . '</p>';
|
||||
|
||||
return $input . parent::getInput();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* @package n3t Cookie Consent
|
||||
* @author Pavel Poles - n3t.cz
|
||||
* @copyright (C) 2021 - Pavel Poles - n3t.cz
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
**/
|
||||
|
||||
use Joomla\CMS\Form\FormHelper;
|
||||
|
||||
defined( '_JEXEC' ) or die( 'Restricted access' );
|
||||
|
||||
FormHelper::loadFieldClass('text');
|
||||
|
||||
class JFormFieldN3tCookieConsentCookie extends JFormFieldText
|
||||
{
|
||||
protected $type = 'N3tCookieConsentCookie';
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
$input = parent::getInput();
|
||||
|
||||
$input = '<div class="input-group flex-nowrap input-append">' . $input .
|
||||
// space after blank is because of Joomla 4 default template adding icon to _blank links
|
||||
'<a href="#" class="btn btn-info" target="_blank " onclick="this.href=\'https://cookiedatabase.org/?s=\'+this.previousElementSibling.value.replace(/^\^/, \'\');"><i class="icon-help"></i></a>' .
|
||||
'</div>';
|
||||
return $input;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
/**
|
||||
* @package n3t Cookie Consent
|
||||
* @author Pavel Poles - n3t.cz
|
||||
* @copyright (C) 2021 - Pavel Poles - n3t.cz
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
**/
|
||||
|
||||
use Joomla\CMS\Form\FormHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
|
||||
defined( '_JEXEC' ) or die( 'Restricted access' );
|
||||
|
||||
FormHelper::loadFieldClass('subform');
|
||||
|
||||
class JFormFieldN3tCookieConsentCookies extends JFormFieldSubform
|
||||
{
|
||||
protected $type = 'N3tCookieConsentCookies';
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
$input = parent::getInput();
|
||||
|
||||
static $index = 0;
|
||||
$index++;
|
||||
|
||||
$input = '<a href="#" data-toggle="collapse" data-target="#n3tCCCookies' . $index . '" data-bs-toggle="collapse" data-bs-target="#n3tCCCookies' . $index . '">' .
|
||||
'<i class="icon-eye"></i> ' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_COLLAPSE_COOKIES') .
|
||||
'</a>' .
|
||||
'<div class="collapse show in" id="n3tCCCookies' . $index . '">' . $input . '</div>';
|
||||
return $input;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* @package n3t Cookie Consent
|
||||
* @author Pavel Poles - n3t.cz
|
||||
* @copyright (C) 2021 - Pavel Poles - n3t.cz
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
**/
|
||||
|
||||
use Joomla\CMS\Form\FormField;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
defined( '_JEXEC' ) or die( 'Restricted access' );
|
||||
|
||||
class JFormFieldN3tCookieConsentExport extends FormField
|
||||
{
|
||||
protected $type = 'N3tCookieConsentExport';
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
if (PluginHelper::isEnabled('system', 'n3tcookieconsent'))
|
||||
return '<a href="' . Route::_('index.php?option=com_ajax&group=system&format=raw&plugin=N3tCookieConsentExport') . '" download class="btn btn-primary" id="n3t-cookie-consent-export">' .
|
||||
'<i class="icon-download"></i> ' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_EXPORT_BTN') .
|
||||
'</a>';
|
||||
|
||||
return '<p class="alert alert-warning">' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_ENABLE_PLUGIN_FIRST') . '</p>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* @package n3t Cookie Consent
|
||||
* @author Pavel Poles - n3t.cz
|
||||
* @copyright (C) 2021 - Pavel Poles - n3t.cz
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
**/
|
||||
|
||||
use Joomla\CMS\Form\FormField;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
defined( '_JEXEC' ) or die( 'Restricted access' );
|
||||
|
||||
class JFormFieldN3tCookieConsentExportLog extends FormField
|
||||
{
|
||||
protected $type = 'N3tCookieConsentExportLog';
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
if (PluginHelper::isEnabled('system', 'n3tcookieconsent'))
|
||||
return '<a href="' . Route::_('index.php?option=com_ajax&group=system&format=raw&plugin=N3tCookieConsentExportLog') . '" download class="btn btn-primary" id="n3t-cookie-consent-export-log">' .
|
||||
'<i class="icon-file"></i> ' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_EXPORT_LOG_BTN') .
|
||||
'</a>';
|
||||
|
||||
return '<p class="alert alert-warning">' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_ENABLE_PLUGIN_FIRST') . '</p>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
/**
|
||||
* @package n3t Cookie Consent
|
||||
* @author Pavel Poles - n3t.cz
|
||||
* @copyright (C) 2021 - Pavel Poles - n3t.cz
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
**/
|
||||
|
||||
use Joomla\CMS\Form\FormField;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\CMS\Router\Route;
|
||||
|
||||
defined( '_JEXEC' ) or die( 'Restricted access' );
|
||||
|
||||
class JFormFieldN3tCookieConsentImport extends FormField
|
||||
{
|
||||
protected $type = 'N3tCookieConsentImport';
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
if (PluginHelper::isEnabled('system', 'n3tcookieconsent'))
|
||||
return
|
||||
'<input type="file" name="n3tcc[import]" accept="application/json" />' .
|
||||
'<button type="submit" class="btn btn-primary" formaction="' . Route::_('index.php?option=com_ajax&group=system&format=raw&plugin=N3tCookieConsentImport') . '" formenctype="multipart/form-data" formmethod="post">' .
|
||||
'<i class="icon-upload"></i> ' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_IMPORT_BTN') .
|
||||
'</button>';
|
||||
|
||||
return '<p class="alert alert-warning">' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_ENABLE_PLUGIN_FIRST') . '</p>';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
/**
|
||||
* @package n3t Cookie Consent
|
||||
* @author Pavel Poles - n3t.cz
|
||||
* @copyright (C) 2021 - Pavel Poles - n3t.cz
|
||||
* @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
|
||||
**/
|
||||
|
||||
use Joomla\CMS\Form\FormField;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\Plugin\PluginHelper;
|
||||
use Joomla\Registry\Registry;
|
||||
use Joomla\CMS\Version;
|
||||
|
||||
defined( '_JEXEC' ) or die( 'Restricted access' );
|
||||
|
||||
class JFormFieldN3tCookieConsentUsage extends FormField
|
||||
{
|
||||
protected $type = 'N3tCookieConsentUsage';
|
||||
|
||||
public function __construct($form = null)
|
||||
{
|
||||
parent::__construct($form);
|
||||
if (Version::MAJOR_VERSION >= 4)
|
||||
$this->hiddenLabel = true;
|
||||
}
|
||||
|
||||
protected function getInput()
|
||||
{
|
||||
if (Version::MAJOR_VERSION >= 4) {
|
||||
return $this->getHtml();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function getLabel()
|
||||
{
|
||||
if (Version::MAJOR_VERSION < 4) {
|
||||
// Joomla 3 hack inspired by Note field
|
||||
return '</div><div>' . $this->getHtml();
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private function getHtml()
|
||||
{
|
||||
$html = '';
|
||||
if (!PluginHelper::isEnabled('system', 'n3tcookieconsent'))
|
||||
$html.= '<p class="alert alert-warning">' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_USAGE_ENABLE_PLUGIN_FIRST') . '</p>';
|
||||
else {
|
||||
$plugin = PluginHelper::getPlugin('system', 'n3tcookieconsent');
|
||||
$params = new Registry($plugin->params);
|
||||
|
||||
$hasDefinition = false;
|
||||
$blocks = (array)$params->get('blocks', []);
|
||||
foreach ($blocks as $block) {
|
||||
if (isset($block->cookies) && !empty($block->cookies)) {
|
||||
$hasDefinition = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$hasDefinition)
|
||||
$html.= '<p class="alert alert-warning">' . Text::_('PLG_SYSTEM_N3TCOOKIECONSENT_CFG_USAGE_SETUP_COOKIES_FIRST') . '</p>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user