Page Top

機能・内容 anchor.png

Page Top

コメント元記事の閲覧権限の継承 anchor.png

メインとなる機能です。 D3コメント統合を行った各モジュールの、D3commentクラス内の、「Validate_id」メソッドへの問い合わせを行って、その結果で判定します。 対象となるページは、

  1. listtopics ページ、 listtopics_over_categories ページ
  2. listtopicsブロック、listpostsブロック
  3. forum検索 ページ
  4. Global 検索 ページ → 各ユーザーの投稿ログページには反映されません。 そちらには別途テンプレート編集が必要です。

となっています。
各モジュールへの問い合わせた結果は、そのモジュールのD3commentクラスの内容次第です。

 但し、listtopics ページと listtopics_over_categories ページ については、管理者とアドミニストレータに対しては、問い合わせ結果に関わらず全て表示します。 
 理由は、どこか表示しておかないと、元記事が削除されたりしてモジュール間の記事リンクが切れた場合に、迷子になった記事のメンテナンスが出来なくなってしまうからです。

 今回のpluginによる副作用として、このような迷子記事は 一般ユーザーやゲストからは一切見えなくなりますので、そのメリット・デメリットを考慮のうえご使用ください。

Page Top

Plugin 本体 anchor.png

以下のソースを、「(xoops_root_path)/class/smarty/plugins/modifier.d3com_validate_id.php」として保存・アップロードします。 ホダ塾ディストリビューションの場合は、「(xoops_trust_path)/libs/smartyplugins/modifier.d3com_validate_id.php」でもOKです。

 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
function smarty_modifier_d3com_validate_id($d3forum_dir, $topic_id = NULL, $post_id = NULL)
{
    $db =& Database::getInstance();
 
    // ルート側のd3forumのディレクトリチェック
    if (empty($d3forum_dir)) {
        return TRUE;
    }
    if (!is_dir(XOOPS_ROOT_PATH .'/modules/'. $d3forum_dir)) {
        return TRUE;
    }
 
    // $GLOBALS の post_id をチェック
    if (!empty($post_id) && isset($GLOBALS['d3com_'. $d3forum_dir . '_post_id_' . $post_id])) {
        return $GLOBALS['d3com_'. $d3forum_dir . '_post_id_' . $post_id];
    }
 
    // $topic_idがない場合、post_id から topic_id を取得
    if (empty($topic_id)) {
        if (empty($post_id)) {
            return TRUE;
        }
        $sql = "SELECT `topic_id` FROM `" 
                . $db->prefix(mysql_real_escape_string($d3forum_dir."_posts"))
                . "` WHERE `post_id`=" . intval($post_id);
        $result_row = $db->fetchArray($db->query($sql));
        if (!empty($result_row['topic_id'])) {
            $topic_id = intval($result_row['topic_id']);
        } else {
            return TRUE;
        }
    }
 
    // $GLOBALS の topic_id をチェック
    if (!empty($post_id) && isset($GLOBALS['d3com_'. $d3forum_dir . '_topic_id_' . $topic_id])) {
        return $GLOBALS['d3com_'. $d3forum_dir . '_topic_id_' . $topic_id];
    }
 
    // topic_id から topic_external_link_id を取得
    $sql = "SELECT `topic_external_link_id`, `forum_id` FROM `" 
            . $db->prefix(mysql_real_escape_string($d3forum_dir."_topics"))
            . "` WHERE `topic_id`=" . intval($topic_id);
    $result_row = $db->fetchArray($db->query($sql));
    if (empty($result_row['topic_external_link_id'])) {
        return TRUE;
    }
    $topic_external_link_id = intval($result_row['topic_external_link_id']);
 
    // forum_id
    if (($forum_id = $result_row['forum_id']) == '') {
        return TRUE;
    }
 
    if (isset($GLOBALS['d3com_'. $d3forum_dir . '_forum_id_' . $forum_id]) && is_object($GLOBALS['d3com_'. $d3forum_dir . '_forum_id_' . $forum_id])) {
        $obj = $GLOBALS['d3com_'. $d3forum_dir . '_forum_id_' . $forum_id];
    } else {
        // forum_id から forum_external_link_format を取得
        $sql = "SELECT `forum_external_link_format` FROM `" 
                . $db->prefix(mysql_real_escape_string($d3forum_dir."_forums"))
                . "` WHERE `forum_id`=". intval($forum_id);
        $result_row = $db->fetchArray($db->query($sql));
 
        if (empty($result_row['forum_external_link_format'])) {
            return TRUE;
        }
 
        require_once XOOPS_TRUST_PATH . '/modules/d3forum/include/main_functions.php';
        $obj =& d3forum_main_get_comment_object($d3forum_dir, $result_row['forum_external_link_format']);
 
        if (!is_object($obj)) {
            return TRUE;
        }
 
        $GLOBALS['d3com_'. $d3forum_dir . '_forum_id_' . $forum_id] = $obj;
    }
 
    // validate_id()メソッドで権限チェックする
    if (!method_exists($obj, 'validate_id')) {
        return TRUE;
    }
    $check_result = $obj->validate_id($topic_external_link_id);
 
    // $GLOBALS に post_id, topic_id で権限チェックをいれておく
    if (!empty($post_id)) $GLOBALS['d3com_'. $d3forum_dir . '_post_id_' . $post_id] = $check_result;
    if (!empty($topic_id)) $GLOBALS['d3com_'. $d3forum_dir . '_topic_id_' . $topic_id] = $check_result;
 
    return $check_result;
}
Page Top

テンプレート (d3forum)_main_listtopics.html anchor.png

92行目 あたりと、118行目あたりを、以下のように編集します。

<{if 'd3forum'|d3com_validate_id:$post.post_id ===FALSE}>

の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。

なお、フォーラムの管理者・モデレータには、迷子記事にはタイトル直下にLost Contents ?と表示されます。

Everything is expanded.Everything is shortened.
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
 
 
 
 
 
 
 
 
 
 
 
<{foreach item=topic from=$topics}>
<{if 'd3forum'|d3com_validate_id:$topic.id ===FALSE}>
     <{assign var="topic_permission_ok" value="0"}>
<{else}>
     <{assign var="topic_permission_ok" value="1"}>
<{/if}>
<{if $topic_permission_ok || $forum.isadminormod}>
<{if $topic.sticky}>
    <{assign var="topic_icon_src" value="`$mod_imageurl`/topic_sticky`$topic.bit_new`.gif"}>
    <{assign var="topic_icon_alt" value=$smarty.const._MD_D3FORUM_TOPICSTICKY}>
<{elseif $topic.invisible}>
Everything is expanded.Everything is shortened.
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    <a href="<{$mod_url}>/index.php?topic_id=<{$topic.id}>"><{$topic.title}></a><{$topic.topic_page_jump}>
    <{if !$topic_permission_ok}>
    <font color="red">Lost Contents ?</font>
    <{/if}></td>
    <td><{$topic.replies}></td>
    <td><{$topic.views}></td>
    <{if $mod_config.use_vote}>
    <td><{$topic.votes_count}></td>
    <td><{$topic.votes_avg|string_format:"%.2f"}></td>
    <{/if}>
    <td class="d3f_posters"><{$topic.first_post_time_formatted}><br />
    <{$topic.first_post_uname}> <a href="<{$mod_url}>/index.php?post_id=<{$topic.first_post_id}>"><img src="<{$mod_imageurl}>/posticon<{$topic.first_post_icon}>.gif" alt="<{$topic.first_post_subject}>" /></a></td>
    <td class="d3f_posters"><{if $topic.replies>0}><{$topic.last_post_time_formatted}><br />
    <{$topic.last_post_uname}> <a href="<{$mod_url}>/index.php?post_id=<{$topic.last_post_id}>"><img src="<{$mod_imageurl}>/posticon<{$topic.last_post_icon}>.gif" alt="<{$topic.last_post_subject}>" /></a><{/if}></td>
</tr>
<{/if}>
<{/foreach}>
<!-- end forum topic -->
Page Top

テンプレート (d3forum)_main_listtopics_over_categories.html anchor.png

47行目 あたりと、91行目あたりを、以下のように編集します。

<{if 'd3forum'|d3com_validate_id:$topic.id ===FALSE}>

の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。

Everything is expanded.Everything is shortened.
47
48
49
50
51
52
53
54
55
56
57
 
 
 
 
 
 
 
 
 
 
 
<{foreach item=topic from=$topics}>
<{if 'd3forum'|d3com_validate_id:$topic.id ===FALSE}>
     <{assign var="topic_permission_ok" value="0"}>
<{else}>
     <{assign var="topic_permission_ok" value="1"}>
<{/if}>
<{if $topic_permission_ok}>
<{if $topic.sticky}>
    <{assign var="topic_icon_src" value="`$mod_imageurl`/topic_sticky`$topic.bit_new`.gif"}>
    <{assign var="topic_icon_alt" value=$smarty.const._MD_D3FORUM_TOPICSTICKY}>
<{elseif $topic.invisible}>
Everything is expanded.Everything is shortened.
91
92
93
94
95
 
 
 
 
 
<{/strip}>
</tr>
<{/if}>
<{/foreach}>
<!-- end forum topic -->
Page Top

テンプレート (d3forum)_block_list_topics.html anchor.png

12行目 あたりと、35行目あたり、60行目あたりを、以下のように編集します。

<{if 'd3forum'|d3com_validate_id:$topic.id ===FALSE}>

の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。
(09-11-20修正:stripタグの重複を削除。thx Maria)

Everything is expanded.Everything is shortened.
12
13
14
15
16
17
18
19
20
21
 
 
 
 
 
 
 
 
 
 
<{foreach item=topic from=$block.topics}>
<{if 'd3forum'|d3com_validate_id:$topic.id ===FALSE}>
     <{assign var="topic_permission_ok" value="0"}>
<{else}>
     <{assign var="topic_permission_ok" value="1"}>
<{/if}>
<{if $topic_permission_ok}>
<{strip}>
<tr class="<{cycle values="even,odd"}>">
    <td><a href="<{$block.mod_url}>/index.php?forum_id=<{$topic.forum_id}>"><{$topic.forum_title}></a></td>
Everything is expanded.Everything is shortened.
35
36
37
38
39
 
 
 
 
 
</tr>
<{/strip}>
<{/if}>
<{/foreach}>
</table>
Everything is expanded.Everything is shortened.
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<ol style="padding:3px;margin:0;">
<{foreach item=topic from=$block.topics}>
<{if 'd3forum'|d3com_validate_id:$topic.id ===FALSE}>
     <{assign var="topic_permission_ok" value="0"}>
<{else}>
     <{assign var="topic_permission_ok" value="1"}>
<{/if}>
<{if $topic_permission_ok}>
    <li><a href="<{$block.mod_url}>/index.php?topic_id=<{$topic.id}>"><{$topic.title}></a>(<{$topic.replies}>) <{$topic.last_uname}> <{$topic.last_post_time_formatted}></li>
<{/if}>
<{/foreach}>
</ol>
 
<{/if}>
Page Top

テンプレート (d3forum)_block_list_posts.html anchor.png

以下のように編集します。

<{if 'd3forum'|d3com_validate_id:$post.id ===FALSE}>

の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。

Everything is expanded.Everything is shortened.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 
 
 
 
 
 
 
 
 
 
 
 
<ol style="padding:3px;margin:0;">
<{foreach item=post from=$block.posts}>
<{if 'd3forum'|d3com_validate_id:$post.id ===FALSE}>
     <{assign var="post_permission_ok" value="0"}>
<{else}>
     <{assign var="post_permission_ok" value="1"}>
<{/if}>
<{if $post_permission_ok}>
    <li style="margin:1px;"><a href="<{$block.mod_url}>/index.php?post_id=<{$post.id}>"><{$post.subject}></a> <{$post.uname}> <{$post.post_time_formatted}></li>
<{/if}>
<{/foreach}>
</ol>
Page Top

テンプレート (d3forum)_main_search.html anchor.png

75行目あたりを、以下のように編集します。

<{if 'd3forum'|d3com_validate_id:$post.post_id ===FALSE}>

の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。

Everything is expanded.Everything is shortened.
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<{foreach from=$results item=post}>
<{if 'd3forum'|d3com_validate_id:$post.post_id ===FALSE}>
     <{assign var="post_permission_ok" value="0"}>
<{else}>
     <{assign var="post_permission_ok" value="1"}>
<{/if}>
<{if $post_permission_ok}>
<tr>
    <td class="even d3f_topictitle"><a href="<{$mod_url}>/index.php?forum_id=<{$post.forum_id}>"><{$post.forum_title}></a></td>
    <td class="odd d3f_topictitle"><a href="<{$mod_url}>/index.php?post_id=<{$post.post_id}>"><img src="<{$mod_imageurl}>/posticon<{$post.icon}>.gif" /><{$post.subject}></a> <{$post.body_length|string_format:$smarty.const._MD_D3FORUM_FMT_BYTE}></td>
    <td class="even"><a href="<{$xoops_url}>/userinfo.php?uid=<{$post.poster_uid}>"><{$post.poster_uname}></a></td>
    <td class="odd"><{if $mod_config.use_vote}><{$post.votes_avg|string_format:"%.2f"}>/<{$post.votes_count}><{else}><{$post.topic_views}><{/if}></td>
    <td class="even"><{$post.post_time_formatted}></td>
</tr><{/if}>
<{/foreach}>
Page Top

テンプレート legacy_search_result.html anchor.png

コアがXCLの場合、このテンプレートの6行目あたりからを、以下のように編集します。

<{if 'd3forum'|d3com_validate_id:$post_id ===FALSE}>

の 'd3forum'の部分は、インストールディレクトリ名に変更してください。

Everything is expanded.Everything is shortened.
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  <!-- start results item loop -->
  <ul style="list-style:none;margin-left:10px;">
  <{foreach item=result from=$module.results}>
<{assign var="post_id" value=$result.link|replace:'http://www.enbisp.com/modules/forum/index.php?post_id=':''}>
<{if 'd3forum'|d3com_validate_id:$post_id ===FALSE}>
     <{assign var="post_permission_ok" value="0"}>
<{else}>
     <{assign var="post_permission_ok" value="1"}>
<{/if}>
<{if $post_permission_ok}>
    <li><img src="<{$result.image}>" alt="<{$module.name}>" title="<{$module.name}>" /><span style="font-weight:bold;"><a href="<{$result.link}>"><{$result.title}></a></span><br />
    <span style="font-size:small;">
      <{if $result.uid > 0}>
        <a href="<{$smarty.const.XOOPS_URL}>/userinfo.php?uid=<{$result.uid|xoops_escape}>"><{$result.uid|xoops_user:uname}></a>
      <{/if}>
      (<{$result.time|xoops_formattimestampGMT:l}>)
    </span></li>
<{/if}>
  <{/foreach}>
Page Top

謝辞 anchor.png

すばらしいpluginを作ってくださいました、wyeさんに感謝致します。ありがとうございます。
d3forumの当該ソースはもちろんのこと、その他のソースも参考にさせていただきました。 GIJOEさん、ありがとうございます。

Page Top

改変履歴 anchor.png

2009/11/20修正:stripタグの重複を削除。thx Maria
2009/08/09公開


トップ   凍結 差分 バックアップ 複製 名前変更 リロード印刷に適した表示   ページ新規作成 全ページ一覧 単語検索 最新ページの一覧   ヘルプ   最新ページのRSS 1.0 最新ページのRSS 2.0 最新ページのRSS Atom Powered by xpWiki
Counter: 2928, today: 1, yesterday: 0
初版日時: 2009-08-09 (日) 12:13:31
最終更新: 2019-08-17 (土) 07:11:56 (JST) (1713d) by なーお