View Single Post
  #2  
Old 05-28-2015, 04:23 AM
MarkFL's Avatar
MarkFL MarkFL is offline
 
Join Date: Feb 2014
Location: St. Augustine, FL
Posts: 3,853
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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']/$p3'.''');
    }
    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 $postcount3'.''');
        }
        
        
$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.
Reply With Quote
Благодарность от:
BrettC Frontier
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01210 seconds
  • Memory Usage 1,857KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (5)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_box_bit
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete