module PlataformaSocial
module Helpers
def plataforma_social_javascripts
plataforma_social_script_tag + plataforma_social_config_script + signed_request_javascript
end
def plataforma_social_script_tag
%Q{}.html_safe
end
def plataforma_social_config_script
%Q{}.html_safe
end
def signed_request_javascript
default_params = {
:signed_request => params[:signed_request] || nil,
:code => params[:code] || nil
}
%Q{
}.html_safe
end
def custom_redirect_to path, options = {}
options.each_pair do |key, value|
cookies[key] = value
end
render :text => %Q{
}
end
def from_facebook?
request && request.referer && request.referer.index('facebook.com')
end
def from_admin?
params.present? && params[:controller].present? && params[:controller].index(PlataformaSocial.admin_controller_name) == 0
end
def link_to *args, &block
args[2] ||= {}
if args[2][:normal] === true
super
else
unless block_given?
if from_facebook? && !from_admin?
server_domain = request.env['HTTP_HOST']
url = 'apps.facebook.com/' + PlataformaSocial.facebook_app_namespace
if args[1].include? server_domain
args[1].gsub! server_domain, url
else
args[1] = request.protocol + url + args[1]
end
args[2][:target] = '_top'
else
super
end
end
super
end
end
end
end
ActiveSupport.on_load(:action_view) do
include PlataformaSocial::Helpers
end
class ActionController::Base
include PlataformaSocial::Helpers
end