View Full Version : str replace into forumhome_forumbit_level2_post

04 Dec 2009, 18:10
I have read the other threads about this but none had helped me.

I have added an option in the editing/creating a forum page. My option variable is $forum[var].
When I place the variable {vb:raw forum.newoption} directly into forumhome_forumbit_level2_post it works, it displays the data.
So I'm trying to do this via plugin with the following code:

$find = '<p class="theclass">';
$insert = '{vb:raw forum.newoption}';
$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace($find,$find.$insert , $vbulletin->templatecache['forumhome_forumbit_level2_post']);

The plugin works, but I get the variable outputted, not the data that is storing.

After this, I did try using a template, with the variable in it. Then I registered and rendered the template y used that to str replace.

$templater = vB_Template::create('forumhome_mynewoption');
$templater->register('forum', $forum);
$insert = $templater->render();
$find = '<p class="forumdescription">';

$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace($find,$find.$insert , $vbulletin->templatecache['forumhome_forumbit_level2_post']);

This works, but outputs the same data for each forum, even if I just inserted some values in my option in only one forum.

I must say that I'm new creating plugins, maybe I'm missing something.

04 Dec 2009, 18:15
{vb:raw forum.newoption}
is for templates not plugins.

It would be more like the following:

$find = '<p class="theclass">';
$insert = $forum[var];
$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace($find,$find.$insert , $vbulletin->templatecache['forumhome_forumbit_level2_post']);

04 Dec 2009, 18:58
That works as my template approach.
The variable ouput get repeated into the next forum, even is the next has its own value. The second forum shows its value, but the value from the previous forum.

I'm looking into the vBulletin files to see how they do that, I'm not good at this but i'm learning :)

04 Dec 2009, 19:08
can you paste more of your code

Did you set your own variable for $forum or $forum[newoption]

I am not totally understanding what it is you want to do. I think you want to grab the postid for each post.

add this in your code towards the bottom:


Tell me the output that shows above the header.

04 Dec 2009, 19:16
You probably need to zero it out prior to setting it. That way, if you don't set it for that particular forum, it won't show the previous setting.

04 Dec 2009, 19:35
$forum[newoption] is from the options when editing a forum. I've added a new option there:

hook: forumadmin_edit_form

print_input_row($vbphrase['teh_forumicon_desc'], 'forum[iconlocation]', $forum['iconlocation']);

I then validated the data:
hook: forumdata_start
$this->validfields['iconlocation'] = array(TYPE_STR, REQ_NO);

I also added a iconlocation field to the forum table in my database. That part works as spected. It saves the data.

Now using the variable directly into my template it works as spected too: $forum[iconlocation] as {vb:raw forum.iconlocation}

The problem is trying to insert that variable using a plugin:

$find = '<p class="forumdescription">';
$insert = '<img src="'.$forum[iconlocation].'" alt="'.$forum[title].'" />';
$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace($find,$find.$insert, $vbulletin->templatecache['forumhome_forumbit_level2_post']);

I've attaced a screenshot so you can see what i'm talking about.

Also the output for var_dump($forum[iconlocation]); is
string(31) "images/misc/skype_voicemail.gif" string(32) "images/misc/skype_addcontact.gif" string(0) ""

04 Dec 2009, 19:53
try this:

$insert = '<img src="$forum[iconlocation]" alt="$forum[title]" />';

you can remove this:

04 Dec 2009, 20:42
No, that isn't the problem. If I use that I get printed the variable names, not the data.

Thank you for your help, I'm going to release the plugin as it is, and ask the user to make a template edit to insert the html code. I can't make it work.

04 Dec 2009, 23:27
When you release it I will take a look and see if I cant make it work the way you want.

04 Dec 2009, 23:52
It's been released. Actually without automatic template edit the product is useless since the same icon can be added into the forum description without having to modify templates :(


05 Dec 2009, 02:31
Well after looking whats wrong with a template?

Just do a auto template with in the xml file.

05 Dec 2009, 11:43
Here's an example of how I do it. Not sure what issues your code is having.
/* If you want to edit the template yourself, by default this latches on to threadbit on <div class="threaddetailicons">
and adds the contents of the threadbit_stafftracker template right after it. */

$threadbitsearch = '<div class="threaddetailicons">';
if (isset($vbulletin->templatecache['threadbit'])) {
$vbulletin->templatecache['threadbit'] = str_replace($threadbitsearch, $threadbitsearch . vB_Template::fetch_template_raw('threadbit_stafftracker'), $vbulletin->templatecache['threadbit']);

Essentially, call your template using vB_Template::fetch_template_raw('templatename') - that way it pulls the raw code needed to be eval'd at the end. If you do it that way, it shouldn't fail. Good luck.

06 Dec 2009, 01:04
Hey Elmer sorry it took so long been busy.

Here is what you are looking for:

$vbulletin->templatecache['forumhome_forumbit_level2_post'] = str_replace(array('<p class="forumdescription">'), array('<p class="forumdescription"><img src="\' . $forum[\'iconlocation\'] . \'" alt="\' . $forum[\'title\'] . \'" />'), $vbulletin->templatecache['forumhome_forumbit_level2_post']);

Make a plugin with the hook location process_templates_complete
I named mine "Forum Icon Template Replacement"

Put the code from above in there.

Be advised there is no if statement so it shows for every forum even if there is no icon in place I left that for you to do.

06 Dec 2009, 22:08
Thaks BBR, I will try again, I'll let you know if it works.