Skip to content

Commit

Permalink
Always use the data resource to return thumbs, resizes and full sizes.
Browse files Browse the repository at this point in the history
That way the client does not have to differentiate between RESTful
request types and raw request types.  If there's a public raw url,
return that as well.
  • Loading branch information
bharat committed Aug 14, 2010
1 parent b562751 commit dbe595f
Showing 1 changed file with 14 additions and 16 deletions.
30 changes: 14 additions & 16 deletions modules/gallery/models/item.php
Expand Up @@ -668,9 +668,9 @@ public function scale_dimensions($max) {
public function resize_img($extra_attrs) {
$attrs = array_merge($extra_attrs,
array("src" => $this->resize_url(),
"alt" => $this->title,
"width" => $this->resize_width,
"height" => $this->resize_height)
"alt" => $this->title,
"width" => $this->resize_width,
"height" => $this->resize_height)
);
// html::image forces an absolute url which we don't want
return "<img" . html::attributes($attrs) . "/>";
Expand Down Expand Up @@ -973,27 +973,25 @@ public function as_restful_array() {
}
unset($data["album_cover_item_id"]);

if (access::can("view_full", $this) && $this->is_photo()) {
if (access::user_can(identity::guest(), "view_full", $this)) {
$data["file_url"] = $this->file_url(true);
} else {
$data["file_url"] = rest::url("data", $this, "full");
}
if (access::can("view_full", $this) && !$this->is_album()) {
$data["file_url"] = rest::url("data", $this, "full");
}
if (access::user_can(identity::guest(), "view_full", $this)) {
$data["file_url_public"] = $this->file_url(true);
}

if (($tmp = $this->resize_url(true)) && $this->is_photo()) {
if ($this->is_photo()) {
$data["resize_url"] = rest::url("data", $this, "resize");
if (access::user_can(identity::guest(), "view", $this)) {
$data["resize_url"] = $tmp;
} else {
$data["resize_url"] = rest::url("data", $this, "resize");
$data["resize_url_public"] = $this->resize_url(true);
}
}

$data["thumb_url"] = rest::url("data", $this, "thumb");
if (access::user_can(identity::guest(), "view", $this)) {
$data["thumb_url"] = $this->thumb_url(true);
} else {
$data["thumb_url"] = rest::url("data", $this, "thumb");
$data["thumb_url_public"] = $this->thumb_url(true);
}

$data["can_edit"] = access::can("edit", $this);

// Elide some internal-only data that is going to cause confusion in the client.
Expand Down

0 comments on commit dbe595f

Please sign in to comment.