Merge remote-tracking branch 'upstream/release/0.9' into release/0.9
This commit is contained in:
commit
4ced550942
@ -21,7 +21,6 @@ use Framadate\Services\InputService;
|
|||||||
use Framadate\Services\LogService;
|
use Framadate\Services\LogService;
|
||||||
use Framadate\Services\PurgeService;
|
use Framadate\Services\PurgeService;
|
||||||
use Framadate\Services\SecurityService;
|
use Framadate\Services\SecurityService;
|
||||||
use Framadate\Utils;
|
|
||||||
|
|
||||||
include_once __DIR__ . '/../app/inc/init.php';
|
include_once __DIR__ . '/../app/inc/init.php';
|
||||||
include_once __DIR__ . '/../bandeaux.php';
|
include_once __DIR__ . '/../bandeaux.php';
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
namespace Framadate;
|
namespace Framadate;
|
||||||
|
|
||||||
use Framadate\Editable;
|
|
||||||
|
|
||||||
class Form
|
class Form
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -5,7 +5,14 @@ class MailService {
|
|||||||
|
|
||||||
private $smtp_allowed;
|
private $smtp_allowed;
|
||||||
|
|
||||||
|
const DELAY_BEFORE_RESEND = 300;
|
||||||
|
|
||||||
|
const MAILSERVICE_KEY = 'mailservice';
|
||||||
|
|
||||||
|
private $logService;
|
||||||
|
|
||||||
function __construct($smtp_allowed) {
|
function __construct($smtp_allowed) {
|
||||||
|
$this->logService = new LogService();
|
||||||
$this->smtp_allowed = $smtp_allowed;
|
$this->smtp_allowed = $smtp_allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -13,10 +20,12 @@ class MailService {
|
|||||||
return filter_var($email, FILTER_VALIDATE_EMAIL);
|
return filter_var($email, FILTER_VALIDATE_EMAIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
function send($to, $subject, $body, $param = '') {
|
function send($to, $subject, $body, $msgKey = null) {
|
||||||
if ($this->smtp_allowed == true) {
|
if ($this->smtp_allowed == true && $this->canSendMsg($msgKey)) {
|
||||||
mb_internal_encoding('UTF-8');
|
mb_internal_encoding('UTF-8');
|
||||||
|
|
||||||
|
// Build headers
|
||||||
|
|
||||||
$subject = mb_encode_mimeheader(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'), 'UTF-8', 'B', "\n", 9);
|
$subject = mb_encode_mimeheader(html_entity_decode($subject, ENT_QUOTES, 'UTF-8'), 'UTF-8', 'B', "\n", 9);
|
||||||
|
|
||||||
$encoded_app = mb_encode_mimeheader(NOMAPPLICATION, 'UTF-8', 'B', "\n", 6);
|
$encoded_app = mb_encode_mimeheader(NOMAPPLICATION, 'UTF-8', 'B', "\n", 6);
|
||||||
@ -39,11 +48,38 @@ class MailService {
|
|||||||
$headers .= "Auto-Submitted:auto-generated\n";
|
$headers .= "Auto-Submitted:auto-generated\n";
|
||||||
$headers .= 'Return-Path: <>';
|
$headers .= 'Return-Path: <>';
|
||||||
|
|
||||||
|
// Build body
|
||||||
|
|
||||||
$body = $body . '<br/><br/>' . __('Mail', 'Thanks for your trust.') . '<br/>' . NOMAPPLICATION . '<hr/>' . __('Mail', 'FOOTER');
|
$body = $body . '<br/><br/>' . __('Mail', 'Thanks for your trust.') . '<br/>' . NOMAPPLICATION . '<hr/>' . __('Mail', 'FOOTER');
|
||||||
|
|
||||||
mail($to, $subject, $body, $headers, $param);
|
// Send mail
|
||||||
|
|
||||||
|
$this->sendMail($to, $subject, $body, $msgKey, $headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function canSendMsg($msgKey) {
|
||||||
|
if ($msgKey == null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($_SESSION[self::MAILSERVICE_KEY])) {
|
||||||
|
$_SESSION[self::MAILSERVICE_KEY] = [];
|
||||||
|
}
|
||||||
|
return !isset($_SESSION[self::MAILSERVICE_KEY][$msgKey]) || time() - $_SESSION[self::MAILSERVICE_KEY][$msgKey] > self::DELAY_BEFORE_RESEND;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function sendMail($to, $subject, $body, $msgKey, $headers) {
|
||||||
|
mail($to, $subject, $body, $headers, '');
|
||||||
|
|
||||||
|
// Log
|
||||||
|
|
||||||
|
$this->logService->log('MAIL', 'Mail sent to: ' . $to . ', key: ' . $msgKey);
|
||||||
|
|
||||||
|
// Store the mail sending date
|
||||||
|
|
||||||
|
$_SESSION[self::MAILSERVICE_KEY][$msgKey] = time();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -28,7 +28,7 @@ if (isset($_POST['lang']) && is_string($_POST['lang']) && in_array($_POST['lang'
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* <html lang="$locale"> */
|
/* <html lang="$locale"> */
|
||||||
$i18n->get('Something, just to load the dictionary');
|
$i18n->get('', 'Something, just to load the dictionary');
|
||||||
$locale = $i18n->getLoadedLang();
|
$locale = $i18n->getLoadedLang();
|
||||||
|
|
||||||
/* Date Format */
|
/* Date Format */
|
||||||
|
23
app/tests/Framadate/FramaTestCase.php
Normal file
23
app/tests/Framadate/FramaTestCase.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
namespace Framadate;
|
||||||
|
|
||||||
|
abstract class FramaTestCase extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
protected function getTestResourcePath($resourcepath) {
|
||||||
|
return __DIR__ . '/../resources/'.$resourcepath;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function readTestResource($resourcepath) {
|
||||||
|
return file_get_contents($this->getTestResourcePath($resourcepath));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function invoke(&$object, $methodName) {
|
||||||
|
$reflectionClass = new \ReflectionClass($object);
|
||||||
|
$reflectionMethod = $reflectionClass->getMethod($methodName);
|
||||||
|
$reflectionMethod->setAccessible(true);
|
||||||
|
|
||||||
|
$params = array_slice(func_get_args(), 2); // get all the parameters after $methodName
|
||||||
|
return $reflectionMethod->invokeArgs($object, $params);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
39
app/tests/Framadate/Services/MailServiceUnitTest.php
Normal file
39
app/tests/Framadate/Services/MailServiceUnitTest.php
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
<?php
|
||||||
|
namespace Framadate\Services;
|
||||||
|
|
||||||
|
use Framadate\FramaTestCase;
|
||||||
|
|
||||||
|
class MailServiceUnitTest extends FramaTestCase {
|
||||||
|
const MSG_KEY = '666';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
function should_send_a_2nd_mail_after_a_good_interval() {
|
||||||
|
// Given
|
||||||
|
$mailService = new MailService(true);
|
||||||
|
$_SESSION[MailService::MAILSERVICE_KEY] = [self::MSG_KEY => time() - 1000];
|
||||||
|
|
||||||
|
// When
|
||||||
|
$canSendMsg = $mailService->canSendMsg(self::MSG_KEY);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
$this->assertEquals(true, $canSendMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @test
|
||||||
|
*/
|
||||||
|
function should_not_send_2_mails_in_a_short_interval() {
|
||||||
|
// Given
|
||||||
|
$mailService = new MailService(true);
|
||||||
|
$_SESSION[MailService::MAILSERVICE_KEY] = [self::MSG_KEY => time()];
|
||||||
|
|
||||||
|
// When
|
||||||
|
$canSendMsg = $mailService->canSendMsg(self::MSG_KEY);
|
||||||
|
|
||||||
|
// Then
|
||||||
|
$this->assertEquals(false, $canSendMsg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
3
app/tests/bootstrap.php
Normal file
3
app/tests/bootstrap.php
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
$loader = require __DIR__ . '/../../vendor/autoload.php';
|
||||||
|
$loader->addPsr4('Framadate\\', __DIR__.'/Framadate');
|
@ -14,6 +14,10 @@
|
|||||||
"o80/i18n": "dev-develop"
|
"o80/i18n": "dev-develop"
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^4.5"
|
||||||
|
},
|
||||||
|
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"Framadate\\": "app/classes/Framadate/"
|
"Framadate\\": "app/classes/Framadate/"
|
||||||
|
972
composer.lock
generated
972
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@ -41,13 +41,13 @@ if (file_exists('bandeaux_local.php')) {
|
|||||||
// Step 1/4 : error if $_SESSION from info_sondage are not valid
|
// Step 1/4 : error if $_SESSION from info_sondage are not valid
|
||||||
if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (($config['use_smtp']) ? empty($_SESSION['form']->admin_mail) : false)) {
|
if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (($config['use_smtp']) ? empty($_SESSION['form']->admin_mail) : false)) {
|
||||||
|
|
||||||
Utils::print_header(__("Error!"));
|
Utils::print_header(__('Error', 'Error!'));
|
||||||
bandeau_titre(__("Error!"));
|
bandeau_titre(__('Error', 'Error!'));
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
<div class="alert alert-danger">
|
<div class="alert alert-danger">
|
||||||
<h3>' . __('You haven\'t filled the first section of the poll creation.') . ' !</h3>
|
<h3>' . __('Error', 'You haven\'t filled the first section of the poll creation.') . ' !</h3>
|
||||||
<p>' . __('Back to the homepage of') . ' <a href="' . Utils::get_server_name() . '"> ' . NOMAPPLICATION . '</a></p>
|
<p>' . __('Generic', 'Back to the homepage of') . ' <a href="' . Utils::get_server_name() . '"> ' . NOMAPPLICATION . '</a></p>
|
||||||
</div>' . "\n";
|
</div>' . "\n";
|
||||||
|
|
||||||
bandeau_pied();
|
bandeau_pied();
|
||||||
@ -149,7 +149,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
|
|||||||
|
|
||||||
// Summary
|
// Summary
|
||||||
$summary = '<ol>';
|
$summary = '<ol>';
|
||||||
foreach ($_SESSION['form']->getChoices() as $choice) {
|
foreach ($_SESSION['form']->getChoices() as $i=>$choice) {
|
||||||
|
|
||||||
preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/', $choice->getName(), $md_a_img); // Markdown [![alt](src)](href)
|
preg_match_all('/\[!\[(.*?)\]\((.*?)\)\]\((.*?)\)/', $choice->getName(), $md_a_img); // Markdown [![alt](src)](href)
|
||||||
preg_match_all('/!\[(.*?)\]\((.*?)\)/', $choice->getName(), $md_img); // Markdown ![alt](src)
|
preg_match_all('/!\[(.*?)\]\((.*?)\)/', $choice->getName(), $md_img); // Markdown ![alt](src)
|
||||||
@ -198,7 +198,7 @@ if (empty($_SESSION['form']->title) || empty($_SESSION['form']->admin_name) || (
|
|||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="input-group date">
|
<div class="input-group date">
|
||||||
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
|
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
|
||||||
<input type="text" class="form-control" id="enddate" data-date-format="' . __('Date', 'dd/mm/yyyy') . '" aria-describedby="dateformat" name="enddate" value="' . $end_date_str . '" size="10" maxlength="10" placeholder="' . __("dd/mm/yyyy") . '" />
|
<input type="text" class="form-control" id="enddate" data-date-format="' . __('Date', 'dd/mm/yyyy') . '" aria-describedby="dateformat" name="enddate" value="' . $end_date_str . '" size="10" maxlength="10" placeholder="' . __('Date', 'dd/mm/yyyy') . '" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span id="dateformat" class="sr-only">' . __('Date', 'dd/mm/yyyy') . '</span>
|
<span id="dateformat" class="sr-only">' . __('Date', 'dd/mm/yyyy') . '</span>
|
||||||
|
@ -194,7 +194,7 @@ if (!isset($_SESSION['form']->title) || !isset($_SESSION['form']->admin_name) ||
|
|||||||
<div class="col-sm-6">
|
<div class="col-sm-6">
|
||||||
<div class="input-group date">
|
<div class="input-group date">
|
||||||
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
|
<span class="input-group-addon"><i class="glyphicon glyphicon-calendar text-info"></i></span>
|
||||||
<input type="text" class="form-control" id="enddate" data-date-format="'. __('Date', 'dd/mm/yyyy') .'" aria-describedby="dateformat" name="enddate" value="'.$end_date_str.'" size="10" maxlength="10" placeholder="'. __('dd/mm/yyyy') .'" />
|
<input type="text" class="form-control" id="enddate" data-date-format="'. __('Date', 'dd/mm/yyyy') .'" aria-describedby="dateformat" name="enddate" value="'.$end_date_str.'" size="10" maxlength="10" placeholder="'. __('Date', 'dd/mm/yyyy') .'" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<span id="dateformat" class="sr-only">('. __('Date', 'dd/mm/yyyy') .')</span>
|
<span id="dateformat" class="sr-only">('. __('Date', 'dd/mm/yyyy') .')</span>
|
||||||
|
@ -18,9 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
use Framadate\Services\LogService;
|
use Framadate\Services\LogService;
|
||||||
use Framadate\Services\PollService;
|
use Framadate\Services\PollService;
|
||||||
use Framadate\Services\InputService;
|
|
||||||
use Framadate\Services\MailService;
|
|
||||||
use Framadate\Message;
|
|
||||||
use Framadate\Utils;
|
use Framadate\Utils;
|
||||||
|
|
||||||
include_once __DIR__ . '/app/inc/init.php';
|
include_once __DIR__ . '/app/inc/init.php';
|
||||||
|
@ -43,7 +43,7 @@ if (!empty($_POST['mail'])) {
|
|||||||
$smarty->assign('polls', $polls);
|
$smarty->assign('polls', $polls);
|
||||||
$body = $smarty->fetch('mail/find_polls.tpl');
|
$body = $smarty->fetch('mail/find_polls.tpl');
|
||||||
|
|
||||||
$mailService->send($mail, __('Homepage', 'Where are my polls'), $body);
|
$mailService->send($mail, __('Homepage', 'Where are my polls'), $body, 'SEND_POLLS');
|
||||||
$message = new Message('success', __('FindPolls', 'Polls sent'));
|
$message = new Message('success', __('FindPolls', 'Polls sent'));
|
||||||
} else {
|
} else {
|
||||||
$message = new Message('warning', __('Error', 'No polls found'));
|
$message = new Message('warning', __('Error', 'No polls found'));
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 9.5 KiB |
@ -17,9 +17,7 @@
|
|||||||
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
* Auteurs de Framadate/OpenSondage : Framasoft (https://github.com/framasoft)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use Framadate\Services\LogService;
|
|
||||||
use Framadate\Services\PollService;
|
use Framadate\Services\PollService;
|
||||||
use Framadate\Utils;
|
|
||||||
|
|
||||||
include_once __DIR__ . '/app/inc/init.php';
|
include_once __DIR__ . '/app/inc/init.php';
|
||||||
|
|
||||||
|
1
phpunit.bat
Normal file
1
phpunit.bat
Normal file
@ -0,0 +1 @@
|
|||||||
|
vendor\bin\phpunit.bat --bootstrap app\tests\bootstrap.php app/tests
|
1
phpunit.sh
Normal file
1
phpunit.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
vendor\bin\phpunit --bootstrap app\tests\bootstrap.php app/tests
|
@ -64,7 +64,7 @@ function sendUpdateNotification($poll, $mailService, $name, $type) {
|
|||||||
$_SESSION['mail_sent'] = [];
|
$_SESSION['mail_sent'] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($poll->receiveNewVotes && (!isset($_SESSION['mail_sent'][$poll->id]) || $_SESSION['mail_sent'][$poll->id] !== true)) {
|
if ($poll->receiveNewVotes) {
|
||||||
|
|
||||||
$subject = '[' . NOMAPPLICATION . '] ' . __('Mail', 'Poll\'s participation') . ' : ' . $poll->title;
|
$subject = '[' . NOMAPPLICATION . '] ' . __('Mail', 'Poll\'s participation') . ' : ' . $poll->title;
|
||||||
|
|
||||||
@ -82,9 +82,8 @@ function sendUpdateNotification($poll, $mailService, $name, $type) {
|
|||||||
}
|
}
|
||||||
$message .= Utils::getUrlSondage($poll->admin_id, true) . "\n\n";
|
$message .= Utils::getUrlSondage($poll->admin_id, true) . "\n\n";
|
||||||
|
|
||||||
$mailService->send($poll->admin_mail, $subject, $message);
|
$messageTypeKey = $type . '-' . $poll->id;
|
||||||
|
$mailService->send($poll->admin_mail, $subject, $message, $messageTypeKey);
|
||||||
$_SESSION['mail_sent'][$poll->id] = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,7 +151,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
|
|||||||
$message = new Message('danger', __('Error', 'The name is invalid.'));
|
$message = new Message('danger', __('Error', 'The name is invalid.'));
|
||||||
}
|
}
|
||||||
if (count($choices) != count($_POST['choices'])) {
|
if (count($choices) != count($_POST['choices'])) {
|
||||||
$message = new Message('danger', __('There is a problem with your choices'));
|
$message = new Message('danger', __('Error', 'There is a problem with your choices'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($message == null) {
|
if ($message == null) {
|
||||||
|
@ -29,8 +29,6 @@
|
|||||||
<div class="col-md-6 col-md-offset-3 text-center">
|
<div class="col-md-6 col-md-offset-3 text-center">
|
||||||
<p class="home-choice">
|
<p class="home-choice">
|
||||||
<a href="{$SERVER_URL}find_polls.php" class="opacity" role="button">
|
<a href="{$SERVER_URL}find_polls.php" class="opacity" role="button">
|
||||||
<img alt="" class="img-responsive center-block" src="{'images/question.png'|resource}"/>
|
|
||||||
<br/>
|
|
||||||
<span class="btn btn-warning btn-lg">
|
<span class="btn btn-warning btn-lg">
|
||||||
<span class="glyphicon glyphicon-search"></span>
|
<span class="glyphicon glyphicon-search"></span>
|
||||||
{__('Homepage', 'Where are my polls')}
|
{__('Homepage', 'Where are my polls')}
|
||||||
|
Loading…
Reference in New Issue
Block a user