Skip to content

Commit

Permalink
Port my plugin plg_content_consentbox as plg_content_confirmconsent f…
Browse files Browse the repository at this point in the history
…or the joomla core Fixes #6 (#12)

* inital port to the joomla core

* add com_mailto as supported form (requires joomla#20265)

* install & update SQL & mark as core extension

* bump version to trigger drone

* new line & drone

* implement consentbox text based on the work by @brianteeman thanks!

* thanks drone

* new line

* doc block

* rename plugin to ConfirmConsent

* fix inine comments

* typo thanks @sandewt

* implement LanguageAssociations thanks @infograf768

* fix check

* move the update sql's to its own files to avoid merge conflicts

* fix postgresql file

* thanks @infograf768

* fix problems fund by @infograf768

* extend description

* implement modal support thanks @infograf768

* new text thanks @brianteeman

* drone

* add missing period

* thanks @brianteeman

* thanks @Sandra97

* remove Scalar types

* fix association

* fix comments thanks @sandewt

* class var type

* fix language string and us another namesprace

* the 2nd field is package_id

* the 2nd field is package_id

* the 2nd field is package_id

* add com_privacy.request
  • Loading branch information
zero-24 authored and mbabker committed May 17, 2018
1 parent 5ce62f6 commit bdc5816
Show file tree
Hide file tree
Showing 11 changed files with 277 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `manifest_cache`, `params`, `custom_data`, `system_data`, `checked_out`, `checked_out_time`, `ordering`, `state`) VALUES
(481, 0, 'plg_content_confirmconsent', 'plugin', 'confirmconsent', 'content', 0, 0, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "manifest_cache", "params", "custom_data", "system_data", "checked_out", "checked_out_time", "ordering", "state") VALUES
(481, 0, 'plg_content_confirmconsent', 'plugin', 'confirmconsent', 'content', 0, 0, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SET IDENTITY_INSERT #__extensions ON;

INSERT INTO [#__extensions] ([extension_id], [package_id], [name], [type], [element], [folder], [client_id], [enabled], [access], [protected], [manifest_cache], [params], [custom_data], [system_data], [checked_out], [checked_out_time], [ordering], [state]) VALUES
(481, 0, 'plg_content_confirmconsent', 'plugin', 'confirmconsent', 'content', 0, 0, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0);

SET IDENTITY_INSERT #__extensions OFF;
11 changes: 11 additions & 0 deletions administrator/language/en-GB/en-GB.plg_content_confirmconsent.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
; Joomla! Project
; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_CONTENT_CONFIRMCONSENT_CONSENTBOX_LABEL="Privacy Note"
PLG_CONTENT_CONFIRMCONSENT_FIELD_ARTICLE_DESC="Select the desired Privacy article from the list."
PLG_CONTENT_CONFIRMCONSENT_FIELD_ARTICLE_LABEL="Privacy Article"
PLG_CONTENT_CONFIRMCONSENT_FIELD_NOTE_DEFAULT="By submitting this form you agree to the Privacy Policy of this website and the storing of the submitted information."
PLG_CONTENT_CONFIRMCONSENT_FIELD_NOTE_DESC="Write a summary of the site's privacy policy."
PLG_CONTENT_CONFIRMCONSENT_FIELD_NOTE_LABEL="Short Privacy Policy"
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
; Note : All ini files need to be saved as UTF-8

PLG_CONTENT_CONFIRMCONSENT="Content - ConfirmConsent"
PLG_CONTENT_CONFIRMCONSENT_XML_DESCRIPTION="This plugin adds a required consent checkbox to a form eg. the core contact component."
1 change: 1 addition & 0 deletions installation/sql/mysql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,7 @@ INSERT INTO `#__extensions` (`extension_id`, `package_id`, `name`, `type`, `elem
(478, 0, 'plg_editors-xtd_fields', 'plugin', 'fields', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(479, 0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(480, 0, 'plg_system_sessiongc', 'plugin', 'sessiongc', 'system', 0, 1, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(481, 0, 'plg_content_confirmconsent', 'plugin', 'confirmconsent', 'content', 0, 0, 1, 0, '', '', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(503, 0, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(504, 0, 'hathor', 'template', 'hathor', '', 1, 1, 1, 0, '', '{"showSiteName":"0","colourChoice":"0","boldText":"0"}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
(506, 0, 'protostar', 'template', 'protostar', '', 0, 1, 1, 0, '', '{"templateColor":"","logoFile":"","googleFont":"1","googleFontName":"Open+Sans","fluidContainer":"0"}', '', '', 0, '0000-00-00 00:00:00', 0, 0),
Expand Down
1 change: 1 addition & 0 deletions installation/sql/postgresql/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "elem
(478, 0, 'plg_editors-xtd_fields', 'plugin', 'fields', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0),
(479, 0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0),
(480, 0, 'plg_system_sessiongc', 'plugin', 'sessiongc', 'system', 0, 1, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0),
(481, 0, 'plg_content_confirmconsent', 'plugin', 'confirmconsent', 'content', 0, 0, 1, 0, '', '', '', '', 0, '1970-01-01 00:00:00', 0, 0),
(503, 0, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '1970-01-01 00:00:00', 0, 0),
(504, 0, 'hathor', 'template', 'hathor', '', 1, 1, 1, 0, '', '{"showSiteName":"0","colourChoice":"0","boldText":"0"}', '', '', 0, '1970-01-01 00:00:00', 0, 0),
(506, 0, 'protostar', 'template', 'protostar', '', 0, 1, 1, 0, '', '{"templateColor":"","logoFile":"","googleFont":"1","googleFontName":"Open+Sans","fluidContainer":"0"}', '', '', 0, '1970-01-01 00:00:00', 0, 0),
Expand Down
1 change: 1 addition & 0 deletions installation/sql/sqlazure/joomla.sql
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ INSERT INTO "#__extensions" ("extension_id", "package_id", "name", "type", "elem
(478, 0, 'plg_editors-xtd_fields', 'plugin', 'fields', 'editors-xtd', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0),
(479, 0, 'plg_sampledata_blog', 'plugin', 'blog', 'sampledata', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0),
(480, 0, 'plg_system_sessiongc', 'plugin', 'sessiongc', 'system', 0, 1, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0),
(481, 0, 'plg_content_confirmconsent', 'plugin', 'confirmconsent', 'content', 0, 0, 1, 0, '', '', '', '', 0, '1900-01-01 00:00:00', 0, 0),
(503, 0, 'beez3', 'template', 'beez3', '', 0, 1, 1, 0, '', '{"wrapperSmall":"53","wrapperLarge":"72","sitetitle":"","sitedescription":"","navposition":"center","templatecolor":"nature"}', '', '', 0, '1900-01-01 00:00:00', 0, 0),
(504, 0, 'hathor', 'template', 'hathor', '', 1, 1, 1, 0, '', '{"showSiteName":"0","colourChoice":"0","boldText":"0"}', '', '', 0, '1900-01-01 00:00:00', 0, 0),
(506, 0, 'protostar', 'template', 'protostar', '', 0, 1, 1, 0, '', '{"templateColor":"","logoFile":"","googleFont":"1","googleFontName":"Open+Sans","fluidContainer":"0"}', '', '', 0, '1900-01-01 00:00:00', 0, 0),
Expand Down
1 change: 1 addition & 0 deletions libraries/src/Extension/ExtensionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ class ExtensionHelper
array('plugin', 'recaptcha', 'captcha', 0),

// Core plugin extensions - content
array('plugin', 'confirmconsent', 'content', 0),
array('plugin', 'contact', 'content', 0),
array('plugin', 'emailcloak', 'content', 0),
array('plugin', 'fields', 'content', 0),
Expand Down
202 changes: 202 additions & 0 deletions plugins/content/confirmconsent/confirmconsent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
<?php
/**
* @package Joomla.Plugin
* @subpackage Content.confirmconsent
*
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Factory;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Associations;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Plugin\CMSPlugin;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Uri\Uri;

/**
* The Joomla Core confirm consent plugin
*
* @since __DEPLOY_VERSION__
*/
class PlgContentConfirmConsent extends CMSPlugin
{
/**
* The Application object
*
* @var JApplicationSite
* @since __DEPLOY_VERSION__
*/
protected $app;

/**
* The Database object.
*
* @var JDatabaseDriver
* @since __DEPLOY_VERSION__
*/
protected $db;

/**
* Load the language file on instantiation.
*
* @var boolean
* @since __DEPLOY_VERSION__
*/
protected $autoloadLanguage = true;

/**
* The supported form contexts
*
* @var array
* @since __DEPLOY_VERSION__
*/
protected $supportedContext = array(
'com_contact.contact',
'com_mailto.mailto',
'com_privacy.request',
);

/**
* Add additional fields to the supported forms
*
* @param JForm $form The form to be altered.
* @param mixed $data The associated data for the form.
*
* @return boolean
*
* @since __DEPLOY_VERSION__
*/
public function onContentPrepareForm(JForm $form, $data)
{
if ($this->app->isClient('administrator') || !in_array($form->getName(), $this->supportedContext))
{
return true;
}

// Get the consent box Text & the selected privacyarticle
$consentboxText = (string) $this->params->get('consentbox_text', Text::_('PLG_CONTENT_CONFIRMCONSENT_FIELD_NOTE_DEFAULT'));
$privacyarticle = $this->params->get('privacy_article', false);

// When we have a article just add it arround to the text
if ($privacyarticle)
{
HTMLHelper::_('behavior.modal');

$consentboxText = $this->getAssignedArticleUrl($privacyarticle, $consentboxText);
}

$form->load('
<form>
<fieldset name="default">
<field
name="consentbox"
type="checkboxes"
label="PLG_CONTENT_CONFIRMCONSENT_CONSENTBOX_LABEL"
required="true"
>
<option value="0">' . htmlspecialchars($consentboxText, ENT_COMPAT, 'UTF-8') . '</option>
</field>
</fieldset>
</form>
');

return true;
}

/**
* Return the url of the assigned article based on the current user language
*
* @param integer $articleId The form to be altered.
* @param string $consentboxText The consent box text
*
* @return string Returns the a tag containing everything for the modal
*
* @since __DEPLOY_VERSION__
*/
private function getAssignedArticleUrl($articleId, $consentboxText)
{
// Get the info from the article
$query = $this->db->getQuery(true)
->select($this->db->quoteName(array('id', 'catid', 'language')))
->from($this->db->quoteName('#__content'))
->where($this->db->quoteName('id') . ' = ' . (int) $articleId);
$this->db->setQuery($query);

$attribs = array();
$attribs['class'] = 'modal';
$attribs['rel'] = '{handler: \'iframe\', size: {x:800, y:500}}';

try
{
$article = $this->db->loadObject();
}
catch (JDatabaseExceptionExecuting $e)
{
// Something at the database layer went wrong
return HTMLHelper::_(
'link',
Route::_(
'index.php?option=com_content&view=article&id='
. $articleId . '&tmpl=component'
),
$consentboxText,
$attribs
);
}

// Register ContentHelperRoute
JLoader::register('ContentHelperRoute', JPATH_BASE . '/components/com_content/helpers/route.php');

if (!Associations::isEnabled())
{
return HTMLHelper::_('link',
Route::_(
ContentHelperRoute::getArticleRoute(
$article->id,
$article->catid,
$article->language
) . '&tmpl=component'
),
$consentboxText,
$attribs
);
}

$associatedArticles = Associations::getAssociations('com_content', '#__content', 'com_content.item', $article->id);
$currentLang = Factory::getLanguage()->getTag();

if (isset($associatedArticles) && $currentLang !== $article->language && array_key_exists($currentLang, $associatedArticles))
{
return HTMLHelper::_('link',
Route::_(
ContentHelperRoute::getArticleRoute(
$associatedArticles[$currentLang]->id,
$associatedArticles[$currentLang]->catid,
$associatedArticles[$currentLang]->language
) . '&tmpl=component'
),
$consentboxText,
$attribs
);
}

// Association is enabled but this article is not associated
return HTMLHelper::_(
'link',
Route::_(
'index.php?option=com_content&view=article&id='
. $article->id . '&catid=' . $article->catid
. '&tmpl=component&lang=' . $article->language
),
$consentboxText,
$attribs
);


}
}
43 changes: 43 additions & 0 deletions plugins/content/confirmconsent/confirmconsent.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.9" type="plugin" group="content" method="upgrade">
<name>plg_content_confirmconsent</name>
<author>Joomla! Project</author>
<creationDate>May 2018</creationDate>
<copyright>Copyright (C) 2005 - 2018 Open Source Matters. All rights reserved.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>admin@joomla.org</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>__DEPLOY_VERSION__</version>
<description>PLG_CONTENT_CONFIRMCONSENT_XML_DESCRIPTION</description>
<files>
<filename plugin="confirmconsent">confirmconsent.php</filename>
</files>
<config>
<fields name="params">
<fieldset name="basic" addfieldpath="/administrator/components/com_content/models/fields">
<field
name="consentbox_text"
type="textarea"
label="PLG_CONTENT_CONFIRMCONSENT_FIELD_NOTE_LABEL"
description="PLG_CONTENT_CONFIRMCONSENT_FIELD_NOTE_DESC"
hint="PLG_CONTENT_CONFIRMCONSENT_FIELD_NOTE_DEFAULT"
class="span12"
rows="7"
cols="20"
filter="html"
/>

<field
name="privacy_article"
type="modal_article"
label="PLG_CONTENT_CONFIRMCONSENT_FIELD_ARTICLE_LABEL"
description="PLG_CONTENT_CONFIRMCONSENT_FIELD_ARTICLE_DESC"
select="true"
new="true"
edit="true"
clear="true"
/>
</fieldset>
</fields>
</config>
</extension>

0 comments on commit bdc5816

Please sign in to comment.