/** * Load the Facebook Graph API * * @param string $appId Application id * @param string $locale locale e.g 'en_US' * @param array $meta meta tags to add * * @return void|string */ public static function facebookGraphAPI($appId, $locale = 'en_US', $meta = array()) { if (!isset(self::$facebookgraphapi)) { self::$facebookgraphapi = true; return "<div id=\"fb-root\"></div>\r\n\t\t\t<script>\r\n\t\t\twindow.fbAsyncInit = function() {\r\n\t\t\tFB.init({appId: '{$appId}', status: true, cookie: true,\r\n\t\t\txfbml: true});\r\n\t\t};\r\n\t\t(function() {\r\n\t\tvar e = document.createElement('script'); e.async = true;\r\n\t\te.src = document.location.protocol +\r\n\t\t'//connect.facebook.net/{$locale}/all.js';\r\n\t\tdocument.getElementById('fb-root').appendChild(e);\r\n\t\t}());\r\n\t\t</script>"; } $document = JFactory::getDocument(); $data = array('custom' => array()); $typeFound = false; foreach ($meta as $k => $v) { if (is_array($v)) { $v = implode(',', $v); } $v = strip_tags($v); // $$$ rob og:type required if ($k == 'og:type') { $typeFound = true; if ($v == '') { $v = 'article'; } } $data['custom'][] = '<meta property="' . $k . '" content="' . $v . '"/>'; } if (!$typeFound) { $data['custom'][] = '<meta property="og:type" content="article"/>'; } $document->setHeadData($data); }
public function facebookGraphAPI($appid, $locale = 'en_US', $meta = array()) { if (!isset(self::$facebookgraphapi)) { self::$facebookgraphapi = true; return "<div id=\"fb-root\"></div> <script> window.fbAsyncInit = function() { FB.init({appId: '$appid', status: true, cookie: true, xfbml: true}); }; (function() { var e = document.createElement('script'); e.async = true; e.src = document.location.protocol + '//connect.facebook.net/$locale/all.js'; document.getElementById('fb-root').appendChild(e); }()); </script>"; } $document = JFactory::getDocument(); $data = array('custom'=>array()); $typeFound = false; foreach ($meta as $k => $v) { $v = strip_tags($v); //og:type required if ($k == 'og:type') { $typeFound = true; if ($v == '') { $v = 'article'; } } $data['custom'][] = "<meta property=\"$k\" content=\"$v\"/>"; } if (!$typeFound) { $data['custom'][] = "<meta property=\"og:type\" content=\"article\"/>"; } $document->setHeadData($data); }