[RC1] Thank Post by User v0.3.2

A place for MOD Authors to post and receive feedback on MODs still in development. No MODs within this forum should be used within a live environment! No new topics are allowed in this forum.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

IMPORTANT: MOD Development Forum rules

On February 1, 2009 this forum will be set to read only as part of retiring of phpBB2.
mahninphyu
Registered User
Posts: 7
Joined: Sat Sep 08, 2007 4:30 am

Re: [BETA] Thank Post by User 0.2.5a

Post by mahninphyu »

Hello alexi02

thanks for the help again. everybody in my forum is very happy with the thank bottom. also my forum is clean coz they not post the spem post. i am really appriciate you work. one thing i would lite to ask again. i saw one forum. they are using vBulletin. they have thank bottom too. but when you click the bottom, it is not going to another page. you are at the post and your name is coming up in the thanks user list. i am asking because my forum people are all over the world and some of the country internet connetion are really suck. so when they click thank bottom they have to wait about 2 mins and they said that even they want to thank, they have to avoid it.
so, if you have time, can you please help me with this matter.
thanks
regards
mahninphyu
alexi02
Registered User
Posts: 271
Joined: Fri Mar 05, 2004 2:15 am
Location: Australia
Contact:

Re: [BETA] Thank Post by User 0.2.5a

Post by alexi02 »

cavallino wrote:Thanks alexi,
the second solution (removing completely the line, along with the end braket) works, but I believe that in this way, the "Thanked Listing" are always showing up when you open a user's profile, and you can't hide them, am I correct? So if for example a user get 100 thanks in different posts, the profile page is gonna be very very long... hmmm maybe I will try to study if i can put somehow a toggle to hide/show the thanked listing field...
Yes that's true, it will list them all the time which will make it a bit slower when loading up the profile page. It's a bit weird that the code &thankslist=1 doesn't bring up the Thanked Listing. Hmm, try changing the last isset to $HTTP_POST_VARS['thankedlist']. I think I forgot to change that...

cavallino wrote:Anyway, would be possible to do the same way to show a "Given Thanks listing"?
Sure is. It's pretty much the same kind of thing.

Open includes/usercp_profile.php

Find

Code: Select all

$thanks_given = $user_row['user_thanks_given'];
Replace with

Code: Select all

$temp_url = "profile.$phpEx?mode=viewprofile&u=" . $profiledata['user_id'] . "&thankedlist=1";
$thanks_given = '<a href="' . $temp_url . '">' . $user_row['user_thanks_given'] . '</a>';
Find

Code: Select all

else {
   $thanks_given = "";
   $thanks_received = "";
}

//
// End Thank Post by User Mod
//
After Add

Code: Select all

// Thanked Listing
if ( isset($HTTP_GET_VARS['thankedlist']) || isset($HTTP_GET_VARS['thankedlist']) ) {

   // Thanked Listing SQL
   $sql = "SELECT thanks_from_user_id, topic_id, post_id, poster_id
           FROM " . POSTS_TABLE . "
           WHERE thanks_count <> 0";

   if ( !($result = $db->sql_query($sql)) ) {
      message_die(GENERAL_ERROR, "Could not obtain posts information", '', __LINE__, __FILE__, $sql);
   }

   $thanks_listing = $db->sql_fetchrowset($result);
   $db->sql_freeresult($result);
   $thanks_listing_count = count($thanks_listing);

   $thanked_post = 0;

   for ($i = 0; $i < $thanks_listing_count; $i++) {

      $thanks_users = explode("|",$thanks_listing[$i]['thanks_from_user_id']);
      $thanks_count = count($thanks_users);

      // Loop through all users who thanked the post
      for ($x = 0; $x < $thanks_count; $x++) {

       if ($profiledata['user_id'] == $thanks_users[$x]) {
          $thanked_post = 1;

         // Users SQL
         $sql = "SELECT user_id, username
                 FROM " . USERS_TABLE . "
                 WHERE user_id = " . $thanks_listing[$i]['poster_id'];

         if ( !($result = $db->sql_query($sql)) ) {
            message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
         }

         $user_row = $db->sql_fetchrow($result);
         $db->sql_freeresult($result);

            // Add user to thanked by list
            $temp_url = "profile.$phpEx?mode=viewprofile&u=" . $user_row['user_id'];
            $thanks_compiled = '<a href="' . $temp_url . '">' . $user_row['username'] . '</a>';
       }
      }

      if ($thanked_post == 1) {

      // Topic SQL
      $sql = "SELECT topic_title
              FROM " . TOPICS_TABLE . "
              WHERE topic_id = '" . $thanks_listing[$i]['topic_id'] . "'";

      if ( !($result = $db->sql_query($sql)) ) {
         message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
      }

      $topic_row = $db->sql_fetchrow($result);
      $db->sql_freeresult($result);

      $temp_url_post = "viewtopic.$phpEx?p=" . $thanks_listing[$i]['post_id'] . "#" . $thanks_listing[$i]['post_id'];
      $temp_url_topic = "viewtopic.$phpEx?t=" . $thanks_listing[$i]['topic_id'];
      $thanked_post = '<a href="' . $temp_url_post . '"> (Post #' . $thanks_listing[$i]['post_id'] . ')</a>';
      $thanked_topic = '<a href="' . $temp_url_topic . '">' . $topic_row['topic_title'] . '</a>';
      $thanked_listing .= "Thanked $thanks_compiled in $thanked_topic - $thanked_post<br/>";

      $thanks_compiled = '';

      $thanked_post = 0;
      }

   }

   $template->assign_block_vars('thankedlist', array(
      'THANKED_LISTING' => $thanked_listing,
      'L_THANKED_LISTING' => 'Thanks Listing')
   );
}
cavallino wrote:Also I noticed that if for somewhat reason an admin/moderator deletes a post or topic in which a user gave or received a post thank, then the counters in the profile or viewtopic are not going back...
I'll post back in a few minutes with v0.2.6 which will deincrement thanks given and received by 1 in the function delete_post.
alexi02
Registered User
Posts: 271
Joined: Fri Mar 05, 2004 2:15 am
Location: Australia
Contact:

Re: [BETA] Thank Post by User 0.2.5a

Post by alexi02 »

2007-10-26 - Version 0.2.6
- Updates thanks_given and thanked_received when posts are deleted


Thank Post by User 0.2.6 (9.91KB)


To upgrade from v0.2.5a:

Open

Code: Select all

includes/functions_post.php
Find

Code: Select all

function delete_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_id, &$post_id, &$poll_id)
{
        global $board_config, $lang, $db, $phpbb_root_path, $phpEx;
        global $userdata, $user_ip;
After Add

Code: Select all

        //
        // Start Thank Post by User Mod
        //

        // Thanked Listing SQL
        $sql = "SELECT thanks_from_user_id, thanks_count, poster_id
                FROM " . POSTS_TABLE . "
                WHERE post_id = '$post_id'";

        if ( !($result = $db->sql_query($sql)) ) {
           message_die(GENERAL_ERROR, "Could not obtain posts information", '', __LINE__, __FILE__, $sql);
        }

        $post_thanks = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);

        // If this post was thanked, then continue
        if ($post_thanks['thanks_from_user_id']) {

           $thanked_users = explode("|", $post_thanks['thanks_from_user_id']);

           // Loop through all users who thanked the post
           for ($i = 0; $i < count($thanked_users); $i++) {

              $from_user = $thanked_users[$i];
              $to_user = $post_thanks['poster_id'];

              // Remove 1 from the user who thanked the post
              $sql = "SELECT user_thanks_given
                      FROM " . USERS_TABLE . "
                      WHERE user_id = " . $from_user;

              if ( !($result = $db->sql_query($sql)) ) {
                 message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
              }

              $from_user_row = $db->sql_fetchrow($result);
              $db->sql_freeresult($result);

              $thanks_given = $from_user_row['user_thanks_given'] - 1;

              // Update DB with the new thanks given
              $update_sql = "UPDATE " . USERS_TABLE . "
                             SET user_thanks_given = '" . $thanks_given . "'
                             WHERE user_id = " . $from_user;

              if ( !($result = $db->sql_query($update_sql)) ) {
                 message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $update_sql);
              }

              // Remove 1 from the user who was thanked
              $sql = "SELECT user_thanks_received
                      FROM " . USERS_TABLE . "
                      WHERE user_id = " . $to_user;

              if ( !($result = $db->sql_query($sql)) ) {
                 message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
              }

              $to_user_row = $db->sql_fetchrow($result);
              $db->sql_freeresult($result);

              $thanks_received = $to_user_row['user_thanks_received'] - 1;

              // Update DB with the new thanks given
              $update_sql = "UPDATE " . USERS_TABLE . "
                             SET user_thanks_received = '" . $thanks_received . "'
                             WHERE user_id = " . $to_user;

              if ( !($result = $db->sql_query($update_sql)) ) {
                 message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $update_sql);
              }
           }
        }

        //
        // End Thank Post by User Mod
        //
Last edited by alexi02 on Wed Oct 31, 2007 10:03 am, edited 2 times in total.
cavallino
Registered User
Posts: 317
Joined: Thu Aug 04, 2005 7:06 am

Re: [BETA] Thank Post by User 0.2.6

Post by cavallino »

Thanks again alexi for these updates...

Anyway I think that the given thanks listing conflicts somehow with the thanked listing because in the profile I get: Thanked Listing: ArrayThanked by......
So both lists are not showing up, just the thanked listing, with that "Array" word before... strange.
Maybe its this part:

Code: Select all

$temp_url = "profile.$phpEx?mode=viewprofile&u=" . $profiledata['user_id'] . "&thankslist=1";
$temp_url = "profile.$phpEx?mode=viewprofile&u=" . $profiledata['user_id'] . "&thankedlist=1";
$thanks_given = '<a href="' . $temp_url . '">' . $user_row['user_thanks_given'] . '</a>';
$thanks_received = '<a href="' . $temp_url . '">' . $user_row['user_thanks_received'] . ' ' . $lang['Thanks_thanked_2'] . ' ' . $thanked_post_count['thanks_count'] . ' ' . $lang['Thanks_thanked_3'] . '</a>';
Anyway... the issue about not displaying the listings with a click is still present for me... but maybe its just my template related... I dont know. Maybe if someone else can test it on a vanilla board, would be nice to know if it works or not.
alexi02
Registered User
Posts: 271
Joined: Fri Mar 05, 2004 2:15 am
Location: Australia
Contact:

Re: [BETA] Thank Post by User 0.2.6

Post by alexi02 »

Hm. Try using all of this instead. Hope it works.

Code: Select all

$temp_url = "profile.$phpEx?mode=viewprofile&u=" . $profiledata['user_id'] . "&thankedlist=1";
$thanks_given = '<a href="' . $temp_url . '">' . $user_row['user_thanks_given'] . '</a>';
$temp_url = "profile.$phpEx?mode=viewprofile&u=" . $profiledata['user_id'] . "&thankslist=1";
$thanks_received = '<a href="' . $temp_url . '">' . $user_row['user_thanks_received'] . ' ' . $lang['Thanks_thanked_2'] . ' ' . $thanked_post_count['thanks_count'] . ' ' . $lang['Thanks_thanked_3'] . '</a>';

}
else {
   $thanks_given = "";
   $thanks_received = "";
}

//
// End Thank Post by User Mod
//


// Thanked Listing
if ( isset($HTTP_GET_VARS['thankedlist']) || isset($HTTP_POST_VARS['thankedlist']) ) {

   // Thanked Listing SQL
   $sql = "SELECT thanks_from_user_id, topic_id, post_id, poster_id
           FROM " . POSTS_TABLE . "
           WHERE thanks_count <> 0";

   if ( !($result = $db->sql_query($sql)) ) {
      message_die(GENERAL_ERROR, "Could not obtain posts information", '', __LINE__, __FILE__, $sql);
   }

   $thanks_listing = $db->sql_fetchrowset($result);
   $db->sql_freeresult($result);
   $thanks_listing_count = count($thanks_listing);

   $thanked_post = 0;

   for ($i = 0; $i < $thanks_listing_count; $i++) {

      $thanks_users = explode("|",$thanks_listing[$i]['thanks_from_user_id']);
      $thanks_count = count($thanks_users);

      // Loop through all users who thanked the post
      for ($x = 0; $x < $thanks_count; $x++) {

       if ($profiledata['user_id'] == $thanks_users[$x]) {
          $thanked_post = 1;

         // Users SQL
         $sql = "SELECT user_id, username
                 FROM " . USERS_TABLE . "
                 WHERE user_id = " . $thanks_listing[$i]['poster_id'];

         if ( !($result = $db->sql_query($sql)) ) {
            message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
         }

         $user_row = $db->sql_fetchrow($result);
         $db->sql_freeresult($result);

            // Add user to thanked by list
            $temp_url = "profile.$phpEx?mode=viewprofile&u=" . $user_row['user_id'];
            $thanks_compiled = '<a href="' . $temp_url . '">' . $user_row['username'] . '</a>';
       }
      }

      if ($thanked_post == 1) {

      // Topic SQL
      $sql = "SELECT topic_title
              FROM " . TOPICS_TABLE . "
              WHERE topic_id = '" . $thanks_listing[$i]['topic_id'] . "'";

      if ( !($result = $db->sql_query($sql)) ) {
         message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
      }

      $topic_row = $db->sql_fetchrow($result);
      $db->sql_freeresult($result);

      $temp_url_post = "viewtopic.$phpEx?p=" . $thanks_listing[$i]['post_id'] . "#" . $thanks_listing[$i]['post_id'];
      $temp_url_topic = "viewtopic.$phpEx?t=" . $thanks_listing[$i]['topic_id'];
      $thanked_post = '<a href="' . $temp_url_post . '"> (Post #' . $thanks_listing[$i]['post_id'] . ')</a>';
      $thanked_topic = '<a href="' . $temp_url_topic . '">' . $topic_row['topic_title'] . '</a>';
      $thanked_listing .= "Thanked $thanks_compiled in $thanked_topic - $thanked_post<br/>";

      $thanks_compiled = '';

      $thanked_post = 0;
      }

   }

   $template->assign_block_vars('thankedlist', array(
      'THANKED_LISTING' => $thanked_listing,
      'L_THANKED_LISTING' => 'Thanks Listing')
   );
}


// Thanks Listing
if ( isset($HTTP_GET_VARS['thankslist']) || isset($HTTP_POST_VARS['thankslist']) ) {

   // Thanked Listing SQL
   $sql = "SELECT thanks_from_user_id, thanks_count, topic_id, post_id
           FROM " . POSTS_TABLE . "
           WHERE poster_id = " . $profiledata['user_id'] . " AND thanks_count <> 0";

   if ( !($result = $db->sql_query($sql)) ) {
   message_die(GENERAL_ERROR, "Could not obtain posts information", '', __LINE__, __FILE__, $sql);
   }

   $thanked_listing = $db->sql_fetchrowset($result);
   $db->sql_freeresult($result);
   $thanked_listing_count = count($thanked_listing);

   for ($i = 0; $i < $thanked_listing_count; $i++) {

      $thanked_users = explode("|",$thanked_listing[$i]['thanks_from_user_id']);
      $thanked_count = $thanked_listing[$i]['thanks_count'];

      // Loop through all users who thanked the post
      for ($x = 0; $x < $thanked_count; $x++) {

         // Users SQL
         $sql = "SELECT user_id, username
                 FROM " . USERS_TABLE . "
                 WHERE user_id = " . $thanked_users[$x];

         if ( !($result = $db->sql_query($sql)) ) {
            message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
         }

         $user_row = $db->sql_fetchrow($result);
         $db->sql_freeresult($result);

         if ($x >= 1) { $thanks_compiled .= ", "; }

            // Add user to thanked by list
            $temp_url = "profile.$phpEx?mode=viewprofile&u=" . $user_row['user_id'];
            $thanks_compiled .= '<a href="' . $temp_url . '">' . $user_row['username'] . '</a>';
      }

      // Topic SQL
      $sql = "SELECT topic_title
              FROM " . TOPICS_TABLE . "
              WHERE topic_id = " . $thanked_listing[$i]['topic_id'];

      if ( !($result = $db->sql_query($sql)) ) {
         message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
      }

      $topic_row = $db->sql_fetchrow($result);
      $db->sql_freeresult($result);


      $temp_url_post = "viewtopic.$phpEx?p=" . $thanked_listing[$i]['post_id'] . "#" . $thanked_listing[$i]['post_id'];
      $temp_url_topic = "viewtopic.$phpEx?t=" . $thanked_listing[$i]['topic_id'];
      $thanks_post = '<a href="' . $temp_url_post . '"> (Post #' . $thanked_listing[$i]['post_id'] . ')</a>';
      $thanks_topic = '<a href="' . $temp_url_topic . '">' . $topic_row['topic_title'] . '</a>';
      $thanks_listing .= "Thanked by $thanks_compiled in $thanks_topic - $thanks_post<br/>";

      $thanks_compiled = '';
   }

   $template->assign_block_vars('thankslist', array(
      'THANKS_LISTING' => $thanks_listing,
      'L_THANKS_LISTING' => $lang['Thanks_listing'])
   );
}
And for the TPL:

Code: Select all

                <!-- BEGIN thankedlist -->
                <tr>
                  <td valign="top" align="right" nowrap="nowrap"><span class="gen">{thankedlist.L_THANKED_LISTING}:</span></td>
                  <td> <span class="gen">{thankedlist.THANKED_LISTING}</span></td>
                </tr>
                <!-- END thankedlist -->
                <!-- BEGIN thankslist -->
                <tr>
                  <td valign="top" align="right" nowrap="nowrap"><span class="gen">{thankslist.L_THANKS_LISTING}:</span></td>
                  <td> <span class="gen">{thankslist.THANKS_LISTING}</span></td>
                </tr>
                <!-- END thankslist -->
cavallino
Registered User
Posts: 317
Joined: Thu Aug 04, 2005 7:06 am

Re: [BETA] Thank Post by User 0.2.6

Post by cavallino »

Hi alexi,
listings are working fine in profile (still not the function open/close, but don't worry anymore about it) but anyway there's still a little issue: only in the Thanked Listing, for the first entry only i still get that "Array" word, like this:

Code: Select all

Thanked Listing:  ArrayThanked by ............ in ..... - post...
                  Thanked by ............ in ..... - post....
                  Thanked by ............ in ..... - post...
As you can see, only for the first line and only in the Thanked listing.
fmahash
Registered User
Posts: 39
Joined: Thu Nov 23, 2006 1:58 pm

Re: [BETA] Thank Post by User 0.2.6

Post by fmahash »

Hiya I installed this great mod but I get this error when I try to delete a post

Code: Select all

Could not obtain user information

DEBUG MODE

SQL Error : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

SELECT user_thanks_given FROM phpbb_users WHERE user_id =

Line : 491
File : functions_post.php
can anyone help?
alexi02
Registered User
Posts: 271
Joined: Fri Mar 05, 2004 2:15 am
Location: Australia
Contact:

Re: [BETA] Thank Post by User 0.2.6

Post by alexi02 »

Is the post being deleted or the entire topic?

Add this code:

Code: Select all

echo "SQL = " . $sql . "<br/> Post Thanks = " . $post_thanks['thanks_from_user_id'] . "<br/> Thanked Users = " . $thanked_users . "<br/> Thanked Users Element1 = " . $thanked_users[1]; 
Before

Code: Select all

// Remove 1 from the user who thanked the post
           $sql = "SELECT user_thanks_given
                   FROM " 
to troubleshoot and post back the results.
fmahash
Registered User
Posts: 39
Joined: Thu Nov 23, 2006 1:58 pm

Re: [BETA] Thank Post by User 0.2.6

Post by fmahash »

should I add it in functions_post.php? and thanks for helping
fmahash
Registered User
Posts: 39
Joined: Thu Nov 23, 2006 1:58 pm

Re: [BETA] Thank Post by User 0.2.6

Post by fmahash »

ok this is the code that appeared at the top of the page

Code: Select all

SQL = SELECT thanks_from_user_id, thanks_count, poster_id FROM phpbb_posts WHERE post_id = '408'
Post Thanks =
Thanked Users = Array
Thanked Users Element1 =
Warning: Cannot modify header information - headers already sent by (output started at /home/hash86/public_html/includes/functions_post.php:486) in /home/hash86/public_html/includes/page_header.php on line 662

Warning: Cannot modify header information - headers already sent by (output started at /home/hash86/public_html/includes/functions_post.php:486) in /home/hash86/public_html/includes/page_header.php on line 664

Warning: Cannot modify header information - headers already sent by (output started at /home/hash86/public_html/includes/functions_post.php:486) in /home/hash86/public_html/includes/page_header.php on line 665
and this in general error

Code: Select all

Could not obtain user information

DEBUG MODE

SQL Error : 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 3

SELECT user_thanks_given FROM phpbb_users WHERE user_id =

Line : 493
File : functions_post.php
alexi02
Registered User
Posts: 271
Joined: Fri Mar 05, 2004 2:15 am
Location: Australia
Contact:

Re: [BETA] Thank Post by User 0.2.6

Post by alexi02 »

Ah! I forgot to set up the condition that would only go ahead with removing the thanks if the post was even thanked at all. Thanks for reporting the error.

Replace the code in the includes\functions_post.php with:

Code: Select all

        //
        // Start Thank Post by User Mod
        //

        // Thanked Listing SQL
        $sql = "SELECT thanks_from_user_id, thanks_count, poster_id
                FROM " . POSTS_TABLE . "
                WHERE post_id = '$post_id'";

        if ( !($result = $db->sql_query($sql)) ) {
           message_die(GENERAL_ERROR, "Could not obtain posts information", '', __LINE__, __FILE__, $sql);
        }

        $post_thanks = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);

        // If this post was thanked, then continue
        if ($post_thanks['thanks_from_user_id']) {

           $thanked_users = explode("|", $post_thanks['thanks_from_user_id']);

           // Loop through all users who thanked the post
           for ($i = 0; $i < count($thanked_users); $i++) {

              $from_user = $thanked_users[$i];
              $to_user = $post_thanks['poster_id'];

              // Remove 1 from the user who thanked the post
              $sql = "SELECT user_thanks_given
                      FROM " . USERS_TABLE . "
                      WHERE user_id = " . $from_user;

              if ( !($result = $db->sql_query($sql)) ) {
                 message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
              }

              $from_user_row = $db->sql_fetchrow($result);
              $db->sql_freeresult($result);

              $thanks_given = $from_user_row['user_thanks_given'] - 1;

              // Update DB with the new thanks given
              $update_sql = "UPDATE " . USERS_TABLE . "
                             SET user_thanks_given = '" . $thanks_given . "'
                             WHERE user_id = " . $from_user;

              if ( !($result = $db->sql_query($update_sql)) ) {
                 message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $update_sql);
              }

              // Remove 1 from the user who was thanked
              $sql = "SELECT user_thanks_received
                      FROM " . USERS_TABLE . "
                      WHERE user_id = " . $to_user;

              if ( !($result = $db->sql_query($sql)) ) {
                 message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
              }

              $to_user_row = $db->sql_fetchrow($result);
              $db->sql_freeresult($result);

              $thanks_received = $to_user_row['user_thanks_received'] - 1;

              // Update DB with the new thanks given
              $update_sql = "UPDATE " . USERS_TABLE . "
                             SET user_thanks_received = '" . $thanks_received . "'
                             WHERE user_id = " . $to_user;

              if ( !($result = $db->sql_query($update_sql)) ) {
                 message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $update_sql);
              }
           }
        }

        //
        // End Thank Post by User Mod
        //
fmahash
Registered User
Posts: 39
Joined: Thu Nov 23, 2006 1:58 pm

Re: [BETA] Thank Post by User 0.2.6

Post by fmahash »

So should I replace

Code: Select all

        //
        // Start Thank Post by User Mod
        //

        // Thanked Listing SQL
        $sql = "SELECT thanks_from_user_id, thanks_count, poster_id
                FROM " . POSTS_TABLE . "
                WHERE post_id = '$post_id'";

        if ( !($result = $db->sql_query($sql)) ) {
           message_die(GENERAL_ERROR, "Could not obtain posts information", '', __LINE__, __FILE__, $sql);
        }

        $post_thanks = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);

        $thanked_users = explode("|", $post_thanks['thanks_from_user_id']);

        // Loop through all users who thanked the post
        for ($i = 0; $i < count($thanked_users); $i++) {

           $from_user = $thanked_users[$i];
           $to_user = $post_thanks['poster_id'];

           // Remove 1 from the user who thanked the post
           $sql = "SELECT user_thanks_given
                   FROM " . USERS_TABLE . "
                   WHERE user_id = " . $from_user;

           if ( !($result = $db->sql_query($sql)) ) {
              message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
           }

           $from_user_row = $db->sql_fetchrow($result);
           $db->sql_freeresult($result);

           $thanks_given = $from_user_row['user_thanks_given'] - 1;

           // Update DB with the new thanks given
           $update_sql = "UPDATE " . USERS_TABLE . "
                          SET user_thanks_given = '" . $thanks_given . "'
                          WHERE user_id = " . $from_user;

           if ( !($result = $db->sql_query($update_sql)) ) {
              message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $update_sql);
           }

           // Remove 1 from the user who was thanked
           $sql = "SELECT user_thanks_received
                   FROM " . USERS_TABLE . "
                   WHERE user_id = " . $to_user;

           if ( !($result = $db->sql_query($sql)) ) {
              message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
           }

           $to_user_row = $db->sql_fetchrow($result);
           $db->sql_freeresult($result);

           $thanks_received = $to_user_row['user_thanks_received'] - 1;

           // Update DB with the new thanks given
           $update_sql = "UPDATE " . USERS_TABLE . "
                          SET user_thanks_received = '" . $thanks_received . "'
                          WHERE user_id = " . $to_user;

           if ( !($result = $db->sql_query($update_sql)) ) {
              message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $update_sql);
           }
        }

        //
        // End Thank Post by User Mod
        //
with this

Code: Select all

        //
        // Start Thank Post by User Mod
        //

        // Thanked Listing SQL
        $sql = "SELECT thanks_from_user_id, thanks_count, poster_id
                FROM " . POSTS_TABLE . "
                WHERE post_id = '$post_id'";

        if ( !($result = $db->sql_query($sql)) ) {
           message_die(GENERAL_ERROR, "Could not obtain posts information", '', __LINE__, __FILE__, $sql);
        }

        $post_thanks = $db->sql_fetchrow($result);
        $db->sql_freeresult($result);

        // If this post was thanked, then continue
        if ($post_thanks['thanks_from_user_id']) {

           $thanked_users = explode("|", $post_thanks['thanks_from_user_id']);

           // Loop through all users who thanked the post
           for ($i = 0; $i < count($thanked_users); $i++) {

              $from_user = $thanked_users[$i];
              $to_user = $post_thanks['poster_id'];

              // Remove 1 from the user who thanked the post
              $sql = "SELECT user_thanks_given
                      FROM " . USERS_TABLE . "
                      WHERE user_id = " . $from_user;

              if ( !($result = $db->sql_query($sql)) ) {
                 message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
              }

              $from_user_row = $db->sql_fetchrow($result);
              $db->sql_freeresult($result);

              $thanks_given = $from_user_row['user_thanks_given'] - 1;

              // Update DB with the new thanks given
              $update_sql = "UPDATE " . USERS_TABLE . "
                             SET user_thanks_given = '" . $thanks_given . "'
                             WHERE user_id = " . $from_user;

              if ( !($result = $db->sql_query($update_sql)) ) {
                 message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $update_sql);
              }

              // Remove 1 from the user who was thanked
              $sql = "SELECT user_thanks_received
                      FROM " . USERS_TABLE . "
                      WHERE user_id = " . $to_user;

              if ( !($result = $db->sql_query($sql)) ) {
                 message_die(GENERAL_ERROR, "Could not obtain user information", '', __LINE__, __FILE__, $sql);
              }

              $to_user_row = $db->sql_fetchrow($result);
              $db->sql_freeresult($result);

              $thanks_received = $to_user_row['user_thanks_received'] - 1;

              // Update DB with the new thanks given
              $update_sql = "UPDATE " . USERS_TABLE . "
                             SET user_thanks_received = '" . $thanks_received . "'
                             WHERE user_id = " . $to_user;

              if ( !($result = $db->sql_query($update_sql)) ) {
                 message_die(GENERAL_ERROR, 'Could not update users table', '', __LINE__, __FILE__, $update_sql);
              }
           }
        }

        //
        // End Thank Post by User Mod
        //
fmahash
Registered User
Posts: 39
Joined: Thu Nov 23, 2006 1:58 pm

Re: [BETA] Thank Post by User 0.2.6

Post by fmahash »

thanks It worked ^.^ :D
djvini
Registered User
Posts: 91
Joined: Sun Sep 04, 2005 1:55 pm
Location: Sheffield, UK
Contact:

Re: [BETA] Thank Post by User 0.2.6

Post by djvini »

Is there a way to make it so that the 'thanks' button is only visible on the first post in each thread, is this possible do you know?
alexi02
Registered User
Posts: 271
Joined: Fri Mar 05, 2004 2:15 am
Location: Australia
Contact:

Re: [BETA] Thank Post by User 0.2.6

Post by alexi02 »

Yes there is a way. Most simplest way is:

In viewtopic.php

Find

Code: Select all

if ( ($userdata['session_logged_in']) && ($userdata['user_id'] != $poster_id) ) {
Replace with

Code: Select all

if ($i == 0 && ($userdata['session_logged_in']) && ($userdata['user_id'] != $poster_id) ) {
Post Reply

Return to “[2.0.x] MODs in Development”