Class: UtilityController

Inherits:
KitController show all
Defined in:
app/controllers/utility_controller.rb

Constant Summary collapse

BLOCK_SCORE_BAD_AUTH =
10

Constants inherited from KitController

KitController::Pagebase

Instance Attribute Summary

Attributes inherited from KitController

#is_image_request, #kit_request, #layout_being_used, #requested_url, #template_being_used

Instance Method Summary collapse

Methods inherited from KitController

#anti_spam_okay?, #app_name, #can_moderate, #can_use, #captcha_okay?, #check_and_record_goal, #check_user, #csv_headers, #dif, #edit_page_path, #feature?, #get_asset, #get_view_content, #host_name, #index_name, #info_page_path, #kit_layout_in_use, #kit_render, #kit_session, #kit_session_end, #link_to, #mailchimp_connect, #mobile_template, #no_read, #no_write, #not_found, #not_found_404, #offline, #page_path, #pref, #rails_app_name, #render, #render_error, #render_page, #render_page_by_url, #routing_error, #sanity_check_okay?, #session_id, #set_requested_url, #show_form, #stylesheets, #super_render, #user_sees_menu?

Instance Method Details

#add_commentObject



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'app/controllers/utility_controller.rb', line 102

def add_comment
  return :js=>"alert('Cannot submit a comment at this time');" unless anti_spam_okay?
  return :js=>"alert('Cannot submit a comment at this time');" unless sanity_check_okay?
  @comment = Comment.new(params[:comment])
  @comment.system_id = _sid
  @comment.user_id = current_user ? current_user.id : 0
  @comment.is_visible = 1
  if request.referer =~ /\/\/[^\/]+(\/.*)$/
    @comment.url = $1
  end
  @comment.save

  Activity.add(_sid, "Comment added to #{link_to @comment.url, @comment.url}", current_user ? current_user.id : 0, 'Comment')    

  if Preference.get_cached(_sid, 'moderate_comments')!='false'
    Notification.moderation_required("comment", "A comment has been added to #{Preference.get_cached(_sid, 'host')}#{@comment.url} which requires moderation. You can moderate comments here:  #{Preference.get_cached(_sid, 'host')}/admin/dashboard/user_comments", _sid).deliver
  end

  render :js=>"comment_added();"
end

#addressesObject



38
39
40
# File 'app/controllers/utility_controller.rb', line 38

def addresses
  @addresses = Postcode.addresses(params[:postcode])
end

#design_historyObject



33
34
35
36
# File 'app/controllers/utility_controller.rb', line 33

def design_history
  @dh = DesignHistory.sys(_sid).where(:id=>params[:id]).first
  render "design_history", :layout=>"cms"
end

#display_name_checkObject



61
62
63
64
65
66
67
# File 'app/controllers/utility_controller.rb', line 61

def display_name_check
  if User.sys(_sid).where(:display_name=>params[:name]).count > 0 
    render :js=>"display_name_check('Name in use');"
  else
    render :js=>"display_name_check('');"
  end
end

#down_for_maintenanceObject



25
26
27
# File 'app/controllers/utility_controller.rb', line 25

def down_for_maintenance
  render :text=>Preference.get_cached(_sid, "down_for_maintenance_message"), :layout=>false, :status=>503
end


42
43
44
# File 'app/controllers/utility_controller.rb', line 42

def external_link
  redirect_to "#{url}"
end

#fetch_rssObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/controllers/utility_controller.rb', line 69

def fetch_rss
  content = open(params[:rss].gsub('&', '&')).read
  html = params[:html]
  limit = (params[:limit] || "1000000").to_i
  truncate_body = (params[:truncate_body] || 100000).to_i

  rss = SimpleRss.parse content

  response = {}
  response[:title] = rss.channel.title
  response[:link] = rss.channel.link
  response[:items] = []
  c = 0
  rss.items.each do |rssitem|
    c += 1
    break if c > limit
    item = {}
    item[:title] = rssitem.title
    item[:link] = rssitem.link
    body = rssitem.description.gsub("&lt;","<").gsub("&gt;",">")
    body = strip_tags(body) if html=='strip'
    body = truncate(body, :length=>truncate_body, :ommission=>"...")
    item[:body] = body
    response[:items] << item
  end

  render :json=>response
end

#markdown_previewObject



29
30
31
# File 'app/controllers/utility_controller.rb', line 29

def markdown_preview
  render :text=>params[:body].sanitise.friendly_format({:smilies=>true}).html_safe
end

#mercury_htmlObject



98
99
100
# File 'app/controllers/utility_controller.rb', line 98

def mercury_html
  render :layout=>false
end

#postcodeObject



46
47
48
49
50
51
# File 'app/controllers/utility_controller.rb', line 46

def postcode
  location_mod = Postcode.clean(params[:postcode])
  @pc = Postcode.find_by_input_postcode(location_mod)
  
  # redner postcode.rjs which basically just calls whatever callback function was specified as parameter, indicating success or failure
end

#set_locationObject



53
54
55
56
57
58
59
# File 'app/controllers/utility_controller.rb', line 53

def set_location
  current_user.location = Location.find(params[:location_id])
  current_user.save

  @to_update = params[:to_update]
  @to_update ||= 'set_location'
end

#snippet_listObject



14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/utility_controller.rb', line 14

def snippet_list
  @snippets = Snippet
              .includes(:user)
              .order("created_at desc")
              .where(:show_editors=>1)
              
  @snippets = @snippets.where("description like '%#demo%'") unless current_user && current_user.editor?
  @snippets = @snippets.all
  render "admin/snippet/list.html.haml", :layout=>false
end

#user_email_to_idsObject



10
11
12
# File 'app/controllers/utility_controller.rb', line 10

def user_email_to_ids
  render :json => User.sys(_sid).order(:email).where("email like '%#{params[:term]}%'").collect { |u| {:label=>u.email, :value=>u.id} }
end