-
Notifications
You must be signed in to change notification settings - Fork 0
/
tweetflow.module
121 lines (101 loc) · 2.67 KB
/
tweetflow.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
// $Id$
/**
* @file
* Display realtime twitter search.
*/
// TODO: Ability to add unlimited block of search result (profiles).
define(MODULE_PATH, drupal_get_path('module', 'tweetflow'));
/**
* Implementation of hook_menu().
*/
function tweetflow_menu() {
$items = array();
$items['admin/settings/tweetflow'] = array(
'title' => "TweetFlow",
'description' => "Display twitter search result in realtime.",
'page callback' => 'drupal_get_form',
'page arguments' => array('tweetflow_settings_form'),
'access arguments' => array('access content'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
/**
* Callback function: display settings.
*/
function tweetflow_settings_form() {
$form = array();
$form['tweetflow_keyword'] = array(
'#type' => 'textarea',
'#title' => t('Keyword'),
'#description' => t("Enter keyword to search from twitter, seperate by enter (newline)."),
'#default_value' => variable_get('tweetflow_keyword', ''),
);
$form['tweetflow_rpp'] = array(
'#type' => 'textfield',
'#title' => t('Result per page'),
'#default_value' => variable_get('tweetflow_rpp', 5),
);
return system_settings_form($form);
}
/**
* Implementation of hook_block().
*/
function tweetflow_block($op = 'list', $delta =0, $edit = array()) {
if ($op == 'list') {
$blocks[0] = array(
'info' => t("Tweetflow"),
);
return $blocks;
}
else if ($op == 'configure' && $delta == 0) {
}
else if ($op == 'view') {
$query = variable_get("tweetflow_keyword", "");
if (empty($query)) {
return;
}
else {
$query = explode("\n", $query);
foreach ($query as $k => &$val) {
$val = trim($val);
}
}
$rpp = variable_get('tweetflow_rpp', 5);
$block = array(
'subject' => t("TweetFlow"),
'content' => theme('tweetflow_realtime', $query, $rpp),
);
return $block;
}
}
/**
* Implementation of hook_themes().
*/
function tweetflow_theme($existing, $type, $theme, $path) {
return array(
'tweetflow_static' => array(
'argument' => array('query', 'rpp'),
),
'tweetflow_realtime' => array(
'argument' => array('query', 'rpp'),
),
);
}
/**
* Display realtime search.
*/
function theme_tweetflow_realtime($keyword, $rpp) {
$query = implode('+OR+', $keyword);
$settings = array(
'tweetflow_query' => $query,
'tweetflow_rpp' => $rpp,
'tweetflow_keyword' => $keyword,
);
drupal_add_css(MODULE_PATH .'/tweetflow.css');
drupal_add_js(MODULE_PATH .'/tweetflow.js');
drupal_add_js($settings, 'setting');
$content = '<div class="tweetflow-realtime">Your browser not support javascript.</div>';
return $content;
}