X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=Images.php;h=bfda2826ca553b7843eda775815488e85a9443ac;hp=3a4b741bcf2b1e07a4d9d1488063b038217c19af;hb=HEAD;hpb=81b82c12f33746b22863df989c119918a371013e diff --git a/Images.php b/Images.php index 3a4b741b..bcedb003 100644 --- a/Images.php +++ b/Images.php @@ -42,9 +42,9 @@ class Pman_Core_Images extends Pman { // tables that do not need authentication checks before serving. - var $public_image_tables = array(); - - var $is_email = false; + var $public_image_tables = array( + 'crm_mailing_list_message' // we know these are ok... + ); var $sizes = array( '100', @@ -77,6 +77,9 @@ class Pman_Core_Images extends Pman var $as_mimetype = false; var $method = 'inline'; var $page = false; + var $is_local = false; + var $size; + function get($s, $opts=array()) // determin what to serve!!!! { @@ -84,10 +87,10 @@ class Pman_Core_Images extends Pman //if (!empty($_GET['_post'])) { // return $this->post(); //} + - if(!empty($_REQUEST['is_email'])) { - $this->is_email = true; - } + + $this->is_local = (!empty($_SERVER['HTTP_HOST']) && $_SERVER['HTTP_HOST'] == 'localhost') ? true : false; $this->as_mimetype = empty($_REQUEST['as']) ? '' : $_REQUEST['as']; @@ -127,7 +130,7 @@ class Pman_Core_Images extends Pman } if (strpos($id,':') > 0) { // id format tablename:id:-imgtype - + //DB_DataObject::debugLevel(1); if (!$this->authUser) { $this->imgErr("not-authenticated-using-colon-format",$s); @@ -184,15 +187,16 @@ class Pman_Core_Images extends Pman $img = DB_DataObjecT::factory('Images'); - if (!$id || !$img->get($id)) { + if (!$id || !$img->get($id) || !$img->exists()) { + //print_r($img); die("HERE"); $this->imgErr("image has been removed or deleted.",$s); } + if($this->is_local) { + return $this->serve($img); + } + if (!$this->authUser && !in_array($img->ontable,$this->public_image_tables)) { - - if($this->is_email) { - return $this->serve($img); - } if ($img->ontable != 'core_company') { $this->imgErr("not-authenticated {$img->ontable}",$s); @@ -218,8 +222,9 @@ class Pman_Core_Images extends Pman } function imgErr($reason,$path) { - header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' . - urlencode($reason) .'&path='.urlencode($path)); + header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' . urlencode($reason) ); + header('X-Error: ' . $reason . ':' . $path); + echo $reason . ':' . $path; exit; } @@ -230,6 +235,9 @@ class Pman_Core_Images extends Pman function post($v) { + if (!empty($_REQUEST['_get'])) { + return $this->get($v); + } if (!$this->authUser) { $this->jerr("image conversion only allowed by registered users"); @@ -280,23 +288,27 @@ class Pman_Core_Images extends Pman function serve($img) { - $this->sessionState(0); // turn off session... - locking... + $this->sessionState(0); // turn off session... - locking... require_once 'File/Convert.php'; - if (!file_exists($img->getStoreName())) { -// print_r($img);exit; - header('Location: ' . $this->rootURL . '/Pman/templates/images/file-broken.png?reason=' . - urlencode("Original file was missing : " . $img->getStoreName())); - + if (!$img->exists()) { + $this->imgErr("serve = missing-image", $img->getStoreName()); + } // print_r($img);exit; $x = $img->toFileConvert(); if (empty($this->as_mimetype) || $img->mimetype == 'image/gif') { $this->as_mimetype = $img->mimetype; } + + if (!$this->thumb) { + if ($x->mimetype == $this->as_mimetype) { + $x->serveOnly($this->method, $img->filename); + exit; + } $x->convert( $this->as_mimetype); - $x->serve($this->method); + $x->serve($this->method, $img->filename); exit; } //echo "SKALING? $this->size"; @@ -321,6 +333,7 @@ class Pman_Core_Images extends Pman if (!file_exists($fn)) { $this->validateSize(); } + if(!empty($this->page) && !is_nan($this->page * 1)){ $x->convert( $this->as_mimetype, $this->size, 0, $this->page); @@ -337,6 +350,10 @@ class Pman_Core_Images extends Pman } function validateSize() { + if($this->is_local) { + return true; + } + if (($this->authUser && !empty($this->authUser->company_id) && $this->authUser->company()->comptype=='OWNER') || $_SERVER['SERVER_ADDR'] == $_SERVER['REMOTE_ADDR']) { return true; @@ -388,7 +405,7 @@ class Pman_Core_Images extends Pman */ - static function replaceImageURLS($html) + static function replaceImageURLS($html, $obj = false) { $ff = HTML_FlexyFramework::get(); @@ -398,61 +415,142 @@ class Pman_Core_Images extends Pman //var_dump($ff->Pman_Images['public_baseURL']); $baseURL = $ff->Pman_Images['public_baseURL']; - preg_match_all('/]+>/i',$html, $result); - //print_r($result); - $matches = array_unique($result[0]); - foreach($matches as $img) { - $imatch = array(); - preg_match_all('/(width|height|src)="([^"]*)"/i',$img, $imatch); - // build a keymap - $attr = array(); - - foreach($imatch[1] as $i=>$key) { - $attr[$key] = $imatch[2][$i]; - } - // does it contain baseURL??? --- well what about relative paths... - //print_R($attr); - - if (empty($attr['src'])) { + libxml_use_internal_errors(true); + $dom = new DOMDocument(); + $dom->loadHTML("