Пример #1
0
 public function procesar_portada()
 {
     $this->mostrar = 'portada';
     if (isset($_GET['mostrar'])) {
         $this->mostrar = $_GET['mostrar'];
     }
     $this->buscar = '';
     if (isset($_REQUEST['buscar'])) {
         $this->buscar = $_REQUEST['buscar'];
     }
     $this->codfuente = '';
     if (isset($_GET['codfuente'])) {
         $this->codfuente = $_GET['codfuente'];
     }
     $this->keyword = '';
     if (isset($_GET['keyword'])) {
         $this->keyword = $_GET['keyword'];
     }
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     $this->preview = new inme_noticia_preview();
     $noti = new inme_noticia_fuente();
     if ($this->buscar != '') {
         $this->noticias = $noti->search($this->buscar, $this->offset);
     } else {
         if ($this->codfuente != '') {
             $this->noticias = $noti->all_from_fuente($this->codfuente, $this->offset);
         } else {
             if ($this->keyword != '') {
                 $this->noticias = $noti->all_from_keyword($this->keyword, $this->offset);
             } else {
                 if ($this->mostrar == 'portada') {
                     if ($this->offset > 0) {
                         $this->noticias = $noti->all($this->offset, 'publicada DESC');
                     } else {
                         $this->noticias = $this->cache->get('inme_portada');
                         if (!$this->noticias) {
                             $this->noticias = $noti->all($this->offset, 'publicada DESC');
                             $this->cache->set('inme_portada', $this->noticias, 300);
                         }
                     }
                 } else {
                     if ($this->mostrar == 'populares') {
                         $this->noticias = $noti->all($this->offset, 'popularidad DESC');
                     } else {
                         $this->noticias = $noti->all($this->offset);
                     }
                 }
             }
         }
     }
     $tema = new inme_tema();
     $this->mostrar_tema = FALSE;
     if (isset($_GET['keyword'])) {
         $this->mostrar_tema = $tema->get($_GET['keyword']);
     }
     $this->temas_populares = $this->cache->get('inme_temas_populares');
     if (!$this->temas_populares) {
         $this->temas_populares = $tema->populares();
         $this->cache->set('inme_temas_populares', $this->temas_populares, 300);
     }
 }
Пример #2
0
 private function comprobar_temas()
 {
     $noti0 = new inme_noticia_fuente();
     $tema0 = new inme_tema();
     /**
      * Leemos noticias y sacamos las keywords.
      */
     $keys = array();
     /// noticias de portadas
     foreach ($noti0->all(0, 'publicada DESC') as $n) {
         foreach ($n->keywords() as $key) {
             if (!in_array($key, $keys)) {
                 $keys[] = $key;
             }
         }
     }
     /// últimas noticias
     foreach ($noti0->all() as $n) {
         foreach ($n->keywords() as $key) {
             if (!in_array($key, $keys)) {
                 $keys[] = $key;
             }
         }
     }
     shuffle($keys);
     /**
      * Ahora buscamos los temas de esas keywords.
      */
     $temas = array();
     foreach ($keys as $k) {
         $tema = $tema0->get($k);
         if ($tema) {
             $temas[] = $tema;
         }
     }
     /**
      * Completamos descripciones de los temas con ayuda de la wikipedia.
      */
     $max = 10;
     foreach ($temas as $tema) {
         if ($max <= 0) {
             break;
         } else {
             if ($tema->activo and mb_strtolower($tema->texto, 'UTF8') == mb_strtolower($tema->titulo, 'UTF8')) {
                 /// buscamos en la wikipedia
                 $url = 'https://es.wikipedia.org/w/api.php?format=json&action=query&prop=extracts' . '&exintro=&explaintext=&redirects=1&titles=' . urlencode($tema->titulo);
                 $html = file_get_contents($url);
                 if ($html) {
                     $json = json_decode($html);
                     if (isset($json->query)) {
                         if (isset($json->query->pages)) {
                             foreach ($json->query->pages as $page) {
                                 if (!isset($page->extract)) {
                                     /// caca
                                 } else {
                                     if (mb_strlen($page->extract) > 100) {
                                         $tema->titulo = $page->title;
                                         $tema->texto = $page->extract;
                                         if ($tema->save()) {
                                             echo '- Wikipedia: ' . $tema->codtema . ' -';
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
                 $max--;
             }
         }
     }
     /**
      * Agregamos imágenes a los temas con ayuda de bing.
      */
     $max = 10;
     foreach ($temas as $tema) {
         if ($max <= 0) {
             break;
         } else {
             if ($tema->activo and is_null($tema->imagen)) {
                 $tema->imagen = $this->get_image_from_bing($tema->titulo);
                 if ($tema->imagen) {
                     if ($tema->save()) {
                         echo '- Bing: ' . $tema->codtema . ' ';
                         /// buscamos noticias relacionadas
                         foreach ($noti0->all_from_keyword($tema->codtema) as $n) {
                             if (is_null($n->preview)) {
                                 $n->preview = $tema->imagen;
                                 $n->save();
                                 echo '*';
                             }
                         }
                         echo ' -';
                     }
                 }
                 $max--;
             }
         }
     }
     /**
      * Realizamos una busqueda en las noticias para asignarle tema
      */
     $sql = "SELECT * FROM inme_temas WHERE busqueda != '' ORDER BY popularidad DESC;";
     $data = $this->db->select($sql);
     if ($data) {
         foreach ($data as $d) {
             $tema = new inme_tema($d);
             foreach ($tema->busquedas() as $buscar) {
                 echo '- buscar: ' . $buscar . ' ';
                 foreach ($noti0->search($buscar, 0, 'fecha DESC') as $no) {
                     $no->set_keyword($tema->codtema);
                     if (is_null($no->preview) and $tema->imagen) {
                         $no->preview = $tema->imagen;
                         echo '*';
                     }
                     $no->save();
                 }
                 echo ' -';
             }
         }
     }
     $max = 10;
     $total = $tema0->count();
     while ($total > 0 and $max > 0) {
         $tema0->cron_job();
         $total -= FS_ITEM_LIMIT;
         $max--;
         echo 'T';
     }
 }
Пример #3
0
 protected function public_core()
 {
     $this->template = 'inme_public/portada';
     $this->mostrar = 'portada';
     if (isset($_GET['mostrar'])) {
         $this->mostrar = $_GET['mostrar'];
     }
     $this->buscar = '';
     if (isset($_REQUEST['buscar'])) {
         $this->buscar = $_REQUEST['buscar'];
     }
     $this->codfuente = '';
     if (isset($_GET['codfuente'])) {
         $this->codfuente = $_GET['codfuente'];
     }
     $this->offset = 0;
     if (isset($_GET['offset'])) {
         $this->offset = intval($_GET['offset']);
     }
     $this->preview = new inme_noticia_preview();
     $noti = new inme_noticia_fuente();
     if ($this->buscar != '') {
         $this->noticias = $noti->search($this->buscar, $this->offset);
     } else {
         if ($this->codfuente != '') {
             $this->noticias = $noti->all_from_fuente($this->codfuente, $this->offset);
         } else {
             if ($this->mostrar == 'portada') {
                 $this->noticias = $noti->all($this->offset, 'publicada DESC');
             } else {
                 if ($this->mostrar == 'populares') {
                     $this->noticias = $noti->all($this->offset, 'popularidad DESC');
                 } else {
                     $this->noticias = $noti->all($this->offset);
                 }
             }
         }
     }
 }