Differences
This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision Next revision | Previous revision | ||
| dev:grapher-php [2020/10/06 07:26] – bab | dev:grapher-php [2020/11/01 15:59] (current) – bab | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== | + | <file php grapher.php |
| - | <code> | + | |
| # | # | ||
| <?php | <?php | ||
| if(!defined(' | if(!defined(' | ||
| - | requirrapher | + | require_once(DOKU_INC . ' |
| + | |||
| + | class Grapher | ||
| /** | /** | ||
| Line 29: | Line 30: | ||
| "graph with graphviz. The ' | "graph with graphviz. The ' | ||
| "about the found nodes and can be loaded in Gephi. Default: dot", | "about the found nodes and can be loaded in Gephi. Default: dot", | ||
| - | ' | + | ' |
| $options-> | $options-> | ||
| ' | ' | ||
| Line 57: | Line 58: | ||
| } | } | ||
| $format = $options-> | $format = $options-> | ||
| - | if(!in_array($format, | + | if(!in_array($format, |
| $this-> | $this-> | ||
| } | } | ||
| Line 74: | Line 75: | ||
| } elseif($format == ' | } elseif($format == ' | ||
| $this-> | $this-> | ||
| - | } | + | } elseif($format == ' |
| + | | ||
| + | } | ||
| fclose($fh); | fclose($fh); | ||
| } | } | ||
| Line 237: | Line 239: | ||
| $pages[$pid][' | $pages[$pid][' | ||
| } | } | ||
| - | // | ||
| return array(' | return array(' | ||
| Line 255: | Line 256: | ||
| fwrite($fh, " | fwrite($fh, " | ||
| - | fwrite($fh, "concentrate=true; | + | fwrite($fh, "labelloc=\" |
| - | // | + | |
| - | // | + | |
| - | splines=ortho; | + | |
| - | splines=spline; | + | |
| - | labelURL=\"http:// | + | |
| - | // | + | |
| - | // | + | |
| - | // | + | |
| - | size=\" | + | |
| - | ratio=compress; | + | |
| - | rankype=same; | + | |
| - | rankdir=TB; | + | |
| - | fixedsize=true; | + | |
| - | dpi=100; | + | |
| - | bgcolor=\" | + | |
| node [shape = \" | node [shape = \" | ||
| edge [arrowsize=2, | edge [arrowsize=2, | ||
| + | root=\" | ||
| + | |||
| + | subgraph corporations { | ||
| + | \" | ||
| + | \" | ||
| + | \" | ||
| + | \" | ||
| + | \" | ||
| + | } | ||
| + | |||
| + | subgraph leaks { | ||
| + | \" | ||
| + | \" | ||
| + | \" | ||
| + | } | ||
| + | |||
| + | subgraph countries { | ||
| + | \" | ||
| + | \" | ||
| + | \" | ||
| + | \" | ||
| + | |||
| + | } | ||
| \n"); | \n"); | ||
| Line 307: | Line 317: | ||
| // now create all the links | // now create all the links | ||
| foreach($pages as $id => $page) { | foreach($pages as $id => $page) { | ||
| - | foreach($page[' | + | for($n=0;$n<count($page[' |
| - | foreach($page[' | + | { |
| - | fwrite($fh, " | + | fwrite($fh, " |
| - | } | + | |
| } | } | ||
| - | /* | ||
| - | foreach($page[' | ||
| - | fwrite($fh, " | ||
| - | } | ||
| - | */ | ||
| } | } | ||
| fwrite($fh, " | fwrite($fh, " | ||
| Line 406: | Line 410: | ||
| fwrite($fh, " | fwrite($fh, " | ||
| fwrite($fh, "</ | fwrite($fh, "</ | ||
| + | | ||
| + | } | ||
| + | |||
| + | /* Create a JSON representation | ||
| + | */ | ||
| + | protected function create_json(& | ||
| + | | ||
| + | $pages =& $data[' | ||
| + | $media =& $data[' | ||
| + | $root_name = array_values($pages)[0][" | ||
| + | |||
| + | $output = '{ | ||
| + | " | ||
| + | " | ||
| + | $i=0; | ||
| + | // create all nodes first | ||
| + | foreach($pages as $id => $item){ | ||
| + | $i++; | ||
| + | $title = htmlspecialchars($item[' | ||
| + | $lang = htmlspecialchars($item[' | ||
| + | $output .= " | ||
| + | $output .= '" | ||
| + | $output .= '" | ||
| + | $output .= '" | ||
| + | $output .= '" | ||
| + | if (!empty( $item[' | ||
| + | { | ||
| + | $path = explode (":", | ||
| + | $file = count($path ); | ||
| + | $folder=""; | ||
| + | for($n=0 ; $n < $file-1 ; $n++) | ||
| + | { | ||
| + | $folder = $folder . $path[$n] . "/"; | ||
| + | } | ||
| + | $output .= '," | ||
| + | } | ||
| + | // $output .= '" | ||
| + | // $output .= '" | ||
| + | $output .= " | ||
| + | if ($i <= count($pages)-1) $output .= ','; | ||
| + | | ||
| + | } | ||
| + | |||
| + | // now create all the edges | ||
| + | | ||
| + | " | ||
| + | |||
| + | $cnt = 0; | ||
| + | foreach($pages as $id => $page){ | ||
| + | |||
| + | foreach($page[' | ||
| + | if ($cnt > 0) $output .= ','; | ||
| + | |||
| + | $output .= '{ | ||
| + | " | ||
| + | " | ||
| + | " | ||
| + | }'; | ||
| + | $cnt++; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | | ||
| + | $output .= " ] }"; | ||
| + | | ||
| + | fwrite($fh, | ||
| } | } | ||
| Line 413: | Line 484: | ||
| $grapher-> | $grapher-> | ||
| - | </code> | + | |
| + | |||
| + | |||
| + | </file> | ||