images.php 4.24 KB
Newer Older
Ayolo's avatar
Ayolo committed
1
<?php
2
/*
Feu's avatar
fix  
Feu committed
3
 * AECMS : CMS pour les clubs et activités de l'AE UTBM
4
 *
Ayolo's avatar
Ayolo committed
5 6 7
 * Copyright 2004-2007
 * - Julien Etelain < julien dot etelain at gmail dot com >
 *
Feu's avatar
fix  
Feu committed
8
 * Ce fichier fait partie du site de l'Association des Étudiants de
Ayolo's avatar
Ayolo committed
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 * l'UTBM, http://ae.utbm.fr/
 *
 * 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; either version 2 of the
 * License, or (at your option) any later version.
 *
 * 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.
 */
26

Ayolo's avatar
Ayolo committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
require_once("include/site.inc.php");
require_once($topdir."sas2/include/cat.inc.php");
require_once($topdir."sas2/include/photo.inc.php");

session_write_close(); // on n'a plus besoin de la session, liberons le semaphore...

if ( ereg("^(.*)/([0-9]*).jpg$",$_SERVER["argv"][0],$regs) )
{
  $id_photo = intval($regs[2]);
  $mode = "";
}
else if ( ereg("^(.*)/([0-9]*).vignette.jpg$",$_SERVER["argv"][0],$regs) )
{
  $id_photo = intval($regs[2]);
  $mode = "vignette";
}
else if ( ereg("^(.*)/([0-9]*).diapo.jpg$",$_SERVER["argv"][0],$regs) )
{
  $id_photo = intval($regs[2]);
  $mode = "diapo";
}
Feu's avatar
fix  
Feu committed
48 49 50 51 52
else if ( ereg("^(.*)/([0-9]*).flv$",$_SERVER["argv"][0],$regs) )
{
  $id_photo = intval($regs[2]);
  $mode = "flv";
}
Ayolo's avatar
bleh  
Ayolo committed
53 54 55 56 57
else if ( ereg("^(.*)/([0-9]*)$",$_SERVER["argv"][0],$regs) )
{
  $id_photo = intval($regs[2]);
  $mode = "diapo";
}
Ayolo's avatar
Ayolo committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71
else if ( ereg("^/(.*)$",$_SERVER["argv"][0]) )
{
  $path = $_SERVER["argv"][0];
}
else
{
  header("Location: index.php?name=404");
  exit();
}

if ( $id_photo > 0 )
{
  function renvoyer_image ( $file )
  {
72 73

    $lastModified = gmdate('D, d M Y H:i:s', filemtime($file) ) . ' GMT';
Ayolo's avatar
Ayolo committed
74
    $etag=md5($file.'#'.$lastModified);
75

Ayolo's avatar
Ayolo committed
76 77 78 79 80 81 82 83 84 85
    if ( isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) )
    {
      $ifModifiedSince = preg_replace('/;.*$/', '', $_SERVER['HTTP_IF_MODIFIED_SINCE']);
      if ($lastModified == $ifModifiedSince)
      {
        header("HTTP/1.0 304 Not Modified");
        header('ETag: "'.$etag.'"');
        exit();
      }
    }
86

Ayolo's avatar
bleh  
Ayolo committed
87
    if ( isset($_SERVER['HTTP_IF_NONE_MATCH']) )    {      if ( $etag == str_replace('"', '',stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) )
Ayolo's avatar
Ayolo committed
88 89 90 91 92 93
      {
        header("HTTP/1.0 304 Not Modified");
        header('ETag: "'.$etag.'"');
        exit();
      }
    }
94

Ayolo's avatar
bleh  
Ayolo committed
95
    header("Cache-Control: must-revalidate");    header("Pragma: cache");
Ayolo's avatar
Ayolo committed
96 97 98
    header("Last-Modified: ".$lastModified);
    header("Cache-Control: public");
    header("Content-type: image/jpeg");
99
    header('Content-length: '.filesize($file));
Ayolo's avatar
Ayolo committed
100 101 102 103 104 105 106
    header('ETag: "'.$etag.'"');
    readfile($file);
    exit();
  }

  $photo = new photo($site->db);
  $photo->load_by_id($id_photo);
107

Ayolo's avatar
Ayolo committed
108 109
  if ( !$photo->is_valid() || !$photo->is_right($site->user,DROIT_LECTURE) )
  {
jlaval's avatar
jlaval committed
110
    renvoyer_image($topdir."images/actions/delete.png");
Ayolo's avatar
Ayolo committed
111 112
    exit();
  }
113

Ayolo's avatar
Ayolo committed
114 115
  $rootcat = new catphoto($site->db);
  $catpr = new catphoto($site->db);
116

Ayolo's avatar
Ayolo committed
117 118 119 120 121 122 123 124 125
  $rootcat->load_by_asso_summary($site->asso->id);

  if ( !$rootcat->is_valid() )
  {
    renvoyer_image($topdir."images/actions/delete.png");
    exit();
  }

  $catpr->load_by_id($photo->id_catph);
126

Ayolo's avatar
Ayolo committed
127 128
  while ( $catpr->is_valid() && $catpr->id != $rootcat->id )
    $catpr->load_by_id($catpr->id_catph_parent);
129

Ayolo's avatar
Ayolo committed
130 131 132 133 134
  if ( ($catpr->id != $rootcat->id) && ($site->asso->id != $photo->meta_id_asso)  )
  {
    renvoyer_image($topdir."images/actions/delete.png");
    exit();
  }
135

Ayolo's avatar
Ayolo committed
136
  $abs_file = $photo->get_abs_path().$photo->id;
137

Feu's avatar
fix  
Feu committed
138 139
  if ( $mode == "flv" && $photo->type_media == MEDIA_VIDEOFLV )
  {
140
    header('Content-length: '.filesize($abs_file.".flv"));
Feu's avatar
fix  
Feu committed
141 142 143
    header("Content-type: video/x-flv");
    header("Content-Disposition: file; filename=\"".$photo->id.".flv\"");
    readfile($abs_file.".flv");
144
    exit();
Feu's avatar
fix  
Feu committed
145
  }
146

Ayolo's avatar
Ayolo committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
  if ( $mode == "vignette" )
    $abs_file.=".vignette.jpg";
  else if ( $mode == "diapo" )
    $abs_file.=".diapo.jpg";
  else
    $abs_file.=".jpg";

  renvoyer_image($abs_file);

  exit();
}



?>