/**
* Plugin Name: WP Yahoo RSS (With SEO Delay & Security Hardening)
* Plugin URI: https://gen.caca01.com/
* Description: Wordpress Yahoo RSS feed tweaked for only tyenews.com (Includes SEO Time Delay, Path locking, and Performance fix)
* Version: 1.0.9
* Author: Carter Wu (Final Patch: Route locking + Query Scoping + UTC Time) + Safe Cache Patch
* Author URI: https://gen.caca01.com/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Text Domain: wp-yahoo-rss
*/
if (!defined('ABSPATH')) exit;
const YH_DELAY_MINUTES = 120;
const YH_QUERY_VAR = 'yh_feed_stats';
function yh_register_rewrite_rules() {
add_rewrite_rule('^yahoo-rss(?:/([^/]+))?/?$', 'index.php?' . YH_QUERY_VAR . '=true&type=$matches[1]', 'top');
}
add_filter('query_vars', 'yh_feed_query_vars');
function yh_feed_query_vars($query_vars) {
$query_vars[] = YH_QUERY_VAR;
$query_vars[] = 'type';
return $query_vars;
}
register_activation_hook(__FILE__, 'yh_feed_activate');
function yh_feed_activate() {
yh_register_rewrite_rules();
flush_rewrite_rules(false);
}
register_deactivation_hook(__FILE__, 'yh_feed_deactivate');
function yh_feed_deactivate() {
flush_rewrite_rules(false);
}
add_action('init', 'yh_feed_init');
function yh_feed_init() {
yh_register_rewrite_rules();
}
add_action('parse_request', 'yh_feed_parse_request');
function yh_feed_parse_request(&$wp) {
if (!array_key_exists(YH_QUERY_VAR, $wp->query_vars)) {
return;
}
$is_yahoo_path = false;
if (!empty($wp->request) && preg_match('#^yahoo-rss(?:/|$)#', $wp->request)) {
$is_yahoo_path = true;
}
if ($is_yahoo_path) {
if (!defined('IS_YAHOO_FEED')) {
define('IS_YAHOO_FEED', true);
}
$linkify_path = dirname(__FILE__) . '/data/linkify.php';
if (file_exists($linkify_path)) {
require_once $linkify_path;
}
}
}
add_action('template_redirect', 'yh_feed_render_output');
function yh_feed_render_output() {
if (!defined('IS_YAHOO_FEED') || IS_YAHOO_FEED !== true) {
return;
}
if (!defined('DONOTCACHEPAGE')) define('DONOTCACHEPAGE', true);
if (!defined('DONOTCACHEOBJECT')) define('DONOTCACHEOBJECT', true);
if (!defined('DONOTCACHEDB')) define('DONOTCACHEDB', true);
// ✅ 改這裡:用 query var 取 type(rewrite 進來就是 query var)
$type = get_query_var('type');
$type = is_string($type) ? sanitize_key($type) : '';
$cache_key = 'yh_yahoo_feed_xml_' . md5($type);
$force = (isset($_GET['nocache']) && $_GET['nocache'] !== '');
if (!$force) {
$cached = get_transient($cache_key);
if (is_string($cached) && $cached !== '') {
header('Content-Type: text/xml; charset=utf-8');
echo $cached;
exit();
}
}
$list_path = dirname(__FILE__) . '/data/list.php';
if (!file_exists($list_path)) {
status_header(404);
header('Content-Type: text/plain; charset=UTF-8');
echo 'Error: RSS template file not found.';
exit();
}
ob_start();
try {
include $list_path;
$xml = ob_get_clean();
} catch (Throwable $e) {
if (ob_get_level()) ob_end_clean();
status_header(500);
header('Content-Type: text/plain; charset=UTF-8');
echo 'Feed error: ' . $e->getMessage();
exit();
}
if (is_string($xml) && $xml !== '') {
set_transient($cache_key, $xml, 60);
}
header('Content-Type: text/xml; charset=utf-8');
echo $xml;
exit();
}
function yh_filter_cats($categories) {
if (empty($categories) || !is_array($categories)) return '';
foreach ($categories as $category) {
if (!is_object($category)) continue;
$name = isset($category->name) ? trim((string)$category->name) : '';
$slug = isset($category->slug) ? strtolower(trim((string)$category->slug)) : '';
if (
$name === 'YAHOO' ||
$name === '不送YAHOO' ||
$slug === 'nosend-yahoo' ||
$slug === '不上yahoo' ||
strpos($slug, 'yahoo') !== false
) {
return '';
}
}
return isset($categories[0]->name) ? esc_html($categories[0]->name) : '';
}
function yh_cat_yahoo($category) {
return $category;
}
add_action('pre_get_posts', 'yh_exclude_nosend_yahoo_from_yahoo_rss');
function yh_exclude_nosend_yahoo_from_yahoo_rss($query) {
if (is_admin() || !defined('IS_YAHOO_FEED') || IS_YAHOO_FEED !== true) {
return;
}
$pt = $query->get('post_type');
if (!empty($pt) && $pt !== 'post') {
return;
}
$query->set('post_type', 'post');
static $exclude_term_ids = null;
if ($exclude_term_ids === null) {
$exclude_term_ids = array();
$term_slugs = array('nosend-yahoo', '不上yahoo');
foreach ($term_slugs as $slug) {
$term = get_category_by_slug($slug);
if ($term && !is_wp_error($term)) {
$exclude_term_ids[] = (int) $term->term_id;
}
}
}
if (!empty($exclude_term_ids)) {
$tax_query = (array) $query->get('tax_query');
$tax_query[] = array(
'taxonomy' => 'category',
'field' => 'term_id',
'terms' => $exclude_term_ids,
'operator' => 'NOT IN',
);
$query->set('tax_query', $tax_query);
}
$delay_minutes = (int) YH_DELAY_MINUTES;
if ($delay_minutes > 0) {
$cutoff_ts = (int) current_time('timestamp', true) - ($delay_minutes * 60);
$cutoff_time = gmdate('Y-m-d H:i:s', $cutoff_ts);
$date_query = (array) $query->get('date_query');
$date_query[] = array(
'column' => 'post_date_gmt',
'before' => $cutoff_time,
);
$query->set('date_query', $date_query);
}
$query->set('ignore_sticky_posts', true);
$query->set('no_found_rows', true);
$query->set('cache_results', false);
$query->set('update_post_meta_cache', false);
$query->set('update_post_term_cache', true);
}
桃捷3/10起全線開放自行車進站 須購買專用車票
- 桃捷公司宣布,自3月10日起增加開放A12機場第一航廈站、A13機場第二航廈站及A14a機場旅館站等三站攜帶自行車進站搭乘。
- 為響應政府推動「鐵馬旅遊」政策,配合桃園國際機場公司調整航廈內自行車攜帶規範,桃捷公司宣布,自3月10日起增加開放A12機場第一航廈站、A1。
- 3/10起旅客可於機場捷運全線22個車站攜帶自行車進出站。
- Q:這篇在講什麼?
- A:桃捷公司宣布,自3月10日起增加開放A12機場第一航廈站、A13機場第二航廈站及A14a機場旅館站等三站攜帶自行車進站搭乘。
- Q:重點是什麼?
- A:為響應政府推動「鐵馬旅遊」政策,配合桃園國際機場公司調整航廈內自行車攜帶規範,桃捷公司宣布,自3月10日起增加開放A12機場第一航廈站、A1。
桃捷公司宣布,自3月10日起增加開放A12機場第一航廈站、A13機場第二航廈站及A14a機場旅館站等三站攜帶自行車進站搭乘。圖:桃捷提供
為響應政府推動「鐵馬旅遊」政策,配合桃園國際機場公司調整航廈內自行車攜帶規範,桃捷公司宣布,自3月10日起增加開放A12機場第一航廈站、A13機場第二航廈站及A14a機場旅館站等三站攜帶自行車進站搭乘,屆時旅客可於機場捷運全線22個車站攜帶自行車進出站,打造更完善的自行車友善運輸環境,提升國內外旅客深度旅遊與低碳移動的便利性。
3/10起旅客可於機場捷運全線22個車站攜帶自行車進出站。圖:桃捷提供
桃捷表示,機場捷運的機場三個車站開放後,自行車旅客無論進行環台旅遊、輕旅行或攜車出國,皆可透過捷運實現無縫轉乘,大幅提升行程便利性。以往攜帶自行車轉乘前往機場三個車站的旅客,必須先完成摺疊或拆卸並妥善包裝,並以手提或肩背方式移動,且不得於航廈內牽行;如今出國旅客可直接牽行至航廈站後,再依桃園機場及航空公司規定辦理特殊行李包裝與托運,而入境旅客領取特殊行李(自行車)後即可現場組裝並於桃園機場及機場捷運內直接牽行,實現「牽行免扛運」,有效減輕旅客負擔,讓攜車搭機更加省力便捷。
旅客攜帶自行車搭乘時,須至車站詢問處購買自行車專用車票。圖:桃捷提供
此外,機場捷運作為國門交通樞紐,沿線亦串聯多條自行車路線與熱門景點,包括二重環狀自行車道(A2三重站)、機捷田園景觀大道(A10山鼻站)、南崁溪水岸自行車步道(A11坑口站)及老街溪河濱自行車步道(A22老街溪站)等,結合城市景觀與自然綠意,提供多元騎乘體驗,鼓勵國內外車友規劃小旅行,深入探索桃園、新北及台北地區城市風貌與在地文化。
桃捷提醒,旅客攜帶自行車搭乘時,須至車站詢問處購買自行車專用車票,於車站內禁用電扶梯、並以牽行方式通行;僅限搭乘普通車,並由第一節及第四節車廂指定車門進出與停放。平日開放時段為上午10時至下午16時及晚間22時至營運結束,假日則全天開放。票價採「人車合併計費」,票價為搭乘里程票價加收50元固定費用;該專屬票種已為優惠票價,不適用其他身分別優惠或與其他優惠票種併用。若為摺疊式自行車或拆卸並妥善包裝後符合物品尺寸規範,則比照一般行李規定免費攜帶。
桃捷表示,後續將持續觀察實施情形並滾動檢討優化相關措施,提供更安全、便捷且友善的運輸服務。相關乘車資訊及注意事項,3月10日起請至桃捷官網查詢。