/** * Process events * * @param Charcoal_IEventContext $context event context */ public function processEvent($context) { $request = $context->getRequest(); $response = $context->getResponse(); $sequence = $context->getSequence(); $procedure = $context->getProcedure(); $event = $context->getEvent(); // form token component $form_token = $context->getComponent(s('form_token@:charcoal:form')); if ($event instanceof Charcoal_SetupEvent) { $form_token->setupForm($sequence, $response); return b(TRUE); } elseif ($event instanceof Charcoal_AuthTokenEvent) { return $form_token->checkToken($sequence, $request); } return b(FALSE); }
/** * Process events * * @param Charcoal_IEventContext $context event context * * @return boolean */ public function processEvent($context) { log_debug("smarty", "smarty=" . spl_object_hash($this->smarty), self::TAG); /** @var Charcoal_RenderLayoutEvent $event */ $event = $context->getEvent(); /** @var Charcoal_HttpResponse $response */ $response = $context->getResponse(); $sequence = $context->getSequence(); // output response headers // $response->flushHeaders(); // retrieve layout $layout = $event->getLayout(); log_debug("smarty", "Rendering by smarty. Layout:" . print_r($layout, true), self::TAG); log_debug("smarty", "caching=" . print_r($this->smarty->caching, true), self::TAG); log_debug("smarty", "template_dir=" . print_r($this->smarty->template_dir, true), self::TAG); log_debug("smarty", "compile_dir=" . print_r($this->smarty->compile_dir, true), self::TAG); log_debug("smarty", "config_dir=" . print_r($this->smarty->config_dir, true), self::TAG); log_debug("smarty", "cache_dir=" . print_r($this->smarty->cache_dir, true), self::TAG); log_debug("smarty", "plugins_dir=" . print_r($this->smarty->plugins_dir, true), self::TAG); $error_handler_old = NULL; try { $charcoal = array(); // page redirection if ($layout instanceof Charcoal_IRedirectLayout) { $url = $layout->makeRedirectURL(); $response->redirect(s($url)); log_debug("system, debug, smarty, redirect", "redirected to URL: {$url}", self::TAG); } elseif ($event instanceof Charcoal_URLRedirectEvent) { /** @var Charcoal_URLRedirectEvent $event */ $url = $event->getURL(); $response->redirect(s($url)); log_debug("system, debug, smarty, redirect", "redirected to URL: {$url}", self::TAG); } elseif ($event instanceof Charcoal_RenderLayoutEvent) { // Page information $page_info = $layout->getAttribute(s('page_info')); log_debug("smarty", "page_info=" . print_r($page_info, true), self::TAG); // Profile information $profile_config = $this->getSandbox()->getProfile()->getAll(); if ($profile_config && is_array($profile_config)) { foreach ($profile_config as $key => $value) { $charcoal['profile'][$key] = $value; } } // Cookie information if ($response instanceof Charcoal_HttpResponse) { $cookies = $response->getCookies(); if ($cookies && is_array($cookies)) { foreach ($cookies as $key => $value) { $charcoal['cookie'][$key] = $value; } } } $smarty = $this->smarty; // Assign variables if ($page_info && is_array($page_info)) { foreach ($page_info as $key => $value) { $smarty->assign($key, $value); } } // Sequence data $charcoal['sequence'] = $sequence; // Request ID and reauest path $charcoal['request']['id'] = $this->getSandbox()->getEnvironment()->get('%REQUEST_ID%'); $charcoal['request']['path'] = $this->getSandbox()->getEnvironment()->get('%REQUEST_PATH%'); // Assign all $smarty->assign('charcoal', $charcoal); // Assign all layout values $layout_values = $event->getValues(); if (!$layout_values) { // If layout values are not set, response values will be used instead. $layout_values = $response->getAll(); } foreach ($layout_values as $key => $value) { $smarty->assign($key, $value); } $smarty->assign('_smarty', $smarty); // render template $template = $layout->getAttribute(s('layout')); // set smarty error_reporting flags $this->smarty->error_reporting = E_ALL & ~E_STRICT & ~E_WARNING & ~E_NOTICE & ~8192; // rewrite error handler $error_handler_old = set_error_handler(array($this, "onUnhandledError")); // compile and output template log_debug("smarty", "template={$template}", self::TAG); $html = $smarty->fetch($template); log_debug("smarty", "html={$html}", self::TAG); // output to rendering target $render_target = $event->getRenderTarget(); if ($render_target) { $render_target->render($html); log_debug("smarty", "Rendered by render target: {$render_target}", self::TAG); } else { echo $html; log_debug("smarty", "Output by echo.", self::TAG); } } } catch (Exception $ex) { _catch($ex); _throw(new Charcoal_SmartyRendererTaskException("rendering failed", $ex)); } if ($error_handler_old) { set_error_handler($error_handler_old); } return b(TRUE); }
/** * Process events * * @param Charcoal_IEventContext $context event context */ public function processEvent($context) { $event = $context->getEvent(); $response = $context->getResponse(); $sequence = $context->getSequence(); // output response headers $response->flushHeaders(); // retrieve layout $layout = $event->getLayout(); // log_info( "system,renderer", "Rendering by smarty. Layout:" . print_r($layout,true) ); try { $charcoal = array(); // page redirection if ($layout instanceof Charcoal_IRedirectLayout) { $url = $layout->makeRedirectURL(); $response->redirect(s($url)); // log_info( "system,renderer", "renderer", "Redirected to: $url" ); } elseif ($event instanceof Charcoal_URLRedirectEvent) { $url = $event->getURL(); $response->redirect(s($url)); // log_info( "system,renderer", "renderer", "Redirected to: $url" ); } else { // Page information $page_info = $layout->getAttribute(s('page_info')); // Profile information $profile_config = Charcoal_Profile::getConfig(); if ($profile_config && is_array($profile_config)) { foreach ($profile_config as $key => $value) { $charcoal['profile'][$key] = $value; } } // Cookie information $cookies = $response->getCookies(); if ($cookies && is_array($cookies)) { foreach ($cookies as $key => $value) { $charcoal['cookie'][$key] = $value; } } // Assign variables if ($page_info && is_array($page_info)) { foreach ($page_info as $key => $value) { ${$key} = $value; } } // Sequence data $charcoal['sequence'] = $sequence; // Request ID and reauest path $charcoal['request']['id'] = $this->getSandbox()->getEnvironment()->get('%REQUEST_ID%'); $charcoal['request']['path'] = $this->getSandbox()->getEnvironment()->get('%REQUEST_PATH%'); // Assign all //$charcoal = $charcoal; // Assign all response values $keys = $response->getKeys(); foreach ($keys as $key) { $value = $response->get(s($key)); $smarty->assign($key, $value); } // render template $template = $layout->getAttribute(s('layout')); // log_info( "smarty", "template=$template" ); $html = $smarty->fetch($template); // log_info( "smarty", "html=$html" ); echo $html; } } catch (Exception $ex) { _catch($ex); _throw(new Charcoal_SmartyRendererTaskException("rendering failed", $ex)); } return b(TRUE); }