hypweb.net
XOOPSマニア  最新情報のRSS(サイト全体)
[ 自宅サーバーWebRing |ID=54 前後5表示乱移動サイト一覧 ]

TOP » xpwiki » xpWiki開発日記 » 2006-10-30

2006 10月 30 (月)
 

Ver 0.5.2 anchor.png Edit

XOOPSのモジュール間通信の方法の一つとして、プラグイン型があります。 例えば、はっぴぃ・りなっくす さんの 新着情報(What's New) モジュール 2.xxです。

それらのプラグインは常時必要ではないので必要な時にのみ読み込む仕組みが必要だと考えました。そこで、XpWikiオブジェクトを拡張する形で、動的にエクステンションを読む方法にしてみました。

各エクステンションは TRUST_PATH/modules/xpwiki/class/extension ディレクトリに置きます。

そして、必要な時に XpWikiオブジェクトのインスタンスを作成後に読み込みます。

例えばこんな感じで。

1
2
3
4
5
6
7
8
9
    // 必要なファイルの読み込み
    $mytrustdirpath = dirname(dirname( __FILE__ )) ;
    include_once "$mytrustdirpath/include.php";
    
    // XpWiki オブジェクト作成
    $xpwiki = new XpWiki($mydirname);
    
    // whatsnew extension 読み込み
    $xpwiki->load_extensions("whatsnew");
Page Top

これを利用した What's Newプラグイン 用エクステンションは、次のようになります。 anchor.png Edit

xpWiki を modules/xpwiki ディレクトリにインストールしているとします。違うディレクトリにインストールしている場合は、赤字の部分のみ変更すればOK。(要するにプラグインの置き場所を変えるだけです。)

Page Top

エクステンション anchor.png Edit

  • trust側/modules/xpwiki/class/extension ディレクトリに配置します。
filewhatsnew.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
38
39
40
41
42
43
44
<?php
//
// Created on 2006/10/29 by nao-pon http://hypweb.net/
// $Id: whatsnew.php,v 1.1 2006/10/30 03:01:48 nao-pon Exp $
//
 
class XpWikiExtension_whatsnew extends XpWikiExtension {
 
// $this->xpwiki : Parent XpWiki object.
// $this->root   : Global variable.
// $this->cont   : Constant.
// $this->func   : XpWiki functions.
 
    function get ($limit, $offset) {
 
        $i    = 0;
        $ret  = array();
        $desc = '';
    
        $recent_dat  = $this->cont['PKWK_MAXSHOW_CACHE'];
        $recent_line = @file($this->cont['CACHE_DIR'] . $recent_dat);
        $recent_arr  = array_slice($recent_line, 0, $limit);
        
        foreach($recent_arr as $line) {
            list($time, $base) = explode("\t", trim($line));
            $localtime = $time + ($this->cont['ZONETIME']);
    
            $ret[$i]['link']  = $this->root->script."?".rawurlencode($base);
            $ret[$i]['title'] = $base;
            $ret[$i]['time']  = $localtime;
            
            // 指定ページの本文取得
            $page = new XpWiki($this->root->mydirname);
            $page->init($base);
            $page->execute();
            $desc = $page->body;
    
            $ret[$i]['description'] = $desc;
            $i++;
        }
        return $ret;
    }
}
?>
Page Top

プラグイン anchor.png Edit

  • html側/modules/whatsnew/plugins/xpwiki ディレクトリに配置します。
filedata.inc.php
1
2
3
4
5
6
7
8
9
<?php
 
if( ! defined( 'XOOPS_TRUST_PATH' ) ) die( 'set XOOPS_TRUST_PATH into mainfile.php' ) ;
 
$mydirname = basename( dirname( __FILE__ ) ) ;
 
require XOOPS_TRUST_PATH.'/modules/xpwiki/include/whatsnew.inc.php' ;
 
?>
Page Top

プラグインの実体 anchor.png Edit

  • trust側/modules/xpwiki/include ディレクトリに配置します。
filewhatsnew.inc.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
//
// Created on 2006/10/29 by nao-pon http://hypweb.net/
// $Id: whatsnew.inc.php,v 1.1 2006/10/30 03:01:48 nao-pon Exp $
//
 
// DIRNAME_new() 関数を動的に生成
eval( '
 
function '.$mydirname.'_new( $limit=0, $offset=0 )
{
    return xpwiki_whatsnew_base( "'.$mydirname.'" , $limit, $offset ) ;
}
 
' ) ;
 
 
// DIRNAME_new() 関数の実体
function xpwiki_whatsnew_base( $mydirname, $limit, $offset ) {
 
    // 必要なファイルの読み込み
    $mytrustdirpath = dirname(dirname( __FILE__ )) ;
    include_once "$mytrustdirpath/include.php";
    
    // XpWiki オブジェクト作成
    $xpwiki = new XpWiki($mydirname);
    
    // whatsnew extension 読み込み
    $xpwiki->load_extensions("whatsnew");
    
    // 初期化
    $xpwiki->init();
    
    // whatsnew データ取得
    return $xpwiki->extension->whatsnew->get ($limit, $offset);
}
?>
Page Top

コメント anchor.png Edit

  • まずは、XOOPSのグローバル検索, piCalプラグインのエクステンションを作成予定です。 :) -- nao-pon 2006-10-30 (月) 13:57:49



トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード印刷に適した表示   ページ新規作成 全ページ一覧 単語検索 最新ページの一覧   ヘルプ   最新ページのRSS 1.0 最新ページのRSS 2.0 最新ページのRSS Atom Powered by xpWiki
Counter: 197, today: 1, yesterday: 0
初版日時: 2006-10-30 (月) 13:48:33
最終更新: 2006-10-30 (月) 13:57:49 (JST) (6359d) by nao-pon
このページのTopへ
メインメニュー
ログイン

ユーザー名:


パスワード:





パスワード紛失  |新規登録
オンライン状況
437 人のユーザが現在オンラインです。 (6 人のユーザが xpwiki を参照しています。)

登録ユーザ: 0
ゲスト: 437

もっと...
サイト情報