We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 24865
    • 289 Posts
    I’ve been fiddling around with the onPageNotFound event but I don’t seem to got it right.

    Now, I know that there is a difference between sendForward and sendRedirect. Redirect simply redirects you to the new location, ergo: new url. I need to preserve the URL to make it look like the client is accessing a existing file (resource).

    Scenario:

    The user goes to domain/profile/user-4.html.
    The resource tree contains only a container resource named "profile" (and aliassed of course)

    Knowning that that specific resource isn’t there, I call on the OnPageNotFound event, parsing the URL, finding the ID and returning to the profile container to parse it as a resource (fetches database information, outputs a chunk).

    Now, this is where it gets funky. I’ve got a connector set up to fetch some AJAX data from another resource that, of course, exists (yes, I’ve quadruple checked it). When I try to access an unexisting file (tryout-4.html), it works perfectly and forwards me to my chosen ID. Only the weird thing it, my connector acts out. It keeps requesting something and returning a doctype header error. Knowning that the connector is a file and has nothing to do with FURL/SEF, I find it weird that that file executes the OnPageNotFound event. Am I missing something?
      @MarkGHErnst

      Developer at Adwise Internetmarketing, the Netherlands.
      • 2611
      • 394 Posts
      Without the connector code’s content we cant do much...the problem is in your connector definantly.
        Follow me on twitter: @b03tz
        Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
        CodeMaster
        • 24865
        • 289 Posts
        <?php
        
        	/**
        	* @author ReSpawN
        	* @copyright 2010
        	*/
        	
        	$base = reset(explode('assets', dirname(__FILE__)));
        	
        	require_once($base.'config.core.php');
        	require_once(MODX_CORE_PATH.'config/'.MODX_CONFIG_KEY.'.inc.php');
        	require_once(MODX_CONNECTORS_PATH.'index.php');
        	
        	// TwitFeed
        	require_once(MODX_CORE_PATH.'components/twitfeed/model/twitfeed/twitfeed.class.php');
        	$modx->twitfeed = new twitFeed($modx, 'xxx', 'xxx');
        
        	$modx->request->handleRequest(array(
        		'processors_path' => $modx->getOption('core_path').'components/twitfeed/processors/',
        		'location' => 'web'
        	));


        <?php
        
        	/**
        	* @author ReSpawN
        	* @copyright 2010
        	*/
        	
        	$count = null;
        	$offsetId = null;
        	
        	if (isset($_POST['messageCount']) && $_POST['messageCount'] != '' && is_numeric($_POST['messageCount']) && $_POST['messageCount'] != 0) {
        		$count = (int) $_POST['messageCount'];
        	}
        	
        	if (isset($_POST['offsetId']) && $_POST['offsetId'] != '' && is_numeric($_POST['offsetId']) && $_POST['offsetId'] != 0) {
        		$offsetId = ($_POST['offsetId'] + 10);
        	}
        	
        	return json_encode($modx->twitfeed->getMessages($count, $offsetId));
          @MarkGHErnst

          Developer at Adwise Internetmarketing, the Netherlands.
          • 24865
          • 289 Posts
          Oh yea, the ajax call is made with my own version of ExtJS’s request. Kinda works the same way. I’ve also copied the authCode from the manager’s backend, so it all works fine. I just don’t get why the connector.php (and others from connector) execute the PageNotFound command, since I am requesting existing files, no FURL/SEF here.
            @MarkGHErnst

            Developer at Adwise Internetmarketing, the Netherlands.
            • 24865
            • 289 Posts
            I found a funky error, I hope it’s not linked to my connector because I wouldn’t know where to look to be frank.

             [2010-08-18 08:35:05] (ERROR @ C:\wamp\www\modx\core\model\modx\modcontext.class.php : 68) PHP warning: Missing argument 2 for modContext::getOption(), called in C:\wamp\www\modx\core\model\modx\processors\system\config.js.php on line 31 and defined
            [2010-08-18 08:35:05] (ERROR @ C:\wamp\www\modx\core\model\modx\modcontext.class.php : 68) PHP warning: Missing argument 2 for modContext::getOption(), called in C:\wamp\www\modx\core\model\modx\processors\system\config.js.php on line 31 and defined
            [2010-08-18 08:35:05] (ERROR @ C:\wamp\www\modx\core\model\modx\modcontext.class.php : 68) PHP warning: Missing argument 2 for modContext::getOption(), called in C:\wamp\www\modx\core\model\modx\processors\system\config.js.php on line 33 and defined
            [2010-08-18 08:35:05] (ERROR @ C:\wamp\www\modx\core\model\modx\modcontext.class.php : 68) PHP warning: Missing argument 2 for modContext::getOption(), called in C:\wamp\www\modx\core\model\modx\processors\system\config.js.php on line 34 and defined
            [2010-08-18 08:35:05] (ERROR @ C:\wamp\www\modx\core\model\modx\modcontext.class.php : 68) PHP warning: Missing argument 2 for modContext::getOption(), called in C:\wamp\www\modx\core\model\modx\processors\system\config.js.php on line 36 and defined
            


            In the code: ($template_url is on line 31);
            $template_url = $context->getOption('manager_url').'templates/'.$context->getOption('manager_theme').'/';
            $c = array(
                'base_url' => $context->getOption('base_url'),
                'connectors_url' => $context->getOption('connectors_url'),
                'icons_url' => $template_url.'images/ext/modext/',
                'manager_url' => $context->getOption('manager_url'),
                'template_url' => $template_url,
                'http_host' => $context->getOption('http_host',null,MODX_HTTP_HOST),
                'site_url' => $context->getOption('site_url',null,MODX_SITE_URL),
                'http_host_remote' => MODX_URL_SCHEME.$_SERVER['HTTP_HOST'],
                'user' => $modx->user->get('id'),
                'version' => $modx->version['full_version'],
                'custom_resource_classes' => $customResourceClasses,
            );


            Oh and one other funny thing is, this function obviously sanitized the requests, post, cookie and get variable. Seeing that, I don’t know why it still submits $_GET/$_REQUEST[’q’] as ’undefined’.
                /**
                 * Harden GPC variables by removing any MODx tags, Javascript, or entities.
                 */
                public function sanitizeRequest() {
                    $modxtags = array_values($this->modx->sanitizePatterns);
                    modX :: sanitize($_GET, $modxtags, 0);
                    if ($this->modx->getOption('allow_tags_in_post',null,true)) {
                        modX :: sanitize($_POST);
                    } else {
                        modX :: sanitize($_POST, $modxtags);
                    }
                    modX :: sanitize($_COOKIE, $modxtags);
                    modX :: sanitize($_REQUEST, $modxtags);
                    $rAlias = $this->modx->getOption('request_param_alias',null,'q');
                    if (isset ($_GET[$rAlias])) {
                        $_GET[$rAlias] = preg_replace("/[^A-Za-z0-9_\-\.\/]/", "", $_GET[$rAlias]);
                    }
                }

            It clearly reads if isset then..., but it does it anyway. I’ve checked through the mail test (mailing me a print_r dump of post, get, request, server and cookie).
              @MarkGHErnst

              Developer at Adwise Internetmarketing, the Netherlands.
              • 24865
              • 289 Posts
              I found the bug after 12 long hours of searching. A external script included my javascript rendered scripts but if there weren’t any, it would include as "undefined", as to: src="undefined". It would then of course keep redirecting. Aside from that, the last portion of my previous post is indeed a bug, at least - I think so. $_GET[’q’] should never be set if it were to be "undefined".
                @MarkGHErnst

                Developer at Adwise Internetmarketing, the Netherlands.