0: - no date -  |
現: 2026-08-13 (木) 08:56:06 なーお  |
| | + | * d3コメント統合の、元記事閲覧権限連動ハック Plugin版 [#he2a029a] |
| | | | |
| | + | 元ネタ:d3コメント統合の、元記事閲覧権限連動ハック |
| | + | |
| | + | 上記のハックでは、d3forum本体がバージョンアップした場合に、必ずマージ作業が発生します。 |
| | + | wyeさんから、ハック無しで同様の閲覧権限反映ができるsmarty pluginをいただきましたので、この場で公開させていただきます。 |
| | + | |
| | + | ** 機能・内容 [#ye84a863] |
| | + | *** コメント元記事の閲覧権限の継承 [#g0aed2f7] |
| | + | メインとなる機能です。 D3コメント統合を行った各モジュールの、D3commentクラス内の、「Validate_id」メソッドへの問い合わせを行って、その結果で判定します。 対象となるページは、 |
| | + | + listtopics ページ、 listtopics_over_categories ページ |
| | + | + listtopicsブロック、listpostsブロック |
| | + | + forum検索 ページ |
| | + | + Global 検索 ページ → 各ユーザーの投稿ログページには反映されません。 そちらには別途テンプレート編集が必要です。 |
| | + | |
| | + | となっています。 |
| | + | 各モジュールへの問い合わせた結果は、そのモジュールのD3commentクラスの内容次第です。 |
| | + | |
| | + | 但し、listtopics ページと listtopics_over_categories ページ については、管理者とアドミニストレータに対しては、問い合わせ結果に関わらず全て表示します。 |
| | + | 理由は、どこか表示しておかないと、元記事が削除されたりしてモジュール間の記事リンクが切れた場合に、迷子になった記事のメンテナンスが出来なくなってしまうからです。 |
| | + | |
| | + | &font(Red){今回のpluginによる副作用として、このような迷子記事は 一般ユーザーやゲストからは一切見えなくなります};ので、そのメリット・デメリットを考慮のうえご使用ください。 |
| | + | |
| | + | *** Plugin 本体 [#p95898d4] |
| | + | 以下のソースを、「(xoops_root_path)/class/smarty/plugins/modifier.d3com_validate_id.php」として保存・アップロードします。 ホダ塾ディストリビューションの場合は、「(xoops_trust_path)/libs/smartyplugins/modifier.d3com_validate_id.php」でもOKです。 |
| | + | #code(php,1-){{ |
| | + | <?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 [#d764379a] |
| | + | 92行目 あたりと、118行目あたりを、以下のように編集します。 |
| | + | <{if 'd3forum'|d3com_validate_id:$post.post_id ===FALSE}> |
| | + | の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。 |
| | + | |
| | + | なお、フォーラムの管理者・モデレータには、迷子記事にはタイトル直下に&font(Red){Lost Contents ?};と表示されます。 |
| | + | |
| | + | #code(html,92-){{ |
| | + | <{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}> |
| | + | }} |
| | + | |
| | + | #code(html,124-){{ |
| | + | <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 [#xb9788d9] |
| | + | 47行目 あたりと、91行目あたりを、以下のように編集します。 |
| | + | <{if 'd3forum'|d3com_validate_id:$topic.id ===FALSE}> |
| | + | の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。 |
| | + | |
| | + | #code(html,47-){{ |
| | + | <{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}> |
| | + | }} |
| | + | |
| | + | #code(html,91-){{ |
| | + | <{/strip}> |
| | + | </tr> |
| | + | <{/if}> |
| | + | <{/foreach}> |
| | + | <!-- end forum topic --> |
| | + | }} |
| | + | |
| | + | *** テンプレート (d3forum)_block_list_topics.html [#sbeaa634] |
| | + | 12行目 あたりと、35行目あたり、60行目あたりを、以下のように編集します。 |
| | + | <{if 'd3forum'|d3com_validate_id:$topic.id ===FALSE}> |
| | + | の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。 |
| | + | (09-11-20修正:stripタグの重複を削除。[[thx Maria:http://www.xugj.org/modules/d3forum/index.php?post_id=5653]]) |
| | + | |
| | + | #code(html,12-){{ |
| | + | <{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> |
| | + | }} |
| | + | |
| | + | #code(html,35-){{ |
| | + | </tr> |
| | + | <{/strip}> |
| | + | <{/if}> |
| | + | <{/foreach}> |
| | + | </table> |
| | + | }} |
| | + | |
| | + | #code(html,60-){{ |
| | + | <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 [#l0fa4cde] |
| | + | 以下のように編集します。 |
| | + | <{if 'd3forum'|d3com_validate_id:$post.id ===FALSE}> |
| | + | の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。 |
| | + | |
| | + | #code(html,1-){{ |
| | + | <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 [#u09cfdb0] |
| | + | 75行目あたりを、以下のように編集します。 |
| | + | <{if 'd3forum'|d3com_validate_id:$post.post_id ===FALSE}> |
| | + | の、'd3forum'の部分は、インストールディレクトリ名にあわせてください。 |
| | + | |
| | + | #code(html,75-){{ |
| | + | <{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 [#p9173bc1] |
| | + | コアがXCLの場合、このテンプレートの6行目あたりからを、以下のように編集します。 |
| | + | <{if 'd3forum'|d3com_validate_id:$post_id ===FALSE}> |
| | + | の 'd3forum'の部分は、インストールディレクトリ名に変更してください。 |
| | + | |
| | + | #code(html,6-){{ |
| | + | <!-- 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}> |
| | + | }} |
| | + | |
| | + | ** 謝辞 [#ed7885e2] |
| | + | すばらしいpluginを作ってくださいました、wyeさんに感謝致します。ありがとうございます。 |
| | + | d3forumの当該ソースはもちろんのこと、その他のソースも参考にさせていただきました。 GIJOEさん、ありがとうございます。 |
| | + | |
| | + | ** 改変履歴 [#af087a06] |
| | + | 2009/11/20修正:stripタグの重複を削除。[[thx Maria:http://www.xugj.org/modules/d3forum/index.php?post_id=5653]] |
| | + | 2009/08/09公開 |