プラグインの仕様§
基本的にスクリプト全体がプラグイン形式ですが、テキスト整形用に別途仕様を考える。と言うかPukiWiki?プラグインの劣化コピーっぽいです(汗
基本動作§
exists_plugin(引数1,引数2='inline') を呼び出し、
- プラグインファイルの有無 ・ 操作関数があるかチェック
- 関数がある場合は、関数を適用して結果を返す。*1
まですべて行います。
インライン関数の呼び出し§
インライン用関数は preg_replace_collback で呼び出す
preg_replace_callback('/&(\w{1,20})(?:\((.+?)\))?(?:\{(.+?)\})?;/',exists_plugin,$str);
ブロックレベル関数の呼び出し§
ブロックレベル関数は Div クラスから呼び出す。
preg_match('/^(\w{1,20})(?:\((.+?)\))?(?:\{(.+?)\})?$/',$str,$match);
$this->html=method_exists($this,$match[1])?$this->$match[1]($match[2]):exists_plugin($match,'convert');
つまり、メゾットが優先されるので、プラグインを作る場合は衝突に注意。
操作用関数の呼び出し§
$_SERVER['QUERY_STRING'] で第一番目を ?plugin=プラグイン名 にする必要があります。その後
exists_plugin(array('',プラグイン名),'action');
header('location:'.SELF);
とするので、関数内で適切に終了・ヘッダの送信をする必要があります。
exists_plugin のソース§
//define('PLU_DIR','plugin/');
function exists_plugin($dat,$action='inline')
{
static $ctplugin;
array_shift($dat);
$name=array_shift($dat);
if (file_exists(PLU_DIR.$name.'.inc.php'))
{
require_once(PLU_DIR.$name.'.inc.php');
$func='plugin_'.$name.'_'.$action;
if(function_exists($func))
return $func($dat,$ctplugin++);
}
if(count($dat)==0&&$action==='inline')
return '&'.$name.';';
elseif($action==='action') return false;
return setTag('p','<em>[ #'.$name.': plugin not found. ]</em>');
}
各関数の仕様§
- 関数基本型
pligin_プラグイン名_振舞名(引数)とする*4- ファイル名
プラグイン名.inc.php- ブロック整形関数
plugin_プラグイン名_convert(引数)- インライン整形関数
plugin_プラグイン名_inline(引数)- 操作関数
plugin_プラグイン名_action(引数)
- 更新者:
- takz
- 制作日:
- 2006年04月16日(日)01:50:25
- 更新日:
- 2006年04月16日(日)05:30:03
このページは制作者により凍結されています。
- Trackback:Ping
- http://bbs.takzweb.com/index.php?etc=tb&p=9