We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 22829 ☆ A M B ☆
    • 80 Posts
    <?php
    /**
     * SimpleCleaner
     *
     * Can remove or replace unwanted tags and words in the content
     * by Paul Merchant
     *
     * Fire with the OnDocFormSave event
     */
    
    /* Modify the cleaners array to add more patterns and replacements */
    $cleaners = array(
       // Removes paragraph tags when they are directly surrounding a modx tag
       '~<p>(\r?\n|\s)?\[\[(.+?)\]\](\r?\n|\s)?</p>~' => '[[$2]]'
    );
    $content = $resource->get('content');
    foreach ($cleaners as $pattern => $replacement){
       $content = preg_replace($pattern,$replacement,$content);
    }
    $resource->set('content',$content);
    $resource->save();
    ?>


    Just a starting point for replacing unwanted tags or words in the content. The current pattern allows editors to insert modx tags "[[" inside of their own (forced) TinyMCE paragraphs "<p>". The unwanted paragraph tags are then neatly cleaned up. It could probably be expanded for other purposes. This seemed to be easier than fighting or hacking TinyMCE.

    Commments and advice are always welcome.
      Time is what keeps everything from happening all at once.
      • 12379
      • 460 Posts
      Great idea! Replaces [*content*] tag in template then?
        Mostly harmless.
        • 22829 ☆ A M B ☆
        • 80 Posts
        Quote from: hotdiggity at Jun 22, 2010, 05:34 AM

        Great idea! Replaces [*content*] tag in template then?

        The current cleaner in the above plugin will go through content that looks like this:

        <p>This is my content. [[*MyTV]]</p>
        <p>[[$MyChunk]] </p>
        <p>
        [[MySnippetCall? &param=`1`]]
        </p>
        <p>More content...</p>

        And then store it in the database like this:

        <p>This is my content. [[*MyTV]]</p>
        [[$MyChunk]]
        [[MySnippetCall? &param=`1`]]
        <p>More content...</p>

        We don’t use modx tags within the content very often, but when we do it’s often a pain. TinyMCE wraps them with <p> tags and can make some of the code ugly or even mess it up. Turning off the forced <p> tags isn’t always easy or a good option.

        I couldn’t get the $_POST or scriptProperties to work with the latest Revo. That’s why it’s a database write after the content has been saved. I don’t think this will work if there are line breaks inside of your modx tag.
          Time is what keeps everything from happening all at once.
          • 12379
          • 460 Posts
          Sorry, I mean’t instead of putting [*content*] into the template, do I call content by replacing it with [[SimpleCleaner]]?
            Mostly harmless.
            • 28042 ☆ A M B ☆
            • 24,524 Posts
            It’s a plugin, not a snippet.
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 12379
              • 460 Posts
              Right, so what (if any) System Events need to be ticked?
                Mostly harmless.
                • 26931
                • 2,314 Posts
                Right, so what (if any) System Events need to be ticked?
                ->
                Fire with the OnDocFormSave event
                  • 12379
                  • 460 Posts
                  i did get outta bed on the wrong side today...
                    Mostly harmless.
                    • 28042 ☆ A M B ☆
                    • 24,524 Posts
                    We all have days like that wink
                      Studying MODX in the desert - http://sottwell.com
                      Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                      Join the Slack Community - http://modx.org
                      • 26931
                      • 2,314 Posts
                      i did get outta bed on the wrong side today.
                      .... standard procedure for me smiley