/app/controllers/site_controller.rb
Ruby | 151 lines | 134 code | 3 blank | 14 comment | 7 complexity | 95929d180218c38db8c051ff5f072e89 MD5 | raw file
- class SiteController < ApplicationController
- before_filter :require_school_user, :only => [:school_listing]
- caches_action :index
- #after_filter TranslationFilter
- def index
- @page_title = "Learn Spanish Free Online | 123TeachMe"
- @page_heading = "Learn Spanish Free Online"
- @meta_description = 'Free Spanish lessons, verb conjugator, and other resources to learn Spanish online at no cost.'
- @meta_keywords = 'learn spanish, free lessons, free online lessons, verb conjugation, podcasts, translation, spanish'
- @wide_layout=true
- end
- # cache only first page, and only if there are few params
- #caches_action :search, :if => Proc.new { params.length < 3 && (params[:page].blank? || params[:page].to_i==1) }
- #caches_action :search <--- this fails, perhaps due to bug???
- #caches_action :search, :if => Proc.new { params.length < 4 } # caching is not working properly -- it ignores parameters in the query string
- def search
- @token = true if params[:token].present?
- # first convert old style parameters
- params[:city_id]=params[:relCityID] if !params[:relCityID].blank?
- # params[:country_id]=params[:relCountryID] if !params[:relCountryID].blank?
- # params[:country_id]=Country.find_by_enName(params[:country_name].humanize).try(:id) if params[:country_name].present?
- @wide_layout=true # removes the right nav from the layout
- @countries = Country.find_all_valid()
- @search_agent = SearchAgent.new
- # @page = params[:page].blank? ? 1 : params[:page].to_i
- # @schools, school_count, per_page = @search_agent.search_schools(params)
- @schools = @search_agent.search_schools(params,false).panna(params[:page])
- #@paginator = Paginator.new(self, school_count, per_page, @page)
- # @paginator = WillPaginate::Collection.new(@page, per_page, school_count)
- # set the title
- @page_title = "Learn Spanish at " + @search_agent.page_title
- @meta_description = 'Spanish Immersion Programs: ' + @search_agent.page_title
- @meta_keywords = @search_agent.page_title
- # travel blogs
- country_id = params[:relCountryID] if !params[:relCountryID].blank?
- if !params[:city_id].blank?
- @city_hash = City.lookup(params[:city_id])
- country_id = @city_hash['country_id']
- end
- if !country_id.blank? && country_id.to_i > 0
- @logs = TravelLog.find_by_country(country_id, :limit=>3, :order=>'rand()')
- @country_hash = Country.lookup(country_id)
- end
- if !params[:qstr].blank?
- qstr = params[:qstr]
- safe_qstr = qstr.gsub(/'/,"''").gsub(/;/,'').gsub(/from /,'invalid')
- end
- respond_with do |format|
- # format.json { render :json => {:success => true, :html => (render_to_string '/language_schools/list_schools')} }
- end
- end
- def school_search
- search_agent = SearchAgent.new
- @schools = search_agent.search_schools(params,false).panna(params[:page])
- render :index
- return
- end
- def site_map
- @page_title = '123TeachMe Site Map: Learn Spanish Online'
- @wide_layout = true
- end
- def adv_search
- @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.'
- @meta_keywords = 'advanced search, spanish language schools, immersion programs'
- @countries = Country.find_all_valid()
- end
- def about_us
- end
- def faq
- end
- def contact
- if request.post?
- if !verify_recaptcha
- render(:text => "Please check whether you have entered the captcha properly. Go back and try again.")
- return
- end
- # spam control: block if 'site' param does not equal 'checked' and 'href=' is in message
- site = params[:site] || ''
- block_message = false
- message = params[:message]
- if message
- block_message=true if !site.eql?('checked') && message.index('http:')
- block_message=true if message.index(/bcc:/i)
- block_message=true if message.index(/Content-Type:/i)
- else
- block_message = true
- end
- if block_message
- render(:text => 'Message could not be delivered. Please contact staff@123teachme.com')
- return
- end
- to_email = ConfigInfo['submit_comment_email']
- from_email = params[:email]
- subject = '123TeachMe.com: Contact Form'
- message =<<EOF
- The following message was sent from the website contact form on 123TeachMe.com
- email: #{params[:email]}
- --------------------------------------------------------------------------------
- #{params[:message]}
- EOF
- GenericMailer.generic_message(to_email, from_email, subject, message).deliver
- flash[:notice] = "Your message has been sent. Thank You."
- end
- end
- def whats_new
- render(:text => WhatsNew.last_entry.entry)
- return
- end
- def bookmark_js
- @bookmark_uri = params[:b_uri]
- @bookmark_title = params[:b_title]
- @abbreviated = true if params[:abbrev] && params[:abbrev].index('true')
- response.headers["Content-Type"]='application/x-javascript'
- js = render_to_string(:partial => '/site/bookmark_big')
- render(:text => html2javascript(js))
- return
- end
- def frames
- @main_src = params[:src]
- render(:layout => 'frames')
- end
- def school_listing
- @wide_layout = true
- @country = current_account.schools.first.country
- if current_account && current_account.has_subscriptions?
- redirect_to account_path
- end
- end
- def show_partial
- partial_name = params[:partial_name]
- render(:partial => partial_name)
- end
- end