'行政院', 'gov' => '中央政府', 'taipei' => '台北市', 'tpc' => '新北市', 'kcg' => '高雄市', ); } # 頁碼處理 $page = ((int)$_GET['p'] < 1) ? 1 : $_GET['p']; $itemPerPage = ($list_style == 'summary') ? 60 : 24; $itemStart = ($page - 1) * $itemPerPage; #組舊的頭條 $head_incfile = $EDITOR_DIR . 'head_list_' . $cid . '.inc'; $head_incfile_auto = $EDITOR_DIR . 'head_list_auto_' . $cid . '.inc'; $incFile = (filemtime($head_incfile) >= strtotime('-2 hours')) ? $head_incfile : $head_incfile_auto ; $new_headItem_old = LoadRequireFile($incFile); if (is_array($new_headItem_old)) { $new_headItem_old = array_map('make_headItem_bigpic', $new_headItem_old); $new_headItem_old = array_slice($new_headItem_old, 0, 8); $new_headItem_old_new = $new_headItem_old; } if (is_array($new_headItem_old_new) && !empty($new_headItem_old_new)) { foreach ($new_headItem_old_new as $k1 => $v1) { if ($v1['abc'] == "new") { $bbs_arr_old[] = $new_headItem_old_new[$k1]; unset($new_headItem_old_new[$k1]); break; } } } if ($bbs_arr_old == null) { if (isset($new_headItem_old_new[0])) { $bbs_arr_old[] = $new_headItem_old_new[0]; unset($new_headItem_old_new[0]); } else { $bbs_arr_old = []; } } #old 頭條 $bbs_arr_old_cat_index = $bbs_arr_old; $new_headItem_old_new = (is_array($new_headItem_old_new)) ? array_values($new_headItem_old_new) : []; #news 過濾 nid $head_nid = array(); foreach ($new_headItem_old as $key => $val) { $head_nid[]['nid'] = $val['nid']; } $head_nid = array_merge($head_nid, $cookie_nid_arr); # 讀取 BDB 資料庫 $listFile = ($cat_subtype == 'hot') ? $cid . '_hot' : $cid . '_news'; if ($cid == "022") { $listFile = "022_news"; } $dbh = new BDB_news_lists($listFile); if (!$dbh) { oops($cid); exit; } $allItms = $dbh->getAllKeys(); $allItms = is_array($allItms) ? $allItms : array(); $totalNews = count($allItms); # 只取需要的數量 $allItms = array_slice($allItms, $itemStart, $itemPerPage); if ($page > 1 && count($allItms) == 0) { oops($cid); exit; } $newsList = array(); foreach ($allItms as $k => $v) { $newsList[] = $dbh->getNews($v); } # 關閉 BDB 資料庫 $dbh->closeDb(); $newsList = is_array($newsList) ? array_map('make_newsitem', $newsList) : []; } # 分類頭條 if ($page == 1 && !empty($cid)) { if ($cat_subtype == "new") { $head_incfile = $EDITOR_DIR . 'head_list_' . $cid . '_new1.inc'; } else { if ($_COOKIE['keyword_new'] != "" || $_COOKIE['keyword_new'] != "null") { # 將陣列json->array $kk_arr = json_decode($_COOKIE['keyword_new'], true); $kk_arr = (is_array($kk_arr)) ? $kk_arr : []; $new_keyword_arr = array_values($kk_arr); $acc = array_unique($new_keyword_arr); $keyword_news_cat = []; foreach ($acc as $keyword_new) { for ($x = 0; $x < 2; $x++) { $temp_cat = get_keyword_news($keyword_new, $cat_cname, $head_nid, "", "", "", "", ""); if (!empty($temp_cat)) { $head_nid[] = trim($temp_cat['nid']); $keyword_news_cat[] = $temp_cat; } if (count($keyword_news_cat) > 8) { break; } } } //移除[中央商情]及[勁報]新聞 $keyword_news_cat = array_filter($keyword_news_cat, function($val){ return !in_array($val['emedia'], ['cna_business', 'twpowernews']); }); $keyword_news_cat = array_values($keyword_news_cat); if (!empty($keyword_news_cat)) { $keyword_news_cat = array_map('make_headItem_bigpic', $keyword_news_cat); $keyword_news_cat = array_slice(array_values($keyword_news_cat), 0, 4); } else { $keyword_news_cat = []; } $tmpnewsList_hot = LoadRequireFile($EDITOR_DIR . 'hot_list_' . $cid . '.inc'); $tmpnewsList_hot = is_array($tmpnewsList_hot) ? array_map('make_newsitem_new', $tmpnewsList_hot) : []; foreach ($tmpnewsList_hot as $k => $v) { $news_link_arr = explode("/", $v['url']); $nid = str_replace(['index-', '.html'], "", $news_link_arr[4]); $tmpnewsList_hot[$k]['nid'] = $nid; $tmpnewsList_hot[$k]['link'] = $v['url']; } #檢查是否有重複看過的新聞 $hd_headItem = (is_array($tmpnewsList_hot)) ? $tmpnewsList_hot : [] ; $tmpnewsList_hot = filter_news($head_nid, $hd_headItem); $new_headItem = array_merge($bbs_arr_old_cat_index, $keyword_news_cat, $new_headItem_old_new, $tmpnewsList_hot); $new_headItem = array_slice($new_headItem, 0, 9); } } $tmpheadItem = is_array($tmpheadItem) ? $tmpheadItem : []; if ($cat_ename == "entertainment") { $head_incfile = $EDITOR_DIR . 'head_list_auto_' . $cid . '.inc'; $tmpheadItem = LoadRequireFile($head_incfile); $headItem = array_map('make_entertainment_headItem', $tmpheadItem); } else { $num = count($tmpheadItem); } } if ($cat_subtype === "new") { $head_incfile = $EDITOR_DIR . 'head_list_' . $cid . '_new.inc'; if (is_file($head_incfile)) { $tmpheadItem = LoadRequireFile($head_incfile); $new_headItem = []; if ($tmpheadItem) { $new_headItem = array_map('make_headItem_bigpic', array_slice($tmpheadItem, 0, 9)); if (!empty($new_headItem)) { #檢查大圖 $new_headItem_new = $new_headItem; foreach ($new_headItem_new as $k1 => $v1) { if ($v1['abc'] == "new") { $bbs_arr_new[] = $new_headItem_new[$k1]; unset($new_headItem_new[$k1]); break; } } #沒有大圖片則取第一則新聞當頭條 if (empty($bbs_arr_new)) { $bbs_arr_new = array(); $new_headItem_new = array_values($new_headItem_new); $bbs_arr_new[] = $new_headItem_new[0]; unset($new_headItem_new[0]); } #檢查是否有重複看過的新聞 $hd_headItem = array_values($new_headItem_new); $new_new_headItem = array_merge($bbs_arr_new, filter_news($head_nid, $hd_headItem)); if (count($new_new_headItem) <= 8) { $tmpnewsList_new = LoadRequireFile($EDITOR_DIR . 'new_list_' . $cid . '.inc'); if(is_array($tmpnewsList_new)) { foreach ($tmpnewsList_new as $kk => $vv) { $tmpnewsList_new[$kk]['link'] = $vv['url']; } $tmpnewsList_new = array_map('make_headItem_bigpic', $tmpnewsList_new); } else { $tmpnewsList_new = []; } #檢查是否有重複看過的新聞 $tmpnewsList_new = filter_news($cookie_nid_arr, $tmpnewsList_new); $tmpnewsList_new = array_slice(array_values($tmpnewsList_new), 5, 20); if (is_array($new_new_headItem) && is_array($tmpnewsList_new)) { $new_headItem = array_merge($new_new_headItem, $tmpnewsList_new); $new_headItem = array_slice($new_headItem, 0, 9); } } else { $new_headItem = array_slice($new_new_headItem, 0, 9); } } } } } # 右欄分類新聞 $incfile = $EDITOR_DIR . ($cat_subtype == 'hot' ? 'new' : 'hot') . '_list_' . $cid . '.inc'; $rightCatNewsItem = LoadRequireFile($incfile); $rightCatNewsItem = (!empty($rightCatNewsItem)) ? array_slice($rightCatNewsItem, 0, 10) : []; #是否顯示曲線圖 $incfile_keyword = $EDITOR_DIR . 'election_staristics_' . $cid . '.inc'; if (file_exists($incfile_keyword)) { $keyword_name = LoadRequireFile($incfile_keyword); } #新聞分類關鍵字操作頁籤 $incfile_cat_sub = $EDITOR_DIR . 'cat_sub/' . $cid . '.inc'; if (file_exists($incfile_cat_sub)) { $cat_sub = LoadRequireFile($incfile_cat_sub); foreach ($cat_sub['data'] as $kk => $vv) { if (empty($vv['name'])) { unset($cat_sub['data'][$kk]); } } unset($cat_sub['data']['cat_sub_cid']); } # 標題 $cat_subtype_name = ($cat_subtype == "hot") ? "熱門" : "最新"; $html_title = $cat_subtype_name . $cat_cname . '新聞-PChome Online新聞' ; $html_description = "提供" . $cat_subtype_name . $cat_cname . "新聞大事、即時焦點新聞快訊!內容涵蓋" . $cat_cname . "新聞時事議題文章、影片、照片等各種資訊,關注PChome Online新聞不錯過" . $cat_cname . "熱門大小事。"; $html_keywords = $cat_cname . "新聞," . $cat_subtype_name . $cat_cname . "新聞," . $cat_cname . "新聞大事,頭條,即時,PChome新聞"; # 右欄空氣品質 $rightAir = rightAir(); # 右欄氣象資訊 $rightWeather = right_get_weather(); # 右欄樂透 $rightLottery = rightLottery(); # 右欄星座 $rightConstellation = rightConstellation(); # 右欄合作媒體 $collMediaItem = ($cat_ename == 'public') ? rightCollMedia('public') : rightCollMedia(); #20231220 新增結構化資料 $newsItem['cat_cname'] = $cat_cname; $newsItem['cat_link'] = "/cat/" . $cat_ename; $final_BreadcrumbList = BreadcrumbList_schema($newsItem); # 廣告 switch ($cat_ename) { # 財經 case 'finance': $UAD = getUserAD(11, 16, 18, 22, 34, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 90, 91, 92, 93, 94, 80); if ($UAD[130] || $UAD[131] || $UAD[132] || $UAD[133] || $UAD[134] || $UAD[135] || $UAD[136] || $UAD[137] || $UAD[138] || $UAD[139]) { $HEAD_iframeAD = array( 'tag1_title' => $UAD[130], 'tag1_body' => $UAD[131], 'tag2_title' => $UAD[132], 'tag2_body' => $UAD[133], 'tag3_title' => $UAD[134], 'tag3_body' => $UAD[135], 'tag4_title' => $UAD[136], 'tag4_body' => $UAD[137], 'tag5_title' => $UAD[138], 'tag5_body' => $UAD[139], ); } break; # 科技 case 'science': $UAD = getUserAD(11, 18, 34, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 90, 91, 92, 93, 94); if ($UAD[140] || $UAD[141] || $UAD[142] || $UAD[143] || $UAD[144] || $UAD[145] || $UAD[146] || $UAD[147] || $UAD[148] || $UAD[149]) { $HEAD_iframeAD = array( 'tag1_title' => $UAD[140], 'tag1_body' => $UAD[141], 'tag2_title' => $UAD[142], 'tag2_body' => $UAD[143], 'tag3_title' => $UAD[144], 'tag3_body' => $UAD[145], 'tag4_title' => $UAD[146], 'tag4_body' => $UAD[147], 'tag5_title' => $UAD[148], 'tag5_body' => $UAD[149], ); } break; # 娛樂 case 'entertainment': if ($list_style == 'summary') { $UAD = getUserAD(11, 18, 34, 150, 1105, 152, 153, 154, 155, 156, 157, 158, 159, 90, 91, 92, 93, 94); } else { $UAD = getUserAD(11, 18, 34, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 90, 91, 92, 93, 94); } if ($UAD[150] || $UAD[151] || $UAD[152] || $UAD[153] || $UAD[154] || $UAD[155] || $UAD[156] || $UAD[157] || $UAD[158] || $UAD[159]) { $HEAD_iframeAD = array( 'tag1_title' => $UAD[150], 'tag1_body' => $UAD[151], 'tag2_title' => $UAD[152], 'tag2_body' => $UAD[153], 'tag3_title' => $UAD[154], 'tag3_body' => $UAD[155], 'tag4_title' => $UAD[156], 'tag4_body' => $UAD[157], 'tag5_title' => $UAD[158], 'tag5_body' => $UAD[159], ); } break; # 消費 case 'expense': $UAD = getUserAD(11, 18, 34, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 90, 91, 92, 93, 94); if ($UAD[160] || $UAD[161] || $UAD[162] || $UAD[163] || $UAD[164] || $UAD[165] || $UAD[166] || $UAD[167] || $UAD[168] || $UAD[169]) { $HEAD_iframeAD = array( 'tag1_title' => $UAD[160], 'tag1_body' => $UAD[161], 'tag2_title' => $UAD[162], 'tag2_body' => $UAD[163], 'tag3_title' => $UAD[164], 'tag3_body' => $UAD[165], 'tag4_title' => $UAD[166], 'tag4_body' => $UAD[167], 'tag5_title' => $UAD[168], 'tag5_body' => $UAD[169], ); } break; # 旅遊 case 'travel': $UAD = getUserAD(11, 18, 34, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 90, 91, 92, 93, 94); if ($UAD[170] || $UAD[171] || $UAD[172] || $UAD[173] || $UAD[174] || $UAD[175] || $UAD[176] || $UAD[177] || $UAD[178] || $UAD[179]) { $HEAD_iframeAD = array( 'tag1_title' => $UAD[170], 'tag1_body' => $UAD[171], 'tag2_title' => $UAD[172], 'tag2_body' => $UAD[173], 'tag3_title' => $UAD[174], 'tag3_body' => $UAD[175], 'tag4_title' => $UAD[176], 'tag4_body' => $UAD[177], 'tag5_title' => $UAD[178], 'tag5_body' => $UAD[179], ); } break; # 生活 case 'living': $UAD = getUserAD(11, 18, 34, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 90, 91, 92, 93, 94); if ($UAD[180] || $UAD[181] || $UAD[182] || $UAD[183] || $UAD[184] || $UAD[185] || $UAD[186] || $UAD[187] || $UAD[188] || $UAD[189]) { $HEAD_iframeAD = array( 'tag1_title' => $UAD[180], 'tag1_body' => $UAD[181], 'tag2_title' => $UAD[182], 'tag2_body' => $UAD[183], 'tag3_title' => $UAD[184], 'tag3_body' => $UAD[185], 'tag4_title' => $UAD[186], 'tag4_body' => $UAD[187], 'tag5_title' => $UAD[188], 'tag5_body' => $UAD[189], ); } break; # 寵物 case 'pet': $UAD = getUserAD(11, 18, 34, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 90, 91, 92, 93, 94); if ($UAD[180] || $UAD[181] || $UAD[182] || $UAD[183] || $UAD[184] || $UAD[185] || $UAD[186] || $UAD[187] || $UAD[188] || $UAD[189]) { $HEAD_iframeAD = array( 'tag1_title' => $UAD[180], 'tag1_body' => $UAD[181], 'tag2_title' => $UAD[182], 'tag2_body' => $UAD[183], 'tag3_title' => $UAD[184], 'tag3_body' => $UAD[185], 'tag4_title' => $UAD[186], 'tag4_body' => $UAD[187], 'tag5_title' => $UAD[188], 'tag5_body' => $UAD[189], ); } break; # 汽車 case 'car': $UAD = getUserAD(11, 14, 18, 34, 80, 81, 82, 83, 84, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 90, 91, 92, 93, 94); if ($UAD[190] || $UAD[191] || $UAD[192] || $UAD[193] || $UAD[194] || $UAD[195] || $UAD[196] || $UAD[197] || $UAD[198] || $UAD[199]) { $HEAD_iframeAD = array( 'tag1_title' => $UAD[190], 'tag1_body' => $UAD[191], 'tag2_title' => $UAD[192], 'tag2_body' => $UAD[193], 'tag3_title' => $UAD[194], 'tag3_body' => $UAD[195], 'tag4_title' => $UAD[196], 'tag4_body' => $UAD[197], 'tag5_title' => $UAD[198], 'tag5_body' => $UAD[199], ); } break; # 健康 case 'healthcare': $UAD = getUserAD(11, 18, 34, 90, 91, 92, 93, 94, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219); if ($UAD[210] || $UAD[211] || $UAD[212] || $UAD[213] || $UAD[214] || $UAD[215] || $UAD[216] || $UAD[217] || $UAD[218] || $UAD[219]) { $HEAD_iframeAD = array( 'tag1_title' => $UAD[210], 'tag1_body' => $UAD[211], 'tag2_title' => $UAD[212], 'tag2_body' => $UAD[213], 'tag3_title' => $UAD[214], 'tag3_body' => $UAD[215], 'tag4_title' => $UAD[216], 'tag4_body' => $UAD[217], 'tag5_title' => $UAD[218], 'tag5_body' => $UAD[219], ); } break; # 大陸 case 'china': $UAD = getUserAD(11, 18, 34, 90, 91, 92, 93, 94, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219); if ($UAD[210] || $UAD[211] || $UAD[212] || $UAD[213] || $UAD[214] || $UAD[215] || $UAD[216] || $UAD[217] || $UAD[218] || $UAD[219]) { $HEAD_iframeAD = array( 'tag1_title' => $UAD[210], 'tag1_body' => $UAD[211], 'tag2_title' => $UAD[212], 'tag2_body' => $UAD[213], 'tag3_title' => $UAD[214], 'tag3_body' => $UAD[215], 'tag4_title' => $UAD[216], 'tag4_body' => $UAD[217], 'tag5_title' => $UAD[218], 'tag5_body' => $UAD[219], ); } break; case 'society': $UAD = getUserAD(11, 18, 34, 90, 91, 92, 93, 94, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209); if ($UAD[200] || $UAD[201] || $UAD[202] || $UAD[203] || $UAD[204] || $UAD[205] || $UAD[206] || $UAD[207] || $UAD[208] || $UAD[209]) { $HEAD_iframeAD = array( 'tag1_title' => $UAD[200], 'tag1_body' => $UAD[201], 'tag2_title' => $UAD[202], 'tag2_body' => $UAD[203], 'tag3_title' => $UAD[204], 'tag3_body' => $UAD[205], 'tag4_title' => $UAD[206], 'tag4_body' => $UAD[207], 'tag5_title' => $UAD[208], 'tag5_body' => $UAD[209], ); } break; default: $UAD = getUserAD(11, 18, 34, 90, 91, 92, 93, 94); break; } # 底下ad_extra 廣告 $ad_extra = ad_extra(); # 時間檢測 PageLoadCostTime(); # 記憶體檢測 PageLoadCostMemory(); # PV 記錄 $a = pv('C', $cid); $pv_js_code = pv_js_code('C', $cid); # 讀入版型 $dd = date("Ymd"); $template = $TEMPLATES . 'base_body.tpl.html'; require_once($template); function make_entertainment_headItem($v) { return array( 'nid' => $v['nid'], 'title' => $v['title'], 'cat_ename' => $v['ecat'], 'cat_cname' => $v['cat'], 'media_ename' => $v['emedia'], 'media_cname' => $v['media'], 'pubdate' => $v['pubdate'], 'desc' => $v['desc'], 'content' => '', 'link' => $v['link'], 'picsrc' => pic_exists($v['pic'], '', $v['ecat']), 'piclink' => $v['piclink'], 'keyword' => $v['keyword'], 'pv' => $v['pv'], 'sversion' => pic_exists($v['pic'], '', $v['ecat']), 'ori_url' => $v['ori_url'], ); } function make_newsitem($v) { if (is_object($v)) { $v->picsrc = pic_exists($v->picsrc, 's', $v->media_ename); } if (is_array($v)) { $v['picsrc'] = pic_exists($v['picsrc'], 's', $v['media_ename']); } return $v; } function make_newsitem_new($v) { if (is_object($v)) { $v->picsrc = pic_exists($v->picsrc, 's', $v->media_ename); } if (is_array($v)) { $v['picsrc'] = pic_exists($v['picsrc'], 'p23', $v['ecat']); } return $v; } function make_headItem_bigpic($v) { //檢查圖片的長跟寬 //寬度小於512排除 //達成條件用新版型 $img_path = '/var/www/news/data/news/data/'; $url = str_replace("/newsdata", "", $v['pic']); $url_1 = str_replace("_m", "", $url); $new_url = $img_path . $url_1; $new_url = str_replace("//", "/", $new_url); $image_info = getimagesize($new_url); $size = "p23"; $hight = $image_info[1] * 1.3; if ($image_info[0] >= 512 && $image_info[0] != 0 && !preg_match("/default2/i", $v['picsrc'])) { $version = "new"; $abc = "new"; } else { $version = "old"; $abc = "old"; } return array( 'nid' => $v['nid'], 'title' => $v['title'], 'cid' => $v['cid'], 'cat_ename' => $v['ecat'], 'cat_cname' => $v['cat'], 'media_ename' => $v['emedia'], 'media_cname' => $v['media'], 'pubdate' => $v['pubdate'], 'desc' => $v['desc'], 'content' => '', 'link' => $v['link'], 'picsrc' => pic_exists_hd($v['pic'], 'p23', $v['ecat'], $size), 'newpic' => pic_exists($v['pic'], $v['ecat']), 'piclink' => $v['piclink'], 'keyword' => $v['keyword'], 'pv' => $v['pv'], 'version' => $version, 'abc' => $abc, 'width' => $image_info[0], 'hight' => $hight, 'ori_url' => $v['ori_url'], ); }