public function set_downloads($num)
 {
     self::$downloads = $num;
 }
Example #2
0
 /**
  * Busca imágentes/vídeos en la noticia.
  * @param inme_noticia_fuente $noti
  */
 private function preview_noticia(&$noti)
 {
     if ($noti->editada) {
         /// si está editada, no hacemos nada
         echo 'E';
     } else {
         if (is_null($noti->preview)) {
             /// primero intentamos asignar la imagen de un tema
             $tema0 = new inme_tema();
             foreach ($noti->keywords() as $key) {
                 $tema = $tema0->get($key);
                 if ($tema) {
                     if ($tema->imagen and $tema->activo) {
                         $noti->preview = $tema->imagen;
                         $noti->save();
                         echo 'T';
                         break;
                     }
                 }
             }
             /// ahora buscamos una previsualización
             $preview = new inme_noticia_preview();
             $preview->load($noti->url, $noti->texto);
             if ($preview->type) {
                 /**
                  * nos interesan previews de youtube y vimeo, así como imágenes de imgur,
                  * PERO si es una imagen normal, solamente la queremos si no tenemos nada.
                  */
                 if (is_null($noti->preview) and ($preview->type == 'imgur' or $preview->type == 'image')) {
                     $noti->preview = $preview->preview();
                     $noti->texto .= "\n<div class='thumbnail'>\n<img src='" . $preview->link . "' alt='" . $noti->titulo . "'/>\n</div>";
                     $noti->editada = TRUE;
                     $noti->save();
                 } else {
                     if ($preview->type == 'youtube') {
                         $imagen = $preview->preview();
                         if ($imagen) {
                             $noti->preview = $imagen;
                             $noti->texto = '<div class="embed-responsive embed-responsive-16by9">' . '<iframe class="embed-responsive-item" src="//www.youtube-nocookie.com/embed/' . $preview->filename . '"></iframe>' . '</div><br/>' . $noti->texto;
                             $noti->editada = TRUE;
                             $noti->save();
                         }
                     } else {
                         if ($preview->type == 'vimeo') {
                             $imagen = $preview->preview();
                             if ($imagen) {
                                 $noti->preview = $imagen;
                                 $noti->texto = '<div class="embed-responsive embed-responsive-16by9">' . '<iframe class="embed-responsive-item" src="//player.vimeo.com/video/' . $preview->filename . '"></iframe>' . '</div><br/>' . $noti->texto;
                                 $noti->editada = TRUE;
                                 $noti->save();
                             }
                         }
                     }
                 }
             } else {
                 if (is_null($noti->preview)) {
                     /// exploramos la página para buscar imágenes
                     $html = $preview->curl_download($noti->url);
                     $txt_adicional = FALSE;
                     $urls = array();
                     if (preg_match_all('@<meta property="og:image" content="([^"]+)@', $html, $urls)) {
                         foreach ($urls[1] as $url) {
                             $preview->load($url);
                             if ($preview->type and stripos($url, 'logo') === FALSE and $noti->preview != $preview->link) {
                                 $noti->preview = $preview->preview();
                                 $noti->save();
                                 $txt_adicional = "\n<div class='thumbnail'>\n<img src='" . $preview->link . "' alt='" . $noti->titulo . "'/>\n</div>";
                                 break;
                             }
                         }
                     }
                     if (!$preview->type) {
                         /// buscamos vídeos de youtube o vimeo
                         $urls = array();
                         if (preg_match_all('@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\S+)?)?)*)@', $html, $urls)) {
                             foreach ($urls[0] as $url) {
                                 foreach (array('youtube', 'youtu.be', 'vimeo') as $domain) {
                                     if (strpos($url, $domain) !== FALSE) {
                                         $preview->load($url);
                                         if (in_array($preview->type, array('youtube', 'vimeo'))) {
                                             $noti->preview = $preview->preview();
                                             $noti->save();
                                             if ($preview->type == 'youtube') {
                                                 $txt_adicional = '<div class="embed-responsive embed-responsive-16by9">' . '<iframe class="embed-responsive-item" src="//www.youtube-nocookie.com/embed/' . $preview->filename . '"></iframe>' . '</div>';
                                             } else {
                                                 if ($preview->type == 'vimeo') {
                                                     $txt_adicional = '<div class="embed-responsive embed-responsive-16by9">' . '<iframe class="embed-responsive-item" src="//player.vimeo.com/video/' . $preview->filename . '"></iframe>' . '</div>';
                                                 }
                                             }
                                             break;
                                         }
                                     }
                                 }
                                 if ($preview->type) {
                                     break;
                                 }
                             }
                         }
                     }
                     if ($txt_adicional) {
                         $noti->texto .= $txt_adicional;
                         $noti->save();
                     }
                 }
             }
             if (!is_null($noti->preview)) {
                 echo 'I';
             }
         }
     }
 }
Example #3
0
 private function preview_noticias()
 {
     $preview = new inme_noticia_preview();
     $preview->set_downloads(5);
     foreach ($this->noticia->all(mt_rand(0, 100), 'popularidad DESC') as $noti) {
         $preview->load($noti->titulo, $noti->texto . ' ' . $noti->preview);
         if (!$preview->type) {
             $html = $preview->curl_download($noti->url);
             $urls = array();
             if (preg_match_all('@<meta property="og:image" content="([^"]+)@', $html, $urls)) {
                 foreach ($urls[1] as $url) {
                     $preview->load($url);
                     if ($preview->type and stripos($url, 'logo') === FALSE and $noti->preview != $preview->link) {
                         $noti->preview = $preview->link;
                         $noti->texto .= "\n<div class='thumbnail'>\n<img src='" . $preview->link . "' alt='" . $noti->titulo . "'/>\n</div>";
                         $noti->save();
                         $this->log[] = 'Encontrada imagen: <a href="' . $preview->link . '" target="_blank">' . $preview->link . '</a>';
                         break;
                     }
                 }
             }
             if (!$preview->type) {
                 /// buscamos vídeos de youtube
                 $urls = array();
                 if (preg_match_all('@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\S+)?)?)*)@', $html, $urls)) {
                     foreach ($urls[0] as $url) {
                         foreach (array('youtube', 'youtu.be', 'vimeo') as $domain) {
                             if (strpos($url, $domain) !== FALSE) {
                                 $preview->load($url);
                                 if (in_array($preview->type, array('youtube', 'vimeo'))) {
                                     $noti->preview = $preview->link;
                                     $noti->save();
                                     $this->log[] = 'Encontrada vídeo: <a href="' . $preview->link . '" target="_blank">' . $preview->link . '</a>';
                                     break;
                                 }
                             }
                         }
                         if ($preview->type) {
                             break;
                         }
                     }
                 }
             }
         }
     }
 }