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 $bits= explode('/', $s);
40 // without id as first part...
41 if (!empty($bits[0]) && $bits[0] == 'Thumb') {
43 $this->as_mimetype = 'image/jpeg';
44 $this->size = empty($bits[1]) ? '0x0' : $bits[1];
45 $id = empty($bits[2]) ? 0 : $bits[2];
47 } else if (!empty($bits[0]) && $bits[0] == 'Download') {
48 $this->method = 'attachment';
49 $id = empty($bits[1]) ? 0 : $bits[1];
51 } else if (!empty($bits[1]) && $bits[1] == 'Thumb') { // with id as first part.
53 $this->as_mimetype = 'image/jpeg';
54 $this->size = empty($bits[2]) ? '0x0' : $bits[2];
55 $id = empty($bits[3]) ? 0 : $bits[3];
58 $id = empty($bits[0]) ? 0 : $bits[0];
64 $img = DB_DataObjecT::factory('Images');
65 if (!$id || !$img->get($id)) {
67 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
68 urlencode("image with id does not exist, or is invalid"));
75 //----------- Authentication...
79 $obj = $img->object();
80 if ($obj->tableName() == 'Projects') {
81 if ($this->currentProject() != $obj->id) {
82 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
83 urlencode("image is not the same project (1)"));
88 if (empty($obj->project_id) || $obj->project_id != $this->currentProject()) {
89 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
90 urlencode("image is not the same project (2)"));
95 // -- spamming us with resize..
101 var $asmimetype = false;
102 var $method = 'inline';
105 require_once 'File/Convert.php';
106 if (!file_exists($img->getStoreName())) {
107 //print_r($img);exit;
108 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
109 urlencode("Original file was missing : " . $img->getStoreName()));
113 $x = new File_Convert($img->getStoreName(), $img->mimetype);
114 if (empty($this->as_mimetype)) {
115 $this->as_mimetype = $img->mimetype;
118 $x->convert( $this->as_mimetype);
119 $x->serve($this->method);
123 $this->validateSize();
124 $x->convert( $this->as_mimetype, $this->size);
129 function validateSize()
131 if (!in_array($this->size, array(
143 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
144 urlencode("invalid size"));