Dotclear

source: plugins/dcLibFoursquare/inc/lib.foursquare.utils.php @ 2955

Revision 2955, 2.3 KB checked in by JcDenis, 2 years ago (diff)

dcLibFoursquare 0.2-alpha2

  • First public release of Foursquare libraries for Dotclear
  • Added support of plugin soCialMe
Line 
1<?php
2# -- BEGIN LICENSE BLOCK ----------------------------------
3# This file is part of dcLibFoursquare, a plugin for Dotclear 2.
4#
5# Copyright (c) 2009-2011 JC Denis and contributors
6# jcdenis@gdwd.com
7#
8# Licensed under the GPL version 2.0 license.
9# A copy of this license is available in LICENSE file or at
10# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
11# -- END LICENSE BLOCK ------------------------------------
12
13class foursquareUtils
14{
15     public static $default_app = array('client_id'=>'','client_secret'=>'','redirect_uri'=>'');
16     
17     public static function decodeApp($side)
18     {
19          global $core;
20         
21          if ($side == 'admin') {
22               $enc = $core->blog->settings->dcLibFoursquare->oauth_admin;
23               $u = DC_ADMIN_URL;
24          }
25          else {
26               $enc = $core->blog->settings->dcLibFoursquare->oauth_public;
27               $u = $core->blog->url;
28          }
29         
30          $s = @unserialize(base64_decode($enc));
31          if (!is_array($s)) $s = array();
32         
33          if (empty($s['client_id']) || empty($s['client_secret']) || empty($s['redirect_uri']) || substr($s['redirect_uri'],0,strlen($u)) != $u)
34          {
35               $s = self::$default_app;
36          }
37          return array_merge(self::$default_app,$s);
38     }
39     
40     public static function encodeApp($side,$id,$secret,$uri)
41     {
42          global $core;
43         
44          if ($side == 'admin') {
45               $u = DC_ADMIN_URL;
46          }
47          else {
48               $u = $core->blog->url;
49          }
50         
51          $s = array(
52               'client_id' => $id,
53               'client_secret' => $secret,
54               'redirect_uri' => $uri
55          );
56          if (empty($s['client_id']) || empty($s['client_secret']) || empty($s['redirect_uri']) || substr($s['redirect_uri'],0,strlen($u)) != $u)
57          {
58               $s = self::$default_app;
59          }
60          $enc = base64_encode(serialize($s));
61         
62          if ($side == 'admin') {
63               $core->blog->settings->dcLibFoursquare->put('oauth_admin',$enc,'string','',true,true);
64          }
65          else {
66               $core->blog->settings->dcLibFoursquare->put('oauth_public',$enc);
67          }
68          return $s;
69     }
70     
71     //obj = oAuthClient20Foursquare object
72     public static function api($obj,$url,$params=array(),$method='GET')
73     {
74          $rsp = $obj->query($url,$method,$params);
75          if ($obj->http_code != 200) {
76               throw new Exception('Failed to query service');
77          }
78         
79          $rsp = json_decode($rsp);
80         
81          if ($rsp->meta->code != 200) {
82               throw new Exception('Bad query on service');
83          }
84         
85          return $rsp->response;
86     }
87     
88     //todo: parser for items (checkins, badges, etc)
89}
90
91?>
Note: See TracBrowser for help on using the repository browser.

Sites map