protected function private_core() { /// ¿El usuario tiene permiso para eliminar en esta página? $this->allow_delete = $this->user->allow_delete_on(__CLASS__); $tema0 = new inme_tema(); $this->tema = FALSE; if (isset($_REQUEST['cod'])) { $this->tema = $tema0->get($_REQUEST['cod']); } if ($this->tema) { if (isset($_POST['titulo'])) { $this->tema->titulo = $_POST['titulo']; $this->tema->texto = $_POST['texto']; $this->tema->busqueda = $_POST['busqueda']; $this->tema->activo = isset($_POST['activo']); $this->tema->clean_keywords(); $keys = explode(',', $_POST['keywords']); if ($keys) { foreach ($keys as $k) { if ($k != '') { $this->tema->set_keyword($this->sanitize_url($k, 50)); } } } $this->tema->imagen = NULL; if ($_POST['imagen'] != '') { $this->tema->imagen = $_POST['imagen']; $this->aplicar_cambios(); } if ($this->tema->save()) { $this->new_message('Datos guardadados correctamente.'); $this->cache->delete('inme_temas_populares'); } else { $this->new_error_msg('Error al guardar los datos.'); } } else { if (isset($_GET['bad_image'])) { $this->cambiar_imagen(); } } $noti = new inme_noticia_fuente(); $this->noticias = $noti->all_from_keyword($this->tema->codtema); } else { $this->new_error_msg('Tema no encontrado.'); } }
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'; } }
protected function public_core() { $this->template = 'inme_public/editar_noticia'; $this->page_description = 'Detalle de la noticia.'; $this->buscar = ''; $fsvar = new fs_var(); $this->analytics = $fsvar->simple_get('inme_analytics'); $this->modrewrite = $fsvar->simple_get('inme_modrewrite'); if (isset($_GET['ok_cookies'])) { setcookie('ok_cookies', 'TRUE', time() + FS_COOKIES_EXPIRE, '/'); $fslog = new fs_log(); $fslog->tipo = 'cookies'; $fslog->detalle = 'Se han aceptado las cookies'; $fslog->ip = $_SERVER['REMOTE_ADDR']; $fslog->save(); } $this->noticia = FALSE; $this->relacionada = FALSE; $this->temas = array(); $noti0 = new inme_noticia_fuente(); if (isset($_REQUEST['id'])) { $this->noticia = $noti0->get($_REQUEST['id']); } else { if (isset($_REQUEST['permalink'])) { $this->noticia = $noti0->get_by_permalink($_REQUEST['permalink']); } } if ($this->noticia) { $this->page_title = $this->noticia->titulo; $this->page_description = $this->true_text_break($this->noticia->resumen, 140); if (!is_null($this->noticia->id_relacionada)) { $this->relacionada = $noti0->get($this->noticia->id_relacionada); } $tema0 = new inme_tema(); foreach ($this->noticia->keywords() as $key) { $tema = $tema0->get($key); if ($tema) { if ($tema->activo) { $this->temas[] = $tema; /// si no hay una preview, usamos la de un tema if ($tema->imagen and !$this->noticia->preview) { $this->noticia->preview = $tema->imagen; $this->noticia->save(); } } } else { $this->new_error_msg('Tema ' . $key . ' no encontrado.'); } } } else { $this->new_error_msg('Noticia no encontrada.'); } }
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); } }
/** * 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 } 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(); $this->log[] = 'Asignada imagen del tema ' . $tema->titulo . ': <a href="' . $noti->edit_url() . '" target="_blank">' . $noti->titulo . '</a>'; 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(); $this->log[] = 'Encontrada imagen: <a href="' . $preview->link . '" target="_blank">' . $preview->link . '</a>'; $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(); $this->log[] = 'Encontrado vídeo: <a href="' . $preview->link . '" target="_blank">' . $preview->link . '</a>'; 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(); } } } } } }