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.

Hashtag plugin

hello,

I am using the Hashtag on a financial forum and I was wondering if it's possible to change the actual # of a hashtag to a $, so it becomes a "cashtag". Is there any way this can be edited somewhere?

Comments

  • R_JR_J Ex-Fanboy Munich Admin

    Funny idea! I cannot answer for this plugin, but I would guess that it at least in parts rely on Vanillas hashtag features. For that you would have to create a plugin with a custom MentionsFormatter (since hashtag formatting is handled in class Formats method mentions().

    That would have to look similar to this (untested):

    <?php
    
    $PluginInfo['cashTag'] = [
        ...
    ];
    
    Gdn::factoryInstall('MentionsFormatter', 'CashTagPlugin', __FILE__, Gdn::FactorySingleton);
    
    class CashTagPlugin extends Gdn_Plugin {
    
        public function formatMentions($Mixed) {
            // All this code is copied from /library/class.format.php
            // Only change is made below to change hashtag character "#"
            // to a "CashTag" (dollar sign)
                // Handle @mentions.
                if (c('Garden.Format.Mentions')) {
                    // Only format mentions that are not already in anchor tags or code tags.
                    $Mixed = self::tagContent($Mixed, 'Gdn_Format::formatMentionsCallback');
                }
    
                // Handle #hashtag searches
                // Changed to use "$" as the tagging character
                if (c('Garden.Format.Hashtags')) {
                    $Mixed = Gdn_Format::replaceButProtectCodeBlocks(
                        '/(^|[\s,\.>])\$([\w\-]+)(?=[\s,\.!?<]|$)/i',
                        '\1'.anchor('$\2', '/search?Search=%23\2&Mode=like').'\3',
                        $Mixed
                    );
                }
    
                // Handle "/me does x" action statements
                if (c('Garden.Format.MeActions')) {
                    $Mixed = Gdn_Format::replaceButProtectCodeBlocks(
                        '/(^|[\n])(\/me)(\s[^(\n)]+)/i',
                        '\1'.wrap(wrap('\2', 'span', array('class' => 'MeActionName')).'\3', 'span', array('class' => 'AuthorAction')),
                        $Mixed
                    );
                }
    
                return $Mixed;
        }
    }
    

    I'n not sure if that would be enough already. The hashtag functionality isn't made to be configurable in concern to which character it uses. There might be more tweaks needed

  • edited May 2017

    Oh that's plenty of code for me to work with. Thanks for taking the time to create this snippet and its explanation. I'll try to implement it and will let you know what comes out of it!

    Thanks!

    but I would guess that it at least in parts rely on Vanillas hashtag features.

    it relies heavily on the Tagging plugin for a lot of its logic. It's a required plugin to be activated before activating this one.

  • rbrahmsonrbrahmson "You may say I'm a dreamer / But I'm not the only one" NY ✭✭✭

    Yes, indeed I relied and created dependency on the Tagging plugin. I am traveling and haven't looked at my code but I think that if you really want to implement your change you'd have to change both plugins... Good luck and thank you for trying my plugin.

Sign In or Register to comment.