[RC] Post Display Order

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.
User avatar
warmweer
Registered User
Posts: 2686
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

[RC] Post Display Order

Post by warmweer » Sun Aug 10, 2003 9:40 pm

The following code allows a user to define the order in which posts are displayed in viewtopic. Choices are ascending or descending. If descending is chosen (newest posts first) then the newest post will always be the top post on the first page in viewtopic.
In viewforum the link to the last post (titled latest post) points to the last pots considering pagination. This implies that with order descending, the last post is actually the very first posted.

1st edit 22/08/03: there are a couple of mistakes in the code which have been solved - see posts by mad_dog_bob. Be sure to read those posts before installing. I will edit the code this weekend to include the corrections. Sorry, no time now :oops:

2nd edit 27/08/03: Version 0.0.2 had been posted (a bit lower). I've refrained from editing the code below so as not cause cause any confusion when reading later posts.

3rd edit 03/09/03: Changed topic title to [RC].

4th edit 23/02/04: old code removed - see later posts
BTW this mod is offered to anybody willing to continue development or just plain submit it

Code: Select all

code removed so as to avoid confusion
Last edited by warmweer on Mon Feb 23, 2004 8:53 pm, edited 6 times in total.

User avatar
warmweer
Registered User
Posts: 2686
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Post by warmweer » Sun Aug 10, 2003 9:43 pm

At the moment I can't show the demo forum (I'm cleaning it up but tomorrow i'll probably add the link to my signature). Code is for 2.0.6 but as far as I can see it should also work on 2.0.4 and 2.0.5

I hope there are no boobies in the code (since I've had to look for clean 2.0.6 files as my board is heavily modded).

I just noticed that only new members will have a setting, so I'll have to include an update sql soon.

Suggestions, corrections, any remarks are welcome. I'll support this in the forum here but not by email (nor PM) (sorry guys, but i'm too busy)
My board's not broken, it just went peculiar

User avatar
warmweer
Registered User
Posts: 2686
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Post by warmweer » Tue Aug 12, 2003 9:25 pm

No comments yet?

Well, I found a little problem. Aftere posting a new message it doesn't redirect to that posted message if the display order chosen is descending, but redirects to the last page.

I'll have to sort that out tomorrow but if anybody has any idea already, please post it.

you can try it out on my testing forum (see signature)
My board's not broken, it just went peculiar

User avatar
warmweer
Registered User
Posts: 2686
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Post by warmweer » Wed Aug 13, 2003 9:17 pm

Well, it seems to be a bit more complicated than I thought and I would really like some assistance from more knowledgeable guys (or gals).

After some seriuous debugging I think I've got it cracked. It's the variable $start which defines which page will be shown when linking to a post. So this would have to be calculated differently according to the display order (ascending or descending).

Something extra has to be changed in viewtopic.php

Find:

Code: Select all

if ( !empty($post_id) )
{
	$start = floor(($forum_topic_data['prev_posts'] - 1) / intval($board_config['posts_per_page'])) * intval($board_config['posts_per_page']);
}

Replace by

Code: Select all

if ( !empty($post_id) )
{
	if ($userdata['user_sortorder'] == 0)
	{
		$sql = "SELECT COUNT(post_id) AS total_posts FROM  " . POSTS_TABLE . " WHERE forum_id = " . $forum_id . " AND topic_id = " . $topic_id;
		if ( !($result = $db->sql_query($sql)) )
		{
			message_die(GENERAL_ERROR, "Could not obtain number of posts in topic", '', __LINE__, __FILE__, $sql);
		}
		$total_posts = ( $row = $db->sql_fetchrow($result) ) ? intval($row['total_posts']) : 0;

		$start = floor(($total_posts - $forum_topic_data['prev_posts'] )/ intval($board_config['posts_per_page'])) * intval($board_config['posts_per_page']);
	}
	else
	{
		$start = floor(($forum_topic_data['prev_posts'] - 1) / intval($board_config['posts_per_page'])) * intval($board_config['posts_per_page']);
	}
}
This seems to work fine on my testboard, but since I'm the only one testing it takes quite some time to try out all possibilities.

Therefore, please try it (there is a forum where you can post without having to be registered - the top one) and give some feedback. In the second forum (registered) there is a topic with 17 posts and another topic in which the 11th post of that long topic is linked.

Any ideas on optimising the code are welcome.
My board's not broken, it just went peculiar

imagedude
Registered User
Posts: 296
Joined: Wed Sep 25, 2002 10:28 pm
Location: /home/kai
Name: Kai Ponte
Contact:

Post by imagedude » Wed Aug 13, 2003 9:27 pm

Doesn't this mod exist already? I could swear I have it in one of my development forums.


(checking....)

Yes, I do. I don't remember the MOD, but you should search for it. Here's a screen shot of it in action:

Image

I can choose to sort by whatever order.

User avatar
warmweer
Registered User
Posts: 2686
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Post by warmweer » Wed Aug 13, 2003 9:40 pm

Well, if it exists allready, I have no problem with this topic being closed.

However, I have searched for something which allows every member to have his own sort order (for the posts within a topic). (and I haven't found anything :oops: )

The screenshot in your post looks like something to order the display of topics within a forum. (but maybe I have to see the mod in action first).
Anyway, I'm glad at least one comment came out of it ;)
My board's not broken, it just went peculiar

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

Post by Ptirhiik » Wed Aug 13, 2003 9:52 pm

I don't think it is related to the same sort : what imagedude shows seems to be a topic display order (I don't know this version, but I have my topic display order mod published here, so perhaps is this an enhancement of my prec version), acting on the order of the topic in viewforum, not the order of the posts in viewtopic :). At this time I see no reasons not to go on with this mod :).

imagedude
Registered User
Posts: 296
Joined: Wed Sep 25, 2002 10:28 pm
Location: /home/kai
Name: Kai Ponte
Contact:

Post by imagedude » Thu Aug 14, 2003 2:29 pm

warmweer wrote: Well, if it exists allready, I have no problem with this topic being closed.

However, I have searched for something which allows every member to have his own sort order (for the posts within a topic). (and I haven't found anything :oops: )

The screenshot in your post looks like something to order the display of topics within a forum. (but maybe I have to see the mod in action first).
Anyway, I'm glad at least one comment came out of it ;)


Ahh, you allow the members to choose. That is different. The one I have up is set by admins.

User avatar
mad_dog_bob
Registered User
Posts: 26
Joined: Tue May 28, 2002 3:25 pm
Location: UK
Contact:

Re: [BETA] Post Display Order

Post by mad_dog_bob » Fri Aug 22, 2003 3:12 pm

Hi,

Thanks for posting this - I've been asked by some of my members to add this to my site so you've saved me some time.

I've got a question - is this an error:

Code: Select all

#
#-----[ OPEN ]------------------------------------------
#
includes/usercp_register.php
#
#-----[ FIND ]------------------------------------------
#
	$popup_pm = ( isset($HTTP_POST_VARS['popup_pm']) ) ? ( ($HTTP_POST_VARS['popup_pm']) ? TRUE : 0 ) : TRUE;
#
#-----[ AFTER, ADD ]------------------------------------------
#
	$sortorder = ( isset($HTTP_POST_VARS['sortorder']) ) ? ( ($HTTP_POST_VARS['sortorder']) ? TRUE : 0 ) : 0;
Because when you refer to this value in the UPDATE SQL you use 'user_sortorder' not 'sortorder':

Code: Select all

#
#-----[ FIND ]------------------------------------------
#
         $sql = "UPDATE " . USERS_TABLE . " 
            SET " . $username_sql . $passwd_sql . "user_email = '" . str_replace("\'", "''", $email) ."', user_icq = '" . str_replace("\'", "''", $icq) . "', user_website = '" . str_replace("\'", "''", $website) . "', user_occ = '" . str_replace("\'", "''", $occupation) . "', user_from = '" . str_replace("\'", "''", $location) . "', user_interests = '" . str_replace("\'", "''", $interests) . "', user_sig = '" . str_replace("\'", "''", $signature) . "', user_sig_bbcode_uid = '$signature_bbcode_uid', user_viewemail = $viewemail, user_aim = '" . str_replace("\'", "''", str_replace(' ', '+', $aim)) . "', user_yim = '" . str_replace("\'", "''", $yim) . "', user_msnm = '" . str_replace("\'", "''", $msn) . "', user_attachsig = $attachsig, user_allowsmile = $allowsmilies, user_allowhtml = $allowhtml, user_allowbbcode = $allowbbcode, user_allow_viewonline = $allowviewonline, user_notify = $notifyreply, user_notify_pm = $notifypm, user_popup_pm = $popuppm, user_timezone = $user_timezone, user_dateformat = '" . str_replace("\'", "''", $user_dateformat) . "', user_lang = '" . str_replace("\'", "''", $user_lang) . "', user_style = $user_style, user_active = $user_active, user_actkey = '" . str_replace("\'", "''", $user_actkey) . "'" . $avatar_sql . "
#
#----- [ IN-LINE, FIND ] -------------------------------------
#
user_style = $user_style,
#
#-----[ IN-LINE AFTER, ADD ]------------------------------------------
#
user_sortorder = $user_sortorder,
I think that last line should be:

Code: Select all

user_sortorder = $sortorder,
It also applies to the admin_user.php changes too.

Hope that makes sense, I'll let you know how I get on with the rest!

Rob

User avatar
mad_dog_bob
Registered User
Posts: 26
Joined: Tue May 28, 2002 3:25 pm
Location: UK
Contact:

Post by mad_dog_bob » Fri Aug 22, 2003 3:56 pm

Here's another change for you:

In viewtopic.php

Code: Select all

#-----[ FIND ]------------------------------------------ 
# 
   $post_order = 'asc'; 
   $post_time_order = 'ASC'; 
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
   $post_order = $user_post_order; 
   $post_time_order = $user_post_time_order; 
Instead of adding those after the existing lines, you can just replace the existing lines. No need to assign them twice, unless I'm missing something.

User avatar
mad_dog_bob
Registered User
Posts: 26
Joined: Tue May 28, 2002 3:25 pm
Location: UK
Contact:

Post by mad_dog_bob » Fri Aug 22, 2003 4:21 pm

One more :D

The user's settings aren't loaded when editing their profile...

This needs adding:

Code: Select all

# 
#-----[ OPEN ]------------------------------------------ 
# 
includes/usercp_register.php 
# 
#-----[ FIND ]------------------------------------------ 
# 
   $allowviewonline = $userdata['user_allow_viewonline'];
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
   $sortorder = $userdata['user_sortorder'];
Hope this is useful,
Rob

User avatar
warmweer
Registered User
Posts: 2686
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Post by warmweer » Fri Aug 22, 2003 5:14 pm

Thanks mad_dog_bob, I really appreciate it.

My problem is with writing the d*mned instructions properly :wink:
All remarks made in your three posts are correct (the non removal of the lines is intentional but in the how to I forgot to comment out those two lines). They were however included in my files but due to the rush job the how to is faulty. I had realised that the find instructions (on the update and insert SQL) will cause some problems on modded boards.

Edit: Just some clarification concerning your first post .

Code: Select all

# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 
   $sortorder = ( isset($HTTP_POST_VARS['sortorder']) ) ? ( ($HTTP_POST_VARS['sortorder']) ? TRUE : 0 ) : 0; 

This is correct (I'm fairly sure). Sortorder is the name of the POST_VAR, user_sortorder is the name of the field in the table into which the value $sortorder is entered. But I'll have another look at it during the weekend to make sure.

The correction you propose is valid.



I plan on editing my first post to include the corrections as soon as possible (and will at least edit it now to point to the corrections - final edition this weekend).

After editing the install instructions I'll just wait a couple more days to find out if any problems are noticed (with the instructions) and then it will be up for submission.

It's been on my test board and on the live board for some time now and no problems were encountered. It does seem though that many members revert back to the standard Oldest First order, only 5% of old members keep the reverse sortorder and only 15% of new members
My board's not broken, it just went peculiar

User avatar
mad_dog_bob
Registered User
Posts: 26
Joined: Tue May 28, 2002 3:25 pm
Location: UK
Contact:

Post by mad_dog_bob » Sat Aug 23, 2003 4:29 pm

Glad to be of help.

My first post was just saying that the SQL was using the wrong variable name ($user_sort_order instead of $sort_order) but I think you've figured out what I was saying now :D


I'm using it on my TacticalTrader site now, and it'll be interesting to see how many people choose newest first - personally I prefer oldest first, but I guess everybody is different!


Thanks again for doing the hard work on this mod,
Rob

User avatar
mad_dog_bob
Registered User
Posts: 26
Joined: Tue May 28, 2002 3:25 pm
Location: UK
Contact:

Post by mad_dog_bob » Wed Aug 27, 2003 9:20 am

Sorry to bother you again...got a couple of suggestions:

In admin/admin_users.php and usercp_register.php instead of:

Code: Select all

        'L_SORT_ASCENDING' => $lang['Sort_Ascending'], 
        'L_SORT_DESCENDING' => $lang['Sort_Descending'], 
I've used

Code: Select all

        'L_SORT_ASCENDING' => $lang['Oldest_First'], 
        'L_SORT_DESCENDING' => $lang['Newest_First'], 
As it makes more sense to the average user :) and ties in with the sort listbox on the viewtopic page.

Also the files modified list at the top of the mod mentions page_header.php, but this isn't modified in the mod. admin/users.php should be admin/admin_users.php

But these are really trivial things, the bulk of the mod is working really well on my site 8)

rob

User avatar
warmweer
Registered User
Posts: 2686
Joined: Fri Jul 04, 2003 6:34 am
Location: Van Allen Belt ... well actually Belgium

Post by warmweer » Wed Aug 27, 2003 4:12 pm

Thanks again mad_dog_bob. I've taken your suggestions into account in version 0.0.2. The errors and ommitances mentioned in previous posts are corrected (again I hope) and I've used Oldest_first and Newest_first (this is clearer, I agree). I've also changed the difficulty level to Easy. I've actually reinstalled it in 8 minutes using EditPlus (which I didn't know existed before coming to phpbb; another credit to this board 8) )

This code has been tested by the online mod validator and after a lot of cursing, sweating, spitting at the screen, hammering the keyboard and gulping down coffee, it finally passed 8O .

I'm still unsure of certain FIND actions (like the long SQLs). Because I fear the FIND wouldn't work on modded boards, I've shortened the find-string to what I think should never be changed by any modding. I hope the IN-LINE FIND then just searches from that point on and finds the first instance of the searchstring.

I would appreciate it if somebody could try it with EasyMod (as this MOD should be EM compatible) (I haven't got EM and won't install it due to my constant modifying) .

I'm pasting the complete code here because just changing my first post would confuse readers (I'll mention this in my edited first post)

edit 23/02/04: removed code - see later post

Code: Select all

 code removed
Last edited by warmweer on Mon Feb 23, 2004 8:56 pm, edited 3 times in total.

Locked

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