Terence kilima Club
jiunge
Fanpop
New Post
Explore Fanpop
if use_new_lookup_system == false sites = Array.new if controller.controller_name == "site" #sites = Site_slave.find_by_sql(["SELECT * FROM sites, (SELECT id FROM sites WHERE (category_id = ? AND ext_type IN (5,6,7) AND id <= ?) ORDER BY id DESC LIMIT #{mobile_page_size}) as x WHERE sites.id = x.id", @site.category_id, @site.id]) if @permalink_site.ext_type == 4 if false # this loads same type of content after the permalink sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type = 4 AND id <= ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC, id DESC", :limit=>numshowing, :offset=>array_start) if sites.length == 0 offset_count = Site_slave.count(:all, :conditions=>["category_id = ? AND ext_type = 4 AND id <= ?", @permalink_site.category_id, @permalink_site.id]) new_current_page = current_page - ((offset_count+numshowing-1) / numshowing) # page number starting from 0 is going to be the current page minus the number of pages it took to show from permalink to end array_start = numshowing * (new_current_page - 1) sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type = 4 AND id > ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC, id DESC", :limit=>numshowing, :offset=>array_start) end else sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) and id <= ?", @category.id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) if sites.length == 0 offset_count = Site_slave.count(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) AND id <= ?", @permalink_site.category_id, @permalink_site.id]) new_current_page = current_page - ((offset_count+numshowing-1) / numshowing) # page number starting from 0 is going to be the current page minus the number of pages it took to show from permalink to end array_start = numshowing * (new_current_page - 1) sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) AND id > ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) end end elsif @permalink_site.is_image? if false # this loads same type of content after the permalink sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (5,6,7) AND id <= ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC, id DESC", :limit=>numshowing, :offset=>array_start) if sites.length == 0 # wrap to newest if no results were found going back in time offset_count = Site_slave.count(:all, :conditions=>["category_id = ? AND ext_type IN (5,6,7) AND id <= ?", @permalink_site.category_id, @permalink_site.id]) new_current_page = current_page - ((offset_count+numshowing-1) / numshowing) # page number starting from 0 is going to be the current page minus the number of pages it took to show from permalink to end array_start = numshowing * (new_current_page - 1) sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (5,6,7) AND id > ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC, id DESC", :limit=>numshowing, :offset=>array_start) end else # this loads any type of content after the permalink sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) and id <= ?", @category.id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) if sites.length == 0 offset_count = Site_slave.count(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) AND id <= ?", @permalink_site.category_id, @permalink_site.id]) new_current_page = current_page - ((offset_count+numshowing-1) / numshowing) # page number starting from 0 is going to be the current page minus the number of pages it took to show from permalink to end array_start = numshowing * (new_current_page - 1) sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) AND id > ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) end end elsif @permalink_site.is_video? if false # this loads same type of content after the permalink sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (9,10) AND id <= ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) if sites.length == 0 offset_count = Site_slave.count(:all, :conditions=>["category_id = ? AND ext_type IN (9,10) AND id <= ?", @permalink_site.category_id, @permalink_site.id]) new_current_page = current_page - ((offset_count+numshowing-1) / numshowing) # page number starting from 0 is going to be the current page minus the number of pages it took to show from permalink to end array_start = numshowing * (new_current_page - 1) sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (9,10) AND id > ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) end else # this loads any type of content after the permalink sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) and id <= ?", @category.id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) if sites.length == 0 offset_count = Site_slave.count(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) AND id <= ?", @permalink_site.category_id, @permalink_site.id]) new_current_page = current_page - ((offset_count+numshowing-1) / numshowing) # page number starting from 0 is going to be the current page minus the number of pages it took to show from permalink to end array_start = numshowing * (new_current_page - 1) sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) AND id > ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) end end end elsif controller.controller_name == "search" sites = @site_results #@site_results is the array of site objects returned by sphinx elsif controller.controller_name == "collection" sites = @sites_collections2D##.collect {|site| site[0]} Special case below to bundle site and collection_site together for display later elsif controller.controller_name == "welcome" sites = Popculture_slave.find(:all, :order=>"publish_date desc", :limit=>numshowing, :offset=>array_start) elsif controller.controller_name == "soapbox" && controller.action_name == "show" if false # this loads same type of content after the permalink sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type = 1 AND id <= ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) if sites.length == 0 offset_count = Site_slave.count(:all, :conditions=>["category_id = ? AND ext_type = 1 AND id <= ?", @permalink_site.category_id, @permalink_site.id]) new_current_page = current_page - ((offset_count+numshowing-1) / numshowing) # page number starting from 0 is going to be the current page minus the number of pages it took to show from permalink to end array_start = numshowing * (new_current_page - 1) sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type = 1 AND id > ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) end else # this loads any type of content after the permalink sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) and id <= ?", @category.id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) if sites.length == 0 offset_count = Site_slave.count(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) AND id <= ?", @permalink_site.category_id, @permalink_site.id]) new_current_page = current_page - ((offset_count+numshowing-1) / numshowing) # page number starting from 0 is going to be the current page minus the number of pages it took to show from permalink to end array_start = numshowing * (new_current_page - 1) sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10) AND id > ?", @permalink_site.category_id, @permalink_site.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) end end elsif controller.controller_name == "soapbox" && controller.action_name == "list" sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type = 1", @category.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) elsif controller.controller_name == "category" && controller.action_name == "home" sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (1,5,6,7,9,10)", @category.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) if false && @luser && @luser.id < 10 if sites.length > 0 if current_page.to_i == 1 wall_entries = Wall_entry_slave.find(:all, :conditions=>["category_id = ? AND timestamp > ? AND deleted_by = 0", @category.id, sites[sites.length - 1].datecreated], :order=>"timestamp DESC") else wall_entries = Wall_entry_slave.find(:all, :conditions=>["category_id = ? AND timestamp < ? and timestamp > ? AND deleted_by = 0", @category.id, sites[0].datecreated, sites[sites.length - 1].datecreated], :order=>"timestamp DESC") end begin wall_entries.each do |wall_entry| wall_site_hash = {:card_type=>"chatter", :datecreated=>wall_entry.timestamp, :chatter_data=>wall_entry} site_counter = 0 sites.each do |site_object| if site_object.is_a? Site_slave if site_counter == 0 && wall_site_hash[:datecreated] > site_object.datecreated #wall post is newer than the newest site in the array sites.insert(0, wall_site_hash) break end if site_counter > 0 && site_object.datecreated < wall_site_hash[:datecreated] sites.insert(site_counter, wall_site_hash) break end end site_counter = site_counter + 1 end end rescue StandardError => kaboom Notifier::deliver_email_alert_request("Cliff Szu", "theclifbar@gmail.com", "Error: chatter card error", "#{kaboom.inspect}") puts "################################### _viewer_main_viewer_body_cardcontainer Error: #{__LINE__} #{kaboom.inspect} :::: #{session.inspect.to_s}, #{params.to_s}, #{request.env.to_s}" end end end site = sites[0] # commented following line out - there should not be a @permalink_site on club home; the first card should not be treated differently on club home # @permalink_site = sites[0] else #I also need to change pagination to pull from a different set... maybe we should just pass in a parameter or object like @site or site_id, and if that is not nil, then use similar queries to pull the subsequent pages for sites if params[:show_only].to_s != "" show_only = params[:show_only].to_s case show_only when "images" sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (5,6,7)", @category.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) when "videos" sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type IN (9,10)", @category.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) when "trivia" sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type = 3", @category.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) when "polls" sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type = 2", @category.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) when "links" sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type = 0", @category.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) when "articles" sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type = 1", @category.id], :order=>"datecreated DESC", :limit=>numshowing, :offset=>array_start) when "answers" answer_topics = Answer_topic_slave.find(:all, :conditions=>["category_id = ? AND enabled = 1", @category.id], :order=>"date_created DESC", :limit=>numshowing, :offset=>array_start) answer_topics.each do |answer_topic| sitetemp = Site.new sitetemp.id = answer_topic.id sitetemp.title = answer_topic.question sitetemp.description = answer_topic.description sitetemp.datecreated = answer_topic.date_created sitetemp.ext_type = -1 sitetemp.user_id = answer_topic.user_id sites << sitetemp end when "forums" forum_topics = Forum_topic_slave.find(:all, :conditions=>["category_id = ?", @category.id], :order=>"created_at DESC", :limit=>numshowing, :offset=>array_start) forum_topics.each do |forum_topic| forum_post = Forum_post_slave.find(:first, :conditions=>["id = ?", forum_topic.first_post_id]) sitetemp = Site.new sitetemp.id = forum_topic.id sitetemp.title = forum_topic.title sitetemp.description = forum_post.postbody if forum_post sitetemp.datecreated = forum_topic.created_at sitetemp.ext_type = -2 sitetemp.user_id = forum_topic.created_by sites << sitetemp end when "chatter" wall_entries = Wall_entry_slave.find(:all, :conditions=>["category_id = ?", @category.id], :order=>"timestamp DESC", :limit=>numshowing, :offset=>array_start) wall_entries.each do |wall_entry| sitetemp = Site.new sitetemp.id = wall_entry.id sitetemp.title = wall_entry.comment sitetemp.datecreated = wall_entry.timestamp sitetemp.ext_type = -3 sitetemp.user_id = wall_entry.user_id sites << sitetemp end when "posts" #articles, answers and forum posts sites = Site_slave.find(:all, :conditions=>["category_id = ? AND ext_type = 1", @category.id], :order=>"datecreated DESC", :limit=>numsho