Support for twitter cards (in both directions)

This commit is contained in:
Michael Vogel 2014-02-22 15:46:19 +01:00
parent bc69e57636
commit 608d5255ec
3 changed files with 86 additions and 46 deletions

View file

@ -203,6 +203,10 @@ function display_content(&$a, $update = 0) {
$title = trim(html2plain(bbcode($r[0]["title"], false, false), 0, true));
$author_name = $r[0]["author-name"];
$image = "";
if ($image == "")
$image = $r[0]["thumb"];
if ($title == "")
$title = $author_name;
@ -219,9 +223,16 @@ function display_content(&$a, $update = 0) {
// Schema.org microdata
$a->page['htmlhead'] .= '<meta itemprop="name" content="'.$title.'" />'."\n";
$a->page['htmlhead'] .= '<meta itemprop="description" content="'.$description.'" />'."\n";
$a->page['htmlhead'] .= '<meta itemprop="image" content="'.$r[0]["thumb"].'" />'."\n";
$a->page['htmlhead'] .= '<meta itemprop="image" content="'.$image.'" />'."\n";
$a->page['htmlhead'] .= '<meta itemprop="author" content="'.$author_name.'" />'."\n";
// Twitter cards
$a->page['htmlhead'] .= '<meta name="twitter:card" content="summary" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$title.'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:description" content="'.$description.'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$image.'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:url" content="'.$r[0]["plink"].'" />'."\n";
// Dublin Core
$a->page['htmlhead'] .= '<meta name="DC.title" content="'.$title.'" />'."\n";
$a->page['htmlhead'] .= '<meta name="DC.description" content="'.$description.'" />'."\n";
@ -229,7 +240,7 @@ function display_content(&$a, $update = 0) {
// Open Graph
$a->page['htmlhead'] .= '<meta property="og:type" content="website" />'."\n";
$a->page['htmlhead'] .= '<meta property="og:title" content="'.$title.'" />'."\n";
$a->page['htmlhead'] .= '<meta property="og:image" content="'.$r[0]["thumb"].'" />'."\n";
$a->page['htmlhead'] .= '<meta property="og:image" content="'.$image.'" />'."\n";
$a->page['htmlhead'] .= '<meta property="og:url" content="'.$r[0]["plink"].'" />'."\n";
$a->page['htmlhead'] .= '<meta property="og:description" content="'.$description.'" />'."\n";
$a->page['htmlhead'] .= '<meta name="og:article:author" content="'.$author_name.'" />'."\n";

View file

@ -52,6 +52,9 @@ function completeurl($url, $scheme) {
function parseurl_getsiteinfo($url, $no_guessing = false) {
$siteinfo = array();
$siteinfo["type"] = "link";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
@ -165,6 +168,18 @@ function parseurl_getsiteinfo($url, $no_guessing = false) {
case "description":
$siteinfo["text"] = $attr["content"];
break;
case "twitter:image":
$siteinfo["image"] = $attr["content"];
break;
case "twitter:card":
$siteinfo["type"] = $attr["content"];
break;
case "twitter:description":
$siteinfo["text"] = $attr["content"];
break;
case "twitter:title":
$siteinfo["title"] = $attr["content"];
break;
case "dc.title":
$siteinfo["title"] = $attr["content"];
break;
@ -311,9 +326,9 @@ function parse_url_content(&$a) {
logger('parse_url: ' . $url);
if($textmode)
$template = '[bookmark=%s]%s[/bookmark]%s' . $br;
$template = '[bookmark=%s]%s[/bookmark]%s';
else
$template = "<a class=\"bookmark\" href=\"%s\" >%s</a>%s<br />";
$template = "<a class=\"bookmark\" href=\"%s\" >%s</a>%s";
$arr = array('url' => $url, 'text' => '');
@ -386,9 +401,10 @@ function parse_url_content(&$a) {
$text = '<blockquote>'.htmlspecialchars(trim($text)).'</blockquote>';
}
if($image) {
if($image)
$text = $br.$br.$image.$text;
}
else
$text = $br.$text;
$title = str_replace(array("\r","\n"),array('',''),$title);
@ -398,7 +414,10 @@ function parse_url_content(&$a) {
$sitedata .= trim($result);
if (($siteinfo["type"] != "photo"))
echo "[class=type-link]".$sitedata."[/class]";
else
echo "[class=type-photo]".$title.$br.$image."[/class]";
killme();
}

View file

@ -1368,7 +1368,11 @@ function photos_content(&$a) {
$photo = array(
'href' => $a->get_baseurl() . '/photo/' . $hires['resource-id'] . '-' . $hires['scale'] . '.' . $phototypes[$hires['type']],
'title'=> t('View Full Size'),
'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis')
'src' => $a->get_baseurl() . '/photo/' . $lores['resource-id'] . '-' . $lores['scale'] . '.' . $phototypes[$lores['type']] . '?f=&_u=' . datetime_convert('','','','ymdhis'),
'height' => $hires['height'],
'width' => $hires['width'],
'album' => $hires['album'],
'filename' => $hires['filename'],
);
if($nextlink)
@ -1723,6 +1727,12 @@ function photos_content(&$a) {
'$paginate' => $paginate,
));
$a->page['htmlhead'] .= "\n".'<meta name="twitter:card" content="photo" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:title" content="'.$photo["album"].'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:image" content="'.$photo["href"].'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:image:width" content="'.$photo["width"].'" />'."\n";
$a->page['htmlhead'] .= '<meta name="twitter:image:height" content="'.$photo["height"].'" />'."\n";
return $o;
}