public static function addCard(&$blog, $rawIntroText) { $cfg = EasyBlogHelper::getConfig(); // @rule: Check if user really wants to append the opengraph tags on the headers. if (!$cfg->get('main_twitter_cards')) { return false; } // Get the absolute permalink for this blog item. $url = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $blog->id, false, true); // Get the image of the blog post. $image = self::getImage($blog, $rawIntroText); // @task: Get Joomla's document object. $doc = JFactory::getDocument(); // Add card definition. $doc->addCustomTag('<meta property="twitter:card" content="summary" />'); $doc->addCustomTag('<meta property="twitter:url" content="' . $url . '" />'); $doc->addCustomTag('<meta property="twitter:title" content="' . $blog->title . '" />'); $text = EasyBlogHelper::stripEmbedTags($rawIntroText); $text = strip_tags($text); $text = str_ireplace("\r\n", "", $text); // Remove any " in the content as this would mess up the headers. $text = str_ireplace('"', '', $text); $maxLength = 137; if (!empty($maxLength)) { $text = JString::strlen($text) > $maxLength ? JString::substr($text, 0, $maxLength) . '...' : $text; } $text = EasyBlogStringHelper::escape($text); $doc->addCustomTag('<meta property="twitter:description" content="' . $text . '" />'); if ($image) { $doc->addCustomTag('<meta property="twitter:image" content="' . $image . '"/> '); } return true; }
public static function addOpenGraphTags(&$blog, $rawIntroText = '') { $cfg = EasyBlogHelper::getConfig(); // @rule: Check if user really wants to append the opengraph tags on the headers. if (!$cfg->get('main_facebook_opengraph')) { return false; } // Get the absolute permalink for this blog item. $url = EasyBlogRouter::getRoutedURL('index.php?option=com_easyblog&view=entry&id=' . $blog->id, false, true); // Get the image of the blog post. $image = self::getImage($blog, $rawIntroText); // @task: Get Joomla's document object. $doc = JFactory::getDocument(); // Add the blog image. $doc->addCustomTag('<meta property="og:image" content="' . $image . '"/> '); if ($cfg->get('main_facebook_like')) { $doc->addCustomTag('<meta property="fb:app_id" content="' . $cfg->get('main_facebook_like_appid') . '"/> '); $doc->addCustomTag('<meta property="fb:admins" content="' . $cfg->get('main_facebook_like_admin') . '"/>'); } $meta = EasyBlogHelper::getTable('Meta', 'Table'); $meta->loadByType(META_TYPE_POST, $blog->id); $doc->addCustomTag('<meta property="og:title" content="' . $blog->title . '" />'); // @task: Add description of the blog. if (!empty($meta->description)) { $meta->description = EasyBlogStringHelper::escape($meta->description); $doc->addCustomTag('<meta property="og:description" content="' . $meta->description . '" />'); } else { $maxLength = $cfg->get('integrations_facebook_blogs_length'); $text = EasyBlogHelper::stripEmbedTags($rawIntroText); $text = strip_tags($text); $text = str_ireplace("\r\n", "", $text); // Remove any " in the content as this would mess up the headers. $text = str_ireplace('"', '', $text); if (!empty($maxLength)) { $text = JString::strlen($text) > $maxLength ? JString::substr($text, 0, $maxLength) . '...' : $text; } $text = EasyBlogStringHelper::escape($text); $doc->addCustomTag('<meta property="og:description" content="' . $text . '" />'); } $doc->addCustomTag('<meta property="og:type" content="article" />'); $doc->addCustomTag('<meta property="og:url" content="' . $url . '" />'); return true; }