source: trunk/action.php @ 1677

Last change on this file since 1677 was 1677, checked in by rub, 17 years ago

Feature Issue ID 0000601: Filter all public pages with only recent elements

It's a finalized version.
Obsolete code of draft are removed.

You can filter categories and images with recent date period on your screen selection.
In the future, filter could be easy done on other type data (plugin?)

You can flat categories and sub-categories with a recent date period of your choice.

Next, perhaps, a panel to choice recent date for the 2 features.

On draft, there have problem with MySql 5, be careful!

Css problem not resolved:

  • Menu "Categories" is bad centered
  • Icon on dark too on the top
  • Property svn:keywords set to Date Author Rev URL
File size: 5.4 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $URL: trunk/action.php $
9// | last update   : $Date: 2006-12-21 21:38:20 +0000 (Thu, 21 Dec 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Rev: 1677 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28define('PHPWG_ROOT_PATH','./');
29include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
30
31// Check Access and exit when user status is not ok
32check_status(ACCESS_GUEST);
33
34function guess_mime_type($ext)
35{
36  switch ( strtolower($ext) )
37  {
38    case "jpe": case "jpeg":
39    case "jpg": $ctype="image/jpeg"; break;
40    case "png": $ctype="image/png"; break;
41    case "gif": $ctype="image/gif"; break;
42    case "tiff":
43    case "tif": $ctype="image/tiff"; break;
44    case "txt": $ctype="text/plain"; break;
45    case "html":
46    case "htm": $ctype="text/html"; break;
47    case "xml": $ctype="text/xml"; break;
48    case "pdf": $ctype="application/pdf"; break;
49    case "zip": $ctype="application/zip"; break;
50    case "ogg": $ctype="application/ogg"; break;
51    default: $ctype="application/octet-stream";
52  }
53  return $ctype;
54}
55
56function do_error( $code, $str )
57{
58  set_status_header( $code );
59  echo $str ;
60  exit();
61}
62
63
64if ( !isset($_GET['id']) or !is_numeric($_GET['id'])
65    or !isset($_GET['part'])
66    or !in_array($_GET['part'], array('t','e','i','h') ) )
67{
68  do_error(400, 'Invalid request - id/part');
69}
70
71$id = $_GET['id'];
72$query = '
73SELECT * FROM '. IMAGES_TABLE.'
74  WHERE id='.$id.'
75;';
76
77$result = pwg_query($query);
78$element_info = mysql_fetch_assoc($result);
79if ( empty($element_info) )
80{
81  do_error(404, 'Requested id not found');
82}
83
84// $filter['visible_categories'] and $filter['visible_images']
85// are not used because it's not necessary (filter <> restriction)
86$query='
87SELECT id FROM '.CATEGORIES_TABLE.'
88  INNER JOIN '.IMAGE_CATEGORY_TABLE.'
89  ON category_id=id
90  WHERE image_id='.$id.'
91.'get_sql_condition_FandF(array('forbidden_categories' => 'category_id'), 'AND').'
92  LIMIT 1
93;';
94if ( mysql_num_rows(pwg_query($query))<1 )
95{
96  do_error(401, 'Access denied');
97}
98
99include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
100$file='';
101switch ($_GET['part'])
102{
103  case 't':
104    $file = get_thumbnail_path($element_info);
105    break;
106  case 'e':
107    $file = get_element_path($element_info);
108    break;
109  case 'i':
110    $file = get_image_path($element_info);
111    break;
112  case 'h':
113    if ( $user['enabled_high']!='true' )
114    {
115      do_error(401, 'Access denied h');
116    }
117    $file = get_high_path($element_info);
118    break;
119}
120
121if ( empty($file) )
122{
123  do_error(404, 'Requested file not found');
124}
125
126$http_headers = array();
127
128$ctype = null;
129if (!url_is_remote($file))
130{
131  if ( !@is_readable($file) )
132  {
133    do_error(404, "Requested file not found - $file");
134  }
135  $http_headers[] = 'Content-Length: '.@filesize($file);
136  if ( function_exists('mime_content_type') )
137  {
138    $ctype = mime_content_type($file);
139  }
140
141  $gmt_mtime = gmdate('D, d M Y H:i:s', filemtime($file)).' GMT';
142  $http_headers[] = 'Last-Modified: '.$gmt_mtime;
143
144  // following lines would indicate how the client should handle the cache
145  /* $max_age=300;
146  $http_headers[] = 'Expires: '.gmdate('D, d M Y H:i:s', time()+$max_age).' GMT';
147  // HTTP/1.1 only
148  $http_headers[] = 'Cache-Control: private, must-revalidate, max-age='.$max_age;*/
149
150  if ( isset( $_SERVER['HTTP_IF_MODIFIED_SINCE'] ) )
151  {
152    set_status_header(304);
153    foreach ($http_headers as $header)
154    {
155      header( $header );
156    }
157    exit();
158  }
159}
160
161if (!isset($ctype))
162{ // give it a guess
163  $ctype = guess_mime_type( get_extension($file) );
164}
165
166$http_headers[] = 'Content-Type: '.$ctype;
167
168if (!isset($_GET['view']))
169{
170  $http_headers[] = 'Content-Disposition: attachment; filename="'
171            .basename($file).'";';
172  $http_headers[] = 'Content-Transfer-Encoding: binary';
173}
174else
175{
176  $http_headers[] = 'Content-Disposition: inline; filename="'
177            .basename($file).'";';
178}
179
180foreach ($http_headers as $header)
181{
182  header( $header );
183}
184
185// Looking at the safe_mode configuration for execution time
186if (ini_get('safe_mode') == 0)
187{
188  @set_time_limit(0);
189}
190
191@readfile($file);
192
193?>
Note: See TracBrowser for help on using the repository browser.