/** * Render a share button * * @param boolean $loadJs * @return string */ public function render($loadJs = TRUE) { if (!empty($this->arguments['type'])) { $this->tag->addAttribute('data-type', $this->arguments['type']); $this->tag->removeAttribute('type'); } else { $this->tag->addAttribute('data-type', 'button_count'); } $shareUrl = empty($this->arguments['shareurl']) ? \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') : $this->arguments['shareurl']; $this->tag->addAttribute('data-href', $shareUrl); $this->tag->removeAttribute('shareurl'); $this->tag->addAttribute('class', 'fb-share-button'); $this->tag->setContent(' '); $code = $this->tag->render(); if ($loadJs) { $code .= '<div id="fb-root"></div> <script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/de_DE/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, \'script\', \'facebook-jssdk\'));</script>'; } // Social interaction Google Analytics if ($this->pluginSettingsService->getByPath('analytics.social.facebookShare') == 1) { $code .= \TYPO3\CMS\Core\Utility\GeneralUtility::wrapJS("\n\t\t\t\tFB.Event.subscribe('message.send', function(targetUrl) {\n\t\t\t\t _gaq.push(['_trackSocial', 'facebook', 'send', targetUrl]);\n\t\t\t\t});\n\t\t\t"); } return $code; }
/** * Render the facebook like viewhelper * * @return string */ public function render() { $code = ''; $url = !empty($this->arguments['href']) ? $this->arguments['href'] : \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL'); // absolute urls are needed $this->tag->addAttribute('href', Tx_News_Utility_Url::prependDomain($url)); $this->tag->forceClosingTag(TRUE); // -1 means no JS if ($this->arguments['javaScript'] != '-1') { if (empty($this->arguments['javaScript'])) { $tsSettings = $this->pluginSettingsService->getSettings(); $locale = !empty($tsSettings['facebookLocale']) && strlen($tsSettings['facebookLocale']) <= 5 ? $tsSettings['facebookLocale'] : 'en_US'; $code = '<script src="https://connect.facebook.net/' . $locale . '/all.js#xfbml=1"></script>'; // Social interaction Google Analytics if ($this->pluginSettingsService->getByPath('analytics.social.facebookLike') == 1) { $code .= \TYPO3\CMS\Core\Utility\GeneralUtility::wrapJS("\n\t\t\t\t\t\tFB.Event.subscribe('edge.create', function(targetUrl) {\n\t\t\t\t\t\t \t_gaq.push(['_trackSocial', 'facebook', 'like', targetUrl]);\n\t\t\t\t\t\t});\n\t\t\t\t\t\tFB.Event.subscribe('edge.remove', function(targetUrl) {\n\t\t\t\t\t\t _gaq.push(['_trackSocial', 'facebook', 'unlike', targetUrl]);\n\t\t\t\t\t\t});\n\t\t\t\t\t"); } } else { $code = '<script src="' . htmlspecialchars($this->arguments['javaScript']) . '"></script>'; } } // seems as if a div with id fb-root is needed this is just a dirty // workaround to make things work again Perhaps we should // use the iframe variation. $code .= '<div id="fb-root"></div>' . $this->tag->render(); return $code; }
/** * Render link to news item or internal/external pages * * @param Tx_News_Domain_Model_News $newsItem current news object * @param array $settings * @param boolean $uriOnly return only the url without the a-tag * @param array $configuration optional typolink configuration * @return string link */ public function render(Tx_News_Domain_Model_News $newsItem, array $settings = array(), $uriOnly = FALSE, $configuration = array()) { $tsSettings = $this->pluginSettingsService->getSettings(); $this->init(); $newsType = (int) $newsItem->getType(); switch ($newsType) { // internal news case 1: $configuration['parameter'] = $newsItem->getInternalurl(); break; // external news // external news case 2: $configuration['parameter'] = $newsItem->getExternalurl(); break; // normal news record // normal news record default: $configuration = $this->getLinkToNewsItem($newsItem, $tsSettings, $configuration); } if (isset($tsSettings['link']['typesOpeningInNewWindow'])) { if (\TYPO3\CMS\Core\Utility\GeneralUtility::inList($tsSettings['link']['typesOpeningInNewWindow'], $newsType)) { $this->tag->addAttribute('target', '_blank'); } } $url = $this->cObj->typoLink_URL($configuration); if ($uriOnly) { return $url; } $this->tag->addAttribute('href', $url); $this->tag->setContent($this->renderChildren()); return $this->tag->render(); }
/** * Render facebook comment viewhelper * * @param string $appId * @return string */ public function render($appId) { $tsSettings = $this->pluginSettingsService->getSettings(); $this->tag->addAttribute('data-href', \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL')); $this->tag->forceClosingTag(TRUE); $locale = !empty($tsSettings['facebookLocale']) && strlen($tsSettings['facebookLocale']) <= 5 ? $tsSettings['facebookLocale'] : 'en_US'; $code = '<div id="fb-root"></div> <script src="http://connect.facebook.net/' . $locale . '/all.js#appId=' . htmlspecialchars($appId) . '&xfbml=1"></script>'; $code .= $this->tag->render(); return $code; }
/** * Render the Google+ button * * @param string $jsCode Alternative JavaScript code which is used * @return string */ public function render($jsCode = '') { if (empty($jsCode)) { $jsCode = 'https://apis.google.com/js/plusone.js'; } elseif ($jsCode != '-1') { $jsCode = htmlspecialchars($jsCode); } $tsSettings = $this->pluginSettingsService->getSettings(); $locale = !empty($tsSettings['googlePlusLocale']) && strlen($tsSettings['googlePlusLocale']) <= 5 ? '{lang:\'' . $tsSettings['googlePlusLocale'] . '\'}' : ''; $code = '<script type="text/javascript" src="' . $jsCode . '">' . $locale . '</script>'; $this->tag->setContent(' '); $code .= $this->tag->render(); return $code; }
/** * Render a share button * * @param boolean $loadJs * @return string */ public function render($loadJs = TRUE) { // check defaults if (empty($this->arguments['href'])) { $this->tag->addAttribute('href', 'https://www.facebook.com/sharer/sharer.php'); } if (empty($this->arguments['name'])) { $this->tag->addAttribute('name', 'fb_share'); } if (empty($this->arguments['type'])) { $this->tag->addAttribute('type', 'button_count'); } $shareUrl = empty($this->arguments['shareurl']) ? \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_REQUEST_URL') : $this->arguments['shareurl']; $this->tag->addAttribute('share_url', $shareUrl); $this->tag->removeAttribute('shareurl'); $this->tag->setContent($this->renderChildren()); $code = $this->tag->render(); if ($loadJs) { $code .= '<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>'; } // Social interaction Google Analytics if ($this->pluginSettingsService->getByPath('analytics.social.facebookShare') == 1) { $code .= \TYPO3\CMS\Core\Utility\GeneralUtility::wrapJS("\n\t\t\t\tFB.Event.subscribe('message.send', function(targetUrl) {\n\t\t\t\t _gaq.push(['_trackSocial', 'facebook', 'send', targetUrl]);\n\t\t\t\t});\n\t\t\t"); } return $code; }
/** * Render twitter viewhelper * * @return string */ public function render() { $code = ''; $this->tag->addAttribute('href', 'https://twitter.com/share'); $this->tag->addAttribute('class', !empty($this->arguments['class']) ? $this->arguments['class'] : 'twitter-share-button'); // rewrite tags as it seems that it is not possible to have tags with a '-'. $rewriteTags = array('datacount', 'datavia', 'datarelated', 'datatext', 'dataurl', 'datalang'); foreach ($rewriteTags as $tag) { if (!empty($this->arguments[$tag])) { $newTag = str_replace('data', 'data-', $tag); $this->tag->addAttribute($newTag, $this->arguments[$tag]); $this->tag->removeAttribute($tag); } } // -1 means no JS if ($this->arguments['javaScript'] != '-1') { if (empty($this->arguments['javaScript'])) { $code = '<script type="text/javascript" src="https://platform.twitter.com/widgets.js"></script>'; } else { $code = '<script src="' . htmlspecialchars($this->arguments['javaScript']) . '"></script>'; } } // Social interaction Google Analytics if ($this->pluginSettingsService->getByPath('analytics.social.twitter') == 1) { $code .= \TYPO3\CMS\Core\Utility\GeneralUtility::wrapJS("\n\t\t\t\ttwttr.events.bind('tweet', function(event) {\n\t\t\t\t if (event) {\n\t\t\t\t var targetUrl;\n\t\t\t\t if (event.target && event.target.nodeName == 'IFRAME') {\n\t\t\t\t targetUrl = extractParamFromUri(event.target.src, 'url');\n\t\t\t\t }\n\t\t\t\t _gaq.push(['_trackSocial', 'twitter', 'tweet', targetUrl]);\n\t\t\t\t }\n\t\t\t\t});\n\t\t\t"); } $this->tag->removeAttribute('javaScript'); $this->tag->setContent($this->renderChildren()); $code = $this->tag->render() . $code; return $code; }
/** * Render disqus thread * * @param Tx_News_Domain_Model_News $newsItem news item * @param string $shortName shortname * @param string $link link * @return string */ public function render(Tx_News_Domain_Model_News $newsItem, $shortName, $link) { $tsSettings = $this->pluginSettingsService->getSettings(); $code = '<script type="text/javascript"> var disqus_shortname = ' . t3lib_div::quoteJSvalue($shortName, TRUE) . '; var disqus_identifier = \'news_' . $newsItem->getUid() . '\'; var disqus_url = ' . t3lib_div::quoteJSvalue($link, TRUE) . '; var disqus_title = ' . t3lib_div::quoteJSvalue($newsItem->getTitle(), TRUE) . '; var disqus_config = function () { this.language = ' . t3lib_div::quoteJSvalue($tsSettings['disqusLang']) . '; }; (function() { var dsq = document.createElement("script"); dsq.type = "text/javascript"; dsq.async = true; dsq.src = "http://" + disqus_shortname + ".disqus.com/embed.js"; (document.getElementsByTagName("head")[0] || document.getElementsByTagName("body")[0]).appendChild(dsq); })(); </script>'; return $code; }
/** * Render link to news item or internal/external pages * * @param Tx_News_Domain_Model_News $newsItem current news object * @param array $settings * @param boolean $uriOnly return only the url without the a-tag * @param array $configuration optional typolink configuration * @return string link */ public function render(Tx_News_Domain_Model_News $newsItem, array $settings = array(), $uriOnly = FALSE, $configuration = array()) { $tsSettings = $this->pluginSettingsService->getSettings(); /** @var $cObj tslib_cObj */ $cObj = t3lib_div::makeInstance('tslib_cObj'); $newsType = (int) $newsItem->getType(); switch ($newsType) { // internal news case 1: $configuration['parameter'] = $newsItem->getInternalurl(); break; // external news // external news case 2: $configuration['parameter'] = $newsItem->getExternalurl(); break; // normal news record // normal news record default: $detailPid = 0; $detailPidDeterminationMethods = t3lib_div::trimExplode(',', $settings['detailPidDetermination'], TRUE); // if TS is not set, prefer flexform setting if (!isset($settings['detailPidDetermination'])) { $detailPidDeterminationMethods[] = 'flexform'; } foreach ($detailPidDeterminationMethods as $determinationMethod) { if ($callback = $this->detailPidDeterminationCallbacks[$determinationMethod]) { if ($detailPid = call_user_func(array($this, $callback), $settings, $newsItem)) { break; } } } if (!$detailPid) { $detailPid = $GLOBALS['TSFE']->id; } $configuration['useCacheHash'] = 1; $configuration['parameter'] = $detailPid; $configuration['additionalParams'] .= '&tx_news_pi1[news]=' . $newsItem->getUid(); if ((int) $tsSettings['link']['skipControllerAndAction'] !== 1) { $configuration['additionalParams'] .= '&tx_news_pi1[controller]=News' . '&tx_news_pi1[action]=detail'; } // Add date as human readable (30/04/2011) if ($tsSettings['link']['hrDate'] == 1 || $tsSettings['link']['hrDate']['_typoScriptNodeValue'] == 1) { $dateTime = $newsItem->getDatetime(); if (!empty($tsSettings['link']['hrDate']['day'])) { $configuration['additionalParams'] .= '&tx_news_pi1[day]=' . $dateTime->format($tsSettings['link']['hrDate']['day']); } if (!empty($tsSettings['link']['hrDate']['month'])) { $configuration['additionalParams'] .= '&tx_news_pi1[month]=' . $dateTime->format($tsSettings['link']['hrDate']['month']); } if (!empty($tsSettings['link']['hrDate']['year'])) { $configuration['additionalParams'] .= '&tx_news_pi1[year]=' . $dateTime->format($tsSettings['link']['hrDate']['year']); } } } if (isset($tsSettings['link']['typesOpeningInNewWindow'])) { if (t3lib_div::inList($tsSettings['link']['typesOpeningInNewWindow'], $newsType)) { $this->tag->addAttribute('target', '_blank'); } } $url = $cObj->typoLink_URL($configuration); if ($uriOnly) { return $url; } $this->tag->addAttribute('href', $url); $this->tag->setContent($this->renderChildren()); return $this->tag->render(); }