From 6f93d148f553f6f76c81d09ad333170f312b0fa6 Mon Sep 17 00:00:00 2001 From: rWatcher Date: Wed, 22 Jul 2009 16:49:46 -0400 Subject: [PATCH] Initial Commit. --- .../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 @@ + +