Skip to content

Commit

Permalink
Tidying up email functions
Browse files Browse the repository at this point in the history
  • Loading branch information
DHS committed Jun 24, 2012
1 parent a38cd60 commit a1b009e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
6 changes: 2 additions & 4 deletions controllers/admin_controller.php
Expand Up @@ -201,13 +201,11 @@ function invite() {
$this->plugins->log->add($_SESSION['user_id'], 'invite', $id, 'admin_add', $email);
}

$to = $email;
$link = $this->config->url . 'users/add/' . $id . '/?email=' . urlencode($email);

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

// Email user
$this->email->send_email($to, $subject, $body);
Expand Down
5 changes: 2 additions & 3 deletions controllers/comments_controller.php
Expand Up @@ -18,13 +18,12 @@ function add() {

$to = array('name' => $item->user->username, 'email' => $item->user->email);
$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 . '!';
$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));
$link = substr($this->config->url, 0, -1) . $this->url_for('items', 'show', $item->id);
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/item_comment.html"), array('link' => $link, 'app' => $this, 'user' => $item->user));

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

} else {
ECHO 'NO';
}

// Log new comment
Expand Down
2 changes: 1 addition & 1 deletion controllers/friends_controller.php
Expand Up @@ -23,7 +23,7 @@ function add($friend_id) {
$to = array('email' => $email, 'friend' => $friend);
$link = $this->config->url . 'users/show/' . $user->id;
$subject = '[' . $this->config->name . '] Your ' . $this->config->name . ' invite is here!';
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/follower_new.html"), array('link' => $link, 'app' => array('config' => $this->config)));
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/follower_new.html"), array('link' => $link, 'app' => $this));

// Email user
$this->email->send_email($to, $subject, $body);
Expand Down
7 changes: 3 additions & 4 deletions controllers/invites_controller.php
Expand Up @@ -86,11 +86,10 @@ function add() {

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

$link = $this->config->url . 'signup/' . $id;

$to = array('email' => $_POST['email']);
$to = array('email' => $_POST['email']);
$subject = '[' . $this->config->name . '] An invitation from ' . $user->username;
$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)));
$link = $this->config->url . 'signup/' . $id;
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/invite_friend.html"), array('user' => $user, 'link' => $link, 'app' => $this));

// Email user
$this->email->send_email($to, $subject, $body);
Expand Down
3 changes: 2 additions & 1 deletion controllers/likes_controller.php
Expand Up @@ -14,7 +14,8 @@ function add($item_id) {

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

// Email user
$this->email->send_email($to, $subject, $body);
Expand Down
16 changes: 8 additions & 8 deletions controllers/users_controller.php
Expand Up @@ -250,7 +250,7 @@ function reset($code = null) {
$to = array('email' => $_POST['email']);
$link = substr($this->config->url, 0, -1).$this->url_for('users', 'reset', $code);
$subject = '[' . $this->config->name . '] Password reset';
$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)));
$body = $this->twig_string->render(file_get_contents("themes/{$this->config->theme}/emails/password_reset.html"), array('user' => $user, 'link' => $link, 'app' => $this));

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

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

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

Expand Down Expand Up @@ -582,9 +582,9 @@ private function signup_beta() {
// There was an error

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

// Show error message
Application::flash('error', $error);
Expand Down Expand Up @@ -641,9 +641,9 @@ private function signup_full() {

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

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

// Email user
$this->email->send_email($to, $subject, $body, TRUE);
Expand Down
1 change: 1 addition & 0 deletions lib/email.php
Expand Up @@ -24,6 +24,7 @@ public function send_email($to, $subject, $body, $debug = FALSE) {
if ($debug == TRUE) {
$to = htmlentities($to);
echo "$to<br />$subject<br />$body<br />$headers";
exit;
} else {
mail($to, $subject, $body, $headers);
}
Expand Down

0 comments on commit a1b009e

Please sign in to comment.