We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36764 ☆ A M B ☆
    • 45 Posts
    Evengard aka Eiventeleiron Reply #1, 15 years ago
    Hello, people!
    I am planning in adapting one very good BBCode parser to make it being able to parse input in some forms (I dislike the one included with Discuss + I want to make it universal, not only for Discuss. Basically I dislike Discuss completely, thinking about creating my own forum system for modx, but that is another story) I select.
    But... I just doesn't know how to accomplish that at best! It should be available for use in the live site AND in the manager. How can it be accomplished? What is the good way of making such parsers?
    The nearest thing in another CMS - Drupal - is this one addon: http://drupal.org/project/bbcode
    Basically I would like to make something similar in Modx Revo.

    One note - the parsing must be done on the rendering stage, cause the content should be saved in bbcode format to being editable. Seems to be the best way of accomplishing that is using plugins, but which events should be handled?

    This question has been answered by eiventeleiron. See the first response.

    [ed. note: eiventeleiron last edited this post 15 years ago.]
      • 4172
      • 5,888 Posts
      there is http://modx.com/extras/package/textilefilter

      Its an output-filter. Easy to use.
      if you need BBCode-parser, you can do the same for BBCode, I think.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 36764 ☆ A M B ☆
        • 45 Posts
        Evengard aka Eiventeleiron Reply #3, 15 years ago
        Ah, I see, understood. This is an output filter. Basically, what would I need is creating the filter in question, and then applying it in the places you like. For example, using [[*content:bbcode]] in template for outputting any content data in bbcode in the resource to html. So you just select your right template (the bbcode powered or not) and proceed.

        But I want to make it slightly difficultier. I want to be able to switch on or off the bbcode behaviour by a custom TV! And, actually, without touching the template itself. Probably by some mean of a pouting, I would like to check if my bbcode TV is in "enabled" position then parse the content TV accordingly (with or without the output filtering snippet). How can I realise that? In which pouting event I would have access to the data of Template Variables?

        UPD: Basically what can I do is using this syntax:
        [[*content:bbcode=`[ [*myBbcodeTv]]` ]]
        in the template, but is there a way to make the same thing WITHOUT even modifying the content tag in a template?
          • 3749
          • 24,544 Posts
          Your custom output modifier can check the value of the TV with this code:

          $bbcode = $modx->resource->getTVValue('bbcode');


          But if you want to do it when the page is rendered, you'd have to use a plugin. I think the best event to attach it to would be OnParseDocument, which fires just before the tags are processed.
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 36764 ☆ A M B ☆
            • 45 Posts
            Evengard aka Eiventeleiron Reply #5, 15 years ago
            Isn't OnWebPagePrerender is better?
              • 3749
              • 24,544 Posts
              At the time OnWebPagePrerender fires, all MODX tags have been parsed and replaced, and unidentified tags have been removed, so it's probably not what you want.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting
              • discuss.answer
                • 36764 ☆ A M B ☆
                • 45 Posts
                Evengard aka Eiventeleiron Reply #7, 15 years ago
                Thank you. But isn't OnParseDocument called multiple times?
                And how to set the TV value (just for this request)?
                $modx->resource->setTVValue()?

                And how to strip all possible tags out from the content of the TV? Or just disallowing it's parsing? Is it just by replacing
                [[ and ]] by & #091;& #091; and & #093;& #093;
                ?

                UPD: it seems like the default Template Variables - such as pagetitle or content - are not requestable via $modx->resource->getTVValue("content"), one should use $modx->resource->get("content"). Same for setTVValue - replacing by set.
                Basically these are not TVs but Resource Fields, but their tag syntax is the same as for TVs. Full list is here:
                http://rtfm.modx.com/display/revolution20/Resources#Resources-ResourceFields

                UPD2: OnLoadWebDocument seems to be the best case. Cause we have the content and TVs/Resource Fields available. Basically this is the event which occures before any tag rendering is performed.

                UPD3: based on this script - http://www.shawnwilkerson.com/modx-revolution/modx-snippets/showsnippet-snippet.html - I suppose, that indeed to disallow the tags parsing we need just do a
                str_replace(array("[[", "]]"), array("& #091;& #091;", "& #093;& #093;"), $content);


                UPD4: WARNING! setTVValue() actually saves the information into the database, and the content of the TV is not updated until next request! Is there a way to make the exact contrary - make the change only for current request and don't save in database?

                UPD5: it seems that to make a TV parsable without using [ [*myTv:myFilter]] we need to make an TV Output Type - it's the only way. Basically, TV Output Types is exactly what is needed, it is even very logical to actually use them, but I thougth that it won't be needed and it is possible to perform by a plugin or such - an easier approach. Well, it is not.
                There is a very good tutorial on about how to make it - described here: http://rtfm.modx.com/display/revolution20/Adding+a+Custom+TV+Output+Type

                Is there an addon/extension of a TV Output Type which enables the value of a TV to be processed by a snippet? [ed. note: eiventeleiron last edited this post 15 years ago.]
                  • 36764 ☆ A M B ☆
                  • 45 Posts
                  Evengard aka Eiventeleiron Reply #8, 15 years ago
                  I've made an extra, which adds a TV Output Type, which parses the TV with the help of a snippet of your choice. I'll keep you posted when it become available in the extras repository. In meantime check on GitHub: https://github.com/Evengard/TVSnippEdit

                  UPD: check https://forums.modx.com/thread/70337/tvsnippedit-addon---now-snippets-take-care-of-parsing-the-output-of-tvs#dis-post-394244 for the info about the addon. [ed. note: eiventeleiron last edited this post 15 years ago.]