Page MenuHomeIn-Portal Phabricator

in-portal
No OneTemporary

File Metadata

Created
Thu, Sep 18, 9:52 PM

in-portal

Index: branches/unlabeled/unlabeled-1.1.4/kernel/units/images/image_tag_processor.php
===================================================================
--- branches/unlabeled/unlabeled-1.1.4/kernel/units/images/image_tag_processor.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.1.4/kernel/units/images/image_tag_processor.php (revision 4304)
@@ -0,0 +1,206 @@
+<?php
+
+class ImageTagProcessor extends kDBTagProcessor {
+
+ function Image($params)
+ {
+ $params['img_path'] = $this->ImageSrc($params);
+ $params['img_size'] = $this->ImageSize($params);
+ if (!$params['img_size']){
+ $params['img_size'] = ' width="'.getArrayValue($params, 'DefaultWidth').'"';
+ }
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+ $params['alt'] = htmlspecialchars($object->GetField('AltName'));
+ $params['name'] = $this->SelectParam($params, 'block,render_as');
+
+ return $this->Application->ParseBlock($params);
+ }
+
+ function ItemImage($params)
+ {
+ $this->LoadItemImage($params);
+ $params['img_path'] = $this->ImageSrc($params);
+ $params['img_size'] = $this->ImageSize($params);
+ if (!$params['img_size']){
+ if (isset($params['DefaultWidth'])) {
+ $params['img_size'] = ' width="'.getArrayValue($params, 'DefaultWidth').'"';
+ }
+ }
+ $params['name'] = $this->SelectParam($params, 'render_as,block');
+ $object =& $this->Application->recallObject($this->getPrefixSpecial());
+ if ( !$object->isLoaded() && !$this->SelectParam($params, 'default_image,DefaultImage') ) return false;
+
+ $params['alt'] = htmlspecialchars($object->GetField('AltName'));
+ return $this->Application->ParseBlock($params);
+ }
+
+ function LargeImageExists($params) {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
+ if ( $object->GetDBField('SameImages') == null || $object->GetDBField('SameImages')=='1' )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ function LoadItemImage($params)
+ {
+ $parent_item =& $this->Application->recallObject($params['PrefixSpecial']);
+
+ $this->Application->setUnitOption($this->Prefix,'AutoLoad',false);
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+
+ // if we need primary thumbnail which is preloaded with products list
+ $object->Clear();
+
+ // if we need primary thumbnail which is preloaded with products list
+ if (
+ $this->SelectParam($params, 'thumbnail,Thumbnail') &&
+ (
+ (
+ $this->SelectParam($params, 'primary,Primary')
+ ||
+ !isset($params['name'])
+ )
+ &&
+ !$this->Application->GetVar('img_id')
+ &&
+ isset($parent_item->Fields['LocalThumb'])
+ )
+ )
+ {
+ $object->SetDefaultValues();
+ $object->SetDBFieldsFromHash($parent_item->GetFieldValues(), Array('SameImages', 'LocalThumb', 'ThumbPath', 'ThumbUrl', 'LocalImage', 'LocalPath', 'Url') );
+ $object->Loaded = true;
+ }
+ else { // if requested image is not primary thumbnail - load it directly
+ $id_field = $this->Application->getUnitOption($this->Prefix, 'ForeignKey');
+ $parent_table_key = $this->Application->getUnitOption($this->Prefix, 'ParentTableKey');
+
+ $keys[$id_field] = $parent_item->GetDBField($parent_table_key);
+
+ // which image to load?
+ if ( getArrayValue($params, 'Primary') ) { //load primary image
+ $keys['DefaultImg'] = 1;
+ }
+ elseif ( getArrayValue($params, 'name') ) { //load by name
+ $keys['Name'] = $params['name'];
+ }
+ elseif ( $image_id = $this->Application->GetVar($this->Prefix.'_id') ) {
+ $keys['ImageId'] = $image_id;
+ }
+ else {
+ $keys['DefaultImg'] = 1; //if primary was not set explicity and name was also not passed - load primary
+ }
+
+ $object->Load($keys);
+ }
+ }
+
+ function ImageSrc($params)
+ {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+ $ret = '';
+ // if we need thumb, or full image is same as thumb
+ if ( $this->SelectParam($params, 'thumbnail,Thumbnail') || $object->GetDBField('SameImages') )
+ {
+ // return local image or url
+ $ret = $object->GetDBField('LocalThumb') ? PROTOCOL.SERVER_NAME.BASE_PATH.'/'.$object->GetDBField('ThumbPath') : $object->GetDBField('ThumbUrl');
+ if ( $object->GetDBField('LocalThumb') && !file_exists(FULL_PATH.'/'.$object->GetDBField('ThumbPath')) ) $ret = '';
+ }
+ else { // if we need full which is not the same as thumb
+ $ret = $object->GetDBField('LocalImage') ? PROTOCOL.SERVER_NAME.BASE_PATH.'/'.$object->GetDBField('LocalPath') : $object->GetDBField('Url');
+ if ( $object->GetDBField('LocalImage') && !file_exists(FULL_PATH.'/'.$object->GetDBField('LocalPath')) ) $ret = '';
+ }
+
+ return ($ret && $ret != PROTOCOL.SERVER_NAME.BASE_PATH && $ret != PROTOCOL.SERVER_NAME.BASE_PATH.'/') ? $ret : PROTOCOL.SERVER_NAME.BASE_PATH.THEMES_PATH.'/'.$this->SelectParam($params, 'default_image,DefaultImage');
+ }
+
+ function GetFullPath($path)
+ {
+ if(!$path) return $path;
+
+ // absolute url
+ if( preg_match('/^(.*):\/\/(.*)$/U', $path) )
+ {
+ if(strpos($path, PROTOCOL.SERVER_NAME.BASE_PATH) === 0)
+ {
+ $path = str_replace(PROTOCOL.SERVER_NAME.BASE_PATH, FULL_PATH.'/', $path);
+ }
+ return $path;
+ }
+
+ // relative url
+ return FULL_PATH.'/'.substr(THEMES_PATH,1).'/'.$path;
+ }
+
+ /**
+ * Makes size clause for img tag, such as
+ * ' width="80" height="100"' according to max_width
+ * and max_heght limits.
+ *
+ * @param array $params
+ * @return string
+ */
+ function ImageSize($params)
+ {
+ $img_path = $this->GetFullPath( getArrayValue($params, 'img_path') );
+
+ $image_info = @getimagesize($img_path);
+
+// if( !($img_path && file_exists($img_path) && isset($image_info) ) )
+ if( !$image_info )
+ {
+ trigger_error('Image <b>'.$img_path.'</b> <span class="debug_error">missing or invalid</span>', E_USER_WARNING);
+ return false;
+ }
+
+ $orig_width = getArrayValue($image_info, 0);
+ $orig_height = getArrayValue($image_info, 1);
+ $max_width = getArrayValue($params, 'MaxWidth');
+ $max_height = getArrayValue($params, 'MaxHeight');
+
+ $too_large = is_numeric($max_width) ? ($orig_width > $max_width) : false;
+ $too_large = $too_large || (is_numeric($max_height) ? ($orig_height > $max_height) : false);
+
+ if($too_large)
+ {
+ $width_ratio = $max_width ? $max_width / $orig_width : 1;
+ $height_ratio = $max_height ? $max_height / $orig_height : 1;
+ $ratio = min($width_ratio, $height_ratio);
+
+ $width = ceil($orig_width * $ratio);
+ $height = ceil($orig_height * $ratio);
+ }
+ else
+ {
+ $width = $orig_width;
+ $height = $orig_height;
+ }
+
+ $size_clause = ' width="'.$width.'" height="'.$height.'"';
+ return $size_clause;
+ }
+
+
+ // used in admin
+ function ImageUrl($params)
+ {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
+ if ($object->GetDBField('SameImages') ? $object->GetDBField('LocalThumb') : $object->GetDBField('LocalImage') )
+ {
+ $ret = $this->Application->Phrase(getArrayValue($params,'local_phrase'));
+ }
+ else
+ {
+ $ret = $object->GetDBField('SameImages') ? $object->GetDBField('ThumbUrl') : $object->GetDBField('Url');
+ }
+ return $ret;
+ }
+
+}
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.1.4/kernel/units/images/image_tag_processor.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: branches/unlabeled/unlabeled-1.1.4/core/units/images/image_tag_processor.php
===================================================================
--- branches/unlabeled/unlabeled-1.1.4/core/units/images/image_tag_processor.php (nonexistent)
+++ branches/unlabeled/unlabeled-1.1.4/core/units/images/image_tag_processor.php (revision 4304)
@@ -0,0 +1,206 @@
+<?php
+
+class ImageTagProcessor extends kDBTagProcessor {
+
+ function Image($params)
+ {
+ $params['img_path'] = $this->ImageSrc($params);
+ $params['img_size'] = $this->ImageSize($params);
+ if (!$params['img_size']){
+ $params['img_size'] = ' width="'.getArrayValue($params, 'DefaultWidth').'"';
+ }
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+ $params['alt'] = htmlspecialchars($object->GetField('AltName'));
+ $params['name'] = $this->SelectParam($params, 'block,render_as');
+
+ return $this->Application->ParseBlock($params);
+ }
+
+ function ItemImage($params)
+ {
+ $this->LoadItemImage($params);
+ $params['img_path'] = $this->ImageSrc($params);
+ $params['img_size'] = $this->ImageSize($params);
+ if (!$params['img_size']){
+ if (isset($params['DefaultWidth'])) {
+ $params['img_size'] = ' width="'.getArrayValue($params, 'DefaultWidth').'"';
+ }
+ }
+ $params['name'] = $this->SelectParam($params, 'render_as,block');
+ $object =& $this->Application->recallObject($this->getPrefixSpecial());
+ if ( !$object->isLoaded() && !$this->SelectParam($params, 'default_image,DefaultImage') ) return false;
+
+ $params['alt'] = htmlspecialchars($object->GetField('AltName'));
+ return $this->Application->ParseBlock($params);
+ }
+
+ function LargeImageExists($params) {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
+ if ( $object->GetDBField('SameImages') == null || $object->GetDBField('SameImages')=='1' )
+ {
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ function LoadItemImage($params)
+ {
+ $parent_item =& $this->Application->recallObject($params['PrefixSpecial']);
+
+ $this->Application->setUnitOption($this->Prefix,'AutoLoad',false);
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+
+ // if we need primary thumbnail which is preloaded with products list
+ $object->Clear();
+
+ // if we need primary thumbnail which is preloaded with products list
+ if (
+ $this->SelectParam($params, 'thumbnail,Thumbnail') &&
+ (
+ (
+ $this->SelectParam($params, 'primary,Primary')
+ ||
+ !isset($params['name'])
+ )
+ &&
+ !$this->Application->GetVar('img_id')
+ &&
+ isset($parent_item->Fields['LocalThumb'])
+ )
+ )
+ {
+ $object->SetDefaultValues();
+ $object->SetDBFieldsFromHash($parent_item->GetFieldValues(), Array('SameImages', 'LocalThumb', 'ThumbPath', 'ThumbUrl', 'LocalImage', 'LocalPath', 'Url') );
+ $object->Loaded = true;
+ }
+ else { // if requested image is not primary thumbnail - load it directly
+ $id_field = $this->Application->getUnitOption($this->Prefix, 'ForeignKey');
+ $parent_table_key = $this->Application->getUnitOption($this->Prefix, 'ParentTableKey');
+
+ $keys[$id_field] = $parent_item->GetDBField($parent_table_key);
+
+ // which image to load?
+ if ( getArrayValue($params, 'Primary') ) { //load primary image
+ $keys['DefaultImg'] = 1;
+ }
+ elseif ( getArrayValue($params, 'name') ) { //load by name
+ $keys['Name'] = $params['name'];
+ }
+ elseif ( $image_id = $this->Application->GetVar($this->Prefix.'_id') ) {
+ $keys['ImageId'] = $image_id;
+ }
+ else {
+ $keys['DefaultImg'] = 1; //if primary was not set explicity and name was also not passed - load primary
+ }
+
+ $object->Load($keys);
+ }
+ }
+
+ function ImageSrc($params)
+ {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), null);
+ $ret = '';
+ // if we need thumb, or full image is same as thumb
+ if ( $this->SelectParam($params, 'thumbnail,Thumbnail') || $object->GetDBField('SameImages') )
+ {
+ // return local image or url
+ $ret = $object->GetDBField('LocalThumb') ? PROTOCOL.SERVER_NAME.BASE_PATH.'/'.$object->GetDBField('ThumbPath') : $object->GetDBField('ThumbUrl');
+ if ( $object->GetDBField('LocalThumb') && !file_exists(FULL_PATH.'/'.$object->GetDBField('ThumbPath')) ) $ret = '';
+ }
+ else { // if we need full which is not the same as thumb
+ $ret = $object->GetDBField('LocalImage') ? PROTOCOL.SERVER_NAME.BASE_PATH.'/'.$object->GetDBField('LocalPath') : $object->GetDBField('Url');
+ if ( $object->GetDBField('LocalImage') && !file_exists(FULL_PATH.'/'.$object->GetDBField('LocalPath')) ) $ret = '';
+ }
+
+ return ($ret && $ret != PROTOCOL.SERVER_NAME.BASE_PATH && $ret != PROTOCOL.SERVER_NAME.BASE_PATH.'/') ? $ret : PROTOCOL.SERVER_NAME.BASE_PATH.THEMES_PATH.'/'.$this->SelectParam($params, 'default_image,DefaultImage');
+ }
+
+ function GetFullPath($path)
+ {
+ if(!$path) return $path;
+
+ // absolute url
+ if( preg_match('/^(.*):\/\/(.*)$/U', $path) )
+ {
+ if(strpos($path, PROTOCOL.SERVER_NAME.BASE_PATH) === 0)
+ {
+ $path = str_replace(PROTOCOL.SERVER_NAME.BASE_PATH, FULL_PATH.'/', $path);
+ }
+ return $path;
+ }
+
+ // relative url
+ return FULL_PATH.'/'.substr(THEMES_PATH,1).'/'.$path;
+ }
+
+ /**
+ * Makes size clause for img tag, such as
+ * ' width="80" height="100"' according to max_width
+ * and max_heght limits.
+ *
+ * @param array $params
+ * @return string
+ */
+ function ImageSize($params)
+ {
+ $img_path = $this->GetFullPath( getArrayValue($params, 'img_path') );
+
+ $image_info = @getimagesize($img_path);
+
+// if( !($img_path && file_exists($img_path) && isset($image_info) ) )
+ if( !$image_info )
+ {
+ trigger_error('Image <b>'.$img_path.'</b> <span class="debug_error">missing or invalid</span>', E_USER_WARNING);
+ return false;
+ }
+
+ $orig_width = getArrayValue($image_info, 0);
+ $orig_height = getArrayValue($image_info, 1);
+ $max_width = getArrayValue($params, 'MaxWidth');
+ $max_height = getArrayValue($params, 'MaxHeight');
+
+ $too_large = is_numeric($max_width) ? ($orig_width > $max_width) : false;
+ $too_large = $too_large || (is_numeric($max_height) ? ($orig_height > $max_height) : false);
+
+ if($too_large)
+ {
+ $width_ratio = $max_width ? $max_width / $orig_width : 1;
+ $height_ratio = $max_height ? $max_height / $orig_height : 1;
+ $ratio = min($width_ratio, $height_ratio);
+
+ $width = ceil($orig_width * $ratio);
+ $height = ceil($orig_height * $ratio);
+ }
+ else
+ {
+ $width = $orig_width;
+ $height = $orig_height;
+ }
+
+ $size_clause = ' width="'.$width.'" height="'.$height.'"';
+ return $size_clause;
+ }
+
+
+ // used in admin
+ function ImageUrl($params)
+ {
+ $object =& $this->Application->recallObject($this->getPrefixSpecial(), $this->Prefix, $params);
+ if ($object->GetDBField('SameImages') ? $object->GetDBField('LocalThumb') : $object->GetDBField('LocalImage') )
+ {
+ $ret = $this->Application->Phrase(getArrayValue($params,'local_phrase'));
+ }
+ else
+ {
+ $ret = $object->GetDBField('SameImages') ? $object->GetDBField('ThumbUrl') : $object->GetDBField('Url');
+ }
+ return $ret;
+ }
+
+}
+
+?>
\ No newline at end of file
Property changes on: branches/unlabeled/unlabeled-1.1.4/core/units/images/image_tag_processor.php
___________________________________________________________________
Added: cvs2svn:cvs-rev
## -0,0 +1 ##
+1.1
\ No newline at end of property
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property

Event Timeline