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 3  
4 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 6 settings_items :proxy_url, :type => :string, :default => 'http://161.148.1.167:3128' # Remember to use add the port, if needed!
10 7 settings_items :twitter_enabled, :type => :boolean, :default => false
11 8 settings_items :hashtags_twitter, :type => :string, :default => "participa.br,participabr,arenanetmundial,netmundial"
... ... @@ -20,7 +17,7 @@ class CommunityHubPlugin::Hub &lt; Folder
20 17 before_create do |hub|
21 18 hub.mediators = [hub.author.id]
22 19 end
23   -
  20 +
24 21 def self.icon_name(article = nil)
25 22 'community-hub'
26 23 end
... ... @@ -37,28 +34,34 @@ class CommunityHubPlugin::Hub &lt; Folder
37 34 true
38 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 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 59 end
  60 + sleep(5)
  61 + end
59 62 end
60   -
  63 +
61 64 def view_page
62 65 "content_viewer/hub.rhtml"
63 66 end
64 67 -end
  68 +end
65 69 \ No newline at end of file
... ...
plugins/community_hub/public/style.css
... ... @@ -325,4 +325,14 @@
325 325 textarea#message_body {
326 326 width: auto;
327 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 339 \ No newline at end of file
... ...
plugins/community_hub/script/hub_updater 0 → 100755
... ... @@ -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 15 def perform_request
16 16 client.perform_request_from_options(options) { |response|
17 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 20 begin
21 21 parsed = JSON.parse(chunk)
22 22 ic = Iconv.new('UTF-8//IGNORE', 'UTF-8')
... ... @@ -24,17 +24,16 @@ module Twurl
24 24 print "#{comment_text}\n"
25 25 comment = Comment.new
26 26 comment.title = 'hub-message-twitter'
27   - comment.source_id = Stream.page.id
  27 + comment.source_id = options.page.id
28 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 39 rescue URI::InvalidURIError
... ...
plugins/community_hub/tweeter_stream/lib/twurl/stream.rb
... ... @@ -14,8 +14,6 @@ module Twurl
14 14 attr_accessor :output
15 15 def run(page, author_id, tags, config_file_path, proxy=nil)
16 16 begin
17   - @page = page # maybe should not be a class variable
18   - @author_id = author_id
19 17 @@file_path = config_file_path
20 18 Twurl.options = Options.new
21 19 Twurl.options.command = 'request' # Not necessary anymore
... ... @@ -30,6 +28,8 @@ module Twurl
30 28 Twurl.options.path="/1.1/statuses/filter.json"
31 29 Twurl.options.host="stream.twitter.com"
32 30 Twurl.options.read_timeout= 0
  31 + Twurl.options.page = page
  32 + Twurl.options.author_id = author_id
33 33 rescue NoPathFound => e
34 34 exit
35 35 end
... ... @@ -40,14 +40,6 @@ module Twurl
40 40 @@file_path
41 41 end
42 42  
43   - def author_id
44   - @author_id
45   - end
46   -
47   - def page
48   - @page
49   - end
50   -
51 43 def dispatch(options)
52 44 client = OAuthClient.load_from_options(options)
53 45 controller = RequestController
... ...
plugins/community_hub/tweeter_stream/noosfero.rb
... ... @@ -3,4 +3,4 @@ require &#39;rubygems&#39; # if you use RubyGems
3 3  
4 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 9 <% elsif post.title == 'hub-message-facebook' %>
10 10 <%= image_tag('/designs/themes/default/images/logo-facebook-50x50.png', :alt => "Facebook") %>
11 11 <% else %>
12   - <%= image_tag(profile_icon(post.author, :minor)) %>
  12 + <%= image_tag(profile_icon(post.author, :minor)) if post.author %>
13 13 <% end %>
14 14 </li>
15 15 <li class="message"><span class="author"><%= post.author_name %>:</span> <%= post.body %></li>
... ... @@ -19,7 +19,7 @@
19 19  
20 20 <ul>
21 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 23 </li>
24 24 <li class="pin">
25 25 <% if !pinned_message?(hub, post.id) %>
... ... @@ -36,4 +36,4 @@
36 36 <% end %>
37 37  
38 38 </ul>
39   -</li>
40 39 \ No newline at end of file
  40 +</li>
... ...
plugins/community_hub/views/content_viewer/hub.rhtml
1 1 <% extend CommunityHubPlugin::HubHelper %>
2 2  
3   -<% CommunityHubPlugin::Hub.twitter_service(@page, :start) %>
4   -<% CommunityHubPlugin::Hub.facebook_service(@page, :start) %>
5   -
6 3 <div id="<%=@page.id%>" class="hub">
7 4  
8 5 <div class="title"><%= @page.title %> HUB</div>
... ...