diff options
Diffstat (limited to 'bin/wiki/ImportarExperiencia/index.php')
-rw-r--r-- | bin/wiki/ImportarExperiencia/index.php | 343 |
1 files changed, 343 insertions, 0 deletions
diff --git a/bin/wiki/ImportarExperiencia/index.php b/bin/wiki/ImportarExperiencia/index.php new file mode 100644 index 00000000..36d88429 --- /dev/null +++ b/bin/wiki/ImportarExperiencia/index.php @@ -0,0 +1,343 @@ +<?php +# ---- +# Copyright (C) 2013-2020 - Reevo Project (http://reevo.org) +# License: Affero GPL version 3 - http://www.gnu.org/licenses/agpl.html +# ES: Este script importa los datos de usuario desde el perfil de Elgg hacia la paginade usuario en MW +# ---- + + +error_reporting(0); +// Load all the stuff +// require_once( __DIR__ . '/../vendor/autoload.php' ); +// require_once( __DIR__ .'/../../../etc/global_config.php' ); +// +// // Log in to a wiki +// $api = new \Mediawiki\Api\MediawikiApi( $wgServer .'/api.php' ); +// $api->login( new \Mediawiki\Api\ApiUser( $REEVO_WIKI_API_USER, $REEVO_WIKI_API_PASS ) ); +// $services = new \Mediawiki\Api\MediawikiFactory( $api ); + +// ImportarPerfil.php -u <username> -e <email> -f <true> + +function ObtenerExperiencia($id) { + + $lines = file('./procesados.log'); + foreach ($lines as $lineNumber => $line) { + $exp = explode(',',$line); + if ($exp[0] == $id) { + $titulo = $exp[1]; + $estado = $exp[2]; + if ($estado === 'si') { + echo '<div class="alert alert-warning"> + <strong>CUIDADO!</strong> Esta experiencia ya fue importada con anterioridad. <b><a target="_blank" href="/Experiencia:'.$titulo.'">Ir a la pagina</a></b> + </div>'; + break; + } else { + echo '<div class="alert alert-warning"> + <strong>CUIDADO!</strong> Esta experiencia ya fue procesada y omitida con anterioridad. + </div>'; + break; + } + } + } + + # Carga datos de experiencia + $strJsonFileContents = file_get_contents("export-mapa.json"); + $array_experiencia = json_decode($strJsonFileContents, true); + // print_r($array_experiencia); // print array + $key = array_search((int)$id, array_column($array_experiencia, '#')); + if ($key) { + $media_urls = array(); + $media_images = array(); + $file = fopen('export-mapa-media.csv', 'r'); + while (($line = fgetcsv($file)) !== FALSE) { + //$line is an array of the csv elements + if ($line[0] == $id) { + if(filter_var($line[1], FILTER_VALIDATE_URL) !== FALSE){ + # si es una URL, lo cargamos en un array de URLs + array_push($media_urls,$line[1]); + }else{ + # si NO es una URL, lo cargamos en un array de URLs + array_push($media_images,$line[1]); + } + + } + } + fclose($file); + + $array = $array_experiencia[$key]; + $titulo = $array['EXPERIENCIA/PROYECTO']; + ?> + <form action="import.php" method="post" class="form-horizontal" id="xxx"> + <div class="row"> + <div class="col-lg-12"> + <div class="input-group col-lg-2"> + <input value='<?php echo $id; ?>' name="uid" type="text" class="form-control" placeholder='' readonly> + </div> + <div class="input-group col-lg-10"> + <input value='<?php echo $titulo; ?>' name="titulo" type="text" class="form-control" placeholder='' autofocus> + <span class="input-group-btn"> + <button class="btn btn-default" type="submit">Importar</button> + </span> + </div><!-- /input-group --> + </div><!-- /.col-lg-6 --> + </div><!-- /.row --> + </form> + <form action="noimport.php" method="post" class="form-horizontal" id="xxx"> + <div class="row"> + <div class="col-lg-12"> + <div class="input-group col-lg-10"> + <input value='<?php echo $id; ?>' name="uid" type="text" class="form-control" placeholder='' style='display:none;'> + <input value='<?php echo $titulo; ?>' name="titulo" type="text" class="form-control" placeholder='' style='display:none;'> + + <input value="Si no cumple los critrios, hay que omitirla" type="text" class="form-control" placeholder='' readonly> + <span class="input-group-btn"> + <button class="btn btn-warning" type="submit">NO Importar (excluir)</button> + </span> + </div><!-- /input-group --> + </div><!-- /.col-lg-6 --> + </div><!-- /.row --> + </form> + + <br><hr> + <?php + + echo '<pre>'; + print_r($array_experiencia[$key], FALSE); // print array + echo 'Imagenes:'; + print_r($media_images, FALSE); // print array + echo 'URLs:'; + print_r($media_urls, FALSE); // print array + + echo '</pre>'; + } else { + $proximo = $id + 1; + echo "No existe un experiencia con ese ID."; + echo '<br/><a href="/ImportarExperiencia/?id='.$proximo.'" class="btn btn-secondary active" role="button" aria-pressed="true">Importar siguiente experiencia</a> + <a href="/ImportarExperiencia/" class="btn btn-warning active" role="button" aria-pressed="true">Importar otra experiencia</a>'; + + } + + +} + + + +function ImportarExperiencia($id, $profiledata,$services) { + $userdata = json_decode($profiledata, true); + + $content = '{{Experiencia +|experiencia:descripcion='.$userdata['name'].' +}} + +'.strip_tags($userdata['description'], '<p>').' + +[[CategorÃa:Experiencia]]'; + + $newContent = new \Mediawiki\DataModel\Content( $content ); + $title = new \Mediawiki\DataModel\Title( 'Experiencia:' . $username ); + $identifier = new \Mediawiki\DataModel\PageIdentifier( $title ); + $revision = new \Mediawiki\DataModel\Revision( $newContent, $identifier ); + $services->newRevisionSaver()->save( $revision ); + error_log("#### Se ha importado la experiencia: $username\n"); +} + + +function accessProtected($obj, $prop) { + $reflection = new ReflectionClass($obj); + $property = $reflection->getProperty($prop); + $property->setAccessible(true); + return $property->getValue($obj); +} + + + +?> + + + +<!DOCTYPE html> +<html lang="en"> + <head> + <!-- ================================================== --> + <meta charset="UTF-8"> + <!-- ================================================== --> + <!-- Optional support for older (IE9 or older) Microsoft browsers: --> + <meta http-equiv="X-UA-Compatible" content="IE=edge" /> + <!-- ================================================== --> + <title>REEVO - Importar Experiencia</title> + <!-- ================================================== --> + <!-- Bootstrap CSS: --> + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> + <link rel="stylesheet" href="../bootstrap.min.css"/> + <!-- ================================================== --> + <!-- Bootstrap CSS optional theme: --> + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"> + <link rel="stylesheet" href="../bootstrap-theme.min.css"/> + <!-- ================================================== --> + <!-- Optional Font Awesome library: --> + <link rel="stylesheet" href="https://opensource.keycdn.com/fontawesome/4.7.0/font-awesome.min.css"/> + <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"/> + <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"/> + <link rel="stylesheet" href="../font-awesome.min.css"/> + <!-- + Font Awesome attribution is appreciated, but not required, as of version 3.0: "Font Awesome by Dave Gandy - http://fontawesome.io". + Font Awesome CDN: https://fontawesomecdn.com/ + Font Awesome cheat sheet: http://fontawesome.io/cheatsheet/ + Font Awesome examples: http://fontawesome.io/examples/ + Font Awesome icons: http://fontawesome.io/icons/ + --> + <!-- ================================================== --> + <style> + * {/*INCLUDE BORDER AND PADDING WITHIN HEIGHT AND WIDTH*/ + box-sizing: border-box; + } + article, aside, figure, footer, header, main, nav, section {/*BACKWARD COMPATIBILITY*/ + display: block; + } + blockquote,body,button,code,div,footer,h1,h2,h3,h4,h5,h6,html,i,img,li,.nowrap,ol,p,pre,.row,ul {/*CSS RESET*/ + margin:0; + max-width: 100%; + padding:0; + word-wrap: break-word; + } + unknown-element-name {/*UNKNOWN ELEMENT*/ + display: block; + } + + pre { + white-space: pre-wrap; /* Since CSS 2.1 */ + white-space: -moz-pre-wrap; /* Mozilla, since 1999 */ + white-space: -pre-wrap; /* Opera 4-6 */ + white-space: -o-pre-wrap; /* Opera 7 */ + word-wrap: break-word; /* Internet Explorer 5.5+ */ + } + </style> + </head> + <body> + <div class="panel panel-default col-md-8 col-md-offset-2"> + <div class="panel-body"> + +<?php + if ($_POST) { ?> + <h1>Resultados</h1> + <?php ObtenerExperiencia($_POST['id']);?> + +<?php } else { ?> + <h1>Buscar experiencia por ID</h1> + <br> + <form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post" id="buscar" class="form-horizontal"> + + <div class="row"> + <div class="col-lg-6"> + <div class="input-group"> + <input value="<?php if ($_GET['id']) echo intval($_GET['id']);?>" name="id" type="text" class="form-control" placeholder="Ingresa el ID de la experiencia" autofocus> + <span class="input-group-btn"> + <button class="btn btn-default" type="submit">Buscar!</button> + </span> + </div><!-- /input-group --> + </div><!-- /.col-lg-6 --> + </div><!-- /.row --> + + </form><br><br> + <?php + $collect = array(); + $file = fopen('procesados.log', 'r'); + + while (($line = fgetcsv($file)) !== FALSE) { + if ($line[2] === 'si') { // diferencia si esta importado o omitido + $collect[] = "<tr><th scope='row'>$line[0]</th><td>$line[1]</td><td><a target='_blank' href='/Experiencia:$line[1]'>/Experiencia:$line[1]</a></td></tr>"; + } else { + $collect[] = "<tr class='danger'><th scope='row'>$line[0]</th><td>$line[1]</td><td><b>No importado</b></td></tr>"; + } + } + fclose($file); + + $importados = count($collect); + $total = 1645; + $porcentaje = intval(($importados * 100) / $total); + echo ' + <h2>Experiencias procesadas ('.$importados.'/'.$total.')</h2> + <br> + + <div class="progress"> + <div class="progress-bar" role="progressbar" aria-valuenow="'.$porcentaje.'" + aria-valuemin="0" aria-valuemax="100" style="width:'.$porcentaje.'%"> + '.$porcentaje.'% + </div> + </div>'; + ?> + + <br> + <table class="table"> + <thead class="thead-light"> + <tr> + <th scope="col">Id</th> + <th scope="col">Nombre</th> + <th scope="col">Estado</th> + </tr> + </thead> + <tbody> + <?php + + echo implode(PHP_EOL,array_reverse($collect)); + ?> + </tbody> + </table> + + + + + + + + + +<?php } ?> + + </div> + </div> + + </body> + <!-- ================================================== --> + <!-- JavaScript at bottom for faster page loading. --> + <!-- ================================================== --> + <!-- jQuery library: --> + <!-- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> --> + <!-- <script src="js/bootstrap.min.js"></script> --> + <!-- ================================================== --> + <!-- jQuery library: --> + <script type="text/javascript" src="https://code.jquery.com/jquery-3.2.1.js"></script> + <script type="application/javascript">window.jQuery || document.write('<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js">\x3C/script>')</script> + <script type="application/javascript">window.jQuery || document.write('<script src="../jquery.min.js">\x3C/script>')</script> + <script> + $(document).ready(function(){ + }); + </script> + <!-- ================================================== --> + <!-- Bootstrap JavaScript library: --> + <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> + <script type="application/javascript">$.fn.modal || document.write('<script src="../bootstrap.min.js">\x3C/script>')</script> + <!-- ================================================== --> + <!-- Bootstrap hack for Windows 8 IE10 viewport Surface/desktop bug (local fall-back) --> + <script src="../ie10-viewport-bug-workaround.js"></script> + <!-- ================================================== --> + <!-- Optional support for handling unknown elements in older browsers: --> + <!--[if lt IE 9]> + <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script> + <script src="/js/html5shiv.js"></script> + <![endif]--> + <!-- ================================================== --> + + <?php + if ($_GET['id']) { + // code... + echo ' + <script> + $(document).ready(function(){ + $("#buscar").submit(); + }); + </script>'; + } + ?> + +</html> |