From d11e4a11404bf0b605bd567dbf4193139d5ea3da Mon Sep 17 00:00:00 2001 From: deadbok Date: Thu, 22 Mar 2018 23:39:26 +0100 Subject: [PATCH] Add option to disable the cookie warning in iframes --- cookie-notice.php | 17 +++- js/front.js | 31 ++++--- languages/cookie-notice.pot | 165 +++++++++++++++++++----------------- readme.md | 1 + readme.txt | 1 + 5 files changed, 124 insertions(+), 91 deletions(-) diff --git a/cookie-notice.php b/cookie-notice.php index 2e76118..ef44bc1 100644 --- a/cookie-notice.php +++ b/cookie-notice.php @@ -68,7 +68,8 @@ class Cookie_Notice { ), 'script_placement' => 'header', 'translate' => true, - 'deactivation_delete' => 'no' + 'deactivation_delete' => 'no', + 'iframe_disable' => true ), 'version' => '1.2.37' ); @@ -299,6 +300,7 @@ public function register_settings() { add_settings_field( 'cn_time', __( 'Cookie expiry', 'cookie-notice' ), array( $this, 'cn_time' ), 'cookie_notice_options', 'cookie_notice_configuration' ); add_settings_field( 'cn_script_placement', __( 'Script placement', 'cookie-notice' ), array( $this, 'cn_script_placement' ), 'cookie_notice_options', 'cookie_notice_configuration' ); add_settings_field( 'cn_deactivation_delete', __( 'Deactivation', 'cookie-notice' ), array( $this, 'cn_deactivation_delete' ), 'cookie_notice_options', 'cookie_notice_configuration' ); + add_settings_field( 'cn_iframe_disable', __( 'Iframes', 'cookie-notice' ), array( $this, 'cn_iframe_disable' ), 'cookie_notice_options', 'cookie_notice_configuration' ); // design add_settings_section( 'cookie_notice_design', __( 'Design', 'cookie-notice' ), array( $this, 'cn_section_design' ), 'cookie_notice_options' ); @@ -322,6 +324,15 @@ public function cn_deactivation_delete() { '; } + /** + * Disable in iframes. + */ + public function cn_iframe_disable() { + echo ' + + '; + } + /** * Cookie message option. */ @@ -628,6 +639,9 @@ public function validate_options( $input ) { // deactivation $input['deactivation_delete'] = (bool) isset( $input['deactivation_delete'] ) ? 'yes' : 'no'; + // iframe + $input['iframe_disable'] = (bool) isset( $input['iframe_disable'] ) ? 'yes' : 'no'; + // read more $input['see_more'] = (bool) isset( $input['see_more'] ) ? 'yes' : 'no'; $input['see_more_opt']['text'] = sanitize_text_field( isset( $input['see_more_opt']['text'] ) && $input['see_more_opt']['text'] !== '' ? $input['see_more_opt']['text'] : $this->defaults['general']['see_more_opt']['text'] ); @@ -831,6 +845,7 @@ public function front_load_scripts_styles() { 'hideEffect' => $this->options['general']['hide_effect'], 'onScroll' => $this->options['general']['on_scroll'], 'onScrollOffset' => $this->options['general']['on_scroll_offset'], + 'onIframe' => $this->options['general']['iframe_disable'], 'cookieName' => self::$cookie['name'], 'cookieValue' => self::$cookie['value'], 'cookieTime' => $this->times[$this->options['general']['time']][1], diff --git a/js/front.js b/js/front.js index 3cbd7e7..7d0bd2c 100644 --- a/js/front.js +++ b/js/front.js @@ -1,4 +1,11 @@ (function ($) { + $.fn.isCrossOriginFrame = function () { + try { + return (!window.top.location.hostname); + } catch (e) { + return true; + } + } // set Cookie Notice $.fn.setCookieNotice = function (cookie_value) { @@ -67,19 +74,21 @@ $(window).on('scroll', cnHandleScroll); } - // display cookie notice - if (document.cookie.indexOf('cookie_notice_accepted') === -1) { - if (cnArgs.hideEffect === 'fade') { - cnDomNode.fadeIn(300); - } else if (cnArgs.hideEffect === 'slide') { - cnDomNode.slideDown(300); + // check if we're in an iframe + if (!($(this).isCrossOriginFrame() && cnArgs.onIframe == 'no')) { + // display cookie notice + if (document.cookie.indexOf('cookie_notice_accepted') === -1) { + if (cnArgs.hideEffect === 'fade') { + cnDomNode.fadeIn(300); + } else if (cnArgs.hideEffect === 'slide') { + cnDomNode.slideDown(300); + } else { + cnDomNode.show(); + } + $('body').addClass('cookies-not-accepted'); } else { - cnDomNode.show(); + cnDomNode.removeCookieNotice(); } - $('body').addClass('cookies-not-accepted'); - } else { - cnDomNode.removeCookieNotice(); } - }) })(jQuery); diff --git a/languages/cookie-notice.pot b/languages/cookie-notice.pot index 03035a5..1eda78c 100644 --- a/languages/cookie-notice.pot +++ b/languages/cookie-notice.pot @@ -2,7 +2,7 @@ msgid "" msgstr "" "Project-Id-Version: Cookie Notice\n" -"POT-Creation-Date: 2016-12-07 10:49+0100\n" +"POT-Creation-Date: 2018-03-22 23:03+0100\n" "PO-Revision-Date: 2015-03-24 11:30+0100\n" "Last-Translator: Bartosz Arendt \n" "Language-Team: dFactory \n" @@ -10,314 +10,321 @@ msgstr "" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 1.8.11\n" +"X-Generator: Poedit 2.0.6\n" "X-Poedit-KeywordsList: gettext;gettext_noop;__;_e;_n\n" "X-Poedit-Basepath: .\n" "X-Poedit-SourceCharset: UTF-8\n" "X-Poedit-SearchPath-0: ..\n" -#: ../cookie-notice.php:126 +#: ../cookie-notice.php:127 msgid "Top" msgstr "" -#: ../cookie-notice.php:127 +#: ../cookie-notice.php:128 msgid "Bottom" msgstr "" -#: ../cookie-notice.php:131 ../cookie-notice.php:162 +#: ../cookie-notice.php:132 ../cookie-notice.php:163 msgid "None" msgstr "" -#: ../cookie-notice.php:132 +#: ../cookie-notice.php:133 msgid "WordPress" msgstr "" -#: ../cookie-notice.php:133 +#: ../cookie-notice.php:134 msgid "Bootstrap" msgstr "" -#: ../cookie-notice.php:137 +#: ../cookie-notice.php:138 msgid "Custom link" msgstr "" -#: ../cookie-notice.php:138 +#: ../cookie-notice.php:139 msgid "Page link" msgstr "" -#: ../cookie-notice.php:147 +#: ../cookie-notice.php:148 msgid "Text color" msgstr "" -#: ../cookie-notice.php:148 +#: ../cookie-notice.php:149 msgid "Bar color" msgstr "" -#: ../cookie-notice.php:152 +#: ../cookie-notice.php:153 msgid "1 day" msgstr "" -#: ../cookie-notice.php:153 +#: ../cookie-notice.php:154 msgid "1 week" msgstr "" -#: ../cookie-notice.php:154 +#: ../cookie-notice.php:155 msgid "1 month" msgstr "" -#: ../cookie-notice.php:155 +#: ../cookie-notice.php:156 msgid "3 months" msgstr "" -#: ../cookie-notice.php:156 +#: ../cookie-notice.php:157 msgid "6 months" msgstr "" -#: ../cookie-notice.php:157 +#: ../cookie-notice.php:158 msgid "1 year" msgstr "" -#: ../cookie-notice.php:158 +#: ../cookie-notice.php:159 msgid "infinity" msgstr "" -#: ../cookie-notice.php:163 +#: ../cookie-notice.php:164 msgid "Fade" msgstr "" -#: ../cookie-notice.php:164 +#: ../cookie-notice.php:165 msgid "Slide" msgstr "" -#: ../cookie-notice.php:168 +#: ../cookie-notice.php:169 msgid "Header" msgstr "" -#: ../cookie-notice.php:169 +#: ../cookie-notice.php:170 msgid "Footer" msgstr "" -#: ../cookie-notice.php:175 +#: ../cookie-notice.php:176 msgid "We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it." msgstr "" -#: ../cookie-notice.php:176 +#: ../cookie-notice.php:177 msgid "Ok" msgstr "" -#: ../cookie-notice.php:177 +#: ../cookie-notice.php:178 msgid "No" msgstr "" -#: ../cookie-notice.php:178 +#: ../cookie-notice.php:179 msgid "Read more" msgstr "" -#: ../cookie-notice.php:238 ../cookie-notice.php:250 ../cookie-notice.php:253 +#: ../cookie-notice.php:239 ../cookie-notice.php:251 ../cookie-notice.php:254 msgid "Cookie Notice" msgstr "" -#: ../cookie-notice.php:255 +#: ../cookie-notice.php:256 msgid "Need support?" msgstr "" -#: ../cookie-notice.php:256 +#: ../cookie-notice.php:257 msgid "If you are having problems with this plugin, please talk about them in the" msgstr "" -#: ../cookie-notice.php:256 +#: ../cookie-notice.php:257 msgid "Support forum" msgstr "" -#: ../cookie-notice.php:258 +#: ../cookie-notice.php:259 msgid "Do you like this plugin?" msgstr "" -#: ../cookie-notice.php:259 +#: ../cookie-notice.php:260 msgid "Rate it 5" msgstr "" -#: ../cookie-notice.php:259 +#: ../cookie-notice.php:260 msgid "on WordPress.org" msgstr "" -#: ../cookie-notice.php:260 +#: ../cookie-notice.php:261 msgid "Blog about it & link to the" msgstr "" -#: ../cookie-notice.php:260 +#: ../cookie-notice.php:261 msgid "plugin page" msgstr "" -#: ../cookie-notice.php:261 +#: ../cookie-notice.php:262 msgid "Check out our other" msgstr "" -#: ../cookie-notice.php:261 +#: ../cookie-notice.php:262 msgid "WordPress plugins" msgstr "" -#: ../cookie-notice.php:276 +#: ../cookie-notice.php:277 msgid "Reset to defaults" msgstr "" -#: ../cookie-notice.php:292 +#: ../cookie-notice.php:293 msgid "Configuration" msgstr "" -#: ../cookie-notice.php:293 +#: ../cookie-notice.php:294 msgid "Message" msgstr "" -#: ../cookie-notice.php:294 +#: ../cookie-notice.php:295 msgid "Button text" msgstr "" -#: ../cookie-notice.php:295 +#: ../cookie-notice.php:296 msgid "More info link" msgstr "" -#: ../cookie-notice.php:296 +#: ../cookie-notice.php:297 msgid "Link target" msgstr "" -#: ../cookie-notice.php:297 +#: ../cookie-notice.php:298 msgid "Refuse button" msgstr "" -#: ../cookie-notice.php:298 +#: ../cookie-notice.php:299 msgid "On scroll" msgstr "" -#: ../cookie-notice.php:299 +#: ../cookie-notice.php:300 msgid "Cookie expiry" msgstr "" -#: ../cookie-notice.php:300 +#: ../cookie-notice.php:301 msgid "Script placement" msgstr "" -#: ../cookie-notice.php:301 +#: ../cookie-notice.php:302 msgid "Deactivation" msgstr "" -#: ../cookie-notice.php:304 +#: ../cookie-notice.php:303 +msgid "Iframes" +msgstr "" + +#: ../cookie-notice.php:306 msgid "Design" msgstr "" -#: ../cookie-notice.php:305 +#: ../cookie-notice.php:307 msgid "Position" msgstr "" -#: ../cookie-notice.php:306 +#: ../cookie-notice.php:308 msgid "Animation" msgstr "" -#: ../cookie-notice.php:307 +#: ../cookie-notice.php:309 msgid "Button style" msgstr "" -#: ../cookie-notice.php:308 +#: ../cookie-notice.php:310 msgid "Colors" msgstr "" -#: ../cookie-notice.php:322 +#: ../cookie-notice.php:324 msgid "Enable if you want all plugin data to be deleted on deactivation." msgstr "" -#: ../cookie-notice.php:332 -msgid "Enter the cookie notice message." +#: ../cookie-notice.php:333 +msgid "Show cookie notice in iframes." msgstr "" #: ../cookie-notice.php:343 +msgid "Enter the cookie notice message." +msgstr "" + +#: ../cookie-notice.php:354 msgid "The text of the option to accept the usage of the cookies and make the notification disappear." msgstr "" -#: ../cookie-notice.php:353 +#: ../cookie-notice.php:364 msgid "Give to the user the possibility to refuse third party non functional cookies." msgstr "" -#: ../cookie-notice.php:358 +#: ../cookie-notice.php:369 msgid "The text of the option to refuse the usage of the cookies. To get the cookie notice status use cn_cookies_accepted() function." msgstr "" -#: ../cookie-notice.php:363 +#: ../cookie-notice.php:374 msgid "Enter non functional cookies Javascript code here (for e.g. Google Analitycs). It will be used after cookies are accepted." msgstr "" -#: ../cookie-notice.php:389 +#: ../cookie-notice.php:400 msgid "Enable Read more link." msgstr "" -#: ../cookie-notice.php:390 +#: ../cookie-notice.php:401 #, php-format msgid "Need a Cookie Policy? Generate one with iubenda" msgstr "" -#: ../cookie-notice.php:396 +#: ../cookie-notice.php:407 msgid "The text of the more info button." msgstr "" -#: ../cookie-notice.php:410 +#: ../cookie-notice.php:421 msgid "Select where to redirect user for more information about cookies." msgstr "" -#: ../cookie-notice.php:413 +#: ../cookie-notice.php:424 msgid "-- select page --" msgstr "" -#: ../cookie-notice.php:424 +#: ../cookie-notice.php:435 msgid "Select from one of your site's pages" msgstr "" -#: ../cookie-notice.php:428 +#: ../cookie-notice.php:439 msgid "Enter the full URL starting with http://" msgstr "" -#: ../cookie-notice.php:448 +#: ../cookie-notice.php:459 msgid "Select the link target for more info page." msgstr "" -#: ../cookie-notice.php:468 +#: ../cookie-notice.php:479 msgid "The ammount of time that cookie should be stored for." msgstr "" -#: ../cookie-notice.php:482 +#: ../cookie-notice.php:493 msgid "Select where all the plugin scripts should be placed." msgstr "" -#: ../cookie-notice.php:500 +#: ../cookie-notice.php:511 msgid "Select location for your cookie notice." msgstr "" -#: ../cookie-notice.php:519 +#: ../cookie-notice.php:530 msgid "Cookie notice acceptance animation." msgstr "" -#: ../cookie-notice.php:529 +#: ../cookie-notice.php:540 msgid "Enable cookie notice acceptance when users scroll." msgstr "" -#: ../cookie-notice.php:533 +#: ../cookie-notice.php:544 msgid "Number of pixels user has to scroll to accept the usage of the cookies and make the notification disappear." msgstr "" -#: ../cookie-notice.php:553 +#: ../cookie-notice.php:564 msgid "Choose buttons style." msgstr "" -#: ../cookie-notice.php:657 +#: ../cookie-notice.php:671 msgid "Settings restored to defaults." msgstr "" -#: ../cookie-notice.php:758 +#: ../cookie-notice.php:772 msgid "Support" msgstr "" -#: ../cookie-notice.php:777 +#: ../cookie-notice.php:791 msgid "Settings" msgstr "" -#: ../cookie-notice.php:811 +#: ../cookie-notice.php:825 msgid "Are you sure you want to reset these settings to defaults?" msgstr "" - diff --git a/readme.md b/readme.md index c53920e..35ee629 100644 --- a/readme.md +++ b/readme.md @@ -23,6 +23,7 @@ For more information, check out plugin page at [dFactory](http://www.dfactory.eu * Set the text and bar background colors * WPML and Polylang compatible * .pot file for translations included +* Option to disable the warning in iframes. ### Usage: ### diff --git a/readme.txt b/readme.txt index 8e875d3..cfca3cd 100644 --- a/readme.txt +++ b/readme.txt @@ -31,6 +31,7 @@ For more information, check out plugin page at [dFactory](http://www.dfactory.eu * Set the text and bar background colors * WPML and Polylang compatible * .pot file for translations included +* Option to disable the warning in iframes. = Usage: =