Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
framadate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Nounous
framadate
Commits
8109b11b
Commit
8109b11b
authored
10 years ago
by
Olivier PEREZ
Browse files
Options
Downloads
Patches
Plain Diff
Move mail sending to class \Framadate\Service\MailService
parent
d942f82b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/classes/Framadate/Services/MailService.php
+49
-0
49 additions, 0 deletions
app/classes/Framadate/Services/MailService.php
app/classes/Framadate/Utils.php
+9
-6
9 additions, 6 deletions
app/classes/Framadate/Utils.php
studs.php
+29
-2
29 additions, 2 deletions
studs.php
with
87 additions
and
8 deletions
app/classes/Framadate/Services/MailService.php
0 → 100644
+
49
−
0
View file @
8109b11b
<?php
namespace
Framadate\Services
;
class
MailService
{
private
$smtp_allowed
;
function
__construct
(
$smtp_allowed
)
{
$this
->
smtp_allowed
=
$smtp_allowed
;
}
public
function
isValidEmail
(
$email
)
{
return
filter_var
(
$email
,
FILTER_VALIDATE_EMAIL
);
}
function
send
(
$to
,
$subject
,
$body
,
$param
=
''
)
{
if
(
$this
->
smtp_allowed
==
true
)
{
mb_internal_encoding
(
'UTF-8'
);
$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
);
$size_encoded_app
=
(
6
+
strlen
(
$encoded_app
))
%
75
;
$size_admin_email
=
strlen
(
ADRESSEMAILADMIN
);
if
((
$size_encoded_app
+
$size_admin_email
+
9
)
>
74
)
{
$folding
=
"
\n
"
;
}
else
{
$folding
=
''
;
};
$from
=
sprintf
(
"From: %s%s <%s>
\n
"
,
$encoded_app
,
$folding
,
ADRESSEMAILADMIN
);
$headers
=
$from
;
$headers
.
=
'Reply-To: '
.
ADRESSEMAILREPONSEAUTO
.
"
\n
"
;
$headers
.
=
"MIME-Version: 1.0
\n
"
;
$headers
.
=
"Content-Type: text/plain; charset=UTF-8
\n
"
;
$headers
.
=
"Content-Transfer-Encoding: 8bit
\n
"
;
$headers
.
=
"Auto-Submitted:auto-generated
\n
"
;
$headers
.
=
'Return-Path: <>'
;
$body
=
html_entity_decode
(
$body
,
ENT_QUOTES
,
'UTF-8'
)
.
_
(
'\n--\n\n« La route est longue, mais la voie est libre… »\nFramasoft ne vit que par vos dons (déductibles des impôts).\nMerci d\'avance pour votre soutien http://soutenir.framasoft.org.'
);
mail
(
$to
,
$subject
,
$body
,
$headers
,
$param
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
app/classes/Framadate/Utils.php
+
9
−
6
View file @
8109b11b
...
...
@@ -45,6 +45,10 @@ class Utils
return
(
USE_REMOTE_USER
&&
isset
(
$_SERVER
[
'REMOTE_USER'
]))
||
isset
(
$_SESSION
[
'nom'
]);
}
/**
* @param string $title
* @deprecated
*/
public
static
function
print_header
(
$title
=
''
)
{
global
$lang
;
...
...
@@ -87,6 +91,7 @@ class Utils
*
* @param string $email Email address to check
* @return bool True if valid. False if not valid.
* @deprecated
*/
public
static
function
isValidEmail
(
$email
)
{
...
...
@@ -96,7 +101,7 @@ class Utils
/**
* Envoi un courrier avec un codage correct de To et Subject
* Les en-têtes complémentaires ne sont pas gérés
*
*
@deprecated
*/
public
static
function
sendEmail
(
$to
,
$subject
,
$body
,
$headers
=
''
,
$param
=
''
)
{
...
...
@@ -175,8 +180,7 @@ class Utils
* Completly delete data about the given poll
* TODO Move this function to FramaDB
*/
public
static
function
removeSondage
(
$poll_id
)
{
public
static
function
removeSondage
(
$poll_id
)
{
global
$connect
;
$prepared
=
$connect
->
prepare
(
'DELETE FROM sujet_studs WHERE id_sondage = ?'
);
...
...
@@ -195,7 +199,7 @@ class Utils
/**
* Clean old poll (end_date < now).
* TODO Move this function to
FramaDB
* TODO Move this function to
PurgePollService
*/
public
static
function
cleaningOldPolls
(
$log_txt
)
{
global
$connect
;
...
...
@@ -216,8 +220,7 @@ class Utils
* This method pretty prints an object to the page framed by pre tags.
* @param mixed $object The object to print.
*/
public
static
function
debug
(
$object
)
{
public
static
function
debug
(
$object
)
{
echo
'<pre>'
;
print_r
(
$object
);
echo
'</pre>'
;
...
...
This diff is collapsed.
Click to expand it.
studs.php
+
29
−
2
View file @
8109b11b
...
...
@@ -18,6 +18,7 @@
*/
use
Framadate\Services\PollService
;
use
Framadate\Services\InputService
;
use
Framadate\Services\MailService
;
use
Framadate\Message
;
use
Framadate\Utils
;
...
...
@@ -25,6 +26,7 @@ include_once __DIR__ . '/app/inc/init.php';
/* Variables */
/* --------- */
$poll_id
=
null
;
$poll
=
null
;
$message
=
null
;
...
...
@@ -35,6 +37,31 @@ $editingVoteId = 0;
$pollService
=
new
PollService
(
$connect
);
$inputService
=
new
InputService
();
$mailService
=
new
MailService
(
$config
[
'use_smtp'
]);
/* Functions */
/*-----------*/
/**
* Send a notification to the poll admin to notify him about an update.
*
* @param $poll Object The poll
* @param $mailService MailService The mail service
*/
function
sendUpdateNotification
(
$poll
,
$mailService
)
{
if
(
$poll
->
receiveNewVotes
&&
!
isset
(
$_SESSION
[
'mail_sent'
][
$poll
->
poll_id
]))
{
$subject
=
'['
.
NOMAPPLICATION
.
'] '
.
_
(
'Poll\'s participation'
)
.
' : '
.
html_entity_decode
(
$poll
->
title
,
ENT_QUOTES
,
'UTF-8'
);
$message
=
html_entity_decode
(
'"$nom" '
,
ENT_QUOTES
,
'UTF-8'
)
.
_
(
'has filled a line.\nYou can find your poll at the link'
)
.
" :
\n\n
"
.
Utils
::
getUrlSondage
(
$poll
->
admin_poll_id
,
true
)
.
"
\n\n
"
.
_
(
'Thanks for your confidence.'
)
.
"
\n
"
.
NOMAPPLICATION
;
$mailService
->
send
(
$poll
->
admin_mail
,
$subject
,
$message
);
$_SESSION
[
"mail_sent"
][
$poll
->
poll_id
]
=
true
;
}
}
/* PAGE */
/* ---- */
...
...
@@ -79,7 +106,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
$result
=
$pollService
->
updateVote
(
$poll_id
,
$editedVote
,
$choices
);
if
(
$result
)
{
$message
=
new
Message
(
'success'
,
_
(
'Update vote successfully.'
));
// TODO Send mail to notify the poll admin
sendUpdateNotification
(
$poll
,
$mailService
);
}
else
{
$message
=
new
Message
(
'danger'
,
_
(
'Update vote failed.'
));
}
...
...
@@ -100,7 +127,7 @@ if (!empty($_POST['save'])) { // Save edition of an old vote
$result
=
$pollService
->
addVote
(
$poll_id
,
$name
,
$choices
);
if
(
$result
)
{
$message
=
new
Message
(
'success'
,
_
(
'Update vote successfully.'
));
// TODO Send mail to notify the poll admin
sendUpdateNotification
(
$poll
,
$mailService
);
}
else
{
$message
=
new
Message
(
'danger'
,
_
(
'Update vote failed.'
));
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment