Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make nav helper more friendly and filterable for plugins and themes. #1125

Merged
merged 2 commits into from
May 27, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 41 additions & 24 deletions application/helpers/nav.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ class nav_Core {
* Generate Main Tabs
* @param string $this_page
* @param array $dontshow
* @return string $menu
*/
public static function main_tabs($this_page = FALSE, $dontshow = FALSE)
{
$menu = "";
$menu_items = array();

if( ! is_array($dontshow))
{
// Set $dontshow as an array to prevent errors
Expand All @@ -28,27 +27,33 @@ public static function main_tabs($this_page = FALSE, $dontshow = FALSE)
// Home
if( ! in_array('home',$dontshow))
{
$menu .= "<li><a href=\"".url::site()."main\" ";
$menu .= ($this_page == 'home') ? " class=\"active\"" : "";
$menu .= ">".Kohana::lang('ui_main.home')."</a></li>";
}
$menu_items[] = array(
'page' => 'home',
'url' => url::site('main'),
'name' => Kohana::lang('ui_main.home')
);
}

// Reports List
if( ! in_array('reports',$dontshow))
{
$menu .= "<li><a href=\"".url::site()."reports\" ";
$menu .= ($this_page == 'reports') ? " class=\"active\"" : "";
$menu .= ">".Kohana::lang('ui_main.reports')."</a></li>";
$menu_items[] = array(
'page' => 'reports',
'url' => url::site('reports'),
'name' => Kohana::lang('ui_main.reports')
);
}

// Reports Submit
if( ! in_array('reports_submit',$dontshow))
{
if (Kohana::config('settings.allow_reports'))
{
$menu .= "<li><a href=\"".url::site()."reports/submit\" ";
$menu .= ($this_page == 'reports_submit') ? " class=\"active\"":"";
$menu .= ">".Kohana::lang('ui_main.submit')."</a></li>";
$menu_items[] = array(
'page' => 'reports_submit',
'url' => url::site('reports/submit'),
'name' => Kohana::lang('ui_main.submit')
);
}
}

Expand All @@ -57,9 +62,11 @@ public static function main_tabs($this_page = FALSE, $dontshow = FALSE)
{
if(Kohana::config('settings.allow_alerts'))
{
$menu .= "<li><a href=\"".url::site()."alerts\" ";
$menu .= ($this_page == 'alerts') ? " class=\"active\"" : "";
$menu .= ">".Kohana::lang('ui_main.alerts')."</a></li>";
$menu_items[] = array(
'page' => 'alerts',
'url' => url::site('alerts'),
'name' => Kohana::lang('ui_main.alerts')
);
}
}

Expand All @@ -68,9 +75,11 @@ public static function main_tabs($this_page = FALSE, $dontshow = FALSE)
{
if (Kohana::config('settings.site_contact_page') AND Kohana::config('settings.site_email') != "")
{
$menu .= "<li><a href=\"".url::site()."contact\" ";
$menu .= ($this_page == 'contact') ? " class=\"active\"" : "";
$menu .= ">".Kohana::lang('ui_main.contact')."</a></li>";
$menu_items[] = array(
'page' => 'contact',
'url' => url::site('contact'),
'name' => Kohana::lang('ui_main.contact')
);
}
}

Expand All @@ -83,15 +92,23 @@ public static function main_tabs($this_page = FALSE, $dontshow = FALSE)
{
if( ! in_array('page/'.$page->id,$dontshow))
{
$menu .= "<li><a href=\"".url::site()."page/index/".$page->id."\" ";
$menu .= ($this_page == 'page_'.$page->id) ? " class=\"active\"" : "";
$menu .= ">".$page->page_tab."</a></li>";
$menu_items[] = array(
'page' => 'page_'.$page->id,
'url' => url::site('page/index/'.$page->id),
'name' => $page->page_tab
);
}
}
}

echo $menu;

Event::run('ushahidi_filter.nav_main_tabs', $menu_items);

foreach( $menu_items as $item )
{
$active = ($this_page == $item['page']) ? ' class="active"' : '';
echo '<li><a href="'.$item['url'].'"'.$active.'>'.$item['name'].'</a></li>';
}

// Action::nav_admin_reports - Add items to the admin reports navigation tabs
Event::run('ushahidi_action.nav_main_top', $this_page);
}
Expand Down