/** * New messenger method: * Uses an expandable array of options and supports direct template rendering and subject prepending. * * @param array $message_options An array of message options. * @return bool|void */ public static function send($message_options) { $di = \Phalcon\Di::getDefault(); $config = $di->get('config'); $default_options = array('reply_to' => NULL, 'delivery_date' => NULL, 'options' => NULL); $options = array_merge($default_options, $message_options); // Render the template as the message if a template is specified. if (isset($options['template'])) { $previous_sp_setting = \DF\Url::getSchemePrefixSetting(); \DF\Url::forceSchemePrefix(TRUE); $view = \DF\Phalcon\View::getView(array('views_dir' => 'messages', 'layouts_dir' => '../templates', 'layout' => 'message')); $view->subject = $options['subject']; $view->setVars((array) $options['vars']); $options['message'] = $view->getRender('', $options['template']); \DF\Url::forceSchemePrefix($previous_sp_setting); } else { if (isset($options['body']) && !isset($options['message'])) { $options['message'] = $options['body']; unset($options['body']); } } // Append the system name as a prefix to the message. if (!isset($options['no_prefix']) || $options['no_prefix'] == FALSE) { $app_name = $config->application->name; $options['subject'] = $app_name . ': ' . $options['subject']; } return self::sendMail($options); }
/** * @param \Phalcon\DiInterface $di */ public function registerServices(\Phalcon\DiInterface $di = null) { // Set up MVC dispatcher. $controller_class = 'Modules\\' . $this->_module_class_name . '\\Controllers'; $di['dispatcher'] = function () use($controller_class) { $eventsManager = new \Phalcon\Events\Manager(); $eventsManager->attach("dispatch:beforeDispatchLoop", function ($event, $dispatcher) { // Set odd/even pairs as the key and value of parameters, respectively. $keyParams = array(); $params = $dispatcher->getParams(); foreach ($params as $number => $value) { if ($number & 1) { $keyParams[$params[$number - 1]] = urldecode($value); } } $dispatcher->setParams($keyParams); // Detect filename in controller and convert to "format" parameter. $controller_name = $dispatcher->getControllerName(); if (strstr($controller_name, '.') !== false) { list($controller_clean, $format) = explode('.', $controller_name, 2); $dispatcher->setControllerName($controller_clean); $dispatcher->setParam('format', $format); } // Detect filename in action and convert to "format" parameter. $action_name = $dispatcher->getActionName(); if (strstr($action_name, '.') !== false) { list($action_clean, $format) = explode('.', $action_name, 2); $dispatcher->setActionName($action_clean); $dispatcher->setParam('format', $format); } }); $dispatcher = new \Phalcon\Mvc\Dispatcher(); $dispatcher->setEventsManager($eventsManager); $dispatcher->setDefaultNamespace($controller_class); return $dispatcher; }; // Set up module-specific configuration. $module_base_name = strtolower($this->_module_class_name); $module_config = $di->get('module_config'); $di->setShared('current_module_config', function () use($module_base_name, $module_config) { if (isset($module_config[$module_base_name])) { return $module_config[$module_base_name]; } else { return null; } }); // Set up the view component and shared templates. $views_dir = 'modules/' . $module_base_name . '/views/scripts/'; $di['view'] = function () use($views_dir) { return \DF\Phalcon\View::getView(array('views_dir' => $views_dir)); }; }
public static function handle(\Exception $e, \Phalcon\DiInterface $di) { if ($e instanceof \DF\Exception\NotLoggedIn) { // Redirect to login page for not-logged-in users. \DF\Flash::addMessage('You must be logged in to access this page!'); // Set referrer for login redirection. $session = \DF\Session::get('referrer_login'); $session->url = \DF\Url::current($di); // Redirect to login page. $login_url = $di->get('url')->get('account/login'); $response = $di->get('response'); $response->redirect($login_url, 302); $response->send(); return; } elseif ($e instanceof \DF\Exception\PermissionDenied) { // Bounce back to homepage for permission-denied users. \DF\Flash::addMessage('You do not have permission to access this portion of the site.', \DF\Flash::ERROR); $home_url = $di->get('url')->get(''); $response = $di->get('response'); $response->redirect($home_url, 302); $response->send(); return; } elseif ($e instanceof \Phalcon\Mvc\Dispatcher\Exception) { // Handle 404 page not found exception if ($di->has('view')) { $view = $di->get('view'); $view->disable(); } $view = \DF\Phalcon\View::getView(array()); $result = $view->getRender('error', 'pagenotfound'); $response = $di->get('response'); $response->setStatusCode(404, "Not Found"); $response->setContent($result); $response->send(); return; } elseif ($e instanceof \DF\Exception\Bootstrap) { // Bootstrapping error; cannot render template for error display. if (DF_APPLICATION_ENV != 'production') { self::renderPretty($e, $di); return; } else { $response = $di->get('response'); $response->setStatusCode(500, "Internal Server Error"); $exception_msg = "<b>Application core exception: </b>\n<blockquote>" . $e->getMessage() . "</blockquote>" . "\n" . "on line <b>" . $e->getLine() . "</b> of <i>" . $e->getFile() . "</i>"; $response->setContent($exception_msg); $response->send(); return; } } else { if ($di->has('view')) { $view = $di->get('view'); $view->disable(); } $show_debug = false; if ($di->has('acl')) { $acl = $di->get('acl'); if ($acl->isAllowed('administer all')) { $show_debug = true; } } if (DF_APPLICATION_ENV != 'production') { $show_debug = true; } if ($show_debug) { self::renderPretty($e, $di); return; } else { $view = \DF\Phalcon\View::getView(array()); $view->setVar('exception', $e); $result = $view->getRender('error', 'general'); $response = $di->get('response'); $response->setStatusCode(500, "Internal Server Error"); $response->setContent($result); $response->send(); return; } } }