summaryrefslogtreecommitdiff
path: root/modules/gallery/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gallery/helpers')
-rw-r--r--modules/gallery/helpers/MY_url.php6
-rw-r--r--modules/gallery/helpers/auth.php1
-rw-r--r--modules/gallery/helpers/gallery.php2
-rw-r--r--modules/gallery/helpers/gallery_block.php4
-rw-r--r--modules/gallery/helpers/gallery_event.php91
-rw-r--r--modules/gallery/helpers/gallery_rss.php8
-rw-r--r--modules/gallery/helpers/item.php9
-rw-r--r--modules/gallery/helpers/item_rest.php36
-rw-r--r--modules/gallery/helpers/items_rest.php70
-rw-r--r--modules/gallery/helpers/message.php1
-rw-r--r--modules/gallery/helpers/module.php7
-rw-r--r--modules/gallery/helpers/photo.php2
-rw-r--r--modules/gallery/helpers/site_status.php2
-rw-r--r--modules/gallery/helpers/theme.php16
14 files changed, 194 insertions, 61 deletions
diff --git a/modules/gallery/helpers/MY_url.php b/modules/gallery/helpers/MY_url.php
index 57ce9623..877c5ada 100644
--- a/modules/gallery/helpers/MY_url.php
+++ b/modules/gallery/helpers/MY_url.php
@@ -70,8 +70,7 @@ class url extends url_Core {
* Just like url::file() except that it returns an absolute URI
*/
static function abs_file($path) {
- return url::base(
- false, (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off') ? 'http' : 'https') . $path;
+ return url::base(false, request::protocol()) . $path;
}
/**
@@ -79,8 +78,7 @@ class url extends url_Core {
* doesn't take a protocol parameter.
*/
static function abs_site($path) {
- return url::site(
- $path, (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off') ? 'http' : 'https');
+ return url::site($path, request::protocol());
}
/**
diff --git a/modules/gallery/helpers/auth.php b/modules/gallery/helpers/auth.php
index 1a9fe869..48b5fc32 100644
--- a/modules/gallery/helpers/auth.php
+++ b/modules/gallery/helpers/auth.php
@@ -21,6 +21,7 @@ class auth_Core {
static function get_login_form($url) {
$form = new Forge($url, "", "post", array("id" => "g-login-form"));
$form->set_attr("class", "g-narrow");
+ $form->hidden("continue_url")->value(Session::instance()->get("continue_url"));
$group = $form->group("login")->label(t("Login"));
$group->input("name")->label(t("Username"))->id("g-username")->class(null)
->callback("auth::validate_too_many_failed_logins")
diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php
index 7f7db10b..d4078209 100644
--- a/modules/gallery/helpers/gallery.php
+++ b/modules/gallery/helpers/gallery.php
@@ -18,7 +18,7 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class gallery_Core {
- const VERSION = "3.0 RC1 (Santa Fe)";
+ const VERSION = "3.0 RC2 (Santa Fe)";
/**
* If Gallery is in maintenance mode, then force all non-admins to get routed to a "This site is
diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php
index 08ce21b7..cb28cbcd 100644
--- a/modules/gallery/helpers/gallery_block.php
+++ b/modules/gallery/helpers/gallery_block.php
@@ -70,9 +70,9 @@ 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") && $first_line = current(@file("/proc/loadavg"))) {
$block->content->load_average =
- join(" ", array_slice(explode(" ", current(file("/proc/loadavg"))), 0, 3));
+ join(" ", array_slice(explode(" ", $first_line), 0, 3));
} else {
$block->content->load_average = t("Unavailable");
}
diff --git a/modules/gallery/helpers/gallery_event.php b/modules/gallery/helpers/gallery_event.php
index 2416f2e5..272fd205 100644
--- a/modules/gallery/helpers/gallery_event.php
+++ b/modules/gallery/helpers/gallery_event.php
@@ -98,6 +98,15 @@ class gallery_event_Core {
static function item_deleted($item) {
access::delete_item($item);
+ // Find any other albums that had the deleted item as the album cover and null it out.
+ // In some cases this may leave us with a missing album cover up in this item's parent
+ // hierarchy, but in most cases it'll work out fine.
+ foreach (ORM::factory("item")
+ ->where("album_cover_item_id", "=", $item->id)
+ ->find_all() as $parent) {
+ item::remove_album_cover($parent);
+ }
+
$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
@@ -157,17 +166,28 @@ class gallery_event_Core {
->view("login_current_user.html")
->url(user_profile::url($user->id))
->label($user->display_name()));
+
+ if (isset($theme->item)) {
+ if (access::user_can(identity::guest(), "view", $theme->item)) {
+ $continue_url = $theme->item->abs_url();
+ } else {
+ $continue_url = item::root()->abs_url();
+ }
+ } else {
+ $continue_url = url::abs_current();
+ }
+
$menu->append(Menu::factory("link")
->id("user_menu_logout")
->css_id("g-logout-link")
- ->url(url::site("logout?csrf=$csrf&continue=" .
- urlencode(url::abs_current())))
+ ->url(url::site("logout?csrf=$csrf&continue_url=" .
+ urlencode($continue_url)))
->label(t("Logout")));
}
}
}
- static function site_menu($menu, $theme) {
+ static function site_menu($menu, $theme, $item_css_selector) {
if ($theme->page_subtype != "login") {
$menu->append(Menu::factory("link")
->id("home")
@@ -191,7 +211,7 @@ class gallery_event_Core {
$add_menu->append(Menu::factory("dialog")
->id("add_photos_item")
->label(t("Add photos"))
- ->url(url::site("simple_uploader/app/$item->id")));
+ ->url(url::site("flash_uploader/app/$item->id")));
if ($item->is_album()) {
$add_menu->append(Menu::factory("dialog")
->id("add_album_item")
@@ -208,14 +228,17 @@ class gallery_event_Core {
case "album":
$option_text = t("Album options");
$edit_text = t("Edit album");
+ $delete_text = t("Delete album");
break;
case "movie":
$option_text = t("Movie options");
$edit_text = t("Edit movie");
+ $delete_text = t("Delete movie");
break;
default:
$option_text = t("Photo options");
$edit_text = t("Edit photo");
+ $delete_text = t("Delete photo");
}
$menu->append($options_menu = Menu::factory("submenu")
@@ -238,6 +261,63 @@ class gallery_event_Core {
}
}
}
+
+ $csrf = access::csrf_token();
+ $theme_item = $theme->item();
+ $page_type = $theme->page_type();
+ if ($can_edit && $item->is_photo() && graphics::can("rotate")) {
+ $options_menu
+ ->append(
+ Menu::factory("ajax_link")
+ ->id("rotate_ccw")
+ ->label(t("Rotate 90° counter clockwise"))
+ ->css_class("ui-icon-rotate-ccw")
+ ->ajax_handler("function(data) { " .
+ "\$.gallery_replace_image(data, \$('$item_css_selector')) }")
+ ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type")))
+ ->append(
+ Menu::factory("ajax_link")
+ ->id("rotate_cw")
+ ->label(t("Rotate 90° clockwise"))
+ ->css_class("ui-icon-rotate-cw")
+ ->ajax_handler("function(data) { " .
+ "\$.gallery_replace_image(data, \$('$item_css_selector')) }")
+ ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type")));
+ }
+
+ if ($item->id != item::root()->id) {
+ $parent = $item->parent();
+ if (access::can("edit", $parent)) {
+ // We can't make this item the highlight if it's an album with no album cover, or if it's
+ // already the album cover.
+ if (($item->type == "album" && empty($item->album_cover_item_id)) ||
+ ($item->type == "album" && $parent->album_cover_item_id == $item->album_cover_item_id) ||
+ $parent->album_cover_item_id == $item->id) {
+ $disabledState = " ui-state-disabled";
+ } else {
+ $disabledState = " ";
+ }
+
+ if ($item->parent()->id != 1) {
+ $options_menu
+ ->append(
+ Menu::factory("ajax_link")
+ ->id("make_album_cover")
+ ->label(t("Choose as the album cover"))
+ ->css_class("ui-icon-star")
+ ->ajax_handler("function(data) { window.location.reload() }")
+ ->url(url::site("quick/make_album_cover/$item->id?csrf=$csrf")));
+ }
+ $options_menu
+ ->append(
+ Menu::factory("dialog")
+ ->id("delete")
+ ->label($delete_text)
+ ->css_class("ui-icon-trash")
+ ->css_class("g-quick-delete")
+ ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type")));
+ }
+ }
}
if (identity::active_user()->admin) {
@@ -394,7 +474,6 @@ class gallery_event_Core {
->id("delete")
->label($delete_title)
->css_class("ui-icon-trash")
- ->css_class("g-quick-delete")
->url(url::site("quick/form_delete/$item->id?csrf=$csrf&from_id=$theme_item->id&page_type=$page_type")));
}
@@ -404,7 +483,7 @@ class gallery_event_Core {
->id("add_item")
->label(t("Add a photo"))
->css_class("ui-icon-plus")
- ->url(url::site("simple_uploader/app/$item->id")))
+ ->url(url::site("flash_uploader/app/$item->id")))
->append(Menu::factory("dialog")
->id("add_album")
->label(t("Add an album"))
diff --git a/modules/gallery/helpers/gallery_rss.php b/modules/gallery/helpers/gallery_rss.php
index 9c528c0e..bec34912 100644
--- a/modules/gallery/helpers/gallery_rss.php
+++ b/modules/gallery/helpers/gallery_rss.php
@@ -28,18 +28,18 @@ class gallery_rss_Core {
$feed = new stdClass();
switch ($feed_id) {
case "latest":
- $feed->children = ORM::factory("item")
+ $feed->items = ORM::factory("item")
->viewable()
->where("type", "<>", "album")
->order_by("created", "DESC")
->find_all($limit, $offset);
- $all_children = ORM::factory("item")
+ $all_items = ORM::factory("item")
->viewable()
->where("type", "<>", "album")
->order_by("created", "DESC");
- $feed->max_pages = ceil($all_children->find_all()->count() / $limit);
+ $feed->max_pages = ceil($all_items->find_all()->count() / $limit);
$feed->title = t("Recent updates");
$feed->description = t("Recent updates");
return $feed;
@@ -48,7 +48,7 @@ class gallery_rss_Core {
$item = ORM::factory("item", $id);
access::required("view", $item);
- $feed->children = $item
+ $feed->items = $item
->viewable()
->descendants($limit, $offset, array(array("type", "=", "photo")));
$feed->max_pages = ceil(
diff --git a/modules/gallery/helpers/item.php b/modules/gallery/helpers/item.php
index 43c93225..aef68c6e 100644
--- a/modules/gallery/helpers/item.php
+++ b/modules/gallery/helpers/item.php
@@ -136,7 +136,7 @@ class item_Core {
*/
static function convert_filename_to_title($filename) {
$title = strtr($filename, "_", " ");
- $title = preg_replace("/\..*?$/", "", $title);
+ $title = preg_replace("/\..{3,4}$/", "", $title);
$title = preg_replace("/ +/", " ", $title);
return $title;
}
@@ -162,6 +162,8 @@ class item_Core {
"quick/delete/$item->id?page_type=$page_type", "", "post", array("id" => "g-confirm-delete"));
$group = $form->group("confirm_delete")->label(t("Confirm Deletion"));
$group->submit("")->value(t("Delete"));
+ $form->script("")
+ ->url(url::abs_file("modules/gallery/js/item_form_delete.js"));
return $form;
}
@@ -209,17 +211,14 @@ class item_Core {
/**
* Return a query to get a random Item_Model, with optional filters
- *
- * @param array (optional) where tuple
*/
- static function random_query($where=null) {
+ static function random_query() {
// Pick a random number and find the item that's got nearest smaller number.
// This approach works best when the random numbers in the system are roughly evenly
// distributed so this is going to be more efficient with larger data sets.
return ORM::factory("item")
->viewable()
->where("rand_key", "<", ((float)mt_rand()) / (float)mt_getrandmax())
- ->merge_where($where)
->order_by("rand_key", "DESC");
}
} \ No newline at end of file
diff --git a/modules/gallery/helpers/item_rest.php b/modules/gallery/helpers/item_rest.php
index 36d2ca62..6869181d 100644
--- a/modules/gallery/helpers/item_rest.php
+++ b/modules/gallery/helpers/item_rest.php
@@ -126,18 +126,19 @@ class item_rest_Core {
}
}
}
+ $item->save();
- $weight = 0;
- if (isset($request->params->members)) {
+ if (isset($request->params->members) && $item->sort_column == "weight") {
+ $weight = 0;
foreach ($request->params->members as $url) {
$child = rest::resolve($url);
if ($child->parent_id == $item->id && $child->weight != $weight) {
- $child->weight = $weight++;
+ $child->weight = $weight;
$child->save();
}
+ $weight++;
}
}
- $item->save();
}
static function post($request) {
@@ -151,7 +152,7 @@ class item_rest_Core {
$item->type = "album";
$item->parent_id = $parent->id;
$item->name = $entity->name;
- $item->title = isset($entity->title) ? $entity->title : $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();
@@ -159,18 +160,23 @@ class item_rest_Core {
case "photo":
case "movie":
- $item->type = $entity->type;
- $item->parent_id = $parent->id;
- $item->set_data_file($request->file);
- $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;
+ if (empty($request->file)) {
+ throw new Rest_Exception(
+ "Bad Request", 400, array("errors" => array("file" => t("Upload failed"))));
+ }
+ $item->type = $entity->type;
+ $item->parent_id = $parent->id;
+ $item->set_data_file($request->file);
+ $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: $entity->type", 400);
+ throw new Rest_Exception(
+ "Bad Request", 400, array("errors" => array("type" => "invalid")));
}
return array("url" => rest::url("item", $item));
diff --git a/modules/gallery/helpers/items_rest.php b/modules/gallery/helpers/items_rest.php
index 5d8e80b2..9cca9a54 100644
--- a/modules/gallery/helpers/items_rest.php
+++ b/modules/gallery/helpers/items_rest.php
@@ -18,28 +18,74 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
class items_rest_Core {
+ /**
+ * To retrieve a collection of items, you can specify the following query parameters to specify
+ * the type of the collection. If both are specified, then the url parameter is used and the
+ * ancestors_for is ignored. Specifying the "type" parameter with the urls parameter, will
+ * filter the results based on the specified type. Using the type parameter with the
+ * ancestors_for parameter makes no sense and will be ignored.
+ *
+ * urls=url1,url2,url3
+ * return items that match the specified urls. Typically used to return the member detail
+ *
+ * ancestors_for=url
+ * return the ancestors of the specified item
+ *
+ * type=<comma separate list of photo, movie or album>
+ * limit the type to types in this list. eg, "type=photo,movie"
+ */
static function get($request) {
-
$items = array();
- if (isset($request->params->url)) {
- foreach (json_decode($request->params->url) as $url) {
+ if (isset($request->params->urls)) {
+ foreach (json_decode($request->params->urls) as $url) {
+ if (isset($request->params->type)) {
+ $types = explode(",", $request->params->type);
+ }
$item = rest::resolve($url);
if (access::can("view", $item)) {
- $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);
+ if (isset($types)) {
+ if (in_array($item->type, $types)) {
+ $items[] = items_rest::_format_restful_item($item);
}
- $item_rest["members"] = $members;
+ } else {
+ $items[] = items_rest::_format_restful_item($item);
}
- $items[] = $item_rest;
}
}
+ } else if (isset($request->params->ancestors_for)) {
+ $item = rest::resolve($request->params->ancestors_for);
+ if (!access::can("view", $item)) {
+ throw new Kohana_404_Exception();
+ }
+ $items[] = items_rest::_format_restful_item($item);
+ while (($item = $item->parent()) != null) {
+ array_unshift($items, items_rest::_format_restful_item($item));
+ };
}
return $items;
}
+
+ static function resolve($id) {
+ $item = ORM::factory("item", $id);
+ if (!access::can("view", $item)) {
+ throw new Kohana_404_Exception();
+ }
+ return $item;
+ }
+
+ private static function _format_restful_item($item) {
+ $item_rest = array("url" => rest::url("item", $item),
+ "entity" => $item->as_restful_array(),
+ "relationships" => rest::relationships("item", $item));
+ if ($item->type == "album") {
+ $members = array();
+ foreach ($item->children() as $child) {
+ $members[] = rest::url("item", $child);
+ }
+ $item_rest["members"] = $members;
+ }
+
+ return $item_rest;
+ }
}
diff --git a/modules/gallery/helpers/message.php b/modules/gallery/helpers/message.php
index 047eb2c7..1f69e2a9 100644
--- a/modules/gallery/helpers/message.php
+++ b/modules/gallery/helpers/message.php
@@ -78,6 +78,7 @@ class message_Core {
$messages = Session::instance()->get_once("messages", array());
foreach ($messages as $msg) {
+ $msg[0] = str_replace("__CSRF__", access::csrf_token(), $msg[0]);
$buf[] = "<li class=\"" . self::severity_class($msg[1]) . "\">$msg[0]</li>";
}
if ($buf) {
diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php
index 18d65ed5..5134c7b3 100644
--- a/modules/gallery/helpers/module.php
+++ b/modules/gallery/helpers/module.php
@@ -214,13 +214,6 @@ class module_Core {
throw new Exception("@todo UNKNOWN_MODULE");
}
}
-
- // Now the module is upgraded so deactivate it, but we can'it deactivae gallery or the
- // current identity provider.
- $identity_provider = module::get_var("gallery", "identity_provider", "user");
- if (!in_array($module_name, array("gallery", $identity_provider)) ) {
- self::deactivate($module_name);
- }
module::load_modules();
$version_after = module::get_version($module_name);
diff --git a/modules/gallery/helpers/photo.php b/modules/gallery/helpers/photo.php
index f20d37a3..73cd60c0 100644
--- a/modules/gallery/helpers/photo.php
+++ b/modules/gallery/helpers/photo.php
@@ -26,7 +26,7 @@
class photo_Core {
static function get_edit_form($photo) {
$form = new Forge("photos/update/$photo->id", "", "post", array("id" => "g-edit-photo-form"));
- $form->hidden("from_id");
+ $form->hidden("from_id")->value($photo->id);
$group = $form->group("edit_item")->label(t("Edit Photo"));
$group->input("title")->label(t("Title"))->value($photo->title)
->error_messages("required", t("You must provide a title"))
diff --git a/modules/gallery/helpers/site_status.php b/modules/gallery/helpers/site_status.php
index 759eb382..13c42dda 100644
--- a/modules/gallery/helpers/site_status.php
+++ b/modules/gallery/helpers/site_status.php
@@ -100,7 +100,7 @@ class site_status_Core {
}
$buf = array();
foreach (ORM::factory("message")->find_all() as $msg) {
- $value = str_replace('__CSRF__', access::csrf_token(), $msg->value);
+ $value = str_replace("__CSRF__", access::csrf_token(), $msg->value);
$buf[] = "<li class=\"" . self::severity_class($msg->severity) . "\">$value</li>";
}
diff --git a/modules/gallery/helpers/theme.php b/modules/gallery/helpers/theme.php
index 980ee11a..3589a5b7 100644
--- a/modules/gallery/helpers/theme.php
+++ b/modules/gallery/helpers/theme.php
@@ -53,13 +53,22 @@ class theme_Core {
if (file_exists(THEMEPATH . self::$site_theme_name . "/admin")) {
array_unshift($modules, THEMEPATH . self::$site_theme_name . "/admin");
}
+ // Admins can override the site theme, temporarily. This lets us preview themes.
+ if (identity::active_user()->admin && $override = $input->get("theme")) {
+ if (file_exists(THEMEPATH . $override)) {
+ self::$admin_theme_name = $override;
+ array_unshift($modules, THEMEPATH . self::$admin_theme_name);
+ } else {
+ Kohana_Log::add("error", "Missing override admin theme: '$override'");
+ }
+ }
} else {
// Admins can override the site theme, temporarily. This lets us preview themes.
if (identity::active_user()->admin && $override = $input->get("theme")) {
if (file_exists(THEMEPATH . $override)) {
self::$site_theme_name = $override;
} else {
- Kohana_Log::add("error", "Missing override theme: '$override'");
+ Kohana_Log::add("error", "Missing override site theme: '$override'");
}
}
array_unshift($modules, THEMEPATH . self::$site_theme_name);
@@ -70,7 +79,7 @@ class theme_Core {
static function get_edit_form_admin() {
$form = new Forge("admin/theme_options/save/", "", null, array("id" =>"g-theme-options-form"));
- $group = $form->group("edit_theme");
+ $group = $form->group("edit_theme")->label(t("Theme layout"));
$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"))
@@ -95,7 +104,8 @@ class theme_Core {
module::event("theme_edit_form", $form);
- $group = $form->group("buttons");
+ $group = $form->group("buttons")
+ ->set_attr("style","border: none");
$group->submit("")->value(t("Save"));
return $form;
}