Commit 714ead6ae18ef6b4d3dde474c54354ea008f0bbd
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
Merge branch 'AI3074-community_dashboard' into rails3_community_dashboard
Showing
9 changed files
with
232 additions
and
39 deletions
Show diff stats
plugins/community_hub/facebook_stream/codfish_facebook_api.rb
0 → 100644
... | ... | @@ -0,0 +1,86 @@ |
1 | +require 'rubygems' | |
2 | +require 'open-uri' | |
3 | +require 'json' | |
4 | + | |
5 | +token = 'CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH' | |
6 | +hashtag = "#nba" | |
7 | +pooling_time = 10 | |
8 | + | |
9 | + | |
10 | +#Aviso 12/04/2014 | |
11 | +#token que só deverá expirar em 59 dias | |
12 | +#@graph = Koala::Facebook::API.new('CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH') | |
13 | +# https://graph.facebook.com/v1.0/search?q=%23nba&type=post&access_token=CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH | |
14 | + | |
15 | +def not_blank(v) | |
16 | + if v == nil || v == "" | |
17 | + false | |
18 | + else | |
19 | + true | |
20 | + end | |
21 | +end | |
22 | + | |
23 | +if hashtag[0]='#' | |
24 | + hashtag = hashtag[1,hashtag.length-1] | |
25 | +end | |
26 | + | |
27 | +extractedComments = [] | |
28 | +initialComments = [] | |
29 | +firstTime = true | |
30 | +read = 1 | |
31 | + | |
32 | +while true | |
33 | + file = open("https://graph.facebook.com/v1.0/search?q=%23#{hashtag}&type=post&access_token=#{token}") | |
34 | + itens = JSON.parse(file.read)['data'] | |
35 | + mostRecent = "" | |
36 | + itens.each{|i| | |
37 | + from = "" | |
38 | + message = "" | |
39 | + if not_blank(i['from']['name']) | |
40 | + from = i['from']['name'] | |
41 | + if not_blank(i['message']) | |
42 | + message += i['message'] | |
43 | + end | |
44 | + if not_blank(message) | |
45 | + if mostRecent == "" or mostRecent < i["created_time"] | |
46 | + mostRecent = i["created_time"] | |
47 | + end | |
48 | + | |
49 | + extractedComments.push("#{from} said: #{message}") | |
50 | + # puts "#{from} said: #{message}" | |
51 | + end | |
52 | + end | |
53 | + } | |
54 | + | |
55 | + extractedComments = extractedComments.uniq | |
56 | + if firstTime | |
57 | + initialComments = extractedComments.clone | |
58 | + firstTime = false | |
59 | + end | |
60 | + | |
61 | +# extractedComments.each{|comment| | |
62 | +# puts comment | |
63 | +# } | |
64 | + | |
65 | +# extractedComments.each{|comment| | |
66 | +# puts comment | |
67 | +# } | |
68 | + | |
69 | + | |
70 | + newComments = extractedComments - initialComments | |
71 | + newComments = newComments.uniq | |
72 | + initialComments += newComments | |
73 | + initialComments = initialComments.uniq | |
74 | + newComments.each{|comment| | |
75 | + puts comment | |
76 | + } | |
77 | + puts "****************************************************************************************************************" | |
78 | + puts "most recent post at #{mostRecent}" | |
79 | + puts "Read: #{read} newComments: #{newComments.length} initialComments: #{initialComments.length} extractedComments: #{extractedComments.length} *******" | |
80 | + | |
81 | + read+=1 | |
82 | + sleep(pooling_time) | |
83 | +end | |
84 | + | |
85 | + | |
86 | + | ... | ... |
plugins/community_hub/facebook_stream/facebook_stream.rb
... | ... | @@ -5,6 +5,7 @@ require 'json' |
5 | 5 | #Aviso 12/04/2014 |
6 | 6 | #token que só deverá expirar em 59 dias |
7 | 7 | @graph = Koala::Facebook::API.new('CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH') |
8 | +# https://graph.facebook.com/v1.0/search?q=%23dilma&type=post&access_token=CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH | |
8 | 9 | |
9 | 10 | #feed = @graph.get_connections("participabr", "posts") |
10 | 11 | ... | ... |
plugins/community_hub/facebook_stream/lib_facebook_koala_stream.rb
0 → 100644
... | ... | @@ -0,0 +1,48 @@ |
1 | +require 'rubygems' | |
2 | +require 'koala' | |
3 | +require 'json' | |
4 | + | |
5 | +#Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! | |
6 | +#token will expire at 12/04/2014 (Brazilian date format) + 59 days | |
7 | +#'CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH' | |
8 | +# BACKUP TOKEN 'CAAEhsewl0ZAcBAHhipXszZCURSwWLmgvceDbs9mB5baJdLriFxYMEzywmF2fvZBuThuA2Mm7QF8wPd3E6R5pVqVEnC2VhcBb4VrfAnkZC73ZC5g1NRUnKZCB2e6CaRiUBDatR2nf505PeKp7Aj5XxvTdfSqdZCsXxQFYZApPNSUUgkUWm6HwL4rp21MRJXb612sZD' | |
9 | + | |
10 | +def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) | |
11 | + pooling_time ||= 5 | |
12 | + Koala.http_service.http_options = { :proxy => proxy_url } unless proxy_url.blank? | |
13 | + | |
14 | + @graph = Koala::Facebook::API.new(token) | |
15 | + initialComments = [] | |
16 | + firstTime = true | |
17 | + while true | |
18 | + feed = @graph.get_connections(page_id, "posts") | |
19 | + array = [] | |
20 | + extractedComments = [] | |
21 | + feed.each {|f| | |
22 | + if f['comments'] != nil && f['comments']['data'] != nil | |
23 | + array.push(f['comments']['data']) | |
24 | + end | |
25 | + } | |
26 | + extractedComments = array.flatten.uniq | |
27 | + if firstTime | |
28 | + initialComments = extractedComments.clone | |
29 | + firstTime = false | |
30 | + end | |
31 | + newComments = extractedComments - initialComments | |
32 | + newComments = newComments.uniq | |
33 | + initialComments += newComments | |
34 | + initialComments = initialComments.uniq | |
35 | + newComments.each{|comment| | |
36 | + puts "#{comment['from']['name']} " + _("said") + ": #{comment['message']}" | |
37 | + noosferoComment = Comment.new | |
38 | + noosferoComment.title = 'hub-message-facebook' | |
39 | + noosferoComment.source = hub | |
40 | + noosferoComment.body = comment['message'] | |
41 | + noosferoComment.author_id = author_id | |
42 | + noosferoComment.name = comment['from']['name'] | |
43 | + noosferoComment.email = 'admin@localhost.local' | |
44 | + noosferoComment.save! | |
45 | + } | |
46 | + sleep(pooling_time) | |
47 | + end | |
48 | +end | ... | ... |
plugins/community_hub/facebook_stream/lib_facebook_stream.rb
1 | 1 | require 'rubygems' |
2 | -require 'koala' | |
2 | +require 'open-uri' | |
3 | 3 | require 'json' |
4 | 4 | |
5 | -#Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! Warning!!! | |
6 | -#token will expire at 12/04/2014 (Brazilian date format) + 59 days | |
7 | -#'CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH' | |
8 | -# BACKUP TOKEN 'CAAEhsewl0ZAcBAHhipXszZCURSwWLmgvceDbs9mB5baJdLriFxYMEzywmF2fvZBuThuA2Mm7QF8wPd3E6R5pVqVEnC2VhcBb4VrfAnkZC73ZC5g1NRUnKZCB2e6CaRiUBDatR2nf505PeKp7Aj5XxvTdfSqdZCsXxQFYZApPNSUUgkUWm6HwL4rp21MRJXb612sZD' | |
9 | 5 | |
10 | -def facebook_comments(hub, author_id, page_id, pooling_time, token, proxy_url) | |
11 | - pooling_time ||= 5 | |
12 | - Koala.http_service.http_options = { :proxy => proxy_url } unless proxy_url.blank? | |
6 | + def not_blank(v) | |
7 | + if v == nil || v == "" | |
8 | + false | |
9 | + else | |
10 | + true | |
11 | + end | |
12 | + end | |
13 | + | |
14 | + | |
15 | +def facebook_comments(hub, author_id, hashtag, pooling_time, token, proxy_url) | |
16 | + | |
17 | + puts "entrou" | |
18 | + | |
19 | + pooling_time ||= 10 | |
20 | + token ||= 'CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH' | |
21 | + hashtag ||= "#nba" | |
22 | + | |
23 | + | |
24 | + #Aviso 12/04/2014 | |
25 | + #token que só deverá expirar em 59 dias | |
26 | + #@graph = Koala::Facebook::API.new('CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH') | |
27 | + # https://graph.facebook.com/v1.0/search?q=%23nba&type=post&access_token=CAAD8cd4tMVkBAO3sh2DrzwZCDfeQq9ZAvTz7Jz24ZC26KtMfBoljqaXhD2vBV1zpP0bjrpxXUBzJvKKcFzOm6rMG9Sok7iNVUaxt5iwr7dfMqCvHpMboKpqrqgeLrfCH5ITVTAdezA6ZBSr9iOJrqyCSOYfui0zTmbXJ3FqtshwNRrRy4NPH | |
13 | 28 | |
14 | - @graph = Koala::Facebook::API.new(token) | |
29 | + #removes extra # | |
30 | + if hashtag[0]='#' | |
31 | + hashtag = hashtag[1,hashtag.length-1] | |
32 | + end | |
33 | + | |
34 | + extractedComments = [] | |
15 | 35 | initialComments = [] |
16 | 36 | firstTime = true |
37 | + read = 1 | |
38 | + | |
17 | 39 | while true |
18 | - feed = @graph.get_connections(page_id, "posts") | |
19 | - array = [] | |
20 | - extractedComments = [] | |
21 | - feed.each {|f| | |
22 | - if f['comments'] != nil && f['comments']['data'] != nil | |
23 | - array.push(f['comments']['data']) | |
24 | - end | |
40 | + file = open("https://graph.facebook.com/v1.0/search?q=%23#{hashtag}&type=post&access_token=#{token}") | |
41 | + itens = JSON.parse(file.read)['data'] | |
42 | + mostRecent = "" | |
43 | + itens.each{|i| | |
44 | + from = "" | |
45 | + message = "" | |
46 | + if not_blank(i['from']['name']) | |
47 | + from = i['from']['name'] | |
48 | + if not_blank(i['message']) | |
49 | + message += i['message'] | |
50 | + end | |
51 | + if not_blank(message) | |
52 | + if mostRecent == "" or mostRecent < i["created_time"] | |
53 | + mostRecent = i["created_time"] | |
54 | + end | |
55 | + | |
56 | + extractedComments.push("#{from} said: #{message}") | |
57 | + # puts "#{from} said: #{message}" | |
58 | + end | |
59 | + end | |
25 | 60 | } |
26 | - extractedComments = array.flatten.uniq | |
61 | + | |
62 | + extractedComments = extractedComments.uniq | |
27 | 63 | if firstTime |
28 | 64 | initialComments = extractedComments.clone |
29 | 65 | firstTime = false |
30 | 66 | end |
67 | + | |
68 | + # extractedComments.each{|comment| | |
69 | + # puts comment | |
70 | + # } | |
71 | + | |
72 | + # extractedComments.each{|comment| | |
73 | + # puts comment | |
74 | + # } | |
75 | + | |
31 | 76 | newComments = extractedComments - initialComments |
32 | 77 | newComments = newComments.uniq |
33 | 78 | initialComments += newComments |
34 | 79 | initialComments = initialComments.uniq |
35 | 80 | newComments.each{|comment| |
81 | + puts comment | |
36 | 82 | puts "#{comment['from']['name']} " + _("said") + ": #{comment['message']}" |
37 | 83 | noosferoComment = Comment.new |
38 | 84 | noosferoComment.title = 'hub-message-facebook' |
39 | - noosferoComment.source = hub | |
85 | + noosferoComment.source = Article.last | |
86 | + #noosferoComment.source = hub | |
40 | 87 | noosferoComment.body = comment['message'] |
41 | 88 | noosferoComment.author_id = author_id |
42 | 89 | noosferoComment.name = comment['from']['name'] |
43 | 90 | noosferoComment.email = 'admin@localhost.local' |
44 | 91 | noosferoComment.save! |
45 | 92 | } |
93 | + puts "****************************************************************************************************************" | |
94 | + puts "Read: #{read} last post #{mostRecent} newComments: #{newComments.length} initialComments: #{initialComments.length} extractedComments: #{extractedComments.length}" | |
95 | + read+=1 | |
46 | 96 | sleep(pooling_time) |
47 | 97 | end |
48 | 98 | end |
99 | + | |
100 | + | |
101 | + | |
102 | +facebook_comments(nil, 54, "nba", 5, nil, nil) | |
103 | + | |
104 | + | |
105 | +puts "ola" | |
49 | 106 | \ No newline at end of file | ... | ... |
plugins/community_hub/lib/community_hub_plugin/hub.rb
... | ... | @@ -19,7 +19,7 @@ class CommunityHubPlugin::Hub < Folder |
19 | 19 | settings_items :twitter_access_token, :type => :string, :default => "" |
20 | 20 | settings_items :twitter_access_token_secret, :type => :string, :default => "" |
21 | 21 | settings_items :facebook_enabled, :type => :boolean, :default => false |
22 | - settings_items :facebook_page_id, :type => :string, :default => "" | |
22 | + settings_items :facebook_hashtag, :type => :string, :default => "" | |
23 | 23 | settings_items :facebook_pooling_time, :type => :integer, :default => 5 # Time in seconds |
24 | 24 | settings_items :facebook_access_token, :type => :string, :default => '' |
25 | 25 | settings_items :pinned_messages, :type => Array, :default => [] | ... | ... |
plugins/community_hub/lib/community_hub_plugin/listener.rb
... | ... | @@ -9,7 +9,7 @@ class CommunityHubPlugin::Listener |
9 | 9 | end |
10 | 10 | |
11 | 11 | def facebook_service(hub) |
12 | - facebook_comments(hub, nil, hub.facebook_page_id, hub.facebook_pooling_time, hub.facebook_access_token, hub.proxy_url) | |
12 | + facebook_comments(hub, nil, hub.facebook_hashtag, hub.facebook_pooling_time, hub.facebook_access_token, hub.proxy_url) | |
13 | 13 | end |
14 | 14 | |
15 | 15 | def run |
... | ... | @@ -39,6 +39,7 @@ class CommunityHubPlugin::Listener |
39 | 39 | end |
40 | 40 | |
41 | 41 | def log(message) |
42 | + #puts message | |
42 | 43 | initialize_logger unless @initiated |
43 | 44 | @initiated ||= true |
44 | 45 | @logger << "[#{Time.now.strftime('%F %T %z')}] #{message}\n" | ... | ... |
plugins/community_hub/public/style.css
... | ... | @@ -245,7 +245,7 @@ |
245 | 245 | border: 1px solid lightGray; |
246 | 246 | border-top: 1px solid #96110D; |
247 | 247 | border-bottom: 0px solid #FFFFFF; |
248 | - top: 1px; | |
248 | + top: 3px; | |
249 | 249 | float: left; |
250 | 250 | font-weight: normal; |
251 | 251 | margin-bottom: -1px; |
... | ... | @@ -259,14 +259,16 @@ z-index: 99; |
259 | 259 | float: left; |
260 | 260 | margin-right: 20px; |
261 | 261 | margin-left: 0px; |
262 | + text-align: center; | |
262 | 263 | } |
263 | 264 | |
264 | 265 | #content .main-block .hub .mediation h1.mediation{ |
265 | 266 | float: right; |
266 | 267 | margin-right: 0px; |
267 | 268 | margin-left: 20px; |
268 | - top: 2px; | |
269 | + top: 0px; | |
269 | 270 | left: 2px; |
271 | + text-align: center; | |
270 | 272 | } |
271 | 273 | |
272 | 274 | #content .main-block .hub .live h1.mediation, |
... | ... | @@ -378,7 +380,6 @@ z-index: 99; |
378 | 380 | |
379 | 381 | #content .hub .live.show .on-air, |
380 | 382 | #content .hub .live.show .off-air{ |
381 | -float: right; | |
382 | 383 | margin-right: 10px; |
383 | 384 | } |
384 | 385 | ... | ... |
plugins/community_hub/views/cms/community_hub_plugin/_hub.html.erb
... | ... | @@ -5,10 +5,10 @@ |
5 | 5 | <%= required labelled_form_field(_('Title'), text_field(:article, 'name', :size => '64', :maxlength => 150)) %> |
6 | 6 | </div> |
7 | 7 | <div> |
8 | - <%= render :file => 'shared/tiny_mce' %> | |
9 | - <%= required labelled_form_field(_('Description'), text_area(:article, 'body', :style => 'width: 100%;', :class => 'mceEditor')) %> | |
8 | + <%= required labelled_form_field(_('Description'), text_area(:article, 'body', :style => 'width: 99%;')) %> | |
10 | 9 | </div> |
11 | 10 | <br /> |
11 | + | |
12 | 12 | <div> |
13 | 13 | <%= _('General Streaming Settings:') %> |
14 | 14 | </div> |
... | ... | @@ -18,20 +18,19 @@ |
18 | 18 | </div> |
19 | 19 | <br /> |
20 | 20 | <%= check_box(:article, :twitter_enabled) %> <span><%= _("Turn on TWITTER") %></span> |
21 | - <br /> | |
22 | - <br /> | |
21 | + <br /><br /> | |
23 | 22 | <span><%= required labelled_form_field(_('Twitter\'s Hashtags, comma separated words<br>(example: participa.br,participabr,arenanetmundial,netmundial'), text_field(:article, :twitter_hashtags)) %></span> |
24 | 23 | <br /> |
24 | + <div> | |
25 | + <%= _('Facebook Settings:') %> | |
26 | + </div> | |
25 | 27 | <br /> |
26 | - <span><%= required labelled_form_field(_('Twitter\'s consumer key'), text_field(:article, :twitter_consumer_key)) %></span> | |
27 | - <br /> | |
28 | - <br /> | |
29 | - <span><%= required labelled_form_field(_('Twitter\'s consumer secret'), text_field(:article, :twitter_consumer_secret)) %></span> | |
30 | - <br /> | |
31 | - <br /> | |
32 | - <span><%= required labelled_form_field(_('Twitter\'s access token'), text_field(:article, :twitter_access_token)) %></span> | |
33 | - <br /> | |
28 | + <%= check_box(:article, :facebook_enabled) %> <span><%= _("Turn on FACEBOOK") %></span> | |
29 | + <br /><br /> | |
30 | + <span><%= required labelled_form_field(_('Facebook\'s hashtag (example: #participabr)'), text_field(:article, :facebook_hashtag)) %></span> | |
34 | 31 | <br /> |
35 | - <span><%= required labelled_form_field(_('Twitter\'s access token secret'), text_field(:article, :twitter_access_token_secret)) %></span> | |
32 | + <span><%= required labelled_form_field(_('Facebook\'s access token'), text_field(:article, :facebook_access_token)) %></span> | |
33 | + <br /> | |
34 | + <a href='https://smashballoon.com/custom-facebook-feed/access-token/' ><%= _('How to get a new access token?') %><a> | |
36 | 35 | <br /> |
37 | 36 | -</div> |
37 | +</div> | |
38 | 38 | \ No newline at end of file | ... | ... |
plugins/community_hub/views/content_viewer/hub.rhtml
... | ... | @@ -11,7 +11,7 @@ |
11 | 11 | <div id="left-tab" class="live content-tab show"> |
12 | 12 | |
13 | 13 | <h1 class="live"> |
14 | - <span class="title"><%= @page.title %></span><span class="on-air"><%= _("Live") %></span> | |
14 | + <span class="on-air"><%= _("Live") %></span> | |
15 | 15 | </h1> |
16 | 16 | |
17 | 17 | <h1 class="mediation"> |
... | ... | @@ -50,7 +50,7 @@ |
50 | 50 | <div id="right-tab" class="mediation content-tab hide"> |
51 | 51 | |
52 | 52 | <h1 class="live"> |
53 | - <span class="title"><%= @page.title %></span><span class="on-air"><%= _("Live") %></span> | |
53 | + <span class="on-air"><%= _("Live") %></span> | |
54 | 54 | </h1> |
55 | 55 | |
56 | 56 | <h1 class="mediation"> | ... | ... |