浏览代码

Merge branch 'master' into Gallery

Iñigo Valentin 9 年之前
父节点
当前提交
8865200f48

+ 17 - 4
sql/setup.sql

@@ -333,11 +333,11 @@ CREATE TABLE festival_offer (
 DROP TABLE IF EXISTS location;
 CREATE TABLE location (
 	id		INT			AUTO_INCREMENT 	PRIMARY KEY,
-	action	VARCHAR(40)	NOT NULL,
+	action	VARCHAR(1)	NOT NULL,
 	dtime	TIMESTAMP	NOT NULL		DEFAULT now(),
-	lat		DOUBLE		NOT NULL,
-	lon		DOUBLE		NOT NULL,
-	manual	BOOLEAN		NOT NULL		DEFAULT 0,
+	lat		DOUBLE,
+	lon		DOUBLE,
+	start	INT,
 	user	INT			NOT NULL		REFERENCES user.id
 );
 
@@ -470,6 +470,19 @@ CREATE TABLE transact(
 	category		INT				NOT NULL	REFERENCES transac_category.id
 );
 
+DROP TABLE IF EXISTS translation;
+CREATE TABLE translation(
+	id				INT				AUTO_INCREMENT PRIMARY KEY,
+	dtime			TIMESTAMP		NOT NULL	DEFAULT now(),
+	username		VARCHAR(255)	NOT NULL	DEFAULT 'unknown',
+	tab				VARCHAR(255)	NOT NULL,
+	field			VARCHAR(255)	NOT NULL,
+	eid				INT				NOT NULL,
+	lang			VARCHAR(2)		NOT NULL,
+	text			VARCHAR(9000)	NOT NULL,
+	applied			DATETIME
+);
+
 #Set up two users for database. File dbusers.sql contains:
 /*
 GRANT SELECT ON gm.* TO 'XXXX'@'XXXX' IDENTIFIED BY 'XXXX';

+ 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]

+ 1 - 1
www/API/v1/location.php

@@ -63,7 +63,7 @@
 	}
 	
 	//Get location
-	$q = mysqli_query($con, "SELECT lat, lon, dtime FROM location WHERE action = 'report' AND dtime > NOW() - INTERVAL 30 MINUTE ORDER BY dtime DESC LIMIT 1;");
+	$q = mysqli_query($con, "SELECT lat, lon, dtime FROM location WHERE action <> 'F' AND lat IS NOT null AND lon IS NOT null AND dtime > NOW() - INTERVAL 30 MINUTE ORDER BY dtime DESC LIMIT 1;");
 	if (mysqli_num_rows($q) > 0){
 		$r = mysqli_fetch_array($q);
 		switch ($format){

+ 9 - 9
www/API/v1/notifications.php

@@ -1,29 +1,29 @@
 <?php
 	// Gasteizko Margolariak API v1 //
-		
+
 	//List of available data formatting
 	define('FOR_JSON', 'json');
-	
+
 	//Default info format
 	define('DEF_FORMAT', FOR_JSON);
-	
+
 	//Posible notification target
 	define('TARGET_ALL', 'all');
 	define('TARGET_GM', 'gm');
-	
+
 	//Default target
 	define('DEF_TARGET', TARGET_ALL);
-		
+
 	//$_GET valid parameters
 	define('GET_CLIENT', 'client');
 	define('GET_USER', 'user');
 	define('GET_TARGET', 'target');
 	define('GET_FORMAT', 'json');
-	
+
 	//Error messages
 	define('ERR_TARGET', '-TARGET:');
 	define('ERR_FORMAT', '-FORMAT:');
-	
+
 	/****************************************************
 	* This function is called from almost everywhere at *
 	* the beggining of the page. It initializes the     *
@@ -120,8 +120,8 @@
 		http_response_code(400);
 		$error = $error . ERR_FORMAT . mysqli_real_escape_string($con, $_GET[GET_FORMAT]);
 	}
-	
-	
+
+
 	//If there has not been an error, procede
 	if (strlen($error) == 0){
 		echo(show_notifications($con, $target, $format));

+ 147 - 0
www/API/v1/sendlocation.php

@@ -0,0 +1,147 @@
+<?php
+
+	// $_GET valid parameters
+	define('GET_USER', 'user');
+	define('GET_PASS', 'pass');
+	define('GET_ACTION', 'action');
+	define('GET_LAT', 'lat');
+	define('GET_LON', 'lon');
+
+	// Valid values
+	define('ACTION_START', 'start');
+	define('ACTION_REFRESH', 'refresh');
+	define('ACTION_STOP', 'stop');
+	$actions = [ACTION_START, ACTION_REFRESH, ACTION_STOP];
+
+	// Error messages
+	define('ERR_USER', '-USER:');
+	define('ERR_ACTION', '-ACTION:');
+	define('ERR_LOCATION', '-TITLE:');
+
+	/****************************************************
+	* This function is called from almost everywhere at *
+	* the beggining of the page. It initializes the     *
+	* session variables, connect to the db, enabling    *
+	* the variable $con for futher use everywhere in    *
+	* the php code, and populates the arrays $user      *
+	* and $permission, with info about the user.        *
+	*                                                   *
+	* @return: (db connection): The connection handler. *
+	****************************************************/
+	function startdb(){
+		//Include the db configuration file. It's somehow like this
+		/*
+		 <?php
+		  $host = 'XXXX';
+		  $db_name = 'XXXX';
+		  $username_ro = 'XXXX';
+		  $username_rw = 'XXXX';
+		  $pass_ro = 'XXXX';
+		  $pass_rw = 'XXXX';
+		 ?>
+		*/
+		include('../../.htpasswd');
+
+		//Connect to to database
+		$con = mysqli_connect($host, $username_rw, $pass_rw, $db_name);
+
+		//Set encoding options
+		mysqli_set_charset($con, 'utf-8');
+		header('Content-Type: text/html; charset=utf8');
+		mysqli_query($con, 'SET NAMES utf8;');
+
+		//Return the db connection
+		return $con;
+	}
+
+	$con = startdb('rw');
+
+	//Get fields
+	$user = mysqli_real_escape_string($con, $_GET[GET_USER]);
+	$pass = mysqli_real_escape_string($con, $_GET[GET_PASS]);
+	$lat = mysqli_real_escape_string($con, $_GET[GET_LAT]);
+	$lon = mysqli_real_escape_string($con, $_GET[GET_LON]);
+	$action = mysqli_real_escape_string($con, $_GET[GET_ACTION]);
+
+	//Validate user
+	$q = mysqli_query($con, "SELECT id FROM user WHERE username = '$user' AND md5(concat(password, md5(salt))) = '$pass';");
+	if (mysqli_num_rows($q) == 0){
+		error_log(":SECURITY: Reporting location with wrong credentials (IP $_SERVER[REMOTE_ADDR])");
+		http_response_code(403); // Forbidden
+		$error = $error . ERR_TARGET . mysqli_real_escape_string($con, $_GET[GET_TARGET]);
+	}
+	// Get id
+	$r = mysqli_fetch_array($q);
+	$uid = $r['id'];
+
+	//Validate fields
+	if (!in_array($action, $actions)){
+		http_response_code(400); // Bad request
+		$error = $error . ERR_ACTION . $action;
+	}
+	if (is_numeric($lat) == false || is_numeric($lon) == false){
+		http_response_code(400); // Bad request
+		$error = $error . ERR_LOCATION . '($lat, $lon)';
+	}
+	if (strlen($lat) == 0 xor strlen($lon) == 0){
+		// Only one coordinate.
+		http_response_code(400); // Bad request
+		$error = $error . ERR_LOCATION . '($lat, $lon)';
+	}
+	if (strlen($lat) != 0 && ($lat < -90.0 || $lat > 90.0)){
+		// Invalid latitude
+		http_response_code(400); // Bad request
+		$error = $error . ERR_LOCATION . '(Lat: $lat)';
+	}
+	if (strlen($lon) != 0 && ($lon < -180.0 || $lon > 180.0)){
+		// Invalid longitude
+		http_response_code(400); // Bad request
+		$error = $error . ERR_LOCATION . '(Lon: $lat)';
+	}
+
+	// Discern action
+	switch ($action){
+		case ACTION_START:
+			// Insert
+			mysqli_query($con, "INSERT INTO location (lat, lon, action, user) VALUES ($lat, $lon, 'S', $uid);");
+			break;
+		case ACTION_REFRESH:
+			// Look for start node.
+			$q = mysqli_query($con, "SELECT id, start FROM location WHERE user = $uid AND dtime > NOW() - INTERVAL 30 MINUTE ORDER BY dtime DESC LIMIT 1;");
+			if (mysqli_num_rows($q) == 0){
+				// No recent reports. Start anew.
+				mysqli_query($con, "INSERT INTO location (lat, lon, action, user) VALUES ($lat, $lon, 'S', $uid);");
+			}
+			else{
+				$r = mysqli_fetch_array($q);
+				if ($r['action'] == 'F'){
+					// Previous track was stoped. Start anew.
+					mysqli_query($con, "INSERT INTO location (lat, lon, action, user) VALUES ($lat, $lon, 'S', $uid);");
+				}
+				else{
+					// Continue track.
+					$s = $r['start'];
+					mysqli_query($con, "INSERT INTO location (lat, lon, action, user, start) VALUES ($lat, $lon, 'S', $uid, $s);");
+				}
+			}
+			break;
+		case ACTION_STOP:
+			// Look for start node.
+			$q = mysqli_query($con, "SELECT id, start FROM location WHERE user = $uid AND dtime > NOW() - INTERVAL 30 MINUTE ORDER BY dtime DESC LIMIT 1;");
+			if (mysqli_num_rows($q) > 0){
+				$r = mysqli_fetch_array($q);
+				if ($r['action'] != 'F'){
+					// Finish track.
+					$s = $r['start'];
+					if (strlen($lat) > 0 && strlen($lon) > 0){
+						mysqli_query($con, "INSERT INTO location (lat, lon, action, user, start) VALUES ($lat, $lon, 'F', $uid, $s);");
+					}
+					else{
+						mysqli_query($con, "INSERT INTO location (action, user, start) VALUES ('F', $uid, $s);");
+					}
+				}
+			}
+			break;
+	}
+	http_response_code(204); // No content.
+?>

+ 150 - 0
www/API/v1/sendnotification.php

@@ -0,0 +1,150 @@
+<?php
+	include("../functions.php");
+	$con = startdb('rw');
+
+	// $_GET valid parameters
+	define('GET_USER', 'user');
+	define('GET_PASS', 'pass');
+	define('GET_TITLE_ES', 'title_es');
+	define('GET_TITLE_EN', 'title_en');
+	define('GET_TITLE_EU', 'title_eu');
+	define('GET_TEXT_ES', 'text_es');
+	define('GET_TEXT_EN', 'text_en');
+	define('GET_TEXT_EU', 'text_eu');
+	define('GET_DURATION', 'duration');
+	define('GET_ACTION', 'action');
+	define('GET_PERM', 'permalink');
+	define('GET_ID', 'id');
+	define('GET_GM', 'gm');
+
+	// Valid values
+	define('ACTION_TEXT', 'mensaje');
+	define('ACTION_BLOG', 'blog');
+	define('ACTION_ACTIVITIES', 'actividades');
+	define('ACTION_GALLERY', 'galeria');
+	define('ACTION_LOCALIZACION', 'localizacion');
+	define('ACTION_LABLANCA', 'lablanca');
+	define('ACTION_SCHEDULE', 'programa');
+	define('ACTION_GM_SCHEDULE', 'gprograma');
+	define('ACTION_US', 'nosotros');
+	$actions = [ACTION_TEXT, ACTION_BLOG, ACTION_ACTIVITIES, ACTION_GALLERY, ACTION_LOCALIZATION, ACTION_LABLANCA, ACTION_SCHEDULE, ACTION_GM_SCHEDULE, ACTION_US];
+
+	// Default values
+	define('DEF_GM', 0);
+	define('DEF_ACTION', ACTION_TEXT);
+
+	// Error messages
+	define('ERR_USER', '-USER:');
+	define('ERR_ACTION', '-ACTION:');
+	define('ERR_TITLE', '-TITLE:');
+	define('ERR_TEXT', '-TEXT:');
+	define('ERR_DURATION', '-DURATION:');
+	define('ERR_GM', '-GM:');
+	define('ERR_PERM', '-PERM:');
+	define('ERR_ID', '-ID:');
+
+	/****************************************************
+	* This function is called from almost everywhere at *
+	* the beggining of the page. It initializes the     *
+	* session variables, connect to the db, enabling    *
+	* the variable $con for futher use everywhere in    *
+	* the php code, and populates the arrays $user      *
+	* and $permission, with info about the user.        *
+	*                                                   *
+	* @return: (db connection): The connection handler. *
+	****************************************************/
+	function startdb(){
+		//Include the db configuration file. It's somehow like this
+		/*
+		 <?php
+		  $host = 'XXXX';
+		  $db_name = 'XXXX';
+		  $username_ro = 'XXXX';
+		  $username_rw = 'XXXX';
+		  $pass_ro = 'XXXX';
+		  $pass_rw = 'XXXX';
+		 ?>
+		*/
+		include('../../.htpasswd');
+
+		//Connect to to database
+		$con = mysqli_connect($host, $username_rw, $pass_rw, $db_name);
+
+		//Set encoding options
+		mysqli_set_charset($con, 'utf-8');
+		header('Content-Type: text/html; charset=utf8');
+		mysqli_query($con, 'SET NAMES utf8;');
+
+		//Return the db connection
+			return $con;
+	}
+
+	// Get fields
+	$user = mysqli_real_escape_string($con, $_GET[GET_USER]);
+	$pass = mysqli_real_escape_string($con, $_GET[GET_PASS]);
+	$title_es = urldecode(mysqli_real_escape_string($con, $_GET[GET_TITLE_ES]));
+	$title_en = urldecode(mysqli_real_escape_string($con, $_GET[GET_TITLE_EN]));
+	$title_eu = urldecode(mysqli_real_escape_string($con, $_GET[GET_TITLE_EU]));
+	$text_es = urldecode(mysqli_real_escape_string($con, $_GET[GET_TEXT_ES]));
+	$text_en = urldecode(mysqli_real_escape_string($con, $_GET[GET_TEXT_EN]));
+	$text_eu = urldecode(mysqli_real_escape_string($con, $_GET[GET_TEXT_EU]));
+	$duration = mysqli_real_escape_string($con, $_GET[GET_DURATION]);
+	$action = mysqli_real_escape_string($con, $_GET[GET_ACTION]);
+	$id = mysqli_real_escape_string($con, $_GET[GET_ID]);
+	$perm = mysqli_real_escape_string($con, $_GET[GET_PERM]);
+	$gm = mysqli_real_escape_string($con, $_GET[GET_GM]);
+
+	// Error control
+	$error = '';
+
+	// TODO: Validate user/pass
+	$q = mysqli_query($con, "SELECT id FROM user WHERE id = $user AND md5(concat(password, md5(salt))) = '$pass'");
+	if (mysqli_num_rows($q) == 0){
+		error_log(":SECURITY: Reporting location with wrong credentials (IP $_SERVER[REMOTE_ADDR])");
+		http_response_code(403); // Forbidden
+		$error = $error . ERR_TARGET . mysqli_real_escape_string($con, $_GET[GET_TARGET]);
+	}
+
+	//Validate fields
+	if (strlen($title_es) == 0){
+		http_response_code(400); // Bad request
+		$error = $error . ERR_TITLE . $title_es;
+	}
+
+	if (strlen($text_es) == 0){
+		http_response_code(400); // Bad request
+		$error = $error . ERR_TEXT . $text_es;
+	}
+
+	if (is_numeric($duration) == false || $duration < 1 && $duration > 48 * 60){
+		http_response_code(400); // Bad request
+		$error = $error . ERR_DURATION . $duration;
+	}
+
+	if (!in_array($action, $actions){
+		http_response_code(400); // Bad request
+		$error = $error . ERR_ACTION . $action;
+	}
+
+	//Handle translations
+	if (strlen($title_en) == 0){
+		$title_en = $title_es;
+	}
+	if (strlen($title_eu) == 0){
+		$title_eu = $title_es;
+	}
+	if (strlen($text_en) == 0){
+		$text_en = $text_es;
+	}
+	if (strlen($text_eu) == 0){
+		$text_eu = $text_es;
+	}
+
+	//Insert
+	if (strlen($error) == 0){
+		mysqli_query($con, "INSERT INTO notification (user, title_es, title_en, title_eu, text_es, text_en, text_eu, action, duration) VALUES ($user, '$title_es', '$title_en', '$title_eu', '$text_es', '$text_en', '$text_eu', '$action', $duration);");
+		http_response_code(204) // No content;
+	else{
+		error_log($error);
+	}
+?>

+ 1 - 1
www/API/v1/sync.php

@@ -142,7 +142,7 @@
 				$tables = [ 'post', 'post_comment', 'post_image', 'post_tag' ];
 				break;
 			case SEC_ACTIVITIES:
-				$tables = [ 'activity', 'activity_itinerary', 'activity_comment', 'activity_image', 'activity_tag', 'activity_itinerary', 'location', 'album', 'photo', 'photo_album', 'photo_comment', 'place' ];
+				$tables = [ 'activity', 'activity_itinerary', 'activity_comment', 'activity_image', 'activity_tag', 'activity_itinerary', 'album', 'photo', 'photo_album', 'photo_comment', 'place' ];
 				break;
 			case SEC_GALLERY:
 				$tables = [ 'album', 'photo', 'photo_album', 'photo_comment', 'place' ];

+ 2 - 1
www/app/location.php

@@ -3,7 +3,8 @@
 	$con = startdb();
 		
 	//Get user entry
-	$q = mysqli_query($con, "SELECT lat, lon, dtime, username, manual, action FROM location, user WHERE action = 'report' AND user.id = location.user AND dtime > NOW() - INTERVAL 30 MINUTE ORDER BY dtime DESC LIMIT 1;");
+	// DEBUG 1=0. Disabled.
+	$q = mysqli_query($con, "SELECT lat, lon, dtime, username, manual, action FROM location, user WHERE 0=1 AND action = 'report' AND user.id = location.user AND dtime > NOW() - INTERVAL 30 MINUTE ORDER BY dtime DESC LIMIT 1;");
 	if (mysqli_num_rows($q) > 0){
 		$r = mysqli_fetch_array($q);
 		echo("<reporting>1</reporting>\n");

+ 2 - 1
www/app/notifications.php

@@ -3,7 +3,8 @@
 	$con = startdb();
 		
 	//Get user entry
-	$q = mysqli_query($con, "SELECT id, action, title_es, title_en, title_eu, text_es, text_en, text_eu FROM notification WHERE dtime > NOW() - INTERVAL duration MINUTE ORDER BY dtime DESC ;");
+	// 1=0 Old API is now disabled
+	$q = mysqli_query($con, "SELECT id, action, title_es, title_en, title_eu, text_es, text_en, text_eu FROM notification WHERE 1 = 0 AND dtime > NOW() - INTERVAL duration MINUTE ORDER BY dtime DESC ;");
 	while ($r = mysqli_fetch_array($q)){
 		echo("<notification>\n");
 		echo("\t<id>$r[id]</id>\n");

+ 0 - 1
www/css/index.css

@@ -37,7 +37,6 @@ div#festivals div#festivals_summary img{
 
 div#festivals #festivals_summary_text{
 	display:	inline-block;
-	max-width:	50%;
 }
 
 div#festivals div#festivals_schedule_table{

+ 14 - 0
www/css/m/traducir.css

@@ -0,0 +1,14 @@
+div.translation{
+	display:		block;
+	width:			100%;
+}
+
+div#translation input,textarea{
+	width:			90%;
+}
+
+table#buttons td input{
+	height:	3.5em;
+	width:	100%;
+}
+

+ 94 - 0
www/css/traducir.css

@@ -0,0 +1,94 @@
+div.translation{
+	display:		inline-block;
+	margin:			0;
+	padding:		1em 1em 2em 1em;
+	width:			45%;
+	vertical-align:	top;
+}
+
+div.translation h3{
+	margin-bottom:	2em;
+}
+
+div#original span, p{
+	color:		#333333;
+	font-style:	italic;
+	margin:		1em;
+}
+
+div#translation input, textarea{
+	margin:		1em;
+	width:		100%;
+}
+
+table#buttons{
+	width:	100%;
+}
+
+table#buttons td{
+	padding:	0.3em;
+	width:		33%;
+}
+
+table#buttons td input{
+	height:	2.5em;
+	width:	100%;
+}
+
+table#buttons td input#next{
+	border:				0.2em solid #ff5555;
+	background-color:	#671212;
+}
+
+table#buttons td input#save{
+	border:				0.2em solid #00ff78;
+	background-color:	#126745;
+}
+
+div#w_error{
+	position:	fixed;
+	top:		20%;
+	bottom:		20%;
+	left:		10%;
+	right:		10%;
+	display:	none;
+	text-align:	center;
+	height:		60%;
+	opacity:	0;
+	-webkit-transition: opacity 0.5s ease-in-out;
+    -moz-transition: opacity 0.5s ease-in-out;
+    transition: opacity 0.5s ease-in-out;
+}
+
+div#w_error div.entry{
+	height:	80%;
+}
+
+div#w_error div.entry table{
+	height:	80%;
+	width:	100%;
+	margin:	auto;
+}
+
+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;
+}

+ 61 - 3
www/functions.php

@@ -435,10 +435,25 @@
 		$bot_kw[20] = 'commerce';
 		$bot_kw[21] = 'html';
 		$bot_kw[22] = 'fetch';
-		
+		$bot_kw[23] = 'google';
+		$bot_kw[24] = 'facebook';
+		$bot_kw[25] = 'whatsapp';
+		$bot_kw[26] = 'pinterest';
+		$bot_kw[27] = 'scrapy';
+		$bot_kw[28] = 'libwww';
+		$bot_kw[29] = 'java standard library';
+		$bot_kw[30] = 'default browser';
+		$bot_kw[31] = 'twingly recon';
+		$bot_kw[32] = 'siteexplorer';
+		$bot_kw[33] = 'yandex';
+		$bot_kw[34] = 'wotbox';
+		$bot_kw[35] = 'apache synapse';
+		$bot_kw[36] = 'catexplorador';
+		$bot_kw[37] = 'internet archive';
+
 		$i = 0;
 		while ($i < sizeof($bot_kw)) {
-			if (strpos(strtolower($uagent), $bot_kw[$i]) !== false){
+			if (strpos(strtolower($uagent), $bot_kw[$i]) !== false || strpos(strtolower($browser), $bot_kw[$i]) !== false){
 				mysqli_close($con);
 				return;
 			}
@@ -462,10 +477,53 @@
 		}
 		
 		if (is_array($ad_static)){
-			foreach ($ad_static as &$sponsor) {
+			foreach ($ad_static as $sponsor) {
 				mysqli_query($con, "UPDATE sponsor SET print_static = print_static + 1 WHERE id = $sponsor;");
 			}
 		}
 	}
+
+	function recalculateStats($day = null){
+		$con = startdb('rw');
+
+		// Visit count
+		$s = "SELECT date(dtime) AS day, count(stat_visit.id) AS visit FROM stat_view, stat_visit where stat_visit.id = stat_view.visit";
+		if (day != null){
+			$s = $s . " AND date(dtime) = str_to_date('$day', '%Y-%m-%d')";
+		}
+		$s = $s . " GROUP BY date(dtime);";
+		$q = mysqli_query($con, $s);
+		while ($r = mysqli_fetch-array($q)){
+			$q_check = mysqli_query("SELECT date FROM stat_daily_visit WHERE day = str_to_date('$day', '%Y-%m-%d')");
+			if (mysqli_num_rows($q_check) > 0){
+				// Update
+				mysqli_query($con, "UPDATE stat_daily_visit SET visit = $r[visit] WHERE day = str_to_date('$day', '%Y-%m-%d')");
+			}
+			else{
+				// Insert
+				mysqli_query($con, "INSERT INTO stat_daily_visit (day, visit) VALUES (str_to_date('$day', '%Y-%m-%d'), $r[visit])");
+			}
+		}
+
+		// Visit count by os and browser.
+		$s = "SELECT date(dtime) AS day, os, browser, count(stat_visit.id) AS visit FROM stat_view, stat_visit where stat_visit.id = stat_view.visit";
+		if (day != null){
+			$s = $s . " AND date(dtime) = str_to_date('$day', '%Y-%m-%d')";
+		}
+		$s = $s . " GROUP BY date(dtime), os, browser;";
+		$q = mysqli_query($con, $s);
+		while ($r = mysqli_fetch-array($q)){
+			$q_check = mysqli_query("SELECT date FROM stat_daily_visit_browser WHERE day = str_to_date('$day', '%Y-%m-%d') AND os = $r[os] AND browser = $r[browser]");
+			if (mysqli_num_rows($q_check) > 0){
+				// Update
+				mysqli_query($con, "UPDATE stat_daily_visit_browser SET visit = $r[visit] WHERE day = str_to_date('$day', '%Y-%m-%d') AND os = $r[os] AND browser = $r[browser]");
+			}
+			else{
+				// Insert
+				mysqli_query($con, "INSERT INTO stat_daily_visit_browser (day, os, browser, visit) VALUES (str_to_date('$day', '%Y-%m-%d'), $r[os], $[browser], $r[visit])");
+			}
+		}
+		
+	}
 ?>
 	

文件差异内容过多而无法显示
+ 0 - 1
www/lang/lang_en.php


文件差异内容过多而无法显示
+ 0 - 1
www/lang/lang_eu.php


+ 373 - 0
www/traducir/index.php

@@ -0,0 +1,373 @@
+<?php
+	session_start();
+	$http_host = $_SERVER['HTTP_HOST'];
+	include("../functions.php");
+	$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'){
+?>
+		<!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="
+		SELECT * FROM (
+		SELECT * FROM (
+		SELECT 'activity' AS tab, 'title' AS field, id, title_es AS es, title_eu AS eu, title_en AS en, dtime FROM activity WHERE title_es = title_XX
+		UNION
+		SELECT 'activity' AS tab, 'text' AS field, id, text_es AS es, text_eu AS eu, text_en AS en, dtime FROM activity WHERE text_es = text_XX
+		UNION
+		SELECT 'activity' AS tab, 'after' AS field, id, after_es AS es, after_eu AS eu, after_en AS en, dtime FROM activity WHERE after_es IS NOT NULL AND after_es = after_XX
+		UNION
+		SELECT 'activity_itinerary' AS tab, 'name' AS field, activity_itinerary.id AS id, name_es AS es, name_eu AS eu, name_en AS en, dtime FROM activity, activity_itinerary WHERE activity = activity.id AND name_es = name_XX
+		UNION
+		SELECT 'activity_itinerary' AS tab, 'text' AS field, activity_itinerary.id AS id, text_es AS es, text_eu AS eu, text_en AS en, dtime FROM activity, activity_itinerary WHERE activity = activity.id AND text_es IS NOT null AND text_es = text_XX
+		UNION
+		SELECT 'album' AS tab, 'title' AS field, id, title_es AS es, title_eu AS eu, title_en AS en, dtime FROM album WHERE title_es = title_XX
+		UNION
+		SELECT 'album' AS tab, 'description' AS field, id, description_es AS es, description_eu AS eu, description_en AS en, dtime FROM album WHERE description_es IS NOT NULL AND description_es = description_XX
+		UNION
+		SELECT 'festival' AS tab, 'text' AS field, id, text_es AS es, text_eu AS eu, text_en AS en, str_to_date(year || '-' || month(sysdate()) || '-' || day(sysdate()), '%Y-%m-%d') AS dtime FROM festival WHERE text_es = text_XX
+		UNION
+		SELECT 'festival' AS tab, 'summary' AS field, id, summary_es AS es, summary_eu AS eu, summary_en AS en, str_to_date(year || '-' || month(sysdate()) || '-' || day(sysdate()), '%Y-%m-%d') AS dtime FROM festival WHERE summary_es IS NOT null AND summary_es = summary_XX
+		UNION
+		SELECT 'festival_day' AS tab, 'name' AS field, id AS id, name_es AS es, name_eu AS eu, name_en AS en, date AS dtime FROM festival_day WHERE name_es = name_XX
+		UNION
+		SELECT 'festival_event' AS tab, 'title' AS field, id, title_es AS es, title_eu AS eu, title_en AS en, start AS dtime FROM festival_event WHERE title_es = title_XX
+		UNION
+		SELECT 'festival_event' AS tab, 'description' AS field, id, description_es AS es, description_eu AS eu, description_en AS en, start AS dtime FROM festival_event WHERE description_es IS NOT null AND description_es = description_XX
+		UNION
+		SELECT 'festival_offer' AS tab, 'name' AS field, id AS id, name_es AS es, name_eu AS eu, name_en AS en, str_to_date(year || '-' || month(sysdate()) || '-' || day(sysdate()), '%Y-%m-%d') AS dtime FROM festival_offer WHERE name_es = name_XX
+		UNION
+		SELECT 'festival_offer' AS tab, 'description' AS field, id AS id, description_es AS es, description_eu AS eu, description_en AS en, str_to_date(year || '-' || month(sysdate()) || '-' || day(sysdate()), '%Y-%m-%d') AS dtime FROM festival_offer WHERE description_es IS NOT null AND description_es = description_XX
+		UNION
+		SELECT 'photo' AS tab, 'title' AS field, id, title_es AS es, title_eu AS eu, title_en AS en, dtime FROM photo WHERE title_es IS NOT null AND title_es = title_XX
+		UNION
+		SELECT 'photo' AS tab, 'description' AS field, id, description_es AS es, description_eu AS eu, description_en AS en, dtime FROM photo WHERE description_es IS NOT null AND description_es = description_XX
+		UNION
+		SELECT 'place' AS tab, 'name' AS field, id AS id, name_es AS es, name_eu AS eu, name_en AS en, DATE_SUB(sysdate(), INTERVAL 7 DAY) AS dtime FROM place WHERE name_es = name_XX
+		UNION
+		SELECT 'place' AS tab, 'address' AS field, id AS id, address_es AS es, address_eu AS eu, address_en AS en, DATE_SUB(sysdate(), INTERVAL 7 DAY) AS dtime FROM place WHERE address_es = address_XX
+		UNION
+		SELECT 'post' AS tab, 'title' AS field, id, title_es AS es, title_eu AS eu, title_en AS en, dtime FROM post WHERE title_es = title_XX
+		UNION
+		SELECT 'post' AS tab, 'text' AS field, id, text_es AS es, text_eu AS eu, text_en AS en, dtime FROM post WHERE text_es = text_XX
+		UNION
+		SELECT 'sponsor' AS tab, 'name' AS field, id AS id, name_es AS es, name_eu AS eu, name_en AS en, DATE_SUB(sysdate(), INTERVAL 8 DAY) AS dtime FROM sponsor WHERE name_es = name_XX
+		UNION
+		SELECT 'sponsor' AS tab, 'text' AS field, id AS id, text_es AS es, text_eu AS eu, text_en AS en, DATE_SUB(sysdate(), INTERVAL 8 DAY) AS dtime FROM sponsor WHERE text_es = text_XX
+		UNION
+		SELECT 'sponsor' AS tab, 'address' AS field, id AS id, address_es AS es, address_eu AS eu, address_en AS en, DATE_SUB(sysdate(), INTERVAL 8 DAY) AS dtime FROM sponsor WHERE address_es = address_XX
+		) d ORDER BY dtime DESC LIMIT 100
+		) f ORDER BY rand();
+		";
+
+		// Select language
+		$q_string = str_replace('XX', $l, $q_string);
+	
+?>
+<!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");
+?>
+			var table = [];
+			var field = [];
+			var id = [];
+			var es = [];
+			var en = [];
+			var eu = [];
+			var idx = 0;
+
+<?php
+			$q = mysqli_query($con, $q_string);
+			$i = 0;
+			while ($r = mysqli_fetch_array($q)){
+				// Populate arrays
+?>
+				table[<?=$i?>] = '<?=$r['tab']?>';
+				field[<?=$i?>] = '<?=$r['field']?>';
+				id[<?=$i?>] = '<?=$r['id']?>';
+				es[<?=$i?>] = '<?=$r['es']?>';
+				en[<?=$i?>] = '<?=$r['en']?>';
+				eu[<?=$i?>] = '<?=$r['eu']?>';
+<?php
+				$i = $i + 1;
+			}
+
+?>
+
+			function prepare(){
+				while (es[idx].length == 0){
+					idx = idx + 1;
+				}
+				if (es[idx].length <= 180){
+					document.getElementById('i_original').innerHTML = es[idx];
+					document.getElementById('i_original').style.display = 'inline-block';
+					document.getElementById('i_translation').value = '';
+					document.getElementById('i_translation').style.display = 'inline-block';
+					document.getElementById('t_original').innerHTML = '';
+					document.getElementById('t_original').style.display = 'none';
+					document.getElementById('t_translation').innerHTML = '';
+					document.getElementById('t_translation').innerText = '';
+					document.getElementById('t_translation').value = '';
+					document.getElementById('t_translation').style.display = 'none';
+					document.getElementById('type').value = 'i';
+				}
+				else{
+					document.getElementById('i_original').innerHTML = '';
+					document.getElementById('i_original').style.display = 'none';
+					document.getElementById('i_translation').value = '';
+					document.getElementById('i_translation').style.display = 'none';
+					document.getElementById('t_original').innerHTML = es[idx];
+					document.getElementById('t_original').style.display = 'inline-block';
+					document.getElementById('t_translation').innerHTML = '';
+					document.getElementById('t_translation').innerText = '';
+					document.getElementById('t_translation').value = '';
+					document.getElementById('t_translation').style.display = 'inline-block';
+					document.getElementById('type').value = 'i';
+				}
+			}
+			
+			function error(title, text){
+				document.getElementById('error_title').innerHTML = title;
+				document.getElementById('error_msg').innerHTML = text;
+				document.getElementById('w_error').style.display = 'block';
+				document.getElementById('w_error').style.opacity = 1;
+			}
+			
+			function closeError(){
+				document.getElementById('w_error').style.opacity = 0;
+				setTimeout(function(){ document.getElementById('w_error').style.display = 'none'; }, 500);
+			}
+			
+			function save(){
+				if (document.getElementById('name').value.length == 0){
+					error("Introduce tu nombre.", "Es necesario un nombre para identificar de quien provienen las traducciones.");
+					return;
+				}
+				if (((document.getElementById('type').value == 'i') && (document.getElementById('i_translation').value.length == 0)) || ((document.getElementById('type').value == 't') && (document.getElementById('t_translation').value.length == 0))){
+					error("Introduce una traducci&oacute;n.", "No has introducido una traducci&oacute;n. Si lo prefieres, utiliza el boton rojo para saltar esta traducci&oacute;n.");
+					return;
+				}
+				
+				// Get data
+				var t = encodeURI(table[idx]);
+				var f = encodeURI(field[idx]);
+				var i = encodeURI(id[idx]);
+				var c = "";
+				var l = "<?=$l?>";
+				var n = document.getElementById('name').value;
+				if (document.getElementById('type').value == 'i'){
+					c = encodeURI(document.getElementById('i_translation').value);
+				}
+				else{
+					c = encodeURI(document.getElementById('t_translation').value);
+				}
+				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() {
+					// 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?>"/>
+		<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 onLoad='prepare();'>
+<?php	 include("../header.php"); ?>
+		<div id="content">
+			<div class='section'>
+				<h3 class='section_title'>Traducciones en 
+<?php
+					if ($l == 'en'){
+						echo("ingl&eacute;s");
+					}
+					else{
+						echo("euskera");
+					}
+?>
+				</h3>
+				<div class='entry' id='w_target'>
+					<div class='translation' id='original'>
+						<h3 class='entry_title'>Original (Castellano)</h3>
+						<span id='i_original'></span>
+						<p id='t_original'></p>
+					</div>
+					<div class='translation' id='translation'>
+						<h3 class='entry_title'>Traducci&oacute;n (
+<?php
+							if ($l == 'en'){
+								echo("Ingl&eacute;s");
+							}
+							else{
+								echo("Euskera");
+							}
+?>
+						)</h3>
+						<input type='text' id='i_translation'/>
+						<textarea id='t_translation'></textarea>
+					</div>
+					<input type='hidden' id='type' value='i'/>
+					<input type='hidden' id='lang' value='<?=$l?>'/>
+				</div> <!-- #w_target -->
+				<div class='entry'>
+					<table id='buttons'>
+						<tr>
+							<td>
+								<input type='text' id='name' placeholder='Tu nombre...'/>
+							</td>
+							<td>
+								<input type='button' id='next' value='Saltar esta' onClick='next();'/>
+							</td>
+							<td>
+								<input type='button' id='save' value='Guardar' onClick='save();'/>
+							</td>
+						</tr>
+					</table>
+				</div>
+			</div> <!-- .section -->
+			<br/><br/><br/>
+			<div class='section' id='w_error'>
+				<h3 class='section_title' id='error_title'></h3>
+				<div class='entry'>
+					<table>
+						<tr>
+							<td>
+								<span id='error_msg'></span>
+								<br/><br/><br/><br/>
+							</td>
+						</tr>
+						<tr>
+							<td>
+								<input type='button' value='Cerrar' onClick='closeError();'>
+							</td>
+						</tr>
+					</table>
+				</div>
+			</div>
+		</div> <!-- #content -->
+	</body>
+</html>
+
+<?php
+	}  //if ($l != 'en' && $l != 'en'){  -- ELSE 
+?>

+ 36 - 0
www/traducir/load.php

@@ -0,0 +1,36 @@
+<?php
+	session_start();
+	$http_host = $_SERVER['HTTP_HOST'];
+	include("../functions.php");
+	$proto = getProtocol();
+	$con = startdb('rw');
+	$server = "$proto$http_host";
+
+	// Get parameters
+
+	$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
+
+	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);
+	}
+?>

部分文件因为文件数量过多而无法显示