Skip to content

Commit 4256360

Browse files
committed
Upgraded Swiftmailer and php-markdown.
Switched to smtp transport as mail transport is deprecated.
1 parent 93c18d4 commit 4256360

File tree

3 files changed

+65
-40
lines changed

3 files changed

+65
-40
lines changed

composer.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
"irc" : "irc://freenet/#joindin",
1010
"source" : "https://github.com/joindin/joindin-api"
1111
},
12-
"preferred-install": "dist",
1312
"require" : {
14-
"swiftmailer/swiftmailer": "^v5.0",
15-
"michelf/php-markdown": "1.4.0",
13+
"ext-pdo": "*",
14+
"ext-json": "*",
15+
"swiftmailer/swiftmailer": "^v5.4.9",
16+
"michelf/php-markdown": "^1.8.0",
1617
"guzzlehttp/guzzle": "^4.2.4",
1718
"guzzlehttp/oauth-subscriber": "0.1.*"
1819
},
@@ -51,6 +52,7 @@
5152
]
5253
},
5354
"config" : {
55+
"preferred-install": "dist",
5456
"platform" : {
5557
"php": "5.6.6"
5658
},

src/config.php.dist

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,52 @@
11
<?php
22

3-
$config = array(
4-
'mode' => 'development',
3+
$config = [
4+
'mode' => 'development',
55

66
// the URL of web2 website is used in links within emails
77
'website_url' => 'http://dev.joind.in',
88

9-
'oauth' => array(
10-
'expirable_client_ids' => array(
9+
'oauth' => [
10+
'expirable_client_ids' => [
1111
// some clients, (e.g. web2) do not hold onto their token after the
1212
// user logs out of the client, so we can expire their old tokens.
1313
'web2',
14-
),
15-
),
16-
'event_image_path' => __DIR__ . '/../../joindin-web2/web/inc/img/event_icons/',
17-
'email' => array(
18-
'contact' => '[email protected]',
19-
'from' => '[email protected]',
20-
'forward_all_to' => false
21-
),
22-
'twitter' => array(
14+
],
15+
],
16+
'event_image_path' => __DIR__.'/../../joindin-web2/web/inc/img/event_icons/',
17+
'email' => [
18+
'contact' => '[email protected]',
19+
'from' => '[email protected]',
20+
'forward_all_to' => false,
21+
'smtp' => [
22+
'host' => 'localhost',
23+
'port' => 25,
24+
'username' => 'username',
25+
'password' => 'ChangeMeSeymourChangeMe',
26+
'security' => 'ssl'
27+
],
28+
],
29+
'twitter' => [
2330
// set up the key at https://apps.twitter.com/
2431
// configure the callback url as /user/twitter-access on web2
25-
'consumer_key' => '',
26-
'consumer_secret' => ''
27-
),
28-
'facebook' => array(
32+
'consumer_key' => '',
33+
'consumer_secret' => '',
34+
],
35+
'facebook' => [
2936
// set up at https://developers.facebook.com/apps/
3037
// configure url in OAuth Settings as /user/facebook-access on web2
31-
'app_id' => '',
38+
'app_id' => '',
3239
'app_secret' => '',
33-
),
34-
'features' => array(
35-
'allow_auto_verify_users' => false,
40+
],
41+
'features' => [
42+
'allow_auto_verify_users' => false,
3643
'allow_auto_approve_events' => false,
37-
),
38-
'limits' => array(
39-
'max_pending_events' => 3,
44+
],
45+
'limits' => [
46+
'max_pending_events' => 3,
4047
'max_comment_edit_minutes' => 15,
41-
)
42-
);
48+
],
49+
];
4350

4451
// uncomment and add your akismet key here if you want to do spam checking
4552
// $config['akismet'] = [

src/services/BaseEmailService.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<?php
22

3+
use Michelf\Markdown;
4+
35
/**
46
* Base Email Class
57
*
@@ -32,19 +34,33 @@ abstract class BaseEmailService
3234
/**
3335
* Make a message to be sent later
3436
*
35-
* @param array $config The system config
37+
* @param array $config The system config
3638
* @param array $recipients An array of email addresses
39+
* @throws \Exception
3740
*/
3841
public function __construct(array $config, array $recipients)
3942
{
40-
$transport = \Swift_MailTransport::newInstance();
41-
$this->mailer = \Swift_Mailer::newInstance($transport);
42-
$this->message = \Swift_Message::newInstance();
43+
if (!isset($config['email']['smtp'])) {
44+
throw new Exception("SMTP Server not properly set up.");
45+
}
46+
47+
$transport = (Swift_SmtpTransport::newInstance(
48+
$config['email']['smtp']['host'],
49+
$config['email']['smtp']['port'],
50+
$config['email']['smtp']['security']
51+
))
52+
->setUsername($config['email']['smtp']['username'])
53+
->setPassword($config['email']['smtp']['password'])
54+
;
55+
56+
57+
$this->mailer = Swift_Mailer::newInstance($transport);
58+
$this->message = Swift_Message::newInstance();
4359

4460
if (isset($config['email']['forward_all_to'])
45-
&& ! empty($config['email']['forward_all_to'])
61+
&& !empty($config['email']['forward_all_to'])
4662
) {
47-
$this->recipients = array($config['email']['forward_all_to']);
63+
$this->recipients = [$config['email']['forward_all_to']];
4864
} else {
4965
$this->recipients = $recipients;
5066
}
@@ -57,18 +73,18 @@ public function __construct(array $config, array $recipients)
5773
* with the correct values in it
5874
*
5975
* @param string $templateName
60-
* @param array $replacements
76+
* @param array $replacements
6177
*
6278
* @return string
6379
*/
6480
public function parseEmail($templateName, array $replacements)
6581
{
66-
$template = file_get_contents($this->templatePath . $templateName)
67-
. file_get_contents($this->templatePath . 'signature.md');
82+
$template = file_get_contents($this->templatePath.$templateName)
83+
.file_get_contents($this->templatePath.'signature.md');
6884

6985
$message = $template;
7086
foreach ($replacements as $field => $value) {
71-
$message = str_replace('[' . $field . ']', $value, $message);
87+
$message = str_replace('['.$field.']', $value, $message);
7288
}
7389

7490
return $message;
@@ -154,7 +170,7 @@ public function getRecipients()
154170
*/
155171
public function markdownToHtml($markdown)
156172
{
157-
$messageHTML = Michelf\Markdown::defaultTransform($markdown);
173+
$messageHTML = Markdown::defaultTransform($markdown);
158174

159175
return $messageHTML;
160176
}

0 commit comments

Comments
 (0)