Encheferizer

Cheesegrits

Active member
w00t! Got the beginnings of at least the front end part of The En-Cheferizer working. This is a totally useless mod that I just enjoy having around, that Encheferizes forum posts (renders them in Swedish Chef Speak). I usually use it on a per-user basis, to punish abusive or otherwise PITA users. Death threats and abuse just don't work when rendered in Swedish Chef Speak. :)

Here's the listener code. I'd like to get some feedback on whether I'm taking the right approach here. In particular:

  1. Is running it on front_controller_pre_view listener and testing for the viewname the correct approach?
  2. What should the first arg to the formatter create() method be?
  3. How the heck do I code up ACP options?

Code:
    /**
     * 
     * Public front_controller_pre_view listener for Encheferizer
     * 
     * @param $fc
     * @param $controllerResponse
     * @param $viewRenderer
     * @param $containerParams
     */
    static public function listen(
        XenForo_FrontController $fc,
        XenForo_ControllerResponse_Abstract &$controllerResponse,
        XenForo_ViewRenderer_Abstract &$viewRenderer,
        array &$containerParams)
    {
        // @TODO - work out ACP logic, and add options for which users and/or forums to Encheferize
        // is there a viewName, and if so is it for thread view
        if (isset($controllerResponse->viewName) and $controllerResponse->viewName == 'XenForo_ViewPublic_Thread_View') {
            // create a formatter object, so we can grab a list of bbcodes
            // no idea what the first arg for this should be!
            $formatter = XenForo_BbCode_Formatter_Base::create('XenForo_BbCode_Formatter_BbCode_Strip', false);
            // grab bbcodes
            $bbcodes = $formatter->getTags();
            // extract just the keys, i.e. the actual codes themselves
            $bbcodes_keys = array_keys($bbcodes);
            // iterate through each post and enchef
            foreach ($controllerResponse->params['posts'] as &$post) {
                $didCut = '';
                $post['message'] = self::_bbEencheferize($post['message'], 0, $bbcodes_keys, $didCut);
            }
        }
    }

prechef.webp postchef.webp

-- hugh
 
To answer one of my own questions. Adding ACP settings is trivial. Just add an Options Group in the regular ACP Options page, add new Options as required, and access them in your code using XenForo_Application::get('options')->your_setting.

Adding the group and options will automagically create the phrasing for them.

-- hugh
 
Back
Top Bottom