'/v0/amp-form-0.1.js',
'amp-ad' => '/v0/amp-ad-0.1.js',
'amp-auto-ads' => '/v0/amp-auto-ads-0.1.js',
'amp-analytics' => '/v0/amp-analytics-0.1.js',
'amp-iframe' => '/v0/amp-iframe-0.1.js',
'amp-anim' => '/v0/amp-anim-0.1.js',
'amp-audio' => '/v0/amp-audio-0.1.js',
'amp-video' => '/v0/amp-video-0.1.js',
'amp-carousel' => '/v0/amp-carousel-0.1.js',
'amp-youtube' => '/v0/amp-youtube-0.1.js',
'amp-vine' => '/v0/amp-vine-0.1.js',
'amp-social-share' => '/v0/amp-social-share-0.1.js',
'amp-facebook' => '/v0/amp-facebook-0.1.js',
'amp-twitter' => '/v0/amp-twitter-0.1.js',
'amp-instagram' => '/v0/amp-instagram-0.1.js',
'amp-pinterest' => '/v0/amp-pinterest-0.1.js',
'amp-lightbox' => '/v0/amp-lightbox-0.1.js',
'amp-image-lightbox' => '/v0/amp-image-lightbox-0.1.js',
);
}
endif;
/*---------------------------------------------------------------------------
* AMP で禁止されてる要素の置換もしくは削除
*---------------------------------------------------------------------------*/
if( function_exists( 'thk_amp_not_allowed_tag_replace' ) === false ):
function thk_amp_not_allowed_tag_replace( $contents ) {
global $luxe;
/* チェックで怒られるので、コメントはカタカナ */
// タグ本体に 0x20 を 0xC2 0xA0 で書いてるレアなアホがいたので一応置換
// $contents = str_replace( "\xC2\xA0", "\x20", $contents );
// ↑ これだとタグ内だけでなく文書全体が置換されちゃうので正規表現でやるしかない。
// また、wp_spaces_regexp() は、改行や (HTML エンティティ)も含まれちゃうので使えない。\s は 0xC2 0xA0 自体含まれない。
if( stripos( $contents, chr(0xC2) . chr(0xA0) ) !== false ) {
$contents = preg_replace( '/(<[^>|(?:\xC2\xA0)]+?)(?:\xC2\xA0)+([^>]+?>)/im', "$1\x20$2", $contents );
}
// Amazon 特有のリンク置換
$contents = str_replace( 'rcm-jp.amazon.co.jp', 'rcm-fe.amazon-adsystem.com', $contents );
$contents = preg_replace( '/(http:|https:)*\/\/rcm-fe.amazon-adsystem.com/', 'https://rcm-fe.amazon-adsystem.com', $contents );
// oEmbed で自動挿入されるコンテンツ
$i_frame = 'i' . 'frame';
$contents = preg_replace( '/
<' . $i_frame . '.+?wp-embedded-content.+?' . '<\/' . $i_frame . '><\/p>/', '', $contents );
// アイフレーム
if( stripos( $contents, 'sandbox=' ) !== false ) {
$contents = preg_replace( '/ sandbox=[\'"]{1}[^\'"]+?[\'"]{1}/im', '', $contents );
}
$contents = str_replace( '<' . $i_frame, ']+?src=[^>]+?http:\/\/[^>]+?><\/amp-' . $i_frame . '>/im', '', $contents );
// アイフレームの placeholder(ファーストビューに amp-iframe が出てくるとエラーになるため)
$placeholder = '';
$contents = str_replace( ']+?>/ism', $contents, $frames );
foreach( array_unique( $frames[0] ) as $val ) {
// width が 300px 以下の場合、responsive 消す
$wms = preg_replace( '/.+? width=[\"|\']*([0-9]+)?[\"|\']*.+/', "$1", $val );
if( is_numeric( $wms ) && (int)$wms < 300 ) {
$replace = str_replace( ' layout="responsive"', '', $val );
$contents = str_replace( $val, $replace, $contents );
$val = $replace;
}
// width や height がなかったら、responsive 消して、width と height を指定
if( stripos( $val, ' width=' ) === false || stripos( $val, ' height=' ) === false) {
$replace = str_replace( ' layout="responsive"', '', $val );
$contents = str_replace( $val, $replace, $contents );
$val = $replace;
// Amazon の場合
if( stripos( $val, 'amazon-adsystem.com' ) !== false ) {
if( stripos( $val, ' width=' ) === false ) {
$replace = str_replace( '>', ' width="120">', $val );
$contents = str_replace( $val, $replace, $contents );
}
$val = $replace;
if( stripos( $val, ' height=' ) === false ) {
$replace = str_replace( '>', ' height="250">', $val );
$contents = str_replace( $val, $replace, $contents );
}
}
else {
if( stripos( $val, ' width=' ) === false ) {
$replace = str_replace( '>', ' width="300">', $val );
$contents = str_replace( $val, $replace, $contents );
}
$val = $replace;
if( stripos( $val, ' height=' ) === false ) {
$replace = str_replace( '>', ' height="300">', $val );
$contents = str_replace( $val, $replace, $contents );
}
}
}
}
// イメージ ( thk_amp_tag_replace() の前処理 )
$contents = preg_replace( '/
]+?)>/ism', '', $contents );
// スタイル
/*$contents = preg_replace( '/([\s|\xC2\xA0]*style=([\"|\']).+?\2)/i', '', $contents );*/
if( stripos( $contents, 'style=' ) !== false && stripos( $contents, '!important' ) !== false ) {
preg_match_all( '/style=[\"\']{1}[^\"\']+?\!important[^\"\']*?[\"\']{1}/ism', $contents, $matches );
if( isset( $matches[0] ) ) {
foreach( (array)$matches[0] as $m ) {
$r = str_replace( '!important', '', $m );
$contents = str_replace( $m, $r, $contents );
}
}
}
// アドセンス
if( stripos( $contents, 'data-ad-client' ) !== false ) {
$adsense = thk_replace_amp_adsense( $contents );
if( $adsense !== false ) {
foreach( (array)$adsense as $key => $val ) {
$contents = preg_replace( '/()/ism', $val, $contents );
}
}
}
// スクリプト
if( stripos( $contents, '