4
wow, old thread :)
I have just run into this same problem.
My module identifies the items with an alphanumeric ID, and I really wanted to use the xoopsComments system.
But was stopped when I found out xoops_comments com_itemid must be a numeric value only.
So i dug more into the XOOPS comments system and changed every part that forces $com_itemid or $item_id to be numeric only.
Here is what i did to hack the comments system to handle alphanumeric instead of only numeric:
-------------------------------------------
1. In comment_new.php, comment_view.php and comment_post.php (make sure to look at the include/ versions of these as well) anywhere you see a intval($com_itemid) or intval($_GET['com_itemid']), take off the intval function. For security, anytime your PHP is grabbing com_itemid from a GET or POST, you should use something like ctype_alnum() to validate the incoming data and set it to 0 if its not alphanumeric or numeric only.
2. if you see this: if ($com_itemid > 0)
should change to: if ($com_itemid)
3. In the database under table prefix_xoopscomments
edit the field called com_itemid type and change from mediumint(8) to varchar(32)
4. in kernel/comment.php: change this line in function &getByItemId()
$criteria->add(new Criteria('com_itemid', intval($item_id)));
remove the intval function
ditto for function &getCountByItemId()
as well as function &getTopComments()
5. in kernel/comment.php: edit: $this->initVar('com_itemid', XOBJ_DTYPE_INT, 0, false); (around line73) to be this:
$this->initVar('com_itemid', XOBJ_DTYPE_OTHER, null, true, 32);
and also change these lines in insert() function to this:
(not: changed where it inserts com_itemid with %u to %s and added the single quotes on them. for both insert and update)
if ($comment->isNew()) {
$com_id = $this->db->genId('xoopscomments_com_id_seq');
$sql = sprintf("INSERT INTO %s (com_id, com_pid, com_modid, com_icon, com_title, com_text, com_created, com_modified, com_uid, com_ip, com_sig, com_itemid, com_rootid, com_status, com_exparams, dohtml, dosmiley, doxcode, doimage, dobr) VALUES (%u, %u, %u, %s, %s, %s, %u, %u, %u, %s, %u, %s, %u, %u, %s, %u, %u, %u, %u, %u)", $this->db->prefix('xoopscomments'), $com_id, $com_pid, $com_modid, $this->db->quoteString($com_icon), $this->db->quoteString($com_title), $this->db->quoteString($com_text), $com_created, $com_modified, $com_uid, $this->db->quoteString($com_ip), $com_sig, $this->db->quoteString($com_itemid), $com_rootid, $com_status, $this->db->quoteString($com_exparams), $dohtml, $dosmiley, $doxcode, $doimage, $dobr);
} else {
$sql = sprintf("UPDATE %s SET com_pid = %u, com_icon = %s, com_title = %s, com_text = %s, com_created = %u, com_modified = %u, com_uid = %u, com_ip = %s, com_sig = %u, com_itemid = %s, com_rootid = %u, com_status = %u, com_exparams = %s, dohtml = %u, dosmiley = %u, doxcode = %u, doimage = %u, dobr = %u WHERE com_id = %u", $this->db->prefix('xoopscomments'), $com_pid, $this->db->quoteString($com_icon), $this->db->quoteString($com_title), $this->db->quoteString($com_text), $com_created, $com_modified, $com_uid, $this->db->quoteString($com_ip), $com_sig, $this->db->quoteString($com_itemid), $com_rootid, $com_status, $this->db->quoteString($com_exparams), $dohtml, $dosmiley, $doxcode, $doimage, $dobr, $com_id);
}
done.
-------------------------------------------
This hack should add alphanumeric support for XOOPS comments com_itemid
Hope this helps someone.
************
Unless XOOPS adds alphanumeric support for comments system itemid, then this will need to be hacked on any site that installs a module that might need alphanum support.
What can we get this into the core? I think it will really improve the current XOOPS comments system, while still being compatible with existing sites.
************
Best Regards,
Daniel Hall / XOOPS Module Development & Theme Design
Free XOOPS Support >
My Wish List