aboutsummaryrefslogtreecommitdiffstats
path: root/include/functions_picture.inc.php
blob: d11574b57b0897d19e8e3e73d6bdd345ba4ac144 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
<?php
// +-----------------------------------------------------------------------+
// | PhpWebGallery - a PHP based picture gallery                           |
// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
// +-----------------------------------------------------------------------+
// | file          : $Id$
// | last update   : $Date$
// | last modifier : $Author$
// | revision      : $Revision$
// +-----------------------------------------------------------------------+
// | This program is free software; you can redistribute it and/or modify  |
// | it under the terms of the GNU General Public License as published by  |
// | the Free Software Foundation                                          |
// |                                                                       |
// | This program is distributed in the hope that it will be useful, but   |
// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
// | General Public License for more details.                              |
// |                                                                       |
// | You should have received a copy of the GNU General Public License     |
// | along with this program; if not, write to the Free Software           |
// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
// | USA.                                                                  |
// +-----------------------------------------------------------------------+

/**
 * @param element_info array containing element information from db;
 * at least 'id', 'path' should be present
 */
function get_element_path($element_info)
{
  $path = get_element_location($element_info);
  if ( !url_is_remote($path) )
  {
    $path = PHPWG_ROOT_PATH.$path;
  }
  return $path;
}

/*
 * @param element_info array containing element information from db;
 * at least 'id', 'path' should be present
 */
function get_element_url($element_info)
{
  $url = get_element_location($element_info);
  if ( !url_is_remote($url) )
  {
    $url = embellish_url(get_root_url().$url);
  }
  // plugins want another url ?
  return trigger_event('get_element_url', $url, $element_info);
}

/**
 * Returns the relative path of the element with regards to to the root
 * of PWG (not the current page). This function is not intended to be
 * called directly from code.
 * @param element_info array containing element information from db;
 * at least 'id', 'path' should be present
 */
function get_element_location($element_info)
{
  // maybe a cached watermark ?
  return trigger_event('get_element_location',
    $element_info['path'], $element_info);
}


/**
 * Returns the PATH to the image to be displayed in the picture page. If the
 * element is not a picture, then the representative image or the default
 * mime image. The path can be used in the php script, but not sent to the
 * browser.
 * @param element_info array containing element information from db;
 * at least 'id', 'path', 'representative_ext' should be present
 */
function get_image_path($element_info)
{
  global $conf;
  $ext = get_extension($element_info['path']);
  if (in_array($ext, $conf['picture_ext']))
  {
    if (isset($element_info['element_path']) )
    {
      return $element_info['element_path'];
    }
    return get_element_path($element_info);
  }

  $path = get_image_location($element_info);
  if ( !url_is_remote($path) )
  {
    $path = PHPWG_ROOT_PATH.$path;
  }
  return $path;
}

/**
 * Returns the URL of the image to be displayed in the picture page. If the
 * element is not a picture, then the representative image or the default
 * mime image. The URL can't be used in the php script, but can be sent to the
 * browser.
 * @param element_info array containing element information from db;
 * at least 'id', 'path', 'representative_ext' should be present
 */
function get_image_url($element_info)
{
  global $conf;
  $ext = get_extension($element_info['path']);
  if (in_array($ext, $conf['picture_ext']))
  {
    if (isset($element_info['element_url']) )
    {
      return $element_info['element_url'];
    }
    return get_element_url($element_info);
  }

  $url = get_image_location($element_info);
  if ( !url_is_remote($url) )
  {
    $url = embellish_url(get_root_url().$url);
  }
  return $url;
}

/**
 * Returns the relative path of the image (element/representative/mimetype)
 * with regards to the root of PWG (not the current page). This function
 * is not intended to be called directly from code.
 * @param element_info array containing element information from db;
 * at least 'id', 'path', 'representative_ext' should be present
 */
function get_image_location($element_info)
{
    if (isset($element_info['representative_ext'])
          and $element_info['representative_ext'] != '')
    {
      $pi = pathinfo($element_info['path']);
      $file_wo_ext = get_filename_wo_extension($pi['basename']);
      $path =
        $pi['dirname'].'/pwg_representative/'
        .$file_wo_ext.'.'.$element_info['representative_ext'];
    }
    else
    {
      $ext = get_extension($element_info['path']);
      $path = get_themeconf('mime_icon_dir');
      $path.= strtolower($ext).'.png';
      if ( !file_exists(PHPWG_ROOT_PATH.$path)
          and !empty($element_info['tn_ext']) )
      {
        $path = get_thumbnail_location($element_info);
      }
    }

  // plugins want another location ?
  return trigger_event( 'get_image_location', $path, $element_info);
}


/*
 * @param element_info array containing element information from db;
 * at least 'id', 'path', 'has_high' should be present
 */
function get_high_path($element_info)
{
  $path = get_high_location($element_info);
  if (!empty($path) and !url_is_remote($path) )
  {
    $path = PHPWG_ROOT_PATH.$path;
  }
  return $path;
}

/**
 * @param element_info array containing element information from db;
 * at least 'id', 'path', 'has_high' should be present
 */
function get_high_url($element_info)
{
  $url = get_high_location($element_info);
  if (!empty($url) and !url_is_remote($url) )
  {
    $url = embellish_url(get_root_url().$url);
  }
  // plugins want another url ?
  return trigger_event('get_high_url', $url, $element_info);
}

/**
 * @param element_info array containing element information from db;
 * at least 'id', 'path', 'has_high' should be present
 */
function get_high_location($element_info)
{
  $location = '';
  if ($element_info['has_high'] == 'true')
  {
    $pi = pathinfo($element_info['path']);
    $location=$pi['dirname'].'/pwg_high/'.$pi['basename'];
  }
  return trigger_event( 'get_high_location', $location, $element_info);
}


/**
 * @param what_part string one of 't' (thumbnail), 'e' (element), 'i' (image),
 *   'h' (high resolution image)
 * @param element_info array containing element information from db;
 * at least 'id', 'path' should be present
 */
function get_download_url($what_part, $element_info)
{
  $url = get_root_url().'action.php';
  $url = add_url_params($url,
      array(
        'id' => $element_info['id'],
        'part' => $what_part,
      )
    );
  return trigger_event( 'get_download_url', $url, $element_info);
}

?>