1
0

Delete now works. Added a hook to always extract the access token from the

session and initialize the gallery3 remote library.
This commit is contained in:
Tim Almdal 2009-12-18 15:03:22 -08:00
parent 7638aa9813
commit b16d60916f
10 changed files with 87 additions and 41 deletions

View File

@ -72,7 +72,7 @@ $config['global_xss_filtering'] = FALSE;
/**
* Enable or disable hooks.
*/
$config['enable_hooks'] = FALSE;
$config['enable_hooks'] = true;
/**
* Enable or disable displaying of Kohana error pages. This will not affect
* logging. Turning this off will disable ALL error pages.

View File

@ -124,6 +124,13 @@ class G3_Client_Controller extends Template_Controller {
case "delete_album":
case "delete_photo":
if ($_POST) {
try {
$result = G3Remote::instance()->delete_resource("gallery/$path");
print json_encode(array("result" => $result, "path" => $resource->parent_path));
} catch (Exception $e) {
print json_encode(array("result" => "fail", "message" => $e->getMessage()));
}
return;
} else {
$v = new View("delete.html");
$v->title = $resource->title;

View File

@ -0,0 +1,22 @@
<?php defined('SYSPATH') OR die('No direct access allowed.');
/**
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2009 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.
*/
$access_token = Session::instance()->get("g3_client_access_token");
G3Remote::instance($access_token);

View File

@ -25,20 +25,14 @@ class url_connection {
$extra_headers['Content-Length'] = strlen($_data_raw);
/* Read the web page into a buffer */
list ($response_status, $response_headers, $response_body) =
self::do_request($url, 'POST', $extra_headers, $post_data_raw);
return array($response_body, $response_status, $response_headers);
return self::do_request($url, 'POST', $extra_headers, $_data_raw);
}
static function get($url, $_data_array=array(), $extra_headers=array()) {
$_data_raw = self::_encode_data($_data_array, $extra_headers);
/* Read the web page into a buffer */
list ($response_status, $response_headers, $response_body) =
self::do_request("{$url}?$_data_raw", "GET", $extra_headers);
return array($response_body, $response_status, $response_headers);
return self::do_request("{$url}?$_data_raw", "GET", $extra_headers);
}
static function success($response_status) {
@ -79,7 +73,6 @@ class url_connection {
$handle = fsockopen(
$url_components['fsockhost'], $url_components['port'], $errno, $errstr, 5);
if (empty($handle)) {
// log "Error $errno: '$errstr' requesting $url";
return array(null, null, null);
}
@ -181,7 +174,6 @@ class G3Remote {
private $_resources;
private $_access_token;
private $_identity;
public static function instance($access_token=null) {
if (!isset(G3Remote::$_instance)) {
@ -204,22 +196,19 @@ class G3Remote {
}
public function get_access_token($user, $password) {
$identity = md5("$user/$password");
if (empty($this->_identity) || $this->_identity != $identity) {
$request = "{$this->_config["gallery3_site"]}/access_key";
list ($response_body, $response_status, $response_headers) =
url_connection::get($request, array("user" => $user, "password" => $password));
if (url_connection::success($response_status)) {
$response = json_decode($response_body);
if ($response->status == "OK") {
$this->_access_token = $response->token;
$this->_identity = $identity;
} else {
throw new Exception("Remote host failure: {$response->message}");
}
$request = "{$this->_config["gallery3_site"]}/access_key";
list ($response_status, $response_headers, $response_body) =
url_connection::get($request, array("user" => $user, "password" => $password));
if (url_connection::success($response_status)) {
$response = json_decode($response_body);
if ($response->status == "OK") {
$this->_access_token = $response->token;
$this->_identity = $identity;
} else {
throw new Exception("Remote host failure: $response_status");
throw new Exception("Remote host failure: {$response->message}");
}
} else {
throw new Exception("Remote host failure: $response_status");
}
return $this->_access_token;
}
@ -237,8 +226,12 @@ class G3Remote {
$param["limit"] = $limit;
}
list ($response_body, $response_status, $response_headers) =
url_connection::get($request, $params);
$headers = array();
if (!empty($this->_access_token)) {
$headers["X_GALLERY_REQUEST_KEY"] = $this->_access_token;
}
list ($response_status, $response_headers, $response_body) =
url_connection::get($request, $params, $headers);
if (url_connection::success($response_status)) {
$response = json_decode($response_body);
if ($response->status != "OK") {
@ -249,4 +242,25 @@ class G3Remote {
}
return $response->resource;
}
public function delete_resource($path) {
$request = "{$this->_config["gallery3_site"]}/$path";
$headers["X_GALLERY_REQUEST_METHOD"] = "DELETE";
Kohana_Log::add("error", "access_token: " . $this->_access_token);
if (!empty($this->_access_token)) {
$headers["X_GALLERY_REQUEST_KEY"] = $this->_access_token;
}
list ($response_status, $response_headers, $response_body) =
url_connection::post($request, array(), $headers);
if (url_connection::success($response_status)) {
$response = json_decode($response_body);
if ($response->status != "OK") {
throw new Exception("Remote host failure: {$response->message}");
}
} else {
throw new Exception("Remote host failure: $response_status");
}
return "success";
}
}

View File

@ -1,6 +1,6 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div id="wc-edit">
<?= form::open("<?= $path ?>") ?>
<?= form::open($path) ?>
<fieldset>
<legend style="display: none">Add Resource</legend>
<ul>

View File

@ -8,7 +8,7 @@
});
</script>
<div id="wc-edit">
<?= form::open("<?= $path ?>") ?>
<?= form::open($path) ?>
<fieldset>
<legend style="display: none">Confirm Delete</legend>
<ul>

View File

@ -1,6 +1,6 @@
<?php defined("SYSPATH") or die("No direct script access.") ?>
<div id="wc-edit">
<?= form::open("<?= $path ?>") ?>
<?= form::open($path) ?>
<fieldset>
<legend style="display: none">Update Resource</legend>
<ul>

View File

@ -16,7 +16,7 @@
<div class="wc-buttonset ui-helper-clearfix">
<a href="#" ref="edit" class="wc-button ui-state-default wc-button-icon-solo ui-corner-all" title="Edit"><span class="ui-icon ui-icon-pencil"></span>Edit</a>
<a href="#" ref="delete" class="wc-button ui-state-default ui-state-disabled wc-button-icon-solo ui-corner-all" title="Delete"><span class="ui-icon ui-icon-trash"></span>Delete</a>
<a href="#" ref="delete" class="wc-button ui-state-default wc-button-icon-solo ui-corner-all" title="Delete"><span class="ui-icon ui-icon-trash"></span>Delete</a>
</div>
<div class="wc-buttonset wc-buttonset-single ui-helper-clearfix">

View File

@ -40,9 +40,9 @@ form li {
text-align: left;
}
form li input[type=text],
form li input[type=file],
form li textarea {
#g-dialog form li input[type=text],
#g-dialog form li input[type=file],
#g-dialog form li textarea {
width: 100%;
}

View File

@ -179,9 +179,6 @@
}
function _open_dialog(dialog, resource_path) {
console.group("_open_dialog(" + dialog + ")");
console.log(resource_path);
console.groupEnd();
$("body").append('<div id="g-dialog"></div>');
$("#g-dialog").dialog({
model: true,
@ -220,6 +217,11 @@
}
}
if (data.result == "success") {
$("#g-dialog").dialog('close');
get_detail(data.path, _set_active_album);
} else if (data.result == "fail") {
$("#g-dialog").dialog('close');
alert(data.message);
}
}
});
@ -250,18 +252,17 @@
function _set_navigation_buttons() {
if (current_path != "") {
$(".wc-toolbar .ui-icon-eject").parent("a").removeClass("ui-state-disabled");
$(".wc-toolbar .ui-icon-trash").parent("a").removeClass("ui-state-disabled");
//$(".wc-toolbar .ui-icon-trash").parent("a").removeClass("ui-state-disabled");
} else {
$(".wc-toolbar .ui-icon-eject").parent("a").addClass("ui-state-disabled");
$(".wc-toolbar .ui-icon-trash").parent("a").addClass("ui-state-disabled");
//$(".wc-toolbar .ui-icon-trash").parent("a").addClass("ui-state-disabled");
}
$(".wc-toolbar .ui-icon-eject").attr("ref", parent_path);
$(".wc-toolbar .ui-icon-pencil").attr("ref", current_path);
$(".wc-toolbar .ui-icon-trash").attr("ref", current_path);
$(".wc-toolbar #wc-add-resource span")
.attr("ref", resource_type == "album" ? current_path : parent_path);
var paths = _paths[resource_type == "album" ? current_path : parent_path];
var paths = _paths[resource_type == "album" ? current_path : parent_path];
$(".wc-toolbar .ui-icon-pencil").attr("ref", current_path);
if (paths.length > 0) {
@ -283,6 +284,8 @@
}
}
$(".wc-toolbar .ui-icon-trash").attr("ref", selected_path);
if (i > 0) {
$(".wc-toolbar .ui-icon-seek-prev").parent("a").removeClass("ui-state-disabled");
$(".wc-toolbar .ui-icon-seek-prev").attr("ref", paths[i - 1]);