diff --git a/about.php b/about.php new file mode 100755 index 0000000..105c8dd --- /dev/null +++ b/about.php @@ -0,0 +1,215 @@ + +
+ +
+

+

+
+
+

+
+
+

+
+
+
+
+
+

Alexander Busta

+
+
+ Alexander Busta +
+
+

+ +

+
+
+

+
+
+
+
+

Cesare de Cal

+
+
+ Cesare de Cal +
+
+

+
+ +

+
+
+

+
+
+
+
+

Edoardo de Cal

+
+
+ Edoardo de Cal +
+
+

+
+ +

+
+
+

+
+
+
+
+

Fabio Bottan

+
+
+ Fabio Bottan +
+
+

+
+ +

+
+
+

+
+
+
+
+

Marcelino Franchini

+
+
+ Marcelino Franchini +
+
+

+
+ +

+
+
+

+
+
+
+
+

Valerio Bozzolan

+
+
+ Valerio Bozzolan +
+
+

+
+ +

+
+
+

+
+
+
+
+
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Apache
Boz PHP - Another PHP Framework
Debian GNU/Linux
jQuery + jQuery UI
Leaflet
Materialize
Material Design Icons
MySQLRelational database management system
Open Data MISE
OpenStreetMap
OpenClipArt
PHP
Reveal.JS
+
+
+. + */ + html, body { height:100%; } #map { position:absolute; top:0; left:0; width:100%; height:100%; } #overworld { position:absolute; top:0; left:50px; z-index:100; margin-right:10px; } .leaflet-popup-content { font-family: "Roboto"; font-size:15px; } .prices td { padding:4px !important; white-space: nowrap; } #overworld .card-panel { padding: 2px 20px; } #overworld h1 { font-size:3.2rem; } #overworld-buttons { position:absolute; top:5px; left:50px; z-index:100; } b.station-counter { position:relative; width:50px; } diff --git a/facile.js b/facile.js old mode 100755 new mode 100644 index f6eb3a1..16fa5e3 --- a/facile.js +++ b/facile.js @@ -1,289 +1,326 @@ +/* + * Italian petrol pumps comparator - Project born (and winner) at hackaton Facile.it 2015 + * Copyright (C) 2015 Valerio Bozzolan, Marcelino Franchini, Fabio Mottan, Alexander Bustamente, Cesare de Cal, Edoardo de Cal + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + var map; var EUROS = 40; var errortooresults = true; var trovalatuazona = true; var nessunfornitore = true; var Impianti = { all: [], exists: function(id) { var i = 0; while(i < this.all.length && this.all[i++] !== id); return Impianti.all[i-1] === id; }, add: function(id) { this.all.push(id); } }; var Overworld = { $el: undefined, $action: undefined, visible: true, running: false, hide: function() { if(Overworld.running) { return; } Overworld.running = true; Overworld.$el.hide("drop", {direction: "up"}, "slow", function() { Overworld.$action.show("drop", {direction: "up"}, "fast", function() { Overworld.running = false; }); }); }, show: function() { if(Overworld.running) { return; } Overworld.running = true; map.closePopup(); Overworld.$el.find("input").val(""); Overworld.$action.hide("drop", {direction: "up"}, "slow", function() { Overworld.$el.show("drop", {direction: "up"}, "fast", function() { Overworld.$el.find("input").focus(); Overworld.running = false; }); }); } }; $(document).ready(function() { Overworld.$action = $("#overworld-buttons"); Overworld.$el = $("#overworld"); Overworld.$action.hide().click(function() { Overworld.show(); }); $("form").submit(function(event) { suggest_nominatim_addresses( $("input[name=search_address]").val() ); event.preventDefault(); }); map = L.map('map'); // create the tile layer with correct attribution var osmUrl='http://{s}.tile.osm.org/{z}/{x}/{y}.png'; - var osmAttrib='Map data Facile.it © OpenStreetMap contributors'; + var osmAttrib='© OpenStreetMap contributors'; var osm = new L.TileLayer(osmUrl, {minZoom: 8, maxZoom: 17, attribution: osmAttrib}); map.addLayer(osm); map.setView([45.49, 9.21], 15); map.on("moveend", function() { getMarkersInBounds(); return true; }); map.on("popupopen", function() { Overworld.hide(); }); fitDocument(); map.locate({setView: true, enableHighAccuracy: true, maxZoom: 16}); map.on("locationfound", function(e) { var radius = e.accuracy / 2; enfatizeLatLng(e.latlng, 2000); }); map.on("locationerror", function(e) { Materialize.toast("Posizione non disponibile. Zomma!", 3000); }); getMarkersInBounds(); }); +function toast(s) { + Materialize.toast(s, 3000); +} + function getMarkersInBounds(preCallback, postCallback) { var zoom = map.getZoom(); if(zoom < 13) { - trovalatuazona && Materialize.toast("Trova la tua zona, zomma!", 3000); + trovalatuazona && toast( L10N.pleaseZoomIn ); trovalatuazona = false; return; } trovalatuazona = true; var bounds = map.getBounds(); var data = { lat_n: bounds.getNorth(), lat_s: bounds.getSouth(), lng_w: bounds.getWest(), lng_e: bounds.getEast() }; $.getJSON("/api/bounds.php", data, function(json) { if(json.error) { - errortooresults && Materialize.toast("Vedo molte stazioni. Zomma per scoprirle!", 2000); + errortooresults && toast( L10N.errorTooStations ); errortooresults = false; return; } errortooresults = true; if(json.length === 0) { - nessunfornitore && Materialize.toast("Nessun fornitore in questa zona", 2000); + nessunfornitore && toast( L10N.noStations ); nessunfornitore = false; return; } nessunfornitore = true; if(json.length > 90) { - Materialize.toast("Vedo " + json.length + " risultati! Zooma per scoprirli", 2000); + toast( L10N.tooStations.formatUnicorn({n: json.length}) ); return; } if(preCallback && preCallback(bounds, json) === false ) { return; } var minPriceId = 0; var minPrice = 999.0; for(var i=0; i" + json[i].gestore + ":
"; + var txt = L10N.litersEuros.formatUnicorn({euros: EUROS, station: json[i].gestore}); + txt += ":
"; for(var j=0; j"; } else { txt += ""; } txt += ""; txt += ""; txt += ""; } txt += "
" + litres + " Lper il " + json[i].prezzi[j].descCarburante + ""; if(json[i].prezzi[j].isSelf === "1") { txt += "(self)"; } else { txt += ""; } txt += "
"; - txt += "

+ PREFERITI"; + txt += "

+ " + L10N.actionFavorites + ""; txt += "segnala errore

"; L.marker([json[i].latitudine, json[i].longitudine], { bounceOnAdd: true, bounceOnAddOptions: {duration: 500, height: 100}, bounceOnAddCallback: function() {} }).bindPopup(txt).addTo(map).options.idImpianto = json[i].idImpianto; } postCallback && postCallback(bounds, json); }); } function suggest_nominatim_addresses(query) { $.ajax({ url: "https://nominatim.openstreetmap.org/search", jsonp: "nominatimJsonp", dataType: "jsonp", data: { q: query, format: "json", json_callback: "nominatimJsonp" } }); } function nominatimJsonp(json) { var $searchResults = $("#modal-search-addr-results"); var $list = $searchResults.find("ol").empty(); if(json.length > 0) { for(i=0; i") .append( $('') .text(json[i].display_name) .data("latLng", {lat: json[i].lat, lng: json[i].lon}) .data("bounds", json[i].boundingbox) .click(function(event) { $searchResults.closeModal(); var latLng = $(this).data("latLng"); var bounds = $(this).data("bounds"); var adaptedBounds = [ [bounds[0], bounds[3]], [bounds[1], bounds[2]] ]; map.fitBounds( adaptedBounds ); getMarkersInBounds(); Overworld.hide(); event.preventDefault(); }) ) .append( $("
") ) .append( $("") .text(json[i].licence) ) ); } // Result links $searchResults.find("a").click(function() { $searchResults.closeModal(); }); } else { - $list.append( $("
  • ").text( "Nessun indirizzo trovato" ) ); + $list.append( $("
  • ").text( L10N.noAddressFound ) ); } $searchResults.openModal(); } function enfatizeLatLng(latLng, duration, radius) { duration = duration || 2000; radius = radius || 100; var circle = L.circle(latLng, radius).addTo(map); window.setTimeout(function () { map.removeLayer(circle); }, duration); } function fitDocument() { var w = $("body").width(); var h = $("body").height(); $("#map").width( w ).height( h ); } +// http://stackoverflow.com/questions/610406/javascript-equivalent-to-printf-string-format +String.prototype.formatUnicorn = function() { + var str = this.toString(); + if(!arguments.length) { + return str; + } + var args = typeof arguments[0], + args = (("string" == args || "number" == args) ? arguments : arguments[0]); + for(var arg in args) { + str = str.replace(RegExp("\\{" + arg + "\\}", "gi"), args[arg]); + } + return str; +} + $(window).resize(function() { // jQuery's windowResize is a bit crazy setTimeout(fitDocument, 500); setTimeout(fitDocument, 2000); setTimeout(fitDocument, 4000); }); $(document).on("click", ".add-favorites", function() { - Materialize.toast("Aggiunto ai tuoi preferiti. Facile!", 3000); + toast( L10N.addedToFavorites ); }); $(document).on("click", ".segnala-errore", function() { - Materialize.toast("La tua segnalazione è preziosa. Grazie!", 3000); + toast( L10N.errorSent ); }); diff --git a/favicon.ico b/favicon.ico deleted file mode 100755 index 9493889..0000000 Binary files a/favicon.ico and /dev/null differ diff --git a/import/import.php b/import/import.php index 1afb639..7cb06f7 100755 --- a/import/import.php +++ b/import/import.php @@ -1,148 +1,179 @@ . + */ + +/* + * Manually download data from Ministero dello Sviluppo Economico + * http://www.sviluppoeconomico.gov.it/index.php/it/open-data/elenco-dataset/2032336-carburanti-prezzi-praticati-e-anagrafica-degli-impianti + * + * Files: + * http://www.sviluppoeconomico.gov.it/images/exportCSV/prezzo_alle_8.csv + * http://www.sviluppoeconomico.gov.it/images/exportCSV/anagrafica_impianti_attivi.csv + * + * The files are licensed under the terms of the Italian Open Data License v2.0 + * http://www.dati.gov.it/iodl/2.0/ + */ + +// Uncomment +die("No."); define('FILENAME_STATIONS', 'anagrafica_impianti_attivi.csv'); define('FILENAME_PRICES', 'prezzo_alle_8.csv'); require '../load.php'; -http_json_header(); - $db->query("TRUNCATE {$db->getTable('price')}"); $db->query("TRUNCATE {$db->getTable('station')}"); $error_code = null; $error_message = null; $comuni = $db->getResults("SELECT * FROM {$db->getTable('comune')}"); $provincie = $db->getResults("SELECT * FROM {$db->getTable('provincia')}"); function get_comune_ID($comune_uid, $comune_name, $provincia_name) { global $db, $comuni; $n = count($comuni); $i = 0; while($i<$n && $comuni[$i++]->comune_uid !== $comune_uid); $i--; if($i>=0 && $i<$n && $comuni[$i]->comune_uid === $comune_uid) { return $comuni[$i]->comune_ID; } $db->insertRow('comune', [ new DBCol('comune_uid', $comune_uid, 's'), new DBCol('comune_name', $comune_name, 's') ] ); $comuni[] = $db->getRow( sprintf( "SELECT * FROM {$db->getTable('comune')} WHERE comune_ID = '%d'", $db->getLastInsertedID() ) ); $db->insertRow('rel_provincia_comune', [ new DBCol( 'provincia_ID', get_provincia_ID( generate_slug($provincia_name), $provincia_name ), 'd' ), new DBCol('comune_ID', $comuni[$n]->comune_ID, 'd') ] ); return $comuni[$n]->comune_ID; } function get_provincia_ID($provincia_uid, $provincia_name) { global $db, $provincie; $n = count($provincie); $i = 0; while($i<$n && $provincie[$i++]->provincia_uid !== $provincia_uid); $i--; if($i>=0 && $i<$n && $provincie[$i]->provincia_uid === $provincia_uid) { return $provincie[$i]->provincia_ID; } $db->insertRow('provincia', [ new DBCol('provincia_uid', $provincia_uid, 's'), new DBCol('provincia_name', $provincia_name, 's') ] ); $provincie[] = $db->getRow( sprintf( "SELECT * FROM {$db->getTable('provincia')} WHERE provincia_ID = '%d'", $db->getLastInsertedID() ) ); return $provincie[$n]->provincia_ID; } try { if( ! file_exists(FILENAME_STATIONS) ) { throw new Exception( _("File delle stazioni non trovato"), 1 ); } if( ! $handle = fopen(FILENAME_STATIONS, 'r') ) { throw new Exception( _("Impossibile aprire il file delle stazioni"), 2 ); } // Waste first 2 lines fgetcsv($handle); fgetcsv($handle); while( $data = fgetcsv($handle, 512, ';') ) { $db->insertRow('station', [ new DBCol('idImpianto', intval($data[0]), 'd'), new DBCol('gestore', $data[1], 's'), new DBCol('bandiera', $data[2], 's'), new DBCol('tipoImpianto', $data[3], 's'), new DBCol('nomeImpianto', $data[4], 's'), new DBCol('indirizzo', $data[5], 's'), new DBCol('latitudine', floatval($data[8]), 'f'), new DBCol('longitudine', floatval($data[9]), 'f'), new DBCol( 'comune_ID', get_comune_ID( generate_slug($data[6]), $data[6], $data[7] ), 'd' ) ] ); } fclose($handle); // Prices if( ! file_exists(FILENAME_PRICES) ) { throw new Exception( _("File dei prezzi non trovato"), 3 ); } if( ! $handle = fopen(FILENAME_PRICES, 'r') ) { throw new Exception( _("Impossibile aprire il file dei prezzi"), 4 ); } // Waste first 2 lines fgetcsv($handle); fgetcsv($handle); while( $data = fgetcsv($handle, 255, ';') ) { $db->insertRow('price', [ new DBCol('idImpianto', intval($data[0]), 'd'), new DBCol('descCarburante', $data[1], 's'), new DBCol('prezzo', floatval($data[2]), 'f'), new DBCol('isSelf', intval($data[3]), 'd'), new DBCol('dtComu', $data[4], 's') ] ); } fclose($handle); } catch(Exception $e) { $error_code = $e->getCode(); $error_message = $e->getMessage(); } +http_json_header(); + echo json_encode( [ 'error' => $error_code, 'errorMessage' => $error_message ] ); diff --git a/includes/footer.php b/includes/footer.php index cb223c9..c0daf48 100755 --- a/includes/footer.php +++ b/includes/footer.php @@ -1,24 +1,25 @@ . */ function get_footer($page = null, $args = null) { + load_module('theme-footer'); ?> - . + */ + +/** + * It do what it's written. + * @param float $latitude1 + * @param float $longitude1 + * @param float $latitude2 + * @param float $longitude2 + * @return float Meters + */ function get_distance_between_coordinates($latitude1, $longitude1, $latitude2, $longitude2) { $theta = $longitude1 - $longitude2; $distance = sin(deg2rad($latitude1)) * sin(deg2rad($latitude2)) + ( cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)) ); $distance = acos($distance); $distance = rad2deg($distance) * 60 * 1.1515; $distance = $distance * 1609.344; // To meters return $distance; } -/** - * Retrieve a range of poi. - * - * I monstrously speed-up performance filtering by a simple square radius - * from the MySQL side and stripping the surplus from PHP. - * - * @param $latitude float - * @param $longitude float - * @param $radius float meters -*/ -function get_pois_in_radius($lat, $lon, $radius) { - $comparable_radius = $radius / (111000); // 111Km are ~ 1° +function get_in_touch($url, $who) { + return HTML::a($url, mdi_icon('perm_contact_calendar') . _("Entra in contatto"), sprintf( _("Mettiti in contatto con %s"), $who ), 'waves-effect waves-teal btn'); +} - // Filter poi in MySQL with a simple square margin - $max_lat = $lat + $comparable_radius; - $min_lat = $lat - $comparable_radius; - $max_lon = $lon + $comparable_radius; - $min_lon = $lon - $comparable_radius; - $results = $GLOBALS['db']->getResults( $sql = sprintf( - "SELECT station.idImpianto, station.gestore, station.latitudine, station.longitudine FROM station WHERE " . - "station.latitudine BETWEEN %f AND %f AND " . - "station.longitudine BETWEEN %f AND %f", - $min_lat, - $max_lat, - $min_lon, - $max_lon - )); +function legal_notes($url, $license, $project) { + return HTML::a($url, $license, sprintf( _("Informazioni legali su %s"), $project ), 'waves-effect waves-teal btn-flat' ); +} - // Stripping the surplus out the circle radius - $filtered = array(); - $n = count($results); - for($i=0; $ilatitudine; - $result_lng = $results[$i]->longitudine; - if(get_distance_between_coordinates($lat, $lon, $result_lat, $result_lng) <= $radius) { - $filtered[] = $results[$i]; - unset($results[$i]); - } - } - return $filtered; +function mdi_icon($uid, $class = 'left') { + return "$uid"; } diff --git a/includes/header.php b/includes/header.php index 100005a..cd81a7e 100755 --- a/includes/header.php +++ b/includes/header.php @@ -1,100 +1,65 @@ . */ function get_header($uid, $args = array()) { - $args = merge_args_defaults( - $args, - [ - 'theme' => 'default' - ] - ); + $args = merge_args_defaults($args, [ + 'theme' => 'default' + ] ); switch($args['theme']) { case 'default': enqueue_css('materialize'); enqueue_css('materialize.icons'); - enqueue_css('leaflet'); - enqueue_css('my-facile'); enqueue_js('jquery'); - enqueue_js('jquery.ui'); - enqueue_js('leaflet'); - enqueue_js('leaflet.bouncemarker'); enqueue_js('materialize'); - enqueue_js('my-facile'); break; } - $menuEntry = get_menu_entry($uid); - $menuEntry || error( sprintf( - _("Il menu '%s' non esiste"), - $uid - ) ); - - $title = $menuEntry->extra['title']; - $desc = $menuEntry->extra['desc']; - header("Content-Type: text/html; charset=utf-8"); ?> - <?php echo SITE_NAME ?> - + <?php echo SITE_NAME ?> - <?php echo get_menu_entry($uid)->name ?> + + + -
    -
    -

    url, - $title, - $desc, - 'orange-text' - ) ?>

    -
    url, - $title, - $desc, - 'orange-text' - ) ?>
    -

    getValue( - "SELECT COUNT(*) as count FROM station", - 'count' - ), - HTML::property('class', 'station-counter') - ) - ) ?>
    - Ultimo aggiornamento: 4 ore fa! -

    -
    -
    - navigation - -
    -
    -
    -
    -
    " . HTML::a( + $menuEntry->url, + $menuEntry->name, + $menuEntry->getExtra('description') + ) . "\n"; +} diff --git a/index.php b/index.php index 671a908..d3bf54a 100755 --- a/index.php +++ b/index.php @@ -1,31 +1,93 @@ . */ +// The map + require 'load.php'; -get_header('home'); +enqueue_css('leaflet'); +enqueue_css('my-facile'); +enqueue_js('jquery.ui'); +enqueue_js('leaflet'); +enqueue_js('leaflet.bouncemarker'); +enqueue_js('my-facile'); + +get_header('map'); ?> +
    +
    +

    +
    +

    getValue( + "SELECT COUNT(*) as count FROM station", + 'count' + ), + HTML::property('class', 'station-counter') + ) + ) ?> +

    +
    +
    + navigation + +
    +
    +
    +
    +
    + . */ -// Lasciate questo file intonso per ora +// Customizing Boz PHP - Another PHP framework + +define('SITE_NAME', _("F***** Carburanti") ); +define('SITE_DESCRIPTION', _("Confronta i prezzi dei carburanti") ); define('INCLUDES', 'includes'); define('MATERIALIZE', INCLUDES . _ . 'materialize'); define('JQUERY', INCLUDES . _ . 'jquery'); define('LEAFLET', INCLUDES . _ . 'leaflet'); -define('SITE_NAME', 'Facile Carburanti'); register_js( 'jquery', URL . _ . JQUERY . '/jquery-2.1.4.min.js' ); register_js( 'jquery.ui', URL . _ . INCLUDES . '/jquery-ui/jquery-ui.min.js' ); register_js( 'materialize', URL . _ . MATERIALIZE . '/js/materialize.min.js' ); register_js( 'leaflet', URL . _ . LEAFLET . '/leaflet.js' ); register_js( 'leaflet.bouncemarker', URL . _ . INCLUDES . '/leaflet.bouncemarker/bouncemarker.js' ); register_js( 'my-facile', URL . '/facile.js' ); register_css( 'materialize', URL . _ . MATERIALIZE . '/css/materialize.min.css' ); register_css( 'leaflet', URL . _ . LEAFLET . '/leaflet.css' ); register_css( 'my-facile', URL . '/facile.css' ); register_css( 'materialize.icons', 'https://fonts.googleapis.com/icon?family=Material+Icons' ); add_menu_entries([ new MenuEntry( - 'home', + 'map', URL, - _("Home"), - null, [ - 'title' => SITE_NAME, - 'desc' => _("Confronta e scegli il miglior prezzo") - ] + _("La mappa") + ), + new MenuEntry( + 'about', + URL . '/about.php', + _("Informazioni sulla piattaforma") ) ]); require ABSPATH . _ . INCLUDES . _ . '/header.php'; require ABSPATH . _ . INCLUDES . _ . '/footer.php'; require ABSPATH . _ . INCLUDES . _ . '/functions.php';