From a50a4e0a5f410fb5af080b8a1c4ddffa144879cd Mon Sep 17 00:00:00 2001 From: rWatcher Date: Thu, 9 Jul 2009 03:56:06 +0800 Subject: [PATCH 1/4] Initial Commit. Signed-off-by: Bharat Mediratta --- .../controllers/latestupdates.php | 139 ++++++++++++++++++ .../helpers/latestupdates_installer.php | 31 ++++ .../helpers/latestupdates_theme.php | 38 +++++ modules/latestupdates/module.info | 3 + .../views/latestupdates_block.html.php | 10 ++ modules/latestupdates/views/updates.html.php | 33 +++++ 6 files changed, 254 insertions(+) create mode 100644 modules/latestupdates/controllers/latestupdates.php create mode 100644 modules/latestupdates/helpers/latestupdates_installer.php create mode 100644 modules/latestupdates/helpers/latestupdates_theme.php create mode 100644 modules/latestupdates/module.info create mode 100644 modules/latestupdates/views/latestupdates_block.html.php create mode 100644 modules/latestupdates/views/updates.html.php diff --git a/modules/latestupdates/controllers/latestupdates.php b/modules/latestupdates/controllers/latestupdates.php new file mode 100644 index 00000000..7ccd7ef1 --- /dev/null +++ b/modules/latestupdates/controllers/latestupdates.php @@ -0,0 +1,139 @@ +input->get("page", 1); + if ($page < 1) { + url::redirect("latestupdates/albums/{$item->id}"); + } + + // First item to display. + $offset = ($page - 1) * $itemsPerPage; + + // Determine the total number of items, + // for page numbering purposes. + $count = ORM::factory("item", $id) + ->viewable() + ->where("type !=", "album") + ->orderby("created", "DESC") + ->descendants() + ->count(); + + // Figure out what the highest page number is. + $max_pages = ceil($count / $itemsPerPage); + + // Don't let the visitor go past the last page. + if ($max_pages && $page > $max_pages) { + url::redirect("latestupdates/albums/{$item->id}?page=$max_pages"); + } + + // Figure out which items to display on this page. + $children = ORM::factory("item", $id) + ->viewable() + ->where("type !=", "album") + ->orderby("created", "DESC") + ->limit($itemsPerPage) + ->offset($offset) + ->descendants(); + + // Set up the previous and next page buttons. + if ($page > 1) { + $previous_page = $page - 1; + $view->previous_page_link = url::site("latestupdates/albums/{$item->id}?page={$previous_page}"); + } + if ($page < $max_pages) { + $next_page = $page + 1; + $view->next_page_link = url::site("latestupdates/albums/{$item->id}?page={$next_page}"); + } + + // Set up and display the actual page. + $template = new Theme_View("page.html", "updates"); + $template->set_global("page_size", $itemsPerPage); + $template->set_global("children_count", $count); + $template->content = new View("updates.html"); + $template->content->items = $children; + $template->content->q = count($children); + print $template; + } + + public function updates() { + // Figure out how many items to display on each page. + $itemsPerPage = module::get_var("gallery", "page_size", 9); + + // Figure out which page # the visitor is on and + // don't allow the visitor to go below page 1. + $page = $this->input->get("page", 1); + if ($page < 1) { + url::redirect("latestupdates/updates"); + } + + // First item to display. + $offset = ($page - 1) * $itemsPerPage; + + // Determine the total number of items, + // for page numbering purposes. + $count = ORM::factory("item") + ->viewable() + ->where("type !=", "album") + ->find_all() + ->count(); + + // Figure out what the highest page number is. + $max_pages = ceil($count / $itemsPerPage); + + // Don't let the visitor go past the last page. + if ($max_pages && $page > $max_pages) { + url::redirect("latestupdates/updates?page=$max_pages"); + } + + // Figure out which items to display on this page. + $items = ORM::factory("item") + ->viewable() + ->where("type !=", "album") + ->orderby("created", "DESC") + ->find_all($itemsPerPage, $offset); + + // Set up the previous and next page buttons. + if ($page > 1) { + $previous_page = $page - 1; + $view->previous_page_link = url::site("latestupdates/updates?page={$previous_page}"); + } + if ($page < $max_pages) { + $next_page = $page + 1; + $view->next_page_link = url::site("latestupdates/updates?page={$next_page}"); + } + + // Set up and display the actual page. + $template = new Theme_View("page.html", "updates"); + $template->set_global("page_size", $itemsPerPage); + $template->set_global("children_count", $count); + $template->content = new View("updates.html"); + $template->content->items = $items; + $template->content->q = count($items); + print $template; + } + +} \ No newline at end of file diff --git a/modules/latestupdates/helpers/latestupdates_installer.php b/modules/latestupdates/helpers/latestupdates_installer.php new file mode 100644 index 00000000..71284ec7 --- /dev/null +++ b/modules/latestupdates/helpers/latestupdates_installer.php @@ -0,0 +1,31 @@ +item()) { + return; + } + $albumID = $theme->item->is_album() ? $theme->item->id : $theme->item->parent_id; + + $block = new Block(); + $block->css_id = "gUpdates"; + $block->title = t("Updates"); + $block->content = new View("latestupdates_block.html"); + $block->content->updateLinks = array( + t("Entire Gallery") => url::site("latestupdates/updates"), + t("This Album") => url::site("latestupdates/albums/$albumID") + ); + return $block; + } +} diff --git a/modules/latestupdates/module.info b/modules/latestupdates/module.info new file mode 100644 index 00000000..b0a2a68e --- /dev/null +++ b/modules/latestupdates/module.info @@ -0,0 +1,3 @@ +name = LatestUpdates +description = Display recently uploaded photos and videos. +version = 1 diff --git a/modules/latestupdates/views/latestupdates_block.html.php b/modules/latestupdates/views/latestupdates_block.html.php new file mode 100644 index 00000000..5a2077f2 --- /dev/null +++ b/modules/latestupdates/views/latestupdates_block.html.php @@ -0,0 +1,10 @@ + + diff --git a/modules/latestupdates/views/updates.html.php b/modules/latestupdates/views/updates.html.php new file mode 100644 index 00000000..07df61e5 --- /dev/null +++ b/modules/latestupdates/views/updates.html.php @@ -0,0 +1,33 @@ + + + +
+

+ p::clean($q)) ?> + + + pager() ?> + + +

+ + +
From 091cf2869dba4985c550a11efe6bfb1a7c02f4b0 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Thu, 23 Jul 2009 04:49:46 +0800 Subject: [PATCH 2/4] Initial Commit. Signed-off-by: Bharat Mediratta --- .../controllers/admin_contactowner.php | 96 +++++++++++++ .../contactowner/controllers/contactowner.php | 129 ++++++++++++++++++ .../helpers/contactowner_installer.php | 23 ++++ .../helpers/contactowner_menu.php | 28 ++++ .../helpers/contactowner_theme.php | 70 ++++++++++ modules/contactowner/module.info | 3 + .../views/admin_contactowner.html.php | 5 + .../views/contactowner_block.html.php | 15 ++ .../views/contactowner_emailform.html.php | 2 + 9 files changed, 371 insertions(+) create mode 100644 modules/contactowner/controllers/admin_contactowner.php create mode 100644 modules/contactowner/controllers/contactowner.php create mode 100644 modules/contactowner/helpers/contactowner_installer.php create mode 100644 modules/contactowner/helpers/contactowner_menu.php create mode 100644 modules/contactowner/helpers/contactowner_theme.php create mode 100644 modules/contactowner/module.info create mode 100644 modules/contactowner/views/admin_contactowner.html.php create mode 100644 modules/contactowner/views/contactowner_block.html.php create mode 100644 modules/contactowner/views/contactowner_emailform.html.php diff --git a/modules/contactowner/controllers/admin_contactowner.php b/modules/contactowner/controllers/admin_contactowner.php new file mode 100644 index 00000000..f5972c09 --- /dev/null +++ b/modules/contactowner/controllers/admin_contactowner.php @@ -0,0 +1,96 @@ +content = new View("admin_contactowner.html"); + $view->content->contactowner_form = $this->_get_admin_form(); + print $view; + } + + public function saveprefs() { + // Prevent Cross Site Request Forgery + access::verify_csrf(); + + // Figure out which boxes where checked + $linkOptions_array = Input::instance()->post("ContactOwnerLinkTypes"); + $ownerLink = false; + $userLink = false; + for ($i = 0; $i < count($linkOptions_array); $i++) { + if ($linkOptions_array[$i] == "ContactOwner") { + $ownerLink = true; + } + if ($linkOptions_array[$i] == "ContactUser") { + $userLink = true; + } + } + + // Figure out the values of the text boxes + $str_contactbutton = Input::instance()->post("owner_button_text"); + $str_contactemail = Input::instance()->post("owner_email"); + $str_contactname = Input::instance()->post("owner_name"); + + // Save Settings. + module::set_var("contactowner", "contact_owner_link", $ownerLink); + module::set_var("contactowner", "contact_user_link", $userLink); + module::set_var("contactowner", "contact_button_text", $str_contactbutton); + module::set_var("contactowner", "contact_owner_email", $str_contactemail ); + module::set_var("contactowner", "contact_owner_name", $str_contactname ); + message::success(t("Your Settings Have Been Saved.")); + + // Load Admin page. + $view = new Admin_View("admin.html"); + $view->content = new View("admin_contactowner.html"); + $view->content->contactowner_form = $this->_get_admin_form(); + print $view; + } + + private function _get_admin_form() { + // Make a new Form. + $form = new Forge("admin/contactowner/saveprefs", "", "post", + array("id" => "gContactOwnerAdminForm")); + + // Make an array for the different types of link codes. + $add_contactlinks = $form->group("contactOwnerLinks"); + $linkOptions["ContactOwner"] = array("Display Contact Site Owner Link", + module::get_var("contactowner", "contact_owner_link")); + $linkOptions["ContactUser"] = array("Display Contact Item Owner Link", + module::get_var("contactowner", "contact_user_link")); + + // Turn the array into a series of checkboxes. + $add_contactlinks->checklist("ContactOwnerLinkTypes") + ->options($linkOptions); + + // Set up some text boxes for the site owners Name, email and the + // text for the contact link. + $add_contacts = $form->group("contactOwner"); + $add_contacts->input("owner_button_text")->label(t("Contact Owner Link Text"))->value(module::get_var("contactowner", "contact_button_text")); + $add_contacts->input("owner_email")->label(t("Owner Email Address"))->value(module::get_var("contactowner", "contact_owner_email")); + $add_contacts->input("owner_name")->label(t("Owner Name"))->value(module::get_var("contactowner", "contact_owner_name")); + + // Add a save button to the form. + $add_contacts->submit("SaveSettings")->value(t("Save")); + + // Return the newly generated form. + return $form; + } +} \ No newline at end of file diff --git a/modules/contactowner/controllers/contactowner.php b/modules/contactowner/controllers/contactowner.php new file mode 100644 index 00000000..5b082a49 --- /dev/null +++ b/modules/contactowner/controllers/contactowner.php @@ -0,0 +1,129 @@ + "gContactOwnerSendForm")); + $sendmail_fields = $form->group("contactOwner"); + $sendmail_fields->input("email_to")->label(t("To:"))->value(module::get_var("contactowner", "contact_owner_name")); + $sendmail_fields->input("email_from")->label(t("From:"))->value(); + $sendmail_fields->input("email_subject")->label(t("Subject:"))->value(""); + $sendmail_fields->textarea("email_body")->label(t("Message:"))->value(""); + $sendmail_fields->hidden("email_to_id")->value("-1"); + + // Add a save button to the form. + $sendmail_fields->submit("SendMessage")->value(t("Send")); + + // Set up and display the actual page. + $template = new Theme_View("page.html", "Contact"); + $template->content = new View("contactowner_emailform.html"); + $template->content->sendmail_form = $form; + print $template; + } + + public function emailid($user_id) { + // Display a form that a vistor can use to contact a registered user. + + // If this page is disabled, show a 404 error. + if (module::get_var("contactowner", "contact_user_link") != true) { + kohana::show_404(); + } + + // Locate the record for the user specified by $user_id, + // use this to determine the user's name. + $userDetails = ORM::factory("user") + ->where("id", $user_id) + ->find_all(); + + // Make a new form with a couple of text boxes. + $form = new Forge("contactowner/sendemail", "", "post", + array("id" => "gContactOwnerSendForm")); + $sendmail_fields = $form->group("contactOwner"); + $sendmail_fields->input("email_to")->label(t("To:"))->value($userDetails[0]->name); + $sendmail_fields->input("email_from")->label(t("From:"))->value(); + $sendmail_fields->input("email_subject")->label(t("Subject:"))->value(""); + $sendmail_fields->textarea("email_body")->label(t("Message:"))->value(""); + $sendmail_fields->hidden("email_to_id")->value($user_id); + + // Add a save button to the form. + $sendmail_fields->submit("SendMessage")->value(t("Send")); + + // Set up and display the actual page. + $template = new Theme_View("page.html", "Contact"); + $template->content = new View("contactowner_emailform.html"); + $template->content->sendmail_form = $form; + print $template; + } + + public function sendemail() { + // Process the data from the form into an email, + // then send the email. + + // Copy the data from the email from into a couple of variables. + $str_emailsubject = Input::instance()->post("email_subject"); + $str_emailtoid = Input::instance()->post("email_to_id"); + $str_emailfrom = Input::instance()->post("email_from"); + $str_emailbody = Input::instance()->post("email_body"); + + // Add in some
tags to the message body where ever there are line breaks. + $str_emailbody = str_replace("\n", "
\n", $str_emailbody); + + // Gallery's Sendmail library doesn't allow for custom from addresses, + // so add the from email to the beginning of the message body instead. + $str_emailbody = "Message Sent From " . $str_emailfrom . "

\n\n" . $str_emailbody; + + // Figure out where the email is going to. + $str_emailto = ""; + if ($str_emailtoid == -1) { + // If the email id is "-1" send the message to a pre-determined + // owner email address. + $str_emailto = module::get_var("contactowner", "contact_owner_email"); + } else { + // or else grab the email from the user table. + $userDetails = ORM::factory("user") + ->where("id", $str_emailtoid) + ->find_all(); + $str_emailto = $userDetails[0]->email; + } + + // Send the email message. + Sendmail::factory() + ->to($str_emailto) + ->subject($str_emailsubject) + ->header("Mime-Version", "1.0") + ->header("Content-type", "text/html; charset=utf-8") + ->message($str_emailbody) + ->send(); + + // Display a message telling the visitor that their email has been sent. + $template = new Theme_View("page.html", "Contact"); + $template->content = new View("contactowner_emailform.html"); + $template->content->sendmail_form = t("Your Message Has Been Sent."); + print $template; + } +} diff --git a/modules/contactowner/helpers/contactowner_installer.php b/modules/contactowner/helpers/contactowner_installer.php new file mode 100644 index 00000000..4292ea34 --- /dev/null +++ b/modules/contactowner/helpers/contactowner_installer.php @@ -0,0 +1,23 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("contactowner") + ->label(t("ContactOwner Settings")) + ->url(url::site("admin/contactowner"))); + } +} diff --git a/modules/contactowner/helpers/contactowner_theme.php b/modules/contactowner/helpers/contactowner_theme.php new file mode 100644 index 00000000..2286219b --- /dev/null +++ b/modules/contactowner/helpers/contactowner_theme.php @@ -0,0 +1,70 @@ +item()) { + return; + } + + // Locate the record for the user that created the current item. + // Their name will be displayed as part of the contact link. + $userDetails = ORM::factory("user") + ->where("id", $theme->item->owner_id) + ->find_all(); + + // Create a new block to display the links in. + $block = new Block(); + $block->css_id = "gContactOwner"; + $block->title = t("Contact:"); + $block->content = new View("contactowner_block.html"); + + // if $displayBlock is true, this block will be displayed, + // if there aren't any links to put in the block for whatever reason + // then $displayBlock will rename set to false and the + // block will not be displayed. + $displayBlock = false; + + // Figure out if the contact item owner email link should be displayed. + // only display it if the current owner has an email address and + // the option for allowing item owners to be contacted is set to true. + if ((count($userDetails) > 0) && ($userDetails[0]->email != "") && + (module::get_var("contactowner", "contact_user_link") == true)) { + $block->content->userLink = "item->owner_id) . "\">" . t("Contact") . " " . $userDetails[0]->name . ""; + $displayBlock = true; + } + + // Figure out if the contact site owner link should be displayed. + if (module::get_var("contactowner", "contact_owner_link")) { + $block->content->ownerLink = "" . t(module::get_var("contactowner", "contact_button_text")) . ""; + $displayBlock = true; + } + + if ($displayBlock) { + return $block; + } + } +} diff --git a/modules/contactowner/module.info b/modules/contactowner/module.info new file mode 100644 index 00000000..673023c3 --- /dev/null +++ b/modules/contactowner/module.info @@ -0,0 +1,3 @@ +name = ContactOwner +description = Allows visitors to send the website owner an email. +version = 1 diff --git a/modules/contactowner/views/admin_contactowner.html.php b/modules/contactowner/views/admin_contactowner.html.php new file mode 100644 index 00000000..328e5820 --- /dev/null +++ b/modules/contactowner/views/admin_contactowner.html.php @@ -0,0 +1,5 @@ + +
+

+ +
diff --git a/modules/contactowner/views/contactowner_block.html.php b/modules/contactowner/views/contactowner_block.html.php new file mode 100644 index 00000000..c113564b --- /dev/null +++ b/modules/contactowner/views/contactowner_block.html.php @@ -0,0 +1,15 @@ + +
    + +
  • + +
  • + + +
  • + +
  • + + +
+ diff --git a/modules/contactowner/views/contactowner_emailform.html.php b/modules/contactowner/views/contactowner_emailform.html.php new file mode 100644 index 00000000..61873e91 --- /dev/null +++ b/modules/contactowner/views/contactowner_emailform.html.php @@ -0,0 +1,2 @@ + + From 3fd249ba608795023f74958fb90d0b5eb7294585 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Thu, 23 Jul 2009 07:48:13 +0800 Subject: [PATCH 3/4] Initial Commit Signed-off-by: Bharat Mediratta --- .../phpmailer/controllers/admin_phpmailer.php | 93 +++++++++++++ .../phpmailer/helpers/phpmailer_installer.php | 27 ++++ modules/phpmailer/helpers/phpmailer_menu.php | 28 ++++ modules/phpmailer/libraries/Sendmail.php | 126 ++++++++++++++++++ modules/phpmailer/module.info | 3 + .../phpmailer/views/admin_phpmailer.html.php | 5 + 6 files changed, 282 insertions(+) create mode 100644 modules/phpmailer/controllers/admin_phpmailer.php create mode 100644 modules/phpmailer/helpers/phpmailer_installer.php create mode 100644 modules/phpmailer/helpers/phpmailer_menu.php create mode 100644 modules/phpmailer/libraries/Sendmail.php create mode 100644 modules/phpmailer/module.info create mode 100644 modules/phpmailer/views/admin_phpmailer.html.php diff --git a/modules/phpmailer/controllers/admin_phpmailer.php b/modules/phpmailer/controllers/admin_phpmailer.php new file mode 100644 index 00000000..ae68a20a --- /dev/null +++ b/modules/phpmailer/controllers/admin_phpmailer.php @@ -0,0 +1,93 @@ +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; + } +} \ No newline at end of file diff --git a/modules/phpmailer/helpers/phpmailer_installer.php b/modules/phpmailer/helpers/phpmailer_installer.php new file mode 100644 index 00000000..2c264f68 --- /dev/null +++ b/modules/phpmailer/helpers/phpmailer_installer.php @@ -0,0 +1,27 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("phpmailer") + ->label(t("PHPMailer Settings")) + ->url(url::site("admin/phpmailer"))); + } +} diff --git a/modules/phpmailer/libraries/Sendmail.php b/modules/phpmailer/libraries/Sendmail.php new file mode 100644 index 00000000..8332b659 --- /dev/null +++ b/modules/phpmailer/libraries/Sendmail.php @@ -0,0 +1,126 @@ +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; + } + } +} \ No newline at end of file diff --git a/modules/phpmailer/module.info b/modules/phpmailer/module.info new file mode 100644 index 00000000..5c5b5b98 --- /dev/null +++ b/modules/phpmailer/module.info @@ -0,0 +1,3 @@ +name = PHPMailer +description = Use PHPMailer when sending email messages. +version = 1 diff --git a/modules/phpmailer/views/admin_phpmailer.html.php b/modules/phpmailer/views/admin_phpmailer.html.php new file mode 100644 index 00000000..04a0b6f5 --- /dev/null +++ b/modules/phpmailer/views/admin_phpmailer.html.php @@ -0,0 +1,5 @@ + +
+

+ +
From 23b052758009214f59d197d56798dc6f7ce2f582 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Thu, 23 Jul 2009 10:17:57 +0800 Subject: [PATCH 4/4] Use email of current logged in user for from line, also messed around with the line break code. Signed-off-by: Bharat Mediratta --- modules/contactowner/controllers/contactowner.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/contactowner/controllers/contactowner.php b/modules/contactowner/controllers/contactowner.php index 5b082a49..845454a5 100644 --- a/modules/contactowner/controllers/contactowner.php +++ b/modules/contactowner/controllers/contactowner.php @@ -25,13 +25,13 @@ class ContactOwner_Controller extends Controller { if (module::get_var("contactowner", "contact_owner_link") != true) { kohana::show_404(); } - + // Make a new form with a couple of text boxes. $form = new Forge("contactowner/sendemail", "", "post", array("id" => "gContactOwnerSendForm")); $sendmail_fields = $form->group("contactOwner"); $sendmail_fields->input("email_to")->label(t("To:"))->value(module::get_var("contactowner", "contact_owner_name")); - $sendmail_fields->input("email_from")->label(t("From:"))->value(); + $sendmail_fields->input("email_from")->label(t("From:"))->value(user::active()->email); $sendmail_fields->input("email_subject")->label(t("Subject:"))->value(""); $sendmail_fields->textarea("email_body")->label(t("Message:"))->value(""); $sendmail_fields->hidden("email_to_id")->value("-1"); @@ -65,7 +65,7 @@ class ContactOwner_Controller extends Controller { array("id" => "gContactOwnerSendForm")); $sendmail_fields = $form->group("contactOwner"); $sendmail_fields->input("email_to")->label(t("To:"))->value($userDetails[0]->name); - $sendmail_fields->input("email_from")->label(t("From:"))->value(); + $sendmail_fields->input("email_from")->label(t("From:"))->value(user::active()->email); $sendmail_fields->input("email_subject")->label(t("Subject:"))->value(""); $sendmail_fields->textarea("email_body")->label(t("Message:"))->value(""); $sendmail_fields->hidden("email_to_id")->value($user_id); @@ -91,11 +91,11 @@ class ContactOwner_Controller extends Controller { $str_emailbody = Input::instance()->post("email_body"); // Add in some
tags to the message body where ever there are line breaks. - $str_emailbody = str_replace("\n", "
\n", $str_emailbody); + $str_emailbody = str_replace("\n", "\n
", $str_emailbody); // Gallery's Sendmail library doesn't allow for custom from addresses, // so add the from email to the beginning of the message body instead. - $str_emailbody = "Message Sent From " . $str_emailfrom . "

\n\n" . $str_emailbody; + $str_emailbody = "Message Sent From " . $str_emailfrom . "\r\n\r\n

" . $str_emailbody; // Figure out where the email is going to. $str_emailto = "";