Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Addon to associate more metadata with a thread

edited February 2015 in Vanilla 2.0 - 2.8

OK so I've posted two questions already. This is the last new thread today I promise! This one is a different question.

I'm new here but have been reading about how to write addons.

I'm interested in writing an addon that allows the original poster (just the first person to start a thread) to put some metadata with their post. I know there are tags, but I'm thinking of something more general, and in addition to tags. Like,

  • An arbitrary text box (in addition to the title and actual post box, a custom one for a custom purpose)
  • A dropdown list of five items (similar to the existing "Category" dropdown, but for a different purpose)
  • A set of radio buttons or checkboxes.

All of the above input will be formatted by the addon, and presented in a standardized format as the first post in the discussion thread.

So, instead of a post that just consists of the text as it was typed in the box, the first post would consist of something generated by the addon which may look like this:

Language: ruby
Minimum requirements: 0.23.3
Text: [the text the user pasted]

Just the first post is special; then all subsequent comments on this thread will be the regular type of comment with no bells and whistles.

Can anyone offer some pointers?

Thanks,
David

Tagged:

Comments

  • I'd have a close look at Tagging and other similar-functionality plugins for the hooks you'll want to use since they'll be similar.

    If you want to be able to filter/sort by this info later, make each a new column on the GDN_Discussion table. Otherwise, you could store them all in the Attributes field.

    I'm sure others will be along with more tips soon.

  • edited February 2015

    Thanks Jason and Linc.

    Jason,

    Your plugin looks great. All I'd have to do is have more than one extra GDN_Discussion columns and modify your plugin a bit.

    However I can't get yours to work. Here's what I do. I place the ExtraDiscussionData in my plugin folder, change this line:

    $ExtraDiscussionDataConfig['ColumnName'] = 'Rating';

    to this:

    $ExtraDiscussionDataConfig['ColumnName'] = 'ExtraData1';

    since the extra MySQL column I named "ExtraData1". Then I click Enable your plugin. However I see this message:

    Internal Server Error
    
    The server encountered an internal error or
    misconfiguration and was unable to complete
    your request.
    
    Please contact the server administrator,
     cgiadmin@yourhostingaccount.com and inform them of the time the error occurred,
    and anything you might have done that may have
    caused the error.
    
    More information about this error may be available
    in the server error log.
    
    Additionally, a 500 Internal Server Error
    error was encountered while trying to use an ErrorDocument to handle the request.
    

    Note that ExtraData1 has the following:

        Field = ExtraData1
        Type = int(1)
        Collation = [Blank]
        Attributes = [Blank] 
        Null = No
        Default = 0
        Extra = [Blank]
    

    I'm not experienced with MySQL so I could be doing something wrong!

    I'm using the following config.php file:

    <?php if (!defined('APPLICATION')) exit();
    global $ExtraDiscussionDataConfig;
    $ExtraDiscussionDataConfig = [];
    
    $ExtraDiscussionDataConfig['ColumnName'] = 'ExtraData1';
    
    $ExtraDiscussionDataConfig['ShowFormWhen'] = function($Sender) {
        # Same logic as GetItemID in DiscussionAbout
        if (isset($Sender->Discussion) && is_numeric($Sender->Discussion->ScriptID)) {
            return $Sender->Discussion->ScriptID != '0';
        }
        if (isset($_REQUEST['script']) && is_numeric($_REQUEST['script'])) {
            return $_REQUEST['script'] != '0';
        }
        return false;
    };
    $ExtraDiscussionDataConfig['Values'] = [
        '0' => [
            'form_markup' => ' No rating (just a question or comment)',
            'show_markup' => ''
        ],
        '1' => [
            'form_markup' => ' Report script (malware, stolen code, or other bad things requiring moderator review)',
            'show_markup' => ''
        ],
        '2' => [
            'form_markup' => ' Bad (doesn\'t work)',
            'show_markup' => ''
        ],
        '3' => [
            'form_markup' => ' OK (works, but could use improvement)',
            'show_markup' => ''
        ],
        '4' => [
            'form_markup' => '  Good (works well)',
            'show_markup' => ''
        ]
    ];
    
    ?>
    
    
  • Hmm, maybe I should post the question on your ExtraDiscussionData plugins page. I'll post it there instead..

  • I feel super spammy, but check out Discussion Extender as well: http://vanillaforums.org/addon/discussionextender-plugin

    Search first

    Check out the Documentation! We are always looking for new content and pull requests.

    Click on insightful, awesome, and funny reactions to thank community volunteers for their valuable posts.

Sign In or Register to comment.