PDA

View Full Version : Insert a faux post between the first and second posts


markp_2000
04-28-2013, 07:11 PM
I am trying to insert a faux post between the first and second post of a thread.

I can't quite get if figured out.

I have a template modeled after the postbit template called postbit_faux.


<li class="postbitlegacy postbitim postcontainer" id="post_faux">
<div class="posthead">
<span class="faux-header">Community FAQ</span>
</div>
<div class="postbody">
<div class="postrow">
<div id="post_message_faux">
{vb:raw fauxmessage}
</div>
</div>
</div>
<div class="faux-postfoot">
<a href="faux.php?{vb:raw session.sessionurl}t={vb:raw threadid}"><img src="{vb:stylevar imgdir_button}/edit.gif" alt="{vb:rawphrase edit_delete_lock_faux}" border="0" /></a>
</div>
<hr />
</li>


I am using the following hooks


Hook location: cache_templates

// for a single template
if ($THIS_SCRIPT == 'showthread') {
$cache[] = 'postbit_faux';
}


Hook location: showthread_postbit_create

// posbit
$templater = vB_Template::create('postbit_faux');
$templater->register('fauxmessage',$thread['fauxmessage'];
$templatevalues['fauxmessage'] = $templater->render();
vB_Template::preRegister('SHOWTHREAD', $templatevalues);


The template does not cache (it shows up in red) and the template is not being displayed.

I have been following this thread (https://vborg.vbsupport.ru/showthread.php?t=287225&highlight=preregister) but no love.

I looked at this thread (https://vborg.vbsupport.ru/showthread.php?t=279650) and though the may be the ticket but I did not want to modify the postbit template.

Can I use a hook to accomplish what is in the above thread?

Lynne
04-28-2013, 08:34 PM
The template isn't cached because it isn't $THIS_SCRIPT, it should be simply THIS_SCRIPT.

And what did you add to the SHOWTHREAD template to get this code/template to display? Since all the posts are added by this single line in that template, I really can't see how you think what you are doing is going to add something between the first and second post:

{vb:raw postbits}

markp_2000
04-28-2013, 09:02 PM
I used this if statement to intercept the create of the postbit.

if ($show['fauxcanview'] === true AND $counter == 1 AND $fetchtype == 'post' AND $post['visible'] == 1)
{
MY CODE HERE
}

Lynne
04-28-2013, 09:34 PM
I don't see how that is going to work in the SHOWTHREAD template. $postbits is already defined by the time the template is being rendered, so exactly how are you going to slip a post into that array while in the SHOWTHREAD template?

final kaoss
04-28-2013, 10:38 PM
We already have a mod for inserting messages/ads where you are asking for them.
https://vborg.vbsupport.ru/showthread.php?t=239981

Simply download that and input whatever you want into it.

markp_2000
04-28-2013, 10:47 PM
OK - I missed the last part of my if statement.


if ($show['fauxcanview'] === true AND $counter == 1 AND $fetchtype == 'post' AND $post['visible'] == 1)
{
require_once(DIR . '/includes/class_bbcode.php');
$bbcode_parser =& new vB_BbCodeParser($vbulletin, fetch_tag_list());
$thread['fauxmessage'] = $bbcode_parser->parse($thread['fauxmessage'], $foruminfo['forumid']);

$templater = vB_Template::create('postbit_faux');
$templater->register('fauxmessage',$thread['fauxmessage'];
$templatevalues['fauxmessage'] = $templater->render();
vB_Template::preRegister('SHOWTHREAD', $templatevalues);

eval('$template_hook[\'postbit_end\'] .= "' . fetch_template('postbit_faux') . '";');
}


--------------- Added 1367192936 at 1367192936 ---------------

We already have a mod for inserting messages/ads where you are asking for them.
https://vborg.vbsupport.ru/showthread.php?t=239981

Simply download that and input whatever you want into it.

I'll take a look. We don't what every forum to have this. But I can probably modify to suit.

Mark

final kaoss
04-28-2013, 11:10 PM
It has the ability to exclude usergroups and forums built in :P

markp_2000
04-28-2013, 11:12 PM
We already have a mod for inserting messages/ads where you are asking for them.
https://vborg.vbsupport.ru/showthread.php?t=239981

Simply download that and input whatever you want into it.

Thanks!! I think I see my issue. I need to use the $template_hook.

OK - here is my final code.

I used the showthread_post_start hook location instead of the postbit_display_complete. I don't know if it make a difference both are only called once.


if ($show['fauxcanview'] === true AND $counter == 1 AND $fetchtype == 'post' AND $post['visible'] == 1)
{
$templater = vB_Template::create('postbit_faux');
$templater->register('fauxmessage', $threadinfo['fauxmessage']);
$templater->register('threadid', $threadinfo['threadid']);
$template_hook['postbit_end'] .= $templater->render();
}


Mark

--------------- Added 1367196421 at 1367196421 ---------------

It has the ability to exclude usergroups and forums built in :P

This is not an ad. It is a user created post that can summarize a thread. Such as if a thread goes on for 50 pages you can continue to pull the best or updated info to the front. A good example is when some one here posts a mod and then "reserves" the first post after the mod post. You don't have to do that since you will always have that for your use.