Merge pull request #77 from easyrhino/patch-1
Moving foreach($to_array as $to) to just before the self::_notify is necessary to make "message::success" work for multiple recipients. Otherwise, ecard fails with multiple recipients. Also added a trim around the $to so spaces before/after email address don't blow out function, and also reindented the code using Notepad++. Hope this works for the contrib team.
This commit is contained in:
commit
4c66b631c1
@ -1,122 +1,124 @@
|
|||||||
<?php defined("SYSPATH") or die("No direct script access.");
|
<?php defined("SYSPATH") or die("No direct script access.");
|
||||||
/**
|
/**
|
||||||
* Gallery - a web based photo album viewer and editor
|
* Gallery - a web based photo album viewer and editor
|
||||||
* Copyright (C) 2000-2011 Bharat Mediratta
|
* Copyright (C) 2000-2011 Bharat Mediratta
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation; either version 2 of the License, or (at
|
* the Free Software Foundation; either version 2 of the License, or (at
|
||||||
* your option) any later version.
|
* your option) any later version.
|
||||||
*
|
*
|
||||||
* This program is distributed in the hope that it will be useful, but
|
* This program is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
* General Public License for more details.
|
* General Public License for more details.
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Ecard_Controller extends Controller {
|
class Ecard_Controller extends Controller {
|
||||||
/**
|
/**
|
||||||
* Send the ecard.
|
* Send the ecard.
|
||||||
*/
|
*/
|
||||||
public function send($id) {
|
public function send($id) {
|
||||||
$item = ORM::factory("item", $id);
|
$item = ORM::factory("item", $id);
|
||||||
access::required("view", $item);
|
access::required("view", $item);
|
||||||
if (!ecard::can_send_ecard()) {
|
if (!ecard::can_send_ecard()) {
|
||||||
access::forbidden();
|
access::forbidden();
|
||||||
}
|
}
|
||||||
$form = ecard::get_send_form($item);
|
$form = ecard::get_send_form($item);
|
||||||
try {
|
try {
|
||||||
$valid = $form->validate();
|
$valid = $form->validate();
|
||||||
} catch (ORM_Validation_Exception $e) {
|
} catch (ORM_Validation_Exception $e) {
|
||||||
// Translate ORM validation errors into form error messages
|
// Translate ORM validation errors into form error messages
|
||||||
foreach ($e->validation->errors() as $key => $error) {
|
foreach ($e->validation->errors() as $key => $error) {
|
||||||
$form->edit_item->inputs[$key]->add_error($error, 1);
|
$form->edit_item->inputs[$key]->add_error($error, 1);
|
||||||
}
|
}
|
||||||
$valid = false;
|
$valid = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($valid) {
|
if ($valid) {
|
||||||
$to_array = explode(",",$form->send_ecard->inputs["to_email"]->value);
|
$v = new View("ecard_email.html");
|
||||||
foreach($to_array as $to) {
|
$v->item = $item;
|
||||||
$v = new View("ecard_email.html");
|
$v->subject = module::get_var("ecard", "subject");
|
||||||
$v->item = $item;
|
$from_name = $form->send_ecard->from_name->value;
|
||||||
$v->subject = module::get_var("ecard", "subject");
|
$bcc = module::get_var("ecard", "bcc");
|
||||||
$from_name = $form->send_ecard->from_name->value;
|
if($form->send_ecard->send_to_self->checked == true) {
|
||||||
$bcc = module::get_var("ecard", "bcc");
|
$cc = $form->send_ecard->inputs["from_email"]->value;
|
||||||
if($form->send_ecard->send_to_self->checked == true) {
|
}
|
||||||
$cc = $form->send_ecard->inputs["from_email"]->value;
|
$v->message = t(module::get_var("ecard", "message"), array("fromname" => $from_name));
|
||||||
}
|
$v->custom_message = $form->send_ecard->text->value;
|
||||||
$v->message = t(module::get_var("ecard", "message"), array("fromname" => $from_name));
|
$v->image = $item->name;
|
||||||
$v->custom_message = $form->send_ecard->text->value;
|
$from = $form->send_ecard->inputs["from_email"]->value;
|
||||||
$v->image = $item->name;
|
|
||||||
$from = $form->send_ecard->inputs["from_email"]->value;
|
require_once(MODPATH. "ecard/lib/mime.php");
|
||||||
$headers = array("from" => $from_name."<".$from.">", "to" => $to, "subject" => module::get_var("ecard", "subject"));
|
$mime = new Mail_mime("\n");
|
||||||
require_once(MODPATH. "ecard/lib/mime.php");
|
$mime->setHTMLBody($v->render());
|
||||||
$mime = new Mail_mime("\n");
|
if($form->send_ecard->send_fresh->checked == true) {
|
||||||
$mime->setHTMLBody($v->render());
|
$tmpfile = tempnam(TMPPATH, "clean");
|
||||||
if($form->send_ecard->send_fresh->checked == true) {
|
if($form->send_ecard->send_thumbnail->checked == true) {
|
||||||
$tmpfile = tempnam(TMPPATH, "clean");
|
$options = array("width" => module::get_var("gallery", "thumb_size"), "height" => module::get_var("gallery", "thumb_size"), "master" => Image::AUTO);
|
||||||
if($form->send_ecard->send_thumbnail->checked == true) {
|
gallery_graphics::resize($item->file_path(), $tmpfile, $options, $item);
|
||||||
$options = array("width" => module::get_var("gallery", "thumb_size"), "height" => module::get_var("gallery", "thumb_size"), "master" => Image::AUTO);
|
$mime->addHTMLImage($tmpfile,$item->mime_type,$item->name);
|
||||||
gallery_graphics::resize($item->file_path(), $tmpfile, $options, $item);
|
} else {
|
||||||
$mime->addHTMLImage($tmpfile,$item->mime_type,$item->name);
|
$options = array("width" => module::get_var("gallery", "resize_size"), "height" => module::get_var("gallery", "resize_size"), "master" => Image::AUTO);
|
||||||
} else {
|
gallery_graphics::resize($item->file_path(), $tmpfile, $options, $item);
|
||||||
$options = array("width" => module::get_var("gallery", "resize_size"), "height" => module::get_var("gallery", "resize_size"), "master" => Image::AUTO);
|
$mime->addHTMLImage($tmpfile,$item->mime_type,$item->name);
|
||||||
gallery_graphics::resize($item->file_path(), $tmpfile, $options, $item);
|
}
|
||||||
$mime->addHTMLImage($tmpfile,$item->mime_type,$item->name);
|
} else {
|
||||||
}
|
if($form->send_ecard->send_thumbnail->checked == true) {
|
||||||
} else {
|
$mime->addHTMLImage($item->thumb_path(),$item->mime_type,$item->name);
|
||||||
if($form->send_ecard->send_thumbnail->checked == true) {
|
} else {
|
||||||
$mime->addHTMLImage($item->thumb_path(),$item->mime_type,$item->name);
|
$mime->addHTMLImage($item->resize_path(),$item->mime_type,$item->name);
|
||||||
} else {
|
}
|
||||||
$mime->addHTMLImage($item->resize_path(),$item->mime_type,$item->name);
|
}
|
||||||
}
|
$body = $mime->get(array('html_charset' => 'UTF-8', 'text_charset' => 'UTF-8','text_encoding' => '8bit','head_charset' => 'UTF-8'));
|
||||||
}
|
|
||||||
$body = $mime->get(array('html_charset' => 'UTF-8', 'text_charset' => 'UTF-8','text_encoding' => '8bit','head_charset' => 'UTF-8'));
|
$to_array = explode(",",$form->send_ecard->inputs["to_email"]->value);
|
||||||
self::_notify($headers['to'], $headers['from'], $headers['subject'], $item, $body, $mime->headers(), $bcc, $cc);
|
foreach($to_array as $to) {
|
||||||
|
$headers = array("from" => $from_name."<".$from.">", "to" => trim($to), "subject" => module::get_var("ecard", "subject"));
|
||||||
|
self::_notify($headers['to'], $headers['from'], $headers['subject'], $item, $body, $mime->headers(), $bcc, $cc);
|
||||||
|
}
|
||||||
|
unlink($tmpfile);
|
||||||
|
message::success("eCard successfully sent to ".$form->send_ecard->inputs["to_email"]->value);
|
||||||
|
json::reply(array("result" => "success"));
|
||||||
|
} else {
|
||||||
|
json::reply(array("result" => "error", "html" => (string) $form));
|
||||||
}
|
}
|
||||||
unlink($tmpfile);
|
|
||||||
message::success("eCard successfully sent");
|
|
||||||
json::reply(array("result" => "success"));
|
|
||||||
} else {
|
|
||||||
json::reply(array("result" => "error", "html" => (string) $form));
|
|
||||||
}
|
}
|
||||||
}
|
/**
|
||||||
/**
|
* Present a form for sending a new ecard.
|
||||||
* Present a form for sending a new ecard.
|
*/
|
||||||
*/
|
public function form_send($item_id) {
|
||||||
public function form_send($item_id) {
|
$item = ORM::factory("item", $item_id);
|
||||||
$item = ORM::factory("item", $item_id);
|
access::required("view", $item);
|
||||||
access::required("view", $item);
|
if (!ecard::can_send_ecard()) {
|
||||||
if (!ecard::can_send_ecard()) {
|
access::forbidden();
|
||||||
access::forbidden();
|
}
|
||||||
}
|
$v_form = new View("ecard_form.html");
|
||||||
$v_form = new View("ecard_form.html");
|
$v_form->item_id = $item_id;
|
||||||
$v_form->item_id = $item_id;
|
print $v_form->render();
|
||||||
print $v_form->render();
|
}
|
||||||
}
|
private static function _notify($to, $from, $subject, $item, $text, $headers, $bcc, $cc) {
|
||||||
private static function _notify($to, $from, $subject, $item, $text, $headers, $bcc, $cc) {
|
$sendmail = Sendmail::factory();
|
||||||
$sendmail = Sendmail::factory();
|
$sendmail
|
||||||
$sendmail
|
->to($to)
|
||||||
->to($to)
|
|
||||||
->from($from)
|
->from($from)
|
||||||
->subject($subject);
|
->subject($subject);
|
||||||
if(isset($bcc)) {
|
if(isset($bcc)) {
|
||||||
$sendmail->header("bcc",$bcc);
|
$sendmail->header("bcc",$bcc);
|
||||||
}
|
}
|
||||||
if(isset($cc)) {
|
if(isset($cc)) {
|
||||||
$sendmail->header("cc",$cc);
|
$sendmail->header("cc",$cc);
|
||||||
}
|
}
|
||||||
foreach($headers as $key => $value) {
|
foreach($headers as $key => $value) {
|
||||||
$sendmail->header($key,$value);
|
$sendmail->header($key,$value);
|
||||||
}
|
}
|
||||||
$sendmail
|
$sendmail
|
||||||
->message($text)
|
->message($text)
|
||||||
->send();
|
->send();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user