From dbeadc1407293d0c7af36723db6fe5699890b845 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Wed, 22 Jul 2009 14:27:57 -0700 Subject: Use the Kohana cascading filesystem to locate resources loaded by the theme. Because the theme comes first, this means that themes can override any module resources, at the cost that we no longer have namespacing for JS and CSS files. The only file getting used outside of this model is themes/default/screen.css which is used in the admin theme. I fixed that by copying screen.css into admin_default and renaming its screen.css to admin_screen.css. I also copied over all the images that it was referencing. Fixes tickets #48 and #539. Theme API changes: - theme_script(), theme_url() and theme_css() are no longer needed - script(), url() and css() now refer to the first matching asset in the module load path, where gallery3/lib is at the end of the path --- modules/digibug/helpers/digibug_theme.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'modules/digibug/helpers') diff --git a/modules/digibug/helpers/digibug_theme.php b/modules/digibug/helpers/digibug_theme.php index f94d07c6..ceda55b5 100644 --- a/modules/digibug/helpers/digibug_theme.php +++ b/modules/digibug/helpers/digibug_theme.php @@ -19,6 +19,6 @@ */ class digibug_theme_Core { static function head($theme) { - $theme->script("modules/digibug/js/digibug.js"); + $theme->script("digibug.js"); } } -- cgit v1.2.3 From 7c2cea01a50227088d9da567b08b9fde54b4b95f Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Thu, 23 Jul 2009 07:02:10 -0700 Subject: Fix for ticket #502 This patch allows users with only view permission to request fullsize prints using Digibug. There is now a Digibug config file that contains the IP ranges of the Digibug servers. Any request for the full size image via the print proxy must come from within the ranges in the config file. The reason for the "if (!Test_Mode) {..." is that the print proxy makes a call to Kohana::close_buffers, which closes all the output buffers and then we see the image download on the console which messes up the test output. --- modules/digibug/config/digibug.php | 29 ++++++++ modules/digibug/controllers/digibug.php | 50 ++++++++++--- modules/digibug/helpers/digibug_menu.php | 2 +- modules/digibug/tests/Digibug_Controller_Test.php | 91 +++++++++++++++++++++++ 4 files changed, 159 insertions(+), 13 deletions(-) create mode 100644 modules/digibug/config/digibug.php create mode 100644 modules/digibug/tests/Digibug_Controller_Test.php (limited to 'modules/digibug/helpers') diff --git a/modules/digibug/config/digibug.php b/modules/digibug/config/digibug.php new file mode 100644 index 00000000..6cd165d1 --- /dev/null +++ b/modules/digibug/config/digibug.php @@ -0,0 +1,29 @@ + email address that appears as the from address + * line-length => word wrap length (PHP documentations suggest no larger tha 70 characters + * reply-to => what goes into the reply to header + */ +$config["ranges"] = array( + "Digibug1" => array("low" => "65.249.152.0", "high" => "65.249.159.255"), + "Digibug2" => array("low" => "208.122.55.0", "high" => "208.122.55.255") +); diff --git a/modules/digibug/controllers/digibug.php b/modules/digibug/controllers/digibug.php index d881db9b..e0f4b6bf 100644 --- a/modules/digibug/controllers/digibug.php +++ b/modules/digibug/controllers/digibug.php @@ -21,7 +21,7 @@ class Digibug_Controller extends Controller { public function print_photo($id) { access::verify_csrf(); $item = ORM::factory("item", $id); - access::required("view_full", $item); + access::required("view", $item); if (access::group_can(group::everybody(), "view_full", $item)) { $full_url = $item->file_url(true); @@ -56,6 +56,30 @@ class Digibug_Controller extends Controller { } public function print_proxy($type, $id) { + // If its a request for the full size then make sure we are coming from an + // authorized address + if ($type == "full") { + $remote_addr = ip2long($this->input->server("REMOTE_ADDR")); + if ($remote_addr === false) { + Kohana::show_404(); + } + $config = Kohana::config("digibug"); + + $authorized = false; + foreach ($config["ranges"] as $ip_range) { + $low = ip2long($ip_range["low"]); + $high = ip2long($ip_range["high"]); + $authorized = $low !== false && $high !== false && + $low <= $remote_addr && $remote_addr <= $high; + if ($authorized) { + break; + } + } + if (!$authorized) { + Kohana::show_404(); + } + } + $proxy = ORM::factory("digibug_proxy", array("uuid" => $id)); if (!$proxy->loaded || !$proxy->item->loaded) { Kohana::show_404(); @@ -69,16 +93,18 @@ class Digibug_Controller extends Controller { // We don't need to save the session for this request Session::abort_save(); - // Dump out the image - header("Content-Type: $proxy->item->mime_type"); - Kohana::close_buffers(false); - $fd = fopen($file, "rb"); - fpassthru($fd); - fclose($fd); + if (!TEST_MODE) { + // Dump out the image + header("Content-Type: $proxy->item->mime_type"); + Kohana::close_buffers(false); + $fd = fopen($file, "rb"); + fpassthru($fd); + fclose($fd); - // If the request was for the image and not the thumb, then delete the proxy. - if ($type == "full") { - $proxy->delete(); + // If the request was for the image and not the thumb, then delete the proxy. + if ($type == "full") { + $proxy->delete(); + } } $this->_clean_expired(); @@ -89,8 +115,8 @@ class Digibug_Controller extends Controller { } private function _clean_expired() { - Database::instance()>query( - "DELETE FROM {digibug_proxy} " . + Database::instance()->query( + "DELETE FROM {digibug_proxies} " . "WHERE request_date <= (CURDATE() - INTERVAL 10 DAY) " . "LIMIT 20"); } diff --git a/modules/digibug/helpers/digibug_menu.php b/modules/digibug/helpers/digibug_menu.php index c95cada2..3f70fa24 100644 --- a/modules/digibug/helpers/digibug_menu.php +++ b/modules/digibug/helpers/digibug_menu.php @@ -37,7 +37,7 @@ class digibug_menu { } static function thumb($menu, $theme, $item) { - if ($item->type == "photo" && access::can("view_full", $item)) { + if ($item->type == "photo") { $menu->get("options_menu") ->append( Menu::factory("link") diff --git a/modules/digibug/tests/Digibug_Controller_Test.php b/modules/digibug/tests/Digibug_Controller_Test.php new file mode 100644 index 00000000..6838da5c --- /dev/null +++ b/modules/digibug/tests/Digibug_Controller_Test.php @@ -0,0 +1,91 @@ +_server; + + if ($this->_proxy) { + $this->_proxy->delete(); + } + } + + public function setup() { + $this->_server = $_SERVER; + + $root = ORM::factory("item", 1); + $this->_album = album::create($root, rand(), "test album"); + access::deny(group::everybody(), "view_full", $this->_album); + access::deny(group::registered_users(), "view_full", $this->_album); + + $rand = rand(); + $this->_item = photo::create($this->_album, MODPATH . "gallery/tests/test.jpg", "$rand.jpg", + $rand, $rand); + $this->_proxy = ORM::factory("digibug_proxy"); + $this->_proxy->uuid = md5(rand()); + $this->_proxy->item_id = $this->_item->id; + $this->_proxy->save(); + } + + public function digibug_request_thumb_test() { + try { + $controller = new Digibug_Controller(); + $controller->print_proxy("thumb", $this->_proxy->uuid); + } catch (Exception $e) { + $this->assert_true(false, "Exception Occurred\n" . $e->__toString()); + } + } + + public function digibug_request_full_malicious_ip_test() { + $_SERVER["REMOTE_ADDR"] = "123.456.789.012"; + try { + $controller = new Digibug_Controller(); + $controller->print_proxy("full", $this->_proxy->uuid); + $this->assert_true(false, "Should have failed with an 404 exception"); + } catch (Exception $e) { + if (get_class($e) !== "Kohana_404_Exception") { + $this->assert_true(false, "Exception Occurred\n" . $e->__toString()); + } + } + } + + public function digibug_request_full_authorized_ip_test() { + $config = Kohana::config("digibug"); + if (empty($config)) { + $this->assert_true(false, "The Digibug config is empty"); + } + $ranges = array_values($config["ranges"]); + $low = ip2long($ranges[0]["low"]); + $high = ip2long($ranges[0]["high"]); + + $_SERVER["REMOTE_ADDR"] = long2ip(rand($low, $high)); + try { + $controller = new Digibug_Controller(); + $controller->print_proxy("full", $this->_proxy->uuid); + $results = ob_get_contents(); + } catch (Exception $e) { + $this->assert_true(false, "Exception Occurred\n" . $e->__toString()); + } + } + +} -- cgit v1.2.3 From 1e90e40d3a9fe2cb826b56686f23a33879418048 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Tue, 28 Jul 2009 13:47:22 -0700 Subject: Use events to generate menus, instead of having xxx_menu helpers. This is the first step towards having a simple, lightweight and unified API for module interaction. --- modules/akismet/helpers/akismet_event.php | 16 ++ modules/akismet/helpers/akismet_menu.php | 36 ----- modules/comment/helpers/comment_event.php | 17 +++ modules/comment/helpers/comment_menu.php | 37 ----- modules/digibug/helpers/digibug_event.php | 50 +++++++ modules/digibug/helpers/digibug_menu.php | 50 ------- modules/g2_import/helpers/g2_import_event.php | 9 ++ modules/g2_import/helpers/g2_import_menu.php | 29 ---- modules/gallery/helpers/gallery_menu.php | 164 --------------------- modules/gallery/libraries/Admin_View.php | 70 +++++++-- modules/gallery/libraries/Theme_View.php | 105 +++++++++---- .../notification/helpers/notification_event.php | 19 +++ modules/notification/helpers/notification_menu.php | 39 ----- modules/organize/helpers/organize_event.php | 33 +++++ modules/organize/helpers/organize_menu.php | 33 ----- modules/recaptcha/helpers/recaptcha_event.php | 8 + modules/recaptcha/helpers/recaptcha_menu.php | 28 ---- modules/server_add/helpers/server_add_event.php | 64 ++++++++ modules/server_add/helpers/server_add_menu.php | 64 -------- modules/slideshow/helpers/slideshow_event.php | 30 ++++ modules/slideshow/helpers/slideshow_menu.php | 51 ------- modules/tag/helpers/tag_event.php | 8 + modules/tag/helpers/tag_menu.php | 28 ---- modules/user/helpers/user_event.php | 8 + modules/user/helpers/user_menu.php | 28 ---- modules/watermark/helpers/watermark_event.php | 29 ++++ modules/watermark/helpers/watermark_menu.php | 29 ---- 27 files changed, 426 insertions(+), 656 deletions(-) delete mode 100644 modules/akismet/helpers/akismet_menu.php delete mode 100644 modules/comment/helpers/comment_menu.php create mode 100644 modules/digibug/helpers/digibug_event.php delete mode 100644 modules/digibug/helpers/digibug_menu.php delete mode 100644 modules/g2_import/helpers/g2_import_menu.php delete mode 100644 modules/gallery/helpers/gallery_menu.php delete mode 100644 modules/notification/helpers/notification_menu.php create mode 100644 modules/organize/helpers/organize_event.php delete mode 100644 modules/organize/helpers/organize_menu.php delete mode 100644 modules/recaptcha/helpers/recaptcha_menu.php create mode 100644 modules/server_add/helpers/server_add_event.php delete mode 100644 modules/server_add/helpers/server_add_menu.php delete mode 100644 modules/slideshow/helpers/slideshow_menu.php delete mode 100644 modules/tag/helpers/tag_menu.php delete mode 100644 modules/user/helpers/user_menu.php create mode 100644 modules/watermark/helpers/watermark_event.php delete mode 100644 modules/watermark/helpers/watermark_menu.php (limited to 'modules/digibug/helpers') diff --git a/modules/akismet/helpers/akismet_event.php b/modules/akismet/helpers/akismet_event.php index bffc0fd7..d6cde222 100644 --- a/modules/akismet/helpers/akismet_event.php +++ b/modules/akismet/helpers/akismet_event.php @@ -51,4 +51,20 @@ class akismet_event_Core { akismet::submit_ham($new); } } + + static function admin_menu($menu, $theme) { + $menu->get("settings_menu") + ->append(Menu::factory("link") + ->id("akismet") + ->label(t("Akismet")) + ->url(url::site("admin/akismet"))); + + if (module::get_var("akismet", "api_key")) { + $menu->get("statistics_menu") + ->append(Menu::factory("link") + ->id("akismet") + ->label(t("Akismet")) + ->url(url::site("admin/akismet/stats"))); + } + } } diff --git a/modules/akismet/helpers/akismet_menu.php b/modules/akismet/helpers/akismet_menu.php deleted file mode 100644 index ebd948d6..00000000 --- a/modules/akismet/helpers/akismet_menu.php +++ /dev/null @@ -1,36 +0,0 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("akismet") - ->label(t("Akismet")) - ->url(url::site("admin/akismet"))); - - if (module::get_var("akismet", "api_key")) { - $menu->get("statistics_menu") - ->append(Menu::factory("link") - ->id("akismet") - ->label(t("Akismet")) - ->url(url::site("admin/akismet/stats"))); - } - } -} diff --git a/modules/comment/helpers/comment_event.php b/modules/comment/helpers/comment_event.php index 3850a001..614c7c65 100644 --- a/modules/comment/helpers/comment_event.php +++ b/modules/comment/helpers/comment_event.php @@ -21,4 +21,21 @@ class comment_event_Core { static function item_deleted($item) { Database::instance()->delete("comments", array("item_id" => $item->id)); } + + static function admin_menu($menu, $theme) { + $menu->get("content_menu") + ->append(Menu::factory("link") + ->id("comments") + ->label(t("Comments")) + ->url(url::site("admin/comments"))); + } + + static function photo_menu($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("comments") + ->label(t("View comments on this item")) + ->url("#comments") + ->css_id("gCommentsLink")); + } } diff --git a/modules/comment/helpers/comment_menu.php b/modules/comment/helpers/comment_menu.php deleted file mode 100644 index 01881921..00000000 --- a/modules/comment/helpers/comment_menu.php +++ /dev/null @@ -1,37 +0,0 @@ -get("content_menu") - ->append(Menu::factory("link") - ->id("comments") - ->label(t("Comments")) - ->url(url::site("admin/comments"))); - } - - static function photo($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("comments") - ->label(t("View comments on this item")) - ->url("#comments") - ->css_id("gCommentsLink")); - } -} diff --git a/modules/digibug/helpers/digibug_event.php b/modules/digibug/helpers/digibug_event.php new file mode 100644 index 00000000..c4f9e560 --- /dev/null +++ b/modules/digibug/helpers/digibug_event.php @@ -0,0 +1,50 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("digibug_menu") + ->label(t("Digibug")) + ->url(url::site("admin/digibug"))); + } + + static function photo_menu($menu, $theme) { + $item = $theme->item(); + $menu->append( + Menu::factory("link") + ->id("digibug") + ->label(t("Print with Digibug")) + ->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf")) + ->css_id("gDigibugLink")); + } + + static function thumb_menu($menu, $theme, $item) { + if ($item->type == "photo") { + $menu->get("options_menu") + ->append( + Menu::factory("link") + ->id("digibug") + ->label(t("Print with Digibug")) + ->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf")) + ->css_id("gDigibugLink")); + } + } +} diff --git a/modules/digibug/helpers/digibug_menu.php b/modules/digibug/helpers/digibug_menu.php deleted file mode 100644 index 3f70fa24..00000000 --- a/modules/digibug/helpers/digibug_menu.php +++ /dev/null @@ -1,50 +0,0 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("digibug_menu") - ->label(t("Digibug")) - ->url(url::site("admin/digibug"))); - } - - static function photo($menu, $theme) { - $item = $theme->item(); - $menu->append( - Menu::factory("link") - ->id("digibug") - ->label(t("Print with Digibug")) - ->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf")) - ->css_id("gDigibugLink")); - } - - static function thumb($menu, $theme, $item) { - if ($item->type == "photo") { - $menu->get("options_menu") - ->append( - Menu::factory("link") - ->id("digibug") - ->label(t("Print with Digibug")) - ->url(url::site("digibug/print_photo/$item->id?csrf=$theme->csrf")) - ->css_id("gDigibugLink")); - } - } -} diff --git a/modules/g2_import/helpers/g2_import_event.php b/modules/g2_import/helpers/g2_import_event.php index 77b489a7..609e1a45 100644 --- a/modules/g2_import/helpers/g2_import_event.php +++ b/modules/g2_import/helpers/g2_import_event.php @@ -25,4 +25,13 @@ class g2_import_event_Core { static function item_created($item) { g2_import::copy_matching_thumbnails_and_resizes($item); } + + static function admin_menu($menu, $theme) { + $menu + ->get("settings_menu") + ->append(Menu::factory("link") + ->id("g2_import") + ->label(t("Gallery 2 Import")) + ->url(url::site("admin/g2_import"))); + } } diff --git a/modules/g2_import/helpers/g2_import_menu.php b/modules/g2_import/helpers/g2_import_menu.php deleted file mode 100644 index 68d75cb4..00000000 --- a/modules/g2_import/helpers/g2_import_menu.php +++ /dev/null @@ -1,29 +0,0 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("g2_import") - ->label(t("Gallery 2 Import")) - ->url(url::site("admin/g2_import"))); - } -} diff --git a/modules/gallery/helpers/gallery_menu.php b/modules/gallery/helpers/gallery_menu.php deleted file mode 100644 index 040b19e1..00000000 --- a/modules/gallery/helpers/gallery_menu.php +++ /dev/null @@ -1,164 +0,0 @@ -append(Menu::factory("link") - ->id("home") - ->label(t("Home")) - ->url(url::site("albums/1"))); - - $item = $theme->item(); - - $can_edit = $item && access::can("edit", $item); - $can_add = $item && access::can("add", $item); - - if ($can_add) { - $menu->append(Menu::factory("dialog") - ->id("add_photos_item") - ->label(t("Add photos")) - ->url(url::site("simple_uploader/app/$item->id"))); - } - - $menu->append($options_menu = Menu::factory("submenu") - ->id("options_menu") - ->label(t("Options"))); - if ($item && ($can_edit || $can_add)) { - if ($can_edit) { - $options_menu - ->append(Menu::factory("dialog") - ->id("edit_item") - ->label($item->is_album() ? t("Edit album") : t("Edit photo")) - ->url(url::site("form/edit/{$item->type}s/$item->id"))); - } - - // @todo Move album options menu to the album quick edit pane - if ($item->is_album()) { - if ($can_add) { - $options_menu - ->append(Menu::factory("dialog") - ->id("add_album") - ->label(t("Add an album")) - ->url(url::site("form/add/albums/$item->id?type=album"))); - } - - if ($can_edit) { - $options_menu - ->append(Menu::factory("dialog") - ->id("edit_permissions") - ->label(t("Edit permissions")) - ->url(url::site("permissions/browse/$item->id"))); - } - } - } - - if (user::active()->admin) { - $menu->append($admin_menu = Menu::factory("submenu") - ->id("admin_menu") - ->label(t("Admin"))); - self::admin($admin_menu, $theme); - foreach (module::active() as $module) { - if ($module->name == "gallery") { - continue; - } - $class = "{$module->name}_menu"; - if (method_exists($class, "admin")) { - call_user_func_array(array($class, "admin"), array(&$admin_menu, $theme)); - } - } - } - } - - static function album($menu, $theme) { - } - - static function tag($menu, $theme) { - } - - static function thumb($menu, $theme, $item) { - $menu->append(Menu::factory("submenu") - ->id("options_menu") - ->label(t("Options")) - ->css_class("gThumbMenu")); - } - - static function photo($menu, $theme) { - if (access::can("view_full", $theme->item())) { - $menu->append(Menu::factory("link") - ->id("fullsize") - ->label(t("View full size")) - ->url($theme->item()->file_url()) - ->css_class("gFullSizeLink")); - } - } - - static function admin($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("dashboard") - ->label(t("Dashboard")) - ->url(url::site("admin"))) - ->append(Menu::factory("submenu") - ->id("settings_menu") - ->label(t("Settings")) - ->append(Menu::factory("link") - ->id("graphics_toolkits") - ->label(t("Graphics")) - ->url(url::site("admin/graphics"))) - ->append(Menu::factory("link") - ->id("languages") - ->label(t("Languages")) - ->url(url::site("admin/languages"))) - ->append(Menu::factory("link") - ->id("l10n_mode") - ->label(Session::instance()->get("l10n_mode", false) - ? t("Stop translating") : t("Start translating")) - ->url(url::site("l10n_client/toggle_l10n_mode?csrf=" . - access::csrf_token()))) - ->append(Menu::factory("link") - ->id("advanced") - ->label(t("Advanced")) - ->url(url::site("admin/advanced_settings")))) - ->append(Menu::factory("link") - ->id("modules") - ->label(t("Modules")) - ->url(url::site("admin/modules"))) - ->append(Menu::factory("submenu") - ->id("content_menu") - ->label(t("Content"))) - ->append(Menu::factory("submenu") - ->id("appearance_menu") - ->label(t("Appearance")) - ->append(Menu::factory("link") - ->id("themes") - ->label(t("Theme Choice")) - ->url(url::site("admin/themes"))) - ->append(Menu::factory("link") - ->id("theme_options") - ->label(t("Theme Options")) - ->url(url::site("admin/theme_options")))) - ->append(Menu::factory("submenu") - ->id("statistics_menu") - ->label(t("Statistics"))) - ->append(Menu::factory("link") - ->id("maintenance") - ->label(t("Maintenance")) - ->url(url::site("admin/maintenance"))); - } -} diff --git a/modules/gallery/libraries/Admin_View.php b/modules/gallery/libraries/Admin_View.php index 47770a90..2a48d1e3 100644 --- a/modules/gallery/libraries/Admin_View.php +++ b/modules/gallery/libraries/Admin_View.php @@ -44,22 +44,66 @@ class Admin_View_Core extends Gallery_View { $this->set_global("user", user::active()); } - public function admin_menu() { - $menu = Menu::factory("root"); - gallery_menu::admin($menu, $this); - - foreach (module::active() as $module) { - if ($module->name == "gallery") { - continue; - } - $class = "{$module->name}_menu"; - if (method_exists($class, "admin")) { - call_user_func_array(array($class, "admin"), array(&$menu, $this)); - } + public function admin_menu($menu=null) { + if (!$menu) { + $menu = Menu::factory("root"); } + $menu + ->append(Menu::factory("link") + ->id("dashboard") + ->label(t("Dashboard")) + ->url(url::site("admin"))) + ->append(Menu::factory("submenu") + ->id("settings_menu") + ->label(t("Settings")) + ->append(Menu::factory("link") + ->id("graphics_toolkits") + ->label(t("Graphics")) + ->url(url::site("admin/graphics"))) + ->append(Menu::factory("link") + ->id("languages") + ->label(t("Languages")) + ->url(url::site("admin/languages"))) + ->append(Menu::factory("link") + ->id("l10n_mode") + ->label(Session::instance()->get("l10n_mode", false) + ? t("Stop translating") : t("Start translating")) + ->url(url::site("l10n_client/toggle_l10n_mode?csrf=" . + access::csrf_token()))) + ->append(Menu::factory("link") + ->id("advanced") + ->label(t("Advanced")) + ->url(url::site("admin/advanced_settings")))) + ->append(Menu::factory("link") + ->id("modules") + ->label(t("Modules")) + ->url(url::site("admin/modules"))) + ->append(Menu::factory("submenu") + ->id("content_menu") + ->label(t("Content"))) + ->append(Menu::factory("submenu") + ->id("appearance_menu") + ->label(t("Appearance")) + ->append(Menu::factory("link") + ->id("themes") + ->label(t("Theme Choice")) + ->url(url::site("admin/themes"))) + ->append(Menu::factory("link") + ->id("theme_options") + ->label(t("Theme Options")) + ->url(url::site("admin/theme_options")))) + ->append(Menu::factory("submenu") + ->id("statistics_menu") + ->label(t("Statistics"))) + ->append(Menu::factory("link") + ->id("maintenance") + ->label(t("Maintenance")) + ->url(url::site("admin/maintenance"))); + + module::event("admin_menu", $menu, $this); $menu->compact(); - print $menu; + return $menu; } /** diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index fa45ec89..60471f75 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -81,52 +81,103 @@ class Theme_View_Core extends Gallery_View { public function site_menu() { $menu = Menu::factory("root"); if ($this->page_type != "login") { - gallery_menu::site($menu, $this); + $menu->append(Menu::factory("link") + ->id("home") + ->label(t("Home")) + ->url(url::site("albums/1"))); - foreach (module::active() as $module) { - if ($module->name == "gallery") { - continue; + $item = $this->item(); + + $can_edit = $item && access::can("edit", $item); + $can_add = $item && access::can("add", $item); + + if ($can_add) { + $menu->append(Menu::factory("dialog") + ->id("add_photos_item") + ->label(t("Add photos")) + ->url(url::site("simple_uploader/app/$item->id"))); + } + + $menu->append($options_menu = Menu::factory("submenu") + ->id("options_menu") + ->label(t("Options"))); + if ($item && ($can_edit || $can_add)) { + if ($can_edit) { + $options_menu + ->append(Menu::factory("dialog") + ->id("edit_item") + ->label($item->is_album() ? t("Edit album") : t("Edit photo")) + ->url(url::site("form/edit/{$item->type}s/$item->id"))); } - $class = "{$module->name}_menu"; - if (method_exists($class, "site")) { - call_user_func_array(array($class, "site"), array(&$menu, $this)); + + // @todo Move album options menu to the album quick edit pane + if ($item->is_album()) { + if ($can_add) { + $options_menu + ->append(Menu::factory("dialog") + ->id("add_album") + ->label(t("Add an album")) + ->url(url::site("form/add/albums/$item->id?type=album"))); + } + + if ($can_edit) { + $options_menu + ->append(Menu::factory("dialog") + ->id("edit_permissions") + ->label(t("Edit permissions")) + ->url(url::site("permissions/browse/$item->id"))); + } } } + + if (user::active()->admin) { + $menu->append($admin_menu = Menu::factory("submenu") + ->id("admin_menu") + ->label(t("Admin"))); + Admin_View::admin_menu($admin_menu, $this); + module::event("admin_menu", $admin_menu, $this); + } + + module::event("site_menu", $menu, $this); } - $menu->compact(); - print $menu; + return $menu->compact(); } public function album_menu() { - print $this->_menu("album"); + $menu = Menu::factory("root"); + module::event("album_menu", $menu, $this); + return $menu->compact(); } public function tag_menu() { - print $this->_menu("tag"); + $menu = Menu::factory("root"); + module::event("tag_menu", $menu, $this); + return $menu->compact(); } public function photo_menu() { - print $this->_menu("photo"); - } + $menu = Menu::factory("root"); + if (access::can("view_full", $this->item())) { + $menu->append(Menu::factory("link") + ->id("fullsize") + ->label(t("View full size")) + ->url($this->item()->file_url()) + ->css_class("gFullSizeLink")); + } - public function thumb_menu($item) { - print $this->_menu("thumb", $item)->css_class("gThumbMenu"); + module::event("photo_menu", $menu, $this); + return $menu->compact(); } - private function _menu($type, $item=null) { - $menu = Menu::factory("root"); - call_user_func_array(array("gallery_menu", $type), array(&$menu, $this, $item)); - foreach (module::active() as $module) { - if ($module->name == "gallery") { - continue; - } - $class = "{$module->name}_menu"; - if (method_exists($class, $type)) { - call_user_func_array(array($class, $type), array(&$menu, $this, $item)); - } - } + public function thumb_menu($item) { + $menu = Menu::factory("root") + ->append(Menu::factory("submenu") + ->id("options_menu") + ->label(t("Options")) + ->css_class("gThumbMenu")); + module::event("thumb_menu", $menu, $this, $item); return $menu->compact(); } diff --git a/modules/notification/helpers/notification_event.php b/modules/notification/helpers/notification_event.php index 536557c6..c6e770a7 100644 --- a/modules/notification/helpers/notification_event.php +++ b/modules/notification/helpers/notification_event.php @@ -55,4 +55,23 @@ class notification_event_Core { static function batch_complete() { notification::send_pending_notifications(); } + + static function site_menu($menu, $theme) { + if (!user::active()->guest) { + $item = $theme->item(); + + if ($item && $item->is_album() && access::can("view", $item)) { + $watching = notification::is_watching($item); + + $label = $watching ? t("Remove notifications") : t("Enable notifications"); + + $menu->get("options_menu") + ->append(Menu::factory("link") + ->id("watch") + ->label($label) + ->css_id("gNotifyLink") + ->url(url::site("notification/watch/$item->id?csrf=" . access::csrf_token()))); + } + } + } } \ No newline at end of file diff --git a/modules/notification/helpers/notification_menu.php b/modules/notification/helpers/notification_menu.php deleted file mode 100644 index 73d1dd03..00000000 --- a/modules/notification/helpers/notification_menu.php +++ /dev/null @@ -1,39 +0,0 @@ -guest) { - $item = $theme->item(); - - if ($item && $item->is_album() && access::can("view", $item)) { - $watching = notification::is_watching($item); - - $label = $watching ? t("Remove notifications") : t("Enable notifications"); - - $menu->get("options_menu") - ->append(Menu::factory("link") - ->id("watch") - ->label($label) - ->css_id("gNotifyLink") - ->url(url::site("notification/watch/$item->id?csrf=" . access::csrf_token()))); - } - } - } -} diff --git a/modules/organize/helpers/organize_event.php b/modules/organize/helpers/organize_event.php new file mode 100644 index 00000000..99a28673 --- /dev/null +++ b/modules/organize/helpers/organize_event.php @@ -0,0 +1,33 @@ +item(); + + if ($item && access::can("edit", $item) && $item->is_album()) { + $menu->get("options_menu") + ->append(Menu::factory("link") + ->id("organize") + ->label(t("Organize Album")) + ->css_id("gOrganizeLink") + ->url(url::site("organize/index/{$item->id}"))); + } + } +} diff --git a/modules/organize/helpers/organize_menu.php b/modules/organize/helpers/organize_menu.php deleted file mode 100644 index 850c1eab..00000000 --- a/modules/organize/helpers/organize_menu.php +++ /dev/null @@ -1,33 +0,0 @@ -item(); - - if ($item && access::can("edit", $item) && $item->is_album()) { - $menu->get("options_menu") - ->append(Menu::factory("link") - ->id("organize") - ->label(t("Organize Album")) - ->css_id("gOrganizeLink") - ->url(url::site("organize/index/{$item->id}"))); - } - } -} diff --git a/modules/recaptcha/helpers/recaptcha_event.php b/modules/recaptcha/helpers/recaptcha_event.php index 932ddee6..d23a0c74 100644 --- a/modules/recaptcha/helpers/recaptcha_event.php +++ b/modules/recaptcha/helpers/recaptcha_event.php @@ -23,4 +23,12 @@ class recaptcha_event_Core { $form->add_comment->recaptcha("recaptcha")->label("")->id("gRecaptcha"); } } + + static function admin_menu($menu, $theme) { + $menu->get("settings_menu") + ->append(Menu::factory("link") + ->id("recaptcha") + ->label(t("reCAPTCHA")) + ->url(url::site("admin/recaptcha"))); + } } diff --git a/modules/recaptcha/helpers/recaptcha_menu.php b/modules/recaptcha/helpers/recaptcha_menu.php deleted file mode 100644 index 047abf8f..00000000 --- a/modules/recaptcha/helpers/recaptcha_menu.php +++ /dev/null @@ -1,28 +0,0 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("recaptcha") - ->label(t("reCAPTCHA")) - ->url(url::site("admin/recaptcha"))); - } -} diff --git a/modules/server_add/helpers/server_add_event.php b/modules/server_add/helpers/server_add_event.php new file mode 100644 index 00000000..b53e72d1 --- /dev/null +++ b/modules/server_add/helpers/server_add_event.php @@ -0,0 +1,64 @@ +get("settings_menu") + ->append(Menu::factory("link") + ->id("server_add") + ->label(t("Server Add")) + ->url(url::site("admin/server_add"))); + } + + static function site_menu($menu, $theme) { + $item = $theme->item(); + $paths = unserialize(module::get_var("server_add", "authorized_paths")); + + if ($item && user::active()->admin && $item->is_album() && !empty($paths)) { + // This is a little tricky. Normally there's an "Add Photo" menu option, but we want to + // turn that into a dropdown if there are two different ways to add things. Do that in a + // portable way for now. If we find ourselves duplicating this pattern, we should make an + // API method for this. + $server_add = Menu::factory("dialog") + ->id("server_add") + ->label(t("Add from server")) + ->url(url::site("server_add/browse/$item->id")); + $add_photos_item = $menu->get("add_photos_item"); + $add_photos_menu = $menu->get("add_photos_menu"); + + if ($add_photos_item && !$add_photos_menu) { + // Assuming that $add_menu is unset, create add_menu and add our item + $menu->add_after( + "add_photos_item", + Menu::factory("submenu") + ->id("add_photos_menu") + ->label($add_photos_item->label) + ->append(Menu::factory("dialog") + ->id("add_photos_submenu_item") + ->label(t("Simple Uploader")) + ->url($add_photos_item->url)) + ->append($server_add)); + $menu->remove("add_photos_item"); + } else if ($add_photos_menu) { + // Append to the existing sub-menu + $add_photos_menu->append($server_add); + } + } + } +} diff --git a/modules/server_add/helpers/server_add_menu.php b/modules/server_add/helpers/server_add_menu.php deleted file mode 100644 index 0f01eb64..00000000 --- a/modules/server_add/helpers/server_add_menu.php +++ /dev/null @@ -1,64 +0,0 @@ -get("settings_menu") - ->append(Menu::factory("link") - ->id("server_add") - ->label(t("Server Add")) - ->url(url::site("admin/server_add"))); - } - - static function site($menu, $theme) { - $item = $theme->item(); - $paths = unserialize(module::get_var("server_add", "authorized_paths")); - - if ($item && user::active()->admin && $item->is_album() && !empty($paths)) { - // This is a little tricky. Normally there's an "Add Photo" menu option, but we want to - // turn that into a dropdown if there are two different ways to add things. Do that in a - // portable way for now. If we find ourselves duplicating this pattern, we should make an - // API method for this. - $server_add = Menu::factory("dialog") - ->id("server_add") - ->label(t("Add from server")) - ->url(url::site("server_add/browse/$item->id")); - $add_photos_item = $menu->get("add_photos_item"); - $add_photos_menu = $menu->get("add_photos_menu"); - - if ($add_photos_item && !$add_photos_menu) { - // Assuming that $add_menu is unset, create add_menu and add our item - $menu->add_after( - "add_photos_item", - Menu::factory("submenu") - ->id("add_photos_menu") - ->label($add_photos_item->label) - ->append(Menu::factory("dialog") - ->id("add_photos_submenu_item") - ->label(t("Simple Uploader")) - ->url($add_photos_item->url)) - ->append($server_add)); - $menu->remove("add_photos_item"); - } else if ($add_photos_menu) { - // Append to the existing sub-menu - $add_photos_menu->append($server_add); - } - } - } -} diff --git a/modules/slideshow/helpers/slideshow_event.php b/modules/slideshow/helpers/slideshow_event.php index c6cd7dc7..cf79f71a 100644 --- a/modules/slideshow/helpers/slideshow_event.php +++ b/modules/slideshow/helpers/slideshow_event.php @@ -29,4 +29,34 @@ class slideshow_event_Core { site_status::clear("slideshow_needs_rss"); } } + + static function album_menu($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("slideshow") + ->label(t("View slideshow")) + ->url("javascript:PicLensLite.start(" . + "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") + ->css_id("gSlideshowLink")); + } + + static function photo_menu($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("slideshow") + ->label(t("View slideshow")) + ->url("javascript:PicLensLite.start(" . + "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") + ->css_id("gSlideshowLink")); + } + + static function tag_menu($menu, $theme) { + $menu + ->append(Menu::factory("link") + ->id("slideshow") + ->label(t("View slideshow")) + ->url("javascript:PicLensLite.start(" . + "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") + ->css_id("gSlideshowLink")); + } } diff --git a/modules/slideshow/helpers/slideshow_menu.php b/modules/slideshow/helpers/slideshow_menu.php deleted file mode 100644 index ee975d88..00000000 --- a/modules/slideshow/helpers/slideshow_menu.php +++ /dev/null @@ -1,51 +0,0 @@ -append(Menu::factory("link") - ->id("slideshow") - ->label(t("View slideshow")) - ->url("javascript:PicLensLite.start(" . - "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") - ->css_id("gSlideshowLink")); - } - - static function photo($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("slideshow") - ->label(t("View slideshow")) - ->url("javascript:PicLensLite.start(" . - "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") - ->css_id("gSlideshowLink")); - } - - static function tag($menu, $theme) { - $menu - ->append(Menu::factory("link") - ->id("slideshow") - ->label(t("View slideshow")) - ->url("javascript:PicLensLite.start(" . - "{maxScale:0,feedUrl:PicLensLite.indexFeeds()[0].url})") - ->css_id("gSlideshowLink")); - } - -} diff --git a/modules/tag/helpers/tag_event.php b/modules/tag/helpers/tag_event.php index 0fe8a393..f5fa6d4c 100644 --- a/modules/tag/helpers/tag_event.php +++ b/modules/tag/helpers/tag_event.php @@ -85,4 +85,12 @@ class tag_event_Core { } tag::compact(); } + + static function admin_menu($menu, $theme) { + $menu->get("content_menu") + ->append(Menu::factory("link") + ->id("tags") + ->label(t("Tags")) + ->url(url::site("admin/tags"))); + } } diff --git a/modules/tag/helpers/tag_menu.php b/modules/tag/helpers/tag_menu.php deleted file mode 100644 index e1b61a93..00000000 --- a/modules/tag/helpers/tag_menu.php +++ /dev/null @@ -1,28 +0,0 @@ -get("content_menu") - ->append(Menu::factory("link") - ->id("tags") - ->label(t("Tags")) - ->url(url::site("admin/tags"))); - } -} diff --git a/modules/user/helpers/user_event.php b/modules/user/helpers/user_event.php index 6515fbfb..4bde224b 100644 --- a/modules/user/helpers/user_event.php +++ b/modules/user/helpers/user_event.php @@ -30,4 +30,12 @@ class user_event_Core { I18n::instance()->locale($locale); } } + + static function admin_menu($menu, $theme) { + $menu->add_after("appearance_menu", + Menu::factory("link") + ->id("users_groups") + ->label(t("Users/Groups")) + ->url(url::site("admin/users"))); + } } diff --git a/modules/user/helpers/user_menu.php b/modules/user/helpers/user_menu.php deleted file mode 100644 index 05e401f9..00000000 --- a/modules/user/helpers/user_menu.php +++ /dev/null @@ -1,28 +0,0 @@ -add_after("appearance_menu", - Menu::factory("link") - ->id("users_groups") - ->label(t("Users/Groups")) - ->url(url::site("admin/users"))); - } -} diff --git a/modules/watermark/helpers/watermark_event.php b/modules/watermark/helpers/watermark_event.php new file mode 100644 index 00000000..45b410f9 --- /dev/null +++ b/modules/watermark/helpers/watermark_event.php @@ -0,0 +1,29 @@ +get("content_menu") + ->append( + Menu::factory("link") + ->id("watermarks") + ->label(t("Watermarks")) + ->url(url::site("admin/watermarks"))); + } +} diff --git a/modules/watermark/helpers/watermark_menu.php b/modules/watermark/helpers/watermark_menu.php deleted file mode 100644 index bc3a4fed..00000000 --- a/modules/watermark/helpers/watermark_menu.php +++ /dev/null @@ -1,29 +0,0 @@ -get("content_menu") - ->append( - Menu::factory("link") - ->id("watermarks") - ->label(t("Watermarks")) - ->url(url::site("admin/watermarks"))); - } -} -- cgit v1.2.3 From 52147cf6f857c4c54a2f3d753e72b27b5141d028 Mon Sep 17 00:00:00 2001 From: Bharat Mediratta Date: Mon, 3 Aug 2009 21:45:54 -0700 Subject: Combine the quick menu and the thumb menu into a single menu called the "context" menu. This new context menu is generated using the typical event processing system, like our other menus. The specialized quick CSS and JS is now gone, replaced by our generic menu handling code. It's all rolled together currently using the thumb_menu UI for easy packaging. All the CSS and JS is updated. NOTE: the non-dialog links (rotate, album_cover) have a broken UI because they return JSON which the quick.js code handled specially, but we don't handle properly now. I need to fix this. --- modules/digibug/helpers/digibug_event.php | 4 +- modules/gallery/controllers/quick.php | 14 --- modules/gallery/css/quick.css | 52 ---------- modules/gallery/helpers/gallery.php | 102 ++++++++++++++++++++ modules/gallery/helpers/gallery_quick.php | 152 ------------------------------ modules/gallery/helpers/gallery_theme.php | 31 ------ modules/gallery/helpers/module.php | 8 +- modules/gallery/js/quick.js | 78 --------------- modules/gallery/libraries/Menu.php | 4 +- modules/gallery/libraries/Theme_View.php | 10 +- modules/gallery/views/quick_pane.html.php | 26 ----- themes/default/css/fix-ie.css | 4 - themes/default/css/screen.css | 9 +- themes/default/js/ui.init.js | 31 ++---- themes/default/views/album.html.php | 2 +- 15 files changed, 131 insertions(+), 396 deletions(-) delete mode 100644 modules/gallery/css/quick.css delete mode 100644 modules/gallery/helpers/gallery_quick.php delete mode 100644 modules/gallery/js/quick.js delete mode 100644 modules/gallery/views/quick_pane.html.php (limited to 'modules/digibug/helpers') diff --git a/modules/digibug/helpers/digibug_event.php b/modules/digibug/helpers/digibug_event.php index c4f9e560..efe66a0f 100644 --- a/modules/digibug/helpers/digibug_event.php +++ b/modules/digibug/helpers/digibug_event.php @@ -36,9 +36,9 @@ class digibug_event_Core { ->css_id("gDigibugLink")); } - static function thumb_menu($menu, $theme, $item) { + static function context_menu($menu, $theme, $item) { if ($item->type == "photo") { - $menu->get("options_menu") + $menu ->append( Menu::factory("link") ->id("digibug") diff --git a/modules/gallery/controllers/quick.php b/modules/gallery/controllers/quick.php index de027c1b..82176e02 100644 --- a/modules/gallery/controllers/quick.php +++ b/modules/gallery/controllers/quick.php @@ -18,20 +18,6 @@ * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ class Quick_Controller extends Controller { - public function pane($id) { - $item = model_cache::get("item", $id); - if (!access::can("view", $item) || !access::can("edit", $item)) { - return ""; - } - - $view = new View("quick_pane.html"); - $page_type = Input::instance()->get("page_type"); - $view->button_list = gallery_quick::get_quick_buttons($item, $page_type); - $view->item = $item; - $view->page_type = $page_type; - print $view; - } - public function rotate($id, $dir) { access::verify_csrf(); $item = model_cache::get("item", $id); diff --git a/modules/gallery/css/quick.css b/modules/gallery/css/quick.css deleted file mode 100644 index f153d475..00000000 --- a/modules/gallery/css/quick.css +++ /dev/null @@ -1,52 +0,0 @@ -.gQuickPane { - position: absolute; - top: 0; - left: 0; - text-align: center; - width: 100%; - height: auto; -} - -.gItem:hover { - background-color: #cfdeff; -} - -.gQuick { - border: none !important; - margin: 0 !important; - padding: 0 !important; -} - -.gQuickPane { - background: #000; - border-bottom: 1px solid #ccc; - opacity: 0.9; - position: absolute; - top: 0; - left: 0; -} - -.gQuickPane a { - cursor: pointer; - float: left; - margin: 4px; -} - -.gQuickPaneOptions { - background: #000; - float: left; - width: 100%; -} - -.gQuickPaneOptions li a { - display: block; - float: none; - width: auto; - margin: 0; - padding: .5em .5em .5em .8em; - text-align: left; -} - -.gQuickPaneOptions li a:hover { - background-color: #4d4d4d; -} diff --git a/modules/gallery/helpers/gallery.php b/modules/gallery/helpers/gallery.php index 476e9cbe..085965a2 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -196,4 +196,106 @@ class gallery_Core { ->url(url::site("admin/maintenance"))); return $menu; } + + static function context_menu($menu, $theme, $item, $page_type) { + switch ($item->type) { + case "movie": + $edit_title = t("Edit this movie"); + $move_title = t("Move this movie to another album"); + $cover_title = t("Choose this movie as the album cover"); + $delete_title = t("Delete this movie"); + break; + + case "album": + $edit_title = t("Edit this album"); + $move_title = t("Move this album to another album"); + $cover_title = t("Choose this album as the album cover"); + $delete_title = t("Delete this album"); + break; + + default: + $edit_title = t("Edit this photo"); + $move_title = t("Move this photo to another album"); + $cover_title = t("Choose this photo as the album cover"); + $delete_title = t("Delete this photo"); + break; + } + + $csrf = access::csrf_token(); + $menu->append(Menu::factory("dialog") + ->id("edit") + ->label($edit_title) + ->css_clasS("ui-icon-pencil") + ->url(url::site("quick/form_edit/$item->id?page_type=$page_type"))); + + + if ($item->is_photo() && graphics::can("rotate")) { + $menu + ->append(Menu::factory("link") + ->id("rotate_ccw") + ->label(t("Rotate 90 degrees counter clockwise")) + ->css_class("ui-icon-rotate-ccw") + ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&page_type=$page_type"))) + ->append(Menu::factory("link") + ->id("rotate_cw") + ->label(t("Rotate 90 degrees clockwise")) + ->css_class("ui-icon-rotate-cw") + ->url(url::site("quick/rotate/$item->id/cw?csrf=$csrf&page_type=$page_type"))); + } + + // Don't move photos from the photo page; we don't yet have a good way of redirecting after move + if ($page_type == "album") { + $menu + ->append(Menu::factory("dialog") + ->id("move") + ->label($move_title) + ->css_class("ui-icon-folder-open") + ->url(url::site("move/browse/$item->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 = " "; + } + $menu + ->append(Menu::factory("link") + ->id("make_album_cover") + ->label($cover_title) + ->css_class($disabledState) + ->url( + url::site("quick/make_album_cover/$item->id?csrf=$csrf&page_type=$page_type"))) + ->append(Menu::factory("dialog") + ->id("delete") + ->label($delete_title) + ->css_class("ui-icon-trash") + ->css_id("gQuickDelete") + ->url(url::site("quick/form_delete/$item->id?csrf=$csrf&page_type=$page_type"))); + } + + if ($item->is_album()) { + $menu + ->append(Menu::factory("dialog") + ->id("add_item") + ->label(t("Add a photo")) + ->css_class("add_item") + ->url(url::site("simple_uploader/app/$item->id"))) + ->append(Menu::factory("dialog") + ->id("add_album") + ->label(t("Add an album")) + ->css_class("add_album") + ->url(url::site("form/add/albums/$item->id?type=album"))) + ->append(Menu::factory("dialog") + ->id("edit_permissions") + ->label(t("Edit permissions")) + ->css_class("permissions") + ->url(url::site("permissions/browse/$item->id"))); + } + } } \ No newline at end of file diff --git a/modules/gallery/helpers/gallery_quick.php b/modules/gallery/helpers/gallery_quick.php deleted file mode 100644 index 8a92890b..00000000 --- a/modules/gallery/helpers/gallery_quick.php +++ /dev/null @@ -1,152 +0,0 @@ -name == "gallery") { - continue; - } - $class_name = "{$module->name}_quick"; - if (method_exists($class_name, "buttons")) { - $module_buttons = call_user_func(array($class_name, "buttons"), $item, $page_type); - foreach (array("left", "center", "right", "additional") as $position) { - if (!empty($module_buttons[$position])) { - $buttons[$position] = array_merge($buttons[$position], $module_buttons[$position]); - } - } - } - } - - $sorted_buttons->main = array(); - foreach (array("left", "center", "right") as $position) { - $sorted_buttons->main = array_merge($sorted_buttons->main, $buttons[$position]); - } - - $sorted_buttons->additional = $buttons["additional"]; - $max_display = empty($sorted_buttons->additional) ? 6 : 5; - if (count($sorted_buttons->main) >= $max_display) { - $to_move = array_slice($sorted_buttons->main, 5); - $sorted_buttons->additional = array_merge($to_move, $sorted_buttons->additional); - for ($i = count($sorted_buttons->main); $i >= 5; $i--) { - unset($sorted_buttons->main[$i]); - } - } - - return $sorted_buttons; - } - - static function buttons($item, $page_type) { - $elements = array("left" => array(), "center" => array(), "right" => array(), - "additional" => array()); - switch ($item->type) { - case "movie": - $edit_title = t("Edit this movie"); - $move_title = t("Move this movie to another album"); - $cover_title = t("Choose this movie as the album cover"); - $delete_title = t("Delete this movie"); - break; - case "album": - $edit_title = t("Edit this album"); - $move_title = t("Move this album to another album"); - $cover_title = t("Choose this album as the album cover"); - $delete_title = t("Delete this album"); - break; - default: - $edit_title = t("Edit this photo"); - $move_title = t("Move this photo to another album"); - $cover_title = t("Choose this photo as the album cover"); - $delete_title = t("Delete this photo"); - break; - } - - $csrf = access::csrf_token(); - $elements["left"][] = (object)array( - "title" => $edit_title, - "class" => "gDialogLink gButtonLink", - "icon" => "ui-icon-pencil", - "href" => url::site("quick/form_edit/$item->id?page_type=$page_type")); - - if ($item->is_photo() && graphics::can("rotate")) { - $elements["left"][] = - (object)array( - "title" => t("Rotate 90 degrees counter clockwise"), - "class" => "gButtonLink", - "icon" => "ui-icon-rotate-ccw", - "href" => url::site("quick/rotate/$item->id/ccw?csrf=$csrf&page_type=$page_type")); - $elements["left"][] = - (object)array( - "title" => t("Rotate 90 degrees clockwise"), - "class" => "gButtonLink", - "icon" => "ui-icon-rotate-cw", - "href" => url::site("quick/rotate/$item->id/cw?csrf=$csrf&page_type=$page_type")); - } - - // Don't move photos from the photo page; we don't yet have a good way of redirecting after move - if ($page_type == "album") { - $elements["left"][] = (object)array( - "title" => $move_title, - "class" => "gDialogLink gButtonLink", - "icon" => "ui-icon-folder-open", - "href" => url::site("move/browse/$item->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 = " "; - } - $elements["right"][] = (object)array( - "title" => $cover_title, - "class" => "gButtonLink$disabledState", - "icon" => "ui-icon-star", - "href" => url::site("quick/make_album_cover/$item->id?csrf=$csrf&page_type=$page_type")); - - $elements["right"][] = (object)array( - "title" => $delete_title, - "class" => "gDialogLink gButtonLink", - "icon" => "ui-icon-trash", - "id" => "gQuickDelete", - "href" => url::site("quick/form_delete/$item->id?csrf=$csrf&page_type=$page_type")); - } - - if ($item->is_album()) { - $elements["additional"][] = (object)array( - "title" => t("Add a photo"), - "class" => "add_item gDialogLink", - "href" => url::site("simple_uploader/app/$item->id")); - $elements["additional"][] = (object)array( - "title" => t("Add an album"), - "class" => "add_album gDialogLink", - "href" => url::site("form/add/albums/$item->id?type=album")); - $elements["additional"][] = (object)array( - "title" => t("Edit permissions"), - "class" => "permissions gDialogLink", - "href" => url::site("permissions/browse/$item->id")); - } - return $elements; - } -} diff --git a/modules/gallery/helpers/gallery_theme.php b/modules/gallery/helpers/gallery_theme.php index d3751b80..8fe1c768 100644 --- a/modules/gallery/helpers/gallery_theme.php +++ b/modules/gallery/helpers/gallery_theme.php @@ -24,11 +24,6 @@ class gallery_theme_Core { if ($session->get("debug")) { $theme->css("debug.css"); } - if (($theme->page_type == "album" || $theme->page_type == "photo") - && access::can("edit", $theme->item())) { - $theme->css("quick.css"); - $theme->script("quick.js"); - } if (module::is_active("rss")) { if ($item = $theme->item()) { @@ -51,32 +46,6 @@ class gallery_theme_Core { return $buf; } - static function resize_top($theme, $item) { - if (access::can("edit", $item)) { - $edit_link = url::site("quick/pane/$item->id?page_type=photo"); - return "
"; - } - } - - static function resize_bottom($theme, $item) { - if (access::can("edit", $item)) { - return "
"; - } - } - - static function thumb_top($theme, $child) { - if (access::can("edit", $child)) { - $edit_link = url::site("quick/pane/$child->id?page_type=album"); - return "
"; - } - } - - static function thumb_bottom($theme, $child) { - if (access::can("edit", $child)) { - return "
"; - } - } - static function admin_head($theme) { $session = Session::instance(); if ($session->get("debug")) { diff --git a/modules/gallery/helpers/module.php b/modules/gallery/helpers/module.php index 0d483206..03d538a9 100644 --- a/modules/gallery/helpers/module.php +++ b/modules/gallery/helpers/module.php @@ -274,11 +274,9 @@ class module_Core { array_shift($args); $function = str_replace(".", "_", $name); - foreach (self::$modules as $module) { - if (!$module->active) { - continue; - } - + // @todo: consider calling gallery_event first, since for things menus we need it to do some + // setup + foreach (self::$active as $module) { $class = "{$module->name}_event"; if (method_exists($class, $function)) { call_user_func_array(array($class, $function), $args); diff --git a/modules/gallery/js/quick.js b/modules/gallery/js/quick.js deleted file mode 100644 index fda6470f..00000000 --- a/modules/gallery/js/quick.js +++ /dev/null @@ -1,78 +0,0 @@ -$(document).ready(function() { - if ($("#gAlbumGrid").length) { - // @todo Add quick edit pane for album (meta, move, permissions, delete) - $(".gItem").hover(show_quick, function() {}); - } - if ($("#gPhoto").length) { - $("#gPhoto").hover(show_quick, function() {}); - } -}); - -var show_quick = function() { - var cont = $(this); - var quick = $(this).find(".gQuick"); - var img = cont.find(".gThumbnail,.gResize"); - cont.find(".gQuickPane").remove(); - cont.append("
"); - cont.find(".gQuickPane").hide(); - cont.hover(function() {}, function() { cont.find(".gQuickPane").remove(); }); - $.get( - quick.attr("href"), - {}, - function(data, textStatus) { - cont.find(".gQuickPane").html(data).slideDown("fast"); - $(".ui-state-default").hover( - function() { - $(this).addClass("ui-state-hover"); - }, - function() { - $(this).removeClass("ui-state-hover"); - } - ); - cont.find(".gQuickPane a:not(.options)").click(function(e) { - e.preventDefault(); - quick_do(cont, $(this), img); - }); - cont.find(".gQuickPane a.options").click(function(e) { - e.preventDefault(); - cont.find(".gQuickPaneOptions").slideToggle("fast"); - }); - } - ); -}; - -var quick_do = function(cont, pane, img) { - if (pane.hasClass("ui-state-disabled")) { - return false; - } - if (pane.hasClass("gDialogLink")) { - openDialog(pane); - } else { - img.css("opacity", "0.1"); - cont.addClass("gLoadingLarge"); - $.ajax({ - type: "GET", - url: pane.attr("href"), - dataType: "json", - success: function(data) { - img.css("opacity", "1"); - cont.removeClass("gLoadingLarge"); - if (data.src) { - img.attr("width", data.width); - img.attr("height", data.height); - img.attr("src", data.src); - if (data.height > data.width) { - img.css("margin-top", -32); - } else { - img.css("margin-top", 0); - } - } else if (data.location) { - window.location = data.location; - } else if (data.reload) { - window.location.reload(); - } - } - }); - } - return false; -}; diff --git a/modules/gallery/libraries/Menu.php b/modules/gallery/libraries/Menu.php index a39b59a5..263dc38d 100644 --- a/modules/gallery/libraries/Menu.php +++ b/modules/gallery/libraries/Menu.php @@ -91,7 +91,7 @@ class Menu_Element_Link extends Menu_Element { } else { $css_class = ""; } - return "
  • url\" " . + return "
  • url\" " . "title=\"$this->label\">$this->label
  • "; } } @@ -111,7 +111,7 @@ class Menu_Element_Dialog extends Menu_Element { } else { $css_class = ""; } - return "
  • url\" " . + return "
  • url\" " . "title=\"$this->label\">$this->label
  • "; } } diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 360e5e46..24dea729 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -111,14 +111,16 @@ class Theme_View_Core extends Gallery_View { return $menu->compact(); } - public function thumb_menu($item) { + public function context_menu($item) { $menu = Menu::factory("root") ->append(Menu::factory("submenu") - ->id("options_menu") + ->id("context_menu") ->label(t("Options"))) - ->css_class("gThumbMenu"); + ->css_class("gContextMenu"); - module::event("thumb_menu", $menu, $this, $item); + $page_type = Input::instance()->get("page_type"); + gallery::context_menu($menu, $this, $item, $page_type); + module::event("context_menu", $menu, $this, $item, $page_type); return $menu->compact(); } diff --git a/modules/gallery/views/quick_pane.html.php b/modules/gallery/views/quick_pane.html.php deleted file mode 100644 index e5469696..00000000 --- a/modules/gallery/views/quick_pane.html.php +++ /dev/null @@ -1,26 +0,0 @@ - -main as $button): ?> - - - title ?> - - - - -additional)): ?> -"> - - - - - - - diff --git a/themes/default/css/fix-ie.css b/themes/default/css/fix-ie.css index c7c1ebad..eee88c15 100644 --- a/themes/default/css/fix-ie.css +++ b/themes/default/css/fix-ie.css @@ -35,7 +35,3 @@ input.submit { .gPager .ui-icon-right { width: 60px; } - -.gQuickPane { - height: 32px !important; -} \ No newline at end of file diff --git a/themes/default/css/screen.css b/themes/default/css/screen.css index c5a9956d..eb092b83 100644 --- a/themes/default/css/screen.css +++ b/themes/default/css/screen.css @@ -588,24 +588,25 @@ form .gError, /* Thumb Menu ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ -#gContent .gThumbMenu { +#gContent .gContextMenu { bottom: 0; left: 0; position: absolute; width: 100%; + display: none; } -#gContent .gThumbMenu li { +#gContent .gContextMenu li { border-left: none; border-right: none; border-bottom: none; } -#gContent .gThumbMenu li li { +#gContent .gContextMenu li li { padding: .3em; } -#gContent .gThumbMenu a:hover { +#gContent .gContextMenu a:hover { text-decoration: none; } diff --git a/themes/default/js/ui.init.js b/themes/default/js/ui.init.js index 11cd06ed..d796cb67 100644 --- a/themes/default/js/ui.init.js +++ b/themes/default/js/ui.init.js @@ -32,7 +32,6 @@ $(document).ready(function() { $("#gMessage li").showMessage(); // Initialize dialogs - $(".gMenuLink").addClass("gDialogLink"); $("#gLoginLink").addClass("gDialogLink"); var dialogLinks = $(".gDialogLink"); for (var i=0; i < dialogLinks.length; i++) { @@ -57,9 +56,6 @@ $(document).ready(function() { if ($("#gAlbumGrid").length) { // Vertical align thumbnails/metadata in album grid $(".gItem").vAlign(); - $(".gQuick").ajaxStop(function(){ - $(".gItem").vAlign(); - }); } // Photo/Item item view only @@ -97,26 +93,19 @@ $(document).ready(function() { } ); - // Initialize thumbnail menus - // @todo Toggle between north and south caret's on hover - if ($("#gContent .gThumbMenu").length) { - $("#gContent .gThumbMenu li").addClass("ui-state-default"); - $("#gContent .gThumbMenu li a") - .not('[class]') - .addClass("gButtonLink ui-icon ui-icon-caret-l-n") - .css({ - height: "10px", - margin: "0", - padding: "0 0 3px 0" - }); - - $(".gThumbMenu ul").hide(); - $(".gThumbMenu").hover( + // Initialize context menus + if ($("#gContent .gContextMenu").length) { + $("#gContent .gContextMenu li").addClass("ui-state-default"); + $(".gContextMenu").parent().hover( function() { - $(this).find("ul").slideDown("fast"); + $(this).find(".gContextMenu").slideDown("fast"); + var dialogLinks = $(this).find(".gDialogLink"); + for (var i = 0; i < dialogLinks.length; i++) { + $(dialogLinks[i]).bind("click", handleDialogEvent); + } }, function() { - $(this).find("ul").slideUp("slow"); + $(this).find(".gContextMenu").slideUp("slow"); } ); } diff --git a/themes/default/views/album.html.php b/themes/default/views/album.html.php index 65ea3381..ce57458e 100644 --- a/themes/default/views/album.html.php +++ b/themes/default/views/album.html.php @@ -19,7 +19,7 @@ thumb_img(array("class" => "gThumbnail")) ?> thumb_bottom($child) ?> - thumb_menu($child) ?> + context_menu($child) ?>

    title) ?>