summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorYaco <franco@reevo.org>2019-08-10 11:06:13 -0300
committerYaco <franco@reevo.org>2019-08-10 11:06:13 -0300
commited6c6c758440a511e3bf3575ceb5aa64a783f53e (patch)
tree9b569306eb172727011512cea0e591168af3bd10 /bin
parentf3d7e35c7d4d43347c96bb343fad489062c45f25 (diff)
agrega herramienta para ImportarDesdeURL
Diffstat (limited to 'bin')
-rw-r--r--bin/wiki/ImportarDesdeURL/index.php221
-rw-r--r--bin/wiki/ImportarDesdeURL/metascraper.js30
2 files changed, 251 insertions, 0 deletions
diff --git a/bin/wiki/ImportarDesdeURL/index.php b/bin/wiki/ImportarDesdeURL/index.php
new file mode 100644
index 00000000..367acfc1
--- /dev/null
+++ b/bin/wiki/ImportarDesdeURL/index.php
@@ -0,0 +1,221 @@
+<?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 precarga el formulario de Prensa con los datos obtenidos de una URL
+# ----
+
+// Instalar npm install franc-cli --global
+
+error_reporting(1);
+
+?>
+
+
+
+<!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 URL a Prensa</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+ */
+ }
+
+ #recext-bookmarklet:hover {
+ color: black;
+ }
+
+ #recext-bookmarklet {
+ border: 0 rgba(0,0,0,0);
+ background-color: #e6e6e6;
+ text-decoration: none;
+ border-radius: 2px;
+ box-shadow: 0 0 0 1px rgba(0,0,0,.15) inset, 0 0 6px rgba(0,0,0,.2) inset;
+ padding: 5px 10px;
+ color: black;
+ cursor: move;
+ }
+ </style>
+
+ <?php
+ if ($_GET['u']) {
+ $url = $_GET['u'];
+ $resultado = json_decode(exec("node metascraper.js -u $url"),true);
+ $titulo = $resultado[title];
+ $fecha = $resultado[date];
+ $domain = parse_url($url, PHP_URL_HOST);
+ $pais = geoip_country_code_by_name($domain);
+ $descripcion = $resultado[description];
+ $fuente = $resultado[publisher];
+ $imagen = $resultado[image];
+ $langcode = exec("franc $descripcion");
+ switch ($langcode) {
+ case 'spa':
+ $idioma = 'es';
+ break;
+ case 'eng':
+ $idioma = 'en';
+ break;
+ case 'por':
+ $idioma = 'pt';
+ break;
+ default:
+ $idioma = 'es';
+ break;
+ }
+
+ }
+ ?>
+
+
+ </script>
+ </head>
+ <body>
+ <div class="panel panel-default col-md-8 col-md-offset-2">
+ <div class="panel-body">
+
+ <h1>Generar página de Prensa desde URL</h1>
+ <br>
+ <form id="buscar" class="form-horizontal">
+
+ <div class="row">
+ <div class="col-lg-12">
+ <div class="input-group">
+ <input value="<?php if ($_GET['u']) echo $_GET['u'];?>" name="url" id="url" type="text" class="form-control" placeholder="Ingresa la URL de la página" <?php if (!$_GET['u']) { ?>autofocus <?php } else { ?> disabled <?php } ?> >
+
+ <?php if ($_GET['u']) { ?>
+ <input value="<?php if ($titulo) echo $titulo;?>" name="titulo" id="titulo" type="text" class="form-control" placeholder="Ingresa el título de la página" autofocus>
+ <?php } ?>
+
+ <span class="input-group-btn">
+ <input type="button" name="generar" id="generar" class="btn btn-default" value="Generar!"></input>
+ </span>
+ </div><!-- /input-group -->
+ </div><!-- /.col-lg-6 -->
+ </div><!-- /.row -->
+
+ </form><br>
+
+ <hr>
+
+ <p>Este botón (o <i>bookmarklet</i>) permite compartir y almacenar cualquier enlace de Internet dentro de la red de Reevo. Para usarlo, simplemente arrastra el botón de abajo a la barra de enlaces de tu navegador:</p>
+ <br/>
+ <a target="_blank" id="recext-bookmarklet" href="javascript: window.open('<?php $protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === 0 ? 'https://' : 'http://'; echo $protocol . $_SERVER['HTTP_HOST'];?>/ImportarDesdeURL/?u='+encodeURIComponent(location.href))">Compartir en Reevo</a>
+
+ </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['u']) {
+ echo "
+ <script>
+ $(document).ready(function() {
+ params = '?Prensa[prensa:fecha]=$fecha&Prensa[prensa:pais]=$pais&Prensa[prensa:descripcion]=$descripcion&Prensa[prensa:fuente]=$fuente&Prensa[prensa:url]=$url&Prensa[prensa:imagen]=$imagen&Prensa[prensa:idioma]=$idioma';
+ url = '/Especial:FormEdit/Prensa/Prensa:';
+
+ $( '#generar' ).click(function() {
+ title = $( '#titulo' ).val();
+ window.location.replace(url + title + params);
+ });
+
+ });
+ </script>";
+ } else {
+ echo "
+ <script>
+ $(document).ready(function() {
+ base = '?u=';
+
+ $( '#generar' ).click(function() {
+ url = $( '#url' ).val();
+ window.location.replace(base + url);
+ });
+
+ });
+ </script>";
+ }
+ ?>
+
+</html>
diff --git a/bin/wiki/ImportarDesdeURL/metascraper.js b/bin/wiki/ImportarDesdeURL/metascraper.js
new file mode 100644
index 00000000..36f7d855
--- /dev/null
+++ b/bin/wiki/ImportarDesdeURL/metascraper.js
@@ -0,0 +1,30 @@
+// Para instalar las dependencias:
+//
+// npm install metascraper metascraper-author metascraper-date metascraper-description metascraper-image metascraper-logo metascraper-clearbit metascraper-publisher metascraper-title metascraper-url
+
+'use strict';
+
+const args = require('minimist')(process.argv.slice(2));
+
+
+const metascraper = require('metascraper')([
+ require('metascraper-author')(),
+ require('metascraper-date')(),
+ require('metascraper-description')(),
+ require('metascraper-image')(),
+ require('metascraper-logo')(),
+ require('metascraper-clearbit')(),
+ require('metascraper-publisher')(),
+ require('metascraper-title')(),
+ require('metascraper-url')()
+])
+
+const got = require('got')
+
+const targetUrl = args.u;
+
+;(async () => {
+ const { body: html, url } = await got(targetUrl)
+ const metadata = await metascraper({ html, url })
+ console.log(JSON.stringify(metadata));
+})()