Merge branch 'fb_share' of github.com:Rulingcom/NCCU into fb_share
This commit is contained in:
		
						commit
						3fdff9357c
					
				|  | @ -0,0 +1,33 @@ | ||||||
|  | window.SocialShareButton = | ||||||
|  |   openUrl : (url) -> | ||||||
|  |     window.open(url) | ||||||
|  |     false | ||||||
|  | 
 | ||||||
|  |   share : (el) -> | ||||||
|  |     site = $(el).data('site') | ||||||
|  |     title = encodeURIComponent($(el).parent().data('title')) | ||||||
|  |     img = encodeURIComponent($(el).parent().data("img")) | ||||||
|  |     fb_url = encodeURIComponent($(el).parent().data("fb_url")) | ||||||
|  |     url = encodeURIComponent(location.href) | ||||||
|  |     switch site | ||||||
|  |       when "weibo" | ||||||
|  |         SocialShareButton.openUrl("http://v.t.sina.com.cn/share/share.php?url=#{url}&pic=#{img}&title=#{title}&content=utf-8") | ||||||
|  |       when "twitter" | ||||||
|  |         SocialShareButton.openUrl("https://twitter.com/home?status=#{title}: #{url}") | ||||||
|  |       when "douban" | ||||||
|  |         SocialShareButton.openUrl("http://www.douban.com/recommend/?url=#{url}&title=#{title}&image=#{img}") | ||||||
|  |       when "facebook" | ||||||
|  |         SocialShareButton.openUrl("http://www.facebook.com/sharer.php?t=#{title}&u=#{fb_url}") | ||||||
|  |       when "qq" | ||||||
|  |         SocialShareButton.openUrl("http://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=#{url}&title=#{title}&pics=#{img}") | ||||||
|  |       when "tqq" | ||||||
|  |         SocialShareButton.openUrl("http://share.v.t.qq.com/index.php?c=share&a=index&url=#{url}&title=#{title}&pic=#{img}") | ||||||
|  |       when "baidu" | ||||||
|  |         SocialShareButton.openUrl("http://apps.hi.baidu.com/share/?url=#{url}&title=#{title}&content=") | ||||||
|  |       when "kaixin001" | ||||||
|  |         SocialShareButton.openUrl("http://www.kaixin001.com/rest/records.php?url=#{url}&content=#{title}&style=11&pic=#{img}") | ||||||
|  |       when "renren" | ||||||
|  |         SocialShareButton.openUrl("http://widget.renren.com/dialog/share?resourceUrl=#{url}&title=#{title}&description=") | ||||||
|  |       when "google_plus" | ||||||
|  |         SocialShareButton.openUrl("https://plus.google.com/share?url=#{url}&t=#{title}") | ||||||
|  |     false | ||||||
|  | @ -106,6 +106,15 @@ class ApplicationController < ActionController::Base | ||||||
|       render :text => '404 Not Found' |       render :text => '404 Not Found' | ||||||
|     end |     end | ||||||
|   end |   end | ||||||
|  | 
 | ||||||
|  |   def render_share | ||||||
|  |     object_class = params[:model].classify.constantize | ||||||
|  |     @object = object_class.find(params[:id]) | ||||||
|  |     module_app = ModuleApp.first(:conditions => {:key => params[:key]}) | ||||||
|  |     @item = Item.where(module_app_id: module_app.id).all_of("tag" => {"$in" => [nil,'']},"category" => { "$in" => [nil,'']}).first | ||||||
|  |     @orig_url = "http://#{request.host_with_port}/#{@item.path}?id=#{@object.id}" | ||||||
|  |     render 'shared/render_share', :layout => false | ||||||
|  |   end | ||||||
|    |    | ||||||
|   protected |   protected | ||||||
|    |    | ||||||
|  |  | ||||||
|  | @ -140,7 +140,7 @@ module ApplicationHelper | ||||||
|       stylesheets << "<link href='/assets/bootstrap-orbit.css' rel='stylesheet' type='text/css' />\n" |       stylesheets << "<link href='/assets/bootstrap-orbit.css' rel='stylesheet' type='text/css' />\n" | ||||||
|       stylesheets << "<link href='/assets/style.css' rel='stylesheet' type='text/css' />\n" |       stylesheets << "<link href='/assets/style.css' rel='stylesheet' type='text/css' />\n" | ||||||
|     end |     end | ||||||
|     stylesheets << "<link href='/assets/social-share-button.scss' rel='stylesheet' type='text/css' />\n"  |     stylesheets << "<link href='/assets/social-share-button.css' rel='stylesheet' type='text/css' />\n"  | ||||||
|     stylesheets << "<link href='#{page.design.reset_css.file.url}' rel='stylesheet' type='text/css' />\n" if page.design.reset_css |     stylesheets << "<link href='#{page.design.reset_css.file.url}' rel='stylesheet' type='text/css' />\n" if page.design.reset_css | ||||||
|     stylesheets << "<link href='#{asset_path 'banner_nav.css'}' rel='stylesheet' type='text/css' />\n"  |     stylesheets << "<link href='#{asset_path 'banner_nav.css'}' rel='stylesheet' type='text/css' />\n"  | ||||||
|     stylesheets << "<link href='#{page.design.default_css.file.url}' rel='stylesheet' type='text/css' />\n" if page.design.default_css |     stylesheets << "<link href='#{page.design.default_css.file.url}' rel='stylesheet' type='text/css' />\n" if page.design.default_css | ||||||
|  | @ -162,7 +162,8 @@ module ApplicationHelper | ||||||
|     end |     end | ||||||
|     javascripts << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>\n" |     javascripts << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>\n" | ||||||
|     javascripts << "<script type='text/javascript' src='/static/kernel.js'></script>\n" |     javascripts << "<script type='text/javascript' src='/static/kernel.js'></script>\n" | ||||||
|     javascripts << "<script type='text/javascript' src='/assets/social-share-button.coffee'></script>\n" |     # javascripts << "<script type='text/javascript' src='/assets/social-share-button.js'></script>\n" | ||||||
|  |     javascripts << "<script type='text/javascript' src='/assets/lib/social-share-button.js'></script>\n" | ||||||
|     javascripts << "<script type='text/javascript' src='/assets/event.js'></script>\n" |     javascripts << "<script type='text/javascript' src='/assets/event.js'></script>\n" | ||||||
|     page.design.javascripts.each do |js| |     page.design.javascripts.each do |js| | ||||||
|       # javascripts << "<script type='text/javascript' src='#{js.file.url}'></script>" |       # javascripts << "<script type='text/javascript' src='#{js.file.url}'></script>" | ||||||
|  | @ -214,4 +215,15 @@ module ApplicationHelper | ||||||
|     object.strftime("%Y-%m-%d") |     object.strftime("%Y-%m-%d") | ||||||
|   end |   end | ||||||
| 
 | 
 | ||||||
|  |   def share_links(object, key) | ||||||
|  |     js = '' | ||||||
|  |     js << "<meta property='og:title' content='#{object.title}' />\n" rescue '' | ||||||
|  |     js << "<meta property='og:description' content='#{object.subtitle}' />\n" rescue '' | ||||||
|  |     js << "<meta property='og:image' content='#{object.image.url}' />\n" rescue '' | ||||||
|  |     content_tag :div, :class => 'fb' do | ||||||
|  |       concat social_share_button_tag(object.title, :fb_url => "http://#{request.env['HTTP_HOST']}/share/#{object.class.to_s.underscore}/#{object.id}?key=#{key}", :image => "http://#{request.env['HTTP_HOST']}#{object.image.url}") | ||||||
|  |       # concat javascript_tag "$('head').append('#{j js}');" | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | 
 | ||||||
| end | end | ||||||
|  |  | ||||||
|  | @ -0,0 +1,15 @@ | ||||||
|  | <!DOCTYPE HTML> | ||||||
|  | <html> | ||||||
|  | <head> | ||||||
|  | 	<meta property="og:title" content="<%= @object.title %>" />  | ||||||
|  | 	<meta property="og:description" content="<%= strip_tags @object.subtitle %>" />  | ||||||
|  | 	<meta property="og:image" content="<%= ('http://' + request.env['HTTP_HOST'] + @object.image.url) unless @object.image.blank? %>" /> | ||||||
|  | 	<script type="text/javascript"> | ||||||
|  | 		<!-- | ||||||
|  | 		window.location = "<%= @orig_url %>" | ||||||
|  | 		//--> | ||||||
|  | 	</script> | ||||||
|  | </head> | ||||||
|  | <body> | ||||||
|  | </body> | ||||||
|  | </html> | ||||||
|  | @ -3,3 +3,24 @@ Integer.class_eval do | ||||||
|     !self.zero? |     !self.zero? | ||||||
|   end |   end | ||||||
| end | end | ||||||
|  | 
 | ||||||
|  | module SocialShareButton | ||||||
|  |   module Helper | ||||||
|  |     def social_share_button_tag(title = "", opts = {}) | ||||||
|  |       rel = opts[:rel] | ||||||
|  |       html = [] | ||||||
|  |       html << "<div class='social-share-button' data-title='#{title}' data-img='#{opts[:image]}' data-fb_url='#{opts[:fb_url]}'>" | ||||||
|  |        | ||||||
|  |       SocialShareButton.config.allow_sites.each do |name| | ||||||
|  |         link_title = t "social_share_button.share_to", :name => t("social_share_button.#{name.downcase}") | ||||||
|  |         html << link_to("","#", :rel => "nofollow #{rel}",  | ||||||
|  |                         "data-site" => name,  | ||||||
|  |                         :class => "social-share-button-#{name}",  | ||||||
|  |                         :onclick => "return SocialShareButton.share(this);", | ||||||
|  |                         :title => h(link_title)) | ||||||
|  |       end | ||||||
|  |       html << "</div>" | ||||||
|  |       raw html.join("\n") | ||||||
|  |     end | ||||||
|  |   end | ||||||
|  | end | ||||||
|  | @ -140,6 +140,8 @@ Orbit::Application.routes.draw do | ||||||
|   match '/panel/:app_name/front_end/:app_action' => 'pages#index_from_link', :constraints => lambda { |request| |   match '/panel/:app_name/front_end/:app_action' => 'pages#index_from_link', :constraints => lambda { |request| | ||||||
|     !request.query_string.include?("inner=true") |     !request.query_string.include?("inner=true") | ||||||
|   } |   } | ||||||
|  | 
 | ||||||
|  |   match '/share/:model/:id' => 'application#render_share' | ||||||
|    |    | ||||||
|   # routes for gridfs files |   # routes for gridfs files | ||||||
|   match "/gridfs/*path" => "gridfs#serve"  |   match "/gridfs/*path" => "gridfs#serve"  | ||||||
|  |  | ||||||
|  | @ -36,6 +36,5 @@ | ||||||
| 		</div> | 		</div> | ||||||
| 	<% end %> | 	<% end %> | ||||||
| </div> | </div> | ||||||
| <div class="fb"> | 
 | ||||||
| 	<%= render  "shared/addthis_toolbox"%> | <%= share_links(@bulletin, 'announcement') %> | ||||||
| </div> |  | ||||||
|  |  | ||||||
|  | @ -39,7 +39,4 @@ | ||||||
| 	<% end %> | 	<% end %> | ||||||
| </div> | </div> | ||||||
| 
 | 
 | ||||||
| <div class="fb"> | <%= share_links(@news_bulletin, 'news') %> | ||||||
| 	<%= social_share_button_tag(@news_bulletin.title) %> |  | ||||||
| 	<%#= render  "shared/addthis_toolbox"%> |  | ||||||
| </div> |  | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue