Skip to content

Commit

Permalink
Initial version of eCard from dmolavi, with carriage returns removed.
Browse files Browse the repository at this point in the history
  • Loading branch information
bharat committed Aug 4, 2010
1 parent 1c1e9ad commit 6e38f07
Show file tree
Hide file tree
Showing 11 changed files with 524 additions and 0 deletions.
65 changes: 65 additions & 0 deletions modules/ecard/controllers/admin_ecards.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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_ecards_Controller extends Admin_Controller {
public function index() {
$view = new Admin_View("admin.html");
$view->page_title = t("eCard settings");
$view->content = new View("admin_ecards.html");
$view->content->form = $this->_get_admin_form();
print $view;
}

public function save() {
access::verify_csrf();
$form = $this->_get_admin_form();
$form->validate();
module::set_var(
"ecard", "sender", $form->ecard->sender->value);
module::set_var(
"ecard", "subject", $form->ecard->subject->value);
module::set_var(
"ecard", "message", $form->ecard->message->value);
module::set_var(
"ecard", "access_permissions",
$form->ecard->access_permissions->value);
message::success(t("eCard settings updated"));
url::redirect("admin/ecards");
}

private function _get_admin_form() {
$form = new Forge("admin/ecards/save", "", "post",
array("id" => "g-ecards-admin-form"));
$ecard_settings = $form->group("ecard")->label(t("eCard settings"));
$ecard_settings->input("sender")->label(t('E-mail Sender (leave blank for a user-defined address)'))
->value(module::get_var("ecard", "sender", ""));
$ecard_settings->input("subject")->label(t('E-mail Subject'))
->value(module::get_var("ecard", "subject", "You have been sent an eCard"));
$ecard_settings->textarea("message")->label(t('E-mail Message'))
->value(module::get_var("ecard", "message", "Hello %toname%, \r\n%fromname% has sent you an eCard. Click the image to be taken to the gallery."));
$ecard_settings->dropdown("access_permissions")
->label(t("Who can send eCards?"))
->options(array("everybody" => t("Everybody"),
"registered_users" => t("Only registered users")))
->selected(module::get_var("ecard", "access_permissions"));
$ecard_settings->submit("save")->value(t("Save"));
return $form;
}
}

77 changes: 77 additions & 0 deletions modules/ecard/controllers/ecards.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 ecards_Controller extends Controller {
/**
* Add a new ecard to the collection.
*/
public function create($id) {
$item = ORM::factory("item", $id);
access::required("view", $item);
if (!ecard::can_ecard()) {
access::forbidden();
}

$form = ecard::get_add_form($item);
try {
$valid = $form->validate();
$form->item_id = $id;
$form->author_id = identity::active_user()->id;
$form->text = $form->add_ecard->text->value;
$form->to_name = $form->add_ecard->inputs["to_name"]->value;
$form->to_email = $form->add_ecard->to_email->value;
$form->validate();
} catch (ORM_Validation_Exception $e) {
// Translate ORM validation errors into form error messages
foreach ($e->validation->errors() as $key => $error) {
switch ($key) {
case "to_name": $key = "name"; break;
case "to_email": $key = "email"; break;
}
$form->add_ecard->inputs[$key]->add_error($error, 1);
}
$valid = false;
}

if ($valid) {
ecard::save();

print json_encode(
array("result" => "success",
"view" => (string) $view,
"form" => (string) ecard::get_add_form($item)));
} else {
$form = ecard::prefill_add_form($form);
print json_encode(array("result" => "error", "form" => (string) $form));
}
}

/**
* Present a form for adding a new ecard to this item or editing an existing ecard.
*/
public function form_add($item_id) {
$item = ORM::factory("item", $item_id);
access::required("view", $item);
if (!ecard::can_ecard()) {
access::forbidden();
}

print ecard::prefill_add_form(ecard::get_add_form($item));
}
}
45 changes: 45 additions & 0 deletions modules/ecard/css/ecard.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#g-content #g-ecard-form {
margin-top: 2em;
}

#g-content #g-ecards {
margin-top: 2em;
position: relative;
}

#g-content #g-ecards ul li {
margin: 1em 0;
}

#g-content #g-ecards .g-author {
border-bottom: 1px solid #ccc;
color: #999;
height: 32px;
line-height: 32px;
}

#g-content #g-ecards ul li div {
padding: 0 8px 8px 43px;
}

#g-content #g-ecards .g-avatar {
height: 32px;
margin-right: .4em;
width: 32px;
}

#g-add-ecard {
position: absolute;
right: 0;
top: 2px;
}

#g-admin-ecards-menu {
margin: 1em 0;
}

#g-admin-ecards-menu a {
margin: 0;
padding: .2em .6em;
}

74 changes: 74 additions & 0 deletions modules/ecard/helpers/ecard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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.
*/

/**
* This is the API for handling ecards.
*
* Note: by design, this class does not do any permission checking.
*/
class ecard_Core {
static function get_add_form($item) {
$form = new Forge("ecards/create/{$item->id}", "", "post", array("id" => "g-ecard-form"));
$group = $form->group("add_ecard")->label(t("Send eCard"));
$group->input("from_name")
->label(t("Your Name"))
->id("g-author")
->error_messages("required", t("You must enter a name for yourself"));
$group->input("from_email")
->label(t("Your e-mail"))
->id("g-email")
->error_messages("required", t("You must enter a valid email address"))
->error_messages("invalid", t("You must enter a valid email address"));
$group->input("to_name")
->label(t("Recipient's Name"))
->id("g-recipient")
->error_messages("required", t("You must enter a recipient's name"));
$group->input("to_email")
->label(t("Recipient's e-mail"))
->id("g-recip-email")
->error_messages("required", t("You must enter a valid email address"))
->error_messages("invalid", t("You must enter a valid email address"));
$group->textarea("text")
->label(t("Message"))
->id("g-text")
->error_messages("required", t("You must enter a message"));
$group->hidden("item_id")->value($item->id);
module::event("ecard_add_form", $form);
$group->submit("")->value(t("Send"))->class("ui-state-default ui-corner-all");

return $form;
}

static function prefill_add_form($form) {
$active = identity::active_user();
if (!$active->guest) {
$group = $form->add_ecard;
$group->inputs["from_name"]->value($active->full_name)->disabled("disabled");
$group->from_email->value($active->email)->disabled("disabled");
}
return $form;
}

static function can_ecard() {
return !identity::active_user()->guest ||
module::get_var("ecard", "access_permissions") == "everybody";
}
}

28 changes: 28 additions & 0 deletions modules/ecard/helpers/ecard_event.php
Original file line number Diff line number Diff line change
@@ -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-2010 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 ecard_event_Core {
static function admin_menu($menu, $theme) {
$menu->get("settings_menu")
->append(Menu::factory("link")
->id("ecard")
->label(t("eCard Settings"))
->url(url::site("admin/ecards")));
}
}
43 changes: 43 additions & 0 deletions modules/ecard/helpers/ecard_theme.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php defined("SYSPATH") or die("No direct script access.");
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2010 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 ecard_theme_Core {
static function head($theme) {
$theme->css("ecard.css");
$theme->script("ecard.js");
return "";
}

static function admin_head($theme) {
$theme->css("ecard.css");
return "";
}

static function photo_bottom($theme) {
$block = new Block;
$block->css_id = "g-ecards";
$block->title = t("ecards");
$block->anchor = "ecards";

$view = new View("ecards.html");

$block->content = $view;
return $block;
}
}
45 changes: 45 additions & 0 deletions modules/ecard/js/ecard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
$("document").ready(function() {
$("#g-add-ecard").click(function(event) {
event.preventDefault();
if (!$("#g-ecard-form").length) {
$.get($(this).attr("href"),
{},
function(data) {
$("#g-ecard-detail").append(data);
ajaxify_ecard_form();
$.scrollTo("#g-ecard-form-anchor", 800);
});
}
});
$(".g-no-ecards a").click(function(event) {
event.preventDefault();
if (!$("#g-ecard-form").length) {
$.get($(this).attr("href"),
{},
function(data) {
$("#g-ecard-detail").append(data);
ajaxify_ecard_form();
});
$(".g-no-ecards").remove();
}
});
});

function ajaxify_ecard_form() {
$("#g-ecards form").ajaxForm({
dataType: "json",
success: function(data) {
if (data.result == "success") {
$("#g-ecards #g-ecard-detail ul").append(data.view);
$("#g-ecards #g-ecard-detail ul li:last").effect("highlight", {color: "#cfc"}, 8000);
$("#g-ecard-form").hide(2000).remove();
$("#g-no-ecards").hide(2000);
} else {
if (data.form) {
$("#g-ecards form").replaceWith(data.form);
ajaxify_ecard_form();
}
}
}
});
}
Loading

0 comments on commit 6e38f07

Please sign in to comment.