public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
mephisto / app / helpers / application_helper.rb
100644 73 lines (60 sloc) 2.545 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
require 'digest/md5'
module ApplicationHelper
 
  def author_link_for(comment)
    return h(comment.author) if comment.author_url.blank?
    link_to h(comment.author), "#{'http://' unless comment.author_url =~ /^https?:\/\//}#{comment.author_url}"
  end
 
  def avatar_for(user, options = {})
    image_tag gravatar_url_for(user), {:class => 'avatar'}.merge(options)
  end
 
  def asset_title_for(asset)
    asset.title.blank? ? asset.filename : asset.title
  end
 
  def asset_image_for(asset, thumbnail = :tiny, options = {})
    image_tag(*asset_image_args_for(asset, thumbnail, options))
  end
 
  def todays_short_date
    utc_to_local(Time.now.utc).to_ordinalized_s(:stub)
  end
 
  def yesterdays_short_date
    utc_to_local(Time.now.utc.yesterday).to_ordinalized_s(:stub)
  end
 
  # TODO: write a select helper in the filtered column plugin for this
  def filter_options
    (FilteredColumn.filters.keys).inject([]) { |arr, key| arr << [FilteredColumn.filters[key].filter_name, key.to_s] }.unshift(['Plain HTML', ''])
  end
  
  def who(name)
    return current_user.login == name ? "You" : name
  end
 
  def delete_link(file_type, resource, context)
    link_to_remote image_tag('/images/mephisto/icons/trash.gif', :class => 'iconb red'),
      {:url => url_for_theme(:controller => file_type.to_s, :action => 'remove', :filename => resource, :context => context), :confirm => 'Are you sure? This deletion will be permanent.'},
       :class => 'aicon', :title => 'Delete resource'
  end
 
  if RAILS_ENV == 'development'
    def gravatar_url_for(user, size = 80)
      'mephisto/avatar.gif'
    end
  else
    def gravatar_url_for(user, size = 80)
      return 'mephisto/avatar.gif' unless user && user.email
      "http://www.gravatar.com/avatar.php?size=#{size}&gravatar_id=#{Digest::MD5.hexdigest(user.email)}&default=http://#{request.host_with_port}#{ActionController::AbstractRequest.relative_url_root}/images/mephisto/avatar.gif"
    end
  end
 
  def comment_expiration_options
    [['Are not allowed', -1],
     ['Never expire', 0],
     ['Expire 24 hours after publishing', 1],
     ['Expire 1 week after publishing', 7],
     ['Expire 1 month after publishing', 30],
     ['Expire 3 months after publishing', 90]]
  end
 
  def sanitize_feed_content(html, sanitize_tables = false)
    options = sanitize_tables ? {} : {:tags => %w(table thead tfoot tbody td tr th)}
    returning h(white_list(html.strip, options)) do |html|
      html.gsub! /&amp;(#\d+);/ do |s|
        "&#{$1};"
      end
    end
  end
end