forked from qwerty/tupali
329 lines
9.6 KiB
PHP
329 lines
9.6 KiB
PHP
<?php
|
|
|
|
|
|
|
|
|
|
|
|
function iconifica($formulario){
|
|
$div ="div_icono";
|
|
$frase= $formulario['frase'];
|
|
$frente= $formulario['color_front'];
|
|
$fondo= $formulario['color_back'];
|
|
$mayusculas = ucwords($frase);
|
|
$iniciales="";
|
|
$cantidad_iniciales= preg_match_all("([A-Z-0-9])", $mayusculas, $inicial);
|
|
foreach ($inicial as $valor) {
|
|
foreach ($valor as $valorx) {
|
|
$iniciales .="$valorx";
|
|
}
|
|
}
|
|
// $semantica=wikipedia("$frase","");
|
|
$resultado ="
|
|
<!-- <ul>
|
|
<li>$frase</li>
|
|
<li>$mayusculas</li>
|
|
|
|
<li>$cantidad_iniciales</li>
|
|
$fondo / $frente
|
|
</ul> -->
|
|
|
|
|
|
|
|
";
|
|
|
|
$dibujar="
|
|
function dibujar() {
|
|
cxt1=iniciaCanvas('ejemplo1');
|
|
if (cxt1) {
|
|
ejemplo1.width=ejemplo1.width;
|
|
|
|
texto='$iniciales'; //texto de prueba
|
|
|
|
cxt1.beginPath() //iniciar ruta
|
|
|
|
|
|
// #g8
|
|
cxt1.save();
|
|
cxt1.transform(50, 0.000000, 0.000000, 50, 30, 30);
|
|
|
|
// #pin
|
|
cxt1.miterLimit = 4;
|
|
cxt1.strokeStyle = '$frente';
|
|
cxt1.lineWidth = 0.086814;
|
|
cxt1.fillStyle = '$fondo';
|
|
cxt1.beginPath();
|
|
|
|
cxt1.moveTo(0.905352, -0.105919);
|
|
cxt1.bezierCurveTo(1.323640, -0.105919, 1.662729, 0.233170, 1.662729, 0.651458);
|
|
cxt1.bezierCurveTo(1.662729, 0.788948, 1.626089, 0.917883, 1.562065, 1.029014);
|
|
cxt1.bezierCurveTo(1.300897, 1.482320, 1.095039, 1.587141, 0.901568, 2.113584);
|
|
cxt1.bezierCurveTo(0.706093, 1.581723, 0.496125, 1.474553, 0.242880, 1.018824);
|
|
cxt1.bezierCurveTo(0.182425, 0.910032, 0.147975, 0.784762, 0.147975, 0.651456);
|
|
cxt1.bezierCurveTo(0.147975, 0.233168, 0.487065, -0.105921, 0.905352, -0.105921);
|
|
cxt1.closePath();
|
|
cxt1.fill();
|
|
cxt1.stroke();
|
|
|
|
// #text4535
|
|
|
|
cxt1.lineJoin = 'miter';
|
|
cxt1.lineCap = 'butt';
|
|
cxt1.lineWidth = 4;
|
|
cxt1.fillStyle = '$frente';
|
|
|
|
cxt1.font = 'bold 1px AlfphabetIV';
|
|
//cxt1.font = 'bolder 1px San-serif';
|
|
cxt1.textAlign='center';
|
|
cxt1.fillText('$iniciales', 0.9, 1.1,1);
|
|
|
|
// #sombra
|
|
cxt1.save();
|
|
cxt1.lineJoin = 'miter';
|
|
cxt1.strokeStyle = 'rgb(0, 0, 0)';
|
|
cxt1.lineCap = 'butt';
|
|
cxt1.lineWidth = 0.086814;
|
|
cxt1.fillStyle = 'rgb(0, 0, 0)';
|
|
cxt1.miterLimit = 4;
|
|
cxt1.globalAlpha = 0.1;
|
|
cxt1.beginPath();
|
|
cxt1.transform(1.522548, 0.000000, 0.000000, 0.672158, -0.306407, 0.706407);
|
|
cxt1.moveTo(0.811931, 2.304708);
|
|
cxt1.bezierCurveTo(0.966011, 2.304708, 1.090917, 2.327127, 1.090917, 2.354782);
|
|
cxt1.bezierCurveTo(1.090917, 2.382438, 0.966011, 2.404857, 0.811931, 2.404857);
|
|
cxt1.bezierCurveTo(0.657851, 2.404857, 0.532944, 2.382438, 0.532944, 2.354782);
|
|
cxt1.bezierCurveTo(0.532944, 2.327127, 0.657851, 2.304708, 0.811931, 2.304708);
|
|
cxt1.fill();
|
|
cxt1.stroke();
|
|
cxt1.restore();
|
|
cxt1.restore();
|
|
|
|
}}
|
|
|
|
|
|
";
|
|
$respuesta = new xajaxResponse('utf-8');
|
|
|
|
$respuesta->addAssign("$div","innerHTML","$resultado");
|
|
//sleep(5);
|
|
$respuesta->addScript("javascript: $dibujar");
|
|
$respuesta->addScript("javascript:dibujar()");
|
|
return $respuesta;
|
|
|
|
|
|
}
|
|
$xajax->registerFunction("iconifica");
|
|
|
|
function random_color(){
|
|
mt_srand((double)microtime()*1000000);
|
|
$c = '';
|
|
while(strlen($c)<6){
|
|
$c .= sprintf("%02X", mt_rand(0, 255));
|
|
}
|
|
return $c;
|
|
}
|
|
|
|
|
|
|
|
function wikipedia_item($cadena,$div){
|
|
$cadena = strip_tags($cadena);
|
|
$wiki="";
|
|
|
|
$normalizado = str_replace(array(' '), '_', $cadena);
|
|
|
|
$url_wikipedia = "https://es.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&exintro&redirects&titles=$normalizado";
|
|
$contents = file_get_contents($url_wikipedia);
|
|
//$contents = utf8_encode($contents);
|
|
$wikipedia = json_decode($contents,true);
|
|
foreach($wikipedia as $clave => $valor){
|
|
if(is_array($valor)) {
|
|
foreach($valor as $clave => $valor){
|
|
if(is_array($valor)) {
|
|
foreach($valor as $clave => $valor){
|
|
foreach($valor as $clave => $valor){
|
|
if($clave=="extract") {
|
|
$wiki .="<small>$valor</small>";
|
|
}
|
|
/* if(is_array($valor)) {
|
|
foreach( $valor as $clave => $valor){
|
|
foreach($valor as $clave => $valor){
|
|
if($clave=="title") {
|
|
$categoria=explode(":", $valor);
|
|
if(isset($categoria[2]) AND $categoria[2] == "Desambiguación") {
|
|
$wiki =wikipedia_desambiguar("$cadena",'','categoria');
|
|
}
|
|
if($categoria[1] == "Wikipedia") {
|
|
$wiki .="";
|
|
}
|
|
else{
|
|
$wiki .= "<li class='list-group-item'>".str_replace(array('Categoría:'), '', $valor)." </li>";
|
|
}
|
|
|
|
}else {}
|
|
}
|
|
}
|
|
}*/
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$wiki="$wiki";
|
|
|
|
if($div !='') {
|
|
$respuesta = new xajaxResponse('utf-8');
|
|
$respuesta->addAssign("$div","innerHTML","$wiki");
|
|
return $respuesta;
|
|
}else{
|
|
return $wiki;
|
|
}
|
|
//return $limite;
|
|
}
|
|
$xajax->registerFunction("wikipedia_item");
|
|
|
|
function wikipedia_desambiguar($cadena,$div,$tipo){
|
|
$pagina="";
|
|
if(@$tipo==""){$tipo ="";}
|
|
$cadena = strip_tags($cadena);
|
|
$cadena_original= $cadena;
|
|
$wiki="";
|
|
$arroba = str_replace(array(' '), '', $cadena);
|
|
$normalizado = str_replace(array(' '), '_', $cadena);
|
|
//$url_wikipedia = "https://es.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&titles=".$normalizado."_(desambiguación)";
|
|
if($tipo=="") {
|
|
$url_wikipedia = "https://es.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&titles=".$normalizado."_(desambiguación)";
|
|
}
|
|
if($tipo=="categoria") {
|
|
$url_wikipedia = "https://es.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&titles=".$normalizado."&prop=revisions&rvprop=content&rvparse";
|
|
}
|
|
//$url_wikipedia = "https://es.wikipedia.org/w/api.php?format=json&action=query&prop=categories&redirects&continue&titles=$normalizado";
|
|
$contents = file_get_contents($url_wikipedia);
|
|
//$contents = utf8_encode($contents);
|
|
$wikipedia = json_decode($contents,true);
|
|
if(is_array($wikipedia)) {
|
|
foreach($wikipedia as $clave => $valor){
|
|
if(is_array($valor)) {
|
|
foreach($valor as $clave => $valor){
|
|
foreach($valor as $clave => $valor){
|
|
$pagina=$clave;
|
|
foreach($valor as $clave => $valor){
|
|
if($clave=="extract") {
|
|
$patron = '|<li>(.*?)</li>|is';
|
|
if (preg_match_all($patron, $valor, $valor1)) //preg_match_all('@src="([^"]+)"@', $cadena, $array);
|
|
{
|
|
foreach($valor1[0] as $nombre){
|
|
$cadena ="".between("<li>","</li>","$nombre")." <hr>";
|
|
$cadena=explode(":", $cadena);
|
|
$cadena_busqueda = strip_tags($cadena[0]);
|
|
$wiki .="<a onclick=\"xajax_wikipedia('$cadena_busqueda','div_$arroba'); \" '>$cadena[0] <strong>$cadena[1]</strong></a> ";
|
|
}
|
|
}
|
|
}
|
|
else{
|
|
if(is_array($valor)) {
|
|
foreach($valor as $clave => $valor){
|
|
if(is_array($valor)) {
|
|
foreach($valor as $clave => $valor){
|
|
// $wiki="$valor";
|
|
$patron = '|<li>(.*?)</li>|is';
|
|
if (preg_match_all($patron, $valor, $valor1)) //preg_match_all('@src="([^"]+)"@', $cadena, $array);
|
|
{
|
|
foreach($valor1[0] as $nombre){
|
|
$cadena ="".between("<li>","</li>","$nombre")."";
|
|
|
|
$cadena=explode(":", $cadena);
|
|
$cadena=explode(",", $cadena[0]);
|
|
$cadena=explode(";", $cadena[0]);
|
|
$cadena_titulo = maya_extraer_title($cadena[0]);
|
|
$cadena_busqueda = @strip_tags($cadena[1]);
|
|
if($cadena_titulo !="") {
|
|
$wiki .="<a href='#$arroba' onclick=\"xajax_wikipedia('$cadena_titulo','div_$arroba'); \" '><small>$cadena_titulo</small></a><br> ";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if( $pagina > 0 ) {
|
|
$wiki="<ul class='list-group'> $wiki </ul>";
|
|
}else{
|
|
$wiki = wikipedia("$cadena_original",'');
|
|
}
|
|
|
|
|
|
if($div !='') {
|
|
$respuesta = new xajaxResponse('utf-8');
|
|
$respuesta->addAssign("$div","innerHTML","$wiki");
|
|
return $respuesta;
|
|
}else{
|
|
return $wiki;
|
|
}
|
|
//return $limite;
|
|
}
|
|
$xajax->registerFunction("wikipedia_desambiguar");
|
|
|
|
|
|
function wikipedia($cadena,$div){
|
|
$cadena = strip_tags($cadena);
|
|
$wiki="";
|
|
|
|
$normalizado = str_replace(array(' '), '_', $cadena);
|
|
//$url_wikipedia = "https://es.wikipedia.org/w/api.php?format=json&action=query&prop=extracts&titles=".$normalizado."_(desambiguación)";
|
|
$url_wikipedia = "https://es.wikipedia.org/w/api.php?format=json&action=query&prop=categories&redirects&continue&titles=$normalizado";
|
|
$contents = file_get_contents($url_wikipedia);
|
|
//$contents = utf8_encode($contents);
|
|
$wikipedia = json_decode($contents,true);
|
|
foreach($wikipedia as $clave => $valor){
|
|
if(is_array($valor)) {
|
|
foreach($valor as $clave => $valor){
|
|
if(is_array($valor)) {
|
|
foreach($valor as $clave => $valor){
|
|
foreach($valor as $clave => $valor){
|
|
if(is_array($valor)) {
|
|
foreach( $valor as $clave => $valor){
|
|
foreach($valor as $clave => $valor){
|
|
if($clave=="title") {
|
|
$categoria=explode(":", $valor);
|
|
if(isset($categoria[2]) AND $categoria[2] == "Desambiguación") {
|
|
$wiki =wikipedia_desambiguar("$cadena",'','categoria');
|
|
}
|
|
if($categoria[1] == "Wikipedia") {
|
|
$wiki .="";
|
|
}
|
|
else{
|
|
$wiki .= "<li class='list-group-item'>".str_replace(array('Categoría:'), '', $valor)." </li>";
|
|
}
|
|
|
|
}else {}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$wikipedia_item = wikipedia_item($cadena,"");
|
|
$wiki="<ul class='list-group'>$wikipedia_item <hr> $wiki</ul>";
|
|
|
|
if($div !='') {
|
|
$respuesta = new xajaxResponse('utf-8');
|
|
$respuesta->addAssign("$div","innerHTML","$wiki");
|
|
return $respuesta;
|
|
}else{
|
|
return $wiki;
|
|
}
|
|
//return $limite;
|
|
}
|
|
$xajax->registerFunction("wikipedia");
|
|
?>
|