<commit_before>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

module ApplicationHelper
  @@youtube_title_cache = Hash.new("no-title")

  def modern_browser?
    false
  end

  def current_aspect?(aspect)
    !@aspect.is_a?(Symbol) && @aspect.id == aspect.id
  end

  def aspect_or_all_path aspect
    if @aspect.is_a? Aspect
      aspect_path @aspect
    else
      aspects_path
    end
  end
  
  def object_path(object, opts = {})
    object = object.person if object.is_a? User
    eval("#{object.class.to_s.underscore}_path(object, opts)")
  end

  def object_fields(object)
    object.attributes.keys
  end

  def mine?(post)
    current_user.owns? post
  end

  def type_partial(post)
    class_name = post.class.name.to_s.underscore
    "#{class_name.pluralize}/#{class_name}"
  end

  def how_long_ago(obj)
    "#{time_ago_in_words(obj.created_at)} #{t('ago')}"
  end

  def person_url(person)
    case person.class.to_s
    when "User"
      user_path(person)
    when "Person"
      person_path(person)
    else
      I18n.t('application.helper.unknown_person')
    end
  end

  def owner_image_tag
    person_image_tag(current_user.person)
  end

  def owner_image_link
    person_image_link(current_user.person)
  end

  def person_image_tag(person)
    image_tag image_or_default(person), :class => "avatar", :alt => person.real_name, :title => person.real_name, "data-person_id" => person.id
  end

  def image_or_default(person)
    image_location = person.profile.image_url
    image_location ||= "/images/user/default.png"
    image_location
  end
  
  def hard_link(string, path)
    link_to string, path, :rel => 'external' 
  end

  def person_image_link(person, opts = {})
    if opts[:to] == :photos
      link_to person_image_tag(person), person_photos_path(person)
    else
      link_to person_image_tag(person), object_path(person)
    end
  end

  def new_request(request_count)
    "new_requests" if request_count > 0 #Should not be Il8ned
  end

  def post_yield_tag(post)
    (':' + post.id.to_s).to_sym
  end

  def person_photos_path person
    person_id = person.id if person.respond_to?(:id)<commit_msg>check if profile exists before fetching profile photo<commit_after>#   Copyright (c) 2010, Diaspora Inc.  This file is
#   licensed under the Affero General Public License version 3 or later.  See
#   the COPYRIGHT file.

module ApplicationHelper
  @@youtube_title_cache = Hash.new("no-title")

  def modern_browser?
    false
  end

  def current_aspect?(aspect)
    !@aspect.is_a?(Symbol) && @aspect.id == aspect.id
  end

  def aspect_or_all_path aspect
    if @aspect.is_a? Aspect
      aspect_path @aspect
    else
      aspects_path
    end
  end
  
  def object_path(object, opts = {})
    object = object.person if object.is_a? User
    eval("#{object.class.to_s.underscore}_path(object, opts)")
  end

  def object_fields(object)
    object.attributes.keys
  end

  def mine?(post)
    current_user.owns? post
  end

  def type_partial(post)
    class_name = post.class.name.to_s.underscore
    "#{class_name.pluralize}/#{class_name}"
  end

  def how_long_ago(obj)
    "#{time_ago_in_words(obj.created_at)} #{t('ago')}"
  end

  def person_url(person)
    case person.class.to_s
    when "User"
      user_path(person)
    when "Person"
      person_path(person)
    else
      I18n.t('application.helper.unknown_person')
    end
  end

  def owner_image_tag
    person_image_tag(current_user.person)
  end

  def owner_image_link
    person_image_link(current_user.person)
  end

  def person_image_tag(person)
    image_tag image_or_default(person), :class => "avatar", :alt => person.real_name, :title => person.real_name, "data-person_id" => person.id
  end

  def image_or_default(person)
    image_location = person.profile.image_url if person.profile
    image_location ||= "/images/user/default.png"
    image_location
  end
  
  def hard_link(string, path)
    link_to string, path, :rel => 'external' 
  end

  def person_image_link(person, opts = {})
    if opts[:to] == :photos
      link_to person_image_tag(person), person_photos_path(person)
    else
      link_to person_image_tag(person), object_path(person)
    end
  end

  def new_request(request_count)
    "new_requests" if request_count > 0 #Should not be Il8ned
  end

  def post_yield_tag(post)
    (':' + post.id.to_s).to_sym
  end

  def person_photos_path person
    person_id = person.id if person.respond_to?(:id)
{'fraction_non_alphanumeric': 0.101363236587511, 'fraction_numerical': 0.00395778364116095, 'mean_word_length': 3.464180569185476, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1763981', 'n_tokens_mistral': 1631, 'n_tokens_neox': 1589, 'n_words': 348}