module ApplicationHelper
  def second_button(star)
    if current_user.can_second?(star)
      link_to "Second", star_seconds_url(star), :class => "second",
        'data-remote' => true, 'data-replace-id' => "star_#{star.id}",
        'data-method' => 'post'
    end
  end

  FRIENDLY_TIME_FORMAT = '%b %d at %I:%M%p'
  def friendly_time(time)
    time.getlocal.strftime(FRIENDLY_TIME_FORMAT).
         gsub(/(\s|^)0/, '\\1').
         sub('AM', 'am').
         sub('PM', 'pm')
  end

  def photo(user)
    image_url =
      "http://graph.facebook.com/#{user.facebook_uid.to_i}/picture?type=square"
    link_to image_tag(image_url, :class => "user_photo", :alt => ""),
      user_path(user)
  end

  def background_photo(user)
    image_url =
      "http://graph.facebook.com/#{user.facebook_uid.to_i}/picture?type=large"
    div = content_tag(:div, "", :class => "user_photo", :style =>
      "background-image: url('#{image_url}');
       background-position: center; background-size: cover")
    link_to div, user_path(user)
  end

  def stylesheet(path)
    @stylesheets << path
  end
end

module ApplicationHelper
  def second_button(star)
    if current_user.can_second?(star)
      link_to "Second", star_seconds_url(star), :class => "second",
        'data-remote' => true, 'data-replace-id' => "star_#{star.id}",
        'data-method' => 'post'
    end
  end

  FRIENDLY_TIME_FORMAT = '%b %d at %I:%M%p'
  def friendly_time(time)
    time.getlocal.strftime(FRIENDLY_TIME_FORMAT).
         gsub(/(\s|^)0/, '\\1').
         sub('AM', 'am').
         sub('PM', 'pm')
  end

  def photo(user)
    image_url =
      "http://graph.facebook.com/#{user.facebook_uid.to_i}/picture?type=square"
    link_to image_tag(image_url, :class => "user_photo", :alt => ""),
      user_url(user)
  end

  def background_photo(user)
    image_url =
      "http://graph.facebook.com/#{user.facebook_uid.to_i}/picture?type=large"
    div = content_tag(:div, "", :class => "user_photo", :style =>
      "background-image: url('#{image_url}');
       background-position: center; background-size: cover")
    link_to div, user_path(user)
  end

  def stylesheet(path)
    @stylesheets << path
  end
end

Fix e-mail star recipient picture links.
Fix e-mail star recipient picture links.

Clicking on someone's picture in a star e-mail results in going to a URL
like http://users/2. Since relative links don't work in e-mails, use the
user_url helper instead of the user_path helper to generate this and
other photo links.
