bug with publishing by pulblicator is removed
[appoyo2.git] / appoyo / app / controllers / iframe_controller.rb
blobf26e12814357d7fa2616c27870888a6abc129f75
1 class IframeController < ApplicationController
2   
3   def share_gallery
4     
5     come_from = request.env[:HTTP_REFERER]
6     Rails.logger.warn " > > > request.env['HTTP_ACCEPT'] : #{request.env['HTTP_ACCEPT']}"
7     
8     come_from = request.env['HTTP_REFERER']
9     Rails.logger.warn " > > > request.env['HTTP_REFERER'] : #{come_from}"
10     if come_from != nil || (request.env['HTTP_ACCEPT'].to_s.include? "application/msword")
11       redirect_to "#{Facebook_app}gallery?id=#{params['id']}"
12     else
13       if params[:locale] != nil
14         I18n.locale = params[:locale]
15       end
16       @gallery = Fbgallery.find(params['id']) 
17       @gallery_flash_params = @gallery.flash_params      
18       case I18n.locale
19         when "de"
20           @gallery_flash_params = @gallery_flash_params.gsub("info_en.xml","info_de.xml") 
21           @gallery_flash_params = @gallery_flash_params.gsub("lang=en","lang=de")
22         when "ru"
23           @gallery_flash_params = @gallery_flash_params.gsub("info_en.xml","info_ru.xml")
24           @gallery_flash_params = @gallery_flash_params.gsub("lang=en","lang=ru")
25        end
26       
27     end
28   end
29   
30   def show_gallery
31     if params[:locale] != nil
32         I18n.locale = params[:locale]
33     end
34     @gallery = Fbgallery.find(params['id'])
35     @gallery_flash_params = @gallery.flash_params      
36     case I18n.locale
37       when "de"
38         @gallery_flash_params = @gallery_flash_params.gsub("info_en.xml","info_de.xml") 
39         @gallery_flash_params = @gallery_flash_params.gsub("lang=en","lang=de")
40       when "ru"
41         @gallery_flash_params = @gallery_flash_params.gsub("info_en.xml","info_ru.xml")
42         @gallery_flash_params = @gallery_flash_params.gsub("lang=en","lang=ru")
43      end
44   end
46   def publisher
47    
48     case params[:fb_sig_locale]
49       when "de_DE"
50         I18n.locale = "de"     
51       when "ru_RU"
52         I18n.locale = "ru"
53       else
54         I18n.locale = "en"
55     end
56     debug_message "current  I18n.locale =#{I18n.locale}"
58     #generating json code
59     #if there is a second request
60     if  params['method'] != 'publisher_getInterface'
61       who = ""
62       if params['fb_sig_profile_user'] != nil 
63         action = "{*actor*} " + (I18n.t :likes_the_3d)
64       else
65         action =  I18n.t :i_like_the
66       end
67       gallery = Fbgallery.find(params[:app_params][:gallery_id])
68       @json_code = "{'content':{'attachment':{'name' : '#{gallery.name}','href' : '#{Facebook_app}gallery?id=#{gallery.id}','caption' : '#{action}', 'description' : '#{I18n.t :press_on_the_play_button}', 'media' : [{'type' : 'video', 'video_src' : '#{gallery.swf_link}?#{gallery.flash_params}', 'preview_img' : '#{gallery.preview_link}', 'video_link' : '#{Facebook_app}gallery?id=#{gallery.id}', 'video_title' : '#{gallery.name}'}] } }, 'method':'publisher_getFeedStory'}"
69       @json_code = ActiveSupport::JSON.decode(@json_code)
71     #if there is a first request
72     else
73       @json_code_a = Hash.new
74       debugger
75       the_user = Fbuser.find_by_facebook_id (params["fb_sig_user"])
76       #here might be an error
77       user_galleries = the_user.fbgalleries
78       
79       user_galleries_size = user_galleries.size 
80       #if there is not enough, 10 - number of galleries to show
81       if user_galleries.size < Galleries_for_publications
82         #find additionally 10 most viewed galleries
83         fbgalleries = Fbgallery.find(:all,:order => "was_viewed DESC",:limit=> (Galleries_for_publications - user_galleries.size))
84         user_galleries += fbgalleries
85       end
86       the_string ="<span style='font-size:13px;'>
87       <div style=' width: 98%;'>
88         <div style=' width: 98%; float: left; text-align:center;'>
89           <span style='font-size:17px;'> 
90             <b>#{I18n.t :select_gallery}</b>
91           </span>
92         </div>
93        #{ user_galleries_size > 0 ? "<div style=' width: 98%; float: left; text-align:center;margin: 10px 0 0 0;'><span style='font-size:20px;color:#2E9CCD;'>  #{I18n.t :user_galleries}</span></div>": ""}"
95       #if div is need to be finished
96       div_counter = 0 
97       finish_div_is_needed = false
98       #galleries publication
99       fbgalleries.each_with_index {|one,id|
100       
101         #special div to align other divs
102         if div_counter % 3 == 0
103           if true == finish_div_is_needed
104             the_string += "</div>"
105           end
106           the_string += "<div style='width:100%;float:left'>"
107           finish_div_is_needed = true
108           div_counter = 0
109         end
111         #if user's gallereis has finished
112         if  user_galleries_size == id 
113           #close extra div for alignment
114           the_string += "</div>"
115           the_string += "<div style=' width: 98%; float: left; text-align:center;'><span style='font-size:20px;color:#2E9CCD;margin: 10px 0 0 0;'> #{I18n.t :most_viewed}</span></div>"
116           the_string += "<div style='width:100%;float:left'>"
117           finish_div_is_needed = true
118           div_counter = 0
119         end 
121         the_string += "
122   <div style='width: 27%; float:left; vertical-align:middle;margin:5px;'>   <input id=gallery_id_#{one.id} name=gallery_id type=radio value=#{one.id} />#{id+1}: <img height='60px' src=#{one.preview_link}><br><div style='margin:0 0 0 0px;'>#{one.name}</div></div>"
123          div_counter += 1
124       }
125       if finish_div_is_needed
126          the_string += "</div>"
127       end 
128       the_string += "</div></span>"
129       
130       temp = Hash.new 
131       temp ["fbml"]= the_string
132       temp ["publishEnabled"] = "true"
133       @json_code_a["content"] = temp
134       @json_code_a["method"] = "publisher_getInterface"
135       #@json_code = "{'content':{'fbml':'Select gallery to publish: <br>#{the_string}', 'publishEnabled':true},'method':'publisher_getInterface'}"
136       @json_code = @json_code_a
137     #end of  if  params['method'] != 'publisher_getInterface'
138     end
139   #end of publisher 
140   end
141