1 class UserController < ApplicationController
3 ensure_application_is_installed_by_facebook_user
4 before_filter :source_statistic
7 if (params[:f]) && (params[:f].to_i != 0)
8 add_stat(0, VISITED, params[:f] ? params[:f].to_i : 0)
13 @userF = session[:facebook_session].user
14 if @userF.has_permission?("publish_stream") && session[:facebook_session].user.has_permission?("email")
15 @fbuser = User.find(:first, :conditions => ["uid = ?", @userF.uid])
16 #if user does not exist yet in DB inserting in DB
21 if @userF.birthday != nil
22 birthday_mask = /(\w+)\ (\d+)\, (\d+)/
23 dateOfBirth = birthday_mask.match(@userF.birthday)
24 #if birthday ok for us
25 if (Months[$1] == nil)
28 birthday = Date.new(dateOfBirth[3].to_i,Months[dateOfBirth[1]],dateOfBirth[2].to_i)
32 #end if @userF.birthday != nil
34 #gathering affiliations
36 if @userF.affiliations
37 @userF.affiliations.each do |one_affiliation|
38 @affiliation += one_affiliation.name + " | "
42 #gathering other params
45 :birthday => birthday,
46 :relation => @userF.relationship_status,
47 :gender => @userF.sex,
48 :first_name => @userF.first_name,
49 :last_name => @userF.last_name,
50 :status => "WAS NOT SET YET" ,
51 :hometown_location => (@userF.hometown_location != nil) ? @userF.hometown_location.country.to_s + "/"+ @userF.hometown_location.state.to_s + "/" + @userF.hometown_location.city.to_s : "",
52 :affiliations => @affiliation
55 debug_message("Cannot get information about #{session[:facebook_session].user.uid}",false)
56 render :facebook_error
59 @fbuser = User.new(myParams)
60 debug_message("User #{session[:facebook_session].user.uid} was added to DB")
62 add_stat(@userF.uid, PERMISSION)
64 #end of getting user info
66 #end if @fbuser == nil
68 render :action => "question1"
73 user_has_published_once = false
74 user_has_published_once = question_processor
75 if user_has_published_once
76 render :action => "question2"
83 user_has_published_once = false
84 user_has_published_once = question_processor
85 if user_has_published_once
86 render :action => "question3"
92 user_has_published_once = false
93 user_has_published_once = question_processor
94 if user_has_published_once
95 render :action => "greetings"
100 def question_processor
101 user_has_published_once = false
103 if params["friend_sel0#{i}"] != nil && params["friend_sel0#{i}"] != ""
105 #preparing for public first feed
106 session_new = Facebooker::Session.create
107 if !user_has_published_once
108 @userFB = Facebooker::User.new(session[:facebook_session].user.uid, session_new)
111 @userFB2 =Facebooker::User.new(params["friend_sel0#{i}"], session_new)
112 #publishing first message
113 #p @today_quiz.feedpic.url(:normal)
115 publishing (@userFB,@userFB,"selected his top 5 friends: #{@userFB2.first_name}, X, Y, Z, W to win Nokia E72. How well do you know your friends? Answer and win now!","Take the Nokia E72 challenge","http://foo.com","2Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices","http://foo2.com","3Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices",'image',"http://www.finalsense.com/news/image/mobile/nokia-6124classic.jpg","http://foo3.com")
117 #publishing (@userFB,@userFB2,"#{@userFB2.first_name}, you are one of my best friend here. I also picked X, Y, Z, W. Let's stay in youch","Take the Nokia E72 challenge","http://foo.com","2Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices","http://foo2.com","3Take the Nokia E72 friendship challenge now to win up to 6 Nokia E72 devices",'image',"http://www.finalsense.com/news/image/mobile/nokia-6124classic.jpg","http://foo3.com")
119 debug_message("Message was published into stream")
120 user_has_published_once = true
123 #debug_message("Cannot publish or some problems with getting info from FB",false)
128 return user_has_published_once
140 def publishing (user_from,user_to,main_message,action_link_text,action_link_href,attachment_name,attachment_href,attachment_caption,media_type,media_src,media_href)
141 user_from.publish_to(user_to,
142 :message => main_message,
145 :text => action_link_text,
146 :href => action_link_href}
149 :name => attachment_name,
150 :href => attachment_href,
151 :caption => attachment_caption,