a13261f9d4e417d577f511812591437dd7b6acd2
[atutor.git] / mods / wiki / tools / mkpluginmap
1 #!/usr/local/bin/php -qC
2 <?php
3
4 #  This generates a list (printed to stdout) of available plugins/,
5 #  which can then be used for the "plugins/pluginloader.php" extension.
6 #
7 #
8
9
10 #-- read from directory
11 ($bdir = @$_SERVER["argv"][1])
12 or ($bdir = "plugins/");
13 $bdir = rtrim($bdir, "/");
14
15 #-- those plugins cannot be scanned
16 $skip = array(
17       "phplib", "you", "db_", "spell",
18       "spages", "mpi", "alias", "email_protect",
19       "auth", "db/", "imagegall", "debug",
20       "deletebutton.js", "log.php", "pageima",
21       "templ", "imgresiz", "forum", "phprequ",
22       "subpage", "lib/", "zero_p", "markup/",
23       "wikidump",
24 );
25 $skip = implode("|", $skip);
26
27 #-- make it cleaner
28 ini_set("html_errors", falqse);
29
30 #-- go
31 $found["action"][]=array("view", "", "", 0);
32 $found["action"][]=array("links", "", "", 0);
33 $found["action"][]=array("info", "", "", 0);
34 $found["action"][]=array("edit", "spellcheck.php", "", 0);
35 mkpm_dir($bdir); 
36
37 #-- print results
38 mkpm_dump($found);
39 die;
40
41
42 function mkpm_dir($dir) {
43
44    $dh = opendir($dir);
45    while ($dh && ($fn = readdir($dh))) {
46
47       if ($fn[0] == ".") {
48          continue;
49       }
50       elseif (is_dir("$dir/$fn")) {
51          mkpm_dir("$dir/$fn");
52       }
53       else {
54          mkpm_add("$dir/$fn");
55       }
56
57    }
58    closedir($dh);
59
60 }
61
62
63 function mkpm_add($fn) {
64    global $ewiki_plugins, $ewiki_config;
65    global $found, $bdir, $skip;
66
67    $ewiki_plugins = array();
68
69    #-- call
70    if (!strpos($fn, ".php")) {
71       return;
72    }
73    if (preg_match("#$skip#", $fn)) { 
74       return(0);
75    }
76 echo "@$fn\n";
77    include($fn);
78
79    #-- add to our lists
80    $fn = substr($fn, strlen($bdir) + 1);
81    foreach (array("page", "action", "action_always") as $sect) {
82
83       if ($a = $ewiki_plugins[$sect]) {
84 #<off>#         $sect = strtok($sect, "_");
85          foreach ($a as $name=>$pf) {
86             $found[$sect][] = array($name, $fn, $pf, 0);
87          }
88       }
89
90    }
91
92 }
93
94
95 function mkpm_dump($found) {
96    global $ewiki_config;
97    foreach (array("action", "action_always", "page") as $sect) {
98       if ($list = @$found[$sect]) {
99          echo "\$ewiki_plugins[\"dl\"][\"{$sect}\"] = array(\n";
100          foreach ($list as $a) {
101             echo "#\t\"{$a[0]}\" => array(\"{$a[1]}\", \"{$a[2]}\", {$a[3]}),\n";
102          }
103          echo ");\n\n";
104       }
105    }
106    foreach ($ewiki_config["action_links"] as $where=>$a) {
107       foreach ($a as $action=>$title) {
108          echo "\$ewiki_config[\"dl\"][\"action_links\"][\"$where\"][\"$action\"] = \"$title\";\n";
109       }
110    }
111    echo "\n";
112 }
113
114
115
116 function ewiki_t($a,$b=0) {
117    return($a);
118 }
119
120 ?>