From bb709274b24b9b3bdc4580c58cdad8f6d9d9e6cd Mon Sep 17 00:00:00 2001
From: Jean-Christian Denis '.
- form::field(
- 'disclaimer_title',
- 30,
- 255,
- html::escapeHTML($disclaimer_title)
- ).
- ' '.
- form::field(
- 'disclaimer_redir',
- 30,
- 255,
- html::escapeHTML($disclaimer_redir)
- ).' '.__('Leave blank to redirect to the site Dotclear').' '.
- form::textarea(
- 'disclaimer_text',
- 60,
- 5,
- html::escapeHTML($disclaimer_text)
- ).' ' .
+ form::field(
+ 'disclaimer_title',
+ 30,
+ 255,
+ html::escapeHTML((string) $s->get('disclaimer_title'))
+ ) .
+ ' '.
- form::field(
- 'disclaimer_bots_agents',
- 120,
- 255,
- html::escapeHTML($disclaimer_bots_agents)
- ).' ' .
+ 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)
+ ) . ''.__('Disclaimer').'
'.
+dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function (dcSettings $blog_settings) {
+ $s = $blog_settings->addNamespace(basename(__DIR__));
- '' . __('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', + ], +]; +// Nothing to change below try { + // Version + if (!dcCore::app()->newVersion( + basename(__DIR__), + dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version') + )) { + return null; + } - # Check module version - if (version_compare( - $core->getVersion($mod_id), - $core->plugins->moduleInfo($mod_id, 'version'), - '>=' - )) { + // 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 + ); + } - return null; - } - - # Check Dotclear version - if (!method_exists('dcUtils', 'versionsCompare') - || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false)) { - throw new Exception(sprintf( - '%s requires Dotclear %s', $mod_id, $dc_min - )); - } - - # Set module settings - $core->blog->settings->addNamespace($mod_id); - foreach($mod_conf as $v) { - $core->blog->settings->{$mod_id}->put( - $v[0], $v[2], $v[3], $v[1], false, true - ); - } - - # Set module version - $core->setVersion( - $mod_id, - $core->plugins->moduleInfo($mod_id, 'version') - ); - - return true; + return true; +} catch (Exception $e) { + dcCore::app()->error->add($e->getMessage()); } -catch (Exception $e) { - $core->error->add($e->getMessage()); - return false; -} \ No newline at end of file +return false; diff --git a/_public.php b/_public.php index 5ddfcc9..656f66e 100644 --- a/_public.php +++ b/_public.php @@ -1,27 +1,24 @@ blog->settings->addNamespace('disclaimer'); +dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); # Is active -if (!$core->blog->settings->disclaimer->disclaimer_active) { - - return null; +if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('disclaimer_active')) { + return null; } # Localized l10n @@ -30,28 +27,30 @@ __('Accept terms of uses'); __('I agree'); __('I disagree'); -# Behaviors -$core->addBehavior( - 'publicBeforeDocument', - array('urlDisclaimer', 'publicBeforeDocument') -); -$core->addBehavior( - 'publicHeadContent', - array('urlDisclaimer', 'publicHeadContent') -); - # Templates -$core->tpl->addValue( - 'DisclaimerTitle', - array('tplDisclaimer', 'DisclaimerTitle') -); -$core->tpl->addValue( - 'DisclaimerText', - array('tplDisclaimer', 'DisclaimerText') -); -$core->tpl->addValue( - 'DisclaimerFormURL', - array('tplDisclaimer', 'DisclaimerFormURL') +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'] ); /** @@ -61,202 +60,137 @@ $core->tpl->addValue( */ class urlDisclaimer extends dcUrlHandlers { - public static $default_bots_agents = array( - 'bot','Scooter','Slurp','Voila','WiseNut','Fast','Index','Teoma', - 'Mirago','search','find','loader','archive','Spider','Crawler' - ); + private const COOKIE_PREFIX = 'dc_disclaimer_cookie_'; - /** - * Remove public callbacks (and serve disclaimer css) - * - * @param array $args Arguments - */ - public static function overwriteCallbacks($args) - { - if ($args == 'disclaimer.css') { - self::serveDocument('disclaimer.css', 'text/css', false); - exit; - } + public static $default_bots_agents = [ + 'bot','Scooter','Slurp','Voila','WiseNut','Fast','Index','Teoma', + 'Mirago','search','find','loader','archive','Spider','Crawler', + ]; - return null; - } - - /** - * Add CSS for disclaimer - * - * @param dcCore $core dcCore instance - * @return [type] [description] - */ - public static function publicHeadContent(dcCore $core) - { - $url = $core->blog->getQmarkURL().'pf='.basename(dirname(__FILE__)); - echo - '\n"; - } - - /** - * Check disclaimer - * - * @param array $args Arguments - */ - public static function publicBeforeDocument($args) - { - global $core, $_ctx; - - # Test user-agent to see if it is a bot - if (!$core->blog->settings->disclaimer->disclaimer_bots_unactive) { - $bots_agents = $core->blog->settings->disclaimer->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; - } - } - - # Set default-templates path for disclaimer files - $tplset = $core->themes->moduleInfo($core->blog->settings->system->theme,'tplset'); - if (!empty($tplset) && is_dir(dirname(__FILE__).'/default-templates/'.$tplset)) { - $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/'.$tplset); - } else { - $core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/'.DC_DEFAULT_TPLSET); + /** + * Remove public callbacks (and serve disclaimer css) + * + * @param array $args Arguments + */ + public static function overwriteCallbacks($args) + { + if ($args == 'disclaimer.css') { + self::serveDocument('disclaimer.css', 'text/css', false); + exit; } - # New URL handler - $urlHandler = new urlHandler(); - $urlHandler->mode = $core->url->mode; - $urlHandler->registerDefault(array( - 'urlDisclaimer', - 'overwriteCallbacks' - )); + return null; + } - # Create session if not exists - if (!isset($session)) { - $session = new sessionDB( - $core->con, - $core->prefix.'session', - 'dc_disclaimer_sess_'.$core->blog->id, - '/' - ); - $session->start(); - } + /** + * Check disclaimer + */ + public static function publicBeforeDocumentV2() + { + $s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__)); - # Remove all URLs representations - foreach ($core->url->getTypes() as $k => $v) { - $urlHandler->register( - $k, - $v['url'], - $v['representation'], - array('urlDisclaimer', 'overwriteCallbacks') - ); - } + # 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); - # Get type - $urlHandler->getDocument(); - $type = $urlHandler->type; - unset($urlHandler); + $is_bot = false; + foreach ($bots_agents as $bot) { + if (stristr($_SERVER['HTTP_USER_AGENT'], $bot)) { + $is_bot = true; + } + } - # Test cookie - $cookie_name="dc_disclaimer_cookie_".$core->blog->id; - $cookie_value = - empty($_COOKIE[$cookie_name]) - || !$core->blog->settings->disclaimer->disclaimer_remember ? - false : ($_COOKIE[$cookie_name]) == 1; + if ($is_bot) { + return null; + } + } - # User say "disagree" so go away - if (isset($_POST['disclaimerdisagree'])) { - $session->destroy(); - if ($core->blog->settings->disclaimer->disclaimer_remember) { - setcookie($cookie_name, 0, time()-86400, '/'); - } - $redir = $core->blog->settings->disclaimer->disclaimer_redir; - if (!$redir) { - $redir = 'http://www.dotclear.org'; - } - http::redirect($redir); - exit; - } + # 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); + } - # Check if user say yes before - elseif (!isset($_SESSION['sess_blog_disclaimer']) - || $_SESSION['sess_blog_disclaimer'] != 1 - ) { - if ($core->blog->settings->disclaimer->disclaimer_remember - && $cookie_value != false - ) { - $_SESSION['sess_blog_disclaimer'] = 1; + # New URL handler + $urlHandler = new urlHandler(); + $urlHandler->mode = dcCore::app()->url->mode; + $urlHandler->registerDefault([ + 'urlDisclaimer', + 'overwriteCallbacks', + ]); - return null; - } - if (!empty($_POST['disclaimeragree'])) { - $_SESSION['sess_blog_disclaimer'] = 1; + # Create session + $session = new sessionDB( + dcCore::app()->con, + dcCore::app()->prefix . 'session', + 'dc_disclaimer_sess_' . dcCore::app()->blog->id, + '/' + ); + $session->start(); - if ($core->blog->settings->disclaimer->disclaimer_remember) { - setcookie($cookie_name, 1, time() + 31536000, '/'); - } + # Remove all URLs representations + foreach (dcCore::app()->url->getTypes() as $k => $v) { + $urlHandler->register( + $k, + $v['url'], + $v['representation'], + ['urlDisclaimer', 'overwriteCallbacks'] + ); + } - return null; - } + # Get type + $urlHandler->getDocument(); + $type = $urlHandler->type; + unset($urlHandler); - $session->destroy(); - self::serveDocument('disclaimer.html', 'text/html', false); - exit; - } + # 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; - return null; - } + # 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; + } } - -/** - * @ingroup DC_PLUGIN_DISCLAIMER - * @brief Public disclaimer - Template. - * @since 2.6 - */ -class tplDisclaimer -{ - /** - * Public title of disclaimer page and form - * - * @param array $attr Template value attribute - */ - public static function DisclaimerTitle($attr) - { - $f = $GLOBALS['core']->tpl->getFilters($attr); - - return - 'blog->settings->disclaimer->disclaimer_title' - ).'; ?>'; - } - - /** - * Public disclaimer text - * - * @param array $attr Template value attribute - */ - public static function DisclaimerText($attr) - { - return - 'blog->settings->disclaimer->disclaimer_text; ?>'; - } - - /** - * Public URL of disclaimer form action - * - * @param array $attr Template value attribute - */ - public static function DisclaimerFormURL($attr) - { - return 'blog->url; ?>'; - } -} \ No newline at end of file diff --git a/_uninstall.php b/_uninstall.php index 552c5bc..bbff3f5 100644 --- a/_uninstall.php +++ b/_uninstall.php @@ -1,62 +1,81 @@ addUserAction( - /* type */ 'settings', - /* action */ 'delete_all', - /* ns */ $mod_id, - /* desc */ __('delete all settings') + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + basename(__DIR__), + /* desc */ + __('delete all settings') ); $this->addUserAction( - /* type */ 'plugins', - /* action */ 'delete', - /* ns */ $mod_id, - /* desc */ __('delete plugin files') + /* type */ + 'plugins', + /* action */ + 'delete', + /* ns */ + basename(__DIR__), + /* desc */ + __('delete plugin files') ); $this->addUserAction( - /* type */ 'versions', - /* action */ 'delete', - /* ns */ $mod_id, - /* desc */ __('delete the version number') -); - - -$this->addDirectAction( - /* type */ 'settings', - /* action */ 'delete_all', - /* ns */ $mod_id, - /* desc */ sprintf(__('delete all %s settings'), $mod_id) + /* type */ + 'versions', + /* action */ + 'delete', + /* ns */ + basename(__DIR__), + /* desc */ + __('delete the version number') ); $this->addDirectAction( - /* type */ 'plugins', - /* action */ 'delete', - /* ns */ $mod_id, - /* desc */ sprintf(__('delete %s plugin files'), $mod_id) + /* type */ + 'settings', + /* action */ + 'delete_all', + /* ns */ + basename(__DIR__), + /* desc */ + sprintf(__('delete all %s settings'), basename(__DIR__)) ); $this->addDirectAction( - /* type */ 'versions', - /* action */ 'delete', - /* ns */ $mod_id, - /* desc */ sprintf(__('delete %s version number'), $mod_id) -); \ No newline at end of file + /* 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/dcstore.xml b/dcstore.xml new file mode 100644 index 0000000..3423fda --- /dev/null +++ b/dcstore.xml @@ -0,0 +1,13 @@ + +