-
Notifications
You must be signed in to change notification settings - Fork 1
/
facebook.blocks.inc
250 lines (237 loc) · 8.87 KB
/
facebook.blocks.inc
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
// $Id$
/**
* @file facebook.blocks.inc
* Block handling functions.
*/
/**
* Get the content for the Facebook Events block.
*
* @return
* The block content, or FALSE if an error occurred.
*/
function facebook_block_events_view() {
$stream = variable_get('facebook_block_events_stream', '');
// Fallback to Facebook Page setting.
if (empty($stream)) {
$stream = variable_get('facebook_page', '');
$stream = preg_replace('#^(http|https)://www.facebook.com/((pages/.+/)?([a-z0-9\.]+))$#', '$4', $stream);
}
if (empty($stream)) {
return FALSE;
}
$settings = array(
'stream' => $stream,
'limit' => variable_get('facebook_block_events_limit', 5),
'offset' => variable_get('facebook_block_events_offset', 0) * 60 * 60 * 1000,
);
drupal_add_js(array('facebookEventsBlock' => $settings), 'setting');
drupal_add_js(drupal_get_path('module', 'facebook') . '/js/facebook-events.js');
return array(
'subject' => t('Upcoming events'),
'content' => '<div id="facebook-events-placeholder"></div>',
);
}
/**
* Configure the Facebook Events block settings.
*
* @return
* The configuration form.
*/
function facebook_block_events_form() {
return array(
'facebook_block_events_stream' => array(
'#type' => 'textfield',
'#title' => t('Event stream'),
'#default_value' => variable_get('facebook_block_events_stream', ''),
'#description' => t('The id of a Facebook object that has an events feed. Leave blank to use the default Facebook page configured under <a href="@facebook-settings">Facebook Settings</a>.', array('@facebook-settings', url('admin/settings/facebook'))),
),
'facebook_block_events_limit' => array(
'#type' => 'textfield',
'#title' => t('Number of items'),
'#default_value' => variable_get('facebook_block_events_limit', 5),
'#required' => TRUE,
'#size' => 5,
),
'facebook_block_events_offset' => array(
'#type' => 'textfield',
'#title' => t('Timezone offset'),
'#default_value' => variable_get('facebook_block_events_offset', 0),
'#required' => TRUE,
'#size' => 5,
'#description' => t('The offset in hours from Pacific Standard Time.'),
),
);
}
/**
* Save the configuration settings for the Facebook Events block.
*
* @param $data The data submitted in the form.
*/
function facebook_block_events_form_submit($data) {
foreach ($data as $key => $value) {
variable_set($key, $value);
}
}
function facebook_block_like_view() {
$attributes = array();
$type = variable_get('facebook_block_like_type', 'button');
// Check whether to overrule the URL to like.
$use_facebook_page = variable_get('facebook_block_like_use_page', TRUE);
$facebook_page = variable_get('facebook_page', '');
if ($use_facebook_page && !empty($facebook_page)) {
$attributes['href'] = $facebook_page;
}
// Show faces
$attributes['show_faces'] = variable_get('facebook_block_like_show_faces', TRUE);
// Color scheme
$attributes['colorscheme'] = variable_get('facebook_block_like_colorscheme', '');
// Font
$attributes['font'] = variable_get('facebook_block_like_font', '');
// Width
$attributes['width'] = variable_get('facebook_block_like_width', '');
// Type specific settings
switch ($type) {
case 'button':
$tag = 'fb:like';
// Like button layout
$attributes['layout'] = variable_get('facebook_block_like_button_layout', 'standard');
// Label for Like button
$attributes['action'] = variable_get('facebook_block_like_button_verb', 'like');
// Show Share button
$attributes['share'] = variable_get('facebook_block_like_button_share', FALSE);
break;
case 'box':
$tag = 'fb:like-box';
// Show post stream from page
$attributes['stream'] = variable_get('facebook_block_like_box_stream', FALSE);
// Show header on box
$attributes['header'] = variable_get('facebook_block_like_box_header', FALSE);
// Box border color
$attributes['border_color'] = variable_get('facebook_block_like_box_color', '');
break;
}
// Return block content
return array(
'subject' => t('Like this website'),
'content' => theme('like_button', $type, $attributes),
);
}
/**
* Configuration options for the Facebook Like block.
*
* @return
* The form with the configuration options.
*/
function facebook_block_like_form() {
return array(
'facebook_block_like_type' => array(
'#type' => 'radios',
'#title' => t('Type'),
'#options' => array(
'button' => t('Like Button'),
'box' => t('Like Box'),
),
'#default_value' => variable_get('facebook_block_like_type', 'button'),
),
'facebook_block_like_use_page' => array(
'#type' => 'checkbox',
'#title' => t('Like the Facebook page connected to this site instead of the site URL'),
'#description' => t('The Facebook page can be configured under <a href="@facebook-settings">Facebook Settings</a>.', array('@facebook-settings', url('admin/settings/facebook'))),
'#default_value' => variable_get('facebook_block_like_use_page', TRUE),
),
'facebook_block_like_show_faces' => array(
'#type' => 'checkbox',
'#title' => t('Show the faces of the people that like this item.'),
'#default_value' => variable_get('facebook_block_like_show_faces', TRUE),
),
'facebook_block_like_colorscheme' => array(
'#type' => 'select',
'#title' => t('Color scheme'),
'#options' => array(
'light' => t('Light'),
'dark' => t('Dark'),
),
'#default_value' => variable_get('facebook_block_like_colorscheme', 'light'),
),
'facebook_block_like_font' => array(
'#type' => 'select',
'#title' => t('Font'),
'#options' => array(
'arial' => 'Arial',
'lucida grande' => 'Lucida Grande',
'segoe ui' => 'Segoe UI',
'tahoma' => 'Tahoma',
'trebuchet ms' => 'Trebuchet MS',
'verdana' => 'Verdana'
),
'#default_value' => variable_get('facebook_block_like_font', 'lucida grande'),
),
'facebook_block_like_width' => array(
'#type' => 'textfield',
'#title' => t('Width'),
'#default_value' => variable_get('facebook_block_like_width', ''),
),
'like_button' => array(
'#type' => 'fieldset',
'#title' => t('Like button specific settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'facebook_block_like_button_layout' => array(
'#type' => 'select',
'#title' => t('Layout'),
'#options' => array(
'standard' => t('Standard'),
'button_count' => t('Button count'),
'box_count' => t('Box count'),
),
'#default_value' => variable_get('facebook_block_like_button_layout', 'standard'),
),
'facebook_block_like_button_verb' => array(
'#type' => 'select',
'#title' => t('Action'),
'#options' => array(
'like' => t('Like'),
'recommend' => t('Recommend'),
),
'#default_value' => variable_get('facebook_block_like_button_verb', 'like'),
),
'facebook_block_like_button_share' => array(
'#type' => 'checkbox',
'#title' => t('Show an additional Share button.'),
'#default_value' => variable_get('facebook_block_like_button_share', TRUE),
),
),
'like_box' => array(
'#type' => 'fieldset',
'#title' => t('Like box specific settings'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
'facebook_block_like_box_stream' => array(
'#type' => 'checkbox',
'#title' => t('Show the feed from the linked page.'),
'#default_value' => variable_get('facebook_block_like_box_stream', FALSE),
),
'facebook_block_like_box_header' => array(
'#type' => 'checkbox',
'#title' => t('Show the box header.'),
'#default_value' => variable_get('facebook_block_like_box_header', FALSE),
),
'facebook_block_like_box_border_color' => array(
'#type' => 'textfield',
'#title' => t('Border color'),
'#default_value' => variable_get('facebook_block_like_box_border_color', ''),
),
),
);
}
/**
* Save the configuration settings for the Facebook Like block.
*
* @param $data The data submitted in the form.
*/
function facebook_block_like_form_submit($data) {
foreach ($data as $key => $value) {
variable_set($key, $value);
}
}