Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 02-07-2013, 12:35 AM
addamroy addamroy is offline
 
Join Date: Sep 2010
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Determine thread position in the threadlist

I have some ideas running around in my head but can't put my finger on how to make it happen.

Anyway what I want to accomplish somehow is...

possibly a conditional or a variable of some sort to determine a threads position in the threadlist. A conditional that I could use in SHOWTHREAD template.

For example,

In the showthread template I could add a line of code somewhere that says "Your thread is at X position in this forum" Where X would be the threads position in the thread list for that forum section.

Or I could use a conditional somehow, if X >= 20 then display a message that says "your thread is no longer on the first page.

Either way I'm just curious if there's any way to get the position of a thread, and have that be usable in the showthread template.
Reply With Quote
  #2  
Old 02-07-2013, 02:43 AM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

How would you determine which thread of the user's to check for? Would you just want it to check their "latest" thread?

--------------- Added [DATE]1360208626[/DATE] at [TIME]1360208626[/TIME] ---------------

Will it be every forum, or just one?
Reply With Quote
  #3  
Old 02-07-2013, 02:55 AM
addamroy addamroy is offline
 
Join Date: Sep 2010
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I was thinking in just one forum for now, and yes that message would only show if it's their own thread.

I know how to show the message in certain forums, in the right spot and only for the thread owner, but can't for the life of me figure out a way to determine the thread's position so I can use that info too
Reply With Quote
  #4  
Old 02-07-2013, 03:02 AM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Will it be for the user's most recent thread? or all threads like "your threads are in position 8 and 14" or "your thread is in position 4" for just their most recent?
Reply With Quote
  #5  
Old 02-07-2013, 03:14 AM
addamroy addamroy is offline
 
Join Date: Sep 2010
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It will show ON the thread they are viewing.

For example - This thread is at position 7
Reply With Quote
  #6  
Old 02-07-2013, 03:20 AM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

This also depends on your forum sort order. what would that be?

--------------- Added [DATE]1360212358[/DATE] at [TIME]1360212358[/TIME] ---------------

This should help you A LOT. I am not sure if it needs to go into showthread_start or showthread_complete but the code is sound. may need a bit of tweaking. Hope it helps.

Code:
$current_thread = $threadinfo['threadid'];
$current_thread_forum = $threadinfo['forumid'];
$thread_owner = $threadinfo['postuserid'];
$current_user = $bbuserinfo['userid'];
$forum_id = 2;

if ($current_thread_forum == $forum_id) {
  if ($thread_owner == $current_user) {
    $query = $vbulletin->db->query_first('set @row_num = 0; SELECT @row_num := @row_num + 1 as row_number,threadid,postuserid,title FROM thread WHERE forumid = ' . $forum_id . ' AND postuserid = ' . $current_user . ' ORDER BY dateline DESC LIMIT 1;');
    $position = $query['row_number'];
    $display = "This thread is at position: " . $position;
    vB_Template::preRegister('SHOWTHREAD',array('display' => $display));
  }
}
Then you should be able to use {vb:raw display} in the SHOWTHREAD template.
Reply With Quote
  #7  
Old 02-07-2013, 09:15 PM
addamroy addamroy is offline
 
Join Date: Sep 2010
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for the help I appreciate it!

Unfortunately that didn't work using either showthread_complete or showthread_start

PS - My threads are sorted by start time
Reply With Quote
  #8  
Old 02-08-2013, 01:17 PM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It does work, run this query inside phpmyadmin or whatever you use.

Code:
set @row_num = 0; SELECT @row_num := @row_num + 1 as row_number,threadid,postuserid,title FROM thread WHERE forumid = # AND postuserid = ## ORDER BY dateline DESC LIMIT 1;
# = forumid is the forum you want to use the mod in
## = userid , just make it one to run test on admin first user

will return row of thread with its placement. if you remove "LIMIT 1" it will show more threads.

--------------- Added [DATE]1360336817[/DATE] at [TIME]1360336817[/TIME] ---------------

ill revise the code in a bit. i forgot something.

--------------- Added [DATE]1360346941[/DATE] at [TIME]1360346941[/TIME] ---------------

Here is the final working and tested code. It will show the position of the thread based on start date, not last reply. With new threads being position 1. (if you would like it the other way around change "DESC" to "ASC" in the $query)

PHP Code:
$current_thread $thread['threadid'];
$current_thread_forum $thread['forumid'];
$thread_owner $thread['postuserid'];
$current_user $vbulletin->userinfo['userid'];
$forum_id 2;

if (
$current_thread_forum == $forum_id) {
  if (
$thread_owner == $current_user) {
    
$vbulletin->db->query_write('set @row_num = 0;');
    
$query $vbulletin->db->query_read_slave(
        
'SELECT (SELECT @row_num := @row_num + 1) 
        AS row_number,threadid,postuserid
        FROM ' 
TABLE_PREFIX 'thread
        WHERE forumid = ' 
$forum_id 
        ORDER BY dateline DESC'
        
);

    while(
$query2 $vbulletin->db->fetch_array($query)) {
        if (
$query2['threadid'] == $current_thread && $query2['postuserid'] == $current_user) {
                
$position $query2['row_number'];
                
$display "<p id='pos-text-main'><span>This thread is at position:</span> <span id='pos-num'>" $position "</span></p>";
        }
    }

    
vB_Template::preRegister('SHOWTHREAD',array('display' => $display));
  }

add that code to a new plugin with hook showthread_complete

Then add the following where you want it inside of SHOWTHREAD.
{vb:raw display}

I have added some span id's so you can style it how you'd like.

Be sure to change $forum_id to the forum you'd like this running in.

--------------- Added [DATE]1360347115[/DATE] at [TIME]1360347115[/TIME] ---------------

Here is a sample CSS to add to additional.css

Code:
p#pos-text-main {
	background: rgb(255, 202, 202);
	border: 1px solid rgb(184, 0, 0);
	margin: 10px 0;
	padding: 10px;
}
span#pos-num {
	font-weight: bold;
}
It will only show for the thread author. Example attached.
Attached Images
File Type: png Untitled.png (13.6 KB, 0 views)
Reply With Quote
Благодарность от:
addamroy
  #9  
Old 02-09-2013, 12:43 PM
addamroy addamroy is offline
 
Join Date: Sep 2010
Posts: 352
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Perfect!
Reply With Quote
  #10  
Old 02-09-2013, 01:10 PM
LifesGreatestGift's Avatar
LifesGreatestGift LifesGreatestGift is offline
 
Join Date: Jul 2009
Location: Louisville, KY USA
Posts: 885
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

forgot to add the p and span to final code check now
Reply With Quote
Благодарность от:
obglobal.net
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:10 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06597 seconds
  • Memory Usage 2,297KB
  • Queries Executed 14 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (3)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (2)post_thanks_box_bit
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (1)postbit_attachment
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_attachment
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete