<?
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Allow: GET, POST, OPTIONS, PUT, DELETE");
$method = $_SERVER['REQUEST_METHOD'];
if($method == "OPTIONS") {
    die();
} ?>[

  <?
    include 'url_amigable.php';
    include 'concha.php';
    
    
    $id_nota = urls_amigables($_GET['id_nota']);
    $cat_no = urls_amigables($_GET['cat_no']);
    
    
   

                                                                    if ($cat_no == 0)  {
                                                                        $sql = "SELECT ID,titulo,d,m,a,carpetafoto,foto,cat,ext_img,impresiones FROM notas WHERE ver = 'si' AND foto != '' AND ID != '$ID_NOTA' ORDER BY ID desc LIMIT 8";
                                                                    } else {
                                                                        //$sql = "SELECT ID,titulo,texto,bajada,audio,youtube,d,m,a,carpetafoto,foto,cat,home,impresiones, ext_img FROM notas WHERE cat = '$cat_no' AND ver = 'si' AND foto != '' AND ID != '$ID_NOTA' AND m = '$m2' ORDER BY ID LIMIT 3";
                                                                        $sql = "SELECT ID,titulo,d,m,a,carpetafoto,foto,cat,ext_img,impresiones FROM notas WHERE cat = '$cat_no' AND ver = 'si' AND foto != '' AND ID != '$ID_NOTA' ORDER BY ID DESC LIMIT 8";
                                                                    }
                                                                    $consulta = $conn->query($sql);	
                                                                    while ($row = $consulta->fetch_assoc())

                                                                    {

                                                                    $ID = $row["ID"];
                                                                    $i_publi = $i_publi + 1;
                                                                    $titulo = $row["titulo"];
                                                                    $d = $row["d"];
                                                                    $m = $row["m"];
                                                                    $a = $row["a"];
                                                                    $fecha = "$d - $m - $a";
                                                                    $carpetafoto = $row["carpetafoto"];
                                                                    $foto = $row["foto"];
                                                                    $cat11 = $row["cat"];
                                                                    $home = $row["home"];
                                                                    $ext_img = $row["ext_img"];
                                                                    $impresiones = $row["impresiones"];
                                                                    $impresiones = $impresiones + 1;
                                                                    
                                                                    
                                                                    $n = $n  + 1;
                                                                    
                                                                    $sSQL="UPDATE  `$basedatos`.`notas` SET  `impresiones` =  '$impresiones' WHERE ID = '$ID'";
                                                                    $conn->query($sSQL);
                                                                    
                                                                    if ($cat_no == 0) {} else {
                                                                    $sql2 = "SELECT * FROM categorias WHERE ID = '$cat_no'";
                                                                    $consulta = $conn->query($sql);
                                                                    while ($row = $consulta->fetch_assoc())
                                                                    {
                                                                    $cat_name = $row2["nombre"];
                                                                    $color_cat = $row2["color"];
                                                                    }
                                                                    $consulta->free_result();
                                                                    
                                                                    };
                                                                    
                                                                   
  ?>


        {
          "titulo": "<? echo $titulo ?>",
          "foto": "<? echo $dom?>/<? echo $carpetafoto?>/resize_<? echo $foto ;?><? echo $ext_img?>",
          "url_nota": "<? echo $dom?>/nota/<? echo $ID ?>/<? echo urls_amigables($titulo) ?>"
        }<? if ($n == 7) {} else { echo ","; } ?>
        
        
        

  <?} $consulta->free_result();

?>
]
