1<?php 2/** 3 * DokuWiki Plugin likeit 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author lisps 7 */ 8 9if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); 10if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); 11require_once(DOKU_PLUGIN.'syntax.php'); 12 13/* 14 * All DokuWiki plugins to extend the parser/rendering mechanism 15 * need to inherit from this class 16 */ 17class syntax_plugin_likeit extends DokuWiki_Syntax_Plugin { 18 19 private $_itemPos = array(); 20 function incItemPos() { 21 global $ID; 22 if(array_key_exists($ID,$this->_itemPos)) { 23 return $this->_itemPos[$ID]++; 24 } else { 25 $this->_itemPos[$ID] = 1; 26 return 0; 27 } 28 } 29 function getItemPos(){ 30 global $ID; 31 if(array_key_exists($ID,$this->_itemPos)) { 32 $this->_itemPos[$ID]; 33 } else { 34 return 0; 35 } 36 } 37 38 /* 39 * What kind of syntax are we? 40 */ 41 function getType() { 42 return 'substition'; 43 } 44 45 /* 46 * Where to sort in? 47 */ 48 function getSort() { 49 return 155; 50 } 51 52 /* 53 * Paragraph Type 54 */ 55 function getPType() { 56 return 'normal'; 57 } 58 59 /* 60 * Connect pattern to lexer 61 */ 62 function connectTo($mode) { 63 $this->Lexer->addSpecialPattern("<likeit[^>]*>",$mode,'plugin_likeit'); 64 } 65 66 /* 67 * Handle the matches 68 */ 69 function handle($match, $state, $pos, Doku_Handler $handler){ 70 global $ID; 71 72 $opts = array( 73 $this->incItemPos(), 74 $ID, 75 trim(substr($match,8,strlen($match)-8-1)) 76 ); 77 78 return ($opts); 79 } 80 81 /* 82 * Create output 83 */ 84 function render($mode, Doku_Renderer $renderer, $opts) 85 { 86 if($mode == 'metadata') return false; 87 88 global $INFO; 89 $H = $this->loadHelper('likeit'); 90 list($index,$pageid,$users) = $opts; 91 92 $H->setUser($users); 93 94 if($mode == 'xhtml') { 95 $Hajax = $this->loadHelper('ajaxedit'); 96 97 $doAction = $Hajax && $pageid == $INFO['id']; 98 99 100 $htmlid = hsc($pageid).'_'.$index; 101 102 $renderer->doc .= "<span class='plugin_likeit container ".($doAction?'':'disabled')."' id='plugin_likeit_".$htmlid."'>"; 103 $renderer->doc .= "<span class='plugin_likeit button'>"; 104 $renderer->doc .= "<span class='plugin_likeit image'>"; 105 $renderer->doc .= "</span>"; 106 $renderer->doc .= "<span class='plugin_likeit label'>".hsc($this->getLang('likeit')); 107 108 $renderer->doc .= "</span>"; 109 $renderer->doc .= "<span class='plugin_likeit count'>"; 110 $renderer->doc .= $H->getUserCount(); 111 $renderer->doc .= "</span>"; 112 $renderer->doc .= "</span>"; 113 $renderer->doc .= "<span class='plugin_likeit list'>"; 114 $renderer->doc .= $H->renderUserList(); 115 $renderer->doc .= "</span>"; 116 $renderer->doc .= "</span>"; 117 118 } 119 else { 120 $renderer->doc .= hsc($this->getLang('likeit')) ." (". $H->getUserCount() .")" ; 121 } 122 return true; 123 } 124 125 126 127} 128 129