2008-11-05 07:42:52 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
|
|
|
|
/**
|
|
|
|
|
* Gallery - a web based photo album viewer and editor
|
2011-01-21 23:01:06 -08:00
|
|
|
* Copyright (C) 2000-2011 Bharat Mediratta
|
2008-11-05 07:42:52 +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.
|
|
|
|
|
*/
|
2008-11-19 00:12:25 +00:00
|
|
|
class Photos_Controller extends Items_Controller {
|
2009-11-30 11:10:58 -08:00
|
|
|
public function show($photo) {
|
|
|
|
|
if (!is_object($photo)) {
|
|
|
|
|
// show() must be public because we route to it in url::parse_url(), so make
|
|
|
|
|
// sure that we're actually receiving an object
|
2010-02-12 19:05:44 -08:00
|
|
|
throw new Kohana_404_Exception();
|
2009-11-30 11:10:58 -08:00
|
|
|
}
|
2010-07-06 14:12:00 -07:00
|
|
|
|
2010-02-11 14:28:32 -08:00
|
|
|
access::required("view", $photo);
|
2010-07-06 14:12:00 -07:00
|
|
|
|
2009-11-26 18:47:40 -08:00
|
|
|
$where = array(array("type", "!=", "album"));
|
2011-01-09 00:22:46 +01:00
|
|
|
$position = item::get_position($photo, $where);
|
2009-06-04 22:11:08 -07:00
|
|
|
if ($position > 1) {
|
|
|
|
|
list ($previous_item, $ignore, $next_item) =
|
2011-01-09 00:22:46 +01:00
|
|
|
$photo->parent()->viewable()->children(3, $position - 2, $where);
|
2009-06-04 22:11:08 -07:00
|
|
|
} else {
|
|
|
|
|
$previous_item = null;
|
2009-11-04 09:50:49 -08:00
|
|
|
list ($next_item) = $photo->parent()->viewable()->children(1, $position, $where);
|
2009-06-04 22:11:08 -07:00
|
|
|
}
|
2008-12-31 07:06:10 +00:00
|
|
|
|
2009-11-17 13:42:51 -08:00
|
|
|
$template = new Theme_View("page.html", "item", "photo");
|
2011-01-03 11:41:25 -08:00
|
|
|
$template->set_global(
|
|
|
|
|
array("item" => $photo,
|
|
|
|
|
"children" => array(),
|
|
|
|
|
"children_count" => 0,
|
|
|
|
|
"parents" => $photo->parents()->as_array(),
|
|
|
|
|
"next_item" => $next_item,
|
|
|
|
|
"previous_item" => $previous_item,
|
|
|
|
|
"sibling_count" => $photo->parent()->viewable()->children_count($where),
|
|
|
|
|
"position" => $position));
|
2008-11-27 16:19:07 +00:00
|
|
|
|
2008-11-09 19:20:23 +00:00
|
|
|
$template->content = new View("photo.html");
|
2008-12-20 20:04:57 +00:00
|
|
|
|
2011-01-03 13:21:54 +01:00
|
|
|
$photo->increment_view_count();
|
2008-12-20 20:11:51 +00:00
|
|
|
|
|
|
|
|
print $template;
|
2008-11-05 07:42:52 +00:00
|
|
|
}
|
2008-12-06 21:14:36 +00:00
|
|
|
|
2009-11-25 12:41:01 -08:00
|
|
|
public function update($photo_id) {
|
2009-06-01 22:40:22 -07:00
|
|
|
access::verify_csrf();
|
2009-11-25 12:41:01 -08:00
|
|
|
$photo = ORM::factory("item", $photo_id);
|
2009-06-01 22:40:22 -07:00
|
|
|
access::required("view", $photo);
|
2008-12-24 00:20:26 +00:00
|
|
|
access::required("edit", $photo);
|
|
|
|
|
|
2009-07-28 20:40:28 +08:00
|
|
|
$form = photo::get_edit_form($photo);
|
2010-01-16 11:12:27 -08:00
|
|
|
try {
|
|
|
|
|
$valid = $form->validate();
|
|
|
|
|
$photo->title = $form->edit_item->title->value;
|
|
|
|
|
$photo->description = $form->edit_item->description->value;
|
|
|
|
|
$photo->slug = $form->edit_item->slug->value;
|
2010-01-19 19:31:01 -08:00
|
|
|
$photo->name = $form->edit_item->inputs["name"]->value;
|
2010-01-16 11:12:27 -08:00
|
|
|
$photo->validate();
|
|
|
|
|
} catch (ORM_Validation_Exception $e) {
|
|
|
|
|
// Translate ORM validation errors into form error messages
|
|
|
|
|
foreach ($e->validation->errors() as $key => $error) {
|
|
|
|
|
$form->edit_item->inputs[$key]->add_error($error, 1);
|
2009-05-16 04:32:00 +00:00
|
|
|
}
|
2010-01-16 11:12:27 -08:00
|
|
|
$valid = false;
|
2009-05-16 04:32:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($valid) {
|
2008-12-24 00:20:26 +00:00
|
|
|
$photo->save();
|
2009-07-20 08:51:12 -07:00
|
|
|
module::event("item_edit_form_completed", $photo, $form);
|
2009-07-19 17:02:20 +08:00
|
|
|
|
2009-09-08 13:44:52 -07:00
|
|
|
log::success("content", "Updated photo", "<a href=\"{$photo->url()}\">view</a>");
|
2009-07-01 17:57:39 -07:00
|
|
|
message::success(
|
2009-12-31 17:21:19 -08:00
|
|
|
t("Saved photo %photo_title", array("photo_title" => html::purify($photo->title))));
|
2008-12-24 00:20:26 +00:00
|
|
|
|
2009-12-31 17:21:19 -08:00
|
|
|
if ($form->from_id->value == $photo->id) {
|
|
|
|
|
// Use the new url; it might have changed.
|
2010-07-21 21:30:13 -07:00
|
|
|
json::reply(array("result" => "success", "location" => $photo->url()));
|
2009-12-31 17:21:19 -08:00
|
|
|
} else {
|
|
|
|
|
// Stay on the same page
|
2010-07-21 21:30:13 -07:00
|
|
|
json::reply(array("result" => "success"));
|
2009-12-31 17:21:19 -08:00
|
|
|
}
|
2008-12-24 00:20:26 +00:00
|
|
|
} else {
|
2010-07-31 21:16:17 -07:00
|
|
|
json::reply(array("result" => "error", "html" => (string)$form));
|
2008-12-24 00:20:26 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-11-25 12:41:01 -08:00
|
|
|
public function form_edit($photo_id) {
|
|
|
|
|
$photo = ORM::factory("item", $photo_id);
|
2009-06-01 22:40:22 -07:00
|
|
|
access::required("view", $photo);
|
2008-12-24 00:20:26 +00:00
|
|
|
access::required("edit", $photo);
|
2009-06-01 22:40:22 -07:00
|
|
|
|
2010-07-31 21:16:17 -07:00
|
|
|
print photo::get_edit_form($photo);
|
2008-12-06 21:14:36 +00:00
|
|
|
}
|
2008-11-05 07:42:52 +00:00
|
|
|
}
|