Skip to content

Commit

Permalink
Pesquisa por categorias
Browse files Browse the repository at this point in the history
Carrega a lista de categorias via PHP, armezena num arquivo temporário
por 12 horas e grava no localstorage. Removido o campo 'Perto de' e
reorganizado os demais. Credenciais movidas para arquivo de include
separado.
  • Loading branch information
gavlinski committed Jul 24, 2013
1 parent 4c4734b commit 8aebce1
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 61 deletions.
2 changes: 1 addition & 1 deletion FoursquareAPI.Class.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class FoursquareApi {
* @param String $client_secret
* @param String $version Defaults to v2, appends into the API url
*/
public function __construct($client_id = false,$client_secret = false, $redirect_uri='', $version='v2', $language='en'){
public function __construct($client_id = false,$client_secret = false, $redirect_uri='', $version='v2', $language='pt'){
$this->BaseUrl = "{$this->BaseUrl}$version/";
$this->ClientID = $client_id;
$this->ClientSecret = $client_secret;
Expand Down
28 changes: 14 additions & 14 deletions estilo.css
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,23 @@ a:hover {
width: 547px;
padding-top: 1px;
}
#toolContainer .row span.labelNear {
#toolContainer .row span.labelLl {
float: left;
width: 53px;
padding-left: 1px;
padding-top: 8px;
padding-right: 12px;
}
#toolContainer .row span.labelQuery {
float: left;
width: 61px;
width: 39px;
padding-left: 1px;
padding-top: 8px;
padding-right: 4px;
}
#toolContainer .row span.labelIntent {
float: left;
width: 54px;
width: 53px;
padding-left: 0;
padding-top: 8px;
padding-right: 7px;
}
#toolContainer .row span.labelRadius {
float: left;
width: 30px;
width: 8px;
padding-left: 1px;
padding-top: 8px;
padding-right: 35px;
Expand Down Expand Up @@ -138,12 +131,19 @@ a:hover {
.dijitSelect .dijitButtonText {
text-align: left;
}
#toolContainer .row span.combobox .dijitSelectLabel {
width: 243px;
#toolContainer .row span.combobox .dijitTextBox {
width: 170px;
overflow: hidden;
}
#toolContainer .row span.combobox .dijitArrowButtonInner {
width: 19px;
overflow: hidden;
}
.claro .dijitComboBox .dijitHasDropDownOpen .dijitArrowButtonInner {
width: 17px !important;
}
#toolContainer .row span.comboboxes .dijitSelectLabel {
width: 72px;
width: 46px;
overflow: hidden;
}
.checkbox {
Expand Down
9 changes: 9 additions & 0 deletions includes/app_credentials.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
// Set client key and secret
$client_key = "3EZPQCWMPTP0TLV4SJNPOLMWJB4UVCBGMADXWQCYFU3MPIQZ";
$client_secret = "J2310KS05Z50PU44DUC0T0HPEYM2CEQKBBPROAGXMBACZRZG";
$redirect_uri = "http://localhost/4sqmet/index.php";
//$client_key = "LFWOW3NHC1MINMYZY4UUHHPCC5Z2LWZ0DZHYH3XBXYJBPGDO";
//$client_secret = "QIG3AB5SFSAE5TP00QZSHLRSMCKQHTN5EAMAOLHNSNJJDQDL";
//$redirect_uri = "http://4sq.gcp.net.br/index.php";
?>
7 changes: 1 addition & 6 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
require_once("FoursquareAPI.Class.php");

// Set client key and secret
//$client_key = "3EZPQCWMPTP0TLV4SJNPOLMWJB4UVCBGMADXWQCYFU3MPIQZ";
//$client_secret = "J2310KS05Z50PU44DUC0T0HPEYM2CEQKBBPROAGXMBACZRZG";
//$redirect_uri = "http://localhost/4sqmet/index.php";
$client_key = "LFWOW3NHC1MINMYZY4UUHHPCC5Z2LWZ0DZHYH3XBXYJBPGDO";
$client_secret = "QIG3AB5SFSAE5TP00QZSHLRSMCKQHTN5EAMAOLHNSNJJDQDL";
$redirect_uri = "http://4sq.gcp.net.br/index.php";
include 'includes/app_credentials.php';

// Load the Foursquare API library
$foursquare = new FoursquareAPI($client_key, $client_secret);
Expand Down
130 changes: 96 additions & 34 deletions main.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* @category Foursquare
* @package Foursquare-Mass-Editor-Tools
* @author Elio Gavlinski <[email protected]>
* @copyright Copyleft (c) 2012
* @version 1.0
* @copyright Copyleft (c) 2012-2013
* @version 1.1
* @link https://github.com/gavlinski/Foursquare-Mass-Editor-Tools/blob/master/main.php
* @since File available since Release 1.5
* @license GPLv3 <http://www.gnu.org/licenses/gpl.txt>
Expand All @@ -29,6 +29,39 @@
<meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<script src="js/dojo/dojo.js" djConfig="parseOnLoad: true"></script>
<script type="text/javascript" src="js/main.js"></script>
<?php
$cache_file = "/tmp/cache-" . md5($_SERVER['REQUEST_URI']);
if (file_exists($cache_file) && (filemtime($cache_file) > (time() - 3600 * 12))) {
// Cache file is less than 12 hours old.
// Don't bother refreshing, just use the file as-is.
$response = file_get_contents($cache_file);
} else {
// Our cache is out-of-date, so load the data from our remote server,
// and also save it over our cache for next time.
$response = carregarListaCategorias();
file_put_contents($cache_file, $response, LOCK_EX);
}
setLocalCache("categorias", $response);

function carregarListaCategorias() {
require_once("FoursquareAPI.Class.php");

/*** Set client key and secret ***/
include 'includes/app_credentials.php';

/*** Load the Foursquare API library ***/
$foursquare = new FoursquareAPI($client_key, $client_secret);
$foursquare -> SetAccessToken($_SESSION["oauth_token"]);

return $foursquare->GetPrivate("venues/categories");
}

function setLocalCache($key, $data) {
print('<script type="text/javascript">localStorage.setItem(\''.$key.'\', \''.$data.'\');</script>');
print str_pad('', intval(ini_get('output_buffering')));
flush();
}
?>
<link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="js/dijit/themes/claro/claro.css"/>
<link rel="stylesheet" type="text/css" href="estilo.css"/>
Expand Down Expand Up @@ -342,66 +375,95 @@
<input type="hidden" id="oauth_token_scr" name="oauth_token" value="<?= $oauth_token ?>"/>
<div id="toolContainer">
<div class="row">
<span class="label"><label for="ll"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Lat/Long</a>:</label></span>
<span class="formw"><input type="text" id="ll" name="ll" required="false" dojoType="dijit.form.ValidationTextBox" trim="true" style="width: 266px"/></span>
<span class="labelNear"><label for="near"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Perto de</a>:</label></span>
<span class="formw"><input type="text" id="near" name="near" required="false" dojoType="dijit.form.ValidationTextBox" trim="true" style="width: 95px" disabled="true"/></span>
<span class="label"><label for="query"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Consulta</a>:</label></span>
<span class="formw"><input type="text" id="query" name="query" required="false" dojoType="dijit.form.ValidationTextBox" trim="true" style="width: 170px"/></span>
<span class="labelLl"><label for="ll"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Local</a>:</label></span>
<span class="formw"><input type="text" id="ll" name="ll" required="false" dojoType="dijit.form.ValidationTextBox" trim="true" style="width: 213px"/></span>
</div>
<div class="row">
<span class="label"><label for="categoryId"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Categoria</a>:</label></span>
<span class="formw">
<span class="combobox">
<select data-dojo-id="categoryId" name="categoryId" id="categoryId" data-dojo-type="dijit/form/Select" disabled="true">
<option value=""></option>
<select data-dojo-id="categoryId" name="categoryId" id="categoryId" data-dojo-type="dijit/form/FilteringSelect">
<?php
$categories = json_decode($response);
$categories_names = array();

foreach ($categories->response->categories as $category):
if (property_exists($category, "categories"))
foreach ($category->categories as $category2):
if (property_exists($category2, "name")) {
$categories_names[$category2->id] = $category2->name;
}
if (property_exists($category2, "categories"))
foreach ($category2->categories as $category3):
if (property_exists($category3, "name")) {
$categories_names[$category3->id] = $category3->name;
}
endforeach;
endforeach;
endforeach;

asort($categories_names);
$options = ' <option value=""></option>
';
foreach ($categories_names as $key => $val) {
$options .=
' <option value="' . $key . '">' . $val . '</option>
';
}

echo $options;
?>
</select>
</span>
</span>
<span class="labelQuery"><label for="query"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Consulta</a>:</label></span>
<span class="formw"><input type="text" id="query" name="query" required="false" dojoType="dijit.form.ValidationTextBox" trim="true" style="width: 95px"/></span>
</div>
<div class="row">
<span class="label"><label for="limit"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Limite</a>:</label></span>

<span class="labelRadius"><label for="radius"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Raio</a>:</label></span>
<span class="formw">
<span class="comboboxes">
<select data-dojo-id="limit" name="limit" id="limit" style="margin-bottom: 3px" data-dojo-type="dijit/form/Select">
<option value="10">10</option>
<option value="25">25</option>
<option value="50" selected="selected">50</option>
<option value="100">100</option>
<option value="150">150</option>
<option value="200">200</option>
<option value="250">250</option>
<select data-dojo-id="radius" name="radius" id="radius" data-dojo-type="dijit/form/Select">
<option value="">Padr&atilde;o</option>
<option value="50">50 m</option>
<option value="100">100 m</option>
<option value="250">250 m</option>
<option value="500">500 m</option>
<option value="1000">1 km</option>
<option value="5000">5 km</option>
<option value="10000">10 km</option>
<option value="50000">50 km</option>
<!--<option value="100000">100 km</option>-->
</select>
</span>
</span>
<span class="labelIntent"><label for="intent"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Inten&ccedil;&atilde;o</a>:</label></span>
<span class="formw">
<span class="comboboxes">
<select data-dojo-id="intent" name="intent" id="intent" data-dojo-type="dijit/form/Select" disabled="true">
<select data-dojo-id="intent" name="intent" data-dojo-type="dijit/form/Select">
<option value="checkin">checkin</option>
<option value="browse">browse</option>
<option value="global">global</option>
<option value="match">match</option>
</select>
</span>
</span>
<span class="labelRadius"><label for="radius"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Raio</a>:</label></span>
</div>
<div class="row">
<span class="label"><label for="limit"><a href="https://developer.foursquare.com/docs/venues/search" target="_blank">Limite</a>:</label></span>
<span class="formw">
<span class="comboboxes">
<select data-dojo-id="radius" name="radius" id="radius" data-dojo-type="dijit/form/Select" disabled="true">
<option value=""></option>
<option value="50">50 m</option>
<option value="100">100 m</option>
<option value="250">250 m</option>
<option value="500">500 m</option>
<option value="1000">1 km</option>
<option value="5000">5 km</option>
<option value="10000">10 km</option>
<option value="50000">50 km</option>
<!--<option value="100000">100 km</option>-->
<select data-dojo-id="limit" name="limit" id="limit" id="intent" style="margin-bottom: 3px" data-dojo-type="dijit/form/Select">
<option value="10">10</option>
<option value="25">25</option>
<option value="50" selected="selected">50</option>
<option value="100">100</option>
<option value="150">150</option>
<option value="200">200</option>
<option value="250">250</option>
</select>
</span>
</span>

</div>
<div class="row">
<span class="label"><label for="campos4">Campos:</label></span>
Expand Down
7 changes: 1 addition & 6 deletions search.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@

if (isset($_POST["ll"]))
$params["ll"] = utf8_encode($_POST["ll"]);
if (isset($_POST["near"]))
$params["near"] = $_POST["near"];
if (isset($_POST["categoryId"]))
$params["categoryId"] = $_POST["categoryId"];
if ((isset($_POST["query"])) && ($_POST["query"] != ""))
Expand Down Expand Up @@ -109,10 +107,7 @@ function pesquisarVenues($params) {
require_once("FoursquareAPI.Class.php");

/*** Set client key and secret ***/
//$client_key = "3EZPQCWMPTP0TLV4SJNPOLMWJB4UVCBGMADXWQCYFU3MPIQZ";
//$client_secret = "J2310KS05Z50PU44DUC0T0HPEYM2CEQKBBPROAGXMBACZRZG";
$client_key = "LFWOW3NHC1MINMYZY4UUHHPCC5Z2LWZ0DZHYH3XBXYJBPGDO";
$client_secret = "QIG3AB5SFSAE5TP00QZSHLRSMCKQHTN5EAMAOLHNSNJJDQDL";
include 'includes/app_credentials.php';

/*** Load the Foursquare API library ***/
$foursquare = new FoursquareAPI($client_key, $client_secret);
Expand Down

0 comments on commit 8aebce1

Please sign in to comment.