From 31ba081b793141ca36866a6dd349cd2eac5af68e Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Thu, 21 Apr 2011 02:06:53 -0600
Subject: Add an event that will collect all valid filename extensions.
---
modules/gallery/controllers/uploader.php | 2 +-
modules/gallery/libraries/Form_Uploadify.php | 1 +
modules/gallery/models/item.php | 9 +++++----
modules/gallery/views/form_uploadify.html.php | 2 +-
system/helpers/upload.php | 20 ++++++++++++++++++++
5 files changed, 28 insertions(+), 6 deletions(-)
diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php
index 6b1455e4..12180893 100644
--- a/modules/gallery/controllers/uploader.php
+++ b/modules/gallery/controllers/uploader.php
@@ -51,7 +51,7 @@ class Uploader_Controller extends Controller {
$file_validation = new Validation($_FILES);
$file_validation->add_rules(
"Filedata", "upload::valid", "upload::required",
- "upload::type[gif,jpg,jpeg,png,flv,mp4,m4v]");
+ "upload::type[" . implode(",", upload::get_upload_extensions()) . "]");
if ($form->validate() && $file_validation->validate()) {
$temp_filename = upload::save("Filedata");
diff --git a/modules/gallery/libraries/Form_Uploadify.php b/modules/gallery/libraries/Form_Uploadify.php
index 27ab9684..ca189f0b 100644
--- a/modules/gallery/libraries/Form_Uploadify.php
+++ b/modules/gallery/libraries/Form_Uploadify.php
@@ -47,6 +47,7 @@ class Form_Uploadify_Core extends Form_Input {
$v->script_data = $this->data["script_data"];
$v->simultaneous_upload_limit = module::get_var("gallery", "simultaneous_upload_limit");
$v->movies_allowed = (bool) movie::find_ffmpeg();
+ $v->extensions = upload::get_upload_filters();
$v->suhosin_session_encrypt = (bool) ini_get("suhosin.session.encrypt");
return $v;
}
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 8f4bc5e4..aaca832a 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -787,9 +787,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_movie() || $this->is_photo()) &&
+ !preg_match("/^(" .
+ implode("|", array_map("preg_quote", upload::get_upload_extensions())) .
+ ")\$/i", $ext)) {
$v->add_error("name", "illegal_data_file_extension");
}
}
@@ -881,7 +882,7 @@ class Item_Model_Core extends ORM_MPTT {
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 = array("image/jpeg", "image/gif", "image/png", "image/tiff");
}
break;
diff --git a/modules/gallery/views/form_uploadify.html.php b/modules/gallery/views/form_uploadify.html.php
index 77b6d493..db90b733 100644
--- a/modules/gallery/views/form_uploadify.html.php
+++ b/modules/gallery/views/form_uploadify.html.php
@@ -28,7 +28,7 @@
uploader: "= url::file("lib/uploadify/uploadify.swf") ?>",
script: "= url::site("uploader/add_photo/{$album->id}") ?>",
scriptData: = json_encode($script_data) ?>,
- fileExt: "*.gif;*.jpg;*.jpeg;*.png;*.GIF;*.JPG;*.JPEG;*.PNG if ($movies_allowed): ?>;*.flv;*.mp4;*.m4v;*.FLV;*.MP4;*.M4V endif ?>",
+ fileExt: "= implode(";", $extensions) ?>",
fileDesc: = t("Photos and movies")->for_js() ?>,
cancelImg: "= url::file("lib/uploadify/cancel.png") ?>",
simUploadLimit: = $simultaneous_upload_limit ?>,
diff --git a/system/helpers/upload.php b/system/helpers/upload.php
index 62de674f..cfd92dd1 100644
--- a/system/helpers/upload.php
+++ b/system/helpers/upload.php
@@ -154,4 +154,24 @@ class upload_Core {
return ($file['size'] <= $size);
}
+
+ static function get_upload_extensions() {
+ // Create a default list of allowed extensions and then let modules modify it.
+ $extensions_wrapper = new stdClass();
+ $extensions_wrapper->extensions = array("gif", "jpg", "jpeg", "png");
+ if (movie::find_ffmpeg()) {
+ array_push($extensions_wrapper->extensions, "flv", "mp4", "m4v");
+ }
+ module::event("upload_extensions", $extensions_wrapper);
+ return $extensions_wrapper->extensions;
+ }
+
+ static function get_upload_filters() {
+ $filters = array();
+ foreach (upload::get_upload_extensions() as $extension) {
+ array_push($filters, "*." . $extension, "*." . strtoupper($extension));
+ }
+ return $filters;
+ }
+
} // End upload
\ No newline at end of file
--
cgit v1.2.3
From 567522bfa08c370bb5baf8454afc5b04bc9e49b4 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Thu, 21 Apr 2011 20:12:32 -0600
Subject: Add an event for when a new graphics toolkit is chosen.
---
modules/gallery/controllers/admin_graphics.php | 2 ++
1 file changed, 2 insertions(+)
diff --git a/modules/gallery/controllers/admin_graphics.php b/modules/gallery/controllers/admin_graphics.php
index a2d19d4a..a8a7cdc0 100644
--- a/modules/gallery/controllers/admin_graphics.php
+++ b/modules/gallery/controllers/admin_graphics.php
@@ -40,6 +40,8 @@ class Admin_Graphics_Controller extends Admin_Controller {
$msg = t("Changed graphics toolkit to: %toolkit", array("toolkit" => $tk->$toolkit_id->name));
message::success($msg);
log::success("graphics", $msg);
+
+ module::event("graphics_toolkit_change", $toolkit_id);
}
url::redirect("admin/graphics");
--
cgit v1.2.3
From 6702104f571413e4d57db3515b2070c48d3e9b55 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 23 Apr 2011 16:35:00 -0600
Subject: Resolve an infinite recursion that happens when the path caches are
updated during saving.
---
modules/gallery/models/item.php | 1 +
1 file changed, 1 insertion(+)
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index aaca832a..a8bca15c 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -432,6 +432,7 @@ class Item_Model_Core extends ORM_MPTT {
if ($original->parent_id != $this->parent_id || $original->name != $this->name) {
// Move all of the items associated data files
+ $this->_build_relative_caches();
@rename($original->file_path(), $this->file_path());
if ($this->is_album()) {
@rename(dirname($original->resize_path()), dirname($this->resize_path()));
--
cgit v1.2.3
From e149cf7238a1f8eaddfc68580f2d636dd8255795 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 23 Apr 2011 16:39:25 -0600
Subject: Support data files that change their extension and MIME type.
---
modules/gallery/models/item.php | 35 ++++++++++++-----------------------
1 file changed, 12 insertions(+), 23 deletions(-)
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index a8bca15c..299d3584 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -410,6 +410,15 @@ 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.
+ if (isset($this->data_file)) {
+ $extension = pathinfo($this->data_file, PATHINFO_EXTENSION);
+ if (!empty($extension)) {
+ $this->name = pathinfo($this->name, PATHINFO_FILENAME) . ".$extension";
+ }
+ }
+
if (array_intersect($this->changed, array("parent_id", "name", "slug"))) {
$original->_build_relative_caches();
$this->relative_path_cache = null;
@@ -463,8 +472,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());
@@ -520,6 +527,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;
}
}
@@ -771,16 +780,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) {
@@ -817,17 +817,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");
- }
- }
}
/**
--
cgit v1.2.3
From 0d6a3a3cfc4f38f450db9e18da47a5e2ad826af8 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 23 Apr 2011 21:19:47 -0600
Subject: Create a tempnam substitute that safely creates files with a given
extension.
---
modules/gallery/controllers/quick.php | 4 +--
modules/gallery/helpers/system.php | 25 ++++++++++++++
modules/gallery/tests/Mock_Built_In.php | 39 ++++++++++++++++++++++
modules/gallery/tests/System_Helper_Test.php | 49 ++++++++++++++++++++++++++++
4 files changed, 115 insertions(+), 2 deletions(-)
create mode 100644 modules/gallery/tests/Mock_Built_In.php
create mode 100644 modules/gallery/tests/System_Helper_Test.php
diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php
index da4768fd..ce52cb8d 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -36,8 +36,8 @@ class Quick_Controller extends Controller {
}
if ($degrees) {
- $tmpfile = tempnam(TMPPATH, "rotate") . "." .
- pathinfo($item->file_path(), PATHINFO_EXTENSION);
+ $tmpfile = system::tempnam(TMPPATH, "rotate",
+ "." . pathinfo($item->file_path(), PATHINFO_EXTENSION));
gallery_graphics::rotate($item->file_path(), $tmpfile, array("degrees" => $degrees), $item);
$item->set_data_file($tmpfile);
$item->save();
diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php
index c39c7227..31ecafa7 100644
--- a/modules/gallery/helpers/system.php
+++ b/modules/gallery/helpers/system.php
@@ -40,4 +40,29 @@ class system_Core {
}
return null;
}
+
+ /**
+ * Create a file with a unique file name.
+ * This helper is similar to the built-in tempnam, except that it supports an optional postfix.
+ */
+ static function tempnam($dir = TMPPATH, $prefix = "", $postfix = "") {
+ return self::_tempnam($dir, $prefix, $postfix, "tempnam");
+ }
+
+ // This helper provides a dependency-injected implementation of tempnam.
+ static function _tempnam($dir, $prefix, $postfix, $builtin) {
+ $success = false;
+ do {
+ $basename = call_user_func($builtin, $dir, $prefix);
+ if (!$basename) {
+ return false;
+ }
+ $filename = $basename . $postfix;
+ $success = !file_exists($filename) && @rename($basename, $filename);
+ if (!$success) {
+ @unlink($basename);
+ }
+ } while (!$success);
+ return $filename;
+ }
}
\ No newline at end of file
diff --git a/modules/gallery/tests/Mock_Built_In.php b/modules/gallery/tests/Mock_Built_In.php
new file mode 100644
index 00000000..b02e5ecf
--- /dev/null
+++ b/modules/gallery/tests/Mock_Built_In.php
@@ -0,0 +1,39 @@
+nonces = func_get_args();
+ }
+
+ function _tempnam($dir, $prefix) {
+ if (empty($this->nonces))
+ return false;
+ $filename = "$dir/$prefix" . array_shift($this->nonces);
+ if (!touch($filename))
+ return false;
+ return $filename;
+ }
+}
diff --git a/modules/gallery/tests/System_Helper_Test.php b/modules/gallery/tests/System_Helper_Test.php
new file mode 100644
index 00000000..734f98ac
--- /dev/null
+++ b/modules/gallery/tests/System_Helper_Test.php
@@ -0,0 +1,49 @@
+assert_true(file_exists($filename), "File not created");
+ unlink($filename);
+ }
+
+ public function tempnam_collision_test() {
+ require_once('Mock_Built_In.php');
+ $existing = TMPPATH . "/file1.ext";
+ $available = TMPPATH . "/file2.ext";
+ touch($existing);
+ $filename = system::_tempnam(TMPPATH, "file", ".ext",
+ array(new Mock_Built_In("1", "2"), "_tempnam"));
+ unlink($existing);
+ $this->assert_true(file_exists($filename), "File not created");
+ unlink($filename);
+ $this->assert_equal($available, $filename, "Incorrect filename created");
+ }
+
+ public function tempnam_abort_test() {
+ require_once('Mock_Built_In.php');
+ $filename = system::_tempnam(TMPPATH, "file", ".ext",
+ array(new Mock_Built_In(), "_tempnam"));
+ if ($filename) {
+ @unlink($filename);
+ }
+ $this->assert_false($filename, "Operation not aborted");
+ }
+}
--
cgit v1.2.3
From c6ef706d70c7e48bea1145eec1b13fb5683e023f Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 23 Apr 2011 22:55:59 -0600
Subject: Preserve old data files long enough for them to be available to event
handlers.
---
modules/gallery/models/item.php | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 299d3584..482b6247 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -442,7 +442,9 @@ class Item_Model_Core extends ORM_MPTT {
if ($original->parent_id != $this->parent_id || $original->name != $this->name) {
// Move all of the items associated data files
$this->_build_relative_caches();
- @rename($original->file_path(), $this->file_path());
+ if (!isset($this->data_file)) {
+ @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()));
@@ -491,6 +493,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);
}
}
--
cgit v1.2.3
From fcb06bf175bb9eeff36d9c294e97ace9374ef0f3 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sun, 24 Apr 2011 00:45:12 -0600
Subject: Don't assign to the item->name field if the name is unchanged,
because the save method will crash.
---
modules/gallery/models/item.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 482b6247..7a08d9c2 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -414,8 +414,9 @@ class Item_Model_Core extends ORM_MPTT {
// Preserve the extension of the data file.
if (isset($this->data_file)) {
$extension = pathinfo($this->data_file, PATHINFO_EXTENSION);
- if (!empty($extension)) {
- $this->name = pathinfo($this->name, PATHINFO_FILENAME) . ".$extension";
+ $new_name = pathinfo($this->name, PATHINFO_FILENAME) . ".$extension";
+ if (!empty($extension) && strcmp($this->name, $new_name)) {
+ $this->name = $new_name;
}
}
--
cgit v1.2.3
From 809567f12850f59bdeb47a2963f6968b99b5a201 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sun, 24 Apr 2011 08:10:04 -0600
Subject: Expose the data file field.
---
modules/gallery/models/item.php | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 7a08d9c2..f4d4c521 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -127,6 +127,15 @@ class Item_Model_Core extends ORM_MPTT {
return $this;
}
+ /**
+ * Get the path to the data file associated with this item.
+ * This data file field is only set until you call save().
+ * After that, you can get the path using get_file_path().
+ */
+ public function get_data_file() {
+ return $this->data_file;
+ }
+
/**
* Return the server-relative url to this item, eg:
* /gallery3/index.php/BobsWedding?page=2
--
cgit v1.2.3
From 7ff485fa48c392bbbb0370f67cb1bd6fcc00c2a4 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 27 Apr 2011 20:29:06 -0600
Subject: Move the extensions helpers out of the Kohana system directory and
into their own Gallery Extensions class.
---
modules/gallery/controllers/uploader.php | 2 +-
modules/gallery/helpers/extensions.php | 39 ++++++++++++++++++++++++++++
modules/gallery/libraries/Form_Uploadify.php | 4 +--
modules/gallery/models/item.php | 3 ++-
system/helpers/upload.php | 20 --------------
5 files changed, 44 insertions(+), 24 deletions(-)
create mode 100644 modules/gallery/helpers/extensions.php
diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php
index 12180893..5f3e9ca4 100644
--- a/modules/gallery/controllers/uploader.php
+++ b/modules/gallery/controllers/uploader.php
@@ -51,7 +51,7 @@ class Uploader_Controller extends Controller {
$file_validation = new Validation($_FILES);
$file_validation->add_rules(
"Filedata", "upload::valid", "upload::required",
- "upload::type[" . implode(",", upload::get_upload_extensions()) . "]");
+ "upload::type[" . implode(",", extensions::get_upload_extensions()) . "]");
if ($form->validate() && $file_validation->validate()) {
$temp_filename = upload::save("Filedata");
diff --git a/modules/gallery/helpers/extensions.php b/modules/gallery/helpers/extensions.php
new file mode 100644
index 00000000..bccbfc41
--- /dev/null
+++ b/modules/gallery/helpers/extensions.php
@@ -0,0 +1,39 @@
+extensions = array("gif", "jpg", "jpeg", "png");
+ if (movie::find_ffmpeg()) {
+ array_push($extensions_wrapper->extensions, "flv", "mp4", "m4v");
+ }
+ module::event("upload_extensions", $extensions_wrapper);
+ return $extensions_wrapper->extensions;
+ }
+
+ static function get_upload_filters() {
+ $filters = array();
+ foreach (self::get_upload_extensions() as $extension) {
+ array_push($filters, "*." . $extension, "*." . strtoupper($extension));
+ }
+ return $filters;
+ }
+}
diff --git a/modules/gallery/libraries/Form_Uploadify.php b/modules/gallery/libraries/Form_Uploadify.php
index c79b9aa2..c046fe3a 100644
--- a/modules/gallery/libraries/Form_Uploadify.php
+++ b/modules/gallery/libraries/Form_Uploadify.php
@@ -47,7 +47,7 @@ class Form_Uploadify_Core extends Form_Input {
$v->script_data = $this->data["script_data"];
$v->simultaneous_upload_limit = module::get_var("gallery", "simultaneous_upload_limit");
$v->movies_allowed = (bool) movie::find_ffmpeg();
- $v->extensions = upload::get_upload_filters();
+ $v->extensions = extensions::get_upload_filters();
$v->suhosin_session_encrypt = (bool) ini_get("suhosin.session.encrypt");
list ($toolkit_max_filesize_bytes, $toolkit_max_filesize) = graphics::max_filesize();
@@ -69,4 +69,4 @@ class Form_Uploadify_Core extends Form_Input {
public function validate() {
return true;
}
-}
\ No newline at end of file
+}
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index ba8e7cde..dcdcfd0d 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -803,7 +803,8 @@ class Item_Model_Core extends ORM_MPTT {
if (($this->is_movie() || $this->is_photo()) &&
!preg_match("/^(" .
- implode("|", array_map("preg_quote", upload::get_upload_extensions())) .
+ implode("|", array_map("preg_quote",
+ extensions::get_upload_extensions())) .
")\$/i", $ext)) {
$v->add_error("name", "illegal_data_file_extension");
}
diff --git a/system/helpers/upload.php b/system/helpers/upload.php
index cfd92dd1..62de674f 100644
--- a/system/helpers/upload.php
+++ b/system/helpers/upload.php
@@ -154,24 +154,4 @@ class upload_Core {
return ($file['size'] <= $size);
}
-
- static function get_upload_extensions() {
- // Create a default list of allowed extensions and then let modules modify it.
- $extensions_wrapper = new stdClass();
- $extensions_wrapper->extensions = array("gif", "jpg", "jpeg", "png");
- if (movie::find_ffmpeg()) {
- array_push($extensions_wrapper->extensions, "flv", "mp4", "m4v");
- }
- module::event("upload_extensions", $extensions_wrapper);
- return $extensions_wrapper->extensions;
- }
-
- static function get_upload_filters() {
- $filters = array();
- foreach (upload::get_upload_extensions() as $extension) {
- array_push($filters, "*." . $extension, "*." . strtoupper($extension));
- }
- return $filters;
- }
-
} // End upload
\ No newline at end of file
--
cgit v1.2.3
From 4c2b2ebd3f2052898fbfb175650ed4cf49c8006e Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 27 Apr 2011 20:52:35 -0600
Subject: Remove a newline at the end of the file that I accidentally
introduced.
---
modules/gallery/libraries/Form_Uploadify.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/gallery/libraries/Form_Uploadify.php b/modules/gallery/libraries/Form_Uploadify.php
index c046fe3a..884653e2 100644
--- a/modules/gallery/libraries/Form_Uploadify.php
+++ b/modules/gallery/libraries/Form_Uploadify.php
@@ -69,4 +69,4 @@ class Form_Uploadify_Core extends Form_Input {
public function validate() {
return true;
}
-}
+}
\ No newline at end of file
--
cgit v1.2.3
From b875368167658fd7992812504674afeb61c64831 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Thu, 28 Apr 2011 19:41:44 -0600
Subject: This patch helps provide raw photo support with some small changes to
the framework. Items can now change their extension and MIME type.
Squashed commit of the following:
commit 4c2b2ebd3f2052898fbfb175650ed4cf49c8006e
Author: Chad Parry
Date: Wed Apr 27 20:52:35 2011 -0600
Remove a newline at the end of the file that I accidentally introduced.
commit 6d564f185e5279d6cca9a7385066514ff18a2455
Merge: 7ff485f 4060640
Author: Chad Parry
Date: Wed Apr 27 20:35:58 2011 -0600
Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto
commit 7ff485fa48c392bbbb0370f67cb1bd6fcc00c2a4
Author: Chad Parry
Date: Wed Apr 27 20:29:06 2011 -0600
Move the extensions helpers out of the Kohana system directory and into their own Gallery Extensions class.
commit 26585fed03236f0f70a75959e1d3002025f4e15e
Merge: 809567f c8f90e8
Author: Chad Parry
Date: Sun Apr 24 08:28:39 2011 -0600
Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto
commit 809567f12850f59bdeb47a2963f6968b99b5a201
Author: Chad Parry
Date: Sun Apr 24 08:10:04 2011 -0600
Expose the data file field.
commit fcb06bf175bb9eeff36d9c294e97ace9374ef0f3
Author: Chad Parry
Date: Sun Apr 24 00:45:12 2011 -0600
Don't assign to the item->name field if the name is unchanged, because the save method will crash.
commit c6ef706d70c7e48bea1145eec1b13fb5683e023f
Author: Chad Parry
Date: Sat Apr 23 22:55:59 2011 -0600
Preserve old data files long enough for them to be available to event handlers.
commit 0d6a3a3cfc4f38f450db9e18da47a5e2ad826af8
Author: Chad Parry
Date: Sat Apr 23 21:19:47 2011 -0600
Create a tempnam substitute that safely creates files with a given extension.
commit e149cf7238a1f8eaddfc68580f2d636dd8255795
Author: Chad Parry
Date: Sat Apr 23 16:39:25 2011 -0600
Support data files that change their extension and MIME type.
commit 6702104f571413e4d57db3515b2070c48d3e9b55
Author: Chad Parry
Date: Sat Apr 23 16:35:00 2011 -0600
Resolve an infinite recursion that happens when the path caches are updated during saving.
commit 944cb72eea946f4c45a04b7e4c7c33929fa8b9f3
Merge: 567522b 5af74d4
Author: Chad Parry
Date: Fri Apr 22 14:10:42 2011 -0600
Merge remote branch 'origin/master' into rawphoto
commit 567522bfa08c370bb5baf8454afc5b04bc9e49b4
Author: Chad Parry
Date: Thu Apr 21 20:12:32 2011 -0600
Add an event for when a new graphics toolkit is chosen.
commit 31ba081b793141ca36866a6dd349cd2eac5af68e
Author: Chad Parry
Date: Thu Apr 21 02:06:53 2011 -0600
Add an event that will collect all valid filename extensions.
---
modules/gallery/controllers/admin_graphics.php | 2 +
modules/gallery/controllers/quick.php | 4 +-
modules/gallery/controllers/uploader.php | 2 +-
modules/gallery/helpers/extensions.php | 39 ++++++++++++++++
modules/gallery/helpers/system.php | 25 ++++++++++
modules/gallery/libraries/Form_Uploadify.php | 1 +
modules/gallery/models/item.php | 63 ++++++++++++++------------
modules/gallery/tests/Mock_Built_In.php | 39 ++++++++++++++++
modules/gallery/tests/System_Helper_Test.php | 49 ++++++++++++++++++++
modules/gallery/views/form_uploadify.html.php | 2 +-
10 files changed, 194 insertions(+), 32 deletions(-)
create mode 100644 modules/gallery/helpers/extensions.php
create mode 100644 modules/gallery/tests/Mock_Built_In.php
create mode 100644 modules/gallery/tests/System_Helper_Test.php
diff --git a/modules/gallery/controllers/admin_graphics.php b/modules/gallery/controllers/admin_graphics.php
index a2d19d4a..a8a7cdc0 100644
--- a/modules/gallery/controllers/admin_graphics.php
+++ b/modules/gallery/controllers/admin_graphics.php
@@ -40,6 +40,8 @@ class Admin_Graphics_Controller extends Admin_Controller {
$msg = t("Changed graphics toolkit to: %toolkit", array("toolkit" => $tk->$toolkit_id->name));
message::success($msg);
log::success("graphics", $msg);
+
+ module::event("graphics_toolkit_change", $toolkit_id);
}
url::redirect("admin/graphics");
diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php
index da4768fd..ce52cb8d 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -36,8 +36,8 @@ class Quick_Controller extends Controller {
}
if ($degrees) {
- $tmpfile = tempnam(TMPPATH, "rotate") . "." .
- pathinfo($item->file_path(), PATHINFO_EXTENSION);
+ $tmpfile = system::tempnam(TMPPATH, "rotate",
+ "." . pathinfo($item->file_path(), PATHINFO_EXTENSION));
gallery_graphics::rotate($item->file_path(), $tmpfile, array("degrees" => $degrees), $item);
$item->set_data_file($tmpfile);
$item->save();
diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php
index 6b1455e4..5f3e9ca4 100644
--- a/modules/gallery/controllers/uploader.php
+++ b/modules/gallery/controllers/uploader.php
@@ -51,7 +51,7 @@ class Uploader_Controller extends Controller {
$file_validation = new Validation($_FILES);
$file_validation->add_rules(
"Filedata", "upload::valid", "upload::required",
- "upload::type[gif,jpg,jpeg,png,flv,mp4,m4v]");
+ "upload::type[" . implode(",", extensions::get_upload_extensions()) . "]");
if ($form->validate() && $file_validation->validate()) {
$temp_filename = upload::save("Filedata");
diff --git a/modules/gallery/helpers/extensions.php b/modules/gallery/helpers/extensions.php
new file mode 100644
index 00000000..bccbfc41
--- /dev/null
+++ b/modules/gallery/helpers/extensions.php
@@ -0,0 +1,39 @@
+extensions = array("gif", "jpg", "jpeg", "png");
+ if (movie::find_ffmpeg()) {
+ array_push($extensions_wrapper->extensions, "flv", "mp4", "m4v");
+ }
+ module::event("upload_extensions", $extensions_wrapper);
+ return $extensions_wrapper->extensions;
+ }
+
+ static function get_upload_filters() {
+ $filters = array();
+ foreach (self::get_upload_extensions() as $extension) {
+ array_push($filters, "*." . $extension, "*." . strtoupper($extension));
+ }
+ return $filters;
+ }
+}
diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php
index c39c7227..31ecafa7 100644
--- a/modules/gallery/helpers/system.php
+++ b/modules/gallery/helpers/system.php
@@ -40,4 +40,29 @@ class system_Core {
}
return null;
}
+
+ /**
+ * Create a file with a unique file name.
+ * This helper is similar to the built-in tempnam, except that it supports an optional postfix.
+ */
+ static function tempnam($dir = TMPPATH, $prefix = "", $postfix = "") {
+ return self::_tempnam($dir, $prefix, $postfix, "tempnam");
+ }
+
+ // This helper provides a dependency-injected implementation of tempnam.
+ static function _tempnam($dir, $prefix, $postfix, $builtin) {
+ $success = false;
+ do {
+ $basename = call_user_func($builtin, $dir, $prefix);
+ if (!$basename) {
+ return false;
+ }
+ $filename = $basename . $postfix;
+ $success = !file_exists($filename) && @rename($basename, $filename);
+ if (!$success) {
+ @unlink($basename);
+ }
+ } while (!$success);
+ return $filename;
+ }
}
\ No newline at end of file
diff --git a/modules/gallery/libraries/Form_Uploadify.php b/modules/gallery/libraries/Form_Uploadify.php
index 3e35e380..884653e2 100644
--- a/modules/gallery/libraries/Form_Uploadify.php
+++ b/modules/gallery/libraries/Form_Uploadify.php
@@ -47,6 +47,7 @@ class Form_Uploadify_Core extends Form_Input {
$v->script_data = $this->data["script_data"];
$v->simultaneous_upload_limit = module::get_var("gallery", "simultaneous_upload_limit");
$v->movies_allowed = (bool) movie::find_ffmpeg();
+ $v->extensions = extensions::get_upload_filters();
$v->suhosin_session_encrypt = (bool) ini_get("suhosin.session.encrypt");
list ($toolkit_max_filesize_bytes, $toolkit_max_filesize) = graphics::max_filesize();
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 2a5e6894..5ccbe75c 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -127,6 +127,15 @@ class Item_Model_Core extends ORM_MPTT {
return $this;
}
+ /**
+ * Get the path to the data file associated with this item.
+ * This data file field is only set until you call save().
+ * After that, you can get the path using get_file_path().
+ */
+ public function get_data_file() {
+ return $this->data_file;
+ }
+
/**
* Return the server-relative url to this item, eg:
* /gallery3/index.php/BobsWedding?page=2
@@ -408,6 +417,16 @@ 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.
+ 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 (array_intersect($this->changed, array("parent_id", "name", "slug"))) {
$original->_build_relative_caches();
$this->relative_path_cache = null;
@@ -430,7 +449,10 @@ class Item_Model_Core extends ORM_MPTT {
if ($original->parent_id != $this->parent_id || $original->name != $this->name) {
// Move all of the items associated data files
- @rename($original->file_path(), $this->file_path());
+ $this->_build_relative_caches();
+ if (!isset($this->data_file)) {
+ @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 +482,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 +501,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 +540,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 +793,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 +801,11 @@ 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_movie() || $this->is_photo()) &&
+ !preg_match("/^(" .
+ implode("|", array_map("preg_quote",
+ extensions::get_upload_extensions())) .
+ ")\$/i", $ext)) {
$v->add_error("name", "illegal_data_file_extension");
}
}
@@ -813,17 +831,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");
- }
- }
}
/**
@@ -879,7 +886,7 @@ class Item_Model_Core extends ORM_MPTT {
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 = array("image/jpeg", "image/gif", "image/png", "image/tiff");
}
break;
diff --git a/modules/gallery/tests/Mock_Built_In.php b/modules/gallery/tests/Mock_Built_In.php
new file mode 100644
index 00000000..b02e5ecf
--- /dev/null
+++ b/modules/gallery/tests/Mock_Built_In.php
@@ -0,0 +1,39 @@
+nonces = func_get_args();
+ }
+
+ function _tempnam($dir, $prefix) {
+ if (empty($this->nonces))
+ return false;
+ $filename = "$dir/$prefix" . array_shift($this->nonces);
+ if (!touch($filename))
+ return false;
+ return $filename;
+ }
+}
diff --git a/modules/gallery/tests/System_Helper_Test.php b/modules/gallery/tests/System_Helper_Test.php
new file mode 100644
index 00000000..734f98ac
--- /dev/null
+++ b/modules/gallery/tests/System_Helper_Test.php
@@ -0,0 +1,49 @@
+assert_true(file_exists($filename), "File not created");
+ unlink($filename);
+ }
+
+ public function tempnam_collision_test() {
+ require_once('Mock_Built_In.php');
+ $existing = TMPPATH . "/file1.ext";
+ $available = TMPPATH . "/file2.ext";
+ touch($existing);
+ $filename = system::_tempnam(TMPPATH, "file", ".ext",
+ array(new Mock_Built_In("1", "2"), "_tempnam"));
+ unlink($existing);
+ $this->assert_true(file_exists($filename), "File not created");
+ unlink($filename);
+ $this->assert_equal($available, $filename, "Incorrect filename created");
+ }
+
+ public function tempnam_abort_test() {
+ require_once('Mock_Built_In.php');
+ $filename = system::_tempnam(TMPPATH, "file", ".ext",
+ array(new Mock_Built_In(), "_tempnam"));
+ if ($filename) {
+ @unlink($filename);
+ }
+ $this->assert_false($filename, "Operation not aborted");
+ }
+}
diff --git a/modules/gallery/views/form_uploadify.html.php b/modules/gallery/views/form_uploadify.html.php
index 83dfcc68..ba4a3621 100644
--- a/modules/gallery/views/form_uploadify.html.php
+++ b/modules/gallery/views/form_uploadify.html.php
@@ -28,7 +28,7 @@
uploader: "= url::file("lib/uploadify/uploadify.swf") ?>",
script: "= url::site("uploader/add_photo/{$album->id}") ?>",
scriptData: = json_encode($script_data) ?>,
- fileExt: "*.gif;*.jpg;*.jpeg;*.png;*.GIF;*.JPG;*.JPEG;*.PNG if ($movies_allowed): ?>;*.flv;*.mp4;*.m4v;*.FLV;*.MP4;*.M4V endif ?>",
+ fileExt: "= implode(";", $extensions) ?>",
fileDesc: = t("Photos and movies")->for_js() ?>,
cancelImg: "= url::file("lib/uploadify/cancel.png") ?>",
simUploadLimit: = $simultaneous_upload_limit ?>,
--
cgit v1.2.3
From 7e61a01a96f5eab7212dba754ac64fdfb4d9e8ab Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 30 Apr 2011 16:08:49 -0600
Subject: Change the name of the extensions helper to legal_file.
---
modules/gallery/helpers/legal_file.php | 39 ++++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
create mode 100644 modules/gallery/helpers/legal_file.php
diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php
new file mode 100644
index 00000000..2cb0fb25
--- /dev/null
+++ b/modules/gallery/helpers/legal_file.php
@@ -0,0 +1,39 @@
+extensions = array("gif", "jpg", "jpeg", "png");
+ if (movie::find_ffmpeg()) {
+ array_push($extensions_wrapper->extensions, "flv", "mp4", "m4v");
+ }
+ module::event("legal_file_extensions", $extensions_wrapper);
+ return $extensions_wrapper->extensions;
+ }
+
+ static function get_filters() {
+ $filters = array();
+ foreach (self::get_extensions() as $extension) {
+ array_push($filters, "*." . $extension, "*." . strtoupper($extension));
+ }
+ return $filters;
+ }
+}
--
cgit v1.2.3
From a8ca9dcf9edd54633c0c78b3af76aa974d38fc64 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 30 Apr 2011 16:10:06 -0600
Subject: Change the name of the extensions helper to legal_file.
---
modules/gallery/controllers/uploader.php | 2 +-
modules/gallery/helpers/extensions.php | 39 ----------------------------
modules/gallery/libraries/Form_Uploadify.php | 2 +-
modules/gallery/models/item.php | 2 +-
4 files changed, 3 insertions(+), 42 deletions(-)
delete mode 100644 modules/gallery/helpers/extensions.php
diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php
index 5f3e9ca4..9c2bf7d7 100644
--- a/modules/gallery/controllers/uploader.php
+++ b/modules/gallery/controllers/uploader.php
@@ -51,7 +51,7 @@ class Uploader_Controller extends Controller {
$file_validation = new Validation($_FILES);
$file_validation->add_rules(
"Filedata", "upload::valid", "upload::required",
- "upload::type[" . implode(",", extensions::get_upload_extensions()) . "]");
+ "upload::type[" . implode(",", legal_file::get_extensions()) . "]");
if ($form->validate() && $file_validation->validate()) {
$temp_filename = upload::save("Filedata");
diff --git a/modules/gallery/helpers/extensions.php b/modules/gallery/helpers/extensions.php
deleted file mode 100644
index bccbfc41..00000000
--- a/modules/gallery/helpers/extensions.php
+++ /dev/null
@@ -1,39 +0,0 @@
-extensions = array("gif", "jpg", "jpeg", "png");
- if (movie::find_ffmpeg()) {
- array_push($extensions_wrapper->extensions, "flv", "mp4", "m4v");
- }
- module::event("upload_extensions", $extensions_wrapper);
- return $extensions_wrapper->extensions;
- }
-
- static function get_upload_filters() {
- $filters = array();
- foreach (self::get_upload_extensions() as $extension) {
- array_push($filters, "*." . $extension, "*." . strtoupper($extension));
- }
- return $filters;
- }
-}
diff --git a/modules/gallery/libraries/Form_Uploadify.php b/modules/gallery/libraries/Form_Uploadify.php
index 884653e2..450320b3 100644
--- a/modules/gallery/libraries/Form_Uploadify.php
+++ b/modules/gallery/libraries/Form_Uploadify.php
@@ -47,7 +47,7 @@ class Form_Uploadify_Core extends Form_Input {
$v->script_data = $this->data["script_data"];
$v->simultaneous_upload_limit = module::get_var("gallery", "simultaneous_upload_limit");
$v->movies_allowed = (bool) movie::find_ffmpeg();
- $v->extensions = extensions::get_upload_filters();
+ $v->extensions = legal_file::get_filters();
$v->suhosin_session_encrypt = (bool) ini_get("suhosin.session.encrypt");
list ($toolkit_max_filesize_bytes, $toolkit_max_filesize) = graphics::max_filesize();
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 5ccbe75c..27b821f3 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -804,7 +804,7 @@ class Item_Model_Core extends ORM_MPTT {
if (($this->is_movie() || $this->is_photo()) &&
!preg_match("/^(" .
implode("|", array_map("preg_quote",
- extensions::get_upload_extensions())) .
+ legal_file::get_extensions())) .
")\$/i", $ext)) {
$v->add_error("name", "illegal_data_file_extension");
}
--
cgit v1.2.3
From 2375a02e2cdbd1ccaf7dc4d3db9d85119972e3a9 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 30 Apr 2011 16:40:55 -0600
Subject: Change the signature of system::tempnam to something more appropriate
for Gallery.
---
modules/gallery/controllers/quick.php | 4 ++--
modules/gallery/helpers/system.php | 13 ++++++++-----
modules/gallery/tests/System_Helper_Test.php | 5 +++--
3 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php
index ce52cb8d..b6576ec0 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -36,8 +36,8 @@ class Quick_Controller extends Controller {
}
if ($degrees) {
- $tmpfile = system::tempnam(TMPPATH, "rotate",
- "." . pathinfo($item->file_path(), PATHINFO_EXTENSION));
+ $tmpfile = system::temp_filename("rotate",
+ pathinfo($item->file_path(), PATHINFO_EXTENSION));
gallery_graphics::rotate($item->file_path(), $tmpfile, array("degrees" => $degrees), $item);
$item->set_data_file($tmpfile);
$item->save();
diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php
index 31ecafa7..9815d588 100644
--- a/modules/gallery/helpers/system.php
+++ b/modules/gallery/helpers/system.php
@@ -43,15 +43,18 @@ class system_Core {
/**
* Create a file with a unique file name.
- * This helper is similar to the built-in tempnam, except that it supports an optional postfix.
+ * This helper is similar to the built-in tempnam.
+ * It allows the caller to specify a prefix and an extension.
+ * It always places the file in TMPPATH.
*/
- static function tempnam($dir = TMPPATH, $prefix = "", $postfix = "") {
- return self::_tempnam($dir, $prefix, $postfix, "tempnam");
+ static function temp_filename($prefix = "", $extension = "") {
+ return self::_tempnam(TMPPATH, $prefix, ".$extension", "tempnam");
}
- // This helper provides a dependency-injected implementation of tempnam.
+ /**
+ * This helper provides a dependency-injected implementation of tempnam.
+ */
static function _tempnam($dir, $prefix, $postfix, $builtin) {
- $success = false;
do {
$basename = call_user_func($builtin, $dir, $prefix);
if (!$basename) {
diff --git a/modules/gallery/tests/System_Helper_Test.php b/modules/gallery/tests/System_Helper_Test.php
index 734f98ac..dfe5d9ab 100644
--- a/modules/gallery/tests/System_Helper_Test.php
+++ b/modules/gallery/tests/System_Helper_Test.php
@@ -18,10 +18,11 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class System_Helper_Test extends Gallery_Unit_Test_Case {
- public function tempnam_random_test() {
- $filename = system::tempnam(TMPPATH, "file", ".ext");
+ public function temp_filename_random_test() {
+ $filename = system::temp_filename("file", "ext");
$this->assert_true(file_exists($filename), "File not created");
unlink($filename);
+ $this->assert_pattern($filename, "|/file.*\\.ext$|");
}
public function tempnam_collision_test() {
--
cgit v1.2.3
From c3e8c1e3b5e3cb1046acd4c923bb0ae9dbcd603a Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 30 Apr 2011 18:12:56 -0600
Subject: The data_file field is public, so we don't need to supply an accessor
method.
---
modules/gallery/models/item.php | 9 ---------
1 file changed, 9 deletions(-)
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 27b821f3..22634cbf 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -127,15 +127,6 @@ class Item_Model_Core extends ORM_MPTT {
return $this;
}
- /**
- * Get the path to the data file associated with this item.
- * This data file field is only set until you call save().
- * After that, you can get the path using get_file_path().
- */
- public function get_data_file() {
- return $this->data_file;
- }
-
/**
* Return the server-relative url to this item, eg:
* /gallery3/index.php/BobsWedding?page=2
--
cgit v1.2.3
From 1b3a6b85c156e4777d2aa8205b130984f55dc66d Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 30 Apr 2011 18:29:34 -0600
Subject: Improve the comment explaining why the data_file extension is
important.
---
modules/gallery/models/item.php | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 22634cbf..81830fb9 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -409,7 +409,11 @@ class Item_Model_Core extends ORM_MPTT {
// keep it around.
$original = ORM::factory("item", $this->id);
- // Preserve the extension of the data file.
+ // 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";
--
cgit v1.2.3
From f0f094c3f79b09536f58083681c28f73271c506d Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 30 Apr 2011 20:22:49 -0600
Subject: Explain the conditional rename in item::save() with a comment.
---
modules/gallery/models/item.php | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 81830fb9..807c88a7 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -443,11 +443,19 @@ class Item_Model_Core extends ORM_MPTT {
}
if ($original->parent_id != $this->parent_id || $original->name != $this->name) {
- // Move all of the items associated data files
$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
if ($this->is_album()) {
@rename(dirname($original->resize_path()), dirname($this->resize_path()));
@rename(dirname($original->thumb_path()), dirname($this->thumb_path()));
--
cgit v1.2.3
From d2d37fe3f2e550dff0c62afa9faa3100f305df0e Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Sat, 30 Apr 2011 21:33:20 -0600
Subject: Results from a round of feedback with Bharat.
Squashed commit of the following:
commit 13dbd3515bfb5324cfbcb3bbeafc179771b54f75
Merge: f0f094c 97400b7
Author: Chad Parry
Date: Sat Apr 30 20:33:02 2011 -0600
Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto
commit f0f094c3f79b09536f58083681c28f73271c506d
Author: Chad Parry
Date: Sat Apr 30 20:22:49 2011 -0600
Explain the conditional rename in item::save() with a comment.
commit 1b3a6b85c156e4777d2aa8205b130984f55dc66d
Author: Chad Parry
Date: Sat Apr 30 18:29:34 2011 -0600
Improve the comment explaining why the data_file extension is important.
commit c3e8c1e3b5e3cb1046acd4c923bb0ae9dbcd603a
Author: Chad Parry
Date: Sat Apr 30 18:12:56 2011 -0600
The data_file field is public, so we don't need to supply an accessor method.
commit 2375a02e2cdbd1ccaf7dc4d3db9d85119972e3a9
Author: Chad Parry
Date: Sat Apr 30 16:40:55 2011 -0600
Change the signature of system::tempnam to something more appropriate for Gallery.
commit a8ca9dcf9edd54633c0c78b3af76aa974d38fc64
Author: Chad Parry
Date: Sat Apr 30 16:10:06 2011 -0600
Change the name of the extensions helper to legal_file.
commit 7e61a01a96f5eab7212dba754ac64fdfb4d9e8ab
Author: Chad Parry
Date: Sat Apr 30 16:08:49 2011 -0600
Change the name of the extensions helper to legal_file.
commit 4c2b2ebd3f2052898fbfb175650ed4cf49c8006e
Author: Chad Parry
Date: Wed Apr 27 20:52:35 2011 -0600
Remove a newline at the end of the file that I accidentally introduced.
commit 6d564f185e5279d6cca9a7385066514ff18a2455
Merge: 7ff485f 4060640
Author: Chad Parry
Date: Wed Apr 27 20:35:58 2011 -0600
Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto
commit 7ff485fa48c392bbbb0370f67cb1bd6fcc00c2a4
Author: Chad Parry
Date: Wed Apr 27 20:29:06 2011 -0600
Move the extensions helpers out of the Kohana system directory and into their own Gallery Extensions class.
commit 26585fed03236f0f70a75959e1d3002025f4e15e
Merge: 809567f c8f90e8
Author: Chad Parry
Date: Sun Apr 24 08:28:39 2011 -0600
Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto
commit 809567f12850f59bdeb47a2963f6968b99b5a201
Author: Chad Parry
Date: Sun Apr 24 08:10:04 2011 -0600
Expose the data file field.
commit fcb06bf175bb9eeff36d9c294e97ace9374ef0f3
Author: Chad Parry
Date: Sun Apr 24 00:45:12 2011 -0600
Don't assign to the item->name field if the name is unchanged, because the save method will crash.
commit c6ef706d70c7e48bea1145eec1b13fb5683e023f
Author: Chad Parry
Date: Sat Apr 23 22:55:59 2011 -0600
Preserve old data files long enough for them to be available to event handlers.
commit 0d6a3a3cfc4f38f450db9e18da47a5e2ad826af8
Author: Chad Parry
Date: Sat Apr 23 21:19:47 2011 -0600
Create a tempnam substitute that safely creates files with a given extension.
commit e149cf7238a1f8eaddfc68580f2d636dd8255795
Author: Chad Parry
Date: Sat Apr 23 16:39:25 2011 -0600
Support data files that change their extension and MIME type.
commit 6702104f571413e4d57db3515b2070c48d3e9b55
Author: Chad Parry
Date: Sat Apr 23 16:35:00 2011 -0600
Resolve an infinite recursion that happens when the path caches are updated during saving.
commit 944cb72eea946f4c45a04b7e4c7c33929fa8b9f3
Merge: 567522b 5af74d4
Author: Chad Parry
Date: Fri Apr 22 14:10:42 2011 -0600
Merge remote branch 'origin/master' into rawphoto
commit 567522bfa08c370bb5baf8454afc5b04bc9e49b4
Author: Chad Parry
Date: Thu Apr 21 20:12:32 2011 -0600
Add an event for when a new graphics toolkit is chosen.
commit 31ba081b793141ca36866a6dd349cd2eac5af68e
Author: Chad Parry
Date: Thu Apr 21 02:06:53 2011 -0600
Add an event that will collect all valid filename extensions.
---
modules/gallery/controllers/quick.php | 4 +--
modules/gallery/controllers/uploader.php | 2 +-
modules/gallery/helpers/legal_file.php | 39 ++++++++++++++++++++++++++++
modules/gallery/helpers/system.php | 13 ++++++----
modules/gallery/libraries/Form_Uploadify.php | 2 +-
modules/gallery/models/item.php | 18 ++++++++++---
modules/gallery/tests/System_Helper_Test.php | 5 ++--
7 files changed, 69 insertions(+), 14 deletions(-)
create mode 100644 modules/gallery/helpers/legal_file.php
diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php
index ce52cb8d..b6576ec0 100644
--- a/modules/gallery/controllers/quick.php
+++ b/modules/gallery/controllers/quick.php
@@ -36,8 +36,8 @@ class Quick_Controller extends Controller {
}
if ($degrees) {
- $tmpfile = system::tempnam(TMPPATH, "rotate",
- "." . pathinfo($item->file_path(), PATHINFO_EXTENSION));
+ $tmpfile = system::temp_filename("rotate",
+ pathinfo($item->file_path(), PATHINFO_EXTENSION));
gallery_graphics::rotate($item->file_path(), $tmpfile, array("degrees" => $degrees), $item);
$item->set_data_file($tmpfile);
$item->save();
diff --git a/modules/gallery/controllers/uploader.php b/modules/gallery/controllers/uploader.php
index 5f3e9ca4..9c2bf7d7 100644
--- a/modules/gallery/controllers/uploader.php
+++ b/modules/gallery/controllers/uploader.php
@@ -51,7 +51,7 @@ class Uploader_Controller extends Controller {
$file_validation = new Validation($_FILES);
$file_validation->add_rules(
"Filedata", "upload::valid", "upload::required",
- "upload::type[" . implode(",", extensions::get_upload_extensions()) . "]");
+ "upload::type[" . implode(",", legal_file::get_extensions()) . "]");
if ($form->validate() && $file_validation->validate()) {
$temp_filename = upload::save("Filedata");
diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php
new file mode 100644
index 00000000..2cb0fb25
--- /dev/null
+++ b/modules/gallery/helpers/legal_file.php
@@ -0,0 +1,39 @@
+extensions = array("gif", "jpg", "jpeg", "png");
+ if (movie::find_ffmpeg()) {
+ array_push($extensions_wrapper->extensions, "flv", "mp4", "m4v");
+ }
+ module::event("legal_file_extensions", $extensions_wrapper);
+ return $extensions_wrapper->extensions;
+ }
+
+ static function get_filters() {
+ $filters = array();
+ foreach (self::get_extensions() as $extension) {
+ array_push($filters, "*." . $extension, "*." . strtoupper($extension));
+ }
+ return $filters;
+ }
+}
diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php
index 31ecafa7..9815d588 100644
--- a/modules/gallery/helpers/system.php
+++ b/modules/gallery/helpers/system.php
@@ -43,15 +43,18 @@ class system_Core {
/**
* Create a file with a unique file name.
- * This helper is similar to the built-in tempnam, except that it supports an optional postfix.
+ * This helper is similar to the built-in tempnam.
+ * It allows the caller to specify a prefix and an extension.
+ * It always places the file in TMPPATH.
*/
- static function tempnam($dir = TMPPATH, $prefix = "", $postfix = "") {
- return self::_tempnam($dir, $prefix, $postfix, "tempnam");
+ static function temp_filename($prefix = "", $extension = "") {
+ return self::_tempnam(TMPPATH, $prefix, ".$extension", "tempnam");
}
- // This helper provides a dependency-injected implementation of tempnam.
+ /**
+ * This helper provides a dependency-injected implementation of tempnam.
+ */
static function _tempnam($dir, $prefix, $postfix, $builtin) {
- $success = false;
do {
$basename = call_user_func($builtin, $dir, $prefix);
if (!$basename) {
diff --git a/modules/gallery/libraries/Form_Uploadify.php b/modules/gallery/libraries/Form_Uploadify.php
index 884653e2..450320b3 100644
--- a/modules/gallery/libraries/Form_Uploadify.php
+++ b/modules/gallery/libraries/Form_Uploadify.php
@@ -47,7 +47,7 @@ class Form_Uploadify_Core extends Form_Input {
$v->script_data = $this->data["script_data"];
$v->simultaneous_upload_limit = module::get_var("gallery", "simultaneous_upload_limit");
$v->movies_allowed = (bool) movie::find_ffmpeg();
- $v->extensions = extensions::get_upload_filters();
+ $v->extensions = legal_file::get_filters();
$v->suhosin_session_encrypt = (bool) ini_get("suhosin.session.encrypt");
list ($toolkit_max_filesize_bytes, $toolkit_max_filesize) = graphics::max_filesize();
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 5ccbe75c..6eb93cfa 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -418,7 +418,11 @@ class Item_Model_Core extends ORM_MPTT {
// keep it around.
$original = ORM::factory("item", $this->id);
- // Preserve the extension of the data file.
+ // 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";
@@ -448,11 +452,19 @@ class Item_Model_Core extends ORM_MPTT {
}
if ($original->parent_id != $this->parent_id || $original->name != $this->name) {
- // Move all of the items associated data files
$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
if ($this->is_album()) {
@rename(dirname($original->resize_path()), dirname($this->resize_path()));
@rename(dirname($original->thumb_path()), dirname($this->thumb_path()));
@@ -804,7 +816,7 @@ class Item_Model_Core extends ORM_MPTT {
if (($this->is_movie() || $this->is_photo()) &&
!preg_match("/^(" .
implode("|", array_map("preg_quote",
- extensions::get_upload_extensions())) .
+ legal_file::get_extensions())) .
")\$/i", $ext)) {
$v->add_error("name", "illegal_data_file_extension");
}
diff --git a/modules/gallery/tests/System_Helper_Test.php b/modules/gallery/tests/System_Helper_Test.php
index 734f98ac..dfe5d9ab 100644
--- a/modules/gallery/tests/System_Helper_Test.php
+++ b/modules/gallery/tests/System_Helper_Test.php
@@ -18,10 +18,11 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class System_Helper_Test extends Gallery_Unit_Test_Case {
- public function tempnam_random_test() {
- $filename = system::tempnam(TMPPATH, "file", ".ext");
+ public function temp_filename_random_test() {
+ $filename = system::temp_filename("file", "ext");
$this->assert_true(file_exists($filename), "File not created");
unlink($filename);
+ $this->assert_pattern($filename, "|/file.*\\.ext$|");
}
public function tempnam_collision_test() {
--
cgit v1.2.3
From 72f3fc46f6c7c9043e730063051ecfd88bf314c8 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 4 May 2011 17:22:15 -0600
Subject: Avoid "self::" because Kohana can't override it.
---
modules/gallery/helpers/legal_file.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php
index 2cb0fb25..68403fa6 100644
--- a/modules/gallery/helpers/legal_file.php
+++ b/modules/gallery/helpers/legal_file.php
@@ -31,7 +31,7 @@ class legal_file_Core {
static function get_filters() {
$filters = array();
- foreach (self::get_extensions() as $extension) {
+ foreach (legal_file::get_extensions() as $extension) {
array_push($filters, "*." . $extension, "*." . strtoupper($extension));
}
return $filters;
--
cgit v1.2.3
From 5e62d327a8dc477d3edea99826183548aca3e7f3 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 18 May 2011 20:17:36 -0600
Subject: Expand the legal_file events to include separate photo and movie
events, and to support MIME types.
---
modules/gallery/helpers/legal_file.php | 36 ++++++++++++++++++++++++++++++----
modules/gallery/models/item.php | 15 ++++++++------
2 files changed, 41 insertions(+), 10 deletions(-)
diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php
index 68403fa6..5d10dffd 100644
--- a/modules/gallery/helpers/legal_file.php
+++ b/modules/gallery/helpers/legal_file.php
@@ -18,15 +18,28 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class legal_file_Core {
- static function get_extensions() {
+ static function get_photo_extensions() {
// Create a default list of allowed extensions and then let modules modify it.
$extensions_wrapper = new stdClass();
$extensions_wrapper->extensions = array("gif", "jpg", "jpeg", "png");
+ module::event("legal_photo_extensions", $extensions_wrapper);
+ return $extensions_wrapper->extensions;
+ }
+
+ static function get_movie_extensions() {
+ // Create a default list of allowed extensions and then let modules modify it.
+ $extensions_wrapper = new stdClass();
+ $extensions_wrapper->extensions = array("flv", "mp4", "m4v");
+ module::event("legal_movie_extensions", $extensions_wrapper);
+ return $extensions_wrapper->extensions;
+ }
+
+ static function get_extensions() {
+ $extensions = legal_file::get_photo_extensions();
if (movie::find_ffmpeg()) {
- array_push($extensions_wrapper->extensions, "flv", "mp4", "m4v");
+ array_push($extensions, legal_file::get_movie_extensions());
}
- module::event("legal_file_extensions", $extensions_wrapper);
- return $extensions_wrapper->extensions;
+ return $extensions;
}
static function get_filters() {
@@ -36,4 +49,19 @@ class legal_file_Core {
}
return $filters;
}
+
+ static function get_photo_types() {
+ // Create a default list of allowed types and then let modules modify it.
+ $types_wrapper = new stdClass();
+ module::event("legal_photo_types", $types_wrapper);
+ $types_wrapper->types = array("image/jpeg", "image/gif", "image/png");
+ }
+
+ static function get_movie_types() {
+ // Create a default list of allowed types and then let modules modify it.
+ $types_wrapper = new stdClass();
+ $types_wrapper->types = array("video/flv", "video/x-flv", "video/mp4");
+ module::event("legal_movie_types", $types_wrapper);
+ return $types_wrapper->types;
+ }
}
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 1704ff6e..1dd9b00b 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -804,10 +804,13 @@ class Item_Model_Core extends ORM_MPTT {
return;
}
- if (($this->is_movie() || $this->is_photo()) &&
+ if ($this->is_photo() &&
!preg_match("/^(" .
- implode("|", array_map("preg_quote",
- legal_file::get_extensions())) .
+ implode("|", array_map("preg_quote", legal_file::get_photo_extensions())) .
+ ")\$/i", $ext) ||
+ $this->is_movie() &&
+ !preg_match("/^(" .
+ implode("|", array_map("preg_quote", legal_file::get_movie_extensions())) .
")\$/i", $ext)) {
$v->add_error("name", "illegal_data_file_extension");
}
@@ -887,9 +890,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;
--
cgit v1.2.3
From e9862d8fbc4d6fd06abf157f48dce671a7283993 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 18 May 2011 20:20:19 -0600
Subject: Correction for the merge conflict markers I accidentally committed.
---
modules/gallery/helpers/system.php | 17 ----------------
modules/gallery/tests/System_Helper_Test.php | 30 ----------------------------
2 files changed, 47 deletions(-)
diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php
index d2e9c125..4110b4ed 100644
--- a/modules/gallery/helpers/system.php
+++ b/modules/gallery/helpers/system.php
@@ -47,22 +47,6 @@ class system_Core {
* It allows the caller to specify a prefix and an extension.
* It always places the file in TMPPATH.
*/
-<<<<<<< HEAD
- static function temp_filename($prefix = "", $extension = "") {
- return self::_tempnam(TMPPATH, $prefix, ".$extension", "tempnam");
- }
-
- /**
- * This helper provides a dependency-injected implementation of tempnam.
- */
- static function _tempnam($dir, $prefix, $postfix, $builtin) {
- do {
- $basename = call_user_func($builtin, $dir, $prefix);
- if (!$basename) {
- return false;
- }
- $filename = $basename . $postfix;
-=======
static function temp_filename($prefix="", $extension="") {
do {
$basename = tempnam(TMPPATH, $prefix);
@@ -70,7 +54,6 @@ class system_Core {
return false;
}
$filename = "$basename.$extension";
->>>>>>> db734130c5fe10408040b2326b28b102f3131271
$success = !file_exists($filename) && @rename($basename, $filename);
if (!$success) {
@unlink($basename);
diff --git a/modules/gallery/tests/System_Helper_Test.php b/modules/gallery/tests/System_Helper_Test.php
index 4b395799..3d56c516 100644
--- a/modules/gallery/tests/System_Helper_Test.php
+++ b/modules/gallery/tests/System_Helper_Test.php
@@ -18,40 +18,10 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class System_Helper_Test extends Gallery_Unit_Test_Case {
-<<<<<<< HEAD
- public function temp_filename_random_test() {
-=======
public function temp_filename_test() {
->>>>>>> db734130c5fe10408040b2326b28b102f3131271
$filename = system::temp_filename("file", "ext");
$this->assert_true(file_exists($filename), "File not created");
unlink($filename);
$this->assert_pattern($filename, "|/file.*\\.ext$|");
}
-<<<<<<< HEAD
-
- public function tempnam_collision_test() {
- require_once('Mock_Built_In.php');
- $existing = TMPPATH . "/file1.ext";
- $available = TMPPATH . "/file2.ext";
- touch($existing);
- $filename = system::_tempnam(TMPPATH, "file", ".ext",
- array(new Mock_Built_In("1", "2"), "_tempnam"));
- unlink($existing);
- $this->assert_true(file_exists($filename), "File not created");
- unlink($filename);
- $this->assert_equal($available, $filename, "Incorrect filename created");
- }
-
- public function tempnam_abort_test() {
- require_once('Mock_Built_In.php');
- $filename = system::_tempnam(TMPPATH, "file", ".ext",
- array(new Mock_Built_In(), "_tempnam"));
- if ($filename) {
- @unlink($filename);
- }
- $this->assert_false($filename, "Operation not aborted");
- }
-=======
->>>>>>> db734130c5fe10408040b2326b28b102f3131271
}
--
cgit v1.2.3
From 4e3964527b66d8ccd76fb261d549cd9861a7a780 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 18 May 2011 20:30:28 -0600
Subject: Initialize legal file arrays correctly.
---
modules/gallery/helpers/legal_file.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php
index 5d10dffd..0d3e9728 100644
--- a/modules/gallery/helpers/legal_file.php
+++ b/modules/gallery/helpers/legal_file.php
@@ -37,7 +37,7 @@ class legal_file_Core {
static function get_extensions() {
$extensions = legal_file::get_photo_extensions();
if (movie::find_ffmpeg()) {
- array_push($extensions, legal_file::get_movie_extensions());
+ $extensions = array_merge($extensions, legal_file::get_movie_extensions());
}
return $extensions;
}
@@ -53,8 +53,9 @@ class legal_file_Core {
static function get_photo_types() {
// Create a default list of allowed types and then let modules modify it.
$types_wrapper = new stdClass();
- module::event("legal_photo_types", $types_wrapper);
$types_wrapper->types = array("image/jpeg", "image/gif", "image/png");
+ module::event("legal_photo_types", $types_wrapper);
+ return $types_wrapper->types;
}
static function get_movie_types() {
--
cgit v1.2.3
From e06b20738d0e0bdb80bae68b7fec2b3746192f6e Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 18 May 2011 21:10:08 -0600
Subject: Adding an image representing a broken thumbnail. This image was
derived from the equivalent Gallery2 icon. It uses the same washed-out gray
color scheme as the Gallery3 missing_movie icon.
---
modules/gallery/images/missing_photo.png | Bin 0 -> 1570 bytes
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 modules/gallery/images/missing_photo.png
diff --git a/modules/gallery/images/missing_photo.png b/modules/gallery/images/missing_photo.png
new file mode 100644
index 00000000..67786275
Binary files /dev/null and b/modules/gallery/images/missing_photo.png differ
--
cgit v1.2.3
From f2336a5aaa0eb797f252388ecd7b93a82f9646fd Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 18 May 2011 21:56:10 -0600
Subject: Behave reasonably if the image cannot be resized.
---
modules/gallery/helpers/graphics.php | 22 ++++++++++++++++++----
1 file changed, 18 insertions(+), 4 deletions(-)
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index acb11bfb..3b9769de 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -170,23 +170,37 @@ class graphics_Core {
foreach (self::_get_rules($target) as $rule) {
$args = array($working_file, $output_file, unserialize($rule->args), $item);
- call_user_func_array($rule->operation, $args);
- $working_file = $output_file;
+ try {
+ call_user_func_array($rule->operation, $args);
+ $working_file = $output_file;
+ } catch (Exception $e) {
+ // Ignore this filter and move on.
+ Kohana_Log::add("error", "Caught exception filtering image: {$item->title}\n" .
+ $e->getMessage() . "\n" . $e->getTraceAsString());
+ }
}
}
if (!empty($ops["thumb"])) {
+ if (file_exists($item->thumb_path())) {
+ $item->thumb_dirty = 0;
+ } else {
+ copy(MODPATH . "gallery/images/missing_photo.png", $item->thumb_path());
+ }
$dims = getimagesize($item->thumb_path());
$item->thumb_width = $dims[0];
$item->thumb_height = $dims[1];
- $item->thumb_dirty = 0;
}
if (!empty($ops["resize"])) {
+ if (file_exists($item->resize_path())) {
+ $item->resize_dirty = 0;
+ } else {
+ copy(MODPATH . "gallery/images/missing_photo.png", $item->resize_path());
+ }
$dims = getimagesize($item->resize_path());
$item->resize_width = $dims[0];
$item->resize_height = $dims[1];
- $item->resize_dirty = 0;
}
$item->save();
} catch (Exception $e) {
--
cgit v1.2.3
From 97c3ded2bae24fa18801c94548d1cfd97e19cf2a Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 18 May 2011 22:01:51 -0600
Subject: Better validation for uploaded files, especially where third-party
modules might make a mistake.
Squashed commit of the following:
commit f2336a5aaa0eb797f252388ecd7b93a82f9646fd
Author: Chad Parry
Date: Wed May 18 21:56:10 2011 -0600
Behave reasonably if the image cannot be resized.
commit e06b20738d0e0bdb80bae68b7fec2b3746192f6e
Author: Chad Parry
Date: Wed May 18 21:10:08 2011 -0600
Adding an image representing a broken thumbnail.
This image was derived from the equivalent Gallery2 icon. It uses the same washed-out gray color scheme as the Gallery3 missing_movie icon.
commit 4e3964527b66d8ccd76fb261d549cd9861a7a780
Author: Chad Parry
Date: Wed May 18 20:30:28 2011 -0600
Initialize legal file arrays correctly.
commit e9862d8fbc4d6fd06abf157f48dce671a7283993
Author: Chad Parry
Date: Wed May 18 20:20:19 2011 -0600
Correction for the merge conflict markers I accidentally committed.
commit 5e62d327a8dc477d3edea99826183548aca3e7f3
Author: Chad Parry
Date: Wed May 18 20:17:36 2011 -0600
Expand the legal_file events to include separate photo and movie events, and to support MIME types.
commit f0bfd1fef0b6d17da9a491f7c724ae53491926a2
Merge: 72f3fc4 db73413
Author: Chad Parry
Date: Wed May 18 19:49:25 2011 -0600
Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto
Conflicts:
modules/gallery/helpers/system.php
modules/gallery/tests/System_Helper_Test.php
commit db734130c5fe10408040b2326b28b102f3131271
Author: Automatic Build Number Updater
Date: Mon May 16 21:38:07 2011 -0700
Automated update of .build_number to 153 for branch master
Last update: 9aeb824aa1d15bd94bd7cef0a322c4e8a667e67b (1 commits ago)
commit 8549ba30ca5045211d2efcf8e1c4f98f8a1e9f25
Author: Chad Kieffer
Date: Mon May 16 22:37:09 2011 -0600
Stop IE 9 album grid craziness. Thanks floridave. Fixes #1430.
commit 9aeb824aa1d15bd94bd7cef0a322c4e8a667e67b
Author: Automatic Build Number Updater
Date: Sun May 8 11:43:38 2011 -0700
Automated update of .build_number to 152 for branch master
Last update: 7c80e6ef84b460dcade80c4dd5a65b41b0523505 (1 commits ago)
commit 57f7e42a128848d73ad2a7ac0bf9df2fee6ba8b8
Author: Bharat Mediratta
Date: Sun May 8 11:42:40 2011 -0700
Add the item id to the print_proxy line so that we have a little more info
about what the original was, and extend the timeout to 90 days from 10.
Fixes #1733.
commit 7c80e6ef84b460dcade80c4dd5a65b41b0523505
Author: Automatic Build Number Updater
Date: Fri May 6 11:48:43 2011 -0700
Automated update of .build_number to 151 for branch master
Last update: 5d09cbff048fc2f457c8b19adb2177a12445890a (1 commits ago)
commit 80dda6f64fd26f373cc138a199652099accceb26
Merge: 5d09cbf 46da011
Author: Bharat Mediratta
Date: Fri May 6 11:48:13 2011 -0700
Merge pull request #52 from chadparry/tempnam
Fixes #1732
commit 5d09cbff048fc2f457c8b19adb2177a12445890a
Author: Automatic Build Number Updater
Date: Thu May 5 21:53:39 2011 -0700
Automated update of .build_number to 150 for branch master
Last update: 011eaa6480cbee8d328a31c9ac5c8e0ddc1f8a84 (1 commits ago)
commit d5a31ceedee5841531f57342266746bb62d7d923
Author: Tim Almdal
Date: Thu May 5 21:53:10 2011 -0700
Fix for ticket 1275. Do the same checking as Kohana uses and don't worry about calling the utf8_encode routine.
Corrected the error messages and also added a check to insure the XML Parser extension is loaded as we still need the utf8_encode function from it.
commit 011eaa6480cbee8d328a31c9ac5c8e0ddc1f8a84
Author: Automatic Build Number Updater
Date: Thu May 5 14:53:06 2011 -0700
Automated update of .build_number to 149 for branch master
Last update: 05ecfda36b7acee7f8d36df8391ba960097178a8 (1 commits ago)
commit 5bae21864f54a03b557ab349cf97ba5f1d4276dc
Author: Bharat Mediratta
Date: Thu May 5 14:52:47 2011 -0700
Follow-on to 6f916e49d5b431c2c1961a13d1a61fef8c02d628 -- don't make
database calls if Gallery isn't installed, else we fail to bounce the
user to the installer on fresh packages. #1637.
commit 46da011bf69bbc4e45757feda8f0d28e91e7fb6a
Author: Chad Parry
Date: Wed May 4 17:51:00 2011 -0600
Remove a newline I accidentally introduced.
commit 5c6c71ffcdea354b5b9b30aaea2c1f92c8860d42
Merge: d2331bf 05ecfda
Author: Chad Parry
Date: Wed May 4 17:49:42 2011 -0600
Merge branch 'master' into tempnam
commit d2331bf43457a8d33491921f106879f087438171
Author: Chad Parry
Date: Wed May 4 17:48:25 2011 -0600
Simplified the temp_filename implementation and removed the mocks.
commit 72f3fc46f6c7c9043e730063051ecfd88bf314c8
Author: Chad Parry
Date: Wed May 4 17:22:15 2011 -0600
Avoid "self::" because Kohana can't override it.
commit 05ecfda36b7acee7f8d36df8391ba960097178a8
Author: Automatic Build Number Updater
Date: Mon May 2 21:38:50 2011 -0700
Automated update of .build_number to 148 for branch master
Last update: 97400b78153620262120868b37545170416413c9 (2 commits ago)
commit 229bfc5c7c760c53d1357503fd61bf9a165acf6e
Author: Bharat Mediratta
Date: Mon May 2 21:37:04 2011 -0700
Track and redirect core.DownloadItem requests properly. This can
happen if the G2 was imported with rewrite on, so the g2_url in the
g2_map table has a shortened url, but then rewrite is disabled and the
.htaccess mod_rewrite rules are sending over a &g2_view=core.DownloadItem
request. Fixes #1728.
commit 68370b92f5f6fa68744655f8c68b4b0ca59bf4fd
Author: Bharat Mediratta
Date: Mon May 2 21:36:17 2011 -0700
Map the G2 album highlight thumbnail derivative id to the G3 album's
thumbnail. Fixes #1729.
commit 13dbd3515bfb5324cfbcb3bbeafc179771b54f75
Merge: f0f094c 97400b7
Author: Chad Parry
Date: Sat Apr 30 20:33:02 2011 -0600
Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto
commit f0f094c3f79b09536f58083681c28f73271c506d
Author: Chad Parry
Date: Sat Apr 30 20:22:49 2011 -0600
Explain the conditional rename in item::save() with a comment.
commit 1b3a6b85c156e4777d2aa8205b130984f55dc66d
Author: Chad Parry
Date: Sat Apr 30 18:29:34 2011 -0600
Improve the comment explaining why the data_file extension is important.
commit c3e8c1e3b5e3cb1046acd4c923bb0ae9dbcd603a
Author: Chad Parry
Date: Sat Apr 30 18:12:56 2011 -0600
The data_file field is public, so we don't need to supply an accessor method.
commit 0e844766baf3b3875cbb2d84579626e05e879420
Author: Chad Parry
Date: Sat Apr 30 16:40:55 2011 -0600
Change the signature of system::tempnam to something more appropriate for Gallery.
commit 5c9a3b3f39f6ff0d5c84c2cf283d27eaebe2e66e
Author: Chad Parry
Date: Sat Apr 23 21:19:47 2011 -0600
Create a tempnam substitute that safely creates files with a given extension.
commit 2375a02e2cdbd1ccaf7dc4d3db9d85119972e3a9
Author: Chad Parry
Date: Sat Apr 30 16:40:55 2011 -0600
Change the signature of system::tempnam to something more appropriate for Gallery.
commit a8ca9dcf9edd54633c0c78b3af76aa974d38fc64
Author: Chad Parry
Date: Sat Apr 30 16:10:06 2011 -0600
Change the name of the extensions helper to legal_file.
commit 7e61a01a96f5eab7212dba754ac64fdfb4d9e8ab
Author: Chad Parry
Date: Sat Apr 30 16:08:49 2011 -0600
Change the name of the extensions helper to legal_file.
commit 4c2b2ebd3f2052898fbfb175650ed4cf49c8006e
Author: Chad Parry
Date: Wed Apr 27 20:52:35 2011 -0600
Remove a newline at the end of the file that I accidentally introduced.
commit 6d564f185e5279d6cca9a7385066514ff18a2455
Merge: 7ff485f 4060640
Author: Chad Parry
Date: Wed Apr 27 20:35:58 2011 -0600
Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto
commit 7ff485fa48c392bbbb0370f67cb1bd6fcc00c2a4
Author: Chad Parry
Date: Wed Apr 27 20:29:06 2011 -0600
Move the extensions helpers out of the Kohana system directory and into their own Gallery Extensions class.
commit 26585fed03236f0f70a75959e1d3002025f4e15e
Merge: 809567f c8f90e8
Author: Chad Parry
Date: Sun Apr 24 08:28:39 2011 -0600
Merge branch 'master' of https://github.com/gallery/gallery3 into rawphoto
commit 809567f12850f59bdeb47a2963f6968b99b5a201
Author: Chad Parry
Date: Sun Apr 24 08:10:04 2011 -0600
Expose the data file field.
commit fcb06bf175bb9eeff36d9c294e97ace9374ef0f3
Author: Chad Parry
Date: Sun Apr 24 00:45:12 2011 -0600
Don't assign to the item->name field if the name is unchanged, because the save method will crash.
commit c6ef706d70c7e48bea1145eec1b13fb5683e023f
Author: Chad Parry
Date: Sat Apr 23 22:55:59 2011 -0600
Preserve old data files long enough for them to be available to event handlers.
commit 0d6a3a3cfc4f38f450db9e18da47a5e2ad826af8
Author: Chad Parry
Date: Sat Apr 23 21:19:47 2011 -0600
Create a tempnam substitute that safely creates files with a given extension.
commit e149cf7238a1f8eaddfc68580f2d636dd8255795
Author: Chad Parry
Date: Sat Apr 23 16:39:25 2011 -0600
Support data files that change their extension and MIME type.
commit 6702104f571413e4d57db3515b2070c48d3e9b55
Author: Chad Parry
Date: Sat Apr 23 16:35:00 2011 -0600
Resolve an infinite recursion that happens when the path caches are updated during saving.
commit 944cb72eea946f4c45a04b7e4c7c33929fa8b9f3
Merge: 567522b 5af74d4
Author: Chad Parry
Date: Fri Apr 22 14:10:42 2011 -0600
Merge remote branch 'origin/master' into rawphoto
commit 567522bfa08c370bb5baf8454afc5b04bc9e49b4
Author: Chad Parry
Date: Thu Apr 21 20:12:32 2011 -0600
Add an event for when a new graphics toolkit is chosen.
commit 31ba081b793141ca36866a6dd349cd2eac5af68e
Author: Chad Parry
Date: Thu Apr 21 02:06:53 2011 -0600
Add an event that will collect all valid filename extensions.
---
.build_number | 2 +-
installer/installer.php | 10 +++++--
modules/digibug/controllers/digibug.php | 6 ++---
modules/g2_import/controllers/g2.php | 4 ++-
modules/g2_import/helpers/g2_import.php | 7 ++++-
modules/gallery/config/locale.php | 7 ++++-
modules/gallery/helpers/graphics.php | 22 ++++++++++++---
modules/gallery/helpers/legal_file.php | 39 +++++++++++++++++++++++----
modules/gallery/helpers/system.php | 13 +++------
modules/gallery/images/missing_photo.png | Bin 0 -> 1570 bytes
modules/gallery/models/item.php | 15 ++++++-----
modules/gallery/tests/System_Helper_Test.php | 25 +----------------
themes/wind/js/ui.init.js | 2 +-
13 files changed, 93 insertions(+), 59 deletions(-)
create mode 100644 modules/gallery/images/missing_photo.png
diff --git a/.build_number b/.build_number
index 1bdd507d..190e1781 100644
--- a/.build_number
+++ b/.build_number
@@ -3,4 +3,4 @@
; process. You don't need to edit it. In fact..
;
; DO NOT EDIT THIS FILE BY HAND!
-build_number=147
+build_number=153
diff --git a/installer/installer.php b/installer/installer.php
index c23d918f..0bef57ae 100644
--- a/installer/installer.php
+++ b/installer/installer.php
@@ -191,8 +191,10 @@ class installer {
$errors[] = "Gallery 3 requires a MySQL database, but PHP doesn't have either the MySQL or the MySQLi extension.";
}
- if (!@preg_match("/^.$/u", utf8_encode("\xF1"))) {
- $errors[] = "PHP is missing Perl-Compatible Regular Expression support.";
+ if (!preg_match("/^.$/u", "ñ")) {
+ $errors[] = "PHP is missing Perl-Compatible Regular Expression with UTF-8 support.";
+ } else if (!preg_match("/^\pL$/u", "ñ")) {
+ $errors[] = "PHP is missing Perl-Compatible Regular Expression with Unicode support.";
}
if (!(function_exists("spl_autoload_register"))) {
@@ -211,6 +213,10 @@ class installer {
$errors[] = "PHP is missing the iconv extension";
}
+ if (!(extension_loaded("xml"))) {
+ $errors[] = "PHP is missing the XML Parser extension";
+ }
+
if (!(extension_loaded("simplexml"))) {
$errors[] = "PHP is missing the SimpleXML extension";
}
diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php
index 4acb6513..672afe57 100644
--- a/modules/digibug/controllers/digibug.php
+++ b/modules/digibug/controllers/digibug.php
@@ -33,8 +33,8 @@ class Digibug_Controller extends Controller {
$proxy->uuid = random::hash();
$proxy->item_id = $item->id;
$proxy->save();
- $full_url = url::abs_site("digibug/print_proxy/full/$proxy->uuid");
- $thumb_url = url::abs_site("digibug/print_proxy/thumb/$proxy->uuid");
+ $full_url = url::abs_site("digibug/print_proxy/full/$proxy->uuid/$item->id");
+ $thumb_url = url::abs_site("digibug/print_proxy/thumb/$proxy->uuid/$item->id");
}
$v = new View("digibug_form.html");
@@ -114,7 +114,7 @@ class Digibug_Controller extends Controller {
private function _clean_expired() {
db::build()
->delete("digibug_proxies")
- ->where("request_date", "<=", db::expr("(CURDATE() - INTERVAL 10 DAY)"))
+ ->where("request_date", "<=", db::expr("(CURDATE() - INTERVAL 90 DAY)"))
->limit(20)
->execute();
}
diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php
index 6e60bed0..90984e84 100644
--- a/modules/g2_import/controllers/g2.php
+++ b/modules/g2_import/controllers/g2.php
@@ -41,7 +41,9 @@ class G2_Controller extends Controller {
// (bbcode, embedding) people are using the id style URLs although URL rewriting is enabled.
$where = array(array("g2_id", "=", $id));
$view = $input->get("g2_view");
- if ($view) {
+ if ($view == "core.DownloadItem") {
+ $where[] = array("resource_type", "IN", array("file", "resize", "thumbnail", "full"));
+ } else if ($view) {
$where[] = array("g2_url", "like", "%g2_view=$view%");
} // else: Assuming that the first search hit is sufficiently good.
} else if ($path) {
diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php
index 3606c7ef..c79a8d36 100644
--- a/modules/g2_import/helpers/g2_import.php
+++ b/modules/g2_import/helpers/g2_import.php
@@ -560,7 +560,7 @@ class g2_import_Core {
$table = g2(GalleryCoreApi::fetchThumbnailsByItemIds(array($g2_album_id)));
if (isset($table[$g2_album_id])) {
// Backtrack the source id to an item
- $g2_source = $table[$g2_album_id];
+ $orig_g2_source = $g2_source = $table[$g2_album_id];
while (GalleryUtilities::isA($g2_source, "GalleryDerivative")) {
$g2_source = g2(GalleryCoreApi::loadEntitiesById($g2_source->getDerivativeSourceId()));
}
@@ -584,6 +584,11 @@ class g2_import_Core {
array("name" => $g3_album->name)),
$e);
}
+
+ self::set_map(
+ $orig_g2_source->getId(), $g3_album->id,
+ "thumbnail",
+ self::g2_url(array("view" => "core.DownloadItem", "itemId" => $orig_g2_source->getId())));
}
}
}
diff --git a/modules/gallery/config/locale.php b/modules/gallery/config/locale.php
index 13de9098..bce7fb49 100644
--- a/modules/gallery/config/locale.php
+++ b/modules/gallery/config/locale.php
@@ -32,7 +32,12 @@ $config['language'] = array('en_US', 'English_United States');
* Locale timezone. Set in 'Advanced' settings, falling back to the server's zone.
* @see http://php.net/timezones
*/
-$config['timezone'] = module::get_var("gallery", "timezone", date_default_timezone_get());
+if (file_exists(VARPATH . "database.php")) {
+ $config['timezone'] = module::get_var("gallery", "timezone", date_default_timezone_get());
+} else {
+ // Gallery3 is not installed yet -- don't make module::get_var() calls.
+ $config['timezone'] = date_default_timezone_get();
+}
// i18n settings
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index acb11bfb..3b9769de 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -170,23 +170,37 @@ class graphics_Core {
foreach (self::_get_rules($target) as $rule) {
$args = array($working_file, $output_file, unserialize($rule->args), $item);
- call_user_func_array($rule->operation, $args);
- $working_file = $output_file;
+ try {
+ call_user_func_array($rule->operation, $args);
+ $working_file = $output_file;
+ } catch (Exception $e) {
+ // Ignore this filter and move on.
+ Kohana_Log::add("error", "Caught exception filtering image: {$item->title}\n" .
+ $e->getMessage() . "\n" . $e->getTraceAsString());
+ }
}
}
if (!empty($ops["thumb"])) {
+ if (file_exists($item->thumb_path())) {
+ $item->thumb_dirty = 0;
+ } else {
+ copy(MODPATH . "gallery/images/missing_photo.png", $item->thumb_path());
+ }
$dims = getimagesize($item->thumb_path());
$item->thumb_width = $dims[0];
$item->thumb_height = $dims[1];
- $item->thumb_dirty = 0;
}
if (!empty($ops["resize"])) {
+ if (file_exists($item->resize_path())) {
+ $item->resize_dirty = 0;
+ } else {
+ copy(MODPATH . "gallery/images/missing_photo.png", $item->resize_path());
+ }
$dims = getimagesize($item->resize_path());
$item->resize_width = $dims[0];
$item->resize_height = $dims[1];
- $item->resize_dirty = 0;
}
$item->save();
} catch (Exception $e) {
diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php
index 2cb0fb25..0d3e9728 100644
--- a/modules/gallery/helpers/legal_file.php
+++ b/modules/gallery/helpers/legal_file.php
@@ -18,22 +18,51 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class legal_file_Core {
- static function get_extensions() {
+ static function get_photo_extensions() {
// Create a default list of allowed extensions and then let modules modify it.
$extensions_wrapper = new stdClass();
$extensions_wrapper->extensions = array("gif", "jpg", "jpeg", "png");
+ module::event("legal_photo_extensions", $extensions_wrapper);
+ return $extensions_wrapper->extensions;
+ }
+
+ static function get_movie_extensions() {
+ // Create a default list of allowed extensions and then let modules modify it.
+ $extensions_wrapper = new stdClass();
+ $extensions_wrapper->extensions = array("flv", "mp4", "m4v");
+ module::event("legal_movie_extensions", $extensions_wrapper);
+ return $extensions_wrapper->extensions;
+ }
+
+ static function get_extensions() {
+ $extensions = legal_file::get_photo_extensions();
if (movie::find_ffmpeg()) {
- array_push($extensions_wrapper->extensions, "flv", "mp4", "m4v");
+ $extensions = array_merge($extensions, legal_file::get_movie_extensions());
}
- module::event("legal_file_extensions", $extensions_wrapper);
- return $extensions_wrapper->extensions;
+ return $extensions;
}
static function get_filters() {
$filters = array();
- foreach (self::get_extensions() as $extension) {
+ foreach (legal_file::get_extensions() as $extension) {
array_push($filters, "*." . $extension, "*." . strtoupper($extension));
}
return $filters;
}
+
+ static function get_photo_types() {
+ // Create a default list of allowed types and then let modules modify it.
+ $types_wrapper = new stdClass();
+ $types_wrapper->types = array("image/jpeg", "image/gif", "image/png");
+ module::event("legal_photo_types", $types_wrapper);
+ return $types_wrapper->types;
+ }
+
+ static function get_movie_types() {
+ // Create a default list of allowed types and then let modules modify it.
+ $types_wrapper = new stdClass();
+ $types_wrapper->types = array("video/flv", "video/x-flv", "video/mp4");
+ module::event("legal_movie_types", $types_wrapper);
+ return $types_wrapper->types;
+ }
}
diff --git a/modules/gallery/helpers/system.php b/modules/gallery/helpers/system.php
index 9815d588..4110b4ed 100644
--- a/modules/gallery/helpers/system.php
+++ b/modules/gallery/helpers/system.php
@@ -47,20 +47,13 @@ class system_Core {
* It allows the caller to specify a prefix and an extension.
* It always places the file in TMPPATH.
*/
- static function temp_filename($prefix = "", $extension = "") {
- return self::_tempnam(TMPPATH, $prefix, ".$extension", "tempnam");
- }
-
- /**
- * This helper provides a dependency-injected implementation of tempnam.
- */
- static function _tempnam($dir, $prefix, $postfix, $builtin) {
+ static function temp_filename($prefix="", $extension="") {
do {
- $basename = call_user_func($builtin, $dir, $prefix);
+ $basename = tempnam(TMPPATH, $prefix);
if (!$basename) {
return false;
}
- $filename = $basename . $postfix;
+ $filename = "$basename.$extension";
$success = !file_exists($filename) && @rename($basename, $filename);
if (!$success) {
@unlink($basename);
diff --git a/modules/gallery/images/missing_photo.png b/modules/gallery/images/missing_photo.png
new file mode 100644
index 00000000..67786275
Binary files /dev/null and b/modules/gallery/images/missing_photo.png differ
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 6eb93cfa..4a0c8e38 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -813,10 +813,13 @@ class Item_Model_Core extends ORM_MPTT {
return;
}
- if (($this->is_movie() || $this->is_photo()) &&
+ if ($this->is_photo() &&
!preg_match("/^(" .
- implode("|", array_map("preg_quote",
- legal_file::get_extensions())) .
+ implode("|", array_map("preg_quote", legal_file::get_photo_extensions())) .
+ ")\$/i", $ext) ||
+ $this->is_movie() &&
+ !preg_match("/^(" .
+ implode("|", array_map("preg_quote", legal_file::get_movie_extensions())) .
")\$/i", $ext)) {
$v->add_error("name", "illegal_data_file_extension");
}
@@ -896,9 +899,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", "image/tiff");
+ $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/tests/System_Helper_Test.php b/modules/gallery/tests/System_Helper_Test.php
index dfe5d9ab..3d56c516 100644
--- a/modules/gallery/tests/System_Helper_Test.php
+++ b/modules/gallery/tests/System_Helper_Test.php
@@ -18,33 +18,10 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class System_Helper_Test extends Gallery_Unit_Test_Case {
- public function temp_filename_random_test() {
+ public function temp_filename_test() {
$filename = system::temp_filename("file", "ext");
$this->assert_true(file_exists($filename), "File not created");
unlink($filename);
$this->assert_pattern($filename, "|/file.*\\.ext$|");
}
-
- public function tempnam_collision_test() {
- require_once('Mock_Built_In.php');
- $existing = TMPPATH . "/file1.ext";
- $available = TMPPATH . "/file2.ext";
- touch($existing);
- $filename = system::_tempnam(TMPPATH, "file", ".ext",
- array(new Mock_Built_In("1", "2"), "_tempnam"));
- unlink($existing);
- $this->assert_true(file_exists($filename), "File not created");
- unlink($filename);
- $this->assert_equal($available, $filename, "Incorrect filename created");
- }
-
- public function tempnam_abort_test() {
- require_once('Mock_Built_In.php');
- $filename = system::_tempnam(TMPPATH, "file", ".ext",
- array(new Mock_Built_In(), "_tempnam"));
- if ($filename) {
- @unlink($filename);
- }
- $this->assert_false($filename, "Operation not aborted");
- }
}
diff --git a/themes/wind/js/ui.init.js b/themes/wind/js/ui.init.js
index 2c67bf3a..3ee3e32e 100644
--- a/themes/wind/js/ui.init.js
+++ b/themes/wind/js/ui.init.js
@@ -82,7 +82,7 @@ $(document).ready(function() {
} else {
var sib_height = $(this).prev().height();
}
- if ($.browser.msie && $.browser.version >= 8) {
+ if ($.browser.msie && $.browser.version <= 8) {
sib_height = sib_height + 1;
}
$(this).css("height", sib_height);
--
cgit v1.2.3
From 1807e10a56be504b11900f3ffe3cfb28b7bca5ed Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 18 May 2011 22:05:40 -0600
Subject: Merging some changes from rawphoto
---
modules/gallery/helpers/extensions.php | 39 ----------------------------------
modules/gallery/models/item.php | 9 --------
2 files changed, 48 deletions(-)
delete mode 100644 modules/gallery/helpers/extensions.php
diff --git a/modules/gallery/helpers/extensions.php b/modules/gallery/helpers/extensions.php
deleted file mode 100644
index bccbfc41..00000000
--- a/modules/gallery/helpers/extensions.php
+++ /dev/null
@@ -1,39 +0,0 @@
-extensions = array("gif", "jpg", "jpeg", "png");
- if (movie::find_ffmpeg()) {
- array_push($extensions_wrapper->extensions, "flv", "mp4", "m4v");
- }
- module::event("upload_extensions", $extensions_wrapper);
- return $extensions_wrapper->extensions;
- }
-
- static function get_upload_filters() {
- $filters = array();
- foreach (self::get_upload_extensions() as $extension) {
- array_push($filters, "*." . $extension, "*." . strtoupper($extension));
- }
- return $filters;
- }
-}
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 4a0c8e38..1dd9b00b 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -127,15 +127,6 @@ class Item_Model_Core extends ORM_MPTT {
return $this;
}
- /**
- * Get the path to the data file associated with this item.
- * This data file field is only set until you call save().
- * After that, you can get the path using get_file_path().
- */
- public function get_data_file() {
- return $this->data_file;
- }
-
/**
* Return the server-relative url to this item, eg:
* /gallery3/index.php/BobsWedding?page=2
--
cgit v1.2.3
From 3a89dbb359310c100a66604528376f29a4ad04a1 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 18 May 2011 22:10:38 -0600
Subject: Removing an unused file.
---
modules/gallery/tests/Mock_Built_In.php | 39 ---------------------------------
1 file changed, 39 deletions(-)
delete mode 100644 modules/gallery/tests/Mock_Built_In.php
diff --git a/modules/gallery/tests/Mock_Built_In.php b/modules/gallery/tests/Mock_Built_In.php
deleted file mode 100644
index b02e5ecf..00000000
--- a/modules/gallery/tests/Mock_Built_In.php
+++ /dev/null
@@ -1,39 +0,0 @@
-nonces = func_get_args();
- }
-
- function _tempnam($dir, $prefix) {
- if (empty($this->nonces))
- return false;
- $filename = "$dir/$prefix" . array_shift($this->nonces);
- if (!touch($filename))
- return false;
- return $filename;
- }
-}
--
cgit v1.2.3
From 1f464cb7d84a9c701f88ca3c8efb4c92e8de1151 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 18 May 2011 22:12:41 -0600
Subject: Removing an unused file.
---
modules/gallery/tests/Mock_Built_In.php | 39 ---------------------------------
1 file changed, 39 deletions(-)
delete mode 100644 modules/gallery/tests/Mock_Built_In.php
diff --git a/modules/gallery/tests/Mock_Built_In.php b/modules/gallery/tests/Mock_Built_In.php
deleted file mode 100644
index b02e5ecf..00000000
--- a/modules/gallery/tests/Mock_Built_In.php
+++ /dev/null
@@ -1,39 +0,0 @@
-nonces = func_get_args();
- }
-
- function _tempnam($dir, $prefix) {
- if (empty($this->nonces))
- return false;
- $filename = "$dir/$prefix" . array_shift($this->nonces);
- if (!touch($filename))
- return false;
- return $filename;
- }
-}
--
cgit v1.2.3
From c76c4e654880a6e03d70522ed8427154d53c1590 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 15 Jun 2011 20:15:20 -0600
Subject: Refer to "rules" not "filters"
---
modules/gallery/helpers/graphics.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index 3b9769de..39c87fbd 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -174,8 +174,8 @@ class graphics_Core {
call_user_func_array($rule->operation, $args);
$working_file = $output_file;
} catch (Exception $e) {
- // Ignore this filter and move on.
- Kohana_Log::add("error", "Caught exception filtering image: {$item->title}\n" .
+ // Ignore this rule and move on.
+ Kohana_Log::add("error", "Caught exception processing image: {$item->title}\n" .
$e->getMessage() . "\n" . $e->getTraceAsString());
}
}
--
cgit v1.2.3
From 20d7bfd6b904053c2bc27b69d32c71a321e0dae9 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Wed, 15 Jun 2011 20:21:06 -0600
Subject: Write more PHP docs
---
modules/gallery/helpers/legal_file.php | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php
index 0d3e9728..d78efdda 100644
--- a/modules/gallery/helpers/legal_file.php
+++ b/modules/gallery/helpers/legal_file.php
@@ -18,22 +18,29 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class legal_file_Core {
+ /**
+ * Create a default list of allowed photo extensions and then let modules modify it.
+ */
static function get_photo_extensions() {
- // Create a default list of allowed extensions and then let modules modify it.
$extensions_wrapper = new stdClass();
$extensions_wrapper->extensions = array("gif", "jpg", "jpeg", "png");
module::event("legal_photo_extensions", $extensions_wrapper);
return $extensions_wrapper->extensions;
}
+ /**
+ * Create a default list of allowed movie extensions and then let modules modify it.
+ */
static function get_movie_extensions() {
- // Create a default list of allowed extensions and then let modules modify it.
$extensions_wrapper = new stdClass();
$extensions_wrapper->extensions = array("flv", "mp4", "m4v");
module::event("legal_movie_extensions", $extensions_wrapper);
return $extensions_wrapper->extensions;
}
+ /**
+ * Create a merged list of all allowed photo and movie extensions.
+ */
static function get_extensions() {
$extensions = legal_file::get_photo_extensions();
if (movie::find_ffmpeg()) {
@@ -42,6 +49,10 @@ class legal_file_Core {
return $extensions;
}
+ /**
+ * Create a merged list of all photo and movie filename filters,
+ * (e.g. "*.gif"), based on allowed extensions.
+ */
static function get_filters() {
$filters = array();
foreach (legal_file::get_extensions() as $extension) {
@@ -50,16 +61,20 @@ class legal_file_Core {
return $filters;
}
+ /**
+ * Create a default list of allowed photo MIME types and then let modules modify it.
+ */
static function get_photo_types() {
- // Create a default list of allowed types and then let modules modify it.
$types_wrapper = new stdClass();
$types_wrapper->types = array("image/jpeg", "image/gif", "image/png");
module::event("legal_photo_types", $types_wrapper);
return $types_wrapper->types;
}
+ /**
+ * Create a default list of allowed movie MIME types and then let modules modify it.
+ */
static function get_movie_types() {
- // Create a default list of allowed types and then let modules modify it.
$types_wrapper = new stdClass();
$types_wrapper->types = array("video/flv", "video/x-flv", "video/mp4");
module::event("legal_movie_types", $types_wrapper);
--
cgit v1.2.3
From 44b624f6fbc34cbc638afa1c2a1f6cb0ae154a03 Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Thu, 21 Jul 2011 00:11:52 -0600
Subject: Squashed commit of the following:
commit 41d379c2b777ae7b3a11f528971228e234f8976f
Author: Chad Parry
Date: Thu Jul 21 00:10:10 2011 -0600
Replace an overly-complicated regular expression with a simple in_array, at Bharat's suggestion.
commit 1b3f7111d4c2607baaa2da0aab3b501f2d9a1426
Merge: 8f7904a 403f64b
Author: Chad Parry
Date: Wed Jul 20 21:02:56 2011 -0600
Merge branch 'master' into rawphoto
commit 403f64bf2a91fe3ac2496a0a6a6180ece26afd82
Author: Automatic Build Number Updater
Date: Tue Jul 12 21:44:14 2011 -0700
Automated update of .build_number to 163 for branch master
Last update: e8382b960a3c19bb28140833e348e6c9c9db8a8a (1 commits ago)
commit 51726f9e4b8372c40b27f843fca7b783e6db9623
Author: Tim Almdal
Date: Tue Jul 12 21:44:40 2011 -0700
Fix for ticket #1752. Add an RSS field link for the current album. Or, in the case of a photo or movie, add a link to the rss field of the parent album.
commit e8382b960a3c19bb28140833e348e6c9c9db8a8a
Author: Automatic Build Number Updater
Date: Mon Jun 27 22:27:04 2011 -0700
Automated update of .build_number to 162 for branch master
Last update: 40cda7fa3fa8d9ede1f24bfa8460aab1ac681c34 (1 commits ago)
commit 1afbcafe0e556ac571a5282f8b481fb90f5fb05a
Merge: 40cda7f fc6c139
Author: Bharat Mediratta
Date: Mon Jun 27 22:26:41 2011 -0700
Merge pull request #56 from alindeman/alindeman/1758
[Fixes #1758] Link to themes codex page instead of modules codex page
commit 40cda7fa3fa8d9ede1f24bfa8460aab1ac681c34
Author: Automatic Build Number Updater
Date: Mon Jun 27 22:25:54 2011 -0700
Automated update of .build_number to 161 for branch master
Last update: 771de0a3746ac0d780cb5dce2a14aa5a6ddf06d7 (1 commits ago)
commit aa08df7f0a839c95d268853cd745f622c98cadd0
Merge: 771de0a 784c429
Author: Bharat Mediratta
Date: Mon Jun 27 22:25:46 2011 -0700
Merge pull request #55 from alindeman/alindeman/1757
[Fixes #1757] Redirect to root album if path comes in as main.php or index.php
commit fc6c1390d3d5f3d99d75b04acf208ae3729c11ce
Author: Andy Lindeman
Date: Mon Jun 27 08:25:50 2011 -0400
[Fixes #1758] Link to themes codex page instead of modules codex page
commit 784c429070db54e183feb3e0ea6f2726b6507081
Author: Andy Lindeman
Date: Mon Jun 27 07:24:37 2011 -0400
[Fixes #1757] Redirect to root album if path comes in as main.php or index.php
commit 8f7904ab62c71a7e4ee68762f936030b4dcb4ea1
Merge: e950573 771de0a
Author: Chad Parry
Date: Sat Jun 25 14:12:39 2011 -0600
Merge branches 'master' and 'rawphoto' into rawphoto
commit e95057337996351e49915d9f85d007d50103a4be
Author: Chad Parry
Date: Wed Jun 15 20:24:18 2011 -0600
Merge branches 'rawphoto-squash' and 'rawphoto' into rawphoto
---
.build_number | 2 +-
modules/g2_import/controllers/g2.php | 2 +-
modules/gallery/helpers/gallery_rss.php | 8 ++++++++
modules/gallery/models/item.php | 8 ++------
modules/gallery/views/admin_themes.html.php | 4 ++--
5 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/.build_number b/.build_number
index e627526e..a10819e7 100644
--- a/.build_number
+++ b/.build_number
@@ -3,4 +3,4 @@
; process. You don't need to edit it. In fact..
;
; DO NOT EDIT THIS FILE BY HAND!
-build_number=160
+build_number=163
diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php
index 90984e84..1252014f 100644
--- a/modules/g2_import/controllers/g2.php
+++ b/modules/g2_import/controllers/g2.php
@@ -34,7 +34,7 @@ class G2_Controller extends Controller {
$path = $input->get("path");
$id = $input->get("g2_itemId");
- if ($path || $id) {
+ if (($path && $path != 'index.php' && $path != 'main.php') || $id) {
if ($id) {
// Requests by id are either core.DownloadItem or core.ShowItem requests. Later versions of
// Gallery 2 don't specify g2_view if it's the default (core.ShowItem). And in some cases
diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php
index 612872e6..9af67118 100644
--- a/modules/gallery/helpers/gallery_rss.php
+++ b/modules/gallery/helpers/gallery_rss.php
@@ -21,6 +21,14 @@
class gallery_rss_Core {
static function available_feeds($item, $tag) {
$feeds["gallery/latest"] = t("Latest photos and movies");
+
+ if ($item) {
+ $feed_item = $item -> is_album() ? $item : $item->parent();
+
+ $feeds["gallery/album/{$feed_item->id}"] =
+ t("%title photos and movies", array("title" => $feed_item->title));
+ }
+
return $feeds;
}
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 1dd9b00b..cccb7074 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -805,13 +805,9 @@ class Item_Model_Core extends ORM_MPTT {
}
if ($this->is_photo() &&
- !preg_match("/^(" .
- implode("|", array_map("preg_quote", legal_file::get_photo_extensions())) .
- ")\$/i", $ext) ||
+ !in_array(strtolower($ext), array_map("strtolower", legal_file::get_photo_extensions())) ||
$this->is_movie() &&
- !preg_match("/^(" .
- implode("|", array_map("preg_quote", legal_file::get_movie_extensions())) .
- ")\$/i", $ext)) {
+ !in_array(strtolower($ext), array_map("strtolower", legal_file::get_movie_extensions()))) {
$v->add_error("name", "illegal_data_file_extension");
}
}
diff --git a/modules/gallery/views/admin_themes.html.php b/modules/gallery/views/admin_themes.html.php
index 7d947b28..9d53779f 100644
--- a/modules/gallery/views/admin_themes.html.php
+++ b/modules/gallery/views/admin_themes.html.php
@@ -48,7 +48,7 @@
if (!$count): ?>
- = t("There are no other site themes available. Download one now!", array("url" => "http://codex.gallery2.org/Category:Gallery_3:Modules")) ?>
+ = t("There are no other site themes available. Download one now!", array("url" => "http://codex.gallery2.org/Category:Gallery_3:Themes")) ?>
endif ?>
@@ -88,7 +88,7 @@
if (!$count): ?>
- = t("There are no other admin themes available. Download one now!", array("url" => "http://codex.gallery2.org/Category:Gallery_3:Modules")) ?>
+ = t("There are no other admin themes available. Download one now!", array("url" => "http://codex.gallery2.org/Category:Gallery_3:Themes")) ?>
endif ?>
--
cgit v1.2.3
From 0672c8f83f068c546454bacefac123b5acb508cc Mon Sep 17 00:00:00 2001
From: Chad Parry
Date: Thu, 21 Jul 2011 01:12:26 -0600
Subject: Polishing the rawphoto changes, including adding some tests.
Squashed commit of the following:
commit 945316a8c220b12adb687c896bcc5e86f99f46a4
Author: Chad Parry
Date: Thu Jul 21 01:11:13 2011 -0600
Add a test for the sunny-day scenario where a rule changes a data file's MIME type.
commit 4ee1ee000c8f4d8ebaae66f637bc71080486fd73
Author: Chad Parry
Date: Thu Jul 21 00:49:47 2011 -0600
Ensure that a third-party cannot swap out a legitimate photo with an unsafe file type.
commit 7dd0105bfc59c150e5640e693778f51bbaa44eab
Author: Chad Parry
Date: Thu Jul 21 00:48:19 2011 -0600
Update the MIME type and other meta-data when a new data file is provided.
commit 5a8844c7947b21cf658f22cc61f20ffa9e8f07f2
Author: Chad Parry
Date: Thu Jul 21 00:30:01 2011 -0600
Remove a unit test that no longer applies. Replacement data files are allowed to have different MIME types.
commit 0de9c6283ce4f5773cad8e92b6785d6a1f7b5e46
Author: Chad Parry
Date: Thu Jul 21 00:27:45 2011 -0600
If one rule fails, then abort processing, rather than trying to proceed to subsequent rules.
commit 41d379c2b777ae7b3a11f528971228e234f8976f
Author: Chad Parry
Date: Thu Jul 21 00:10:10 2011 -0600
Replace an overly-complicated regular expression with a simple in_array, at Bharat's suggestion.
commit 1b3f7111d4c2607baaa2da0aab3b501f2d9a1426
Merge: 8f7904a 403f64b
Author: Chad Parry
Date: Wed Jul 20 21:02:56 2011 -0600
Merge branch 'master' into rawphoto
commit 8f7904ab62c71a7e4ee68762f936030b4dcb4ea1
Merge: e950573 771de0a
Author: Chad Parry
Date: Sat Jun 25 14:12:39 2011 -0600
Merge branches 'master' and 'rawphoto' into rawphoto
commit e95057337996351e49915d9f85d007d50103a4be
Author: Chad Parry
Date: Wed Jun 15 20:24:18 2011 -0600
Merge branches 'rawphoto-squash' and 'rawphoto' into rawphoto
---
modules/gallery/helpers/graphics.php | 10 ++--------
modules/gallery/models/item.php | 7 +++++++
modules/gallery/tests/Item_Model_Test.php | 23 +++++++++++++++++++++--
3 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/modules/gallery/helpers/graphics.php b/modules/gallery/helpers/graphics.php
index 39c87fbd..3548faa1 100644
--- a/modules/gallery/helpers/graphics.php
+++ b/modules/gallery/helpers/graphics.php
@@ -170,14 +170,8 @@ class graphics_Core {
foreach (self::_get_rules($target) as $rule) {
$args = array($working_file, $output_file, unserialize($rule->args), $item);
- try {
- call_user_func_array($rule->operation, $args);
- $working_file = $output_file;
- } catch (Exception $e) {
- // Ignore this rule and move on.
- Kohana_Log::add("error", "Caught exception processing image: {$item->title}\n" .
- $e->getMessage() . "\n" . $e->getTraceAsString());
- }
+ call_user_func_array($rule->operation, $args);
+ $working_file = $output_file;
}
}
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index cccb7074..93e97af6 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -420,6 +420,13 @@ class Item_Model_Core extends ORM_MPTT {
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"))) {
diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php
index 968d7510..19ab8ec4 100644
--- a/modules/gallery/tests/Item_Model_Test.php
+++ b/modules/gallery/tests/Item_Model_Test.php
@@ -394,15 +394,34 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
$this->assert_equal(20337, filesize($photo->file_path()));
}
- public function replacement_data_file_must_be_same_mime_type_test() {
+ public function replace_data_file_type_test() {
// Random photo is modules/gallery/tests/test.jpg
$photo = test::random_photo();
+ $this->assert_equal(1024, $photo->width);
+ $this->assert_equal(768, $photo->height);
+ $this->assert_equal(6232, filesize($photo->file_path()));
+ $this->assert_equal("image/jpeg", $photo->mime_type);
+ $orig_name = $photo->name;
+
+ // Random photo is gallery/images/graphicsmagick.png is 104x76 and 1486 bytes
$photo->set_data_file(MODPATH . "gallery/images/graphicsmagick.png");
+ $photo->save();
+
+ $this->assert_equal(104, $photo->width);
+ $this->assert_equal(76, $photo->height);
+ $this->assert_equal(1486, filesize($photo->file_path()));
+ $this->assert_equal("image/png", $photo->mime_type);
+ $this->assert_equal("png", pathinfo($photo->name, PATHINFO_EXTENSION));
+ $this->assert_equal(pathinfo($orig_name, PATHINFO_FILENAME), pathinfo($photo->name, PATHINFO_FILENAME));
+ }
+ public function unsafe_data_file_replacement_test() {
try {
+ $photo = test::random_photo();
+ $photo->set_data_file(MODPATH . "gallery/tests/Item_Model_Test.php");
$photo->save();
} catch (ORM_Validation_Exception $e) {
- $this->assert_same(array("name" => "cant_change_mime_type"), $e->validation->errors());
+ $this->assert_same(array("mime_type" => "invalid"), $e->validation->errors());
return; // pass
}
$this->assert_true(false, "Shouldn't get here");
--
cgit v1.2.3
From 98fb81458411551489804d07fceff7af8f990fca Mon Sep 17 00:00:00 2001
From: Automatic Build Number Updater
Date: Sun, 24 Jul 2011 08:26:35 -0700
Subject: Automated update of .build_number to 164 for branch master Last
update: 403f64bf2a91fe3ac2496a0a6a6180ece26afd82 (1 commits ago)
---
.build_number | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.build_number b/.build_number
index a10819e7..381b0525 100644
--- a/.build_number
+++ b/.build_number
@@ -3,4 +3,4 @@
; process. You don't need to edit it. In fact..
;
; DO NOT EDIT THIS FILE BY HAND!
-build_number=163
+build_number=164
--
cgit v1.2.3
From 458c6316e7810cb430b5e00b22808175f3134bc2 Mon Sep 17 00:00:00 2001
From: Bharat Mediratta
Date: Sun, 24 Jul 2011 08:31:39 -0700
Subject: Assign copyright to Bharat Mediratta as trustee for Gallery, per
https://github.com/gallery/gallery3/pull/51/files
---
modules/gallery/helpers/legal_file.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/gallery/helpers/legal_file.php b/modules/gallery/helpers/legal_file.php
index d78efdda..6f66c85c 100644
--- a/modules/gallery/helpers/legal_file.php
+++ b/modules/gallery/helpers/legal_file.php
@@ -1,7 +1,7 @@
Date: Sun, 24 Jul 2011 08:32:14 -0700
Subject: Update golden file.
---
modules/gallery/tests/xss_data.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt
index 954caf54..df087669 100644
--- a/modules/gallery/tests/xss_data.txt
+++ b/modules/gallery/tests/xss_data.txt
@@ -184,6 +184,7 @@ modules/gallery/views/form_uploadify.html.php 16 DIRTY_JS url::s
modules/gallery/views/form_uploadify.html.php 24 DIRTY_JS $flash_minimum_version
modules/gallery/views/form_uploadify.html.php 28 DIRTY_JS url::file("lib/uploadify/uploadify.swf")
modules/gallery/views/form_uploadify.html.php 29 DIRTY_JS url::site("uploader/add_photo/{$album->id}")
+modules/gallery/views/form_uploadify.html.php 31 DIRTY_JS implode(";",$extensions)
modules/gallery/views/form_uploadify.html.php 33 DIRTY_JS url::file("lib/uploadify/cancel.png")
modules/gallery/views/form_uploadify.html.php 34 DIRTY_JS $simultaneous_upload_limit
modules/gallery/views/form_uploadify.html.php 35 DIRTY_JS $size_limit_bytes
--
cgit v1.2.3
From 4d7105d89ee286698d2f20e9261d21c6626984d3 Mon Sep 17 00:00:00 2001
From: Automatic Build Number Updater
Date: Sun, 24 Jul 2011 08:34:28 -0700
Subject: Automated update of .build_number to 165 for branch master Last
update: 403f64bf2a91fe3ac2496a0a6a6180ece26afd82 (4 commits ago)
---
.build_number | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.build_number b/.build_number
index 381b0525..091288a2 100644
--- a/.build_number
+++ b/.build_number
@@ -3,4 +3,4 @@
; process. You don't need to edit it. In fact..
;
; DO NOT EDIT THIS FILE BY HAND!
-build_number=164
+build_number=165
--
cgit v1.2.3
From de1b4082cd99337242287889e56edc15a9fe9cda Mon Sep 17 00:00:00 2001
From: Tim Almdal
Date: Sun, 24 Jul 2011 17:11:04 -0700
Subject: Patch for ticket #1763. Where offset could be converted to a null
string. It's not really a problem in the current release, but will cause
isses when we serialize the offset as part of the display context.
---
modules/search/helpers/search.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/modules/search/helpers/search.php b/modules/search/helpers/search.php
index bbde8feb..a3fd795a 100644
--- a/modules/search/helpers/search.php
+++ b/modules/search/helpers/search.php
@@ -54,7 +54,7 @@ class search_Core {
"WHERE MATCH({search_records}.`data`) AGAINST ('$q' IN BOOLEAN MODE) " .
$access_sql .
"ORDER BY `score` DESC " .
- "LIMIT $limit OFFSET $offset";
+ "LIMIT $limit OFFSET " . (int)$offset;
$data = $db->query($query);
$count = $db->query("SELECT FOUND_ROWS() as c")->current()->c;
--
cgit v1.2.3
From 71560f1fcd5d968fc9b3a9372bda03b4262b5728 Mon Sep 17 00:00:00 2001
From: Automatic Build Number Updater
Date: Sun, 24 Jul 2011 17:11:13 -0700
Subject: Automated update of .build_number to 166 for branch master Last
update: 4d7105d89ee286698d2f20e9261d21c6626984d3 (1 commits ago)
---
.build_number | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.build_number b/.build_number
index 091288a2..4df64494 100644
--- a/.build_number
+++ b/.build_number
@@ -3,4 +3,4 @@
; process. You don't need to edit it. In fact..
;
; DO NOT EDIT THIS FILE BY HAND!
-build_number=165
+build_number=166
--
cgit v1.2.3
From 7f8056b593d04a9abd070399c0d4d176c650a309 Mon Sep 17 00:00:00 2001
From: Tim Almdal
Date: Thu, 4 Aug 2011 19:44:19 -0700
Subject: fix for ticket #1759. correct parameter names to match usage.
---
modules/gallery/libraries/IdentityProvider.php | 12 ++++++------
modules/user/libraries/drivers/IdentityProvider/Gallery.php | 2 +-
2 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/modules/gallery/libraries/IdentityProvider.php b/modules/gallery/libraries/IdentityProvider.php
index 153446e6..3f995923 100644
--- a/modules/gallery/libraries/IdentityProvider.php
+++ b/modules/gallery/libraries/IdentityProvider.php
@@ -110,11 +110,11 @@ class IdentityProvider_Core {
Kohana_Log::add("error", "Error restoring original identity provider\n" .
$e2->getMessage() . "\n" . $e2->getTraceAsString());
}
-
+
message::error(
t("Error attempting to enable \"%new_provider\" identity provider, reverted to \"%old_provider\" identity provider",
array("new_provider" => $new_provider, "old_provider" => $current_provider)));
-
+
$restore_already_running = false;
}
throw $e;
@@ -260,14 +260,14 @@ class IdentityProvider_Core {
/**
* @see IdentityProvider_Driver::add_user_to_group.
*/
- public function add_user_to_group($user, $group_id) {
- return $this->driver->add_user_to_group($user, $group_id);
+ public function add_user_to_group($user, $group) {
+ return $this->driver->add_user_to_group($user, $group);
}
/**
* @see IdentityProvider_Driver::remove_user_to_group.
*/
- public function remove_user_from_group($user, $group_id) {
- return $this->driver->remove_user_from_group($user, $group_id);
+ public function remove_user_from_group($user, $group) {
+ return $this->driver->remove_user_from_group($user, $group);
}
} // End Identity
diff --git a/modules/user/libraries/drivers/IdentityProvider/Gallery.php b/modules/user/libraries/drivers/IdentityProvider/Gallery.php
index 8cba3c82..79d31f7c 100644
--- a/modules/user/libraries/drivers/IdentityProvider/Gallery.php
+++ b/modules/user/libraries/drivers/IdentityProvider/Gallery.php
@@ -156,7 +156,7 @@ class IdentityProvider_Gallery_Driver implements IdentityProvider_Driver {
/**
* @see IdentityProvider_Driver::remove_user_to_group.
*/
- public function remove_user_from_group($user, $group_id) {
+ public function remove_user_from_group($user, $group) {
$group->remove($user);
$group->save();
}
--
cgit v1.2.3
From 5b4913ca11a27d6275937d50dcf5e651812f24d8 Mon Sep 17 00:00:00 2001
From: Automatic Build Number Updater
Date: Thu, 4 Aug 2011 20:28:57 -0700
Subject: Automated update of .build_number to 167 for branch master Last
update: 71560f1fcd5d968fc9b3a9372bda03b4262b5728 (2 commits ago)
---
.build_number | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/.build_number b/.build_number
index 4df64494..78fb7ec6 100644
--- a/.build_number
+++ b/.build_number
@@ -3,4 +3,4 @@
; process. You don't need to edit it. In fact..
;
; DO NOT EDIT THIS FILE BY HAND!
-build_number=166
+build_number=167
--
cgit v1.2.3
From 11c76572f0875e69f513e236a4c65e2d103d56c4 Mon Sep 17 00:00:00 2001
From: Tim Almdal
Date: Thu, 4 Aug 2011 20:29:06 -0700
Subject: Patch for ticket #1769. Remove the rows in groups_users when the user
or the group is deleted.
---
modules/user/models/group.php | 6 ++++++
modules/user/models/user.php | 6 ++++++
2 files changed, 12 insertions(+)
diff --git a/modules/user/models/group.php b/modules/user/models/group.php
index 4409dcb8..46642203 100644
--- a/modules/user/models/group.php
+++ b/modules/user/models/group.php
@@ -28,6 +28,12 @@ class Group_Model_Core extends ORM implements Group_Definition {
$old = clone $this;
module::event("group_before_delete", $this);
parent::delete($id);
+
+ db::build()
+ ->delete("groups_users")
+ ->where("group_id", "=", empty($id) ? $old->id : $id)
+ ->execute();
+
module::event("group_deleted", $old);
$this->users_cache = null;
}
diff --git a/modules/user/models/user.php b/modules/user/models/user.php
index a8a3a0e7..8fe0a87b 100644
--- a/modules/user/models/user.php
+++ b/modules/user/models/user.php
@@ -43,6 +43,12 @@ class User_Model_Core extends ORM implements User_Definition {
$old = clone $this;
module::event("user_before_delete", $this);
parent::delete($id);
+
+ db::build()
+ ->delete("groups_users")
+ ->where("user_id", "=", empty($id) ? $old->id : $id)
+ ->execute();
+
module::event("user_deleted", $old);
$this->groups_cache = null;
}
--
cgit v1.2.3
From e736d98eaa37df24122c746c21c473f0988d58f2 Mon Sep 17 00:00:00 2001
From: Tim Almdal
Date: Thu, 4 Aug 2011 21:00:21 -0700
Subject: Patch for ticket #1765. Provide the full site url for the the gallery
link instead of trying to use url_base for the hidden link and the
presentation text.
---
modules/user/views/reset_password.html.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/modules/user/views/reset_password.html.php b/modules/user/views/reset_password.html.php
index 3afca881..d939ad42 100644
--- a/modules/user/views/reset_password.html.php
+++ b/modules/user/views/reset_password.html.php
@@ -9,8 +9,9 @@
= t("Hello, %name,", array("name" => $user->full_name ? $user->full_name : $user->name)) ?>
- = t("We received a request to reset your password for %site_url. If you made this request, you can confirm it by clicking this link. If you didn't request this password reset, it's ok to ignore this mail.",
- array("site_url" => html::mark_clean(url::base(false, "http")),
+ = t("We received a request to reset your password for %base_url. If you made this request, you can confirm it by clicking this link. If you didn't request this password reset, it's ok to ignore this mail.",
+ array("site_url" => html::mark_clean(url::abs_site("/")),
+ "base_url" => html::mark_clean(url::base(false)),
"confirm_url" => $confirm_url)) ?>