/**
* 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);
}
錄音想到大S痛哭!小S獻聲101跨年影片 賈永婕:給她前進力量
錄音想到大S痛哭!小S獻聲101跨年影片 賈永婕:給她前進力量
台北101今(3日)舉辦跨年煙火記者會,公開品牌影片《Together, As Always 因為有你》,藝人小S驚喜獻聲旁白,她自從大S驟逝停工至今,僅在金鐘獎露面,這次受好友賈永婕邀請,影片最後幽默喊話:「賈董,我再跟妳說一次喔!我要看澎湃的煙火,如果只有煙,我會要求在立法院諮詢妳,OK?」不過賈永婕透露,小S在錄音室一度情緒崩潰大哭,仍努力錄完,希望透過聲音帶給大家勇氣,相信新的一年會更好。
小S在台北101品牌影片說出:「20年來大家相約台北101,不怕冷、不怕人擠人,只為了一起看煙火。」她提到每年都穿著睡衣和家人一起倒數、許願,感慨時間過得很快,生活中有太多酸甜苦辣,但每到跨年總是最甜蜜幸福的時光,「世界在變,但台北101一直在這裡,20年了,就像一個好朋友陪伴身邊」。
台北101董事長賈永婕透露,旁白內容是她親自撰寫,也提到看跨年煙火對小S一家是很重要的儀式,想傳達就算今年過得不如意,但這個儀式感還是要堅持下去,「用最燦爛的煙火迎接未來」;她說小S接到邀約立刻就答應,接著就擔心無法完成工作,雖然影片裡的聲音很平靜、溫暖,「但其實我們兩個在錄音間哭爆了」。
賈永婕表示,小S觸景傷情,難過到必須握緊拳頭,才能很用力將每個字講出來,相信這個工作可以帶給小S繼續前進的力量,「要看煙火的人,她不見得會在你身邊,她在其他地方、其他空間一樣陪著你看煙火,只要你心裡有這個人」。
更多《鏡新聞》報導 錄取台大碩士班遭嫉妒室友「冒名放棄」 校方同意外加名額入學 「嚴重錯判」被黃國昌背叛 林飛帆:對民主破壞力強大堪比水門案 中配錢麗被除籍仍經營武統社團 再被「廢止依親居留許可」喊被迫害
免責聲明:本文為外稿合作單位授權刊登,如對內容有任何疑問,請向原作單位確認。
點我訂閱