private function _sh404sefGetSocialButtons($sefConfig, $url = '', $context = '', $content = null) { // if no URL, use current if (empty($url)) { // no url set on social button tag, we should // use current URL, except if we are on a page // where this would cause the wrong url to be shared // try identify this condition if ($this->_shouldDisplaySocialButtons($sefConfig, $context, $content)) { Sh404sefHelperShurl::updateShurls(); $pageInfo = Sh404sefFactory::getPageInfo(); $url = !$this->_params->get('useShurl', true) || empty($pageInfo->shURL) ? JURI::current() : JURI::base() . $pageInfo->shURL; } else { return ''; } } // buttons html $buttonsHtml = ''; // get language from Joomla $longLang = JFactory::getLanguage()->getTag(); // networks use en_GB, not en-GB $shortLang = substr($longLang, 0, 2); // we wrap buttons in unordered list $wrapperOpen = '<li>'; $wrapperClose = '</li>'; // Tweet if ($this->_params->get('enableTweet', true) && in_array('twitter', $this->_enabledButtons)) { $buttonsHtml .= $wrapperOpen . '<a href="https://twitter.com/share" data-via="' . $this->_params->get('viaAccount', '') . '" data-count="' . $this->_params->get('tweetLayout', 'none') . '" data-url="' . $url . '" data-lang="' . $shortLang . '" class="twitter-share-button">Tweet</a>' . $wrapperClose; } // plus One if ($this->_params->get('enablePlusOne', true) && in_array('googleplusone', $this->_enabledButtons)) { $buttonsHtml .= $wrapperOpen . '<g:plusone callback="_sh404sefSocialTrackGPlusTracking" annotation="' . $this->_params->get('plusOneAnnotation', 'none') . '" size="' . $this->_params->get('plusOneSize', '') . '" href="' . $url . '"></g:plusone>' . $wrapperClose; } // Google plus page badge $page = $this->_params->get('googlePlusPage', ''); $page = JString::trim($page, '/'); if ($this->_params->get('enableGooglePlusPage', true) && in_array('googlepluspage', $this->_enabledButtons) && !empty($page)) { $buttonsHtml .= $wrapperOpen . '<a class="google-page-badge" onclick="_sh404sefSocialTrack.GPageTracking(\'/' . $page . '/\', \'' . $url . '\')" href="https://plus.google.com/' . $page . '/?prsrc=3">'; // badge image switch ($this->_params->get('googlePlusPageSize', 'medium')) { case 'small': $size = '16'; $buttonsHtml .= '<div style="display: inline-block;">'; // custom text if ($this->_params->get('googlePlusCustomText', '')) { $buttonsHtml .= '<span style="float: left; font: bold 13px/16px arial,sans-serif; margin-right: 4px;">' . htmlspecialchars($this->_params->get('googlePlusCustomText', '')) . '</span><span style="float: left; font: 13px/16px arial,sans-serif; margin-right: 11px;">' . htmlspecialchars($this->_params->get('googlePlusCustomText2', '')) . '</span>'; } $buttonsHtml .= '<div style="float: left;"><img src="https://ssl.gstatic.com/images/icons/gplus-16.png" width="16" height="16" style="border: 0;"/></div><div style="clear: both"></div>'; break; case 'large': $size = '64'; $buttonsHtml .= '<div style="display: inline-block; *display: inline;"><div style="text-align: center;"><img src="https://ssl.gstatic.com/images/icons/gplus-64.png" width="64" height="64" style="border: 0;"></img></div><div style="font: bold 13px/16px arial,sans-serif; text-align: center;">' . $this->_params->get('googlePlusCustomText', '') . '</div><div style="font: 13px/16px arial,sans-serif; text-align: center;">' . htmlspecialchars($this->_params->get('googlePlusCustomText2', '')) . '</div>'; break; default: $size = '32'; $buttonsHtml .= '<div style="display: inline-block;">'; // custom text if ($this->_params->get('googlePlusCustomText', '')) { $buttonsHtml .= '<span style="float: left; font: bold 13px/16px arial,sans-serif; margin-right: 4px; margin-top: 7px;">' . htmlspecialchars($this->_params->get('googlePlusCustomText', '')) . '</span><span style="float: left; font: 13px/16px arial,sans-serif; margin-right: 11px; margin-top: 7px;">' . htmlspecialchars($this->_params->get('googlePlusCustomText2', '')) . '</span>'; } $buttonsHtml .= '<div style="float: left;"><img src="https://ssl.gstatic.com/images/icons/gplus-32.png" width="32" height="32" style="border: 0;"/></div><div style="clear: both"></div>'; break; } $buttonsHtml .= '</div></a>' . $wrapperClose; } // FB Like if ($this->_params->get('enableFbLike', 1) && in_array('facebooklike', $this->_enabledButtons)) { $layout = $this->_params->get('fbLayout', '') == 'none' ? '' : $this->_params->get('fbLayout', ''); if ($this->_params->get('fbUseHtml5', false)) { $buttonsHtml .= $wrapperOpen . '<div class="fb-like" data-href="' . $url . '" data-send="' . ($this->_params->get('enableFbSend', 1) ? 'true' : 'false') . '" data-action="' . $this->_params->get('fbAction', '') . '" data-width="' . $this->_params->get('fbWidth', '') . '" data-layout="' . $layout . '" data-show-faces="' . $this->_params->get('fbShowFaces', 'true') . '" data-colorscheme="' . $this->_params->get('fbColorscheme', 'light') . '"></div>' . $wrapperClose; } else { $buttonsHtml .= $wrapperOpen . '<fb:like href="' . $url . '" send="' . ($this->_params->get('enableFbSend', 1) ? 'true' : 'false') . '" action="' . $this->_params->get('fbAction', '') . '" width="' . $this->_params->get('fbWidth', '') . '" layout="' . $layout . '" show_faces="' . $this->_params->get('fbShowFaces', 'true') . '" colorscheme="' . $this->_params->get('fbColorscheme', '') . '"></fb:like>' . $wrapperClose; } } else { if ($this->_params->get('enableFbSend', 1) && in_array('facebooksend', $this->_enabledButtons)) { if ($this->_params->get('fbUseHtml5', false)) { $buttonsHtml .= $wrapperOpen . '<div class="fb-send" data-href="' . $url . '" data-colorscheme="' . $this->_params->get('fbColorscheme', '') . '"></div>' . $wrapperClose; } else { $buttonsHtml .= $wrapperOpen . '<fb:send href="' . $url . '" colorscheme="' . $this->_params->get('fbColorscheme', '') . '"></fb:send>' . $wrapperClose; } } } // perform replace if (!empty($buttonsHtml)) { $buttonsHtml = '<div class="sh404sef-social-buttons"><ul>' . $buttonsHtml . '</ul></div>'; } return $buttonsHtml; }
private function _sh404sefGetSocialButtons($sefConfig, $url = '', $context = '', $content = null, $imageSrc = '', $imageDesc = '') { // if no URL, use current if (empty($url)) { // no url set on social button tag, we should // use current URL, except if we are on a page // where this would cause the wrong url to be shared // try identify this condition if ($this->_shouldDisplaySocialButtons($sefConfig, $context, $content)) { Sh404sefHelperShurl::updateShurls(); $pageInfo = Sh404sefFactory::getPageInfo(); $url = !$this->_params->get('useShurl', true) || empty($pageInfo->shURL) ? JURI::current() : JURI::base() . ltrim($sefConfig->shRewriteStrings[$sefConfig->shRewriteMode], '/') . $pageInfo->shURL; } else { return ''; } } // buttons html $buttonsHtml = ''; // get language from Joomla $longLang = JFactory::getLanguage()->getTag(); // networks use en_GB, not en-GB $shortLang = substr($longLang, 0, 2); // we wrap buttons in unordered list $wrapperOpen = '<li>'; $wrapperClose = '</li>'; // Tweet if ($this->_params->get('enableTweet', true) && in_array('twitter', $this->_enabledButtons)) { $buttonsHtml .= $wrapperOpen . '<a href="https://twitter.com/share" data-via="' . $this->_params->get('viaAccount', '') . '" data-count="' . $this->_params->get('tweetLayout', 'none') . '" data-url="' . $url . '" data-lang="' . $shortLang . '" class="twitter-share-button">Tweet</a>' . $wrapperClose; } // plus One if ($this->_params->get('enablePlusOne', true) && in_array('googleplusone', $this->_enabledButtons)) { $buttonsHtml .= $wrapperOpen . '<g:plusone callback="_sh404sefSocialTrackGPlusTracking" annotation="' . $this->_params->get('plusOneAnnotation', 'none') . '" size="' . $this->_params->get('plusOneSize', '') . '" href="' . $url . '"></g:plusone>' . $wrapperClose; } // Google plus page badge $page = $this->_params->get('googlePlusPage', ''); $page = JString::trim($page, '/'); if ($this->_params->get('enableGooglePlusPage', true) && in_array('googlepluspage', $this->_enabledButtons) && !empty($page)) { $buttonsHtml .= $wrapperOpen . '<a class="google-page-badge" onclick="_sh404sefSocialTrack.GPageTracking(\'/' . $page . '/\', \'' . $url . '\')" href="https://plus.google.com/' . $page . '/?prsrc=3">'; // badge image switch ($this->_params->get('googlePlusPageSize', 'medium')) { case 'small': $size = '16'; $buttonsHtml .= '<div style="display: inline-block;">'; // custom text if ($this->_params->get('googlePlusCustomText', '')) { $buttonsHtml .= '<span style="float: left; font: bold 13px/16px arial,sans-serif; margin-right: 4px;">' . htmlspecialchars($this->_params->get('googlePlusCustomText', '')) . '</span><span style="float: left; font: 13px/16px arial,sans-serif; margin-right: 11px;">' . htmlspecialchars($this->_params->get('googlePlusCustomText2', '')) . '</span>'; } $buttonsHtml .= '<div style="float: left;"><img src="https://ssl.gstatic.com/images/icons/gplus-16.png" width="16" height="16" style="border: 0;"/></div><div style="clear: both"></div>'; break; case 'large': $size = '64'; $buttonsHtml .= '<div style="display: inline-block; *display: inline;"><div style="text-align: center;"><img src="https://ssl.gstatic.com/images/icons/gplus-64.png" width="64" height="64" style="border: 0;"></img></div><div style="font: bold 13px/16px arial,sans-serif; text-align: center;">' . $this->_params->get('googlePlusCustomText', '') . '</div><div style="font: 13px/16px arial,sans-serif; text-align: center;">' . htmlspecialchars($this->_params->get('googlePlusCustomText2', '')) . '</div>'; break; default: $size = '32'; $buttonsHtml .= '<div style="display: inline-block;">'; // custom text if ($this->_params->get('googlePlusCustomText', '')) { $buttonsHtml .= '<span style="float: left; font: bold 13px/16px arial,sans-serif; margin-right: 4px; margin-top: 7px;">' . htmlspecialchars($this->_params->get('googlePlusCustomText', '')) . '</span><span style="float: left; font: 13px/16px arial,sans-serif; margin-right: 11px; margin-top: 7px;">' . htmlspecialchars($this->_params->get('googlePlusCustomText2', '')) . '</span>'; } $buttonsHtml .= '<div style="float: left;"><img src="https://ssl.gstatic.com/images/icons/gplus-32.png" width="32" height="32" style="border: 0;"/></div><div style="clear: both"></div>'; break; } $buttonsHtml .= '</div></a>' . $wrapperClose; } // Pinterest if ($this->_params->get('enablePinterestPinIt', 1) && in_array('pinterestpinit', $this->_enabledButtons)) { // we use either the first image in content, or the provided one (from a user created tag) if (empty($imageSrc)) { // we're using the first image in the content $regExp = '#<img([^>]*)/>#is'; $text = empty($content->fulltext) ? $content->introtext : $content->introtext . $content->fulltext; $img = preg_match($regExp, $text, $match); if (empty($img) || empty($match[1])) { // could not find an image in the article // last chance is maybe webmaster is using Joomla! full text image article feature // note: if we are not on the canonical page (ie the full article display), Joomla! // uses the image_intro instead. However, I decided to still pin the full image // in such case, as the image_intro will most often be a thumbnail // Is this correct? can there be side effects? $imageSrc = ''; if ($context == 'com_content.article' && !empty($content->images)) { $registry = new JRegistry(); $registry->loadString($content->images); $fulltextImage = $registry->get('image_fulltext'); if (!empty($fulltextImage)) { $imageSrc = $fulltextImage; $imageDesc = $registry->get('image_fulltext_alt', ''); } } } else { // extract image details jimport('joomla.utilities.utility'); $attributes = JUtility::parseAttributes($match[1]); $imageSrc = empty($attributes['src']) ? '' : $attributes['src']; $imageDesc = empty($attributes['alt']) ? '' : $attributes['alt']; } } if (!empty($imageSrc)) { if (substr($imageSrc, 0, 4) != 'http' && substr($imageSrc, 0, 1) != '/') { // relative url, prepend root url $imageSrc = JURI::base() . $imageSrc; } $buttonsHtml .= $wrapperOpen; $buttonsHtml .= '<a href="http://pinterest.com/pin/create/button/?url=' . urlencode($url) . '&media=' . urlencode($imageSrc) . (empty($imageDesc) ? '' : '&description=' . urlencode($imageDesc)) . '" ' . 'class="pin-it-button" count-layout="' . $this->_params->get('pinItCountLayout', 'none') . '">' . $this->_params->get('pinItButtonText', 'Pin it') . '</a>'; $buttonsHtml .= $wrapperClose; } } // FB Like if ($this->_params->get('enableFbLike', 1) && in_array('facebooklike', $this->_enabledButtons)) { $layout = $this->_params->get('fbLayout', '') == 'none' ? '' : $this->_params->get('fbLayout', ''); if ($this->_params->get('fbUseHtml5', false)) { $buttonsHtml .= $wrapperOpen . '<div class="fb-like" data-href="' . $url . '" data-send="' . ($this->_params->get('enableFbSend', 1) ? 'true' : 'false') . '" data-action="' . $this->_params->get('fbAction', '') . '" data-width="' . $this->_params->get('fbWidth', '') . '" data-layout="' . $layout . '" data-show-faces="' . $this->_params->get('fbShowFaces', 'true') . '" data-colorscheme="' . $this->_params->get('fbColorscheme', 'light') . '"></div>' . $wrapperClose; } else { $buttonsHtml .= $wrapperOpen . '<fb:like href="' . $url . '" send="' . ($this->_params->get('enableFbSend', 1) ? 'true' : 'false') . '" action="' . $this->_params->get('fbAction', '') . '" width="' . $this->_params->get('fbWidth', '') . '" layout="' . $layout . '" show_faces="' . $this->_params->get('fbShowFaces', 'true') . '" colorscheme="' . $this->_params->get('fbColorscheme', '') . '"></fb:like>' . $wrapperClose; } } else { if ($this->_params->get('enableFbSend', 1) && in_array('facebooksend', $this->_enabledButtons)) { if ($this->_params->get('fbUseHtml5', false)) { $buttonsHtml .= $wrapperOpen . '<div class="fb-send" data-href="' . $url . '" data-colorscheme="' . $this->_params->get('fbColorscheme', '') . '"></div>' . $wrapperClose; } else { $buttonsHtml .= $wrapperOpen . '<fb:send href="' . $url . '" colorscheme="' . $this->_params->get('fbColorscheme', '') . '"></fb:send>' . $wrapperClose; } } } // perform replace if (!empty($buttonsHtml)) { $buttonsHtml = '<div class="sh404sef-social-buttons"><ul>' . $buttonsHtml . '</ul></div>'; } return $buttonsHtml; }
function onAfterDispatch() { $mainframe =& JFactory::getApplication(); if (!$mainframe->isAdmin()) { $this->setTemplate(); // fix base tag when using Joomfish if (defined('SH404SEF_IS_RUNNING')) { // set base url, as Joomla! does not handle // UTF-8 urls. Will also fix base tag when running Joomfish $document =& JFactory::getDocument(); if ($document->getType() == 'html') { if (!shIsCurrentPageHome()) { $shPageInfo =& shRouter::shPageInfo(); $document->setBase(htmlspecialchars($shPageInfo->baseUrl, ENT_COMPAT, 'UTF-8')); } // shortlinks Sh404sefHelperShurl::updateShurls(); } } } }
public function onAfterDispatch() { $app =& JFactory::getApplication(); if (!$app->isAdmin() && defined('SH404SEF_IS_RUNNING')) { // reset alternate template $this->_resetAlternateTemplate(); // create shurl on the fly for this page // if not already done if (JFactory::getDocument()->getType() == 'html') { // shortlinks Sh404sefHelperShurl::updateShurls(); } } }