protected function execAjaxHandlers()
    {
        if ($handler = $this->getAjaxHandler()) {
            try {
                /*
                 * Validate the handler name
                 */
                if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler)) {
                    throw new CmsException(Lang::get('cms::lang.ajax_handler.invalid_name', ['name'=>$handler]));
                }

                /*
                 * Validate the handler partial list
                 */
                if ($partialList = trim(Request::header('X_OCTOBER_REQUEST_PARTIALS'))) {
                    $partialList = explode('&', $partialList);

                    foreach ($partialList as $partial) {
                        if (!preg_match('/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i', $partial)) {
                            throw new CmsException(Lang::get('cms::lang.partial.invalid_name', ['name'=>$partial]));
                        }
                    }
                }
                else {
                    $partialList = [];
                }

                $responseContents = [];

                /*
                 * Execute the handler
                 */
                if (!$result = $this->runAjaxHandler($handler)) {
                    throw new CmsException(Lang::get('cms::lang.ajax_handler.not_found', ['name'=>$handler]));
                }

                /*
                 * Render partials and return the response as array that will be converted to JSON automatically.
                 */
                foreach ($partialList as $partial) {
                    $responseContents[$partial] = $this->renderPartial($partial);
                }

                /*
                 * If the handler returned a redirect, process the URL and dispose of it so
                 * framework.js knows to redirect the browser and not the request!
                 */
                if ($result instanceof RedirectResponse) {
                    $responseContents['X_OCTOBER_REDIRECT'] = $result->getTargetUrl();
                    $result = null;
                }
                /*
                 * No redirect is used, look for any flash messages
                 */
                elseif (Request::header('X_OCTOBER_REQUEST_FLASH') && Flash::check()) {
                    $responseContents['X_OCTOBER_FLASH_MESSAGES'] = Flash::all();
                }

                /*
                 * If the handler returned an array, we should add it to output for rendering.
                 * If it is a string, add it to the array with the key "result".
                 * If an object, pass it to Laravel as a response object.
                 */
                if (is_array($result)) {
                    $responseContents = array_merge($responseContents, $result);
                }
                elseif (is_string($result)) {
                    $responseContents['result'] = $result;
                }
                elseif (is_object($result)) {
                    return $result;
                }

                return Response::make($responseContents, $this->statusCode);
            }
            catch (ValidationException $ex) {
                /*
                 * Handle validation errors
                 */
                $responseContents['X_OCTOBER_ERROR_FIELDS'] = $ex->getFields();
                $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $ex->getMessage();
                throw new AjaxException($responseContents);
            }
            catch (Exception $ex) {
                throw $ex;
            }
        }

        return null;
    }
protected function execAjaxHandlers()
    {
        if ($handler = $this->getAjaxHandler()) {
            try {
                /*
                 * Validate the handler name
                 */
                if (!preg_match('/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/', $handler)) {
                    throw new CmsException(Lang::get('cms::lang.ajax_handler.invalid_name', ['name'=>$handler]));
                }

                /*
                 * Validate the handler partial list
                 */
                if ($partialList = trim(Request::header('X_OCTOBER_REQUEST_PARTIALS'))) {
                    $partialList = explode('&', $partialList);

                    foreach ($partialList as $partial) {
                        if (!preg_match('/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i', $partial)) {
                            throw new CmsException(Lang::get('cms::lang.partial.invalid_name', ['name'=>$partial]));
                        }
                    }
                }
                else {
                    $partialList = [];
                }

                $responseContents = [];

                /*
                 * Execute the handler
                 */
                if (!$result = $this->runAjaxHandler($handler)) {
                    throw new CmsException(Lang::get('cms::lang.ajax_handler.not_found', ['name'=>$handler]));
                }

                /*
                 * Render partials and return the response as array that will be converted to JSON automatically.
                 */
                foreach ($partialList as $partial) {
                    $responseContents[$partial] = $this->renderPartial($partial);
                }

                /*
                 * If the handler returned a redirect, process the URL and dispose of it so
                 * framework.js knows to redirect the browser and not the request!
                 */
                if ($result instanceof RedirectResponse) {
                    $responseContents['X_OCTOBER_REDIRECT'] = $result->getTargetUrl();
                    $result = null;
                }
                /*
                 * No redirect is used, look for any flash messages
                 */
                elseif (Request::header('X_OCTOBER_REQUEST_FLASH') && Flash::check()) {
                    $responseContents['X_OCTOBER_FLASH_MESSAGES'] = Flash::all();
                }

                /*
                 * If the handler returned an array, we should add it to output for rendering.
                 * If it is a string, add it to the array with the key "result".
                 * If an object, pass it to Laravel as a response object.
                 */
                if (is_array($result)) {
                    $responseContents = array_merge($responseContents, $result);
                }
                elseif (is_string($result)) {
                    $responseContents['result'] = $result;
                }
                elseif (is_object($result)) {
                    return $result;
                }

                return Response::make($responseContents, $this->statusCode);
            }
            catch (ValidationException $ex) {
                /*
                 * Handle validation errors
                 */
                $responseContents['X_OCTOBER_ERROR_FIELDS'] = $ex->getFields();
                $responseContents['X_OCTOBER_ERROR_MESSAGE'] = $ex->getMessage();
                throw new AjaxException($responseContents);
            }
            catch (Exception $ex) {
                throw $ex;
            }
        }

        return null;
    }
protected function execAjaxHandlers ( ) { if ( $ handler = $ this -> getAjaxHandler ( ) ) { try { /*
                 * Validate the handler name
                 */ if ( ! preg_match ( '/^(?:\w+\:{2})?on[A-Z]{1}[\w+]*$/' , $ handler ) ) { throw new CmsException ( Lang :: get ( 'cms::lang.ajax_handler.invalid_name' , [ 'name' => $ handler ] ) ) ; } /*
                 * Validate the handler partial list
                 */ if ( $ partialList = trim ( Request :: header ( 'X_OCTOBER_REQUEST_PARTIALS' ) ) ) { $ partialList = explode ( '&' , $ partialList ) ; foreach ( $ partialList as $ partial ) { if ( ! preg_match ( '/^(?:\w+\:{2}|@)?[a-z0-9\_\-\.\/]+$/i' , $ partial ) ) { throw new CmsException ( Lang :: get ( 'cms::lang.partial.invalid_name' , [ 'name' => $ partial ] ) ) ; } } } else { $ partialList = [ ] ; } $ responseContents = [ ] ; /*
                 * Execute the handler
                 */ if ( ! $ result = $ this -> runAjaxHandler ( $ handler ) ) { throw new CmsException ( Lang :: get ( 'cms::lang.ajax_handler.not_found' , [ 'name' => $ handler ] ) ) ; } /*
                 * Render partials and return the response as array that will be converted to JSON automatically.
                 */ foreach ( $ partialList as $ partial ) { $ responseContents [ $ partial ] = $ this -> renderPartial ( $ partial ) ; } /*
                 * If the handler returned a redirect, process the URL and dispose of it so
                 * framework.js knows to redirect the browser and not the request!
                 */ if ( $ result instanceof RedirectResponse ) { $ responseContents [ 'X_OCTOBER_REDIRECT' ] = $ result -> getTargetUrl ( ) ; $ result = null ; } /*
                 * No redirect is used, look for any flash messages
                 */ elseif ( Request :: header ( 'X_OCTOBER_REQUEST_FLASH' ) && Flash :: check ( ) ) { $ responseContents [ 'X_OCTOBER_FLASH_MESSAGES' ] = Flash :: all ( ) ; } /*
                 * If the handler returned an array, we should add it to output for rendering.
                 * If it is a string, add it to the array with the key "result".
                 * If an object, pass it to Laravel as a response object.
                 */ if ( is_array ( $ result ) ) { $ responseContents = array_merge ( $ responseContents , $ result ) ; } elseif ( is_string ( $ result ) ) { $ responseContents [ 'result' ] = $ result ; } elseif ( is_object ( $ result ) ) { return $ result ; } return Response :: make ( $ responseContents , $ this -> statusCode ) ; } catch ( ValidationException $ ex ) { /*
                 * Handle validation errors
                 */ $ responseContents [ 'X_OCTOBER_ERROR_FIELDS' ] = $ ex -> getFields ( ) ; $ responseContents [ 'X_OCTOBER_ERROR_MESSAGE' ] = $ ex -> getMessage ( ) ; throw new AjaxException ( $ responseContents ) ; } catch ( Exception $ ex ) { throw $ ex ; } } return null ; }
Executes the page, layout, component and plugin AJAX handlers.
@return mixed Returns the AJAX Response object or null.
Executes the page layout component and plugin AJAX handlers .