# 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 def how_long_ago(obj) timeago(obj.created_at) end def timeago(time, options={}) options[:class] ||= "timeago" content_tag(:abbr, time.to_s, options.merge(:title => time.iso8601)) if time end def bookmarklet "javascript:(function(){f='#{AppConfig[:pod_url]}bookmarklet?url='+encodeURIComponent(window.location.href)+'&title='+encodeURIComponent(document.title)+'¬es='+encodeURIComponent(''+(window.getSelection?window.getSelection():document.getSelection?document.getSelection():document.selection.createRange().text))+'&v=1&';a=function(){if(!window.open(f+'noui=1&jump=doclose','diasporav1','location=yes,links=no,scrollbars=no,toolbar=no,width=620,height=250'))location.href=f+'jump=yes'};if(/Firefox/.test(navigator.userAgent)){setTimeout(a,0)}else{a()}})()" end def object_path(object, opts={}) return "" if object.nil? object = object.person if object.is_a? User eval("#{object.class.name.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 profile_photo(person) person_image_link(person, :size => :thumb_large, :to => :photos) end def owner_image_tag(size=nil) person_image_tag(current_user.person, size) end def owner_image_link person_image_link(current_user.person) end def person_image_tag(person, size=:thumb_small) "\"#{h(person.name)}\"".html_safe end def person_link(person, opts={}) " #{h(person.name)} ".html_safe end def hard_link(string, path) link_to string, path, :rel => 'external' end def person_image_link(person, opts={}) return "" if person.nil? || person.profile.nil? if opts[:to] == :photos link_to person_image_tag(person, opts[:size]), person_photos_path(person) else " #{person_image_tag(person)} ".html_safe end end def post_yield_tag(post) (':' + post.id.to_s).to_sym end def info_text(text) image_tag 'icons/monotone_question.png', :class => 'what_is_this', :title => text end def get_javascript_strings_for(language) defaults = I18n.t('javascripts', :locale => DEFAULT_LANGUAGE) if language != DEFAULT_LANGUAGE translations = I18n.t('javascripts', :locale => language) defaults.update(translations) end defaults end def direction_for(string) return '' unless string.respond_to?(:cleaned_is_rtl?) string.cleaned_is_rtl? ? 'rtl' : '' end def rtl? @rtl ||= RTL_LANGUAGES.include? I18n.locale end end