WordPressモジュールのコメントをd3forumに統合 anchor.png

  • まだ途中です。何とか動くようになりました。(2007-06-13)
  • WordPressモジュールはnobunobuさん版です。0.6.0で試してます。
  • nobunobuさん版はXOOPSのコメントシステムにも対応しているので、カスタマイズができるかなと思って。でも、テンプレートがないのでファイルに直書きですね。
  • ちなみに、このサイトの「ごくろぐ」で使っているWordPressモジュールはXPressです。なのでこの作業は別のサイトでためしてます。
Page Top

作業の覚え書き anchor.png

Page Top

フォーラムの作成 anchor.png

  • まずは、管理画面で、d3forumモジュールにWordPressモジュール用のフォーラムを作成する。
    • 「コメント統合時の参照方法」には、"{XOOPS_URL}/modules/wordpress1/index.php?&p=%s"を入れる。
Page Top

WordPressモジュールのコメントシステムの設定 anchor.png

  • 管理画面から、WordPressモジュールのコメントをXOOPSコメントシステムに設定します。
Page Top

xoops-comments-template.phpの修正 anchor.png

  • /modules/worpress/themes/themes_files/xoops-comments-template.phpに以下を記述。$forum_idはd3forumに作成したWordPressモジュール用のフォーラム番号にする。
    <?php
    require_once(XOOPS_TRUST_PATH.'/modules/d3forum/include/comment_functions.php');
    $dirname = "d3forum";
    $forum_id = "2";
    $post_title = get_the_title();
    $params = array("dirname" => $dirname,
    		"forum_id" => $forum_id,
    		"itemname" => "p",
    		"subject" => $post_title);
    ?>
    <div id="comments">
    <?php
    d3forum_display_comment( $dirname , $forum_id , $params ) ;
    ?>
    </div>
  • これで、d3forumモジュールの該当フォーラムにかかれたコメントがWordPressモジュールの各記事個別ページに表示されるようになる。
Page Top

template-functions-comment.phpの修正 anchor.png

  • 各記事ごとのコメント数表示がおかしいので、修正。(2007-06-09、2007-06-13再修正)
    • /modules/wordpress/wp-includes/template-functions-comment.phpのfunction comments_numberを修正。
      		$number = $commentHandler->getCount($criteria);
      	}
      の後に、
      	require_once(XOOPS_TRUST_PATH.'/modules/d3forum/include/comment_functions_2.php');
      	$number = d3forum_display_comment_topicscount ( $GLOBALS['dirname'] , $GLOBALS['forum_id'] , $GLOBALS['params'] ) ;
      を追記。
    • /modules/wordpress/wp-includes/template-functions-comment.phpのfunction comments_popup_linkを修正。
      	$comments_popup_link .= comments_number($zero, $one, $more, $number, false);
      の直前に、
      $dirname = "d3forum";
      $forum_id = "2";
      $params = array("dirname" => $dirname,
      		"forum_id" => $forum_id,
      		"link_id" => $wp_post_id);
      を追記。
Page Top

index-template.phpの修正 anchor.png

  • /modules/worpress/themes/themes_files/index-template.phpを修正。
    <?php comments_popup_link(_WP_TPL_COMMENT0, _WP_TPL_COMMENT1, _WP_TPL_COMMENTS); ?> 
    のすぐ前に、
    <?php
    	require_once(XOOPS_TRUST_PATH.'/modules/d3forum/include/comment_functions.php');
    	$dirname = "d3forum";
    	$forum_id = "2";
    	$params = array("dirname" => $dirname,
    			"forum_id" => $forum_id,
    			"link_id" => $wp_post_id);
    ?>
    を追記。

(2007-07-04追記)

  • /modules/worpress/themes/themes_files/content_block-template.phpにも同じ修正を加えると幸せになれるかも。
Page Top

comment_functions_2.phpの作成 anchor.png

(2007-06-13追記)

    • XOOPS_TRUST_PATH/modules/d3forum/includeに以下の内容のファイル(comment_functions_2.php)を作成。comment_functions.phpのfunction d3forum_display_comment_topicscountの最後のechoをreturnに変えただけです。
      <?php
      
      function d3forum_display_comment_topicscount_2( $mydirname , $forum_id , $params , $mode = 'post' )
      {
      	global $xoopsUser , $xoopsConfig ;
      
      	$mydirpath = XOOPS_ROOT_PATH.'/modules/'.$mydirname ;
      	$mytrustdirpath = dirname( dirname( __FILE__ ) ) ;
      
      	$db =& Database::getInstance() ;
      
      	// external_link_id
      	if( ! empty( $params['link_id'] ) ) {
      		$external_link_id = $params['link_id'] ;
      	} else if( ! empty( $params['itemname'] ) ) {
      		$external_link_id = @$_GET[ $params['itemname'] ] ;
      	} else {
      		echo "set valid link_id or itemname in the template" ;
      		return ;
      	}
      	if( empty( $external_link_id ) ) return ;
      
      	// check the d3forum exists and is active
      	$module_hanlder =& xoops_gethandler( 'module' ) ;
      	$module =& $module_hanlder->getByDirname( $mydirname ) ;
      	if( ! is_object( $module ) || ! $module->getVar('isactive') ) {
      		return ;
      	}
      
      	// check permission of "module_read"
      	$moduleperm_handler =& xoops_gethandler( 'groupperm' ) ;
      	$groups = is_object( $xoopsUser ) ? $xoopsUser->getGroups() : array( XOOPS_GROUP_ANONYMOUS ) ;
      	if( ! $moduleperm_handler->checkRight( 'module_read' , $module->getVar( 'mid' ) , $groups ) ) {
      		return ;
      	}
      
      	$select = $mode == 'topic' ? 'COUNT(t.topic_id)' : 'SUM(t.topic_posts_count)' ;
      
      	$sql = "SELECT $select FROM ".$db->prefix($mydirname."_topics")." t WHERE t.forum_id=$forum_id AND ! t.topic_invisible AND topic_external_link_id='".addslashes($external_link_id)."'" ;
      	if( ! $trs = $db->query( $sql ) ) die( 'd3forum_comment_error in '.__LINE__ ) ;
      	list( $count ) = $db->fetchRow( $trs ) ;
      //	echo intval( $count ) ;
      	return intval( $count ) ;
      }
      
      ?>

以上で、何とか動いています。


新しくコメントをつける

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

コメント一覧


Front page   Freeze Diff Backup Copy Rename ReloadPrint View   New Page Page list Search Recent changes   Help   RSS of recent changes (RSS 1.0) RSS of recent changes (RSS 2.0) RSS of recent changes (RSS Atom) Powered by xpWiki
Counter: 1730, today: 2, yesterday: 0
Princeps date: 2007-06-09 (Sat) 20:33:53
Last-modified: 2008-05-11 (Sun) 03:45:37 (JST) (1366d) by gokuraku

ログイン

ユーザ名:

パスワード:



パスワード紛失

新規登録

ad by google