function share_links($limit = 4, $url = '', $title = '', $short_title = '', $image = '') { $db = array('facebook', 'twitter', 'googleplus', 'reddit'); $ret = array(); foreach ($db as $key) { $ret[$key] = share_url($key, $url, $title, $short_title, $image); } return array_slice($ret, 0, $limit); }
/** * Generate buttons for share at some social networks * * @param string $type type of share * @param array $args parameters for share * @return string */ function share_button($type = '', $args = array()) { $url = share_check($type); if ($url === FALSE) { log_message('debug', 'Please check your type share_button(' . $type . ')'); return "#ERROR-check_share_button_type"; } $params = array(); $param = ''; if ($type == 'twitter') { if (isset($args['iframe'])) { $url = share_url($type, $args); list($url, $param) = explode('?', $url); $button = <<<DOT \t\t\t\t<iframe allowtransparency="true" frameborder="0" scrolling="no" style="width:130px; height:50px;" \t\t\t\tsrc="http://platform.twitter.com/widgets/tweet_button.html?{$param}"></iframe> DOT; } else { foreach (explode(' ', 'url via text related count lang counturl') as $v) { if (isset($args[$v])) { $params[] = 'data-' . $v . '="' . $args[$v] . '"'; } } $param = implode(' ', $params); $button = <<<DOT \t\t\t\t<a href="http://twitter.com/share" class="twitter-share-button" {$param}>Tweet</a> \t\t\t\t<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> DOT; } } elseif ($type == 'facebook') { if (!isset($args['type'])) { $args['type'] = 'button_count'; } if (isset($args['fb'])) { $params = array('type' => 'type', 'href' => 'url', 'class' => 'class'); foreach ($params as $k => $v) { if (isset($args[$v])) { $param .= $k . '="' . $args[$v] . '"'; } } $button = "<fb:share-button {$param}></fb:share-button>"; } else { $params = array('type' => 'type', 'share_url' => 'url'); foreach ($params as $k => $v) { if (isset($args[$v])) { $param .= $k . '="' . $args[$v] . '"'; } } if (!isset($args['button_text'])) { $args['button_text'] = 'Share to Facebook'; } $button = <<<DOT \t\t\t\t<a name="fb_share" {$param}>{$args['button_text']}</a> \t\t\t\t<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script> DOT; } } elseif ($type == 'buzz') { $params = array('button-style' => 'type', 'local' => 'lang', 'url' => 'url', 'imageurl' => 'image'); foreach ($params as $k => $v) { if (isset($args[$v])) { $param .= ' data-' . $k . '="' . $args[$v] . '"'; } } if (!isset($args['title'])) { $args['title'] = 'Share to Google Buzz'; } $button = <<<DOT \t\t\t<a title="{$args['title']}" class="google-buzz-button" href="http://www.google.com/buzz/post" {$param}></a> \t\t\t<script type="text/javascript" src="http://www.google.com/buzz/api/button.js"></script> DOT; } elseif ($type == 'vkontakte') { $url = isset($args['url']) ? '{url: "' . $args['url'] . '"}' : 'false'; foreach (explode(' ', 'type text') as $v) { if (isset($args[$v])) { $param[] = $k . ': "' . urlencode($args[$v]) . '"'; } } $param = implode(', ', $params); if (!empty($param)) { $param = ', {' . $param . '}'; } $button = <<<DOT \t\t\t<script type="text/javascript" src="http://vkontakte.ru/js/api/share.js?9" charset="windows-1251"></script> \t\t\t<script type="text/javascript">document.write(VK.Share.button({$url}{$param}));</script> DOT; } return $button; }
/** * Generate buttons for share at some social networks * * @param string $type type of share * @param array $args parameters for share * @return string */ function share_button($type = '', $args = array()) { $url = share_check($type); if ($url === FALSE) { log_message('debug', 'Please check your type share_button(' . $type . ')'); return "#ERROR-check_share_button_type"; } $params = array(); $param = ''; if ($type == 'twitter') { if (isset($args['iframe'])) { $url = share_url($type, $args); list($url, $param) = explode('?', $url); $button = <<<DOT \t\t\t\t<iframe allowtransparency="true" frameborder="0" scrolling="no" style="width:130px; height:50px;" \t\t\t\tsrc="http://platform.twitter.com/widgets/tweet_button.html?{$param}"></iframe> DOT; } else { foreach (explode(' ', 'url via text related count lang counturl') as $v) { if (isset($args[$v])) { $params[] = 'data-' . $v . '="' . $args[$v] . '"'; } } $param = implode(' ', $params); $button = <<<DOT \t\t\t\t<a href="http://twitter.com/share" class="twitter-share-button" {$param}>Tweet</a> \t\t\t\t<script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script> DOT; } } elseif ($type == 'facebook') { if (!isset($args['type'])) { $args['type'] = 'button_count'; } if (isset($args['fb'])) { $params = array('type' => 'type', 'href' => 'url', 'class' => 'class'); foreach ($params as $k => $v) { if (isset($args[$v])) { $param .= $k . '="' . $args[$v] . '"'; } } $button = "<fb:share-button {$param}></fb:share-button>"; } else { $params = array('type' => 'type', 'share_url' => 'url'); foreach ($params as $k => $v) { if (isset($args[$v])) { $param .= $k . '="' . $args[$v] . '"'; } } if (!isset($args['button_text'])) { $args['button_text'] = 'Share to Facebook'; } $button = <<<DOT \t\t\t\t<a name="fb_share" {$param}>{$args['button_text']}</a> \t\t\t\t<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script> DOT; } } elseif ($type == 'buzz') { $params = array('button-style' => 'type', 'local' => 'lang', 'url' => 'url', 'imageurl' => 'image'); foreach ($params as $k => $v) { if (isset($args[$v])) { $param .= ' data-' . $k . '="' . $args[$v] . '"'; } } if (!isset($args['title'])) { $args['title'] = 'Share to Google Buzz'; } $button = <<<DOT \t\t\t<a title="{$args['title']}" class="google-buzz-button" href="http://www.google.com/buzz/post" {$param}></a> \t\t\t<script type="text/javascript" src="http://www.google.com/buzz/api/button.js"></script> DOT; } elseif ($type == 'vkontakte') { $url = isset($args['url']) ? '{url: "' . $args['url'] . '"}' : 'false'; foreach (explode(' ', 'type text') as $v) { if (isset($args[$v])) { $param[] = $k . ': "' . urlencode($args[$v]) . '"'; } } $param = implode(', ', $params); if (!empty($param)) { $param = ', {' . $param . '}'; } $button = <<<DOT \t\t\t<script type="text/javascript" src="http://vkontakte.ru/js/api/share.js?9" charset="windows-1251"></script> \t\t\t<script type="text/javascript">document.write(VK.Share.button({$url}{$param}));</script> DOT; } elseif ($type == 'google') { $button = <<<DOT <!-- Place this tag where you want the +1 button to render. --> <g:plusone size="standard" count="true"></g:plusone> <!-- Place this tag after the last +1 button tag. --> <script src="https://apis.google.com/js/plusone.js"></script> DOT; } elseif ($type == 'fb') { $button = <<<DOT <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/en_US/all.js#xfbml=1&appId=453531711432561"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script> <div class="fb-like" data-href="{$args['url']}" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div> DOT; } return $button; }