diff options
| author | Tim Almdal <tnalmdal@shaw.ca> | 2009-08-19 05:14:05 -0700 | 
|---|---|---|
| committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-08-19 05:14:05 -0700 | 
| commit | bc42df35ee6cce419cbd9f514f245dcf8c70262b (patch) | |
| tree | d1ad4c36130edf320368c5e08f79ebb950b6bcec /modules/gallery | |
| parent | 2ac916783ad81f49185fa5c8514aefcb330a6128 (diff) | |
| parent | 3b8323d5b4db4904aba9ea2f922140ab235dd681 (diff) | |
Merge branch 'master' of git://github.com/gallery/gallery3
Diffstat (limited to 'modules/gallery')
| -rw-r--r-- | modules/gallery/controllers/quick.php | 14 | ||||
| -rw-r--r-- | modules/gallery/css/quick.css | 52 | ||||
| -rw-r--r-- | modules/gallery/helpers/gallery.php | 114 | ||||
| -rw-r--r-- | modules/gallery/helpers/gallery_quick.php | 152 | ||||
| -rw-r--r-- | modules/gallery/helpers/gallery_theme.php | 31 | ||||
| -rw-r--r-- | modules/gallery/helpers/module.php | 8 | ||||
| -rw-r--r-- | modules/gallery/js/quick.js | 78 | ||||
| -rw-r--r-- | modules/gallery/libraries/Menu.php | 38 | ||||
| -rw-r--r-- | modules/gallery/libraries/Theme_View.php | 9 | ||||
| -rw-r--r-- | modules/gallery/views/quick_pane.html.php | 26 | 
10 files changed, 158 insertions, 364 deletions
| 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..c81af842 100644 --- a/modules/gallery/helpers/gallery.php +++ b/modules/gallery/helpers/gallery.php @@ -196,4 +196,118 @@ class gallery_Core {                 ->url(url::site("admin/maintenance")));      return $menu;    } + +  static function context_menu($menu, $theme, $item, $thumb_css_selector) { +    $menu->append($options_menu = Menu::factory("submenu") +                  ->id("options_menu") +                  ->label(t("Options")) +                  ->css_class("ui-icon-carat-1-n")); + +    if (access::can("edit", $item)) { +      $page_type = $theme->page_type(); +      switch ($item->type) { +      case "movie": +        $edit_title = t("Edit this movie"); +        $delete_title = t("Delete this movie"); +        break; + +      case "album": +        $edit_title = t("Edit this album"); +        $delete_title = t("Delete this album"); +        break; + +      default: +        $edit_title = t("Edit this photo"); +        $delete_title = t("Delete this photo"); +        break; +      } +      $cover_title = t("Choose as the album cover"); +      $move_title = t("Move to another album"); + +      $csrf = access::csrf_token(); + +      $options_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")) { +        $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, \$('$thumb_css_selector')) }") +            ->url(url::site("quick/rotate/$item->id/ccw?csrf=$csrf&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, \$('$thumb_css_selector')) }") +            ->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") { +        $options_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 = " "; +        } +        $options_menu +          ->append(Menu::factory("ajax_link") +                   ->id("make_album_cover") +                   ->label($cover_title) +                   ->css_class("ui-icon-star") +                   ->ajax_handler("function(data) { window.location.reload() }") +                   ->url(url::site("quick/make_album_cover/$item->id?csrf=$csrf"))) +          ->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()) { +        $options_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 @@ -<?php defined("SYSPATH") or die("No direct script access."); -/** - * Gallery - a web based photo album viewer and editor - * Copyright (C) 2000-2009 Bharat Mediratta - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or (at - * your option) any later version. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA  02110-1301, USA. - */ -class gallery_quick_Core { -  static function get_quick_buttons($item, $page_type) { -    $buttons = self::buttons($item, $page_type); -    foreach (module::active() as $module) { -      if ($module->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 903827cc..69c5a091 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 "<div class=\"gQuick\" href=\"$edit_link\">"; -    } -  } - -  static function resize_bottom($theme, $item) { -    if (access::can("edit", $item)) { -      return "</div>"; -    } -  } - -  static function thumb_top($theme, $child) { -    if (access::can("edit", $child)) { -      $edit_link = url::site("quick/pane/$child->id?page_type=album"); -      return "<div class=\"gQuick\" href=\"$edit_link\">"; -    } -  } - -  static function thumb_bottom($theme, $child) { -    if (access::can("edit", $child)) { -      return "</div>"; -    } -  } -    static function admin_head($theme) {      $theme->script("gallery.panel.js");      $session = Session::instance(); 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 1c243b79..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("<div class=\"gQuickPane\"></div>"); -  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")) { -    $(pane).gallery_dialog({immediate: true}); -  } 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..07b2b2b8 100644 --- a/modules/gallery/libraries/Menu.php +++ b/modules/gallery/libraries/Menu.php @@ -91,12 +91,43 @@ class Menu_Element_Link extends Menu_Element {      } else {        $css_class = "";      } -    return "<li><a$css_id class=\"gMenuElement$css_class\" href=\"$this->url\" " . +    return "<li><a$css_id class=\"gMenuLink $css_class\" href=\"$this->url\" " .        "title=\"$this->label\">$this->label</a></li>";    }  }  /** + * Menu element that provides an AJAX link. + */ +class Menu_Element_Ajax_Link extends Menu_Element { +  public $ajax_handler; + +  /** +   * Set the AJAX handler +   * @chainable +   */ +  public function ajax_handler($ajax_handler) { +    $this->ajax_handler = $ajax_handler; +    return $this; +  } + +  public function __toString() { +    if (isset($this->css_id) && !empty($this->css_id)) { +      $css_id = " id=\"$this->css_id\""; +    } else { +      $css_id = ""; +    } +    if (isset($this->css_class) && !empty($this->css_class)) { +      $css_class = " $this->css_class"; +    } else { +      $css_class = ""; +    } +    return "<li><a$css_id class=\"gAjaxLink $css_class\" href=\"$this->url\" " . +      "title=\"$this->label\" ajax_handler=\"$this->ajax_handler\">$this->label</a></li>"; +  } +} + +/**   * Menu element that provides a pop-up dialog   */  class Menu_Element_Dialog extends Menu_Element { @@ -111,7 +142,7 @@ class Menu_Element_Dialog extends Menu_Element {      } else {        $css_class = "";      } -    return "<li><a$css_id class=\"gMenuLink$css_class\" href=\"$this->url\" " . +    return "<li><a$css_id class=\"gDialogLink $css_class\" href=\"$this->url\" " .             "title=\"$this->label\">$this->label</a></li>";    }  } @@ -132,6 +163,9 @@ class Menu_Core extends Menu_Element {      case "link":        return new Menu_Element_Link($type); +    case "ajax_link": +      return new Menu_Element_Ajax_Link($type); +      case "dialog":        return new Menu_Element_Dialog($type); diff --git a/modules/gallery/libraries/Theme_View.php b/modules/gallery/libraries/Theme_View.php index 360e5e46..541bce88 100644 --- a/modules/gallery/libraries/Theme_View.php +++ b/modules/gallery/libraries/Theme_View.php @@ -111,14 +111,15 @@ class Theme_View_Core extends Gallery_View {      return $menu->compact();    } -  public function thumb_menu($item) { +  public function context_menu($item, $thumbnail_css_selector) {      $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); +    gallery::context_menu($menu, $this, $item, $thumbnail_css_selector); +    module::event("context_menu", $menu, $this, $item, $thumbnail_css_selector);      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 @@ -<?php defined("SYSPATH") or die("No direct script access.") ?> -<? foreach ($button_list->main as $button): ?> -<a class="<?= $button->class ?> ui-corner-all ui-state-default" href="<?= $button->href ?>" -  title="<?= $button->title ?>"> -  <span class="ui-icon <?= $button->icon ?>"> -    <?= $button->title ?> -  </span> -</a> -<? endforeach ?> - -<? if (!empty($button_list->additional)): ?> -<a class="gButtonLink ui-corner-all ui-state-default options" href="#" title="<?= t("additional options") ?>"> -  <span class="ui-icon ui-icon-triangle-1-s"> -    <?= t("Additional options") ?> -  </span> -</a> - -<ul class="gQuickPaneOptions" style="display: none"> -  <? foreach ($button_list->additional as $button): ?> -  <li><a class="<?= $button->class ?>" href="<?= $button->href ?>" -    title="<?= $button->title ?>"> -    <?=  $button->title ?> -  </a></li> -  <? endforeach ?> -</ul> -<? endif ?> | 
