1<?php 2 3if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 4if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 5require_once(DOKU_PLUGIN.'syntax.php'); 6 7/** 8 * All DokuWiki plugins to extend the parser/rendering mechanism 9 * need to inherit from this class 10 */ 11class syntax_plugin_socialmark extends DokuWiki_Syntax_Plugin { 12 13 /** 14 * return some info 15 */ 16 function getInfo(){ 17 return array( 18 'author' => 'iDo', 19 'email' => 'iDo@woow-fr.com', 20 'date' => '21/03/2006', 21 'name' => 'Social Mark Plugin', 22 'desc' => 'Add some link to social bookmarking page. syntaxe : {{socialmark}}', 23 'url' => 'http://wiki.splitbrain.org/plugin:socialmark', 24 ); 25 } 26 27 /** 28 * What kind of syntax are we? 29 */ 30 function getType(){ 31 return 'substition'; 32 } 33 34 /** 35 * Where to sort in? 36 */ 37 function getSort(){ 38 return 108; 39 } 40 41 /** 42 * Connect pattern to lexer 43 */ 44 function connectTo($mode) { 45 $this->Lexer->addSpecialPattern("{{socialmark}}",$mode,'plugin_socialmark'); 46 } 47 48 /** 49 * Handle the match 50 */ 51 function handle($match, $state, $pos, &$handler){ 52 return true; 53 } 54 55 /** 56 * Create output 57 */ 58 function render($mode, &$renderer, $data) { 59 if($mode == 'xhtml'){ 60 $renderer->doc .= '<div>'; 61 $renderer->doc .= $this->_socialmark(); 62 $renderer->doc .= '</div>'; 63 return true; 64 } 65 return false; 66 } 67 68 function _socialmark() { 69 global $conf; 70 $r='<ul id="socialmark">'; 71 $g=@file(DOKU_PLUGIN.'socialmark/list.txt'); 72 foreach ($g as $v) { 73 if ($v{0}=='#') continue; /*comments line starts by #*/ 74 $v=explode('|',$v,2); 75 if (@$v[1]) 76 $h=$v[1]; 77 else { 78 $h=parse_url($v[0]); 79 $h=$h['host']; 80 } 81 82 $r.='<li><a href="'.$v[0].$this->_getfullURL().'" '.(($conf['target']['extern']!='')?'target="'.$conf['target']['extern'].'"':'').'>'.$h."</a></li>\n"; 83 } 84 return $r.'</ul>'; 85 } 86 function _getfullURL() { 87 return 'http'.(($_SERVER['HTTPS']=='on')?'s':'').'://'.$_SERVER['HTTP_HOST'].(($_SERVER['SERVER_PORT']!='80')?':'.$_SERVER['SERVER_PORT']:'').$_SERVER['REQUEST_URI']; 88 } 89} 90 91//Setup VIM: ex: et ts=4 enc=utf-8 : 92?>