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

Contenido eliminado Contenido añadido
→‎Script en PHP: Actualizo y reparo un bug que impedía su funcionamiento
Línea 91:
===Script en PHP===
Lo mismo que el anterior, salvo que en este caso es para servidores web, hecho en PHP. Si alguien desea añadir la "Frase del día" en su página web, solo tendria que añadir este texto en un archivo .php, y hacer que imprima la variable $texto_final donde quiera que aparezca la frase del dia de wikiquote.
<syntaxhighlight lang="php">
<pre><nowiki>
<?php
## Version 1.2 by davidmartindel (http://es.wikiquote.org/wiki/Usuario_Discusión:Davidmartindel) under GPL license
 
$semana = date("D");
## Version 1.2 by davidmartindel (http://es.wikiquote.org/wiki/Usuario_Discusión:Davidmartindel) under GPL license
$semanaArray = array( "Mon" => "lunes", "Tue" => "martes", "Wed" => "miércoles", "Thu" => "jueves", "Fri" => "viernes", "Sat" => "sábado", "Sun" => "domingo", );
$semana = date("D");
$title="urlencode(sprintf('{{Plantilla:Frase-".%s}}', $semanaArray[$semana]));
$semanaArray = array( "Mon" => "lunes", "Tue" => "martes", "Wed" => "miércoles", "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) {
echo "$errstr ($errno)<br/>\n"; ##Error si no ha sido posible
{
} else
echo "$errstr ($errno)<br/>\n"; ##Error si no ha sido posible
{
}
{
else
# ##Hacemos la peticion al servidor
{
$array__ = unserialize(stream_get_contents($sock));
##Hacemos la peticion al servidor
$texto_final=$array__["parse"]["text"]["*"];
 
}
$array__ = unserialize(stream_get_contents($sock));
$texto_final=utf8_decode( $texto_final);
 
$texto_final=str_replace ('/wiki/', 'http://es.wikiquote.org/wiki/' ,$texto_final );
$texto_final=$array__["parse"]["text"]["*"];
$texto_final=str_replace ('a href=', 'a target="_blank" href=' ,$texto_final );
 
$texto_final=utf8_decodestr_replace ('/w/index.php?title=', 'http://es.wikiquote.org/w/index.php?title=' ,$texto_final );
{
$texto_final=str_replace ('/wiki/', 'http://es.wikiquote.org/wiki/' ,$texto_final );
// #mostramos en pantalla la frase
$texto_final=str_replace ('a href=', 'a target="_blank" href=' ,$texto_final );
echo $texto_final;
$texto_final=str_replace ('/w/index.php?title=', 'http://es.wikiquote.org/w/index.php?title=' ,$texto_final );
 
//mostramos en pantalla la frase
echo $texto_final;
}
 
?>
</syntaxhighlight>
</nowiki></pre>
 
[[Categoría:Wikiquote:Frase del día|Frase del día]]