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 var $as_mimetype = false;
41 var $method = 'inline';
43 function get($s) // determin what to serve!!!!
45 $this->as_mimetype = empty($_REQUEST['as']) ? '' : $_REQUEST['as'];
47 $bits= explode('/', $s);
49 // without id as first part...
50 if (!empty($bits[0]) && $bits[0] == 'Thumb') {
52 $this->as_mimetype = 'image/jpeg';
53 $this->size = empty($bits[1]) ? '0x0' : $bits[1];
54 $id = empty($bits[2]) ? 0 : $bits[2];
56 } else if (!empty($bits[0]) && $bits[0] == 'Download') {
57 $this->method = 'attachment';
58 $id = empty($bits[1]) ? 0 : $bits[1];
60 } else if (!empty($bits[1]) && $bits[1] == 'Thumb') { // with id as first part.
62 $this->as_mimetype = 'image/jpeg';
63 $this->size = empty($bits[2]) ? '0x0' : $bits[2];
64 $id = empty($bits[3]) ? 0 : $bits[3];
67 $id = empty($bits[0]) ? 0 : $bits[0];
70 if (strpos($id,':') > 0) { // id format tablename:id:-imgtype
71 $onbits = explode(':', $id);
72 if ((count($onbits) < 2) || empty($onbits[1]) || !is_numeric($onbits[1]) || !strlen($onbits[0])) {
75 //DB_DataObject::debugLevel(1);
76 $img = DB_DataObjecT::factory('Images');
77 $img->ontable = $onbits[0];
78 $img->onid = $onbits[1];
79 if (empty($_REQUEST['anytype'])) {
80 $img->whereAdd("mimetype like 'image/%'");
83 if (isset($onbits[2])) {
84 $img->imgtype = $onbits[2];
87 if (!$img->find(true)) {
88 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
89 urlencode("no images for that item: " . htmlspecialchars($id)));
98 // depreciated - should use ontable:onid:type here...
99 if (!empty($_REQUEST['ontable'])) {
101 //DB_DataObjecT::debugLevel(1);
102 $img = DB_DataObjecT::factory('Images');
103 $img->setFrom($_REQUEST);
104 // use imgtype now...
105 // if (!empty($_REQUEST['query']['filename'])){
106 // $img->whereAdd("filename LIKE '". $img->escape($_REQUEST['query']['filename']).".%'");
111 if (!$img->find(true)) {
112 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason='.
113 urlencode("No file exists"));
121 $img = DB_DataObjecT::factory('Images');
122 if (!$id || !$img->get($id)) {
124 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
125 urlencode("image has been removed or deleted."));
133 require_once 'File/Convert.php';
134 if (!file_exists($img->getStoreName())) {
135 //print_r($img);exit;
136 header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' .
137 urlencode("Original file was missing : " . $img->getStoreName()));
141 $x = new File_Convert($img->getStoreName(), $img->mimetype);
142 if (empty($this->as_mimetype)) {
143 $this->as_mimetype = $img->mimetype;
146 $x->convert( $this->as_mimetype);
147 $x->serve($this->method);
150 //echo "SKALING? $this->size";
151 $this->validateSize();
152 $x->convert( $this->as_mimetype, $this->size);
160 function validateSize()
171 '300x100', // logo on login.
175 // this should be configurable...
176 $ff = HTML_FlexyFramework::get();
177 if (!empty($ff->Pman_Images['sizes'])) {
178 $sizes = array_merge($sizes , $ff->Pman_Images['sizes']);
182 if (!in_array($this->size, $sizes)) {
183 die("invalid scale - ".$this->size);