/', $keyword)) { $keyword = ''; } if (empty($keyword)) { oops('000'); exit(); } # 手持裝置導SmartWeb版型 if (isMobile() && !in_array($_COOKIE['website_viewmode'], ['normal', 'summary'])) { $headerUrl = (strlen($keyword) > 0) ? m_url() . '/search/' . $keyword : m_url() . '/index'; header('Location:' . $headerUrl); exit; } # 頁碼處理 $page = ((int)$_GET['p'] < 1) ? 1 : $_GET['p']; $itemPerPage = ($list_style == 'summary') ? 60 : 12; $itemStart = ($page - 1) * $itemPerPage; $REWRITE = 'NO'; #去除 雙引號 $keywordCharsDecode = str_replace('"', '', htmlspecialchars_decode($keyword, ENT_QUOTES | ENT_SUBSTITUTE)); #去除 加號&&逗號&&空格 $keywordList = array_map(function ($str) { return sprintf('"%s"', $str); }, preg_split('/(\+|\s|\,)+/', $keywordCharsDecode)); #搜尋結果 (solor) if (!empty($keywordList)) { $_keyword = (count($keywordList) > 1) ? implode(' ', $keywordList) : array_shift($keywordList) ; $search_keyword = urlencode('+channel:news +(title:(' . $_keyword . ') desc:(' . $_keyword . '))'); $limit = 500; $solrHost = 'solrsegc.mypchome.com.tw'; // $solrHost = 'solrse.mypchome.com.tw'; // $API = 'http://solrse.mypchome.com.tw/solr/localsearch/select?q='; $API = 'http://' . $solrHost . '/solr/localsearch/select?q='; $new_API = $API . $search_keyword . '&wt=json&indent=true&start=0&sort=update%20desc&rows=' . $limit; if (!empty($_SERVER['HTTP_USER_AGENT']) && !preg_match('/bot|spider|crawler|search/i', $_SERVER['HTTP_USER_AGENT'])) { $newsSearchList = json_decode(curl_get_content($new_API), true); } $newsList = (isset($newsSearchList['response']['docs'])) ? $newsSearchList['response']['docs'] : []; #找不到物件 回到搜尋頁 if (empty($newsList)) { header('HTTP/1.0 404 Not Found'); echo ""; } foreach ($newsList as $key => $val) { $incfile = ''; $getMediaInfo = []; if (preg_match("/https?:\/\/news\.pchome\.com\.tw\/(\w+)\/(\w+)\/(\d+)\/index-(\d+)\.html/", $val['url_link'], $match)) { //新聞 $incfile = $NEWS_DATA_DIR . $match[1] . '/' . $match[2] . '/' . $match[3] . '/' . $match[4] . '.inc'; $getMediaInfo = getMediaInfo($match[2]); } elseif (preg_match("/https?:\/\/news\.pchome\.com\.tw\/magazine\/report\/(\w+)\/(\w+)\/(\d+)\/(\d+).htm/", $val['url_link'], $match)) { //雜誌 $incfile = $MAG_DATA_DIR . $match[1] . '/' . $match[2] . '/' . $match[3] . '/' . $match[4] . '.inc'; } $unsetFlag = true; if (!empty($incfile) && is_file($incfile)) { $newsItem = LoadRequireFile($incfile); if (!empty($newsItem)) { $unsetFlag = false; $newsList[$key]['keyword'] = isset($newsItem['keyword']) ? $newsItem['keyword'] : ''; # 取得該篇新聞的關鍵字 $newsList[$key]['pubDate'] = isset($newsItem['pubDate']) ? date('Y-m-d H:i:s', strtotime($newsItem['pubDate'])) : date('Y-m-d H:i:s'); #取得發佈日期 $newsList[$key]['media'] = isset($getMediaInfo['media_cname']) ? $getMediaInfo['media_cname'] : ''; #媒體 $newsList[$key]['desc'] = isset($newsItem['summary']) ? $newsItem['summary'] : ''; #新聞描述 } } if ($unsetFlag === true) { unset($newsList[$key]); } } $newsList = assoc_unique(array_values($newsList), 'title'); $totalNews = count($newsList); $newsList = array_map('make_newsList', array_slice($newsList, $itemStart, $itemPerPage)); #日期整理,時間越大越前面 $pubdate = array_column($newsList, 'pubdate'); array_multisort($pubdate, SORT_DESC, $newsList); } # 標題 # 頁面資訊 $html_title = '新聞搜尋 - PChome Online 新聞'; # 右欄空氣品質 $rightAir = rightAir(); # 右欄氣象資訊 $rightWeather = right_get_weather(); # 右欄樂透 $rightLottery = rightLottery(); # 右欄星座 $rightConstellation = rightConstellation(); # 右欗媒體名單 $collMediaItem = ($cat_ename == 'public') ? rightCollMedia('public') : rightCollMedia(); #AD29特殊處理 $ad_29 = getNativeAD(29, "js", 3); # 底下ad_extra 廣告 $ad_extra = ad_extra(); # 時間檢測 PageLoadCostTime(); # 記憶體檢測 PageLoadCostMemory(); # PV 記錄 pv('china', "001"); $pv_js_code = pv_js_code('china', "001"); # 讀入版型 $template = $TEMPLATES . 'base_body.tpl.html'; require_once($template); function make_newsList($v) { return array( 'title' => $v['title'], 'cat_ename' => '', 'cat_cname' => '', 'media_ename' => '', 'media_cname' => $v['media'], 'pubdate' => $v['pubDate'], 'news_dt' => $v['pubDate'], 'desc' => $v['desc'], 'content' => '', 'link' => $v['url_link'], 'picsrc' => changPhotoSize($v['img_link'], 's'), 'pic' => changPhotoSize($v['img_link'], 'p23'), 'piclink' => $v['img_link'], 'keyword' => $v['keyword'], 'pv' => $v['pv'], ); }