0: - no date -  |
現: 2026-08-13 (木) 08:56:06 なーお  |
| | + | * d3forumコメント統合でブロックから元記事へリンクしたい [#g3142053] |
| | | | |
| | + | - 元ネタ:[[XUGJのこのトピ:http://www.xugj.org/modules/QandA/index.php?topic_id=1377]] |
| | + | - 実装例1: このサイトのなーおn研究室の、右側にコメントトピック一覧、ブログの左側のコメントトピック一覧があります。デフォルトテンプレートの編集でやってます。 |
| | + | - 実装例2: テストサイトの[[このページ:http://www.mc8.jp/HD3/modules/pico/]]の右側に、コメントトピック一覧と投稿一覧があります。&br; |
| | + | |
| | + | ** 1. d3forumソースハック [#sc5f918d] |
| | + | (trust_path)/modules/d3forum/blocks/block_functions.php を編集します。 |
| | + | |
| | + | *** 1.1. function b_d3forum_list_topics_show [#z63c35da] |
| | + | |
| | + | 内の191~195行目付近を、以下のように変更。 |
| | + | _d3forum_topics テーブルから フィールド値「topic_external_link_id」を抽出し、アサインします。 |
| | + | #code(php,191-){{ |
| | + | if( $uid > 0 && $is_markup ) { |
| | + | $sql = "SELECT t.topic_id, t.topic_title, t.topic_last_uid, t.topic_last_post_id, t.topic_last_post_time, t.topic_views, t.topic_votes_count, t.topic_votes_sum, t.topic_posts_count, t.topic_external_link_id, $sel_solved, t.forum_id, f.forum_title, u2t.u2t_marked FROM ".$db->prefix($mydirname."_topics")." t LEFT JOIN ".$db->prefix($mydirname."_forums")." f ON f.forum_id=t.forum_id LEFT JOIN ".$db->prefix($mydirname."_users2topics")." u2t ON u2t.topic_id=t.topic_id AND u2t.uid=$uid WHERE ! t.topic_invisible AND ($whr_forum) AND ($whr_categories) AND ($whr_forums) AND ($whr_order) ORDER BY u2t.u2t_marked<=>1 DESC , $odr" ; |
| | + | } else { |
| | + | $sql = "SELECT t.topic_id, t.topic_title, t.topic_last_uid, t.topic_last_post_id, t.topic_last_post_time, t.topic_views, t.topic_votes_count, t.topic_votes_sum, t.topic_posts_count, t.topic_external_link_id, $sel_solved, t.forum_id, f.forum_title, 0 AS u2t_marked FROM ".$db->prefix($mydirname."_topics")." t LEFT JOIN ".$db->prefix($mydirname."_forums")." f ON f.forum_id=t.forum_id WHERE ! t.topic_invisible AND ($whr_forum) AND ($whr_categories) AND ($whr_forums) AND ($whr_order) ORDER BY $odr" ; |
| | + | } |
| | + | }} |
| | + | |
| | + | 同じく、224~243行目付近、以下の1行を追記 |
| | + | #code(php,224-){{ |
| | + | $topic4assign = array( |
| | + | 'id' => intval( $topic_row['topic_id'] ) , |
| | + | 'title' => $myts->makeTboxData4Show( $topic_row['topic_title'] ) , |
| | + | 'forum_id' => intval( $topic_row['forum_id'] ) , |
| | + | 'forum_title' => $myts->makeTboxData4Show( $topic_row['forum_title'] ) , |
| | + | 'replies' => $topic_row['topic_posts_count'] - 1 , |
| | + | 'views' => intval( $topic_row['topic_views'] ) , |
| | + | 'votes_count' => $topic_row['topic_votes_count'] , |
| | + | 'votes_sum' => intval( $topic_row['topic_votes_sum'] ) , |
| | + | 'last_post_id' => intval( $topic_row['topic_last_post_id'] ) , |
| | + | 'last_post_time' => intval( $topic_row['topic_last_post_time'] ) , |
| | + | 'last_post_time_formatted' => formatTimestamp($topic_row['topic_last_post_time'] , 'm' ) , |
| | + | 'last_uid' => intval( $topic_row['topic_last_uid'] ) , |
| | + | 'last_uname' => XoopsUser::getUnameFromId( $topic_row['topic_last_uid'] ) , |
| | + | 'solved' => intval( $topic_row['topic_solved'] ) , |
| | + | 'u2t_marked' => intval( $topic_row['u2t_marked'] ) , |
| | + | 'external_link_id' => intval( $topic_row['topic_external_link_id'] ) , //← 追記 |
| | + | ) ; |
| | + | }} |
| | + | |
| | + | *** 1.2. function b_d3forum_list_posts_show [#w99d060e] |
| | + | 内の392行目付近 |
| | + | #code(php,392){{ |
| | + | $sql = "SELECT p.post_id, p.subject, p.votes_sum, p.votes_count, p.post_time, p.post_text, p.uid, p.html, p.xcode, p.smiley, p.br, f.forum_id, f.forum_title, t.topic_external_link_id FROM ".$db->prefix($mydirname."_posts")." p LEFT JOIN ".$db->prefix($mydirname."_topics")." t ON p.topic_id=t.topic_id LEFT JOIN ".$db->prefix($mydirname."_forums")." f ON f.forum_id=t.forum_id WHERE ! t.topic_invisible AND ($whr_forum) AND ($whr_categories) AND ($whr_forums) AND ($whr_order) ORDER BY $odr" ; |
| | + | }} |
| | + | 同じく421~433行目付近に1行追加 |
| | + | #code(php,421-){{ |
| | + | $post4assign = array( |
| | + | 'id' => intval( $post_row['post_id'] ) , |
| | + | 'subject' => $myts->makeTboxData4Show( $post_row['subject'] ) , |
| | + | 'forum_id' => intval( $post_row['forum_id'] ) , |
| | + | 'forum_title' => $myts->makeTboxData4Show( $post_row['forum_title'] ) , |
| | + | 'votes_count' => $post_row['votes_count'] , |
| | + | 'votes_sum' => intval( $post_row['votes_sum'] ) , |
| | + | 'post_time' => intval( $post_row['post_time'] ) , |
| | + | 'post_time_formatted' => formatTimestamp( $post_row['post_time'] , 'm' ) , |
| | + | 'uid' => intval( $post_row['uid'] ) , |
| | + | 'uname' => XoopsUser::getUnameFromId( $post_row['uid'] ) , |
| | + | 'external_link_id' => intval( $post_row['topic_external_link_id'] ) , //← 追記 |
| | + | ) ; |
| | + | }} |
| | + | |
| | + | ** 2. カスタムテンプレート作成(Altsys使用) [#w749b797] |
| | + | |
| | + | 以下、picoへのリンクの例です。 ディレクトリ名や、他のモジュールの場合は当該行を適宜編集してください。 |
| | + | また、コメント元記事でのコメントはpost一覧表示を前提にしています。 トピック表示の場合は省略します。 |
| | + | なお、複数のモジュールに対応するためには、テンプレート内で |
| | + | <{if $post.forum_id == 1}> や |
| | + | <{if $topic.forum_id == 1}> |
| | + | などの方法で場合分けし、リンク先を切り替える必要があります。 逆に言えば、きちんと場合分けを記載しさえすれば、カスタムテンプレートである必要はなく、d3forumの各デフォルトテンプレート本体を編集しても構いません。 |
| | + | |
| | + | *** 2.1. _custom_d3f_topics.html [#db00490a] |
| | + | 「(d3forum)_block_list_topics.html」からコピーしてきて、16行目付近と54行目を付近のリンクを編集します。 |
| | + | |
| | + | #code(html,1-){{ |
| | + | <{if $block.full_view == true}> |
| | + | <table class="outer" cellspacing="1"> |
| | + | <thead> |
| | + | <tr> |
| | + | <th><{$block.lang_forum}></th> |
| | + | <th><{$block.lang_topic}></th> |
| | + | <th align="center"><{$block.lang_replies}></th> |
| | + | <th align="center"><{$block.lang_views}></th> |
| | + | <th align="center" colspan="2"><{$block.lang_lastpost}></th> |
| | + | </tr> |
| | + | </thead> |
| | + | <{foreach item=topic from=$block.topics}> |
| | + | <{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> |
| | + | <td><a href="<{$xoops_url}>/modules/pico/index.php?content_id=<{$topic.external_link_id}>#post_id<{$topic.last_post_id}>"> |
| | + | <{if $topic.u2t_marked}><img src="<{$block.mod_imageurl}>/block_marked.gif" alt="<{$block.lang_alt_marked}>" /><{/if}> |
| | + | <{* displays the last post's subject or topic title *}> |
| | + | <{if $block.disp_last_subject }> |
| | + | <{$topic.last_subject}> |
| | + | <{else}> |
| | + | <{$topic.title}> |
| | + | <{/if}></a> |
| | + | <{if ! $topic.solved}><img src="<{$block.mod_imageurl}>/block_unsolved.gif" alt="<{$block.lang_alt_unsolved}>" /><{/if}></td> |
| | + | <td align="center"><{$topic.replies}></td> |
| | + | <td align="center"><{$topic.views}></td> |
| | + | <td align="center" nowrap="nowrap"><{$topic.last_uname}></td> |
| | + | <td align="right" nowrap="nowrap"><{$topic.last_post_time_formatted}></td> |
| | + | </tr> |
| | + | <{/strip}> |
| | + | <{/foreach}> |
| | + | </table> |
| | + | |
| | + | <div style="text-align:right; padding: 5px;"> |
| | + | <a href="<{$block.mod_url}>/index.php?page=search"><{$block.lang_linktosearch}></a> |
| | + | |
| | + | <{if is_numeric( $block.forums ) }> |
| | + | <a href="<{$block.mod_url}>/index.php?forum_id=<{$block.forums}>"><{$block.lang_linktolisttopics}></a> |
| | + | <{else}> |
| | + | <a href="<{$block.mod_url}>/index.php?cat_ids=<{$block.categories}>"><{$block.lang_linktolisttopics}></a> |
| | + | <{/if}> |
| | + | |
| | + | <{if is_numeric( $block.categories ) }> |
| | + | <a href="<{$block.mod_url}>/index.php?cat_id=<{$block.categories}>"><{$block.lang_linktolistforums}></a> |
| | + | |
| | + | <{/if}> |
| | + | <a href="<{$block.mod_url}>/index.php"><{$block.lang_linktolistcategories}></a> |
| | + | </div> |
| | + | |
| | + | <{else}> |
| | + | |
| | + | <ol style="padding:3px;margin:0;"> |
| | + | <{foreach item=topic from=$block.topics}> |
| | + | <li><a href="<{$xoops_url}>/modules/pico/index.php?content_id=<{$topic.external_link_id}>#post_id<{$topic.last_post_id}>"><{$topic.title}></a>(<{$topic.replies}>) <{$topic.last_uname}> <{$topic.last_post_time_formatted}></li> |
| | + | <{/foreach}> |
| | + | </ol> |
| | + | <{/if}> |
| | + | }} |
| | + | |
| | + | なお、デフォルトテンプレート「(d3forum)_block_list_topics.html」を編集して使用する場合は、 |
| | + | #code(html,16-){{ |
| | + | <td> |
| | + | <{if $topic.forum_id == 4}> |
| | + | <a href="<{$xoops_url}>/modules/pico/index.php?content_id=<{$topic.external_link_id}>#post_id<{$topic.last_post_id}>"> |
| | + | <{elseif $topic.forum_id == 2}> |
| | + | <a href="<{$xoops_url}>/modules/d3blog/details.php?bid=<{$topic.external_link_id}>#post_id<{$topic.last_post_id}>"> |
| | + | <{else}> |
| | + | <a href="<{$block.mod_url}>/index.php?topic_id=<{$topic.id}>#post_id<{$topic.last_post_id}>"> |
| | + | <{/if}> |
| | + | }} |
| | + | |
| | + | #code(html,62-){{ |
| | + | <li> |
| | + | <{if $topic.forum_id == 4}> |
| | + | <a href="<{$xoops_url}>/modules/pico/index.php?content_id=<{$topic.external_link_id}>#post_id<{$topic.last_post_id}>"> |
| | + | <{elseif $topic.forum_id == 2}> |
| | + | <a href="<{$xoops_url}>/modules/d3blog/details.php?bid=<{$topic.external_link_id}>#post_id<{$topic.last_post_id}>"> |
| | + | <{else}> |
| | + | <a href="<{$block.mod_url}>/index.php?topic_id=<{$topic.id}>#post_id<{$topic.last_post_id}>"> |
| | + | <{/if}> |
| | + | <{$topic.title}></a>(<{$topic.replies}>) <{$topic.last_uname}> <{$topic.last_post_time_formatted}></li> |
| | + | }} |
| | + | |
| | + | などとして判別分岐すればOKです。上記の例は、picoとd3blogのリンク先を変更する場合です。$topic.forum_idの部分と、リンク先はサイト毎に適宜設定が必要です。 |
| | + | |
| | + | *** 2.2. _custom_d3f_posts.html [#e6d73320] |
| | + | 「(d3forum)_block_list_posts.html」からコピーしてきて、3行目付近のリンクを編集します。 |
| | + | |
| | + | #code(html,1-){{ |
| | + | <ol style="padding:3px;margin:0;"> |
| | + | <{foreach item=post from=$block.posts}> |
| | + | <li style="margin:1px;"><a href="<{$xoops_url}>/modules/pico/index.php?content_id=<{$post.external_link_id}>#post_id<{$post.id}>"><{$post.subject}></a> <{$post.uname}> <{$post.post_time_formatted}></li> |
| | + | <{/foreach}> |
| | + | </ol> |
| | + | }} |
| | + | |
| | + | なお、デフォルトテンプレート「(d3forum)_block_list_posts.html」を編集して使用する場合は、 |
| | + | #code(html,3-){{ |
| | + | <li style="margin:1px;"> |
| | + | <{if $post.forum_id == 4}> |
| | + | <a href="<{$xoops_url}>/modules/pico/index.php?content_id=<{$post.external_link_id}>#post_id<{$post.id}>"> |
| | + | <{elseif $post.forum_id == 2}> |
| | + | <a href="<{$xoops_url}>/modules/d3blog/details.php?bid=<{$post.external_link_id}>#post_id<{$post.id}>"> |
| | + | <{else}> |
| | + | <li style="margin:1px;"><a href="<{$block.mod_url}>/index.php?post_id=<{$post.id}>"> |
| | + | <{/if}> |
| | + | <{$post.subject}></a> <{$post.uname}> <{$post.post_time_formatted}></li> |
| | + | }} |
| | + | |
| | + | などとして判別分岐すればOKです。上記の例は、picoとd3blogのリンク先を変更する場合です。$topic.forum_idの部分と、リンク先はサイト毎に適宜設定が必要です。 |
| | + | |
| | + | ** 3. d3forumブロックの複製 [#hb23e68a] |
| | + | Altsysで、d3forumのブロックを複製します。 |
| | + | なお、それぞれコメント統合元モジュールごとに、複製する必要があります。 |
| | + | 複数の統合コメントのフォーラムを一括指定して表示することも可能ですが、テンプレート内の記述で if文で場合分けが必要になってきますので、ここでは割愛します。 |
| | + | |
| | + | *** 3.1. トピック一覧 ブロック [#h58d7c0e] |
| | + | - カスタムテンプレートを使用する場合は、ブロックオプションの「このブロックのテンプレート」には、 「db:_custom_d3f_topics.html」 に変更します。 |
| | + | - 「フォーラムを指定する」 欄には、コメント統合したフォーラムを指定します。 |
| | + | - 表示件数、その他オプションを指定します。 |
| | + | - タイトル、表示対象、優先度、などを適切に設定します。 |
| | + | |
| | + | *** 3.2. 投稿一覧 ブロック [#y9593886] |
| | + | - カスタムテンプレートを使用する場合は、ブロックオプションの「このブロックのテンプレート」には、 「db:_custom_d3f_posts.html」 に変更します。 |
| | + | - 「フォーラムを指定する」 欄には、コメント統合したフォーラムを指定します。 |
| | + | - 表示件数、その他オプションを指定します。 |
| | + | - タイトル、表示対象、優先度、などを適切に設定します。 |
| | + | |
| | + | ** 4. d3forumのテンプレート変更 [#odf9dd77] |
| | + | コメント一覧のリンクをクリックした時に、当該コメントにジャンプするように、アンカーを変更します。 |
| | + | |
| | + | *** 4.1. d3forum_comment_listposts_flat.html [#l1ccf49d] |
| | + | 26行目付近。 |
| | + | <a href="<{$mod_url}>/index.php?post_id=<{$post.id}>" id="post_path<{$post.unique_path}>" name="post_path<{$post.unique_path}>"><{$post.subject}></a> |
| | + | これを、以下のように変更 |
| | + | |
| | + | <a href="<{$mod_url}>/index.php?post_id=<{$post.id}>" id="post_path<{$post.unique_path}>" name="post_id<{$post.id}>"><{$post.subject}></a> |