You are not logged in.
- Topics: Active | Unanswered
Pages: 1
#1 2010-07-21 21:57:33
- blissend
- FluxBB Donor
- From: NY, USA
- Registered: 2009-07-02
- Posts: 30
- Website
thanks for post mod fix
The mod found at http://fluxbb.org/resources/mods/thanks-for-post/ doesn't work for me. On mine it won't show post replies for topics anymore. Since I know a little about php I attempted to diagnose and fix it.
It seems when I comment out the query it makes in viewtopic.php it will suddenly show replies but of course not the thanks submitted. I'm guessing its related to the query being made inside the loop of another query? Is this some sort of php limitation or fluxbb limitation? Does anyone else that use this mod have the same issue?
Anyway if anyone wants I can provide my fix.
I have no idea what I'm doing.
Contributions: [MOD] Spam IP Check, [PLUGIN] News Generator, [1.4 Style] Gray Orange, thanks for post mod fix
Offline
#2 2010-08-03 13:33:27
- Porcepic
- Member
- From: France
- Registered: 2010-08-03
- Posts: 13
- Website
Re: thanks for post mod fix
Hey,
I've tried to install this mod too, first on a new forum and it worked perfectly, but then I tried again with another one, using a rather big database from 1.2.* that I've upgraded for a test, and now I've got the same issue...
I do not have any explanation for this (except that I've also noticed that it might come from the query), but I would be very pleased to know what your fix is.
Thanks a lot.
Offline
#3 2010-08-04 14:05:25
- Porcepic
- Member
- From: France
- Registered: 2010-08-03
- Posts: 13
- Website
Re: thanks for post mod fix
OK, I've finally managed to find a solution.
I think that the problem definitely comes from the second $db->fetch_assoc, in the while { ... }, which seems to "erase" the content of $cur_post and then stop displaying the posts.
The idea is thus to insert the retrieving of the name of the users who thanked the post in the first query (which looks by the way nicer). I use GROUP_CONCAT (with a LEFT JOIN on thanks.post_id = p.id) to retrieve all the thanks_by, separated by any separator (', ' can make it really easy to display).
If you want to add nice links to the profile of the users, you can make another GROUP_CONCAT in order to retrieve the thanks_by_id, and then using explode() to make proper links, for instance like that :
$users_thanks = explode(',', $cur_post['thanks_by']);
if($pun_user['g_view_users'] == '1') {
$users_thanks_id = explode(',', $cur_post['thanks_by_id']);
for($i=0;$i<count($users_thanks);$i++) {
$userThanksName = $users_thanks[$i];
$users_thanks[$i] = '<a href="profile.php?id='.$users_thanks_id[$i].'">'.pun_htmlspecialchars($userThanksName).'</a>';
}
}
You can even make another one to retrieve the color of the group of the user...
I can't guarantee it is a clean solution (although I think it's at least cleaner that the initial solution), but it seems to work fine.
Offline
#4 2010-08-04 14:15:32
- Reines
- Administrator
- From: Scotland
- Registered: 2008-05-11
- Posts: 3,197
- Website
Re: thanks for post mod fix
I think that the problem definitely comes from the second $db->fetch_assoc, in the while { ... }, which seems to "erase" the content of $cur_post and then stop displaying the posts.
Sounds simply like you're overwriting the $result variable. Name the one inside the while { ... } something else.
Offline
#5 2010-08-04 14:21:41
- Porcepic
- Member
- From: France
- Registered: 2010-08-03
- Posts: 13
- Website
Re: thanks for post mod fix
No, they were already named differently, as the one inside the while { ... } was named $result_thanks.
(For a few seconds, I've nearly made a heart attack. "No, OMG, don't tell me I didn't even notice that..." )
Offline
#6 2010-08-04 14:33:25
- Smartys
- Former Developer
- Registered: 2008-04-27
- Posts: 3,139
- Website
Re: thanks for post mod fix
I think that the problem definitely comes from the second $db->fetch_assoc, in the while { ... }, which seems to "erase" the content of $cur_post and then stop displaying the posts.
It's an unbuffered query. Your way is one valid solution, although not necessarily the most efficient.
Offline
#7 2010-08-04 15:42:25
- Franz
- Lead developer
- From: Germany
- Registered: 2008-05-13
- Posts: 6,744
- Website
Offline
#8 2010-08-17 15:01:36
- blissend
- FluxBB Donor
- From: NY, USA
- Registered: 2009-07-02
- Posts: 30
- Website
Re: thanks for post mod fix
I just ran the mod authors query outside the original one to avoid the problem. Of course other changes had to be made to allow this so I'm not sure how efficient it is. Anyway I edited his viewtopic.php instructions to this...
#
#---------[ 1. OPEN ]---------------------------------------------------------
#
viewtopic.php
#
#---------[ 2. FIND ]---------------------------------------------
#
require PUN_ROOT.'lang/'.$pun_user['language'].'/topic.php';
#
#---------[ 3. AFTER, ADD ]---------------------------------------------------
#
if (file_exists(PUN_ROOT.'lang/'.$pun_user['language'].'/thanks.php'))
require PUN_ROOT.'lang/'.$pun_user['language'].'/thanks.php';
else
require PUN_ROOT.'lang/English/thanks.php';
#
#---------[ 4. FIND ]---------------------------------------------
#
for ($i = 0;$cur_post_id = $db->result($result, $i);$i++)
$post_ids[] = $cur_post_id;
#
#---------[ 5. AFTER, ADD ]---------------------------------------------------
#
$users_thanks = array(array());
foreach($post_ids as $pids) {
$result_thanks = $db->query('SELECT thanks_by, thanks_by_id FROM '.$db->prefix.'thanks WHERE post_id='.$pids) or error('Unable to fetch thanks info', __FILE__, __LINE__, $db->error());
while ($thanks = $db->fetch_assoc($result_thanks))
{
if ($pun_user['g_view_users'] == '1' && $thanks['thanks_by_id'] > 1)
$users_thanks[$pids][] = '<a href="profile.php?id='.$thanks['thanks_by_id'].'">'.pun_htmlspecialchars($thanks['thanks_by']).'</a>';
else
$users_thanks[$pids][] = pun_htmlspecialchars($thanks['thanks_by']);
}
}
#
#---------[ 6. FIND ]---------------------------------------------
#
$post_count++;
$user_avatar = '';
$user_info = array();
$user_contacts = array();
$post_actions = array();
$is_online = '';
$signature = '';
#
#---------[ 7. AFTER, ADD ]---------------------------------------------------
#
$num_thanks = count($users_thanks[$cur_post['id']]);
#
#---------[ 8. FIND ]---------------------------------------------
#
if (($cur_topic['post_replies'] == '' && $pun_user['g_post_replies'] == '1') || $cur_topic['post_replies'] == '1')
$post_actions[] = '<li class="postquote"><span><a href="post.php?tid='.$id.'&qid='.$cur_post['id'].'">'.$lang_topic['Quote'].'</a></span></li>';
#
#---------[ 9. AFTER, ADD ]---------------------------------------------------
#
if (($cur_topic['post_replies'] == '' && $pun_user['g_can_thanks'] == '1'))
$post_actions[] = '<li class="postthanks"><span><a href="thanks.php?tid='.$id.'&pid='.$cur_post['id'].'">'.$lang_thanks['Say Thanks'].'</a></span></li>';
#
#---------[ 10. FIND ]---------------------------------------------
#
$post_actions[] = '<li class="postedit"><span><a href="edit.php?id='.$cur_post['id'].'">'.$lang_topic['Edit'].'</a></span></li>';
$post_actions[] = '<li class="postquote"><span><a href="post.php?tid='.$id.'&qid='.$cur_post['id'].'">'.$lang_topic['Quote'].'</a></span></li>';
#
#---------[ 11. AFTER, ADD ]---------------------------------------------------
#
$post_actions[] = '<li class="postthanks"><span><a href="thanks.php?tid='.$id.'&pid='.$cur_post['id'].'">'.$lang_thanks['Say Thanks'].'</a></span></li>';
#
#---------[ 12. FIND ]---------------------------------------------
#
<div class="postfoot clearb">
<div class="postfootleft"><?php if ($cur_post['poster_id'] > 1) echo '<p>'.$is_online.'</p>'; ?></div>
<?php if (count($post_actions)) echo "\t\t\t\t".'<div class="postfootright">'."\n\t\t\t\t\t".'<ul>'."\n\t\t\t\t\t\t".implode("\n\t\t\t\t\t\t", $post_actions)."\n\t\t\t\t\t".'</ul>'."\n\t\t\t\t".'</div>'."\n" ?>
</div>
</div>
</div>
</div>
#
#---------[ 13. AFTER, ADD ]---------------------------------------------------
#
<?php if ($num_thanks != '0')
{
?>
<div class="thanks">
<?php
if ($num_thanks == '1')
echo $lang_thanks['Thanks one'].implode(', ', $users_thanks[$cur_post['id']]);
else
echo sprintf($lang_thanks['Thanks'], $num_thanks).implode(', ', $users_thanks[$cur_post['id']]);
?>
</div>
<?php
}
?>
Last edited by blissend (2010-08-17 15:03:10)
I have no idea what I'm doing.
Contributions: [MOD] Spam IP Check, [PLUGIN] News Generator, [1.4 Style] Gray Orange, thanks for post mod fix
Offline
#9 2010-08-26 10:54:54
- Jessica
- Member
- Registered: 2010-06-14
- Posts: 22
Re: thanks for post mod fix
Many thanks to you all seems right... now
Offline
Pages: 1