123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- if (!defined('DOKU_INC')) die();
- class syntax_plugin_lsb_button extends DokuWiki_Syntax_Plugin {
-
- public function getType() {
- return 'substition';
- }
-
- public function getPType() {
- return 'normal';
- }
-
- public function getSort() {
- return 999;
- }
-
- public function connectTo($mode) {
- $this->Lexer->addSpecialPattern('~~(lsb|LSB)\b.*?~~',$mode,'plugin_lsb_button');
- }
-
- public function handle($match, $state, $pos, Doku_Handler &$handler){
- $match = strtolower(trim(substr($match, 5, -2)));
- if (empty($match)) {
- $match = strtolower(trim($this->getConf('networks')));
- }
- return explode(' ', $match);
- }
-
- public function render($mode, Doku_Renderer &$renderer, $data) {
- if($mode != 'xhtml') return false;
-
- $protected = array('twitter', 'facebook', 'googleplus', 'linkedin', 'pinterest', 'tumblr', 'reddit', 'taringa');
- $renderer->doc .= '<ul class="lsb">';
- foreach ($data as $network) {
- if (in_array($network, $protected)) {
- $renderer->doc .= $this->lsb_button($network);
- }
- }
- $renderer->doc .= '</ul>';
- return true;
- }
-
- protected function lsb_button ($network) {
- global $ID;
- global $INFO;
- $url = rawurlencode(wl($ID,'',true));
- $title = rawurlencode(($INFO['meta']['title']) ? $INFO['meta']['title'] : $meta);
- $abstract = rawurlencode($INFO['meta']['description']['abstract']);
-
- $class = $this->getConf('display') . '-' . $network;
-
-
-
-
-
-
-
-
-
-
-
-
- switch ($network) {
- case 'twitter':
- $name = 'Twitter';
- $href = 'https://twitter.com/intent/tweet?url=' . $url . '&text='. $title;
- break;
- case 'facebook':
- $name = 'Facebook';
- $href = 'http://www.facebook.com/sharer.php?u='. $url;
- break;
- case 'googleplus':
- $name = 'Google+';
- $href = 'https://plus.google.com/share?url='. $url;
- break;
- case 'linkedin':
- $name = 'LinkedIn';
- $href = 'https://www.linkedin.com/shareArticle?url='. $url .'&title=' . $title . '&summary=' . $abstract . '&mini=true&source=' . $url;
- break;
- case 'pinterest':
- $name = 'Pinterest';
- $href = 'https://pinterest.com/pin/create/button/?url='. $url .'&description=' . $abstract;
- break;
- case 'tumblr':
- $name = 'Tumblr';
- $href = 'http://www.tumblr.com/share/link?url='. $url .'&description=' . $abstract;
- break;
- case 'reddit':
- $name = 'Reddit';
- $href = 'http://www.reddit.com/submit?url='. $url .'&title=' . $title;
- break;
- case 'taringa':
- $name = 'Taringa';
- $href = 'http://www.taringa.net/widgets/share.php?url='. $url .'&body=' . $abstract;
- break;
- }
- $xhtml = '<li class="lsb-item-' . $class . '">';
- $xhtml .= '<a class="lsb-link-' . $class . '" href="' . $href . '">' . $name . '</a>';
- $xhtml .= '</li>';
- return $xhtml;
- }
-
-
-
-
-
-
-
-
-
-
- }
|