summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.build_number2
-rw-r--r--modules/gallery/helpers/item.php12
-rw-r--r--modules/gallery/models/item.php4
-rw-r--r--modules/gallery/tests/Item_Helper_Test.php4
4 files changed, 17 insertions, 5 deletions
diff --git a/.build_number b/.build_number
index 7a220ac6..70103095 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=92
+build_number=93
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 1a5c631e..7e779544 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -152,8 +152,18 @@ class item_Core {
* @param string $filename
*/
static function convert_filename_to_slug($filename) {
- $result = pathinfo($filename, PATHINFO_FILENAME);
+ $result = str_replace("&", "-and-", $filename);
+ $result = str_replace(" ", "-", $result);
+
+ // It's not easy to extend the text helper since it's called by the Input class which is
+ // referenced in hooks/init_gallery, so it's
+ if (class_exists("transliterate")) {
+ $result = transliterate::utf8_to_ascii($result);
+ } else {
+ $result = text::transliterate_to_ascii($result);
+ }
$result = preg_replace("/[^A-Za-z0-9-_]+/", "-", $result);
+ $result = preg_replace("/-+/", "-", $result);
return trim($result, "-");
}
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 8f4bc5e4..f46db696 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -336,9 +336,7 @@ class Item_Model_Core extends ORM_MPTT {
// Make an url friendly slug from the name, if necessary
if (empty($this->slug)) {
- $tmp = pathinfo($this->name, PATHINFO_FILENAME);
- $tmp = preg_replace("/[^A-Za-z0-9-_]+/", "-", $tmp);
- $this->slug = trim($tmp, "-");
+ $this->slug = item::convert_filename_to_slug($this->name);
// If the filename is all invalid characters, then the slug may be empty here. Pick a
// random value.
diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php
index 4d5aed41..2fde7cc0 100644
--- a/modules/gallery/tests/Item_Helper_Test.php
+++ b/modules/gallery/tests/Item_Helper_Test.php
@@ -49,6 +49,10 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case {
public function convert_filename_to_slug_test() {
$this->assert_equal("foo", item::convert_filename_to_slug("{[foo]}"));
$this->assert_equal("foo-bar", item::convert_filename_to_slug("{[foo!@#!$@#^$@($!(@bar]}"));
+ $this->assert_equal("english-text", item::convert_filename_to_slug("english text"));
+ $this->assert_equal("new-line", item::convert_filename_to_slug("new \n line"));
+ $this->assert_equal("foo-and-bar", item::convert_filename_to_slug("foo&bar"));
+ $this->assert_equal("special", item::convert_filename_to_slug("šṗëçîąļ"));
}
public function move_test() {