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_languageHandler.php
<?php

/**
* Spire
*
* Created By: Komma Mediadesign
* Author: Mike van der Sanden
* January 2013
*
*/


class LanguageHandler
{
    /*
     * @property array options
     * Languages used in this website.
     * What files match with what languages
     */
    private $_options = array();

    /*
     * @property string lang
     * Current language.
     */
    private $_lang = '';
    
    public function __construct()
    {
        // set options
        $this->_options = array('en'=> DOCUMENT_ROOT.'lang/en.php',
                                'nl'=> DOCUMENT_ROOT.'lang/nl.php'
                                );
    }

    /*
     * Get current Language
     * 1. Include Language Class
     * 2. Get the array
     * 3. Return to the user
     */
    public function get(){
        $lang = $this->_lang;
        if(isset($this->_options[$lang]))
        {
            include $this->_options[$lang];

            $Language = new Language();
            return $Language->get();
        }
        return FALSE;
    }

    /*
     * Set language string
     */
    public function set($lang)
    {
        $lang = strtolower($lang);
        if( array_key_exists($lang, $this->_options))
        {
            $this->_lang = $lang;
        }
    }

    /*
     * Display the menu
     */
    public function displayMenu()
    {
        $output = '';

        /* Define link to go */
        $subject = 'http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
        $search = $_SERVER['HTTP_HOST'].'/kms/'.URL_LANG.'/';

        foreach(array_keys($this->_options) as $country)
        {
            $replace = $_SERVER['HTTP_HOST'].'/kms/'.$country.'/';
            $url = str_replace($search, $replace, $subject);

            $output .= ' <a href="'.$url.'" class="flag '.$country;
            if($country == URL_LANG)
            {
                $output .= ' active';
            }
            $output .= '"></a>';
        }
        return $output;
    }
}