Commit 9c8d5049 authored by Oleg Dzhimiev's avatar Oleg Dzhimiev

+rating

parent b347ca49
...@@ -11,7 +11,7 @@ $(function(){ ...@@ -11,7 +11,7 @@ $(function(){
parseURL(); parseURL();
init_maps(); init_maps();
var url = 'list.php'; var url = 'list.php?rating='+SETTINGS.rating;
if (SETTINGS.showall){ if (SETTINGS.showall){
url += "?showall"; url += "?showall";
...@@ -34,6 +34,7 @@ $(function(){ ...@@ -34,6 +34,7 @@ $(function(){
}); });
var SETTINGS = { var SETTINGS = {
'rating':5,
'showall':false, 'showall':false,
'lat': 40.7233861, 'lat': 40.7233861,
'lng': -111.9328843, 'lng': -111.9328843,
...@@ -79,6 +80,7 @@ function parseURL(){ ...@@ -79,6 +80,7 @@ function parseURL(){
for (var i=1;i<parameters.length;i++) { for (var i=1;i<parameters.length;i++) {
switch (parameters[i][0]) { switch (parameters[i][0]) {
case "showall": SETTINGS.showall = true; break; case "showall": SETTINGS.showall = true; break;
case "rating": SETTINGS.rating = parseInt(parameters[i][1]); break;
case "lat": SETTINGS.lat = parseFloat(parameters[i][1]); break; case "lat": SETTINGS.lat = parseFloat(parameters[i][1]); break;
case "lng": SETTINGS.lng = parseFloat(parameters[i][1]); break; case "lng": SETTINGS.lng = parseFloat(parameters[i][1]); break;
case "zoom": SETTINGS.zoom = parseFloat(parameters[i][1]); break; case "zoom": SETTINGS.zoom = parseFloat(parameters[i][1]); break;
...@@ -346,7 +348,7 @@ function init_maps(){ ...@@ -346,7 +348,7 @@ function init_maps(){
var center = map.getCenter(); var center = map.getCenter();
var zoom = map.getZoom(); var zoom = map.getZoom();
window.history.pushState("", "x3d models index", "?lat="+center.lat+"&lng="+center.lng+"&zoom="+zoom); window.history.pushState("", "x3d models index", "?lat="+center.lat+"&lng="+center.lng+"&zoom="+zoom+"&rating="+SETTINGS.rating);
if (!BLOCK_MOVEEND){ if (!BLOCK_MOVEEND){
......
...@@ -104,6 +104,7 @@ function menu_init(){ ...@@ -104,6 +104,7 @@ function menu_init(){
reset_view_init(); reset_view_init();
align_init(); align_init();
work_with_kml_init(); work_with_kml_init();
save_rating_init();
editmode_init(); editmode_init();
$("#global_coordinates").on('click',function(){ $("#global_coordinates").on('click',function(){
...@@ -173,6 +174,37 @@ function work_with_kml_init(){ ...@@ -173,6 +174,37 @@ function work_with_kml_init(){
} }
function save_rating_init(){
$.ajax({
url: "store_rating.php?model="+SETTINGS.path,
complete: function(response){
var value = parseInt(response.responseText);
$("#model_rating").val(value);
// bind onchange
$("#model_rating").on('change',function(){
$.ajax({
url: "store_rating.php?model="+SETTINGS.path+"&rating="+$(this).val(),
complete:function(response){
var res = parseInt(response.responseText);
if (res==0){
$("#rstatus").css({color:"rgba(70,200,70,1)"}).html("stored");
$("#rstatus").show(0).delay(1000).fadeOut(250);
}else{
var msg = "no access";
if ((res==-1)||(res==-2)) msg = "no access";
if (res==-3) msg = "no access";
$("#rstatus").css({color:"rgba(200,70,70,1)"}).html("fail: "+msg);
$("#rstatus").show(0).delay(1000).fadeOut(250);
}
}
})
});
}
});
}
function editmode_init(){ function editmode_init(){
// the id is buried in the leaflet plugin // the id is buried in the leaflet plugin
......
...@@ -3,15 +3,26 @@ ...@@ -3,15 +3,26 @@
$base = "models"; $base = "models";
$THUMBNAME = "thumb.jpeg"; $THUMBNAME = "thumb.jpeg";
$RATINGFILE = "rating.txt";
$READMENAME = "README.txt"; $READMENAME = "README.txt";
// for htaccess
$SECRET_PATTERN = "/# public access/";
$showall = false; $showall = false;
$rating = false;
if (isset($_GET['rating'])){
$rating = intval($_GET['rating']);
}
$rating = get_allowed_rating($rating);
if (isset($_GET['showall'])){ if (isset($_GET['showall'])){
$showall = true; $showall = true;
} }
$models = selective_scandir($base,false); $models = selective_scandir($base,false,$rating);
$res = ""; $res = "";
foreach($models as $model){ foreach($models as $model){
...@@ -19,37 +30,43 @@ foreach($models as $model){ ...@@ -19,37 +30,43 @@ foreach($models as $model){
$model_path = "$base/$model"; $model_path = "$base/$model";
$thumb = "$model_path/$THUMBNAME"; $thumb = "$model_path/$THUMBNAME";
$versions = selective_scandir($model_path,$showall); $model_rating = get_model_rating("$model_path/$RATINGFILE");
// create thumb if ($model_rating>=$rating){
create_thumbnail($model_path,$versions,$thumb);
if (!is_file($thumb)){ $versions = selective_scandir($model_path,$showall,0);
$thumb="";
}
$res .= "<model name='$model' thumb='$thumb'>\n"; // create thumb
create_thumbnail($model_path,$versions,$thumb);
// read kml if (!is_file($thumb)){
$res .= "\t<map>\n".parse_kml("$base/$model/$model.kml")."\t</map>\n"; $thumb="";
}
foreach($versions as $version){ $res .= "<model name='$model' thumb='$thumb'>\n";
$res .= "\t<version name='$version'>\n"; // read kml
$res .= "\t<map>\n".parse_kml("$base/$model/$model.kml")."\t</map>\n";
$comments = "-"; foreach($versions as $version){
$readme = "$model_path/$version/$READMENAME";
if (is_file($readme)){
$comments = trim(file_get_contents($readme),"\t\n\r");
}
$res .= "\t\t<comments>$comments</comments>\n"; $res .= "\t<version name='$version'>\n";
$res .= "\t</version>\n"; $comments = "-";
$readme = "$model_path/$version/$READMENAME";
if (is_file($readme)){
$comments = trim(file_get_contents($readme),"\t\n\r");
}
} $res .= "\t\t<comments>$comments</comments>\n";
$res .= "</model>\n"; $res .= "\t</version>\n";
}
$res .= "</model>\n";
}
} }
...@@ -57,7 +74,7 @@ return_xml($res); ...@@ -57,7 +74,7 @@ return_xml($res);
//functions //functions
function selective_scandir($path,$showall){ function selective_scandir($path,$showall,$rating=5){
$results = Array(); $results = Array();
...@@ -91,6 +108,42 @@ function return_xml($str){ ...@@ -91,6 +108,42 @@ function return_xml($str){
} }
function get_model_rating($file){
if (is_file($file)){
$r = intval(trim(file_get_contents($file)));
}else{
$r = 0;
}
return $r;
}
function get_allowed_rating($r){
global $SECRET_PATTERN;
if (!is_file(".htaccess")) {
$r = $r;
}else{
$htaccess = file_get_contents(".htaccess");
$m = preg_match($SECRET_PATTERN,$htaccess);
// restrict to 1
if ($m) {
$r = 1;
}
}
return $r;
}
function create_thumbnail($path,$vpaths,$thumbname){ function create_thumbnail($path,$vpaths,$thumbname){
if (!is_file($thumbname)){ if (!is_file($thumbname)){
......
<?php
/*
*! -----------------------------------------------------------------------------**
*! FILE NAME : store_rating.php
*! REVISION : 1.0
*! DESCRIPTION: save changes to a rating file.
*! Copyright (C) 2017 Elphel, Inc.
*!
*! -----------------------------------------------------------------------------**
*! This program is free software: you can redistribute it and/or modify
*! it under the terms of the GNU General Public License as published by
*! the Free Software Foundation, either version 3 of the License, or
*! (at your option) any later version.
*!
*! This program is distributed in the hope that it will be useful,
*! but WITHOUT ANY WARRANTY; without even the implied warranty of
*! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
*! GNU General Public License for more details.
*!
*! You should have received a copy of the GNU General Public License
*! along with this program. If not, see <http://www.gnu.org/licenses/>.
*!
*! It means that the program's users have the four essential freedoms:
*!
*! * The freedom to run the program, for any purpose (freedom 0).
*! * The freedom to study how the program works, and change it to make it do what you wish (freedom 1).
*! Access to the source code is a precondition for this.
*! * The freedom to redistribute copies so you can help your neighbor (freedom 2).
*! * The freedom to distribute copies of your modified versions to others (freedom 3).
*!
*! By doing this you can give the whole community a chance to benefit from your changes.
*! Access to the source code is a precondition for this.
*! -----------------------------------------------------------------------------**
*/
require_once("call_filter.php");
$model = $_GET['model'];
$rating_file = "models/$model/rating.txt";
if (isset($_GET['rating'])){
$rating = $_GET['rating'];
}else{
if (is_file($rating_file)){
echo trim(file_get_contents($rating_file));
}else{
echo "0";
}
die();
}
if (!preg_match("/\//",$model)){
$result = file_put_contents($rating_file,$rating);
if (!$result) {
die("-1");
}else{
die("0");
}
}else{
die("-2");
}
?>
...@@ -180,6 +180,13 @@ Instructions: ...@@ -180,6 +180,13 @@ Instructions:
<div id='kmlstatus'></div> <div id='kmlstatus'></div>
</td> </td>
</tr> </tr>
<tr class='edit'>
<td>Model rating: </td>
<td><input id='model_rating' type='text' class='input donothide' value='0' /></td>
<td valign='middle'>
<div id='rstatus'></div>
</td>
</tr>
<!--<tr class='experimental'> <!--<tr class='experimental'>
<td> <td>
<button id='align_0' class='donothide'>Align0</button> <button id='align_0' class='donothide'>Align0</button>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment