9
Ok well... Since nobody seems to be interested, I decided to try this myself. But after I completed step 4 I don't really understand what to do next.
How do I actually make it work? Do I have to at a table to the database? How do I call the comment functions on userinfo.php? What is a callback and why is it optional?
Someone out there that knows more than me must be interested in this hack! At least tell me if I am crazy to try to make this work?
===== 3.4.3.1 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).
<div style="text-align: center; padding: 3px; margin: 3px;">
<{$commentsnav}>
<{$lang_notice}>
div>
<div style="margin: 3px; padding: 3px;">
<{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}>
div>
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
}