private function processRequest() { if ($this->httpRequest->isPost() && $this->httpRequest->isAjax() && $this->httpRequest->getHeader(self::XHR_HEADER)) { $data = json_decode(file_get_contents('php://input'), true); if ($data && isset($data[self::AJAX_ACTION_KEY])) { switch ($data[self::AJAX_ACTION_KEY]) { case self::AJAX_ACTION_LOAD: $message = $data[self::AJAX_MESSAGE_KEY]; if (!$this->translator->hasTranslation($message)) { throw new \Exception(); } $data = array('translation' => $this->translator->findTranslation($message)); $this->httpResponse->setContentType('application/json'); echo json_encode($data); break; case self::AJAX_ACTION_EDIT: $message = $data[self::AJAX_MESSAGE_KEY]; $translation = $data[self::AJAX_TRANSLATION_KEY]; if (!$this->translator->hasTranslation($message)) { throw new \Exception(); } $info = $this->translator->getMessageInfo($message); $data = $this->translator->_loadCategory($info['path'], $info['category']); $data[$info['name']] = $translation; $this->translator->getLoader()->save($info['path'], $info['category'], $this->translator->getLanguage(), $data); $this->httpResponse->setContentType('application/json'); break; default: throw new \Exception(); break; } } exit; } }
public function run(Nette\Application\Request $request) { $dir = realpath($this->container->parameters['tempDir'] . '/webfiles'); try { if (!$dir) { throw new Nette\Application\BadRequestException("File not found"); } $filePath = $dir . '/' . $request->parameters['file']; $this->httpResponse->setContentType($request->parameters['type'] == 'js' ? 'text/javascript' : 'text/css', 'utf-8'); return new vBuilder\Application\Responses\FileResponse($filePath, $request->parameters['file'], FALSE); } catch (Nette\Application\BadRequestException $e) { $this->httpResponse->setCode(404); return new Nette\Application\Responses\TextResponse("Not found"); } }
public function renderAuthFtp() { if ($this->httpRequest->getMethod() != "POST") { $this->error('Neplatná metoda.', 403); } $this->httpResponse->setContentType('text/plain', 'UTF-8'); $username = $this->httpRequest->getPost('username', ''); $password = $this->httpRequest->getPost('password', ''); $s = $this->share->findOneBy(array('var' => $username, 'var2' => $password)); $out = array(); if (!$s) { $out[] = 'auth_ok:0'; } else { $out[] = 'auth_ok:1'; $out[] = 'uid:' . Model\Share::shareuid; $out[] = 'gid:' . Model\Share::sharegid; $out[] = 'dir:' . Model\Share::dataBaseUrl . $s->folder->name . '/'; } $out[] = 'end'; $this->send($out); }
/** * @return Nette\Http\Response */ public static function createServiceHttpResponse() { $response = new Nette\Http\Response(); if (!$response->isSent()) { $response->setContentType('text/html', 'utf-8'); } return $response; }