*/
// based on http://wiki.splitbrain.org/plugin:tutorial
// must be run within Dokuwiki
if (!defined('DOKU_INC')) die();
if (!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN', DOKU_INC . 'lib/plugins/');
require_once(DOKU_PLUGIN . 'syntax.php');
/**
* All DokuWiki plugins to extend the parser/rendering mechanism
* need to inherit from this class
*/
class syntax_plugin_favoris extends DokuWiki_Syntax_Plugin {
function getInfo() {
return array(
'author' => 'Etienne M.',
'email' => 'emauvaisfr@yahoo.fr',
'date' => @file_get_contents(DOKU_PLUGIN.'favoris/VERSION'),
'name' => 'favoris Plugin',
'desc' => html_entity_decode($this->getLang('fav_description')),
'url' => 'http://www.dokuwiki.org/plugin:favoris'
);
}
function connectTo($mode) {
$this->Lexer->addSpecialPattern('~~FAVORIS~~', $mode, 'plugin_favoris');
}
//function getType() { return 'substition'; }
function getType() { return 'disabled'; }
function getSort() { return 667; }
function handle($match, $state, $pos, &$handler) {
return array($match, $state, $pos);
}
function render($mode, &$renderer, $data) {
$maxFav=5;
$maxRec=5;
if ($mode == 'xhtml') {
$renderer->info['cache'] = FALSE;
$renderer->doc .= '';
if (isset($_COOKIE['favoris'])) {
$fav=$_COOKIE['favoris'];
//Si la page off existe et vaut 1, on sort
if (isset($fav['off']) && $fav['off']==1) {
$renderer->doc .= $this->getLang('fav_desact');
//Activer
$renderer->doc .= ' '.$this->getLang('fav_activer').'. ';
$renderer->doc .= $this->getLang('fav_cookies').' ';
return;
}
//Si la page off existe et vaut 2, on recharge la page
if (isset($fav['off']) && $fav['off']==2) {
$renderer->doc .= "";
return;
}
//Combien de pages afficher au maximum ?
$max=$maxFav;
if (isset($_COOKIE['fav_maxFav'])) $max=$_COOKIE['fav_maxFav'];
if (intval($max) != $max) $max=$maxFav;
$maxFav=$max;
$max=$maxRec;
if (isset($_COOKIE['fav_maxRec'])) $max=$_COOKIE['fav_maxRec'];
if (intval($max) != $max) $max=$maxRec;
$maxRec=$max;
$renderer->doc .= '
';
//Pages recentes
//Tri des pages par date de visite decroissante
uasort($fav, create_function('$a, $b', '
list($cpt, $date1)=explode(";", $a);
list($cpt, $date2)=explode(";", $b);
if ($date1=="") $date1=0;
if ($date2=="") $date2=0;
$date1=intval($date1);
$date2=intval($date2);
if ($date1==$date2) return 0;
return ($date1 > $date2) ? -1 : 1;
'));
$idx1=0;
if ($maxRec>0) {
foreach ($fav as $page => $cpt) {
list($cpt, $date) = explode(";", $cpt);
if ($page=='off' || $cpt<1 || !$date) continue;
if (!$idx1) {
$renderer->doc .= "".$this->getLang('fav_prec')."";
$renderer->listu_open();
}
$lien = $this->donneLien($page, "");
$renderer->listitem_open(1);
$renderer->doc .= $lien;
$renderer->listitem_close();
$idx1++;
if ($idx1>=$maxRec) break;
}
}
if ($idx1) $renderer->listu_close();
//else $renderer->doc .= " ";
//Pages favorites
//Tri des pages par visites decroissantes
uasort($fav, create_function('$a, $b', '
list($cpt1, $date)=explode(";", $a);
list($cpt2, $date)=explode(";", $b);
$cpt1=intval($cpt1);
$cpt2=intval($cpt2);
if ($cpt1==$cpt2) return 0;
return ($cpt1 > $cpt2) ? -1 : 1;
'));
$idx2=0;
if ($maxFav>0) {
foreach ($fav as $page => $cpt) {
list($cpt, $date) = explode(";", $cpt);
if ($page=='off' || $cpt<1) continue;
if (!$idx2) {
$renderer->doc .= "".$this->getLang('fav_pfav')."";
$renderer->listu_open();
}
$lien = $this->donneLien($page, " ($cpt ".$this->getLang('fav_visites').")");
$renderer->doc .= "