summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/css/upgrader.css39
-rw-r--r--modules/gallery/helpers/gallery_block.php2
-rw-r--r--modules/gallery/helpers/gallery_installer.php6
-rw-r--r--modules/gallery/helpers/item.php51
-rw-r--r--modules/gallery/helpers/locales.php2
-rw-r--r--modules/gallery/libraries/MY_Input.php31
-rw-r--r--modules/gallery/tests/Item_Helper_Test.php65
-rw-r--r--modules/gallery/views/upgrader.html.php4
8 files changed, 187 insertions, 13 deletions
diff --git a/modules/gallery/css/upgrader.css b/modules/gallery/css/upgrader.css
index 73da0ff4..2b3b5afd 100644
--- a/modules/gallery/css/upgrader.css
+++ b/modules/gallery/css/upgrader.css
@@ -26,6 +26,12 @@ div#footer {
margin: 1em;
}
+table {
+ width: 600px;
+ margin-bottom: 10px;
+}
+
+th.name,
td.name {
text-align: left;
padding-left: 30px;
@@ -53,11 +59,6 @@ tr.upgradeable td.gallery {
color: #00d;
}
-table {
- width: 600px;
- margin-bottom: 10px;
-}
-
p {
font-size: .9em;
}
@@ -125,3 +126,31 @@ pre {
margin: 0px;
padding: 0px;
}
+
+.rtl {
+ direction: rtl;
+}
+
+.rtl th.name,
+.rtl td.name {
+ text-align: right;
+ padding-right: 30px;
+}
+
+
+.rtl li:before {
+ content: "";
+}
+
+.rtl li:after {
+ content: "\00BB \0020";
+}
+
+.rtl ul {
+ margin-right: 0;
+ padding-right: 0;
+}
+
+.rtl div#dialog a.close {
+ float: left;
+}
diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php
index be0f11b8..46742743 100644
--- a/modules/gallery/helpers/gallery_block.php
+++ b/modules/gallery/helpers/gallery_block.php
@@ -70,7 +70,7 @@ class gallery_block_Core {
$block->css_id = "g-platform";
$block->title = t("Platform information");
$block->content = new View("admin_block_platform.html");
- if (is_readable("/proc/loadavg")) {
+ if (@is_readable("/proc/loadavg")) {
$block->content->load_average =
join(" ", array_slice(explode(" ", current(file("/proc/loadavg"))), 0, 3));
} else {
diff --git a/modules/gallery/helpers/gallery_installer.php b/modules/gallery/helpers/gallery_installer.php
index ed4a62a5..dd53cf43 100644
--- a/modules/gallery/helpers/gallery_installer.php
+++ b/modules/gallery/helpers/gallery_installer.php
@@ -287,7 +287,7 @@ class gallery_installer {
// @todo this string needs to be picked up by l10n_scanner
module::set_var("gallery", "credits", "Powered by <a href=\"%url\">Gallery %version</a>");
module::set_var("gallery", "simultaneous_upload_limit", 5);
- module::set_var("gallery", "admin_area_timeout", 20 * 60);
+ module::set_var("gallery", "admin_area_timeout", 90 * 60);
module::set_version("gallery", 28);
}
@@ -534,8 +534,8 @@ class gallery_installer {
}
if ($version == 27) {
- // Set the admin area timeout to 20 minutes
- module::set_var("gallery", "admin_area_timeout", 20 * 60);
+ // Set the admin area timeout to 90 minutes
+ module::set_var("gallery", "admin_area_timeout", 90 * 60);
module::set_version("gallery", $version = 28);
}
}
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 41d49ce9..36193071 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -40,7 +40,56 @@ class item_Core {
}
$source->parent_id = $target->id;
- $source->save();
+
+ // Moving may result in name or slug conflicts. If that happens, try up to 5 times to pick a
+ // random name (or slug) to avoid the conflict.
+ $orig_name = $source->name;
+ $orig_name_filename = pathinfo($source->name, PATHINFO_FILENAME);
+ $orig_name_extension = pathinfo($source->name, PATHINFO_EXTENSION);
+ $orig_slug = $source->slug;
+ for ($i = 0; $i < 5; $i++) {
+ try {
+ $source->save();
+ if ($orig_name != $source->name) {
+ switch ($source->type) {
+ case "album":
+ message::info(
+ t("Album <b>%old_name</b> renamed to <b>%new_name</b> to avoid a conflict",
+ array("old_name" => $orig_name, "new_name" => $source->name)));
+ break;
+
+ case "photo":
+ message::info(
+ t("Photo <b>%old_name</b> renamed to <b>%new_name</b> to avoid a conflict",
+ array("old_name" => $orig_name, "new_name" => $source->name)));
+ break;
+
+ case "movie":
+ message::info(
+ t("Movie <b>%old_name</b> renamed to <b>%new_name</b> to avoid a conflict",
+ array("old_name" => $orig_name, "new_name" => $source->name)));
+ break;
+ }
+ }
+ break;
+ } catch (ORM_Validation_Exception $e) {
+ $rand = rand(10, 99);
+ $errors = $e->validation->errors();
+ if (isset($errors["name"])) {
+ $source->name = $orig_name_filename . "-{$rand}." . $orig_name_extension;
+ unset($errors["name"]);
+ }
+ if (isset($errors["slug"])) {
+ $source->slug = $orig_slug . "-{$rand}";
+ unset($errors["slug"]);
+ }
+
+ if ($errors) {
+ // There were other validation issues-- we don't know how to handle those
+ throw $e;
+ }
+ }
+ }
// If the target has no cover item, make this it.
if ($target->album_cover_item_id == null) {
diff --git a/modules/gallery/helpers/locales.php b/modules/gallery/helpers/locales.php
index 883d2f9a..e72d7ed9 100644
--- a/modules/gallery/helpers/locales.php
+++ b/modules/gallery/helpers/locales.php
@@ -131,7 +131,7 @@ class locales_Core {
}
static function is_rtl($locale=null) {
- return Gallery_I18n::instance()->is_rtl($locale);
+ return Gallery_I18n::instance()->is_rtl($locale);
}
/**
diff --git a/modules/gallery/libraries/MY_Input.php b/modules/gallery/libraries/MY_Input.php
new file mode 100644
index 00000000..dce569fd
--- /dev/null
+++ b/modules/gallery/libraries/MY_Input.php
@@ -0,0 +1,31 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2009 Bharat Mediratta
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+class Input extends Input_Core {
+ /**
+ * Modified form of Input::clean_input_keys() that replaces malformed values
+ * instead of dying on bad input.
+ *
+ * @param string string to clean
+ * @return string
+ */
+ public function clean_input_keys($str) {
+ return preg_replace('#^[\pL0-9:_.-]++$#uD', '_', $str);
+ }
+}
diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php
index cdbdd324..50587702 100644
--- a/modules/gallery/tests/Item_Helper_Test.php
+++ b/modules/gallery/tests/Item_Helper_Test.php
@@ -19,6 +19,10 @@
*/
class Item_Helper_Test extends Gallery_Unit_Test_Case {
+ public function setup() {
+ identity::set_active_user(identity::admin_user());
+ }
+
public function viewable_test() {
$album = test::random_album();
$item = test::random_photo($album);
@@ -42,4 +46,65 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_equal("foo", item::convert_filename_to_slug("{[foo]}"));
$this->assert_equal("foo-bar", item::convert_filename_to_slug("{[foo!@#!$@#^$@($!(@bar]}"));
}
+
+ public function move_test() {
+ $photo = test::random_photo(item::root());
+ $dst_album = test::random_album();
+
+ item::move($photo, $dst_album);
+ $this->assert_same($dst_album->id, $photo->parent_id);
+ }
+
+
+ public function move_updates_album_covers_test() {
+ // 2 photos in the source album
+ $src_album = test::random_album();
+ $photo1 = test::random_photo($src_album);
+ $photo2 = test::random_photo($src_album);
+ $src_album->reload();
+
+ // destination album
+ $dst_album = test::random_album();
+
+ item::move($photo1, $dst_album);
+
+ // Refresh cached copies
+ $src_album->reload();
+ $dst_album->reload();
+
+ // photo 2 becomes the album cover for the source album and photo 1
+ // becomes the album cover for the destination
+ $this->assert_same($photo1->id, $dst_album->album_cover_item_id);
+ $this->assert_same($photo2->id, $src_album->album_cover_item_id);
+ }
+
+ public function move_leaves_empty_album_with_no_album_cover_test() {
+ $src_album = test::random_album();
+ $photo = test::random_photo($src_album);
+
+ item::move($photo, item::root());
+
+ $src_album->reload();
+ $this->assert_false($src_album->album_cover_item_id);
+ }
+
+ public function move_conflicts_result_in_a_rename_test() {
+ $rand = rand();
+ $photo1 = test::random_photo_unsaved(item::root());
+ $photo1->name = "{$rand}.jpg";
+ $photo1->slug = (string)$rand;
+ $photo1->save();
+
+ $src_album = test::random_album();
+ $photo2 = test::random_photo_unsaved($src_album);
+ $photo2->name = "{$rand}.jpg";
+ $photo2->slug = (string)$rand;
+ $photo2->save();
+
+ item::move($photo2, item::root());
+
+ $this->assert_same(item::root()->id, $photo2->parent_id);
+ $this->assert_not_same("{$rand}.jpg", $photo2->name);
+ $this->assert_not_same($rand, $photo2->slug);
+ }
}
diff --git a/modules/gallery/views/upgrader.html.php b/modules/gallery/views/upgrader.html.php
index 4490557c..55731440 100644
--- a/modules/gallery/views/upgrader.html.php
+++ b/modules/gallery/views/upgrader.html.php
@@ -6,7 +6,7 @@
media="screen,print,projection" />
<script src="<?= url::file("lib/jquery.js") ?>" type="text/javascript"></script>
</head>
- <body>
+ <body<? if (locales::is_rtl()) { echo ' class="rtl"'; } ?>>
<div id="outer">
<img src="<?= url::file("modules/gallery/images/gallery.png") ?>" />
<div id="inner">
@@ -59,7 +59,7 @@
</p>
<table>
<tr class="<?= $done ? "muted" : "" ?>">
- <th> <?= t("Module name") ?> </th>
+ <th class="name"> <?= t("Module name") ?> </th>
<th> <?= t("Installed version") ?> </th>
<th> <?= t("Available version") ?> </th>
</tr>