title;
$url = $graph->url;
$description = $graph->description;
if( isset($graph->{'image:secure_url'}) ){
$src = $graph->{'image:secure_url'};
} else {
$src = $graph->image;
}
if( substr($src, 0, 2) === '//'){$src = 'https:' . $src;}
$title_check = utf8_decode($title);
$description_check = utf8_decode($description);
if(mb_detect_encoding($title_check) == 'UTF-8'){
$title = $title_check; // 文字化け解消
}
if(mb_detect_encoding($description_check) == 'UTF-8'){
$description = $description_check; // 文字化け解消
}
$detects = array('ASCII','EUC-JP','SJIS','JIS','CP51932','UTF-16','ISO-8859-1');
// 上記以外でもUTF-8以外の文字コードが渡ってきてた場合、UTF-8に変換する
if(mb_detect_encoding($title) != 'UTF-8'){
$title = mb_convert_encoding($title, 'UTF-8', mb_detect_encoding($title, $detects, true));
}
if(mb_detect_encoding($description) != 'UTF-8'){
$description = mb_convert_encoding($description, 'UTF-8', mb_detect_encoding($description, $detects, true));
}
$grapharray = array('title' => $title, 'description' => $description, 'src' => $src, 'url' => $args[0], 'date' => date("Y-m-d H:i:s"));
file_put_contents($datcache, json_encode($grapharray, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT));
if(file_exists($imgcache)) {
$src = $imgcache ;
} else {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $src);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$imgfile = curl_exec($ch);
curl_close($ch);
if(file_exists($imgfile)){
$imginfo = getimagesize($imgfile);
$filetype = $imginfo[2];
if( $filetype == 1 ){
file_put_contents($gifcache, $imgfile) ;
} else if ( $filetype == 3 ){
file_put_contents($pngcache, $imgfile) ;
} else {
file_put_contents($jpgcache, $imgfile) ;
} //どの拡張子でもない場合どうするか(webp,gzip)、jpg拡張子に偽装したgzファイルなどでエラーが出る
}
}
} else return '#ogp Error: Page not found.';
}
$is_noimg = (in_array('noimg', $args) || filesize($imgcache) == 0 );
if($is_noimg) {$noimgclass = "ogp-noimg" ;}
if(in_array('ogp2', $args)) {$ogpclass = 'ogp2';} //ogp2
//XSS回避
$description = htmlspecialchars($description);
$args[0] = htmlspecialchars($args[0]);
//WEBP表示のfallback
if ( PLUGIN_OGP_WEBP_FALLBACK && file_exists($webpcache)) {
$fallback1 = '';
} else {
$fallback1 = '';
$fallback2 = '';
}
return <<
$fallback1
$fallback2
$description
$args[0]
EOD;
}
?>