Commit 84c6d0035f3ade2e2965a04c76817d191a234360

Authored by Evandro Junior
2 parents d921f872 8cd3d94d

Merge branch 'AI3074-community_dashboard' of gitlab.com:participa/noosfero into …

…AI3074-community_dashboard

Conflicts:
	plugins/community_hub/lib/community_hub_plugin/hub.rb
plugins/community_hub/lib/community_hub_plugin/hub.rb
@@ -3,9 +3,6 @@ require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream' @@ -3,9 +3,6 @@ require File.dirname(__FILE__) + '/../../facebook_stream/lib_facebook_stream'
3 3
4 class CommunityHubPlugin::Hub < Folder 4 class CommunityHubPlugin::Hub < Folder
5 5
6 - @@twitter_thread_started = false #change to hash  
7 - @@facebook_thread_started = false #change to hash  
8 -  
9 settings_items :proxy_url, :type => :string, :default => 'http://161.148.1.167:3128' # Remember to use add the port, if needed! 6 settings_items :proxy_url, :type => :string, :default => 'http://161.148.1.167:3128' # Remember to use add the port, if needed!
10 settings_items :twitter_enabled, :type => :boolean, :default => false 7 settings_items :twitter_enabled, :type => :boolean, :default => false
11 settings_items :hashtags_twitter, :type => :string, :default => "participa.br,participabr,arenanetmundial,netmundial" 8 settings_items :hashtags_twitter, :type => :string, :default => "participa.br,participabr,arenanetmundial,netmundial"
@@ -20,7 +17,7 @@ class CommunityHubPlugin::Hub &lt; Folder @@ -20,7 +17,7 @@ class CommunityHubPlugin::Hub &lt; Folder
20 before_create do |hub| 17 before_create do |hub|
21 hub.mediators = [hub.author.id] 18 hub.mediators = [hub.author.id]
22 end 19 end
23 - 20 +
24 def self.icon_name(article = nil) 21 def self.icon_name(article = nil)
25 'community-hub' 22 'community-hub'
26 end 23 end
@@ -37,28 +34,34 @@ class CommunityHubPlugin::Hub &lt; Folder @@ -37,28 +34,34 @@ class CommunityHubPlugin::Hub &lt; Folder
37 true 34 true
38 end 35 end
39 36
40 - def self.twitter_service(hub, action)  
41 - author_id = 54  
42 - if action==:start  
43 - thread = Thread.new {  
44 - Twurl::Stream.run(hub, author_id, hub.setting[:hashtags_twitter], File.dirname(__FILE__) + '/../../tweeter_stream/config/twurlrc', hub.setting[:proxy_url])  
45 - } unless@@twitter_thread_started  
46 - @@twitter_thread_started = true  
47 - end 37 + def twitter_service
  38 + Twurl::Stream.run(self, nil, hashtags_twitter, File.dirname(__FILE__) + '/../../tweeter_stream/config/twurlrc', proxy_url)
48 end 39 end
49 -  
50 - #Faraday.new(:proxy => { :uri => 'http://proxy.example.com', :user => 'foo', :password => 'bar' })  
51 - def self.facebook_service(hub, action)  
52 - author_id = 54  
53 - if action==:start  
54 - thread = Thread.new {  
55 - facebook_comments(hub, author_id, hub.setting[:facebook_page_id], hub.setting[:facebook_pooling_time], hub.setting[:facebook_access_token], hub.setting[:proxy_url])  
56 - } unless@@facebook_thread_started  
57 - @@facebook_thread_started = true 40 +
  41 + def facebook_service
  42 + facebook_comments(self, nil, facebook_page_id, facebook_pooling_time, facebook_access_token, proxy_url)
  43 + end
  44 +
  45 + def self.start_listen
  46 + hubs = {}
  47 + loop do
  48 + puts "searching for hubs"
  49 + CommunityHubPlugin::Hub.all.each do |hub|
  50 + hub_conf = hubs[hub.id]
  51 + if hub_conf.nil? || hub_conf[:hub].updated_at < hub.updated_at
  52 + hub_conf[:threads].each {|t| t.terminate} if hub_conf
  53 + puts "hub #{hub.id} found!!!!!!"
  54 + threads = []
  55 + threads << Thread.new { hub.twitter_service } if hub.twitter_enabled
  56 + threads << Thread.new { hub.facebook_service } if hub.facebook_enabled
  57 + hubs[hub.id] = {:threads => threads, :hub => hub}
  58 + end
58 end 59 end
  60 + sleep(5)
  61 + end
59 end 62 end
60 - 63 +
61 def view_page 64 def view_page
62 "content_viewer/hub.rhtml" 65 "content_viewer/hub.rhtml"
63 end 66 end
64 -end 67 -end
  68 +end
65 \ No newline at end of file 69 \ No newline at end of file
plugins/community_hub/public/style.css
@@ -325,4 +325,14 @@ @@ -325,4 +325,14 @@
325 textarea#message_body { 325 textarea#message_body {
326 width: auto; 326 width: auto;
327 margin-left: 80px; 327 margin-left: 80px;
  328 +}
  329 +
  330 +.comment-count {
  331 + margin-left: 80px;
  332 + padding: 5px 10px;
  333 + background-color: white;
  334 + display: inline-block;
  335 + border-radius: 5px;
  336 + font-weight: bold;
  337 + margin-bottom: -5px;
328 } 338 }
329 \ No newline at end of file 339 \ No newline at end of file
plugins/community_hub/script/hub_updater 0 → 100755
@@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
  1 +#!/usr/bin/env ruby
  2 +
  3 +require 'daemons'
  4 +require 'optparse'
  5 +
  6 +NOOSFERO_ROOT = File.expand_path(File.dirname(__FILE__) + '/../../../')
  7 +
  8 +Daemons.run_proc('hub') do
  9 + require NOOSFERO_ROOT + '/config/environment'
  10 + CommunityHubPlugin::Hub.start_listen
  11 +end
plugins/community_hub/tweeter_stream/lib/twurl/request_controller.rb
@@ -15,8 +15,8 @@ module Twurl @@ -15,8 +15,8 @@ module Twurl
15 def perform_request 15 def perform_request
16 client.perform_request_from_options(options) { |response| 16 client.perform_request_from_options(options) { |response|
17 response.read_body { |chunk| 17 response.read_body { |chunk|
18 -# print "#{chunk}\n"  
19 - #unless chunk.to_i.length = 0 18 + #print "chunk: #{chunk}\n"
  19 + unless chunk.blank?
20 begin 20 begin
21 parsed = JSON.parse(chunk) 21 parsed = JSON.parse(chunk)
22 ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') 22 ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
@@ -24,17 +24,16 @@ module Twurl @@ -24,17 +24,16 @@ module Twurl
24 print "#{comment_text}\n" 24 print "#{comment_text}\n"
25 comment = Comment.new 25 comment = Comment.new
26 comment.title = 'hub-message-twitter' 26 comment.title = 'hub-message-twitter'
27 - comment.source_id = Stream.page.id 27 + comment.source_id = options.page.id
28 comment.body = comment_text 28 comment.body = comment_text
29 - comment.author_id = Stream.author_id  
30 - comment.save!  
31 - rescue  
32 - print "Erro gravando comentário twitter\n"  
33 - end  
34 - #raise comment.inspect  
35 -# rescue  
36 -# end  
37 - #end 29 + comment.author_id = options.author_id
  30 + comment.name = parsed["user"]["name"]
  31 + comment.email = 'admin@localhost.local'
  32 + comment.save!
  33 + rescue => e
  34 + print "Erro gravando comentário twitter #{e}\n"
  35 + end
  36 + end
38 } 37 }
39 } 38 }
40 rescue URI::InvalidURIError 39 rescue URI::InvalidURIError
plugins/community_hub/tweeter_stream/lib/twurl/stream.rb
@@ -14,8 +14,6 @@ module Twurl @@ -14,8 +14,6 @@ module Twurl
14 attr_accessor :output 14 attr_accessor :output
15 def run(page, author_id, tags, config_file_path, proxy=nil) 15 def run(page, author_id, tags, config_file_path, proxy=nil)
16 begin 16 begin
17 - @page = page # maybe should not be a class variable  
18 - @author_id = author_id  
19 @@file_path = config_file_path 17 @@file_path = config_file_path
20 Twurl.options = Options.new 18 Twurl.options = Options.new
21 Twurl.options.command = 'request' # Not necessary anymore 19 Twurl.options.command = 'request' # Not necessary anymore
@@ -30,6 +28,8 @@ module Twurl @@ -30,6 +28,8 @@ module Twurl
30 Twurl.options.path="/1.1/statuses/filter.json" 28 Twurl.options.path="/1.1/statuses/filter.json"
31 Twurl.options.host="stream.twitter.com" 29 Twurl.options.host="stream.twitter.com"
32 Twurl.options.read_timeout= 0 30 Twurl.options.read_timeout= 0
  31 + Twurl.options.page = page
  32 + Twurl.options.author_id = author_id
33 rescue NoPathFound => e 33 rescue NoPathFound => e
34 exit 34 exit
35 end 35 end
@@ -40,14 +40,6 @@ module Twurl @@ -40,14 +40,6 @@ module Twurl
40 @@file_path 40 @@file_path
41 end 41 end
42 42
43 - def author_id  
44 - @author_id  
45 - end  
46 -  
47 - def page  
48 - @page  
49 - end  
50 -  
51 def dispatch(options) 43 def dispatch(options)
52 client = OAuthClient.load_from_options(options) 44 client = OAuthClient.load_from_options(options)
53 controller = RequestController 45 controller = RequestController
plugins/community_hub/tweeter_stream/noosfero.rb
@@ -3,4 +3,4 @@ require &#39;rubygems&#39; # if you use RubyGems @@ -3,4 +3,4 @@ require &#39;rubygems&#39; # if you use RubyGems
3 3
4 require File.dirname(__FILE__) + '/lib/twurl' 4 require File.dirname(__FILE__) + '/lib/twurl'
5 5
6 -Twurl::Stream.run('popcorntime,time4popcorn', '/root/.twurlrc') 6 +Twurl::Stream.run(Article.last, 1, '#nba', '/home/00838716598/participa/noosfero/plugins/community_hub/tweeter_stream/config/twurlrc')
plugins/community_hub/views/community_hub_plugin_public/_post.rhtml
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 <% elsif post.title == 'hub-message-facebook' %> 9 <% elsif post.title == 'hub-message-facebook' %>
10 <%= image_tag('/designs/themes/default/images/logo-facebook-50x50.png', :alt => "Facebook") %> 10 <%= image_tag('/designs/themes/default/images/logo-facebook-50x50.png', :alt => "Facebook") %>
11 <% else %> 11 <% else %>
12 - <%= image_tag(profile_icon(post.author, :minor)) %> 12 + <%= image_tag(profile_icon(post.author, :minor)) if post.author %>
13 <% end %> 13 <% end %>
14 </li> 14 </li>
15 <li class="message"><span class="author"><%= post.author_name %>:</span> <%= post.body %></li> 15 <li class="message"><span class="author"><%= post.author_name %>:</span> <%= post.body %></li>
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 19
20 <ul> 20 <ul>
21 <li class="promote"> 21 <li class="promote">
22 - <img class="<%= !promoted?(hub, post.author.id) ? "promoted" : "not-promoted" %>" src="/designs/icons/default/outras/16x16/actions/spread.png" /> 22 + <img class="<%= !promoted?(hub, post.author.id) ? "promoted" : "not-promoted" if post.author %>" src="/designs/icons/default/outras/16x16/actions/spread.png" />
23 </li> 23 </li>
24 <li class="pin"> 24 <li class="pin">
25 <% if !pinned_message?(hub, post.id) %> 25 <% if !pinned_message?(hub, post.id) %>
@@ -36,4 +36,4 @@ @@ -36,4 +36,4 @@
36 <% end %> 36 <% end %>
37 37
38 </ul> 38 </ul>
39 -</li>  
40 \ No newline at end of file 39 \ No newline at end of file
  40 +</li>
plugins/community_hub/views/content_viewer/hub.rhtml
1 <% extend CommunityHubPlugin::HubHelper %> 1 <% extend CommunityHubPlugin::HubHelper %>
2 2
3 -<% CommunityHubPlugin::Hub.twitter_service(@page, :start) %>  
4 -<% CommunityHubPlugin::Hub.facebook_service(@page, :start) %>  
5 -  
6 <div id="<%=@page.id%>" class="hub"> 3 <div id="<%=@page.id%>" class="hub">
7 4
8 <div class="title"><%= @page.title %> HUB</div> 5 <div class="title"><%= @page.title %> HUB</div>