Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Shobba committed Apr 6, 2017
1 parent 3394322 commit f140386
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 0 deletions.
12 changes: 12 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "YourVendorName/CookieNotice",
"type": "pimcore-plugin",
"require": {
"pimcore/installer-plugin": ">=1"
},
"autoload": {
"psr-4": {
"CookieNotice\\": "lib"
}
}
}
32 changes: 32 additions & 0 deletions controllers/IndexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php


class CookieNotice_IndexController extends \Pimcore\Controller\Action\Admin
{
public function indexAction()
{

}

public function jsAction()
{
$this->disableViewAutoRender();
$this->getResponse()->setHeader("Content-Type", "application/javascript");
$config = $this->getConfig();
echo "var COOKIE_NOTICE_TEXT = '" . str_replace("'", "\'", $config->text) . "';\n";
echo "var COOKIE_NOTICE_BUTTON = '" . str_replace("'", "\'", $config->buttonLabel) . "';\n";
}

public function cssAction()
{
$this->disableViewAutoRender();
$this->getResponse()->setHeader("Content-Type", "text/css");
$config = $this->getConfig();
echo $config->css;
}

private function getConfig() {
$fileContent = file_get_contents(PIMCORE_WEBSITE_PATH . '/var/config/cookienotice.json');
return json_decode(str_replace("\n", "", $fileContent));
}
}
7 changes: 7 additions & 0 deletions cookienotice.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"css": ".cookieNotice {}
.cookieNotice__text {}
.cookieNotice__button {}",
"text": "",
"buttonLabel": ""
}
Binary file added lib/.DS_Store
Binary file not shown.
69 changes: 69 additions & 0 deletions lib/CookieNotice/Plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace CookieNotice;

use Pimcore\API\Plugin as PluginLib;

class Plugin extends PluginLib\AbstractPlugin implements PluginLib\PluginInterface
{
const SAMPLE_CONFIG_XML = "/CookieNotice/cookienotice.json";
const CONFIG_XML = '/var/config/cookienotice.json';

public function init()
{
parent::init();

// register your events here

// using anonymous function
\Pimcore::getEventManager()->attach("frontend.controller.postInit", function ($event) {
// do something
$event->getTarget()->view->headLink()->appendStylesheet('/plugins/CookieNotice/static/css/cookieNotice.css');
$event->getTarget()->view->headLink()->appendStylesheet('/plugin/CookieNotice/index/css');
$event->getTarget()->view->headScript()->appendFile('/plugin/CookieNotice/index/js');
$event->getTarget()->view->headScript()->appendFile('/plugins/CookieNotice/static/js/cookieNotice.js');

});
}

public function handleDocument($event) {}

public static function install()
{
if (!file_exists(self::getConfigName())) {
$defaultContent = file_get_contents(PIMCORE_PLUGINS_PATH . self::SAMPLE_CONFIG_XML);
file_put_contents(self::getConfigName(), $defaultContent);
//copy(PIMCORE_PLUGINS_PATH . self::SAMPLE_CONFIG_XML, self::getConfigName())
/*$defaultConfig = self::getDefaultConfigXML();
$configWriter = new \Zend_Config_Writer_Xml();
$configWriter->setConfig($defaultConfig);
$configWriter->write(self::getConfigName());*/
}
}

public static function uninstall() {
if (file_exists(self::getConfigName())) {
unlink(self::getConfigName());
}
}

public static function isInstalled()
{
return file_exists(self::getConfigName());
}

private static function getConfigName()
{
return PIMCORE_WEBSITE_PATH . self::CONFIG_XML;
}

private static function getDefaultConfigXML()
{
return new \Zend_Config_Xml(PIMCORE_PLUGINS_PATH . self::SAMPLE_CONFIG_XML);
}

private static function getConfigXML()
{
return new \Zend_Config_Xml(self::getConfigName());
}
}
34 changes: 34 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0"?>
<zend-config xmlns:zf="http://framework.zend.com/xml/zend-config-xml/1.0/">
<plugin>

<!-- the plugin name [A-Za-z_] -->
<pluginName>CookieNotice</pluginName>

<!-- a short description -->
<pluginDescription>Displays a notification bar regarding the EU cookie law</pluginDescription>

<!-- meta data -->
<pluginVersion>1.0</pluginVersion>
<pluginRevision>1</pluginRevision>
<pluginBuildTimestamp>0</pluginBuildTimestamp>

<!-- put in the URL for the plugin configuration eg. /plugin/CookieNotice/admin/index -->
<pluginIframeSrc></pluginIframeSrc>

<!-- className of the plugin which extends Pimcore_API_Plugin_Abstract-->
<pluginClassName>\CookieNotice\Plugin</pluginClassName>

<!-- include paths relative to plugin-directory -->
<pluginIncludePaths>
<path>/CookieNotice/lib</path>
</pluginIncludePaths>

<!-- namespaces to register with autoloader-->
<pluginNamespaces>
<namespace>CookieNotice</namespace>
</pluginNamespaces>

<pluginXmlEditorFile>/website/var/config/cookienotice.json</pluginXmlEditorFile>
</plugin>
</zend-config>
Binary file added static/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions static/css/cookieNotice.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions static/css/cookieNotice.css.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions static/css/cookieNotice.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.cookieNotice {
position: fixed;
bottom: 0px;
left: 0px;
width: 100%;
background: #FFFFFF;
padding: 10px;
display: flex;

.cookieNotice__text {
color: #333;
margin: auto 0px;
flex-grow: 1;
}

.cookieNotice__button {
margin: 0px 0px auto 15px;
border: 2px solid #333;
padding: 10px;
color: #333;
background-color: #FFF;
cursor: pointer;
flex-grow: 0;
}
}
40 changes: 40 additions & 0 deletions static/js/cookieNotice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
window.onload = function () {
var cookieName = 'cookiesAllowed';

var splitted = document.cookie.split(';');
var cookieFound = false;
for(var i = 0; i < splitted.length; i++) {
if(splitted[i].trim() == cookieName + '=1') {
cookieFound = true;
break;
}
}

if(!cookieFound) {
var cookieNotice = document.createElement('div');
cookieNotice.setAttribute('class', 'cookieNotice');

var cookieNoticeButton = document.createElement('div');
cookieNoticeButton.setAttribute('class', 'cookieNotice__button');
cookieNoticeButton.innerHTML = typeof(COOKIE_NOTICE_BUTTON) !== 'undefined' && COOKIE_NOTICE_BUTTON != '' ? COOKIE_NOTICE_BUTTON : 'Cookies&nbsp;erlauben';

cookieNoticeButton.addEventListener('click', function () {
var days = 30;
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
document.cookie = cookieName + "=1; expires=" + date.toUTCString();
var notice = document.getElementsByClassName('cookieNotice')[0];
notice.parentNode.removeChild(notice);
});

var cookieNoticeText = document.createElement('div');
cookieNoticeText.setAttribute('class', 'cookieNotice__text');
cookieNoticeText.innerHTML = typeof(COOKIE_NOTICE_TEXT) !== 'undefined' && COOKIE_NOTICE_TEXT != '' ? COOKIE_NOTICE_TEXT : 'Diese Internetseite verwendet Cookies, um die Nutzererfahrung zu verbessern und den Benutzern bestimmte Dienste und Funktionen bereitzustellen.';

cookieNotice.append(cookieNoticeText);
cookieNotice.append(cookieNoticeButton);

document.body.append(cookieNotice);
}
}

Binary file added views/.DS_Store
Binary file not shown.
Binary file added views/scripts/.DS_Store
Binary file not shown.
Empty file added views/scripts/index/index.php
Empty file.

0 comments on commit f140386

Please sign in to comment.