public function testCreationForAllLanguages() { $c = new Config($this->container); $p = new Project($this->container); foreach ($c->getLanguages() as $locale => $language) { Translator::load($locale); $this->assertNotFalse($p->create(array('name' => 'UnitTest ' . $locale)), 'Unable to create project with ' . $locale . ':' . $language); } Translator::load('en_US'); }
/** * Send notification to someone * * @access public * @param array $user User * @param string $event_name * @param array $event_data */ public function sendUserNotification(array $user, $event_name, array $event_data) { Translator::unload(); // Use the user language otherwise use the application language (do not use the session language) if (!empty($user['language'])) { Translator::load($user['language']); } else { Translator::load($this->config->get('application_language', 'en_US')); } foreach ($this->notificationType->getUserSelectedTypes($user['id']) as $type) { $className = strtolower($type) . 'Notification'; $this->{$className}->send($user, $event_name, $event_data); } }
/** * Translate a date * * @return string */ function dt($format, $timestamp) { $t = new Translator(); return $t->datetime($format, $timestamp); }
/** * Reload settings in the session and the translations * * @access public */ public function reload() { $_SESSION['config'] = $this->getAll(); Translator::load($this->get('language', 'en_US')); }
/** * Load translations * * @access public */ public function setupTranslations() { Translator::load($this->getCurrentLanguage()); }
/** * Load translations * * @access public */ public function setupTranslations() { $language = $this->get('application_language', 'en_US'); if ($language !== 'en_US') { Translator::load($language); } }
$user = new User($registry); $category = new Category($registry); $comment = new Comment($registry); $subtask = new SubTask($registry); $board = new Board($registry); $action = new Action($registry); $webhook = new Webhook($registry); $notification = new Notification($registry); $action->attachEvents(); $project->attachEvents(); $webhook->attachEvents(); $notification->attachEvents(); // Load translations $language = $config->get('language', 'en_US'); if ($language !== 'en_US') { Translator::load($language); } $server = new Server(); $server->authentication(array('jsonrpc' => $config->get('api_token'))); /** * Project procedures */ $server->register('createProject', function ($name) use($project) { $values = array('name' => $name); list($valid, ) = $project->validateCreation($values); return $valid && $project->create($values); }); $server->register('getProjectById', function ($project_id) use($project) { return $project->getById($project_id); }); $server->register('getProjectByName', function ($name) use($project) {
/** * Translate a date * * @return string */ function dt($format, $timestamp) { return Translator::getInstance()->datetime($format, $timestamp); }
/** * Method executed before each action * * @access public */ public function beforeAction($controller, $action) { // Start the session $this->session->open(BASE_URL_DIRECTORY, SESSION_SAVE_PATH); // HTTP secure headers $this->response->csp(array('style-src' => "'self' 'unsafe-inline'")); $this->response->nosniff(); $this->response->xss(); $this->response->hsts(); $this->response->xframe(); // Load translations $language = $this->config->get('language', 'en_US'); if ($language !== 'en_US') { Translator::load($language); } // Set timezone date_default_timezone_set($this->config->get('timezone', 'UTC')); // Authentication if (!$this->authentication->isAuthenticated($controller, $action)) { $this->response->redirect('?controller=user&action=login&redirect_query=' . urlencode($this->request->getQueryString())); } // Check if the user is allowed to see this page if (!$this->acl->isPageAccessAllowed($controller, $action)) { $this->response->redirect('?controller=user&action=forbidden'); } // Attach events $this->attachEvents(); }
/** * Load translations * * @access public */ public function setupTranslations() { if ($this->userSession->isLogged() && !empty($this->session['user']['language'])) { Translator::load($this->session['user']['language']); } else { Translator::load($this->get('application_language', 'en_US')); } }
/** * Send the email notifications * * @access public * @param string $template Template name * @param array $users List of users * @param array $data Template data */ public function sendEmails($template, array $users, array $data) { try { $author = ''; if (Session::isOpen() && $this->userSession->isLogged()) { $author = e('%s via Kanboard', $this->user->getFullname($this->session['user'])); } $mailer = Swift_Mailer::newInstance($this->container['mailer']); foreach ($users as $user) { $this->container['logger']->debug('Send email notification to ' . $user['username'] . ' lang=' . $user['language']); $start_time = microtime(true); // Use the user language otherwise use the application language (do not use the session language) if (!empty($user['language'])) { Translator::load($user['language']); } else { Translator::load($this->config->get('application_language', 'en_US')); } // Send the message $message = Swift_Message::newInstance()->setSubject($this->getMailSubject($template, $data))->setFrom(array(MAIL_FROM => $author ?: 'Kanboard'))->setBody($this->getMailContent($template, $data), 'text/html')->setTo(array($user['email'] => $user['name'] ?: $user['username'])); $mailer->send($message); $this->container['logger']->debug('Email sent in ' . round(microtime(true) - $start_time, 6) . ' seconds'); } } catch (Swift_TransportException $e) { $this->container['logger']->error($e->getMessage()); } // Restore locales $this->config->setupTranslations(); }
/** * Send email notification to someone * * @access public * @param array $user User * @param string $event_name * @param array $event_data */ public function sendEmailNotification(array $user, $event_name, array $event_data) { // Use the user language otherwise use the application language (do not use the session language) if (!empty($user['language'])) { Translator::load($user['language']); } else { Translator::load($this->config->get('application_language', 'en_US')); } $this->emailClient->send($user['email'], $user['name'] ?: $user['username'], $this->getMailSubject($event_name, $event_data), $this->getMailContent($event_name, $event_data)); }