Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Go Back button while editing or deleting comments  (Read 5165 times)

henrich

  • Sr. Member
  • ****
  • Karma: 23
  • Posts: 381
  • Passion for quality and excellence!
    • My personal blog and portofolio
Go Back button while editing or deleting comments
« on: January 31, 2008, 11:27:37 pm »

Hi,

I experienced 2 problems while i tryed to edit or delete a comment. The editing and deleting actions are going just fine.

After the succesful comment edit i will get the default succesful text (Operation completed successfully!) and the BACK link which has the next url example:

http://www.domain.com/home/article/

instead of

http://www.domain.com/article/

After deleting a comment:

http://www.domain.com/home//

instead of

http://www.domain.com/article/

I must note that i am using the ML package written by Rui Mendes and i have removed the "home" option from "add new article" panel and from the categories listing.



Quote
case 'editcomment':
         if (isset($_POST['submit_text'])) {
            //comment addon
            mysql_query("UPDATE ".db('prefix')."comments SET name = '$name', email = '$email', 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;

I think here is the bug?!
Logged
By(e) Henrich :)
------------------------------
IT related blog

bikoz

  • Jr. Member
  • **
  • Karma: 3
  • Posts: 66
Re: Go Back button while editing or deleting comments
« Reply #1 on: February 26, 2008, 12:13:19 pm »

I confirm.

It's because $categoryid is not defined and it defaults to 0 (and sNews redirect to 'home').

I've written a fix (for 'editcomment' only, for testing purpose):

Quote
$articleid = retrieve('articleid', 'comments', 'id', $commentid);
$categoryid = retrieve('category', 'articles', 'id', $articleid);
$link = find_cat_sef($categoryid).'/'.retrieve('seftitle', 'articles', 'id', $articleid);
echo notification(0,'',$link);

Please let me know if it works for you.
FYI: I don't use 'home' as a category but I display new articles on 'home'.


« Last Edit: February 26, 2008, 05:19:42 pm by bikoz »
Logged

Dom

  • Full Member
  • ***
  • Karma: 5
  • Posts: 163
    • domdelimar.com
Re: Go Back button while editing or deleting comments
« Reply #2 on: March 28, 2008, 11:45:46 pm »

Yep, bikoz, this solves the bug after comment edit action!

Thank you guys, Henrich for reporting and bikoz for making a fix - I thought it was just my pretty heavily modded sNews but I guess I was wrong...

Now, my limited knowledge of PHP keeps me from getting to the bottom of the "delete comment bug" but I hope upcoming sNews 1.7 won't have it.

Logged

bikoz

  • Jr. Member
  • **
  • Karma: 3
  • Posts: 66
Re: Go Back button while editing or deleting comments
« Reply #3 on: March 29, 2008, 12:04:23 am »

Now, my limited knowledge of PHP keeps me from getting to the bottom of the "delete comment bug" but I hope upcoming sNews 1.7 won't have it.

The fix is the same for the Delete action, here is the full code section (with comments) so that you have context and know where you have to inset the fixes:

Quote
      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);
         // FIXME Link is wrong because $categoryid is not set and defaults to Home (0)
         $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'];
             mysql_query("DELETE FROM ".db('prefix')."comments WHERE id = $commentid LIMIT 1;");
         // FIXME Link is wrong because $categoryid is not set and defaults to Home (0)
         $categoryid = retrieve('category', 'articles', 'id', $articleid);

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

I hope this is what you're looking for...

Logged

Dom

  • Full Member
  • ***
  • Karma: 5
  • Posts: 163
    • domdelimar.com
Re: Go Back button while editing or deleting comments
« Reply #4 on: March 29, 2008, 01:17:10 am »

I don't know what's at work in my instance of sNews. Keep in mind it is modded quite a bit, so it could be it.

I triple checked to make sure the code you posted is identical to what I have in snews.php but that bug after I delete a comment is still bugging me. Well, not really bugging me, it's not something I can't wait for to be fixed in 1.7 (after I re-apply every mod I have).
Logged

bikoz

  • Jr. Member
  • **
  • Karma: 3
  • Posts: 66
Re: Go Back button while editing or deleting comments
« Reply #5 on: March 29, 2008, 01:31:40 am »

I'd say I've just added the missing $categoryid = retrieve('category', 'articles', 'id', $articleid); line of code in both editcomment and deletecomment actions... If one works, the other one should work, too.

The default 1.6 version's code reads:

Quote
      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;
   }


Logged