diff options
author | Nathan Kinkade <nkinkade@nkinka.de> | 2010-12-06 16:14:26 +0000 |
---|---|---|
committer | Nathan Kinkade <nkinkade@nkinka.de> | 2010-12-06 16:14:26 +0000 |
commit | cf1965957c48b1c88a3913f8167688d03d191cec (patch) | |
tree | 9da9e719c68f4428771c9b70389b93f7a1bafd26 /modules/gallery/models | |
parent | 1659e487a26ef0460926376b7b8b40aaba0c0577 (diff) | |
parent | c3ef8921260db8e39b6d2a7b4708e3d19f35f8b5 (diff) |
Merge branch 'master' of git://github.com/gallery/gallery3
Diffstat (limited to 'modules/gallery/models')
-rw-r--r-- | modules/gallery/models/access_cache.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/access_intent.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/cache.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/failed_auth.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/graphics_rule.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/incoming_translation.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/item.php | 32 | ||||
-rw-r--r-- | modules/gallery/models/log.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/message.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/module.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/outgoing_translation.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/permission.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/task.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/theme.php | 2 | ||||
-rw-r--r-- | modules/gallery/models/var.php | 2 |
15 files changed, 36 insertions, 24 deletions
diff --git a/modules/gallery/models/access_cache.php b/modules/gallery/models/access_cache.php index af1b5c6c..e730f25c 100644 --- a/modules/gallery/models/access_cache.php +++ b/modules/gallery/models/access_cache.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Access_Cache_Model extends ORM { +class Access_Cache_Model_Core extends ORM { } diff --git a/modules/gallery/models/access_intent.php b/modules/gallery/models/access_intent.php index e71f8c46..31711014 100644 --- a/modules/gallery/models/access_intent.php +++ b/modules/gallery/models/access_intent.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Access_Intent_Model extends ORM { +class Access_Intent_Model_Core extends ORM { } diff --git a/modules/gallery/models/cache.php b/modules/gallery/models/cache.php index 4a7e37f6..1c464d51 100644 --- a/modules/gallery/models/cache.php +++ b/modules/gallery/models/cache.php @@ -17,4 +17,4 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Cache_Model extends ORM {} +class Cache_Model_Core extends ORM {} diff --git a/modules/gallery/models/failed_auth.php b/modules/gallery/models/failed_auth.php index a541f435..649e4bc9 100644 --- a/modules/gallery/models/failed_auth.php +++ b/modules/gallery/models/failed_auth.php @@ -17,4 +17,4 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Failed_Auth_Model extends ORM {} +class Failed_Auth_Model_Core extends ORM {} diff --git a/modules/gallery/models/graphics_rule.php b/modules/gallery/models/graphics_rule.php index 49036b9c..09410af0 100644 --- a/modules/gallery/models/graphics_rule.php +++ b/modules/gallery/models/graphics_rule.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Graphics_Rule_Model extends ORM { +class Graphics_Rule_Model_Core extends ORM { } diff --git a/modules/gallery/models/incoming_translation.php b/modules/gallery/models/incoming_translation.php index 45340c30..ff6a7160 100644 --- a/modules/gallery/models/incoming_translation.php +++ b/modules/gallery/models/incoming_translation.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Incoming_Translation_Model extends ORM { +class Incoming_Translation_Model_Core extends ORM { } 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); + } } diff --git a/modules/gallery/models/log.php b/modules/gallery/models/log.php index aa1a37ed..5d065313 100644 --- a/modules/gallery/models/log.php +++ b/modules/gallery/models/log.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Log_Model extends ORM { +class Log_Model_Core extends ORM { /** * @see ORM::__get() */ diff --git a/modules/gallery/models/message.php b/modules/gallery/models/message.php index 994d0cdb..3f84efd0 100644 --- a/modules/gallery/models/message.php +++ b/modules/gallery/models/message.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Message_Model extends ORM { +class Message_Model_Core extends ORM { } diff --git a/modules/gallery/models/module.php b/modules/gallery/models/module.php index dc181849..e54613d1 100644 --- a/modules/gallery/models/module.php +++ b/modules/gallery/models/module.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Module_Model extends ORM { +class Module_Model_Core extends ORM { } diff --git a/modules/gallery/models/outgoing_translation.php b/modules/gallery/models/outgoing_translation.php index 43f56dce..cd580bed 100644 --- a/modules/gallery/models/outgoing_translation.php +++ b/modules/gallery/models/outgoing_translation.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Outgoing_Translation_Model extends ORM { +class Outgoing_Translation_Model_Core extends ORM { } diff --git a/modules/gallery/models/permission.php b/modules/gallery/models/permission.php index b6b544d5..51bd95e7 100644 --- a/modules/gallery/models/permission.php +++ b/modules/gallery/models/permission.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Permission_Model extends ORM { +class Permission_Model_Core extends ORM { } diff --git a/modules/gallery/models/task.php b/modules/gallery/models/task.php index 4888a734..4d435101 100644 --- a/modules/gallery/models/task.php +++ b/modules/gallery/models/task.php @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Task_Model extends ORM { +class Task_Model_Core extends ORM { public function get($key, $default=null) { $context = unserialize($this->context); if (array_key_exists($key, $context)) { diff --git a/modules/gallery/models/theme.php b/modules/gallery/models/theme.php index 523542f9..50fd04fd 100644 --- a/modules/gallery/models/theme.php +++ b/modules/gallery/models/theme.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Theme_Model extends ORM { +class Theme_Model_Core extends ORM { }
\ No newline at end of file diff --git a/modules/gallery/models/var.php b/modules/gallery/models/var.php index a79d0048..f21486ee 100644 --- a/modules/gallery/models/var.php +++ b/modules/gallery/models/var.php @@ -17,5 +17,5 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class Var_Model extends ORM { +class Var_Model_Core extends ORM { } |