[DEV] Sticky Post within Topic

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.
LifeIsPain
Former Team Member
Posts: 2148
Joined: Tue Oct 01, 2002 7:04 am
Location: Way Way Behind

[DEV] Sticky Post within Topic

Post by LifeIsPain »

This mod allows you to display the first post of a thread at the top of every page (other than the first page) within that thread. Only the text of the message is displayed (after being parsed for BBCode, smilies, and urls), along with the username of the poster and the time posted. All changes should be made from the normal post.

Only users with the permission to create normal Sticky Topics may set the first post to be Sticky within the topic. If edited by a moderator to become a Sticky Post, this post will continue to stay at the top of each page, even if the original author edits the post.

Code: Select all

######################################################## 
## MOD Title: Sticky Post within Topic
## MOD Author: LifeIsPain <brian@orvp.net> (Brian Evans)
## MOD Description: Allows for the first post in a topic to be at the top of every page in the
##       topic. Pemission for setting this is the same as the Sticky Permission
## MOD Version: 0.1.2
## 
## Installation Level: easy
## Installation Time: 5-10 Minutes
## 
## Files To Edit:         6
##                   - posting.php
##                   - includes/functions_post.php
##                   - templates/subSilver/posting_body.tpl
##                   - language/lang_english/lang_main.php
##                   - viewtopic.php
##                   - templates/subSilver/viewtopic_body.tpl
## 
## Included Files:      None
######################################################## 
## VERSION HISTORY:
## 
## v0.1.0 - 04/17/2003
##    + initial code
## v0.1.1 - 04/19/2003
##    + fix appearance in IE
##    + fixed 1 char typo causing code to not work
##    + 1 file name changed to correct directory
## v0.1.2 - 04/19/2003
##    + fixed display of sticky note
## 
############################################################## 
Download - Sticky Post within Topic 0.1.2
Last edited by LifeIsPain on Sun Apr 20, 2003 5:53 am, edited 2 times in total.
LifeIsPain - one who needs to be smackedLife is pain, highness! Anyone who says differently is selling something.

User avatar
Ptirhiik
Registered User
Posts: 7411
Joined: Mon Jan 06, 2003 10:36 pm
Contact:

Post by Ptirhiik »

Am I right ? :

- only first post can be sticky,
- the post sticked isn't remove from the thread, even if it's on the first page,
- edit informations and user informations missing (except the username).

Perhaps should you set the sticky post switch at a post level (assuming you can have more than one post sticked in a long thread, and the first isn't necessarely the one to stick), and play with the order of the thread, as the posts displayed on the page are first sent in an array. It would able you to add separatly the sticked posts, then except them from other reading, and also use the standard table for display them, adding a line separator between stycked and not sticked.

LifeIsPain
Former Team Member
Posts: 2148
Joined: Tue Oct 01, 2002 7:04 am
Location: Way Way Behind

Post by LifeIsPain »

Yes, only the first post is possible to become the sticky post. It isn't like a nomall sticky in this way, but it makes for a lot simpler code. Because it is only the first post that can be stickied, it isn't removed from the list of posts, the extra information is just not shown on the first page.

I left out the edit information and user information to simplify the way the post looks. It wouldn't be too hard to put this all back in (it was c/p from the rest of the code and then edited) but it was more than was needed IMO, and made the instructions look much longer.
LifeIsPain - one who needs to be smackedLife is pain, highness! Anyone who says differently is selling something.

User avatar
Ptirhiik
Registered User
Posts: 7411
Joined: Mon Jan 06, 2003 10:36 pm
Contact:

Post by Ptirhiik »

Not agreed ;) : in fact it only add (if post_type is the var to say "sticky") :

- the sql sentence copy from and placed just before the original one, adding a filter on both : one with "WHERE post_type > 0" without the limit of start and per page but with and "ORDER BY post_type DESC before the standard sort, and the original one with "WHERE post_type = 0"

- the postrow[] fill after the added sql sentence,

- a var called ie $last_post_type, init with NULL before the display loop, to test the previous row post_type and send a space bar title at change of type except if first (NULL) and not sticky. Of course just after the test you reset $last_post_type with the new post_type (the current one in fact ;)).

Doing so you haven't to care to the display itself, parsing bbcode or so, neither a particular template or other mods installed - I'm thinking ie gender mod or icon topic mod, the sticky posts will be displayed as the other,separated with a space title bar.

It's also very close to what is done for sticky topics and announces in viewforum.

LifeIsPain
Former Team Member
Posts: 2148
Joined: Tue Oct 01, 2002 7:04 am
Location: Way Way Behind

Post by LifeIsPain »

Ok, after reading that, it makes sence (mostly) it took me a bit to figure out how you were going to get the spacer in there, but I think I get it now. The one issue I have with this is the order of posts. Pulling a post from the middle of a thread could get confusing, and I don't know the best way to handle this (unless there was another option to pull it from thread or not).

As far with messing with other mods, neither method would (I don't think). Well, you would have to change the template in both methods, both by adding the same code (modified if you want). Anyway, I will wait to see if anyone else has something to add before I make drastic changes.
LifeIsPain - one who needs to be smackedLife is pain, highness! Anyone who says differently is selling something.

User avatar
Ptirhiik
Registered User
Posts: 7411
Joined: Mon Jan 06, 2003 10:36 pm
Contact:

Post by Ptirhiik »

Regarding the content of a post, I agree : a post not designed to be sticky would be confusing when sticked (nothing before, and nothing after), but I don't think such posts will be sticked ;). Anyway, you can set an option to let it appear in the standard thread of post (meaning not sticked).

For the template part, I don't see your point : acting only with the postrow[] array, and letting the rest of the prog doing the job, you won't have to modified the post template in fact : it will be displayed as it was in its normal sort order. You'll certainly have to add a level to the postrow template loop to take care of the split bar at the good place, but I think it's the only modification to do.

User avatar
rahulkhandelwal
Registered User
Posts: 29
Joined: Wed Mar 19, 2003 4:59 pm
Location: New Delhi, India
Contact:

Thanks!!

Post by rahulkhandelwal »

Thanks guys!!

I'll try this out Monday and let you know how it works out!!!!

Pggar
Registered User
Posts: 18
Joined: Fri Nov 15, 2002 12:20 am
Location: Brazil
Contact:

Post by Pggar »

First, I have to say thank you for doing this! :D

Second, it's not working for me.
After I check the option and finish editing the post, nothing happens.
If I edit the post again the checkbox is not checked.
Also, there's something wrong this line:

Code: Select all

<input type="hidden" name="stickypostok" value="true" />
It messes with the layout and the checkbox is not aligned with the others because of it.

I'm looking for mistakes when I installed and will let you know if it works.
But is it fully functional already, am I missing something?

LifeIsPain
Former Team Member
Posts: 2148
Joined: Tue Oct 01, 2002 7:04 am
Location: Way Way Behind

Post by LifeIsPain »

It was fully working for me, and the checkmark box was aligned just fine, but I am using a Mozilla engine, and I checked it on IE, and there was the problem... Stopic M$ :). To fix line up (and it will be in the next version I have, just not chaning for now) remove the line break after the line, as well as the tabs and spaces, so that you get the >< together.

For the not changing problem, there are only two reason I can think of for it not to work: If the SQL change wasn't made for some reason; If the hidden tag line was removed to make it look pretty. Could you check the SQL table to make sure the row topic_stickypost exists in table phpbb_topics? If you have a different prefix other than phpbb_, please use whatever that one is (just throwing out ideas)

The line mentioned above is necessary because without it, the code won't try to change the value already in the database (allowing a non moderator/person who can do stickies to edit the post, and still leave it at the top).

Also, you won't notice changes on the first page, only on the pages after that. So make sure the thread you are testing on has multiple pages.
LifeIsPain - one who needs to be smackedLife is pain, highness! Anyone who says differently is selling something.

Pggar
Registered User
Posts: 18
Joined: Fri Nov 15, 2002 12:20 am
Location: Brazil
Contact:

Post by Pggar »

Hi LifeIsPain,

The table was changed correctly.
I'm might have done something incorrectly when editind the code.
Checking the box is doing nothing. And I'm using your code. I did not take the hidden from there.
After editing a message, when I try to edit it again, I see the box unchecked.
I edited the db manually and the box is now checked, but I still can't see the sticky post in the subsequent pages of the topic.

Maybe there is another mod interfering with this one.
I'll check the code later today and let you now.

Thanks again.

LifeIsPain
Former Team Member
Posts: 2148
Joined: Tue Oct 01, 2002 7:04 am
Location: Way Way Behind

Post by LifeIsPain »

Ok, it is my fault. In my mod, I left out one "y" that is causing all the problems. In includes/functions_post.php, do a search for stickpost and replace it with stickypost. That is a smash head problem. I also said in the instructions that it was functions/functions_post.php, and that has been changed as well. Furthermore, the instructions now give a layout that still looks good in IE.

Sorry about that.
LifeIsPain - one who needs to be smackedLife is pain, highness! Anyone who says differently is selling something.

Pggar
Registered User
Posts: 18
Joined: Fri Nov 15, 2002 12:20 am
Location: Brazil
Contact:

Post by Pggar »

That's ok.
I'm here to help, not to complain.
You're doing me a favor, and that's great.
I'll be testing your new code in the next couple of days.

Edit: I added the y and now the db is being updated correctly.
But I still don't have sticky posts.

Edit2: I ahve checked the code and it looks fine.
The only problem I can think of is mod incompatibility.
I have some mods that have edited viewtopic.php and that might be the problem.
Other than taht I can't see it.

LifeIsPain
Former Team Member
Posts: 2148
Joined: Tue Oct 01, 2002 7:04 am
Location: Way Way Behind

Post by LifeIsPain »

Rather frasm.... (said in angry voice)

stinking missing code again, I don't know how I do it, I really don't.....
ok, do the following (fixed in code again, no need for next people to do)

Code: Select all

#-----[ OPEN ]-----
viewtopic.php

#-----[ FIND ]-----
$sql = "SELECT t.topic_id, t.topic_title

#-----[ IN-LINE FIND ]-----
 t.topic_first_post_id,

#-----[ IN-LINE BEFORE, ADD ]-----
 t.topic_stickypost,
And I hope that is my last bug. Perhaps I should install easymod so I can test these things easier and make sure the code works as intended...
LifeIsPain - one who needs to be smackedLife is pain, highness! Anyone who says differently is selling something.

Dinosaur Gas
Registered User
Posts: 71
Joined: Thu Jul 11, 2002 11:56 pm
Contact:

Post by Dinosaur Gas »

Something like this has already been done.

http://www.phpbbhacks.com/viewhack.php?id=873
Image

Pggar
Registered User
Posts: 18
Joined: Fri Nov 15, 2002 12:20 am
Location: Brazil
Contact:

Post by Pggar »

It worked!!!!! :D :D :D
Thanks!
Under construction.
Coming Soon!
In a post near you!

Post Reply

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