-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
808 additions
and
0 deletions.
There are no files selected for viewing
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,35 @@ | ||
# cookienotice-ojs-plugin | ||
|
||
A minimal, vanilla JS (ES6+) cookie notification plugin for [OJS](https://github.com/pkp/ojs) | ||
for use on [Publicera](https://publicera.kb.se), an OJS portal hosted by the National Library of Sweden. | ||
|
||
Installation | ||
------------ | ||
* Download and extract the latest release from the [releases section](https://github.com/Kungbib/cookienotice-ojs-plugin/releases). | ||
|
||
* Place the `cookieNotice` directory in your OJS installation's `plugins/generic` directory, or use "Upload A New Plugin" from within the OJS admin interface, if you don't have direct access to the server. | ||
|
||
* Make sure the plugin is enabled under Administration -> Site Settings -> Plugins (under "Generic Plugins"). | ||
|
||
Note that this is a site-wide plugin. It can only be activated/deactivated on site level. | ||
|
||
It simply loads a tiny bit of JS that checks whether the cookie `cookieNotice` has been set. If not, | ||
it injects some HTML with cookie information and a button. If the button is clicked, the cookie is set | ||
and the cookie information disappears. | ||
|
||
If you find that the cookie notice is only shown on the main site and not on individual journals, `cd` | ||
to the OJS root directory and run: | ||
|
||
php lib/pkp/tools/installPluginVersion.php plugins/generic/cookieNotice/version.xm | ||
|
||
Creating a new release | ||
---------------------- | ||
Bump the plugin version in `cookieNotice/version.xml`. | ||
|
||
Merge develop into master. | ||
|
||
In the root directory (cookienotice-ojs-plugin), create a tar file with the latest code: | ||
``` | ||
tar czf cookieNotice.tar.gz --directory=$(pwd) cookieNotice/ | ||
``` | ||
Create a new GitHub release, tag the new version (`v.<M>.<m>.<p>`) and attach `cookieNotice.tar.gz`. |
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,47 @@ | ||
<?php | ||
import('lib.pkp.classes.plugins.GenericPlugin'); | ||
|
||
class CookieNoticePlugin extends GenericPlugin { | ||
public function register($category, $path, $mainContextId = NULL) { | ||
$success = parent::register($category, $path); | ||
|
||
if ($success && $this->getEnabled()) { | ||
$request = Application::get()->getRequest(); | ||
$templateMgr = TemplateManager::getManager($request); | ||
$templateMgr->addStyleSheet( | ||
'cookieNoticeStyles', | ||
$request->getBaseUrl() . '/' . $this->getPluginPath() . '/css/cookieNotice.css', | ||
['context' => ['backend', 'frontend']] | ||
); | ||
$templateMgr->addJavaScript( | ||
'cookieNoticeScript', | ||
$request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/cookieNotice.js', | ||
['context' => ['backend', 'frontend']] | ||
); | ||
} | ||
|
||
return $success; | ||
} | ||
|
||
public function getDisplayName() { | ||
return __('plugins.generic.cookieNotice.displayName'); | ||
} | ||
|
||
public function getDescription() { | ||
return __('plugins.generic.cookieNotice.description'); | ||
} | ||
|
||
public function isSitePlugin() { | ||
return true; | ||
} | ||
|
||
// Can only be activated at site level. | ||
function getCanEnable() { | ||
return !((bool) Application::get()->getRequest()->getContext()); | ||
} | ||
|
||
// Can only be deactivated at site level. | ||
function getCanDisable() { | ||
return !((bool) Application::get()->getRequest()->getContext()); | ||
} | ||
} |
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 @@ | ||
#cookie-notice button { | ||
text-transform: none; | ||
} | ||
|
||
.cookie-notice-hidden { | ||
display: none; | ||
} |
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,4 @@ | ||
<?php | ||
|
||
require_once('CookieNoticePlugin.inc.php'); | ||
return new CookieNoticePlugin(); |
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,20 @@ | ||
let cookieInfoUrl = 'https://publicera.kb.se/kakor'; | ||
let cookieDurationDays = 365; | ||
|
||
document.addEventListener('DOMContentLoaded', function() { | ||
if (!document.cookie.split(';').some((item) => item.trim().startsWith('cookieNotice='))) { | ||
const confirmationHtml = ` | ||
<div id="cookie-notice" class="alert alert-primary" role="alert"> | ||
<div class="container"> | ||
Genom att använda Publicera godkänner du de kakor (cookies) som finns på webbplatsen. <a href="${cookieInfoUrl}">Läs mer om hur vi använder kakor</a>. | ||
<button id="cookie-notice-confirmation" type="button" class="btn btn-secondary btn-light btn-sm">OK, jag förstår</button> | ||
</div> | ||
</div> | ||
`; | ||
document.body.insertAdjacentHTML('afterbegin', confirmationHtml); | ||
document.getElementById('cookie-notice-confirmation').addEventListener('click', function() { | ||
document.cookie = `cookieNotice=1; max-age=${60*60*24*cookieDurationDays}`; | ||
document.getElementById('cookie-notice').classList.add('cookie-notice-hidden'); | ||
}); | ||
} | ||
}); |
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,5 @@ | ||
msgid "plugins.generic.cookieNotice.displayName" | ||
msgstr "Cookie Notice Plugin" | ||
|
||
msgid "plugins.generic.cookieNotice.description" | ||
msgstr "Turns on a site-wide cookie notice." |
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,5 @@ | ||
msgid "plugins.generic.cookieNotice.displayName" | ||
msgstr "Cookie-notifieringsplugin" | ||
|
||
msgid "plugins.generic.cookieNotice.description" | ||
msgstr "Informerar besökare om att cookies används." |
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 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE version SYSTEM "../../../lib/pkp/dtd/pluginVersion.dtd"> | ||
<version> | ||
<application>cookieNotice</application> | ||
<type>plugins.generic</type> | ||
<release>1.0.0</release> | ||
<date>2021-05-25</date> | ||
<lazy-load>1</lazy-load> | ||
<sitewide>1</sitewide> | ||
<class>CookieNoticePlugin</class> | ||
</version> |