diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2010-02-10 08:07:20 -0800 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2010-02-10 08:07:20 -0800 |
commit | b42c736607591f8e2bed4aea474ad622b3f7445a (patch) | |
tree | 83be1069a48cf604a0f73c5d895248c724024fc7 | |
parent | 5e703186fbf0c0cb689fc737de7c074249361ef9 (diff) | |
parent | 8763e475adc7bb26ed9705c9d61a1db2b20e60c4 (diff) |
Merge branch 'master' into talmdal_dev
Conflicts:
modules/organize/js/organize.js
-rw-r--r-- | installer/install.sql | 2 | ||||
-rw-r--r-- | modules/g2_import/controllers/g2.php | 3 | ||||
-rw-r--r-- | modules/g2_import/helpers/g2_import.php | 41 | ||||
-rw-r--r-- | modules/gallery/css/upgrader.css | 39 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_block.php | 2 | ||||
-rw-r--r-- | modules/gallery/helpers/gallery_installer.php | 6 | ||||
-rw-r--r-- | modules/gallery/helpers/item.php | 51 | ||||
-rw-r--r-- | modules/gallery/helpers/locales.php | 2 | ||||
-rw-r--r-- | modules/gallery/libraries/MY_Input.php (renamed from modules/gallery_unit_test/helpers/diff.php) | 15 | ||||
-rw-r--r-- | modules/gallery/tests/Item_Helper_Test.php | 65 | ||||
-rw-r--r-- | modules/gallery/views/upgrader.html.php | 4 | ||||
-rw-r--r-- | modules/gallery_unit_test/helpers/test.php | 6 | ||||
-rw-r--r-- | modules/gallery_unit_test/libraries/Gallery_Unit_Test_Case.php | 2 | ||||
-rw-r--r-- | modules/organize/views/organize_tree.html.php | 6 | ||||
-rw-r--r-- | modules/user/controllers/password.php | 2 | ||||
-rw-r--r-- | modules/user/views/confirm_reset_password.html.php | 2 |
16 files changed, 213 insertions, 35 deletions
diff --git a/installer/install.sql b/installer/install.sql index 1f21ad4e..dea324eb 100644 --- a/installer/install.sql +++ b/installer/install.sql @@ -391,7 +391,7 @@ INSERT INTO {vars} VALUES (NULL,'gallery','time_format','H:i:s'); INSERT INTO {vars} VALUES (NULL,'gallery','show_credits','1'); INSERT INTO {vars} VALUES (NULL,'gallery','credits','Powered by <a href=\"%url\">Gallery %version</a>'); INSERT INTO {vars} VALUES (NULL,'gallery','simultaneous_upload_limit','5'); -INSERT INTO {vars} VALUES (NULL,'gallery','admin_area_timeout','1200'); +INSERT INTO {vars} VALUES (NULL,'gallery','admin_area_timeout','5400'); INSERT INTO {vars} VALUES (NULL,'gallery','blocks_dashboard_sidebar','a:4:{i:2;a:2:{i:0;s:7:\"gallery\";i:1;s:11:\"block_adder\";}i:3;a:2:{i:0;s:7:\"gallery\";i:1;s:5:\"stats\";}i:4;a:2:{i:0;s:7:\"gallery\";i:1;s:13:\"platform_info\";}i:5;a:2:{i:0;s:7:\"gallery\";i:1;s:12:\"project_news\";}}'); INSERT INTO {vars} VALUES (NULL,'gallery','date_time_format','Y-M-d H:i:s'); INSERT INTO {vars} VALUES (NULL,'gallery','date_format','Y-M-d'); diff --git a/modules/g2_import/controllers/g2.php b/modules/g2_import/controllers/g2.php index 347da649..1d97653a 100644 --- a/modules/g2_import/controllers/g2.php +++ b/modules/g2_import/controllers/g2.php @@ -61,9 +61,10 @@ class G2_Controller extends Controller { } $item = ORM::factory("item", $g2_map->g3_id); - if (!$item->loaded() || !access::can("view", $item)) { + if (!$item->loaded()) { throw new Kohana_404_Exception(); } + access::required("view", $item); // Redirect the user to the new url diff --git a/modules/g2_import/helpers/g2_import.php b/modules/g2_import/helpers/g2_import.php index 31368a5b..faf08291 100644 --- a/modules/g2_import/helpers/g2_import.php +++ b/modules/g2_import/helpers/g2_import.php @@ -304,7 +304,15 @@ class g2_import_Core { if ($user) { $message = t("Loaded existing user: '%name'.", array("name" => $user->name)); } else { - $user = identity::create_user($g2_user->getUsername(), $g2_user->getfullname(), ""); + $user = identity::create_user($g2_user->getUsername(), $g2_user->getfullname(), + // Note: The API expects a password in cleartext. + // Just use the hashed password as an unpredictable + // value here. The user will have to reset the password. + $g2_user->getHashedPassword(), $g2_user->getEmail()); + if (class_exists("User_Model") && $user instanceof User_Model) { + // This will work if G2's password is a PasswordHash password as well. + $user->hashed_password = $g2_user->getHashedPassword(); + } $message = t("Created user: '%name'.", array("name" => $user->name)); } @@ -366,6 +374,7 @@ class g2_import_Core { $album->parent_id = self::map($g2_album->getParentId()); $album->name = $g2_album->getPathComponent(); $album->title = self::_decode_html_special_chars($g2_album->getTitle()); + $album->title or $album->title = $album->name; $album->description = self::_decode_html_special_chars(self::extract_description($g2_album)); $album->owner_id = self::map($g2_album->getOwnerId()); $album->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_album_id)); @@ -384,9 +393,14 @@ class g2_import_Core { $direction_map = array( ORDER_ASCENDING => "asc", ORDER_DESCENDING => "desc"); - if (array_key_exists($g2_order = $g2_album->getOrderBy(), $order_map)) { + // Only consider G2's first sort order + $g2_order = explode("|", $g2_album->getOrderBy() . ""); + $g2_order = $g2_order[0]; + $g2_order_direction = explode("|", $g2_album->getOrderDirection() . ""); + $g2_order_direction = $g2_order_direction[0]; + if (array_key_exists($g2_order, $order_map)) { $album->sort_column = $order_map[$g2_order]; - $album->sort_order = $direction_map[$g2_album->getOrderDirection()]; + $album->sort_order = $direction_map[$g2_order_direction]; } $album->save(); @@ -491,6 +505,7 @@ class g2_import_Core { $item->set_data_file($g2_path); $item->name = $g2_item->getPathComponent(); $item->title = self::_decode_html_special_chars($g2_item->getTitle()); + $item->title or $item->title = $item->name; $item->description = self::_decode_html_special_chars(self::extract_description($g2_item)); $item->owner_id = self::map($g2_item->getOwnerId()); $item->save(); @@ -512,6 +527,7 @@ class g2_import_Core { $item->set_data_file($g2_path); $item->name = $g2_item->getPathComponent(); $item->title = self::_decode_html_special_chars($g2_item->getTitle()); + $item->title or $item->title = $item->name; $item->description = self::_decode_html_special_chars(self::extract_description($g2_item)); $item->owner_id = self::map($g2_item->getOwnerId()); } catch (Exception $e) { @@ -725,6 +741,12 @@ class g2_import_Core { array("id" => $g2_comment_id, "exception" => (string)$e)); } + $item_id = self::map($g2_comment->getParentId()); + if (empty($item_id)) { + // Item was not mapped. + return; + } + $text = $g2_comment->getSubject(); if ($text) { $text .= " "; @@ -735,18 +757,17 @@ class g2_import_Core { // we don't trigger spam filtering events $comment = ORM::factory("comment"); $comment->author_id = self::map($g2_comment->getCommenterId()); - $comment->guest_name = $g2_comment->getAuthor(); - $comment->item_id = self::map($g2_comment->getParentId()); + $comment->guest_name = ""; + if ($comment->author_id == identity::guest()->id) { + $comment->guest_name = $g2_comment->getAuthor(); + $comment->guest_name or $comment->guest_name = (string) t("Anonymous coward"); + } + $comment->item_id = $item_id; $comment->text = self::_transform_bbcode($text); $comment->state = "published"; $comment->server_http_host = $g2_comment->getHost(); $comment->created = $g2_comment->getDate(); $comment->save(); - - self::map($g2_comment->getId(), $comment->id); - return t("Imported comment '%comment' for item with id: %id", - array("id" => $comment->item_id, - "comment" => text::limit_words(nl2br(html::purify($comment->text)), 50))); } /** 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_unit_test/helpers/diff.php b/modules/gallery/libraries/MY_Input.php index 7b573732..dce569fd 100644 --- a/modules/gallery_unit_test/helpers/diff.php +++ b/modules/gallery/libraries/MY_Input.php @@ -17,10 +17,15 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ -class diff_Core { - static function compare($a, $b) { - fwrite(fopen($a_name = tempnam("/tmp", "test"), "w"), $a); - fwrite(fopen($b_name = tempnam("/tmp", "test"), "w"), $b); - return `diff $a_name $b_name`; +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> diff --git a/modules/gallery_unit_test/helpers/test.php b/modules/gallery_unit_test/helpers/test.php index 3e116808..91bd1be5 100644 --- a/modules/gallery_unit_test/helpers/test.php +++ b/modules/gallery_unit_test/helpers/test.php @@ -82,4 +82,10 @@ class test_Core { // Reload so that ORM coerces all fields into strings. return $tag->save()->reload(); } + + static function diff($a, $b) { + fwrite(fopen($a_name = tempnam("/tmp", "test"), "w"), $a); + fwrite(fopen($b_name = tempnam("/tmp", "test"), "w"), $b); + return `diff $a_name $b_name`; + } } diff --git a/modules/gallery_unit_test/libraries/Gallery_Unit_Test_Case.php b/modules/gallery_unit_test/libraries/Gallery_Unit_Test_Case.php index 509b4125..545af0fe 100644 --- a/modules/gallery_unit_test/libraries/Gallery_Unit_Test_Case.php +++ b/modules/gallery_unit_test/libraries/Gallery_Unit_Test_Case.php @@ -24,7 +24,7 @@ class Gallery_Unit_Test_Case extends Unit_Test_Case { sprintf("Expected (%s) %s but received (%s) %s\n Diff: %s", gettype($expected), var_export($expected, true), gettype($actual), var_export($actual, true), - diff::compare(var_export($expected, true), var_export($actual, true))), + test::diff(var_export($expected, true), var_export($actual, true))), $debug); } return $this; diff --git a/modules/organize/views/organize_tree.html.php b/modules/organize/views/organize_tree.html.php index 3912c1f6..33d7b4c9 100644 --- a/modules/organize/views/organize_tree.html.php +++ b/modules/organize/views/organize_tree.html.php @@ -1,5 +1,5 @@ <?php defined("SYSPATH") or die("No direct script access.") ?> -<li class="g-organize-album ui-icon-left g-left <?= access::can("edit", $album) ? "" : "g-view-only" ?>" +<li class="g-organize-album ui-icon-left <?= access::can("edit", $album) ? "" : "g-view-only" ?>" ref="<?= $album->id ?>"> <span class="ui-icon ui-icon-minus g-left"> </span> @@ -7,12 +7,12 @@ ref="<?= $album->id ?>"> <?= html::clean($album->title) ?> </span> - <ul> + <ul class="g-left"> <? foreach ($album->children(null, null, array(array("type", "=", "album"))) as $child): ?> <? if ($selected && $child->contains($selected)): ?> <?= View::factory("organize_tree.html", array("selected" => $selected, "album" => $child)); ?> <? else: ?> - <li class="g-organize-album ui-icon-left g-left <?= access::can("edit", $child) ? "" : "g-view-only" ?>" + <li class="g-organize-album ui-icon-left <?= access::can("edit", $child) ? "" : "g-view-only" ?>" ref="<?= $child->id ?>"> <span class="ui-icon ui-icon-plus g-left"></span> <span class="g-organize-album-text g-left <?= $selected && $child->id == $selected->id ? "ui-state-focus" : "" ?>" ref="<?= $child->id ?>"> diff --git a/modules/user/controllers/password.php b/modules/user/controllers/password.php index 8309d2cc..07fdc1ed 100644 --- a/modules/user/controllers/password.php +++ b/modules/user/controllers/password.php @@ -110,7 +110,7 @@ class Password_Controller extends Controller { "mistyped", t("The password and the confirm password must match")); $group->submit("")->value(t("Update")); - $template->content = new View("user_form.html"); + $template->content = new View("confirm_reset_password.html"); $template->content->form = $form; return $template; } diff --git a/modules/user/views/confirm_reset_password.html.php b/modules/user/views/confirm_reset_password.html.php new file mode 100644 index 00000000..4993189e --- /dev/null +++ b/modules/user/views/confirm_reset_password.html.php @@ -0,0 +1,2 @@ +<?php defined("SYSPATH") or die("No direct script access.") ?> +<?= $form ?>
\ No newline at end of file |