summaryrefslogtreecommitdiff
path: root/modules/gallery
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery')
-rw-r--r--modules/gallery/controllers/admin_advanced_settings.php1
-rw-r--r--modules/gallery/controllers/admin_dashboard.php1
-rw-r--r--modules/gallery/controllers/admin_graphics.php1
-rw-r--r--modules/gallery/controllers/admin_languages.php1
-rw-r--r--modules/gallery/controllers/admin_modules.php1
-rw-r--r--modules/gallery/controllers/admin_sidebar.php1
-rw-r--r--modules/gallery/controllers/admin_theme_options.php1
-rw-r--r--modules/gallery/controllers/admin_themes.php1
-rw-r--r--modules/gallery/controllers/albums.php1
-rw-r--r--modules/gallery/controllers/reauthenticate.php2
-rw-r--r--modules/gallery/helpers/album.php4
-rw-r--r--modules/gallery/helpers/gallery_event.php11
-rw-r--r--modules/gallery/helpers/gallery_task.php86
-rw-r--r--modules/gallery/helpers/item_rest.php105
-rw-r--r--modules/gallery/helpers/items_rest.php13
-rw-r--r--modules/gallery/helpers/theme.php6
-rw-r--r--modules/gallery/libraries/MY_Input.php2
-rw-r--r--modules/gallery/models/item.php8
-rw-r--r--modules/gallery/tests/Input_Library_Test.php25
-rw-r--r--modules/gallery/tests/Item_Helper_Test.php13
-rw-r--r--modules/gallery/tests/Item_Model_Test.php15
-rw-r--r--modules/gallery/tests/Item_Rest_Helper_Test.php70
-rw-r--r--modules/gallery/tests/xss_data.txt47
-rw-r--r--modules/gallery/views/movieplayer.html.php7
24 files changed, 314 insertions, 109 deletions
diff --git a/modules/gallery/controllers/admin_advanced_settings.php b/modules/gallery/controllers/admin_advanced_settings.php
index d9a281b5..6f4e9403 100644
--- a/modules/gallery/controllers/admin_advanced_settings.php
+++ b/modules/gallery/controllers/admin_advanced_settings.php
@@ -20,6 +20,7 @@
class Admin_Advanced_Settings_Controller extends Admin_Controller {
public function index() {
$view = new Admin_View("admin.html");
+ $view->page_title = t("Advanced settings");
$view->content = new View("admin_advanced_settings.html");
$view->content->vars = ORM::factory("var")
->order_by("module_name")
diff --git a/modules/gallery/controllers/admin_dashboard.php b/modules/gallery/controllers/admin_dashboard.php
index adc0df16..76c42612 100644
--- a/modules/gallery/controllers/admin_dashboard.php
+++ b/modules/gallery/controllers/admin_dashboard.php
@@ -20,6 +20,7 @@
class Admin_Dashboard_Controller extends Admin_Controller {
public function index() {
$view = new Admin_View("admin.html");
+ $view->page_title = t("Dashboard");
$view->content = new View("admin_dashboard.html");
$view->content->blocks = block_manager::get_html("dashboard_center");
$view->sidebar = "<div id=\"g-admin-dashboard-sidebar\">" .
diff --git a/modules/gallery/controllers/admin_graphics.php b/modules/gallery/controllers/admin_graphics.php
index abbd8986..de98035d 100644
--- a/modules/gallery/controllers/admin_graphics.php
+++ b/modules/gallery/controllers/admin_graphics.php
@@ -20,6 +20,7 @@
class Admin_Graphics_Controller extends Admin_Controller {
public function index() {
$view = new Admin_View("admin.html");
+ $view->page_title = t("Graphics settings");
$view->content = new View("admin_graphics.html");
$view->content->tk = graphics::detect_toolkits();
$view->content->active = module::get_var("gallery", "graphics_toolkit", "none");
diff --git a/modules/gallery/controllers/admin_languages.php b/modules/gallery/controllers/admin_languages.php
index 1ca777dc..0f134fcd 100644
--- a/modules/gallery/controllers/admin_languages.php
+++ b/modules/gallery/controllers/admin_languages.php
@@ -20,6 +20,7 @@
class Admin_Languages_Controller extends Admin_Controller {
public function index($share_translations_form=null) {
$v = new Admin_View("admin.html");
+ $v->page_title = t("Languages and translations");
$v->content = new View("admin_languages.html");
$v->content->available_locales = locales::available();
$v->content->installed_locales = locales::installed();
diff --git a/modules/gallery/controllers/admin_modules.php b/modules/gallery/controllers/admin_modules.php
index 30e1ace5..bf638a37 100644
--- a/modules/gallery/controllers/admin_modules.php
+++ b/modules/gallery/controllers/admin_modules.php
@@ -20,6 +20,7 @@
class Admin_Modules_Controller extends Admin_Controller {
public function index() {
$view = new Admin_View("admin.html");
+ $view->page_title = t("Modules");
$view->content = new View("admin_modules.html");
$view->content->available = module::available();
print $view;
diff --git a/modules/gallery/controllers/admin_sidebar.php b/modules/gallery/controllers/admin_sidebar.php
index 73f84d2f..fb857e4e 100644
--- a/modules/gallery/controllers/admin_sidebar.php
+++ b/modules/gallery/controllers/admin_sidebar.php
@@ -20,6 +20,7 @@
class Admin_Sidebar_Controller extends Admin_Controller {
public function index() {
$view = new Admin_View("admin.html");
+ $view->page_title = t("Manage sidebar");
$view->content = new View("admin_sidebar.html");
$view->content->csrf = access::csrf_token();
$view->content->available = new View("admin_sidebar_blocks.html");
diff --git a/modules/gallery/controllers/admin_theme_options.php b/modules/gallery/controllers/admin_theme_options.php
index cf4fb77a..15a42ee5 100644
--- a/modules/gallery/controllers/admin_theme_options.php
+++ b/modules/gallery/controllers/admin_theme_options.php
@@ -20,6 +20,7 @@
class Admin_Theme_Options_Controller extends Admin_Controller {
public function index() {
$view = new Admin_View("admin.html");
+ $view->page_title = t("Theme options");
$view->content = new View("admin_theme_options.html");
$view->content->form = theme::get_edit_form_admin();
print $view;
diff --git a/modules/gallery/controllers/admin_themes.php b/modules/gallery/controllers/admin_themes.php
index 327ea6c8..e59eadaf 100644
--- a/modules/gallery/controllers/admin_themes.php
+++ b/modules/gallery/controllers/admin_themes.php
@@ -20,6 +20,7 @@
class Admin_Themes_Controller extends Admin_Controller {
public function index() {
$view = new Admin_View("admin.html");
+ $view->page_title = t("Theme choice");
$view->content = new View("admin_themes.html");
$view->content->admin = module::get_var("gallery", "active_admin_theme");
$view->content->site = module::get_var("gallery", "active_site_theme");
diff --git a/modules/gallery/controllers/albums.php b/modules/gallery/controllers/albums.php
index 730db9ae..ea15418f 100644
--- a/modules/gallery/controllers/albums.php
+++ b/modules/gallery/controllers/albums.php
@@ -107,6 +107,7 @@ class Albums_Controller extends Items_Controller {
if ($valid) {
$album->save();
+ module::event("album_add_form_completed", $album, $form);
log::success("content", "Created an album",
html::anchor("albums/$album->id", "view album"));
message::success(t("Created album %album_title",
diff --git a/modules/gallery/controllers/reauthenticate.php b/modules/gallery/controllers/reauthenticate.php
index b2a67f01..3503d80a 100644
--- a/modules/gallery/controllers/reauthenticate.php
+++ b/modules/gallery/controllers/reauthenticate.php
@@ -63,7 +63,7 @@ class Reauthenticate_Controller extends Controller {
$group->password("password")->label(t("Password"))->id("g-password")->class(null)
->callback("auth::validate_too_many_failed_auth_attempts")
->callback("user::valid_password")
- ->error_messages("invalid", t("Incorrect password"))
+ ->error_messages("invalid_password", t("Incorrect password"))
->error_messages(
"too_many_failed_auth_attempts",
t("Too many incorrect passwords. Try again later"));
diff --git a/modules/gallery/helpers/album.php b/modules/gallery/helpers/album.php
index 521806a0..0baae631 100644
--- a/modules/gallery/helpers/album.php
+++ b/modules/gallery/helpers/album.php
@@ -45,9 +45,13 @@ class album_Core {
->error_messages("required", t("You must provide an internet address"))
->error_messages("length", t("Your internet address is too long"));
$group->hidden("type")->value("album");
+
+ module::event("album_add_form", $parent, $form);
+
$group->submit("")->value(t("Create"));
$form->script("")
->url(url::abs_file("modules/gallery/js/albums_form_add.js"));
+
return $form;
}
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index d723cc1b..2416f2e5 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -97,6 +97,17 @@ class gallery_event_Core {
static function item_deleted($item) {
access::delete_item($item);
+
+ $parent = $item->parent();
+ if (!$parent->album_cover_item_id) {
+ // Assume we deleted the album cover and pick a new one. Choosing the first photo in the
+ // album is logical, but it's not the most efficient in the case where we're deleting all
+ // the photos in the album one at a time since we'll probably delete them in order which
+ // means that we'll be resetting the album cover each time.
+ if ($child = $parent->children(1)->current()) {
+ item::make_album_cover($child);
+ }
+ }
}
static function item_moved($item, $old_parent) {
diff --git a/modules/gallery/helpers/gallery_task.php b/modules/gallery/helpers/gallery_task.php
index fa95c612..bc128b3e 100644
--- a/modules/gallery/helpers/gallery_task.php
+++ b/modules/gallery/helpers/gallery_task.php
@@ -18,6 +18,9 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class gallery_task_Core {
+ const MPTT_LEFT = 0;
+ const MPTT_RIGHT = 1;
+
static function available_tasks() {
$dirty_count = graphics::find_dirty_images_query()->count_records();
$tasks = array();
@@ -42,6 +45,14 @@ class gallery_task_Core {
->name(t("Remove old files"))
->description(t("Remove expired files from the logs and tmp directory"))
->severity(log::SUCCESS);
+
+ $tasks[] = Task_Definition::factory()
+ ->callback("gallery_task::fix_mptt")
+ ->name(t("Fix Album/Photo hierarchy"))
+ ->description(t("Fix problems where your album/photo breadcrumbs are out of " .
+ "sync with your actual hierarchy."))
+ ->severity(log::SUCCESS);
+
return $tasks;
}
@@ -298,4 +309,79 @@ class gallery_task_Core {
$task->log($errors);
}
}
+
+ static function fix_mptt($task) {
+ $start = microtime(true);
+
+ $total = $task->get("total");
+ if (empty($total)) {
+ $task->set("total", $total = db::build()->count_records("items"));
+ $task->set("stack", "1:" . self::MPTT_LEFT);
+ $task->set("ptr", 1);
+ $task->set("completed", 0);
+ }
+
+ $ptr = $task->get("ptr");
+ $stack = explode(" ", $task->get("stack"));
+ $completed = $task->get("completed");
+
+ // Implement a depth-first tree walk using a stack. Not the most efficient, but it's simple.
+ while ($stack && microtime(true) - $start < 1.5) {
+ list($id, $state) = explode(":", array_pop($stack));
+ switch ($state) {
+ case self::MPTT_LEFT:
+ self::fix_mptt_set_left($id, $ptr++);
+ $item = ORM::factory("item", $id);
+ array_push($stack, $id . ":" . self::MPTT_RIGHT);
+ foreach (self::fix_mptt_children($id) as $child) {
+ array_push($stack, $child->id . ":" . self::MPTT_LEFT);
+ }
+ break;
+
+ case self::MPTT_RIGHT:
+ self::fix_mptt_set_right($id, $ptr++);
+ $completed++;
+ break;
+ }
+ }
+
+ $task->set("stack", implode(" ", $stack));
+ $task->set("ptr", $ptr);
+ $task->set("completed", $completed);
+
+ if ($total == $completed) {
+ $task->done = true;
+ $task->state = "success";
+ $task->percent_complete = 100;
+ } else {
+ $task->percent_complete = round(100 * $completed / $total);
+ }
+ $task->status = t2("One row updated", "%count / %total rows updated", $completed,
+ array("total" => $total));
+ }
+
+ static function fix_mptt_children($parent_id) {
+ return db::build()
+ ->select("id")
+ ->from("items")
+ ->where("parent_id", "=", $parent_id)
+ ->order_by("left_ptr", "ASC")
+ ->execute();
+ }
+
+ static function fix_mptt_set_left($id, $value) {
+ db::build()
+ ->update("items")
+ ->set("left_ptr", $value)
+ ->where("id", "=", $id)
+ ->execute();
+ }
+
+ static function fix_mptt_set_right($id, $value) {
+ db::build()
+ ->update("items")
+ ->set("right_ptr", $value)
+ ->where("id", "=", $id)
+ ->execute();
+ }
} \ No newline at end of file
diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php
index 16abec5a..36d2ca62 100644
--- a/modules/gallery/helpers/item_rest.php
+++ b/modules/gallery/helpers/item_rest.php
@@ -70,49 +70,70 @@ class item_rest_Core {
$orm->where("type", "IN", explode(",", $p->type));
}
- $members = array();
- foreach ($orm->find_all() as $child) {
- $members[] = rest::url("item", $child);
+ // Apply the item's sort order, using id as the tie breaker.
+ // See Item_Model::children()
+ $order_by = array($item->sort_column => $item->sort_order);
+ if ($item->sort_column != "id") {
+ $order_by["id"] = "ASC";
}
+ $orm->order_by($order_by);
- return array(
+ $result = array(
"url" => $request->url,
"entity" => $item->as_restful_array(),
- "members" => $members,
"relationships" => rest::relationships("item", $item));
+ if ($item->is_album()) {
+ $result["members"] = array();
+ foreach ($orm->find_all() as $child) {
+ $result["members"][] = rest::url("item", $child);
+ }
+ }
+
+ return $result;
}
static function put($request) {
$item = rest::resolve($request->url);
access::required("edit", $item);
- $params = $request->params;
-
- // Only change fields from a whitelist.
- foreach (array("album_cover", "captured", "description",
- "height", "mime_type", "name", "parent", "rand_key", "resize_dirty",
- "resize_height", "resize_width", "slug", "sort_column", "sort_order",
- "thumb_dirty", "thumb_height", "thumb_width", "title", "view_count",
- "weight", "width") as $key) {
- switch ($key) {
- case "album_cover":
- if (property_exists($request->params, "album_cover")) {
- $album_cover_item = rest::resolve($request->params->album_cover);
- access::required("view", $album_cover_item);
- $item->album_cover_item_id = $album_cover_item->id;
+ if ($entity = $request->params->entity) {
+ // Only change fields from a whitelist.
+ foreach (array("album_cover", "captured", "description",
+ "height", "mime_type", "name", "parent", "rand_key", "resize_dirty",
+ "resize_height", "resize_width", "slug", "sort_column", "sort_order",
+ "thumb_dirty", "thumb_height", "thumb_width", "title", "view_count",
+ "width") as $key) {
+ switch ($key) {
+ case "album_cover":
+ if (property_exists($entity, "album_cover")) {
+ $album_cover_item = rest::resolve($entity->album_cover);
+ access::required("view", $album_cover_item);
+ $item->album_cover_item_id = $album_cover_item->id;
+ }
+ break;
+
+ case "parent":
+ if (property_exists($entity, "parent")) {
+ $parent = rest::resolve($entity->parent);
+ access::required("edit", $parent);
+ $item->parent_id = $parent->id;
+ }
+ break;
+ default:
+ if (property_exists($entity, $key)) {
+ $item->$key = $entity->$key;
+ }
}
- break;
+ }
+ }
- case "parent":
- if (property_exists($request->params, "parent")) {
- $parent = rest::resolve($request->params->parent);
- access::required("edit", $parent);
- $item->parent_id = $parent->id;
- }
- break;
- default:
- if (property_exists($request->params, $key)) {
- $item->$key = $request->params->$key;
+ $weight = 0;
+ if (isset($request->params->members)) {
+ foreach ($request->params->members as $url) {
+ $child = rest::resolve($url);
+ if ($child->parent_id == $item->id && $child->weight != $weight) {
+ $child->weight = $weight++;
+ $child->save();
}
}
}
@@ -123,33 +144,33 @@ class item_rest_Core {
$parent = rest::resolve($request->url);
access::required("edit", $parent);
- $params = $request->params;
+ $entity = $request->params->entity;
$item = ORM::factory("item");
- switch ($params->type) {
+ switch ($entity->type) {
case "album":
$item->type = "album";
$item->parent_id = $parent->id;
- $item->name = $params->name;
- $item->title = isset($params->title) ? $params->title : $name;
- $item->description = isset($params->description) ? $params->description : null;
- $item->slug = isset($params->slug) ? $params->slug : null;
+ $item->name = $entity->name;
+ $item->title = isset($entity->title) ? $entity->title : $name;
+ $item->description = isset($entity->description) ? $entity->description : null;
+ $item->slug = isset($entity->slug) ? $entity->slug : null;
$item->save();
break;
case "photo":
case "movie":
- $item->type = $params->type;
+ $item->type = $entity->type;
$item->parent_id = $parent->id;
$item->set_data_file($request->file);
- $item->name = $params->name;
- $item->title = isset($params->title) ? $params->title : $params->name;
- $item->description = isset($params->description) ? $params->description : null;
- $item->slug = isset($params->slug) ? $params->slug : null;
+ $item->name = $entity->name;
+ $item->title = isset($entity->title) ? $entity->title : $entity->name;
+ $item->description = isset($entity->description) ? $entity->description : null;
+ $item->slug = isset($entity->slug) ? $entity->slug : null;
$item->save();
break;
default:
- throw new Rest_Exception("Invalid type: $params->type", 400);
+ throw new Rest_Exception("Invalid type: $entity->type", 400);
}
return array("url" => rest::url("item", $item));
diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php
index 05ca65cf..5d8e80b2 100644
--- a/modules/gallery/helpers/items_rest.php
+++ b/modules/gallery/helpers/items_rest.php
@@ -22,19 +22,20 @@ class items_rest_Core {
$items = array();
if (isset($request->params->url)) {
- foreach($request->params->url as $url) {
+ foreach (json_decode($request->params->url) as $url) {
$item = rest::resolve($url);
if (access::can("view", $item)) {
- $members = array();
+ $item_rest = array("url" => $url,
+ "entity" => $item->as_restful_array(),
+ "relationship" => rest::relationships("item", $item));
if ($item->type == "album") {
+ $members = array();
foreach ($item->children() as $child) {
$members[] = rest::url("item", $child);
}
+ $item_rest["members"] = $members;
}
- $items[] = array("url" => $url,
- "entity" => $item->as_restful_array(),
- "members" => $members,
- "relationship" => rest::relationships("item", $item));
+ $items[] = $item_rest;
}
}
}
diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php
index ae5f030c..980ee11a 100644
--- a/modules/gallery/helpers/theme.php
+++ b/modules/gallery/helpers/theme.php
@@ -73,12 +73,18 @@ class theme_Core {
$group = $form->group("edit_theme");
$group->input("page_size")->label(t("Items per page"))->id("g-page-size")
->rules("required|valid_digit")
+ ->error_messages("required", t("You must enter a number"))
+ ->error_messages("valid_digit", t("You must enter a number"))
->value(module::get_var("gallery", "page_size"));
$group->input("thumb_size")->label(t("Thumbnail size (in pixels)"))->id("g-thumb-size")
->rules("required|valid_digit")
+ ->error_messages("required", t("You must enter a number"))
+ ->error_messages("valid_digit", t("You must enter a number"))
->value(module::get_var("gallery", "thumb_size"));
$group->input("resize_size")->label(t("Resized image size (in pixels)"))->id("g-resize-size")
->rules("required|valid_digit")
+ ->error_messages("required", t("You must enter a number"))
+ ->error_messages("valid_digit", t("You must enter a number"))
->value(module::get_var("gallery", "resize_size"));
$group->textarea("header_text")->label(t("Header text"))->id("g-header-text")
->value(module::get_var("gallery", "header_text"));
diff --git a/modules/gallery/libraries/MY_Input.php b/modules/gallery/libraries/MY_Input.php
index 703136c7..1d5949e8 100644
--- a/modules/gallery/libraries/MY_Input.php
+++ b/modules/gallery/libraries/MY_Input.php
@@ -26,6 +26,6 @@ class Input extends Input_Core {
* @return string
*/
public function clean_input_keys($str) {
- return preg_replace('#^[\pL0-9:_.-]++$#uD', '_', $str);
+ return preg_replace('#[^a-zA-Z0-9:_.-]+#', '_', $str);
}
}
diff --git a/modules/gallery/models/item.php b/modules/gallery/models/item.php
index 6ede5109..7fc37325 100644
--- a/modules/gallery/models/item.php
+++ b/modules/gallery/models/item.php
@@ -332,6 +332,12 @@ class Item_Model extends ORM_MPTT {
$tmp = pathinfo($this->name, PATHINFO_FILENAME);
$tmp = preg_replace("/[^A-Za-z0-9-_]+/", "-", $tmp);
$this->slug = trim($tmp, "-");
+
+ // If the filename is all invalid characters, then the slug may be empty here. Pick a
+ // random value.
+ if (empty($this->slug)) {
+ $this->slug = (string)rand(1000, 9999);
+ }
}
// Get the width, height and mime type from our data file for photos and movies.
@@ -941,7 +947,7 @@ class Item_Model extends ORM_MPTT {
// Elide some internal-only data that is going to cause confusion in the client.
foreach (array("relative_path_cache", "relative_url_cache", "left_ptr", "right_ptr",
- "thumb_dirty", "resize_dirty") as $key) {
+ "thumb_dirty", "resize_dirty", "weight") as $key) {
unset($data[$key]);
}
return $data;
diff --git a/modules/gallery/tests/Input_Library_Test.php b/modules/gallery/tests/Input_Library_Test.php
new file mode 100644
index 00000000..06641323
--- /dev/null
+++ b/modules/gallery/tests/Input_Library_Test.php
@@ -0,0 +1,25 @@
+<?php defined("SYSPATH") or die("No direct script access.");
+/**
+ * Gallery - a web based photo album viewer and editor
+ * Copyright (C) 2000-2010 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_Library_Test extends Gallery_Unit_Test_Case {
+ function clean_input_keys_test() {
+ $input = Input::instance();
+ $this->assert_same("foo_bar", $input->clean_input_keys("foo|bar"));
+ }
+} \ No newline at end of file
diff --git a/modules/gallery/tests/Item_Helper_Test.php b/modules/gallery/tests/Item_Helper_Test.php
index 295871a5..4771b11a 100644
--- a/modules/gallery/tests/Item_Helper_Test.php
+++ b/modules/gallery/tests/Item_Helper_Test.php
@@ -54,7 +54,6 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case {
$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();
@@ -106,4 +105,16 @@ class Item_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_not_same("{$rand}.jpg", $photo2->name);
$this->assert_not_same($rand, $photo2->slug);
}
+
+ public function delete_cover_photo_picks_new_album_cover() {
+ $album = test::random_album();
+ $photo1 = test::random_photo($album);
+ // At this point, $photo1 is the album cover. We verify this in
+ // Item_Model_Test::first_photo_becomes_album_cover
+ $photo2 = test::random_photo($album);
+ $photo1->delete();
+ $album->reload();
+
+ $this->assert_same($photo2->id, $album->album_cover_item_id);
+ }
}
diff --git a/modules/gallery/tests/Item_Model_Test.php b/modules/gallery/tests/Item_Model_Test.php
index d0676292..15aa2d8c 100644
--- a/modules/gallery/tests/Item_Model_Test.php
+++ b/modules/gallery/tests/Item_Model_Test.php
@@ -295,7 +295,6 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
} catch (ORM_Validation_Exception $e) {
$this->assert_same(array("description" => "length",
"name" => "required",
- "slug" => "required",
"title" => "required",
"album_cover_item_id" => "invalid_item",
"parent_id" => "invalid",
@@ -324,6 +323,12 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
$album->save();
}
+ public function name_with_only_invalid_chars_is_still_valid_test() {
+ $album = test::random_album_unsaved();
+ $album->name = "[]";
+ $album->save();
+ }
+
public function cant_change_item_type_test() {
$photo = test::random_photo();
try {
@@ -358,4 +363,12 @@ class Item_Model_Test extends Gallery_Unit_Test_Case {
$this->assert_true(!array_key_exists("parent_id", $result));
$this->assert_true(!array_key_exists("album_cover_item_id", $result));
}
+
+ public function first_photo_becomes_album_cover() {
+ $album = test::random_album();
+ $photo = test::random_photo($album);
+ $album->reload();
+
+ $this->assert_same($photo->id, $album->album_cover_item_id);
+ }
}
diff --git a/modules/gallery/tests/Item_Rest_Helper_Test.php b/modules/gallery/tests/Item_Rest_Helper_Test.php
index bef95668..0b5e0471 100644
--- a/modules/gallery/tests/Item_Rest_Helper_Test.php
+++ b/modules/gallery/tests/Item_Rest_Helper_Test.php
@@ -42,13 +42,14 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_equal_array(
array("url" => rest::url("item", $album1),
"entity" => $album1->as_restful_array(),
- "members" => array(
- rest::url("item", $photo1),
- rest::url("item", $album2)),
"relationships" => array(
"tags" => array(
"url" => rest::url("item_tags", $album1),
- "members" => array()))),
+ "members" => array())),
+ "members" => array(
+ rest::url("item", $photo1),
+ rest::url("item", $album2)),
+ ),
item_rest::get($request));
$request->url = rest::url("item", $album1);
@@ -56,13 +57,14 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_equal_array(
array("url" => rest::url("item", $album1),
"entity" => $album1->as_restful_array(),
- "members" => array(
- rest::url("item", $photo1),
- rest::url("item", $album2)),
"relationships" => array(
"tags" => array(
"url" => rest::url("item_tags", $album1),
- "members" => array()))),
+ "members" => array())),
+ "members" => array(
+ rest::url("item", $photo1),
+ rest::url("item", $album2)),
+ ),
item_rest::get($request));
$request->url = rest::url("item", $album1);
@@ -70,14 +72,15 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_equal_array(
array("url" => rest::url("item", $album1),
"entity" => $album1->as_restful_array(),
+ "relationships" => array(
+ "tags" => array(
+ "url" => rest::url("item_tags", $album1),
+ "members" => array())),
"members" => array(
rest::url("item", $photo1),
rest::url("item", $album2),
rest::url("item", $photo2)),
- "relationships" => array(
- "tags" => array(
- "url" => rest::url("item_tags", $album1),
- "members" => array()))),
+ ),
item_rest::get($request));
}
@@ -96,12 +99,13 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_equal_array(
array("url" => rest::url("item", $album1),
"entity" => $album1->as_restful_array(),
- "members" => array(
- rest::url("item", $photo2)),
"relationships" => array(
"tags" => array(
"url" => rest::url("item_tags", $album1),
- "members" => array()))),
+ "members" => array())),
+ "members" => array(
+ rest::url("item", $photo2)),
+ ),
item_rest::get($request));
}
@@ -118,12 +122,13 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$this->assert_equal_array(
array("url" => rest::url("item", $album1),
"entity" => $album1->as_restful_array(),
- "members" => array(
- rest::url("item", $album2)),
"relationships" => array(
"tags" => array(
"url" => rest::url("item_tags", $album1),
- "members" => array() ))),
+ "members" => array())),
+ "members" => array(
+ rest::url("item", $album2)),
+ ),
item_rest::get($request));
}
@@ -134,7 +139,8 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$request = new stdClass();
$request->url = rest::url("item", $album1);
$request->params = new stdClass();
- $request->params->title = "my new title";
+ $request->params->entity = new stdClass();
+ $request->params->entity->title = "my new title";
item_rest::put($request);
$this->assert_equal("my new title", $album1->reload()->title);
@@ -147,8 +153,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$request = new stdClass();
$request->url = rest::url("item", $album1);
$request->params = new stdClass();
- $request->params->title = "my new title";
- $request->params->slug = "not url safe";
+ $request->params->entity = new stdClass();
+ $request->params->entity->title = "my new title";
+ $request->params->entity->slug = "not url safe";
try {
item_rest::put($request);
@@ -166,9 +173,10 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$request = new stdClass();
$request->url = rest::url("item", $album1);
$request->params = new stdClass();
- $request->params->type = "album";
- $request->params->name = "my album";
- $request->params->title = "my album";
+ $request->params->entity = new stdClass();
+ $request->params->entity->type = "album";
+ $request->params->entity->name = "my album";
+ $request->params->entity->title = "my album";
$response = item_rest::post($request);
$new_album = rest::resolve($response["url"]);
@@ -183,10 +191,11 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$request = new stdClass();
$request->url = rest::url("item", $album1);
$request->params = new stdClass();
- $request->params->type = "album";
- $request->params->name = "my album";
- $request->params->title = "my album";
- $request->params->slug = "not url safe";
+ $request->params->entity = new stdClass();
+ $request->params->entity->type = "album";
+ $request->params->entity->name = "my album";
+ $request->params->entity->title = "my album";
+ $request->params->entity->slug = "not url safe";
try {
item_rest::post($request);
@@ -205,8 +214,9 @@ class Item_Rest_Helper_Test extends Gallery_Unit_Test_Case {
$request = new stdClass();
$request->url = rest::url("item", $album1);
$request->params = new stdClass();
- $request->params->type = "photo";
- $request->params->name = "my photo.jpg";
+ $request->params->entity = new stdClass();
+ $request->params->entity->type = "photo";
+ $request->params->entity->name = "my photo.jpg";
$request->file = MODPATH . "gallery/tests/test.jpg";
$response = item_rest::post($request);
$new_photo = rest::resolve($response["url"]);
diff --git a/modules/gallery/tests/xss_data.txt b/modules/gallery/tests/xss_data.txt
index a3ca31f4..afad9e13 100644
--- a/modules/gallery/tests/xss_data.txt
+++ b/modules/gallery/tests/xss_data.txt
@@ -70,12 +70,12 @@ modules/gallery/views/admin_graphics_imagemagick.html.php 2 DIRTY_ATTR $is_
modules/gallery/views/admin_graphics_imagemagick.html.php 2 DIRTY_ATTR $tk->installed?" g-installed-toolkit":" g-unavailable"
modules/gallery/views/admin_graphics_imagemagick.html.php 18 DIRTY $tk->error
modules/gallery/views/admin_languages.html.php 43 DIRTY access::csrf_form_field()
-modules/gallery/views/admin_languages.html.php 60 DIRTY_ATTR (isset($installed_locales[$code]))?"g-available":""
-modules/gallery/views/admin_languages.html.php 60 DIRTY_ATTR ($default_locale==$code)?" g-selected":""
-modules/gallery/views/admin_languages.html.php 61 DIRTY form::checkbox("installed_locales[]",$code,isset($installed_locales[$code]))
-modules/gallery/views/admin_languages.html.php 62 DIRTY $display_name
-modules/gallery/views/admin_languages.html.php 64 DIRTY form::radio("default_locale",$code,($default_locale==$code),((isset($installed_locales[$code]))?'':'disabled="disabled"'))
-modules/gallery/views/admin_languages.html.php 109 DIRTY $share_translations_form
+modules/gallery/views/admin_languages.html.php 61 DIRTY_ATTR (isset($installed_locales[$code]))?"g-available":""
+modules/gallery/views/admin_languages.html.php 61 DIRTY_ATTR ($default_locale==$code)?" g-selected":""
+modules/gallery/views/admin_languages.html.php 62 DIRTY form::checkbox("installed_locales[]",$code,isset($installed_locales[$code]))
+modules/gallery/views/admin_languages.html.php 63 DIRTY $display_name
+modules/gallery/views/admin_languages.html.php 65 DIRTY form::radio("default_locale",$code,($default_locale==$code),((isset($installed_locales[$code]))?'':'disabled="disabled"'))
+modules/gallery/views/admin_languages.html.php 110 DIRTY $share_translations_form
modules/gallery/views/admin_maintenance.html.php 24 DIRTY_ATTR text::alternate("g-odd","g-even")
modules/gallery/views/admin_maintenance.html.php 24 DIRTY_ATTR log::severity_class($task->severity)
modules/gallery/views/admin_maintenance.html.php 25 DIRTY_ATTR log::severity_class($task->severity)
@@ -121,10 +121,10 @@ modules/gallery/views/admin_themes.html.php 76 DIRTY $info-
modules/gallery/views/admin_themes.html.php 78 DIRTY $info->description
modules/gallery/views/admin_themes_preview.html.php 7 DIRTY_ATTR $url
modules/gallery/views/error_404.html.php 14 DIRTY $login_form
-modules/gallery/views/form_uploadify.html.php 30 DIRTY_JS url::file("lib/uploadify/uploadify.swf")
-modules/gallery/views/form_uploadify.html.php 31 DIRTY_JS url::site("simple_uploader/add_photo/{$album->id}")
-modules/gallery/views/form_uploadify.html.php 35 DIRTY_JS url::file("lib/uploadify/cancel.png")
-modules/gallery/views/form_uploadify.html.php 36 DIRTY_JS $simultaneous_upload_limit
+modules/gallery/views/form_uploadify.html.php 9 DIRTY_JS url::file("lib/uploadify/uploadify.swf")
+modules/gallery/views/form_uploadify.html.php 10 DIRTY_JS url::site("simple_uploader/add_photo/{$album->id}")
+modules/gallery/views/form_uploadify.html.php 14 DIRTY_JS url::file("lib/uploadify/cancel.png")
+modules/gallery/views/form_uploadify.html.php 15 DIRTY_JS $simultaneous_upload_limit
modules/gallery/views/in_place_edit.html.php 2 DIRTY form::open($action,array("method"=>"post","id"=>"g-in-place-edit-form","class"=>"g-short-form"))
modules/gallery/views/in_place_edit.html.php 3 DIRTY access::csrf_form_field()
modules/gallery/views/in_place_edit.html.php 6 DIRTY form::input("input",$form["input"]," class=\"textbox\"")
@@ -320,19 +320,20 @@ modules/user/views/admin_users_group.html.php 24 DIRTY_JS $group
modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $width
modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $height
modules/watermark/views/admin_watermarks.html.php 20 DIRTY_ATTR $url
-themes/admin_wind/views/admin.html.php 16 DIRTY_JS $theme->url()
-themes/admin_wind/views/admin.html.php 33 DIRTY $theme->admin_head()
-themes/admin_wind/views/admin.html.php 37 DIRTY $theme->admin_page_top()
-themes/admin_wind/views/admin.html.php 45 DIRTY $theme->admin_header_top()
-themes/admin_wind/views/admin.html.php 46 DIRTY_JS item::root()->url()
-themes/admin_wind/views/admin.html.php 49 DIRTY $theme->user_menu()
-themes/admin_wind/views/admin.html.php 51 DIRTY $theme->admin_menu()
-themes/admin_wind/views/admin.html.php 53 DIRTY $theme->admin_header_bottom()
-themes/admin_wind/views/admin.html.php 60 DIRTY $content
-themes/admin_wind/views/admin.html.php 66 DIRTY $sidebar
-themes/admin_wind/views/admin.html.php 71 DIRTY $theme->admin_footer()
-themes/admin_wind/views/admin.html.php 73 DIRTY $theme->admin_credits()
-themes/admin_wind/views/admin.html.php 77 DIRTY $theme->admin_page_bottom()
+themes/admin_wind/views/admin.html.php 9 DIRTY $page_title
+themes/admin_wind/views/admin.html.php 22 DIRTY_JS $theme->url()
+themes/admin_wind/views/admin.html.php 39 DIRTY $theme->admin_head()
+themes/admin_wind/views/admin.html.php 43 DIRTY $theme->admin_page_top()
+themes/admin_wind/views/admin.html.php 51 DIRTY $theme->admin_header_top()
+themes/admin_wind/views/admin.html.php 52 DIRTY_JS item::root()->url()
+themes/admin_wind/views/admin.html.php 55 DIRTY $theme->user_menu()
+themes/admin_wind/views/admin.html.php 57 DIRTY $theme->admin_menu()
+themes/admin_wind/views/admin.html.php 59 DIRTY $theme->admin_header_bottom()
+themes/admin_wind/views/admin.html.php 66 DIRTY $content
+themes/admin_wind/views/admin.html.php 72 DIRTY $sidebar
+themes/admin_wind/views/admin.html.php 77 DIRTY $theme->admin_footer()
+themes/admin_wind/views/admin.html.php 79 DIRTY $theme->admin_credits()
+themes/admin_wind/views/admin.html.php 83 DIRTY $theme->admin_page_bottom()
themes/admin_wind/views/block.html.php 3 DIRTY_ATTR $anchor
themes/admin_wind/views/block.html.php 5 DIRTY $id
themes/admin_wind/views/block.html.php 5 DIRTY_ATTR $css_id
diff --git a/modules/gallery/views/movieplayer.html.php b/modules/gallery/views/movieplayer.html.php
index f7af8d93..2e79b620 100644
--- a/modules/gallery/views/movieplayer.html.php
+++ b/modules/gallery/views/movieplayer.html.php
@@ -5,12 +5,13 @@
"<?= $attrs["id"] ?>",
{
src: "<?= url::abs_file("lib/flowplayer.swf") ?>",
- wmode: "transparent"
+ wmode: "transparent",
+ provider: "pseudostreaming"
},
{
plugins: {
- h264streaming: {
- url: "<?= url::abs_file("lib/flowplayer.h264streaming.swf") ?>"
+ pseudostreaming: {
+ url: "<?= url::abs_file("lib/flowplayer.pseudostreaming.swf") ?>"
},
controls: {
autoHide: 'always',