public function setSocialForMeta(&$meta, $siteMeta, $social, $helper, $identity, $locale)
{
if ($meta) {
/* -- Set up the title prefix and suffix */
$titlePrefix = "";
/* -- We now do this in sanitizeMetaVars() so this can be changed in Twig just like the seoTitle
if ($siteMeta['siteSeoTitlePlacement'] == "before")
$titlePrefix = $siteMeta['siteSeoName'] . " " . $siteMeta['siteSeoTitleSeparator'] . " ";
*/
$titleSuffix = "";
/* -- We now do this in sanitizeMetaVars() so this can be changed in Twig just like the seoTitle
if ($siteMeta['siteSeoTitlePlacement'] == "after")
$titleSuffix = " " . $siteMeta['siteSeoTitleSeparator'] . " " . $siteMeta['siteSeoName'];
*/
/* -- Add in the Twitter Card settings to the meta */
if ($social['twitterHandle']) {
$twitterCard = array();
$twitterCard['card'] = $meta['twitterCardType'];
$twitterCard['site'] = "@" . ltrim($social['twitterHandle'], '@');
switch ($twitterCard['card']) {
case 'summary_large_image':
$twitterCard['creator'] = "@" . ltrim($social['twitterHandle'], '@');
break;
default:
$twitterCard['creator'] = "";
break;
}
$twitterCard['title'] = $titlePrefix . $meta['seoTitle'] . $titleSuffix;
$twitterCard['description'] = $meta['seoDescription'];
/* -- Swap in the seoImageId for the actual asset */
$imgId = 0;
if (isset($meta['seoImageId'])) {
$imgId = $meta['seoImageId'];
}
if (isset($meta['seoTwitterImageId']) && $meta['seoTwitterImageId'] != 0) {
$imgId = $meta['seoTwitterImageId'];
}
if ($imgId) {
$image = craft()->assets->getFileById($imgId);
if ($image) {
$imgUrl = $image->getUrl($meta['seoTwitterImageTransform']);
if (!$imgUrl) {
$imgUrl = $image->url;
}
$twitterCard['image'] = $this->getFullyQualifiedUrl($imgUrl);
} else {
$twitterCard['image'] = '';
}
} else {
$twitterCard['image'] = '';
}
$meta['twitter'] = $twitterCard;
}
/* -- Add in the Facebook Open Graph settings to the meta */
$openGraph = array();
$openGraph['type'] = $meta['openGraphType'];
/* -- Kludges to keep Facebook happy */
if ($locale == "en") {
$openGraph['locale'] = 'en_US';
} else {
$openGraph['locale'] = $locale;
}
if (strlen($openGraph['locale']) == 2) {
$openGraph['locale'] = $openGraph['locale'] . "_" . strtoupper($openGraph['locale']);
}
$openGraph['url'] = $meta['canonicalUrl'];
$openGraph['title'] = $titlePrefix . $meta['seoTitle'] . $titleSuffix;
$openGraph['description'] = $meta['seoDescription'];
/* -- Swap in the seoImageId for the actual asset */
$imgId = 0;
if (isset($meta['seoImageId'])) {
$imgId = $meta['seoImageId'];
}
if (isset($meta['seoFacebookImageId']) && $meta['seoFacebookImageId'] != 0) {
$imgId = $meta['seoFacebookImageId'];
}
if ($imgId) {
$image = craft()->assets->getFileById($imgId);
if ($image) {
$imgUrl = $image->getUrl($meta['seoFacebookImageTransform']);
if (!$imgUrl) {
$imgUrl = $image->url;
$openGraph['image'] = $this->getFullyQualifiedUrl($imgUrl);
$openGraph['image:type'] = $image->getMimeType();
$openGraph['image:width'] = $image->getWidth();
$openGraph['image:height'] = $image->getHeight();
} else {
$openGraph['image'] = $this->getFullyQualifiedUrl($imgUrl);
$openGraph['image:type'] = $image->getMimeType();
$openGraph['image:width'] = $image->getWidth($meta['seoFacebookImageTransform']);
$openGraph['image:height'] = $image->getHeight($meta['seoFacebookImageTransform']);
}
} else {
$openGraph['image'] = '';
}
} else {
$openGraph['image'] = '';
}
$openGraph['site_name'] = $siteMeta['siteSeoName'];
$sameAs = array();
array_push($sameAs, $helper['twitterUrl']);
array_push($sameAs, $helper['facebookUrl']);
array_push($sameAs, $helper['googlePlusUrl']);
array_push($sameAs, $helper['linkedInUrl']);
array_push($sameAs, $helper['youtubeUrl']);
array_push($sameAs, $helper['youtubeChannelUrl']);
array_push($sameAs, $helper['instagramUrl']);
array_push($sameAs, $helper['pinterestUrl']);
array_push($sameAs, $helper['githubUrl']);
array_push($sameAs, $helper['vimeoUrl']);
$sameAs = array_filter($sameAs);
$sameAs = array_values($sameAs);
if (!empty($sameAs)) {
$openGraph['see_also'] = $sameAs;
}
$meta['og'] = $openGraph;
/* -- Handle Open Graph articles */
if ($openGraph['type'] == "article") {
$openGraphArticle = array();
$openGraphArticle['author'] = $helper['facebookUrl'];
$openGraphArticle['publisher'] = $helper['facebookUrl'];
$openGraphArticle['tag'] = array_map('trim', explode(',', $meta['seoKeywords']));
/* -- If an element was injected into the current template, scrape it for attribuates */
if ($this->lastElement) {
$elemType = $this->lastElement->getElementType();
switch ($elemType) {
case ElementType::Entry:
if ($this->lastElement->dateUpdated) {
$openGraphArticle['modified_time'] = $this->lastElement->dateUpdated->iso8601();
}
if ($this->lastElement->postDate) {
$openGraphArticle['published_time'] = $this->lastElement->postDate->iso8601();
}
break;
case "Commerce_Product":
if ($this->lastElement->dateUpdated) {
$openGraphArticle['modified_time'] = $this->lastElement->dateUpdated->iso8601();
}
if ($this->lastElement->postDate) {
$openGraphArticle['published_time'] = $this->lastElement->postDate->iso8601();
}
break;
case ElementType::Category:
if ($this->lastElement->dateUpdated) {
$openGraphArticle['modified_time'] = $this->lastElement->dateUpdated->iso8601();
}
if ($this->lastElement->dateCreated) {
$openGraphArticle['published_time'] = $this->lastElement->dateCreated->iso8601();
}
break;
}
}
$meta['article'] = $openGraphArticle;
}
}
}