vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   "If is first post" within a plugin PHP code (https://vborg.vbsupport.ru/showthread.php?t=275713)

Infoman4ever 12-20-2011 01:59 PM

"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.

kh99 12-20-2011 02:24 PM

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.

Infoman4ever 12-20-2011 02:39 PM

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'?

kh99 12-20-2011 02:44 PM

Code:

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


Infoman4ever 12-20-2011 02:58 PM

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?

kh99 12-20-2011 03:03 PM

Quote:

Originally Posted by Infoman4ever (Post 2279433)
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'].

Infoman4ever 12-20-2011 03:08 PM

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?

kh99 12-20-2011 03:10 PM

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?

Infoman4ever 12-20-2011 03:15 PM

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 :)

kh99 12-20-2011 03:21 PM

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).


All times are GMT. The time now is 01:13 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.01114 seconds
  • Memory Usage 1,747KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete