wordpressの非公開APIを利用した、スクリーンショット作成プラグイン
- Use 1
- Search 0
- Interest 0
- View 5788
デモ
wordpressの本文入力エリアに、用途に応じて以下のように入力します。
1.基本的な使い方
[screenshot url="http://link-to-website"]
2.キャプチャのサイズを指定する場合
[screenshot url="http://link-to-website" width="500"]
3.リンクタイプを変更する場合
[screenshot url="http://link-to-website" width="500" target="_blank"]
4.ALTを指定する場合
[screenshot url="http://link-to-website" width="500" target="_blank" alt="サイト名"]
ソース
PHP
<php define('DEFAULT_CAPTURE_WIDTH',300); function url2screenshot($attributes, $content = '', $code = '') { $setting = array( 'url' => '', 'alt' => '', 'target' => '', 'width' => DEFAULT_CAPTURE_WIDTH, 'class' => '', ); $attributes = shortcode_atts($setting, $attributes); if (empty($attributes['url']) || is_null($attributes['url'])) { return; } $imageUrl = getApiUrl($attributes['url'], $attributes['width']); $srcAttributes = array( 'src' => $imageUrl, 'alt' => (empty($attributes['alt'])) ? $attributes['url'] : $attributes['alt'], 'width' => ($attributes['width'] <= 0) ? DEFAULT_CAPTURE_WIDTH : (int)$attributes['width'], 'class' => $attributes['class'] ); $anchorAttributes = array ( 'href' => $attributes['url'], 'target' => $attributes['target'], ); foreach ($srcAttributes as $k => $v) { if (empty($v) || is_null($v)) { continue; } $srcAttributesString .= $k . '="' . $v . '" '; } foreach ($anchorAttributes as $k => $v) { if (empty($v) || is_null($v)) { continue; } $anchorAttributesString .= $k . '="' . $v . '" '; } $image = sprintf('<img %s />',$srcAttributesString); return sprintf("<a %s>%s</a>",$anchorAttributesString,$image); } /** * get API URL * */ function getApiUrl($url, $width) { return 'http://s.wordpress.com/mshots/v1/' . urlencode(clean_url($url)) . '?w=' . $width; } add_shortcode('screenshot', 'url2screenshot'); ?>
- スクリーンショット
- WordPressプラグイン