4 * So why is this called image? and not attachment
6 * The original database design for handling attachments was only done for images initially
8 * It's role expanded to attachments over time, but still kept the image name..
15 * view permission should be required on the underlying object...
20 * Images/{ID}/fullname.xxxx
22 * (valid thumbs 200, 400)...?
23 * Images/Thumb/200/{ID}/fullname.xxxx
24 * == force a download..
25 * Images/Download/{ID}/fullname.xxxx
28 require_once 'MTrackWeb.php';
30 class MTrackWeb_Image extends MTrackWeb
32 // relies on parent getAuth.
34 function get($s) // determin what to serve!!!!
36 $this->as_mimetype = '' ;
38 //DB_DataObject::debugLevel(1);
40 $bits= explode('/', $s);
42 // without id as first part...
43 if (!empty($bits[0]) && $bits[0] == 'Thumb') {
45 $this->as_mimetype = 'image/jpeg';
46 $this->size = empty($bits[1]) ? '0x0' : $bits[1];
47 $id = empty($bits[2]) ? 0 : $bits[2];
49 } else if (!empty($bits[0]) && $bits[0] == 'Download') {
50 $this->method = 'attachment';
51 $id = empty($bits[1]) ? 0 : $bits[1];
53 } else if (!empty($bits[1]) && $bits[1] == 'Thumb') { // with id as first part.
55 $this->as_mimetype = 'image/jpeg';
56 $this->size = empty($bits[2]) ? '0x0' : $bits[2];
57 $id = empty($bits[3]) ? 0 : $bits[3];
60 $id = empty($bits[0]) ? 0 : $bits[0];
66 $img = DB_DataObjecT::factory('Images');
67 if (!$id || !$img->get($id)) {
69 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
70 urlencode("image with id does not exist, or is invalid"));
77 //----------- Authentication...
81 $obj = $img->object();
82 if ($obj->tableName() == 'Projects') {
83 if ($this->currentProject() != $obj->id) {
84 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
85 urlencode("image is not the same project (1)"));
90 if (empty($obj->project_id) || $obj->project_id != $this->currentProject()) {
91 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
92 urlencode("image is not the same project (2)"));
97 // -- spamming us with resize..
103 var $asmimetype = false;
104 var $method = 'inline';
107 require_once 'File/Convert.php';
108 if (!file_exists($img->getStoreName())) {
109 //print_r($img);exit;
110 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
111 urlencode("Original file was missing : " . $img->getStoreName()));
115 $x = new File_Convert($img->getStoreName(), $img->mimetype);
116 if (empty($this->as_mimetype)) {
117 $this->as_mimetype = $img->mimetype;
120 $x->convert( $this->as_mimetype);
121 $x->serve($this->method);
125 $this->validateSize();
126 $x->convert( $this->as_mimetype, $this->size);
131 function validateSize()
133 if (!in_array($this->size, array(
147 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
148 urlencode("invalid size"));