1 #!/usr/local/bin/php -Cq
5 this utility assembles a .xpi/.jpi file (installable ewiki plugin)
10 The 'xpi-source-file' holds a rfc822-style list of settings and text
12 | id: ThePluginIdOrPageName (REQ)
13 | type: page (REQ; "page" or "init")
14 | license: PublicDomain (OPT)
17 | description: ... (OPT; notes/comments about plugin)
18 | code: ... (REQ; multiline field)
20 All entries, but especially 'description' and 'code' can be multiline
21 entries. The 'code' entry is followed by PHP code, with optional
22 surrounding <?php and ?> tags.
23 For "page" plugins it is simply the code (no function definition!) that
24 would normally be put into a page plugin func, but that you cannot use
25 return() and instead throw all output via the '$o' variable (workaround).
27 For "init" (any type: string will do) xpi plugins, you can add function
28 definitions and ewiki_plugin[] registry settings as usual. The execution
29 of that code is however not guaranteed to happen in global scope - most
30 of the ewiki_* vars are however accessible.
32 The special "jpi" type plugins are "page" plugins, but you must use
33 JavaScript code, so it can safely be executed in a sandbox (phpjs)
34 with the limited WikiApi functionality. Then however everybody can
35 install those .jpi plugins. (not yet ready)
39 function srcxpi2xpi($str) {
46 $uu = preg_split('/^(\w+):/m', $str, $uu, PREG_SPLIT_DELIM_CAPTURE);
47 for ($i=1; $i<count($uu); $i+=2) {
49 $id = strtolower(trim($uu[$i]));
50 $val = trim($uu[$i+1]);
56 if (strpos($xpi["code"], '<?')===0) {
57 $xpi["code"] = trim(preg_replace('/<\?(php|js)+|<\?|\?>/', '', $xpi["code"]));
61 if ($xpi["type"] == "jpi") {
62 $xpi["JPI"] = $xpi["XPI"];
69 if ($file = $_SERVER["argv"][1]) {
70 echo "reading '$file'...";
71 if ($src = implode("", file($file))) {
72 $r = srcxpi2xpi($src);
75 $fn .= ($r["JPI"] ? ".jpi" : ".xpi");
76 echo "writing '
\e[33m".$fn."
\e[37m'...";
77 if ($f = gzopen($fn, "wb9")) {
78 gzwrite($f, serialize($r));
80 echo "
\e[32mdone
\e[37m.";
85 echo "
\e[31minvalid sorce file
\e[37m.\n";
90 echo "syntax: mkxpi xpi-src-file\n";