+
+ static function domImgUrl($baseURL, $dom)
+ {
+ $url = $dom;
+ if (!is_string($url)) {
+ $url = $dom->getAttribute('src');
+ }
+ $umatch = false;
+ if(!preg_match('#/(Images|Images/Thumb/[a-z0-9]+|Images/Download)/([0-9]+)/(.*)$#', $url, $umatch)) {
+ return $url;
+ }
+ $id = $umatch[2];
+ $hash = '';
+
+ if (!empty($umatch[3]) && strpos($umatch[3],'#')) {
+ $hh = explode('#',$umatch[3]);
+ $hash = '#'. array_pop($hh);
+ }
+
+
+ $img = DB_DataObject::factory('Images');
+ if (!$img->get($id)) {
+ return $url;
+ }
+ $type = explode('/', $umatch[1]);
+ $thumbsize = -1;
+
+ if (count($type) > 2 && $type[1] == 'Thumb') {
+ $thumbsize = $type[2];
+ $provider = '/Images/Thumb';
+ } else {
+ $provider = '/'.$umatch[1];
+ }
+
+ $w = is_string($dom) ? false : $dom->getAttribute('width');
+ $h = is_string($dom) ? false : $dom->getAttribute('height');
+
+ if (!is_string($dom) && (!empty($w) || !empty($h) ) && is_numeric($w) && is_numeric($h))
+ {
+ // no support for %...
+ $thumbsize =
+ (empty($w) ? '0' : intval($w) * 1) .
+ 'x' .
+ (empty($h) ? '0' : intval($h) * 1);
+ $provider = '/Images/Thumb';
+
+ }
+
+ if ($thumbsize !== -1) {
+ // change in size..
+ // need to regenerate it..
+
+ $type = array('Images', 'Thumb', $thumbsize);
+
+ $fc = $img->toFileConvert();
+ // make sure it's available..
+ $fc->convert($img->mimetype, $thumbsize);
+
+
+ } else {
+ $provider = $provider == 'Images/Thumb' ? 'Images' : $provider;
+ }
+
+
+ // finally replace the original TAG with the new version..
+
+ return $img->URL($thumbsize, $provider, $baseURL) . $hash ;
+
+
+ }
+
+ static function replaceDataUrl($baseURL, $img, $obj)
+ {
+ $d = DB_DataObject::Factory('Images');
+ $d->object($obj);
+
+
+ $d->createFromData($img->getAttribute('src'));
+ $img->setAttribute('src', $d->URL(-1, '/Images' , $baseURL));
+ }
+