1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
<?php
class ImageProcessingController extends AdminHttpViewController
{
public function actionDefault()
{
$this->contentView->set_template_dir(DIR_FS_ADMIN . 'html/content/');
$html = $this->_render('image_processing.html', array(
'image_options_page_link' => xtc_href_link(FILENAME_CONFIGURATION, 'gID=4', 'NONSSL')
));
$JavaScriptEngineLanguages = array(
'image_processing'
);
return MainFactory::create('AdminPageHttpControllerResponse', 'Image Processing', $html, null, $JavaScriptEngineLanguages);
}
public function actionProcess()
{
@xtc_set_time_limit(0);
require_once DIR_FS_CATALOG . 'admin/includes/classes/' . FILENAME_IMAGEMANIPULATOR;
$logger = LogControl::get_instance();
$imageNumber = (int)$this->_getPostData('image_number');
$files = $this->_getImageFiles();
$responseMessage = '';
$products_image_name = $files[$imageNumber - 1]['text'];
$image_error = false;
$filesCount = count($files);
if($imageNumber <= $filesCount && $imageNumber > 0)
{
include(DIR_WS_INCLUDES . 'product_popup_images.php');
include(DIR_WS_INCLUDES . 'product_info_images.php');
include(DIR_WS_INCLUDES . 'product_thumbnail_images.php');
include(DIR_WS_INCLUDES . 'product_gallery_images.php');
if($image_error)
{
$responseMessage = 'Image ' . $imageNumber . ' "' . $products_image_name . '" could not be processed.';
$logger->notice($responseMessage, 'widgets', 'image_processing', 'notice', $p_level_type = 'DEBUG NOTICE', E_USER_NOTICE);
}
elseif($imageNumber === $filesCount)
{
$logger->notice('Image processing DONE', 'widgets', 'image_processing', 'notice', $p_level_type = 'DEBUG NOTICE', E_USER_NOTICE);
}
$finished = $imageNumber === $filesCount;
}
else
{
$finished = true;
}
$payload = array(
'imagesCount' => $filesCount,
'finished' => $finished
);
$response = array('success' => !$image_error, 'msg' => $responseMessage, 'payload' => $payload);
return MainFactory::create('JsonHttpControllerResponse', $response);
}
protected function _getImageFiles()
{
$files = array();
if($dir = opendir(DIR_FS_CATALOG_ORIGINAL_IMAGES))
{
$i = 0;
while($file = readdir($dir))
{
if(is_file(DIR_FS_CATALOG_ORIGINAL_IMAGES . $file)
&& (strrpos(strtolower($file), '.jpg') !== false
|| strrpos(strtolower($file), '.jpeg') !== false
|| strrpos(strtolower($file), '.gif') !== false
|| strrpos(strtolower($file), '.png') !== false)
)
{
$files[] = array(
'id' => $file,
'text' => $file,
'nr' => $i++
);
}
}
closedir($dir);
array_multisort($files);
}
return $files;
}
}