summaryrefslogtreecommitdiff
path: root/bin/wiki/ImportarDesdeURL/index.php
blob: 367acfc15c5c18640a027121a4bf5eb2c056b02f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
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>