forked from webtechnick/CakePHP-Facebook-Plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfacebook_events.php
182 lines (162 loc) · 4.61 KB
/
facebook_events.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<?php
/*
* Short Description / title.
*
* Overview of what the file does. About a paragraph or two
*
* Copyright (c) 2010 Carl Sutton ( dogmatic69 )
*
* @filesource
* @copyright Copyright (c) 2010 Carl Sutton ( dogmatic69 )
* @link http://www.infinitas-cms.org
* @package {see_below}
* @subpackage {see_below}
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
* @since {check_current_milestone_in_lighthouse}
*
* @author {your_name}
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*/
final class FacebookEvents extends AppEvents{
public function onSetupCache() {
}
public function onRequireLibs(){
App::import('Lib', 'Facebook.FB');
}
public function onSetupConfig(){
return Configure::load('facebook.facebook');
}
private function __getConfig() {
$config = Configure::read('Facebook');
if(empty($config)) {
Configure::load('facebook.facebook');
$config = Configure::read('Facebook');
}
return $config;
}
public function onRequireComponentsToLoad($event){
return 'Facebook.Connect';
}
public function onRequireHelpersToLoad(){
return 'Facebook.Facebook';
}
public function onRequireTodoList($event){
$config = Configure::read('Facebook');
if(!empty($config)){
return false;
}
return array(
array(
'name' => 'Api key is not setup',
'type' => 'error',
'url' => '#'
)
);
}
/**
* Called before cms content is echo'ed
*/
public function onCmsBeforeContentRender($event, $data) {
$config = $this->__getConfig();
if(isset($config['Cms.before']) && in_array('like', $config['Cms.before'])) {
$link = $data['_this']->Event->trigger('cms.slugUrl', array('type' => 'contents', 'data' => $data['content']));
return $data['_this']->Facebook->like(
array(
'href' => Router::url(current($link['slugUrl']), true),
'layout' => 'button_count',
'title' => 'recommend'
)
);
}
}
/**
* Called after cms content is echo'ed
*/
public function onCmsAfterContentRender($event, $data) {
$config = $this->__getConfig();
if(isset($config['Cms.after']) && in_array('like', $config['Cms.after'])) {
$link = $data['_this']->Event->trigger('cms.slugUrl', array('type' => 'contents', 'data' => $data['content']));
return $data['_this']->Facebook->like(
array(
'href' => Router::url(current($link['slugUrl']), true),
'layout' => 'button_count',
'title' => 'recommend'
)
);
}
}
/**
* Called before blog post is echo'ed
*/
public function onBlogBeforeContentRender($event, $data) {
$config = $this->__getConfig();
if(isset($config['Blog.before']) && in_array('like', $config['Blog.before'])) {
$link = $data['_this']->Event->trigger('blog.slugUrl', array('type' => 'posts', 'data' => $data['post']));
return $data['_this']->Facebook->like(
array(
'href' => Router::url(current($link['slugUrl']), true),
'layout' => 'button_count',
'title' => 'recommend'
)
);
}
}
/**
* Called after blog post is echo'ed
*/
public function onBlogAfterContentRender($event, $data) {
$config = $this->__getConfig();
if(isset($config['Blog.after']) && in_array('like', $config['Blog.after'])) {
$link = $data['_this']->Event->trigger('blog.slugUrl', array('type' => 'posts', 'data' => $data['post']));
return $data['_this']->Facebook->like(
array(
'href' => Router::url(current($link['slugUrl']), true),
'layout' => 'button_count',
'title' => 'recommend'
)
);
}
}
/**
* called if a page is added and active, or activated.
*/
public function onCmsContentAdded($event, $data) {
$link = $data['event']->trigger(
'cms.slugUrl',
array(
'type' => 'contents',
'data' => $data
)
);
$link = Router::url(current($link['slugUrl']), true);
$config = $this->__getConfig();
$Facebook = new Facebook($config);
$Facebook->api(
'/'.$config['appId'].'/feed',
'POST',
array(
'body' => $link,
'description' => $event->Handler->params['data']['Content']['description'],
'message' => $event->Handler->params['data']['Content']['description']
)
);
exit;
}
public function onOauthProviders(){
return array(
'element' => 'login',
'config' => array(
'plugin' => 'facebook',
'login' => Configure::read('Facebook.login'),
'logout' => Configure::read('Facebook.logout')
)
);
}
public function onUserProfile($event){
return array(
'element' => 'profile'
);
}
}