トップ  >  趣味の部屋  >  XOOPSサイト構築  >  d3コメント統合の、元記事閲覧権限連動ハック Plugin版

d3コメント統合の、元記事閲覧権限連動ハック Plugin版

user なーお datetime 2009/8/9 8:42 update 2009/11/19 21:29 views 14918

本情報はいささか古く、現在ではハック無しで組み込まれた、こちらのd3forum_rをどうぞご使用ください。

d3コメント統合の、元記事閲覧権限連動ハック Plugin版 anchor.png

元ネタ:d3コメント統合の、元記事閲覧権限連動ハック

上記のハックでは、d3forum本体がバージョンアップした場合に、必ずマージ作業が発生します。

wyeさんから、ハック無しで同様の閲覧権限反映ができるsmarty pluginをいただきましたので、この場で公開させていただきます。

機能・内容 anchor.png

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

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

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

となっています。

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

 但し、listtopics ページと listtopics_over_categories ページ については、管理者とアドミニストレータに対しては、問い合わせ結果に関わらず全て表示します。 

 理由は、どこか表示しておかないと、元記事が削除されたりしてモジュール間の記事リンクが切れた場合に、迷子になった記事のメンテナンスが出来なくなってしまうからです。

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

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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?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 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
103
104
105
106
107
108
109
110
111
112
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<{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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
    <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 -->

テンプレート (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
58
59
60
61
62
63
64
65
66
67
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<{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
96
97
98
99
 
 
 
 
 
 
 
 
 
<{/strip}>
 
</tr>
 
<{/if}>
 
<{/foreach}>
 
<!-- end forum topic -->

テンプレート (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
22
23
24
25
26
27
28
29
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<{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
40
41
42
43
 
 
 
 
 
 
 
 
 
</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
74
75
76
77
78
79
80
81
82
83
84
85
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<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 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
13
14
15
16
17
18
19
20
21
22
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<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 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
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<{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 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
  <!-- 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}>

謝辞 anchor.png

すばらしいpluginを作ってくださいました、wyeさんに感謝致します。ありがとうございます。

d3forumの当該ソースはもちろんのこと、その他のソースも参考にさせていただきました。 GIJOEさん、ありがとうございます。

改変履歴 anchor.png

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

2009/08/09公開


実体ページ:inc/d3com_auth_plugin 関連ページ:d3コメント統合の、元記事閲覧権限連動ハック 関連ページ:d3forumコメント統合でブロックから元記事へリンクしたい

コメント一覧

投稿ツリー


nonn50  投稿日時 2009/9/14 4:55

ご無沙汰しております。

遅ればせながら、「d3コメント統合の、元記事閲覧権限連動ハック Plugin版」を導入させていただきたいと思い、着工しました。

しかし、頭の悪い爺は、テンプレートの書き換えで悩んでおります。

  • 例として
引用:

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

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

として92行目以降の編集事項が書かれていますが、
元テンプレートの何行目までを書き換えれば良いのか?、それとも92行目に挿入すれば良いのか?が理解できません。

そこで、御願いです。

書き換えを必要とするテンプレート等、上記で編集を指示しているファイルの完成版を御示しください。
お手数とは思いますが、無知な爺に愛の手を御願いします。

なーお  投稿日時 2009/9/14 15:58 | 最終変更

nonn50さん、こんばんは。

最近、出張が多くててんやわんやで後手後手です。 :roll:

さて、ご依頼の件ですが、

引用:
書き換えを必要とするテンプレート等、上記で編集を指示しているファイルの完成版を御示しください。
お手数とは思いますが、無知な爺に愛の手を御願いします。

とのことですが、ご存知のとおり私の環境も、d3forumの各テンプレートは色々手を入れていますので、そのまま提示すると却って混乱しますし、それをまた説明するのも大変なため、少々説明不足であることは承知のうえで、このような公開方法としています。 :-D

また、実運用サイトではこのpluginではなく多数のサイトを一括変更できるようにハック版の方を使用していますので、plugin自体は消去してしまいました。(汗)

つきましては上記の事情をご考慮いただき、「○○の行あたり」 の「○○」の行を変更コード部分で照合し、その前後をオリジナルのテンプレートと見比べて、どの範囲を修正すべきか、タグの開始と閉じを確認しつつ見極めていただくのが間違いないと思いますし、じっくり追えば理解できるはずです。

更に、そうして理解しながら書き換えたテンプレートは、別のカスタムの際にも内容が理解できているので取り組みやすいはずですし。

もしこの作業が面倒、ということでしたら、素直にソースコードのハック版のご使用をお勧めします。

よろしくお願いします。

nonn50  投稿日時 2009/9/15 0:47

((i:f8e9))からです。
お忙しい中、回答いただき、ありがとうございました。

お話の内容、承知しました。

頑張ってみます((i:f995))



新しくコメントをつける

題名
ゲスト名
投稿本文
より詳細なコメント入力フォームへ