-
Notifications
You must be signed in to change notification settings - Fork 0
/
fbConnect.php
90 lines (72 loc) · 2.75 KB
/
fbConnect.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<?php
require 'facebook.php';
class fbConnect {
private $facebook;
private $userId;
public function __construct($userId=null){
$this->userId = $userId!=null?$userId:'PoomTshaK';
$this->facebook = new Facebook(array(
'appId' => '127050684078153',
'secret' => '73ace9d64305ac92b18fa86612a66b03',
));
}
public function setUserId($userId=null){
$this->userId = $userId!=null?$userId:'PoomTshaK';
}
public function getUserId($userId=null){
return $this->userId;
}
public function getProfile(){
echo(json_encode($this->facebook->api($this->userId.'/')));
}
public function getPosts(){
echo(json_encode($this->facebook->api($this->userId.'/posts')));
}
public function getAlbums(){
$albums = $this->facebook->api($this->userId.'/albums');
$parsedAlbums = array();
foreach($albums['data'] as $album){
if(is_array($album) && $album['type'] == 'normal'){
$photos = $this->facebook->api($album['id'].'/photos');
$album['photos'] = $photos['data'];
$parsedAlbums[] = $album;
}
}
echo(json_encode($parsedAlbums));
}
public function getPastEvents(){
$posts = $this->facebook->api($this->userId.'/posts?until=today');
$events = array();
foreach($posts['data'] as $post){
//print_r($post);
if(is_array($post) && $post['type'] == 'event' ){
$events[] = $post;
}
if(is_array($post) && $post['type'] == 'status' && in_array('actions',array_keys($post)) && preg_match('#^http(|s)://www.facebook.com/events/?#',$post['actions'][0]['link'])){
$events[] = $this->facebook->api(preg_replace('#^http(|s)://www.facebook.com/events/?#','/',$post['actions'][0]['link']));
}
if(is_array($post) && $post['type'] == 'link' && preg_match('#^http(|s)://www.facebook.com/events/?#',$post['link'])){
$events[] = $this->facebook->api(preg_replace('#^http(|s)://www.facebook.com/events/?#','/',$post['link']));
}
}
echo(json_encode($events));
}
public function getNextEvents(){
$posts = $this->facebook->api($this->userId.'/posts?since=today');
$events = array();
foreach($posts['data'] as $post){
//print_r($post);
if(is_array($post) && $post['type'] == 'event' ){
$events[] = $post;
}
if(is_array($post) && $post['type'] == 'status' && in_array('actions',array_keys($post)) && preg_match('#^http(|s)://www.facebook.com/events/?#',$post['actions'][0]['link'])){
$events[] = $this->facebook->api(preg_replace('#^http(|s)://www.facebook.com/events/?#','/',$post['actions'][0]['link']));
}
if(is_array($post) && $post['type'] == 'link' && preg_match('#^http(|s)://www.facebook.com/events/?#',$post['link'])){
$events[] = $this->facebook->api(preg_replace('#^http(|s)://www.facebook.com/events/?#','/',$post['link']));
}
}
echo(json_encode($events));
}
}
?>