diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/helpers/core_block.php | 5 | ||||
-rw-r--r-- | core/helpers/core_menu.php | 50 | ||||
-rw-r--r-- | core/helpers/menus.php | 42 | ||||
-rw-r--r-- | core/js/menu.js | 24 | ||||
-rw-r--r-- | core/libraries/Menu.php | 111 | ||||
-rw-r--r-- | core/libraries/Theme_View.php | 6 | ||||
-rw-r--r-- | core/tests/Menu_Test.php | 73 |
7 files changed, 311 insertions, 0 deletions
diff --git a/core/helpers/core_block.php b/core/helpers/core_block.php index 801ffb82..1a90d466 100644 --- a/core/helpers/core_block.php +++ b/core/helpers/core_block.php @@ -19,6 +19,11 @@ */ class core_block_Core { + public static function head($theme) { + $url = url::file("core/js/menu.js"); + return "<script src=\"$url\" type=\"text/javascript\"></script>"; + } + public static function page_bottom($theme) { // @todo: guard this with permissions if (Session::instance()->get("user", false)) { diff --git a/core/helpers/core_menu.php b/core/helpers/core_menu.php new file mode 100644 index 00000000..e43c7762 --- /dev/null +++ b/core/helpers/core_menu.php @@ -0,0 +1,50 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 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 core_menu_Core { + public static function items($menus, $theme) { + $menus->append(new Menu(_("HOME"), url::base())); + $menus->append(new Menu(_("BROWSE"), url::site("albums/1"))); + + $user = Session::instance()->get('user', null); + if ($user) { + $upload_menu = new Menu(_("UPLOAD")); + $upload_menu->append( + new Menu(_("File Upload"), "#photo/form/file_upload/" . $theme->item()->id)); + $upload_menu->append( + new Menu(_("Local Upload"), "#photo/form/local_upload/" . $theme->item()->id)); + $menus->append($upload_menu); + + $admin_menu = new Menu(_("ADMIN")); + + // @todo need to do a permission check here + $admin_menu->append( + new Menu(_("Edit Item"), "#photo/form/local_upload/" . $theme->item()->id)); + + if ($user->admin) { + $admin_menu->append( + new Menu(_("Site Admin"), url::site("admin"))); + } + + $menus->append($admin_menu); + } + } + +} diff --git a/core/helpers/menus.php b/core/helpers/menus.php new file mode 100644 index 00000000..28b34781 --- /dev/null +++ b/core/helpers/menus.php @@ -0,0 +1,42 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 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 menus_Core { + public static function get_menu_items($theme) { + $menu = new Menu(); + + // Call core menus first to establish the basic menu + self::_get_module_menu_items("core", $menu, $theme); + foreach (module::installed() as $module) { + if ($module->name == "core") { + continue; + } + self::_get_module_menu_items($module->name, $menu, $theme); + } + + return $menu; + } + + static function _get_module_menu_items($module_name, $menu, $theme) { + $class = "{$module_name}_menu"; + if (method_exists($class, "items")) { + call_user_func_array(array($class, "items"), array(&$menu, $theme)); + } + } +}
\ No newline at end of file diff --git a/core/js/menu.js b/core/js/menu.js new file mode 100644 index 00000000..b5f0a6ee --- /dev/null +++ b/core/js/menu.js @@ -0,0 +1,24 @@ +$("document").ready(function() { + $("#gSiteMenu ul:not(:first)").css("display", "none"); + $("#gSiteMenu li").mouseover(function (ev) { + $(this).children("ul").css("display", "block"); + $(this).children("ul").find("li").css("clear", "both"); + + this.dropdown_open = true; + }); + $("#gSiteMenu li").mouseout(function (ev) { + $(this).children("ul").css("display", "none"); + this.dropdown_open = false; + }); + + $("#gSiteMenu li a").click(function () { + var href = $(this).attr("href"); + if (href == "#") { + return false; + } else if (href.match("^#") == "#") { + alert("Display href: " + href.substring(1) + "in a popup"); + return false; + } + return true; + }); +}); diff --git a/core/libraries/Menu.php b/core/libraries/Menu.php new file mode 100644 index 00000000..4f4530a7 --- /dev/null +++ b/core/libraries/Menu.php @@ -0,0 +1,111 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 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 Menu_Item { + protected $_text; + protected $_url; + + function __constructor($text, $url="#") { + $this->_text = $text; + $this->_url = $url; + } + + function __toString() { + return "<li><a href=\"$this->_url\">$this->_text</a></li>"; + } +} + +class Menu_Core { + protected $_text; + protected $_url; + protected $_items = array(); + + public function __construct($text="", $url="#") { + $this->_text = $text; + $this->_url = $url; + } + + public function append($menu_item) { + $this->_items[] = $menu_item; + } + + public function get($text) { + foreach ($this->_items as $item) { + if ($item->_text == $text) { + return $item; + } + } + return false; + } + + private function _get_index($text) { + foreach ($this->_items as $idx => $item) { + if ($item->_text == $text) { + return (int)$idx; + } + } + return false; + } + + public function insert_before($text, $menu_item) { + $offset = $this->_get_index($text); + + $front_part = ($offset == 0) ? array() : array_splice($this->_items, 0, $offset); + $back_part = ($offset == 0) ? $this->_items : array_splice($this->_items, $offset - 1); + $this->_items = array_merge($front_part, array($menu_item), $back_part); + } + + public function insert_after($text, $menu_item) { + $offset = $this->_get_index($text); + $last_offset = count($this->_items) - 1; + // If not found, then append to the end + if ($offset == false) { + $offset = $last_offset; + } + + $front_part = ($offset == $last_offset) ? $this->_items : array_splice($this->_items, 0, $offset + 1); + Kohana::log("debug", print_r($front_part, 1)); + $back_part = ($offset == $last_offset) ? array() : array_splice($this->_items, $offset - 1); + Kohana::log("debug", print_r($back_part, 1)); + $this->_items = array_merge($front_part, array($menu_item), $back_part); + } + + public function __toString() { + $items_html = array(); + if (!empty($this->_text)) { + $items_html[] = "<li><a href=\"$this->_url\">$this->_text</a>"; + } + + if (!empty($this->_items)) { +// $items_html[] = "<ul class=\"gItemMenu\">"; + $items_html[] = "<ul>"; + + foreach ($this->_items as $item) { + $items_html[] = $item->__toString(); + } + + $items_html[] = "</ul>"; + } + + if (!empty($this->_text)) { + $items_html[] = "</li>"; + } + return implode("\n", $items_html); + } +} diff --git a/core/libraries/Theme_View.php b/core/libraries/Theme_View.php index 16cc8df9..1c388596 100644 --- a/core/libraries/Theme_View.php +++ b/core/libraries/Theme_View.php @@ -57,6 +57,12 @@ class Theme_View_Core extends View { return new $view_class($page_name); } + public function site_navigation() { + $menu = menus::get_menu_items($this)->__toString(); + Kohana::log("debug", sprintf("[%s%s] site_navigation: %s", __FILE__, __LINE__, $menu)); + return $menu; + } + public function pager() { $this->pagination = new Pagination(); $this->pagination->initialize( diff --git a/core/tests/Menu_Test.php b/core/tests/Menu_Test.php new file mode 100644 index 00000000..978e5555 --- /dev/null +++ b/core/tests/Menu_Test.php @@ -0,0 +1,73 @@ +<?php defined("SYSPATH") or die("No direct script access."); +/** + * Gallery - a web based photo album viewer and editor + * Copyright (C) 2000-2008 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 Menu_Test extends Unit_Test_Case { + public function find_menu_item_test() { + $test_menu = new Menu(); + $test_menu->append(new Menu("test1")); + $test_menu->append(new Menu("test2")); + $expected = new Menu("test3"); + $test_menu->append($expected); + $test_menu->append(new Menu("test4")); + + $menu_item = $test_menu->get("test3"); + $this->assert_equal($expected, $menu_item); + } + + public function insert_before_test() { + $expected = new Menu(); + $expected->append(new Menu("test-2")); + $expected->append(new Menu("test0")); + $expected->append(new Menu("test1")); + $expected->append(new Menu("test1b")); + $expected->append(new Menu("test2")); + $expected->append(new Menu("test4")); + + $test_menu = new Menu(); + $test_menu->append(new Menu("test1")); + $test_menu->append(new Menu("test2")); + $test_menu->append(new Menu("test4")); + $test_menu->insert_before("test2", new Menu("test1b")); + $test_menu->insert_before("test1", new Menu("test0")); + $test_menu->insert_before("test-1", new Menu("test-2")); + + $this->assert_equal($expected, $test_menu); + } + + public function insert_after_test() { + $expected = new Menu(); + $expected->append(new Menu("test1")); + $expected->append(new Menu("test2")); + $expected->append(new Menu("test3")); + $expected->append(new Menu("test4")); + $expected->append(new Menu("test5")); + $expected->append(new Menu("test7")); + + $test_menu = new Menu(); + $test_menu->append(new Menu("test1")); + $test_menu->append(new Menu("test2")); + $test_menu->append(new Menu("test4")); + $test_menu->insert_after("test2", new Menu("test3")); + $test_menu->insert_after("test4", new Menu("test5")); + $test_menu->insert_after("test6", new Menu("test7")); + + $this->assert_equal($expected, $test_menu); + } + +}
\ No newline at end of file |