function shInsertOpenGraphData(&$buffer) { // get sh404sef config $sefConfig =& Sh404sefFactory::getConfig(); $pageInfo =& Sh404sefFactory::getPageInfo(); if (empty($sefConfig->shMetaManagementActivated) || !isset($sefConfig) || empty($pageInfo->currentNonSefUrl) || !empty($pageInfo->httpStatus) && $pageInfo->httpStatus == 404) { return; } $nonSef = shGetCurrentNonSef(); $customData = shGetCustomMetaData($nonSef); // user can disable per url if ($customData->og_enable == SH404SEF_OPTION_VALUE_NO || empty($sefConfig->enableOpenGraphData) && $customData->og_enable == SH404SEF_OPTION_VALUE_USE_DEFAULT) { return; } $openGraphData = ''; $ogNameSpace = ''; $fbNameSpace = ''; // add locale - FB use underscore in language tags $locale = str_replace('-', '_', JFactory::getLanguage()->getTag()); $openGraphData .= "\n" . ' <meta property="og:locale" content="' . $locale . '" />'; // insert title if (!empty($pageInfo->pageTitle)) { $openGraphData .= "\n" . ' <meta property="og:title" content="' . $pageInfo->pageTitle . '" />'; } // insert description if (($sefConfig->ogEnableDescription && $customData->og_enable_description == SH404SEF_OPTION_VALUE_USE_DEFAULT || $customData->og_enable_description == SH404SEF_OPTION_VALUE_YES) && !empty($pageInfo->pageDescription)) { $openGraphData .= "\n" . ' <meta property="og:description" content="' . $pageInfo->pageDescription . '" />'; } // insert type $content = $customData->og_type == SH404SEF_OPTION_VALUE_USE_DEFAULT ? $sefConfig->ogType : $customData->og_type; if (!empty($content)) { $openGraphData .= "\n" . ' <meta property="og:type" content="' . $content . '" />'; } // insert url. If any, we insert the canonical url rather than current, to consolidate $content = empty($pageInfo->pageCanonicalUrl) ? $pageInfo->currentSefUrl : $pageInfo->pageCanonicalUrl; $content = Sh404sefHelperGeneral::stripTrackingVarsFromSef($content); $openGraphData .= "\n" . ' <meta property="og:url" content="' . htmlspecialchars($content, ENT_COMPAT, 'UTF-8') . '" />'; // insert image $content = empty($customData->og_image) ? $sefConfig->ogImage : $customData->og_image; if (!empty($content)) { $content = JURI::root(false, '') . JString::ltrim($content, '/'); $openGraphData .= "\n" . ' <meta property="og:image" content="' . $content . '" />'; } // insert site name if ($sefConfig->ogEnableSiteName && $customData->og_enable_site_name == SH404SEF_OPTION_VALUE_USE_DEFAULT || $customData->og_enable_site_name == SH404SEF_OPTION_VALUE_YES) { $content = empty($customData->og_site_name) ? $sefConfig->ogSiteName : $customData->og_site_name; $content = empty($content) ? JFactory::getApplication()->getCfg('sitename') : $content; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:site_name" content="' . $content . '" />'; } } // insert location // disabled: Facebook removed all of that after reducing number of object types to bare minimum if (false && ($sefConfig->ogEnableLocation && $customData->og_enable_location == SH404SEF_OPTION_VALUE_USE_DEFAULT || $customData->og_enable_location == SH404SEF_OPTION_VALUE_YES)) { $content = empty($customData->og_latitude) ? $sefConfig->ogLatitude : $customData->og_latitude; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:latitude" content="' . $content . '" />'; } $content = empty($customData->og_longitude) ? $sefConfig->ogLongitude : $customData->og_longitude; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:longitude" content="' . $content . '" />'; } $content = empty($customData->og_street_address) ? $sefConfig->ogStreetAddress : $customData->og_street_address; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:street-address" content="' . $content . '" />'; } $content = empty($customData->og_locality) ? $sefConfig->ogLocality : $customData->og_locality; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:locality" content="' . $content . '" />'; } $content = empty($customData->og_postal_code) ? $sefConfig->ogPostalCode : $customData->og_postal_code; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:postal-code" content="' . $content . '" />'; } $content = empty($customData->og_region) ? $sefConfig->ogRegion : $customData->og_region; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:region" content="' . $content . '" />'; } $content = empty($customData->og_country_name) ? $sefConfig->ogCountryName : $customData->og_country_name; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:country-name" content="' . $content . '" />'; } } // insert contact // disabled: Facebook removed all of that after reducing number of object types to bare minimum if (false && ($sefConfig->ogEnableContact && $customData->og_enable_contact == SH404SEF_OPTION_VALUE_USE_DEFAULT || $customData->og_enable_contact == SH404SEF_OPTION_VALUE_YES)) { $content = empty($customData->og_email) ? $sefConfig->ogEmail : $customData->og_email; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:email" content="' . $content . '" />'; } $content = empty($customData->og_phone_number) ? $sefConfig->ogPhoneNumber : $customData->og_phone_number; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:phone_number" content="' . $content . '" />'; } $content = empty($customData->og_fax_number) ? $sefConfig->ogFaxNumber : $customData->og_fax_number; if (!empty($content)) { $content = htmlspecialchars(shCleanUpDesc($content), ENT_COMPAT, 'UTF-8'); $openGraphData .= "\n" . ' <meta property="og:fax_number" content="' . $content . '" />'; } } if (!empty($openGraphData)) { $ogNameSpace = 'xmlns:og="http://ogp.me/ns#"'; } // insert fb admin id if (!empty($sefConfig->fbAdminIds) && $customData->og_enable_fb_admin_ids == SH404SEF_OPTION_VALUE_USE_DEFAULT || $customData->og_enable_fb_admin_ids == SH404SEF_OPTION_VALUE_YES) { $content = empty($customData->fb_admin_ids) ? $sefConfig->fbAdminIds : $customData->fb_admin_ids; if ($customData->og_enable_fb_admin_ids != SH404SEF_OPTION_VALUE_NO && !empty($content)) { $openGraphData .= "\n" . ' <meta property="fb:admins" content="' . $content . '" />'; $fbNameSpace = 'xmlns:fb="https://www.facebook.com/2008/fbml"'; } } // actually insert the tags if (!empty($openGraphData)) { $buffer = shInsertCustomTagInBuffer($buffer, '<head>', 'after', $openGraphData, 'first'); } if (!empty($fbNameSpace) || !empty($ogNameSpace)) { // insert as well namespaces $buffer = str_replace('<html ', '<html ' . $ogNameSpace . ' ' . $fbNameSpace . ' ', $buffer); } }