Initial Commit.
Signed-off-by: Bharat Mediratta <bharat@menalto.com>
This commit is contained in:
parent
a50a4e0a5f
commit
091cf2869d
96
modules/contactowner/controllers/admin_contactowner.php
Normal file
96
modules/contactowner/controllers/admin_contactowner.php
Normal file
@ -0,0 +1,96 @@
|
||||
<?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_ContactOwner_Controller extends Admin_Controller {
|
||||
public function index() {
|
||||
// Generate a new 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
129
modules/contactowner/controllers/contactowner.php
Normal file
129
modules/contactowner/controllers/contactowner.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?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 ContactOwner_Controller extends Controller {
|
||||
public function emailowner() {
|
||||
// Display a form that a vistor can use to contact the site owner.
|
||||
|
||||
// If this page is disabled, show a 404 error.
|
||||
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_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 <br> tags to the message body where ever there are line breaks.
|
||||
$str_emailbody = str_replace("\n", "<br/>\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 . "<br/><br/>\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;
|
||||
}
|
||||
}
|
23
modules/contactowner/helpers/contactowner_installer.php
Normal file
23
modules/contactowner/helpers/contactowner_installer.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?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 contactowner_installer {
|
||||
static function install() {
|
||||
module::set_version("contactowner", 1);
|
||||
}
|
||||
}
|
28
modules/contactowner/helpers/contactowner_menu.php
Normal file
28
modules/contactowner/helpers/contactowner_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 contactowner_menu_Core {
|
||||
static function admin($menu, $theme) {
|
||||
$menu->get("settings_menu")
|
||||
->append(Menu::factory("link")
|
||||
->id("contactowner")
|
||||
->label(t("ContactOwner Settings"))
|
||||
->url(url::site("admin/contactowner")));
|
||||
}
|
||||
}
|
70
modules/contactowner/helpers/contactowner_theme.php
Normal file
70
modules/contactowner/helpers/contactowner_theme.php
Normal file
@ -0,0 +1,70 @@
|
||||
<?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 contactowner_theme_Core {
|
||||
|
||||
static function sidebar_blocks($theme) {
|
||||
// Display links in the Gallery sidebar to allow a
|
||||
// visitor to send an email.
|
||||
|
||||
// Make sure the current page belongs to an item.
|
||||
if (!$theme->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 = "<a href=\"" . url::site("contactowner/emailid/" .
|
||||
$theme->item->owner_id) . "\">" . t("Contact") . " " . $userDetails[0]->name . "</a>";
|
||||
$displayBlock = true;
|
||||
}
|
||||
|
||||
// Figure out if the contact site owner link should be displayed.
|
||||
if (module::get_var("contactowner", "contact_owner_link")) {
|
||||
$block->content->ownerLink = "<a href=\"" . url::site("contactowner/emailowner") .
|
||||
"\">" . t(module::get_var("contactowner", "contact_button_text")) . "</a>";
|
||||
$displayBlock = true;
|
||||
}
|
||||
|
||||
if ($displayBlock) {
|
||||
return $block;
|
||||
}
|
||||
}
|
||||
}
|
3
modules/contactowner/module.info
Normal file
3
modules/contactowner/module.info
Normal file
@ -0,0 +1,3 @@
|
||||
name = ContactOwner
|
||||
description = Allows visitors to send the website owner an email.
|
||||
version = 1
|
5
modules/contactowner/views/admin_contactowner.html.php
Normal file
5
modules/contactowner/views/admin_contactowner.html.php
Normal file
@ -0,0 +1,5 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<div id="gContactOwnerAdmin">
|
||||
<h2> <?= t("Contact Owner Settings") ?> </h2>
|
||||
<?= $contactowner_form ?>
|
||||
</div>
|
15
modules/contactowner/views/contactowner_block.html.php
Normal file
15
modules/contactowner/views/contactowner_block.html.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<ul id="gContactOwner">
|
||||
<? if ($ownerLink != "") { ?>
|
||||
<li style="clear: both;">
|
||||
<? print ($ownerLink); ?>
|
||||
</li>
|
||||
<? } ?>
|
||||
<? if ($userLink != "") { ?>
|
||||
<li style="clear: both;">
|
||||
<? print ($userLink); ?>
|
||||
</li>
|
||||
<? } ?>
|
||||
|
||||
</ul>
|
||||
|
@ -0,0 +1,2 @@
|
||||
<?php defined("SYSPATH") or die("No direct script access.") ?>
|
||||
<?= $sendmail_form ?>
|
Reference in New Issue
Block a user