Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Author Topic: Error in `editcomment` and `deletecomment` cases in processing function  (Read 9689 times)

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab

The error is in official 1.6 package. I`m asking myself why has not been observed... not too much commenters on our blogs based on sNews?

The guilty code is here (in processing function):

Code: [Select]
<?php // <-- don`t copy this line
case 'editcomment':
if (isset($_POST['submit_text'])) {
   mysql_query("UPDATE ".db('prefix')."comments SET name = '$name', url = '$url', comment = '$comment', approved = '$approved' WHERE id = '$commentid' LIMIT 1;");
}
else if (isset($_POST['delete_text'])) {
   mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
}
$articleid retrieve('articleid''comments''id'$commentid);
$link find_cat_sef($categoryid).'/'.retrieve('seftitle''articles''id'$articleid);
echo notification(0,'',$link);
break;
case 'deletecomment':
      
$commentid $_GET['commentid'];
    
$articleid $_GET['articleid'];
       
mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
$link find_cat_sef($categoryid).'/'.retrieve('seftitle''articles''id'$articleid);
echo notification(0,''$link);
break;

And must be replaced with this code:
Code: [Select]
<?php // <-- don`t copy this line
case 'editcomment':
   $commentid $_POST['commentid'];
   $articleid retrieve('articleid''comments''id'$commentid);
   if (isset($_POST['submit_text'])) {
mysql_query("UPDATE ".db('prefix')."comments SET name = '$name', url = '$url', comment = '$comment', approved = '$approved' WHERE id = '$commentid' LIMIT 1;");
   }
   else if (isset($_POST['delete_text'])) {
mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
   }
   $categoryid retrieve('category''articles''id'$articleid);
   $link retrieve('seftitle''categories''id'$categoryid).'/'.retrieve('seftitle''articles''id'$articleid);
   echo notification(0,'',$link);
break;
case 'deletecomment':
                   
$commentid $_GET['commentid'];
    
           $articleid $_GET['articleid'];
                   
mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
                   
$categoryid retrieve('category''articles''id'$articleid);
                   
$link retrieve('seftitle''categories''id'$categoryid).'/'.retrieve('seftitle''articles''id'$articleid);
   echo notification(0,''$link);
break;

I posted this on other places but it belongs here.
« Last Edit: April 24, 2008, 05:23:29 PM by funlw65 »
Logged

Joost

  • Guest

I could try and find out....  What is the error being solved?
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab

I described it here but only a part of error http://snewscms.com/forum/index.php?topic=7186.0.
Problem is with wrong link provided by notification function when you delete/edit a comment....deleting from comments page or from edit comment form...
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab

Why this patch is not applied to default sNews 1.6 package? Every time I download standard package I must add this patch...

Is not so good solution? Ok, but that error must be patched, not matter what working code is used.

------------------------------------
Is here a "closed circuit" sNews version?
« Last Edit: June 10, 2008, 02:54:10 PM by funlw65 »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca

Why this patch is not applied to default sNews 1.6 package? Every time I download standard package I must add this patch...
Is not so good solution? Ok, but that error must be patched, not matter what working code is used.

Well... Sir... I just tested the sNews16 package I updated the download with this morning.
Result - after Editing or Deleting a comment to an article (on the Home page)... the "Back" link always brings me back to the article where the comment was posted to. I never get the "no content" message. And I never have this problem with my latest MEMU+++ project either... which is based on the MEMU package (link in my signature).
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab

If that article is published in home category then the back link will guide you to that article again. But if article is published on another category, then, after deleting/editing the comment, the back link will point to home/article which is wrong. I tested (again) on freshly downloaded package ...
Does not matter what is set as homepage (a static page or articles). The same error.
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab

For instance,

this code is wrong:
Code: [Select]
<?php
case 'editcomment':
if (isset($_POST['submit_text'])) {
mysql_query("UPDATE ".db('prefix')."comments SET name = '$name', url = '$url', comment = '$comment', approved = '$approved' WHERE id = '$commentid' LIMIT 1;");
}
else if (isset($_POST['delete_text'])) {
mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
}
$articleid retrieve('articleid''comments''id'$commentid);
$link find_cat_sef($categoryid).'/'.retrieve('seftitle''articles''id'$articleid);
echo notification(0,'',$link);
break;


If I want to delete the comment, after deletion, i want to retrieve the articleid from the commentid  but that comment does not exist anymore so I will never get the articleid because mysql don't find that comment (it was deleted). The work around is to retrieve articleid from commentid before deleting the comment.
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab

I could try and find out....  What is the error being solved?

Joost, what you found? I'm making a mistake?
Logged

Joost

  • Guest

I could try and find out....  What is the error being solved?

Joost, what you found? I'm making a mistake?

That's a long time ago. :) I didn't understand back then, the nature of the issue. Now, I understand.
 What I don't understand, is why always  queries are used for solving issues.
This query is not needed:
$articleid = retrieve('articleid', 'comments', 'id', $commentid);
This should work instead (not tested):
$articleid = $_POST['id'];
Or am I missing something? ???
Logged

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab

Yes, is working but not alone. Now, code is (better than mine):

Code: [Select]
<?php
case 'editcomment':
if (isset($_POST['submit_text'])) {
mysql_query("UPDATE ".db('prefix')."comments SET name = '$name', url = '$url', comment = '$comment', approved = '$approved' WHERE id = '$commentid' LIMIT 1;");
}
else if (isset($_POST['delete_text'])) {
mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
}
//$articleid = retrieve('articleid', 'comments', 'id', $commentid);
//$commentid = $_POST['commentid'];  <-- this line is not need it
$articleid $_POST['id'];
$categoryid retrieve('category''articles''id'$articleid); // <-- new line introduced
$link find_cat_sef($categoryid).'/'.retrieve('seftitle''articles''id'$articleid);
echo notification(0,'',$link);
break;

You have a solution for this line?
$categoryid = retrieve('category', 'articles', 'id', $articleid);

Next, we must solve the case 'deletecomment';
My (working) solution was this:
Code: [Select]
<?php
case 'deletecomment':
                   
$commentid $_GET['commentid'];
    
           $articleid $_GET['articleid'];
                   
mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
                   
$categoryid retrieve('category''articles''id'$articleid);
                   
//$link = retrieve('seftitle', 'categories', 'id', $categoryid).'/'.retrieve('seftitle', 'articles', 'id', $articleid);
                   
$link find_cat_sef($categoryid).'/'.retrieve('seftitle''articles''id'$articleid);
   echo notification(0,''$link);
break;

I commented the $link line and put the line from case 'editcomment' ...
« Last Edit: July 24, 2008, 06:19:32 AM by funlw65 »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca

If that article is published in home category then the back link will guide you to that article again. But if article is published on another category, then, after deleting/editing the comment, the back link will point to home/article which is wrong. I tested (again) on freshly downloaded package ...
Does not matter what is set as homepage (a static page or articles). The same error.

Aha... I see what you mean now... right you are.
Test Results:
@ Funlw65... I tested both of your solutions (above) with comments on another category (only one other than home) and they both appear to solve the path issue OK. Here are the default sections (from the current download package) with your strings added:

Code: [Select]
<?php

case 'editcomment':
if (isset($_POST['submit_text'])) {
   mysql_query("UPDATE ".db('prefix')."comments SET name = '$name', url = '$url', comment = '$comment', approved = '$approved' WHERE id = '$commentid' LIMIT 1;");
}
else if (isset($_POST['delete_text'])) {
   mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
}
# Patch/fix July 24.08 - 1 string replaced by 2 below (funlw65)
//$articleid = retrieve('articleid', 'comments', 'id', $commentid);
$articleid $_POST['id'];
$categoryid retrieve('category''articles''id'$articleid);

$link find_cat_sef($categoryid).'/'.retrieve('seftitle''articles''id'$articleid);
echo notification(0,'',$link);
break;

case 'deletecomment':
$commentid $_GET['commentid'];
$articleid $_GET['articleid'];
# Patch/fix July 24.08 - add 1 string (funlw65)
$categoryid retrieve('category''articles''id'$articleid);

mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
$link find_cat_sef($categoryid).'/'.retrieve('seftitle''articles''id'$articleid);
echo notification(0,''$link);
break;
?>

« Last Edit: July 24, 2008, 03:33:57 PM by Keyrocks »
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab

Thank you Sir!
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca

Thank you Sir!

And thank you for being persistent (insisting on improvement). This is our "Community at Work". ;D
If this meets with your approval, I will update the official download today.
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU

funlw65

  • Hero Member
  • *****
  • Karma: 96
  • Posts: 771
    • Country Lab

What can I say more? Thank you again! I'm a beginner in both php programming and  english language, trying to improve them with the help of sNews forum members.

One line of code from first case is Joost suggestion...
« Last Edit: July 24, 2008, 09:55:48 PM by funlw65 »
Logged

Keyrocks

  • Doug
  • ULTIMATE member
  • ******
  • Karma: 449
  • Posts: 6019
  • Semantically Challenged
    • snews.ca

What can I say more? Thank you again! I'm a beginner in both php programming and  english language, trying to improve them with the help of sNews forum members.

Download is Updated!  ;D
Logged
Do it now... later may not come.
-------------------------------------------------------------------------------------------------
sNews 1.6 MESU | sNews 1.6 MEMU