To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

root / app / helpers / attachments_helper.rb @ 1013:b98f60a6d231

History | View | Annotate | Download (2.09 KB)

1
# encoding: utf-8
2
#
3
# Redmine - project management software
4
# Copyright (C) 2006-2011  Jean-Philippe Lang
5
#
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
10
#
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
# GNU General Public License for more details.
15
#
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19

    
20
module AttachmentsHelper
21
  # Displays view/delete links to the attachments of the given object
22
  # Options:
23
  #   :author -- author names are not displayed if set to false
24
  def link_to_attachments(container, options = {})
25
    options.assert_valid_keys(:author)
26

    
27
    if container.attachments.any?
28
      options = {:deletable => container.attachments_deletable?, :author => true}.merge(options)
29
      render :partial => 'attachments/links', :locals => {:attachments => container.attachments, :options => options}
30
    end
31
  end
32

    
33
  def render_api_attachment(attachment, api)
34
    api.attachment do
35
      api.id attachment.id
36
      api.filename attachment.filename
37
      api.filesize attachment.filesize
38
      api.content_type attachment.content_type
39
      api.description attachment.description
40
      api.content_url url_for(:controller => 'attachments', :action => 'download', :id => attachment, :filename => attachment.filename, :only_path => false)
41
      api.author(:id => attachment.author.id, :name => attachment.author.name) if attachment.author
42
      api.created_on attachment.created_on
43
    end
44
  end
45

    
46
  # Returns true if user agent appears (approximately) to be a search
47
  # bot or crawler
48
  def user_is_search_bot?
49
    agent = request.env['HTTP_USER_AGENT']
50
    agent and agent =~ /(bot|slurp|crawler|spider)\b/i
51
  end
52
end