mirror of
https://github.com/Pathduck/gallery3.git
synced 2026-05-20 11:29:24 -04:00
communicate. Almost all controllers now use JSON to speak to the theme when we're dealing with form processing. This means tht we only send the form back and forth, but we use a JSON protocol to tell the browser success/error status as well as the location of any newly created resources, or where the browser should redirect the user. Lots of small changes: 1) Admin -> Edit Profile is gone. Instead I fixed the "Modify Profile" link in the top right corner to be a modal dialog 2) We use json_encode everywhere. No more Atom/XML for now. We can bring those back later, though. For now there's a lot of code duplication but that'll be easy to clean up. 3) REST_Controller is no longer abstract. All methods its subclasses should create throw exceptions, which means that subclasses don't have to implement stubs for those methods. 4) New pattern: helper method get_add_form calls take an Item_Model, not an id since we have to load the Item_Model in the controller anyway to check permissions. 5) User/Groups REST resources are separate from User/Group in the site admin. They do different things, we should avoid confusing overlap.
80 lines
2.8 KiB
PHP
80 lines
2.8 KiB
PHP
<?php defined("SYSPATH") or die("No direct script access.");
|
|
/**
|
|
* Gallery - a web based photo album viewer and editor
|
|
* Copyright (C) 2000-2008 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 comments.
|
|
*
|
|
* Note: by design, this class does not do any permission checking.
|
|
*/
|
|
class comment_Core {
|
|
const SECONDS_IN_A_MINUTE = 60;
|
|
const SECONDS_IN_AN_HOUR = 3600;
|
|
const SECONDS_IN_A_DAY = 86400;
|
|
const SECONDS_IN_A_MONTH = 2629744;
|
|
const SECONDS_IN_A_YEAR = 31556926;
|
|
|
|
/**
|
|
* Create a new comment.
|
|
* @param string $author author's name
|
|
* @param string $email author's email
|
|
* @param string $text comment body
|
|
* @param integer $item_id id of parent item
|
|
* @return Comment_Model
|
|
*/
|
|
static function create($author, $email, $text, $item_id) {
|
|
$comment = ORM::factory("comment");
|
|
$comment->author = $author;
|
|
$comment->email = $email;
|
|
$comment->text = $text;
|
|
$comment->item_id = $item_id;
|
|
$comment->created = time();
|
|
|
|
$comment->save();
|
|
module::event("comment_created", $comment);
|
|
|
|
return $comment;
|
|
}
|
|
|
|
static function get_add_form($item) {
|
|
$form = new Forge(url::site("comments"), "", "post");
|
|
$group = $form->group("add_comment")->label(_("Add comment"));
|
|
$group->input("author") ->label(_("Author")) ->id("gAuthor");
|
|
$group->input("email") ->label(_("Email")) ->id("gEmail");
|
|
$group->textarea("text")->label(_("Text")) ->id("gText");
|
|
$group->hidden("item_id")->value($item->id);
|
|
$group->submit(_("Add"));
|
|
$form->add_rules_from(ORM::factory("comment"));
|
|
return $form;
|
|
}
|
|
|
|
static function get_edit_form($comment) {
|
|
$form = new Forge(
|
|
url::site("comments/{$comment->id}?_method=put"), "", "post");
|
|
$group = $form->group("edit_comment")->label(_("Edit comment"));
|
|
$group->input("author") ->label(_("Author")) ->id("gAuthor") ->value($comment->author);
|
|
$group->input("email") ->label(_("Email")) ->id("gEmail") ->value($comment->email);
|
|
$group->textarea("text")->label(_("Text")) ->id("gText") ->value($comment->text);
|
|
$group->submit(_("Edit"));
|
|
$form->add_rules_from($comment);
|
|
return $form;
|
|
}
|
|
}
|
|
|