PDA

View Full Version : Preview the first post in a thread first (beta defunct).


Parker Clack
09 Dec 2001, 11:58
One of the things that will happen when you put your mouse pointer on to a hyperlink is put text in a popup box if you put this information into a title line.

For example:

< a href="http://www.yourplace.com" title="your text here">Here ya go< /a >

(the above is just an example to play with without the spaces in the brakets to see how this works)

At any rate. In your forumdisplay.php file right above:

eval("\$forumdisplaybits .= \"".gettemplate('forumdisplaybit')."\";");

put

$post=$DB_site->query_first("SELECT pagetext FROM post WHERE threadid=$thread[threadid] ORDER BY postid");
$page=iif(strlen($post[pagetext])>500,substr($post[pagetext],0,500)."...",$post[pagetext]);
$page=bbcodeparse2($page,1,1,1,1);
$page=strip_tags($page);


Then in your forumdisplaybit template

look for

<a href="showthread.php?s=$session[sessionhash]&threadid=$thread[threadid]">$thread[title]</a>

and replace this with:

<a href="showthread.php?s=$session[sessionhash]&threadid=$thread[threadid]" title="$page">$thread[title]</a>

The next time you get on your board and open the forumdisplay.php file and list the thread titles in your forums if you put your mouse pointer on the hyperlink to the post you will get a brief display of the first post in the thread to use as a preview.

You can play around with the order size of the pagetext from 500 to whatever you want to have displayed.

If anyone can think of anything to add to this please do. I guarantee I am a very limited coder.

Many thanks go to Chen and Bira for helping me with the coding.

Parker

Parker Clack
09 Dec 2001, 13:20
Note:

I have found that if the post has quotes in it that it will affect the display of the hyperlink on the forumdisplay. You have to change this to single quotes instead of double quotes.

Any work around for that?

Parker

Wayne Luke
09 Dec 2001, 14:11
Doesn't this add one query for every thread shown in forumdisplay. At the default that is 15 new queries shown for every forumdisplay page which can add up a to a lot of resources.

A better solution would be to:

1) Add a new "preview" field to the thread table.
2) Move the code that generates the snippet to the newthread.php file.

$page=iif(strlen($message>500,substr($message,0,500)."...",$message);

Place that above the line that begins:

$DB_site->query("INSERT INTO thread


Alter that same INSERT query to insert the preview as well.

4) Alter the statement that begins with:

$threads=$DB_site->query("

so that is pulls the preview from the database as well.

5) Finally in forumdisplay.php you add the other two lines where you had them to begin with:

$page=bbcodeparse2($page,1,1,1,1);
$page=strip_tags($page);


This will give you now new queries while pulling the thread information.

If you have dot folders turned on you can edit the $dotuserid string to pull the message information and get by with less coding and still not have any new queries at display time.

Symbian.info
09 Dec 2001, 20:17
??? What is the good en complete hack? I am lost now..

TheComputerGuy
09 Dec 2001, 21:00
well I think the orginal hack is a great thing, and I think wLuke is saying that for larger boards this would be a good thing to modify...I have it on my test board, and Its going to be included on the new new board for the new year at hand

Wayne Luke
09 Dec 2001, 21:02
That is correct. The original as posted will work fine but if you start running into resource limitations, it can be improved for larger boards. That was my original intent.

Parker Clack
09 Dec 2001, 23:24
wluke:

Great suggestion. I am a poor coder so could you post examples of what you are talking about. The ones you suggested I am afraid I would screw up.

Parker

Parker Clack
09 Dec 2001, 23:43
wluke:

I created a table preview with setting of mediumtext not null in
the database

Then I used:

$page=iif(strlen($message>500,substr($message,0,500)."...",$message);

$DB_site->query("INSERT INTO thread (.....,preview) VALUES (..................,'".addslashes(htmlspecialchars($page))."')");

in the newthread.php file

and

$threads=$DB_site->query("SELECT .....,preview FROM thread..

from forumdisplay.php

and took out the

$post=$DB_site->query_first("SELECT pagetext FROM post WHERE threadid=$thread[threadid] ORDER BY postid");
$page=iif(strlen($post[pagetext])>500,substr($post[pagetext],0,500)."...",$post[pagetext]);
$page=bbcodeparse2($page,1,1,1,1);
$page=strip_tags($page);

and replaced it with:

$page=bbcodeparse2($page,1,1,1,1);
$page=strip_tags($page);

Should that do it?

Parker

Wayne Luke
10 Dec 2001, 03:43
It looks like it. Can't tell until I try it.

I will be finally getting the chance to upgrade SPF to 2.2.1 in the next couple of days. My changelog of modifications I have made is 50K for the user front end alone. I haven't even started applying my changes to the moderators control panel yet.

Once I finish that project, I will probably implement this as well and have the code I write for you to compare with.

Parker Clack
10 Dec 2001, 04:40
wluke:

I look forward to this. One thing though. When I put

$page=iif(strlen($message>500,substr($message,0,500)."...",$message);

into the newthread.php I get a parse error at the line it is on.

I will wait and see what you come up with.

While you are at it see if you can get it to pass quotes in the information that is passed because if they are used in the message of the first post it the text for the hyperlink is not displayed.

Parker

Freddie Bingham
10 Dec 2001, 04:52
$page = iif( strlen($message>500),substr($message,0,500).'...',$message);

Parker Clack
10 Dec 2001, 06:01
freddie:

Thanks. But I still get the parse error at the line it is on.

BTW, will this way show old text messages that have already been written or only new posts that have been written since putting this in?

Parker

freakyshiat
10 Dec 2001, 07:10
so is there a more efficeint way of doing this?

Parker Clack
11 Dec 2001, 00:17
Well:

As stated this was too much of a demand on my server so if you have a large board I would not use this.

Anyone have a way to doing this more efficiently?

Parker

bira
17 Dec 2001, 04:21
Parker a couple more comments:

1) "$page = $thread[preview];" is redundent. place title="$thread[preview]" in your template.


2) you didn't strip out the bbcodes first, before doing strip_tags.

this:


$page = iif(strlen($message)>500,substr($message,0,500).'...',$message);
$page=strip_tags($page);


Should be:


$page = iif(strlen($message)>500,substr($message,0,500).'...',$message);
$page=bbcodepase($page);
$page=strip_tags($page);

bira
17 Dec 2001, 04:35
Ah. Small problem that needs to be looked at.

1) If, for example, the first 500 characters of the opening post include something that you as an admin edit out - they will continue to appear in the preview.

2) If, for example, you split a thread then
---> a) the newly created thread will not have a preview; and
---> b) if you, for example, split the thread so as to remove the first post (say, to your trashcan forum), the that post will continue to exist in the 'preview'.


What needs to be done, is adding an additional hack code to the editpost script and the splitting action script. In both cases, when a thread is updated, the 'preview' must be updated as well.

I'm off to sleep now. I'll see if I can help you when I wake up, if that will be needed :)

bira
17 Dec 2001, 05:44
OK, the necessary add-ons :)

1) Open root/editpost.php, find:


if ($isfirst and $title!="" and $postinfo[dateline]+$editthreadtitlelimit*60>time()) {
$DB_site->query("UPDATE thread SET title='".addslashes(htmlspecialchars($title))."' WHERE threadid=$threadinfo[threadid]");
//$title="";
}


AFTER it ADD:


if ($isfirst) {
$page = iif(strlen($message)>500,substr($message,0,500).'...',$message);
$page = bbcodeparse($page);
$page = strip_tags($page);
$DB_site->query("UPDATE thread SET preview='".addslashes(htmlspecialchars($page))."' WHERE threadid=$threadinfo[threadid]");
}


Save and upload. This will ensure the 'preview' is also updated when the first post is edited.


2) open root/postings.php.

a) find:


$DB_site->query("UPDATE thread SET title='".addslashes(htmlspecialchars($title))."',notes='".addslashes($threadinfo[notes])."'$pollcode WHERE threadid='$threadid'");


Replace is with (changes marked in high):


$getfirstpost=$DB_site->query_first("SELECT pagetext FROM post WHERE threadid=$threadid ORDER BY dateline LIMIT 1");
$page = iif(strlen($getfirstpost[pagetext])>500,substr($getfirstpost[pagetext],0,500).'...',$getfirstpost[pagetext]);
$page = bbcodeparse($page);
$page = strip_tags($page);
$DB_site->query("UPDATE thread SET title='".addslashes(htmlspecialchars($title))."',notes='".addslashes($threadinfo[notes])."',preview='".addslashes(htmlspecialchars($page))."'$pollcode WHERE threadid='$threadid'");


This will ensure the 'preview' is updated when a thread is merged, to correctly reflect the new 1st post.

b) find:


// Update first post in each thread as title information in relation to the sames words being in the first post may have changed now.
$getfirstpost=$DB_site->query_first("SELECT postid FROM post WHERE threadid=$threadid ORDER BY dateline LIMIT 1");
$DB_site->query("DELETE FROM searchindex WHERE postid=$getfirstpost[postid]");
indexpost($getfirstpost[postid]);

$getfirstpost=$DB_site->query_first("SELECT postid FROM post WHERE threadid=$newthreadid ORDER BY dateline LIMIT 1");
$DB_site->query("DELETE FROM searchindex WHERE postid=$getfirstpost[postid]");
indexpost($getfirstpost[postid]);


Replace it with (changes marked in high):


// Update first post in each thread as title information in relation to the sames words being in the first post may have changed now.
$getfirstpost=$DB_site->query_first("SELECT postid,pagetext FROM post WHERE threadid=$threadid ORDER BY dateline LIMIT 1");
$DB_site->query("DELETE FROM searchindex WHERE postid=$getfirstpost[postid]");
indexpost($getfirstpost[postid]);
$page = iif(strlen($getfirstpost[pagetext])>500,substr($getfirstpost[pagetext],0,500).'...',$getfirstpost[pagetext]);
$page = bbcodeparse($page);
$page = strip_tags($page);
$DB_site->query("UPDATE thread SET preview='".addslashes(htmlspecialchars($page))."' WHERE threadid='$threadid'");
unset($page);

$getfirstpost=$DB_site->query_first("SELECT postid,pagetext FROM post WHERE threadid=$newthreadid ORDER BY dateline LIMIT 1");
$DB_site->query("DELETE FROM searchindex WHERE postid=$getfirstpost[postid]");
indexpost($getfirstpost[postid]);
$page = iif(strlen($getfirstpost[pagetext])>500,substr($getfirstpost[pagetext],0,500).'...',$getfirstpost[pagetext]);
$page = bbcodeparse($page);
$page = strip_tags($page);
$DB_site->query("UPDATE thread SET preview='".addslashes(htmlspecialchars($page))."' WHERE threadid='$newthreadid'");
unset($page);


This will ensure the 'preview' is updated for both threads, old and new, after splitting a thread in two.

Very nice hack Parker - I personally will use it a lot!!!

Thanks,

Bira

bira
22 Dec 2001, 16:17
This hack was released in full and can be found here (http://www.vbulletin.org/forum/showthread.php?s=&threadid=33070). Don't use instructions in this thread - go to the 'Full Release' one.

Thanks :)