<commit_before><?php
namespace Concrete\Package\FreeCookiesDisclosure\Src;

defined('C5_EXECUTE') or die(_("Access Denied."));

class CookieAllowance
{

    public function cookiesAllowed()
    {
        if (!isset($_SESSION['cookies_allowed'])) {
            if (isset($_COOKIE['cookies_allowed']) && $_COOKIE['cookies_allowed'] == true) {
                $_SESSION['cookies_allowed'] = true;

                return true;
            }

            return false;
        }

        return $_SESSION['cookies_allowed'] == true;
    }

}<commit_msg>Refactored session\cookie code<commit_after><?php
namespace Concrete\Package\FreeCookiesDisclosure\Src;

use Concrete\Core\Http\Request;
use Concrete\Core\Support\Facade\Application as Core;

defined('C5_EXECUTE') or die(_("Access Denied."));

class CookieAllowance
{

    public function cookiesAllowed()
    {
        $r = Request::getInstance();
        $session = $r->getSession();

        if (!$session) {
            $session = Core::make('session');
        }

        if (!$session->has('cookies_allowed')) {
            $cookie = Core::make('cookie');

            if ($cookie->has('cookies_allowed') && $cookie->get('cookies_allowed') == true) {
                $session->set('cookies_allowed', true);

                return true;
            }

            return false;
        }

        return $session->get('cookies_allowed') == true;
    }

}
{'fraction_non_alphanumeric': 0.14691270404542228, 'fraction_numerical': 0.0014194464158978, 'mean_word_length': 2.49009900990099, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2847957', 'n_tokens_mistral': 415, 'n_tokens_neox': 400, 'n_words': 72}