3 * view permission should be required on the underlying object...
8 * args: ontable request
9 * ontable (req) tablename.
12 * as (serve as a type) = eg. mimetype.
15 * as :(serve as a type) = eg. mimetype.
17 * Images/{ID}/fullname.xxxx
19 * (valid thumbs 200, 400)...?
20 * Images/Thumb/200/{ID}/fullname.xxxx
21 * Images/Download/{ID}/fullname.xxxx
24 require_once 'Pman.php';
25 class Pman_Images extends Pman
29 parent::getAuth(); // load company!
31 $au = $this->getAuthUser();
33 // die("Access denied");
35 $this->authUser = $au;
40 function get($s) // determin what to serve!!!!
42 $this->as_mimetype = empty($_REQUEST['as']) ? '' : $_REQUEST['as'];
44 $bits= explode('/', $s);
46 // without id as first part...
47 if (!empty($bits[0]) && $bits[0] == 'Thumb') {
49 $this->as_mimetype = 'image/jpeg';
50 $this->size = empty($bits[1]) ? '0x0' : $bits[1];
51 $id = empty($bits[2]) ? 0 : $bits[2];
53 } else if (!empty($bits[0]) && $bits[0] == 'Download') {
54 $this->method = 'attachment';
55 $id = empty($bits[1]) ? 0 : $bits[1];
57 } else if (!empty($bits[1]) && $bits[1] == 'Thumb') { // with id as first part.
59 $this->as_mimetype = 'image/jpeg';
60 $this->size = empty($bits[2]) ? '0x0' : $bits[2];
61 $id = empty($bits[3]) ? 0 : $bits[3];
64 $id = empty($bits[0]) ? 0 : $bits[0];
67 if (strpos($id,':') > 0) { // id format tablename:id:-imgtype
68 $onbits = explode(':', $id);
69 if ((count($onbits) < 2) || empty($onbits[1]) || !is_numeric($onbits[1]) || !strlen($onbits[0])) {
72 //DB_DataObject::debugLevel(1);
73 $img = DB_DataObjecT::factory('Images');
74 $img->ontable = $onbits[0];
75 $img->onid = $onbits[1];
76 if (empty($_REQUEST['anytype'])) {
77 $img->whereAdd("mimetype like 'image/%'");
80 if (isset($onbits[2])) {
81 $img->imgtype = $onbits[2];
84 if (!$img->find(true)) {
85 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
86 urlencode("no images for that item: " . htmlspecialchars($id)));
95 // depreciated - should use ontable:onid:type here...
96 if (!empty($_REQUEST['ontable'])) {
98 //DB_DataObjecT::debugLevel(1);
99 $img = DB_DataObjecT::factory('Images');
100 $img->setFrom($_REQUEST);
101 // use imgtype now...
102 // if (!empty($_REQUEST['query']['filename'])){
103 // $img->whereAdd("filename LIKE '". $img->escape($_REQUEST['query']['filename']).".%'");
108 if (!$img->find(true)) {
109 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason='.
110 urlencode("No file exists"));
118 $img = DB_DataObjecT::factory('Images');
119 if (!$id || !$img->get($id)) {
121 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
122 urlencode("image has been removed or deleted."));
128 var $asmimetype = false;
129 var $method = 'inline';
132 require_once 'File/Convert.php';
133 if (!file_exists($img->getStoreName())) {
135 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
136 urlencode("Original file was missing : " . $img->getStoreName()));
140 $x = new File_Convert($img->getStoreName(), $img->mimetype);
141 if (empty($this->as_mimetype)) {
142 $this->as_mimetype = $img->mimetype;
145 $x->convert( $this->as_mimetype);
146 $x->serve($this->method);
150 $this->validateSize();
151 $x->convert( $this->as_mimetype, $this->size);
159 function validateSize()
161 if (!in_array($this->size, array(
171 die("invalid scale - ".$this->size);