• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

BBCode Parsing

Mythotical

Well-known member
#1
Ok so I figured out thanks to Jaxel that I need to include parsing in my ViewPublic file.

So I keep getting this error:
An exception occurred: Argument 1 passed to XenForo_ViewPublic_Helper_Message::bbCodeWrapMessages() must be an array, null given, called in /home/xen/public_html/library/xPortal/ViewPublic/Portal.php on line 25 and defined in /home/xen/public_html/library/XenForo/ViewPublic/Helper/Message.php on line 64
  1. XenForo_Application::handlePhpError()inXenForo/ViewPublic/Helper/Message.phpat line64
  2. XenForo_ViewPublic_Helper_Message::bbCodeWrapMessages()inxPortal/ViewPublic/Portal.phpat line25
  3. xPortal_ViewPublic_Portal->renderHtml()inXenForo/ViewRenderer/Abstract.phpat line222
  4. XenForo_ViewRenderer_Abstract->renderViewObject()inXenForo/ViewRenderer/HtmlPublic.phpat line67
  5. XenForo_ViewRenderer_HtmlPublic->renderView()inXenForo/FrontController.phpat line533
  6. XenForo_FrontController->renderView()inXenForo/FrontController.phpat line156
  7. XenForo_FrontController->run()in/home/xen/public_html/index.phpat line13
This is my ViewPublic file:
PHP:
class xPortal_ViewPublic_Portal extends XenForo_ViewPublic_Base
{
    public function renderHtml()
    {
        // Get the blocks info in a local variable
        $blocks = $this->_params['blocks'];

        // We don't need the blocks being passed to individual templates
        unset($this->_params['blocks']);

        // These are the params that'll be passed to the child templates
        $params = $this->_params;

        // Initialize the arrays keys for storing block content
        $this->_params['leftBlocks'] = '';
        $this->_params['midBlocks'] = '';
        $this->_params['rightBlocks'] = '';

        foreach ($blocks['left'] AS $left)
        {
            $this->_params['leftBlocks'] .= $this->createTemplateObject($left['temp_template'], $params);
        }

        foreach ($blocks['mid'] AS $mid)
        {
             $mid .= $this->createTemplateObject($mid['temp_template'], $params);
$bbCodeParser = new XenForo_BbCode_Parser(XenForo_BbCode_Formatter_Base::create('Base', array('view' => $this)));
$bbCodeOptions = array('viewAttachments' => true);
$this->_params['midBlocks'] = new XenForo_BbCode_TextWrapper($mid, $bbCodeParser, $bbCodeOptions);
        }

        foreach ($blocks['right'] AS $right)
        {
            $this->_params['rightBlocks'] .= $this->createTemplateObject($right['temp_template'], $params);
        }

    }
}
I removed the code for a simpler view, but I'm trying to use this:

Not sure where I can place this without it breaking. I'm trying to parse bbcode used in the news block when it pulls a thread using bbcode but needs to parse no matter which column its in. So any help with this would be great as this is the last step before RC release.

Thanks
 
R

ragtek

Guest
#2
public static function bbCodeWrapMessages(array &$messages, XenForo_BbCode_Parser $parser, array $options = array())

1. param have to be a array.
And it seems that your var was empty/null or not a array
 

Mythotical

Well-known member
#3
Ragtek, don't take this the wrong way but I have been over that code, I have read and read, seriously, stop with the Yoda and just give me some input.

And your stating the obvious, I already know the array issue but I'm new to the BBCode stuff with XenForo so I'm at a loss when it comes to that stuff.
 

Jeremy

Well-known member
#4
Ragtek, don't take this the wrong way but I have been over that code, I have read and read, seriously, stop with the Yoda and just give me some input.

And your stating the obvious, I already know the array issue but I'm new to the BBCode stuff with XenForo so I'm at a loss when it comes to that stuff.
And you again are requesting help without giving enough information. Based on the code you provided: the view and and what you want the BBcode to be parsed using. Ragtek's reply was the only possible solution because you haven't shown us where the main variable is set. Provide that, and we can quit being "yoda" and give you some input.
 

Jeremy

Well-known member
#6
The only definition for $singleText is this:
PHP:
$singleText = new XenForo_BbCode_TextWrapper($singleText, $bbCodeParser, $bbCodeOptions);
If that's true, reread Ragtek's post. He answers you perfectly fine. If $singleText is defined else where for you in the code, you're missing crucial information.
 

Mythotical

Well-known member
#7
$singleText is only example vars. Sheesh, figured that would be obvious as I was describing what the variable would be technically aiming to do.
 

Mythotical

Well-known member
#8
Ok I have added the BBCode parser into the file as you can see above. Assigned a new variable, and got a result, smilies are parsed but now it doesn't parse the rest. Screenshot provided.

screenshot.png
 

Jeremy

Well-known member
#10
Is there actual BBCode in the template? Is it something like the help templates for BBCodes where the template actually stores / holds BBCode rather than the database? Or are you placing text from the DB (say latest news) into a template? If that's the case, you're using the wrong class.
 

Mythotical

Well-known member
#11
Yes exactly, using Latest News block which is just a template name in the database. The file pulls that and converts it to a usable source to be passed to the main page. So could you point me towards the right code and such for doing this on the latest news block?
 

Jeremy

Well-known member
#12
If I'm correct, you are using the wrong formatter. The way you described, you are placing BBCode into the template, but fetching the actual news from the DB? If so, you need to use XenForo_BbCode_Parser_Base::render() and it should in theory work. Then you insert the parsed text into the template object ($viewParam would be the best idea here).