forked from joomla/joomla-cms
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Port my plugin plg_content_consentbox as plg_content_confirmconsent f…
…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
Showing
11 changed files
with
277 additions
and
0 deletions.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
administrator/components/com_admin/sql/updates/mysql/3.9.0-2018-05-03.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
2 changes: 2 additions & 0 deletions
2
administrator/components/com_admin/sql/updates/postgresql/3.9.0-2018-05-03.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
6 changes: 6 additions & 0 deletions
6
administrator/components/com_admin/sql/updates/sqlazure/3.9.0-2018-05-03.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
11
administrator/language/en-GB/en-GB.plg_content_confirmconsent.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
7 changes: 7 additions & 0 deletions
7
administrator/language/en-GB/en-GB.plg_content_confirmconsent.sys.ini
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
|
||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>[email protected]</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> |