/** * This listener is run when the KernelEvents::EXCEPTION event is triggered * * @param GetResponseForExceptionEvent $event * @return null */ public function on_kernel_exception(GetResponseForExceptionEvent $event) { $exception = $event->getException(); $message = $exception->getMessage(); if ($exception instanceof \src\exception\exception_interface) { $message = call_user_func_array(array($this->user, 'lang'), array_merge(array($message), $exception->get_parameters())); } if (!$event->getRequest()->isXmlHttpRequest()) { page_header($this->user->lang('INFORMATION')); $this->template->assign_vars(array('MESSAGE_TITLE' => $this->user->lang('INFORMATION'), 'MESSAGE_TEXT' => $message)); $this->template->set_filenames(array('body' => 'message_body.html')); page_footer(true, false, false); $response = new Response($this->template->assign_display('body'), 500); } else { $data = array(); if (!empty($message)) { $data['message'] = $message; } if (defined('DEBUG')) { $data['trace'] = $exception->getTrace(); } $response = new JsonResponse($data, 500); } if ($exception instanceof HttpExceptionInterface) { $response->setStatusCode($exception->getStatusCode()); $response->headers->add($exception->getHeaders()); } $event->setResponse($response); }
/** * Automate setting up the page and creating the response object. * * @param string $template_file The template handle to render * @param string $page_title The title of the page to output * @param int $status_code The status code to be sent to the page header * @param bool $display_online_list Do we display online users list * * @return Response object containing rendered page */ public function render($template_file, $page_title = '', $status_code = 200, $display_online_list = false) { page_header($page_title, $display_online_list); $this->template->set_filenames(array('body' => $template_file)); page_footer(true, false, false); return new Response($this->template->assign_display('body'), $status_code); }
/** * Set email template to use */ function template($template_file, $template_lang = '', $template_path = '') { global $config, $src_root_path, $phpEx, $user, $src_extension_manager; $this->setup_template(); if (!trim($template_file)) { trigger_error('No template file for emailing set.', E_USER_ERROR); } if (!trim($template_lang)) { // fall back to srcrd default language if the user's language is // missing $template_file. If this does not exist either, // $this->template->set_filenames will do a trigger_error $template_lang = basename($config['default_lang']); } if ($template_path) { $template_paths = array($template_path); } else { $template_path = !empty($user->lang_path) ? $user->lang_path : $src_root_path . 'language/'; $template_path .= $template_lang . '/email'; $template_paths = array($template_path); // we can only specify default language fallback when the path is not a custom one for which we // do not know the default language alternative if ($template_lang !== basename($config['default_lang'])) { $fallback_template_path = !empty($user->lang_path) ? $user->lang_path : $src_root_path . 'language/'; $fallback_template_path .= basename($config['default_lang']) . '/email'; $template_paths[] = $fallback_template_path; } } $this->set_template_paths(array(array('name' => $template_lang . '_email', 'ext_path' => 'language/' . $template_lang . '/email')), $template_paths); $this->template->set_filenames(array('body' => $template_file . '.txt')); return true; }
/** * Return templated value/field. Possible values for $mode are: * change == user is able to set/enter profile values; preview == just show the value */ public function process_field_row($mode, $profile_row) { $preview_options = $mode == 'preview' ? $profile_row['lang_options'] : false; // set template filename $this->template->set_filenames(array('cp_body' => $this->get_template_filename())); // empty previously filled blockvars $this->template->destroy_block_vars($this->get_name_short()); // Assign template variables $this->generate_field($profile_row, $preview_options); return $this->template->assign_display('cp_body'); }