We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 21872
    • 95 Posts
    I made a very simple plugin that just runs smartypants on the content of a resource at the OnWebPagePrerender event. But I’m storing CSS and JavaScript as resources, and I’d like to avoid munging them. Is there a way to restrict where and on what a plugin has permission to act?
      • 18373 ☆ A M B ☆
      • 3,141 Posts
      My knowledge in regards to plugins is quite limited... but couldn’t you simply add in a check for the resource IDs to filter out in your plugin? I’d expect something like $modx->documentIdentifier $modx->resource->get(’id’) to work in that specific event.
        Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

        Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
        • 28215
        • 4,149 Posts
        You can use the API; use:

        $idsToCheck = array(1,23,45,8,11); // an array of IDs to check
        $id = $modx->resource->get('id');
        if (in_array($id,$idsToCheck)) {
           // do code
        }
        


        You can also do $modx->getParentIds($id) to grab all the parents of a resource, or $modx->getChildIds($ids,$depth = 10) to grab all the children.

        How you do it is up to you in your plugin.
          shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
          • 21872
          • 95 Posts
          Thank you, the example made a useful model. This is what I wanted to do:
          <?php
          include_once('/path/to/assets/components/smartypants.php');
          $contentType = $modx->resource->get('contentType');
          if ($contentType == 'text/html') {
              $output = &$modx->resource->_output;
              $output = SmartyPants($output);
          }
          ?>


          Now what I don’t understand is why the plugin doesn’t seem to always work, even after clearing the cache and even when it is just

          include_once(’/path/to/assets/components/smartypants.php’);
          $output = &$modx->resource->_output;
          $output = SmartyPants($output);


          on some resources, it works, on others, it doesn’t do anything. If I change the template to empty on those where it doesn’t, it does.


          I can’t figure out if this is a bug or a feature, but I’m observing behavior I can’t account for.

          1) The plugin does not appear to run on pages that are requested for the first time while logged in -- e.g. a new resource.
          2) A resource that had loaded while logged in but prior to the existence of the plugin displays the processed output when the plugin is active and the default output when it isn’t.
          3) A new resource displays the processed output when logged out, but as soon as I log back in, the output is not processed by SmartyPants, or at least there is no difference between the output when the plugin is enabled and when it is disabled.
          4) Flushing the cache and session cache and browser cache does not alter the behavior I’ve just described.

          Does that make any sense?
            • 22303 MODX Staff
            • 10,725 Posts
            You actually don’t want to use the contentType field on modResource; this is deprecated and only there to support easier migration from Evolution. It will be removed in future releases. This is actually what you want to do:
            <?php
            include_once('/path/to/assets/components/smartypants.php');
            $modx->resource->getOne('ContentType');
            if ($modx->resource->ContentType->get('mime_type') == 'text/html') {
                $modx->resource->_output = SmartyPants($modx->resource->_output);
            }
            ?>


            As for the rest of your problems, I’m not sure what you are experiencing, as it should work the same regardless of first request or coming from the cache. I assume you mean logging into the manager? Have you set up any security access controls other than the default?
              • 21872
              • 95 Posts
              Cool, thank you!

              It’s really weird, I know, but I have nothing special going on with permissions -- all the defaults are in place and nothing else, but when I’m logged into the manager I get the behavior I’ve described. I just tried it in Chrome, after changing the script while logged into the manager in Firefox, and the same thing happened. When logged out of the manager, smart quotes, when logged in (in Chrome) straight quotes. Ditto Firefox. Clearing the site cache has no effect. This is in MODx Revolution 2.0.0-rc-2 rev6923, if that matters. I’m using the smartypants.php file from here: http://michelf.com/docs/projets/php-smartypants-typographer-1.0.zip the plugin looks like this:
              <?php
              $modx->resource->getOne('ContentType');
              if ($modx->resource->ContentType->get('mime_type') == 'text/html') {
                  include_once('/path/to/assets/components/smartypants.php');
                  $modx->resource->_output = SmartyPants($modx->resource->_output);
              }
              ?>
              


              and it is registered to one event, OnWebPagePrerender

              If anyone can reproduce this and I haven’t done anything stupid in my ignorance, I’ll file a bug.
                • 18373 ☆ A M B ☆
                • 3,141 Posts
                You did change [tt]include_once(’/path/to/assets/components/smartypants.php’);[/tt] to the actual [tt]smartypants.php[/tt] file? Not sure if it could make that behaviour, but... yeah.
                  Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

                  Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
                  • 21872
                  • 95 Posts
                  If I hadn’t, it wouldn’t have worked logged in or out...but it makes as much sense as anything else I can think of.