All pastes #554462 Raw Edit

Menu Manager Plugin

public php v1 · immutable
·published 2007-06-10 04:35 UTC
rendered paste body
<?phpclass MenuManager extends Plugin {	public function info() {		return array(			'name' => 'Menu Manager',			'version' => '0.5',			'url' => 'http://www.andrewdasilva.com/',			'author' =>	'Andrew da Silva',			'authorurl' => 'http://www.andrewdasilva.com/',			'license' => 'Apache License 2.0',			'desccription' => 'Adds a template variable containing the menu tabs.',			'copyright' => '2007'		);	}			public function action_add_template_vars( $handler_vars )	{		$menu= array();				/* Add your custom tabs here */		$menu[]= new MenuTab( 'Habari Project', 'http://habariproject.org/', array( 'priority' => 0 ) );				if ( isset( $handler_vars->template_engine->user ) ) {			$menu[]= new MenuTab( 'Admin', Site::get_url( 'admin' ), array( 'class' => 'admintab', 'priority' => 666 ) );		}				foreach ( $handler_vars->template_engine->pages as $page ) {			$menu[]= new MenuTab( $page->title_out, $page->permalink );		}				$menu= Plugins::filter( 'menu_tabs', $menu );				usort( $menu, array("self", "compare_priority") );		$html= new DOMDocument();		$html_ul= $html->createElement('ul');		$html_ul->setAttribute('class', 'menu');		$html->appendChild($html_ul);				foreach ( $menu as $tab ) {			$menu_tab= $html->createElement('li');			if ( isset( $tab->class ) ) {				$menu_tab->setAttribute('class', $tab->class);			}			$html_ul->appendChild($menu_tab);			$menu_tab_link= $html->createElement('a', $tab->title);			$menu_tab_link->setAttribute('href', $tab->url);			$menu_tab_link->setAttribute('alt', $tab->title);			$menu_tab->appendChild($menu_tab_link);		}				$handler_vars->template_engine->menu= $html->saveHTML();	}		public function compare_priority( $a, $b )	{		if ( $a->priority == $b->priority ) {			return 0;		}		return ( $a->priority < $b->priority ) ? -1 : 1;	}}class MenuTab {	public function __construct( $title, $url, $params = array() ) {		$this->title= $title;		$this->url= $url;		foreach ( $params as $key => $value ) {			if ( strlen( trim( $value ) ) > 0 ) {				$this->$key= $value;			}		}			}	}?>