diff --git a/core/page.php b/core/page.php index e779290a..7efa2833 100644 --- a/core/page.php +++ b/core/page.php @@ -299,9 +299,55 @@ class Page $this->add_cookie("flash_message", "", -1, "/"); } usort($this->blocks, "blockcmp"); + $pnbe = new PageNavBuildingEvent(); + send_event($pnbe); + + $nav_links = $pnbe->links; + + $active_link = null; + // To save on event calls, we check if one of the top-level links has already been marked as active + foreach ($nav_links as $link) { + if($link->active===true) { + $active_link = $link; + break; + } + } + $sub_links = null; + // If one is, we just query for sub-menu options under that one tab + if($active_link!==null) { + $psnbe = new PageSubNavBuildingEvent($active_link->name); + send_event($psnbe); + $sub_links = $psnbe->links; + } else { + // Otherwise we query for the sub-items under each of the tabs + foreach ($nav_links as $link) { + $psnbe = new PageSubNavBuildingEvent($link->name); + send_event($psnbe); + + // Now we check for a current link so we can identify the sub-links to show + foreach ($psnbe->links as $sub_link) { + if($sub_link->active===true) { + $sub_links = $psnbe->links; + break; + } + } + // If the active link has been detected, we break out + if($sub_links!==null) { + $link->active = true; + break; + } + } + } + + + + $sub_links = $sub_links??[]; + usort($nav_links, "sort_nav_links"); + usort($sub_links, "sort_nav_links"); + $this->add_auto_html_headers(); $layout = new Layout(); - $layout->display_page($page); + $layout->display_page($page, $nav_links, $sub_links); break; case PageMode::DATA: header("Content-Length: " . strlen($this->data)); @@ -471,3 +517,99 @@ class Page $this->add_html_header("", 44); } } + +class PageNavBuildingEvent extends Event +{ + public $links = []; + + public function add_nav_link(string $name, Link $link, string $desc, ?bool $active = null, int $order = 50) + { + $this->links[] = new NavLink($name, $link, $desc, $active, $order); + } +} + +class PageSubNavBuildingEvent extends Event +{ + public $parent; + + public $links = []; + + public function __construct(string $parent) + { + $this->parent= $parent; + } + + public function add_nav_link(string $name, Link $link, string $desc, ?bool $active = null, int $order = 50) + { + $this->links[] = new NavLink($name, $link, $desc, $active,$order); + } +} + +class NavLink +{ + public $name; + public $link; + public $description; + public $order; + public $active = false; + + public function __construct(String $name, Link $link, String $description, ?bool $active = null, int $order = 50) + { + global $config; + + $this->name = $name; + $this->link = $link; + $this->description = $description; + $this->order = $order; + if($active==null) { + $query = ltrim(_get_query(), "/"); + if ($query === "") { + // This indicates the front page, so we check what's set as the front page + $front_page = trim($config->get_string(SetupConfig::FRONT_PAGE), "/"); + + if ($front_page === $link->page) { + $this->active = true; + } else { + $this->active = self::is_active([$link->page], $front_page); + } + } elseif($query===$link->page) { + $this->active = true; + }else { + $this->active = self::is_active([$link->page]); + } + } else { + $this->active = $active; + } + + } + + public static function is_active(array $pages_matched, string $url = null): bool + { + /** + * Woo! We can actually SEE THE CURRENT PAGE!! (well... see it highlighted in the menu.) + */ + $url = $url??ltrim(_get_query(), "/"); + + $re1='.*?'; + $re2='((?:[a-z][a-z_]+))'; + + if (preg_match_all("/".$re1.$re2."/is", $url, $matches)) { + $url=$matches[1][0]; + } + + $count_pages_matched = count($pages_matched); + + for ($i=0; $i < $count_pages_matched; $i++) { + if ($url == $pages_matched[$i]) { + return true; + } + } + + return false; + } +} + +function sort_nav_links(NavLink $a, NavLink $b) +{ + return $a->order - $b->order; +} diff --git a/core/sys_config.php b/core/sys_config.php index 9ce0d8d0..9eac5f59 100644 --- a/core/sys_config.php +++ b/core/sys_config.php @@ -40,7 +40,7 @@ _d("SEARCH_ACCEL", false); // boolean use search accelerator _d("WH_SPLITS", 1); // int how many levels of subfolders to put in the warehouse _d("VERSION", '2.7-beta'); // string shimmie version _d("TIMEZONE", null); // string timezone -_d("CORE_EXTS", "bbcode,user,mail,upload,image,view,handle_pixel,ext_manager,setup,upgrade,handle_404,handle_static,comment,tag_list,index,tag_edit,alias_editor,media"); // extensions to always enable +_d("CORE_EXTS", "bbcode,user,mail,upload,image,view,handle_pixel,ext_manager,setup,upgrade,handle_404,handle_static,comment,tag_list,index,tag_edit,alias_editor,media,system"); // extensions to always enable _d("EXTRA_EXTS", ""); // string optional extra extensions _d("BASE_URL", null); // string force a specific base URL (default is auto-detect) _d("MIN_PHP_VERSION", '7.1');// string minimum supported PHP version diff --git a/core/urls.php b/core/urls.php index 3bdc9c71..457bfe1b 100644 --- a/core/urls.php +++ b/core/urls.php @@ -3,6 +3,23 @@ * HTML Generation * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +class Link +{ + public $page; + public $query; + + public function __construct(?string $page=null, ?string $query=null) + { + $this->page = $page; + $this->query = $query; + } + + public function make_link(): string + { + return make_link($this->page, $this->query); + } +} + /** * Figure out the correct way to link to a page, taking into account * things like the nice URLs setting. diff --git a/ext/admin/main.php b/ext/admin/main.php index eef919d7..423460c8 100644 --- a/ext/admin/main.php +++ b/ext/admin/main.php @@ -108,6 +108,16 @@ class AdminPage extends Extension $this->theme->display_form(); } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::MANAGE_ADMINTOOLS)) { + $event->add_nav_link("admin", new Link('admin'), "Board Admin"); + } + } + } + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/alias_editor/main.php b/ext/alias_editor/main.php index 4321c78a..36edbfbb 100644 --- a/ext/alias_editor/main.php +++ b/ext/alias_editor/main.php @@ -117,6 +117,13 @@ class AliasEditor extends Extension } } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="tags") { + $event->add_nav_link("aliases", new Link('alias/list'), "Aliases", NavLink::is_active(["alias"])); + } + } + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/blocks/main.php b/ext/blocks/main.php index b444b03a..197b5d9f 100644 --- a/ext/blocks/main.php +++ b/ext/blocks/main.php @@ -26,6 +26,16 @@ class Blocks extends Extension } } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::MANAGE_BLOCKS)) { + $event->add_nav_link("blocks", new Link('blocks/list'), "Blocks Editor"); + } + } + } + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/blotter/main.php b/ext/blotter/main.php index cb88490b..3e18b1a9 100644 --- a/ext/blotter/main.php +++ b/ext/blotter/main.php @@ -56,6 +56,17 @@ class Blotter extends Extension $event->panel->add_block($sb); } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->is_admin()) { + $event->add_nav_link("blotter", new Link('blotter/editor'), "Blotter Editor"); + } + } + } + + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/comment/main.php b/ext/comment/main.php index 2540ef4a..7ea23d37 100644 --- a/ext/comment/main.php +++ b/ext/comment/main.php @@ -157,6 +157,21 @@ class CommentList extends Extension } } + + public function onPageNavBuilding(PageNavBuildingEvent $event) + { + $event->add_nav_link("comment", new Link('comment/list'), "Comments"); + } + + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="comment") { + $event->add_nav_link("comment_list", new Link('comment/list'), "All"); + $event->add_nav_link("comment_help", new Link('ext_doc/comment'), "Help"); + } + } + public function onPageRequest(PageRequestEvent $event) { if ($event->page_matches("comment")) { diff --git a/ext/et/main.php b/ext/et/main.php index f342a39f..576765dd 100644 --- a/ext/et/main.php +++ b/ext/et/main.php @@ -24,6 +24,18 @@ class ET extends Extension } } + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::VIEW_SYSINTO)) { + $event->add_nav_link("system_info", new Link('system_info'), "System Info", null, 10); + } + } + } + + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/ext_manager/main.php b/ext/ext_manager/main.php index e024f286..39c7f572 100644 --- a/ext/ext_manager/main.php +++ b/ext/ext_manager/main.php @@ -162,6 +162,17 @@ class ExtManager extends Extension } } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::MANAGE_EXTENSION_LIST)) { + $event->add_nav_link("ext_manager", new Link('ext_manager'), "Extension Manager"); + } else { + $event->add_nav_link("ext_doc", new Link('ext_doc'), "Board Help"); + } + } + } public function onUserBlockBuilding(UserBlockBuildingEvent $event) { diff --git a/ext/favorites/main.php b/ext/favorites/main.php index e8b7f6fe..91ac1c2d 100644 --- a/ext/favorites/main.php +++ b/ext/favorites/main.php @@ -155,6 +155,20 @@ class Favorites extends Extension } } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent=="posts") { + $event->add_nav_link("posts_favorites", new Link("post/list/favorited_by={$user->name}/1"), "My Favorites"); + } + + if($event->parent==="user") { + if ($user->can(Permissions::MANAGE_ADMINTOOLS)) { + $username = url_escape($user->name); + $event->add_nav_link("favorites", new Link("post/list/favorited_by=$username/1"), "My Favorites"); + } + } + } private function install() { diff --git a/ext/image_hash_ban/main.php b/ext/image_hash_ban/main.php index 67298a89..cc3a7ca1 100644 --- a/ext/image_hash_ban/main.php +++ b/ext/image_hash_ban/main.php @@ -103,6 +103,17 @@ class ImageBan extends Extension } } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::BAN_IMAGE)) { + $event->add_nav_link("image_bans", new Link('image_hash_ban/list/1'), "Image Bans", NavLink::is_active(["image_hash_ban"])); + } + } + } + + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/index/main.php b/ext/index/main.php index eab9d7b3..80c4b610 100644 --- a/ext/index/main.php +++ b/ext/index/main.php @@ -332,6 +332,18 @@ class Index extends Extension } } + public function onPageNavBuilding(PageNavBuildingEvent $event) + { + $event->add_nav_link("posts", new Link('post/list'), "Posts", NavLink::is_active(["post","view"]),20); + } + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="posts") { + $event->add_nav_link("posts_all", new Link('post/list'), "All"); + } + } + public function onSearchTermParse(SearchTermParseEvent $event) { $matches = []; diff --git a/ext/ipban/main.php b/ext/ipban/main.php index bfefb813..90eb198a 100644 --- a/ext/ipban/main.php +++ b/ext/ipban/main.php @@ -105,6 +105,16 @@ class IPBan extends Extension $event->panel->add_block($sb); } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::BAN_IP)) { + $event->add_nav_link("ip_bans", new Link('ip_ban/list'), "IP Bans", NavLink::is_active(["ip_ban"])); + } + } + } + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/log_db/main.php b/ext/log_db/main.php index a5dd1d7f..4002b68c 100644 --- a/ext/log_db/main.php +++ b/ext/log_db/main.php @@ -120,6 +120,16 @@ class LogDatabase extends Extension } } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::VIEW_EVENTLOG)) { + $event->add_nav_link("event_log", new Link('log/view'), "Event Log"); + } + } + } + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/not_a_tag/main.php b/ext/not_a_tag/main.php index 29f31e75..369ab0ff 100644 --- a/ext/not_a_tag/main.php +++ b/ext/not_a_tag/main.php @@ -58,6 +58,16 @@ class NotATag extends Extension } } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="tags") { + if ($user->can(Permissions::BAN_IMAGE)) { + $event->add_nav_link("untags", new Link('untag/list/1'), "UnTags"); + } + } + } + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/numeric_score/main.php b/ext/numeric_score/main.php index 446c5553..84179f7c 100644 --- a/ext/numeric_score/main.php +++ b/ext/numeric_score/main.php @@ -294,6 +294,16 @@ class NumericScore extends Extension } } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="posts") { + $event->add_nav_link("numeric_score_day", new Link('popular_by_day'), "Popular by Day"); + $event->add_nav_link("numeric_score_month", new Link('popular_by_month'), "Popular by Month"); + $event->add_nav_link("numeric_score_year", new Link('popular_by_year'), "Popular by Year"); + + } + } + private function install() { global $database; diff --git a/ext/pm/main.php b/ext/pm/main.php index d4ef16da..d2c7f44d 100644 --- a/ext/pm/main.php +++ b/ext/pm/main.php @@ -93,6 +93,19 @@ class PrivMsg extends Extension } } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="user") { + if (!$user->is_anonymous()) { + $count = $this->count_pms($user); + $h_count = $count > 0 ? " ($count)" : ""; + $event->add_nav_link("pm", new Link('user#private-messages'), "Private Messages$h_count"); + } + } + } + + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/pools/main.php b/ext/pools/main.php index 37a1cc01..cbdf5164 100644 --- a/ext/pools/main.php +++ b/ext/pools/main.php @@ -145,6 +145,23 @@ class Pools extends Extension $event->panel->add_block($sb); } + public function onPageNavBuilding(PageNavBuildingEvent $event) + { + $event->add_nav_link("pool", new Link('pool/list'), "Pools"); + } + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="pool") { + $event->add_nav_link("pool_list", new Link('pool/list'), "List"); + $event->add_nav_link("pool_new", new Link('pool/new'), "Create"); + $event->add_nav_link("pool_updated", new Link('pool/updated'), "Changes"); + $event->add_nav_link("pool_help", new Link('ext_doc/pools'), "Help"); + } + } + + + public function onPageRequest(PageRequestEvent $event) { global $page, $user, $database; diff --git a/ext/random_image/main.php b/ext/random_image/main.php index fc0424f7..b03d21e4 100644 --- a/ext/random_image/main.php +++ b/ext/random_image/main.php @@ -75,4 +75,11 @@ class RandomImage extends Extension } } } + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="posts") { + $event->add_nav_link("posts_random", new Link('random_image/view'), "Random Image"); + } + } } diff --git a/ext/random_list/main.php b/ext/random_list/main.php index 7333905d..47c55b9c 100644 --- a/ext/random_list/main.php +++ b/ext/random_list/main.php @@ -74,4 +74,11 @@ class RandomList extends Extension $event->panel->add_block($sb); } + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="posts") { + $event->add_nav_link("posts_random", new Link('random'), "Shuffle"); + } + } } diff --git a/ext/report_image/main.php b/ext/report_image/main.php index 970d9466..d5436e6b 100644 --- a/ext/report_image/main.php +++ b/ext/report_image/main.php @@ -132,6 +132,20 @@ class ReportImage extends Extension } } + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::VIEW_IMAGE_REPORT)) { + $count = $this->count_reported_images(); + $h_count = $count > 0 ? " ($count)" : ""; + + $event->add_nav_link("image_report", new Link('image_report/list'), "Reported Images$h_count"); + } + } + } + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/rss_comments/main.php b/ext/rss_comments/main.php index f882ca40..f64869e1 100644 --- a/ext/rss_comments/main.php +++ b/ext/rss_comments/main.php @@ -79,4 +79,12 @@ EOD; $page->set_data($xml); } } + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="comment") { + $event->add_nav_link("comment_rss", new Link('rss/comments'), "Feed"); + } + } + } diff --git a/ext/rss_images/main.php b/ext/rss_images/main.php index 516c470f..6e5f9026 100644 --- a/ext/rss_images/main.php +++ b/ext/rss_images/main.php @@ -116,4 +116,11 @@ class RSS_Images extends Extension return $data; } + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="posts") { + $event->add_nav_link("posts_rss", new Link('rss/images'), "Feed"); + } + } } diff --git a/ext/setup/main.php b/ext/setup/main.php index 6259f259..b7bf6181 100644 --- a/ext/setup/main.php +++ b/ext/setup/main.php @@ -411,6 +411,16 @@ class Setup extends Extension log_warning("setup", "Cache cleared"); } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::CHANGE_SETTING)) { + $event->add_nav_link("setup", new Link('setup'), "Board Config", null, 0); + } + } + } + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/source_history/main.php b/ext/source_history/main.php index ac5f7ae7..3fd47cab 100644 --- a/ext/source_history/main.php +++ b/ext/source_history/main.php @@ -82,6 +82,16 @@ class Source_History extends Extension $this->add_source_history($event->image, $event->source); } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::BULK_EDIT_IMAGE_TAG)) { + $event->add_nav_link("source_history", new Link('source_history/all/1'), "Source Changes", NavLink::is_active(["source_history"])); + } + } + } + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/system/main.php b/ext/system/main.php new file mode 100644 index 00000000..2cce82c1 --- /dev/null +++ b/ext/system/main.php @@ -0,0 +1,31 @@ + + * License: MIT + * Description: Provides system screen + */ + +class System extends Extension +{ + public function onPageRequest(PageRequestEvent $event) + { + global $page, $user; + + if ($event->page_matches("system")) { + $e = new PageSubNavBuildingEvent("system"); + send_event($e); + usort($e->links, "sort_nav_links"); + $link = $e->links[0]->link; + + $page->set_redirect($link->make_link()); + $page->set_mode(PageMode::REDIRECT); + } + } + public function onPageNavBuilding(PageNavBuildingEvent $event) + { + $event->add_nav_link("system", new Link('system'), "System"); + } + + +} diff --git a/ext/tag_edit/main.php b/ext/tag_edit/main.php index 7d20b7d0..df6d8b43 100644 --- a/ext/tag_edit/main.php +++ b/ext/tag_edit/main.php @@ -255,6 +255,15 @@ class TagEdit extends Extension $this->theme->display_mass_editor(); } + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="tags") { + $event->add_nav_link("tags_help", new Link('ext_doc/tag_edit'), "Help"); + } + } + + /** * When an alias is added, oldtag becomes inaccessible. */ diff --git a/ext/tag_history/main.php b/ext/tag_history/main.php index 6e241c3e..b317abd3 100644 --- a/ext/tag_history/main.php +++ b/ext/tag_history/main.php @@ -82,6 +82,17 @@ class Tag_History extends Extension $this->add_tag_history($event->image, $event->tags); } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::BULK_EDIT_IMAGE_TAG)) { + $event->add_nav_link("tag_history", new Link('tag_history/all/1'), "Tag Changes", NavLink::is_active(["tag_history"])); + } + } + } + + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/tag_list/main.php b/ext/tag_list/main.php index ec2a4032..9d0e8a53 100644 --- a/ext/tag_list/main.php +++ b/ext/tag_list/main.php @@ -93,6 +93,21 @@ class TagList extends Extension } } + public function onPageNavBuilding(PageNavBuildingEvent $event) + { + $event->add_nav_link("tags", new Link('tags/map'), "Tags"); + } + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="tags") { + $event->add_nav_link("tags_map", new Link('tags/map'), "Map"); + $event->add_nav_link("tags_alphabetic", new Link('tags/alphabetic'), "Alphabetic"); + $event->add_nav_link("tags_popularity", new Link('tags/popularity'), "Popularity"); + $event->add_nav_link("tags_categories", new Link('tags/categories'), "Categories"); + } + } + public function onDisplayingImage(DisplayingImageEvent $event) { global $config, $page; diff --git a/ext/tips/main.php b/ext/tips/main.php index 7e5610a6..60564028 100644 --- a/ext/tips/main.php +++ b/ext/tips/main.php @@ -73,6 +73,16 @@ class Tips extends Extension } } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->is_admin()) { + $event->add_nav_link("tips", new Link('tips/list'), "Tips Editor"); + } + } + } + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/upload/main.php b/ext/upload/main.php index ed13c96b..8c9d313f 100644 --- a/ext/upload/main.php +++ b/ext/upload/main.php @@ -138,6 +138,21 @@ class Upload extends Extension $event->panel->add_block($sb); } + + public function onPageNavBuilding(PageNavBuildingEvent $event) + { + $event->add_nav_link("upload",new Link('upload'), "Upload"); + } + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="upload") { + if (class_exists("Wiki")) { + $event->add_nav_link("upload_guidelines", new Link('wiki/upload_guidelines'), "Guidelines"); + } + } + } + public function onDataUpload(DataUploadEvent $event) { global $config; diff --git a/ext/user/main.php b/ext/user/main.php index f7d202af..65280272 100644 --- a/ext/user/main.php +++ b/ext/user/main.php @@ -237,6 +237,17 @@ class UserPage extends Extension } } + public function onPageNavBuilding(PageNavBuildingEvent $event) + { + global $user; + if ($user->is_anonymous()) { + $event->add_nav_link("user", new Link('user_admin/login'), "Account", null, 10); + } else { + $event->add_nav_link("user", new Link('user'), "Account", null, 10); + } + } + + private function display_stats(UserPageBuildingEvent $event) { global $user, $page, $config; @@ -305,6 +316,16 @@ class UserPage extends Extension $event->panel->add_block($sb); } + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + global $user; + if($event->parent==="system") { + if ($user->can(Permissions::EDIT_USER_CLASS)) { + $event->add_nav_link("user_admin", new Link('user_admin/list'), "User List", NavLink::is_active(["user_admin"])); + } + } + } + public function onUserBlockBuilding(UserBlockBuildingEvent $event) { global $user; diff --git a/ext/wiki/main.php b/ext/wiki/main.php index 65d29ae0..2bb04b0a 100644 --- a/ext/wiki/main.php +++ b/ext/wiki/main.php @@ -176,6 +176,21 @@ class Wiki extends Extension } } + + public function onPageNavBuilding(PageNavBuildingEvent $event) + { + $event->add_nav_link("wiki",new Link('wiki'), "Wiki"); + } + + + public function onPageSubNavBuilding(PageSubNavBuildingEvent $event) + { + if($event->parent=="wiki") { + $event->add_nav_link("wiki_rules", new Link('wiki/rules'), "Rules"); + $event->add_nav_link("wiki_help", new Link('ext_doc/wiki'), "Help"); + } + } + public function onWikiUpdate(WikiUpdateEvent $event) { global $database; diff --git a/themes/danbooru/layout.class.php b/themes/danbooru/layout.class.php index 42efe2a1..6be406a4 100644 --- a/themes/danbooru/layout.class.php +++ b/themes/danbooru/layout.class.php @@ -44,7 +44,7 @@ Tips class Layout { - public function display_page(Page $page) + public function display_page(Page $page, array $nav_links, array $sub_links) { global $config, $user; @@ -96,84 +96,17 @@ class Layout $main_page = $config->get_string(SetupConfig::MAIN_PAGE); // bzchan: change from normal default to get main page for top of page $custom_links = ""; - if ($user->is_anonymous()) { - $custom_links .= $this->navlinks(make_link('user_admin/login'), "My Account", ["user", "user_admin", "setup", "admin"]); - } else { - $custom_links .= $this->navlinks(make_link('user'), "My Account", ["user", "user_admin", "setup", "admin"]); - } - $custom_links .= $this->navlinks(make_link('post/list'), "Posts", ["post"]); - $custom_links .= $this->navlinks(make_link('comment/list'), "Comments", ["comment"]); - $custom_links .= $this->navlinks(make_link('tags'), "Tags", ["tags"]); - if (class_exists("Pools")) { - $custom_links .= $this->navlinks(make_link('pool/list'), "Pools", ["pool"]); - } - $custom_links .= $this->navlinks(make_link('upload'), "Upload", ["upload"]); - if (class_exists("Wiki")) { - $custom_links .= $this->navlinks(make_link('wiki'), "Wiki", ["wiki"]); - $custom_links .= $this->navlinks(make_link('wiki/more'), "More »", ["wiki/more"]); + foreach ($nav_links as $nav_link) { + $custom_links .= "