Diferencia entre revisiones de «Wikiquote:Frase del día»

Contenido eliminado Contenido añadido
Sin resumen de edición
Línea 89:
<pre><nowiki>
<?php
## Version 0.2 by kender (kendersec AT gmail DOT com) under GPL license
 
## Version 1.2 by davidmartindel (http://es.wikiquote.org/wiki/Usuario_Discusión:Davidmartindel) under GPL license
##Abrimos un socket
$semana = date("D",$makedia);
$sock = fsockopen("es.wikiquote.org", 80, $errno, $errstr, 30);
$semanaArray = array( "Mon" => "lunes", "Tue" => "martes", "Wed" => "miercoles", "Thu" => "jueves", "Fri" => "viernes", "Sat" => "sábado", "Sun" => "domingo", );
$title="Plantilla:Frase-".$semanaArray[$semana];
$title="{"."{".$title."}"."}";
$title=utf8_encode($title);
 
$sock = fopen("http://es.wikiquote.org/w/api.php?action=parse&format=php&text=$title","r");
if (!sock)
{
Línea 100 ⟶ 105:
{
##Hacemos la peticion al servidor
$salida = "GET /wiki/Portada HTTP/1.1\nConnection: close\nCache-Control: no-cache\nHost: es.wikiquote.org\nUser-Agent: Bot 0.1 Get the
quote of the day\n\n";
 
$array__ = unserialize(stream_get_contents($sock));
fwrite ($sock, $salida);
while (!feof($sock))
{
##Recojemos lo que el servidor nos devuelve
$content .= fgets($sock, 128);
}
 
$texto_final=$array__["parse"]["text"]["*"];
## Analizamos la web en busca del mensaje
echo $texto_final;
preg_match("/(<div style=\"text-align:center\"><strong>«<i>(.*?)(<\/i>»|<\/i> <i>»<\/i>)<\/strong><\/div>)/",$content,$match);
$resultado = $match[2];
preg_replace("/<.*?>/","",$resultado);
echo "La frase celebre de hoy es:<br/><br/>\"" . $resultado . "\"<br/><br/>";
 
## Lo mismo con el autor y sus fechas
preg_match("/(<div style=\"text-align:right;padding-right:2em\"><small><a href=\"\/wiki\/.*?\" title=\".*?\">(.*?)<\/a>
( <small>|<\/small>\n<p><small><small>)(.*?)<\/small><\/small>(<\/div>|<\/p>))/", $content, $match);
 
if($match[0])
{
##Con fecha
echo "Aut@r:&nbsp;" . $match[2] . "&nbsp;--&nbsp;" . $match[4] . "<br/>";
}
else
{
##Sin fecha
preg_match("/(<div style=\"text-align:right;padding-right:2em\"><small><a href=\"\/wiki\/.*?\"
title=\".*?\">(.*?)<\/a><\/small><\/div>)/", $content,$match);
echo "Aut@r:&nbsp;" . $match[2] . "<br/>";
}
##Cerramos el socket
fclose ($sock);
?>
</nowiki></pre>
 
[http://usuarios.lycos.es/kendersec/wikiquote/wikiquote.php.txt Descargar]. (Renombrar a .php ;-)
[[Categoría:Wikiquote:Frase del día|Frase del día]]