PDA

View Full Version : Creating Addons


Black Snow
09-09-2014, 07:15 AM
Hi,

I have a few different themes on my board and when ever I install a new theme, I have to make manual edits to make everything fit the way I want it to.

For example: I have the post thanks mod installed and I have changed the look of the "thanks box". So I uploaded a new theme, and I have to go into it and edit the thanks box to look the same as the other themes.

I'm looking for someone who can help me create (more to the point, learn) an addon so I can make my own in the future for this kind of situation.

Thanks

cellarius
09-09-2014, 07:39 AM
You want to recreate an existing addon from scratch just because you have to make some style edits? How often do you install new styles :eek:

ozzy47
09-09-2014, 08:58 AM
Some mods are going to be that way, if they use their own classes, vs using built in classes.

Even if you were to us built in classes, it would be using a stylevar, which you would have to change to suit your needs. Or create your own class, assign it a stylevar, and change it for each style.

For most mods, it is much easier just to edit the template, or the CSS for the mod in that style.

Black Snow
09-09-2014, 09:35 AM
You want to recreate an existing addon from scratch just because you have to make some style edits? How often do you install new styles :eek:

I am always changing the layout of the forum, adding new things, removing other things. When I do it to one style, I need to do it to the other styles. I want to make an addon so I can make the edit once, and install it so I don't need to manually edit each style. It will use stylevars eventually to fit with each style but for now I want to make a basic addon to do what I'm asking.

ozzy47
09-09-2014, 09:38 AM
There is no tutorial, basically you have to know, php, html, css, and have a understanding of how vBulletin works. Then take it and put it all together.

PHP, basic guide: PHP 5 Tutorial (http://www.w3schools.com/php/)

HTML basic guide: HTML Tutorial - (HTML5 Compliant) (http://www.w3schools.com/html/)

CSS basic guide: CSS Tutorial (http://www.w3schools.com/css/)

vBulletin basic mod guide: Creating a Product (http://www.vbulletin.com/docs/html/creating_a_product)

Black Snow
09-09-2014, 09:48 AM
There is no tutorial, basically you have to know, php, html, css, and have a understanding of how vBulletin works. Then take it and put it all together.

PHP, basic guide: PHP 5 Tutorial (http://www.w3schools.com/php/)

HTML basic guide: HTML Tutorial - (HTML5 Compliant) (http://www.w3schools.com/html/)

CSS basic guide: CSS Tutorial (http://www.w3schools.com/css/)

vBulletin basic mod guide: Creating a Product (http://www.vbulletin.com/docs/html/creating_a_product)

Hi ozzy47,

I understand PHP, HTML & CSS to a degree. I was looking at your recent mod: https://vborg.vbsupport.ru/showthread.php?t=314177

What I don't understand yet is, if I create an addon (say to replace the post thanks box look) and include my code, will it automatically overwrite the default thanks box code from the post thanks mod? Or do I need to do something to overwrite the default code?/

Scanu
09-09-2014, 10:24 AM
Well actually if you only need to keep changes in templates of a mod, you need to turn on debug mode and edit the template on the master style. This way when you add a new style you won't need to change templates again. However if you still want to know how to make an addon and you already have php and html knowledge you can look for a tutorial ppsted on vb.com on how to make a vb5 extension, it's almost the same

Black Snow
09-09-2014, 10:30 AM
Well actually if you only need to keep changes in templates of a mod, you need to turn on debug mode and edit the template on the master style. This way when you add a new style you won't need to change templates again. However if you still want to know how to make an addon and you already have php and html knowledge you can look for a tutorial ppsted on vb.com on how to make a vb5 extension, it's almost the same

I thought that you could only edit the master theme with child themes if they were the same theme? I have 6 completely different themes. I will have a look for the article you mentioned.

TheLastSuperman
09-09-2014, 08:49 PM
I am always changing the layout of the forum, adding new things, removing other things. When I do it to one style, I need to do it to the other styles. I want to make an addon so I can make the edit once, and install it so I don't need to manually edit each style. It will use stylevars eventually to fit with each style but for now I want to make a basic addon to do what I'm asking.

Try doing it this way then:
https://vborg.vbsupport.ru/showthread.php?t=307739

One plugin could seemingly manipulate all styles to suit, you can define differences there as well.

Edit: Do not turn on debug mode and edit your master style, no!

TheLastSuperman
09-09-2014, 08:50 PM
Well actually if you only need to keep changes in templates of a mod, you need to turn on debug mode and edit the template on the master style.

That is not advised.

Scanu
09-10-2014, 04:32 AM
That is not advised.
Why? If that is a public board you mean?

cellarius
09-10-2014, 05:32 AM
Because the master style will be overwritten when he next upgrades. And I don't imagine he fancies redoing all his styling after every upgrade :)

Black Snow
09-10-2014, 08:52 AM
Try doing it this way then:
https://vborg.vbsupport.ru/showthread.php?t=307739

One plugin could seemingly manipulate all styles to suit, you can define differences there as well.

Edit: Do not turn on debug mode and edit your master style, no!

Thanks for the link and info. It's not simply just the CSS I want to change, it's the template I want to change too. I have edited the Post Thanks box template and renamed certain <DIV> classes and added new div's also. So I want to make a plugin OR addon which will overwrite the default code/template.

ozzy47
09-10-2014, 09:02 AM
O create a new template, in each style, with the exact contents you want. Then create this plugin using the hook location, template_render_output

if ($this->template == 'OLD TEMPLATE NAME')
{
$this->template = 'NEW TEMPLATE NAME';
}

ozzy47
09-10-2014, 09:23 PM
Ohhh, I should also add you will need to cache that new template, using the hook location, cache_templates like so.

$cache = array_merge($cache, array
(
'NEW TEMPLATE NAME',
)
);

tbworld
09-11-2014, 12:20 AM
For a single template, just append to the end of the existing array. Use:


cache[] = 'NEW_TEMPLATE_NAME';

ozzy47
09-11-2014, 12:26 AM
Yeah that's true. :)

Black Snow
09-12-2014, 08:49 AM
O create a new template, in each style, with the exact contents you want. Then create this plugin using the hook location, template_render_output

if ($this->template == 'OLD TEMPLATE NAME')
{
$this->template = 'NEW TEMPLATE NAME';
}

It didn't work. It doesnt do anything.

ozzy47
09-12-2014, 09:11 AM
Sure it does, I have used this for a couple of years now. Did you make sure to add the correct template names?

Black Snow
09-12-2014, 11:11 AM
Sure it does, I have used this for a couple of years now. Did you make sure to add the correct template names?

Yup. I made the plugin:
if ($this->template == 'post_thanks_box')
{
$this->template = 'custom_post_thanks_box';
}

Made a new template called "custom_post_thanks_box" and put my code in it.

ozzy47
09-12-2014, 11:52 AM
If you want, pm me a admin account and I can see if I can figure it out when I get home today.

Black Snow
09-17-2014, 03:01 PM
O create a new template, in each style, with the exact contents you want. Then create this plugin using the hook location, template_render_output

if ($this->template == 'OLD TEMPLATE NAME')
{
$this->template = 'NEW TEMPLATE NAME';
}

I eventually got this to work. Not sure why it won't work on my custom pages.

Anyway, is there any way to use the above code and have 10 different templates changed using an array or something like this?

if ($this->template == 'OLD TEMPLATE NAME 1')
{
$this->template = 'NEW TEMPLATE NAME 1';
}
if ($this->template == 'OLD TEMPLATE NAME 2')
{
$this->template = 'NEW TEMPLATE NAME 2';
}
if ($this->template == 'OLD TEMPLATE NAME 3')
{
$this->template = 'NEW TEMPLATE NAME 3';
}
if ($this->template == 'OLD TEMPLATE NAME 4')
{
$this->template = 'NEW TEMPLATE NAME 4';
}
So instead of a new plugin for each template I change something in, I can do it all in one plugin.

cellarius
09-17-2014, 05:38 PM
I eventually got this to work. Not sure why it won't work on my custom pages.
Probably you did not cache your custom template. If it's not in the cache, there's nothing to replace. It will be queried directly from the database as is.

Anyway, is there any way to use the above code and have 10 different templates changed using an array or something like this?

if ($this->template == 'OLD TEMPLATE NAME 1')
{
$this->template = 'NEW TEMPLATE NAME 1';
}
if ($this->template == 'OLD TEMPLATE NAME 2')
{
$this->template = 'NEW TEMPLATE NAME 2';
}
if ($this->template == 'OLD TEMPLATE NAME 3')
{
$this->template = 'NEW TEMPLATE NAME 3';
}
if ($this->template == 'OLD TEMPLATE NAME 4')
{
$this->template = 'NEW TEMPLATE NAME 4';
}
So instead of a new plugin for each template I change something in, I can do it all in one plugin.
You don't need more than one plugin. You can put that code as is into one plugin. Of course you could also do something like

$replace = array(
'old1' => 'new1',
'old2' => 'new2',
'old3' => 'new3'
);

foreach ($replace as $key => $value)
{
if ($this->template == $key)
{
$this->template = $value;
}
}

Black Snow
09-17-2014, 05:43 PM
Thanks for that. I will test it out.

Black Snow
09-18-2014, 06:17 PM
I want to add something under the navbar. How do I add something to the end of the navbar temaplate OR include a template after the navbar? I'm not quite sure on using the pre-defined hooks or add new hooks into templates.

cellarius
09-18-2014, 08:13 PM
See https://vborg.vbsupport.ru/showthread.php?t=228078

Black Snow
09-19-2014, 07:27 AM
See https://vborg.vbsupport.ru/showthread.php?t=228078

I havd a look and not sure what I am doing wrong. This is my plugin:

$templater = vB_Template::create('custom_template');
$templater->register('custom_template', $custom_template);
$template_hook['postbit_userinfo_right_after_posts'] .= $templater->render();

It doesn't show the contents of custom_template after user posts using hook location postbit_display_complete.

--------------- Added 1411115460 at 1411115460 ---------------

Sorry, I never added the cache and it now shows. Does the code I used above look OK?

I have now added a new plugin for the forumhome using forumhome_complete hook location. I want it to show at the end of the navbar template. How do I insert my OWN custom template hook into the navbar template without having to manually edit the navbar template?

Black Snow
09-28-2014, 02:32 PM
How do I add my own CSS to the additional.css template using a plugin?

ozzy47
09-28-2014, 02:34 PM
You can't, you need to include your own css template, and call it in the script.

Black Snow
09-29-2014, 12:26 PM
This is more for ozzy47 lol as I have used your mod [OzzModz] Change Forumrow Color On Mouseover as an example to make my own mod. I am making this plugin to change the background of moderated posts, does this look OK?

global $vbulletin;

if (THIS_SCRIPT == 'showthread') {
if ($vbulletin->options['mod_post_background_enable'])
{
if ($vbulletin->options['storecssasfile'])
{
$template_hook['custom_css_links'] .= '<link type="text/css" rel="stylesheet" href="' . vB_Template::fetch_css_path() . 'mod_post_background_color.css' . '?d=' . $style['dateline'] . '" />';
} else {
$template_hook['custom_css_list'] .= 'mod_post_background_color.css';
}

$find = '<div class=\"postbody\">';
$replace = '<div class=\"postbody <vb:if condition="$show['moderated']">moderated</vb:if>\">';
$vbulletin->templatecache['postbit_legacy'] = str_replace($find, $replace, $vbulletin->templatecache['postbit_legacy']);
}
}

I am unsure if I escaped the quotes properly or if it is working. What's the quickest way to making a moderated post also?

ozzy47
09-29-2014, 12:54 PM
Looks ok, but I on my mobile, so hard to tell.

Just moderate the post with the moderation tools menu when viewing a post.

Black Snow
09-29-2014, 01:04 PM
I have spent the last 2 hours trying to get it to work. Im not sure if I'm using the wrong hook location (it's parse_templates at the moment) or theres something else wrong.

ozzy47
09-29-2014, 01:12 PM
I can check when I get off work. Where exactly is the color change supposed to show?

Black Snow
09-29-2014, 01:13 PM
The background of the post should change. I'm trying to get this edit to be a mod.

https://vborg.vbsupport.ru/showthread.php?t=285655

ozzy47
09-29-2014, 01:16 PM
All right, I'll look when I get home later today.

Black Snow
09-29-2014, 01:21 PM
All right, I'll look when I get home later today.

Thanks mate. Heres the addon im trying to make so you can test it.

ozzy47
09-29-2014, 01:54 PM
There might be a easier way to do it, I'll look into it later.

Black Snow
09-29-2014, 01:55 PM
OK cool. I want it to be an addon so I can add options to it later.

--------------- Added 1412024571 at 1412024571 ---------------

Spend another 3 hours researching the issue and can't find the problem

ozzy47
09-29-2014, 08:39 PM
Ok here it is. I also added the missing settings for the mod, and set the product URL and the version check URL.

I would suggest creating a stylevar for the background color, instead of having it hardcoded or as a option in the settings. This way the end user can have different colors for different styles.

I would uninstall your version, then load this one up. :)

Black Snow
09-29-2014, 08:44 PM
Thanks. Can you tell me what you added so I know for next time?

ozzy47
09-29-2014, 08:46 PM
Just compare your version to mine. :) It was not much of a change.

Black Snow
09-29-2014, 08:58 PM
Uploaded it and it doesn't work for me lol

ozzy47
09-29-2014, 09:00 PM
Are you sure the post is moderated?

ozzy47
09-29-2014, 09:01 PM
Wait, I had the template edit in, give me a bit.

Black Snow
09-29-2014, 09:01 PM
I unapproved the post and it shows Moderated Post next to the post ID

ozzy47
09-29-2014, 09:08 PM
Ok give me a bit to work it out.

ozzy47
09-30-2014, 12:26 AM
I am getting close on this. Had to completely re write the regex for the replacement.

Now I just have to get the css to get in place.

Black Snow
09-30-2014, 06:59 AM
I didn't think it would be that hard to use the str_replace function. It looks easy enough when looking at other mods/articles.

Black Snow
09-30-2014, 10:01 AM
OK cool. Thanks very much ozzy.

Why is it so hard to do a str_replace on that div?

Black Snow
09-30-2014, 10:02 AM
Not sure how my post just inserted itself before yours although I was replying to you lol. And how did you post at 12:07 when vB states its 12:02 at the bottom of the page?

ozzy47
09-30-2014, 10:07 AM
The issue is what we are trying to replace with. I had looked into this just about a year ago and failed. I have just about got it right as of now, but I neet to test it against other mods to make sure it won't break them.

So hopefully later today I will have this ready. :)

Black Snow
09-30-2014, 10:40 AM
I did reply to you ozzy but the posts went above your last post for some reason.

Black Snow
09-30-2014, 11:33 AM
Haha! Something wrong with vB then.

Well at least your getting something out of helping me. Be nice to have all your temp mods as real mods.

ozzy47
09-30-2014, 11:39 AM
Who knows what's going on with the post times. :confused: I noticed it happen yesterday as well.

As for the str_replace it is difficult because of what we are adding, it needs to be done while the template is being compiled, but I got it working, so I should have this ready for you later today.

Good thing is now I can redo my template modifications, that did something similar and turn them into real mods. :)

Black Snow
09-30-2014, 12:02 PM
After an addon is made and you are testing it, how can you test what the output is? Can you use print or echo to see the output of your code?

ozzy47
09-30-2014, 09:28 PM
Ok here it is.

I added the stylevar for the background also for you.

ozzy47
09-30-2014, 10:15 PM
There is one change you need to make th the CSS template. Remove what is in there and replace it with this:

.postbitlegacy .postbody_moderated, .eventbit .eventdetails .eventbody {
margin-{vb:stylevar left}: {vb:stylevar postbitlegacy_userinfo_width};
border-{vb:stylevar left}: {vb:stylevar postbit_userinfo_border};
background: {vb:stylevar mod_post_background_color};
padding-bottom: -1em;
}I forgot I had some of the values hard coded for testing.

Black Snow
10-01-2014, 06:56 AM
Still nothing happening for me when I install it and make the changes. I think I also need to make the settings for the background colour as there is only the setting to enable the mod.

You can see on the attached image that the post is moderated and the div class is still postbody.

ozzy47
10-01-2014, 09:00 AM
Wierd, it should be showing as moderated. Care to send me a admin account so I can see what is going on?

ozzy47
10-01-2014, 09:32 AM
I just tested this on a vanilla vB4 site and it is working, so I would need to debug what is going on with your site that is stopping the mod from working.

Black Snow
10-02-2014, 06:36 AM
How do I go about debugging to find the cause of the problem?

ozzy47
10-02-2014, 09:17 AM
Not sure, depends on alot of different variables.

Black Snow
10-02-2014, 09:34 AM
Wierd, it should be showing as moderated. Care to send me a admin account so I can see what is going on?

PM sent.

--------------- Added 1412248438 at 1412248438 ---------------

I installed the mod again and for some reason it now changes the postbody class to postbody_moderated. Not sure why it's working now or what happened. But it now need the CSS to work.

ozzy47
10-02-2014, 09:04 PM
This has been fixed on the users site.

Black Snow, make sure you change the CSS in the master style to what I mentioned earlier.

.postbitlegacy .postbody_moderated, .eventbit .eventdetails .eventbody {
margin-{vb:stylevar left}: {vb:stylevar postbitlegacy_userinfo_width};
border-{vb:stylevar left}: {vb:stylevar postbit_userinfo_border};
background: {vb:stylevar mod_post_background_color};
padding-bottom: -1em;
}

Or export the current XML, make the change, then re import.

Black Snow
10-03-2014, 08:24 AM
Thanks again ozzy. I am trying to make new stylevars for the mod. When I fill in all the boxes, select the product and click save, I get this error:

A required field called product is missing or has an invalid value.
Any idea what it means or why it's happening?

ozzy47
10-03-2014, 09:09 AM
Not sure, can't say I ever came across that before.

Black Snow
10-03-2014, 09:14 AM
It works fine most of the time but now and then it pops up with that error and I can't add a stylevar to the product.

ozzy47
10-03-2014, 09:20 AM
Try disabling hooks via includes/config.php and try again.

Black Snow
10-03-2014, 09:41 AM
Try disabling hooks via includes/config.php and try again.

Still get the same error. I had it before and I had to delete the product and make it again from scratch.

ozzy47
10-03-2014, 09:45 AM
Has to be something on your site, I just tried to add another stylevar to the mod and was successful.

ozzy47
10-03-2014, 10:18 AM
Anything in the error logs?

Black Snow
10-03-2014, 10:29 AM
It's not the mod you helped with, it's a fresh mod I'm making stylevars for.

ozzy47
10-03-2014, 11:40 AM
If you pm me the XML file on my site, I can look at it later today.

Black Snow
10-03-2014, 11:48 AM
If you pm me the XML file on my site, I can look at it later today.

I will later. Does this look OK? I am wanting to make an option to choose whether links are underlined or not when hovered over. I have made the option for the mod and if selected yes, then links will be underlined. If selected no, they won't be.

if ($vbulletin->options['url_active']) {

if ($vbulletin->options['url_text_decoration']) {
$decoration = 'underline';
}else{
$decoration = 'none';
}
}


vB_Template::preRegister('url.css',array('decorati on' => $decoration));

Then in url.css I have this:
text-decoration: $decoration;

Black Snow
10-14-2014, 09:12 AM
How do I go about adding a setting from a mod into a plugin?

I want to add an input box into my mod which an admin can enter a URL or name etc, then have the setting output the value via a plugin.

--------------- Added 1413282284 at 1413282284 ---------------

I know I can add this to a template:
{vb:raw vboptions.this_settings}
But I wondered if I can also add it into a plugin or is there a different way to do it?

I suppose I would be better off creating a template, putting my code inside it, then running a plugin to call the template to insert it inside the showthread template?

ozzy47
10-14-2014, 11:32 AM
Kinda hard to say without 1, seeing your code, 2, knowing what it is you are trying to do and 3, knowing what the expected end result is desired.

Black Snow
10-14-2014, 11:40 AM
Sorry, I was in the middle of making it work. I got it in the end. I am looking for your help ozzy, I will PM you my question.

--------------- Added 1413304843 at 1413304843 ---------------

Looking for a way to show all available forums so I can make my mod work on only chosen forums. Any tutorial about how to achieve this?

Black Snow
10-31-2014, 08:56 AM
Is there a way to remove a chunk of code from a template using plugins? I know about the str_replace function but what about removing 20 lines from a template?

SHOWTHREAD template for example, how would I remove this:
<vb:if condition="$show['threadrating']">
<li class="popupmenu" id="threadrating">
<h6><a class="popupctrl" href="javascript://">{vb:rawphrase rate_this_thread}</a></h6>
<div class="popupbody popuphover">
<form action="threadrate.php" method="post" id='showthread_threadrate_form'>
<ul>
<li id="threadrating_current"<vb:if condition="!$show['rating']">class="hidden"</vb:if> title="{vb:rawphrase thread_rating_x_votes_y_average, {vb:raw thread.votenum}, {vb:raw thread.voteavg}}"><label>
<span class="rating r{vb:raw thread.rating}<vb:if condition="$thread['rating'] != 5">_{vb:stylevar right}</vb:if>">{vb:rawphrase current_rating}</span>
</label></li>
<vb:if condition="$show['ratethread']">
<li><label for="r5"><span class="rating r5">
{vb:stylevar dirmark}<input type="radio" name="vote" value="5" id="r5" {vb:raw votechecked.5} tabindex="20" /> {vb:rawphrase excellent}
</span></label></li>
<li><label for="r4"><span class="rating r4_{vb:stylevar right}">
{vb:stylevar dirmark}<input type="radio" name="vote" value="4" id="r4" {vb:raw votechecked.4} tabindex="21" /> {vb:rawphrase good}
</span></label></li>
<li><label for="r3"><span class="rating r3_{vb:stylevar right}">
{vb:stylevar dirmark}<input type="radio" name="vote" value="3" id="r3" {vb:raw votechecked.3} tabindex="22" /> {vb:rawphrase average}
</span></label></li>
<li><label for="r2"><span class="rating r2_{vb:stylevar right}">
{vb:stylevar dirmark}<input type="radio" name="vote" value="2" id="r2" {vb:raw votechecked.2} tabindex="23" /> {vb:rawphrase bad}
</span></label></li>
<li><label for="r1"><span class="rating r1_{vb:stylevar right}">
{vb:stylevar dirmark}<input type="radio" name="vote" value="1" id="r1" {vb:raw votechecked.1} tabindex="24" /> {vb:rawphrase terrible}
</span></label></li>
<li class="formsubmit"><input type="submit" class="button" value="{vb:rawphrase vote_now}" tabindex="25" /></li>
<vb:else />
<li><label>{vb:rawphrase already_rated_this_thread}</label></li>
</vb:if>
</ul>
<input type="hidden" name="s" value="{vb:raw session.sessionhash}" />
<input type="hidden" name="securitytoken" value="{vb:raw bbuserinfo.securitytoken}" />
<input type="hidden" name="t" value="{vb:raw threadid}" />
<input type="hidden" name="pp" value="{vb:raw perpage}" />
<input type="hidden" name="page" value="{vb:raw pagenumber}" />
</form>
</div>
<script type="text/javascript">
<!--
vB_AJAX_ThreadRate_Init('showthread_threadrate_for m', {vb:raw threadinfo.threadid});
//-->
</script>
</li>
</vb:if>
I could use a plugin to render a new showthread template with my customisation but thought there may be a way to remove it from the original template?

ozzy47
10-31-2014, 09:32 AM
Why remove or hide the code, just set the $show['threadrating'] to false.

Black Snow
10-31-2014, 10:32 AM
Because I want use the etiket template mod to put the options above the thread.

ozzy47
10-31-2014, 10:57 AM
Well since that is a template modification, why not just edit the template further, and move the code where you want?

Black Snow
10-31-2014, 11:15 AM
I want it on 3 different themes and dont want to edit all 3 lol

cellarius
10-31-2014, 12:00 PM
In the time you spent asking here, waiting for answers, then implementing whatever is suggested etc you could have made that template edit three dozen times. Honestly, you're wasting your time (and ours, too). Just edit the templates, what's the problem?

Black Snow
10-31-2014, 12:31 PM
If I wanted to turn the template mod into an addon then I would need to know how (if possible) to do what I asked. I'm not doing it just for my benefit.

tbworld
10-31-2014, 08:11 PM
I want it on 3 different themes and dont want to edit all 3 lol

The template system is hierarchical. Make your template change in a parent style, your additional styles should or could be children. :)

Black Snow
11-01-2014, 06:55 AM
The template system is hierarchical. Make your template change in a parent style, your additional styles should or could be children. :)

I understand that but they are 3 different styles and nowhere near the same.

cellarius
11-01-2014, 09:33 AM
Then, why oh why, don't you just use https://vborg.vbsupport.ru/showthread.php?t=152931?