Initial Commit
Signed-off-by: Bharat Mediratta <bharat@menalto.com>
This commit is contained in:
parent
091cf2869d
commit
3fd249ba60
93
modules/phpmailer/controllers/admin_phpmailer.php
Normal file
93
modules/phpmailer/controllers/admin_phpmailer.php
Normal file
@ -0,0 +1,93 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
class Admin_PHPMailer_Controller extends Admin_Controller {
|
||||
public function index() {
|
||||
// Generate a new admin page.
|
||||
$view = new Admin_View("admin.html");
|
||||
$view->content = new View("admin_phpmailer.html");
|
||||
$view->content->phpmailer_form = $this->_get_admin_form();
|
||||
print $view;
|
||||
}
|
||||
|
||||
public function saveprefs() {
|
||||
// Prevent Cross Site Request Forgery
|
||||
access::verify_csrf();
|
||||
|
||||
// Figure out the values of the text boxes
|
||||
$str_phpmailer_path = Input::instance()->post("phpmailer_path");
|
||||
$str_phpmailer_from_addr = Input::instance()->post("phpmailer_from_address");
|
||||
$str_phpmailer_from_name = Input::instance()->post("phpmailer_from_name");
|
||||
$str_smtp_server = Input::instance()->post("phpmailer_smtp_server");
|
||||
$str_smtp_login = Input::instance()->post("phpmailer_smtp_login");
|
||||
$str_smtp_pass = Input::instance()->post("phpmailer_smtp_password");
|
||||
|
||||
// Save Settings.
|
||||
module::set_var("phpmailer", "phpmailer_path", $str_phpmailer_path);
|
||||
module::set_var("phpmailer", "phpmailer_from_address", $str_phpmailer_from_addr);
|
||||
module::set_var("phpmailer", "phpmailer_from_name", $str_phpmailer_from_name);
|
||||
module::set_var("phpmailer", "smtp_server", $str_smtp_server);
|
||||
module::set_var("phpmailer", "smtp_login", $str_smtp_login);
|
||||
module::set_var("phpmailer", "smtp_password", $str_smtp_pass);
|
||||
message::success(t("Your Settings Have Been Saved."));
|
||||
|
||||
// Load Admin page.
|
||||
$view = new Admin_View("admin.html");
|
||||
$view->content = new View("admin_phpmailer.html");
|
||||
$view->content->phpmailer_form = $this->_get_admin_form();
|
||||
print $view;
|
||||
}
|
||||
|
||||
private function _get_admin_form() {
|
||||
// Make a new Form.
|
||||
$form = new Forge("admin/phpmailer/saveprefs", "", "post",
|
||||
array("id" => "gPHPMailerAdminForm"));
|
||||
|
||||
// Create the input boxes for the PHPMailer Settings
|
||||
$phpmailerGroup = $form->group("PHPMailerSettings");
|
||||
$phpmailerGroup->input("phpmailer_path")
|
||||
->label(t("Location of PHPMailer Class"))
|
||||
->value(module::get_var("phpmailer", "phpmailer_path"));
|
||||
$phpmailerGroup->input("phpmailer_from_address")
|
||||
->label(t("From Email Address"))
|
||||
->value(module::get_var("phpmailer", "phpmailer_from_address"));
|
||||
$phpmailerGroup->input("phpmailer_from_name")
|
||||
->label(t("From Name"))
|
||||
->value(module::get_var("phpmailer", "phpmailer_from_name"));
|
||||
|
||||
// Create the input boxes for the SMTP server settings
|
||||
$phpmailerSMTP = $form->group("PHPMailerSMTPSettings");
|
||||
$phpmailerSMTP->input("phpmailer_smtp_server")
|
||||
->label(t("SMTP Server Address"))
|
||||
->value(module::get_var("phpmailer", "smtp_server"));
|
||||
$phpmailerSMTP->input("phpmailer_smtp_login")
|
||||
->label(t("SMTP Login Name"))
|
||||
->value(module::get_var("phpmailer", "smtp_login"));
|
||||
$phpmailerSMTP->input("phpmailer_smtp_password")
|
||||
->label(t("SMTP Password"))
|
||||
->value(module::get_var("phpmailer", "smtp_password"));
|
||||
|
||||
// Add a save button to the form.
|
||||
$form->submit("SaveSettings")->value(t("Save"));
|
||||
|
||||
// Return the newly generated form.
|
||||
return $form;
|
||||
}
|
||||
}
|
27
modules/phpmailer/helpers/phpmailer_installer.php
Normal file
27
modules/phpmailer/helpers/phpmailer_installer.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class phpmailer_installer {
|
||||
static function install() {
|
||||
module::set_version("phpmailer", 1);
|
||||
}
|
||||
|
||||
static function uninstall() {
|
||||
module::delete("phpmailer");
|
||||
}
|
||||
}
|
28
modules/phpmailer/helpers/phpmailer_menu.php
Normal file
28
modules/phpmailer/helpers/phpmailer_menu.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class phpmailer_menu_Core {
|
||||
static function admin($menu, $theme) {
|
||||
$menu->get("settings_menu")
|
||||
->append(Menu::factory("link")
|
||||
->id("phpmailer")
|
||||
->label(t("PHPMailer Settings"))
|
||||
->url(url::site("admin/phpmailer")));
|
||||
}
|
||||
}
|
126
modules/phpmailer/libraries/Sendmail.php
Normal file
126
modules/phpmailer/libraries/Sendmail.php
Normal file
@ -0,0 +1,126 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.");
|
||||
/**
|
||||
* Gallery - a web based photo album viewer and editor
|
||||
* Copyright (C) 2000-2009 Bharat Mediratta
|
||||
*
|
||||
* 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
|
||||
* the Free Software Foundation; either version 2 of the License, or (at
|
||||
* your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
class Sendmail_Core {
|
||||
protected $to;
|
||||
protected $subject;
|
||||
protected $message;
|
||||
protected $headers;
|
||||
protected $line_length = 70;
|
||||
protected $header_separator = "\r\n";
|
||||
|
||||
/**
|
||||
* Return an instance of Sendmail
|
||||
* @chainable
|
||||
*/
|
||||
static function factory() {
|
||||
return new Sendmail();
|
||||
}
|
||||
|
||||
public function __construct() {
|
||||
$this->headers = array();
|
||||
$config = Kohana::config("sendmail");
|
||||
foreach ($config as $key => $value) {
|
||||
$this->$key($value);
|
||||
}
|
||||
}
|
||||
|
||||
public function __get($key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function __call($key, $value) {
|
||||
switch ($key) {
|
||||
case "to":
|
||||
$this->to = is_array($value[0]) ? $value[0] : array($value[0]);
|
||||
break;
|
||||
case "header":
|
||||
if (count($value) != 2) {
|
||||
throw new Exception("@todo INVALID_HEADER_PARAMETERS");
|
||||
}
|
||||
$this->headers[$value[0]] = $value[1];
|
||||
break;
|
||||
case "from":
|
||||
$this->headers["From"] = $value[0];
|
||||
break;
|
||||
case "reply_to":
|
||||
$this->headers["Reply-To"] = $value[0];
|
||||
break;
|
||||
default:
|
||||
$this->$key = $value[0];
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function send() {
|
||||
if (empty($this->to)) {
|
||||
throw new Exception("@todo TO_IS_REQUIRED_FOR_MAIL");
|
||||
}
|
||||
$to = implode(", ", $this->to);
|
||||
$headers = array();
|
||||
foreach ($this->headers as $key => $value) {
|
||||
$key = ucfirst($key);
|
||||
$headers[] = "$key: $value";
|
||||
}
|
||||
|
||||
// The docs say headers should be separated by \r\n, but occasionaly that doesn't work and you
|
||||
// need to use a single \n. This can be set in config/sendmail.php
|
||||
$headers = implode($this->header_separator, $headers);
|
||||
$message = wordwrap($this->message, $this->line_length, "\n");
|
||||
if (!$this->mail($to, $this->subject, $message, $headers)) {
|
||||
Kohana::log("error", wordwrap("Sending mail failed:\nTo: $to\n $this->subject\n" .
|
||||
"Headers: $headers\n $this->message"));
|
||||
throw new Exception("@todo SEND_MAIL_FAILED");
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function mail($to, $subject, $message, $headers) {
|
||||
// This function is completely different from the original
|
||||
// Gallery Sendmail script. Outside of this function,
|
||||
// no other changes were made.
|
||||
|
||||
require(module::get_var("phpmailer", "phpmailer_path"));
|
||||
$mail = new PHPMailer();
|
||||
|
||||
$mail->IsSMTP();
|
||||
$mail->Host = module::get_var("phpmailer", "smtp_server");
|
||||
|
||||
if (module::get_var("phpmailer", "smtp_login") != "") {
|
||||
$mail->SMTPAuth = true;
|
||||
$mail->Username = module::get_var("phpmailer", "smtp_login");
|
||||
$mail->Password = module::get_var("phpmailer", "smtp_password");
|
||||
} else {
|
||||
$mail->SMTPAuth = false;
|
||||
}
|
||||
|
||||
$mail->From = module::get_var("phpmailer", "phpmailer_from_address");
|
||||
$mail->FromName = module::get_var("phpmailer", "phpmailer_from_name");
|
||||
$mail->AddAddress($to);
|
||||
$mail->IsHTML(true);
|
||||
$mail->Subject = $subject;
|
||||
$mail->Body = $message;
|
||||
|
||||
if ($mail->Send()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
3
modules/phpmailer/module.info
Normal file
3
modules/phpmailer/module.info
Normal file
@ -0,0 +1,3 @@
|
||||
name = PHPMailer
|
||||
description = Use PHPMailer when sending email messages.
|
||||
version = 1
|
5
modules/phpmailer/views/admin_phpmailer.html.php
Normal file
5
modules/phpmailer/views/admin_phpmailer.html.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<div id="gPHPMailerAdmin">
|
||||
<h2> <?= t("PHPMailer Settings") ?> </h2>
|
||||
<?= $phpmailer_form ?>
|
||||
</div>
|
Reference in New Issue
Block a user