1
eikke
com_itemid
  • 2004/2/5 11:06

  • eikke

  • Just popping in

  • Posts: 40

  • Since: 2004/1/15


I'm still working on my first big XOOPS module, but I encountered another problem:
I want to enable Comments on certain items. I have a page, a.php, which should be called like 'a.php?a={code}', where code is a string (not an integer, a 'varchar' of 10 digits/characters (so it *can* be an int, but isnt necessarily so)). I cannot change this 'code' thing, its an ID I need to query other services.
Now I did what is in the Wiki: I added
$modversion['hasComments'] = 1;
$modversion['comments']['itemName'] = 'a';
$modversion['comments']['pageName'] = 'a.php';
to my xoops_version.php, copied the mylinks comment files to my module root, added everything to my template,...
Now when I try to add a comment, it's never displayed. I took a look in my database (xoopscomments). Everything seems to be correct over there, except 'com_itemid'. I guess this one should be the $_GET['a'] thing, isnt it?
Problem is: if I want to add a comment on page 'a.php?a=596002564', the value '16777215' is stored as com_itemid, because that column is of type mediumint(8) UNSIGNED, which isn't the right thing for my application (should be varchar(10)).
Is there any way to get around this problem? And if there is none (except changing the layout of the xoopscomment table), is it safe to do so?

Greetz, Ikke

2
eikke
Re: com_itemid
  • 2004/2/21 16:37

  • eikke

  • Just popping in

  • Posts: 40

  • Since: 2004/1/15


*bump* (please...)

3
worlds
Bookstore Comments
  • 2004/4/6 0:46

  • worlds

  • Just popping in

  • Posts: 61

  • Since: 2004/3/13


Sounds like a problem for me, too. I was looking at adding comments to the bookstore module, but the bookstore is keyed off of the amazon id, which is a large alphanumeric field (e.g. B0000AXE8I).

I could make a dummy "id for comments" field, but that wouldn't work as well, for a number of reasons.

Any suggestions?

Tom

4
hyperpod
Re: com_itemid
  • 2005/8/10 11:35

  • hyperpod

  • Quite a regular

  • Posts: 359

  • Since: 2004/10/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

Login

Who's Online

244 user(s) are online (154 user(s) are browsing Support Forums)


Members: 0


Guests: 244


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Apr 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits