本情報はいささか古く、現在ではハック無しで組み込まれた、こちらのd3forum_rをどうぞご使用ください。
元ネタ:d3コメント統合の、元記事閲覧権限連動ハック
上記のハックでは、d3forum本体がバージョンアップした場合に、必ずマージ作業が発生します。
wyeさんから、ハック無しで同様の閲覧権限反映ができるsmarty pluginをいただきましたので、この場で公開させていただきます。
機能・内容
コメント元記事の閲覧権限の継承
メインとなる機能です。 D3コメント統合を行った各モジュールの、D3commentクラス内の、「Validate_id」メソッドへの問い合わせを行って、その結果で判定します。 対象となるページは、
- listtopics ページ、 listtopics_over_categories ページ
- listtopicsブロック、listpostsブロック
- forum検索 ページ
- Global 検索 ページ → 各ユーザーの投稿ログページには反映されません。 そちらには別途テンプレート編集が必要です。
となっています。
各モジュールへの問い合わせた結果は、そのモジュールのD3commentクラスの内容次第です。
但し、listtopics ページと listtopics_over_categories ページ については、管理者とアドミニストレータに対しては、問い合わせ結果に関わらず全て表示します。
理由は、どこか表示しておかないと、元記事が削除されたりしてモジュール間の記事リンクが切れた場合に、迷子になった記事のメンテナンスが出来なくなってしまうからです。
今回のpluginによる副作用として、このような迷子記事は 一般ユーザーやゲストからは一切見えなくなりますので、そのメリット・デメリットを考慮のうえご使用ください。
Plugin 本体
以下のソースを、「(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;
}
|
テンプレート (d3forum)_main_listtopics.html
92行目 あたりと、118行目あたりを、以下のように編集します。
<{if 'd3forum'|d3com_validate_id:$post.post_id ===FALSE}>
の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。
なお、フォーラムの管理者・モデレータには、迷子記事にはタイトル直下にLost Contents ?と表示されます。
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}>
|
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}>
|
テンプレート (d3forum)_main_listtopics_over_categories.html
47行目 あたりと、91行目あたりを、以下のように編集します。
<{if 'd3forum'|d3com_validate_id:$topic.id ===FALSE}>
の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。
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}>
|
91
92
93
94
95
|
| <{/strip}>
</tr>
<{/if}>
<{/foreach}>
|
テンプレート (d3forum)_block_list_topics.html
12行目 あたりと、35行目あたり、60行目あたりを、以下のように編集します。
<{if 'd3forum'|d3com_validate_id:$topic.id ===FALSE}>
の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。
(09-11-20修正:stripタグの重複を削除。thx Maria)
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>
|
35
36
37
38
39
|
| </tr>
<{/strip}>
<{/if}>
<{/foreach}>
</table>
|
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}>
|
テンプレート (d3forum)_block_list_posts.html
以下のように編集します。
<{if 'd3forum'|d3com_validate_id:$post.id ===FALSE}>
の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。
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>
|
テンプレート (d3forum)_main_search.html
75行目あたりを、以下のように編集します。
<{if 'd3forum'|d3com_validate_id:$post.post_id ===FALSE}>
の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。
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}>
|
テンプレート legacy_search_result.html
コアがXCLの場合、このテンプレートの6行目あたりからを、以下のように編集します。
<{if 'd3forum'|d3com_validate_id:$post_id ===FALSE}>
の 'd3forum'の部分は、インストールディレクトリ名に変更してください。
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
|
<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}>
|
謝辞
すばらしいpluginを作ってくださいました、wyeさんに感謝致します。ありがとうございます。
d3forumの当該ソースはもちろんのこと、その他のソースも参考にさせていただきました。 GIJOEさん、ありがとうございます。
改変履歴
2009/11/20修正:stripタグの重複を削除。thx Maria
2009/08/09公開
実体ページ:inc/d3com_auth_plugin
関連ページ:d3コメント統合の、元記事閲覧権限連動ハック
関連ページ:d3forumコメント統合でブロックから元記事へリンクしたい