My own solution for the problem of huge amount of queries( it was wrtitten at 5 AM, so dont be very cruel )
This will MOST LIKELY not work for you if you're going to use patch util
make all changes by hand
--- dev/viewtopic.php (revision 177)
+++ dev/viewtopic.php (revision 178)
@@ -211,8 +211,25 @@
$post_count = 0; // Keep track of post numbers
// Retrieve the posts (and their respective poster/online status)
+$att_res = $db->query('select af.* from '.$db->prefix.'attach_2_files as af left join '.$db->prefix.'posts as p on af.post_id=p.id where p.topic_id='.$id);
+$att_arr = array();
+$attach_allow_download = false;
+
+while ($att_arr[] = $db->fetch_assoc($att_res)) {}
+if($pun_user['g_id']==PUN_ADMIN) $attach_allow_download = true;
+ else{ //fetch the rules of the forum, and check so that the user is allowed to download.
+ $result_attach_two = $db->query('SELECT ar.rules FROM '.$db->prefix.'attach_2_rules AS ar WHERE ar.group_id=\''.$pun_user['group_id'].'\' AND ar.forum_id='.$cur_topic['forum_id'].' LIMIT 1')or error('Unable to fetch rules for the attachments', __FILE__, __LINE__, $db->error());
+ if($db->num_rows($result_attach_two)==1){
+ list($attach_rules)=$db->fetch_row($result_attach_two);
+ $attach_allow_download = attach_rules($attach_rules,ATTACH_DOWNLOAD);
+ }
+ }
+
+
+
while ($cur_post = $db->fetch_assoc($result))
{
$post_count++;
@@ -353,30 +370,23 @@
}
}
// Attachment Mod Block Start
- $attach_allow_download = false;
$attach_output = '';
$attach_num = 0;
+
// Check if this post has any attachments
- $result_attach = $db->query('SELECT af.id, af.filename, af.size, af.downloads FROM '.$db->prefix.'attach_2_files AS af WHERE af.post_id='.$cur_post['id']) or error('Unable to fetch if there were any attachments to the post', __FILE__, __LINE__, $db->error());
- $attach_num = $db->num_rows($result_attach);
- if($attach_num > 0){
- if($pun_user['g_id']==PUN_ADMIN)$attach_allow_download=true;
- else{ //fetch the rules of the forum, and check so that the user is allowed to download.
- $result_attach_two = $db->query('SELECT ar.rules FROM '.$db->prefix.'attach_2_rules AS ar WHERE ar.group_id=\''.$pun_user['group_id'].'\' AND ar.forum_id='.$cur_topic['forum_id'].' LIMIT 1')or error('Unable to fetch rules for the attachments', __FILE__, __LINE__, $db->error());
- if($db->num_rows($result_attach_two)==1){
- list($attach_rules)=$db->fetch_row($result_attach_two);
- $attach_allow_download = attach_rules($attach_rules,ATTACH_DOWNLOAD);
- }
- }
+// $result_attach = $db->query('SELECT af.id, af.filename, af.size, af.downloads FROM '.$db->prefix.'attach_2_files AS af WHERE af.post_id='.$cur_post['id']) or error('Unable to fetch if there were any attachments to the post', __FILE__, __LINE__, $db->error());
+// $attach_num = $db->num_rows($result_attach);
+for ($i=0; $i < sizeof($att_arr)-1;$i++){
+
+ if($att_arr[$i]['post_id'] == $cur_post['id']){
+ $attach_num++;
if($attach_allow_download){//check if the user is allowed to download it.
$attach_output .= $lang_attach['Attachments:'].' ';
- while(list($attachment_id, $attachment_filename, $attachment_size, $attachment_downloads)=$db->fetch_row($result_attach)){
- $attachment_extension=attach_get_extension($attachment_filename);
- $attach_output .= '<br />'."\n\t\t\t\t\t\t".attach_icon($attachment_extension).' <a href="./attachment.php?item='.$attachment_id.'">'.$attachment_filename.'</a>, '.$lang_attach['Size:'].' '.number_format($attachment_size).' '.$lang_attach['bytes'].', '.$lang_attach['Downloads:'].' '.number_format($attachment_downloads);
- }
+ $attachment_extension = attach_get_extension($att_arr[$i]['filename']);
+ $attach_output .= '<br />'."\n\t\t\t\t\t\t".attach_icon($att_arr[$i]['extension']).' <a href="./attachment.php?item='.$att_arr[$i]['id'].'">'.$att_arr[$i]['filename'].'</a>, '.$lang_attach['Size:'].' '.number_format($att_arr[$i]['size']).' '.$lang_attach['bytes'].', '.$lang_attach['Downloads:'].' '.number_format($att_arr[$i]['downloads']);
}
}
- // Attachment Mod Block End
+} // Attachment Mod Block End
?>
<div id="p<?php echo $cur_post['id'] ?>" class="blockpost<?php echo $vtbg ?><?php if (($post_count + $start_from) == 1) echo ' firstpost'; ?>">
@@ -396,7 +406,7 @@
<div class="postmsg">
<?php echo $cur_post['message']."\n" ?>
<?php if ($cur_post['edited'] != '') echo "\t\t\t\t\t".'<p class="postedit"><em>'.$lang_topic['Last edit'].' '.pun_htmlspecialchars($cur_post['edited_by']).' ('.format_time($cur_post['edited']).')</em></p>'."\n"; ?>
-<?php if ($attach_allow_download) echo "\t\t\t\t\t".'<div class="postsignature"><hr />'.$attach_output.'</div>'."\n"; ## Attachment Mod row ?>
+<?php if ($attach_allow_download && $attach_output != '') echo "\t\t\t\t\t".'<div class="postsignature"><hr />'.$attach_output.'</div>'."\n"; ## Attachment Mod row ?>
<?php if ($signature != '') echo "\t\t\t\t".'<div class="postsignature"><hr />'.$signature.'</div>'."\n"; ?>
</div>
</div>