PDA

View Full Version : Detailed Latest Discussions in What's Going On


Albus
05-15-2004, 10:00 PM
Below is my first attempt at creating a hack. It works perfectly on my board but as no others have tested it, I am putting it here for now. I know there are other latest x posts type hacks around, however, in my day long search of this forum, I have yet to find one that suited my needs. Therefore, I wrote my own. I offer it here. It only uses one query to return information on the last x posts including the fields (forum id, forum title, thread id, thread title, initial poster id, initial poster name, last poster id, last poster name, reply count and views). It takes into account permissions using the CANVIEW and CANVIEWOTHERS constants and properly flags the show variable if no rows are deemed showable. Have fun and please do not hesitate to comment on this. This code is entirely of my own writing although it was visually inspired by the hack in place on http://cosforums.com. Thanks.

:)

007
05-16-2004, 03:54 AM
Interesting. Can you post a screenshot of it in action?

Albus
05-16-2004, 04:06 AM
I can, but here's the test forum it's on. Live. http://wizardingrealm.com/index.php The actual domain has a blank index.html in it. Pretty much. Would you still like a screenshot?

M1th
05-16-2004, 12:56 PM
Below is my first attempt at creating a hack. It works perfectly on my board but as no others have tested it, I am putting it here for now. I know there are other latest x posts type hacks around, however, in my day long search of this forum, I have yet to find one that suited my needs. Therefore, I wrote my own. I offer it here. It only uses one query to return information on the last x posts including the fields (forum id, forum title, thread id, thread title, initial poster id, initial poster name, last poster id, last poster name, reply count and views). It takes into account permissions using the CANVIEW and CANVIEWOTHERS constants and properly flags the show variable if no rows are deemed showable. Have fun and please do not hesitate to comment on this. This code is entirely of my own writing although it was visually inspired by the hack in place on http://cosforums.com. Thanks.

:)
Funny, it looks to me as if your whole site was 'visually' inspired by CoSForums.com.

Albus
05-16-2004, 12:57 PM
It was. Does the flattery offend? Mind you , it isn't directly usable, nor has any members, and I'm not advertising it yet. This is my first vB board and I need a good test for skinning to get to know it. I have no clue whether I'll make it live as is, or do something else.

M1th
05-16-2004, 01:13 PM
You have no permission to rip the CoSForums style, which by your own admission you said you did. I ask you to please take it down otherwise I'll have to take further action.

Albus
05-16-2004, 01:18 PM
Considering it was only a skinning test, I have no problems with that. However, I fail to see what I did wrong. There's only so much you can do, and it is all my own work. Nevertheless, it will not go live with that skin. Please see my email.

M1th
05-16-2004, 01:44 PM
Well, that's settled now, I think. Thanks, Serenarules! :)

Albus
05-16-2004, 01:50 PM
Yes, it has been. :) And thanks Wiz. I'll be resetting my board shortly to begin working on the set of skins I actually have in mind for it. At that point, the demo of this hack will go offline until I finish redoing the forumhome templates again. In the meantime, I'd like to know who has used the hack and what they think of it, before this gets too far off topic?

Boofo
05-17-2004, 10:19 AM
Does this hack take into account the permissions a user has as to what threads are shown?

Grendel
05-17-2004, 01:35 PM
... It takes into account permissions using the CANVIEW and CANVIEWOTHERS constants...
You mean like that?

Albus
05-17-2004, 03:36 PM
Thanks Grendel, yes, it does.

Boofo
05-17-2004, 08:01 PM
Maybe the wording threw me off. Sorry I missed that. ;)

Erwin
05-18-2004, 11:43 PM
I had something very similar on my site using 1 query too. I do like the way you implemented yours - especially with the dateline limit. I took mine off as it was causing server loads to go out of the roof. I may try yours out, and see if I can optimize it further.

Holidazed
05-20-2004, 08:16 PM
Awesome job. Thank you

~installs

Albus
05-21-2004, 06:27 PM
Thanks everybody. The site is now up and you can reach it without index.php on the url. I started a feedback thread for it in "Forum Commenting" as well.

http://wizardingrealm.com (To see the hack, or just to visit.)

Holidazed
05-21-2004, 07:38 PM
Serenarules, truly a most awesome design on your site.

Albus
05-21-2004, 07:43 PM
Thanks. See my last post in the "Forum Comments" forum for a note about my current network speed...

Albus
05-22-2004, 11:30 PM
UPDATE: Please adjust all urls in the script I provided to use & instead of just an &. This complies with XHTML validations. I apologize for the error.

subu1
05-23-2004, 06:20 AM
..can User see private Forum Threads?

greetz subu1

Albus
05-23-2004, 06:41 AM
You know what. I answered this earlier, but something in the back of my mind just told me to look at the code again. I made a stupid boo-boo. There's a } in the wrong place, so no, the current hack will not work correctly. However, if you download it, and make the following change to the while loop, it should. Don't forget to make the & changes I listed above either. I'll post an updated version tomorrow.

while($post = $DB_site->fetch_array($posts))
{

$perms = fetch_permissions($post['forumid']);

// if no rows set this then the section will be skipped on display
if($perms & CANVIEW || $perms & CANVIEWOTHERS){

$latestpostcount++;

$post['threadtitle'] = fetch_censored_text(fetch_trimmed_title(unhtmlspec ialchars($post['threadtitle']), 22));
$post['forumtitle'] = fetch_censored_text(fetch_trimmed_title(unhtmlspec ialchars($post['forumtitle']), 22));
$post['replycount'] = vb_number_format($post['replycount']);
$post['views'] = vb_number_format($post['views']);

// keep this in case you want to use alternating colors
exec_switch_bg();

eval("\$latestpostbits .= \"".fetch_template('forumhome_latestpostbits')."\";");

}

}

Good call mate.

subu1
05-23-2004, 06:44 AM
ok nochmal in Deutsch, mein englisch ist so schlecht, werden private Foren aufgelistet, Beispiele Thread Titel aus dem Moderatoren Forum oder ?hnliche;)

Albus
05-23-2004, 02:42 PM
Here's the updated version. In it are the following fixes:

1) Added the following variable to the top of the hack code for easier editing:

$query = 50; // Set the number of row to return
$limit = 8; // Sets the number of rows to display
$chars = 22; // Sets the number of chars to truncate to

This is to ensure that the query is kept light enough to run on a large board and still return enough records so that the average user will have rights to at least your desired minimum display count. If we used only an SQL limit, and the user didn't have rights to see all of them, different users would see varying numbers of rows being displayed. That defeats the purpose for a display count.

2) The parenthetical expressioning in the 'while' has been fixed to properly catch all rows the user does not have rights to view.

3) The testing of the display limit has been adjusted within the 'while' loop to account for the display limit.

4) All '&' characters in hrefs have properly been changed to '&' for XHTML compliancy.

Let me know if anything needs to be changed.

subu1
05-23-2004, 05:27 PM
yeah, click install;)

Smitty
05-24-2004, 12:18 AM
Serenarules,

Nice! Thanks! Click.

BTW - Very nice skin on your site. Did you do the artwork?

Smitty
05-24-2004, 12:31 AM
I'm pretty stupid at this stuff... What's the reason for the <if condition="$show['latestposts']"> statement (and of course the ending /if)?

I assume it's a permissions conditional but where would you set it? Right now on my forum I removed the statement and the closing /if because if I didn't nothing would show up.

What am I missing here?

Albus
05-24-2004, 01:07 AM
In's a conditional that tell the templating mechanism whether or not to display the contained code. If you look at the php code sections you'll see that if there were no results to display, the $show[latestposts'] aray variable is left in it's default setting of false. In such a case, the html contained in that template is not shown. Otherwise, you'd end up with a table with only the header and no data. Basic templating procedures.

As far as nothing showing up, make sure that the conditions in the SQL meet your needs. By default it's set to return a certain set of stuff, excluding closed threads, and what not. So if you have the $query variable set too close to the $limit variable (for example, $query = 15 and $limit = 10) and 12 of them were closed threads, or threads the user doesn't have permission to see, the chances of a valid return is slim. Especially on boards with highly protected forums. The solution is to adjust the SQL and the variables, not the template. If you post more info on how your forum is set up and what you are 'expecting' to see, I might could help more.

And yes, the site design is all mine, including the artwork. :)

Smitty
05-24-2004, 01:34 AM
Thanks! My forums are relatively 'open'. I want anyone to be able to see the posts listing. Of course, permissions - such as access to my 'moderator forum' posts - must apply. Which I see they do - people without permissions do not see those posts in the list.

I got it installed and it appears to be doing everything I want. The forum is:

http://Elsmar.com/Forums/

I'm assuming that leaving out the conditional isn't an issue for me because there will always be results to display because a.) It's not time delimited (such as Posts in the last 24 Hours - Get Daily), and b.) In my forum there is no user group that I do not want to see threads in 95% of the forums.

I appreciate the detail in your response. Obviously I'm not a programmer... Your reply was a big help in understanding what a lot of the conditionals are about - why they're there. I learn a bit at a time...

Your artwork is outstanding!

Smitty
05-24-2004, 01:40 AM
BTW...
I understand this: $chars = 22; // Sets the number of chars to truncate to
But what are these?
$query = 50; // Set the number of row to return
$limit = 8; // Sets the number of rows to display

Albus
05-24-2004, 02:19 AM
The value of $query is used in the actual call to the database and says return that many rows. Permissons are not checked at this point, as it is easier to call the VB function fetch_permissions during the loop. The $limit value acts like a valve so that when the loop has added that many records to the display after passing the perms check, the loop will exit. The reason we have two vars here is that if we simply got the last ten records from he database, and all ten happened to be in a protected forum of sorts, no records would be displayed. There are other scenarios that can occur as well. For you application, your changes are fine, as long as you are aware that if you change your boards perms and no results are found it will still display the header with no rows.

:)

Thanks for the compliment.

Erwin
05-24-2004, 04:50 AM
The code still does a full thread table scan - so this will cause server load problems on a large site. :) Just letting people know. Not a problem with small sites.

Albus
05-24-2004, 05:08 AM
For those who did not understand that, let me elaborate. In a simple one table query you could select x last rows, which would not require the database server to actually 'look' at each row in the table to see if it met your criteria. That's a partial scan. In this hacks case, several tables are linked through join clauses andsome conditionals. This requires the database to scan the full table looking for sets of records that meet the search criteria, and finally get the last x rows. Now, ifyou are with us (Erwin and I) so far, here's why the script even bothers with a limit. With or without the limit, the database will initially do almost as much work, the difference is during transmission time, when the database sends the data back to the calling app (php page in this case). All that data is transmitted via the network. If we limit the data before it's sent, it means less network traffic, sure, but the relative hit on server-side performance is about the same. What Erwin says is true however. Unfortunately, in developing a general use hack, there are some sacrifices we must make in order to make it useful to the most people and trust that those with larger boards have also been around long enough to tailor a hack if required.

:)

That was more than I intended on posting...oh well.

Boofo
05-24-2004, 05:45 AM
Can it be fixed to satisfy both large and small sites?

Erwin
05-24-2004, 12:32 PM
Not really. At least, not without adding new columns and queries, and making it work like lastpost - basically caching the latest post info.

Albus
05-24-2004, 05:14 PM
It could be re-written to do most of the work in the php script. Write an sql statment that returns the last x (50 or so only) threads period. Then, in the php code, make the loop test the thread for perms first to avoid any extra processing time, then simply write a few small queries that get the extra info, like forum info, post info, and deletionlog info. The key here being simple queries with no joins. This would mean more, but less intensive db hits. If you have your display limit set to a small amount, like 8 or 10, then it shouldn't be too bad as your only getting the data you need when you need it. If you interested in this, I'll write an alternate version and you can test the efficiency of it.

Albus
05-24-2004, 05:34 PM
On second look Erwins solution is better. The first real check in this hack is for permissions which uses the forum id. That being the case, displayed or not, that is at least two more queries per row returned by my example above to get the forum id. I'll look into this further.

Erwin
05-25-2004, 11:52 AM
On second look Erwins solution is better. The first real check in this hack is for permissions which uses the forum id. That being the case, displayed or not, that is at least two more queries per row returned by my example above to get the forum id. I'll look into this further.
I just had a look at your site - your style is awesome. :) Well done!

Albus
05-25-2004, 05:59 PM
Many thanks! :)

Erwin
05-26-2004, 06:34 AM
I've figured out a way to pull the latest post from each forum and place it anywhere on the forumhome - without adding any new queries at all - but it does not work like a normal latest thread box as multiple threads in the same forum will not show up - only the latest one would. This is because only the lastpost is cached for each forum. I'll play around with it...

Erwin
05-26-2004, 06:35 AM
On second look Erwins solution is better. The first real check in this hack is for permissions which uses the forum id. That being the case, displayed or not, that is at least two more queries per row returned by my example above to get the forum id. I'll look into this further.
My version of this hack hardcoded the permissions. :) Which saves on database queries. I just excluded certain forums in the actual query itself. Not as elegant, but works.

Albus
05-26-2004, 08:19 AM
Yeah, that's a valid approach. One could take that, and make that static conditions variables in order to make it more easily customized. The great thing about hacks is that there is no 'right' way to do things. Everybody's needs are different. I would like to see what you come up with.

Smitty
05-26-2004, 09:11 AM
Yeah, that's a valid approach. One could take that, and make that static conditions variables in order to make it more easily customized. The great thing about hacks is that there is no 'right' way to do things. Everybody's needs are different. I would like to see what you come up with.
One of the things here is that in todays world, there are very few vB forums which this is a problem for with consideration to the fact that servers are cheap - fast, big servers. I've been online with a site since January 1996 and while I'm not a pro, I've maintained it and and gone from static pages to a relatively active forum. It's a niche forum for quality assurance folks - definitely not like 800 people on at one time. 100 over 30 minutes when it's busy during weekdays.

Typical day:
Date - Unique visitors - Pages - Hits - Bandwidth
25 May 2004 - 3174 - 38485 - 267414 - 1.78 GB

I fought with all sorts of issues until last December when I finally got a dedicated server - and for about $75 less a month than when I had a Verio virtual server. I had to get help setting it up but that was less than US$200. Since then all has been heaven. Not a problem with the database once I got everything straight, response is great and with an 80 gig RAID, I only have 35% of the 80 in use which includes the forum database (I have a lot of other files).

Database Data Disk Usage 93.88 MB
Database Index Disk Usage 34.45 MB
Attachment Disk Usage 220.21 MB
Custom Profile Picture Disk Usage 0.16 MB
Custom Avatar Disk Usage 0.34 MB

My point is, as I have seen myself do, many times we opt for less server than we really need to do what we want to do based upon a financial decision. I do OK profit wise on my site - it well more than pays expenses - so US$175 a month isn't a real big deal.

This is not to say I don't enjoy the code optimization discussion or that I see it as unimportant. In fact, I really appreciate it. It is rare that threads get this much detail and thought. It is a real 'class' for me as you folks are discussing what's going on and I'm better understanding how all this works.

Just a thought because so many times we try to get more out of something than our tools can reasonably handle.

I installed the hack and there is absolutely no server load issue for me. It typically stays below 1. I've never seen it above 1.5 even when Google is attacking it as it does from time to time. I'm on a 10M connection - don't need 100 but I see 100's as more and more common and we all know server rental prices have been dropping for some time.

I also want to say thanks again because this hack really is something I had been wanting for a long time and it fit right in where I wanted it. I took out last poster and thread starter in part because I have a 'sidebar' and I wanted the room, but also because I saw it as another 'complicator' for search bots. I like search bots and don't see those fields as a big deal to users.

Like you say - we each want something different. And sometimes you have to have the proper tool to do the job which, in this 'business' includes software AND server.

Albus
05-26-2004, 09:27 AM
It looks nice on your board too.

:)

Curious, did you also adjust the SQL query and php code in regards to the unused fields? That would trim a tad of processing time and data return size, even if just a hair.

Smitty
05-26-2004, 09:56 AM
No - I didn't touch the code other than removing the fields in a template and the index.php file (if I remember correctly). I'm not motivated enough to really sit down and try to learn to code php. I took fortran, pl1 and cobol courses back in the early 1970's in college and have played with php, perl, etc a bit over the years - so if I get desparate I can follow what's happening reading through the code and Google when I get stuck. But I'm typically not that motivated. I try everything on my Mac Powerbook and if it works on it I make the change on the live BSD server.

That's in part why I mentioned server size. Is it unnecessary overhead for me? Yes - but not enough to even measure on my server. I used to fight those 'just a hair' battles from back in the days where a local ISP would complain because my WWWBoard scripts were taking up too much server CPU time. Each time I'd switch. Eventually I was at wits end on a Verio 'Virtual Server'. It was nice. 24/7/365 tech support answered within minutes. Fully managed. But only 2.4Gigs and I was sharing a processor and as time went on it got slower and slower. Even backing up the database was an hour plus WITH the forums shut down.

But when I 'over bought' (my 'advisor' said I should rent out some of the space and bandwidth) found my life became much less complicated. It's just me, I have plenty of processing power and plenty of disk space. I no longer fight 'just a hair would help' battles and my life has become remarkably uncomplicated.

Now, had the hack stopped working I would have put the fields back in and come here and asked 'how to'. I really wanted the truncated lenght at about 45. Lazy me - it worked and I'm happy. The 'regulars' use the do=getdaily for the last 24 hours of posts - they get the 'details' there so I don't see a 'user experience' problem.

Smitty
05-26-2004, 10:09 AM
BTW - This is, obviously, why I appreciate folks like you who contribute code here for people like me who aren't very 'savvy'. I know just enough to be dangerous, as the saying goes.

My site is relatively plain and uninspired, but web sites are not my forte. I just play with my site. You wouldn't believe what it was like back when I went online in 1996 - landing page was a starfield (as were many, many landing pages in those days). It was really gaudy. I'm sure not an artist or page layout person. Your site page layout and artwork blew me away. Serious time and effort along with artistic talent.

Erwin
05-28-2004, 02:45 AM
My point is, as I have seen myself do, many times we opt for less server than we really need to do what we want to do based upon a financial decision. I do OK profit wise on my site - it well more than pays expenses - so US$175 a month isn't a real big deal...

I installed the hack and there is absolutely no server load issue for me. It typically stays below 1. I've never seen it above 1.5 even when Google is attacking it as it does from time to time. I'm on a 10M connection - don't need 100 but I see 100's as more and more common and we all know server rental prices have been dropping for some time...

Like you say - we each want something different. And sometimes you have to have the proper tool to do the job which, in this 'business' includes software AND server.If you install this hack, and you don't get server problems, then you don't have a very large forum. This hack scans the whole thread table - how many threads does your forum have? It's not about your hardware, it's about the size of your database - with this hack, specifically the size of your thread table.

red_baron2000
04-26-2005, 02:32 PM
is there a way to exclude some forums from beeing scaned and listed?
thank you

Albus
04-26-2005, 05:03 PM
is there a way to exclude some forums from beeing scaned and listed?
thank you
This is an older version. Please see the following thread, in which a similar question was posted, and answered.

https://vborg.vbsupport.ru/showthread.php?t=78805