Skip to content

Commit

Permalink
Add activation flag, should fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
franck-paul committed Jun 6, 2020
1 parent 58a9396 commit 2c47849
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 64 deletions.
2 changes: 1 addition & 1 deletion _define.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"ContactMe", // Name
"Add a simple contact form on your blog", // Description
"Olivier Meunier and contributors", // Author
'1.9.1', // Version
'1.10', // Version
[
'requires' => [['core', '2.16']], // Dependencies
'permissions' => 'admin', // Permissions
Expand Down
37 changes: 37 additions & 0 deletions _install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* @brief contactMe, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugins
*
* @author Olivier Meunier and contributors
*
* @copyright Olivier Meunier
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/

if (!defined('DC_CONTEXT_ADMIN')) {return;}

$new_version = $core->plugins->moduleInfo('contactMe', 'version');
$old_version = $core->getVersion('contactMe');

if (version_compare($old_version, $new_version, '>=')) {
return;
}

try
{
if (version_compare($old_version, '1.10', '<')) {
// Default activation = true
$core->blog->settings->addNamespace('contactme');
$core->blog->settings->contactme->put('active', true, 'boolean', 'Active', false, true);
}

$core->setVersion('contactme', $new_version);

return true;
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
return false;
7 changes: 7 additions & 0 deletions _prepend.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@

$core->url->register('contactme', 'contact', '^contact(?:/(.+))?$', ['urlContactMe', 'contact']);

// Cope with new activation (since 1.10)
$core->blog->settings->addNamespace('contactme');
if (!$core->blog->settings->contactme->settingExists('active')) {
// Set active flag to true only if recipient(s) is/are set
$core->blog->settings->contactme->put('active', (boolean) $core->blog->settings->contactme->cm_recipients, 'boolean');
}

require dirname(__FILE__) . '/_widgets.php';
4 changes: 2 additions & 2 deletions _public.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static function contact($args)
{
global $core, $_ctx;

if (!$core->blog->settings->contactme->cm_recipients) {
if (!$core->blog->settings->contactme->cm_recipients || !$core->blog->settings->contactme->active) {
self::p404();
exit;
}
Expand Down Expand Up @@ -287,7 +287,7 @@ public static function contactMeWidget($w)
return;
}

if (!$core->blog->settings->contactme->cm_recipients) {
if (!$core->blog->settings->contactme->cm_recipients || !$core->blog->settings->contactme->active) {
return;
}

Expand Down
6 changes: 5 additions & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

if (!defined('DC_CONTEXT_ADMIN')) {return;}

$cm_active = $core->blog->settings->contactme->active;
$cm_recipients = $core->blog->settings->contactme->cm_recipients;
$cm_subject_prefix = $core->blog->settings->contactme->cm_subject_prefix;
$cm_page_title = $core->blog->settings->contactme->cm_page_title;
Expand Down Expand Up @@ -42,6 +43,7 @@
if (isset($_POST['cm_recipients'])) {
try
{
$cm_active = !empty($_POST['cm_active']);
$cm_recipients = $_POST['cm_recipients'];
$cm_subject_prefix = $_POST['cm_subject_prefix'];
$cm_page_title = $_POST['cm_page_title'];
Expand Down Expand Up @@ -82,6 +84,7 @@

# Everything's fine, save options
$core->blog->settings->addNamespace('contactme');
$core->blog->settings->contactme->put('active', $cm_active, 'boolean');
$core->blog->settings->contactme->put('cm_recipients', $cm_recipients, 'string', 'ContactMe recipients');
$core->blog->settings->contactme->put('cm_subject_prefix', $cm_subject_prefix, 'string', 'ContactMe subject prefix');
$core->blog->settings->contactme->put('cm_page_title', $cm_page_title, 'string', 'ContactMe page title');
Expand Down Expand Up @@ -132,10 +135,11 @@

echo
'<form action="' . $p_url . '" method="post">' .
'<p>' . form::checkbox('cm_active', 1, $cm_active) . ' ' .
'<label for="cm_active" class="classic">' . __('Activate contactMe on blog') . '</label></p>' .
'<h3>' . __('E-Mail settings') . '</h3>' .
'<p><label for="cm_recipients" class="required" title="' . __('Required field') . '">' . __('Comma separated recipients list:') . '</label> ' .
form::field('cm_recipients', 30, 512, html::escapeHTML($cm_recipients), 'maximal', '', false, 'required placeholder="' . __('Email') . '"') . '</p>' .
'<p class="form-note">' . __('Empty recipients list to disable contact page.') . '</p>' .
'<p><label for="cm_subject_prefix">' . __('E-Mail subject prefix:') . '</label> ' .
form::field('cm_subject_prefix', 30, 128, html::escapeHTML($cm_subject_prefix)) . '</p>' .
'<p class="form-note">' . __('This will be prepend to e-mail subject') . '</p>';
Expand Down
129 changes: 76 additions & 53 deletions locales/_pot/main.pot
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ msgid ""
msgstr ""
"Project-Id-Version: Dotclear 2 contactMe module\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-06-02 10:08+0200\n"
"POT-Creation-Date: 2020-06-06 13:25+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -16,183 +16,206 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

#: ../hg-plugins/contactMe//__html_tpl_dummy.php:5
#: ../hg-plugins/contactMe//_public.php:16
#: ../git-plugins/contactMe/__html_tpl_dummy.php:4
#: ../git-plugins/contactMe/_public.php:18
#: ../git-plugins/contactMe/index.php:165
#: ../git-plugins/contactMe/index.php:169
msgid "Message"
msgstr ""

#: ../hg-plugins/contactMe//__html_tpl_dummy.php:7
#: ../hg-plugins/contactMe//_public.php:15
#: ../git-plugins/contactMe/__html_tpl_dummy.php:6
#: ../git-plugins/contactMe/_public.php:17
msgid "Subject"
msgstr ""

#: ../hg-plugins/contactMe//_admin.php:15
#: ../git-plugins/contactMe/_admin.php:17
msgid "Add a simple contact form on your blog"
msgstr ""

#: ../hg-plugins/contactMe//_admin.php:15
#: ../git-plugins/contactMe/_admin.php:17
msgid "ContactMe"
msgstr ""

#: ../hg-plugins/contactMe//_admin.php:17
#: ../hg-plugins/contactMe//_admin.php:31
#: ../hg-plugins/contactMe//_admin.php:46
#: ../hg-plugins/contactMe//_admin.php:54
#: ../hg-plugins/contactMe//_public.php:37
#: ../hg-plugins/contactMe//_public.php:300
#: ../hg-plugins/contactMe//_widgets.php:20
#: ../hg-plugins/contactMe//_widgets.php:22
#: ../hg-plugins/contactMe//index.php:25 ../hg-plugins/contactMe//index.php:109
#: ../hg-plugins/contactMe//index.php:122
#: ../git-plugins/contactMe/_admin.php:19
#: ../git-plugins/contactMe/_admin.php:34
#: ../git-plugins/contactMe/_admin.php:56
#: ../git-plugins/contactMe/_admin.php:65
#: ../git-plugins/contactMe/_public.php:39
#: ../git-plugins/contactMe/_public.php:297
#: ../git-plugins/contactMe/_widgets.php:23
#: ../git-plugins/contactMe/_widgets.php:25
#: ../git-plugins/contactMe/index.php:28
#: ../git-plugins/contactMe/index.php:110
#: ../git-plugins/contactMe/index.php:132
msgid "Contact me"
msgstr ""

#: ../hg-plugins/contactMe//_admin.php:55
#: ../git-plugins/contactMe/_admin.php:44
msgid "Contact me form caption and messages"
msgstr ""

#: ../git-plugins/contactMe/_admin.php:66
msgid "Mail contact form"
msgstr ""

#: ../hg-plugins/contactMe//_public.php:93
#: ../git-plugins/contactMe/_public.php:92
msgid "You must provide a name."
msgstr ""

#: ../hg-plugins/contactMe//_public.php:101
#: ../git-plugins/contactMe/_public.php:100
msgid "You must provide a subject."
msgstr ""

#: ../hg-plugins/contactMe//_public.php:105
#: ../git-plugins/contactMe/_public.php:104
msgid "You must write a message."
msgstr ""

#: ../hg-plugins/contactMe//_public.php:121
#: ../git-plugins/contactMe/_public.php:120
msgid "No valid contact recipient was found."
msgstr ""

#: ../hg-plugins/contactMe//_public.php:142
#: ../git-plugins/contactMe/_public.php:140
msgid "Message seems to be a spam."
msgstr ""

#: ../hg-plugins/contactMe//_public.php:165
#: ../git-plugins/contactMe/_public.php:163
msgid ""
"Hi there!\n"
"\n"
"You received a message from your blog's contact page."
msgstr ""

#: ../hg-plugins/contactMe//_public.php:167
#: ../git-plugins/contactMe/_public.php:165
#, php-format
msgid "Blog: %s"
msgstr ""

#: ../hg-plugins/contactMe//_public.php:168
#: ../git-plugins/contactMe/_public.php:166
#, php-format
msgid "Message from: %s <%s>"
msgstr ""

#: ../hg-plugins/contactMe//_public.php:169
#: ../git-plugins/contactMe/_public.php:167
#, php-format
msgid "Website: %s"
msgstr ""

#: ../hg-plugins/contactMe//_public.php:170
#: ../git-plugins/contactMe/_public.php:168
msgid "Message:"
msgstr ""

#: ../hg-plugins/contactMe//_widgets.php:20
#: ../git-plugins/contactMe/_widgets.php:23
msgid "Link to the contact form"
msgstr ""

#: ../hg-plugins/contactMe//_widgets.php:21
#: ../git-plugins/contactMe/_widgets.php:24
msgid "Contact"
msgstr ""

#: ../hg-plugins/contactMe//index.php:29
#: ../git-plugins/contactMe/_widgets.php:25
msgid "Link title:"
msgstr ""

#: ../git-plugins/contactMe/index.php:32
msgid "<p>You can use the following form to send me an e-mail.</p>"
msgstr ""

#: ../hg-plugins/contactMe//index.php:33
#: ../git-plugins/contactMe/index.php:36
msgid "<p style=\"color:green\"><strong>Thank you for your message.</strong></p>"
msgstr ""

#: ../hg-plugins/contactMe//index.php:37
#: ../git-plugins/contactMe/index.php:40
#, php-format
msgid "<p style=\"color:red\"><strong>An error occured:</strong> %s</p>"
msgstr ""

#: ../hg-plugins/contactMe//index.php:52
#: ../git-plugins/contactMe/index.php:55
msgid "No recipients."
msgstr ""

#: ../hg-plugins/contactMe//index.php:56
#: ../git-plugins/contactMe/index.php:59
msgid "No page title."
msgstr ""

#: ../hg-plugins/contactMe//index.php:60
#: ../git-plugins/contactMe/index.php:63
msgid "No success message."
msgstr ""

#: ../hg-plugins/contactMe//index.php:64
#: ../git-plugins/contactMe/index.php:67
msgid "No error message."
msgstr ""

#: ../hg-plugins/contactMe//index.php:77
#: ../git-plugins/contactMe/index.php:79
#, php-format
msgid "%s is not a valid e-mail address."
msgstr ""

#: ../hg-plugins/contactMe//index.php:97
#: ../git-plugins/contactMe/index.php:100
msgid "Setting have been successfully updated."
msgstr ""

#: ../hg-plugins/contactMe//index.php:128
#: ../git-plugins/contactMe/index.php:139
msgid "Activate contactMe on blog"
msgstr ""

#: ../git-plugins/contactMe/index.php:140
msgid "E-Mail settings"
msgstr ""

#: ../hg-plugins/contactMe//index.php:129
#: ../git-plugins/contactMe/index.php:141
msgid "Comma separated recipients list:"
msgstr ""

#: ../hg-plugins/contactMe//index.php:131
msgid "Empty recipients list to disable contact page."
#: ../git-plugins/contactMe/index.php:142
msgid "Email"
msgstr ""

#: ../hg-plugins/contactMe//index.php:132
#: ../git-plugins/contactMe/index.php:143
msgid "E-Mail subject prefix:"
msgstr ""

#: ../hg-plugins/contactMe//index.php:134
#: ../git-plugins/contactMe/index.php:145
msgid "This will be prepend to e-mail subject"
msgstr ""

#: ../hg-plugins/contactMe//index.php:141
#: ../git-plugins/contactMe/index.php:151
msgid "Use comments spam filter"
msgstr ""

#: ../hg-plugins/contactMe//index.php:145
#: ../git-plugins/contactMe/index.php:155
msgid "Presentation options"
msgstr ""

#: ../hg-plugins/contactMe//index.php:147
#: ../git-plugins/contactMe/index.php:157
msgid "Page title:"
msgstr ""

#: ../hg-plugins/contactMe//index.php:150
#: ../git-plugins/contactMe/index.php:158
msgid "Title"
msgstr ""

#: ../git-plugins/contactMe/index.php:160
msgid "Form caption:"
msgstr ""

#: ../hg-plugins/contactMe//index.php:154
#: ../git-plugins/contactMe/index.php:164
msgid "Confirmation message:"
msgstr ""

#: ../hg-plugins/contactMe//index.php:158
#: ../git-plugins/contactMe/index.php:168
msgid "Error message:"
msgstr ""

#: ../hg-plugins/contactMe//index.php:161
#: ../git-plugins/contactMe/index.php:171
#, php-format
msgid "\"%s\" is the error message."
msgstr ""

#: ../hg-plugins/contactMe//index.php:166
#: ../git-plugins/contactMe/index.php:173
msgid "Save"
msgstr ""

#: ../git-plugins/contactMe/index.php:176
#, php-format
msgid "Don't forget to add a <a href=\"%s\">“Contact Me” widget</a> linking to your contact page."
msgstr ""
Loading

0 comments on commit 2c47849

Please sign in to comment.