summaryrefslogtreecommitdiff
path: root/modules/gallery/models/item.php
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/models/item.php')
-rw-r--r--modules/gallery/models/item.php32
1 files changed, 22 insertions, 10 deletions
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 07f781d1..9016a04a 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -20,7 +20,7 @@
class Item_Model_Core extends ORM_MPTT {
protected $children = "items";
protected $sorting = array();
- protected $data_file = null;
+ public $data_file = null;
public function __construct($id=null) {
parent::__construct($id);
@@ -71,6 +71,11 @@ class Item_Model_Core extends ORM_MPTT {
}
public function delete($ignored_id=null) {
+ if (!$this->loaded()) {
+ // Concurrent deletes may result in this item already being gone. Ignore it.
+ return;
+ }
+
if ($this->id == 1) {
$v = new Validation(array("id"));
$v->add_error("id", "cant_delete_root_album");
@@ -166,8 +171,9 @@ class Item_Model_Core extends ORM_MPTT {
*/
public function file_url($full_uri=false) {
$relative_path = "var/albums/" . $this->relative_path();
+ $cache_buster = $this->_cache_buster($this->file_path());
return ($full_uri ? url::abs_file($relative_path) : url::file($relative_path))
- . "?m={$this->updated}";
+ . $cache_buster;
}
/**
@@ -198,7 +204,7 @@ class Item_Model_Core extends ORM_MPTT {
* photo: http://example.com/gallery3/var/albums/album1/photo.thumb.jpg
*/
public function thumb_url($full_uri=false) {
- $cache_buster = "?m={$this->updated}";
+ $cache_buster = $this->_cache_buster($this->thumb_path());
$relative_path = "var/thumbs/" . $this->relative_path();
$base = ($full_uri ? url::abs_file($relative_path) : url::file($relative_path));
if ($this->is_photo()) {
@@ -227,9 +233,9 @@ class Item_Model_Core extends ORM_MPTT {
*/
public function resize_url($full_uri=false) {
$relative_path = "var/resizes/" . $this->relative_path();
+ $cache_buster = $this->_cache_buster($this->resize_path());
return ($full_uri ? url::abs_file($relative_path) : url::file($relative_path)) .
- ($this->is_album() ? "/.album.jpg" : "")
- . "?m={$this->updated}";
+ ($this->is_album() ? "/.album.jpg" : "") . $cache_buster;
}
/**
@@ -320,6 +326,7 @@ class Item_Model_Core extends ORM_MPTT {
$this->updated = time();
if (!$this->loaded()) {
// Create a new item.
+ module::event("item_before_create", $this);
// Set a weight if it's missing. We don't do this in the constructor because it's not a
// simple assignment.
@@ -398,6 +405,7 @@ class Item_Model_Core extends ORM_MPTT {
module::event("item_created", $this);
} else {
// Update an existing item
+ module::event("item_before_update", $item);
// If any significant fields have changed, load up a copy of the original item and
// keep it around.
@@ -628,7 +636,7 @@ class Item_Model_Core extends ORM_MPTT {
list ($height, $width) = $this->scale_dimensions($max);
if ($center_vertically && $max) {
// The constant is divide by 2 to calculate the file and 10 to convert to em
- $margin_top = ($max - $height) / 20;
+ $margin_top = (int)(($max - $height) / 20);
$extra_attrs["style"] = "margin-top: {$margin_top}em";
$extra_attrs["title"] = $this->title;
}
@@ -656,10 +664,10 @@ class Item_Model_Core extends ORM_MPTT {
if ($height) {
if (isset($max)) {
if ($width > $height) {
- $height = (int)($max * ($height / $width));
+ $height = (int)($max * $height / $width);
$width = $max;
} else {
- $width = (int)($max * ($width / $height));
+ $width = (int)($max * $width / $height);
$height = $max;
}
}
@@ -700,10 +708,10 @@ class Item_Model_Core extends ORM_MPTT {
$height = $this->height;
if ($width > $max_size || $height > $max_size) {
if ($width > $height) {
- $height *= $max_size / $width;
+ $height = (int)($height * $max_size / $width);
$width = $max_size;
} else {
- $width *= $max_size / $height;
+ $width = (int)($width * $max_size / $height);
$height = $max_size;
}
}
@@ -1022,4 +1030,8 @@ class Item_Model_Core extends ORM_MPTT {
}
return $data;
}
+
+ private function _cache_buster($path) {
+ return "?m=" . (string)(file_exists($path) ? filemtime($path) : 0);
+ }
}