Index: trunk/core/units/general/cat_event_handler.php =================================================================== diff -u -N -r8562 -r8686 --- trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 8562) +++ trunk/core/units/general/cat_event_handler.php (.../cat_event_handler.php) (revision 8686) @@ -670,7 +670,10 @@ function OnAfterItemLoad(&$event) { $special = substr($event->Special, -6); + $object =& $event->getObject(); + /* @var $object kCatDBItem */ + if ($special == 'import' || $special == 'export') { $image_data = $object->getPrimaryImageData(); @@ -688,7 +691,7 @@ } } - //substituiting pending status value for pending editing + // substituiting pending status value for pending editing if ($object->HasField('OrgId') && $object->GetDBField('OrgId') > 0 && $object->GetDBField('Status') == -2) { $options = $object->Fields['Status']['options']; foreach ($options as $key => $val) { @@ -697,14 +700,28 @@ } $object->Fields['Status']['options'] = $new_options; } - /*elseif (!$this->Application->IsAdmin() && $object->GetDBField('Status') != 1 && $object->Prefix != 'cms') { - header('HTTP/1.0 404 Not Found'); - while (ob_get_level()) { ob_end_clean(); } - $this->Application->HTML = $this->Application->ParseBlock(array('name'=>$this->Application->ConfigValue('ErrorTemplate'))); - $this->Application->Done(); - exit(); - }*/ + // linking existing images for item with virtual fields + $sql = 'SELECT * + FROM '.TABLE_PREFIX.'Images + WHERE ResourceId = '.$object->GetDBField('ResourceId').' + ORDER BY ImageId ASC'; + $item_images = $this->Conn->Query($sql); + + $image_counter = 1; + foreach ($item_images as $item_image) { + $image_path = preg_replace('/^'.preg_quote(IMAGES_PATH, '/').'(.*)/', '\\1', $item_image['ThumbPath']); + if ($item_image['DefaultImg'] == 1 || $item_image['Name'] == 'main') { + // process primary image separately + $object->SetDBField('PrimaryImage', $image_path); + $object->Fields['PrimaryImage']['original_field'] = $item_image['Name']; + continue; + } + + $object->SetDBField('Image'.$image_counter, $image_path); + $object->Fields['Image'.$image_counter]['original_field'] = $item_image['Name']; + $image_counter++; + } } function OnAfterItemUpdate(&$event) @@ -2133,6 +2150,19 @@ return $owner_field; } + /** + * Creates virtual image fields for item + * + * @param kEvent $event + */ + function OnAfterConfigRead(&$event) + { + $image_helper =& $this->Application->recallObject('ImageHelper'); + /* @var $image_helper ImageHelper */ + + $image_helper->createItemImages($event->Prefix); + } + } ?> \ No newline at end of file