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/mvc/models/m_navigation.php
<?php

/**
 * Easier and cleaner way to create menu list items
 */
class Navigation extends SiteTemplate
{
	private $_lines;

	public function __construct()
	{
		$this->_lines = array();
	}

    /**
     * Adds data to the $_lines array. ( Adds a new line to the menu )
     * If you want your home-button to go the the SITE_ROOT, enter "_root" as linkName
     * You can set $siteRoot to FALSE if you want to link to a different website.
     *
     * @access public
     * @param string $label
     * @param string $linkName
     * @param bool $siteRoot
     * @return null
     */
	public function addLine($label, $linkName=NULL, $siteRoot = TRUE)
	{
		if( ! empty($label))
		{
			if( empty($linkName))
			{
                $linkName = $this->encodeUrl($label);
			}
			if($siteRoot)
			{
				$url = SITE_ROOT.$linkName.'/';
			}
			else {
				$url = $linkName;
			}

            if($linkName == '_root') $url = SITE_ROOT;

			$this->_lines[] = array('url'=>$url,'label'=>$label,'$linkName'=>$linkName);
		}
	}

    /**
     * Creates an array of listItems
     *
     * @access public
     * @param bool $echo
     * @param bool $span
     * @internal param $
     * @return null
     */
	public function display($echo = TRUE, $span=TRUE)
	{
		$output = '';
		foreach($this->_lines as $key => $line)
		{
            $output .= '<li';

            // Active ?
            $classes = array();

            if((defined('URL_PAGE') && URL_PAGE == $line['$linkName']) || (!defined('URL_PAGE') && $line['$linkName'] == '_root'))
            {
                $classes[] = 'active';
            }

            // SPIRE EXTENSION (products)
            if(defined('URL_PAGE') && $line['$linkName'] == 'products')
            {
                switch(URL_PAGE)
                {
                    case 'pc-accessories':
                    case 'computer-cases':
                    case 'cpu-coolers':
                    case 'gaming':
                    case 'fans':
                    case 'mobile-accessories':
                    case 'power-supplies':
                    case 'system-cooling':
                    case 'products':
                    case 'tablet-pc':
                    case 'results':
                        $classes[] = 'active';
                }
            }

            // SPIRE EXTENSION (media)
            $temp = explode('/',$line['$linkName']);
            if(in_array('media',$temp) && defined('URL_PAGE'))
            {
                if(URL_PAGE == 'media')
                {
                    $classes[] = 'active';
                }
            }
            // SPIRE EXTENSION (support)
            $temp = explode('/',$line['$linkName']);
            if(in_array('support',$temp) && defined('URL_PAGE'))
            {
                if(URL_PAGE == 'support')
                {
                    $classes[] = 'active';
                }
            }

            // First?
            if($key == 0)
            {
                $classes[] = 'first';
            }

            // Last ?
			if($key == count($this->_lines)-1)
            {
                $classes[] = 'last';
            }

            if(count($classes)>0)
            {
                $output .= ' class="';
                foreach($classes as $key => $class)
                {
                    if($key != 0) $output .= ' ';
                    $output .= $class;
                }
                $output .= '"';
            }

			$output .= '>';
				$output .= '<a href="'.$line['url'].'" title="'.$line['label'].'">'.$line['label'].'</a>';

            // Extension Spire
            if($span)
            {
                $output .= '<span></span>';
            }
            $output .= '</li>';
		}
		
		if($echo)
		{
			echo $output;
		}
		else 
		{
			return $output;
		}
	}
}