1<?php 2/** 3 * favoris plugin : Affiche mes pages favorites (les plus visitees). 4 * 5 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html) 6 * @author Etienne M. <emauvaisfr@yahoo.fr> 7 */ 8 9// based on http://wiki.splitbrain.org/plugin:tutorial 10 11// must be run within Dokuwiki 12if (!defined('DOKU_INC')) die(); 13 14if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/'); 15require_once(DOKU_PLUGIN . 'syntax.php'); 16 17/** 18 * All DokuWiki plugins to extend the parser/rendering mechanism 19 * need to inherit from this class 20 */ 21class syntax_plugin_favoris extends DokuWiki_Syntax_Plugin { 22 function getInfo() { 23 return array( 24 'author' => 'Etienne M.', 25 'email' => 'emauvaisfr@yahoo.fr', 26 'date' => @file_get_contents(DOKU_PLUGIN.'favoris/VERSION'), 27 'name' => 'favoris Plugin', 28 'desc' => html_entity_decode($this->getLang('fav_description')), 29 'url' => 'http://www.dokuwiki.org/plugin:favoris' 30 ); 31 } 32 33 function connectTo($mode) { 34 $this->Lexer->addSpecialPattern('~~FAVORIS~~', $mode, 'plugin_favoris'); 35 } 36 37 //function getType() { return 'substition'; } 38 function getType() { return 'disabled'; } 39 40 function getSort() { return 667; } 41 42 function handle($match, $state, $pos, &$handler) { 43 return array($match, $state, $pos); 44 } 45 46 function render($mode, &$renderer, $data) { 47 $maxFav=5; 48 $maxRec=5; 49 50 if ($mode == 'xhtml') { 51 $renderer->info['cache'] = FALSE; 52 $renderer->doc .= '<script type="text/javascript" charset="utf-8" src="'.DOKU_URL.'lib/plugins/favoris/favoris.js" ></script>'; 53 54 if (isset($_COOKIE['favoris'])) { 55 $fav=$_COOKIE['favoris']; 56 57 //Si la page off existe et vaut 1, on sort 58 if (isset($fav['off']) && $fav['off']==1) { 59 $renderer->doc .= $this->getLang('fav_desact'); 60 //Activer 61 $renderer->doc .= ' <img src="'.DOKU_URL.'lib/plugins/favoris/images/activer.png" border="0" height="18" style="vertical-align:middle;" /> <a href="javascript:deleteCookie(\'favoris[off]\', \'/\'); recharge();">'.$this->getLang('fav_activer').'</a>.<br />'; 62 $renderer->doc .= $this->getLang('fav_cookies').'<br />'; 63 return; 64 } 65 66 //Si la page off existe et vaut 2, on recharge la page 67 if (isset($fav['off']) && $fav['off']==2) { 68 $renderer->doc .= "<script>recharge();</script>"; 69 return; 70 } 71 72 //Combien de pages afficher au maximum ? 73 $max=$maxFav; 74 if (isset($_COOKIE['fav_maxFav'])) $max=$_COOKIE['fav_maxFav']; 75 if (intval($max) != $max) $max=$maxFav; 76 $maxFav=$max; 77 78 $max=$maxRec; 79 if (isset($_COOKIE['fav_maxRec'])) $max=$_COOKIE['fav_maxRec']; 80 if (intval($max) != $max) $max=$maxRec; 81 $maxRec=$max; 82 83 $renderer->doc .= '<div id="enveloppe" ondblclick="afficherControles(event,0);" onmouseover="afficherControles(event,2000);" onmouseout="masquerControles(event);" title="'.$this->getLang('fav_flotter').'">'; 84 85 //Pages recentes 86 //Tri des pages par date de visite decroissante 87 uasort($fav, create_function('$a, $b', ' 88 list($cpt, $date1)=explode(";", $a); 89 list($cpt, $date2)=explode(";", $b); 90 91 if ($date1=="") $date1=0; 92 if ($date2=="") $date2=0; 93 94 $date1=intval($date1); 95 $date2=intval($date2); 96 97 if ($date1==$date2) return 0; 98 return ($date1 > $date2) ? -1 : 1; 99 ')); 100 101 $idx1=0; 102 if ($maxRec>0) { 103 foreach ($fav as $page => $cpt) { 104 list($cpt, $date) = explode(";", $cpt); 105 if ($page=='off' || $cpt<1 || !$date) continue; 106 if (!$idx1) { 107 $renderer->doc .= "<b>".$this->getLang('fav_prec')."</b>"; 108 $renderer->listu_open(); 109 } 110 111 $lien = $this->donneLien($page, ""); 112 $renderer->listitem_open(1); 113 $renderer->doc .= $lien; 114 $renderer->listitem_close(); 115 116 $idx1++; 117 if ($idx1>=$maxRec) break; 118 } 119 } 120 if ($idx1) $renderer->listu_close(); 121 //else $renderer->doc .= " <br />"; 122 123 //Pages favorites 124 //Tri des pages par visites decroissantes 125 uasort($fav, create_function('$a, $b', ' 126 list($cpt1, $date)=explode(";", $a); 127 list($cpt2, $date)=explode(";", $b); 128 129 $cpt1=intval($cpt1); 130 $cpt2=intval($cpt2); 131 132 if ($cpt1==$cpt2) return 0; 133 return ($cpt1 > $cpt2) ? -1 : 1; 134 ')); 135 $idx2=0; 136 if ($maxFav>0) { 137 foreach ($fav as $page => $cpt) { 138 list($cpt, $date) = explode(";", $cpt); 139 140 if ($page=='off' || $cpt<1) continue; 141 142 if (!$idx2) { 143 $renderer->doc .= "<b>".$this->getLang('fav_pfav')."</b>"; 144 $renderer->listu_open(); 145 } 146 147 $lien = $this->donneLien($page, " ($cpt ".$this->getLang('fav_visites').")"); 148 149 $renderer->doc .= "<div id=\"$page\">"; 150 $renderer->listitem_open(1); 151 $renderer->doc .= $lien; 152 //Reset 153 $renderer->doc .= ' <a href="javascript:deleteCookie(\'favoris['.$page.']\', \'/\'); cache(\''.$page.'\');"><img src="'.DOKU_URL.'lib/plugins/favoris/images/reset.png" title="'.$this->getLang('fav_reset').'" border="0" height="18" style="vertical-align:middle; display:none;" name="ctrl" /></a>'; 154 //Exclure 155 $renderer->doc .= ' <a href="javascript:setCookie(\'favoris['.$page.']\', -1, new Date(\'July 21, 2099 00:00:00\'), \'/\'); cache(\''.$page.'\');"><img src="'.DOKU_URL.'lib/plugins/favoris/images/exclure.png" title="'.$this->getLang('fav_exclure').'" border="0" height="18" style="vertical-align:middle; display:none;" name="ctrl" /></a>'; 156 $renderer->doc .= "</div>"; 157 $renderer->listitem_close(); 158 159 $idx2++; 160 if ($idx2>=$maxFav) break; 161 } 162 } 163 if ($idx2) { 164 if (!plugin_isdisabled('snap')) $snap=plugin_load('helper', 'snap'); 165 if ($snap) { 166 $renderer->listitem_open(1); 167 $renderer->doc .= "<a href=\"?do=snapfavoris\">".$this->getLang('fav_mosaique')." >></a><br />"; 168 $renderer->listitem_close(); 169 } 170 } 171 if ($idx2) $renderer->listu_close(); 172 173 if (!$idx1 && !$idx2) $renderer->doc .= " <br />"; 174 175 //Pages exclues 176 //Voir/cacher les pages exclures et la configuration 177 $renderer->doc .= '<a href="javascript:afficheMasque(\'exclues\'); this.blur();"><img src="'.DOKU_URL.'lib/plugins/favoris/images/voir-cacher.png" title="'.$this->getLang('fav_voircacher').'" border="0" height="18" style="vertical-align:middle; display:none;" name="ctrl" /></a><div id="exclues" style="display:none;">'; 178 $exclues=0; 179 foreach ($fav as $page => $cpt) { 180 list($cpt, $date) = explode(";", $cpt); 181 182 if ($cpt==-1) { 183 if (!$exclues) $renderer->listu_open(); 184 185 $lien = $this->donneLien($page); 186 $exclues++; 187 188 $renderer->doc.= "<div id=\"ex_$page\">"; //<li><div class=\"li\">"; 189 $renderer->listitem_open(1); 190 $renderer->doc .= $lien; 191 //Inclure 192 $renderer->doc .= ' <a href="javascript:deleteCookie(\'favoris['.$page.']\', \'/\'); cache(\'ex_'.$page.'\');"><img src="'.DOKU_URL.'lib/plugins/favoris/images/inclure.png" title="'.$this->getLang('fav_inclure').'" border="0" height="18" style="vertical-align:middle;" /></a>'; 193 $renderer->doc .= "</div>"; //</li></div>"; 194 $renderer->listitem_close(); 195 } 196 } 197 if ($exclues) $renderer->listu_close(); 198 199 //Configuration 200 $renderer->doc .= "<fieldset style=\"text-align:left;\"><legend><b>".$this->getLang('fav_config')."</b></legend>"; 201 $renderer->doc .= $this->getLang('fav_afficher')." "; 202 $renderer->doc .= "<select value=\"$maxRec\" id=\"maxRec\">"; 203 for ($i=0; $i<10; $i++) { 204 $renderer->doc .= "<option"; 205 if ($i==$maxRec) $renderer->doc .= " selected=\"selected\""; 206 $renderer->doc .= ">$i</option>"; 207 } 208 $renderer->doc .= "</select>"; 209 $renderer->doc .= " ".$this->getLang('fav_conf_prec')."<br />"; 210 $renderer->doc .= $this->getLang('fav_afficher')." "; 211 $renderer->doc .= "<select value=\"$maxFav\" id=\"maxFav\">"; 212 for ($i=0; $i<10; $i++) { 213 $renderer->doc .= "<option"; 214 if ($i==$maxFav) $renderer->doc .= " selected=\"selected\""; 215 $renderer->doc .= ">$i</option>"; 216 } 217 $renderer->doc .= "</select>"; 218 $renderer->doc .= " ".$this->getLang('fav_conf_pfav')."<br />"; 219 $renderer->doc .= "<input type=\"button\" value=\"".$this->getLang('fav_sauver')."\" onclick=\"javascript:sauvePref();\" />"; 220 $renderer->doc .= "</fieldset>"; 221 $renderer->doc .= "</div>"; 222 223 //Rafraichir 224 $renderer->doc .= ' <a href="javascript:recharge();"><img src="'.DOKU_URL.'lib/plugins/favoris/images/rafraichir.png" title="'.$this->getLang('fav_rafraichir').'" border="0" height="18" style="vertical-align:middle; display:none;" name="ctrl" /></a> '; 225 //Reset tous 226 $renderer->doc .= ' <a href="javascript:if(confirm(\''.$this->getLang('fav_confResetAll').'\')) {setCookie(\'favoris[off]\', 2, new Date(\'July 21, 2099 00:00:00\'), \'/\'); recharge();}"><img src="'.DOKU_URL.'lib/plugins/favoris/images/reset.png" title="'.$this->getLang('fav_resetall').'" border="0" height="18" style="vertical-align:middle; display:none;" name="ctrl" /></a> '; 227 //Desactiver 228 $renderer->doc .= ' <a href="javascript:if(confirm(\''.$this->getLang('fav_confirmation').'\')) {setCookie(\'favoris[off]\', 1, new Date(\'July 21, 2099 00:00:00\'), \'/\'); recharge();}"><img src="'.DOKU_URL.'lib/plugins/favoris/images/desactiver.png" title="'.$this->getLang('fav_desactiver').'" border="0" height="18" style="vertical-align:middle; display:none;" name="ctrl" /></a> '; 229 230 $renderer->doc .= "</div>"; 231 } 232 233 else { 234 $renderer->doc .= $this->getLang('fav_pasencore'); 235 } 236 } 237 return false; 238 } 239 240 241 function donneLien($page, $title="") { 242 if (!plugin_isdisabled('pagelist')) $pagelist = plugin_load('helper', 'pagelist'); 243 244 if (!$pagelist) { 245 $titrePage=explode(":",$page); 246 $titrePage=$titrePage[sizeof($titrePage)-1]; 247 $titrePage=str_replace('_',' ',$titrePage); 248 } 249 else { 250 $pagelist->page['id']=$page; 251 $pagelist->page['exists'] = 1; 252 $pagelist->_meta=NULL; 253 $titrePage = $pagelist->_getMeta('title'); 254 if (!$titrePage) $titrePage = str_replace('_', ' ', noNS($page)); 255 $titrePage = hsc($titrePage); 256 } 257 if (@file_exists(fullpath(wikiFN($page)))) return "<a href='doku.php?id=".$page."' class='wikilink1' style='font-weight: lighter;' title='$page".$title."'>$titrePage</a>"; 258 else return "<a href='doku.php?id=".$page."' class='wikilink2' style='font-weight: lighter;' title='$page".$title."' rel='nofollow'>$titrePage</a>"; 259 } 260} 261?> 262