'; //last step by user $laststep = array(); $user = ''; $source = ''; $target = ''; foreach ($content as $line) { $path = explode($delimiter,$line); if (sizeof($path) == 3) { $user = $path[0]; $source = trim($path[1]); $target = trim($path[2]); } else { $data['errorcount']++; } // guard clauses // unautheticated user if ($registeredOnly) if (strcmp($user ,'-') == 0) continue; // one of the pages doesn't exist if ((!page_exists(str_replace('/',':',$source))) || (!page_exists(str_replace('/',':',$target)))) continue; // BUG: This is still not workin properly... // self-reference if (strcmp($source, $target) == 0) { continue; } // check for valid STEP if (!isset($lastmove[$user])) { $lastmove[$user] = array(); $lastmove[$user]['source'] = ''; $lastmove[$user]['target'] = ''; } if ((strcmp($source,$lastmove[$user]['source']) != 0) || (strcmp($target,$lastmove[$user]['target']) != 0)) { // compose step string $step = trim($source).'->'.trim($target); //error_log("step: ".$step); if (!isset($data[$step])) { $data[$step] = 1; } else { $data[$step]++; } } $lastmove[$user]['source'] = $source; $lastmove[$user]['target'] = $target; } return $data; } /** * generateDirections * This function produces the directions (incoming/outgoing pages) for a particular wiki page. * */ function dir_generateDirections($info, $data, $fanInOnly=false, $fanOutOnly=false, $showGraph=true) { // get current page id (name with namespace) $id = getID(); // parse data to find fan in and fan out // $data comes has associative array with step string (page1->page2) on "key" and occurences of step in "value". // find relevant steps first, order by ocurrences second. $graph = array(); foreach ($data as $key=>$value) { $pages = explode("->", $key); $page1 = str_replace('/',':',$pages[0]);$page1 = trim($page1); $page2 = str_replace('/',':',$pages[1]);$page2 = trim($page2); if (strcmp($id,$page1) == 0) { $index = $page1.'->'.$page2; $graph[$index] = $value; $fanOut[$page2] = $value; } if (strcmp($id,$page2) == 0) { $index = $page1.'->'.$page2; $graph[$index] = $value; $fanIn[$page1] = $value; } //sort if (isset($fanOut)) arsort($fanOut); if (isset($fanIn)) arsort($fanIn); } // return (printable) results $results .= dir_prettyPrintResults($fanIn, $fanInOnly, $fanOut, $fanOutOnly); if ($showGraph) { if(!in_array('graphviz',plugin_list())) { $results .= 'To view the graph the graphviz plug-in must be installed.'; } else { //graph $results .= dir_generateGraph($info, $graph); } } return $results; } /** * generateListofJumps * * prints out the table of 'jumps' of the whole wiki. * */ function dir_generateListofJumps($data) { global $conf; $trimLimit = $conf['plugin']['directions']['trim_limit']; $output = '
'; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; //sort descendently arsort($data); foreach ($data as $key=>$value) { $pages = explode("->", $key); $page1 = str_replace('/',':',$pages[0]); $page2 = str_replace('/',':',$pages[1]); $output .= ''; } $output .='
Jumps
FromTimesTo
'; $output .= ''.dir_trimPageTitle(dir_get_first_heading($page1),$trimLimit).''; $output .= ''; $output .= $value; $output .= ''; $output .= ''.dir_trimPageTitle(dir_get_first_heading($page2),$trimLimit).''; $output .= '
'; $output .='
'; return $output; } /** * dir_prettyPrintResults * * helper function that enables optional printing of "incoming" or "outgoing" (or both) sections of the directions table. * */ function dir_prettyPrintResults($fanIn, $fanInOnly, $fanOut, $fanOutOnly, $trimLimit) { global $conf; $maxdirections = $conf['plugin']['directions']['max_directions']; if (!isset($trimLimit)) $trimLimit = $conf['plugin']['directions']['trim_limit']; $limit = $maxdirections; if ($fanInOnly) { $output .= ''; $output .= ''; $output .= ''; $output .='
Incoming
'; // fan in foreach ($fanIn as $key=>$value) { $output .= ''.dir_trimPageTitle(dir_get_first_heading($key),$trimLimit).''; $output .= '('.$value.') ->
'; $limit--; if ($limit == 0) break; } $output .= '
'; return $output; } if ($fanOutOnly) { $output .= ''; $output .= ''; $output .= ''; $output .='
Outgoing
'; // fan out foreach ($fanOut as $key=>$value) { $output .= '-> '.dir_trimPageTitle(dir_get_first_heading($key),$trimLimit).''; $output .= '('.$value.')
'; $limit--; if ($limit == 0) break; } $output .= '
'; return $output; } $output = '
'; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .= ''; $output .='
Directions
IncomingOutgoing
'; // fan in foreach ($fanIn as $key=>$value) { $output .= ''.dir_trimPageTitle(dir_get_first_heading($key),$trimLimit).''; $output .= '('.$value.') ->
'; $limit--; if ($limit == 0) break; } $limit = $maxdirections; $output .= '
'; // fan out foreach ($fanOut as $key=>$value) { $output .= '-> '.dir_trimPageTitle(dir_get_first_heading($key),$trimLimit).''; $output .= '('.$value.')
'; $limit--; if ($limit == 0) break; } $output .= '
'; $output .='
'; return $output; } /** * dir_get_first_heading * * return the first heading of a page or, if nonexistant, the name of the page. * */ function dir_get_first_heading($page) { $heading = p_get_first_heading($page); if (!isset($heading)) $heading = $page; return $heading; } /** * dir_trimPageTitle * * trims the title of a page by $maxchars visible. Useful to printout title names as a preview... * */ function dir_trimPageTitle($title, $maxchars=19) { if (strlen($title) > $maxchars) return substr($title,0,$maxchars).'...'; return $title; } ?>