d3forumコメント統合でブロックから元記事へリンクしたい anchor.png

  • 元ネタ:XUGJのこのトピ
  • 実装例1: このサイトのなーおn研究室の、右側にコメントトピック一覧、ブログの左側のコメントトピック一覧があります。デフォルトテンプレートの編集でやってます。
  • 実装例2: テストサイトのこのページの右側に、コメントトピック一覧と投稿一覧があります。
Page Top

1. d3forumソースハック anchor.png

(trust_path)/modules/d3forum/blocks/block_functions.php を編集します。

Page Top

1.1. function b_d3forum_list_topics_show anchor.png

 内の191~195行目付近を、以下のように変更。
 _d3forum_topics テーブルから フィールド値「topic_external_link_id」を抽出し、アサインします。

191
192
193
194
195
    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行を追記

224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
        $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'] ) , //← 追記
        ) ;
Page Top

1.2. function b_d3forum_list_posts_show anchor.png

内の392行目付近

1
    $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行追加

421
422
423
424
425
426
427
428
429
430
431
432
433
        $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'] ) ,    //← 追記
        ) ;
Page Top

2. カスタムテンプレート作成(Altsys使用) anchor.png

以下、picoへのリンクの例です。 ディレクトリ名や、他のモジュールの場合は当該行を適宜編集してください。
また、コメント元記事でのコメントはpost一覧表示を前提にしています。 トピック表示の場合は省略します。
なお、複数のモジュールに対応するためには、テンプレート内で

<{if $post.forum_id == 1}> や
<{if $topic.forum_id == 1}> 

などの方法で場合分けし、リンク先を切り替える必要があります。 逆に言えば、きちんと場合分けを記載しさえすれば、カスタムテンプレートである必要はなく、d3forumの各デフォルトテンプレート本体を編集しても構いません。

Page Top

2.1. _custom_d3f_topics.html  anchor.png

「(d3forum)_block_list_topics.html」からコピーしてきて、16行目付近と54行目を付近のリンクを編集します。

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
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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
<{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>
&nbsp;
<{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}>
&nbsp;
<{if is_numeric( $block.categories ) }>
<a href="<{$block.mod_url}>/index.php?cat_id=<{$block.categories}>"><{$block.lang_linktolistforums}></a>
&nbsp;
<{/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」を編集して使用する場合は、

Everything is expanded.Everything is shortened.
16
17
18
19
20
21
22
23
 
 
 
 
 
 
 
 
    <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}>
Everything is expanded.Everything is shortened.
62
63
64
65
66
67
68
69
70
 
 
 
 
 
 
 
 
 
    <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の部分と、リンク先はサイト毎に適宜設定が必要です。

Page Top

2.2. _custom_d3f_posts.html anchor.png

「(d3forum)_block_list_posts.html」からコピーしてきて、3行目付近のリンクを編集します。

Everything is expanded.Everything is shortened.
1
2
3
4
5
 
 
 
 
 
<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」を編集して使用する場合は、

Everything is expanded.Everything is shortened.
 3
 4
 5
 6
 7
 8
 9
10
11
 
 
 
 
 
 
 
 
 
     <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の部分と、リンク先はサイト毎に適宜設定が必要です。

Page Top

3. d3forumブロックの複製 anchor.png

Altsysで、d3forumのブロックを複製します。
なお、それぞれコメント統合元モジュールごとに、複製する必要があります。
複数の統合コメントのフォーラムを一括指定して表示することも可能ですが、テンプレート内の記述で if文で場合分けが必要になってきますので、ここでは割愛します。

Page Top

3.1. トピック一覧 ブロック anchor.png

  • カスタムテンプレートを使用する場合は、ブロックオプションの「このブロックのテンプレート」には、 「db:_custom_d3f_topics.html」 に変更します。
  • 「フォーラムを指定する」 欄には、コメント統合したフォーラムを指定します。
  • 表示件数、その他オプションを指定します。
  • タイトル、表示対象、優先度、などを適切に設定します。
Page Top

3.2. 投稿一覧 ブロック anchor.png

  • カスタムテンプレートを使用する場合は、ブロックオプションの「このブロックのテンプレート」には、 「db:_custom_d3f_posts.html」 に変更します。
  • 「フォーラムを指定する」 欄には、コメント統合したフォーラムを指定します。
  • 表示件数、その他オプションを指定します。
  • タイトル、表示対象、優先度、などを適切に設定します。
Page Top

4. d3forumのテンプレート変更 anchor.png

コメント一覧のリンクをクリックした時に、当該コメントにジャンプするように、アンカーを変更します。

Page Top

4.1. d3forum_comment_listposts_flat.html anchor.png

 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>

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