*/
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
class syntax_plugin_lsb_button extends DokuWiki_Syntax_Plugin {
/**
* @return string Syntax mode type
*/
public function getType() {
return 'substition';
}
/**
* @return string Paragraph type
*/
public function getPType() {
return 'normal';
}
/**
* @return int Sort order - Low numbers go before high numbers
*/
public function getSort() {
return 999;
}
/**
* Connect lookup pattern to lexer.
*
* @param string $mode Parser mode
*/
public function connectTo($mode) {
$this->Lexer->addSpecialPattern('~~LSB\b.*?~~',$mode,'plugin_lsb_button');
}
/**
* Handle matches of the lsb syntax
*
* @param string $match The match of the syntax
* @param int $state The state of the handler
* @param int $pos The position in the document
* @param Doku_Handler $handler The handler
* @return array Data for the renderer
*/
public function handle($match, $state, $pos, Doku_Handler &$handler){
$match = strtolower(trim(substr($match, 5, -2))); // strip markup
if (empty($match)) {
$match = strtolower(trim($this->getConf('networks')));
}
return explode(' ', $match);
}
/**
* Render xhtml output or metadata
*
* @param string $mode Renderer mode (supported modes: xhtml)
* @param Doku_Renderer $renderer The renderer
* @param array $data The data from the handler() function
* @return bool If rendering was successful.
*/
public function render($mode, Doku_Renderer &$renderer, $data) {
if($mode != 'xhtml') return false;
// validation list of available social networks
$protected = array('twitter', 'facebook', 'googleplus', 'linkedin', 'pinterest', 'tumblr', 'reddit', 'taringa', 'email');
$renderer->doc .= '
';
foreach ($data as $network) {
if (in_array($network, $protected)) {
$renderer->doc .= $this->lsb_button($network);
}
}
$renderer->doc .= '
';
return true;
}
/**
* Render xhtml output for share buttons
*
* @param string $network The social network to render the button to
* @return string Xhtml code for button.
*/
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']);
//$text = $this->lsb_getText($network);
$class = $this->getConf('display') . '-' . $network;
// see: http://builtbyboon.com/blog/simple-social-sharing-buttons
// see: https://github.com/cferdinandi/social-sharing
// Tweet
// Share on Facebook
// Plus on googleplus
// Share on LinkedIn
// Pin on Pinterest
// Share on VK
// Share on Xing
// Share on Tumblr
// Share on Reddit
// Compartir en Taringa
// Email
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;
case 'email':
$name = 'Email';
$href = 'mailto:?subject='. $title .'&body=' . $url . ': '. $abstract;
break;
}
$xhtml = '';
$xhtml .= '' . $name . '';
$xhtml .= '';
return $xhtml;
}
/**
* Returns the thext to display in share button
*
* @param string $network The social network to get the text to
* @return string text for button or empty string to show just the icon.
*/
// protected function lsb_getText($network) {
// $display = $this->getConf('display');
// if ($display == 'text') {
// return $this->getLang($network . '_text');
// } else {
// // no text, just the icon
// return '';
// }
// }
}