Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Champion committed Apr 11, 2017
0 parents commit 998b895
Show file tree
Hide file tree
Showing 10 changed files with 570 additions and 0 deletions.
339 changes: 339 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

61 changes: 61 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
ExternalDisclaimer
==================

A Joomla plugin to add a disclaimer popup when users click on an external link on your site.


Version History
----------------

* 1.0.0 Initial release.


Installation
----------------

This is a standard Joomla plugin. Installation is via Joomla's extension manager. As with all plugins, remember that it must also be activated after being installed.


Configuration
-------------

In the plugin configuration, set the options as follows:

* Internal Domains:

As a minimum, this should contain your site's domain name. So if your site's URL is `http://www.example.com`, you would enter `www.example.com` into this field.

You may specify multiple domains, one per line. So you could have `www.example.com` on one line and `example.com` on another line.

You can also specify any other domains here that you want the plugin to consider as 'internal'. This would be useful for sites that have a number of sub-domains.

Once the plugin is activated, any links on your site to any sites not listed in this field will generate a popup alert message. Make sure you include all the sites that you link to that you don't this to happen.

* Redirect patterns

It is possible that you may have some links internally in your site that actually redirect to external sites. For example, if you use the Joomla Weblinks plugin, the links generated by this plugin work like this.

This field allows you to specify that these links should generate the disclaimer alert. You can use regular expression patterns, one per line, to specify which links it should apply to.

For the example of the weblinks plugin, a pattern that would match the default URL for these might look like this: `task=weblink\.go`

* Disclaimer Text

This is the message that you want to appear in the popup alert.


Motivation
----------------

This plugin was written to satisfy a need for a specific website. I appreciate that most sites will not need this kind of functionality, and most users will find it annoying.


Todo List and Known Issues
--------------------------

None known.


License
----------------
As with all Joomla extensions and Joomla itself, this plugin is licensed under the GPLv2. The full license document should have been included with the source code.
27 changes: 27 additions & 0 deletions externaldisclaimer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* @package Externaldisclaimer
* @type Plugin (System)
* @version 1.0.0
* @author Simon Champion
* @copyright (C) 2016 Simon Champion
* @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html
**/

defined('_JEXEC') or die;

class plgSystemExternaldisclaimer extends JPlugin
{
public function onBeforeCompileHead()
{
$app = JFactory::getApplication();
if ($app->isAdmin()) {
return;
}

$args = json_encode($this->params->toArray());
$doc = JFactory::getDocument();
$doc->addScript(JUri::root().'media/plg_system_externaldisclaimer/js/externalDisclaimer.js');
$doc->addScriptDeclaration("externalDisclaimer(jQuery,{$args});");
}
}
38 changes: 38 additions & 0 deletions externaldisclaimer.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<extension version="3.0" type="plugin" group="system" method="upgrade">
<name>PLG_SYSTEM_EXTERNALDISCLAIMER_NAME</name>
<version>1.0.0</version>
<creationDate>April 2017</creationDate>
<author>Simon Champion</author>
<authorEmail>[email protected]</authorEmail>
<authorUrl></authorUrl>
<copyright>(C) 2017 Simon Champion</copyright>
<license>GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html</license>
<description>PLG_SYSTEM_EXTERNALDISCLAIMER_DESCRIPTION</description>

<files>
<filename>index.html</filename>
<filename plugin="externaldisclaimer">externaldisclaimer.php</filename>
</files>
<media destination="plg_system_externaldisclaimer" folder="media">
<folder>js</folder>
<file>index.html</file>
</media>

<languages>
<language tag="en-GB">language/en-GB/en-GB.plg_system_externaldisclaimer.sys.ini</language>
</languages>

<config>
<fields name="params">
<fieldset name="basic">
<field name="internal" type="textarea" description="PLG_SYSTEM_EXTERNALDISCLAIMER_INTERNALDOMAINS_DESC" label="PLG_SYSTEM_EXTERNALDISCLAIMER_INTERNALDOMAINS_LABEL" default="" />
<field name="external" type="textarea" description="PLG_SYSTEM_EXTERNALDISCLAIMER_REDIRECTS_DESC" label="PLG_SYSTEM_EXTERNALDISCLAIMER_REDIRECTS_LABEL" default="" />
<field name="disclaimer" type="textarea" description="PLG_SYSTEM_EXTERNALDISCLAIMER_DISCLAIMER_DESC" label="PLG_SYSTEM_EXTERNALDISCLAIMER_DISCLAIMER_LABEL" default="Please be advised that this is a link to an external website. The operators of the this site cannot accept any responsibility for the content of this external site." />
</fieldset>
</fields>
</config>
<updateservers>
<server type="extension" priority="2" name="External Disclaimer Updates">https://raw.githubusercontent.com/Spudley/plg_system_externaldisclaimer/master/update.xml</server>
</updateservers>
</extension>
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<html><head><title></title></head><body></body></html>
18 changes: 18 additions & 0 deletions language/en-GB/en-GB.plg_system_externaldisclaimer.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; @package Externaldisclaimer
; @language English
; @version 1.0.0
; @author Simon Champion
; @license GNU/GPLv2 http://www.gnu.org/licenses/gpl-2.0.html

PLG_SYSTEM_EXTERNALDISCLAIMER_NAME="System - Externaldisclaimer"
PLG_SYSTEM_EXTERNALDISCLAIMER_DESCRIPTION="This plugin generates a popup message whenever your users click on an external URL."
PLG_SYSTEM_EXTERNALDISCLAIMER="System - Externaldisclaimer"

PLG_SYSTEM_EXTERNALDISCLAIMER_INTERNALDOMAINS_DESC="Enter the domain or domains that you consider internal. One domain per line. No http or slashes. Typically this would be the domain of the site itself, but may also include other sites in your network."
PLG_SYSTEM_EXTERNALDISCLAIMER_INTERNALDOMAINS_LABEL="Internal Domains"

PLG_SYSTEM_EXTERNALDISCLAIMER_REDIRECTS_DESC="This is for URLs that look like they are part of your site but actually redirect to a third party. eg URLs generated by the Weblinks extension."
PLG_SYSTEM_EXTERNALDISCLAIMER_REDIRECTS_LABEL="Redirect patterns"

PLG_SYSTEM_EXTERNALDISCLAIMER_DISCLAIMER_DESC="Enter the disclaimer text that you wish to appear when the external links are clicked."
PLG_SYSTEM_EXTERNALDISCLAIMER_DISCLAIMER_LABEL="Disclaimer Text"
2 changes: 2 additions & 0 deletions media/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!DOCTYPE html>
<html><head><title></title></head><body></body></html>
28 changes: 28 additions & 0 deletions media/js/externalDisclaimer-static.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Popup message if clicking on an external link.
* Excludes local links within our sub-domains.
*/
(function($) {
var externalRedirects = [
"task=weblink\\.go"
];
var disclaimer = 'Please be advised that this is a link to an external website. The operators of the YJ Resource Hub cannot accept any responsibility for the content of this site.';

$(document).on('click','a', function() {
var isLocal = !this.hostname || this.hostname.match(/yjresourcehub\.uk$/);
if (isLocal && !hasExternalRedirects($(this).attr('href'))) {
return true; //no alert needed for internal links.
}

return confirm(disclaimer);
});

var hasExternalRedirects = function(str) {
for (i=0; i<externalRedirects.length;i++) {
if(str.match(RegExp(externalRedirects[i]))) {
return true;
}
}
return false;
}
})(jQuery);
37 changes: 37 additions & 0 deletions media/js/externalDisclaimer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Popup message if clicking on an external link.
* Excludes local links within our sub-domains.
*/
var externalDisclaimer = function($, args) {
var internalHosts = args.internal.split(/[\n\r]+/);
var externalRedirects = args.external.split(/[\n\r]+/);
var disclaimer = args.disclaimer;

$(document).on('click','a', function() {
if (isLocal(this.hostname) && !hasExternalRedirects($(this).attr('href'))) {
return true; //no alert needed for internal links.
}

return confirm(disclaimer);
});

var isLocal = function(hostname) {
if (!hostname) {
return true;
}
for (i=0; i<internalHosts.length;i++) {
if(hostname === internalHosts[i]) {
return true;
}
}
return false;
}
var hasExternalRedirects = function(str) {
for (i=0; i<externalRedirects.length;i++) {
if(str.match(RegExp(externalRedirects[i]))) {
return true;
}
}
return false;
}
}
18 changes: 18 additions & 0 deletions update.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<updates>
<update>
<name>External Disclaimer</name>
<description>Pops up a disclaimer message when clicking on an external link within your site</description>
<element>externaldisclaimer</element>
<type>plugin</type>
<folder>content</folder>
<version>1.0.0</version>
<client>0</client>
<infourl title="External Disclaimer plugin">https://github.com/Spudley/plg_content_externaldisclaimer/releases/tag/1.1.0</infourl>
<downloads>
<downloadurl type="full" format="zip">https://github.com/Spudley/plg_content_externaldisclaimer/archive/1.1.0.zip</downloadurl>
</downloads>
<targetplatform name="joomla" version="3.[56789]" />
<php_minimum>5.4.0</php_minimum>
</update>
</updates>

0 comments on commit 998b895

Please sign in to comment.