Пример #1
0
 function __construct($from, $fromName = NULL, Nette\Bridges\ApplicationLatte\ILatteFactory $latteFactory, Nette\Application\LinkGenerator $linkGenerator, Nette\Http\Request $httpRequest)
 {
     $this->from($from, $fromName);
     $this->latteFactory = $latteFactory;
     $this->linkGenerator = $linkGenerator;
     $this->refUrl = $httpRequest->getUrl();
 }
Пример #2
0
 /**
  * @param \Kdyby\Translation\Translator $translator
  * @return string|NULL
  */
 public function resolve(Kdyby\Translation\Translator $translator)
 {
     $short = array_map(function ($locale) {
         return substr($locale, 0, 2);
     }, $translator->getAvailableLocales());
     return $this->httpRequest->detectLanguage($short) ?: NULL;
 }
Пример #3
0
 protected function startup()
 {
     parent::startup();
     if ($this->authentication->getCredential() !== substr($this->httpRequest->getHeader('authorization'), 6)) {
         //throw new AuthenticationException();
     }
 }
Пример #4
0
 public function render()
 {
     $baseUrl = rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/');
     $basePath = preg_replace('#https?://[^/]+#A', '', $baseUrl);
     $this->setTempPath($basePath . $this->relativeTempPath);
     $this->setMedia(null);
     $this->setType('text/css');
     $this->setTitle(null);
     $this->setAlternate(null);
     $args = array();
     if (func_num_args() > 0) {
         foreach (func_get_args() as $arg) {
             if (is_array($arg) && isset($arg['config'])) {
                 if (isset($arg['config']['media'])) {
                     $this->setMedia($arg['config']['media']);
                 }
                 if (isset($arg['config']['type'])) {
                     $this->setType($arg['config']['type']);
                 }
                 if (isset($arg['config']['title'])) {
                     $this->setTitle($arg['config']['title']);
                 }
                 if (isset($arg['config']['alternate'])) {
                     $this->setAlternate($arg['config']['alternate']);
                 }
             } else {
                 $args[] = $arg;
             }
         }
     }
     call_user_func_array(array($this, 'parent::render'), $args);
 }
Пример #5
0
 /**
  * @param Request $request
  * @return Notification
  */
 public static function createFromRequest(Request $request)
 {
     $notification = new Notification();
     $parsed = Json::decode($request->getRawBody());
     $notification->setLive($parsed->live === 'true');
     $items = array();
     foreach ($parsed->notificationItems as $rawItem) {
         $item = new NotificationRequestItem($notification);
         $item->setAdditionalData(self::getNotificationRequestItemValue($rawItem, 'additionalData'));
         $item->setAmountValue(self::getNotificationRequestItemValue($rawItem, 'amount.value'));
         $item->setAmountCurrency(self::getNotificationRequestItemValue($rawItem, 'amount.currency'));
         $item->setPspReference(self::getNotificationRequestItemValue($rawItem, 'pspReference'));
         $item->setEventCode(self::getNotificationRequestItemValue($rawItem, 'eventCode'));
         $date = new DateTime(self::getNotificationRequestItemValue($rawItem, 'eventDate'));
         $item->setEventDate($date);
         $item->setMerchantAccountCode(self::getNotificationRequestItemValue($rawItem, 'merchantAccountCode'));
         $item->setOperations(self::getNotificationRequestItemValue($rawItem, 'operations'));
         $item->setMerchantReference(self::getNotificationRequestItemValue($rawItem, 'merchantReference'));
         $item->setOriginalReference(self::getNotificationRequestItemValue($rawItem, 'originalReference'));
         $item->setPaymentMethod(self::getNotificationRequestItemValue($rawItem, 'paymentMethod'));
         $item->setReason(self::getNotificationRequestItemValue($rawItem, 'reason'));
         $item->setSuccess(self::getNotificationRequestItemValue($rawItem, 'success') === 'true');
         $items[] = $item;
     }
     $notification->setNotificationItems($items);
     return $notification;
 }
Пример #6
0
 /**
  * @param array $values
  * @return Comment
  * @throws ActionFailedException
  */
 public function save(array $values)
 {
     $numberOfComments = $this->getNumberOfComments($values['page']);
     $repliesReferences = $this->findRepliesReferences($values['text']);
     try {
         $this->em->beginTransaction();
         // no replies references found
         if (empty($repliesReferences)) {
             $comment = new Comment($values['author'], $this->texy->process($values['text']), $values['page'], $numberOfComments + 1, $this->request->getRemoteAddress());
             $this->em->persist($comment)->flush();
             $this->em->commit();
             return $comment;
         }
         $commentsToReply = $this->findCommentsToReply($values['page'], $repliesReferences);
         $values['text'] = $this->replaceReplyReferencesByAuthors($values['text'], $commentsToReply);
         $comment = new Comment($values['author'], $this->texy->process($values['text']), $values['page'], $numberOfComments + 1);
         $this->em->persist($comment);
         /** @var Comment $comment */
         foreach ($commentsToReply as $commentToReply) {
             $commentToReply->addReaction($comment);
             $this->em->persist($commentToReply);
         }
         $this->em->flush();
         $this->em->commit();
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         throw new ActionFailedException();
     }
     return $comment;
 }
 public function createTemplate($class = NULL)
 {
     $latte = $this->latteFactory->create();
     $template = $class ? new $class($latte) : new Template($latte);
     $template->getLatte()->addFilter(NULL, 'Nette\\Templating\\Helpers::loader');
     if ($latte->onCompile instanceof Traversable) {
         $latte->onCompile = iterator_to_array($latte->onCompile);
     }
     array_unshift($latte->onCompile, function ($latte) {
         $latte->getParser()->shortNoEscape = TRUE;
         $latte->getCompiler()->addMacro('cache', new CacheMacro($latte->getCompiler()));
         UIMacros::install($latte->getCompiler());
         FormMacros::install($latte->getCompiler());
     });
     $latte->addFilter('url', 'rawurlencode');
     // back compatiblity
     foreach (array('normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse') as $name) {
         $latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name);
     }
     $template->user = $this->user;
     $template->netteHttpResponse = $this->httpResponse;
     $template->netteCacheStorage = $this->httpRequest;
     $template->baseUri = $template->baseUrl = rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/');
     $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl);
     if (!isset($template->flashes) || !is_array($template->flashes)) {
         $template->flashes = array();
     }
     $template->setTranslator($this->translator);
     $template->_control = $this->linker;
     return $template;
 }
 /**
  * Provide auto merge
  */
 public function actionDefault()
 {
     $payload = $this->httpRequest->getRawBody();
     if (!$payload) {
         Debugger::log('No payload data', Debugger::ERROR);
         $this->terminate();
     }
     $data = json_decode($payload, true);
     if (!$data) {
         Debugger::log('json_decode error', Debugger::ERROR);
         $this->terminate();
     }
     if ($data['object_kind'] != 'note') {
         Debugger::log('Only notes object kind processing now. *' . $data['object_kind'] . '* given', Debugger::ERROR);
         $this->terminate();
     }
     $projectId = isset($data['merge_request']['source_project_id']) ? $data['merge_request']['source_project_id'] : false;
     $mergeRequestId = isset($data['merge_request']['id']) ? $data['merge_request']['id'] : false;
     if (!$projectId || !$mergeRequestId) {
         Debugger::log('projectId or mergeRequestId missing', Debugger::ERROR);
         $this->terminate();
     }
     $project = $this->projectRepository->findByGitlabId($projectId);
     if (!$project) {
         Debugger::log('Project ' . $projectId . ' is not allowed to auto merge', Debugger::ERROR);
         $this->terminate();
     }
     $mr = $this->gitlabClient->api('mr')->show($projectId, $mergeRequestId);
     $mergeRequest = $this->mergeRequestBuilder->create($mr, $data);
     if ($mergeRequest->canBeAutoMerged($project->positive_votes)) {
         $this->gitlabClient->api('mr')->merge($projectId, $mergeRequestId, 'Auto merged');
     }
 }
Пример #9
0
 public function __construct(array $options = array(), \Nette\Http\Request $request, \Nette\Http\Response $response)
 {
     $this->_cookies = $request->getCookies();
     $this->_request = $request;
     $this->_response = $response;
     $this->setOptions($options);
 }
Пример #10
0
 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;
     }
 }
Пример #11
0
 /**
  * @return mixed|string
  */
 protected function readData()
 {
     $data = $this->readInput();
     if (!$data) {
         $data = $this->httpRequest->getPost();
     }
     return $data;
 }
Пример #12
0
 private function _detectAction(HttpRequest $request)
 {
     $method = $request->getMethod();
     if (isset($this->actions[$method])) {
         return $this->actions[$method];
     }
     throw new InvalidStateException('Method ' . $method . ' is not allowed.');
 }
Пример #13
0
 /**
  * @return \Nette\Http\Url|\Nette\Http\UrlScript
  */
 public function create()
 {
     $url = $this->httpRequest->getUrl();
     if (!$url->getHost()) {
         $url = $this->fallbackUrl;
     }
     return $url;
 }
 public function render()
 {
     $basePath = $this->request->getUrl()->getBasePath();
     $data = "var base_path = \"" . $basePath . '";';
     /** @var Html $el */
     $el = Html::el("script")->type("text/javascript");
     $el->setText($data);
     echo $el;
 }
 /**
  * @param string $basePath = self::BASE_PATH
  * @param Request $request
  * @return IRouter
  */
 public static function createRouter($basePath = self::BASE_PATH, Request $request)
 {
     $secured = $request->isSecured();
     $installRouter = new RouteList('Install');
     $installRouter[] = $devSubmoduleRouter = new RouteList('Dev');
     $devSubmoduleRouter[] = new Route($basePath . 'dev/<presenter=Default>[/<action=default>]', [], $secured ? Route::SECURED : 0);
     $installRouter[] = new Route($basePath . '<presenter=Default>[/<action=default>]', [], $secured ? Route::SECURED : 0);
     return $installRouter;
 }
Пример #16
0
 /**
  * @return Search
  */
 public function create()
 {
     $search = new Search();
     // Pass parameters from request
     $search->by = $this->request->getQuery('search-by', 'popularity');
     $search->limit = $this->request->getQuery('search-limit');
     $search->q = $this->request->getQuery('q', NULL);
     return $search;
 }
Пример #17
0
 /**
  * Sets the user identity.
  * @param Nette\Security\IIdentity $identity
  * @return Storage
  */
 public function setIdentity(Nette\Security\IIdentity $identity = NULL)
 {
     if (!is_null($identity)) {
         $identity->browser = $this->browser->getName();
         $identity->browserVersion = $this->browser->getVersion();
         $identity->hash = $this->identityHash->createIdentityHash($identity->getId(), $this->request->getRemoteAddress());
     }
     return parent::setIdentity($identity);
 }
Пример #18
0
 /**
  */
 public function renderDefault($city)
 {
     dump(func_get_args());
     $httpRequest = new Nette\Http\Request(new Nette\Http\UrlScript($_SERVER['REQUEST_URI']));
     dump($httpRequest->getUrl());
     dump($httpRequest->getMethod());
     dump($httpRequest->getHeaders());
     // get city
     $this->template->city = $city;
 }
Пример #19
0
 /**
  */
 public function renderShow($seo_url)
 {
     dump(func_get_args());
     $httpRequest = new Nette\Http\Request(new Nette\Http\UrlScript($_SERVER['REQUEST_URI']));
     dump($httpRequest->getUrl());
     dump($httpRequest->getMethod());
     dump($httpRequest->getHeaders());
     // get article
     $this->template->article = $this->_articleModel->fetchSingle($seo_url);
 }
Пример #20
0
 /**
  * Lost password form
  * @return Form
  */
 public function create()
 {
     $form = new Form();
     $form->addText('mail', 'Zadejte svůj registrovaný mail')->setRequired('Zadejte svůj mail')->addRule(Form::EMAIL, 'Nesprávný formát mailu')->setType('email');
     $form->addPassword('password', 'Vaše přihlašovací heslo po 1.:')->setRequired('Prosím zadejte vaše heslo')->addRule(Form::PATTERN, 'Musí obsahovat číslici', '.*[0-9].*')->addRule(Form::MIN_LENGTH, 'Heslo musí mít alespoň %d znaků', 6);
     $form->addPassword('password2', 'Vaše přihlašovací heslo po 2.:')->addRule(Form::FILLED, "Potvrzovací heslo musí být vyplněné !")->addConditionOn($form["password"], Form::FILLED)->addRule(Form::EQUAL, "Hesla se musí shodovat !", $form["password"]);
     $form->addHidden('passwordCheckCode', $this->request->getQuery('id'));
     $form->addSubmit('renew', 'Nastavit nové heslo');
     $form->onSuccess[] = [$this, 'succeeded'];
     return $form;
 }
Пример #21
0
 /**
  * Try find user language.
  *
  * @return string
  */
 public function detectLanguage()
 {
     if ($this->default) {
         return $this->default;
     }
     $lang = $this->request->detectLanguage(array_keys($this->languages));
     if ($lang) {
         return $lang;
     }
     return $this->getDefault();
 }
Пример #22
0
 public function loadParamVat($default)
 {
     $paramGet = $this->request->getQuery($this->getParamVat());
     if ($paramGet !== NULL) {
         return $this->setSessionVat($paramGet);
     }
     if (isset($this->session->{$this->getParamVat()})) {
         return $this->session->{$this->getParamVat()};
     }
     return $this->setSessionVat($default);
 }
Пример #23
0
 /**
  * @return \Texy
  */
 public function createTexyForPage()
 {
     $texy = new \Texy();
     $texy->headingModule->top = 3;
     $texy->setOutputMode(\Texy::HTML5);
     // Images
     $texy->imageModule->root = $this->request->getUrl()->getBaseUrl() . $this->imagesRoot;
     $texy->imageModule->fileRoot = $this->imagesFileRoot;
     $texy->addHandler('block', [$this, 'blockHandler']);
     return $texy;
 }
Пример #24
0
 public function __construct($imageTempDir, $wwwImageTemp, $sourceDir, Http\Request $request)
 {
     if ($wwwImageTemp && substr($wwwImageTemp, -1) == '/') {
         $wwwImageTemp = rtrim($wwwImageTemp, '/');
     }
     $this->imageTempDir = $imageTempDir;
     $this->wwwImageTemp = $wwwImageTemp;
     $this->sourceDir = $sourceDir;
     $url = $request->getUrl();
     $this->basePath = $url->getBasePath();
     $this->hostUrl = $url->getHostUrl();
 }
Пример #25
0
 public function __construct(Request $request, IStorage $cacheStorage)
 {
     $this->request = $request;
     $this->cache = new Cache($cacheStorage, 'MailPanel');
     switch ($request->getQuery('mail-panel')) {
         case 'download':
             $this->handleDownload($request->getQuery('mail-panel-mail'), $request->getQuery('mail-panel-file'));
             break;
         default:
             break;
     }
 }
Пример #26
0
 /**
  * @param Helpers\DeviceView $deviceView
  * @param Http\Request $httpRequest
  */
 public function __construct(Helpers\DeviceView $deviceView, Http\Request $httpRequest)
 {
     $this->deviceView = $deviceView;
     // Get http headers
     $httpHeaders = $httpRequest->getHeaders();
     // Set http headers
     $this->setHttpHeaders($httpHeaders);
     // If user agent info is set in headers...
     if (isset($httpHeaders['user-agent'])) {
         // ...set user agent details
         $this->setUserAgent($httpHeaders['user-agent']);
     }
 }
Пример #27
0
 public function compileConfig()
 {
     $repositories = $this->getAll();
     $domain = $this->httpRequest->getUrl()->getHostUrl();
     $config = ['homepage' => $domain, 'repositories' => []];
     foreach ($this->parameters as $property => $value) {
         $config[$property] = $value;
     }
     foreach ($repositories as $repository) {
         $config['repositories'][] = ['type' => $repository->type, 'url' => $repository->url];
     }
     $json = Json::encode($config, Json::PRETTY);
     FileSystem::write($this->configFile, $json);
 }
Пример #28
0
 public function render()
 {
     $baseUrl = rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/');
     $basePath = preg_replace('#https?://[^/]+#A', '', $baseUrl);
     $this->setTempPath($basePath . $this->relativeTempPath);
     $args = array();
     if (func_num_args() > 0) {
         foreach (func_get_args() as $arg) {
             if (!is_array($arg) || !isset($arg['config'])) {
                 $args[] = $arg;
             }
         }
     }
     call_user_func_array(array($this, 'parent::render'), $args);
 }
Пример #29
0
 /**
  * @see Nette\Application\Control#render()
  */
 public function render()
 {
     if ($this->staticMap) {
         $this->getTemplate()->height = $this->height;
         $this->getTemplate()->width = $this->width;
         $this->getTemplate()->zoom = $this->zoom;
         $this->getTemplate()->position = $this->coordinates;
         $this->getTemplate()->markers = $this->markers;
         $this->getTemplate()->clickable = $this->clickable;
         $this->getTemplate()->setFile(dirname(__FILE__) . '/static.latte');
     } else {
         //forward compatibility
         $currentUrl = '/' . $this->httpRequest->getUrl()->getRelativeUrl();
         if (preg_match('/\\?/i', $currentUrl)) {
             $currentUrl .= '&do=';
         } else {
             $currentUrl .= '?do=';
         }
         $map = array('position' => $this->coordinates, 'height' => $this->height, 'width' => $this->width, 'zoom' => $this->zoom, 'type' => $this->type, 'scrollable' => $this->scrollable, 'key' => $this->key, 'bound' => $this->bound, 'cluster' => $this->markerClusterer);
         $this->getTemplate()->map = \Nette\Utils\Json::encode($map);
         $this->getTemplate()->waypointlimit = $this->waypoint_limit;
         $this->getTemplate()->preserveViewport = $this->preserveViewport;
         $this->getTemplate()->markersFallbackUrl = $currentUrl . 'map-markers';
         $this->getTemplate()->waypointsFallbackUrl = $currentUrl . 'map-waypoints';
         $this->getTemplate()->setFile(dirname(__FILE__) . '/template.latte');
     }
     $this->getTemplate()->render();
 }
Пример #30
0
 protected function startup()
 {
     parent::startup();
     $devIPs = array('10.107.91.237');
     if (!in_array($this->request->getRemoteAddress(), $devIPs) && $this->maintenance) {
         if ($this->getPresenter()->name != "Homepage" || $this->getAction() != "maintenance") {
             $this->redirect("Homepage:maintenance");
         }
     }
     $nonLoginPresenters = array('Sign', 'Homepage', 'Api');
     $presenterName = $this->getPresenter()->name;
     if (!in_array($presenterName, $nonLoginPresenters) && $this->user->isLoggedIn() != true) {
         $this->flashMessage("Pro vstup do systému se přihlašte, prosím.");
         $this->redirect("Sign:in");
     }
 }