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 @ 1592:72d9219f2f19

History | View | Annotate | Download (2.24 KB)

1
# encoding: utf-8
2
#
3
# Redmine - project management software
4
# Copyright (C) 2006-2014  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
  #   :thumbails -- display thumbnails if enabled in settings
25
  def link_to_attachments(container, options = {})
26
    options.assert_valid_keys(:author, :thumbnails)
27

    
28
    if container.attachments.any?
29
      options = {:deletable => container.attachments_deletable?, :author => true}.merge(options)
30
      render :partial => 'attachments/links',
31
        :locals => {:attachments => container.attachments, :options => options, :thumbnails => (options[:thumbnails] && Setting.thumbnails_enabled?)}
32
    end
33
  end
34

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

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