Plugin Directory

Changeset 3346842


Ignore:
Timestamp:
08/19/2025 08:41:24 AM (8 months ago)
Author:
cookieopt2024
Message:

hot fix for conditional display

Location:
cookie-optimizer
Files:
13 deleted
7 edited
46 copied

Legend:

Unmodified
Added
Removed
  • cookie-optimizer/tags/1.0.5/app/Includes/CookieOptBanner.php

    r3346172 r3346842  
    2626            $package_user = $package->packageType();
    2727            if ($package_user !== 'LOCK' && !$package->checkLimitPackage()) {
     28                add_action('template_redirect', [$this, 'prepare_cookie_and_banner_logic'], 0);
    2829                add_action('wp_enqueue_scripts', [$this, 'register_enqueue_script']);
    29                 add_action('wp_head', [$this, 'my_banner_in_content']);
     30                if (function_exists('wp_body_open')) {
     31                    add_action('wp_body_open', [$this, 'my_banner_in_content'], 10);
     32                } else {
     33                    add_action('wp_footer', [$this, 'my_banner_in_content'], 10);
     34                }
    3035            }
    3136        }
     
    7378        if (isset($_POST['none']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['none'])), 'none_handle_banner')) {
    7479            $type = sanitize_text_field(wp_unslash($_POST['type'])); //phpcs:ignore WordPress.Security
    75             // $cookie_category = isset($_POST['cookie_category']) ? sanitize_text_field(wp_unslash($_POST['cookie_category'])) : null;
    7680            $this->CookieOptBanner_service->statisticBanner($type);
    7781            return wp_send_json(
     
    152156        wp_enqueue_script('cookie-custom-banner-js');
    153157    }
     158
     159    public function prepare_cookie_and_banner_logic(){
     160        if (is_admin() || is_feed() || is_robots() || (defined('REST_REQUEST') && REST_REQUEST)) {
     161            return;
     162        }
     163
     164        $cookieRaw = $_COOKIE[COOKIE_OPT_NAME] ?? null;
     165        $dataCookie = null;
     166
     167        if ($cookieRaw) {
     168            $decoded = urldecode(wp_unslash($cookieRaw));
     169            $dataCookie = json_decode($decoded, true);
     170        }
     171
     172        if (!is_array($dataCookie) || !isset($dataCookie['action'])) {
     173            $banner = $this->CookiePermissionService->getDataBannerToShow();
     174            $array = [
     175                'action'      => 0,
     176                'type'        => $banner['regulation'] === 'ja' ? '1' : '',
     177                'necessary'   => 1,
     178                'functional'  => 0,
     179                'socialmedia' => 0,
     180                'performance' => 0,
     181            ];
     182
     183            $options = [
     184                'expires'  => $banner['regulation'] === 'ja' ? time() + 31556926 : 0,
     185                'path'     => '/',
     186                'domain'   => '',
     187                'secure'   => false,
     188                'httponly' => false,
     189                'samesite' => 'Lax',
     190            ];
     191            setcookie(COOKIE_OPT_NAME, wp_json_encode($array), $options);
     192        }
     193    }
     194
    154195    public function my_banner_in_content()
    155196    {
     
    157198        if ($is_banner_active != 1)
    158199            return null;
     200
    159201        $banner = $this->CookiePermissionService->getDataBannerToShow();
    160202
    161         $banner['display'] = false;
    162 
    163         $cookieRaw = isset($_COOKIE[COOKIE_OPT_NAME]) ? $_COOKIE[COOKIE_OPT_NAME] : null;
    164         $dataCookie = json_decode(urldecode(stripslashes(sanitize_text_field(wp_unslash($cookieRaw)))), true);
    165 
    166         if (!is_array($dataCookie) || !isset($dataCookie['action'])) {
    167             // Cookie invalid -> set default
    168             $array = [
    169                 'action' => 0,
    170                 'type' => $banner['regulation'] == 'ja' ? '1' : '',
    171                 'necessary' => 1,
    172                 'functional' => 0,
    173                 'socialmedia' => 0,
    174                 'performance' => 0,
    175             ];
    176             $expires_or_options = $banner['regulation'] == 'ja' ? time() + 31556926 : 0;
    177             $json = wp_json_encode($array);
    178             setcookie(COOKIE_OPT_NAME, $json, $expires_or_options, '/', "", false, false);
    179         } else {
    180             // Cookie valid and exist
    181             if ($dataCookie['action'] != 0) {
    182                 $banner['display'] = true;
    183             }
    184         }
    185 
    186         $condition_status = $banner['conditional']['status'];
    187         $rules_show = $banner['conditional']['rules']['show'];
    188         $rules_hide = $banner['conditional']['rules']['hide'];
    189 
    190         if (!$rules_show || !$rules_hide) {
    191             $this->render_banner($banner);
    192             return;
    193         }
    194         if ($condition_status) {
    195             if (!empty($rules_show)) {
    196                 foreach ($rules_show as $rule) {
    197                     $check = $this->CookiePermissionService->checkParam($rule);
    198                     if (!$check) {
    199                         break;
    200                     }
    201                     $this->render_banner($banner);
    202                     return;
     203        $condition_status = (bool)($banner['conditional']['status'] ?? false);
     204        $rules_show = $banner['conditional']['rules']['show'] ?? [];
     205        $rules_hide = $banner['conditional']['rules']['hide'] ?? [];
     206
     207        $anyMatch = function (array $rules): bool {
     208            foreach ($rules as $rule) {
     209                if ($this->CookiePermissionService->checkParam($rule)) {
     210                    return true;
    203211                }
    204212            }
    205             if (!empty($rules_hide)) {
    206                 foreach ($rules_hide as $rule) {
    207                     $check = $this->CookiePermissionService->checkParam($rule);
    208                     if ($check) {
    209                         break;
    210                     }
    211                     $this->render_banner($banner);
    212                     return;
    213                 }
    214             }
    215         }
    216         $this->render_banner($banner);
     213            return false;
     214        };
     215
     216        if (!$condition_status) {
     217            $this->render_banner($banner);
     218            return;
     219        }
     220
     221        if (!empty($rules_hide) && $anyMatch($rules_hide)) {
     222            return;
     223        }
     224        if (empty($rules_show) || $anyMatch($rules_show)) {
     225            $this->render_banner($banner);
     226            return;
     227        }
    217228        return;
    218229    }
  • cookie-optimizer/tags/1.0.5/constants.php

    r3346172 r3346842  
    22
    33// Plugin version and mode
    4 define('VERSION', '1.0.4');
     4define('VERSION', '1.0.5');
    55
    66// Plugin directory details
  • cookie-optimizer/tags/1.0.5/cookie-opt.php

    r3346178 r3346842  
    1212 * Plugin URI: https://manage.medipartner.jp
    1313 * Description: Cookieをユーザーに見える化し、各法律にする準拠バナー同意ソリューション
    14  * Version: 1.0.4
     14 * Version: 1.0.5
    1515 * Requires at least: 5.3
    1616 * Requires PHP: 7.3
     
    5151 *
    5252 * @class CookieOpt
    53  * @version 1.0.4
     53 * @version 1.0.5
    5454 */
    5555class CookieOpt
     
    7676     */
    7777    public $defaults = [
    78         'version' => '1.0.4',
     78        'version' => '1.0.5',
    7979    ];
    8080
  • cookie-optimizer/tags/1.0.5/readme.txt

    r3346172 r3346842  
    55Requires PHP: 7.3
    66Tested up to: 6.7   
    7 Stable tag: 1.0.4
     7Stable tag: 1.0.5
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    6565== Changelog ==
    6666
    67 = 1.0.4 =
     67= 1.0.5 =
    6868Initial release
    6969
  • cookie-optimizer/tags/1.0.5/templates/cookie_permissions/partials/cookie_opt_setting_data_setup.php

    r3264201 r3346842  
    685685                                            <?php foreach ($data['setting']['all_page'] as $key => $item): ?>
    686686                                                <option <?php $this->propSelected($rule['value'], $item->ID) ?>
    687                                                     value="<?php esc_attr($item->ID) ?>">
     687                                                    value="<?php echo esc_attr($item->ID) ?>">
    688688                                                    <?php echo esc_html($item->post_title); ?>
    689689                                                </option>
  • cookie-optimizer/tags/1.0.5/uninstall.php

    r3346172 r3346842  
    1919 *
    2020 * @link       https://cookieoptimizer.net
    21  * @since      1.0.4
     21 * @since      1.0.5
    2222 *
    2323 * @package    Cookie Optimizer
  • cookie-optimizer/trunk/app/Includes/CookieOptBanner.php

    r3346172 r3346842  
    2626            $package_user = $package->packageType();
    2727            if ($package_user !== 'LOCK' && !$package->checkLimitPackage()) {
     28                add_action('template_redirect', [$this, 'prepare_cookie_and_banner_logic'], 0);
    2829                add_action('wp_enqueue_scripts', [$this, 'register_enqueue_script']);
    29                 add_action('wp_head', [$this, 'my_banner_in_content']);
     30                if (function_exists('wp_body_open')) {
     31                    add_action('wp_body_open', [$this, 'my_banner_in_content'], 10);
     32                } else {
     33                    add_action('wp_footer', [$this, 'my_banner_in_content'], 10);
     34                }
    3035            }
    3136        }
     
    7378        if (isset($_POST['none']) && wp_verify_nonce(sanitize_text_field(wp_unslash($_POST['none'])), 'none_handle_banner')) {
    7479            $type = sanitize_text_field(wp_unslash($_POST['type'])); //phpcs:ignore WordPress.Security
    75             // $cookie_category = isset($_POST['cookie_category']) ? sanitize_text_field(wp_unslash($_POST['cookie_category'])) : null;
    7680            $this->CookieOptBanner_service->statisticBanner($type);
    7781            return wp_send_json(
     
    152156        wp_enqueue_script('cookie-custom-banner-js');
    153157    }
     158
     159    public function prepare_cookie_and_banner_logic(){
     160        if (is_admin() || is_feed() || is_robots() || (defined('REST_REQUEST') && REST_REQUEST)) {
     161            return;
     162        }
     163
     164        $cookieRaw = $_COOKIE[COOKIE_OPT_NAME] ?? null;
     165        $dataCookie = null;
     166
     167        if ($cookieRaw) {
     168            $decoded = urldecode(wp_unslash($cookieRaw));
     169            $dataCookie = json_decode($decoded, true);
     170        }
     171
     172        if (!is_array($dataCookie) || !isset($dataCookie['action'])) {
     173            $banner = $this->CookiePermissionService->getDataBannerToShow();
     174            $array = [
     175                'action'      => 0,
     176                'type'        => $banner['regulation'] === 'ja' ? '1' : '',
     177                'necessary'   => 1,
     178                'functional'  => 0,
     179                'socialmedia' => 0,
     180                'performance' => 0,
     181            ];
     182
     183            $options = [
     184                'expires'  => $banner['regulation'] === 'ja' ? time() + 31556926 : 0,
     185                'path'     => '/',
     186                'domain'   => '',
     187                'secure'   => false,
     188                'httponly' => false,
     189                'samesite' => 'Lax',
     190            ];
     191            setcookie(COOKIE_OPT_NAME, wp_json_encode($array), $options);
     192        }
     193    }
     194
    154195    public function my_banner_in_content()
    155196    {
     
    157198        if ($is_banner_active != 1)
    158199            return null;
     200
    159201        $banner = $this->CookiePermissionService->getDataBannerToShow();
    160202
    161         $banner['display'] = false;
    162 
    163         $cookieRaw = isset($_COOKIE[COOKIE_OPT_NAME]) ? $_COOKIE[COOKIE_OPT_NAME] : null;
    164         $dataCookie = json_decode(urldecode(stripslashes(sanitize_text_field(wp_unslash($cookieRaw)))), true);
    165 
    166         if (!is_array($dataCookie) || !isset($dataCookie['action'])) {
    167             // Cookie invalid -> set default
    168             $array = [
    169                 'action' => 0,
    170                 'type' => $banner['regulation'] == 'ja' ? '1' : '',
    171                 'necessary' => 1,
    172                 'functional' => 0,
    173                 'socialmedia' => 0,
    174                 'performance' => 0,
    175             ];
    176             $expires_or_options = $banner['regulation'] == 'ja' ? time() + 31556926 : 0;
    177             $json = wp_json_encode($array);
    178             setcookie(COOKIE_OPT_NAME, $json, $expires_or_options, '/', "", false, false);
    179         } else {
    180             // Cookie valid and exist
    181             if ($dataCookie['action'] != 0) {
    182                 $banner['display'] = true;
    183             }
    184         }
    185 
    186         $condition_status = $banner['conditional']['status'];
    187         $rules_show = $banner['conditional']['rules']['show'];
    188         $rules_hide = $banner['conditional']['rules']['hide'];
    189 
    190         if (!$rules_show || !$rules_hide) {
    191             $this->render_banner($banner);
    192             return;
    193         }
    194         if ($condition_status) {
    195             if (!empty($rules_show)) {
    196                 foreach ($rules_show as $rule) {
    197                     $check = $this->CookiePermissionService->checkParam($rule);
    198                     if (!$check) {
    199                         break;
    200                     }
    201                     $this->render_banner($banner);
    202                     return;
     203        $condition_status = (bool)($banner['conditional']['status'] ?? false);
     204        $rules_show = $banner['conditional']['rules']['show'] ?? [];
     205        $rules_hide = $banner['conditional']['rules']['hide'] ?? [];
     206
     207        $anyMatch = function (array $rules): bool {
     208            foreach ($rules as $rule) {
     209                if ($this->CookiePermissionService->checkParam($rule)) {
     210                    return true;
    203211                }
    204212            }
    205             if (!empty($rules_hide)) {
    206                 foreach ($rules_hide as $rule) {
    207                     $check = $this->CookiePermissionService->checkParam($rule);
    208                     if ($check) {
    209                         break;
    210                     }
    211                     $this->render_banner($banner);
    212                     return;
    213                 }
    214             }
    215         }
    216         $this->render_banner($banner);
     213            return false;
     214        };
     215
     216        if (!$condition_status) {
     217            $this->render_banner($banner);
     218            return;
     219        }
     220
     221        if (!empty($rules_hide) && $anyMatch($rules_hide)) {
     222            return;
     223        }
     224        if (empty($rules_show) || $anyMatch($rules_show)) {
     225            $this->render_banner($banner);
     226            return;
     227        }
    217228        return;
    218229    }
  • cookie-optimizer/trunk/constants.php

    r3346172 r3346842  
    22
    33// Plugin version and mode
    4 define('VERSION', '1.0.4');
     4define('VERSION', '1.0.5');
    55
    66// Plugin directory details
  • cookie-optimizer/trunk/cookie-opt.php

    r3346178 r3346842  
    1212 * Plugin URI: https://manage.medipartner.jp
    1313 * Description: Cookieをユーザーに見える化し、各法律にする準拠バナー同意ソリューション
    14  * Version: 1.0.4
     14 * Version: 1.0.5
    1515 * Requires at least: 5.3
    1616 * Requires PHP: 7.3
     
    5151 *
    5252 * @class CookieOpt
    53  * @version 1.0.4
     53 * @version 1.0.5
    5454 */
    5555class CookieOpt
     
    7676     */
    7777    public $defaults = [
    78         'version' => '1.0.4',
     78        'version' => '1.0.5',
    7979    ];
    8080
  • cookie-optimizer/trunk/readme.txt

    r3346172 r3346842  
    55Requires PHP: 7.3
    66Tested up to: 6.7   
    7 Stable tag: 1.0.4
     7Stable tag: 1.0.5
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    6565== Changelog ==
    6666
    67 = 1.0.4 =
     67= 1.0.5 =
    6868Initial release
    6969
  • cookie-optimizer/trunk/templates/cookie_permissions/partials/cookie_opt_setting_data_setup.php

    r3264201 r3346842  
    685685                                            <?php foreach ($data['setting']['all_page'] as $key => $item): ?>
    686686                                                <option <?php $this->propSelected($rule['value'], $item->ID) ?>
    687                                                     value="<?php esc_attr($item->ID) ?>">
     687                                                    value="<?php echo esc_attr($item->ID) ?>">
    688688                                                    <?php echo esc_html($item->post_title); ?>
    689689                                                </option>
  • cookie-optimizer/trunk/uninstall.php

    r3346172 r3346842  
    1919 *
    2020 * @link       https://cookieoptimizer.net
    21  * @since      1.0.4
     21 * @since      1.0.5
    2222 *
    2323 * @package    Cookie Optimizer
Note: See TracChangeset for help on using the changeset viewer.