diff --git a/.bzrignore b/.bzrignore index dd91689..ae1f935 100644 --- a/.bzrignore +++ b/.bzrignore @@ -1,3 +1,8 @@ +# Boz-PHP - Another PHP Framework configuration file load.php + +# MISE files *.csv + +# GNU Gettext binary files *.mo diff --git a/README.md b/README.md index 9ef20df..072ac18 100755 --- a/README.md +++ b/README.md @@ -1,43 +1,47 @@ # Italian petrol pumps comparator ![Italian petrol pumps comparator](http://fuel.reyboz.it/images/fuel-64px.png) This web app allows you to list in a map and sort all fuel suppliers who are in a particular area, also it provides the current prices on every suppliers. We have engineered this solution in a Hackathon that was sponsored by *Facile.it*, an Italian price comparator. This submission **won the competition**. ## Use Use the http://fuel.reyboz.it online mirror. It has data updated on a daily basis. ## More about Heroes and original technologies in the [/about.php](http://fuel.reyboz.it/about.php) page of the online mirror. ## Hacking Clone the source code using Bazaar: bzr clone lp:it-fuel-stations-comparator ## Installation +Have GNU/Linux, PHP and MySQL/MariaDB working. + This project is built over the [Boz-PHP - Another PHP framework](https://github.com/valerio-bozzolan/boz-php-another-php-framework). Install it in your `/usr/share`: bzr branch lp:boz-php-another-php-framework /usr/share/boz-php-another-php-framework -After that you only have to rename and fill the `load-sample.php` to `load.php` and import in MySQL/MariaDB the `database-schema.sql` from the `installation` folder. +Import in MySQL/MariaDB the `database-schema.sql` from the `installation` folder. + +Also in the `installation` folder copy the `load-sample.php` in the root folder as `load.php` and fill with your MySQL/MariaDB credentials. ## Import data from MISE Please download data from the Italian [Ministero dello Sviluppo Economico](http://www.sviluppoeconomico.gov.it/index.php/it/open-data/elenco-dataset/2032336-carburanti-prezzi-praticati-e-anagrafica-degli-impianti): * http://www.sviluppoeconomico.gov.it/images/exportCSV/prezzo_alle_8.csv * http://www.sviluppoeconomico.gov.it/images/exportCSV/anagrafica_impianti_attivi.csv They are released under the terms of the Italian [Open Data License v2.0](http://www.dati.gov.it/iodl/2.0/). -The `cli/import.php` can import them into your DB: +The `cli/import-mise.php` can import them into your DB: - php ./cli/import.php anagrafica_impianti_attivi.csv prezzo_alle_8.csv + php ./cli/import-mise.php anagrafica_impianti_attivi.csv prezzo_alle_8.csv ## Pull requests Push in Launchpad: https://code.launchpad.net/it-fuel-stations-comparator ## License This is a **Free** as in **Freedom** project. It comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under the terms of the **GNU Affero General Public License v3+**. diff --git a/api/bounds.php b/api/bounds.php index 31b5a22..ce05070 100755 --- a/api/bounds.php +++ b/api/bounds.php @@ -1,76 +1,76 @@ . */ require '../load.php'; $results = array(); if( isset( $_GET['lat_n'], $_GET['lat_s'], $_GET['lng_e'], $_GET['lng_w'] ) ) { $lat_n = & $_GET['lat_n']; $lat_s = & $_GET['lat_s']; $lng_e = & $_GET['lng_e']; $lng_w = & $_GET['lng_w']; $results = $db->getResults( sprintf( "SELECT station.station_ID, station.station_lat, station.station_lon, " . "stationowner.stationowner_uid, stationowner.stationowner_name " . "FROM {$db->getTables('station', 'stationowner')} " . "WHERE station.station_lat BETWEEN %f AND %f " . "AND station.station_lon BETWEEN %f AND %f " . "AND station.stationowner_ID = stationowner.stationowner_ID", $lat_s, $lat_n, $lng_w, $lng_e ), 'Station' ); $n_results = count( $results ); $results->error = $n_results > 90; if(! $results->error) { // Get prices for($i=0; $i<$n_results; $i++) { $results[$i]->prices = $db->getResults( sprintf( "SELECT DISTINCT price.price_value, price.price_self, " . "fuel.fuel_uid, fuel.fuel_name " . "FROM {$db->getTables('price', 'fuel')} " . "WHERE price.station_ID = %d " . "AND price.fuel_ID = fuel.fuel_ID " . "ORDER BY price.price_value", - $results[$i]->idImpianto + $results[$i]->station_ID ), 'Price' ); } } } http_json_header(); echo json_encode( $results, isset( $_GET['pretty'] ) ? JSON_PRETTY_PRINT : 0 ); diff --git a/cli/import-functions.php b/cli/import-mise-functions.php similarity index 68% rename from cli/import-functions.php rename to cli/import-mise-functions.php index ed1a612..4bdf467 100755 --- a/cli/import-functions.php +++ b/cli/import-mise-functions.php @@ -1,275 +1,224 @@ . */ -/** - * Fu**ing increase performance - */ -function dichotomic_property_in_array($heystack, $needle, $compare_field, $return_existing_field = null, & $i) { - if( $return_existing_field === null ) { - $return_existing_field = $compare_field; - } - - $i = 0; - $inf = 0; - $n = count($heystack); - $sup = $n - 1; - $val = null; - - while($inf <= $sup) { - $i = (int) ( ($inf + $sup) / 2 ); - $val = $heystack[$i]->{$compare_field}; - - if( $val === $needle ) { - return $heystack[$i]->{$return_existing_field}; - } elseif($needle > $val) { - $inf = $i + 1; - } else { - $sup = $i - 1; - } - } - - if($val !== null && $needle > $val) { - // Please insert after this - $i++; - } - - return false; -} - -/* - * Insert an element in an array maintaining ordered indexes - * Assuming 0 < $here < count($heystack) - */ -function insert_here(& $heystack, $insert, $here) { - $n = count($heystack); - for($i=$n; $i>$here; $i--) { - $heystack[$i] = $heystack[$i-1]; +function indexed_array($rows, $property_index, $property_return) { + $indexed = []; + foreach($rows as $row) { + $indexed[ $row->{$property_index} ] = $row->{$property_return}; } - $heystack[ $here ] = $insert; + return $indexed; } function get_station_ID($station_miseID, $station_name = null, $station_type = null, $station_address = null, $station_lat = null, $station_lon = null, $comune_ID = null, $stationowner_ID = null, $fuelprovider_ID = null) { global $db, $stations; - $station_ID = dichotomic_property_in_array($stations, $station_miseID, 'station_miseID', 'station_ID', $here); - if($station_ID !== false) { - return $station_ID; + if( isset( $stations[ $station_miseID ] ) ) { + return $stations[ $station_miseID ]; } if( $station_name === null ) { throw new Exception( _("La stazione miseID %d doveva essere già stata inserita"), $station_miseID ); } if($station_type === 'Altro') { $station_type = 'ALTRO'; } elseif($station_type === 'Strada Statale') { $station_type = 'STRADA_STATALE'; } elseif($station_type === 'Autostradale') { $station_type = 'AUTOSTRADALE'; } else { throw new Exception( sprintf( "Tipo di stazione non prevista: %s", esc_html( $station_type ) ) ); } $db->insertRow('station', [ new DBCol('station_miseID', $station_miseID, 'd'), new DBCol('station_name', $station_name, 's'), new DBCol('station_type', $station_type, 's'), new DBCol('station_address', $station_address, 's'), new DBCol('station_lat', $station_lat, 'f'), new DBCol('station_lon', $station_lon, 'f'), new DBCol('comune_ID', $comune_ID, 'd'), new DBCol('stationowner_ID', $stationowner_ID, 'd'), new DBCol('fuelprovider_ID', $fuelprovider_ID, 'd') ] ); $station = $db->getRow( sprintf( "SELECT station_ID, station_miseID " . "FROM {$db->getTable('station')} " . "WHERE station_ID = %d", $db->getLastInsertedID() ), 'Station' ); - insert_here($stations, $station, $here); - - return $station->station_ID; + return $stations[ $station->station_miseID ] = $station->station_ID; } function get_comune_ID($comune_uid, $comune_name, $provincia_name) { global $db, $comuni; - $comune_ID = dichotomic_property_in_array($comuni, $comune_uid, 'comune_uid', 'comune_ID', $here); - if($comune_ID !== false) { - return $comune_ID; + if( isset( $comuni[ $comune_uid ] ) ) { + return $comuni[ $comune_uid ]; } $db->insertRow('comune', [ new DBCol('comune_uid', $comune_uid, 's'), new DBCol('comune_name', $comune_name, 's') ] ); $comune = $db->getRow( sprintf( "SELECT comune_ID, comune_uid " . "FROM {$db->getTable('comune')} " . "WHERE comune_ID = %d", $db->getLastInsertedID() ), 'Comune' ); - insert_here($comuni, $comune, $here); - $db->insertRow('rel_provincia_comune', [ new DBCol( 'provincia_ID', get_provincia_ID( generate_slug($provincia_name), $provincia_name ), 'd' ), new DBCol('comune_ID', $comune->comune_ID, 'd') ] ); - return $comune->comune_ID; + return $comuni[ $comune->comune_uid ] = $comune->comune_ID; } function get_fuelprovider_ID($fuelprovider_uid, $fuelprovider_name) { global $db, $fuelproviders; - $fuelprovider_ID = dichotomic_property_in_array($fuelproviders, $fuelprovider_uid, 'fuelprovider_uid', 'fuelprovider_ID', $here); - if($fuelprovider_ID !== false) { - return $fuelprovider_ID; + if( isset( $fuelproviders[ $fuelprovider_uid ] ) ) { + return $fuelproviders[ $fuelprovider_uid ]; } $db->insertRow('fuelprovider', [ new DBCol('fuelprovider_uid', $fuelprovider_uid, 's'), new DBCol('fuelprovider_name', $fuelprovider_name, 's') ] ); $fuelprovider = $db->getRow( sprintf( "SELECT fuelprovider_ID, fuelprovider_uid " . "FROM {$db->getTable('fuelprovider')} " . "WHERE fuelprovider_ID = %d", $db->getLastInsertedID() ), 'Fuelprovider' ); - insert_here($fuelproviders, $fuelprovider, $here); - - return $fuelprovider->fuelprovider_ID; + return $fuelproviders[ $fuelprovider->fuelprovider_uid ] = $fuelprovider->fuelprovider_ID; } + function get_stationowner_ID($stationowner_uid, $stationowner_name) { global $db, $stationowners; + if( isset( $stationowners[ $stationowner_uid ] ) ) { + return $stationowners[ $stationowner_uid ]; + } + // Lol if( ($pos = strpos($stationowner_name, ' IL REGISTRO IMPRESE NON GARANTISCE') ) !== false ) { $stationowner_name = substr($stationowner_name, 0, $pos); $stationowner_uid = generate_slug( $stationowner_name ); $stationowner_note = substr($stationowner_name, $pos); } else { $stationowner_note = null; } - $stationowner_ID = dichotomic_property_in_array($stationowners, $stationowner_uid, 'stationowner_uid', 'stationowner_ID', $here); - if($stationowner_ID !== false) { - return $stationowner_ID; + // Another check + if( isset( $stationowners[ $stationowner_uid ] ) ) { + return $stationowners[ $stationowner_uid ]; } $db->insertRow('stationowner', [ new DBCol('stationowner_uid', $stationowner_uid, 's'), new DBCol('stationowner_name', $stationowner_name, 's'), new DBCol('stationowner_note', $stationowner_note, 'snull') ] ); $stationowner = $db->getRow( sprintf( "SELECT stationowner_ID, stationowner_uid " . "FROM {$db->getTable('stationowner')} " . "WHERE stationowner_ID = %d", $db->getLastInsertedID() ), 'Stationowner' ); - insert_here($stationowners, $stationowner, $here); - - return $stationowner->stationowner_ID; + return $stationowners[ $stationowner->stationowner_uid ] = $stationowner->stationowner_ID;; } function get_fuel_ID($fuel_uid, $fuel_name) { global $db, $fuels; - $fuel_ID = dichotomic_property_in_array($fuels, $fuel_uid, 'fuel_uid', 'fuel_ID', $here); - if($fuel_ID !== false) { - return $fuel_ID; + if( isset( $fuels[ $fuel_uid ] ) ) { + return $fuels[ $fuel_uid ]; } $db->insertRow('fuel', [ new DBCol('fuel_uid', $fuel_uid, 's'), new DBCol('fuel_name', $fuel_name, 's') ] ); $fuel = $db->getRow( sprintf( "SELECT fuel_ID, fuel_uid " . "FROM {$db->getTable('fuel')} " . "WHERE fuel_ID = %d", $db->getLastInsertedID() ), 'Fuel' ); - insert_here($fuels, $fuel, $here); - - return $fuel->fuel_ID; + return $fuels[ $fuel->fuel_uid ] = $fuel->fuel_ID; } function get_provincia_ID($provincia_uid, $provincia_name) { global $db, $provincie; - $provincia_ID = dichotomic_property_in_array($provincie, $provincia_uid, 'provincia_uid', 'provincia_ID', $here); - if($provincia_ID !== false) { - return $provincia_ID; + if( isset( $provincie[ $provincia_uid ] ) ) { + return $provincie[ $provincia_uid ]; } $db->insertRow('provincia', [ new DBCol('provincia_uid', $provincia_uid, 's'), new DBCol('provincia_name', $provincia_name, 's') ] ); $provincia = $db->getRow( sprintf( "SELECT provincia_ID, provincia_uid " . "FROM {$db->getTable('provincia')} " . "WHERE provincia_ID = %d", $db->getLastInsertedID() ), 'Provincia' ); - insert_here($provincie, $provincia, $here); - - return $provincia->provincia_ID; + return $provincie[ $provincia->provincia_uid ] = $provincia->provincia_ID; } diff --git a/cli/import.php b/cli/import-mise.php similarity index 76% rename from cli/import.php rename to cli/import-mise.php index 596d83a..0a692c5 100755 --- a/cli/import.php +++ b/cli/import-mise.php @@ -1,157 +1,145 @@ . */ /* * 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/ */ -require '../load.php'; -require 'import-functions.php'; +require __DIR__ . '/../load.php'; +require __DIR__ . '/import-mise-functions.php'; //$db->query("TRUNCATE {$db->getTable('rel_provincia_comune')}"); //$db->query("TRUNCATE {$db->getTable('provincia')}"); //$db->query("TRUNCATE {$db->getTable('comune')}"); //$db->query("TRUNCATE {$db->getTable('station')}"); //$db->query("TRUNCATE {$db->getTable('stationowner')}"); //$db->query("TRUNCATE {$db->getTable('fuelprovider')}"); //$db->query("TRUNCATE {$db->getTable('fuel')}"); $db->query("TRUNCATE {$db->getTable('price')}"); -$comuni = $db->getResults( - "SELECT comune_ID, comune_uid FROM {$db->getTable('comune')} ORDER BY comune_uid", - 'Comune' -); -$provincie = $db->getResults( - "SELECT provincia_ID, provincia_uid FROM {$db->getTable('provincia')} ORDER BY provincia_uid", - 'Provincia' -); -$fuels = $db->getResults( - "SELECT fuel_ID, fuel_uid FROM {$db->getTable('fuel')} ORDER BY fuel_uid", - 'Fuel' -); -$stations = $db->getResults( - "SELECT station_ID, station_miseID FROM {$db->getTable('station')} ORDER BY station_miseID", - 'Station' -); -$stationowners = $db->getResults( - "SELECT stationowner_ID, stationowner_uid FROM {$db->getTable('stationowner')} ORDER BY stationowner_uid", - 'Stationowner' -); -$fuelproviders = $db->getResults( - "SELECT fuelprovider_ID, fuelprovider_uid FROM {$db->getTable('fuelprovider')} ORDER BY fuelprovider_uid", - 'Fuelprovider' -); +$comuni = $db->getResults("SELECT comune_ID, comune_uid FROM {$db->getTable('comune')}", 'Comune'); +$comuni = indexed_array($comuni, 'comune_uid', 'comune_ID'); +$provincie = $db->getResults("SELECT provincia_ID, provincia_uid FROM {$db->getTable('provincia')}", 'Provincia'); +$provincie = indexed_array($provincie, 'provincia_uid', 'provincia_ID'); +$fuels = $db->getResults("SELECT fuel_ID, fuel_uid FROM {$db->getTable('fuel')}", 'Fuel'); +$fuels = indexed_array($fuels, 'fuel_uid', 'fuel_ID'); +$stations = $db->getResults("SELECT station_ID, station_miseID FROM {$db->getTable('station')}", 'Station'); +$stations = indexed_array($stations, 'station_miseID', 'station_ID'); +$stationowners = $db->getResults("SELECT stationowner_ID, stationowner_uid FROM {$db->getTable('stationowner')}", 'Stationowner'); +$stationowners = indexed_array($stationowners, 'stationowner_uid', 'stationowner_ID'); +$fuelproviders = $db->getResults("SELECT fuelprovider_ID, fuelprovider_uid FROM {$db->getTable('fuelprovider')}", 'Fuelprovider'); +$fuelproviders = indexed_array($fuelproviders, 'fuelprovider_uid', 'fuelprovider_ID'); try { if( ! isset( $argv[1], $argv[2] ) ) { throw new Exception( sprintf( _("Utilizzo: %s FILE_STAZIONI.csv PREZZI_ALLE_8.csv"), esc_html( $argv[0] ) ), 1 ); } define('FILENAME_STATIONS', $argv[1]); define('FILENAME_PRICES', $argv[2]); if( ! file_exists(FILENAME_STATIONS) ) { throw new Exception( _("File delle stazioni non trovato"), 2 ); } if( ! $handle = fopen(FILENAME_STATIONS, 'r') ) { throw new Exception( _("Impossibile aprire il file delle stazioni"), 3 ); } // Waste first 2 lines fgetcsv($handle); fgetcsv($handle); while( $data = fgetcsv($handle, 512, ';') ) { get_station_ID( (int) $data[0] /*$station_miseID*/, $data[4] /*$station_name*/, $data[3] /*$station_type*/, $data[5] /*$station_address*/, (float) $data[8] /*$station_lat*/, (float) $data[9] /*$station_lon*/, get_comune_ID( generate_slug( $data[6] ) /*$comune_uid*/, $data[6] /*$comune_name*/, $data[7] /*$provincia_name*/ ), get_stationowner_ID( generate_slug( $data[1] ) /*$stationowner_uid*/, $data[1] /*$stationowner_name*/ ), get_fuelprovider_ID( generate_slug( $data[2] ) /*$fuelprovider_uid*/, $data[2] /*$fuelprovider_name*/ ) ); } fclose($handle); // Prices if( ! file_exists(FILENAME_PRICES) ) { throw new Exception( _("File dei prezzi non trovato"), 4 ); } if( ! $handle = fopen(FILENAME_PRICES, 'r') ) { throw new Exception( _("Impossibile aprire il file dei prezzi"), 5 ); } // Waste first 2 lines fgetcsv($handle); fgetcsv($handle); while( $data = fgetcsv($handle, 255, ';') ) { $db->insertRow('price', [ new DBCol('price_value', (float) $data[2], 'f'), new DBCol('price_self', (int) $data[3], 'd'), new DBCol('price_date', $data[4], 's'), new DBCol( 'fuel_ID', get_fuel_ID( generate_slug($data[1]) /*$fuel_uid*/, $data[1] /*$fuel_name*/ ), 'd' ), new DBCol('station_ID', get_station_ID( (int) $data[0] ), 'd') ] ); } fclose($handle); } catch(Exception $e) { printf( _("Errore:\n\t%s.\n"), $e->getMessage() ); exit( $e->getCode() ); } diff --git a/cli/localize.sh b/cli/localize.sh index 93bca07..6d221a2 100755 --- a/cli/localize.sh +++ b/cli/localize.sh @@ -1,53 +1,53 @@ #!/bin/sh ############################################################################# # # Copyright (C) 2015 Valerio Bozzolan # ############################################################################# # # 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 . # ############################################################################# # This script do the entire Gettext i18n workflow # The copyright older of your localization copyright="Valerio Bozzolan" # The prefix of your localization's files # You have to know how GNU Gettext works to change it. package="fuel.reyboz.it" rtfm() { echo Usage: echo $1 SITE_ROOT echo Example: echo $1 /var/www/mysite } -if [ -z "$1" ]; then +path="$1" + +if [ -z "$path" ]; then rtfm $0 exit 1 fi -path="$1" - # Generate/update the .pot file from the single script (index.php) xgettext --copyright-holder="$copyright" --package-name=$package --from-code=UTF-8 --keyword=_e --default-domain=$package -o "$path"/l10n/$package.pot "$path"/*.php "$path"/*/*.php # Generate/update the .po files from the .pot file find "$path"/l10n -name \*.po -execdir msgmerge -o $package.po $package.po ../../$package.pot \; # Generate/update the .mo files from .po files find "$path"/l10n -name \*.po -execdir msgfmt -o $package.mo $package.po \; diff --git a/import/index.php b/import/index.php deleted file mode 100755 index eea59b9..0000000 --- a/import/index.php +++ /dev/null @@ -1,2 +0,0 @@ -. */ var map; var EUROS = 40; -var errortooresults = true; -var trovalatuazona = true; -var nessunfornitore = true; +var errorTooStations = true; +var pleaseZoomIn = true; +var noStations = true; var Stations = { all: [], exists: function(id) { var i = 0; while(i < this.all.length && this.all[i++] !== id); return this.all[i-1] === id; }, - add: function(id) { - this.all.push(id); - }, alreadyAdded: function(id) { if( this.exists(id) ) { return true; } - this.add(id); + this.all.push(id); return false; } }; 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='© OpenStreetMap contributors'; var osm = new L.TileLayer(osmUrl, {maxZoom: 17, attribution: osmAttrib}); map.addLayer(osm); map.setView([41.49, 13.11], 6); 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); + + Overworld.hide(); }); map.on("locationerror", function(e) { - Materialize.toast("Posizione non disponibile. Zomma!", 3000); + toast( L10n.noLocation ); }); getMarkersInBounds(); }); function toast(s) { Materialize.toast(s, 3000); } function getMarkersInBounds(preCallback, postCallback) { - - var zoom = map.getZoom(); - - if(zoom < 13) { - trovalatuazona && toast( L10N.pleaseZoomIn ); - trovalatuazona = false; + if(map.getZoom() < 13) { + pleaseZoomIn && toast( L10N.pleaseZoomIn ); + pleaseZoomIn = false; return; } - trovalatuazona = true; + pleaseZoomIn = 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 && toast( L10N.errorTooStations ); - errortooresults = false; + errorTooStations && toast( L10N.errorTooStations ); + errorTooStations = false; return; } - errortooresults = true; + errorTooStations = true; if(json.length === 0) { - nessunfornitore && toast( L10N.noStations ); - nessunfornitore = false; + noStations && toast( L10N.noStations ); + noStations = false; return; } - nessunfornitore = true; + noStations = true; if(json.length > 90) { 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"; } else { txt += "" + litres + " L"; } txt += "per il " + json[i].prices[j].fuel_name + ""; txt += ""; if(json[i].prices[j].price_self) { txt += "(self)"; } else { txt += ""; } txt += ""; txt += ""; } txt += ""; txt += "

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

"; var m = L.marker([json[i].station_lat, json[i].station_lon], { bounceOnAdd: true, bounceOnAddOptions: {duration: 500, height: 100}, bounceOnAddCallback: function() {} }) .bindPopup(txt) .addTo(map) .options; m.station_ID = json[i].station_ID; } 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( 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() { toast( L10N.addedToFavorites ); }); $(document).on("click", ".segnala-errore", function() { toast( L10N.errorSent ); }); diff --git a/index.php b/index.php index 83292bf..7eef7ab 100755 --- a/index.php +++ b/index.php @@ -1,92 +1,92 @@ . */ // The map require 'load.php'; enqueue_css('leaflet'); enqueue_css('my-fuel-map'); enqueue_js('jquery.ui'); enqueue_js('leaflet'); enqueue_js('leaflet.bouncemarker'); enqueue_js('my-fuel-map'); get_header('map'); ?>

    getValue( "SELECT COUNT(*) as count FROM {$db->getTable('station')}", 'count' ), HTML::property('class', 'station-counter') ) ) ?>

    navigation
    . */ -// Basic settings for Boz PHP - Another PHP framework +/* + * Basic settings for Boz PHP - Another PHP framework + * Copy this file in the root of the website called 'load.php'. + */ // Database info $database = ''; $username = ''; $password = ''; $location = ''; // Database table prefix $prefix = ''; define('ABSPATH', __DIR__); define('ROOT', ''); define('DEBUG', true); define('USE_DB_OPTIONS', false); require '/usr/share/boz-php-another-php-framework/load.php';