diff options
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 | 78 | ||||
-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, 61 insertions, 45 deletions
diff --git a/modules/gallery/models/access_cache.php b/modules/gallery/models/access_cache.php index 217dd147..f240b020 100644 --- a/modules/gallery/models/access_cache.php +++ b/modules/gallery/models/access_cache.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/access_intent.php b/modules/gallery/models/access_intent.php index 43c46d0c..e9660b53 100644 --- a/modules/gallery/models/access_intent.php +++ b/modules/gallery/models/access_intent.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/cache.php b/modules/gallery/models/cache.php index 9d02a44c..abc4dd54 100644 --- a/modules/gallery/models/cache.php +++ b/modules/gallery/models/cache.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/failed_auth.php b/modules/gallery/models/failed_auth.php index a418681d..87c20687 100644 --- a/modules/gallery/models/failed_auth.php +++ b/modules/gallery/models/failed_auth.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/graphics_rule.php b/modules/gallery/models/graphics_rule.php index feaae3c6..79daff4e 100644 --- a/modules/gallery/models/graphics_rule.php +++ b/modules/gallery/models/graphics_rule.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/incoming_translation.php b/modules/gallery/models/incoming_translation.php index 07df9d2f..093dd2e5 100644 --- a/modules/gallery/models/incoming_translation.php +++ b/modules/gallery/models/incoming_translation.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php index 2a5e6894..e90e0fcb 100644 --- a/modules/gallery/models/item.php +++ b/modules/gallery/models/item.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 @@ -408,6 +408,27 @@ class Item_Model_Core extends ORM_MPTT { // If any significant fields have changed, load up a copy of the original item and // keep it around. $original = ORM::factory("item", $this->id); + + // Preserve the extension of the data file. Many helpers, (e.g. ImageMagick), assume + // the MIME type from the extension. So when we adopt the new data file, it's important + // to adopt the new extension. That ensures that the item's extension is always + // appropriate for its data. We don't try to preserve the name of the data file, though, + // because the name is typically a temporary randomly-generated name. + if (isset($this->data_file)) { + $extension = pathinfo($this->data_file, PATHINFO_EXTENSION); + $new_name = pathinfo($this->name, PATHINFO_FILENAME) . ".$extension"; + if (!empty($extension) && strcmp($this->name, $new_name)) { + $this->name = $new_name; + } + if ($this->is_photo()) { + list ($this->width, $this->height, $this->mime_type, $extension) = + photo::get_file_metadata($this->data_file); + } else if ($this->is_movie()) { + list ($this->width, $this->height, $this->mime_type, $extension) = + movie::get_file_metadata($this->data_file); + } + } + if (array_intersect($this->changed, array("parent_id", "name", "slug"))) { $original->_build_relative_caches(); $this->relative_path_cache = null; @@ -429,8 +450,19 @@ class Item_Model_Core extends ORM_MPTT { } if ($original->parent_id != $this->parent_id || $original->name != $this->name) { + $this->_build_relative_caches(); + // If there is a data file, then we want to preserve both the old data and the new data. + // (Third-party event handlers would like access to both). The old data file will be + // accessible via the $original item, and the new one via $this item. But in that case, + // we don't want to rename the original as below, because the old data would end up being + // clobbered by the new data file. Also, the rename isn't necessary, because the new item + // data is coming from the data file anyway. So we only perform the rename if there isn't + // a data file. Another way to solve this would be to copy the original file rather than + // conditionally rename it, but a copy would cost far more than the rename. + if (!isset($this->data_file)) { + @rename($original->file_path(), $this->file_path()); + } // Move all of the items associated data files - @rename($original->file_path(), $this->file_path()); if ($this->is_album()) { @rename(dirname($original->resize_path()), dirname($this->resize_path())); @rename(dirname($original->thumb_path()), dirname($this->thumb_path())); @@ -460,8 +492,6 @@ class Item_Model_Core extends ORM_MPTT { } // Replace the data file, if requested. - // @todo: we don't handle the case where you swap in a file of a different mime type - // should we prevent that in validation? or in set_data_file() if ($this->data_file && ($this->is_photo() || $this->is_movie())) { copy($this->data_file, $this->file_path()); @@ -481,6 +511,9 @@ class Item_Model_Core extends ORM_MPTT { // Null out the data file variable here, otherwise this event will trigger another // save() which will think that we're doing another file move. $this->data_file = null; + if ($original->file_path() != $this->file_path()) { + @unlink($original->file_path()); + } module::event("item_updated_data_file", $this); } } @@ -517,6 +550,8 @@ class Item_Model_Core extends ORM_MPTT { $this->name = "$base_name-$rand"; } $this->slug = "$base_slug-$rand"; + $this->relative_path_cache = null; + $this->relative_url_cache = null; } } @@ -768,16 +803,7 @@ class Item_Model_Core extends ORM_MPTT { } if ($this->is_movie() || $this->is_photo()) { - if ($this->loaded()) { - // Existing items can't change their extension - $original = ORM::factory("item", $this->id); - $new_ext = pathinfo($this->name, PATHINFO_EXTENSION); - $old_ext = pathinfo($original->name, PATHINFO_EXTENSION); - if (strcasecmp($new_ext, $old_ext)) { - $v->add_error("name", "illegal_data_file_extension"); - return; - } - } else { + if (!$this->loaded()) { // New items must have an extension $ext = pathinfo($this->name, PATHINFO_EXTENSION); if (!$ext) { @@ -785,9 +811,10 @@ class Item_Model_Core extends ORM_MPTT { return; } - if ($this->is_movie() && !preg_match("/^(flv|mp4|m4v)$/i", $ext)) { - $v->add_error("name", "illegal_data_file_extension"); - } else if ($this->is_photo() && !preg_match("/^(gif|jpg|jpeg|png)$/i", $ext)) { + if ($this->is_photo() && + !in_array(strtolower($ext), array_map("strtolower", legal_file::get_photo_extensions())) || + $this->is_movie() && + !in_array(strtolower($ext), array_map("strtolower", legal_file::get_movie_extensions()))) { $v->add_error("name", "illegal_data_file_extension"); } } @@ -813,17 +840,6 @@ class Item_Model_Core extends ORM_MPTT { } else if (filesize($this->data_file) == 0) { $v->add_error("name", "empty_data_file"); } - - if ($this->loaded()) { - if ($this->is_photo()) { - list ($a, $b, $mime_type) = photo::get_file_metadata($this->data_file); - } else if ($this->is_movie()) { - list ($a, $b, $mime_type) = movie::get_file_metadata($this->data_file); - } - if ($mime_type != $this->mime_type) { - $v->add_error("name", "cant_change_mime_type"); - } - } } /** @@ -877,9 +893,9 @@ class Item_Model_Core extends ORM_MPTT { switch($field) { case "mime_type": if ($this->is_movie()) { - $legal_values = array("video/flv", "video/x-flv", "video/mp4"); - } if ($this->is_photo()) { - $legal_values = array("image/jpeg", "image/gif", "image/png"); + $legal_values = legal_file::get_movie_types(); + } else if ($this->is_photo()) { + $legal_values = legal_file::get_photo_types(); } break; diff --git a/modules/gallery/models/log.php b/modules/gallery/models/log.php index a57649ff..013c1870 100644 --- a/modules/gallery/models/log.php +++ b/modules/gallery/models/log.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/message.php b/modules/gallery/models/message.php index 9a0b99f7..034ddf03 100644 --- a/modules/gallery/models/message.php +++ b/modules/gallery/models/message.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/module.php b/modules/gallery/models/module.php index ca251ff5..354e1568 100644 --- a/modules/gallery/models/module.php +++ b/modules/gallery/models/module.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/outgoing_translation.php b/modules/gallery/models/outgoing_translation.php index 7f90a2b0..e0674202 100644 --- a/modules/gallery/models/outgoing_translation.php +++ b/modules/gallery/models/outgoing_translation.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/permission.php b/modules/gallery/models/permission.php index 52e3131e..ca25f90e 100644 --- a/modules/gallery/models/permission.php +++ b/modules/gallery/models/permission.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/task.php b/modules/gallery/models/task.php index 2ee9075a..56d20a8c 100644 --- a/modules/gallery/models/task.php +++ b/modules/gallery/models/task.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/theme.php b/modules/gallery/models/theme.php index ab2ba57f..7fc4f99e 100644 --- a/modules/gallery/models/theme.php +++ b/modules/gallery/models/theme.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 diff --git a/modules/gallery/models/var.php b/modules/gallery/models/var.php index 6e406ac7..4fef278d 100644 --- a/modules/gallery/models/var.php +++ b/modules/gallery/models/var.php @@ -1,7 +1,7 @@ <?php defined("SYSPATH") or die("No direct script access."); /** * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2011 Bharat Mediratta + * Copyright (C) 2000-2012 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 |