'HandleVoix')); SDVA($HandleAuth, array('voix' => 'edit')); SDV($QualifyPatterns["/(\\(:)(voix-.*?:\\))/"], '$1x$2'); SDV($VoixSummary, "{percent}%"); SDV($VoixHTML, "-{neg} · {summary} · +{pos}"); Markup('voix', 'inline', "/\\(:(x)?voix-(\\w+)\\s*(-\\d+)?\\s*(\\+\\d+)?\\s*:\\)/e", "FmtVoix(\$pagename,'$1','$2','$3','$4')"); function FmtVoix($pagename, $remote, $id, $neg, $pos) { global $VoixHTML, $VoixSummary, $HTMLStylesFmt; $HTMLStylesFmt['voix'] = " a.voixlink { text-decoration: none; padding: 0 .1em; } a.voixdown { color: red; border: 1px solid red; background-color: #ffdddd;} a.voixup { color: green; border: 1px solid green; background-color: #ddffdd;} .voixsummary { } "; $neg = intval($neg); $pos = intval($pos); $count = $pos-$neg; $diff = $pos+$neg; $percent = $count? round($pos/$count*100) : 0; $votes = array( '{neg}' => abs($neg), '{pos}' => $pos, '{id}' => $id, '{diff}' => $pos+$neg, '{percent}' => $percent, '{count}' => $count, ); $summary = str_replace(array_keys($votes), array_values($votes), $VoixSummary ); $votes['{summary}'] = $summary; $out = $remote ? $summary : str_replace(array_keys($votes), array_values($votes), $VoixHTML ); return Keep(FmtPageName($out, $pagename)); } function HandleVoix($pagename, $auth="edit") { global $ChangeSummary, $Now, $VoixRecalcIP; $id = @$_GET['id']; $vote = @$_GET['voix']; if(!preg_match('/^\\w+$/', $id) || !preg_match('/^(up|down)$/', $vote) ) Abort('Invalid counter ID or unrecognized Vote.'); $page = RetrieveAuthPage($pagename, $auth); if(!$page) Abort('Page could not be retrieved.'); if(!preg_match("/\\(:voix-$id\\s*(-\\d+)?\\s*(\\+\\d+)?\\s*:\\)/", $page['text'], $m)) Abort('Counter ID not found.'); $new = $page; $search = $m[0]; $neg = abs(intval($m[1])); $pos = intval($m[2]); $ip = $_SERVER['REMOTE_ADDR']; if(IsEnabled($VoixRecalcIP, 1) ) { foreach($new as $k=>$v) { if(strpos($k, 'csum:')===false) continue; if(strpos($v, "Voix : $id : ")===false ) continue; $time = substr($k, 5); if($new["host:$time"] != $ip) continue; $prev_vote = trim(substr($v, strlen("Voix : $id : ") )); if($prev_vote == 'up') $pos--; elseif($prev_vote == 'down') $neg--; else Abort('Previous vote not recognized from history.'); } } $neg = max($neg, 0); $pos = max($pos, 0); if($vote == 'down')$neg++; if($vote == 'up') $pos++; $replace = "(:voix-$id -$neg+$pos:)"; if($replace!=$search) $new['text'] = str_replace($search, $replace, $new['text']); if($new['text']!=$page['text']) { $csum = "Voix : $id : $vote"; $new['csum'] = $new["csum:$Now"] = $ChangeSummary = $csum; $_POST['diffclass']='minor'; UpdatePage($pagename, $page, $new); } Redirect($pagename); }