Allow overriding of PlSession::fillSession()
[platal.git] / classes / plimage.php
index 232fb47..a8113db 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /***************************************************************************
- *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  Copyright (C) 2003-2011 Polytechnique.org                              *
  *  http://opensource.polytechnique.org/                                   *
  *                                                                         *
  *  This program is free software; you can redistribute it and/or modify   *
@@ -23,16 +23,20 @@ class PlImage {
     protected $mime = null;
     protected $x = null;
     protected $y = null;
+    protected $ts = null;
 
     protected $data = null;
     protected $file = null;
 
-    private function __construct()
+    protected function __construct()
     {
     }
 
     public function send()
     {
+        if (!is_null($this->ts)) {
+            header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $this->ts) . ' GMT');
+        }
         pl_cached_dynamic_content_headers($this->mime);
         if (empty($this->data)) {
             readfile($this->file);
@@ -45,7 +49,7 @@ class PlImage {
     public function path()
     {
         if (empty($this->data)) {
-            return $file;
+            return $this->file;
         } else {
             $name = md5($this->data);
             $GLOBALS['img' . $name] = $this->data;
@@ -68,23 +72,25 @@ class PlImage {
         return $this->mime;
     }
 
-    public static function fromData($data, $mime, $x = null, $y = null)
+    public static function fromData($data, $mime, $x = null, $y = null, $ts = null)
     {
         $image = new PlImage();
         $image->data = $data;
         $image->mime = $mime;
         $image->x    = $x;
         $image->y    = $y;
+        $image->ts   = $ts;
         return $image;
     }
 
-    public static function fromFile($path, $mime, $x = null, $y = null)
+    public static function fromFile($path, $mime, $x = null, $y = null, $ts = null)
     {
         $image = new PlImage();
         $image->file = $path;
         $image->mime = $mime;
         $image->x    = $x;
         $image->y    = $y;
+        $image->ts   = $ts;
         return $image;
     }
 }