PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/app/controllers/site_controller.rb

https://bitbucket.org/kapilnakhwa/demo-teachme
Ruby | 151 lines | 134 code | 3 blank | 14 comment | 7 complexity | 95929d180218c38db8c051ff5f072e89 MD5 | raw file
  1. class SiteController < ApplicationController
  2. before_filter :require_school_user, :only => [:school_listing]
  3. caches_action :index
  4. #after_filter TranslationFilter
  5. def index
  6. @page_title = "Learn Spanish Free Online | 123TeachMe"
  7. @page_heading = "Learn Spanish Free Online"
  8. @meta_description = 'Free Spanish lessons, verb conjugator, and other resources to learn Spanish online at no cost.'
  9. @meta_keywords = 'learn spanish, free lessons, free online lessons, verb conjugation, podcasts, translation, spanish'
  10. @wide_layout=true
  11. end
  12. # cache only first page, and only if there are few params
  13. #caches_action :search, :if => Proc.new { params.length < 3 && (params[:page].blank? || params[:page].to_i==1) }
  14. #caches_action :search <--- this fails, perhaps due to bug???
  15. #caches_action :search, :if => Proc.new { params.length < 4 } # caching is not working properly -- it ignores parameters in the query string
  16. def search
  17. @token = true if params[:token].present?
  18. # first convert old style parameters
  19. params[:city_id]=params[:relCityID] if !params[:relCityID].blank?
  20. # params[:country_id]=params[:relCountryID] if !params[:relCountryID].blank?
  21. # params[:country_id]=Country.find_by_enName(params[:country_name].humanize).try(:id) if params[:country_name].present?
  22. @wide_layout=true # removes the right nav from the layout
  23. @countries = Country.find_all_valid()
  24. @search_agent = SearchAgent.new
  25. # @page = params[:page].blank? ? 1 : params[:page].to_i
  26. # @schools, school_count, per_page = @search_agent.search_schools(params)
  27. @schools = @search_agent.search_schools(params,false).panna(params[:page])
  28. #@paginator = Paginator.new(self, school_count, per_page, @page)
  29. # @paginator = WillPaginate::Collection.new(@page, per_page, school_count)
  30. # set the title
  31. @page_title = "Learn Spanish at " + @search_agent.page_title
  32. @meta_description = 'Spanish Immersion Programs: ' + @search_agent.page_title
  33. @meta_keywords = @search_agent.page_title
  34. # travel blogs
  35. country_id = params[:relCountryID] if !params[:relCountryID].blank?
  36. if !params[:city_id].blank?
  37. @city_hash = City.lookup(params[:city_id])
  38. country_id = @city_hash['country_id']
  39. end
  40. if !country_id.blank? && country_id.to_i > 0
  41. @logs = TravelLog.find_by_country(country_id, :limit=>3, :order=>'rand()')
  42. @country_hash = Country.lookup(country_id)
  43. end
  44. if !params[:qstr].blank?
  45. qstr = params[:qstr]
  46. safe_qstr = qstr.gsub(/'/,"''").gsub(/;/,'').gsub(/from /,'invalid')
  47. end
  48. respond_with do |format|
  49. # format.json { render :json => {:success => true, :html => (render_to_string '/language_schools/list_schools')} }
  50. end
  51. end
  52. def school_search
  53. search_agent = SearchAgent.new
  54. @schools = search_agent.search_schools(params,false).panna(params[:page])
  55. render :index
  56. return
  57. end
  58. def site_map
  59. @page_title = '123TeachMe Site Map: Learn Spanish Online'
  60. @wide_layout = true
  61. end
  62. def adv_search
  63. @meta_description = 'Search over 700 Spanish language schools throughout Spain and Latin America. Our advanced search allows filtering by cost, class size, location, activities, and over 7 other fields.'
  64. @meta_keywords = 'advanced search, spanish language schools, immersion programs'
  65. @countries = Country.find_all_valid()
  66. end
  67. def about_us
  68. end
  69. def faq
  70. end
  71. def contact
  72. if request.post?
  73. if !verify_recaptcha
  74. render(:text => "Please check whether you have entered the captcha properly. Go back and try again.")
  75. return
  76. end
  77. # spam control: block if 'site' param does not equal 'checked' and 'href=' is in message
  78. site = params[:site] || ''
  79. block_message = false
  80. message = params[:message]
  81. if message
  82. block_message=true if !site.eql?('checked') && message.index('http:')
  83. block_message=true if message.index(/bcc:/i)
  84. block_message=true if message.index(/Content-Type:/i)
  85. else
  86. block_message = true
  87. end
  88. if block_message
  89. render(:text => 'Message could not be delivered. Please contact staff@123teachme.com')
  90. return
  91. end
  92. to_email = ConfigInfo['submit_comment_email']
  93. from_email = params[:email]
  94. subject = '123TeachMe.com: Contact Form'
  95. message =<<EOF
  96. The following message was sent from the website contact form on 123TeachMe.com
  97. email: #{params[:email]}
  98. --------------------------------------------------------------------------------
  99. #{params[:message]}
  100. EOF
  101. GenericMailer.generic_message(to_email, from_email, subject, message).deliver
  102. flash[:notice] = "Your message has been sent. Thank You."
  103. end
  104. end
  105. def whats_new
  106. render(:text => WhatsNew.last_entry.entry)
  107. return
  108. end
  109. def bookmark_js
  110. @bookmark_uri = params[:b_uri]
  111. @bookmark_title = params[:b_title]
  112. @abbreviated = true if params[:abbrev] && params[:abbrev].index('true')
  113. response.headers["Content-Type"]='application/x-javascript'
  114. js = render_to_string(:partial => '/site/bookmark_big')
  115. render(:text => html2javascript(js))
  116. return
  117. end
  118. def frames
  119. @main_src = params[:src]
  120. render(:layout => 'frames')
  121. end
  122. def school_listing
  123. @wide_layout = true
  124. @country = current_account.schools.first.country
  125. if current_account && current_account.has_subscriptions?
  126. redirect_to account_path
  127. end
  128. end
  129. def show_partial
  130. partial_name = params[:partial_name]
  131. render(:partial => partial_name)
  132. end
  133. end