From f14038653afe60cccdc61384612d32ee5ad496ee Mon Sep 17 00:00:00 2001 From: Marcel Eichhorn Date: Thu, 6 Apr 2017 13:31:48 +0200 Subject: [PATCH] Initial commit --- composer.json | 12 ++++++ controllers/IndexController.php | 32 +++++++++++++++ cookienotice.json | 7 ++++ lib/.DS_Store | Bin 0 -> 8196 bytes lib/CookieNotice/Plugin.php | 69 ++++++++++++++++++++++++++++++++ plugin.xml | 34 ++++++++++++++++ static/.DS_Store | Bin 0 -> 6148 bytes static/css/cookieNotice.css | 2 + static/css/cookieNotice.css.map | 7 ++++ static/css/cookieNotice.scss | 25 ++++++++++++ static/js/cookieNotice.js | 40 ++++++++++++++++++ views/.DS_Store | Bin 0 -> 6148 bytes views/scripts/.DS_Store | Bin 0 -> 6148 bytes views/scripts/index/index.php | 0 14 files changed, 228 insertions(+) create mode 100755 composer.json create mode 100755 controllers/IndexController.php create mode 100644 cookienotice.json create mode 100644 lib/.DS_Store create mode 100755 lib/CookieNotice/Plugin.php create mode 100755 plugin.xml create mode 100644 static/.DS_Store create mode 100644 static/css/cookieNotice.css create mode 100644 static/css/cookieNotice.css.map create mode 100755 static/css/cookieNotice.scss create mode 100755 static/js/cookieNotice.js create mode 100644 views/.DS_Store create mode 100644 views/scripts/.DS_Store create mode 100755 views/scripts/index/index.php diff --git a/composer.json b/composer.json new file mode 100755 index 0000000..e7ce316 --- /dev/null +++ b/composer.json @@ -0,0 +1,12 @@ +{ + "name": "YourVendorName/CookieNotice", + "type": "pimcore-plugin", + "require": { + "pimcore/installer-plugin": ">=1" + }, + "autoload": { + "psr-4": { + "CookieNotice\\": "lib" + } + } +} \ No newline at end of file diff --git a/controllers/IndexController.php b/controllers/IndexController.php new file mode 100755 index 0000000..7af9e4e --- /dev/null +++ b/controllers/IndexController.php @@ -0,0 +1,32 @@ +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)); + } +} diff --git a/cookienotice.json b/cookienotice.json new file mode 100644 index 0000000..6cbe0d7 --- /dev/null +++ b/cookienotice.json @@ -0,0 +1,7 @@ +{ + "css": ".cookieNotice {} + .cookieNotice__text {} + .cookieNotice__button {}", + "text": "", + "buttonLabel": "" +} \ No newline at end of file diff --git a/lib/.DS_Store b/lib/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..a40be51fb1dbb24d6ebd41653a896f62a8838c30 GIT binary patch literal 8196 zcmeHMT}&KR6h4QaGBZHAAcbMUx{6pzp{4Cwptg1SE5+J^E`M#Y%kIutCLLzz&g@b^ z8jLk!RWbjXGx)j#0SNsbCY|&d+#}C z@11YHox5ii0I(~g?FUc+K%&Z#6;pGE!tK1?R`UFrLPDf?00VS54K}#c3rfI1z(Bx2 zz(Bx2z`*~J0XnmJkv2H@g*9jc1_B1|N(T7zAxxEH)W=1E-lKyWF9jehplPpApYi}N zChTL>$3=l&D1D~L9?%a(KgB>1PWCW&Cye^IC{Tn0if}-GW%M%?^j4?1u;&gK6&SPu z0|5iKGr)8A66mI!-G+;6^7jGy|h+g$A@k|Tyb6K9p(w&f-aOHbe8K0az#nmyBHXDrR} zK4&oDPExEa%aR;t>im3r$D!tMBobL@4$rr@N2uQsSy+&z>W2MC`zNMm=jNYTxblX$ zM)aQ(P`2)x-`wniH78{zY0Er#Lsm>D+bvkho6WIuGslXo6syPkPAG9!k)?|rn05`@ zaz^yDLl|de4$;-0vaP|i&h4Wq+ssT^PMnpe5@sr6CS1MKG-Jk`?u@zmWtaEPI(FLa z_8i9yisf^0#xjonq)q`wR_~!OhoQVwvLkd~ePhdkwj-S@rQ6GxQlV6iW(~(kn)>jJ zp}CW15>86DG{d@ZmhO|~8c!Q~S}wQ}q6lLfl-Du{>B6ROQ zMIAO1N!?_cEY>*~QPk0_V2qvgC)+y|bu491P0^N}a%}dej~-Li^L*vU6OKDDty{FK z8~*ZLw5v1R)~RWHPf~rfQHa62()wtt7|C?>)WBXkXimU5y}+7=S-1+<;01UK-i2lO z06v8;;0AmJU&A->1N;O(!!PhF{0@J@UkHe(U=>!QiudC~*oeEa2@hgB9>z!T2=?Mh zJcXxm0LO3wlbAvcr!b4NIEVB2Jid&t;%oRizJu@K5-#KW_z`}BpNXyIq+(p`J!adl6hp-JhNPpefL;CB(L3{#ZID{h@ z_cf@ag*INoG`hHeS8x%Z#pm!UUc(phCDP<8_%>e0rFAOo&*@JfE^ns7Y%Fb=wsnDg zaw=XM9*nk_fqb#P%Jcu;jo<%o@h*eq0|o*H{!Iq3peNSTMJsIdoaVW9nCb*oUbx?) tKre(E?!xE2bewSY4@2sQeOuJWMS*0Y@}Iv52+n`{4H}&Pp7`$K=5L<}>O24d literal 0 HcmV?d00001 diff --git a/lib/CookieNotice/Plugin.php b/lib/CookieNotice/Plugin.php new file mode 100755 index 0000000..b86cb8b --- /dev/null +++ b/lib/CookieNotice/Plugin.php @@ -0,0 +1,69 @@ +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()); + } +} diff --git a/plugin.xml b/plugin.xml new file mode 100755 index 0000000..0a8a380 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,34 @@ + + + + + + CookieNotice + + + Displays a notification bar regarding the EU cookie law + + + 1.0 + 1 + 0 + + + + + + \CookieNotice\Plugin + + + + /CookieNotice/lib + + + + + CookieNotice + + + /website/var/config/cookienotice.json + + diff --git a/static/.DS_Store b/static/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5bd05b3d12bdde4320134fa46ff5e263d263a14e GIT binary patch literal 6148 zcmeHKF=_)r43uIQhBPiy?ic)n#W*j>2ZHS?7+f6gugbgfw9H6K@cBq%NMlAI&8}8+ z%S~}QnVD}d$Bo(A%vNxseKO3A=k%F9Rfgz%#^JO-pHEoY&(Vx?n_%I>4mQ|u9Ip8v z)5I-Ldnq6Vq<|EV0#e{U1=y%ztLH>TDIf);z^?-QJ~TM77mkVX=|G78eBcu4Fsx&i z05&Foy>LuK2Ie&)cu~DZ3{N`FTh;Z#F)``paWkG%H+xMe9=9XkqTIYEDoOzd!*=`< eMOoLl#(6Is6N8R?(1F>_^)oPk`~_p literal 0 HcmV?d00001 diff --git a/static/css/cookieNotice.css b/static/css/cookieNotice.css new file mode 100644 index 0000000..167fc44 --- /dev/null +++ b/static/css/cookieNotice.css @@ -0,0 +1,2 @@ +.cookieNotice{position:fixed;bottom:0px;left:0px;width:100%;background:#FFFFFF;padding:10px;display:flex}.cookieNotice .cookieNotice__text{color:#333;margin:auto 0px;flex-grow:1}.cookieNotice .cookieNotice__button{margin:0px 0px auto 15px;border:2px solid #333;padding:10px;color:#333;background-color:#FFF;cursor:pointer;flex-grow:0} +/*# sourceMappingURL=cookieNotice.css.map */ diff --git a/static/css/cookieNotice.css.map b/static/css/cookieNotice.css.map new file mode 100644 index 0000000..0bb4e3f --- /dev/null +++ b/static/css/cookieNotice.css.map @@ -0,0 +1,7 @@ +{ +"version": 3, +"mappings": "AAAA,aAAc,CACZ,QAAQ,CAAE,KAAK,CACf,MAAM,CAAE,GAAG,CACX,IAAI,CAAE,GAAG,CACT,KAAK,CAAE,IAAI,CACX,UAAU,CAAE,OAAO,CACnB,OAAO,CAAE,IAAI,CACb,OAAO,CAAE,IAAI,CAEb,iCAAoB,CAClB,KAAK,CAAE,IAAI,CACX,MAAM,CAAE,QAAQ,CAChB,SAAS,CAAE,CAAC,CAGd,mCAAsB,CACpB,MAAM,CAAE,iBAAiB,CACzB,MAAM,CAAE,cAAc,CACtB,OAAO,CAAE,IAAI,CACb,KAAK,CAAE,IAAI,CACX,gBAAgB,CAAE,IAAI,CACtB,MAAM,CAAE,OAAO,CACf,SAAS,CAAE,CAAC", +"sources": ["cookieNotice.scss"], +"names": [], +"file": "cookieNotice.css" +} \ No newline at end of file diff --git a/static/css/cookieNotice.scss b/static/css/cookieNotice.scss new file mode 100755 index 0000000..48b8a1b --- /dev/null +++ b/static/css/cookieNotice.scss @@ -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; + } +} \ No newline at end of file diff --git a/static/js/cookieNotice.js b/static/js/cookieNotice.js new file mode 100755 index 0000000..f4e1811 --- /dev/null +++ b/static/js/cookieNotice.js @@ -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 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); + } +} + diff --git a/views/.DS_Store b/views/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..eba13223f6781b153af5c8a6f35630fbb0dc1cc4 GIT binary patch literal 6148 zcmeHKJ5EC}5S)cbM50NV(pTUHR+O9|7eFLUq)0(L=wHRTI2yB`g6NShDL}K*dhGR% zEl=_GEdX16?4N)IfH~a}pFT{@_uVIUR}mx9dB!W=G3EIA80CC1}80XPT z5Ss^xy>Luqgl0)4Ce^CNu%t8IDz6ugiAjf5^I>(fRfl46JI`;C4(o{;rGOMTSKvOE z3$Onh`i1`goTQZ$kOKco0h_J2>lL3=wRQ41ueFW-O!u5Gx*O*~;SlAR80DA?FUQMB b%Dm=t?)SnmG3bm3ov5Dy*F`1;ZmqyKRWud8 literal 0 HcmV?d00001 diff --git a/views/scripts/.DS_Store b/views/scripts/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..08416255f9f6f5a02b5f550ae823b412517596ee GIT binary patch literal 6148 zcmeH~J#GR)427QqNRenLDW}N+xWNdK6L0|pOM!$!fg+`xqvzS^2@!}xoag^?LeHc}5djgH1_A#*6uN6oZC&Hj!68}z>YV8?&ZC#07Ee%XYU|1j z&9Zy2EVXDuJRjxMlKX0E>)Oj<*?d^u*}RLPSuckb1~jW78bm+@Mg(R(Uita|N&m0^ zAC)K+0TFmH0yf|6cU!(xo~?gg&+~`O`n=Jpv7N)iPXGfyir4fot{0zBYijGt3{5`* LfkA@^Je9yN7hV&V literal 0 HcmV?d00001 diff --git a/views/scripts/index/index.php b/views/scripts/index/index.php new file mode 100755 index 0000000..e69de29