1<?php 2/** 3 * Newsboard plugin for dokuwiki 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Arthur Lobert(arthur.lobert@thalesgroup.com) 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_newsboard extends DokuWiki_Syntax_Plugin{ 18 19 function getType() { return 'substition'; } 20 function getPType() { return 'block'; } 21 function getSort() { return 304; } 22 23 function getInfo(){ 24 return array( 25 'author' => 'Arthur Lobert', 26 'email' => 'arthur.lobert@thalesgroup.com', 27 'date' => '2010_09_01', 28 'name' => 'newsboard', 29 'desc' => '', 30 'url' => 'http://www.dokuwiki.org/plugin:newsboard', 31 ); 32 } 33 34 function connectTo($mode) { 35 $this->Lexer->addSpecialPattern('{{newsboard.*?}}',$mode,'plugin_newsboard'); 36 } 37 38 function check_arg($match){ 39 $check = preg_split("/>/",$match, -1 ,PREG_SPLIT_DELIM_CAPTURE); 40 if ($check[0] == "") 41 return substr($match, 1, strlen($match) - 1); 42 else 43 return false; 44 } 45 46 function minmaj($match){ 47 $ret = 0; 48 switch ($match) { 49 case "all": 50 $ret = RECENTS_SKIP_DELETED; 51 break; 52 //default : major 53 default: 54 $ret = RECENTS_SKIP_DELETED | RECENTS_SKIP_MINORS ; 55 break; 56 } 57 return $ret; 58 } 59 60 function nb_arg($nbr){ 61 $nb = (int) $nbr; 62 if ($nb < 1) 63 $nbr = '10'; 64 return ($nbr); 65 } 66 67// function parse_ligne(); 68 69 function handle($match, $state, $pos, &$handler){ 70 $match = html_entity_decode(substr($match, 11, -2)); 71 $match = $this->check_arg($match); 72 if ($match){ 73 $arg = preg_split("/\|/",$match, -1 ,PREG_SPLIT_DELIM_CAPTURE); 74 $ns = $arg[0]; 75 if ($ns[0] == ':') 76 $ns = substr($ns, 1); 77 $change = $this->minmaj($arg[1]); 78 $nbr = $this->nb_arg($arg[2]); 79 $modif = getRecents(0, $nbr, $ns, $change); 80 return ($modif); 81 } 82 else{ 83 return false; 84 } 85 } 86 87function get_titre($text) 88{ 89 $ignore = 0; 90 $tab = preg_split("/======/",$text ,-1,PREG_SPLIT_DELIM_CAPTURE); 91 if ($tab[2] != Null) 92 return ($tab[1]); 93 return (0); 94} 95 96function cut_titre($text, $titre){ 97 return (str_replace('======'.$titre.'======', ' ', $text)); 98} 99 function get_image($page) 100 { 101 $i = 0; 102 $text = rawWiki($page); 103 $tab = preg_split("/(\{\{|\}})/",$text, -1 ,PREG_SPLIT_DELIM_CAPTURE); 104 while ($tab[$i]) 105 { 106 if ($tab[$i] == "{{" && preg_match("/newsboard>/", $tab[$i + 1]) == 0) 107 return $tab[$i].$tab[$i+1].$tab[$i+2]; 108 $i++; 109 } 110 return 0; 111 } 112 113 function cut_text($text){ 114 return (str_replace('/', ' / ', $text)); 115 } 116 117 function render($mode, &$renderer, $data) { 118 119 foreach ($data as $tic): 120 121 $page = $tic[id]; 122 $text = rawWikiSlices('1-500', $page); 123 $text = $this->cut_text($text[1]); 124 $titre = $this->get_titre($text); 125 $text = $this->cut_titre($text, $titre); 126 $media = $this->get_image($page); 127 if ($media) 128 $image =" <input type='image' border='0' src='/dokuwiki/lib/exe/fetch.php?media=".$media."' height='100' width='100' align='left' alt=''/>"; 129 else 130 $image = 0; 131 if (plugin_isdisabled('wrap') || (!$wrap = plugin_load('syntax', 'wrap_div'))) { 132 msg('missing_wrapplugin', -1); 133 return false; 134 } 135 136 $data[0] = '1'; 137 $data[1] = 'round box 600px center'; 138 $wrap->render($mode, &$renderer, $data); 139 140 $renderer->doc .="<table >"; 141 if ($titre) 142 $renderer->doc .=" 143 <tr> 144 <div align='center'><FONT SIZE=5>".$titre."</FONT><br /><br /></div> 145 146 </tr> 147 "; 148 else 149 $renderer->doc .=" 150 <tr> 151 <div align='center'><FONT SIZE=5>".$page."</FONT><br /><br /></div> 152 153 </tr> 154 "; 155 $renderer->doc .="<tr align='center' height='100' width='100'>"; 156 if ($image){ 157 $renderer->doc .=" 158 <td height='100' width='100'> 159 <div align='center'>". $image."</div> 160 </td><td><div height='100' width='5%' style='margin-left:10px;'>"; 161 162 } 163 else 164 $renderer->doc .="<div align='center' height='100' width='5%'> 165 "; 166 $data[0] = '3'; 167 $data[1] = $text; 168 $wrap->render($mode, &$renderer, $data); 169 $renderer->doc .= " 170 171 </div> 172 </td></tr> 173 <tr > 174 175 </table> 176 <div align='center' ><a href='/dokuwiki/doku.php?id=".$page."' class='breadcrumbs' title='".$page."' ><H2>".$this->getLang('next')."</H2></a></div></tr> 177 "; 178 179 $data[0] = '4'; 180 $data[1] = null; 181 $wrap->render($mode, &$renderer, $data); 182 183 endforeach; 184 return true ; 185 } 186}