. */
/**
* Embed a Facebook like-button onto any page
* @license GNU General Public License 3
* @author Marvin Thomas Rabe
*/
if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/');
if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
require_once(DOKU_PLUGIN.'syntax.php');
require_once(DOKU_INC.'inc/auth.php');
class syntax_plugin_facebooklike extends DokuWiki_Syntax_Plugin {
private $data;
/**
* General information about the plugin.
*/
public function getInfo(){
return array(
'author' => 'Marvin Thomas Rabe',
'email' => 'mrabe@marvinrabe.de',
'date' => '2012-06-06',
'name' => 'Facebook Like-Button',
'desc' => 'Adds Facebook like-buttons',
'url' => 'https://github.com/marvinrabe/dokuwiki-facebook',
);
}
/**
* What kind of syntax are we?
*/
public function getType(){
return 'container';
}
/**
* What about paragraphs?
*/
public function getPType(){
return 'block';
}
/**
* Where to sort in?
*/
public function getSort(){
return 309;
}
/**
* Connect pattern to lexer.
*/
public function connectTo($mode) {
$this->Lexer->addSpecialPattern('\{\{like>[^}]*\}\}',$mode,'plugin_facebooklike');
}
/**
* Handle the match
*/
public function handle($match, $state, $pos, &$handler){
if (isset($_REQUEST['comment']))
return false;
$match = substr($match,7,-2); //strip markup from start and end
$data = array();
//handle params
$params = explode('|',$match);
foreach($params as $param){
$splitparam = explode('=',$param);
$data[$splitparam[0]] = $splitparam[1];
}
return $data;
}
/**
* Create output.
*/
public function render($mode, &$renderer, $data) {
if($mode == 'xhtml'){
// Next line just for developing purposes.
// Disables Dokuwiki cache.
// $renderer->info['cache'] = false;
$renderer->doc .= $this->_button($data);
return true;
}
return false;
}
/**
* Does the contact form XHTML creation. Adds some JavaScript to validate the form
* and creates the input form.
*/
protected function _button($data){
global $ID;
global $conf;
$this->data = $data;
$ret = '_setting('layout', $conf).'" '
. 'show_faces="'.$this->_setting('faces', $conf).'" '
. 'width="'.$this->_setting('width', $conf).'" '
. 'action="'.$this->_setting('action', $conf).'" '
. 'font="'.$this->_setting('font', $conf).'" '
. 'colorscheme="'.$this->_setting('colorscheme', $conf).'"'
. '>';
return $ret;
}
/**
* Returns valid setting.
*/
protected function _setting($name, $gconf) {
include dirname(__FILE__).'/conf/default.php';
if(strtolower($name) == 'faces') {
if(empty($this->data['show_faces'])) {
if(!isset($gconf['plugin']['facebooklike']['show_faces']))
return 'true';
else
return ($gconf['plugin']['facebooklike']['show_faces'] == 1)?'true':'false';
} else
return $this->data['show_faces'];
} else {
if(empty($this->data[$name])) {
if(!isset($gconf['plugin']['facebooklike'][$name]))
return $conf[$name];
else
return $gconf['plugin']['facebooklike'][$name];
} else
return $this->data[$name];
}
}
}