Skip to content

Commit

Permalink
Merge pull request #1125 from solarissmoke/filterable-nav
Browse files Browse the repository at this point in the history
Make nav helper more friendly and filterable for plugins and themes.
  • Loading branch information
rjmackay committed May 27, 2013
2 parents ef8a7b9 + a31783b commit b862e0c
Showing 1 changed file with 41 additions and 24 deletions.
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

0 comments on commit b862e0c

Please sign in to comment.