2008-11-16 07:14:12 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
|
|
|
|
/**
|
|
|
|
|
* Gallery - a web based photo album viewer and editor
|
2009-05-13 20:04:58 +00:00
|
|
|
* Copyright (C) 2000-2009 Bharat Mediratta
|
2008-11-16 07:14:12 +00:00
|
|
|
*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2009-11-25 08:05:21 -08:00
|
|
|
class Comments_Controller extends Controller {
|
2008-11-16 07:14:12 +00:00
|
|
|
/**
|
2008-11-18 08:28:32 +00:00
|
|
|
* Add a new comment to the collection.
|
2008-11-16 07:14:12 +00:00
|
|
|
*/
|
2009-11-25 08:05:21 -08:00
|
|
|
public function create($id) {
|
|
|
|
|
$item = ORM::factory("item", $id);
|
2008-12-25 05:12:46 +00:00
|
|
|
access::required("view", $item);
|
2008-12-25 00:47:40 +00:00
|
|
|
|
2008-12-25 05:12:46 +00:00
|
|
|
$form = comment::get_add_form($item);
|
2009-01-16 04:06:03 +00:00
|
|
|
$valid = $form->validate();
|
|
|
|
|
if ($valid) {
|
2009-10-22 13:09:20 -07:00
|
|
|
if (identity::active_user()->guest && !$form->add_comment->inputs["name"]->value) {
|
2009-01-16 04:06:03 +00:00
|
|
|
$form->add_comment->inputs["name"]->add_error("missing", 1);
|
|
|
|
|
$valid = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$form->add_comment->text->value) {
|
|
|
|
|
$form->add_comment->text->add_error("missing", 1);
|
|
|
|
|
$valid = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($valid) {
|
2009-01-10 00:34:23 +00:00
|
|
|
$comment = comment::create(
|
2009-10-22 13:09:20 -07:00
|
|
|
$item, identity::active_user(),
|
2009-01-10 00:34:23 +00:00
|
|
|
$form->add_comment->text->value,
|
|
|
|
|
$form->add_comment->inputs["name"]->value,
|
|
|
|
|
$form->add_comment->email->value,
|
|
|
|
|
$form->add_comment->url->value);
|
2008-12-06 06:10:15 +00:00
|
|
|
|
2009-10-22 13:09:20 -07:00
|
|
|
$active = identity::active_user();
|
2009-02-02 19:18:43 +00:00
|
|
|
if ($active->guest) {
|
|
|
|
|
$form->add_comment->inputs["name"]->value("");
|
|
|
|
|
$form->add_comment->email->value("");
|
|
|
|
|
$form->add_comment->url->value("");
|
|
|
|
|
} else {
|
|
|
|
|
$form->add_comment->inputs["name"]->value($active->full_name);
|
|
|
|
|
$form->add_comment->email->value($active->email);
|
|
|
|
|
$form->add_comment->url->value($active->url);
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-18 23:25:42 +00:00
|
|
|
$form->add_comment->text->value("");
|
2009-11-17 13:42:51 -08:00
|
|
|
$view = new Theme_View("comment.html", "other", "comment-fragment");
|
2008-12-24 04:05:47 +00:00
|
|
|
$view->comment = $comment;
|
2008-12-06 06:10:15 +00:00
|
|
|
|
2008-12-25 00:47:40 +00:00
|
|
|
print json_encode(
|
|
|
|
|
array("result" => "success",
|
2009-11-25 08:05:21 -08:00
|
|
|
"view" => $view->__toString(),
|
|
|
|
|
"form" => $form->__toString()));
|
2008-12-25 00:47:40 +00:00
|
|
|
} else {
|
|
|
|
|
print json_encode(
|
|
|
|
|
array("result" => "error",
|
2009-11-25 08:05:21 -08:00
|
|
|
"form" => $form->__toString()));
|
2008-11-16 07:14:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-18 08:28:32 +00:00
|
|
|
/**
|
|
|
|
|
* Present a form for adding a new comment to this item or editing an existing comment.
|
|
|
|
|
*/
|
2009-11-25 08:05:21 -08:00
|
|
|
public function form_add($item_id) {
|
2008-12-25 05:12:46 +00:00
|
|
|
$item = ORM::factory("item", $item_id);
|
|
|
|
|
access::required("view", $item);
|
|
|
|
|
|
|
|
|
|
print comment::get_add_form($item);
|
2008-11-18 23:40:47 +00:00
|
|
|
}
|
2008-11-16 07:14:12 +00:00
|
|
|
}
|