diff --git a/3.0/modules/custom_menus/controllers/admin_custom_menus.php b/3.0/modules/custom_menus/controllers/admin_custom_menus.php
new file mode 100644
index 00000000..68b43f71
--- /dev/null
+++ b/3.0/modules/custom_menus/controllers/admin_custom_menus.php
@@ -0,0 +1,254 @@
+page_title = t("Manage menus");
+ $view->content = new View("admin_custom_menus.html");
+ $view->content->menu_list = $this->get_html_list(0);
+ print $view;
+ }
+
+ public function form_create($id) {
+ // Display the create new menu form.
+ print $this->get_new_menu_form($id);
+ }
+
+ public function form_edit($id) {
+ // Display the edit menu form.
+ print $this->get_edit_menu_form($id);
+ }
+
+ static function get_new_menu_form($id) {
+ // Generate the create new menu form.
+ $form = new Forge("admin/custom_menus/create/$id", "", "post", array("id" => "g-create-menu-form"));
+ $group = $form->group("create_menu")
+ ->label(t("Add new menu"));
+ $group->input("menu_title")
+ ->label(t("Title"));
+ $group->input("menu_url")
+ ->label(t("URL (Leave blank if this menu will have sub-menus)"));
+ $group->submit("")->value(t("Create menu"));
+ return $form;
+ }
+
+ static function get_edit_menu_form($id) {
+ // Generate the edit menu form.
+ $existing_menu = ORM::factory("custom_menu", $id);
+ $form = new Forge("admin/custom_menus/edit/$id", "", "post", array("id" => "g-edit-menu-form"));
+ $group = $form->group("edit_menu")
+ ->label(t("Edit menu"));
+ $group->input("menu_title")
+ ->label(t("Title"))
+ ->value($existing_menu->title);
+ $group->input("menu_url")
+ ->label(t("URL (Leave blank if this menu will have sub-menus)"))
+ ->value($existing_menu->url);
+ $group->submit("")->value(t("Save changes"));
+ return $form;
+ }
+
+ public function create($id) {
+ // Save a new menu to the database.
+
+ access::verify_csrf();
+
+ // Save form variables to the database.
+ $new_menu = ORM::factory("custom_menu");
+ $new_menu->title = Input::instance()->post("menu_title");
+ $new_menu->url = Input::instance()->post("menu_url");
+ $new_menu->parent_id = $id;
+
+ // Set menu's location to the last position.
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $id)
+ ->order_by("order_by", "DESC")
+ ->find_all(1);
+ if (count($existing_menu) > 0) {
+ $int_position = $existing_menu[0]->order_by;
+ $int_position++;
+ $new_menu->order_by = $int_position;
+ } else {
+ $new_menu->order_by = 0;
+ }
+
+ // Save new menu to the database.
+ $new_menu->save();
+ message::success(t("Menu %menu_name created", array("menu_name" => $new_menu->title)));
+ log::success("custom_menus", t("Menu %menu_name created", array("menu_name" => $new_menu->title)));
+ json::reply(array("result" => "success"));
+ }
+
+ public function edit($id) {
+ // Save a new menu to the database.
+
+ access::verify_csrf();
+
+ // Load the existing menu and save changes.
+ $existing_menu = ORM::factory("custom_menu", $id);
+ if ($existing_menu->loaded()) {
+ $existing_menu->title = Input::instance()->post("menu_title");
+ $existing_menu->url = Input::instance()->post("menu_url");
+ $existing_menu->save();
+ message::success(t("Menu %menu_name saved", array("menu_name" => $existing_menu->title)));
+ log::success("custom_menus", t("Menu %menu_name saved", array("menu_name" => $existing_menu->title)));
+ json::reply(array("result" => "success"));
+ } else {
+ message::error(t("Unable to load menu %menu_id", array("menu_id" => $id)));
+ log::success("custom_menus", t("Unable to load menu %menu_id", array("menu_id" => $id)));
+ json::reply(array("result" => "success"));
+ }
+ }
+
+ function get_html_list($parent_id) {
+ // Generate an HTML list of existing menu items.
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $parent_id)
+ ->order_by("order_by", "ASC")
+ ->find_all();
+ $str_html = "";
+ if (count($existing_menu) > 0) {
+ $str_html = "
\n";
+ }
+ return $str_html;
+ }
+
+ public function form_delete($id) {
+ // Display a form asking the user if they want to delete a menu.
+ $one_menu = ORM::factory("custom_menu", $id);
+ if ($one_menu->loaded()) {
+ print $this->get_delete_form($one_menu);
+ }
+ }
+
+ public function delete($id) {
+ // Delete the specified menu.
+
+ access::verify_csrf();
+
+ // Make sure $id belongs to an actual menu.
+ $one_menu = ORM::factory("custom_menu", $id);
+ if (!$one_menu->loaded()) {
+ throw new Kohana_404_Exception();
+ }
+
+ // If the form validates, delete the specified menu.
+ $form = $this->get_delete_form($one_menu);
+ if ($form->validate()) {
+ $name = $one_menu->title;
+ $this->delete_sub_menus($one_menu->id);
+ $one_menu->delete();
+ message::success(t("Deleted menu %menu_name", array("menu_name" => $name)));
+ log::success("custom_menus", t("Deleted menu %menu_name", array("menu_name" => $name)));
+ json::reply(array("result" => "success", "location" => url::site("admin/custom_menus")));
+ } else {
+ print $form;
+ }
+ }
+
+ function delete_sub_menus($parent_id) {
+ // Delete all sub menus associated with $parent_id.
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $parent_id)
+ ->order_by("title", "ASC")
+ ->find_all();
+ foreach ($existing_menu as $one_menu) {
+ $this->delete_sub_menus($one_menu->id);
+ $one_menu->delete();
+ }
+ }
+
+ static function get_delete_form($one_menu) {
+ // Generate a new form asking the user if they want to delete a menu.
+ $form = new Forge("admin/custom_menus/delete/$one_menu->id", "", "post", array("id" => "g-delete-menu-form"));
+ $group = $form->group("delete_menu")
+ ->label(t("Really delete menu %menu_name & sub-menus?", array("menu_name" => $one_menu->title)));
+ $group->submit("")->value(t("Delete Menu"));
+ return $form;
+ }
+
+ public function move_menu_up($id) {
+ // Move the specified menu item up one position.
+ $one_menu = ORM::factory("custom_menu", $id);
+ if ($one_menu->loaded()) {
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $one_menu->parent_id)
+ ->where("order_by", "<", $one_menu->order_by)
+ ->order_by("order_by", "DESC")
+ ->find_all(1);
+ if (count($existing_menu) > 0) {
+ $second_menu = ORM::factory("custom_menu", $existing_menu[0]->id);
+ $temp_position = $one_menu->order_by;
+ $one_menu->order_by = $second_menu->order_by;
+ $second_menu->order_by = $temp_position;
+ $one_menu->save();
+ $second_menu->save();
+ message::success(t("Menu %menu_title moved up", array("menu_title" => $one_menu->title)));
+ log::success("custom_menus", t("Menu %menu_title moved up", array("menu_title" => $one_menu->title)));
+ }
+ }
+ url::redirect("admin/custom_menus");
+ }
+
+ public function move_menu_down($id) {
+ // Move the specified menu item down one position.
+ $one_menu = ORM::factory("custom_menu", $id);
+ if ($one_menu->loaded()) {
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $one_menu->parent_id)
+ ->where("order_by", ">", $one_menu->order_by)
+ ->order_by("order_by", "ASC")
+ ->find_all(1);
+ if (count($existing_menu) > 0) {
+ $second_menu = ORM::factory("custom_menu", $existing_menu[0]->id);
+ $temp_position = $one_menu->order_by;
+ $one_menu->order_by = $second_menu->order_by;
+ $second_menu->order_by = $temp_position;
+ $one_menu->save();
+ $second_menu->save();
+ message::success(t("Menu %menu_title moved down", array("menu_title" => $one_menu->title)));
+ log::success("custom_menus", t("Menu %menu_title moved down", array("menu_title" => $one_menu->title)));
+ }
+ }
+ url::redirect("admin/custom_menus");
+ }
+}
diff --git a/3.0/modules/custom_menus/helpers/custom_menus_event.php b/3.0/modules/custom_menus/helpers/custom_menus_event.php
new file mode 100644
index 00000000..a26ae3d8
--- /dev/null
+++ b/3.0/modules/custom_menus/helpers/custom_menus_event.php
@@ -0,0 +1,75 @@
+get("content_menu")
+ ->append(Menu::factory("link")
+ ->id("custom_menus")
+ ->label(t("Custom Menus Manager"))
+ ->url(url::site("admin/custom_menus")));
+ }
+
+ static function site_menu($menu, $theme) {
+ // Add user definied menu and sub-menu items to the site menu.
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", "0")
+ ->order_by("order_by", "DESC")
+ ->find_all();
+ if (count($existing_menu) > 0) {
+ foreach ($existing_menu as $one_menu) {
+ if ($one_menu->url == "") {
+ $menu->add_after("home", $new_menu = Menu::factory("submenu")
+ ->id("custom_menus-" . $one_menu->id)
+ ->label($one_menu->title));
+ custom_menus_event::add_sub_menus($one_menu->id, $new_menu);
+ } else {
+ $menu->add_after("home", Menu::factory("link")
+ ->id("custom_menus-" . $one_menu->id)
+ ->label($one_menu->title)
+ ->url($one_menu->url));
+ }
+ }
+ }
+ }
+
+ function add_sub_menus($parent_id, $parent_menu) {
+ // Populate the menu bar with any sub-menu items on the current menu ($parent_menu).
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $parent_id)
+ ->order_by("order_by", "ASC")
+ ->find_all();
+ if (count($existing_menu) > 0) {
+ foreach ($existing_menu as $one_menu) {
+ if ($one_menu->url == "") {
+ $parent_menu->append($new_menu = Menu::factory("submenu")
+ ->id("custom_menus-" . $one_menu->id)
+ ->label($one_menu->title));
+ custom_menus_event::add_sub_menus($one_menu->id, $new_menu);
+ } else {
+ $parent_menu->append(Menu::factory("link")
+ ->id("custom_menus-" . $one_menu->id)
+ ->label($one_menu->title)
+ ->url($one_menu->url));
+ }
+ }
+ }
+ }
+}
diff --git a/3.0/modules/custom_menus/helpers/custom_menus_installer.php b/3.0/modules/custom_menus/helpers/custom_menus_installer.php
new file mode 100644
index 00000000..39021efb
--- /dev/null
+++ b/3.0/modules/custom_menus/helpers/custom_menus_installer.php
@@ -0,0 +1,37 @@
+query("CREATE TABLE IF NOT EXISTS {custom_menus} (
+ `id` int(9) NOT NULL auto_increment,
+ `title` varchar(255) default NULL,
+ `url` text default NULL,
+ `parent_id` int(9) NOT NULL default 0,
+ `order_by` int(9) NOT NULL default 0,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY(`id`))
+ DEFAULT CHARSET=utf8;");
+
+ // Set the module version number.
+ module::set_version("custom_menus", 1);
+ }
+}
diff --git a/3.0/modules/custom_menus/models/custom_menu.php b/3.0/modules/custom_menus/models/custom_menu.php
new file mode 100644
index 00000000..475ad99b
--- /dev/null
+++ b/3.0/modules/custom_menus/models/custom_menu.php
@@ -0,0 +1,21 @@
+
+
+
= t("Manage menus") ?>
+
+
diff --git a/3.1/modules/custom_menus/controllers/admin_custom_menus.php b/3.1/modules/custom_menus/controllers/admin_custom_menus.php
new file mode 100644
index 00000000..68b43f71
--- /dev/null
+++ b/3.1/modules/custom_menus/controllers/admin_custom_menus.php
@@ -0,0 +1,254 @@
+page_title = t("Manage menus");
+ $view->content = new View("admin_custom_menus.html");
+ $view->content->menu_list = $this->get_html_list(0);
+ print $view;
+ }
+
+ public function form_create($id) {
+ // Display the create new menu form.
+ print $this->get_new_menu_form($id);
+ }
+
+ public function form_edit($id) {
+ // Display the edit menu form.
+ print $this->get_edit_menu_form($id);
+ }
+
+ static function get_new_menu_form($id) {
+ // Generate the create new menu form.
+ $form = new Forge("admin/custom_menus/create/$id", "", "post", array("id" => "g-create-menu-form"));
+ $group = $form->group("create_menu")
+ ->label(t("Add new menu"));
+ $group->input("menu_title")
+ ->label(t("Title"));
+ $group->input("menu_url")
+ ->label(t("URL (Leave blank if this menu will have sub-menus)"));
+ $group->submit("")->value(t("Create menu"));
+ return $form;
+ }
+
+ static function get_edit_menu_form($id) {
+ // Generate the edit menu form.
+ $existing_menu = ORM::factory("custom_menu", $id);
+ $form = new Forge("admin/custom_menus/edit/$id", "", "post", array("id" => "g-edit-menu-form"));
+ $group = $form->group("edit_menu")
+ ->label(t("Edit menu"));
+ $group->input("menu_title")
+ ->label(t("Title"))
+ ->value($existing_menu->title);
+ $group->input("menu_url")
+ ->label(t("URL (Leave blank if this menu will have sub-menus)"))
+ ->value($existing_menu->url);
+ $group->submit("")->value(t("Save changes"));
+ return $form;
+ }
+
+ public function create($id) {
+ // Save a new menu to the database.
+
+ access::verify_csrf();
+
+ // Save form variables to the database.
+ $new_menu = ORM::factory("custom_menu");
+ $new_menu->title = Input::instance()->post("menu_title");
+ $new_menu->url = Input::instance()->post("menu_url");
+ $new_menu->parent_id = $id;
+
+ // Set menu's location to the last position.
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $id)
+ ->order_by("order_by", "DESC")
+ ->find_all(1);
+ if (count($existing_menu) > 0) {
+ $int_position = $existing_menu[0]->order_by;
+ $int_position++;
+ $new_menu->order_by = $int_position;
+ } else {
+ $new_menu->order_by = 0;
+ }
+
+ // Save new menu to the database.
+ $new_menu->save();
+ message::success(t("Menu %menu_name created", array("menu_name" => $new_menu->title)));
+ log::success("custom_menus", t("Menu %menu_name created", array("menu_name" => $new_menu->title)));
+ json::reply(array("result" => "success"));
+ }
+
+ public function edit($id) {
+ // Save a new menu to the database.
+
+ access::verify_csrf();
+
+ // Load the existing menu and save changes.
+ $existing_menu = ORM::factory("custom_menu", $id);
+ if ($existing_menu->loaded()) {
+ $existing_menu->title = Input::instance()->post("menu_title");
+ $existing_menu->url = Input::instance()->post("menu_url");
+ $existing_menu->save();
+ message::success(t("Menu %menu_name saved", array("menu_name" => $existing_menu->title)));
+ log::success("custom_menus", t("Menu %menu_name saved", array("menu_name" => $existing_menu->title)));
+ json::reply(array("result" => "success"));
+ } else {
+ message::error(t("Unable to load menu %menu_id", array("menu_id" => $id)));
+ log::success("custom_menus", t("Unable to load menu %menu_id", array("menu_id" => $id)));
+ json::reply(array("result" => "success"));
+ }
+ }
+
+ function get_html_list($parent_id) {
+ // Generate an HTML list of existing menu items.
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $parent_id)
+ ->order_by("order_by", "ASC")
+ ->find_all();
+ $str_html = "";
+ if (count($existing_menu) > 0) {
+ $str_html = "\n";
+ }
+ return $str_html;
+ }
+
+ public function form_delete($id) {
+ // Display a form asking the user if they want to delete a menu.
+ $one_menu = ORM::factory("custom_menu", $id);
+ if ($one_menu->loaded()) {
+ print $this->get_delete_form($one_menu);
+ }
+ }
+
+ public function delete($id) {
+ // Delete the specified menu.
+
+ access::verify_csrf();
+
+ // Make sure $id belongs to an actual menu.
+ $one_menu = ORM::factory("custom_menu", $id);
+ if (!$one_menu->loaded()) {
+ throw new Kohana_404_Exception();
+ }
+
+ // If the form validates, delete the specified menu.
+ $form = $this->get_delete_form($one_menu);
+ if ($form->validate()) {
+ $name = $one_menu->title;
+ $this->delete_sub_menus($one_menu->id);
+ $one_menu->delete();
+ message::success(t("Deleted menu %menu_name", array("menu_name" => $name)));
+ log::success("custom_menus", t("Deleted menu %menu_name", array("menu_name" => $name)));
+ json::reply(array("result" => "success", "location" => url::site("admin/custom_menus")));
+ } else {
+ print $form;
+ }
+ }
+
+ function delete_sub_menus($parent_id) {
+ // Delete all sub menus associated with $parent_id.
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $parent_id)
+ ->order_by("title", "ASC")
+ ->find_all();
+ foreach ($existing_menu as $one_menu) {
+ $this->delete_sub_menus($one_menu->id);
+ $one_menu->delete();
+ }
+ }
+
+ static function get_delete_form($one_menu) {
+ // Generate a new form asking the user if they want to delete a menu.
+ $form = new Forge("admin/custom_menus/delete/$one_menu->id", "", "post", array("id" => "g-delete-menu-form"));
+ $group = $form->group("delete_menu")
+ ->label(t("Really delete menu %menu_name & sub-menus?", array("menu_name" => $one_menu->title)));
+ $group->submit("")->value(t("Delete Menu"));
+ return $form;
+ }
+
+ public function move_menu_up($id) {
+ // Move the specified menu item up one position.
+ $one_menu = ORM::factory("custom_menu", $id);
+ if ($one_menu->loaded()) {
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $one_menu->parent_id)
+ ->where("order_by", "<", $one_menu->order_by)
+ ->order_by("order_by", "DESC")
+ ->find_all(1);
+ if (count($existing_menu) > 0) {
+ $second_menu = ORM::factory("custom_menu", $existing_menu[0]->id);
+ $temp_position = $one_menu->order_by;
+ $one_menu->order_by = $second_menu->order_by;
+ $second_menu->order_by = $temp_position;
+ $one_menu->save();
+ $second_menu->save();
+ message::success(t("Menu %menu_title moved up", array("menu_title" => $one_menu->title)));
+ log::success("custom_menus", t("Menu %menu_title moved up", array("menu_title" => $one_menu->title)));
+ }
+ }
+ url::redirect("admin/custom_menus");
+ }
+
+ public function move_menu_down($id) {
+ // Move the specified menu item down one position.
+ $one_menu = ORM::factory("custom_menu", $id);
+ if ($one_menu->loaded()) {
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $one_menu->parent_id)
+ ->where("order_by", ">", $one_menu->order_by)
+ ->order_by("order_by", "ASC")
+ ->find_all(1);
+ if (count($existing_menu) > 0) {
+ $second_menu = ORM::factory("custom_menu", $existing_menu[0]->id);
+ $temp_position = $one_menu->order_by;
+ $one_menu->order_by = $second_menu->order_by;
+ $second_menu->order_by = $temp_position;
+ $one_menu->save();
+ $second_menu->save();
+ message::success(t("Menu %menu_title moved down", array("menu_title" => $one_menu->title)));
+ log::success("custom_menus", t("Menu %menu_title moved down", array("menu_title" => $one_menu->title)));
+ }
+ }
+ url::redirect("admin/custom_menus");
+ }
+}
diff --git a/3.1/modules/custom_menus/helpers/custom_menus_event.php b/3.1/modules/custom_menus/helpers/custom_menus_event.php
new file mode 100644
index 00000000..a26ae3d8
--- /dev/null
+++ b/3.1/modules/custom_menus/helpers/custom_menus_event.php
@@ -0,0 +1,75 @@
+get("content_menu")
+ ->append(Menu::factory("link")
+ ->id("custom_menus")
+ ->label(t("Custom Menus Manager"))
+ ->url(url::site("admin/custom_menus")));
+ }
+
+ static function site_menu($menu, $theme) {
+ // Add user definied menu and sub-menu items to the site menu.
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", "0")
+ ->order_by("order_by", "DESC")
+ ->find_all();
+ if (count($existing_menu) > 0) {
+ foreach ($existing_menu as $one_menu) {
+ if ($one_menu->url == "") {
+ $menu->add_after("home", $new_menu = Menu::factory("submenu")
+ ->id("custom_menus-" . $one_menu->id)
+ ->label($one_menu->title));
+ custom_menus_event::add_sub_menus($one_menu->id, $new_menu);
+ } else {
+ $menu->add_after("home", Menu::factory("link")
+ ->id("custom_menus-" . $one_menu->id)
+ ->label($one_menu->title)
+ ->url($one_menu->url));
+ }
+ }
+ }
+ }
+
+ function add_sub_menus($parent_id, $parent_menu) {
+ // Populate the menu bar with any sub-menu items on the current menu ($parent_menu).
+ $existing_menu = ORM::factory("custom_menu")
+ ->where("parent_id", "=", $parent_id)
+ ->order_by("order_by", "ASC")
+ ->find_all();
+ if (count($existing_menu) > 0) {
+ foreach ($existing_menu as $one_menu) {
+ if ($one_menu->url == "") {
+ $parent_menu->append($new_menu = Menu::factory("submenu")
+ ->id("custom_menus-" . $one_menu->id)
+ ->label($one_menu->title));
+ custom_menus_event::add_sub_menus($one_menu->id, $new_menu);
+ } else {
+ $parent_menu->append(Menu::factory("link")
+ ->id("custom_menus-" . $one_menu->id)
+ ->label($one_menu->title)
+ ->url($one_menu->url));
+ }
+ }
+ }
+ }
+}
diff --git a/3.1/modules/custom_menus/helpers/custom_menus_installer.php b/3.1/modules/custom_menus/helpers/custom_menus_installer.php
new file mode 100644
index 00000000..39021efb
--- /dev/null
+++ b/3.1/modules/custom_menus/helpers/custom_menus_installer.php
@@ -0,0 +1,37 @@
+query("CREATE TABLE IF NOT EXISTS {custom_menus} (
+ `id` int(9) NOT NULL auto_increment,
+ `title` varchar(255) default NULL,
+ `url` text default NULL,
+ `parent_id` int(9) NOT NULL default 0,
+ `order_by` int(9) NOT NULL default 0,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY(`id`))
+ DEFAULT CHARSET=utf8;");
+
+ // Set the module version number.
+ module::set_version("custom_menus", 1);
+ }
+}
diff --git a/3.1/modules/custom_menus/models/custom_menu.php b/3.1/modules/custom_menus/models/custom_menu.php
new file mode 100644
index 00000000..475ad99b
--- /dev/null
+++ b/3.1/modules/custom_menus/models/custom_menu.php
@@ -0,0 +1,21 @@
+
+
+
= t("Manage menus") ?>
+
+