예제 #1
0
 private function picar($opcion)
 {
     switch ($opcion) {
         case 0:
         case 1:
         case 2:
         case 3:
             /// buscamos noticias en las fuente
             $fuente0 = new inme_fuente();
             $fuentes = $fuente0->all();
             if ($fuentes) {
                 /// leemos de una fuente aleatoria
                 $this->leer_fuente($fuentes[mt_rand(0, count($fuentes) - 1)]);
             } else {
                 $this->new_error_msg('No hay ninguna fuente que picar. <a href="index.php?page=inme_fuentes">Añade alguna</a>.');
             }
             break;
         case 4:
             /// marcamos noticias como publicadas
             $this->log[] = 'Seleccionando noticias para portada...';
             $seleccionadas = FALSE;
             foreach ($this->noticia->all(0, 'popularidad DESC') as $noti) {
                 if (is_null($noti->publicada) and $noti->popularidad() > 10) {
                     $noti->publicada = date('d-m-Y H:i:s');
                     if ($noti->save()) {
                         $seleccionadas = TRUE;
                         $this->log[] = 'Se ha publicado la noticia: <a href="' . $noti->url . '" target="_blank">' . $noti->titulo . '</a> <span class="badge">' . $noti->popularidad() . '</span>';
                     } else {
                         $this->log[] = 'Error al publicar la noticia: ' . $noti->titulo;
                     }
                 }
             }
             if (!$seleccionadas) {
                 $this->log[] = 'Ninguna noticia seleccionada.';
             }
             break;
         case 5:
         case 6:
             $this->log[] = 'Buscamos imágenes en las noticias...';
             $this->preview_noticias();
             break;
         default:
             /// actualizamos popularidad de noticias
             $this->log[] = 'Recalculando popularidad de noticias...';
             /// escogemos un punto aleatorio en la lista de noticias
             $offset = mt_rand(0, max(array(0, $this->total_noticias() - FS_ITEM_LIMIT)));
             foreach ($this->noticia->all($offset) as $noti) {
                 $popularidad = $noti->popularidad();
                 switch (mt_rand(0, 9)) {
                     case 0:
                         $noti->tweets = $this->tweet_count($noti->url);
                         break;
                     case 1:
                         $noti->likes = $this->facebook_count($noti->url);
                         break;
                     case 2:
                         $noti->meneos = $this->meneame_count($noti->url);
                         break;
                     default:
                         break;
                 }
                 if ($noti->popularidad() == $popularidad) {
                 } else {
                     if ($noti->save()) {
                         if ($noti->popularidad() >= $popularidad) {
                             $this->log[] = '<a href="' . $noti->url . '" target="_blank">' . $noti->titulo . '</a> <b>+' . abs($noti->popularidad() - $popularidad) . '</b> popularidad.';
                         } else {
                             $this->log[] = '<a href="' . $noti->url . '" target="_blank">' . $noti->titulo . '</a> <mark>-' . abs($noti->popularidad() - $popularidad) . '</mark> popularidad.';
                         }
                     } else {
                         $this->log[] = 'Error al actualizada la popularidad de la noticia: ' . $noti->titulo;
                     }
                 }
             }
             break;
     }
 }
예제 #2
0
 private function picar()
 {
     $publicar = FALSE;
     /**
      * Si la última noticia publicada tiene menos de una hora,
      * no hace falta comprobar si hay que publicar algo.
      */
     foreach ($this->noticia->all(0, 'publicada DESC') as $noti) {
         if (strtotime($noti->publicada) > time() - 3600) {
             $publicar = FALSE;
             break;
         } else {
             $publicar = TRUE;
         }
     }
     if ($publicar) {
         /// marcamos noticias como publicadas
         $this->log[] = 'Seleccionando noticias para portada...';
         $seleccionadas = FALSE;
         foreach ($this->noticia->all(0, 'popularidad DESC') as $noti) {
             if (is_null($noti->publicada) and $noti->popularidad() > 1) {
                 $noti->publicada = date('d-m-Y H:i:s');
                 $this->preview_noticia($noti);
                 if ($noti->save()) {
                     $seleccionadas = TRUE;
                     $this->log[] = 'Se ha publicado la noticia: <a href="' . $noti->edit_url() . '" target="_blank">' . $noti->titulo . '</a> <span class="badge">' . $noti->popularidad() . '</span>';
                 } else {
                     $this->log[] = 'Error al publicar la noticia: ' . $noti->titulo;
                 }
             } else {
                 $noti->save();
             }
         }
         if (!$seleccionadas) {
             $this->log[] = 'Ninguna noticia seleccionada.';
             $publicar = FALSE;
         }
     }
     if (!$publicar) {
         /// buscamos noticias en las fuentes
         $fuente0 = new inme_fuente();
         $fuentes = $fuente0->all('fcomprobada ASC');
         if ($fuentes) {
             /// no leeremos fuentes que ya hayamos leido hace menos de media hora
             if (strtotime($fuentes[0]->fcomprobada) < time() - 1800) {
                 $this->leer_fuente($fuentes[0]);
             } else {
                 /// si no hay fuentes que leer, hacemos otras cosas
                 $this->log[] = 'Procesamos noticias...';
                 /// escogemos un punto aleatorio en la lista de noticias
                 $total = min(array(500, $this->total_noticias()));
                 $offset = mt_rand(0, max(array(0, $total)));
                 foreach ($this->noticia->all($offset) as $noti) {
                     $popularidad = $noti->popularidad();
                     switch (mt_rand(0, 3)) {
                         case 0:
                             $noti->tweets = max(array($noti->tweets, $this->tweet_count($noti->url)));
                             break;
                         case 1:
                             $noti->likes = max(array($noti->likes, $this->facebook_count($noti->url)));
                             break;
                         case 2:
                             $noti->meneos = max(array($noti->meneos, $this->meneame_count($noti->url)));
                             break;
                         default:
                             $this->preview_noticia($noti);
                             break;
                     }
                     if ($noti->save()) {
                         if ($noti->popularidad() > $popularidad) {
                             $this->log[] = '<a href="' . $noti->edit_url() . '" target="_blank">' . $noti->titulo . '</a> <b>+' . abs($noti->popularidad() - $popularidad) . '</b> popularidad.';
                         } else {
                             if ($noti->popularidad() < $popularidad) {
                                 $this->log[] = '<a href="' . $noti->edit_url() . '" target="_blank">' . $noti->titulo . '</a> <mark>-' . abs($noti->popularidad() - $popularidad) . '</mark> popularidad.';
                             }
                         }
                     } else {
                         $this->log[] = 'Error al actualizada la popularidad de la noticia: ' . $noti->titulo;
                     }
                 }
             }
         } else {
             $this->new_error_msg('No hay ninguna fuente que picar. <a href="index.php?page=inme_fuentes">Añade alguna</a>.');
         }
     }
     /// guardamos el log
     foreach ($this->log as $l) {
         $fslog = new fs_log();
         $fslog->tipo = 'picar';
         $fslog->detalle = $l;
         $fslog->ip = $_SERVER['REMOTE_ADDR'];
         if ($this->user) {
             $fslog->usuario = $this->user->nick;
         }
         $fslog->save();
     }
 }