code review for dotclear 2.24
This commit is contained in:
parent
c8de8345a1
commit
bb709274b2
@ -1,3 +1,9 @@
|
||||
todo
|
||||
bug jsToolBar !
|
||||
|
||||
1.0 - 2022.12.xx
|
||||
* update to dotclear 2.24
|
||||
|
||||
v0.9 - 19-07-2015 - Pierre Van Glabek
|
||||
* héritabe thème mustek
|
||||
* dc2.8 requis
|
||||
|
@ -1,5 +1,12 @@
|
||||
# README
|
||||
|
||||
[![Release](https://img.shields.io/github/v/release/JcDenis/disclaimer)](https://github.com/JcDenis/disclaimer/releases)
|
||||
[![Date](https://img.shields.io/github/release-date/JcDenis/disclaimer)](https://github.com/JcDenis/disclaimer/releases)
|
||||
[![Issues](https://img.shields.io/github/issues/JcDenis/disclaimer)](https://github.com/JcDenis/disclaimer/issues)
|
||||
[![Dotclear](https://img.shields.io/badge/dotclear-v2.24-blue.svg)](https://fr.dotclear.org/download)
|
||||
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/disclaimer)
|
||||
[![License](https://img.shields.io/github/license/JcDenis/disclaimer)](https://github.com/JcDenis/disclaimer/blob/master/LICENSE)
|
||||
|
||||
## QU'EST CE QUE DISCLAIMER ?
|
||||
|
||||
"disclaimer" est un plugin pour l'outil open source de
|
||||
|
221
_admin.php
221
_admin.php
@ -1,207 +1,124 @@
|
||||
<?php
|
||||
# -- BEGIN LICENSE BLOCK ----------------------------------
|
||||
#
|
||||
# This file is part of disclaimer, a plugin for Dotclear 2.
|
||||
#
|
||||
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors
|
||||
#
|
||||
# Licensed under the GPL version 2.0 license.
|
||||
# A copy of this license is available in LICENSE file or at
|
||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
#
|
||||
# -- END LICENSE BLOCK ------------------------------------
|
||||
|
||||
/**
|
||||
* @brief disclaimer, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis, Pierre Van Glabeke
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$core->addBehavior(
|
||||
'adminBeforeBlogSettingsUpdate',
|
||||
array('adminDisclaimer', 'adminBeforeBlogSettingsUpdate')
|
||||
);
|
||||
$core->addBehavior(
|
||||
'adminBlogPreferencesHeaders',
|
||||
array('adminDisclaimer', 'adminDisclaimerHeaders')
|
||||
);
|
||||
$core->addBehavior(
|
||||
'adminBlogPreferencesForm',
|
||||
array('adminDisclaimer', 'adminBlogPreferencesForm')
|
||||
);
|
||||
dcCore::app()->addBehavior('adminBeforeBlogSettingsUpdate', function (dcSettings $blog_settings) {
|
||||
$s = $blog_settings->addNamespace(basename(__DIR__));
|
||||
|
||||
/**
|
||||
* @ingroup DC_PLUGIN_DISCLAIMER
|
||||
* @brief Public disclaimer - Admin methods.
|
||||
* @since 2.6
|
||||
*/
|
||||
class adminDisclaimer
|
||||
{
|
||||
|
||||
/**
|
||||
* Save settings
|
||||
*
|
||||
* @param dcSettings $blog_settings dcSettings instance
|
||||
*/
|
||||
public static function adminBeforeBlogSettingsUpdate(dcSettings $blog_settings)
|
||||
{
|
||||
$blog_settings->addNamespace('disclaimer');
|
||||
$s = $blog_settings->disclaimer;
|
||||
try {
|
||||
$disclaimer_active =
|
||||
isset($_POST['disclaimer_active']);
|
||||
$disclaimer_remember =
|
||||
isset($_POST['disclaimer_remember']);
|
||||
$disclaimer_redir =
|
||||
isset($_POST['disclaimer_redir']) ?
|
||||
$_POST['disclaimer_redir'] : '';
|
||||
$disclaimer_title =
|
||||
isset($_POST['disclaimer_title']) ?
|
||||
$_POST['disclaimer_title'] : '';
|
||||
$disclaimer_text =
|
||||
isset($_POST['disclaimer_text']) ?
|
||||
$_POST['disclaimer_text'] : '';
|
||||
$disclaimer_bots_unactive =
|
||||
isset($_POST['disclaimer_bots_unactive']);
|
||||
$disclaimer_bots_agents =
|
||||
isset($_POST['disclaimer_bots_agents']) ?
|
||||
$_POST['disclaimer_bots_agents'] : '';
|
||||
|
||||
$s->put('disclaimer_active', $disclaimer_active);
|
||||
$s->put('disclaimer_remember', $disclaimer_remember);
|
||||
$s->put('disclaimer_redir', $disclaimer_redir);
|
||||
$s->put('disclaimer_title', $disclaimer_title);
|
||||
$s->put('disclaimer_text', $disclaimer_text);
|
||||
$s->put('disclaimer_bots_unactive', $disclaimer_bots_unactive);
|
||||
$s->put('disclaimer_bots_agents', $disclaimer_bots_agents);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
public static function adminDisclaimerHeaders()
|
||||
{
|
||||
global $core;
|
||||
dcCore::app()->addBehavior('adminBlogPreferencesHeaders', function () {
|
||||
$editor = dcCore::app()->auth->getOption('editor');
|
||||
|
||||
$post_format = $core->auth->getOption('post_format');
|
||||
$post_editor = $core->auth->getOption('editor');
|
||||
echo
|
||||
dcCore::app()->callBehavior('adminPostEditor', $editor['xhtml'], 'disclaimer', ['#disclaimer_text'], 'xhtml') .
|
||||
dcPage::jsModuleLoad(basename(__DIR__) . '/js/admin.js');
|
||||
});
|
||||
|
||||
$admin_post_behavior = '';
|
||||
if ($post_editor && !empty($post_editor[$post_format])) {
|
||||
$admin_post_behavior = $core->callBehavior('adminPostEditor', $post_editor[$post_format],
|
||||
'disclaimer_text', array('#disclaimer_text')
|
||||
);
|
||||
}
|
||||
dcCore::app()->addBehavior('adminBlogPreferencesFormV2', function (dcSettings $blog_settings) {
|
||||
$s = $blog_settings->addNamespace(basename(__DIR__));
|
||||
|
||||
return
|
||||
dcPage::jsToolBar().
|
||||
$admin_post_behavior.
|
||||
dcPage::jsConfirmClose('opts-forms').
|
||||
dcPage::jsLoad('index.php?pf=disclaimer/js/config.js');
|
||||
}
|
||||
/**
|
||||
* Form
|
||||
*
|
||||
* @param dcCore $core dcCore instance
|
||||
* @param dcSettings $blog_settings dcSettings instance
|
||||
*/
|
||||
public static function adminBlogPreferencesForm(dcCore $core, dcSettings $blog_settings)
|
||||
{
|
||||
$blog_settings->addNamespace('disclaimer');
|
||||
$s = $blog_settings->disclaimer;
|
||||
$disclaimer_active = (boolean) $s->disclaimer_active;
|
||||
$disclaimer_remember = (boolean) $s->disclaimer_remember;
|
||||
$disclaimer_redir = (string) $s->disclaimer_redir;
|
||||
$disclaimer_title = (string) $s->disclaimer_title;
|
||||
$disclaimer_text = (string) $s->disclaimer_text;
|
||||
$disclaimer_bots_unactive = (boolean) $s->disclaimer_bots_unactive;
|
||||
$disclaimer_bots_agents = $s->disclaimer_bots_agents;
|
||||
if (!$disclaimer_bots_agents) {
|
||||
$disclaimer_bots_agents =
|
||||
'bot;Scooter;Slurp;Voila;WiseNut;Fast;Index;Teoma;'.
|
||||
$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
|
||||
'<div class="fieldset">'.
|
||||
'<h4>'.__('Disclaimer').'</h4>'.
|
||||
'<div class="fieldset">' .
|
||||
'<h4>' . __('Disclaimer') . '</h4>' .
|
||||
'<div class="two-boxes">' .
|
||||
|
||||
'<div class="two-boxes">'.
|
||||
|
||||
'<p><label class="classic" for="disclaimer_active">'.
|
||||
'<p><label class="classic" for="disclaimer_active">' .
|
||||
form::checkbox(
|
||||
'disclaimer_active',
|
||||
'1',
|
||||
$disclaimer_active
|
||||
).
|
||||
__('Enable disclaimer').'</label></p>'.
|
||||
(bool) $s->get('disclaimer_active')
|
||||
) .
|
||||
__('Enable disclaimer') . '</label></p>' .
|
||||
|
||||
'<p><label for="disclaimer_title">'.
|
||||
__('Title:').
|
||||
'</label>'.
|
||||
'<p><label for="disclaimer_title">' . __('Title:') . '</label>' .
|
||||
form::field(
|
||||
'disclaimer_title',
|
||||
30,
|
||||
255,
|
||||
html::escapeHTML($disclaimer_title)
|
||||
).
|
||||
'</p>'.
|
||||
html::escapeHTML((string) $s->get('disclaimer_title'))
|
||||
) .
|
||||
'</p>' .
|
||||
|
||||
'</div><div class="two-boxes">'.
|
||||
'</div><div class="two-boxes">' .
|
||||
|
||||
'<p><label class="classic">'.
|
||||
'<p><label class="classic">' .
|
||||
form::checkbox(
|
||||
'disclaimer_remember',
|
||||
'1',
|
||||
$disclaimer_remember
|
||||
).
|
||||
__('Remember the visitor').'</label></p>'.
|
||||
(bool) $s->get('disclaimer_remember')
|
||||
) .
|
||||
__('Remember the visitor') . '</label></p>' .
|
||||
|
||||
'<p><label for="disclaimer_redir">'.
|
||||
__('Link output:').
|
||||
'</label>'.
|
||||
'<p><label for="disclaimer_redir">' . __('Link output:') . '</label>' .
|
||||
form::field(
|
||||
'disclaimer_redir',
|
||||
30,
|
||||
255,
|
||||
html::escapeHTML($disclaimer_redir)
|
||||
).'</p>'.
|
||||
'<p class="form-note info">'.__('Leave blank to redirect to the site Dotclear').'</p>'.
|
||||
html::escapeHTML((string) $s->get('disclaimer_redir'))
|
||||
) . '</p>' .
|
||||
'<p class="form-note info">' . __('Leave blank to redirect to the site Dotclear') . '</p>' .
|
||||
|
||||
'</div><div class="clear">'.
|
||||
'</div><div class="clear">' .
|
||||
|
||||
'<p class="area"><label for="disclaimer_text">'.
|
||||
__('Disclaimer:').
|
||||
'</label>'.
|
||||
'<p class="area"><label for="disclaimer_text">' . __('Disclaimer:') . '</label>' .
|
||||
form::textarea(
|
||||
'disclaimer_text',
|
||||
60,
|
||||
5,
|
||||
html::escapeHTML($disclaimer_text)
|
||||
).'</p>'.
|
||||
[
|
||||
'default' => html::escapeHTML((string) $s->get('disclaimer_text')),
|
||||
'extra_html' => 'lang="' . dcCore::app()->blog->settings->get('system')->get('lang') . '" spellcheck="true"',
|
||||
]
|
||||
) . '</p>' .
|
||||
|
||||
'<p><label for="disclaimer_bots_agents">'.
|
||||
__('List of robots allowed to index the site pages (separated by semicolons):').
|
||||
'</label>'.
|
||||
'<p><label for="disclaimer_bots_agents">' . __('List of robots allowed to index the site pages (separated by semicolons):') . '</label>' .
|
||||
form::field(
|
||||
'disclaimer_bots_agents',
|
||||
120,
|
||||
255,
|
||||
html::escapeHTML($disclaimer_bots_agents)
|
||||
).'</p>'.
|
||||
) . '</p>' .
|
||||
|
||||
'<p><label for="disclaimer_bots_unactive">'.
|
||||
'<p><label for="disclaimer_bots_unactive">' .
|
||||
form::checkbox(
|
||||
'disclaimer_bots_unactive',
|
||||
'1',
|
||||
$disclaimer_bots_unactive
|
||||
).
|
||||
__('Disable the authorization of indexing by search engines').
|
||||
'</label></p>'.
|
||||
|
||||
'</div>'.
|
||||
(bool) $s->get('disclaimer_bots_unactive')
|
||||
) .
|
||||
__('Disable the authorization of indexing by search engines') .
|
||||
'</label></p>' .
|
||||
|
||||
'</div>' .
|
||||
'</div>';
|
||||
}
|
||||
}
|
||||
});
|
||||
|
50
_define.php
50
_define.php
@ -1,36 +1,32 @@
|
||||
<?php
|
||||
# -- BEGIN LICENSE BLOCK ----------------------------------
|
||||
#
|
||||
# This file is part of disclaimer, a plugin for Dotclear 2.
|
||||
#
|
||||
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors
|
||||
#
|
||||
# Licensed under the GPL version 2.0 license.
|
||||
# A copy of this license is available in LICENSE file or at
|
||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
#
|
||||
# -- END LICENSE BLOCK ------------------------------------
|
||||
|
||||
/**
|
||||
* @brief disclaimer, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis, Pierre Van Glabeke
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->registerModule(
|
||||
/* Name */
|
||||
"disclaimer",
|
||||
/* Description*/
|
||||
"Add a disclaimer to your blog entrance",
|
||||
/* Author */
|
||||
"Jean-Christian Denis, Pierre Van Glabeke",
|
||||
/* Version */
|
||||
'0.9',
|
||||
/* Properties */
|
||||
array(
|
||||
'permissions' => 'admin',
|
||||
'disclaimer',
|
||||
'Add a disclaimer to your blog entrance',
|
||||
'Jean-Christian Denis, Pierre Van Glabeke',
|
||||
'0.10',
|
||||
[
|
||||
'requires' => [['core', '2.24']],
|
||||
'permissions' => dcCore::app()->auth->makePermissions([
|
||||
dcAuth::PERMISSION_ADMIN,
|
||||
]),
|
||||
'type' => 'plugin',
|
||||
'dc_min' => '2.8',
|
||||
'support' => 'http://forum.dotclear.org/viewtopic.php?id=40000',
|
||||
'details' => 'http://plugins.dotaddict.org/dc2/details/disclaimer'
|
||||
)
|
||||
'details' => 'https://github.com/JcDenis/' . basename(__DIR__),
|
||||
'repository' => 'https://raw.githubusercontent.com/JcDenis/' . basename(__DIR__) . '/master/dcstore.xml',
|
||||
]
|
||||
);
|
131
_install.php
131
_install.php
@ -1,67 +1,62 @@
|
||||
<?php
|
||||
# -- BEGIN LICENSE BLOCK ----------------------------------
|
||||
#
|
||||
# This file is part of disclaimer, a plugin for Dotclear 2.
|
||||
#
|
||||
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors
|
||||
#
|
||||
# Licensed under the GPL version 2.0 license.
|
||||
# A copy of this license is available in LICENSE file or at
|
||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
#
|
||||
# -- END LICENSE BLOCK ------------------------------------
|
||||
|
||||
/**
|
||||
* @brief disclaimer, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis, Pierre Van Glabeke
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
# -- Module specs --
|
||||
|
||||
$dc_min = '2.7';
|
||||
$mod_id = 'disclaimer';
|
||||
$mod_conf = array(
|
||||
array(
|
||||
// Module specs
|
||||
$mod_conf = [
|
||||
[
|
||||
'disclaimer_active',
|
||||
'Enable disclaimer plugin',
|
||||
false,
|
||||
'boolean'
|
||||
),
|
||||
array(
|
||||
'boolean',
|
||||
],
|
||||
[
|
||||
'disclaimer_remember',
|
||||
'Remember the visitor who has already accepted the terms',
|
||||
false,
|
||||
'boolean'
|
||||
),
|
||||
array(
|
||||
'boolean',
|
||||
],
|
||||
[
|
||||
'disclaimer_redir',
|
||||
'Redirection if disclaimer is refused',
|
||||
'https://www.google.fr',
|
||||
'string'
|
||||
),
|
||||
array(
|
||||
'string',
|
||||
],
|
||||
[
|
||||
'disclaimer_title',
|
||||
'Title for disclaimer',
|
||||
'Disclaimer',
|
||||
'string'
|
||||
),
|
||||
array(
|
||||
'string',
|
||||
],
|
||||
[
|
||||
'disclaimer_text',
|
||||
'Description for disclaimer',
|
||||
__('<p>You must accept this term before entering</p>'),
|
||||
//'You must accept this term before entering',
|
||||
'string'
|
||||
),
|
||||
array(
|
||||
'string',
|
||||
],
|
||||
[
|
||||
'disclaimer_bots_unactive',
|
||||
'Bypass disclaimer for bots',
|
||||
false,
|
||||
'boolean'
|
||||
),
|
||||
array(
|
||||
'boolean',
|
||||
],
|
||||
[
|
||||
'disclaimer_bots_agents',
|
||||
'List of know bots',
|
||||
implode(';', array(
|
||||
implode(';', [
|
||||
'bot',
|
||||
'Scooter',
|
||||
'Slurp',
|
||||
@ -76,52 +71,38 @@ $mod_conf = array(
|
||||
'loader',
|
||||
'archive',
|
||||
'Spider',
|
||||
'Crawler'
|
||||
)),
|
||||
'string'
|
||||
)
|
||||
);
|
||||
|
||||
# -- Nothing to change below --
|
||||
'Crawler',
|
||||
]),
|
||||
'string',
|
||||
],
|
||||
];
|
||||
|
||||
// Nothing to change below
|
||||
try {
|
||||
|
||||
# Check module version
|
||||
if (version_compare(
|
||||
$core->getVersion($mod_id),
|
||||
$core->plugins->moduleInfo($mod_id, 'version'),
|
||||
'>='
|
||||
// Version
|
||||
if (!dcCore::app()->newVersion(
|
||||
basename(__DIR__),
|
||||
dcCore::app()->plugins->moduleInfo(basename(__DIR__), 'version')
|
||||
)) {
|
||||
|
||||
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
|
||||
// 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
|
||||
);
|
||||
}
|
||||
|
||||
# Set module version
|
||||
$core->setVersion(
|
||||
$mod_id,
|
||||
$core->plugins->moduleInfo($mod_id, 'version')
|
||||
);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
|
206
_public.php
206
_public.php
@ -1,26 +1,23 @@
|
||||
<?php
|
||||
# -- BEGIN LICENSE BLOCK ----------------------------------
|
||||
#
|
||||
# This file is part of disclaimer, a plugin for Dotclear 2.
|
||||
#
|
||||
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors
|
||||
#
|
||||
# Licensed under the GPL version 2.0 license.
|
||||
# A copy of this license is available in LICENSE file or at
|
||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
#
|
||||
# -- END LICENSE BLOCK ------------------------------------
|
||||
|
||||
/**
|
||||
* @brief disclaimer, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis, Pierre Van Glabeke
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$core->blog->settings->addNamespace('disclaimer');
|
||||
dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
||||
|
||||
# Is active
|
||||
if (!$core->blog->settings->disclaimer->disclaimer_active) {
|
||||
|
||||
if (!dcCore::app()->blog->settings->get(basename(__DIR__))->get('disclaimer_active')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -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 '<?php echo ' . sprintf(
|
||||
dcCore::app()->tpl->getFilters($attr),
|
||||
'dcCore::app()->blog->settings->get("disclaimer")->get("disclaimer_title")'
|
||||
) . '; ?>';
|
||||
});
|
||||
|
||||
dcCore::app()->tpl->addValue('DisclaimerText', function ($attr) {
|
||||
return '<?php echo dcCore::app()->blog->settings->get("disclaimer")->get("disclaimer_text"); ?>';
|
||||
});
|
||||
|
||||
dcCore::app()->tpl->addValue('DisclaimerFormURL', function ($attr) {
|
||||
return '<?php dcCore::app()->blog->url; ?>';
|
||||
});
|
||||
|
||||
# Behaviors
|
||||
dcCore::app()->addBehavior('publicHeadContent', function () {
|
||||
echo dcUtils::cssModuleLoad(basename(__DIR__) . '/css/disclaimer.css');
|
||||
});
|
||||
|
||||
dcCore::app()->addBehavior(
|
||||
'publicBeforeDocumentV2',
|
||||
['urlDisclaimer', 'publicBeforeDocumentV2']
|
||||
);
|
||||
|
||||
/**
|
||||
@ -61,10 +60,12 @@ $core->tpl->addValue(
|
||||
*/
|
||||
class urlDisclaimer extends dcUrlHandlers
|
||||
{
|
||||
public static $default_bots_agents = array(
|
||||
private const COOKIE_PREFIX = 'dc_disclaimer_cookie_';
|
||||
|
||||
public static $default_bots_agents = [
|
||||
'bot','Scooter','Slurp','Voila','WiseNut','Fast','Index','Teoma',
|
||||
'Mirago','search','find','loader','archive','Spider','Crawler'
|
||||
);
|
||||
'Mirago','search','find','loader','archive','Spider','Crawler',
|
||||
];
|
||||
|
||||
/**
|
||||
* Remove public callbacks (and serve disclaimer css)
|
||||
@ -81,82 +82,62 @@ class urlDisclaimer extends dcUrlHandlers
|
||||
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
|
||||
'<link rel="stylesheet" type="text/css" media="screen" href="'.$url."/css/disclaimer.css\" />\n";
|
||||
}
|
||||
|
||||
/**
|
||||
* Check disclaimer
|
||||
*
|
||||
* @param array $args Arguments
|
||||
*/
|
||||
public static function publicBeforeDocument($args)
|
||||
public static function publicBeforeDocumentV2()
|
||||
{
|
||||
global $core, $_ctx;
|
||||
$s = dcCore::app()->blog->settings->addNamespace(basename(__DIR__));
|
||||
|
||||
# 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);
|
||||
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)) {
|
||||
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);
|
||||
$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 {
|
||||
$core->tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates/'.DC_DEFAULT_TPLSET);
|
||||
dcCore::app()->tpl->setPath(dcCore::app()->tpl->getPath(), __DIR__ . '/default-templates/' . DC_DEFAULT_TPLSET);
|
||||
}
|
||||
|
||||
# New URL handler
|
||||
$urlHandler = new urlHandler();
|
||||
$urlHandler->mode = $core->url->mode;
|
||||
$urlHandler->registerDefault(array(
|
||||
$urlHandler->mode = dcCore::app()->url->mode;
|
||||
$urlHandler->registerDefault([
|
||||
'urlDisclaimer',
|
||||
'overwriteCallbacks'
|
||||
));
|
||||
'overwriteCallbacks',
|
||||
]);
|
||||
|
||||
# Create session if not exists
|
||||
if (!isset($session)) {
|
||||
# Create session
|
||||
$session = new sessionDB(
|
||||
$core->con,
|
||||
$core->prefix.'session',
|
||||
'dc_disclaimer_sess_'.$core->blog->id,
|
||||
dcCore::app()->con,
|
||||
dcCore::app()->prefix . 'session',
|
||||
'dc_disclaimer_sess_' . dcCore::app()->blog->id,
|
||||
'/'
|
||||
);
|
||||
$session->start();
|
||||
}
|
||||
|
||||
# Remove all URLs representations
|
||||
foreach ($core->url->getTypes() as $k => $v) {
|
||||
foreach (dcCore::app()->url->getTypes() as $k => $v) {
|
||||
$urlHandler->register(
|
||||
$k,
|
||||
$v['url'],
|
||||
$v['representation'],
|
||||
array('urlDisclaimer', 'overwriteCallbacks')
|
||||
['urlDisclaimer', 'overwriteCallbacks']
|
||||
);
|
||||
}
|
||||
|
||||
@ -166,19 +147,17 @@ class urlDisclaimer extends dcUrlHandlers
|
||||
unset($urlHandler);
|
||||
|
||||
# Test cookie
|
||||
$cookie_name="dc_disclaimer_cookie_".$core->blog->id;
|
||||
$cookie_value =
|
||||
empty($_COOKIE[$cookie_name])
|
||||
|| !$core->blog->settings->disclaimer->disclaimer_remember ?
|
||||
$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 ($core->blog->settings->disclaimer->disclaimer_remember) {
|
||||
setcookie($cookie_name, 0, time()-86400, '/');
|
||||
if ($s->get('disclaimer_remember')) {
|
||||
setcookie($cookie_name, '0', time() - 86400, '/');
|
||||
}
|
||||
$redir = $core->blog->settings->disclaimer->disclaimer_redir;
|
||||
$redir = $s->get('disclaimer_redir');
|
||||
if (!$redir) {
|
||||
$redir = 'http://www.dotclear.org';
|
||||
}
|
||||
@ -190,7 +169,7 @@ class urlDisclaimer extends dcUrlHandlers
|
||||
elseif (!isset($_SESSION['sess_blog_disclaimer'])
|
||||
|| $_SESSION['sess_blog_disclaimer'] != 1
|
||||
) {
|
||||
if ($core->blog->settings->disclaimer->disclaimer_remember
|
||||
if ($s->get('disclaimer_remember')
|
||||
&& $cookie_value != false
|
||||
) {
|
||||
$_SESSION['sess_blog_disclaimer'] = 1;
|
||||
@ -200,8 +179,8 @@ class urlDisclaimer extends dcUrlHandlers
|
||||
if (!empty($_POST['disclaimeragree'])) {
|
||||
$_SESSION['sess_blog_disclaimer'] = 1;
|
||||
|
||||
if ($core->blog->settings->disclaimer->disclaimer_remember) {
|
||||
setcookie($cookie_name, 1, time() + 31536000, '/');
|
||||
if ($s->get('disclaimer_remember')) {
|
||||
setcookie($cookie_name, '1', time() + 31536000, '/');
|
||||
}
|
||||
|
||||
return null;
|
||||
@ -215,48 +194,3 @@ class urlDisclaimer extends dcUrlHandlers
|
||||
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
|
||||
'<?php echo '.sprintf(
|
||||
$f,
|
||||
'$core->blog->settings->disclaimer->disclaimer_title'
|
||||
).'; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Public disclaimer text
|
||||
*
|
||||
* @param array $attr Template value attribute
|
||||
*/
|
||||
public static function DisclaimerText($attr)
|
||||
{
|
||||
return
|
||||
'<?php echo $core->blog->settings->disclaimer->disclaimer_text; ?>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Public URL of disclaimer form action
|
||||
*
|
||||
* @param array $attr Template value attribute
|
||||
*/
|
||||
public static function DisclaimerFormURL($attr)
|
||||
{
|
||||
return '<?php $core->blog->url; ?>';
|
||||
}
|
||||
}
|
105
_uninstall.php
105
_uninstall.php
@ -1,62 +1,81 @@
|
||||
<?php
|
||||
# -- BEGIN LICENSE BLOCK ----------------------------------
|
||||
#
|
||||
# This file is part of disclaimer, a plugin for Dotclear 2.
|
||||
#
|
||||
# Copyright (c) 2009-2015 Jean-Christian Denis and contributors
|
||||
#
|
||||
# Licensed under the GPL version 2.0 license.
|
||||
# A copy of this license is available in LICENSE file or at
|
||||
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
||||
#
|
||||
# -- END LICENSE BLOCK ------------------------------------
|
||||
|
||||
/**
|
||||
* @brief disclaimer, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis, Pierre Van Glabeke
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$mod_id = 'disclaimer';
|
||||
|
||||
$this->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)
|
||||
/* 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__))
|
||||
);
|
13
dcstore.xml
Normal file
13
dcstore.xml
Normal file
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0"?>
|
||||
<modules xmlns:da="http://dotaddict.org/da/">
|
||||
<module id="disclaimer">
|
||||
<name>disclaimer</name>
|
||||
<version>0.10</version>
|
||||
<author>Jean-Christian Denis, Pierre Van Glabeke</author>
|
||||
<desc>Add a disclaimer to your blog entrance</desc>
|
||||
<file>https://github.com/JcDenis/disclaimer/releases/download/v0.10/plugin-disclaimer.zip</file>
|
||||
<da:dcmin>2.24</da:dcmin>
|
||||
<da:details>https://github.com/JcDenis/disclaimer</da:details>
|
||||
<da:support>http://forum.dotclear.org/viewtopic.php?id=40000</da:support>
|
||||
</module>
|
||||
</modules>
|
14
js/admin.js
14
js/admin.js
@ -1,6 +1,12 @@
|
||||
$(function() {
|
||||
if ($.isFunction(jsToolBar)) {
|
||||
var tbUser = new jsToolBar(document.getElementById('disclaimer_text'));
|
||||
tbUser.draw('xhtml');
|
||||
/*global $, dotclear, jsToolBar */
|
||||
'use strict';
|
||||
|
||||
$(() => {
|
||||
if (typeof jsToolBar === 'function') {
|
||||
$('#disclaimer_text').each(function () {
|
||||
const tbWidgetTextDisclaimer = new jsToolBar(this);
|
||||
tbWidgetTextDisclaimer.context = 'disclaimer_text';
|
||||
tbWidgetTextDisclaimer.draw('xhtml');
|
||||
});
|
||||
}
|
||||
});
|
Loading…
Reference in New Issue
Block a user