5.) Write The Plugins
The first plugin will cache the custom templates if appropriate, that is, if the product is enabled, the right script is running and the associated setting is enabled.
So, follow:
AdminCP ► Plugins & Products ► Add New Plugin
Select the product we are developing, and then enter:
Hook Location: cache_templates
Title: Cache Templates
Execution Order: 5
Plugin PHP Code:
PHP Code:
if ($vbulletin->options['markfl_dtd_enabled'])
{
if (THIS_SCRIPT === 'showthread' AND $vbulletin->options['markfl_dtd_postbit'])
{
$cache = array_merge($cache, array('markfl_thanks_postbit'));
}
elseif (THIS_SCRIPT === 'member' AND $vbulletin->options['markfl_dtd_profile'])
{
$cache = array_merge($cache, array('markfl_thanks_memberinfo_block_statistics'));
}
}
The next plugin will create the template group for our product so that when the user views all the templates when editing templates, our custom templates will be grouped together for efficient organization.
So, add another new plugin, and choose the product we are developing, and then enter:
Hook Location: template_groups
Title: Create Product Template Group
Execution Order: 5
Plugin PHP Code:
PHP Code:
$only['markfl_thanks_'] = 'MarkFL Display DBTech Thanks Data';
This instructs vBulletin to put any templates whose title begins with the string "markfl_thanks_" into a group named "MarkFL: Display DBTech Thanks Data."
The next plugin will instruct vBulletin to replace its default template with our custom version (if our product is enabled, thanks data on profiles is enabled, and the template to be replaced is running). So, add a new plugin and choose the product we are developing, and then enter:
Hook Location: template_render_output
Title: memberinfo_block_statistics Template Replacement
Execution Order: 5
Plugin PHP Code:
PHP Code:
if (($vbulletin->options['markfl_dtd_enabled'] AND $vbulletin->options['markfl_dtd_profile']) AND $this->template == 'memberinfo_block_statistics')
{
$this->template = 'markfl_thanks_memberinfo_block_statistics';
}
The next plugin will render the thanks data in user postbits, if the appropriate settings are correct, and only for posts in threads or private messages, and if the user has not disabled the postbit stats in their settings for DBTech's product.
Hook Location: postbit_display_complete
Title: Render Thanks Data In Postbits
Execution Order: 1 (I wanted to ensure that the thanks data goes right below the number of posts in the postbit)
Plugin PHP Code:
PHP Code:
if (($vbulletin->options['markfl_dtd_enabled'] AND $vbulletin->options['markfl_dtd_postbit']) AND ((THIS_SCRIPT === 'showthread') OR (THIS_SCRIPT === 'private')) AND $post['dbtech_thanks_settings'] == 0)
{
if ($post['posts'])
{
$p = str_replace( ',', '', $post['posts']);
$thanked_per_post = number_format($post['likes_received']/$p, 3, '.', '');
}
else
{
$p = 0;
$thanked_per_post = 0;
}
$post['likes_received'] = number_format($post['likes_received']);
$post['likes_given'] = number_format($post['likes_given']);
$templater = vB_Template::create('markfl_thanks_postbit');
$templater->register('post', $post);
$templater->register('thanked_per_post', $thanked_per_post);
$templater->register('p', $p);
$template_hook['postbit_userinfo_right_after_posts'] .= $templater->render();
}
And the last plugin will render the thanks data on user profiles if the settings are appropriate:
Hook Location: member_build_blocks_start
Title: Render Thanks Data On Profile
Execution Order: 5
Plugin PHP Code:
PHP Code:
if (($vbulletin->options['markfl_dtd_enabled'] AND $vbulletin->options['markfl_dtd_profile']) AND (THIS_SCRIPT === 'member'))
{
$user_data = $vbulletin->db->query_read_slave("
SELECT user.*
FROM " . TABLE_PREFIX . "user AS user
WHERE userid = " . $prepared['userid']
);
$user_stats = $db->fetch_array($user_data);
if ($user_stats['dbtech_thanks_settings'] == 0)
{
$thanks_data = $vbulletin->db->query_read_slave("
SELECT dbtech_thanks_statistics.*
FROM " . TABLE_PREFIX . "dbtech_thanks_statistics AS dbtech_thanks_statistics
WHERE userid = " . $prepared['userid']
);
$thanks_stats = $db->fetch_array($thanks_data);
$markfl_thanks_received = $thanks_stats['likes_received'];
$markfl_thanks_given = $thanks_stats['likes_given'];
$markfl_thanks_per_post = 0;
$postcount = $user_stats['posts'];
if ($postcount)
{
$markfl_thanks_per_post = number_format($markfl_thanks_received / $postcount, 3, '.', '');
}
$markfl_thanks_received = number_format($markfl_thanks_received);
$markfl_thanks_given = number_format($markfl_thanks_given);
vB_Template::preRegister('memberinfo_block_statistics',array('markfl_thanks_given' => $markfl_thanks_given,'markfl_thanks_received' => $markfl_thanks_received, 'markfl_thanks_per_post' => $markfl_thanks_per_post, 'postcount' => $postcount));
}
}
Okay, we now have all the coding done, and it is time to export the product, which will create the XML file we can distribute to others.
6.) Export The Product
Follow:
AdminCP ► Plugins & Products ► Manage Products
Scroll down to the product we have developed, and on the right, from the drop-down menu for our product, click "Export" and save the XML file in an appropriate location on your hard drive. I like to put each product's files in its own folder.
You should write a text file instructing those who download your product how to install it and state the purpose of the product and give its development history.
7.) Zip Up the Files
Use an application of your choice to compress all of the files associated with your product into a ZIP file. Now you are ready to share your product with others. If you are uploading here, you should be sure to include screenshots of your product's setting page in the AdminCP and your product in action.
The product developed in this article is very modest, but I wanted to keep it simple for the purposes of a tutorial on the general method for using vBulletin's intrinsic tools for developing and sharing products. I encourage those of you with years of experience, rather than the weeks of experience I have under my belt to offer further insights and/or corrections to what I have written.