We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3749
    • 24,544 Posts
    OK, now I’m not so sure.

    Let me be more specific about what I might want to do. Say, in the default context, the System Setting: captcha_use_mathstring = false.
    Any use of captcha.php as an image source would not use the mathstring because the veriword class checks it to decide.

    Say I load a page that’s on the same server in the default context and use a plugin to set it to another context based on its document ID.
    Snippets on that page would operate in the new context. Now a snippet on that page sets the System Setting captcha_use_mathstring to true and then uses captcha.php as an image source. The mathstring appears?

    Now, the user transfers to another page, again on the same server in the default context, that doesn’t trigger the plugin and uses captcha.php as an image source. The mathstring doesn’t appear because we’re back in the default context?

    It’s probably better to write my own captcha.php that responds the way I want it to (or rewrite the original so it takes an argument and uses the system setting as a default), but this example is helping me understand contexts.
      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
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: BobRay at Oct 12, 2008, 12:38 AM

      Let me be more specific about what I might want to do. Say, in the default context, the System Setting: captcha_use_mathstring = false.
      Any use of captcha.php as an image source would not use the mathstring because the veriword class checks it to decide.

      Say I load a page that’s on the same server in the default context and use a plugin to set it to another context based on its document ID.
      Snippets on that page would operate in the new context. Now a snippet on that page sets the System Setting captcha_use_mathstring to true and then uses captcha.php as an image source. The mathstring appears?

      Now, the user transfers to another page, again on the same server in the default context, that doesn’t trigger the plugin and uses captcha.php as an image source. The mathstring doesn’t appear because we’re back in the default context?

      It’s probably better to write my own captcha.php that responds the way I want it to (or rewrite the original so it takes an argument and uses the system setting as a default), but this example is helping me understand contexts.
      undecided I’m kind of lost on this one. I think the problem is configuration settings are not intended to be modified at runtime, ever, so changing a setting in a Snippet IMO, should not be allowed. Because they are stored in an array and you can doesn’t mean you should. In fact, in an upcoming change to further improve scalability of extremely busy, large sites, the configuration settings will be accessed via a function call, i.e. modX::config(), rather than via direct access to the modX::$config array. This will also close the gap on some seldom considered security issues, e.g. users won’t be able to write scripts to modify their config settings, which could be used maliciously.
        • 3749
        • 24,544 Posts
        I agree completely. There’s no doubt that protecting System Settings from on-the-fly changes is good (if not critical) for both security and robustness.

        For the sake of my understanding of contexts, though, would what I described in my last post actually work as I described it (assuming that $modx->config[’setting’] = $x works)?

          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
          • 22303 MODX Staff
          • 10,725 Posts
          Quote from: BobRay at Oct 12, 2008, 02:34 PM

          For the sake of my understanding of contexts, though, would what I described in my last post actually work as I described it (assuming that $modx->config[’setting’] = $x works)?
          No, because that would only modify the setting for the duration of the current request. Once that request is done, the value of the system setting would be reloaded from the cache with the original value. To modify a system setting permanently, you would have to save changes to the table row and clear the cache.
            • 3749
            • 24,544 Posts
            Quote from: OpenGeek at Oct 12, 2008, 02:36 PM

            Quote from: BobRay at Oct 12, 2008, 02:34 PM

            For the sake of my understanding of contexts, though, would what I described in my last post actually work as I described it (assuming that $modx->config[’setting’] = $x works)?
            No, because that would only modify the setting for the duration of the current request. Once that request is done, the value of the system setting would be reloaded from the cache with the original value. To modify a system setting permanently, you would have to save changes to the table row and clear the cache.

            Wouldn’t the use of captcha.php as an image source be included in the current request (or is that a new request).? I wanted a *temporary* change in the system setting to begin with.

              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
              • 22303 MODX Staff
              • 10,725 Posts
              Quote from: BobRay at Oct 12, 2008, 02:45 PM

              Wouldn’t the use of captcha.php as an image source be included in the current request (or is that a new request).? I wanted a *temporary* change in the system setting to begin with.
              That is a separate request, and, IMHO, one that should go through the MODx gateway rather than directly called via an external php file. Why can’t the captcha.php logic be encapsulated into a processor in the model, then called from the connectors context, or a front-end context, or from a controller in the mgr context for that matter?

              But I’ve drifted from the topic; which is that configuration settings should always be considered read-only, unless you are changing them permanently in the scope of the system, a context, or a user. Changes to settings will potentially affect all users, since context and user settings can inherit values from the previous layer.
                • 3749
                • 24,544 Posts
                Quote from: OpenGeek at Oct 12, 2008, 04:29 PM

                Why can’t the captcha.php logic be encapsulated into a processor in the model, then called from the connectors context, or a front-end context, or from a controller in the mgr context for that matter?

                It certainly could, but I seem to recall that someone wanted it out of the core. wink


                But I’ve drifted from the topic; which is that configuration settings should always be considered read-only, unless you are changing them permanently in the scope of the system, a context, or a user. Changes to settings will potentially affect all users, since context and user settings can inherit values from the previous layer.

                Agreed - 100%. I can think of several very doable ways to solve my problem without touching any System Settings. I was just trying to get a better handle on contexts.
                  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
                  • 22303 MODX Staff
                  • 10,725 Posts
                  Quote from: BobRay at Oct 12, 2008, 05:24 PM

                  Quote from: OpenGeek at Oct 12, 2008, 04:29 PM

                  Why can’t the captcha.php logic be encapsulated into a processor in the model, then called from the connectors context, or a front-end context, or from a controller in the mgr context for that matter?
                  It certainly could, but I seem to recall that someone wanted it out of the core. wink
                  I still do. wink Just because it adds something to the model doesn’t mean it can’t be installed from a transport package.
                    • 3749
                    • 24,544 Posts
                    Quote from: OpenGeek at Oct 12, 2008, 05:46 PM

                    Quote from: BobRay at Oct 12, 2008, 05:24 PM

                    Quote from: OpenGeek at Oct 12, 2008, 04:29 PM

                    Why can’t the captcha.php logic be encapsulated into a processor in the model, then called from the connectors context, or a front-end context, or from a controller in the mgr context for that matter?
                    It certainly could, but I seem to recall that someone wanted it out of the core. wink
                    I still do. wink Just because it adds something to the model doesn’t mean it can’t be installed from a transport package.

                    I’d have to know a lot more about how the model functions to make that happen. wink

                    At the least, I ought to re-do the captcha function so it’s easier to override the system setting for using the mathstring -- maybe with a $_POST variable (or setPlaceholder() ). Some users might want to use the mathstring in the Manager login but not elsewhere or vice versa.

                      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
                      • 22303 MODX Staff
                      • 10,725 Posts
                      Quote from: BobRay at Oct 13, 2008, 03:56 AM

                      At the least, I ought to re-do the captcha function so it’s easier to override the system setting for using the mathstring -- maybe with a $_POST variable (or setPlaceholder() ). Some users might want to use the mathstring in the Manager login but not elsewhere or vice versa.
                      Just create context settings to override the system settings. Then each context will be able to determine which options are in effect for captcha_mathstring. That said, the login processor might process logins for any context itself (via the connector context), and this would be a different challenge, since captcha occurs before an authenticated user is logged into a specific context. I think you picked the toughest thing to implement first; let me get my head out of a couple of things this morning and I’ll spend some time looking over the captcha stuff again and make some recommendations.