HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/spire.komma-mediadesign.nl/wwwroot/kms/app/models/m_menu.php
<?php

/*
	
	Eassier and cleaner way to create menu list items

*/


class Menu
{
	private $_lines;
	private $_template;
	
	public function __construct()
	{
		global $template;
		$this->_template = $template;
		
		$this->_lines = array();
	}
	
	/**
	* Adds data to the $_lines array. ( Adds a new line to the menu )
	*
	* @access public
	* @param string string boolean
	* @return null
	*/
	public function addLine($label, $linkname=NULL, $siteroot = TRUE)
	{
		
		if( ! empty($label))
		{
			if( empty($linkname))
			{
				$linkname = $this->_template->encodeUrl($label);		
			}
			if($siteroot)
			{
				$url = LANG_ROOT.$linkname.'/';
			}
			else {
				$url = $linkname;
			}

            // X2 Links ?
            $x2Links = array('nieuws','awards','homebanners','pcaccessories','pccases','cpucoolers','mobileaccessories','powersupply','systemcooling','tabletpc');
            if(in_array($linkname,$x2Links))
            {
                // Check if we are on X2
                if(defined('URL_SUB') && URL_SUB == 'x2')
                {
                    $url .= '/x2';
                    $url = str_replace('//','/',$url);
                }
            }

			$this->_lines[] = array('url'=>$url,'label'=>$label,'linkname'=>$linkname);
		}
	}
	
	/**
	* Creates an array of listitems
	*
	* @access public
	* @param 
	* @return null
	*/
	public function display($echo = TRUE)
	{
		$output = '';
		
		foreach($this->_lines as $line)
		{
			$output .= '<li';
			if(defined('URL_PAGE') && URL_PAGE == $line['linkname']) $output .= ' class="active"';
			$output .= '>';
				$output .= '<a href="'.$line['url'].'" title="'.$line['label'].'">'.$line['label'].'</a>';
			$output .= '</li>';
		}
		
		if($echo)
		{
			echo $output;
		}
		else 
		{
			return $output;
		}
	}
}