View Full Version : str replace into forumhome_forumbit_level2_post
Elmer
12-04-2009, 04:10 PM
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.
BBR-APBT
12-04-2009, 04:15 PM
{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']);
Elmer
12-04-2009, 04:58 PM
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 :)
BBR-APBT
12-04-2009, 05:08 PM
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:
var_dump($forum[newoption]);
Tell me the output that shows above the header.
Lynne
12-04-2009, 05:16 PM
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.
Elmer
12-04-2009, 05:35 PM
$forum[newoption] is from the options when editing a forum. I've added a new option there:
hook: forumadmin_edit_form
print_table_header($vbphrase['teh_forumicon']);
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']);
var_dump($forum[iconlocation]);
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) ""
BBR-APBT
12-04-2009, 05:53 PM
try this:
$insert = '<img src="$forum[iconlocation]" alt="$forum[title]" />';
you can remove this:
var_dump($forum[iconlocation]);
Elmer
12-04-2009, 06:42 PM
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.
BBR-APBT
12-04-2009, 09:27 PM
When you release it I will take a look and see if I cant make it work the way you want.
Elmer
12-04-2009, 09:52 PM
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 :(
https://vborg.vbsupport.ru/showthread.php?p=1925448
BBR-APBT
12-05-2009, 12:31 AM
Well after looking whats wrong with a template?
Just do a auto template with in the xml file.
Link14716
12-05-2009, 09:43 AM
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_stafftr acker'), $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.
BBR-APBT
12-05-2009, 11:04 PM
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.
Elmer
12-06-2009, 08:08 PM
Thaks BBR, I will try again, I'll let you know if it works.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2024, vBulletin Solutions Inc.