<?php



/*

 * To change this license header, choose License Headers in Project Properties.

 * To change this template file, choose Tools | Templates

 * and open the template in the editor.

 */



/**

 * Description of Urls

 *

 * @author Puro Ingenio Samario

 */

class Urls {



    public static function saca_dominio_url($url) {

        $url = explode('/',

                       str_replace('www.', '', str_replace('http://', '', $url)));

        return $url[0];

    }



    public static function actual() {

        return 'http://' . $_SERVER['SERVER_NAME'] . '' . $_SERVER['REQUEST_URI'] . '';

    }



    public static function servidor() {

        if (isset($_SERVER['SERVER_NAME'])) {

            return self::obtenerSERVIDOR();

        }

        return '';

        //return "http://localhost/pocket-market.com/sinap/";

    }



    public static function limpiar_url($string) {



        $string = trim($string);



        $string = str_replace(

            array('á', 'à', 'ä', 'â', 'ª', 'Á', 'À', 'Â', 'Ä'),

            array('a', 'a', 'a', 'a', 'a', 'A', 'A', 'A', 'A'), $string

        );



        $string = str_replace(

            array('é', 'è', 'ë', 'ê', 'É', 'È', 'Ê', 'Ë'),

            array('e', 'e', 'e', 'e', 'E', 'E', 'E', 'E'), $string

        );



        $string = str_replace(

            array('í', 'ì', 'ï', 'î', 'Í', 'Ì', 'Ï', 'Î'),

            array('i', 'i', 'i', 'i', 'I', 'I', 'I', 'I'), $string

        );



        $string = str_replace(

            array('ó', 'ó', 'ò', 'ö', 'ô', 'Ó', 'Ò', 'Ö', 'Ô'),

            array('o', 'o', 'o', 'o', 'O', 'O', 'O', 'O'), $string

        );



        $string = str_replace(

            array('ú', 'ù', 'ü', 'û', 'Ú', 'Ù', 'Û', 'Ü'),

            array('u', 'u', 'u', 'u', 'U', 'U', 'U', 'U'), $string

        );



        $string = str_replace(

            array('ñ', 'Ñ', 'ç', 'Ç'), array('n', 'N', 'c', 'C',), $string

        );



        //Esta parte se encarga de eliminar cualquier caracter extraño

        $string = str_replace(

            array("\\", "¨", "º", "-", "~",

            "#", "@", "|", "!", "\"",

            "·", "$", "%", "&", "/",

            "(", ")", "?", "'", "¡",

            "¿", "[", "^", "`", "]",

            "+", "}", "{", "¨", "´",

            ">", "< ", ";", ",", ":",

            "."), '', $string

        );



        $string = str_replace(" ", "-", $string);

        $string = preg_replace('/\&(.)[^;]*;/', '\\1', $string);

        $string = strtolower($string);







        return $string;

    }



    static function obtenerURL() {

        $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";

        $protocol = self::strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/") . $s;

        $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":" . $_SERVER["SERVER_PORT"]);

        return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port . $_SERVER['REQUEST_URI'];

    }

    static function obtenerSERVIDOR() {

        $s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";

        $protocol = self::strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/") . $s;

        $port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":" . $_SERVER["SERVER_PORT"]);

        return $protocol . "://" . $_SERVER['SERVER_NAME'] . $port ."/";

    }



    static function strleft($s1, $s2) {

        return substr($s1, 0, strpos($s1, $s2));

    }



}


