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

+rating

parent b347ca49
Loading
Loading
Loading
Loading
+4 −2
Original line number Diff line number Diff line
@@ -11,7 +11,7 @@ $(function(){
    parseURL();
    init_maps();

    var url = 'list.php';
    var url = 'list.php?rating='+SETTINGS.rating;

    if (SETTINGS.showall){
      url += "?showall";
@@ -34,6 +34,7 @@ $(function(){
});

var SETTINGS = {
  'rating':5,
  'showall':false,
  'lat': 40.7233861,
  'lng': -111.9328843,
@@ -79,6 +80,7 @@ function parseURL(){
    for (var i=1;i<parameters.length;i++) {
        switch (parameters[i][0]) {
            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 "lng":     SETTINGS.lng  = parseFloat(parameters[i][1]); break;
            case "zoom":    SETTINGS.zoom = parseFloat(parameters[i][1]); break;
@@ -346,7 +348,7 @@ function init_maps(){
    var center = map.getCenter();
    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){

+32 −0
Original line number Diff line number Diff line
@@ -104,6 +104,7 @@ function menu_init(){
    reset_view_init();
    align_init();
    work_with_kml_init();
    save_rating_init();
    editmode_init();

    $("#global_coordinates").on('click',function(){
@@ -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(){

  // the id is buried in the leaflet plugin
+75 −22
Original line number Diff line number Diff line
@@ -3,15 +3,26 @@
$base = "models";

$THUMBNAME = "thumb.jpeg";
$RATINGFILE = "rating.txt";
$READMENAME = "README.txt";

// for htaccess
$SECRET_PATTERN = "/# public access/";

$showall = false;
$rating = false;

if (isset($_GET['rating'])){
  $rating = intval($_GET['rating']);
}

$rating = get_allowed_rating($rating);

if (isset($_GET['showall'])){
  $showall = true;
}

$models = selective_scandir($base,false);
$models = selective_scandir($base,false,$rating);
$res = "";

foreach($models as $model){
@@ -19,7 +30,11 @@ foreach($models as $model){
    $model_path = "$base/$model";
    $thumb = "$model_path/$THUMBNAME";

    $versions = selective_scandir($model_path,$showall);
    $model_rating = get_model_rating("$model_path/$RATINGFILE");

    if ($model_rating>=$rating){

      $versions = selective_scandir($model_path,$showall,0);

      // create thumb
      create_thumbnail($model_path,$versions,$thumb);
@@ -53,11 +68,13 @@ foreach($models as $model){

    }

}

return_xml($res);

//functions

function selective_scandir($path,$showall){
function selective_scandir($path,$showall,$rating=5){

    $results = Array();

@@ -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){

    if (!is_file($thumbname)){

store_rating.php

0 → 100644
+67 −0
Original line number Diff line number Diff line
<?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");

}

?>
+7 −0
Original line number Diff line number Diff line
@@ -180,6 +180,13 @@ Instructions:
                      <div id='kmlstatus'></div>
                    </td>
                </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'>
                    <td>
                      <button id='align_0' class='donothide'>Align0</button>