/**
* 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);
}
桃園勞檢處推微電影 加強工地職安意識
- 近年來工作事故頻傳,常見高處屋頂修繕及衝剪機械操作時,未設置防墜設施、安全裝置,且未督導作業勞工使用安全防護具,導致發生墜落或被捲夾職業災害。
- 影片中傳遞高處屋頂修繕及衝剪機械操作安全之重要性。
- 勞檢處長李賢祥呼籲,高處屋頂修繕作業及衝剪機械操作等作業之安全事項,應為勞工與雇主雙方共同努力,高處作業應落實上工前不飲酒、正確佩戴安全帽、。
- Q:這篇在講什麼?
- A:近年來工作事故頻傳,常見高處屋頂修繕及衝剪機械操作時,未設置防墜設施、安全裝置,且未督導作業勞工使用安全防護具,導致發生墜落或被捲夾職業災害。
- Q:重點是什麼?
- A:影片中傳遞高處屋頂修繕及衝剪機械操作安全之重要性。
近年來工作事故頻傳,常見高處屋頂修繕及衝剪機械操作時,未設置防墜設施、安全裝置,且未督導作業勞工使用安全防護具,導致發生墜落或被捲夾職業災害,桃園市勞動檢查處守護勞工安全,針對「高處屋頂作業安全」與「衝剪機械操作安全」兩大主題為主軸,特地拍攝微電影與製作動畫短片,傳遞高處屋頂修繕及衝剪機械操作安全之重要性,提醒所有工作者應注意作業安全,並隨時充實自我安全文化。
影片中傳遞高處屋頂修繕及衝剪機械操作安全之重要性。圖:翻攝自勞檢處
勞檢處長李賢祥呼籲,高處屋頂修繕作業及衝剪機械操作等作業之安全事項,應為勞工與雇主雙方共同努力,高處作業應落實上工前不飲酒、正確佩戴安全帽、確實使用安全帶及不輕易拆除安全設施;衝剪機械應設置安全護圍及安全裝置,並指導勞工正確安全操作機械,以及落實維修、調整機械應停止運轉並張掛警告牌等安全事項,共同遠離作業風險危害並守護職場安全,期望透過微電影與動畫以活潑的方式,向市民朋友宣導工作安全的重要性,落實職業安全衛生法令,建立職場安全管理新思維,勿讓今早的再見成為回憶。
勞檢處表示,此次推出宣導影片共2部,每部片約5分鐘,微電影部分以網紅精湛之演技,細膩的拍攝手法,忠實呈現高處屋頂作業安全注意事項,藉由主角家人意外喪生,呼籲勞工於高處作業須依規定戴上安全帽,鋪設安全走道避免踏穿墜落,正確穿戴背負式安全帶並確實勾掛於安全母索,以及宣導自今(111)年起新設置或大規模翻修屋頂須確實設置安全欄杆;動畫部分以生動活潑之對話來傳遞衝剪機械之安全裝置設置用意及使用方法,養成確實使用雙手操作式及光電式安全裝置,維修及調整作業時應落實停機、上鎖、掛牌及使用安全柱等良好安全習慣,2部影片內容都非常實用且豐富,期盼能透過影片幫助民眾養成安全觀念,民眾可處勞檢處官網觀看影片。