Skip to content

Commit a1b009e

Browse files
committed
Tidying up email functions
1 parent a38cd60 commit a1b009e

File tree

7 files changed

+19
-21
lines changed

7 files changed

+19
-21
lines changed

controllers/admin_controller.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,11 @@ function invite() {
201201
$this->plugins->log->add($_SESSION['user_id'], 'invite', $id, 'admin_add', $email);
202202
}
203203

204-
$to = $email;
205-
$link = $this->config->url . 'users/add/' . $id . '/?email=' . urlencode($email);
206-
207204
// Load template into $body variable
208205
$to = array('email' => $email);
209206
$subject = '[' . $this->config->name . '] Your ' . $this->config->name . ' invite is here!';
210-
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/admin_invite.html"), array('link' => $link, 'app' => array('config' => $this->config)));
207+
$link = $this->config->url . 'users/add/' . $id . '/?email=' . urlencode($email);
208+
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/admin_invite.html"), array('link' => $link, 'app' => $this));
211209

212210
// Email user
213211
$this->email->send_email($to, $subject, $body);

controllers/comments_controller.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ function add() {
1818

1919
$to = array('name' => $item->user->username, 'email' => $item->user->email);
2020
$subject = '[' . $this->config->name . '] Someone left a ' . strtolower($this->config->items['comments']['name']) . ' on your ' . strtolower($this->config->items['titles']['name']) . ' on ' . $this->config->name . '!';
21-
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/item_comment.html"), array('link' => substr($this->config->url, 0, -1) . $this->url_for('items', 'show', $item->id), 'app' => array('config' => $this->config), 'user' => $item->user));
21+
$link = substr($this->config->url, 0, -1) . $this->url_for('items', 'show', $item->id);
22+
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/item_comment.html"), array('link' => $link, 'app' => $this, 'user' => $item->user));
2223

2324
// Email user
2425
$this->email->send_email($to, $subject, $body);
2526

26-
} else {
27-
ECHO 'NO';
2827
}
2928

3029
// Log new comment

controllers/friends_controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function add($friend_id) {
2323
$to = array('email' => $email, 'friend' => $friend);
2424
$link = $this->config->url . 'users/show/' . $user->id;
2525
$subject = '[' . $this->config->name . '] Your ' . $this->config->name . ' invite is here!';
26-
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/follower_new.html"), array('link' => $link, 'app' => array('config' => $this->config)));
26+
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/follower_new.html"), array('link' => $link, 'app' => $this));
2727

2828
// Email user
2929
$this->email->send_email($to, $subject, $body);

controllers/invites_controller.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ function add() {
8686

8787
$admin = User::get_by_id($this->config->admin_users[0]);
8888

89-
$link = $this->config->url . 'signup/' . $id;
90-
91-
$to = array('email' => $_POST['email']);
89+
$to = array('email' => $_POST['email']);
9290
$subject = '[' . $this->config->name . '] An invitation from ' . $user->username;
93-
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/invite_friend.html"), array('link' => $link, 'user' => $user, 'app' => array('config' => $this->config)));
91+
$link = $this->config->url . 'signup/' . $id;
92+
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/invite_friend.html"), array('user' => $user, 'link' => $link, 'app' => $this));
9493

9594
// Email user
9695
$this->email->send_email($to, $subject, $body);

controllers/likes_controller.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ function add($item_id) {
1414

1515
$to = array('name' => $item->user->username, 'email' => $item->user->email);
1616
$subject = '[' . $this->config->name . '] Someone clicked ' . strtolower($this->config->items['likes']['name']) . ' on your ' . strtolower($this->config->items['name']) . ' on ' . $this->config->name . '!';
17-
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/item_like.html"), array('link' => substr($this->config->url, 0, -1) . $this->url_for('items', 'show', $item->id), 'app' => array('config' => $this->config), 'user' => $item->user));
17+
$link = substr($this->config->url, 0, -1) . $this->url_for('items', 'show', $item->id);
18+
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/item_like.html"), array('user' => $item->user, 'link' => $link, 'app' => $this));
1819

1920
// Email user
2021
$this->email->send_email($to, $subject, $body);

controllers/users_controller.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ function reset($code = null) {
250250
$to = array('email' => $_POST['email']);
251251
$link = substr($this->config->url, 0, -1).$this->url_for('users', 'reset', $code);
252252
$subject = '[' . $this->config->name . '] Password reset';
253-
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/password_reset.html"), array('link' => $link, 'user' => $user, 'app' => array('config' => $this->config)));
253+
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/password_reset.html"), array('user' => $user, 'link' => $link, 'app' => $this));
254254

255255
// Email user
256256
$this->email->send_email($to, $subject, $body);
@@ -453,7 +453,7 @@ private function signup_code() {
453453

454454
$to = array('name' => $_POST['username'], 'email' => $_POST['email']);
455455
$subject = '[' . $this->config->name . '] Your ' . $this->config->name . ' invite is here!';
456-
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/signup.html"), array('username' => $_POST['username'], 'app' => array('config' => $this->config)));
456+
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/signup.html"), array('username' => $_POST['username'], 'app' => $this));
457457

458458
$this->email->send_email($to, $subject, $body);
459459

@@ -582,9 +582,9 @@ private function signup_beta() {
582582
// There was an error
583583

584584
// Propagate get vars to be picked up by the form
585-
$this->uri['params']['email'] = $_POST['email'];
586-
$this->uri['params']['username'] = $_POST['username'];
587-
$this->code = $_POST['code'];
585+
$this->uri['params']['email'] = $_POST['email'];
586+
$this->uri['params']['username'] = $_POST['username'];
587+
$this->code = $_POST['code'];
588588

589589
// Show error message
590590
Application::flash('error', $error);
@@ -641,9 +641,9 @@ private function signup_full() {
641641

642642
$admin = User::get_by_id($this->config->admin_users[0]);
643643

644-
$to = array('name' => $_POST['username'], 'email' => $_POST['email']);
645-
$subject = '[' . $this->config->name . '] Welcome to ' . $this->config->name . '!';
646-
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/signup.html"), array('username' => $_POST['username'], 'app' => array('config' => $this->config)));
644+
$to = array('name' => $_POST['username'], 'email' => $_POST['email']);
645+
$subject = '[' . $this->config->name . '] Welcome to ' . $this->config->name . '!';
646+
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/signup.html"), array('username' => $_POST['username'], 'app' => $this));
647647

648648
// Email user
649649
$this->email->send_email($to, $subject, $body, TRUE);

lib/email.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public function send_email($to, $subject, $body, $debug = FALSE) {
2424
if ($debug == TRUE) {
2525
$to = htmlentities($to);
2626
echo "$to<br />$subject<br />$body<br />$headers";
27+
exit;
2728
} else {
2829
mail($to, $subject, $body, $headers);
2930
}

0 commit comments

Comments
 (0)