# [メタ情報] # 識別子: vimeo_vm5用php_exe # システム名: 未分類 # 技術種別: Misc # 機能名: Misc # 使用言語: php # 状態: 実行用 # [/メタ情報] 要約:このPHPテンプレートは、WordPressでVimeo動画を表示するためのカスタムテンプレートです。URLパラメータから動画ID(movid)を取得し、複数候補のJSONファイル(主に/_secure/wp_json/videoembed.json)から該当データを読み込みます。データが存在すれば埋め込みコードを整形・表示し、不要なリンクを除去します。?debug=1指定時にはデバッグ情報(パス・更新日時・件数など)を表示します。データが見つからない場合はエラーメッセージを出力します。 'n/a', 'mtime' => 'n/a', 'entries' => 0, 'json_ok' => false]; $raw = false; foreach ($path_candidates as $p) { if (is_readable($p)) { $raw = @file_get_contents($p); $debug_info['path'] = $p; break; } } if ($raw === false) { error_log('vm5: failed to read any json path'); return false; } $mtime = @filemtime($debug_info['path']); if ($mtime) $debug_info['mtime'] = date('Y-m-d H:i:s', $mtime); $data = json_decode($raw, true); if ($data === null && json_last_error() !== JSON_ERROR_NONE) { error_log('vm5: json decode error - ' . json_last_error_msg()); return false; } $debug_info['json_ok'] = true; $debug_info['entries'] = is_array($data) ? count($data) : 0; return is_array($data) ? $data : []; } // 厳密一致検索 function vm5_find_by_movid($data, $movid) { if (!is_array($data)) return null; $movid = trim((string)$movid); foreach ($data as $row) { $vid = isset($row['videoid']) ? trim((string)$row['videoid']) : ''; if ($vid === $movid) return $row; } return null; } function vm5_strip_unwanted_link($html) { $pattern = '/]*>\s*動画を別ページで表示\(ここをクリック\)\s*<\/a>/u'; return preg_replace($pattern, '', (string)$html); } // ========== 表示開始 ========== get_header(); $movid = get_vimeo_video_id(); if ($movid) { $dbg = []; $arr = vm5_load_embed_json_array($dbg); $video_info = vm5_find_by_movid($arr, $movid); // ?debug=1 で内部情報表示 $debug = isset($_GET['debug']) && $_GET['debug'] == '1'; if ($debug) { echo '
'; echo 'path=' . esc_html($dbg['path']) . '
'; echo 'mtime=' . esc_html($dbg['mtime']) . '
'; echo 'entries=' . esc_html($dbg['entries']) . '
'; echo 'movid=' . esc_html($movid) . '
'; echo 'hit=' . ($video_info ? ('videoid=' . esc_html($video_info['videoid'])) : 'none'); echo '
'; } if ($video_info && !empty($video_info['embedCode'])) { $embed = do_shortcode($video_info['embedCode']); $embed = vm5_strip_unwanted_link($embed); echo $embed; echo '
'; echo '<vimeo playerへ飛ぶ>'; echo '
'; } else { echo '

No data found for movid: ' . esc_html($movid) . '

'; } } else { echo '

No movid provided.

'; } add_filter('the_content', function($c){ return vm5_strip_unwanted_link($c); }, 9); if (have_posts()) : while (have_posts()) : the_post(); the_content(); endwhile; endif; remove_filter('the_content', 'vm5_strip_unwanted_link', 9); get_footer(); ?>