From 2c10ad8e021642778778f4a2eaea26e4a0e82e78 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Mon, 10 Apr 2023 10:14:10 +0200 Subject: [PATCH] use namespace --- src/Backend.php | 229 +++++++++++++++++++++++---------------------- src/Frontend.php | 213 +++++++++-------------------------------- src/Install.php | 193 ++++++++++++++++++++------------------ src/My.php | 83 ++++++++++++++++ src/Uninstall.php | 157 +++++++++++++++++-------------- src/UrlHandler.php | 152 ++++++++++++++++++++++++++++++ 6 files changed, 590 insertions(+), 437 deletions(-) create mode 100644 src/My.php create mode 100644 src/UrlHandler.php diff --git a/src/Backend.php b/src/Backend.php index 3e924df..4a3a8db 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -10,115 +10,122 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_CONTEXT_ADMIN')) { - return null; +declare(strict_types=1); + +namespace Dotclear\Plugin\disclaimer; + +use dcCore; +use dcPage; +use dcNsProcess; +use dcSettings; +use Dotclear\Helper\Html\Form\{ + Checkbox, + Div, + Label, + Input, + Note, + Para, + Text, + Textarea +}; +use Dotclear\Helper\Html\Html; +use Exception; + +class Backend extends dcNsProcess +{ + public static function init(): bool + { + static::$init = defined('DC_CONTEXT_ADMIN') + && My::phpCompliant() + && dcCore::app()->auth->check(dcCore::app()->auth->makePermissions([ + dcCore::app()->auth::PERMISSION_CONTENT_ADMIN, + ]), dcCore::app()->blog->id); + + return static::$init; + } + + public static function process(): bool + { + if (!static::$init) { + return false; + } + + dcCore::app()->addBehaviors([ + 'adminBeforeBlogSettingsUpdate' => function (dcSettings $blog_settings): void { + $s = $blog_settings->get(My::id()); + + try { + $s->put('disclaimer_active', isset($_POST['disclaimer_active'])); + $s->put('disclaimer_remember', isset($_POST['disclaimer_remember'])); + $s->put('disclaimer_redir', $_POST['disclaimer_redir'] ?? ''); + $s->put('disclaimer_title', $_POST['disclaimer_title'] ?? ''); + $s->put('disclaimer_text', $_POST['disclaimer_text'] ?? ''); + $s->put('disclaimer_bots_unactive', isset($_POST['disclaimer_bots_unactive'])); + $s->put('disclaimer_bots_agents', $_POST['disclaimer_bots_agents'] ?? ''); + } catch (Exception $e) { + $s->drop('disclaimer_active'); + $s->put('disclaimer_active', 0); + } + }, + + 'adminBlogPreferencesHeaders' => function (): string { + $editor = dcCore::app()->auth->getOption('editor'); + + return + dcCore::app()->callBehavior('adminPostEditor', $editor['xhtml'], 'disclaimer', ['#disclaimer_text'], 'xhtml') . + dcPage::jsModuleLoad(My::id() . '/js/backend.js'); + }, + + 'adminBlogPreferencesFormV2' => function (dcSettings $blog_settings): void { + $s = $blog_settings->get(My::id()); + + $disclaimer_bots_agents = $s->get('disclaimer_bots_agents'); + if (empty($disclaimer_bots_agents)) { + $disclaimer_bots_agents = implode(';', My::DEFAULT_BOTS_AGENTS); + } + + echo + (new Div())->class('fieldset')->items([ + (new Text('h4', My::name()))->id('disclaimerParam'), + (new Div())->class('two-boxes even')->items([ + (new Para())->items([ + (new Checkbox('disclaimer_active', (bool) $s->get('disclaimer_active')))->value(1), + (new Label(__('Enable disclaimer'), Label::OUTSIDE_LABEL_AFTER))->for('disclaimer_active')->class('classic'), + ]), + (new Para())->items([ + (new Label(__('Title:')))->for('disclaimer_title'), + (new Input('disclaimer_title'))->size(30)->maxlenght(255)->value(Html::escapeHTML((string) $s->get('disclaimer_title'))), + ]), + ]), + (new Div())->class('two-boxes odd')->items([ + (new Para())->items([ + (new Checkbox('disclaimer_remember', (bool) $s->get('disclaimer_remember')))->value(1), + (new Label(__('Remember the visitor'), Label::OUTSIDE_LABEL_AFTER))->for('disclaimer_remember')->class('classic'), + ]), + (new Para())->items([ + (new Label(__('Link output:')))->for('disclaimer_redir'), + (new Input('disclaimer_redir'))->size(30)->maxlenght(255)->value(Html::escapeHTML((string) $s->get('disclaimer_redir'))), + ]), + (new Note())->class('form-note')->text(__('Leave blank to redirect to the site Dotclear')), + ]), + (new Div())->class('clear')->items([ + (new Para())->items([ + (new Label(__('Disclaimer:'), Label::OUTSIDE_LABEL_BEFORE))->for('disclaimer_text'), + (new Textarea('disclaimer_text', Html::escapeHTML((string) $s->get('disclaimer_text'))))->cols(60)->rows(5)->lang(dcCore::app()->blog->settings->get('system')->get('lang'))->spellcheck(true), + ]), + (new Para())->items([ + (new Label(__('List of robots allowed to index the site pages (separated by semicolons):')))->for('disclaimer_bots_agents'), + (new Input('disclaimer_bots_agents'))->size(120)->maxlenght(255)->value(Html::escapeHTML($disclaimer_bots_agents)), + ]), + (new Para())->items([ + (new Checkbox('disclaimer_bots_unactive', (bool) $s->get('disclaimer_bots_unactive')))->value(1), + (new Label(__('Disable the authorization of indexing by search engines'), Label::OUTSIDE_LABEL_AFTER))->for('disclaimer_bots_unactive')->class('classic'), + ]), + ]), + ])->render(); + }, + ]); + + return true; + } } - -dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function (dcSettings $blog_settings) { - $s = $blog_settings->addNamespace(basename(__DIR__)); - - try { - $s->put('disclaimer_active', isset($_POST['disclaimer_active'])); - $s->put('disclaimer_remember', isset($_POST['disclaimer_remember'])); - $s->put('disclaimer_redir', $_POST['disclaimer_redir'] ?? ''); - $s->put('disclaimer_title', $_POST['disclaimer_title'] ?? ''); - $s->put('disclaimer_text', $_POST['disclaimer_text'] ?? ''); - $s->put('disclaimer_bots_unactive', isset($_POST['disclaimer_bots_unactive'])); - $s->put('disclaimer_bots_agents', $_POST['disclaimer_bots_agents'] ?? ''); - } catch (Exception $e) { - $s->drop('disclaimer_active'); - $s->put('disclaimer_active', 0); - } -}); - -dcCore::app()->addBehavior('adminBlogPreferencesHeaders', function () { - $editor = dcCore::app()->auth->getOption('editor'); - - return - dcCore::app()->callBehavior('adminPostEditor', $editor['xhtml'], 'disclaimer', ['#disclaimer_text'], 'xhtml') . - dcPage::jsModuleLoad(basename(__DIR__) . '/js/admin.js'); -}); - -dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (dcSettings $blog_settings) { - $s = $blog_settings->addNamespace(basename(__DIR__)); - - $disclaimer_bots_agents = $s->get('disclaimer_bots_agents'); - if (empty($disclaimer_bots_agents)) { - $disclaimer_bots_agents = 'bot;Scooter;Slurp;Voila;WiseNut;Fast;Index;Teoma;' . - 'Mirago;search;find;loader;archive;Spider;Crawler'; - } - - echo - '
' . - '

' . __('Disclaimer') . '

' . - '
' . - - '

' . - - '

' . - form::field( - 'disclaimer_title', - 30, - 255, - html::escapeHTML((string) $s->get('disclaimer_title')) - ) . - '

' . - - '
' . - - '

' . - - '

' . - form::field( - 'disclaimer_redir', - 30, - 255, - html::escapeHTML((string) $s->get('disclaimer_redir')) - ) . '

' . - '

' . __('Leave blank to redirect to the site Dotclear') . '

' . - - '
' . - - '

' . - form::textarea( - 'disclaimer_text', - 60, - 5, - [ - 'default' => html::escapeHTML((string) $s->get('disclaimer_text')), - 'extra_html' => 'lang="' . dcCore::app()->blog->settings->get('system')->get('lang') . '" spellcheck="true"', - ] - ) . '

' . - - '

' . - form::field( - 'disclaimer_bots_agents', - 120, - 255, - html::escapeHTML($disclaimer_bots_agents) - ) . '

' . - - '

' . - - '
' . - '
'; -}); diff --git a/src/Frontend.php b/src/Frontend.php index bdbbeba..3e468ec 100644 --- a/src/Frontend.php +++ b/src/Frontend.php @@ -10,188 +10,65 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_RC_PATH')) { - return null; -} +declare(strict_types=1); -dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); +namespace Dotclear\Plugin\disclaimer; -# Is active -if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('disclaimer_active')) { - return null; -} +use ArrayObject; +use dcCore; +use dcNsProcess; +use dcUtils; -# Localized l10n -__('Disclaimer'); -__('Accept terms of uses'); -__('I agree'); -__('I disagree'); - -# Templates -dcCore::app()->tpl->addValue('DisclaimerTitle', function ($attr) { - return 'tpl->getFilters($attr), - 'dcCore::app()->blog->settings->get("disclaimer")->get("disclaimer_title")' - ) . '; ?>'; -}); - -dcCore::app()->tpl->addValue('DisclaimerText', function ($attr) { - return 'blog->settings->get("disclaimer")->get("disclaimer_text"); ?>'; -}); - -dcCore::app()->tpl->addValue('DisclaimerFormURL', function ($attr) { - return 'blog->url; ?>'; -}); - -# Behaviors -dcCore::app()->addBehavior('publicHeadContent', function () { - echo dcUtils::cssModuleLoad(basename(__DIR__) . '/css/disclaimer.css'); -}); - -dcCore::app()->addBehavior( - 'publicBeforeDocumentV2', - ['urlDisclaimer', 'publicBeforeDocumentV2'] -); - -/** - * @ingroup DC_PLUGIN_DISCLAIMER - * @brief Public disclaimer - URL handler. - * @since 2.6 - */ -class urlDisclaimer extends dcUrlHandlers +class Frontend extends dcNsProcess { - private const COOKIE_PREFIX = 'dc_disclaimer_cookie_'; - private const SESSION_PREFIX = 'dc_disclaimer_sess_'; - - public static $default_bots_agents = [ - 'bot','Scooter','Slurp','Voila','WiseNut','Fast','Index','Teoma', - 'Mirago','search','find','loader','archive','Spider','Crawler', - ]; - - /** - * Remove public callbacks (and serve disclaimer css) - * - * @param array $args Arguments - */ - public static function overwriteCallbacks($args) + public static function init(): bool { - if ($args == 'disclaimer.css') { - self::serveDocument('disclaimer.css', 'text/css', false); - exit; - } + static::$init = My::phpCompliant(); - return null; + return static::$init; } - /** - * Check disclaimer - */ - public static function publicBeforeDocumentV2() + public static function process(): bool { - $s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); - - # Test user-agent to see if it is a bot - if (!$s->get('disclaimer_bots_unactive')) { - $bots_agents = $s->get('diclaimer_bots_agents'); - $bots_agents = !$bots_agents ? self::$default_bots_agents : explode(';', $bots_agents); - - $is_bot = false; - foreach ($bots_agents as $bot) { - if (stristr($_SERVER['HTTP_USER_AGENT'], $bot)) { - $is_bot = true; - } - } - - if ($is_bot) { - return null; - } + if (!static::$init) { + return false; } - # Set default-templates path for disclaimer files - $tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->get('system')->get('theme'), 'tplset'); - if (!empty($tplset) && is_dir(__DIR__ . '/default-templates/' . $tplset)) { - dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/' . $tplset); - } else { - dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/' . DC_DEFAULT_TPLSET); + # Is active + if (!dcCore::app()->blog->settings->get(My::id())->get('disclaimer_active')) { + return false; } - # New URL handler - $urlHandler = new urlHandler(); - $urlHandler->mode = dcCore::app()->url->mode; - $urlHandler->registerDefault([ - 'urlDisclaimer', - 'overwriteCallbacks', + # Localized l10n + __('Disclaimer'); + __('Accept terms of uses'); + __('I agree'); + __('I disagree'); + + # Templates + dcCore::app()->tpl->addValue('DisclaimerTitle', function (ArrayObject $attr): string { + return 'tpl->getFilters($attr), + 'dcCore::app()->blog->settings->get("disclaimer")->get("disclaimer_title")' + ) . '; ?>'; + }); + + dcCore::app()->tpl->addValue('DisclaimerText', function (ArrayObject $attr): string { + return 'blog->settings->get("disclaimer")->get("disclaimer_text"); ?>'; + }); + + dcCore::app()->tpl->addValue('DisclaimerFormURL', function (ArrayObject $attr): string { + return 'blog->url; ?>'; + }); + + # Behaviors + dcCore::app()->addBehaviors([ + 'publicHeadContent' => function (): void { + echo dcUtils::cssModuleLoad(My::id() . '/css/disclaimer.css'); + }, + 'publicBeforeDocumentV2' => [UrlHandler::class, 'publicBeforeDocumentV2'], ]); - # Create session - $session = new sessionDB( - dcCore::app()->con, - dcCore::app()->prefix . 'session', - self::SESSION_PREFIX . dcCore::app()->blog->id, - '/' - ); - $session->start(); - - # Remove all URLs representations - foreach (dcCore::app()->url->getTypes() as $k => $v) { - $urlHandler->register( - $k, - $v['url'], - $v['representation'], - ['urlDisclaimer', 'overwriteCallbacks'] - ); - } - - # Get type - $urlHandler->getDocument(); - $type = $urlHandler->type; - unset($urlHandler); - - # Test cookie - $cookie_name = self::COOKIE_PREFIX . dcCore::app()->blog->id; - $cookie_value = empty($_COOKIE[$cookie_name]) || !$s->get('disclaimer_remember') ? - false : ($_COOKIE[$cookie_name]) == 1; - - # User say "disagree" so go away - if (isset($_POST['disclaimerdisagree'])) { - $session->destroy(); - if ($s->get('disclaimer_remember')) { - setcookie($cookie_name, '0', time() - 86400, '/'); - } - $redir = $s->get('disclaimer_redir'); - if (!$redir) { - $redir = 'http://www.dotclear.org'; - } - http::redirect($redir); - exit; - } - - # Check if user say yes before - elseif (!isset($_SESSION['sess_blog_disclaimer']) - || $_SESSION['sess_blog_disclaimer'] != 1 - ) { - if ($s->get('disclaimer_remember') - && $cookie_value != false - ) { - $_SESSION['sess_blog_disclaimer'] = 1; - - return null; - } - if (!empty($_POST['disclaimeragree'])) { - $_SESSION['sess_blog_disclaimer'] = 1; - - if ($s->get('disclaimer_remember')) { - setcookie($cookie_name, '1', time() + 31536000, '/'); - } - - return null; - } - - $session->destroy(); - self::serveDocument('disclaimer.html', 'text/html', false); - exit; - } - - return null; + return true; } } diff --git a/src/Install.php b/src/Install.php index 40f15b9..81cb845 100644 --- a/src/Install.php +++ b/src/Install.php @@ -10,99 +10,112 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_CONTEXT_ADMIN')) { - return null; -} +declare(strict_types=1); -// Module specs -$mod_conf = [ - [ - 'disclaimer_active', - 'Enable disclaimer plugin', - false, - 'boolean', - ], - [ - 'disclaimer_remember', - 'Remember the visitor who has already accepted the terms', - false, - 'boolean', - ], - [ - 'disclaimer_redir', - 'Redirection if disclaimer is refused', - 'https://www.google.fr', - 'string', - ], - [ - 'disclaimer_title', - 'Title for disclaimer', - 'Disclaimer', - 'string', - ], - [ - 'disclaimer_text', - 'Description for disclaimer', - __('

You must accept this term before entering

'), - //'You must accept this term before entering', - 'string', - ], - [ - 'disclaimer_bots_unactive', - 'Bypass disclaimer for bots', - false, - 'boolean', - ], - [ - 'disclaimer_bots_agents', - 'List of know bots', - implode(';', [ - 'bot', - 'Scooter', - 'Slurp', - 'Voila', - 'WiseNut', - 'Fast', - 'Index', - 'Teoma', - 'Mirago', - 'search', - 'find', - 'loader', - 'archive', - 'Spider', - 'Crawler', - ]), - 'string', - ], -]; +namespace Dotclear\Plugin\disclaimer; -// Nothing to change below -try { - // Version - if (!dcCore::app()->newVersion( - basename(__DIR__), - dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') - )) { - return null; +use dcCore; +use dcNsProcess; +use Exception; + +class Install extends dcNsProcess +{ + public static function init(): bool + { + static::$init = defined('DC_CONTEXT_ADMIN') + && My::phpCompliant() + && dcCore::app()->newVersion(My::id(), dcCore::app()->plugins->moduleInfo(My::id(), 'version')); + + return static::$init; } - // Settings - dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); - foreach ($mod_conf as $v) { - dcCore::app()->blog->settings->get(basename(__DIR__))->put( - $v[0], - $v[2], - $v[3], - $v[1], - false, - true - ); + public static function process(): bool + { + if (!static::$init) { + return false; + } + + // Module specs + $mod_conf = [ + [ + 'disclaimer_active', + 'Enable disclaimer plugin', + false, + 'boolean', + ], + [ + 'disclaimer_remember', + 'Remember the visitor who has already accepted the terms', + false, + 'boolean', + ], + [ + 'disclaimer_redir', + 'Redirection if disclaimer is refused', + 'https://www.google.fr', + 'string', + ], + [ + 'disclaimer_title', + 'Title for disclaimer', + 'Disclaimer', + 'string', + ], + [ + 'disclaimer_text', + 'Description for disclaimer', + __('

You must accept this term before entering

'), + //'You must accept this term before entering', + 'string', + ], + [ + 'disclaimer_bots_unactive', + 'Bypass disclaimer for bots', + false, + 'boolean', + ], + [ + 'disclaimer_bots_agents', + 'List of know bots', + implode(';', [ + 'bot', + 'Scooter', + 'Slurp', + 'Voila', + 'WiseNut', + 'Fast', + 'Index', + 'Teoma', + 'Mirago', + 'search', + 'find', + 'loader', + 'archive', + 'Spider', + 'Crawler', + ]), + 'string', + ], + ]; + + try { + // Settings + foreach ($mod_conf as $v) { + dcCore::app()->blog->settings->get(My::id())->put( + $v[0], + $v[2], + $v[3], + $v[1], + false, + true + ); + } + + return true; + } catch (Exception $e) { + dcCore::app()->error->add($e->getMessage()); + } + + return true; } - - return true; -} catch (Exception $e) { - dcCore::app()->error->add($e->getMessage()); } - -return false; diff --git a/src/My.php b/src/My.php new file mode 100644 index 0000000..d246b92 --- /dev/null +++ b/src/My.php @@ -0,0 +1,83 @@ +plugins->moduleInfo(self::id(), 'name')); + } + + /** + * This mdoule directory + */ + public static function root(): string + { + return dirname(__DIR__); + } + + /** + * Check php version + */ + public static function phpCompliant(): bool + { + return version_compare(phpversion(), self::PHP_MIN, '>='); + } +} diff --git a/src/Uninstall.php b/src/Uninstall.php index bbff3f5..d19efc9 100644 --- a/src/Uninstall.php +++ b/src/Uninstall.php @@ -10,72 +10,93 @@ * @copyright Jean-Christian Denis * @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html */ -if (!defined('DC_CONTEXT_ADMIN')) { - return null; +declare(strict_types=1); + +namespace Dotclear\Plugin\disclaimer; + +class Uninstall +{ + protected static bool $init = false; + + public static function init(): bool + { + self::$init = defined('DC_RC_PATH'); + + return self::$init; + } + + public static function process($uninstaller): ?bool + { + if (!self::$init) { + return false; + } + + $uninstaller->addUserAction( + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + My::id(), + /* desc */ + __('delete all settings') + ); + + $uninstaller->addUserAction( + /* type */ + 'plugins', + /* action */ + 'delete', + /* ns */ + My::id(), + /* desc */ + __('delete plugin files') + ); + + $uninstaller->addUserAction( + /* type */ + 'versions', + /* action */ + 'delete', + /* ns */ + My::id(), + /* desc */ + __('delete the version number') + ); + + $uninstaller->addDirectAction( + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + My::id(), + /* desc */ + sprintf(__('delete all %s settings'), My::id()) + ); + + $uninstaller->addDirectAction( + /* type */ + 'plugins', + /* action */ + 'delete', + /* ns */ + My::id(), + /* desc */ + sprintf(__('delete %s plugin files'), My::id()) + ); + + $uninstaller->addDirectAction( + /* type */ + 'versions', + /* action */ + 'delete', + /* ns */ + My::id(), + /* desc */ + sprintf(__('delete %s version number'), My::id()) + ); + + return true; + } } - -$this->addUserAction( - /* type */ - 'settings', - /* action */ - 'delete_all', - /* ns */ - basename(__DIR__), - /* desc */ - __('delete all settings') -); - -$this->addUserAction( - /* type */ - 'plugins', - /* action */ - 'delete', - /* ns */ - basename(__DIR__), - /* desc */ - __('delete plugin files') -); - -$this->addUserAction( - /* type */ - 'versions', - /* action */ - 'delete', - /* ns */ - basename(__DIR__), - /* desc */ - __('delete the version number') -); - -$this->addDirectAction( - /* type */ - 'settings', - /* action */ - 'delete_all', - /* ns */ - basename(__DIR__), - /* desc */ - sprintf(__('delete all %s settings'), basename(__DIR__)) -); - -$this->addDirectAction( - /* type */ - 'plugins', - /* action */ - 'delete', - /* ns */ - basename(__DIR__), - /* desc */ - sprintf(__('delete %s plugin files'), basename(__DIR__)) -); - -$this->addDirectAction( - /* type */ - 'versions', - /* action */ - 'delete', - /* ns */ - basename(__DIR__), - /* desc */ - sprintf(__('delete %s version number'), basename(__DIR__)) -); diff --git a/src/UrlHandler.php b/src/UrlHandler.php new file mode 100644 index 0000000..e3cd2d1 --- /dev/null +++ b/src/UrlHandler.php @@ -0,0 +1,152 @@ +blog->settings->get(My::id()); + + # Test user-agent to see if it is a bot + if (!$s->get('disclaimer_bots_unactive')) { + $bots_agents = $s->get('diclaimer_bots_agents'); + $bots_agents = !$bots_agents ? My::DEFAULT_BOTS_AGENTS : explode(';', $bots_agents); + + $is_bot = false; + foreach ($bots_agents as $bot) { + if (stristr($_SERVER['HTTP_USER_AGENT'], $bot)) { + $is_bot = true; + } + } + + if ($is_bot) { + return; + } + } + + # Set default-templates path for disclaimer files + $tplset = dcCore::app()->themes->moduleInfo(dcCore::app()->blog->settings->get('system')->get('theme'), 'tplset'); + if (!empty($tplset) && is_dir(My::root() . '/default-templates/' . $tplset)) { + dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), My::root() . '/default-templates/' . $tplset); + } else { + dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), My::root() . '/default-templates/' . DC_DEFAULT_TPLSET); + } + + # New URL handler + $urlHandler = new HelperHandler(); + $urlHandler->mode = dcCore::app()->url->mode; + $urlHandler->registerDefault([ + self::class, + 'overwriteCallbacks', + ]); + + # Create session + $session = new sessionDB( + dcCore::app()->con, + dcCore::app()->prefix . 'session', + My::SESSION_PREFIX . dcCore::app()->blog->id, + '/' + ); + $session->start(); + + # Remove all URLs representations + foreach (dcCore::app()->url->getTypes() as $k => $v) { + $urlHandler->register( + $k, + $v['url'], + $v['representation'], + [self::class, 'overwriteCallbacks'] + ); + } + + # Get type + $urlHandler->getDocument(); + $type = $urlHandler->type; + unset($urlHandler); + + # Test cookie + $cookie_name = My::COOKIE_PREFIX . dcCore::app()->blog->id; + $cookie_value = empty($_COOKIE[$cookie_name]) || !$s->get('disclaimer_remember') ? + false : ($_COOKIE[$cookie_name]) == 1; + + # User say "disagree" so go away + if (isset($_POST['disclaimerdisagree'])) { + $session->destroy(); + if ($s->get('disclaimer_remember')) { + setcookie($cookie_name, '0', time() - 86400, '/'); + } + $redir = $s->get('disclaimer_redir'); + if (!$redir) { + $redir = 'http://www.dotclear.org'; + } + Http::redirect($redir); + exit; + } + + # Check if user say yes before + elseif (!isset($_SESSION['sess_blog_disclaimer']) + || $_SESSION['sess_blog_disclaimer'] != 1 + ) { + if ($s->get('disclaimer_remember') + && $cookie_value != false + ) { + $_SESSION['sess_blog_disclaimer'] = 1; + + return; + } + if (!empty($_POST['disclaimeragree'])) { + $_SESSION['sess_blog_disclaimer'] = 1; + + if ($s->get('disclaimer_remember')) { + setcookie($cookie_name, '1', time() + 31536000, '/'); + } + + return; + } + + $session->destroy(); + self::serveDocument('disclaimer.html', 'text/html', false); + exit; + } + } +}