private function miao_collect_insert($item, $cate_id) { $items_mod = D('items'); $items_tags_mod = D('items_tags'); $items_tags_item_mod = D('items_tags_item'); //需要判断商品是否已经存在 $isset = $items_mod->where("item_key='" . $item['item_key'] . "'")->getField('id'); if ($isset) { return; } $add_time = time(); if (strpos($item['pic_url'], 'taobao') !== false) { $item['img'] = $item['pic_url'] . '_210x1000.jpg'; $item['simg'] = $item['pic_url'] . '_64x64.jpg'; //$item['bimg'] = $item['pic_url'].'_460x460.jpg'; $item['bimg'] = $item['pic_url']; } else { $item['img'] = str_replace('.jpg', '_210x1000.jpg', $item['pic_url']); $item['simg'] = str_replace('.jpg', '_60x60.jpg', $item['pic_url']); //$item['bimg'] = str_replace('.jpg', '_460x460.jpg', $item['pic_url']); $item['bimg'] = $item['pic_url']; } if ($item['popular'] == 0) { $item['popular'] = 1; } $item_id = $items_mod->add(array('title' => ReplaceKeywords(strip_tags($item['title'])), 'cid' => $cate_id, 'sid' => $item['sid'], 'item_key' => $item['item_key'], 'img' => $item['img'], 'simg' => $item['simg'], 'bimg' => $item['bimg'], 'price' => $item['price'], 'url' => $item['click_url'], 'likes' => $item['popular'], 'seller_name' => $item['seller_name'], 'cash_back_rate' => $item['cashback_scope'], 'haves' => 1, 'add_time' => $add_time)); }
function doComment() { $this->check_login(); //解析URL $parse_url = parse_url($_POST['type']); $parse_str = parse_str($parse_url['query'], $option); $type = $option['m'] . ',' . $option['a']; $result = trim($type, ','); //组装数据 $replace = str_replace("\n", " ", $_POST['info']); $data['info'] = htmlspecialchars(ReplaceKeywords(trim(strip_tags($replace)))); //评论替换 $data['pid'] = $_POST['pid']; //$data['type']=$result; $data['type'] = "item,index"; $data['uid'] = $_COOKIE['user']['id']; $data['uname'] = $_COOKIE['user']['name']; $user_rel = $this->user_mod->field('id,name')->where("id='{$data['uid']}'")->find(); $user_rel['face'] = getUserFace($data['uid']); $data['status'] = 1; $data['add_time'] = time(); if (M('UserComments')->add($data)) { $arr = array('id' => $data['pid'], 'comments' => $this->user_comments_mod->where('pid=' . $data['pid'] . ' and type="item,index"')->count()); $this->items_mod->save($arr); $this->ajaxReturn($user_rel); } else { echo 0; } }
function comments() { import("ORG.Util.Page"); $user_comments_mod = D('user_comments'); $act = $_REQUEST['act']; $type = $_REQUEST['type']; $pid = empty($_REQUEST['pid']) ? 0 : intval($_REQUEST['pid']); if ($act == 'add') { if (empty($_COOKIE['user']['id'])) { exit; } $data = $user_comments_mod->create(); $replace = str_replace("\n", " ", $data['info']); $data['info'] = htmlspecialchars(ReplaceKeywords($replace)); $data['add_time'] = time(); $data['uid'] = $_COOKIE['user']['id']; $data['uname'] = $_COOKIE['user']['name']; $user_comments_mod->add($data); if ($data['type'] == 'item,index') { $arr = array('id' => $data['pid'], 'comments' => $this->user_comments_mod->where('pid=' . $data['pid'] . ' and type="item,index"')->count()); $this->items_mod->save($arr); } return; } $where = "type='" . $_REQUEST['type'] . "' and pid={$pid} and status=1"; $count = $user_comments_mod->where($where)->count(); $p = new Page($count, 8); $list = $user_comments_mod->where($where)->relation('user')->where($where)->order("id desc")->limit($p->firstRow . ',' . $p->listRows)->select(); $this->assign('comments', array('list' => $list, 'page' => $p->show_1(), 'count' => $count, 'type' => $type)); if ($this->isAjax()) { $this->ajaxReturn(array('list' => $this->fetch('comments_list'), 'count' => $count)); } }
private function add($data) { $items_site_mod = D('items_site'); $items_tags_mod = D('items_tags'); $items_tags_item_mod = D('items_tags_item'); $items_mod = $this->items_mod; $data['title'] = ReplaceKeywords($data['title']); //替换屏蔽的关键词 $data['add_time'] = time(); $data['sid'] = $items_site_mod->where("alias='miao'")->getField('id'); $data['cid'] = 0; $new_item_id = $items_mod->add($data); if ($new_item_id) { $tags = $items_tags_mod->get_tags_by_title($data['title']); if ($tags) { $tags_arr = array_unique($tags); foreach ($tags_arr as $tag) { $isset_id = $items_tags_mod->where("name='" . $tag . "'")->getField('id'); if ($isset_id) { $items_tags_mod->where('id=' . $isset_id)->setInc('item_nums'); $items_tags_item_mod->add(array('item_id' => $new_item_id, 'tag_id' => $isset_id)); } else { $tag_id = $items_tags_mod->add(array('name' => $tag)); $items_tags_item_mod->add(array('item_id' => $new_item_id, 'tag_id' => $tag_id)); } } } } return $new_item_id; }
/** * 采集指定商品的评论 */ private function collect_one_goods($iid, $item_id, $cmt_num, $users) { import("ORG.Net.Http"); $seller = $this->get_seller_id($iid); if (!$seller['id']) { return false; } $item_mod = D('items'); $item_comment_mod = D('user_comments'); if ($seller['type'] == 'tmall') { $rate_tmall_api = 'http://rate.tmall.com/list_detail_rate.htm?itemId=' . $iid . '&spuId=&sellerId=' . $seller_id . '&order=0&forShop=1&append=0¤tPage=1'; $source = Http::fsockopenDownload($rate_tmall_api); $source = rtrim(ltrim(trim($source), '('), ')'); $source = iconv('GBK', 'UTF-8//IGNORE', $source); $source = str_replace('"rateDetail":', '', $source); $rate_resp = json_decode($source, true); $rate_list = $rate_resp['rateList']; $is_cmt_taobao = $item_mod->where(array('id' => $item_id))->getField('is_collect_comments'); for ($i = 0; $i < $cmt_num; $i++) { $user_rand = array_rand($users); $time = strtotime($rate_list[$i]['rateDate']); if ($is_cmt_taobao == 1) { return false; } else { if (trim($rate_list[$i]['content']) != '') { $item_comment_rel = $item_comment_mod->add(array('pid' => $item_id, 'uid' => $users[$user_rand]['id'], 'uname' => $users[$user_rand]['name'], 'info' => ReplaceKeywords($rate_list[$i]['content']), 'type' => 'item,index', 'add_time' => $time)); if ($item_comment_rel) { $item_mod->where("id='{$item_id}'")->setInc('comments', 1); } } } } //更新item表的 is_collect_comments为1同时采集评论 $item_mod->where(array('id' => $item_id))->save(array('is_collect_comments' => 1)); } else { $rate_taobao_api = 'http://rate.taobao.com/feedRateList.htm?userNumId=' . $seller['id'] . '&auctionNumId=' . $iid . '¤tPageNum=1'; $source = Http::fsockopenDownload($rate_taobao_api); $source = rtrim(ltrim(trim($source), '('), ')'); $source = iconv('GBK', 'UTF-8//IGNORE', $source); $rate_resp = json_decode($source, true); $rate_list = $rate_resp['comments']; $is_cmt_taobao = $item_mod->where(array('id' => $item_id))->getField('is_collect_comments'); for ($i = 0; $i < $cmt_num; $i++) { $user_rand = array_rand($users); $date = explode('.', $rate_list[$i]['date']); $time = mktime(0, 0, 0, $date[1], $date[2], $date[0]); if ($is_cmt_taobao == 1) { return false; } else { if (trim($rate_list[$i]['content']) != '') { $item_comment_rel = $item_comment_mod->add(array('pid' => $item_id, 'uid' => $users[$user_rand]['id'], 'uname' => $users[$user_rand]['name'], 'info' => ReplaceKeywords($rate_list[$i]['content']), 'type' => 'item,index', 'add_time' => $time)); if ($item_comment_rel) { $item_mod->where("id='{$item_id}'")->setInc('comments', 1); } } } } //更新item表的 is_collect_comments为1同时采集评论 $item_mod->where(array('id' => $item_id))->save(array('is_collect_comments' => 1)); echo '正在采集,请稍后...'; } }
if (($pos = mb_strpos(strtolower($res['text']), strtolower(str_replace('*', '', $srch)))) !== false) { break; } } if (!isset($pos) || $pos < 100) { $pos = 100; } $name = $res['name']; $text = functions::checkout(mb_substr($res['text'], $pos - 100, 400), 1); if ($search_t) { foreach ($array as $val) { $name = ReplaceKeywords($val, $name); } } else { foreach ($array as $val) { $text = ReplaceKeywords($val, $text); } } echo '<b><a href="index.php?id=' . $res['id'] . '">' . $name . '</a></b><br />' . $text . ' <div class="sub"><span class="gray">' . $lng_lib['added'] . ':</span> ' . $res['avtor'] . ' <span class="gray">(' . functions::display_date($res['time']) . ')</span><br />' . '<span class="gray">' . $lng_lib['reads'] . ':</span> ' . $res['count'] . '</div></div>'; ++$i; } } else { echo '<div class="rmenu"><p>' . $lng['search_results_empty'] . '</p></div>'; } echo '<div class="phdr">' . $lng['total'] . ': ' . $total . '</div>'; if ($total > $kmess) { echo '<div class="topmenu">' . functions::display_pagination('search.php?' . ($search_t ? 't=1&' : '') . 'search=' . urlencode($search) . '&', $start, $total, $kmess) . '</div>' . '<p><form action="search.php?' . ($search_t ? 't=1&' : '') . 'search=' . urlencode($search) . '" method="post">' . '<input type="text" name="page" size="2"/>' . '<input type="submit" value="' . $lng['to_page'] . ' >>"/>' . '</form></p>'; } } else { if ($error) { echo functions::display_error($error);
function ReplaceKeyPENIS($Matches) { $FixedMatches[] = $Matches[0]; $FixedMatches[] = $Matches[1]; $FixedMatches[] = $Matches[3]; $FixedMatches[] = $Matches[4]; $FixedMatches[] = $Matches[5]; return $Matches[2] . "[" . ReplaceKeywords($FixedMatches) . "]"; }