function _process($type, $image_group, $position, $opacity, $watermark = true) { global $osC_Database; if ($type == 'products') { $Qimages = $osC_Database->query('select image from :table_products_images'); $Qimages->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); } else { $Qimages = $osC_Database->query('select articles_image as image from :table_articles'); $Qimages->bindTable(':table_articles', TABLE_ARTICLES); } $Qimages->execute(); $osC_Image = new osC_Image_Admin(); while ($Qimages->next()) { $image = $Qimages->value('image'); if ($watermark === true) { $original_image = DIR_FS_CATALOG . DIR_WS_IMAGES . $type . '/originals/' . $image; $original_watermarked_image = DIR_FS_CATALOG . DIR_WS_IMAGES . $type . '/originals/' . 'watermark_' . $image; toc_draw_watermark($original_image, $original_watermarked_image, DIR_FS_CATALOG . DIR_WS_IMAGES . WATERMARK_FILE_NAME, $position, $opacity); } foreach ($osC_Image->getGroups() as $group) { if ($group['id'] == $image_group) { $osC_Image->resize($image, $group['id'], $type, $watermark); } } } return true; }
function loadImageGroups() { global $toC_Json; $osC_Image = new osC_Image_Admin(); foreach ($osC_Image->getGroups() as $group) { if ($group['id'] != 1) { $modules[] = array('id' => $group['id'], 'text' => $group['code']); } } $response = array(EXT_JSON_READER_ROOT => $modules); echo $toC_Json->encode($response); }
function osC_Image_Admin_resize() { global $osC_Language; parent::osC_Image_Admin(); $osC_Language->loadIniFile('modules/image/resize.php'); $this->_title = $osC_Language->get('images_resize_title'); }
function osC_Image_Admin_check() { global $osC_Language; parent::osC_Image_Admin(); $osC_Language->loadIniFile('modules/image/check.php'); $this->_title = $osC_Language->get('images_check_title'); }
function getImages() { global $toC_Json, $osC_Database, $osC_Session; $osC_Image = new osC_Image_Admin(); $records = array(); if (isset($_REQUEST['products_id']) && is_numeric($_REQUEST['products_id'])) { $Qimages = $osC_Database->query('select id, image, default_flag from :table_products_images where products_id = :products_id order by sort_order'); $Qimages->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qimages->bindInt(':products_id', $_REQUEST['products_id']); $Qimages->execute(); while ($Qimages->next()) { $records[] = array('id' => $Qimages->valueInt('id'), 'image' => '<img src="' . DIR_WS_HTTP_CATALOG . 'images/products/mini/' . $Qimages->value('image') . '" border="0" />', 'name' => $Qimages->value('image'), 'size' => number_format(@filesize(DIR_FS_CATALOG . DIR_WS_IMAGES . 'products/originals/' . $Qimages->value('image'))) . ' bytes', 'default' => $Qimages->valueInt('default_flag')); } } else { $image_path = '../images/products/_upload/' . $osC_Session->getID() . '/'; $osC_DirectoryListing = new osC_DirectoryListing($image_path, true); $osC_DirectoryListing->setIncludeDirectories('false'); foreach ($osC_DirectoryListing->getFiles() as $file) { $records[] = array('id' => '', 'image' => '<img src="' . $image_path . $file['name'] . '" border="0" width="' . $osC_Image->getWidth('mini') . '" height="' . $osC_Image->getHeight('mini') . '" />', 'name' => $file['name'], 'size' => number_format($file['size']) . ' bytes', 'default' => $_SESSION['default_images'] == $file['name'] ? 1 : 0); } } $response = array(EXT_JSON_READER_TOTAL => sizeof($records), EXT_JSON_READER_ROOT => $records); echo $toC_Json->encode($response); }
function getImages() { global $toC_Json, $osC_Database; $osC_Image = new osC_Image_Admin(); $records = array(); $Qimages = $osC_Database->query('select id, image, default_flag from :table_products_images where products_id = :products_id order by sort_order'); $Qimages->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qimages->bindInt(':products_id', $_REQUEST['products_id']); $Qimages->execute(); while ($Qimages->next()) { $records[] = array('id' => $Qimages->valueInt('id'), 'image' => '<img src="' . DIR_WS_HTTP_CATALOG . 'images/products/mini/' . $Qimages->value('image') . '" border="0" width="' . $osC_Image->getWidth('mini') . '" />', 'name' => $Qimages->value('image'), 'size' => number_format(@filesize(DIR_FS_CATALOG . DIR_WS_IMAGES . 'products/originals/' . $Qimages->value('image'))) . ' bytes', 'default' => $Qimages->valueInt('default_flag')); } $response = array(EXT_JSON_READER_TOTAL => sizeof($records), EXT_JSON_READER_ROOT => $records); echo $toC_Json->encode($response); }
function insertProduct($product, $descriptions, $categories_id, $images) { global $osC_Database; $insert = true; $products_id = (int) $product['products_id']; unset($product['products_id']); if ($products_id > 0 && osC_Products_Importer::isProductExist($products_id)) { $insert = false; } if ($insert == true) { $products_id = toC_Importer::insertData(TABLE_PRODUCTS, $product); //categories if (is_array($categories_id) && !empty($categories_id)) { foreach ($categories_id as $category) { $data = array('categories_id' => $category, 'products_id' => $products_id); toC_Importer::insertData(TABLE_PRODUCTS_TO_CATEGORIES, $data); } } //description foreach ($descriptions as $description) { $description['products_id'] = $products_id; toC_Importer::insertData(TABLE_PRODUCTS_DESCRIPTION, $description); } $sort_id = 1; foreach ($images as $image) { $image['products_id'] = $products_id; $image['default_flag'] = $sort_id == 1 ? 1 : 0; $image['sort_order'] = $sort_id++; if (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . 'products/_upload/' . $image['image'])) { $image_id = toC_Importer::insertData(TABLE_PRODUCTS_IMAGES, $image); copy('../images/products/_upload/' . $image['image'], '../images/products/originals/' . $image['image']); $new_image_name = $products_id . '_' . $image_id . '_' . $image['image']; @rename('../images/products/originals/' . $image['image'], '../images/products/originals/' . $new_image_name); $Qupdate = $osC_Database->query('update :table_products_images set image = :image where id = :id'); $Qupdate->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qupdate->bindValue(':image', $new_image_name); $Qupdate->bindInt(':id', $image_id); $Qupdate->execute(); $osC_Image = new osC_Image_Admin(); foreach ($osC_Image->getGroups() as $group) { if ($group['id'] != '1') { $osC_Image->resize($new_image_name, $group['id'], 'products'); } } } } } }
public function __construct() { global $osC_Language, $osC_MessageStack; parent::__construct(); $this->_page_contents = 'edit.php'; if ((osc_empty(CFG_APP_IMAGEMAGICK_CONVERT) || !file_exists(CFG_APP_IMAGEMAGICK_CONVERT)) && !osC_Image_Admin::hasGDSupport()) { $osC_MessageStack->add('header', $osC_Language->get('ms_warning_image_processor_not_available'), 'warning'); } if (isset($_POST['subaction']) && $_POST['subaction'] == 'confirm') { $error = false; $data = array('quantity' => isset($_POST['products_quantity']) ? $_POST['products_quantity'] : 0, 'price' => is_numeric($_POST['products_price']) ? $_POST['products_price'] : 0, 'weight' => isset($_POST['products_weight']) ? $_POST['products_weight'] : 0, 'weight_class' => isset($_POST['products_weight_class']) ? $_POST['products_weight_class'] : '', 'status' => $_POST['products_status'], 'model' => isset($_POST['products_model']) ? $_POST['products_model'] : '', 'tax_class_id' => $_POST['products_tax_class_id'], 'products_name' => $_POST['products_name'], 'products_description' => $_POST['products_description'], 'products_keyword' => $_POST['products_keyword'], 'products_tags' => $_POST['products_tags'], 'products_url' => $_POST['products_url']); if (isset($_POST['attributes'])) { $data['attributes'] = $_POST['attributes']; } if (isset($_POST['categories'])) { $data['categories'] = $_POST['categories']; } if (isset($_POST['localimages'])) { $data['localimages'] = $_POST['localimages']; } if (isset($_POST['variants_tax_class_id'])) { $data['variants_tax_class_id'] = $_POST['variants_tax_class_id']; } if (isset($_POST['variants_price'])) { $data['variants_price'] = $_POST['variants_price']; } if (isset($_POST['variants_model'])) { $data['variants_model'] = $_POST['variants_model']; } if (isset($_POST['variants_quantity'])) { $data['variants_quantity'] = $_POST['variants_quantity']; } if (isset($_POST['variants_combo'])) { $data['variants_combo'] = $_POST['variants_combo']; } if (isset($_POST['variants_combo_db'])) { $data['variants_combo_db'] = $_POST['variants_combo_db']; } if (isset($_POST['variants_weight'])) { $data['variants_weight'] = $_POST['variants_weight']; } if (isset($_POST['variants_weight_class'])) { $data['variants_weight_class'] = $_POST['variants_weight_class']; } if (isset($_POST['variants_status'])) { $data['variants_status'] = $_POST['variants_status']; } if (isset($_POST['variants_default_combo'])) { $data['variants_default_combo'] = $_POST['variants_default_combo']; } foreach ($data['products_keyword'] as $value) { if (empty($value)) { $osC_MessageStack->add($this->_module, $osC_Language->get('ms_error_product_keyword_empty'), 'error'); $error = true; } elseif (preg_match('/^[a-z0-9_-]+$/iD', $value) !== 1) { $osC_MessageStack->add($this->_module, sprintf($osC_Language->get('ms_error_product_keyword_invalid'), osc_output_string_protected($value)), 'error'); $error = true; } if (osC_Products_Admin::getKeywordCount($value, isset($_GET[$this->_module]) && is_numeric($_GET[$this->_module]) ? $_GET[$this->_module] : null) > 0) { $osC_MessageStack->add($this->_module, sprintf($osC_Language->get('ms_error_product_keyword_exists'), osc_output_string_protected($value)), 'error'); $error = true; } } if ($error === false) { if (osC_Products_Admin::save(isset($_GET[$this->_module]) && is_numeric($_GET[$this->_module]) ? $_GET[$this->_module] : null, $data)) { $osC_MessageStack->add($this->_module, $osC_Language->get('ms_success_action_performed'), 'success'); } else { $osC_MessageStack->add($this->_module, $osC_Language->get('ms_error_action_not_performed'), 'error'); } osc_redirect_admin(osc_href_link_admin(FILENAME_DEFAULT, $this->_module . '&cID=' . $_GET['cID'])); } } }
function insertProduct($product, $descriptions, $categories_id, $images) { global $osC_Database; $products_id = toC_Importer::insertData(TABLE_PRODUCTS, $product); if (isset($products_id) && $products_id != '') { foreach ($descriptions as $description) { $description['products_id'] = $products_id; toC_Importer::insertData(TABLE_PRODUCTS_DESCRIPTION, $description); } $category['categories_id'] = $categories_id; $category['products_id'] = $products_id; toC_Importer::insertData(TABLE_PRODUCTS_TO_CATEGORIES, $category); $sort_id = 1; foreach ($images as $image) { $image['products_id'] = $products_id; $image['default_flag'] = $sort_id == 1 ? 1 : 0; $image['sort_order'] = $sort_id++; if (file_exists(DIR_FS_CATALOG . DIR_WS_IMAGES . 'products/_upload/' . $image['image'])) { copy('../images/products/_upload/' . $image['image'], '../images/products/originals/' . $image['image']); $osC_Image = new osC_Image_Admin(); foreach ($osC_Image->getGroups() as $group) { if ($group['id'] != '1') { $osC_Image->resize($image['image'], $group['id'], 'products'); } } toC_Importer::insertData(TABLE_PRODUCTS_IMAGES, $image); } } } }
public static function fileUpload() { global $osC_Database, $_module; $osC_Image = new osC_Image_Admin(); if (is_numeric($_GET[$_module])) { $products_image = new upload('products_image'); $products_image->set_extensions(array('gif', 'jpg', 'jpeg', 'png')); if ($products_image->exists()) { $products_image->set_destination(realpath('../images/products/originals')); if ($products_image->parse() && $products_image->save()) { $default_flag = 1; $Qcheck = $osC_Database->query('select id from :table_products_images where products_id = :products_id and default_flag = :default_flag limit 1'); $Qcheck->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qcheck->bindInt(':products_id', $_GET[$_module]); $Qcheck->bindInt(':default_flag', 1); $Qcheck->execute(); if ($Qcheck->numberOfRows() === 1) { $default_flag = 0; } $Qimage = $osC_Database->query('insert into :table_products_images (products_id, image, default_flag, sort_order, date_added) values (:products_id, :image, :default_flag, :sort_order, :date_added)'); $Qimage->bindTable(':table_products_images', TABLE_PRODUCTS_IMAGES); $Qimage->bindInt(':products_id', $_GET[$_module]); $Qimage->bindValue(':image', $products_image->filename); $Qimage->bindInt(':default_flag', $default_flag); $Qimage->bindInt(':sort_order', 0); $Qimage->bindRaw(':date_added', 'now()'); $Qimage->setLogging($_SESSION['module'], $_GET[$_module]); $Qimage->execute(); foreach ($osC_Image->getGroups() as $group) { if ($group['id'] != '1') { $osC_Image->resize($products_image->filename, $group['id']); } } } } } $result = array('result' => 1, 'rpcStatus' => RPC_STATUS_SUCCESS); echo json_encode($result); }