diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index e887549c2..47ac32530 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -13,4 +13,5 @@ class SessionsController < Devise::SessionsController } end end + end diff --git a/app/controllers/status_messages_controller.rb b/app/controllers/status_messages_controller.rb index aa5914952..8b0ad56c7 100644 --- a/app/controllers/status_messages_controller.rb +++ b/app/controllers/status_messages_controller.rb @@ -25,6 +25,12 @@ class StatusMessagesController < ApplicationController end end + def bookmarklet + @aspects = current_user.aspects + @aspect_ids = @aspects.map{|x| x.id} + render :layout => nil + end + def create params[:status_message][:aspect_ids] = params[:aspect_ids] diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index b788191f9..c1b018221 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -21,13 +21,13 @@ module ApplicationHelper def aspects_with_post aspects, post aspects.select do |aspect| - aspect.has_post?(post) + PostVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id) end end def aspects_without_post aspects, post aspects.reject do |aspect| - aspect.has_post?(post) + PostVisibility.exists?(:aspect_id => aspect.id, :post_id => post.id) end end @@ -39,6 +39,10 @@ module ApplicationHelper str.html_safe end + def bookmarklet + "javascript:(function(){f='#{AppConfig[:pod_url]}bookmarklet?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'¬es='+encodeURIComponent(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text))+'&v=1&';a=function(){if(!window.open(f+'noui=1&jump=doclose','diasporav1','location=yes,links=no,scrollbars=no,toolbar=no,width=620,height=250'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()" + end + def aspect_badge aspect, opts = {} str = "" link = opts.delete(:link) diff --git a/app/models/aspect.rb b/app/models/aspect.rb index 77a371f37..b6a99cef8 100644 --- a/app/models/aspect.rb +++ b/app/models/aspect.rb @@ -21,14 +21,6 @@ class Aspect < ActiveRecord::Base name.strip! end - def has_post? post - post_ids = post_visibilities.each { |pv| pv.post_id } - post_ids.each { |id| - return true if id == post.id - } - return false - end - def to_s name end diff --git a/app/models/profile.rb b/app/models/profile.rb index b0e7cefad..d45c29fbb 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -40,7 +40,9 @@ class Profile < ActiveRecord::Base :image_url_small, :birthday, :gender, :bio, :location, :searchable, :date, :tag_string belongs_to :person - + before_validation do + self.tag_string = self.tag_string.split[0..4].join(' ') + end before_save do self.build_tags end diff --git a/app/views/admins/user_search.html.haml b/app/views/admins/user_search.html.haml index 5ec26af37..4fb742507 100644 --- a/app/views/admins/user_search.html.haml +++ b/app/views/admins/user_search.html.haml @@ -50,3 +50,9 @@ %br #resp + +%br + post to Diaspora v1 + + + diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 3983696b2..5f4bc34c4 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -27,12 +27,14 @@ - if @request_count > 0 %h4 = new_request_link(@request_count) - + %h4 + != t('bookmarklet.explanation', :link => link_to(t('bookmarklet.explanation_link_text'), bookmarklet)) - if @invites > 0 .section.invite_friends %h4= t('shared.invitations.invite_your_friends') = render "shared/invitations", :invites => @invites + #aspect_listings.section = render 'aspects/aspect_listings', :aspects => @aspects diff --git a/app/views/aspects/show.html.haml b/app/views/aspects/show.html.haml index 81149f9bb..e103ea15c 100644 --- a/app/views/aspects/show.html.haml +++ b/app/views/aspects/show.html.haml @@ -20,7 +20,7 @@ .span-8.append-1 = render 'aspects/aspect_contacts', :contacts => @aspect_contacts, :aspect => @aspect = render 'aspects/edit_aspect_pane', :contacts => @all_contacts, :aspect => @aspect - + moms .span-15.last = render 'shared/publisher', :aspect => @aspect, :aspect_ids => @aspect_ids diff --git a/app/views/status_messages/bookmarklet.html.haml b/app/views/status_messages/bookmarklet.html.haml new file mode 100644 index 000000000..e25248aa4 --- /dev/null +++ b/app/views/status_messages/bookmarklet.html.haml @@ -0,0 +1,40 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + += include_javascripts :jquery += include_javascripts :main += include_stylesheets :default, :media => 'all' += stylesheet_link_tag "blueprint/screen", :media => 'screen' += javascript_include_tag "publisher.js" + +:javascript + Diaspora.widgets.i18n.loadLocale(#{get_javascript_strings_for(current_user.language).to_json}, "#{current_user.language}"); + $(document).ready(function() + { + Publisher.open(); + $("#publisher").bind('ajax:success', function(){ + $('h4').text("#{t('bookmarklet.post_success')}"); + Publisher.close(); + + window.setTimeout(window.close, 2000, true); + }); + + var contents = "#{params[:title]} - #{params[:url]}"; + if ("#{params[:notes]}".length > 0){ + contents = contents + " - #{params[:notes]}"; + } + + $("#publisher #status_message_fake_text").val(contents); + $("#publisher #status_message_text").val(contents); + $('input.button')[0].removeAttribute('disabled'); + }); + +#new_status_message_pane + .span-15.last + #facebox_header + %h4 + =t('bookmarklet.post_something') + + = render :partial => 'shared/publisher', :locals => { :aspect => :profile, :aspects_with_person => @aspects, :aspect_ids => @aspect_ids} + diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 265a5b225..cc37554de 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -144,6 +144,12 @@ en: failure: "Failed to remove person from aspect" no_membership: "Could not find the selected person in that aspect" + bookmarklet: + post_success: "Posted! Closing!" + post_something: "Post something to Diaspora" + explanation: "%{link} from anywhere by bookmarking this link." + explanation_link_text: "Post to Diaspora" + comments: zero: "no comments" one: "1 comment" diff --git a/config/routes.rb b/config/routes.rb index 684c4b056..f8d68a5e6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -64,6 +64,7 @@ Diaspora::Application.routes.draw do get 'admin_inviter' => :admin_inviter end + get 'bookmarklet' => 'status_messages#bookmarklet' resource :profile resources :requests, :only => [:destroy, :create] diff --git a/public/robots.txt b/public/robots.txt index 085187fa5..8e1d42063 100644 --- a/public/robots.txt +++ b/public/robots.txt @@ -1,5 +1,5 @@ # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file # # To ban all spiders from the entire site uncomment the next two lines: -# User-Agent: * -# Disallow: / +User-Agent: * +Disallow: / diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 706548001..cb088f9b9 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -855,6 +855,7 @@ label .options_and_submit :min-height 21px + :clear both :position relative :padding :top 6px diff --git a/spec/controllers/status_messages_controller_spec.rb b/spec/controllers/status_messages_controller_spec.rb index 128a7a7af..4ffc7e6a6 100644 --- a/spec/controllers/status_messages_controller_spec.rb +++ b/spec/controllers/status_messages_controller_spec.rb @@ -17,6 +17,13 @@ describe StatusMessagesController do alice.reload end + describe '#bookmarklet' do + it 'succeeds' do + get :bookmarklet + response.should be_success + end + end + describe '#new' do it 'succeeds' do get :new, diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index da464f770..aab27c789 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -188,9 +188,10 @@ describe Profile do @object.should be_valid end - it 'allows no more than 5 tags' do + it 'strips more than 5 tags' do @object.tag_string = '#one #two #three #four #five #six' - @object.should_not be_valid + @object.save + @object.tags.count.should == 5 end it_should_behave_like 'it is taggable' end