Skip to content
Snippets Groups Projects
Commit cd197629 authored by Hakkel Tamás's avatar Hakkel Tamás
Browse files

first stable version with new database on web.ppke.hu

parent 3897a738
No related branches found
No related tags found
No related merge requests found
RewriteEngine On
RewriteRule ^img/(.*\.jpg.*)$ https://users.itk.ppke.hu/~hakta/belepteto/image.php?$1 [NC]
RewriteCond %{SERVER_PORT} 80 RewriteCond %{SERVER_PORT} 80
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
...@@ -6,7 +6,7 @@ $now = microtime(true); ...@@ -6,7 +6,7 @@ $now = microtime(true);
$enabled_time_window = 20; // in sec $enabled_time_window = 20; // in sec
$required_time_between_trials = 30; // in sec $required_time_between_trials = 30; // in sec
$enabled_trials_per_day = 5; $enabled_trials_per_day = 5;
$today = strtotime(date('Y-m-d').' 00:00 GMT'); $today = strtotime(date('Y-m-d').' 00:00 GMT')*1000.;
$result = $db->prepare(' $result = $db->prepare('
SELECT count(*) SELECT count(*)
...@@ -23,10 +23,6 @@ if (intval($trials_today) > $enabled_trials_per_day) { ...@@ -23,10 +23,6 @@ if (intval($trials_today) > $enabled_trials_per_day) {
output($db,'locked'); output($db,'locked');
} }
if ($last_action === 'locked' AND $last_action > $today) {
output($db,'locked');
}
$result = $db->prepare(' $result = $db->prepare('
SELECT timestamp,action SELECT timestamp,action
FROM registration_log FROM registration_log
...@@ -42,7 +38,7 @@ if ($last_action === 'start' AND $last_timestamp > $now - $enabled_time_window) ...@@ -42,7 +38,7 @@ if ($last_action === 'start' AND $last_timestamp > $now - $enabled_time_window)
$result = $db->prepare(' $result = $db->prepare('
SELECT card_ID SELECT card_ID
FROM card_log FROM card_log
WHERE timestamp > :start WHERE timestamp > :start AND emulated = 0
GROUP BY card_ID GROUP BY card_ID
HAVING count(*) > 2'); HAVING count(*) > 2');
$result->execute(array('start' => $last_entry['timestamp'])); $result->execute(array('start' => $last_entry['timestamp']));
...@@ -117,7 +113,7 @@ function saveUser($db,$card_ID) { ...@@ -117,7 +113,7 @@ function saveUser($db,$card_ID) {
else else
$db->exec("INSERT INTO user (shibboleth,name,email,card_ID) $db->exec("INSERT INTO user (shibboleth,name,email,card_ID)
VALUES ('{$_SERVER['uid']}','{$_SERVER['displayName']}','{$_SERVER['mail']}','$card_ID')"); VALUES ('{$_SERVER['uid']}','{$_SERVER['displayName']}','{$_SERVER['mail']}','$card_ID')");
} }
function sqlSave($db,$now,$shibboleth,$last_action) { function sqlSave($db,$now,$shibboleth,$last_action) {
......
...@@ -3,7 +3,7 @@ language = language(); ...@@ -3,7 +3,7 @@ language = language();
function setup() { function setup() {
info('description'.language); info('description'.language);
ajax(processReceivedData); ajax(processReceivedData);
$(".start").click( () => ajax(processReceivedData,{ "action": true }) ); $(".start").click( function() {ajax(processReceivedData,{ "action": true })} );
} }
var interval; var interval;
...@@ -23,7 +23,7 @@ function processReceivedData(data) { ...@@ -23,7 +23,7 @@ function processReceivedData(data) {
clearInterval(interval); clearInterval(interval);
interval = null; interval = null;
} else if (!interval) } else if (!interval)
interval = setInterval(ajax, 300); interval = setInterval(function() {ajax(processReceivedData,{ "action": true })}, 300);
if (message === 'waiting') { if (message === 'waiting') {
var time = new Date(- new Date()); var time = new Date(- new Date());
$(".time").text(Math.floor((parsed['timestamp'] - Date.now()) / 1000)); $(".time").text(Math.floor((parsed['timestamp'] - Date.now()) / 1000));
......
AuthType shibboleth
ShibRequireSession On
Require valid-user
\ No newline at end of file
<?php <?php
ob_start("ob_gzhandler"); if (! defined('NO_GZIP')) {
header('Vary: Accept-Encoding'); ob_start('ob_gzhandler');
header('Pragma: no-cache'); header('Content-Encoding: gzip');
header('Cache-Control: no-cache'); }
if (! defined('CACHE')) {
header('Pragma: no-cache');
header('Cache-Control: no-cache');
}
header('Accept-Ranges: bytes'); header('Accept-Ranges: bytes');
header('Content-Encoding: gzip'); header('Vary: Accept-Encoding');
define(CORE_PATH,__DIR__.DIRECTORY_SEPARATOR); define(CORE_PATH,__DIR__.DIRECTORY_SEPARATOR);
......
<?php
// Example url:
// http://kibusam.itk.ppke.hu/image.php?thumbnail&1190
define('NO_GZIP',TRUE);
define('CACHE',TRUE);
require('backend.php');
$shibboleth = $_SERVER['uid'];
$uri = $_SERVER['QUERY_STRING'];
$uri_parts = explode('&',$uri);
if(!in_array($uri_parts[0], array('thumbnail', 'full_frame'))) {
die('Not valid request!');
}
$type = $uri_parts[0];
$pic_ID = intval($uri_parts[1]);
$result = $db->prepare("
SELECT $type
FROM photo JOIN user USING(card_ID)
WHERE photo_ID=:picid AND shibboleth=:shibboleth");
$result->execute(array('picid' => $pic_ID,'shibboleth' => $shibboleth ));
$result = $result->fetch(PDO::FETCH_NUM);
if($result) {
header('Content-type: image/jpeg');
die($result[0]);
} else {
die('Access denied or not existing image');
}
<?php
if (empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] === 'off')
die(json_encode(array(
'success' => FALSE,
'answer' => 'Only https is allowed'
)));
if (!isset($_POST['password']))
die(json_encode(array(
'success' => FALSE,
'answer' => 'Missing password'
)));
if (!isset($_POST['query']))
die(json_encode(array(
'success' => FALSE,
'answer' => 'Missing query'
)));
if ($_POST['password'] !== "wY^!8FsB.+DSA}tb=nhfMTq6XHy`;?u%']m_dp{~xV,Z#5(va-")
die(json_encode(array(
'success' => FALSE,
'answer' => 'Access denied'
)));
$db = new PDO('sqlite:db/db.sqlite');
$db->beginTransaction();
$queries = explode(';',$_POST['query']);
foreach ($queries as $query) {
if (trim($query) === '') continue;
$result = $db->prepare($query);
$success = $result !== FALSE;
if ($success)
$result->execute();
else {
$error = $db->errorInfo();
break;
}
}
if ($success)
$db->commit();
else
$db->rollBack();
$answer = json_encode(array(
'success' => $success,
'answer' => $success ? $result->fetchAll(PDO::FETCH_ASSOC) : $error[2]
));
$db = new PDO('sqlite:../belepteto-dev/db/db.sqlite');
$db->beginTransaction();
$queries = explode(';',$_POST['query']);
foreach ($queries as $query) {
if (trim($query) === '') continue;
$result = $db->prepare($query);
$success = $result !== FALSE;
if ($success)
$result->execute();
else {
$error = $db->errorInfo();
break;
}
}
if ($success)
$db->commit();
else
$db->rollBack();
die($answer);
<?php
ob_start("ob_gzhandler");
$uri = $_SERVER['QUERY_STRING'];
$uri_parts = explode('&',$uri);
$path = "/home/hakta/public_html/belepteto/images/".$uri_parts[0];
header('Content-type: image/jpeg');
header('Accept-Ranges: bytes');
//header('Content-Length: ' . filesize($path));
header('Last-Modified: '.gmdate('D, d M Y H:i:s', filemtime($path)).' GMT');
$seconds_to_cache = 31536000;
header('Expires: '.gmdate('D, d M Y H:i:s', time()+$seconds_to_cache).' GMT');
header('Pragma: cache');
header('Cache-Control: max-age='.$seconds_to_cache);
header('Vary: Accept-Encoding');
//header('Content-Encoding: gzip');
header_remove('x-powered-by');
//readfile($path);die();
$image=imagecreatefromjpeg($path);
if (count($uri_parts) > 1) {
list($width, $height) = getimagesize($path);
$new_width = (int)$uri_parts[1];
$new_height = $new_width / $width * $height;
$tmp = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($tmp, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
} else {
$tmp = $image;
}
imagejpeg($tmp, NULL, 85);
...@@ -14,6 +14,7 @@ else ...@@ -14,6 +14,7 @@ else
$last_timestamp = time()*1000; $last_timestamp = time()*1000;
// Saving annotation // Saving annotation
/*
if (isset($_POST['accepted']) OR isset($_POST['rejected'])) { if (isset($_POST['accepted']) OR isset($_POST['rejected'])) {
$result = $db->prepare('SELECT user_ID FROM user WHERE shibboleth=:shibboleth'); $result = $db->prepare('SELECT user_ID FROM user WHERE shibboleth=:shibboleth');
$result->execute(array('shibboleth' => $shibboleth)); $result->execute(array('shibboleth' => $shibboleth));
...@@ -33,17 +34,16 @@ if (isset($_POST['accepted']) OR isset($_POST['rejected'])) { ...@@ -33,17 +34,16 @@ if (isset($_POST['accepted']) OR isset($_POST['rejected'])) {
} else { } else {
$limit = 500; $limit = 500;
} }
*/
$limit = 500;
// Query for not annotated images // Query for not annotated images
$query = ' $query = '
SELECT thumbnail_ID,timestamp,path as photo_path,thumbnail_path,xmin,ymin,xmax,ymax SELECT photo_ID,timestamp
FROM suggestion FROM photo JOIN user USING(card_ID)
JOIN thumbnail USING(thumbnail_ID) JOIN photo USING(photo_ID)
JOIN user USING(user_ID)
WHERE shibboleth=:shibboleth WHERE shibboleth=:shibboleth
AND thumbnail_ID NOT IN (SELECT thumbnail_ID FROM annotation JOIN user USING(user_ID) WHERE shibboleth=:shibboleth) AND is_it_sure = 1
AND timestamp < :last_timestamp AND timestamp < :last_timestamp
GROUP BY thumbnail_ID
ORDER BY timestamp ASC ORDER BY timestamp ASC
LIMIT '.$limit; LIMIT '.$limit;
$result = $db->prepare($query); $result = $db->prepare($query);
...@@ -65,7 +65,6 @@ $day = $hungarian ? ...@@ -65,7 +65,6 @@ $day = $hungarian ?
class Burst { class Burst {
var $first_timestamp; var $first_timestamp;
var $last_timestamp; var $last_timestamp;
var $xmin,$ymin,$xmax,$ymax;
var $items = array(); var $items = array();
var $grouping_time = 3000; var $grouping_time = 3000;
...@@ -75,24 +74,12 @@ class Burst { ...@@ -75,24 +74,12 @@ class Burst {
} }
function check($new_item) { function check($new_item) {
// If less than 3 sec between the new item and the last item in that burst return $new_item['timestamp'] - $this->last_timestamp < $this->grouping_time;
// and center of the new frame is inside the previous frame
return ($new_item['timestamp'] - $this->last_timestamp < $this->grouping_time
AND $this->xmin < $new_item['xcenter'] AND $this->ymin < $new_item['ycenter']
AND $new_item['xcenter'] < $this->xmax AND $new_item['ycenter'] < $this->ymax);
} }
function add($new_item) { function add($new_item) {
$this->last_timestamp = $new_item['timestamp']; $this->last_timestamp = $new_item['timestamp'];
array_push($this->items, array( array_push($this->items, $new_item['photo_ID']);
'thumbnail_ID' => $new_item['thumbnail_ID'],
'photo_path' => $new_item['photo_path'],
'thumbnail_path' => $new_item['thumbnail_path'],
));
$this->xmin = $new_item['xmin'];
$this->ymin = $new_item['ymin'];
$this->xmax = $new_item['xmax'];
$this->ymax = $new_item['ymax'];
} }
function toArray() { function toArray() {
...@@ -111,23 +98,14 @@ class Burst { ...@@ -111,23 +98,14 @@ class Burst {
class BurstManager { class BurstManager {
var $burst_array = array(); var $burst_array = array();
var $last_timestamp; var $last_timestamp;
var $path_part_to_remove = '/home/csbotos/video/';
var $path_part_to_remove_length;
function __construct() {
$this->path_part_to_remove_length = strlen($this->path_part_to_remove);
}
function add($new_value) { function add($new_value) {
$this->last_timestamp = $new_value['timestamp']; $this->last_timestamp = $new_value['timestamp'];
$new_value['photo_path'] = substr($new_value['photo_path'],$this->path_part_to_remove_length);
$new_value['thumbnail_path'] = substr($new_value['thumbnail_path'],$this->path_part_to_remove_length);
$new_value['xcenter'] = ($new_value['xmin'] + $new_value['xmax']) / 2;
$new_value['ycenter'] = ($new_value['ymin'] + $new_value['ymax']) / 2;
foreach($this->burst_array as &$burst) foreach($this->burst_array as &$burst)
if ($burst->check($new_value)){ if ($burst->check($new_value)){
$burst->add($new_value); $burst->add($new_value);
return; } return;
}
array_push($this->burst_array, new Burst($new_value)); array_push($this->burst_array, new Burst($new_value));
} }
...@@ -151,5 +129,3 @@ die(json_encode(array( ...@@ -151,5 +129,3 @@ die(json_encode(array(
'last_timestamp' => $burstManager->last_timestamp, 'last_timestamp' => $burstManager->last_timestamp,
'result' => $result, 'result' => $result,
))); )));
ob_end_flush();
...@@ -106,4 +106,8 @@ label img { ...@@ -106,4 +106,8 @@ label img {
#image-wrapper { #image-wrapper {
margin-bottom: 3em; margin-bottom: 3em;
}
.template {
display: none;
} }
\ No newline at end of file
shibboleth = window.location.href.split("?")[1]; var shibboleth = window.location.href.split("?")[1];
language = language(); var language = language();
waitFor("jQuery", setup); waitFor("jQuery", setup);
var first_timestamp, last_timestamp;
function createPhoto(date,photoID) {
var img = $("#img-template > div").clone(true);
img.find(".lightbox").attr("href","../core/image.php?full_frame&" + photoID);
img.find("input").attr("id",photoID).attr("data-group",date);
img.find("label").attr("for",photoID);
img.find("img").attr("data-src","../core/image.php?thumbnail&" + photoID)
return img;
}
function receivePhotos(data) { function receivePhotos(data) {
var parsed = jsonParse(data); var parsed = jsonParse(data);
var photos = parsed['photos']; var photos = parsed['photos'];
var last_timestamp = parsed['last_timestamp']; last_timestamp = parsed['last_timestamp'];
var div = $(document.createElement('div')); var div = $(document.createElement('div'));
for (var date of Object.keys(photos).reverse()) { for (var date of Object.keys(photos).reverse()) {
var group_template = $("#img-group-template > div").clone(true); var group_template = $("#img-group-template > div").clone(true);
group_template.find("p").text(date); group_template.find("p").text(date);
group_template.find("a").attr("data-group",date); group_template.find("a").attr("data-group",date);
var img_burst = group_template.find(".img-burst"); var img_burst = group_template.find(".img-burst");
for (var photo of photos[date]) { for (var photoID of photos[date]) {
var img_template = $("#img-template > div").clone(true); img_burst.append(createPhoto(date,photoID));
img_template.find(".lightbox").attr("href","../img/" + photo["photo_path"]);
img_template.find("input").attr("id",photo["thumbnail_ID"]).attr("data-group",date);
img_template.find("label").attr("for",photo["thumbnail_ID"]);
img_template.find("img").attr("data-src","../img/"+photo["thumbnail_path"]+"&80")
img_burst.append(img_template);
} }
div.append(group_template); div.append(group_template);
} }
console.log(div);
$("#image-wrapper").append(div.children()); $("#image-wrapper").append(div.children());
$(":checkbox").prop("indeterminate", true); $(":checkbox").prop("indeterminate", true);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment