Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 12-20-2011, 01:59 PM
Infoman4ever Infoman4ever is offline
 
Join Date: Oct 2011
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default "If is first post" within a plugin PHP code

Hello folks,
I got a question, I want know what's the condition that says whether it's the first post of a given thread or not within a "plugin" (which is linked to "showthread_postbit_create" hook), it's the equivalent of :
PHP Code:
<vb:if condition="$post['isfirstshown']">something</vb:if> 
of the template side, right?
Thanks in advance.
Reply With Quote
  #2  
Old 12-20-2011, 02:24 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

That hook is called before the isfirstshown is set, but you can use this:

Code:
if ($counter == 1 AND $fetchtype == 'post' AND $post['visible'] == 1)
{
}

Also, that hook is called froom some scripts other than showthread (newreply.php, editpost.php, comments.php). The above might work because $fetchtype is probably not set in the other scripts, but you could add THIS_SCRIPT == 'showthread' to be safe.
Reply With Quote
  #3  
Old 12-20-2011, 02:39 PM
Infoman4ever Infoman4ever is offline
 
Join Date: Oct 2011
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nice, it works except something, I have something to add just to the first post, but -and you're right about the hook- now I'm getting it for each post of the thread, what's the point kh99?
And where to put THIS_SCRIPT == 'showthread'?
Reply With Quote
  #4  
Old 12-20-2011, 02:44 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Code:
if (THIS_SCRIPT == 'showthread' AND $counter == 1 AND $fetchtype == 'post' AND $post['visible'] == 1)
{
}
Reply With Quote
  #5  
Old 12-20-2011, 02:58 PM
Infoman4ever Infoman4ever is offline
 
Join Date: Oct 2011
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thank you dear but unluckily it still the same problem, it shows the thing in every post, very annoyed. I think it's logical, as long as we're on the same thread, "showthread_postbit_create" should be called in all posts of the same thread, or what?
Reply With Quote
  #6  
Old 12-20-2011, 03:03 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Infoman4ever View Post
Thank you dear but unluckily it still the same problem, it shows the thing in every post, very annoyed. I think it's logical, as long as we're on the same thread, "showthread_postbit_create" should be called in all posts of the same thread, or what?
Yes but $counter should only be 1 for the first post. That if condition I posted above is exactly the same as is used to set $post['isfirstshown'].
Reply With Quote
  #7  
Old 12-20-2011, 03:08 PM
Infoman4ever Infoman4ever is offline
 
Join Date: Oct 2011
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Wow, I printed the $counter and I found it's the same (is 1) on every post, it's weird, does this make sense to you?
Reply With Quote
  #8  
Old 12-20-2011, 03:10 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

No, it doesn't. You said you're using hook location showthread_postbit_create, right? You could post your plugin code if you want us to check it out.

Edit: Actually it might make some sense - are you using threaded or hybrid display mode?
Reply With Quote
  #9  
Old 12-20-2011, 03:15 PM
Infoman4ever Infoman4ever is offline
 
Join Date: Oct 2011
Posts: 23
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Absolutely I could:
PHP Code:
<?php
if($vbulletin->options['data_onoff']){

if(
THIS_SCRIPT == 'showthread' AND $counter == AND $fetchtype == 'post' AND $post['visible'] == 1)
{
$result $db->query("SELECT data FROM thread WHERE threadid = ".$threadid);
$fetch $db->fetch_array($result);
$find '<span class="date">';
$replace '<span class="date"> - '.$fetch['data'] ; 
$vbulletin->templatecache['postbit_legacy'] = str_replace($find$replace$vbulletin->templatecache['postbit_legacy']);
}
}
?>
That's it and the hook is double checked: showthread_postbit_create.
Honestly I don't know what the display mode is
Reply With Quote
  #10  
Old 12-20-2011, 03:21 PM
kh99 kh99 is offline
 
Join Date: Aug 2009
Location: Maine
Posts: 13,185
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Oh...well the reason that it's showing up in every post is because you're changing the cached template, which is used for every post. And if you inserted the value of $counter in the template, it would of course always show a value of 1.

What you could do is, instead of modifying the cached template for every post, change it once and insert some php code that checks $post['isfirstshown']. That will get even trickier because you need to make the replacement string so that the resulting cached template is valid php code that build the string you want. (I hope that makes sense).
Reply With Quote
Reply

Thread Tools
Display Modes

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 09:06 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.05045 seconds
  • Memory Usage 2,250KB
  • Queries Executed 13 (?)
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
  • (2)bbcode_code
  • (2)bbcode_php
  • (1)bbcode_quote
  • (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
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (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
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete