<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Url {

    public static function urlamigavel($nome) {

        $subs = array(
            'ar_token' => array(' ', 'á', 'à', 'ã', 'â', 'é', 'ê', 'í', 'ó', 'ô', 'õ', 'ú', 'ü', 'ç', 'Á', 'À', 'Ã', 'Â', 'É', 'Ê', 'Í', 'Ó', 'Ô', 'Õ', 'Ú', 'Ü', 'Ç'),
            'ar_token_replace' => array('+', 'a', 'a', 'a', 'a', 'e', 'e', 'i', 'o', 'o', 'o', 'u', 'u', 'c', 'A', 'A', 'A', 'A', 'E', 'E', 'I', 'O', 'O', 'O', 'U', 'U', 'C')
        );

        return str_replace($subs['ar_token'], $subs['ar_token_replace'], $nome);
    }

    public function get_client_ip_server() {
        $ipaddress = '';
        if (getenv('HTTP_CLIENT_IP'))
            $ipaddress = getenv('HTTP_CLIENT_IP');
        else if (getenv('HTTP_X_FORWARDED_FOR'))
            $ipaddress = getenv('HTTP_X_FORWARDED_FOR');
        else if (getenv('HTTP_X_FORWARDED'))
            $ipaddress = getenv('HTTP_X_FORWARDED');
        else if (getenv('HTTP_FORWARDED_FOR'))
            $ipaddress = getenv('HTTP_FORWARDED_FOR');
        else if (getenv('HTTP_FORWARDED'))
            $ipaddress = getenv('HTTP_FORWARDED');
        else if (getenv('REMOTE_ADDR'))
            $ipaddress = getenv('REMOTE_ADDR');
        else
            $ipaddress = 'UNKNOWN';

        return $ipaddress;
    }

    public function getBrowser() {

        $useragent = $_SERVER['HTTP_USER_AGENT'];

        if (strpos($useragent, "MSIE") !== false && strpos($useragent, "Opera") === false && strpos($useragent, "Netscape") === false) {
            $found = preg_match("/MSIE ([0-9]{1}\.[0-9]{1,2})/", $useragent, $mathes);
            if ($found) {
                return "Internet Explorer " . $mathes[1];
            }
        } elseif (strpos($useragent, "Gecko")) {
            $found = preg_match("/Firefox\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $mathes);
            if ($found) {
                return "Mozilla Firefox " . $mathes[1];
            }

            $found = preg_match("/Netscape\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $mathes);
            if ($found) {
                return "Netscape " . $mathes[1];
            }

            $found = preg_match("/Chrome\/([^\s]+)/", $useragent, $mathes);
            if ($found) {
                return "Google Chrome " . $mathes[1];
            }

            $found = preg_match("/Safari\/([0-9]{2,3}(\.[0-9])?)/", $useragent, $mathes);
            if ($found) {
                return "Safari " . $mathes[1];
            }

            $found = preg_match("/Galeon\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $mathes);
            if ($found) {
                return "Galeon " . $mathes[1];
            }

            $found = preg_match("/Konqueror\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $mathes);
            if ($found) {
                return "Konqueror " . $mathes[1];
            }

            return "Gecko based";
        } elseif (strpos($useragent, "Opera") !== false) {
            $found = preg_match("/Opera[\/ ]([0-9]{1}\.[0-9]{1}([0-9])?)/", $useragent, $mathes);
            if ($found) {
                return "Opera " . $mathes[1];
            }
        } elseif (strpos($useragent, "Lynx") !== false) {
            $found = preg_match("/Lynx\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $mathes);
            if ($found) {
                return "Lynx " . $mathes[1];
            }
        } elseif (strpos($useragent, "Netscape") !== false) {
            $found = preg_match("/Netscape\/([0-9]{1}\.[0-9]{1}(\.[0-9])?)/", $useragent, $mathes);
            if ($found) {
                return "Netscape " . $mathes[1];
            }
        } else {
            return false;
        }
    }

}
