'; }
elseif (($rater_end!='never') || (strtotime($today) <= strtotime($rater_end)))
{ $ret_details = '
'.sprintf($msg_ratingend,date('d.m.Y',strtotime($data['rater_end']))).'
';
$alink_Details = '
(Details)';}
else
{ $ret_details ='
';
$alink_Details = '';}
if ($data['rater_tracedetails']==='1') {
if ($alink_Details === '')
{
$alink_Details = '(Details)'; }
$ret_details .= ' '.$r1.' visitor votes
';
$ret_details .= ' '.$r2.' visitor votes
';
$ret_details .= ' '.$r3.' visitor votes
';
$ret_details .= ' '.$r4.' visitor votes
';
$ret_details .= ' '.$r5.' visitor votes';
}
$ret_details .= '
';
// Output rate
$rater_img_xhtml = "";
if($rater_img!=false) {
// render the image link and output centralized within rater box
$info = array();
$rater_img_xhtml = p_render('xhtml',p_get_instructions("{{".$rater_img."}}"),$info);
$rater_img_xhtml = str_replace("
","",$rater_img_xhtml);
$rater_img_xhtml = str_replace("
","",$rater_img_xhtml);
$rater_img_xhtml = '
'.$rater_img_xhtml.' |
'.NL;
}
$ret .= '
';
}
/******************************************************************************/
elseif ($rater_type=="vote") {
// Get current rating
if(is_file($rater_filename)){
$rater_file=fopen($rater_filename,"r");
$rater_str="";
$rater_str = fread($rater_file, 1024*8);
if($rater_str!=""){
$rater_data=explode($rater_end_of_line_char,$rater_str);
$rater_votes=count($rater_data)-1;
$vote1='0';
$vote2='0';
foreach($rater_data as $d){
$d=explode("|",$d);
if ($d[0]==='1') {
$vote1 = $vote1 +1;
$who1 .= $d[1]."
";
}
elseif ($d[0]==='2') {
$vote2 = $vote2 +1;
$who2 .= $d[1]."
";
}
}
}
else{
$vote1='0';
$vote2='0';
}
fclose($rater_file);
}
$rater_img_xhtml = "";
if($rater_img!=false) {
// render the image link and output centralized within rater box
$info = array();
$rater_img_xhtml = p_render('xhtml',p_get_instructions("{{".$rater_img."}}"),$info);
$rater_img_xhtml = str_replace("
","",$rater_img_xhtml);
$rater_img_xhtml = str_replace("
","",$rater_img_xhtml);
$rater_img_xhtml = '
'.$rater_img_xhtml.' |
'.NL;
}
//check if vote period already ended
if (($rater_end!='never') && (strtotime($today) > strtotime($rater_end)))
{$rater_endmsg = sprintf($msg_votended,date('d.m.Y',strtotime($data['rater_end']))).'
';}
elseif (($rater_end!='never') || (strtotime($today) <= strtotime($rater_end)))
{$rater_endmsg = sprintf($msg_votend,date('d.m.Y',strtotime($data['rater_end']))).'
';}
else
{$rater_endmsg ='';}
// build the return value for details if details option is on
$ret_details = '
'.$rater_endmsg;
if ($data['rater_tracedetails']==='1') {
$ret_details .= '
('.$vote1.')
'. $who1.'
';
$ret_details .= '
('.$vote2.')
'. $who2.'
';
}
$ret_details .= '';
// Output vote
// $ret .= '
';
}
/******************************************************************************/
elseif (($rater_type=="stat") || ($rater_type=="localstat")) {
global $conf;
// 1. load all rating files into array
// create an array of all rating files
$delim1 = ".rating";
$delim2 = ".txt";
clearstatcache();
$listRatingFiles = $this->list_files_in_array($conf['metadir'], $delim1, $params_array);
// create a list of all page-files, consider ns syntax parameer
if(strlen($rater_ns)>1) {
if(is_file($conf['datadir']."/".str_replace(":","/",$rater_ns))) {
$listPages = array($conf['datadir']."/".str_replace(":","/",$rater_ns));
}
else {
$r_datadir = $conf['datadir']."/".str_replace(":","/",$rater_ns);
$listPages = $this->list_rec_files_in_array($r_datadir, $delim2, $params_array);
}
}
else {
$r_datadir = $conf['datadir'];
$listPages = $this->list_rec_files_in_array($r_datadir, $delim2, $params_array);
}
// loop through all wiki pages
$returns['ratings'] = array();
$returns['votings'] = array();
if ($rater_type=="stat") {
foreach($listPages as &$page_filepath) {
//read the content of the page file to be analyzed for rater items
$body = '';
$body = file_get_contents($page_filepath);
// find all rater items on this page file
$links = array();
// define('LINK_PATTERN', "/\{\{.*\}\}/");
$body = preg_replace('/
.*?<\/code>/si', '', $body);
define('LINK_PATTERN', "(rater>[^}]*)");
// check for rater syntax on current page
if( preg_match(LINK_PATTERN, $body) ) {
preg_match_all(LINK_PATTERN, $body, $links);
}
// loop through all rater items of this page
// needs: $links, $listRatingFiles, $page_filepath, $returns
// returns: $found_ratings, $found_votings
if (count($links)>0) $returns = $this->rater_on_page($links, $listRatingFiles, $page_filepath, $returns);
}
}
elseif ($rater_type=="localstat") {
$tmp = pageinfo();
$body = '';
$body = file_get_contents($tmp['filepath']);
// find all rater items on this page file
$links = array();
// define('LINK_PATTERN', "/\{\{.*\}\}/");
$body = preg_replace('/.*?<\/code>/si', '', $body);
define('LINK_PATTERN', "(rater>[^}]*)");
// check for rater syntax on current page
if( preg_match(LINK_PATTERN, $body) ) {
preg_match_all(LINK_PATTERN, $body, $links);
}
if (count($links)>0) $returns = $this->rater_on_page($links, $listRatingFiles, $tmp['filepath'], $returns);
}
$found_ratings = $returns['ratings'];
$found_votings = $returns['votings'];
// calculate ratings
for ($a=0;$acalc_rater_rating($rater_filename);
$rater_rating = $tmp_array[0][0];
if($rater_rating=='') $rater_rating='0.00';
if ($tmp_array[0][1] < 1) { $tmp_array[0][1] = '0'; }
if ($tmp_array[0][2] < 1) { $tmp_array[0][2] = '0'; }
if ($tmp_array[0][3] < 1) { $tmp_array[0][3] = '0'; }
if ($tmp_array[0][4] < 1) { $tmp_array[0][4] = '0'; }
if ($tmp_array[0][5] < 1) { $tmp_array[0][5] = '0'; }
if ($tmp_array[0][6] < 1) { $tmp_array[0][6] = '0'; }
if ($tmp_array[0][7] < 1) { $tmp_array[0][7] = '0'; }
$found_ratings[$a][] = array('value' => $rater_rating);
$rater_stars = $this->assign_star_image($rater_rating);
$found_ratings[$a][] = array('image' => $rater_stars);
$found_ratings[$a][] = array($tmp_array[0][1],$tmp_array[0][2],$tmp_array[0][3],$tmp_array[0][4],$tmp_array[0][5],$tmp_array[0][6]);
}
}
// sort array
if($rater_stat_sort=='') $rater_stat_sort = 'value' ;
$found_ratings = $this->array_sort($found_ratings, $rater_stat_sort, SORT_DESC);
// script template
$ret_script = '';
// calculate votes
for ($a=0;$acalc_rater_voting($rater_filename);
// returns array($rater_votes, $r1, $who1, $r2, $who2, $rater_sum)
$rater_voting = $tmp_array[0][0];
if($rater_voting=='') $rater_voting='0';
if ($tmp_array[0][1] < 1) { $tmp_array[0][1] = '0'; } // no thumb-up votes so far
if ($tmp_array[0][3] < 1) { $tmp_array[0][3] = '0'; } // no thumb-down votes so far
$found_votings[$a][] = array('value' => $rater_voting);
$found_votings[$a][] = array($tmp_array[0][1], $tmp_array[0][2],$tmp_array[0][3],$tmp_array[0][4]);
$found_votings[$a][] = array('votes' => $tmp_array[0][0],);
//number_format(($rater_sum/$rater_votes), 2, '.', '');
if(($tmp_array[0][1]+$tmp_array[0][3])>0) $calc_result=($tmp_array[0][1]/($tmp_array[0][1]+$tmp_array[0][3])*100);
else $calc_result=0;
$rater_thumbs = ' ('.$tmp_array[0][1].') '.
'
'.number_format($calc_result,2,'.','').'% '.NL;
if($data['rater_tracedetails']=== '1') {
$rater_thumbs .= $ret_script1.
'
(Details)'.
'
'.$tmp_array[0][2].'
'.
'
'.NL;
}
if(($tmp_array[0][1]+$tmp_array[0][3])>0) $calc_result=($tmp_array[0][3]/($tmp_array[0][1]+$tmp_array[0][3])*100);
else $calc_result=0;
$rater_thumbs .= ' ('.$tmp_array[0][3].') '.
'
'.number_format($calc_result,2,'.','').'% '.NL;
if($data['rater_tracedetails']=== '1') {
$rater_thumbs .= $ret_script2.
'
(Details)'.
'
'.$tmp_array[0][4].'
'.
'
'.NL;
}
$found_votings[$a][] = array('image' => $rater_thumbs);
}
}
// sort array
if($rater_stat_sort=='') $rater_stat_sort = 'value' ;
$found_ratings = $this->array_sort($found_ratings, $rater_stat_sort, SORT_DESC);
// script to make table sortable
$ret .='
';
$d2="";
// output statistic table
if (strlen($rater_zoom) >0) {
$d2 = 'Thumbs | '.NL;
}
if($rater_sid!=false) {
$d2 .= 'ID | '.NL;
}
$ret .= '
'.$d2.'
Item |
Value |
Details |
';
foreach($found_ratings as $findings) {
$dtls_id = uniqid((double)microtime()*1000000,1);
$alink_id++;
$blink_id = 'statanker_'.$alink_id;
$anker_id = 'anker_'.$alink_id;
$info = array();
$d3 ="";
$d1=array();
if (strlen($rater_zoom) >0) {
$d1=explode("?",$findings['img']);
if(strlen($d1[0])>1) {
$rater_img_xhtml = p_render('xhtml',p_get_instructions("{{".trim($d1[0])."?".$rater_zoom."}}"),$info);
$rater_img_xhtml = str_replace("","",$rater_img_xhtml);
$rater_img_xhtml = str_replace("
","",$rater_img_xhtml);
}
else $rater_img_xhtml=" ";
$d3 = ''.$rater_img_xhtml.' | '.NL;
}
if ($rater_sid!=false) {
$d3 .= ''.$findings['id'].' | ';
}
$ret .= ''.
$d3.
''.$findings['item'].' | '.
''.$findings[0]['value'].' | '.
''.$ret_script1.
''.
' '.$findings[2][5].' votes ';
if($data['rater_tracedetails']=== '1') {
$ret_details =' ';
$ret_details .= ' '.$findings[2][0].' visitor votes ';
$ret_details .= ' '.$findings[2][1].' visitor votes ';
$ret_details .= ' '.$findings[2][2].' visitor votes ';
$ret_details .= ' '.$findings[2][3].' visitor votes ';
$ret_details .= ' '.$findings[2][4].' visitor votes';
$ret_details .= ' ';
$ret_script1 = str_ireplace('$blink_id', $blink_id, $ret_script);
$ret .= '(Details)'.
''.$ret_details.' '.NL;
}
$ret .= ' |
';
}
foreach($found_votings as $findings) {
// build the return value for details if details option is on
$dtls_id = uniqid((double)microtime()*1000000,1);
$alink_id++;
$blink_id = 'statanker_'.$alink_id;
$anker_id = 'anker_'.$alink_id;
$info = array();
$d3 = '';
$d1=array();
if($data['rater_tracedetails']=== '1') {
// build the return value for details
$ret_details = '';
$ret_details .= '
('.$findings[0][0].')
'. $findings[0][1].'
';
$ret_details .= ' ('.$findings[0][2].')
'. $findings[0][3].'
';
$ret_details .= '';
}
if (strlen($rater_zoom) >0) {
$d1=explode("?",$findings['img']);
if(strlen($d1[0])>1) {
$rater_img_xhtml = p_render('xhtml',p_get_instructions("{{".trim($d1[0])."?".$rater_zoom."}}"),$info);
$rater_img_xhtml = str_replace("","",$rater_img_xhtml);
$rater_img_xhtml = str_replace("
","",$rater_img_xhtml);
}
else $rater_img_xhtml=" ";
$d3 = ''.$rater_img_xhtml.' | ';
}
if ($rater_sid!=false) {
$d3 .= ''.$findings['id'].' | ';
}
$ret .= ''.
$d3.
''.$findings['item'].' | '.
''.$findings[2]['votes'].' votes | '.
''.$findings[3]['image'].
' | '.
'
';
}
$ret .= '
'.NL;
}
// Render
$renderer->doc .= $ret;
}
}
/******************************************************************************/
function assign_star_image($rater_rating) {
// Assign star image
if ($rater_rating <= 0 ){$rater_stars = DOKU_BASE."lib/plugins/rater/img/00star.gif";$rater_stars_txt="Not Rated";}
if ($rater_rating >= 0.5){$rater_stars = DOKU_BASE."lib/plugins/rater/img/05star.gif";$rater_stars_txt="0.5";}
if ($rater_rating >= 1 ){$rater_stars = DOKU_BASE."lib/plugins/rater/img/1star.gif";$rater_stars_txt="1";}
if ($rater_rating >= 1.5){$rater_stars = DOKU_BASE."lib/plugins/rater/img/15star.gif";$rater_stars_txt="1.5";}
if ($rater_rating >= 2 ){$rater_stars = DOKU_BASE."lib/plugins/rater/img/2star.gif";$rater_stars_txt="2";}
if ($rater_rating >= 2.5){$rater_stars = DOKU_BASE."lib/plugins/rater/img/25star.gif";$rater_stars_txt="2.5";}
if ($rater_rating >= 3 ){$rater_stars = DOKU_BASE."lib/plugins/rater/img/3star.gif";$rater_stars_txt="3";}
if ($rater_rating >= 3.5){$rater_stars = DOKU_BASE."lib/plugins/rater/img/35star.gif";$rater_stars_txt="3.5";}
if ($rater_rating >= 4 ){$rater_stars = DOKU_BASE."lib/plugins/rater/img/4star.gif";$rater_stars_txt="4";}
if ($rater_rating >= 4.5){$rater_stars = DOKU_BASE."lib/plugins/rater/img/45star.gif";$rater_stars_txt="4.5";}
if ($rater_rating >= 5 ){$rater_stars = DOKU_BASE."lib/plugins/rater/img/5star.gif";$rater_stars_txt="5";}
return $rater_stars;
}
/******************************************************************************/
function array_sort($array, $on, $order)
{
$new_array = array();
$sortable_array = array();
if (count($array) > 0) {
foreach ($array as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $on) {
$sortable_array[$k] = $v2;
}
}
} else {
$sortable_array[$k] = $v;
}
}
switch ($order) {
case SORT_ASC:
asort($sortable_array);
break;
case SORT_DESC:
arsort($sortable_array);
break;
}
foreach ($sortable_array as $k => $v) {
$new_array[$k] = $array[$k];
}
}
return $new_array;
}
/******************************************************************************/
function calc_rater_rating($rater_filename) {
$rater_end_of_line_char = $this->getConf('eol_char');
if($rater_end_of_line_char == '') $rater_end_of_line_char = '\n';
$rater_file=fopen($rater_filename,"r");
$rater_str="";
$rater_str = fread($rater_file, 1024*8);
if($rater_str!=""){
$rater_data=explode($rater_end_of_line_char,$rater_str);
$rater_votes=count($rater_data)-1;
$rater_sum=0;
foreach($rater_data as $d){
$d=explode("|",$d);
$rater_sum+=$d[0];
// collect votes per level to display the details
if ($d[0] === '1' ){$r1 = $r1 + 1;}
if ($d[0] === '2' ){$r2 = $r2 + 1;}
if ($d[0] === '3' ){$r3 = $r3 + 1;}
if ($d[0] === '4' ){$r4 = $r4 + 1;}
if ($d[0] === '5' ){$r5 = $r5 + 1;}
}
if($rater_votes>0) $rater_rating=number_format(($rater_sum/$rater_votes), 2, '.', '');
}
fclose($rater_file);
$tmp_array[] = array($rater_rating,$r1,$r2,$r3,$r4,$r5,$rater_votes,$rater_sum);
return $tmp_array;
}
/******************************************************************************/
function calc_rater_voting($rater_filename) {
$rater_end_of_line_char = $this->getConf('eol_char');
if($rater_end_of_line_char == '') $rater_end_of_line_char = '\n';
$rater_file=fopen($rater_filename,"r");
$rater_str="";
$rater_str = fread($rater_file, 1024*8);
if($rater_str!=""){
$rater_data=explode($rater_end_of_line_char,$rater_str);
$rater_votes=count($rater_data)-1;
$rater_sum=0;
foreach($rater_data as $d){
$d=explode("|",$d);
$rater_sum++;
if($d[1]=="") $d[1] = $this->getLang('foreigner'); // text & styling
// collect votes per level to display the details
if ($d[0] === '1' ){$r1++;$who1 .= $d[1]."
";}
if ($d[0] === '2' ){$r2++;$who2 .= $d[1]."
";}
}
if (!$r1) { $r1='0'; $who1 = ''; }
if (!$r2) { $r2='0'; $who2 = ''; }
$rater_rating=$r1." : ".$r2;
}
fclose($rater_file);
$tmp_array[] = array($rater_votes, $r1, $who1, $r2, $who2, $rater_sum);
// echo '
'.var_dump($tmp_array).'
';
return $tmp_array;
}
/******************************************************************************/
// search given directory store all files into array
function list_files_in_array($dir, $delim)
{
$listDir = array();
if($handler = opendir($dir)) {
while (FALSE !== ($sub = readdir($handler))) {
if ($sub !== "." && $sub !== "..") {
if(is_file($dir."/".$sub)) {
$x = strpos(basename($dir."/".$sub),$delim);
if(($x > 0)){
$listDir[] = $dir."/".$sub;
}
//if(DEBUG) echo sprintf("%s
\n", $dir."/".$sub);
}
}
}
closedir($handler);
}
return $listDir;
}
/******************************************************************************/
// search given directory recursively and store all files into array
function list_rec_files_in_array($dir, $delim, $excludes)
{
$max_count_files = 10;
$listDir = array();
if($handler = opendir($dir)) {
while (FALSE !== ($sub = readdir($handler))) {
if ($sub !== "." && $sub !== "..") {
if(is_file($dir."/".$sub)) {
$x = strpos(basename($dir."/".$sub),".txt");
if(($delim === '.txt') && ($x > 0)){
$listDir[] = $dir."/".$sub;
}
elseif($delim === 'all') {
$listDir[] = $dir."/".$sub;
}
}
elseif(is_dir($dir."/".$sub)) {
$listDir[$sub] = $this->list_rec_files_in_array($dir."/".$sub, $delim,$excludes);
}
}
}
closedir($handler);
}
$listDir = $this->array_flat($listDir);
sort($listDir);
return $listDir;
}
/******************************************************************************/
// flatten the hierarchical arry to store path + file at first "column"
function array_flat($array) {
$out=array();
foreach($array as $k=>$v){
if(is_array($array[$k])) { $out=array_merge($out,$this->array_flat($array[$k])); }
else { $out[]=$v; }
}
return $out;
}
/******************************************************************************/
// to elaborate the ns:page for stat link to rater obj on the pages
function __savedir($page_filepath) {
global $conf;
$savedir = $this->getConf('savedir');
if($savedir == '') $savedir='data';
$savedir = str_replace("../", "", $savedir);
$savedir = str_replace("./", "", $savedir);
$y_pos = stripos($page_filepath, $savedir."/pages");
$t1 = substr($page_filepath, $y_pos);
$t1 = substr(str_replace( ".txt" , "" , $t1 ) , strlen($savedir."/pages"), 9999);
// turn it into wiki link without "pages"
$t2 = str_replace("/", ":", $t1);
$t2 = substr($t2, 1, strlen($t2));
//echo '('.$savedir.') '.$t2.'
';
return $t2;
}
/******************************************************************************/
// search and load all rater objects of a given page
function rater_on_page($links, $listRatingFiles, $page_filepath, $returns) {
foreach($links as $wse) {
foreach($wse as $link) {
// strip präfix "rater>" = left 6 signs and last sign = ")"
$link = substr($link,6,-1);
$type = '';
$img = '';
$name = '';
// ignore all "type=stat" references
if ((stripos($link,"type=stat") === false) && (stripos($link,"type=localstat") === false)) {
// extract rater file name
$fileReference = explode("|",$link);
foreach ($fileReference as $param) {
if(stripos($param,"id=")!== false) { $rater_id = substr($param,4); }
elseif(stripos($param,"name=")!== false) {
$name = substr($param,5);
$needles = array(":","/","\\");
$name = str_replace($needles, "_", $name);
}
elseif(stripos($param,"type=")!== false) { $type = substr($param,5); }
elseif(stripos($param,"img=")!== false) { $img = substr($param,4); }
}
$cFlag = false;
// loop through rater list to find matching rater
foreach($listRatingFiles as $ratingFile) {
// check if rater name is part of path
if(stripos($ratingFile,$this->sonderzeichen($rater_id.'_'.$name.'_'.$type))>0) {
//extract page file name
$p_filename = basename($page_filepath);
//cut everything before pages/ from link
$t2 = $this->__savedir($page_filepath);
// make a link out of it
//$t1 = html_wikilink(':'.$t2, $rater_id.' '.$name);
$t1 = html_wikilink(':'.$t2, $name);
// differ between rate and vote
if (stripos($ratingFile,'rate.rating')>0){
$rate_counter = $rate_counter+1;
// store page file and rater file link for output
$returns['ratings'][] = array('id' => $rater_id, 'item' => $t1 , 'file' => basename($ratingFile), 'img' => $img);
$cFlag = true;
break;
}
elseif (stripos($ratingFile,'vote.rating')>0){
$vote_counter = $vote_counter+1;
// store page file and rater file link for output
$returns['votings'][] = array('id' => $rater_id, 'item' => $t1 , 'file' => basename($ratingFile), 'img' => $img);
$cFlag = true;
break;
}
}
}
// link on page but rater file not existent due to no votes registerd so far
if($cFlag === false) {
$mis_counter = $mis_counter+1;
//extract page file name
$p_filename = basename($page_filepath);
//cut everything before pages/ from link
$t2 = $this->__savedir($page_filepath);
// make a link out of it
$t1 = html_wikilink(':'.$t2,$rater_id.' '.$name);
// store page file where rater file not existent
$found_nok[] = $t1 . " : " . basename($ratingFile);
}
}
}
}
return $returns;
}
/******************************************************************************/
function sonderzeichen($string)
{
// utf8 decoding in function call not valid anymore, following deleted there
// utf8_decode($rater_id.'_'.$name.'_'.$type)
// former replacements for German umlauts now in language files defined
// $search = array(" ", "ä", "ö", "ü", "Ä", "Ö", "Ü", "ß", "´", "&");
// $replace = array("_", "ae", "oe", "ue", "Ae", "Oe", "Ue", "ss", "", "");
$search = explode(",",$this->getLang('search'));
$replace = explode(",",$this->getLang('replace'));
$string = str_replace($search, $replace, $string);
return $string;
}
/******************************************************************************/
}