Skip to content

Instantly share code, notes, and snippets.

@jesperlauridsen
Created March 8, 2018 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesperlauridsen/f19bbf882a81bb1d37748a004a76d963 to your computer and use it in GitHub Desktop.
Save jesperlauridsen/f19bbf882a81bb1d37748a004a76d963 to your computer and use it in GitHub Desktop.
Main file for CookiePolicy plugin
<?php
import('lib.pkp.classes.plugins.GenericPlugin');
class RDLCookiePolicyPlugin extends GenericPlugin {
/** @var bool Whether or not the header has been injected */
var $injected = false;
/**
* Called as a plugin is registered to the registry
* @param $category String Name of category plugin was registered to
* @return boolean True iff plugin initialized successfully; if false,
* the plugin will not be registered.
*/
function register($category, $path) {
$success = parent::register($category, $path);
if (!Config::getVar('general', 'installed') || defined('RUNNING_UPGRADE')) return true;
if ($success && $this->getEnabled()) {
// Insert RDLCookiePolicy into page tag to footer
HookRegistry::register('TemplateManager::display', array($this, 'displayTemplateHook'));
}
return $success;
}
/**
* Get the plugin display name.
* @return string
*/
function getDisplayName() {
return __('plugins.generic.RDLCookiePolicy.displayName');
}
/**
* Get the plugin description.
* @return string
*/
function getDescription() {
return __('plugins.generic.RDLCookiePolicy.description');
}
function getCanEnable() {
if(array_intersect(array(ROLE_ID_SITE_ADMIN), (array)$userRoles)) {
return true;
}
else {
return false;
}
}
function isSitePlugin() {
return true;
}
function displayTemplateHook($hookName, $params) {
if (!$this->injected) {
$this->injected = true;
$templateMgr =& $params[0];
$request = Application::getRequest();
$templateMgr->addJavaScript(
'cookiePolicy',
$request->getBaseUrl() . '/' . $this->getPluginPath() . '/js/cookiePolicy.js'
);
$templateMgr->addStyleSheet(
'cookiePolicyStyles',
$request->getBaseUrl() . '/' . $this->getPluginPath() . '/css/cookiePolicy.css'
);
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment