OSDN Git Service

BugTrack/2557 touchgraph plugin: Update doc (exec on Windows) and URL
[pukiwiki/pukiwiki.git] / plugin / touchgraph.inc.php
1 <?php
2 // PukiWiki - Yet another WikiWikiWeb clone
3 // touchgraph.inc.php
4 // Copyright
5 //   2005-2022 PukiWiki Development Team
6 //
7 // Output an index for 'TouchGraph WikiBrowser'
8 // https://sourceforge.net/projects/touchgraph/
9 // https://www.touchgraph.com/
10 //
11 // Prepare:
12 //   On Windows OS, change console active codepage by chcp command
13 //   UTF-8:
14 //     chcp 65001
15 //   EUC-JP:
16 //     chcp 20932
17 //
18 // Usage: (Check also TGWikiBrowser's sample)
19 //    java -Dfile.encoding=UTF-8 -jar TGWikiBrowser.jar \
20 //    "http://<pukiwiki site>/?plugin=touchgraph" \
21 //    "http://<pukiwiki site>/?" FrontPage 2 true
22
23 function plugin_touchgraph_action()
24 {
25         global $vars;
26         pkwk_headers_sent();
27         header('Content-Type: text/plain; charset=' . SOURCE_ENCODING);
28         if (isset($vars['reverse'])) {
29                 plugin_touchgraph_ref();
30         } else {
31                 plugin_touchgraph_rel();
32         }
33         exit;
34 }
35
36 // Normal
37 function plugin_touchgraph_rel()
38 {
39         foreach (get_existpages() as $page) {
40                 if (check_non_list($page)) continue;
41
42                 $file = CACHE_DIR . encode($page) . '.rel';
43                 if (file_exists($file)) {
44                         echo $page;
45                         $data = file($file);
46                         foreach(explode("\t", trim($data[0])) as $name) {
47                                 if (check_non_list($name)) continue;
48                                 echo ' ', $name;
49                         }
50                         echo "\n";
51                 }
52         }
53 }
54
55 // Reverse
56 function plugin_touchgraph_ref()
57 {
58         foreach (get_existpages() as $page) {
59                 if (check_non_list($page)) continue;
60
61                 $file = CACHE_DIR . encode($page) . '.ref';
62                 if (file_exists($file)) {
63                         echo $page;
64                         foreach (file($file) as $line) {
65                                 list($name) = explode("\t", $line);
66                                 if (check_non_list($name)) continue;
67                                 echo ' ', $name;
68                         }
69                         echo "\n";
70                 }
71         }
72 }