-
Notifications
You must be signed in to change notification settings - Fork 0
/
custom_fb_feed.module
103 lines (95 loc) · 3.06 KB
/
custom_fb_feed.module
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
<?php
/**
* Implements hook_menu().
*/
function custom_fb_feed_menu() {
$items = array();
$items['admin/config/services/custom_fb_feed'] = array(
'title' => 'Custom Facebook Feed',
'description' => 'Configuration for Custom Facebook Feed module',
'page callback' => 'drupal_get_form',
'page arguments' => array('_custom_fb_feed_settings'),
'access arguments' => array('access administration pages'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
function _custom_fb_feed_settings($form, &$form_state) {
$form['custom_fb_feed_page_name'] = array(
'#type' => 'textfield',
'#title' => t('Facebook Page Name'),
'#default_value' => variable_get('custom_fb_feed_page_name'),
'#required' => TRUE,
);
$form['custom_fb_feed_app_id'] = array(
'#type' => 'textfield',
'#title' => t('Facebook App ID'),
'#default_value' => variable_get('custom_fb_feed_app_id'),
'#required' => TRUE,
);
$form['custom_fb_feed_secret_key'] = array(
'#type' => 'textfield',
'#title' => t('Facebook Secret Key'),
'#default_value' => variable_get('custom_fb_feed_secret_key'),
'#required' => TRUE,
);
$form['custom_fb_feed_feeds_number'] = array(
'#type' => 'textfield',
'#title' => t('Number of Feeds'),
'#default_value' => variable_get('custom_fb_feed_feeds_number', 10),
'#size' => 2,
'#maxlength' => 2,
'#element_validate' => array('element_validate_integer_positive'),
);
return system_settings_form($form);
}
/**
* Implements hook_block_info().
*/
function custom_fb_feed_block_info() {
$blocks = array();
$blocks['fb_feed'] = array(
'info' => t('Facebook feed'),
);
return $blocks;
}
/**
* Implements hook_block_view().
*/
function custom_fb_feed_block_view($delta='') {
$block = array();
switch($delta) {
case 'fb_feed':
$block['subject'] = t('Facebook feed');
$block['content'] = _custom_fb_feed_block_view();
break;
}
return $block;
}
/**
* Implements hook_theme().
*/
function custom_fb_feed_theme($existing, $type, $theme, $path) {
return array(
'custom_fb_feed_facebook' => array(
'variables' => array('facebook' => NULL),
'template' => 'custom_fb_feed_facebook',
),
);
}
function _custom_fb_feed_block_view() {
$feed = array();
$page_name = variable_get('custom_fb_feed_page_name');
$app_id = variable_get('custom_fb_feed_app_id');
$secret = variable_get('custom_fb_feed_secret_key');
$limit = variable_get('custom_fb_feed_feeds_number', 10);
$url = "https://graph.facebook.com/" . $page_name . "/feed?limit=" . $limit . "&access_token=" . $app_id . "|" . $secret . "&posts&fields=id,picture,type,story,from,message,status_type,object_id,name,caption,description,link,created_time,comments.limit(1).summary(true),likes.limit(1).summary(true)";
$request = drupal_http_request($url);
if ($request->status_message == "OK") {
$json_response = drupal_json_decode($request->data);
foreach ($json_response['data'] as $value) {
$feed[] = $value;
}
}
return theme('custom_fb_feed_facebook', array('facebook' => $feed));
}