Просмотр исходного кода

Translations home page implemented. Vnity URLs. Security fixes.

Iñigo Valentin 9 лет назад
Родитель
Сommit
ca88c1def6
4 измененных файлов с 121 добавлено и 26 удалено
  1. 5 0
      www/.htaccess
  2. 19 0
      www/css/traducir.css
  3. 74 11
      www/traducir/index.php
  4. 23 15
      www/traducir/load.php

+ 5 - 0
www/.htaccess

@@ -50,6 +50,11 @@ RewriteRule ^galeria/([A-Z\-a-z0-9{3,}]+)/$ /galeria/album.php?perm=$1 [NC]
 RewriteRule ^galeria/([A-Z\-a-z0-9{3,}]+)/([A-Z\-a-z0-9{3,}]+)$ /galeria/photo.php?album=$2&perm=$1 [NC]
 RewriteRule ^galeria/([A-Z\-a-z0-9{3,}]+)/([A-Z\-a-z0-9{3,}]+)/$ /galeria/photo.php?album=$2&perm=$1 [NC]
 
+RewriteRule ^traducir/eu$ /traducir/index.php?l=eu [NC]
+RewriteRule ^traducir/eu/$ /traducir/index.php?l=eu [NC]
+RewriteRule ^traducir/en$ /traducir/index.php?l=en [NC]
+RewriteRule ^traducir/en/$ /traducir/index.php?l=en [NC]
+
 #API redirections
 #TODO: This changes the url in the browser
 RewriteRule ^API/V([{0-9}]+)/help/([A-Z\-a-z0-9{3,}]+)$ /API/V$1/help/$2.php [NC,QSA,L]

+ 19 - 0
www/css/traducir.css

@@ -73,3 +73,22 @@ div#w_error div.entry table{
 div#w_error input{
 	height:		4em;
 }
+
+/* Initial page */
+
+div#w_init div.entry{
+	text-align:	center;
+}
+div#w_init div.entry a.lang{
+	display:		inline-block;
+	width:			30%;
+	border-radius:      0.3em;
+    border:             0.2em solid #0078ff;
+    font-weight:        bold;
+    color:              #ffffff;
+    background-color:   #124567;
+    cursor:             pointer;
+    margin:             1em;
+	padding:			1em;
+    letter-spacing:     0.1em;
+}

+ 74 - 11
www/traducir/index.php

@@ -5,16 +5,77 @@
 	$proto = getProtocol();
 	$con = startdb();
 	$server = "$proto$http_host";
-	
+
 	//Language
 	$lang = 'es';
 	include("../lang/lang_es.php");
-	
+
 	$cur_section = 'Traducciones';
-	
+
 	$l = strtolower(mysqli_real_escape_string($con, $_GET['l'])); // language
 	if ($l != 'en' && $l != 'eu'){
-		// TODO Regular page
+?>
+		<!DOCTYPE html>
+			<html>
+				<head>
+					<meta content="text/html; charset=utf-8" http-equiv="content-type"/>
+					<meta charset="utf-8"/>
+					<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
+					<title>Traducciones - Gasteizko Margolariak</title>
+					<link rel="shortcut icon" href="<?=$server?>/img/logo/favicon.ico">
+					<!-- CSS files -->
+					<style>
+<?php
+							include("../css/ui.css"); 
+							include("../css/traducir.css");
+?>
+					</style>
+					<!-- CSS for mobile version -->
+					<style media="(max-width : 990px)">
+<?php
+							include("../css/m/ui.css"); 
+							include("../css/m/traducir.css");
+?>
+					</style>
+					<!-- Script files -->
+					<script type="text/javascript">
+<?php
+						include("../script/ui.js");
+?>
+					</script>
+					<!-- Meta tags -->
+					<link rel="canonical" href="<?=$server?>/traducir/"/>
+					<link rel="author" href="<?=server?>"/>
+					<link rel="publisher" href="<?=server?>"/>
+					<meta name="description" content="Traduccion de contenidos de la web de Gasteizko Margolariak"/>
+					<meta property="og:title" content="Traducciones - Gasteizko Margolariak"/>
+					<meta property="og:url" content="<?=$server?>/traducir/"/>
+					<meta property="og:description" content="Traduccion de contenidos de la web de Gasteizko Margolariak"/>
+					<meta property="og:image" content="<?=$server?>/img/logo/logo.png"/>
+					<meta property="og:site_name" content="Gasteizko Margolariak"/>
+					<meta property="og:type" content="website"/>
+					<meta property="og:locale" content="es"/>
+					<meta name="twitter:card" content="summary"/>
+					<meta name="twitter:title" content="Traducciones - Gasteizko Margolariak"/>
+					<meta name="twitter:description" content="Traduccion de contenidos de la web de Gasteizko Margolariak"/>
+					<meta name="twitter:image" content="<?=$server?>/img/logo/logo.png"/>
+					<meta name="twitter:url" content="<?$server?>/traducir/"/>
+					<meta name="robots" content="noindex nofollow"/>
+				</head>
+				<body>
+<?php				include("../header.php"); ?>
+					<div id="content">
+						<div class='section' id='w_init'>
+							<h3 class='section_title'>Traducciones</h3>
+							<div class='entry'>
+								<a class='lang' href='<?=$server?>/traducir/eu/'>Traducir al euskera</a>
+								<a class='lang' href='<?=$server?>/traducir/en/'>Traducir al ingl&eacute;s</a>
+							</div>
+						</div>
+					</div>
+				</body>
+			</html>
+<?php
 	}
 	else{
 		$q_string="
@@ -193,27 +254,29 @@
 				else{
 					c = encodeURI(document.getElementById('t_translation').value);
 				}
-				var url = "load.php?t=" + t + "&f=" + f + "&i=" + i + "&c=" + c + "&l=" + l + "&n=" + n;
+				var url = "<?=$server?>/traducir/load.php?t=" + t + "&f=" + f + "&i=" + i + "&c=" + c + "&l=" + l + "&n=" + n;
+				alert(url);
 				var xhttp = new XMLHttpRequest();
 				xhttp.onreadystatechange = function() {
-					if (this.readyState == 4 && this.status == 200) {
+					// I won't notify  400 status code. I dont' want to be anoying.
+					if (this.readyState == 4 && (this.status == 200 || this.status == 400)) {
 						next();
 					}
 				};
 				xhttp.open("GET", url, true);
 				xhttp.send();
 			}
-			
+
 			function next(){
 				idx = idx + 1;
 				prepare();
 			}
-			
+
 		</script>
 		<!-- Meta tags -->
 		<link rel="canonical" href="<?=$server?>/traducir/"/>
-		<link rel="author" href="<?=server?>"/>
-		<link rel="publisher" href="<?=server?>"/>
+		<link rel="author" href="<?=$server?>"/>
+		<link rel="publisher" href="<?=$server?>"/>
 		<meta name="description" content="Traduccion de contenidos de la web de Gasteizko Margolariak"/>
 		<meta property="og:title" content="Traducciones - Gasteizko Margolariak"/>
 		<meta property="og:url" content="<?=$server?>/traducir/"/>
@@ -226,7 +289,7 @@
 		<meta name="twitter:title" content="Traducciones - Gasteizko Margolariak"/>
 		<meta name="twitter:description" content="Traduccion de contenidos de la web de Gasteizko Margolariak"/>
 		<meta name="twitter:image" content="<?=$server?>/img/logo/logo.png"/>
-		<meta name="twitter:url" content="<?$server?>/traducir/"/>
+		<meta name="twitter:url" content="<?=$server?>/traducir/"/>
 		<meta name="robots" content="noindex nofollow"/>
 	</head>
 	<body onLoad='prepare();'>

+ 23 - 15
www/traducir/load.php

@@ -5,24 +5,32 @@
 	$proto = getProtocol();
 	$con = startdb('rw');
 	$server = "$proto$http_host";
-	
+
 	// Get parameters
-	
-	/*$t = mysqli_real_escape_string($con, urldecode($_GET['t'])); // table
+
+	$t = mysqli_real_escape_string($con, urldecode($_GET['t'])); // table
 	$f = mysqli_real_escape_string($con, urldecode($_GET['f'])); // field (column)
 	$i = mysqli_real_escape_string($con, urldecode($_GET['i'])); // id
 	$c = mysqli_real_escape_string($con, urldecode($_GET['c'])); // content (translation)
 	$l = mysqli_real_escape_string($con, urldecode($_GET['l'])); // language
-	$n = mysqli_real_escape_string($con, urldecode($_GET['n'])); // translator name*/
-	
-	$t = urldecode($_GET['t']); // table
-	$f = urldecode($_GET['f']); // field (column)
-	$i = urldecode($_GET['i']); // id
-	$c = urldecode($_GET['c']); // content (translation)
-	$l = urldecode($_GET['l']); // language
-	$n = urldecode($_GET['n']); // translator name
-	
-	// TODO: Validate parameters
-	$q_string = "INSERT INTO translation (username, tab, field, eid, lang, text) VALUES ('$n', '$t', '$f', '$i', '$l', '$c');";
-	mysqli_query($con, $q_string);
+	$n = mysqli_real_escape_string($con, urldecode($_GET['n'])); // translator name
+
+	if (strlen($t) == 0 || strlen($f) == 0 || 
+	  is_numeric($i) == false || strlen($c) == 0 || 
+	  ($l != 'en' && $l != 'eu') || strlen($n) == 0){
+		 http_response_code(400); // Bad request
+	}
+	else{
+
+		/*$t = urldecode($_GET['t']); // table
+		$f = urldecode($_GET['f']); // field (column)
+		$i = urldecode($_GET['i']); // id
+		$c = urldecode($_GET['c']); // content (translation)
+		$l = urldecode($_GET['l']); // language
+		$n = urldecode($_GET['n']); // translator name*/
+
+		// TODO: Validate parameters
+		$q_string = "INSERT INTO translation (username, tab, field, eid, lang, text) VALUES ('$n', '$t', '$f', '$i', '$l', '$c');";
+		mysqli_query($con, $q_string);
+	}
 ?>