2009-12-12 17:39:18 +00:00
|
|
|
<?php defined('SYSPATH') OR die('No direct access allowed.');
|
|
|
|
/**
|
|
|
|
* Gallery - a web based photo album viewer and editor
|
2010-03-03 18:16:08 +00:00
|
|
|
* Copyright (C) 2000-2010 Bharat Mediratta
|
2009-12-12 17:39:18 +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.
|
|
|
|
*/
|
|
|
|
class G3_Client_Controller extends Template_Controller {
|
|
|
|
// Set the name of the template to use
|
|
|
|
public $template = 'g3_template.html';
|
|
|
|
|
|
|
|
public function index() {
|
|
|
|
$this->template->title = 'G3 Web Client';
|
|
|
|
|
|
|
|
if (Session::instance()->get("g3_client_access_token")) {
|
2009-12-21 19:30:38 +00:00
|
|
|
$response = G3Remote::instance()->get_resource("gallery");
|
|
|
|
$this->template->content = $this->_get_main_view($response->resource);
|
2009-12-12 17:39:18 +00:00
|
|
|
} else {
|
|
|
|
$this->template->content = new View('login.html');
|
|
|
|
$this->template->content->errors = $this->template->content->form =
|
|
|
|
array("user" => "", "password" => "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function login() {
|
|
|
|
$form = $errors = array("user" => "", "password" => "");
|
|
|
|
$post = new Validation($_POST);
|
|
|
|
$post->add_rules("user", "required");
|
|
|
|
$post->add_rules("password", "required");
|
2009-12-29 20:18:16 +00:00
|
|
|
if ($valid = $post->validate()) {
|
2009-12-12 17:39:18 +00:00
|
|
|
try {
|
|
|
|
$token = G3Remote::instance()->get_access_token($post["user"], $post["password"]);
|
|
|
|
Session::instance()->set("g3_client_access_token", $token);
|
2009-12-22 20:31:15 +00:00
|
|
|
$response = G3Remote::instance()->get_resource("gallery");
|
2009-12-16 04:41:10 +00:00
|
|
|
$valid = true;
|
2009-12-22 20:31:15 +00:00
|
|
|
$content = $this->_get_main_view($response->resource);
|
2009-12-12 17:39:18 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
Kohana_Log::add("error", Kohana_Exception::text($e));
|
|
|
|
$valid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$valid) {
|
|
|
|
$content = new View('login.html');
|
|
|
|
$content->form = arr::overwrite($form, $post->as_array());
|
|
|
|
$content->errors = arr::overwrite($errors, $post->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->auto_render = false;
|
2009-12-16 04:41:10 +00:00
|
|
|
print json_encode(array("status" => $valid ? "ok" : "error", "content" => (string)$content));
|
2009-12-12 17:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function albums() {
|
|
|
|
$path = $this->input->get("path");
|
2009-12-24 19:38:05 +00:00
|
|
|
$response = G3Remote::instance()->get_resource("gallery/$path", array("filter" => "album"));
|
2009-12-12 17:39:18 +00:00
|
|
|
$this->auto_render = false;
|
2009-12-21 19:30:38 +00:00
|
|
|
print $this->_get_album_tree($response->resource);
|
2009-12-12 17:39:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function detail() {
|
|
|
|
$path = $this->input->get("path");
|
2009-12-21 19:30:38 +00:00
|
|
|
$response = G3Remote::instance()->get_resource("gallery/$path");
|
2009-12-12 17:39:18 +00:00
|
|
|
$this->auto_render = false;
|
2009-12-21 19:30:38 +00:00
|
|
|
print $this->_get_detail($response->resource);
|
2009-12-18 20:24:10 +00:00
|
|
|
}
|
|
|
|
|
2009-12-29 21:40:33 +00:00
|
|
|
public function tagged_album($tags) {
|
2009-12-29 20:18:16 +00:00
|
|
|
$response = G3Remote::instance()->get_resource("tag/$tags");
|
|
|
|
$this->auto_render = false;
|
2009-12-29 21:40:33 +00:00
|
|
|
$v = new View("tag_detail.html");
|
|
|
|
$v->resources = $response->resources;
|
|
|
|
print $v;
|
2009-12-29 20:18:16 +00:00
|
|
|
}
|
|
|
|
|
2009-12-23 02:53:24 +00:00
|
|
|
public function block($type) {
|
|
|
|
switch ($type) {
|
|
|
|
case "random":
|
|
|
|
print $this->_get_image_block();
|
|
|
|
break;
|
2009-12-29 20:18:16 +00:00
|
|
|
case "tags":
|
|
|
|
print "";
|
|
|
|
break;
|
2009-12-23 02:53:24 +00:00
|
|
|
default:
|
|
|
|
print "";
|
|
|
|
}
|
|
|
|
$this->auto_render = false;
|
|
|
|
}
|
|
|
|
|
2009-12-12 17:39:18 +00:00
|
|
|
private function _get_album_tree($resource) {
|
|
|
|
$v = new View("tree_part.html");
|
|
|
|
$v->element = (object)array("title" => $resource->title, "path" => $resource->path);
|
|
|
|
$v->element->children = array();
|
|
|
|
foreach ($resource->children as $child) {
|
|
|
|
if ($child->type != "album") {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$v->element->children[] = $child;
|
|
|
|
}
|
|
|
|
return $v;
|
|
|
|
}
|
|
|
|
|
2009-12-16 04:41:10 +00:00
|
|
|
private function _get_main_view($resource) {
|
|
|
|
$v = new View("main.html");
|
|
|
|
$v->album_tree = $this->_get_album_tree($resource);
|
|
|
|
$v->detail = $this->_get_detail($resource);
|
2009-12-23 02:53:24 +00:00
|
|
|
$v->image_block = $this->_get_image_block();
|
2009-12-29 20:18:16 +00:00
|
|
|
$v->tag_block = $this->_get_tag_block();
|
2009-12-16 04:41:10 +00:00
|
|
|
return $v;
|
|
|
|
}
|
|
|
|
|
2009-12-12 17:39:18 +00:00
|
|
|
private function _get_detail($resource) {
|
|
|
|
$v = new View("{$resource->type}_detail.html");
|
|
|
|
$v->resource = $resource;
|
2009-12-21 19:30:38 +00:00
|
|
|
$v->parent_path = substr($resource->path, 0, -strlen($resource->slug));
|
2009-12-17 19:25:46 +00:00
|
|
|
if (strrpos($v->parent_path, "/") == strlen($v->parent_path) - 1) {
|
|
|
|
$v->parent_path = substr($v->parent_path, 0, -1);
|
|
|
|
}
|
2009-12-12 17:39:18 +00:00
|
|
|
return $v;
|
|
|
|
}
|
2009-12-23 02:53:24 +00:00
|
|
|
|
|
|
|
private function _get_image_block() {
|
2009-12-24 19:38:05 +00:00
|
|
|
$response = G3Remote::instance()->get_resource("image_block", array("type" => "random"));
|
2009-12-23 02:53:24 +00:00
|
|
|
if ($response->status == "OK") {
|
|
|
|
$v = new View("image_block.html");
|
|
|
|
$v->path = $response->resource->path;
|
|
|
|
$v->src = $response->resource->thumb_url;
|
|
|
|
$v->title = $response->resource->title;
|
|
|
|
} else {
|
|
|
|
$v = "";
|
|
|
|
}
|
|
|
|
return $v;
|
|
|
|
}
|
2009-12-29 20:18:16 +00:00
|
|
|
|
|
|
|
private function _get_tag_block() {
|
|
|
|
$response = G3Remote::instance()->get_resource("tag", array("limit" => "15"));
|
|
|
|
if ($response->status == "OK") {
|
|
|
|
$v = new View("tag_block.html");
|
|
|
|
$v->tags = $response->tags;
|
|
|
|
$v->max_count = $response->tags[0]->count;;
|
|
|
|
} else {
|
|
|
|
$v = "";
|
|
|
|
}
|
|
|
|
return $v;
|
|
|
|
}
|
2009-12-12 17:39:18 +00:00
|
|
|
} // End G3 Client Controller
|