/** * Handler for accepting a new product images from the image manager or other products * * @param ISC_ADMIN_REMOTE $remote */ public function remoteUseSourceImages(ISC_ADMIN_REMOTE $remote) { GetLib('class.imagedir'); $db = $GLOBALS["ISC_CLASS_DB"]; $sourceImages = @$_POST['images']; $tags = array(); $errors = array(); $images = array(); $productId = false; $productHash = false; if (isset($_POST['product'])) { $productId = (int)@$_POST['product']; if (!isId($productId) || !ProductExists($productId)) { $errors[] = GetLang('ProductDoesntExist'); } } else if (isset($_POST['hash']) && $_POST['hash']) { $productHash = $_POST['hash']; } else { $errors[] = GetLang('ProductDoesntExist'); } if (empty($errors) && count($sourceImages)) { // only proceed if they had images selected $imageDir = new ISC_IMAGEDIR(); foreach ($sourceImages as $imageId) { if(substr($imageId, 0, strlen('productimage_')) == 'productimage_') { // image from another product $productImageId = (int)str_replace('productimage_', '', $imageId); $productImage = new ISC_PRODUCT_IMAGE($productImageId); $sourceFilePath = $productImage->getAbsoluteSourceFilePath(); $originalFilename = $productImage->getFileName(); } elseif (substr($imageId, 0, strlen('imagemanager_')) == 'imagemanager_') { // image from the image manager $imageManagerId = str_replace('imagemanager_', '', $imageId); $originalFilename = $imageDir->findFileNameById($imageManagerId); $sourceFilePath = $imageDir->GetImagePath() . '/' . $originalFilename; } else { // not a valid selection continue; } try { if ($productHash) { $image = ISC_PRODUCT_IMAGE::importImage($sourceFilePath, $originalFilename, $productHash, true, false); } else { $image = ISC_PRODUCT_IMAGE::importImage($sourceFilePath, $originalFilename, $productId, false, false); } } catch (ISC_PRODUCT_IMAGE_IMPORT_INVALIDIMAGEFILE_EXCEPTION $exception) { $errors[] = $url . ": " . $exception->getMessage() . ' ' . GetLang('ProductImageInvalidFileFromSource'); continue; } catch (ISC_PRODUCT_IMAGE_IMPORT_EXCEPTION $exception) { // these exceptions should have language-powered messages so are safe to return to the user $errors[] = $url . ": " . $exception->getMessage(); continue; } catch (Exception $exception) { // other unknown error $errors[] = $url . ': ' . GetLang('ProductImageProcessUnknownError'); continue; } // all done, add to list of successful images $images[] = $image; } } foreach ($images as /*ISC_PRODUCT_IMAGE*/$image) { $json = array( 'id' => $image->getProductImageId(), 'product' => $image->getProductId(), 'hash' => $image->getProductHash(), 'preview' => $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_THUMBNAIL, true), 'zoom' => $image->getResizedUrl(ISC_PRODUCT_IMAGE_SIZE_ZOOM, true), 'description' => $image->getDescription(), 'baseThumbnail' => $image->getIsThumbnail(), 'sort' => $image->getSort(), ); $tags[] = $remote->MakeXMLTag('image', isc_json_encode($json), true); } foreach ($errors as $message) { $tags[] = $remote->MakeXMLTag('error', $message, true); } $remote->SendXMLHeader(); $remote->SendXMLResponse($tags); die(); }