/** * Добавление и удаление фото * @param integer $id_news id новости * @param array $images_arr массив фотографий */ public function UpdatePhoto($id_news, $images_arr = array()) { $sql = "DELETE FROM " . _DB_PREFIX_ . "image_news WHERE id_news = " . $id_news; $this->db->StartTrans(); $this->db->Query($sql) or G::DieLoger("<b>SQL Error - </b>{$sql}"); $this->db->CompleteTrans(); $f['id_news'] = $id_news; if (isset($images_arr) && !empty($images_arr)) { $images = new Images(); $path = $GLOBALS['PATH_news_img'] . $id_news . '/'; $images->checkStructure($path); foreach ($images_arr as $src) { if (strpos($src, '\\temp/')) { $new_path = '/' . str_replace('\\temp/', '/' . $id_news . '/', $src); rename($GLOBALS['PATH_global_root'] . $src, $GLOBALS['PATH_global_root'] . $new_path); $src = $new_path; } $f['src'] = $src; $this->db->StartTrans(); if (!$this->db->Insert(_DB_PREFIX_ . 'image_news', $f)) { $this->db->FailTrans(); return false; } $this->db->CompleteTrans(); } } unset($id_news, $sql, $new_path, $f); return true; }
/** * [AcceptProductModeration description] * @param [type] $data [description] */ public function AcceptProductModeration($data) { $product = $this->GetProductOnModeration($data['id']); $f['art'] = $data['art']; $f['name'] = $product['name']; $f['translit'] = G::StrToTrans($product['name']); $f['descr'] = $product['descr']; $f['inbox_qty'] = $product['inbox_qty']; $f['min_mopt_qty'] = $product['min_mopt_qty']; if (isset($product['qty_control'])) { $f['qty_control'] = $product['qty_control']; } $f['sertificate'] = ''; $f['country'] = ''; $f['max_supplier_qty'] = 0; $f['manufacturer_id'] = 0; $f['weight'] = $product['height'] * $product['width'] * $product['length'] * 1.0E-6; $f['volume'] = str_replace(',', '.', $product['weight']); $f['height'] = $product['height']; $f['width'] = $product['width']; $f['length'] = $product['length']; $f['coefficient_volume'] = $product['coefficient_volume']; $f['edit_user'] = trim($_SESSION['member']['id_user']); $f['edit_date'] = date('Y-m-d H:i:s'); $f['create_user'] = $product['id_supplier']; $f['id_unit'] = $product['id_unit']; $f['prod_status'] = 3; $f['indexation'] = 1; $Images = new Images(); if (isset($product['images']) && $product['images'] != '') { foreach (explode(';', $product['images']) as $k => $image) { $to_resize[] = $newname = $data['art'] . ($k == 0 ? '' : '-' . $k) . '.jpg'; $structure = $GLOBALS['PATH_product_img'] . 'original/' . date('Y') . '/' . date('m') . '/' . date('d') . '/'; $structure_bd = '/product_images/original/' . date('Y') . '/' . date('m') . '/' . date('d') . '/'; $Images->checkStructure($structure); copy($_SERVER['DOCUMENT_ROOT'] . str_replace(_base_url, '/', $image), $structure . $newname); $images_arr[] = $structure_bd . $newname; $visible[] = 1; } } else { $images_arr = array(); } $Images->resize(false, $to_resize); $this->db->StartTrans(); if (!$this->db->Insert(_DB_PREFIX_ . 'product', $f)) { $this->db->FailTrans(); return false; } $this->db->CompleteTrans(); $sql = "SELECT MAX(id_product) AS id_product\n\t\t\tFROM " . _DB_PREFIX_ . "product"; $res = $this->db->GetOneRowArray($sql); $sql = "SELECT koef_nazen_mopt, koef_nazen_opt\n\t\t\tFROM " . _DB_PREFIX_ . "supplier\n\t\t\tWHERE id_user = " . $product['id_supplier']; $sup = $this->db->GetOneRowArray($sql); $id = $res['id_product']; $a['id_product'] = $id; $this->UpdatePhoto($id, $images_arr, $visible); $a['id_supplier'] = $product['id_supplier']; $a['price_mopt_otpusk'] = str_replace(',', '.', $product['price_mopt']); $a['price_opt_otpusk'] = str_replace(',', '.', $product['price_opt']); $a['price_mopt_recommend'] = str_replace(',', '.', $product['price_mopt'] * $sup['koef_nazen_mopt']); $a['price_opt_recommend'] = str_replace(',', '.', $product['price_opt'] * $sup['koef_nazen_opt']); $a['product_limit'] = $product['product_limit']; $a['sup_comment'] = ''; $a['edited'] = date('Y-m-d'); $this->db->StartTrans(); if (!$this->db->Insert(_DB_PREFIX_ . 'assortiment', $a)) { $this->db->FailTrans(); return false; } $this->db->CompleteTrans(); return $id; }
<?if($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'){ if(isset($_POST['action'])){ switch($_POST['action']){ case "error": if(isset($_POST['err_msg']) && $_POST['err_msg'] !=''){ if(isset($_POST['img_src']) && $_POST['img_src'] !=''){ $data = $_POST['img_src']; list($type, $data) = explode(';', $data); list(, $data) = explode(',', $data); $data = base64_decode($data); $folder_name = 'error_feedback/'; $pathname = $GLOBALS['PATH_root'].$folder_name; $filenameDB = 'error_'.time().'.png'; $images = new Images(); $images->checkStructure($pathname); $filename = $pathname.$filenameDB; // путь к файлу в который нужно писать file_put_contents($filename, $data); $err['image'] = '/'.$folder_name.$filenameDB; // записываем результат в файл } // if(isset($_FILES['file'])){ // // Проверяем загружен ли файл // if(is_uploaded_file($_FILES['file']['tmp_name'])){ // $folder_name = 'error_feedback/'; // $pathname = $GLOBALS['PATH_root'].$folder_name; // $images = new Images(); // $images->checkStructure($pathname); // if(move_uploaded_file($_FILES['file']['tmp_name'], $pathname.$_FILES['file']['name'])) { // $arr['file'] = '/'.$folder_name.$_FILES['file']['name']; // } // } // }
require_once $GLOBALS['PATH_block'] . 't_fnc.php'; // для ф-ции проверки формы list($err, $errm) = News_form_validate(); //Удаление фото при нажатии на корзину if (isset($_POST['removed_images'])) { foreach ($_POST['removed_images'] as $del_image) { unlink($GLOBALS['PATH_global_root'] . $del_image); } } //Добавление фото if (isset($_POST['images'])) { foreach ($_POST['images'] as &$image) { if (strpos($image, '/temp/') !== false) { $Images = new Images(); $path = $GLOBALS['PATH_news_img'] . $_POST['id_news'] . '/'; $Images->checkStructure($path); $file = pathinfo($GLOBALS['PATH_global_root'] . $image); if (preg_match('/[А-Яа-яЁё]/u', $image)) { $file['filename'] = G::StrToTrans($file['filename']); $file['basename'] = $file['filename'] . '.' . $file['extension']; } $new_file = $path . $file['basename']; rename($GLOBALS['PATH_global_root'] . $image, $new_file); $image = str_replace($GLOBALS['PATH_global_root'], '/', $new_file); } } } if (!$err) { if ($News->UpdateNews($_POST)) { $News->UpdatePhoto($id, $_POST['images']); $tpl->Assign('msg', 'Новость обновлена.');
public function parseUrl($url) { $Products = new Products(); $Specification = new Specification(); $Images = new Images(); $product = array(); $html = file_get_html($url); if (!$html) { return false; } // Название товара $product['name'] = $html->find('[itemprop="name"]', 0)->plaintext; if (!$product['name']) { return false; } // if($Products->SetFieldsByRewrite(G::StrToTrans($product['name']))){ // return false; // } // Описание товара $product['descr'] = $html->find('[itemprop="description"]', 0)->plaintext; // Указываем базовую активность товара $product['active'] = 1; // Получаем цену товара $product['price_opt_otpusk'] = $product['price_mopt_otpusk'] = $html->find('[itemprop="price"]', 0)->innertext; // Находим характеристики товара foreach ($html->find('.stats tr') as $element) { $caption = trim($element->find('.name span', 0)->innertext); if ($caption == 'Артикул') { $sup_comment = trim($element->children(1)->plaintext); } elseif ($caption !== '' && !in_array($caption, array('Доставка', 'Самовывоз', 'Гарантия'))) { $value = trim($element->children(1)->plaintext); $spec = $Specification->SpecExistsByCaption($caption); $product['specs'][] = array('id_spec' => $spec ? $spec['id'] : $Specification->Add(array('caption' => $caption)), 'value' => $value); } } // Выбираем изображения максимального размера foreach ($html->find('#photo #elementTableImg img') as $element) { $filename = 'http://zona220.com' . str_replace('/500_500_1/', '/', str_replace('/resize_cache/', '/', $element->src)); $img_info = array_merge(getimagesize($filename), pathinfo($filename)); $path = $GLOBALS['PATH_product_img'] . 'original/' . date('Y') . '/' . date('m') . '/' . date('d') . '/'; $Images->checkStructure($path); copy($filename, $path . $img_info['basename']); $product['images'][] = str_replace($GLOBALS['PATH_global_root'], '/', $path . $img_info['basename']); $product['images_visible'][] = 1; } $html->clear(); unset($html); // Добавляем новый товар в БД if ($id_product = $Products->AddProduct($product)) { // Добавляем характеристики новому товару if (!empty($product['specs'])) { foreach ($product['specs'] as $specification) { $Specification->AddSpecToProd($specification, $id_product); } } // Формирем массив записи ассортимента $assort = array('id_assortiment' => false, 'id_supplier' => 25392, 'id_product' => $id_product, 'price_opt_otpusk' => $product['price_opt_otpusk'], 'price_mopt_otpusk' => $product['price_mopt_otpusk'], 'active' => 0, 'inusd' => 0, 'sup_comment' => $sup_comment); // $assort = array('id_assortiment' => false, 'id_supplier' => 23029, 'id_product' => $id_product, 'price_opt_otpusk' => $product['price_opt_otpusk'], 'price_mopt_otpusk' => $product['price_mopt_otpusk'], 'active' => 0, 'inusd' => 0); // Добавляем зпись в ассортимент $Products->AddToAssortWithAdm($assort); // Получаем артикул нового товара $article = $Products->GetArtByID($id_product); // Переименовываем фото товара $to_resize = $images_arr = array(); if (isset($product['images'])) { foreach ($product['images'] as $k => $image) { $to_resize[] = $newname = $article['art'] . ($k == 0 ? '' : '-' . $k) . '.jpg'; $file = pathinfo(str_replace('/' . str_replace($GLOBALS['PATH_global_root'], '', $GLOBALS['PATH_product_img']), '', $image)); $path = $GLOBALS['PATH_product_img'] . trim($file['dirname']) . '/'; $images_arr[] = str_replace($file['basename'], $newname, $image); rename($path . $file['basename'], $path . $newname); } } //Проверяем ширину и высоту загруженных изображений, и если какой-либо из показателей выше 1000px, уменяьшаем размер foreach ($images_arr as $filename) { $file = $GLOBALS['PATH_product_img'] . str_replace('/' . str_replace($GLOBALS['PATH_global_root'], '', $GLOBALS['PATH_product_img']), '', $filename); $size = getimagesize($file); // $size = getimagesize($path.$filename); //Получаем ширину, высоту, тип картинки $width = $size[0]; $height = $size[1]; if ($size[0] > 1000 || $size[1] > 1000) { $ratio = $size[0] / $size[1]; //коэфициент соотношения сторон //Определяем размеры нового изображения if (max($size[0], $size[1]) == $size[0]) { $width = 1000; $height = 1000 / $ratio; } elseif (max($size[0], $size[1]) == $size[1]) { $width = 1000 * $ratio; $height = 1000; } } $res = imagecreatetruecolor($width, $height); imagefill($res, 0, 0, imagecolorallocate($res, 255, 255, 255)); $src = $size['mime'] == 'image/jpeg' ? imagecreatefromjpeg($file) : imagecreatefrompng($file); imagecopyresampled($res, $src, 0, 0, 0, 0, $width, $height, $size[0], $size[1]); $stamp = imagecreatefrompng($GLOBALS['PATH_global_root'] . 'images/watermark.png'); imagecopyresampled($res, $stamp, 10, 10, 0, 0, imagesx($stamp), imagesy($stamp), imagesx($stamp), imagesy($stamp)); imagejpeg($res, $file); } $Images->resize(false, $to_resize); // Привязываем новые фото к товару в БД $Products->UpdatePhoto($id_product, $images_arr, $product['images_visible']); } return $id_product; }
public function UpdatePost($arr) { if (strpos($arr['thumb'], '/temp/')) { $images = new Images(); $path = $GLOBALS['PATH_post_img'] . $arr['id'] . '/'; $images->checkStructure($path); if (preg_match('/[А-Яа-яЁё]/u', $arr['thumb'])) { $file = pathinfo($GLOBALS['PATH_global_root'] . $arr['thumb']); $new_file = $file['dirname'] . '/' . G::StrToTrans($file['filename']) . '.' . $file['extension']; rename($GLOBALS['PATH_global_root'] . $arr['thumb'], $new_file); $arr['thumb'] = str_replace($GLOBALS['PATH_global_root'], '', $new_file); } $new_path = str_replace('temp/', trim($arr['id']) . '/thumb_', $arr['thumb']); rename($GLOBALS['PATH_global_root'] . $arr['thumb'], $GLOBALS['PATH_global_root'] . $new_path); $arr['thumb'] = $new_path; } $f['title'] = trim($arr['title']); $f['thumbnail'] = trim($arr['thumb']); list($d, $m, $y) = explode(".", trim($arr['date'])); $f['date'] = mktime(0, 0, 0, $m, $d, $y); $f['content_preview'] = trim($arr['content_preview']); $f['content'] = trim($arr['content']); $f['translit'] = G::StrToTrans($arr['title']); $f['sid'] = $arr['sid']; $f['indexation'] = isset($arr['indexation']) && $arr['indexation'] == "on" ? 1 : 0; $f['visible'] = isset($arr['visible']) && $arr['visible'] == "on" ? 0 : 1; $f['date_update'] = Date('Y-m-d H:i:s'); $f['id_user'] = $_SESSION['member'][id_user]; $this->db->StartTrans(); if (!($sql = $this->db->Update(_DB_PREFIX_ . "post", $f, "id = " . $arr['id']))) { $this->db->FailTrans(); return false; } $this->db->CompleteTrans(); return true; }