User Login    
 + Register
  • Main navigation
Login
Username:

Password:


Lost Password?

Register now!
Documentation
Who's Online
85 user(s) are online (6 user(s) are browsing XoopsWiki)

Members: 1
Guests: 84

meezs, more...
[Main Page]

Dev:comment system

From XOOPS Project

Main Page | Recent changes | Edit this page | Page history | Switch to MediaWiki mode

Printable version | Disclaimers | Privacy policy
Category: Development

Contents

Adding XOOPS global comments feature to your module (Smarty version)

Step 1

First of all, there are 2 variables that you must prepare before proceeding to subsequent steps. Those are:

   * A. The name of unique ID for an item to which comments will be added. For example, this will be 'storyid' in News module, and 'poll_id' in XoopsPoll module.
   * B. The name of file which displays each item when the above unique item ID is passed as HTTP GET request. For example, the file name will be 'article.php' for News module, where an each article will be displayed by accessing this file as article.php?storyid=(unique id here). Similarly, it will be 'pollresults.php' for XoopsPoll module.

Now open xoops_version.php and add the following lines:

$modversion['hasComments'] = 1; $modversion['comments']['itemName'] = 'value obtained in A'; $modversion['comments']['pageName'] = 'value obtained in B';

For example, in News module:

$modversion['hasComments'] = 1; $modversion['comments']['itemName'] = 'storyid'; $modversion['comments']['pageName'] = 'article.php';

Step 2

Copy the following files from the web links module and save them to your module directory

       * comment_new.php
       * comment_edit.php
       * comment_delete.php
       * comment_post.php
       * comment_reply.php

Step 3

Open the file specified in Step 1B (i.e. article.php in News), and add the following line just before including footer.php

include XOOPS_ROOT_PATH.'/include/comment_view.php';

Step 4

Open the appropriate template file for your module (news_article.html for News module), and copy paste the following lines where comments should be displayed (You can of course customise the HTML tags as you prefer).

<{$commentsnav}> <{$lang_notice}>


<{if $comment_mode == "flat"}> <{include file="db:system_comments_flat.html"}> <{elseif $comment_mode == "thread"}> <{include file="db:system_comments_thread.html"}> <{elseif $comment_mode == "nest"}> <{include file="db:system_comments_nest.html"}> <{/if}> 

That's about all you would need to add on the user side. As for the admin side, ALWAYS call the following function whenever an item is deleted so that the comments attached to the deleted item will also be removed and number of user posts be updated accordingly.

function xoops_comment_delete(integer module_id , integer item_id)

For example in News module, the function is called as below whenever a news article is deleted:

xoops_comment_delete($xoopsModule->getVar('mid'), $storyid)

Another useful function is xoops_comment_count(), which takes module ID and item ID as parameters and will return the total number of comments for the specified item.

function xoops_comment_count(integer module_id [, integer item_id*])

If item_id is not specified, then the total number of comments for the module specified by module_id will be returned.

Step 5 (Optional)

Setting up callback functions

You can specify callback functions by adding the following lines to xoops_version.php.

$modversion['comments']['callback']['approve'] = 'function';

function will be executed upon successful post of an approved comment. This includes comment posts by administrators, and change of comment status from 'pending' to 'active' state. An XoopsComment object that has been approved will be passed as the first and only parameter. This should be useful for example notifying the item submitter of a comment post.

$modversion['comments']['callback']['update'] = 'function';

function will be executed whenever the total number of 'active' comments for an item is changed. Two parameters will be passed as parameters, the unique ID of an item as the first parameter and the total number of active comments for that item as the second.

$modversion['comments']['callbackFile'] = 'file name';

The name of file in which callback functions are defined.

Example

modules/mylinks/xoops_version.php

$modversion['comments']['callbackFile'] = 'include/comment_functions.php'; $modversion['comments']['callback']['approve'] = 'mylinks_com_approve'; $modversion['comments']['callback']['update'] = 'mylinks_com_update';

modules/mylinks/include/comment_functions.php

function mylinks_com_update($link_id, $total_num){

       $db =& Database::getInstance();
       $sql = 'UPDATE '.$db->prefix('mylinks_links').' SET comments = '.$total_num.' WHERE lid = '.$link_id;
       $db->query($sql);

}

function mylinks_com_approve(&$comment){

       / / send notification mail

}

Retrieved from "http://www.xoops.org/modules/mediawiki/index.php/Dev:comment_system"

This page has been accessed 403 times. This page was last modified 02:05, 16 December 2007. Content is available under XOOPS Project.


Local Support Sites
Powered by
XOOPS Code hosted on SourceForge

Powered by PHP



Powered by MySQL

Powered by Smarty

OSI certified

All content on this site is subject to the Creative Commons License
Developers for Hire