<?php 


/** 
***************************************************
*欢迎使用免费版SiteTeam企业建站软件！
*这是一个专业为搜索引擎营销而设计的，极稳定、极易维护的建站软件！
*官方客服：help@php.net.cn
*官方下载网址：http://www.SiteTeam.cn 
***************************************************
**/




if(!defined('IN_SITETEAM')) { exit('Access Denied'); } if (!empty($_POST['dosubmit'])) { $key = $_COOKIE['key']; if (empty($key)) { go_url("admin.php?action=product&operation=list&category={$category}", "缺少category参数！"); } if (!empty($_FILES['ptitle']['name'])) { if (!in_array($_FILES['ptitle']['type'], array("image/pjpeg", "image/gif", "image/jpeg", "image/png", "image/jpg"))) { go_url("admin.php?action=product&operation=edit&category={$category}&key={$key}", "你所上传的图片格式不正确！请按说明上传"); } } $year_dir = date("Y", $key); $month_dir = date("md", $key); $attach_year_dir = "{$user_product_upload_dir}/" . date("Y", $key); $attach_month_dir = "{$attach_year_dir}/" . date("md", $key); if(!file_exists($attach_year_dir)) mkdir($attach_year_dir); if(!file_exists($attach_month_dir)) mkdir($attach_month_dir); $product_info_file = $user_product_dir . "/{$category}/{$key}.txt"; $indexdata = $savedata = $_POST['data']; $savedata['content'] = stripslashes($savedata['content']); if ($auto_image == 1) { $remote_file = array(); if (preg_match_all('/src=[\'|"]+([^\'"]+\.[jpg|gif|png|jpeg]+)[\'|"]+/is', $savedata['content'], $temp)) { $temp = $temp[1]; if (is_array($temp) && count($temp)) { foreach ($temp as $v) { if (preg_match('/^http:\/\//is', $v)) { if (!preg_match('/^http:\/\/' . preg_quote($site_url) . '/is', $v)) { $remote_file[md5($v)] = $v; } } } } } if (is_array($remote_file) && count($remote_file)) { $user_attachments_dir = "{$user_upload_dir}/public"; if(!file_exists("{$user_attachments_dir}")) mkdir("{$user_attachments_dir}"); if(!file_exists("{$user_attachments_dir}/{$year_dir}")) mkdir("{$user_attachments_dir}/{$year_dir}"); if(!file_exists("{$user_attachments_dir}/{$year_dir}/{$month_dir}")) mkdir("{$user_attachments_dir}/{$year_dir}/{$month_dir}"); } if (is_array($remote_file) && count($remote_file)) { foreach ($remote_file as $k => $v) { $fileinfo = pathinfo($v); $filename = "{$user_attachments_dir}/{$year_dir}/{$month_dir}/{$k}.{$fileinfo['extension']}"; if ($image_file = file_get_contents($v)) { $fp = fopen($filename, "w"); fwrite($fp, $image_file); fclose($fp); $filename = str_replace(SITE_ROOT . '/', '', $filename); $savedata['content'] = str_replace($v, $filename, $savedata['content']); echo "\n<br />已经下载远端文件并下载之本地：{$v}"; } } } } if (!empty($_FILES['ptitle']['name'])) { $fileinfo = pathinfo($_FILES['ptitle']['name']); $src_filename = "{$user_product_upload_dir}/{$year_dir}/{$month_dir}/src_{$key}.{$fileinfo['extension']}"; $filename = "{$user_product_upload_dir}/{$year_dir}/{$month_dir}/{$key}.{$fileinfo['extension']}"; if (file_exists($src_filename)) unlink($src_filename); if (file_exists($filename)) unlink($filename); if (!empty($savedata['ptitle'])) { if (file_exists($savedata['ptitle'])) { @unlink($savedata['ptitle']); $fileinfo = dirname($savedata['ptitle']) . '/src_' . basename($savedata['ptitle']); if (file_exists($fileinfo)) { @unlink($fileinfo); } } } if (move_uploaded_file($_FILES['ptitle']['tmp_name'],$filename)) { copy($filename, $src_filename); img_resize($filename, 118, 70); $savedata['ptitle'] = str_replace(SITE_ROOT . '/', '', $filename); } } for($i = 1; $i <= 8 ; $i++) { if (!empty($_FILES["product_pic_{$i}"]['name'])) { if (!in_array($_FILES["product_pic_{$i}"]['type'], array("image/pjpeg", "image/gif", "image/jpeg", "image/png", "image/jpg", "image/jp2"))) { continue; } $fileinfo = pathinfo($_FILES["product_pic_{$i}"]['name']); $filename = "{$user_product_upload_dir}/{$year_dir}/{$month_dir}/{$key}_pic_{$i}.{$fileinfo['extension']}"; if (file_exists($filename)) unlink($filename); if (file_exists($savedata['product_pic']["pic_{$i}"])) unlink($savedata['product_pic']["pic_{$i}"]); if (move_uploaded_file($_FILES["product_pic_{$i}"]['tmp_name'],$filename)) { $imginfo = getimagesize($filename); $new_width = 1024; if ($imginfo[0] > $new_width) @img_resize($filename, $new_width, ($new_width * $imginfo[1] / $imginfo[0])); $savedata['product_pic']["pic_{$i}"] = str_replace(SITE_ROOT . '/', '', $filename); if (empty($savedata['ptitle'])) { if (copy($savedata['product_pic']["pic_{$i}"], "{$user_product_upload_dir}/{$year_dir}/{$month_dir}/{$key}.{$fileinfo['extension']}")) { copy($savedata['product_pic']["pic_{$i}"], "{$user_product_upload_dir}/{$year_dir}/{$month_dir}/src_{$key}.{$fileinfo['extension']}"); $savedata['ptitle'] = str_replace(SITE_ROOT . '/', '', "{$user_product_upload_dir}/{$year_dir}/{$month_dir}/{$key}.{$fileinfo['extension']}"); img_resize($savedata['ptitle'], 118, 70); } } } } } save_array_file($savedata, $product_info_file); $db = new txtSQL('./data/siteteam'); if ($db->connect('root', 'siteteam')){ $row = $db->execute('select', array('db' => dbname($site_id), 'select' => array('key'), 'table' => 'sm_product', 'where' => array("key = {$key}"), 'limit' => array(0))); $data = array(); if (count($row)) { $data['category'] = $category; $data['name'] = $savedata['name']; $data['ptitle'] = $savedata['ptitle']; $data['pname'] = $savedata['pname']; $data['pass'] = $savedata['pass']; $data['status'] = $savedata['status']; $db->update(array('db' => dbname($site_id), 'table' => 'sm_product', 'values' => $data, 'where' => array("key = {$key}"), 'limit' => array(0))); } else { $data['key'] = $key; $data['category'] = $category; $data['name'] = $savedata['name']; $data['ptitle'] = $savedata['ptitle']; $data['pname'] = $savedata['pname']; $data['pass'] = $savedata['pass']; $data['status'] = $savedata['status']; $db->insert(array('db' => dbname($site_id), 'table' => 'sm_product', 'values' => $data)); } $db->disconnect(); } if (file_exists($user_product_dir . "/{$category}.index.txt")) { update_product_index($category); unlink($user_product_dir . "/{$category}.index.txt"); } go_url("admin.php?action=product&operation=list&category={$category}" . (!empty($page) ? "&page={$page}" : "")); } else { $default_structure_file = SITE_ROOT . "/data/default.product.structure.txt"; $default_structure = read_array_file($default_structure_file); $diy_structure_file = $user_data_dir . "/product.structure.txt"; if (file_exists($diy_structure_file)) { $diy_structure = read_array_file($diy_structure_file); $forum_structure = array_merge($default_structure, $diy_structure); } else { $forum_structure = $default_structure; } if (!empty($key) && file_exists($user_product_dir . "/{$category}/{$key}.txt")) { $product_info_file = $user_product_dir . "/{$category}/{$key}.txt"; $product_info = read_array_file($product_info_file); if (is_array($product_info) && count($product_info) > 0) foreach ($product_info as $k => $v) { if (array_key_exists($k, $forum_structure)) $forum_structure[$k]['value'] = $v; } } if (empty($key)) { $key = time(); } ob_start(); setcookie("key", $key); ob_end_flush(); foreach ($forum_structure as $k => $v) { $form[$v['formtype']][$k] = $forum_structure[$k]; } extract($form); if (isset($content['content']['name'])) { $content['content']['name'] .= '<a style="cursor:hand" onclick="create_editor(\'content\');">[开]</a><a style="cursor:hand" onclick="close_editor();">[关]</a><a target="_blank" href="http://ps.net.cn">[图]</a>'; } include "admin/tpl/product_edit.tpl.php"; } ?>