$rec_array = array(1 => 'best', 2 => 'new', 3 => 'hot'); $rec_type = !empty($_REQUEST['rec_type']) ? intval($_REQUEST['rec_type']) : '1'; $cat_id = !empty($_REQUEST['cid']) ? intval($_REQUEST['cid']) : '0'; include_once 'include/cls_json.php'; $json = new JSON(); $result = array('error' => 0, 'content' => '', 'type' => $rec_type, 'cat_id' => $cat_id); $children = get_children($cat_id); $smarty->assign($rec_array[$rec_type] . '_goods', get_category_recommend_goods($rec_array[$rec_type], $children)); // 推荐商品 $smarty->assign('cat_rec_sign', 1); $result['content'] = $smarty->fetch('library/recommend_' . $rec_array[$rec_type] . '.lbi'); die($json->encode($result)); } elseif ($act == 'select_shop') { $shop_id = intval($_REQUEST['id']); //check shop if (!check_shop($shop_id)) { $_SESSION['default_shop'] = 0; show_message('取货门店无效', '重新选择', 'index.php'); } if ($shop_id) { if ($_SESSION['user_id'] > 0) { //update user data $sql = "UPDATE " . $ecs->table('users') . " SET default_shop = '{$shop_id}' WHERE user_id = '{$_SESSION['user_id']}'"; $db->query($sql); } $_SESSION['default_shop'] = $shop_id; } ecs_header("Location: index.php\n"); exit; } /*------------------------------------------------------ */
function idex_EAN($get_EAN) { include 'configuration.php'; $url = "http://www.idealo.de/preisvergleich/MainSearchProductCategory.html?q=" . $get_EAN; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'spider'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $get_choice = curl_exec($ch); curl_close($ch); $regex = '~<a\\s+class="b\\s+fs13"\\s+href="(.*?)">~'; preg_match($regex, $get_choice, $url_choice); unset($get_choice); if (count($url_choice['1']) == 1) { // Check if search result is there or not. $url = "http://www.idealo.de" . $url_choice['1']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'spider'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $get_merchants = curl_exec($ch); curl_close($ch); $regex = '~<option\\svalue="\\s+(.*?)\\s+">nur sofort lieferbare</option>~'; preg_match($regex, $get_merchants, $filter_merchants); unset($get_merchants); $url = "http://www.idealo.de/" . $filter_merchants['1']; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, 'spider'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $filtered_list = curl_exec($ch); curl_close($ch); // $regex = '~<form\saction="(.*?)"\sstyle="display:\sinline;">\s+Sortierung: ~'; // preg_match($regex, $filtered_list, $sort_url); // unset($regex); // $url = "http://www.idealo.de/".$sort_url['1']; $ch = curl_init(); $variables = "param.offersofproduct.sortKey=btpb"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $variables); curl_setopt($ch, CURLOPT_USERAGENT, 'spider'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $sort_list = curl_exec($ch); curl_close($ch); $list_regex = '<td\\s+style="vertical-align:top;">'; preg_match_all($list_regex, $sort_list, $islist); if (!empty($islist[0])) { $ch = curl_init(); $variables = "param.alternativeView=true"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $variables); curl_setopt($ch, CURLOPT_USERAGENT, 'spider'); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); $sort_list = curl_exec($ch); curl_close($ch); } $regex = '~\\<div\\sid="opp_.*?href="(.*?)\\<div\\sstyle="vertical-align:\\stext-bottom;"\\>.*?(\\<span\\sclass="nobr"\\>(.*?)\\</span\\>|\\<div\\sclass="ebayratingpercent"\\sstyle="margin-top:3px;\\stext-align:center;"\\>\\s+(.*?)\\s+\\</div\\>)~s'; preg_match_all($regex, $sort_list, $shop_info); for ($c = 0; $c < count($shop_info[1]); $c++) { preg_match_all('~versandkostenfrei~', $shop_info[1][$c], $check_final); preg_match_all('~price=(.*?)&~', $shop_info[1][$c], $price); preg_match_all('~/pics/rating/orange\\.gif~', $shop_info[2][$c], $full); preg_match_all('~/pics/rating/halb\\.gif~', $shop_info[2][$c], $half); preg_match_all('~/pics/rating/amazon/full.png~', $shop_info[2][$c], $amazon_full); preg_match_all('~/pics/rating/amazon/half.png~', $shop_info[2][$c], $amazon_half); $shop_name = check_shop($shop_info[2][$c]); // Ebay,Slef or Other if (!empty($check_final[0][0])) { $LTP = $price[1][0]; // $LTP = str_replace("." , '', $LTP); $LTP = str_replace(",", '.', $LTP); } else { preg_match_all('~Gesamtpreis:\\s(.*?)\\s€~s', $shop_info[1][$c], $final_ltp); $LTP = $final_ltp[1][0]; $LTP = str_replace(".", '', $LTP); $LTP = str_replace(",", '.', $LTP); } // Lowest Total Price. if (count($amazon_full[0]) > 0 || count($amazon_half[0]) > 0) { $hal = 0.5 * count($amazon_half[0]); $rating = count($amazon_full[0]) + $hal; // Rating } if (count($full[0]) > 0 || count($half[0]) > 0) { $hal = 0.5 * count($half[0]); $rating = count($full[0]) + $hal; // Rating } if ($shop_name == 'ebay') { preg_match('~\\<div\\sclass="ebayratingpercent"\\sstyle="margin-top:3px;\\stext-align:center;">\\s+(.*?)%~', $shop_info[2][$c], $ebay_rating); // Rating $rating_percent = $ebay_rating[1]; $rating_percent = str_replace(",", '.', $rating_percent); //Rating } $shop_allowed = shop_allow($shop_name); if ($shop_allowed != 1) { continue; } if ($rating < $min_rating && $rating != NULL) { continue; } if ($rating_percent < $min_percent_rating && $rating_percent != NULL) { continue; } if ($shop_name == 'self') { $sql = mysql_query("SELECT * FROM `" . $table_name . "` WHERE `EAN` = '" . $get_EAN . "'"); $get_CP = mysql_fetch_array($sql); $insert = mysql_query("INSERT INTO self (`Artikelnummer`, `EAN`, `Produktname`) VALUES ('" . $get_CP['Artikelnummer'] . "', '" . $get_CP['EAN'] . "','" . mysql_real_escape_string($get_CP['Produktname']) . "')") or die(mysql_error()); continue; } break; } } else { $sql = mysql_query("SELECT * FROM `" . $table_name . "` WHERE `EAN` = '" . $get_EAN . "'"); $get_noresult = mysql_fetch_array($sql); $insert = mysql_query("INSERT INTO nosearch (`Artikelnummer`, `EAN`, `Produktname`) VALUES ('" . $get_noresult['Artikelnummer'] . "', '" . $get_noresult['EAN'] . "','" . mysql_real_escape_string($get_noresult['Produktname']) . "')") or die(mysql_error()); } if (!empty($LTP)) { return $LTP; } else { return '0'; } }