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
    Quote from: OpenGeek at Oct 13, 2008, 10:07 AM

    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.

    Now I’m completely confused. tongue You said this earlier.

    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.

    My original idea was to create a context to override the system settings. I took the comment just above as intended to discourage me from doing that. Now it sounds like you’re suggesting that as a solution. huh What am I missing?
      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
      You don’t need to create a context, just add those settings to a context when you want to override the value in the system setting, for existing contexts.
        • 3749
        • 24,544 Posts
        Quote from: OpenGeek at Oct 13, 2008, 01:21 PM

        You don’t need to create a context, just add those settings to a context when you want to override the value in the system setting, for existing contexts.

        Um . . . how can I add settings to a context that hasn’t been created?

        Just guessing here, but would this do it in the snippet code?

        $ctx = $modx->newObject('modContext',"newContext");
        
        $modx->switchContext('newContext');
        
        $ss = $modx->newObject('modSystemSetting');
        $ss->set('key','captcha_use_mathstring');
        $ss->set('value',false);



          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
          • 28215
          • 4,149 Posts
          Quote from: BobRay at Oct 13, 2008, 02:00 PM

          Quote from: OpenGeek at Oct 13, 2008, 01:21 PM

          You don’t need to create a context, just add those settings to a context when you want to override the value in the system setting, for existing contexts.

          Um . . . how can I add settings to a context that hasn’t been created?
          Do you want to do it in the build, or runtime? If build:

          $ctx = $modx->newObject('modContext');
          $ctx->set('key','newContext');
          
          $settings[] = array();
          
          $ss = $modx->newObject('modContextSetting');
          $ss->set('key','captcha_use_mathstring');
          $ss->set('value',false);
          $settings[$ss->get('key')] = $ss;
          
          $ctx->addMany($settings);
          
          $builder->createVehicle($ctx,array (
          	XPDO_TRANSPORT_PRESERVE_KEYS => true,
          	XPDO_TRANSPORT_UPDATE_OBJECT => true,
          	XPDO_TRANSPORT_UNIQUE_KEY => 'key',
          	XPDO_TRANSPORT_RELATED_OBJECTS => true,
          	XPDO_TRANSPORT_RELATED_OBJECT_ATTRIBUTES => array (
          		'modContextSetting' => array (
          			XPDO_TRANSPORT_PRESERVE_KEYS => false,
          			XPDO_TRANSPORT_UPDATE_OBJECT => true,
          			XPDO_TRANSPORT_UNIQUE_KEY => array ('context_key', 'key'),
          		),
          	),
          ));
          

            shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
            • 22303 MODX Staff
            • 10,725 Posts
            Why would you need to create a context, this is where I’m getting lost. You just need to set the settings for the existing contexts, web, mgr, and connectors, right?
              • 3749
              • 24,544 Posts
              Cool. How about runtime? Is it the same, but without the builder code?

              Also, I don’t understand what this is doing or why it’s necessary:

              $ctx->set('key','newContext');


                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
                • 3749
                • 24,544 Posts
                Quote from: OpenGeek at Oct 13, 2008, 02:26 PM

                Why would you need to create a context, this is where I’m getting lost. You just need to set the settings for the existing contexts, web, mgr, and connectors, right?
                I guess we’re both lost, though I was there first. wink

                I want to override an existing System Setting (captcha_use_mathstring) at runtime (in a snippet) long enough to have my temporary setting be in effect for the use of <img src="captcha.php">. Captcha.php needs to see my temporary System Setting. I’d like the temporary System setting to go out of scope by the end of the snippet so it won’t affect other snippets. If I could do it without a plugin, that would be a plus.

                I thought it might be easy to do with contexts. If not, there are other ways to handle the problem.
                  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, 02:30 PM

                  Cool. How about runtime? Is it the same, but without the builder code?

                  Also, I don’t understand what this is doing or why it’s necessary:

                  $ctx->set('key','newContext');

                  Creating contexts at run-time will be cool for a multi-site setup tool, but I don’t see any valid scenarios for doing this otherwise.

                  As for setting the key, all contexts must have a unique ’key’ attribute; this is the identifier of the context, i.e. web, mgr, connectors.

                  Quote from: BobRay at Oct 13, 2008, 02:41 PM

                  I want to override an existing System Setting (captcha_use_mathstring) at runtime (in a snippet) long enough to have my temporary setting be in effect for the use of <img src="captcha.php">. Captcha.php needs to see my temporary System Setting. I’d like the temporary System setting to go out of scope by the end of the snippet so it won’t affect other snippets. If I could do it without a plugin, that would be a plus.

                  I thought it might be easy to do with contexts. If not, there are other ways to handle the problem.
                  No, settings are configuration values that are available to every request to the system, context, and/or a specific user account. They are not meant to be used for temporary settings across requests. This is what a session is for (or one could use messages in modRegistry, but that’s another topic for a later date).
                    • 28215
                    • 4,149 Posts
                    Quote from: BobRay at Oct 13, 2008, 02:41 PM

                    I want to override an existing System Setting (captcha_use_mathstring) at runtime (in a snippet) long enough to have my temporary setting be in effect for the use of <img src="captcha.php">. Captcha.php needs to see my temporary System Setting. I’d like the temporary System setting to go out of scope by the end of the snippet so it won’t affect other snippets. If I could do it without a plugin, that would be a plus.

                    I thought it might be easy to do with contexts. If not, there are other ways to handle the problem.

                    Would be best to have a Captcha class, that goes like so:

                    class Captcha {
                    	var $config;
                    	var $modx;
                    	
                    	// php4 compat
                    	function Captcha(&$modx, $config = array()) {
                    		$this->__construct($modx,$config);
                    	}
                    	
                    	function __construct(&$modx, $config = array()) {
                    		$this->modx =& $modx;
                    		
                    		$config = array_merge($config,array(
                    			'use_mathstring' => false, // here's the override, you can change this 
                    									   // to whatever, whenever, via $this->config
                    		));		
                    		$this->config = $config;
                    	}
                    	
                    	function doSomething() {
                    		$um = $this->config['use_mathstring'];		
                    		//etc...
                    		
                    		return $a_value;
                    	}
                    }
                    


                    And then in the snippet...

                    $captcha = new Captcha($modx,array(
                    	'use_mathstring' => $modx->config['use_mathstring'],
                    ));
                    $result = $captcha->doSomething();
                    //...
                    
                      shaun mccormick | bigcommerce mgr of software engineering, former modx co-architect | github | splittingred.com
                      • 3749
                      • 24,544 Posts
                      @OpenGeek - OK, clearly contexts are not the answer to this question. The obvious solution seems to be to have the Captcha code look for a $_SESSION variable that would override the effect of the System Setting. I don’t know why I didn’t think of it before. I guess I was being lazy and reluctant to re-do captcha now that it’s an available package.

                      @splittingred - I originally looked at going in that direction, but I think the captcha image source needs to be a file (a URL, actually) rather than an object. All the CAPTCHA code I’ve looked at does it that way so I’m guessing there must be a reason for it. It may be so the $_SESSION variable set by CAPTCHA isn’t set in your own code.
                        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