From 589f2b2562cc62e77db7ed3a04600fdcf2849721 Mon Sep 17 00:00:00 2001 From: shizhao Date: Mon, 21 Mar 2011 22:28:54 +0800 Subject: [PATCH 01/14] 4sqr --- CHANGELOG | 17 +++++++++ COPYING | 13 +++++++ THANKSTO | 1 + add.php | 44 ++++++++++++++++++++++++ check.php | 70 +++++++++++++++++++++++++++++++++++++ checkin.php | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ index.php | 69 +++++++++++++++++++++++++++++++++++++ latitude.php | 19 +++++++++++ login.php | 15 ++++++++ loginaction.php | 5 +++ logout.php | 4 +++ photo.php | 51 +++++++++++++++++++++++++++ 12 files changed, 399 insertions(+) create mode 100644 CHANGELOG create mode 100644 COPYING create mode 100644 THANKSTO create mode 100644 add.php create mode 100644 check.php create mode 100644 checkin.php create mode 100644 index.php create mode 100644 latitude.php create mode 100644 login.php create mode 100644 loginaction.php create mode 100644 logout.php create mode 100644 photo.php diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..45aa044 --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,17 @@ +1.0 - Initial relsese +1.1 - Remaked the Google Laitiude code + - minor changes to the index.php + - removed the shout form in check.php (the damm PHP Class does not work for shouting) + - Private check in works + - +1.2 - now can add venue + - fix POST error + - show checkin response + - add shout, but not work + - suppot twitter & facebook +1.3 - shout now work +1.4 - add login screen, and logout + - add 4sqr logo +1.5 - fixed Issue 6 + - login screen add latidude_code, not need conf/conf.php + - Now latidude_code with minus sign (some latidude_code of user no with minus sign) diff --git a/COPYING b/COPYING new file mode 100644 index 0000000..f3bbedb --- /dev/null +++ b/COPYING @@ -0,0 +1,13 @@ + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (C) 2004 Sam Hocevar + 14 rue de Plaisance, 75014 Paris, France + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. \ No newline at end of file diff --git a/THANKSTO b/THANKSTO new file mode 100644 index 0000000..0077e0a --- /dev/null +++ b/THANKSTO @@ -0,0 +1 @@ +Thanks to Lucky Strike and Coke developers \ No newline at end of file diff --git a/add.php b/add.php new file mode 100644 index 0000000..8842932 --- /dev/null +++ b/add.php @@ -0,0 +1,44 @@ + + + + + +

+post("/venues/add", array( + 'name' => "{$name}", 'address' => "{$address}", 'crossStreet' => "{$crossstreet}", 'city'=>"{$city}", 'state'=>"{$state}", 'zip'=>"{$zip}", 'phone'=>"{$phone}", 'll' => "{$geolat},{$geolong}" + )); +?> +
+Add new venue , OK!
+"; +$id=$venues->response->venue->id; +echo "Check in!
" ; +?> + +
+ + diff --git a/check.php b/check.php new file mode 100644 index 0000000..7e89cb9 --- /dev/null +++ b/check.php @@ -0,0 +1,70 @@ + + + + + + +

+format = "json"; +$new = $_GET['new']; + +if ($new ==1){ + echo "
"; + echo "
"; + echo"Add venue:
"; + echo"name:
"; + echo "address:
"; + echo "crossstreet:
"; + echo "city:
"; + echo "state:
"; + echo "zip:
"; + echo "phone:
"; + echo ""; + echo ""; + echo ""; + } + + +else { + $id = $_GET['id']; + $name = $_GET['name']; + $add = $_GET['add']; + $city = $_GET['city']; + $state = $_GET['state']; + echo "
"; + echo "Check in @ $name
"; + $array = array($add,$city,$state); + + $adds = implode(", ", $array); + + echo "$adds
"; + echo ""; + + echo ""; + echo ""; + echo ""; + echo ""; + echo "shout:
"; + echo "private:
"; + echo "twitter:
"; + echo "Facebook:
"; + echo "Image:
"; + echo ""; + } +?> + +
+ + diff --git a/checkin.php b/checkin.php new file mode 100644 index 0000000..cfaa6d1 --- /dev/null +++ b/checkin.php @@ -0,0 +1,91 @@ + + + + + +

+setAccessToken($_COOKIE['access_token']); + +$id = $_POST['id']; +$shout = $_POST['shout']; +$name = $_POST['name']; +$geolat = $_POST['latitude']; +$geolong = $_POST['longitude']; +$photo = $_POST['media']; + +if ($_POST['privat']== NULL){ + $privat = 'public'; + if ($_POST['facebook']== 1) + $privat = 'public, facebook'; + if ($_POST['twitter']== 1) + $privat = 'public,facebook,twitter'; + } +else { + $privat = 'private'; +} + +$checkin = $fsObjUnAuth->post('/checkins/add',array( + 'venueId' => "{$id}", 'venue' => "{$name}", 'shout'=>"{$shout}", 'broadcast' => "{$privat}", 'll' => "{$geolat},{$geolong}" + )); + +if {$photo !=NULL){ + +$pcheckin = $fsObjUnAuth->post('/photos/add',array( + 'venueId' => "{$id}", 'broadcast' => "{$privat}", 'll' => "{$geolat},{$geolong}" + )); +} + +?> +
+ +notifications[0]->item->message; +$add = $checkin->response->checkin->venue ->location->address; +$mayor = $checkin->notifications[1]->item->message; +$score = $checkin->notifications[3]->item->scores; +$total = $checkin->notifications[3]->item->total; + +?> +notifications; +foreach ($notification as $notifications){ + if ($notifications -> type == "message"){ + $message = $notifications->item->message; + echo "$message
"; + echo "$add
"; + if ($shout != NULL){ + echo "$shout
"; + } + } + if ($notifications -> type == "mayorship"){ + $mayor = $notifications->item->message; + echo "$mayor
"; + } + + if ($notifications -> type == "score"){ + $score = $notifications->item->scores; + if ($score != NULL){ + foreach ($score as $s){ + $points = $s->points; + $smessage = $s->message; + + echo "$smessage (+$points) pts
"; + } + } + $total = $notifications->item->total; + echo "Total: $total pts
"; + } +} +?> +
+ + diff --git a/index.php b/index.php new file mode 100644 index 0000000..df0e04d --- /dev/null +++ b/index.php @@ -0,0 +1,69 @@ + + + + + + +

+getAuthorizeUrl($redirectUri); ?> +authorization + + + getAccessToken($_GET['code'], $redirectUri); + setcookie('access_token', $token->access_token, time()+(100*24*3600)); + $_COOKIE['access_token'] = $token->access_token; + } ?> + access_token;?> + +
+ Latidude code:
+ you can find Latidude code here. + +
+ + + setAccessToken($_COOKIE['access_token']); + $venues = $fsObjUnAuth->get('/venues/search', array('ll' => "{$latitude},{$longitude}", 'limit' => 50)); +// if (is_object($venues->response)) { + foreach ($venues->response->groups[0]->items as $venue) { + $name = $venue->name; + $id = $venue->id; + $dist = $venue->location->distance; + $add = $venue->location->address; + $city = $venue->location->city; + $state = $venue->location->state; + echo "$name - $dist m
" ; + } +// } + + echo "
Add venue
"; + echo "I an here!
"; + echo "
Logout
"; + } + } +?> +
+ + diff --git a/latitude.php b/latitude.php new file mode 100644 index 0000000..6a3aca5 --- /dev/null +++ b/latitude.php @@ -0,0 +1,19 @@ + + + + + +

+
+Username:
+Password:
+Latidude code:
+you can find Latidude code here. + +
+ + diff --git a/loginaction.php b/loginaction.php new file mode 100644 index 0000000..13d5cdb --- /dev/null +++ b/loginaction.php @@ -0,0 +1,5 @@ + diff --git a/logout.php b/logout.php new file mode 100644 index 0000000..c87ceec --- /dev/null +++ b/logout.php @@ -0,0 +1,4 @@ + diff --git a/photo.php b/photo.php new file mode 100644 index 0000000..9af288c --- /dev/null +++ b/photo.php @@ -0,0 +1,51 @@ + 0) { + $digit = $num[strlen($num)-1]; + $decoded += $multi * strpos($alphabet, $digit); + $multi = $multi * strlen($alphabet); + $num = substr($num, 0, -1); + } + return $decoded; +} + +?> From 20c40e6f886c11dc7e6b1ab155f235beb379d5c8 Mon Sep 17 00:00:00 2001 From: shizhao Date: Tue, 22 Mar 2011 00:26:53 +0800 Subject: [PATCH 02/14] =?UTF-8?q?format,=20=E4=B8=AA=E4=BA=BA=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- add.php | 15 +-- check.php | 19 +-- checkin.php | 18 +-- config.php | 6 + index.php | 84 +++++-------- kernel/EpiCurl.php | 191 +++++++++++++++++++++++++++++ kernel/EpiFoursquare.php | 259 +++++++++++++++++++++++++++++++++++++++ kernel/EpiSequence.php | 54 ++++++++ kernel/latitude.php | 19 +++ logo.png | Bin 0 -> 3758 bytes logout.php | 2 +- 11 files changed, 577 insertions(+), 90 deletions(-) create mode 100644 config.php create mode 100644 kernel/EpiCurl.php create mode 100644 kernel/EpiFoursquare.php create mode 100644 kernel/EpiSequence.php create mode 100644 kernel/latitude.php create mode 100644 logo.png diff --git a/add.php b/add.php index 8842932..a286dab 100644 --- a/add.php +++ b/add.php @@ -3,14 +3,11 @@ -

-
+
Add new venue , OK!
- -

-format = "json"; +

+ -

-
+setAccessToken($_COOKIE['access_token']); $id = $_POST['id']; $shout = $_POST['shout']; @@ -46,7 +42,7 @@ ?>
-notifications[0]->item->message; $add = $checkin->response->checkin->venue ->location->address; @@ -54,8 +50,6 @@ $score = $checkin->notifications[3]->item->scores; $total = $checkin->notifications[3]->item->total; -?> -notifications; foreach ($notification as $notifications){ if ($notifications -> type == "message"){ diff --git a/config.php b/config.php new file mode 100644 index 0000000..a70a22a --- /dev/null +++ b/config.php @@ -0,0 +1,6 @@ + diff --git a/index.php b/index.php index df0e04d..552693b 100644 --- a/index.php +++ b/index.php @@ -1,11 +1,8 @@ @@ -13,57 +10,36 @@ -

+

getAuthorizeUrl($redirectUri); +?> + authorization + getAccessToken($_GET['code'], $redirectUri); + setcookie('access_token', $token->access_token, time()+(100*24*3600)); + $_COOKIE['access_token'] = $token->access_token; + } ?> + setAccessToken($_COOKIE['access_token']); + $venues = $fsObjUnAuth->get('/venues/search', array('ll' => "{$latitude},{$longitude}", 'limit' => 50)); + foreach ($venues->response->groups[0]->items as $venue) { + $name = $venue->name; + $id = $venue->id; + $dist = $venue->location->distance; + $add = $venue->location->address; + $city = $venue->location->city; + $state = $venue->location->state; + echo "$name - $dist m
" ; + } - $authorizeUrl = $fsObjUnAuth->getAuthorizeUrl($redirectUri); ?> -authorization - - - getAccessToken($_GET['code'], $redirectUri); - setcookie('access_token', $token->access_token, time()+(100*24*3600)); - $_COOKIE['access_token'] = $token->access_token; + echo "
Add venue
"; + echo "I an here!
"; + echo "
Logout
"; } ?> - access_token;?> - -
- Latidude code:
- you can find Latidude code here. - -
- - - setAccessToken($_COOKIE['access_token']); - $venues = $fsObjUnAuth->get('/venues/search', array('ll' => "{$latitude},{$longitude}", 'limit' => 50)); -// if (is_object($venues->response)) { - foreach ($venues->response->groups[0]->items as $venue) { - $name = $venue->name; - $id = $venue->id; - $dist = $venue->location->distance; - $add = $venue->location->address; - $city = $venue->location->city; - $state = $venue->location->state; - echo "$name - $dist m
" ; - } -// } - - echo "
Add venue
"; - echo "I an here!
"; - echo "
Logout
"; - } - } -?>
- + diff --git a/kernel/EpiCurl.php b/kernel/EpiCurl.php new file mode 100644 index 0000000..71fb870 --- /dev/null +++ b/kernel/EpiCurl.php @@ -0,0 +1,191 @@ +mc = curl_multi_init(); + $this->properties = array( + 'code' => CURLINFO_HTTP_CODE, + 'time' => CURLINFO_TOTAL_TIME, + 'length'=> CURLINFO_CONTENT_LENGTH_DOWNLOAD, + 'type' => CURLINFO_CONTENT_TYPE, + 'url' => CURLINFO_EFFECTIVE_URL + ); + } + + public function addCurl($ch) + { + $key = $this->getKey($ch); + $this->requests[$key] = $ch; + curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'headerCallback')); + + $code = curl_multi_add_handle($this->mc, $ch); + $this->startTimer($key); + + // (1) + if($code === CURLM_OK || $code === CURLM_CALL_MULTI_PERFORM) + { + do { + $code = $this->execStatus = curl_multi_exec($this->mc, $this->running); + } while ($this->execStatus === CURLM_CALL_MULTI_PERFORM); + + return new EpiCurlManager($key); + } + else + { + return $code; + } + } + + public function getResult($key = null) + { + if($key != null) + { + if(isset($this->responses[$key])) + { + return $this->responses[$key]; + } + + $innerSleepInt = $outerSleepInt = 1; + while($this->running && ($this->execStatus == CURLM_OK || $this->execStatus == CURLM_CALL_MULTI_PERFORM)) + { + usleep($outerSleepInt); + $outerSleepInt = intval(max(1, ($outerSleepInt*$this->sleepIncrement))); + $ms=curl_multi_select($this->mc, 0); + if($ms > 0) + { + do{ + $this->execStatus = curl_multi_exec($this->mc, $this->running); + usleep($innerSleepInt); + $innerSleepInt = intval(max(1, ($innerSleepInt*$this->sleepIncrement))); + }while($this->execStatus==CURLM_CALL_MULTI_PERFORM); + $innerSleepInt = 1; + } + $this->storeResponses(); + if(isset($this->responses[$key]['data'])) + { + return $this->responses[$key]; + } + $runningCurrent = $this->running; + } + return null; + } + return false; + } + + public static function getSequence() + { + return new EpiSequence(self::$timers); + } + + public static function getTimers() + { + return self::$timers; + } + + private function getKey($ch) + { + return (string)$ch; + } + + private function headerCallback($ch, $header) + { + $_header = trim($header); + $colonPos= strpos($_header, ':'); + if($colonPos > 0) + { + $key = substr($_header, 0, $colonPos); + $val = preg_replace('/^\W+/','',substr($_header, $colonPos)); + $this->responses[$this->getKey($ch)]['headers'][$key] = $val; + } + return strlen($header); + } + + private function storeResponses() + { + while($done = curl_multi_info_read($this->mc)) + { + $key = (string)$done['handle']; + $this->stopTimer($key, $done); + $this->responses[$key]['data'] = curl_multi_getcontent($done['handle']); + foreach($this->properties as $name => $const) + { + $this->responses[$key][$name] = curl_getinfo($done['handle'], $const); + } + curl_multi_remove_handle($this->mc, $done['handle']); + curl_close($done['handle']); + } + } + + private function startTimer($key) + { + self::$timers[$key]['start'] = microtime(true); + } + + private function stopTimer($key, $done) + { + self::$timers[$key]['end'] = microtime(true); + self::$timers[$key]['api'] = curl_getinfo($done['handle'], CURLINFO_EFFECTIVE_URL); + self::$timers[$key]['time'] = curl_getinfo($done['handle'], CURLINFO_TOTAL_TIME); + self::$timers[$key]['code'] = curl_getinfo($done['handle'], CURLINFO_HTTP_CODE); + } + + static function getInstance() + { + if(self::$inst == null) + { + self::$singleton = 1; + self::$inst = new EpiCurl(); + } + + return self::$inst; + } +} + +class EpiCurlManager +{ + private $key; + private $epiCurl; + + public function __construct($key) + { + $this->key = $key; + $this->epiCurl = EpiCurl::getInstance(); + } + + public function __get($name) + { + $responses = $this->epiCurl->getResult($this->key); + return isset($responses[$name]) ? $responses[$name] : null; + } + + public function __isset($name) + { + $val = self::__get($name); + return empty($val); + } +} + +/* + * Credits: + * - (1) Alistair pointed out that curl_multi_add_handle can return CURLM_CALL_MULTI_PERFORM on success. + */ diff --git a/kernel/EpiFoursquare.php b/kernel/EpiFoursquare.php new file mode 100644 index 0000000..ab680c0 --- /dev/null +++ b/kernel/EpiFoursquare.php @@ -0,0 +1,259 @@ + + */ +class EpiFoursquare +{ + protected $clientId, $clientSecret, $accessToken; + protected $requestTokenUrl= 'https://foursquare.com/oauth2/authenticate'; + protected $accessTokenUrl = 'https://foursquare.com/oauth2/access_token'; + protected $authorizeUrl = 'https://foursquare.com/oauth2/authorize'; + protected $apiUrl = 'https://api.foursquare.com'; + protected $userAgent = 'EpiFoursquare (http://github.com/jmathai/foursquare-async/tree/)'; + protected $apiVersion = 'v2'; + protected $isAsynchronous = false; + protected $followLocation = false; + protected $connectionTimeout = 5; + protected $requestTimeout = 30; + protected $debug = false; + + public function getAccessToken($code, $redirectUri) + { + $params = array('client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'grant_type' => 'authorization_code', 'redirect_uri' => $redirectUri, 'code' => $code); + $qs = http_build_query($params); + return $this->request('GET', "{$this->accessTokenUrl}", $params); + } + + public function getAuthorizeUrl($redirectUri) + { + $params = array('client_id' => $this->clientId, 'response_type' => 'code', 'redirect_uri' => $redirectUri); + $qs = http_build_query($params); + return "{$this->requestTokenUrl}?{$qs}"; + } + + public function setAccessToken($accessToken) + { + $this->accessToken = $accessToken; + } + + public function setTimeout($requestTimeout = null, $connectionTimeout = null) + { + if($requestTimeout !== null) + $this->requestTimeout = floatval($requestTimeout); + if($connectionTimeout !== null) + $this->connectionTimeout = floatval($connectionTimeout); + } + + public function setUserAgent($agent) + { + $this->userAgent = $agent; + } + + public function useApiVersion($version = null) + { + $this->apiVersion = $version; + } + + public function useAsynchronous($async = true) + { + $this->isAsynchronous = (bool)$async; + } + + // Public api interface for most calls GET/POST/DELETE + public function delete($endpoint, $params = null) + { + return $this->request('DELETE', $endpoint, $params); + } + + public function get($endpoint, $params = null) + { + return $this->request('GET', $endpoint, $params); + } + + public function post($endpoint, $params = null) + { + return $this->request('POST', $endpoint, $params); + } + + public function __construct($clientId = null, $clientSecret = null, $accessToken = null) + { + $this->clientId = $clientId; + $this->clientSecret = $clientSecret; + $this->accessToken = $accessToken; + } + + private function getApiUrl($endpoint) + { + if(!empty($this->apiVersion)) + return "{$this->apiUrl}/{$this->apiVersion}{$endpoint}"; + else + return "{$this->apiUrl}{$endpoint}"; + } + + private function request($method, $endpoint, $params = null) + { + if(preg_match('#^https?://#', $endpoint)) + $url = $endpoint; + else + $url = $this->getApiUrl($endpoint); + + if($this->accessToken) + { + $params['oauth_token'] = $this->accessToken; + } + else + { + $params['client_id'] = $this->clientId; + $params['client_secret'] = $this->clientSecret; + } + + if($method === 'GET') + $url .= is_null($params) ? '' : '?'.http_build_query($params, '', '&'); + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, $this->requestTimeout); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + if(isset($_SERVER ['SERVER_ADDR']) && !empty($_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] != '127.0.0.1') + curl_setopt($ch, CURLOPT_INTERFACE, $_SERVER ['SERVER_ADDR']); + if($method === 'POST' && $params !== null) + { + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); + } + + $resp = new EpiFoursquareJson(EpiCurl::getInstance()->addCurl($ch), $this->debug); + if(!$this->isAsynchronous) + $resp->responseText; + + return $resp; + } +} + +class EpiFoursquareJson implements ArrayAccess, Countable, IteratorAggregate +{ + private $debug; + private $__resp; + public function __construct($response, $debug = false) + { + $this->__resp = $response; + $this->debug = $debug; + } + + // ensure that calls complete by blocking for results, NOOP if already returned + public function __destruct() + { + $this->responseText; + } + + // Implementation of the IteratorAggregate::getIterator() to support foreach ($this as $...) + public function getIterator () + { + if ($this->__obj) { + return new ArrayIterator($this->__obj); + } else { + return new ArrayIterator($this->response); + } + } + + // Implementation of Countable::count() to support count($this) + public function count () + { + return count($this->response); + } + + // Next four functions are to support ArrayAccess interface + // 1 + public function offsetSet($offset, $value) + { + $this->response[$offset] = $value; + } + + // 2 + public function offsetExists($offset) + { + return isset($this->response[$offset]); + } + + // 3 + public function offsetUnset($offset) + { + unset($this->response[$offset]); + } + + // 4 + public function offsetGet($offset) + { + return isset($this->response[$offset]) ? $this->response[$offset] : null; + } + + public function __get($name) + { + $accessible = array('responseText'=>1,'headers'=>1,'code'=>1); + $this->responseText = $this->__resp->data; + $this->headers = $this->__resp->headers; + $this->code = $this->__resp->code; + if(isset($accessible[$name]) && $accessible[$name]) + return $this->$name; + elseif(($this->code < 200 || $this->code >= 400) && !isset($accessible[$name])) + EpiFoursquareException::raise($this->__resp, $this->debug); + + // Call appears ok so we can fill in the response + $this->response = json_decode($this->responseText, 1); + $this->__obj = json_decode($this->responseText); + + if(gettype($this->__obj) === 'object') + { + foreach($this->__obj as $k => $v) + { + $this->$k = $v; + } + } + + if (property_exists($this, $name)) { + return $this->$name; + } + return null; + } + + public function __isset($name) + { + $value = self::__get($name); + return !empty($name); + } +} + +class EpiFoursquareException extends Exception +{ + public static function raise($response, $debug) + { + $message = $response->data; + + switch($response->code) + { + case 400: + throw new EpiFoursquareBadRequestException($message, $response->code); + case 401: + throw new EpiFoursquareNotAuthorizedException($message, $response->code); + case 403: + throw new EpiFoursquareForbiddenException($message, $response->code); + case 404: + throw new EpiFoursquareNotFoundException($message, $response->code); + default: + throw new EpiFoursquareException($message, $response->code); + } + } +} +class EpiFoursquareBadRequestException extends EpiFoursquareException{} +class EpiFoursquareNotAuthorizedException extends EpiFoursquareException{} +class EpiFoursquareForbiddenException extends EpiFoursquareException{} +class EpiFoursquareNotFoundException extends EpiFoursquareException{} diff --git a/kernel/EpiSequence.php b/kernel/EpiSequence.php new file mode 100644 index 0000000..c47c0c2 --- /dev/null +++ b/kernel/EpiSequence.php @@ -0,0 +1,54 @@ +timers = $timers; + + $min = PHP_INT_MAX; + $max = 0; + foreach($this->timers as $timer) + { + $min = min($timer['start'], $min); + $max = max($timer['end'], $max); + } + $this->min = $min; + $this->max = $max; + $this->range = $max-$min; + $this->step = floatval($this->range/$this->width); + } + + public function renderAscii() + { + $tpl = ''; + foreach($this->timers as $timer) + $tpl .= $this->tplAscii($timer); + + return $tpl; + } + + private function tplAscii($timer) + { + $lpad = $rpad = 0; + $lspace = $chars = $rspace = ''; + if($timer['start'] > $this->min) + $lpad = intval(($timer['start'] - $this->min) / $this->step); + if($timer['end'] < $this->max) + $rpad = intval(($this->max - $timer['end']) / $this->step); + $mpad = $this->width - $lpad - $rpad; + if($lpad > 0) + $lspace = str_repeat(' ', $lpad); + if($mpad > 0) + $chars = str_repeat('=', $mpad); + if($rpad > 0) + $rspace = str_repeat(' ', $rpad); + + $tpl = <<Y^e(Kt&s%L{%CBjYNtlG(a0j01F4QI*IMXj6I$ik7w+e zxy!qpbDpOk?qqR1u2Uh9TIDajAKv@ktLOha%kw_xx$v@H*30@oEwk#UH{H9Y>FSSI zV{TNDQB|2YmfZ#(Ni2s%Wk!sBrt8gq{^5q+FWB>OIsxEUzP>lNv&C1>-!l4U5n-uQ zadf$4dcMQlLYHn);eDVEF-QmpjWv4>%oubgfk$h#59ht|;L)@9cDVIc`Go`g)Bf@k z*62sAHJ~7>)IlhHWVu(f)Gq1tJd2%@xrGjM^KCl4imLKdWldH3py(V?=GDeIun(!x z2c2=xR3;v&mKsO+@^5v1E&!k3SDXQ|N1=f=m@GjIR6S2!2cjt67=nVY0-^Slb)cvM zMIGoAHH*sy-J+t`t7*4;^p<9+@0$77KYR*|{!9S3 zJ=1%wQFfYUhIUKpClAs7;S+>ChoPwHNrhcAgniXnl;=#~Panf8grcI3iWk9)Qi)PW zrHqko<>{0)-7-*?6?MBHc6vxrp+1llJsL%~c2OR!>-tl(U;pSo|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aBpSp z{N&{1s%^$q)98!!N88LYaNo+shaR3C$lGRnFnW!^1)`j|jNcEemJ?kFW( z))jMBAz{0Za*l|aXWQ>S3PBV^`gZarZvOD%#((+vpJaQ!fBU}vx{oJ|^K%1ORd+p} zownFLAJuJT)Gbw%3qq80B From 188f85d2cce7fb46019feaafcdd5cdc19ebde71c Mon Sep 17 00:00:00 2001 From: shizhao Date: Tue, 22 Mar 2011 00:31:58 +0800 Subject: [PATCH 03/14] clean --- EpiCurl.php | 191 ---------------------------------- EpiFoursquare.php | 259 ---------------------------------------------- EpiSequence.php | 54 ---------- latitude.php | 19 ---- 4 files changed, 523 deletions(-) delete mode 100644 EpiCurl.php delete mode 100644 EpiFoursquare.php delete mode 100644 EpiSequence.php delete mode 100644 latitude.php diff --git a/EpiCurl.php b/EpiCurl.php deleted file mode 100644 index 71fb870..0000000 --- a/EpiCurl.php +++ /dev/null @@ -1,191 +0,0 @@ -mc = curl_multi_init(); - $this->properties = array( - 'code' => CURLINFO_HTTP_CODE, - 'time' => CURLINFO_TOTAL_TIME, - 'length'=> CURLINFO_CONTENT_LENGTH_DOWNLOAD, - 'type' => CURLINFO_CONTENT_TYPE, - 'url' => CURLINFO_EFFECTIVE_URL - ); - } - - public function addCurl($ch) - { - $key = $this->getKey($ch); - $this->requests[$key] = $ch; - curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'headerCallback')); - - $code = curl_multi_add_handle($this->mc, $ch); - $this->startTimer($key); - - // (1) - if($code === CURLM_OK || $code === CURLM_CALL_MULTI_PERFORM) - { - do { - $code = $this->execStatus = curl_multi_exec($this->mc, $this->running); - } while ($this->execStatus === CURLM_CALL_MULTI_PERFORM); - - return new EpiCurlManager($key); - } - else - { - return $code; - } - } - - public function getResult($key = null) - { - if($key != null) - { - if(isset($this->responses[$key])) - { - return $this->responses[$key]; - } - - $innerSleepInt = $outerSleepInt = 1; - while($this->running && ($this->execStatus == CURLM_OK || $this->execStatus == CURLM_CALL_MULTI_PERFORM)) - { - usleep($outerSleepInt); - $outerSleepInt = intval(max(1, ($outerSleepInt*$this->sleepIncrement))); - $ms=curl_multi_select($this->mc, 0); - if($ms > 0) - { - do{ - $this->execStatus = curl_multi_exec($this->mc, $this->running); - usleep($innerSleepInt); - $innerSleepInt = intval(max(1, ($innerSleepInt*$this->sleepIncrement))); - }while($this->execStatus==CURLM_CALL_MULTI_PERFORM); - $innerSleepInt = 1; - } - $this->storeResponses(); - if(isset($this->responses[$key]['data'])) - { - return $this->responses[$key]; - } - $runningCurrent = $this->running; - } - return null; - } - return false; - } - - public static function getSequence() - { - return new EpiSequence(self::$timers); - } - - public static function getTimers() - { - return self::$timers; - } - - private function getKey($ch) - { - return (string)$ch; - } - - private function headerCallback($ch, $header) - { - $_header = trim($header); - $colonPos= strpos($_header, ':'); - if($colonPos > 0) - { - $key = substr($_header, 0, $colonPos); - $val = preg_replace('/^\W+/','',substr($_header, $colonPos)); - $this->responses[$this->getKey($ch)]['headers'][$key] = $val; - } - return strlen($header); - } - - private function storeResponses() - { - while($done = curl_multi_info_read($this->mc)) - { - $key = (string)$done['handle']; - $this->stopTimer($key, $done); - $this->responses[$key]['data'] = curl_multi_getcontent($done['handle']); - foreach($this->properties as $name => $const) - { - $this->responses[$key][$name] = curl_getinfo($done['handle'], $const); - } - curl_multi_remove_handle($this->mc, $done['handle']); - curl_close($done['handle']); - } - } - - private function startTimer($key) - { - self::$timers[$key]['start'] = microtime(true); - } - - private function stopTimer($key, $done) - { - self::$timers[$key]['end'] = microtime(true); - self::$timers[$key]['api'] = curl_getinfo($done['handle'], CURLINFO_EFFECTIVE_URL); - self::$timers[$key]['time'] = curl_getinfo($done['handle'], CURLINFO_TOTAL_TIME); - self::$timers[$key]['code'] = curl_getinfo($done['handle'], CURLINFO_HTTP_CODE); - } - - static function getInstance() - { - if(self::$inst == null) - { - self::$singleton = 1; - self::$inst = new EpiCurl(); - } - - return self::$inst; - } -} - -class EpiCurlManager -{ - private $key; - private $epiCurl; - - public function __construct($key) - { - $this->key = $key; - $this->epiCurl = EpiCurl::getInstance(); - } - - public function __get($name) - { - $responses = $this->epiCurl->getResult($this->key); - return isset($responses[$name]) ? $responses[$name] : null; - } - - public function __isset($name) - { - $val = self::__get($name); - return empty($val); - } -} - -/* - * Credits: - * - (1) Alistair pointed out that curl_multi_add_handle can return CURLM_CALL_MULTI_PERFORM on success. - */ diff --git a/EpiFoursquare.php b/EpiFoursquare.php deleted file mode 100644 index ab680c0..0000000 --- a/EpiFoursquare.php +++ /dev/null @@ -1,259 +0,0 @@ - - */ -class EpiFoursquare -{ - protected $clientId, $clientSecret, $accessToken; - protected $requestTokenUrl= 'https://foursquare.com/oauth2/authenticate'; - protected $accessTokenUrl = 'https://foursquare.com/oauth2/access_token'; - protected $authorizeUrl = 'https://foursquare.com/oauth2/authorize'; - protected $apiUrl = 'https://api.foursquare.com'; - protected $userAgent = 'EpiFoursquare (http://github.com/jmathai/foursquare-async/tree/)'; - protected $apiVersion = 'v2'; - protected $isAsynchronous = false; - protected $followLocation = false; - protected $connectionTimeout = 5; - protected $requestTimeout = 30; - protected $debug = false; - - public function getAccessToken($code, $redirectUri) - { - $params = array('client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'grant_type' => 'authorization_code', 'redirect_uri' => $redirectUri, 'code' => $code); - $qs = http_build_query($params); - return $this->request('GET', "{$this->accessTokenUrl}", $params); - } - - public function getAuthorizeUrl($redirectUri) - { - $params = array('client_id' => $this->clientId, 'response_type' => 'code', 'redirect_uri' => $redirectUri); - $qs = http_build_query($params); - return "{$this->requestTokenUrl}?{$qs}"; - } - - public function setAccessToken($accessToken) - { - $this->accessToken = $accessToken; - } - - public function setTimeout($requestTimeout = null, $connectionTimeout = null) - { - if($requestTimeout !== null) - $this->requestTimeout = floatval($requestTimeout); - if($connectionTimeout !== null) - $this->connectionTimeout = floatval($connectionTimeout); - } - - public function setUserAgent($agent) - { - $this->userAgent = $agent; - } - - public function useApiVersion($version = null) - { - $this->apiVersion = $version; - } - - public function useAsynchronous($async = true) - { - $this->isAsynchronous = (bool)$async; - } - - // Public api interface for most calls GET/POST/DELETE - public function delete($endpoint, $params = null) - { - return $this->request('DELETE', $endpoint, $params); - } - - public function get($endpoint, $params = null) - { - return $this->request('GET', $endpoint, $params); - } - - public function post($endpoint, $params = null) - { - return $this->request('POST', $endpoint, $params); - } - - public function __construct($clientId = null, $clientSecret = null, $accessToken = null) - { - $this->clientId = $clientId; - $this->clientSecret = $clientSecret; - $this->accessToken = $accessToken; - } - - private function getApiUrl($endpoint) - { - if(!empty($this->apiVersion)) - return "{$this->apiUrl}/{$this->apiVersion}{$endpoint}"; - else - return "{$this->apiUrl}{$endpoint}"; - } - - private function request($method, $endpoint, $params = null) - { - if(preg_match('#^https?://#', $endpoint)) - $url = $endpoint; - else - $url = $this->getApiUrl($endpoint); - - if($this->accessToken) - { - $params['oauth_token'] = $this->accessToken; - } - else - { - $params['client_id'] = $this->clientId; - $params['client_secret'] = $this->clientSecret; - } - - if($method === 'GET') - $url .= is_null($params) ? '' : '?'.http_build_query($params, '', '&'); - $ch = curl_init($url); - curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); - curl_setopt($ch, CURLOPT_TIMEOUT, $this->requestTimeout); - curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); - curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); - if(isset($_SERVER ['SERVER_ADDR']) && !empty($_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] != '127.0.0.1') - curl_setopt($ch, CURLOPT_INTERFACE, $_SERVER ['SERVER_ADDR']); - if($method === 'POST' && $params !== null) - { - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); - } - - $resp = new EpiFoursquareJson(EpiCurl::getInstance()->addCurl($ch), $this->debug); - if(!$this->isAsynchronous) - $resp->responseText; - - return $resp; - } -} - -class EpiFoursquareJson implements ArrayAccess, Countable, IteratorAggregate -{ - private $debug; - private $__resp; - public function __construct($response, $debug = false) - { - $this->__resp = $response; - $this->debug = $debug; - } - - // ensure that calls complete by blocking for results, NOOP if already returned - public function __destruct() - { - $this->responseText; - } - - // Implementation of the IteratorAggregate::getIterator() to support foreach ($this as $...) - public function getIterator () - { - if ($this->__obj) { - return new ArrayIterator($this->__obj); - } else { - return new ArrayIterator($this->response); - } - } - - // Implementation of Countable::count() to support count($this) - public function count () - { - return count($this->response); - } - - // Next four functions are to support ArrayAccess interface - // 1 - public function offsetSet($offset, $value) - { - $this->response[$offset] = $value; - } - - // 2 - public function offsetExists($offset) - { - return isset($this->response[$offset]); - } - - // 3 - public function offsetUnset($offset) - { - unset($this->response[$offset]); - } - - // 4 - public function offsetGet($offset) - { - return isset($this->response[$offset]) ? $this->response[$offset] : null; - } - - public function __get($name) - { - $accessible = array('responseText'=>1,'headers'=>1,'code'=>1); - $this->responseText = $this->__resp->data; - $this->headers = $this->__resp->headers; - $this->code = $this->__resp->code; - if(isset($accessible[$name]) && $accessible[$name]) - return $this->$name; - elseif(($this->code < 200 || $this->code >= 400) && !isset($accessible[$name])) - EpiFoursquareException::raise($this->__resp, $this->debug); - - // Call appears ok so we can fill in the response - $this->response = json_decode($this->responseText, 1); - $this->__obj = json_decode($this->responseText); - - if(gettype($this->__obj) === 'object') - { - foreach($this->__obj as $k => $v) - { - $this->$k = $v; - } - } - - if (property_exists($this, $name)) { - return $this->$name; - } - return null; - } - - public function __isset($name) - { - $value = self::__get($name); - return !empty($name); - } -} - -class EpiFoursquareException extends Exception -{ - public static function raise($response, $debug) - { - $message = $response->data; - - switch($response->code) - { - case 400: - throw new EpiFoursquareBadRequestException($message, $response->code); - case 401: - throw new EpiFoursquareNotAuthorizedException($message, $response->code); - case 403: - throw new EpiFoursquareForbiddenException($message, $response->code); - case 404: - throw new EpiFoursquareNotFoundException($message, $response->code); - default: - throw new EpiFoursquareException($message, $response->code); - } - } -} -class EpiFoursquareBadRequestException extends EpiFoursquareException{} -class EpiFoursquareNotAuthorizedException extends EpiFoursquareException{} -class EpiFoursquareForbiddenException extends EpiFoursquareException{} -class EpiFoursquareNotFoundException extends EpiFoursquareException{} diff --git a/EpiSequence.php b/EpiSequence.php deleted file mode 100644 index c47c0c2..0000000 --- a/EpiSequence.php +++ /dev/null @@ -1,54 +0,0 @@ -timers = $timers; - - $min = PHP_INT_MAX; - $max = 0; - foreach($this->timers as $timer) - { - $min = min($timer['start'], $min); - $max = max($timer['end'], $max); - } - $this->min = $min; - $this->max = $max; - $this->range = $max-$min; - $this->step = floatval($this->range/$this->width); - } - - public function renderAscii() - { - $tpl = ''; - foreach($this->timers as $timer) - $tpl .= $this->tplAscii($timer); - - return $tpl; - } - - private function tplAscii($timer) - { - $lpad = $rpad = 0; - $lspace = $chars = $rspace = ''; - if($timer['start'] > $this->min) - $lpad = intval(($timer['start'] - $this->min) / $this->step); - if($timer['end'] < $this->max) - $rpad = intval(($this->max - $timer['end']) / $this->step); - $mpad = $this->width - $lpad - $rpad; - if($lpad > 0) - $lspace = str_repeat(' ', $lpad); - if($mpad > 0) - $chars = str_repeat('=', $mpad); - if($rpad > 0) - $rspace = str_repeat(' ', $rpad); - - $tpl = << Date: Tue, 22 Mar 2011 00:33:15 +0800 Subject: [PATCH 04/14] del loginaction.php --- loginaction.php | 5 ----- 1 file changed, 5 deletions(-) delete mode 100644 loginaction.php diff --git a/loginaction.php b/loginaction.php deleted file mode 100644 index 13d5cdb..0000000 --- a/loginaction.php +++ /dev/null @@ -1,5 +0,0 @@ - From cd5c975a64293267eb4c47f6bfd64854ddbaa288 Mon Sep 17 00:00:00 2001 From: shizhao Date: Tue, 22 Mar 2011 00:34:13 +0800 Subject: [PATCH 05/14] del --- login.php | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 login.php diff --git a/login.php b/login.php deleted file mode 100644 index 0ea1bc7..0000000 --- a/login.php +++ /dev/null @@ -1,15 +0,0 @@ - - - - - -

-
-Username:
-Password:
-Latidude code:
-you can find Latidude code here. - -
- - From 0386dc970b6f1a5fa72727d703eb65f1a56a93ab Mon Sep 17 00:00:00 2001 From: shizhao Date: Tue, 22 Mar 2011 00:41:42 +0800 Subject: [PATCH 06/14] del --- config.php | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 config.php diff --git a/config.php b/config.php deleted file mode 100644 index a70a22a..0000000 --- a/config.php +++ /dev/null @@ -1,6 +0,0 @@ - From 4a3fd55e6a4888d55eeffc18ac5d268bedb2f984 Mon Sep 17 00:00:00 2001 From: shizhao Date: Tue, 22 Mar 2011 00:42:28 +0800 Subject: [PATCH 07/14] config --- config.php | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 config.php diff --git a/config.php b/config.php new file mode 100644 index 0000000..9a080e4 --- /dev/null +++ b/config.php @@ -0,0 +1,7 @@ + From 8aaaf84b55e2401f7a310eb8418f7a3a41cee89b Mon Sep 17 00:00:00 2001 From: shizhao Date: Tue, 22 Mar 2011 01:11:47 +0800 Subject: [PATCH 08/14] fix list of venues near the current location --- index.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/index.php b/index.php index 552693b..cc4856b 100644 --- a/index.php +++ b/index.php @@ -26,14 +26,16 @@ require_once "kernel/latitude.php"; $fsObjUnAuth->setAccessToken($_COOKIE['access_token']); $venues = $fsObjUnAuth->get('/venues/search', array('ll' => "{$latitude},{$longitude}", 'limit' => 50)); - foreach ($venues->response->groups[0]->items as $venue) { - $name = $venue->name; - $id = $venue->id; - $dist = $venue->location->distance; - $add = $venue->location->address; - $city = $venue->location->city; - $state = $venue->location->state; - echo "$name - $dist m
" ; + foreach ($venues->response->groups as $groups) { + foreach ($groups->items as $venue) { + $name = $venue->name; + $id = $venue->id; + $dist = $venue->location->distance; + $add = $venue->location->address; + $city = $venue->location->city; + $state = $venue->location->state; + echo "$name - $dist m
" ; + } } echo "
Add venue
"; @@ -41,5 +43,6 @@ echo "
Logout
"; } ?>
+ From 0fcf7194ba7eb457f488810a1daae1e84f788923 Mon Sep 17 00:00:00 2001 From: shizhao Date: Wed, 23 Mar 2011 01:03:59 +0800 Subject: [PATCH 09/14] 2.0 done! add photo upload --- CHANGELOG | 5 ++ add.php | 3 +- check.php | 7 +-- checkin.php | 58 +++++++++++++++------- index.php | 7 +-- kernel/EpiFoursquare.php | 12 +++-- LICENSE => kernel/LICENSE | 0 README.markdown => kernel/README.markdown | 0 photo.php | 51 ------------------- robots.txt | 2 + signinwith-foursquare.png | Bin 0 -> 4400 bytes 11 files changed, 64 insertions(+), 81 deletions(-) rename LICENSE => kernel/LICENSE (100%) rename README.markdown => kernel/README.markdown (100%) delete mode 100644 photo.php create mode 100644 robots.txt create mode 100644 signinwith-foursquare.png diff --git a/CHANGELOG b/CHANGELOG index 45aa044..c60b599 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,3 +15,8 @@ 1.5 - fixed Issue 6 - login screen add latidude_code, not need conf/conf.php - Now latidude_code with minus sign (some latidude_code of user no with minus sign) + +2.0 - update to 4sq API V2, using foursquare-async, https://github.com/jmathai/foursquare-async + - rewrite code + - support upload photo + diff --git a/add.php b/add.php index a286dab..38d25b7 100644 --- a/add.php +++ b/add.php @@ -1,6 +1,7 @@ - + +

diff --git a/check.php b/check.php index 1176137..3d47a96 100644 --- a/check.php +++ b/check.php @@ -4,6 +4,7 @@ +

@@ -41,7 +42,7 @@ $adds = implode(", ", $array); echo "$adds
"; - echo "
"; + echo ""; echo ""; echo ""; @@ -50,8 +51,8 @@ echo "shout:
"; echo "private:
"; echo "twitter:
"; - echo "Facebook:
"; - echo "Image:
"; + echo "Facebook:
"; + echo "Photo:
"; echo "
"; } ?> diff --git a/checkin.php b/checkin.php index 7e24136..b3dc3bb 100644 --- a/checkin.php +++ b/checkin.php @@ -1,6 +1,7 @@ +

@@ -15,40 +16,53 @@ $name = $_POST['name']; $geolat = $_POST['latitude']; $geolong = $_POST['longitude']; -$photo = $_POST['media']; +$privat = 'public'; -if ($_POST['privat']== NULL){ - $privat = 'public'; - if ($_POST['facebook']== 1) - $privat = 'public, facebook'; - if ($_POST['twitter']== 1) - $privat = 'public,facebook,twitter'; - } -else { - $privat = 'private'; +if ($_FILES['photo']['name'] == NULL){ + if ($_POST['privat']== NULL){ + $privat = 'public'; + if ($_POST['facebook']== 1) + $privat = $privat.' ,facebook'; + if ($_POST['twitter']== 1) + $privat = $privat.' ,twitter'; + } + else { + $privat = 'private'; + } } $checkin = $fsObjUnAuth->post('/checkins/add',array( 'venueId' => "{$id}", 'venue' => "{$name}", 'shout'=>"{$shout}", 'broadcast' => "{$privat}", 'll' => "{$geolat},{$geolong}" )); -if {$photo !=NULL){ +if ($_FILES['photo']['name'] !=NULL){ -$pcheckin = $fsObjUnAuth->post('/photos/add',array( - 'venueId' => "{$id}", 'broadcast' => "{$privat}", 'll' => "{$geolat},{$geolong}" - )); -} + if (($_POST['twitter']== 1) && ($_POST['facebook']== 0)){ + $privat = 'twitter'; + } + elseif (($_POST['twitter']== 0) && ($_POST['facebook']== 1)) { + $privat = 'facebook'; + } + elseif (($_POST['twitter']== 1) && ($_POST['facebook']== 1)) { + $privat = 'twitter,facebook'; + } + else { + $privat = ''; + } + $postVars = array(); + $postVars['checkinId'] = $checkin->response->checkin->id; + $postVars['ll'] = "{$geolat},{$geolong}"; + $postVars['broadcast'] = "{$privat}"; + $postVars['photo'] = '@'.$_FILES['photo']['tmp_name']; + $pcheckin = $fsObjUnAuth->post('/photos/add', $postVars, $up=1); +} ?>
notifications[0]->item->message; $add = $checkin->response->checkin->venue ->location->address; -$mayor = $checkin->notifications[1]->item->message; -$score = $checkin->notifications[3]->item->scores; -$total = $checkin->notifications[3]->item->total; $notification=$checkin ->notifications; foreach ($notification as $notifications){ @@ -79,7 +93,13 @@ echo "Total: $total pts
"; } } +if ($_FILES['photo']['name'] !=NULL){ + $myphoto=$pcheckin->response->photo->sizes->items[2]->url; + echo "Photo upload done!
"; + echo ""; +} ?> +
diff --git a/index.php b/index.php index cc4856b..00d5e6e 100644 --- a/index.php +++ b/index.php @@ -8,6 +8,7 @@ +

@@ -15,7 +16,7 @@ if (!isset($_GET['code']) && !isset($_COOKIE['access_token'])){ $authorizeUrl = $fsObjUnAuth->getAuthorizeUrl($redirectUri); ?> - authorization + getAccessToken($_GET['code'], $redirectUri); @@ -40,9 +41,9 @@ echo "
Add venue
"; echo "I an here!
"; - echo "
Logout
"; + echo "Logout
"; } ?> +Power by 4sqr.
- diff --git a/kernel/EpiFoursquare.php b/kernel/EpiFoursquare.php index ab680c0..670e567 100644 --- a/kernel/EpiFoursquare.php +++ b/kernel/EpiFoursquare.php @@ -77,9 +77,9 @@ public function get($endpoint, $params = null) return $this->request('GET', $endpoint, $params); } - public function post($endpoint, $params = null) + public function post($endpoint, $params = null, $up = 0) { - return $this->request('POST', $endpoint, $params); + return $this->request('POST', $endpoint, $params, $up); } public function __construct($clientId = null, $clientSecret = null, $accessToken = null) @@ -97,7 +97,7 @@ private function getApiUrl($endpoint) return "{$this->apiUrl}{$endpoint}"; } - private function request($method, $endpoint, $params = null) + private function request($method, $endpoint, $params = null, $up = 0) { if(preg_match('#^https?://#', $endpoint)) $url = $endpoint; @@ -128,7 +128,11 @@ private function request($method, $endpoint, $params = null) curl_setopt($ch, CURLOPT_INTERFACE, $_SERVER ['SERVER_ADDR']); if($method === 'POST' && $params !== null) { - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); + if ($up == 0) { + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); + } else { + curl_setopt($ch, CURLOPT_POSTFIELDS, $params); + } } $resp = new EpiFoursquareJson(EpiCurl::getInstance()->addCurl($ch), $this->debug); diff --git a/LICENSE b/kernel/LICENSE similarity index 100% rename from LICENSE rename to kernel/LICENSE diff --git a/README.markdown b/kernel/README.markdown similarity index 100% rename from README.markdown rename to kernel/README.markdown diff --git a/photo.php b/photo.php deleted file mode 100644 index 9af288c..0000000 --- a/photo.php +++ /dev/null @@ -1,51 +0,0 @@ - 0) { - $digit = $num[strlen($num)-1]; - $decoded += $multi * strpos($alphabet, $digit); - $multi = $multi * strlen($alphabet); - $num = substr($num, 0, -1); - } - return $decoded; -} - -?> diff --git a/robots.txt b/robots.txt new file mode 100644 index 0000000..1f53798 --- /dev/null +++ b/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: / diff --git a/signinwith-foursquare.png b/signinwith-foursquare.png new file mode 100644 index 0000000000000000000000000000000000000000..3c0df807a0a02bdab4f26ee2a047536b71eca3aa GIT binary patch literal 4400 zcmV-05zp?4P)|(rujX5^d*mYxE+|!)8iQNPzscR>xgVP>|l;&Vg9iOrUs#t;ya5C|kdXhCQnjWn9&Ez{rczM02JqJJ6M=A5~QtNWIF@B7_*zx(~Zd*2&O z!QdCk`J2A(wMY^yW)nq9B@;{>0hmnu7YGJ}(1M{<<753?)igSXIH!N1RKLf^aj|X; zdK~(BsNAi5R3G#-8lvHw2G56EO{V;3-Uy~oDL~Gw83beqFk1-25&>BffJO+=1i~<| z0UgXCVCvxI`#~dL7|@L${~H!RxCV`q)5sS@2+*N=qj-*nZyH)poI+2111wfTZ_dne z*i1oK3B8;$sLhlLP>%p~7?fc!E1^`40JR#*tJ1N>VuqR7p7Q8X&xZ(hjsiLwzG=v= zn5hHWMu4*t{A>cuCd3f<`ntX7?(~Kv2auT&kFgnX2D_>ZWG$2m*+C!<0ay*)_sJSO zE7S+ohUR36i%Ttx0k@IHF@yFyew=#E$M8p>iU@(+N6ba zvp{lGLr23M1hiNPvNRytJb$Pe%l4dvBPcHvXNMo@sd%N;<~=^mW;-n}@~?gD!NURaufngB9FVAdCiy6n)RfR2Vc z253nlpsDEVl~I1=0>;KBL9&`@K`6oF8-!J|!sqj&-{L~hSc_xapouYCn$O}wKEG$imrn9pe)PWrgfjcTWqTvn(bKbm_ThnrL;jigJ zN$U{e;^IY=Br_C6CSq0K4!GeCx?xc*=+4ZB$6*(RJzf=8+l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bsq@;?%bF;;r@bM42X9=x%uDGuTNYaKExW&n+&- zOQEqkLVZ#`J{|FN{kH_{qI4(T-nhuH=f`_bV=T$VwPktO@|(l>=t3Lfl62ktXLM~N zO}IBct1Xn;JCsf z#F6`sCopqlP}@m@#8G;pUdDx1+0e^jiNWE6Q#Zr{kOPDHTO|x;6&^pufS&d=okB(B zDjYv^U4Ko^pdRrFX*B%l2KJmTl6xkz^nY$k$Hh8gXkrB)xfGCA4pVzjXk85oQT&{V z5?!{S{)S?(F@u`H{DVE0bTB(4EGf1?CKeeYAbUAdoqk!<8Jd91@*@o9$k*OcK>uln zz5%b{MgCvBDU=Dc0bW=s1ZZBcP^wW>=~$IXuLR7Pkw@pMgoX}HfO^)CjtYsvA;oSY zZOJ;^rvsTl%&CuJfR1^>u;)|*0bO!L**O~SCZPF)B4%jKYzn>j;5USlU}xD%I+%oe ztksNZ*(Bfz)J@$mz??*Kt)f67HYS!Q2IfyjN2aXN)gbSr=sO7;-oYa0n~~%ml+AML6l|t;q_|bYdb#yI6#xY&r#M> zK375@RszbcpK(RO91V93(1b8QfsH>RQYF&6{7EQ(l*C&q7EOGh&!3oD`KviP&P|YE zGue=4moeniwKfBqwQ?W?VzCvd>iU_ZcpJ&vP>4#6Xt>LO7C)a7pLX)PkiWZNz0C51 zWrqm?DfGix{%)FoN@X&^ZuSwF^e-r%b`%7bfSLFEvy6m)?^8!&m`c0(B&i=~SfQ5N2Nk)WKWe4!_>E qTD`RBjE#ah8t!`F|Hk0I1sDJs&66}V;_op40000 Date: Wed, 23 Mar 2011 01:07:57 +0800 Subject: [PATCH 10/14] hr --- add.php | 3 ++- check.php | 3 ++- checkin.php | 3 ++- index.php | 1 + 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/add.php b/add.php index 38d25b7..b914380 100644 --- a/add.php +++ b/add.php @@ -36,7 +36,8 @@ $id=$venues->response->venue->id; echo "Check in!
" ; ?> - +
+Power by 4sqr.
diff --git a/check.php b/check.php index 3d47a96..eb20549 100644 --- a/check.php +++ b/check.php @@ -56,7 +56,8 @@ echo ""; } ?> - +
+Power by 4sqr.
diff --git a/checkin.php b/checkin.php index b3dc3bb..504a710 100644 --- a/checkin.php +++ b/checkin.php @@ -99,7 +99,8 @@ echo ""; } ?> - +
+Power by 4sqr.
diff --git a/index.php b/index.php index 00d5e6e..dc42bf8 100644 --- a/index.php +++ b/index.php @@ -43,6 +43,7 @@ echo "I an here!
"; echo "Logout
"; } ?> +
Power by 4sqr.
From c2354f7eb70b58d419c501e5f665ab2be458efc9 Mon Sep 17 00:00:00 2001 From: shizhao Date: Wed, 23 Mar 2011 01:10:57 +0800 Subject: [PATCH 11/14] readme --- README | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..c60b599 --- /dev/null +++ b/README @@ -0,0 +1,22 @@ +1.0 - Initial relsese +1.1 - Remaked the Google Laitiude code + - minor changes to the index.php + - removed the shout form in check.php (the damm PHP Class does not work for shouting) + - Private check in works + - +1.2 - now can add venue + - fix POST error + - show checkin response + - add shout, but not work + - suppot twitter & facebook +1.3 - shout now work +1.4 - add login screen, and logout + - add 4sqr logo +1.5 - fixed Issue 6 + - login screen add latidude_code, not need conf/conf.php + - Now latidude_code with minus sign (some latidude_code of user no with minus sign) + +2.0 - update to 4sq API V2, using foursquare-async, https://github.com/jmathai/foursquare-async + - rewrite code + - support upload photo + From 4149fbff8dc0525d5667b1de53da1d20dfd5b4c6 Mon Sep 17 00:00:00 2001 From: shizhao Date: Wed, 23 Mar 2011 01:11:26 +0800 Subject: [PATCH 12/14] readme --- CHANGELOG | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 CHANGELOG diff --git a/CHANGELOG b/CHANGELOG deleted file mode 100644 index c60b599..0000000 --- a/CHANGELOG +++ /dev/null @@ -1,22 +0,0 @@ -1.0 - Initial relsese -1.1 - Remaked the Google Laitiude code - - minor changes to the index.php - - removed the shout form in check.php (the damm PHP Class does not work for shouting) - - Private check in works - - -1.2 - now can add venue - - fix POST error - - show checkin response - - add shout, but not work - - suppot twitter & facebook -1.3 - shout now work -1.4 - add login screen, and logout - - add 4sqr logo -1.5 - fixed Issue 6 - - login screen add latidude_code, not need conf/conf.php - - Now latidude_code with minus sign (some latidude_code of user no with minus sign) - -2.0 - update to 4sq API V2, using foursquare-async, https://github.com/jmathai/foursquare-async - - rewrite code - - support upload photo - From 2377bdd2f46d40598927d786090e9e086a72355f Mon Sep 17 00:00:00 2001 From: shizhao Date: Wed, 23 Mar 2011 01:39:51 +0800 Subject: [PATCH 13/14] at --- index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.php b/index.php index dc42bf8..2c6662f 100644 --- a/index.php +++ b/index.php @@ -40,7 +40,7 @@ } echo "
Add venue
"; - echo "I an here!
"; + echo "I at here!
"; echo "Logout
"; } ?>
From 11a66a8f37299841faf746baaa913e029f273ea8 Mon Sep 17 00:00:00 2001 From: shizhao Date: Tue, 17 May 2011 02:02:58 +0800 Subject: [PATCH 14/14] :2.1 --- README | 3 + check.php | 58 +++- config.php | 3 +- index.php | 58 +++- kernel/.svn/all-wcprops | 41 +++ kernel/.svn/entries | 256 +++++++++++++++++ kernel/.svn/prop-base/EpiCurl.php.svn-base | 5 + .../.svn/prop-base/EpiFoursquare.php.svn-base | 5 + .../.svn/prop-base/EpiSequence.php.svn-base | 5 + kernel/.svn/text-base/EpiCurl.php.svn-base | 191 +++++++++++++ .../.svn/text-base/EpiFoursquare.php.svn-base | 263 ++++++++++++++++++ .../.svn/text-base/EpiSequence.php.svn-base | 54 ++++ kernel/.svn/text-base/LICENSE.svn-base | 24 ++ .../.svn/text-base/README.markdown.svn-base | 31 +++ kernel/.svn/text-base/latitude.php.svn-base | 19 ++ kernel/latitude.php | 8 + places.php | 27 ++ simpleTest.php | 6 +- 18 files changed, 1028 insertions(+), 29 deletions(-) create mode 100644 kernel/.svn/all-wcprops create mode 100644 kernel/.svn/entries create mode 100644 kernel/.svn/prop-base/EpiCurl.php.svn-base create mode 100644 kernel/.svn/prop-base/EpiFoursquare.php.svn-base create mode 100644 kernel/.svn/prop-base/EpiSequence.php.svn-base create mode 100644 kernel/.svn/text-base/EpiCurl.php.svn-base create mode 100644 kernel/.svn/text-base/EpiFoursquare.php.svn-base create mode 100644 kernel/.svn/text-base/EpiSequence.php.svn-base create mode 100644 kernel/.svn/text-base/LICENSE.svn-base create mode 100644 kernel/.svn/text-base/README.markdown.svn-base create mode 100644 kernel/.svn/text-base/latitude.php.svn-base create mode 100644 places.php diff --git a/README b/README index c60b599..abda7f4 100644 --- a/README +++ b/README @@ -19,4 +19,7 @@ 2.0 - update to 4sq API V2, using foursquare-async, https://github.com/jmathai/foursquare-async - rewrite code - support upload photo +2.1 - fix Issue 12 + - Search Venues: add favorites, trending,and nearby types + - Google Places Searches diff --git a/check.php b/check.php index eb20549..89b8416 100644 --- a/check.php +++ b/check.php @@ -9,23 +9,51 @@

"; - echo "
"; - echo"Add venue:
"; - echo"name:
"; - echo "address:
"; - echo "crossstreet:
"; - echo "city:
"; - echo "state:
"; - echo "zip:
"; - echo "phone:
"; - echo ""; - echo ""; - echo ""; + if ($ref ==Null){ + echo "
"; + echo ""; + echo"Add venue:
"; + echo"name:
"; + echo "address:
"; + echo "crossstreet:
"; + echo "city:
"; + echo "state:
"; + echo "zip:
"; + echo "phone:
"; + echo ""; + echo ""; + echo ""; + } + else { + $name=$placedetails["result"]["name"]; + $address=$placedetails["result"]["formatted_address"]; + if ($placedetails["result"]["address_components"] !=Null) { + foreach ($placedetails["result"]["address_components"] as $address_components) { + if ($address_components["types"][0]=="postal_code"){ + $zip=$address_components["long_name"]; + } + } + } + $phone=$placedetails["result"]["formatted_phone_number"]; + echo "
"; + echo ""; + echo"Add venue:
"; + echo"name:
"; + echo "address:
"; + echo "crossstreet:
"; + echo "city:
"; + echo "state:
"; + echo "zip:
"; + echo "phone:
"; + echo ""; + echo ""; + echo ""; + } } diff --git a/config.php b/config.php index 9a080e4..5662f08 100644 --- a/config.php +++ b/config.php @@ -3,5 +3,6 @@ $clientId = ''; //Your CLIENT ID $clientSecret = ''; //CLIENT SECRET $redirectUri = ''; //CALLBACK URL, is http://path/index.php, path is your URL -$latidude_code = ''; ///* google latitude user id... you can find it at http://www.google.com/latitude/apps/badge +$latidude_code = ''; //* google latitude user id... you can find it at http://www.google.com/latitude/apps/badge +$placeskey = ''; //* Google Places API key... you must require it, see https://code.google.com/apis/maps/documentation/places/#Limits ?> diff --git a/index.php b/index.php index 2c6662f..da24a8f 100644 --- a/index.php +++ b/index.php @@ -28,18 +28,56 @@ $fsObjUnAuth->setAccessToken($_COOKIE['access_token']); $venues = $fsObjUnAuth->get('/venues/search', array('ll' => "{$latitude},{$longitude}", 'limit' => 50)); foreach ($venues->response->groups as $groups) { - foreach ($groups->items as $venue) { - $name = $venue->name; - $id = $venue->id; - $dist = $venue->location->distance; - $add = $venue->location->address; - $city = $venue->location->city; - $state = $venue->location->state; - echo "$name - $dist m
" ; + if ($groups->type =='favorites'){ + echo $groups->name.'
'; + foreach ($groups->items as $venue) { + $name = $venue->name; + $id = $venue->id; + $dist = $venue->location->distance; + $add = $venue->location->address; + $city = $venue->location->city; + $state = $venue->location->state; + echo "$name - $dist m
" ; + } } + elseif ($groups->type =='trending'){ + echo $groups->name.'
'; + foreach ($groups->items as $venue) { + $name = $venue->name; + $id = $venue->id; + $dist = $venue->location->distance; + $add = $venue->location->address; + $city = $venue->location->city; + $state = $venue->location->state; + echo "$name - $dist m
" ; + } + } + elseif ($groups->type =='nearby') { + echo $groups->name.'
'; + foreach ($groups->items as $venue) { + $name = $venue->name; + $id = $venue->id; + $dist = $venue->location->distance; + $add = $venue->location->address; + $city = $venue->location->city; + $state = $venue->location->state; + echo "$name - $dist m
" ; + } + } + else { + foreach ($groups->items as $venue) { + $name = $venue->name; + $id = $venue->id; + $dist = $venue->location->distance; + $add = $venue->location->address; + $city = $venue->location->city; + $state = $venue->location->state; + echo "$name - $dist m
" ; + } + } } - - echo "
Add venue
"; + echo "
Place Searches
"; + echo "Add venue
"; echo "I at here!
"; echo "Logout
"; } ?> diff --git a/kernel/.svn/all-wcprops b/kernel/.svn/all-wcprops new file mode 100644 index 0000000..5ef6682 --- /dev/null +++ b/kernel/.svn/all-wcprops @@ -0,0 +1,41 @@ +K 25 +svn:wc:ra_dav:version-url +V 29 +/svn/!svn/ver/30/trunk/kernel +END +EpiFoursquare.php +K 25 +svn:wc:ra_dav:version-url +V 47 +/svn/!svn/ver/33/trunk/kernel/EpiFoursquare.php +END +latitude.php +K 25 +svn:wc:ra_dav:version-url +V 42 +/svn/!svn/ver/31/trunk/kernel/latitude.php +END +LICENSE +K 25 +svn:wc:ra_dav:version-url +V 37 +/svn/!svn/ver/33/trunk/kernel/LICENSE +END +EpiCurl.php +K 25 +svn:wc:ra_dav:version-url +V 41 +/svn/!svn/ver/33/trunk/kernel/EpiCurl.php +END +EpiSequence.php +K 25 +svn:wc:ra_dav:version-url +V 45 +/svn/!svn/ver/33/trunk/kernel/EpiSequence.php +END +README.markdown +K 25 +svn:wc:ra_dav:version-url +V 45 +/svn/!svn/ver/33/trunk/kernel/README.markdown +END diff --git a/kernel/.svn/entries b/kernel/.svn/entries new file mode 100644 index 0000000..bf55929 --- /dev/null +++ b/kernel/.svn/entries @@ -0,0 +1,256 @@ +10 + +dir +30 +https://4sqr.googlecode.com/svn/trunk/kernel +https://4sqr.googlecode.com/svn + + + +2010-09-13T14:25:21.033276Z +30 +shizhao@gmail.com + + + + + + + + + + + + + + +d216f025-e60a-a35b-bdfd-79cb14247bae + +EpiFoursquare.php +file +33 + + + +2011-03-22T15:41:18.000000Z +27e60a72a0c6ac229b8a7ebce51d48c5 +2011-03-22T17:35:09.778978Z +33 +shizhao@gmail.com +has-props + + + + + + + + + + + + + + + + + + + + +7847 + +latitude.php +file +31 + + + +2011-03-21T15:45:09.000000Z +3a269fa378d8130f77268c04ad81e2bb +2011-03-22T17:29:28.230031Z +31 +shizhao@gmail.com + + + + + + + + + + + + + + + + + + + + + +569 + +LICENSE +file +33 + + + +2011-03-21T14:13:47.000000Z +a6f50a9c4566c24df6d80bc1f8c1f5b8 +2011-03-22T17:35:09.778978Z +33 +shizhao@gmail.com + + + + + + + + + + + + + + + + + + + + + +1479 + +foursquare.class.php +file +33 + + + + + + + + + + + + + + + + + + + +deleted + +EpiCurl.php +file +33 + + + +2011-03-21T14:13:47.000000Z +9f7d8a87574022eb78e1f7bea4f9ac03 +2011-03-22T17:35:09.778978Z +33 +shizhao@gmail.com +has-props + + + + + + + + + + + + + + + + + + + + +4823 + +EpiSequence.php +file +33 + + + +2011-03-21T14:13:47.000000Z +af97792e8781a0bcf563e49df08695af +2011-03-22T17:35:09.778978Z +33 +shizhao@gmail.com +has-props + + + + + + + + + + + + + + + + + + + + +1321 + +README.markdown +file +33 + + + +2011-03-21T14:13:47.000000Z +e4e1f18d1b4292ca93218a0d14277028 +2011-03-22T17:35:09.778978Z +33 +shizhao@gmail.com + + + + + + + + + + + + + + + + + + + + + +1193 + diff --git a/kernel/.svn/prop-base/EpiCurl.php.svn-base b/kernel/.svn/prop-base/EpiCurl.php.svn-base new file mode 100644 index 0000000..bdbd305 --- /dev/null +++ b/kernel/.svn/prop-base/EpiCurl.php.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:eol-style +V 6 +native +END diff --git a/kernel/.svn/prop-base/EpiFoursquare.php.svn-base b/kernel/.svn/prop-base/EpiFoursquare.php.svn-base new file mode 100644 index 0000000..bdbd305 --- /dev/null +++ b/kernel/.svn/prop-base/EpiFoursquare.php.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:eol-style +V 6 +native +END diff --git a/kernel/.svn/prop-base/EpiSequence.php.svn-base b/kernel/.svn/prop-base/EpiSequence.php.svn-base new file mode 100644 index 0000000..bdbd305 --- /dev/null +++ b/kernel/.svn/prop-base/EpiSequence.php.svn-base @@ -0,0 +1,5 @@ +K 13 +svn:eol-style +V 6 +native +END diff --git a/kernel/.svn/text-base/EpiCurl.php.svn-base b/kernel/.svn/text-base/EpiCurl.php.svn-base new file mode 100644 index 0000000..71fb870 --- /dev/null +++ b/kernel/.svn/text-base/EpiCurl.php.svn-base @@ -0,0 +1,191 @@ +mc = curl_multi_init(); + $this->properties = array( + 'code' => CURLINFO_HTTP_CODE, + 'time' => CURLINFO_TOTAL_TIME, + 'length'=> CURLINFO_CONTENT_LENGTH_DOWNLOAD, + 'type' => CURLINFO_CONTENT_TYPE, + 'url' => CURLINFO_EFFECTIVE_URL + ); + } + + public function addCurl($ch) + { + $key = $this->getKey($ch); + $this->requests[$key] = $ch; + curl_setopt($ch, CURLOPT_HEADERFUNCTION, array($this, 'headerCallback')); + + $code = curl_multi_add_handle($this->mc, $ch); + $this->startTimer($key); + + // (1) + if($code === CURLM_OK || $code === CURLM_CALL_MULTI_PERFORM) + { + do { + $code = $this->execStatus = curl_multi_exec($this->mc, $this->running); + } while ($this->execStatus === CURLM_CALL_MULTI_PERFORM); + + return new EpiCurlManager($key); + } + else + { + return $code; + } + } + + public function getResult($key = null) + { + if($key != null) + { + if(isset($this->responses[$key])) + { + return $this->responses[$key]; + } + + $innerSleepInt = $outerSleepInt = 1; + while($this->running && ($this->execStatus == CURLM_OK || $this->execStatus == CURLM_CALL_MULTI_PERFORM)) + { + usleep($outerSleepInt); + $outerSleepInt = intval(max(1, ($outerSleepInt*$this->sleepIncrement))); + $ms=curl_multi_select($this->mc, 0); + if($ms > 0) + { + do{ + $this->execStatus = curl_multi_exec($this->mc, $this->running); + usleep($innerSleepInt); + $innerSleepInt = intval(max(1, ($innerSleepInt*$this->sleepIncrement))); + }while($this->execStatus==CURLM_CALL_MULTI_PERFORM); + $innerSleepInt = 1; + } + $this->storeResponses(); + if(isset($this->responses[$key]['data'])) + { + return $this->responses[$key]; + } + $runningCurrent = $this->running; + } + return null; + } + return false; + } + + public static function getSequence() + { + return new EpiSequence(self::$timers); + } + + public static function getTimers() + { + return self::$timers; + } + + private function getKey($ch) + { + return (string)$ch; + } + + private function headerCallback($ch, $header) + { + $_header = trim($header); + $colonPos= strpos($_header, ':'); + if($colonPos > 0) + { + $key = substr($_header, 0, $colonPos); + $val = preg_replace('/^\W+/','',substr($_header, $colonPos)); + $this->responses[$this->getKey($ch)]['headers'][$key] = $val; + } + return strlen($header); + } + + private function storeResponses() + { + while($done = curl_multi_info_read($this->mc)) + { + $key = (string)$done['handle']; + $this->stopTimer($key, $done); + $this->responses[$key]['data'] = curl_multi_getcontent($done['handle']); + foreach($this->properties as $name => $const) + { + $this->responses[$key][$name] = curl_getinfo($done['handle'], $const); + } + curl_multi_remove_handle($this->mc, $done['handle']); + curl_close($done['handle']); + } + } + + private function startTimer($key) + { + self::$timers[$key]['start'] = microtime(true); + } + + private function stopTimer($key, $done) + { + self::$timers[$key]['end'] = microtime(true); + self::$timers[$key]['api'] = curl_getinfo($done['handle'], CURLINFO_EFFECTIVE_URL); + self::$timers[$key]['time'] = curl_getinfo($done['handle'], CURLINFO_TOTAL_TIME); + self::$timers[$key]['code'] = curl_getinfo($done['handle'], CURLINFO_HTTP_CODE); + } + + static function getInstance() + { + if(self::$inst == null) + { + self::$singleton = 1; + self::$inst = new EpiCurl(); + } + + return self::$inst; + } +} + +class EpiCurlManager +{ + private $key; + private $epiCurl; + + public function __construct($key) + { + $this->key = $key; + $this->epiCurl = EpiCurl::getInstance(); + } + + public function __get($name) + { + $responses = $this->epiCurl->getResult($this->key); + return isset($responses[$name]) ? $responses[$name] : null; + } + + public function __isset($name) + { + $val = self::__get($name); + return empty($val); + } +} + +/* + * Credits: + * - (1) Alistair pointed out that curl_multi_add_handle can return CURLM_CALL_MULTI_PERFORM on success. + */ diff --git a/kernel/.svn/text-base/EpiFoursquare.php.svn-base b/kernel/.svn/text-base/EpiFoursquare.php.svn-base new file mode 100644 index 0000000..670e567 --- /dev/null +++ b/kernel/.svn/text-base/EpiFoursquare.php.svn-base @@ -0,0 +1,263 @@ + + */ +class EpiFoursquare +{ + protected $clientId, $clientSecret, $accessToken; + protected $requestTokenUrl= 'https://foursquare.com/oauth2/authenticate'; + protected $accessTokenUrl = 'https://foursquare.com/oauth2/access_token'; + protected $authorizeUrl = 'https://foursquare.com/oauth2/authorize'; + protected $apiUrl = 'https://api.foursquare.com'; + protected $userAgent = 'EpiFoursquare (http://github.com/jmathai/foursquare-async/tree/)'; + protected $apiVersion = 'v2'; + protected $isAsynchronous = false; + protected $followLocation = false; + protected $connectionTimeout = 5; + protected $requestTimeout = 30; + protected $debug = false; + + public function getAccessToken($code, $redirectUri) + { + $params = array('client_id' => $this->clientId, 'client_secret' => $this->clientSecret, 'grant_type' => 'authorization_code', 'redirect_uri' => $redirectUri, 'code' => $code); + $qs = http_build_query($params); + return $this->request('GET', "{$this->accessTokenUrl}", $params); + } + + public function getAuthorizeUrl($redirectUri) + { + $params = array('client_id' => $this->clientId, 'response_type' => 'code', 'redirect_uri' => $redirectUri); + $qs = http_build_query($params); + return "{$this->requestTokenUrl}?{$qs}"; + } + + public function setAccessToken($accessToken) + { + $this->accessToken = $accessToken; + } + + public function setTimeout($requestTimeout = null, $connectionTimeout = null) + { + if($requestTimeout !== null) + $this->requestTimeout = floatval($requestTimeout); + if($connectionTimeout !== null) + $this->connectionTimeout = floatval($connectionTimeout); + } + + public function setUserAgent($agent) + { + $this->userAgent = $agent; + } + + public function useApiVersion($version = null) + { + $this->apiVersion = $version; + } + + public function useAsynchronous($async = true) + { + $this->isAsynchronous = (bool)$async; + } + + // Public api interface for most calls GET/POST/DELETE + public function delete($endpoint, $params = null) + { + return $this->request('DELETE', $endpoint, $params); + } + + public function get($endpoint, $params = null) + { + return $this->request('GET', $endpoint, $params); + } + + public function post($endpoint, $params = null, $up = 0) + { + return $this->request('POST', $endpoint, $params, $up); + } + + public function __construct($clientId = null, $clientSecret = null, $accessToken = null) + { + $this->clientId = $clientId; + $this->clientSecret = $clientSecret; + $this->accessToken = $accessToken; + } + + private function getApiUrl($endpoint) + { + if(!empty($this->apiVersion)) + return "{$this->apiUrl}/{$this->apiVersion}{$endpoint}"; + else + return "{$this->apiUrl}{$endpoint}"; + } + + private function request($method, $endpoint, $params = null, $up = 0) + { + if(preg_match('#^https?://#', $endpoint)) + $url = $endpoint; + else + $url = $this->getApiUrl($endpoint); + + if($this->accessToken) + { + $params['oauth_token'] = $this->accessToken; + } + else + { + $params['client_id'] = $this->clientId; + $params['client_secret'] = $this->clientSecret; + } + + if($method === 'GET') + $url .= is_null($params) ? '' : '?'.http_build_query($params, '', '&'); + $ch = curl_init($url); + curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + curl_setopt($ch, CURLOPT_TIMEOUT, $this->requestTimeout); + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); + if(isset($_SERVER ['SERVER_ADDR']) && !empty($_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] != '127.0.0.1') + curl_setopt($ch, CURLOPT_INTERFACE, $_SERVER ['SERVER_ADDR']); + if($method === 'POST' && $params !== null) + { + if ($up == 0) { + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); + } else { + curl_setopt($ch, CURLOPT_POSTFIELDS, $params); + } + } + + $resp = new EpiFoursquareJson(EpiCurl::getInstance()->addCurl($ch), $this->debug); + if(!$this->isAsynchronous) + $resp->responseText; + + return $resp; + } +} + +class EpiFoursquareJson implements ArrayAccess, Countable, IteratorAggregate +{ + private $debug; + private $__resp; + public function __construct($response, $debug = false) + { + $this->__resp = $response; + $this->debug = $debug; + } + + // ensure that calls complete by blocking for results, NOOP if already returned + public function __destruct() + { + $this->responseText; + } + + // Implementation of the IteratorAggregate::getIterator() to support foreach ($this as $...) + public function getIterator () + { + if ($this->__obj) { + return new ArrayIterator($this->__obj); + } else { + return new ArrayIterator($this->response); + } + } + + // Implementation of Countable::count() to support count($this) + public function count () + { + return count($this->response); + } + + // Next four functions are to support ArrayAccess interface + // 1 + public function offsetSet($offset, $value) + { + $this->response[$offset] = $value; + } + + // 2 + public function offsetExists($offset) + { + return isset($this->response[$offset]); + } + + // 3 + public function offsetUnset($offset) + { + unset($this->response[$offset]); + } + + // 4 + public function offsetGet($offset) + { + return isset($this->response[$offset]) ? $this->response[$offset] : null; + } + + public function __get($name) + { + $accessible = array('responseText'=>1,'headers'=>1,'code'=>1); + $this->responseText = $this->__resp->data; + $this->headers = $this->__resp->headers; + $this->code = $this->__resp->code; + if(isset($accessible[$name]) && $accessible[$name]) + return $this->$name; + elseif(($this->code < 200 || $this->code >= 400) && !isset($accessible[$name])) + EpiFoursquareException::raise($this->__resp, $this->debug); + + // Call appears ok so we can fill in the response + $this->response = json_decode($this->responseText, 1); + $this->__obj = json_decode($this->responseText); + + if(gettype($this->__obj) === 'object') + { + foreach($this->__obj as $k => $v) + { + $this->$k = $v; + } + } + + if (property_exists($this, $name)) { + return $this->$name; + } + return null; + } + + public function __isset($name) + { + $value = self::__get($name); + return !empty($name); + } +} + +class EpiFoursquareException extends Exception +{ + public static function raise($response, $debug) + { + $message = $response->data; + + switch($response->code) + { + case 400: + throw new EpiFoursquareBadRequestException($message, $response->code); + case 401: + throw new EpiFoursquareNotAuthorizedException($message, $response->code); + case 403: + throw new EpiFoursquareForbiddenException($message, $response->code); + case 404: + throw new EpiFoursquareNotFoundException($message, $response->code); + default: + throw new EpiFoursquareException($message, $response->code); + } + } +} +class EpiFoursquareBadRequestException extends EpiFoursquareException{} +class EpiFoursquareNotAuthorizedException extends EpiFoursquareException{} +class EpiFoursquareForbiddenException extends EpiFoursquareException{} +class EpiFoursquareNotFoundException extends EpiFoursquareException{} diff --git a/kernel/.svn/text-base/EpiSequence.php.svn-base b/kernel/.svn/text-base/EpiSequence.php.svn-base new file mode 100644 index 0000000..c47c0c2 --- /dev/null +++ b/kernel/.svn/text-base/EpiSequence.php.svn-base @@ -0,0 +1,54 @@ +timers = $timers; + + $min = PHP_INT_MAX; + $max = 0; + foreach($this->timers as $timer) + { + $min = min($timer['start'], $min); + $max = max($timer['end'], $max); + } + $this->min = $min; + $this->max = $max; + $this->range = $max-$min; + $this->step = floatval($this->range/$this->width); + } + + public function renderAscii() + { + $tpl = ''; + foreach($this->timers as $timer) + $tpl .= $this->tplAscii($timer); + + return $tpl; + } + + private function tplAscii($timer) + { + $lpad = $rpad = 0; + $lspace = $chars = $rspace = ''; + if($timer['start'] > $this->min) + $lpad = intval(($timer['start'] - $this->min) / $this->step); + if($timer['end'] < $this->max) + $rpad = intval(($this->max - $timer['end']) / $this->step); + $mpad = $this->width - $lpad - $rpad; + if($lpad > 0) + $lspace = str_repeat(' ', $lpad); + if($mpad > 0) + $chars = str_repeat('=', $mpad); + if($rpad > 0) + $rspace = str_repeat(' ', $rpad); + + $tpl = <<post('/checkins/add', array( + 'venueId' => '35610', 'broadcast' => 'public' + ) + ); + echo "You've checked in a total of {$checkin->response->checkins->count} times"; + + +### Documentation + +There's complete documentation available on Github at .. + +### The authors + +Get in touch with the authors if you have suggestions or questions. + + + + +
Jaisen Mathai
jaisen-at-jmathai.com
http://www.jaisenmathai.com
diff --git a/kernel/.svn/text-base/latitude.php.svn-base b/kernel/.svn/text-base/latitude.php.svn-base new file mode 100644 index 0000000..1c2d2c3 --- /dev/null +++ b/kernel/.svn/text-base/latitude.php.svn-base @@ -0,0 +1,19 @@ + diff --git a/places.php b/places.php new file mode 100644 index 0000000..b309afb --- /dev/null +++ b/places.php @@ -0,0 +1,27 @@ + + + + + + + +

+$name - $vic
"; +} +echo "
Add venue
"; +echo "I at here!
"; +?> +
+Power by 4sqr. +
+ + diff --git a/simpleTest.php b/simpleTest.php index 5f0d3c5..63ea3b8 100644 --- a/simpleTest.php +++ b/simpleTest.php @@ -1,7 +1,7 @@ response); ?> -
\ No newline at end of file +