ページへ戻る

− Links

 印刷 

Ver 0.5.6-10 :: XOOPS マニア

xpwiki:xpWiki開発日記/2006-11-03


Tag: 基本設計[4] イベントフック[5] ini設定[6]
2006 11月 3 (金)
 
ページ内コンテンツ
  • Ver 0.5.6-10
    • ページ保存時のイベントフック
    • XOOPS のグローバル検索に対応
  • Ver 0.5.11
  • コメント

Ver 0.5.6-10 anchor.png[7] Edit [8]

Page Top

ページ保存時のイベントフック anchor.png[9] Edit [10]

ページ保存直前と直後に、独自の処理を挟み込めるようにしました。

  • trust側/events/onPageWriteBefore
  • trust側/events/onPageWriteAfter

ディレクトリにPHPファイルを置くことで、そのファイル内容の処理が実行されます。

基本的には、こんな感じ。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/*
Custom event files are included in this directory.
You can use next variables here.
 
$this        : XpWiki[11] Function object
$page        : page name
$postdata    : text data of page
$notimestamp : no change time stamp flag (TRUE or FALSE)
$mode        : Action mode (insert, update or delete)
 
*/
 
// Here is a sample code.
 
// This block always execute.
 
// Get plugin[12] instance
$_plugin = & $this->get_plugin_instance('PLUGIN_NAME');
 
// exec plugin[12] function with arguments.
$aryargs = array('hoge', 'hege');
$result  = call_user_func_array(array(& $_plugin, 'PLUGIN_FUNCTION_NAME'), $aryargs);
 
if ( $mode === 'insert' ) {
    // Only page create time.
 
} else if ( $mode === 'update' ) {
    // Only page update time.
 
} else if ( $mode === 'delete' ) {
    // Only page delete time.
 
}
 
unset ($_plugin);
?>

この機能を利用したプラグインが tag.inc.php です。 tag プラグインでは、ページ編集してtagプラグインの記述が削除された時とページ削除時に Tag の更新処理を行います。 その内容は、次の通りです。

filetag.inc.php[13]
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
//
// Created on 2006/10/31 by nao-pon[14] http://hypweb.net/
// $Id: tag.inc.php,v 1.3 2006/11/02 15:59:29 nao-pon[14] Exp $
//
if (file_exists($this->cont['CACHE_DIR'] . $this->encode($page) . '_page.tag')) {
    // ページのtagデータファイルがある場合
    
    // temp
    $_temparr = array();
    
    // tagプラグイン記述の存在チェック
    $_temparr['found'] = FALSE;
    $_temparr['ic'] = new XpWikiInlineConverter($this->xpwiki[11], array('plugin[12]'));
    $_temparr['data'] = explode("\n",$postdata);
    while (! empty($_temparr['data'])) {
        
        $_temparr['line'] =  array_shift($_temparr['data']);
        
        // The first character
        $_temparr['head'] = $_temparr['line']{0};
        
        if (
            // Escape comments
            substr($_temparr['line'], 0, 2) === '//' ||
            // Horizontal Rule
            substr($_temparr['line'], 0, 4) === '----' ||
            // Pre
            $_temparr['head'] === ' ' || $_temparr['head'] === "\t"
        ) {    continue; }
 
        // Multiline-enabled block plugin[12]
        if (!$this->cont['PKWKEXP_DISABLE_MULTILINE_PLUGIN_HACK'] && preg_match('/^#[^{]+(\{\{+)\s*$/', $_temparr['line'], $matches)) {
            $_temparr['len'] = strlen($matches[1]);
            while (! empty ($_temparr['data'])) {
                $_temparr['$next_line'] = preg_replace("/[\r\n]*$/", '', array_shift($_temparr['data']));
                if (preg_match('/\}{'.$_temparr['len'].'}/', $_temparr['$next_line'])) { break; }
            }
        }
        
        // ちょっと重いけどしっかりチェック版
        $_temparr['arr'] = $_temparr['ic']->get_objects($_temparr['line'], $page);
        while( ! empty($_temparr['arr']) ) {
            $_temparr['obj'] = array_shift($_temparr['arr']);
            if ( $_temparr['obj']->name === 'tag' ) {
                $_temparr['found'] = TRUE;
                break 2;
            }
        }
        
        /*
        // ちょっと手抜きの軽量版
        if (preg_match("/&tag\([\^)]*\)(\{.*?\})?;/",$_temparr['line'])) {
            $_temparr['found'] = TRUE;
            break;
        }
        */
        
    }
    
    if ($mode === 'delete' || ($mode === 'update' && $_temparr['found'] === FALSE)) {
        // ページ削除または&tag();を削除した場合
        $_temparr['plugin[12]'] =& $this->get_plugin_instance('tag');
        if ($_temparr['plugin[12]'] !== FALSE) {
            $aryargs = array($page, array());
            call_user_func_array(array($this->root->plugin_tag, 'renew_tagcache'), $aryargs);
        }
    } else if ($mode === 'update' && $notimestamp) {
        // ページ編集でページタイムスタンプを保持する場合
        $this->pkwk_touch_file($this->cont['CACHE_DIR'] . $this->encode($page) . '_page.tag',1);
    }
    unset($_temparr);
}
?>
Page Top

XOOPS[15] のグローバル検索に対応 anchor.png[16] Edit [17]

XOOPS[15] のグローバル検索に対応するとともに、XOOPS[15]検索モジュールにも対応しました。

Page Top

Ver 0.5.11 anchor.png[18] Edit [19]

pukiwiki[20].ini.php に設定項目を追加しました。

ページキャッシュ関連の設定項目です。

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
/////////////////////////////////////////////////
// ページキャッシュの設定 (ゲストアクセス時のみ)
// ページキャッシュを最長何分間するか?
$root->pagecache_min = 0;
 
// ページ更新時常にページキャッシュを破棄するページ
$root->always_clear_cache_pages = array (
    //$root->defaultpage,
    $root->menubar[21],
);
 
// 上位層のページもキャッシュをクリアする
$root->clear_cache_parent = TRUE; // (TRUE or FASLE)
Page Top

コメント anchor.png[22] Edit [23]




Last-modified: 2006-11-15 (水) 16:50:25 (JST) (7237d) by nao-pon