1 |
henoheno |
1.1 |
<?php |
2 |
|
|
///////////////////////////////////////////////// |
3 |
|
|
// PukiWiki - Yet another WikiWikiWeb clone. |
4 |
|
|
// |
5 |
henoheno |
1.2 |
// $Id: plugin.php,v 1.1 2004/08/01 01:54:35 henoheno Exp $ |
6 |
henoheno |
1.1 |
// |
7 |
|
|
|
8 |
henoheno |
1.2 |
// プラグイン用に未定義のグローバル変数を設定 |
9 |
henoheno |
1.1 |
function set_plugin_messages($messages) |
10 |
|
|
{ |
11 |
henoheno |
1.2 |
foreach ($messages as $name=>$val) { |
12 |
|
|
if (! isset($GLOBALS[$name])) $GLOBALS[$name] = $val; |
13 |
henoheno |
1.1 |
} |
14 |
|
|
} |
15 |
|
|
|
16 |
|
|
//プラグインが存在するか |
17 |
|
|
function exist_plugin($name) |
18 |
|
|
{ |
19 |
henoheno |
1.2 |
$name = strtolower($name); // 大文字と小文字を区別しないファイルシステム対策 |
20 |
|
|
if (preg_match('/^\w{1,64}$/', $name) && |
21 |
|
|
file_exists(PLUGIN_DIR . $name . '.inc.php')) { |
22 |
henoheno |
1.1 |
require_once(PLUGIN_DIR . $name . '.inc.php'); |
23 |
|
|
return TRUE; |
24 |
henoheno |
1.2 |
} else { |
25 |
|
|
return FALSE; |
26 |
henoheno |
1.1 |
} |
27 |
|
|
} |
28 |
|
|
|
29 |
|
|
//プラグイン関数(action)が存在するか |
30 |
|
|
function exist_plugin_action($name) { |
31 |
|
|
return function_exists('plugin_' . $name . '_action') ? TRUE : exist_plugin($name) ? |
32 |
|
|
function_exists('plugin_' . $name . '_action') : FALSE; |
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
//プラグイン関数(convert)が存在するか |
36 |
|
|
function exist_plugin_convert($name) { |
37 |
|
|
return function_exists('plugin_' . $name . '_convert') ? TRUE : exist_plugin($name) ? |
38 |
|
|
function_exists('plugin_' . $name . '_convert') : FALSE; |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
//プラグイン関数(inline)が存在するか |
42 |
|
|
function exist_plugin_inline($name) { |
43 |
|
|
return function_exists('plugin_' . $name . '_inline') ? TRUE : exist_plugin($name) ? |
44 |
|
|
function_exists('plugin_' . $name . '_inline') : FALSE; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
//プラグインの初期化を実行 |
48 |
|
|
function do_plugin_init($name) |
49 |
|
|
{ |
50 |
henoheno |
1.2 |
static $checked = array(); |
51 |
henoheno |
1.1 |
|
52 |
henoheno |
1.2 |
if (! isset($checked[$name])) { |
53 |
|
|
$func = 'plugin_' . $name . '_init'; |
54 |
|
|
if (function_exists($func)) { |
55 |
|
|
// TRUE or FALSE or NULL (return nothing) |
56 |
|
|
$checked[$name] = call_user_func($func); |
57 |
|
|
} else { |
58 |
|
|
// Not exists |
59 |
|
|
$checked[$name] = null; |
60 |
|
|
} |
61 |
henoheno |
1.1 |
} |
62 |
henoheno |
1.2 |
return $checked[$name]; |
63 |
henoheno |
1.1 |
} |
64 |
|
|
|
65 |
|
|
//プラグイン(action)を実行 |
66 |
|
|
function do_plugin_action($name) |
67 |
|
|
{ |
68 |
henoheno |
1.2 |
if (! exist_plugin_action($name)) return array(); |
69 |
|
|
|
70 |
|
|
if(do_plugin_init($name) === FALSE) |
71 |
|
|
die_message("Plugin init failed: $name"); |
72 |
henoheno |
1.1 |
|
73 |
henoheno |
1.2 |
$retvar = call_user_func('plugin_' . $name . '_action'); |
74 |
henoheno |
1.1 |
|
75 |
henoheno |
1.2 |
// 文字エンコーディング検出用 hidden フィールドを挿入 |
76 |
|
|
return preg_replace('/(<form[^>]*>)/', |
77 |
|
|
"$1\n" . '<div><input type="hidden" name="encode_hint" value="ぷ" /></div>', |
78 |
|
|
$retvar); |
79 |
henoheno |
1.1 |
} |
80 |
|
|
|
81 |
|
|
//プラグイン(convert)を実行 |
82 |
henoheno |
1.2 |
function do_plugin_convert($name, $args = '') |
83 |
henoheno |
1.1 |
{ |
84 |
|
|
global $digest; |
85 |
|
|
|
86 |
henoheno |
1.2 |
if(do_plugin_init($name) === FALSE) |
87 |
|
|
die_message("Plugin init failed: $name"); |
88 |
henoheno |
1.1 |
|
89 |
henoheno |
1.2 |
if ($args !== '') { |
90 |
|
|
$aryargs = csv_explode(',', $args); |
91 |
|
|
} else { |
92 |
|
|
$aryargs = array(); |
93 |
|
|
} |
94 |
|
|
|
95 |
|
|
$_digest = $digest; // 退避 |
96 |
|
|
$retvar = call_user_func_array('plugin_' . $name . '_convert', $aryargs); |
97 |
|
|
$digest = $_digest; // 復元 |
98 |
|
|
|
99 |
|
|
if ($retvar === FALSE) { |
100 |
|
|
return htmlspecialchars('#' . $name . ($args ? "($args)" : '')); |
101 |
|
|
} else { |
102 |
|
|
// 文字エンコーディング検出用 hidden フィールドを挿入 |
103 |
|
|
return preg_replace('/(<form[^>]*>)/', |
104 |
|
|
"$1\n" . '<div><input type="hidden" name="encode_hint" value="ぷ" /></div>', |
105 |
|
|
$retvar); |
106 |
henoheno |
1.1 |
} |
107 |
|
|
} |
108 |
|
|
|
109 |
|
|
//プラグイン(inline)を実行 |
110 |
henoheno |
1.2 |
function do_plugin_inline($name, $args, & $body) |
111 |
henoheno |
1.1 |
{ |
112 |
|
|
global $digest; |
113 |
|
|
|
114 |
henoheno |
1.2 |
if(do_plugin_init($name) === FALSE) |
115 |
|
|
die_message("Plugin init failed: $name"); |
116 |
henoheno |
1.1 |
|
117 |
henoheno |
1.2 |
if ($args !== '') { |
118 |
|
|
$aryargs = csv_explode(',', $args); |
119 |
|
|
} else { |
120 |
|
|
$aryargs = array(); |
121 |
|
|
} |
122 |
|
|
$aryargs[] = & $body; // Added reference of $body |
123 |
henoheno |
1.1 |
|
124 |
henoheno |
1.2 |
$_digest = $digest; // 退避 |
125 |
|
|
$retvar = call_user_func_array('plugin_' . $name . '_inline', $aryargs); |
126 |
|
|
$digest = $_digest; // 復元 |
127 |
henoheno |
1.1 |
|
128 |
henoheno |
1.2 |
if($retvar === FALSE) { |
129 |
henoheno |
1.1 |
return htmlspecialchars("&${name}" . ($args ? "($args)" : '') . ';'); |
130 |
henoheno |
1.2 |
} else { |
131 |
|
|
return $retvar; |
132 |
henoheno |
1.1 |
} |
133 |
|
|
} |
134 |
|
|
?> |