<?php
function remove_acentos($string) 
{ 
  return strtolower( str_replace( array('à','á','â','ã','ä', 'ç', 'è','é','ê','ë', 'ì','í','î','ï', 'ñ', 'ò','ó','ô','õ','ö', 'ù','ú','û','ü', 'ý','ÿ', 'À','Á','Â','Ã','Ä', 'Ç', 'È','É','Ê','Ë', 'Ì','Í','Î','Ï', 'Ñ', 'Ò','Ó','Ô','Õ','Ö', 'Ù','Ú','Û','Ü', 'Ý'), array('a','a','a','a','a', 'c', 'e','e','e','e', 'i','i','i','i', 'n', 'o','o','o','o','o', 'u','u','u','u', 'y','y', 'A','A','A','A','A', 'C', 'E','E','E','E', 'I','I','I','I', 'N', 'O','O','O','O','O', 'U','U','U','U', 'Y'), $string)); 
} 

function generate_seo_titulo($input,$replace = '-')  { 
	 $return=remove_acentos($input);
     $return = @trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',$return  )));  
     return str_replace(' ',$replace,$return);  
} 

function generate_seo_titulo1($input, $table, $id, $replace = '-')  {

	$return=remove_acentos($input);
	$return = trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',$return  )));
	
	$return= str_replace(' ',$replace,$return);
	

	$db= new dbMy;
	$teste="";
	$found=0;
	do {
		$sql = "select id from $table where permatitulo='" . $return . $teste . "'";
		if ($id) $sql .=" and id!=$id";
		//print $sql;
		
		$result=mysql_query($sql);
		$num_rows=mysql_num_rows($result);
		
		if ($num_rows>0){
			if ($teste=="")
				$teste=0;
			$teste++;
			$found=1;
		} else {
			$found=0;
			
		} 
			
	} while ($found==1);
	
	
	return $return . $teste;
}

function generate_seo_link($input, $idCat, $data="", $replace = '-')  {       
	$c= new categoria;
	$path=$c->seo_path($idCat);
	//print $path;
	$return=remove_acentos($path);
	//print $return; 
    
	$return = str_replace(' ',$replace,$return);
   	if ($data) $data=str_replace('-','/',$data);
    
   	$ultimo=($input)?$input ."/":"";
	return substr($data . $return  . $ultimo, 1); 
} 

function generate_seo_link_cat($cat="categoria", $input, $idCat, $data="", $replace = '-')  {       
	$c= new categoria;
	$return=remove_acentos($c->seo_path($idCat, $cat));
	//$return = trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',$return  )));  
    
	$return = str_replace(' ',$replace,$return);
   	if ($data) $data=str_replace('-','/',$data);
    
   	$ultimo=($input)?$input ."/":"";
	return substr($data . $return  . $ultimo, 1); 
} 

function seo_path($idCat){}

function generate_seo_link_old($input, $idCat, $data="", $replace = '-')  {       
	
	$c= new categoria;
	$return=remove_acentos($c->path($idCat));
	//$return = trim(ereg_replace(' +',' ',preg_replace('/[^a-zA-Z0-9\s]/','',$return  )));  
    $return = str_replace(' ','',$return);  
	
   	if ($data) $data=str_replace('-','/',$data);
    
   	$ultimo=($input)?$input ."/":"";
	return $data . $return  . $ultimo; 
} 
?>