/** * 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); }
/** * 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'); }
/** * Send the mail out to the recipients set previously in var $this->addresses */ function send($method = NOTIFY_EMAIL, $break = false) { global $config, $user; // We add some standard variables we always use, no need to specify them always $this->assign_vars(array('U_srcRD' => generate_srcrd_url(), 'EMAIL_SIG' => str_replace('<br />', "\n", "-- \n" . htmlspecialchars_decode($config['srcrd_email_sig'])), 'SITENAME' => htmlspecialchars_decode($config['sitename']))); // Parse message through template $this->msg = trim($this->template->assign_display('body')); // Because we use \n for newlines in the body message we need to fix line encoding errors for those admins who uploaded email template files in the wrong encoding $this->msg = str_replace("\r\n", "\n", $this->msg); // We now try and pull a subject from the email body ... if it exists, // do this here because the subject may contain a variable $drop_header = ''; $match = array(); if (preg_match('#^(Subject:(.*?))$#m', $this->msg, $match)) { $this->subject = trim($match[2]) != '' ? trim($match[2]) : ($this->subject != '' ? $this->subject : $user->lang['NO_EMAIL_SUBJECT']); $drop_header .= '[\\r\\n]*?' . preg_quote($match[1], '#'); } else { $this->subject = $this->subject != '' ? $this->subject : $user->lang['NO_EMAIL_SUBJECT']; } if ($drop_header) { $this->msg = trim(preg_replace('#' . $drop_header . '#s', '', $this->msg)); } if ($break) { return true; } switch ($method) { case NOTIFY_EMAIL: $result = $this->msg_email(); break; case NOTIFY_IM: $result = $this->msg_jabber(); break; case NOTIFY_BOTH: $result = $this->msg_email(); $this->msg_jabber(); break; } $this->reset(); return $result; }