<? 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 'concha.php';
include 'url_amigable.php';
?>{"notas":[{
        <?php
    

    $pageno = $_POST['pageno'];

    $no_of_records_per_page = 4;
    $offset = ($pageno-1) * $no_of_records_per_page;

    mysql_connect ("$host", "$usuario", "$contra");
    mysql_select_db ("$basedatos");
    $sql = "SELECT ID,titulo,texto,bajada,audio,youtube,d,m,a,carpetafoto,foto,cat,home,impresiones, ext_img FROM notas WHERE destacado = 'no' AND ver = 'si' AND home = 'si' and des_cat = 0 ORDER BY ID desc LIMIT 1";
    $consulta = mysql_query ($sql);
    $total_r = mysql_num_rows($consulta);
    while ($row = mysql_fetch_array($consulta))
    {
    $ID = $row["ID"];
    $i_publi = $i_publi + 1;
    $titulo = $row["titulo"];
    $bajada = $row["bajada"];
    $texto = $row["texto"];
    $audio = $row["audio"];
    $youtube  = $row["youtube"];
    $d = $row["d"];
    $m = $row["m"];
    $a = $row["a"];
    $fecha = "$d - $m - $a";
    $carpetafoto = $row["carpetafoto"];
    $foto = $row["foto"]; $ext_img = $row["ext_img"];
    $cat = $row["cat"];
    $home = $row["home"];
    $impresiones = $row["impresiones"];
    $impresiones = $impresiones + 1;
    $nn = $nn + 1;

    $sSQL="UPDATE  `$basedatos`.`notas` SET  `impresiones` =  '$impresiones' WHERE ID = '$ID'";
        mysql_db_query("$basedatos",$sSQL);
        $M = $m;
        if ($M == '01') {$m = "enero";};
        if ($M == '02') {$m = "febrero";};
        if ($M == '03') {$m = "marzo";};
        if ($M == '04') {$m = "abril";};
        if ($M == '05') {$m = "mayo";};
        if ($M == '06') {$m = "junio";};
        if ($M == '07') {$m = "julio";};
        if ($M == '08') {$m = "agosto";};
        if ($M == '09') {$m = "septiembre";};
        if ($M == '10') {$m = "octubre";};
        if ($M == '11') {$m = "noviembre";};
        if ($M == '12') {$m = "diciembre";};
        if ($cat == 0) {} else {
        $sql2 = "SELECT * FROM categorias WHERE ID = '$cat'";
        $consulta2 = mysql_query ($sql2);
        while ($row2 = mysql_fetch_array($consulta2))
        {
        $cat = $row2["nombre"];
        $color_cat = $row2["color"];
        }
        mysql_free_result($consulta2);
    }
    ?>

    <?
        $n = 0;
        $sql2 = "SELECT * FROM comentarios WHERE IDD = '$ID' and ver = 'si'";
        $consulta2 = mysql_query ($sql2);
        while ($row2 = mysql_fetch_array($consulta2))
        {
        $n = $n + 1;
        }
        mysql_free_result($consulta2);
    ?>



                                    <?       ////aca arranca el articulo?>

                                    "nota": {
                                                "categoria": "<div class='cat-title larger cat-6'
                                                        style='background-color:<?php echo $color_cat ?>;'>
                                                        <a style='color:rgba(<? echo $color_titulo_barra2 ?>)!important;'
                                                            href='<? echo $dom;?>/nota/<?php echo $ID ?>/<?php echo urls_amigables($titulo) ?>'><?php echo $cat ?></a></div>",
                                                "videos": "<?$tiene = 0;
                                                            $sql44 = "SELECT * FROM videos WHERE 'ID_nota' = $ID limit 1";
                                                            $consulta44 = mysql_query ($sql44);
                                                            while ($row44 = mysql_fetch_array($consulta44))
                                                            {
                                                            $ID_video = $row44["ID"];
                                                            $video_vid = $row44["video"];
                                                            $ID_nota = $row44["ID_nota"];
                                                            $tiene = 1;
                                                            }
                                                            mysql_free_result($consulta44);
                                                            ?>

                                                            <? if ($foto == '') {} else {?>



                                                                <a href='<? echo $dom;?>/nota/<?php echo $ID ?>/<?php echo urls_amigables($titulo) ?>'
                                                                    style='text-align:center;display:block;'>
                                                                    
                                                                    <ul style='position: absolute;top:5px;right:15px; color:#fff;list-style:none;'>

                                                                        <? if($tiene == 1 || $youtube != '' || $youtube != NULL) {?>

                                                                        <li><i style='font-size:1.8rem;' class='far fa-play-circle'></i></li>
                                                                        <?}?>

                                                                        <? if($audio != '' || $audio != NULL) {?>

                                                                        <li><i style='font-size:1.8rem;' class='fas fa-volume-up'></i></li>
                                                                        <?}?>
                                                                    </ul>
                                                                    <img class='img-fluid lazy'
                                                                        data-src='<?php echo $dom ?>/<?php echo $carpetafoto ?>/thumbnail_<?php echo $foto ?><?php echo $ext_img ?>'
                                                                        src='spinner.gif'
                                                                        data-hidpi='<?php echo $dom ?>/<?php echo $carpetafoto ?>/thumbnail_<?php echo $foto ?><?php echo $ext_img ?>'
                                                                        alt='<?php echo $titulo ?>'>
                                                                </a>

                                                            <? }; ?>",
                                                "titulo": "
                                                <div class='news-summary'>
                                                    <a href='<? echo $dom;?>/nota/<?php echo $ID ?>/<?php echo urls_amigables($titulo) ?>'>
                                                        <h3 class='colorTitulo'><?php echo $titulo ?></h3>
                                                    </a>

                                                    <div class='mom-post-meta nb-item-meta'>
                                                        <span class='entry-date'><?php echo $d ?> de <?php echo $m ?>,
                                                            <?php echo $a ?></span>
                                                    </div>

                                                    <div class='bajada'>

                                                        <p class='selectionShareable' style='margin-bottom:0;'>
                                                            <?php $bajada = str_replace('<em>','',$bajada);  $bajada = str_replace('</em>','',$bajada);  echo $bajada; ?>
                                                        </p>

                                                    </div>

                                                </div>
                                                ",


                                                
                                            

                                            <ul class='navbar-nav flex-row ml-md-auto d-md-flex px-2'>

                                                <li class='nav-item'>
                                                    <a style='padding:5px 7.5px;' target='_blank'
                                                        href='https://www.facebook.com/sharer.php?u=<?php echo $dom ?>/nota/<?php echo $ID ?>/<?php echo urls_amigables($titulo) ?>&t=<?php echo $titulo ?>'>
                                                        <i class='fab fa-facebook' style='font-size:1.2rem;color:#545454; '
                                                            aria-hidden='true'></i>
                                                    </a>
                                                </li>

                                                <li class='nav-item'>
                                                    <a style='padding:5px 7.5px;' target='_blank'
                                                        href='https://twitter.com/share?original_referer=<?php echo $dom ?>/nota/<?php echo $ID ?>/<?php echo urls_amigables($titulo_xx) ?>&amp;source=tweetbutton&amp;text=<?php echo $titulo; ?>&amp;url=<?php echo $dom ?>/nota/<?php echo $ID ?>/<?php echo urls_amigables($titulo) ?>'>
                                                        <i class='fab fa-twitter' style='font-size:1.2rem;color:#545454; '
                                                            aria-hidden='true'></i>
                                                    </a>
                                                </li>

                                                <li class='nav-item'>
                                                    <a style='padding:5px 7.5px;' target='_blank'
                                                        href='https://api.whatsapp.com/send?text=*<?php echo $titulo ?>.*  <?php echo $dom ?>/nota/<?php echo $ID ?>/<?php echo urls_amigables($titulo);?>'>
                                                        <i class='fab fa-whatsapp' style='font-size:1.2rem;color:#545454;'
                                                            aria-hidden='true'></i>
                                                    </a>
                                                </li>

                                            </ul>

                                        </article>

                                    </div>
                                    }
                                    <?   
                                        ////////////ADSENSE
                                        if(($i_publi % 5 ) == 0){ ?>

                                            <?       
                                                if ($adsense == ' ') {} else { ?>
                                            
                                                <div class='grid-item base-box col-12 col-sm-6 col-md-6 col-lg-6'
                                                    style='text-align:center; '>
                                                    <? echo $adsense; ?>
                                                </div>

                                            <?  }; ?>

                                        <?  }; ?>

                                        <?php
                                            ////////////GIF
                                            $sql2 = "SELECT * FROM publicidades_gif WHERE lugar = '$i_publi'";
                                            $consulta2 = mysql_query ($sql2);
                                            while ($row2 = mysql_fetch_array($consulta2))
                                            {
                                                $img = $row2["img"];
                                                $url = $row2["url"];
                                                $carpetafoto = $row2["carpetafoto"];
                                        ?>

                                        <div class='grid-item base-box col-12 col-sm-6 col-md-6 col-lg-6'
                                            style='text-align:center; '>

                                            <?php   if ($url == NULL) {} else { ?>

                                                <a href='<?php echo $url; ?>' target='_blank' class='Estilo1'><?php };?>

                                                    <? $ext = substr($img, -3); if ($ext == 'mp4') { ?>

                                                    <div class='col-12 text-center'>
                                                        <video autoplay muted loop style='width:100%'>
                                                            <source
                                                                src='<?php echo $dom ?>/<?php echo $carpetafoto ?>/<?php echo $img ?>'
                                                                type='video/mp4'>
                                                            Your browser does not support the video tag.
                                                        </video>



                                                    </div>

                                                    <? } else { ?>


                                                    <img class='img-fluid lazy'
                                                        data-src='<?php echo $dom ?>/<?php echo $carpetafoto?>/<?php echo $img ?>'
                                                        src='spinner.gif'> <?php   if ($url == NULL) {} else { ?>
                                                </a>
                                                
                                            <?php };?>

                                            <? } ?>

                                        </div>
                                    <?

                                        } mysql_free_result($consulta2);                              
                                        //////////////////// FIN GIF
                                    ?>

                                    <?php     
                                        $tam_ancho = 300;
                                        $sql44 = "SELECT * FROM publicidades_swf WHERE lugar = $i_publi";
                                        $consulta44 = mysql_query ($sql44);
                                        while ($row44 = mysql_fetch_array($consulta44))
                                        {
                                        $ID = $row44["ID"];
                                        $swf = $row44["swf"];
                                        $carpetafoto = $row44["carpetafoto"];
                                        $ancho = $row44["ancho"];
                                        $alto = $row44["alto"];
                                        $lugar = $row44["lugar"];
                                        $tam_alto = $alto * $tam_ancho / $ancho;
                                    ?>

                                    <div class='grid-item base-box col-12 col-sm-6 col-md-6 col-lg-6'
                                        style=' margin-bottom:10px;'>

                                        <object width='100%' height='100%'>

                                            <param name='src'
                                                value='<? echo $dom ?>/<? echo $carpetafoto ?>/<?php echo $swf ?>' />

                                            <embed src='<? echo $dom ?>/<? echo $carpetafoto ?>/<?php echo $swf ?>'
                                                pluginspage='https://www.adobe.com/shockwave/download/'
                                                width='<?php echo $tam_ancho ?>' height='<?php echo $tam_alto ?>'><embed>

                                        </object>

                                    </div>


                                    <?
                                        } mysql_free_result($consulta44);
                                    ?>

                                    <?
                                        //arranca publis jpg
                                        $sql2 = "SELECT * FROM publicidades WHERE lugar = '$i_publi'";
                                        $consulta2 = mysql_query ($sql2);
                                        while ($row2 = mysql_fetch_array($consulta2))
                                        {
                                        $img = $row2["img"];
                                        $url = $row2["url"];
                                        $carpetafoto = $row2["carpetafoto"];
                                    ?>

                                    <div class='grid-item base-box col-12 col-sm-6 col-md-6 col-lg-6'
                                        style='text-align:center;'>

                                        <?php   if ($url == NULL) {} else { ?>

                                            <a href='<?php echo $url; ?>' target='_blank' class='Estilo1'><?php };?><img
                                                    class='img-fluid lazy'
                                                    data-src='<?php echo $carpetafoto?>/resize_<?php echo $img ?>.jpg'
                                                    src='spinner.gif'> <?php   if ($url == NULL) {} else { ?>
                                            </a>
                                        
                                        <?php };?>

                                    </div>


                                    <? } mysql_free_result($consulta2);
                                        ///termina publi jpg
                                    ?>

                                    <?
                                        $i= $i + 1;
                                        } mysql_free_result($consulta);

                                //aca termina la nota sin descatar

?>}<? if ($total_r == $nn) {} else {echo ',';} ?>
   ] 
}
