">
@@ -45,7 +45,7 @@
-
+
">
Index: trunk/core/units/general/cat_event_handler.php
===================================================================
diff -u -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
Fisheye: Tag 8686 refers to a dead (removed) revision in file `trunk/kernel/images/pending/.cvs'.
Fisheye: No comparison available. Pass `N' to diff?
Index: trunk/core/admin_templates/incs/image_blocks.tpl
===================================================================
diff -u -r8413 -r8686
--- trunk/core/admin_templates/incs/image_blocks.tpl (.../image_blocks.tpl) (revision 8413)
+++ trunk/core/admin_templates/incs/image_blocks.tpl (.../image_blocks.tpl) (revision 8686)
@@ -2,7 +2,7 @@
" border="0" />
-
+
">
@@ -45,7 +45,7 @@
-
+
">
Index: trunk/core/units/general/helpers/image_helper.php
===================================================================
diff -u -r8474 -r8686
--- trunk/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 8474)
+++ trunk/core/units/general/helpers/image_helper.php (.../image_helper.php) (revision 8686)
@@ -12,7 +12,46 @@
*/
function ScaleImage($src_image, $dst_image, $dst_width, $dst_height)
{
+ $image_info = $this->getImageInfo($src_image);
+ if (!$image_info) {
+ return false;
+ }
+ list ($dst_width, $dst_height, $resized) = $this->GetImageDimensions($src_image, $dst_width, $dst_height);
+ if (!$resized) {
+ // image dimensions are smaller or equals to required dimensions
+ return false;
+ }
+
+ if (function_exists('imagecreatefromjpeg')) {
+ // try to resize using GD
+ $resize_map = Array (
+ 'image/jpeg' => 'imagecreatefromjpeg:imagejpeg',
+ 'image/gif' => 'imagecreatefromgif:imagegif',
+ 'image/png' => 'imagecreatefrompng:imagepng',
+ );
+
+ $mime_type = $image_info['mime'];
+ if (!isset($resize_map[$mime_type])) {
+ return false;
+ }
+
+ list ($read_function, $write_function) = explode(':', $resize_map[$mime_type]);
+
+ $src_image_rs = @$read_function($src_image);
+ if ($src_image_rs) {
+ $dst_image_rs = imagecreatetruecolor($dst_width, $dst_height);
+ imagecopyresampled($dst_image_rs, $src_image_rs, 0, 0, 0, 0, $dst_width, $dst_height, $image_info[0], $image_info[1]);
+ return @$write_function($dst_image_rs, $dst_image, 100);
+ }
+ }
+ else {
+ // try to resize using ImageMagick
+ exec('/usr/bin/convert '.$src_image.' -resize '.$dst_width.'x'.$dst_height.' '.$dst_image, $shell_output, $exec_status);
+ return $exec_status == 0;
+ }
+
+ return false;
}
/**
@@ -49,7 +88,7 @@
$height = $orig_height;
}
- return Array ($width, $height);
+ return Array ($width, $height, $too_large);
}
/**
@@ -72,6 +111,82 @@
return $image_info;
}
+
+ /**
+ * Determines what image fields should be created (from post or just dummy fields for 1st upload)
+ *
+ * @param string $prefix
+ */
+ function createItemImages($prefix)
+ {
+ $items_info = $this->Application->GetVar($prefix);
+ if ($items_info) {
+ list ($id, $fields_values) = each($items_info);
+ $this->createImageFields($prefix, $fields_values);
+ }
+ else {
+ $this->createImageFields($prefix, Array());
+ }
+ }
+
+ /**
+ * Dynamically creates virtual fields for item for each image field in submit
+ *
+ * @param string $prefix
+ * @param Array $fields_values
+ */
+ function createImageFields($prefix, $fields_values)
+ {
+ $field_options = Array (
+ 'type' => 'string',
+ 'formatter' => 'kPictureFormatter',
+// 'skip_empty' => 1,
+ 'max_len' => 240,
+ 'default' => '',
+ 'not_null' => 1,
+ 'include_path' => 1,
+ 'allowed_types' => Array ('image/jpeg', 'image/pjpeg', 'image/png', 'image/gif', 'image/bmp'),
+ 'error_msgs' => Array (
+ 'bad_file_format' => '!la_error_InvalidFileFormat!',
+ 'bad_file_size' => '!la_error_FileTooLarge!',
+ 'cant_save_file' => '!la_error_cant_save_file!'
+ ),
+ );
+
+ $fields = $this->Application->getUnitOption($prefix, 'Fields');
+ $virtual_fields = $this->Application->getUnitOption($prefix, 'VirtualFields');
+
+ $image_count = 0;
+ foreach ($fields_values as $field_name => $field_value) {
+ if (preg_match('/^(Image[\d]+|PrimaryImage)$/', $field_name)) {
+ $fields[$field_name] = $field_options;
+ $virtual_fields[$field_name] = $field_options;
+ $image_count++;
+ }
+ }
+
+ if (!$image_count) {
+ // no images found in POST -> create default image fields
+ $image_names = Array ('PrimaryImage' => '');
+ $image_count = $this->Application->ConfigValue($prefix.'_MaxImageCount');
+ if (!$image_count) {
+ $image_count = 3; // primary image + 2 additional images
+ }
+
+ $created_count = 1;
+ while ($created_count < $image_count) {
+ $image_names['Image'.$created_count] = '';
+ $created_count++;
+ }
+
+ $this->createImageFields($prefix, $image_names);
+ return ;
+ }
+
+ $this->Application->setUnitOption($prefix, 'ImageCount', $image_count);
+ $this->Application->setUnitOption($prefix, 'Fields', $fields);
+ $this->Application->setUnitOption($prefix, 'VirtualFields', $virtual_fields);
+ }
}
?>
\ No newline at end of file
| | | |