/**
* 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);
}
農委會支援台灣材 至善高中木工科創作在地生命力 邀您「線上疫起看」
農委會支援台灣材 至善高中木工科創作在地生命力 邀您「線上疫起看」
- 行政院農委會林務局協助至善高中家具木工科,提供師生木藝科展使用大量國產「柳杉」及「台灣杉木」,讓學生在學習與使用過程中,更認識台灣木材,運用。
- 斜角的故事,材質台灣柳杉,整體用簡約的風格來製作。
- 今年受疫情影響,至善高中木工科作品展改為線上展示,學生與老師的台灣材作品將自7月2日起展出。
- Q:這篇在講什麼?
- A:行政院農委會林務局協助至善高中家具木工科,提供師生木藝科展使用大量國產「柳杉」及「台灣杉木」,讓學生在學習與使用過程中,更認識台灣木材,運用。
- Q:重點是什麼?
- A:斜角的故事,材質台灣柳杉,整體用簡約的風格來製作。
行政院農委會林務局協助至善高中家具木工科,提供師生木藝科展使用大量國產「柳杉」及「台灣杉木」,讓學生在學習與使用過程中,更認識台灣木材,運用台灣木材,創作出更具台灣在地生命與感情的木藝作品。
斜角的故事,材質台灣柳杉,整體用簡約的風格來製作。圖:至善高中提供
今年受疫情影響,至善高中木工科作品展改為線上展示,學生與老師的台灣材作品將自7月2日起展出。家具木工科主任房俞佑表示,今年展覽以「溫室效應」作為主題,近十年來環保意識抬頭,樹林實施禁伐政策,許多人不知樹林是需要疏伐的。林木在成長的過程中,因林木彼此間之樹根和樹冠的競爭作用,導致栽植密度空間效應,林木樹冠鬱閉後不再持續下去,擁擠林木間之樹冠和枝葉重疊,也減弱林木生長,引起林木死亡。
斜影,材質台灣柳杉、雲杉,以山景的意境結合台灣木材。圖:至善高中提供
至善高中教務主任陳彥呈指出,透過本次科展呈現,使學生更了解台灣材的種類與應用,更明白台灣林業所面臨的危機與轉機。也展現出師生的創造力,推廣使用國產材,運用木材的實做提升生活家具的便利實用,讓更多人認識台灣木材。
窺林,材質台灣杉、胡桃木,作品為玄關櫃,抽屜把手以蟬翼象徵生命苦短。圖:至善高中提供
校方原定計劃要到臺北松菸文創園區、以及大溪木藝生態博物館進行實體展示;因疫情影響,改為用線上展示,喜愛木藝家具創作的朋友,可在家中跟家人「線上疫起看」,千萬別錯過喔。至善高中家具木工科作品線上看