<?php 

	function preparar_url($string) {

      $not_allowed = array ("á","é","í","ó","ú","Á","É","Í","Ó","Ú","ñ","À","Ã","Ì","Ò","Ù","Ã™","Ã ","Ã¨","Ã¬","Ã²","Ã¹","ç","Ç","Ã¢","ê","Ã®","Ã´","Ã»","Ã‚","ÃŠ","ÃŽ","Ã”","Ã›","ü","Ã¶","Ã–","Ã¯","Ã¤","«","Ò","Ã","Ã„","Ã‹",' ','Ñ','´');

      $permitted   = array ("a","e","i","o","u","A","E","I","O","U","n","N","A","E","I","O","U","a","e","i","o","u","c","C","a","e","i","o","u","A","E","I","O","U","u","o","O","i","a","e","U","I","A","E",'-');

      $url = str_replace($not_allowed, $permitted ,$string);

      $url=strtolower($url);

      return $url;
   }

   function generar_code($n){
   		$pattern = '1234567890ABCDEFGHIJKLMNOPQRSTUVWYZ';
   		$key = '';
        $max = strlen($pattern)-1;
        	for($j=0; $j <$n ;$j++) {
                $key .= $pattern{mt_rand(0,$max)};
                              
        	}
        return $key;
   }

   function video_hotel($video=null){

      if (is_null($video)) {
        return 1;
      }else{
        
        $data = array(); 

        if (strpos($video, 'vimeo.com') !== false) {          
          $data['video'] = 'vimeo';
          $data['link'] = $video;

          return $data;
        }

        if (strpos($video, 'youtube.com') !== false) {          
          $data['video'] = 'youtube';
          

          $link = strlen($video);
          $youtube = strlen('https://www.youtube.com/watch?v=');

          $url='';

          for($i=$youtube; $i<$link;$i++){
            $url = $url.$video[$i];
          }
          $data['link'] = $url;
          return $data;
        }



        return 1;

      }
   }


   function segundo_plano($url){

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT_MS, 300); 
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
    curl_exec ($ch);
    curl_close ($ch);
   }
   
 ?>