public function dataFormatTemplateFiles() { $context = \Nette\Environment::getContext(); return array( array('Nella\Foo\Bar::render', array( $context->params['appDir'] . "/Foo/Bar.latte", $context->params['appDir'] . "/templates/Foo/Bar.latte", __DIR__ . "/Foo/Bar.latte", __DIR__ . "/templates/Foo/Bar.latte", NELLA_FRAMEWORK_DIR . "/Foo/Bar.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo/Bar.latte", )), array('Nella\Foo\Bar::renderBaz', array( $context->params['appDir'] . "/Foo/Bar.baz.latte", $context->params['appDir'] . "/templates/Foo/Bar.baz.latte", __DIR__ . "/Foo/Bar.baz.latte", __DIR__ . "/templates/Foo/Bar.baz.latte", NELLA_FRAMEWORK_DIR . "/Foo/Bar.baz.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo/Bar.baz.latte", )), array('Nella\Foo::renderBarBaz', array( $context->params['appDir'] . "/Foo.barBaz.latte", $context->params['appDir'] . "/templates/Foo.barBaz.latte", __DIR__ . "/Foo.barBaz.latte", __DIR__ . "/templates/Foo.barBaz.latte", NELLA_FRAMEWORK_DIR . "/Foo.barBaz.latte", NELLA_FRAMEWORK_DIR . "/templates/Foo.barBaz.latte", )), ); }
/** * @return Cache */ protected static function getCache() { if (self::$cache === NULL) { self::$cache = \Nette\Environment::getService('webloader.cache'); } return self::$cache; }
/** * @param Nette\Web\IHttpRequest $httpRequest * @return Nette\Application\PresenterRequest|NULL */ public function match(\Nette\Http\IRequest $httpRequest) { /** @var $appRequest \Nette\Application\Request */ $appRequest = parent::match($httpRequest); // doplněno: pokud match vrátí NULL, musíme také vrátit NULL if (!$appRequest) { return $appRequest; } // musím si přeložit host, kvůli localhostu to není dané if (strpos($httpRequest->url->host, '.localhost') !== false && !\Nette\Environment::isProduction()) { // jsme na localhostu $host = substr($httpRequest->url->host, 0, strripos($httpRequest->url->host, '.localhost')); // musíme si doménu osamostatnit od .localhost $host = str_replace('_', '.', $host); // na lokálu mám místo teček podtržení } else { // jsme na produkci $host = $httpRequest->url->host; } // zkusím zda je soubor již v cache if (is_file(WEB_DIR . '/' . $host . '/cache' . $httpRequest->url->path)) { return new Nette\Application\Request('Frontend', 'POST', array('action' => 'cache', 'file' => WEB_DIR . '/' . $host . '/cache' . $httpRequest->url->path)); } /* if ($params = $this->doFilterParams($this->getRequestParams($appRequest), $appRequest, self::WAY_IN)) { return $this->setRequestParams($appRequest, $params); } */ // $pages = $this->context->createPages(); $data = array('action' => 'default'); return new Nette\Application\Request('Frontend', 'POST', $data); }
public function renderShow($id) { $service = new TripService($this->entityManager); $trip = $service->find($id); $this->template->trip = $trip; try { $eventService = new EventService(); $config = Environment::getConfig('api'); $events = $eventService->getEvents($trip->arrival, new DateTime(), new EventfulMapper($config->eventfulUser, $config->eventfulPassword, $config->eventfulKey)); $this->template->events = $events; } catch (InvalidStateException $e) { $this->template->events = array(); } $articleService = new ArticleService($this->entityManager); $this->template->article = $articleService->buildArticle($trip->arrival, new ArticleWikipediaMapper()); try { $airportMapper = new AirportTravelMathMapper(); $airportService = new AirportService(); $locationService = new LocationService(); $coordinates = $locationService->getCoordinates($trip->getDeparture()); $from = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']); $coordinates = $locationService->getCoordinates($trip->getArrival()); $to = $airportService->searchNearestAirport($airportMapper, $coordinates['latitude'], $coordinates['longitude']); $flightMapper = new FlightKayakMapper(); $flightService = new FlightService($this->entityManager); $depart_date = new DateTime('now'); $return_date = new DateTime('+1 week'); $this->template->flights = $flightService->buildFlights($flightMapper, $from, $to, $depart_date, $return_date, '1', 'e', 'n'); } catch (FlightException $e) { $this->template->flightsError = "Connection with search system <a href='http://kayak.com'>Kayak</a> failed."; } catch (AirportException $e) { $this->template->flightsError = $e->getMessage(); } }
/** * Handles uploaded files * forwards it to model */ public function handleUploads() { // Iterujeme nad přijatými soubory foreach (\Nette\Environment::getHttpRequest()->getFiles() as $name => $controlValue) { // MFU vždy posílá soubory v této struktuře: // // array( // "token" => "blablabla", // "files" => array( // 0 => HttpUploadedFile(...), // ... // ) // ) $isFormMFU = (is_array($controlValue) and isset($controlValue["files"]) and isset($_POST[$name]["token"])); if ($isFormMFU) { $token = $_POST[$name]["token"]; foreach ($controlValue["files"] as $file) { self::processFile($token, $file); } } // soubory, které se netýkají MFU nezpracujeme -> zpracuje si je standardním způsobem formulář } return true; // Skip all next }
public function setLocale($lang) { switch ($lang) { case 'en': setlocale(LC_ALL, 'en_EN.UTF8', 'en_EN.UTF-8', 'en_EN '); break; case 'cs': default: setlocale(LC_ALL, 'cs_CZ.UTF8', 'cs_CZ.UTF-8', 'cs_CZ'); } $this->lang = $lang; $cache = Environment::getCache(); $cacheName = 'getText-' . $this->lang; if (isset($cache[$cacheName])) { $this->dictionary = unserialize($cache[$cacheName]); } else { $dict = new Model\Dictionary('utils/translate'); try { $this->dictionary = $dict->getPairs($this->lang); $cache->save($cacheName, serialize((array) $this->dictionary), array('expire' => time() + 60 * 30, 'refresh' => TRUE, 'tags' => array('dictionary'))); } catch (DibiException $e) { echo $e; } } }
/** * Renders blue screen. * @param \Exception * @return void */ public static function renderBlueScreen(\Exception $exception) { if (class_exists('Nette\\Environment', FALSE)) { $application = Environment::getContext()->hasService('Nette\\Application\\Application', TRUE) ? Environment::getContext()->getService('Nette\\Application\\Application') : NULL; } require __DIR__ . '/templates/bluescreen.phtml'; }
function log_write($data, FileDownload $file, IDownloader $downloader) { $cache = Environment::getCache("FileDownloader/log"); $log = array(); $tid = (string) $file->getTransferId(); if (!isset($cache["registry"])) { $cache["registry"] = array(); } $reg = $cache["registry"]; $reg[$tid] = true; $cache["registry"] = $reg; if (isset($cache[$tid])) { $log = $cache[$tid]; } Debugger::fireLog("Data: " . $data . "; " . $downloader->end); $data = $data . ": " . Helpers::bytes($file->transferredBytes) . " <->; "; if ($downloader instanceof AdvancedDownloader and $downloader->isInitialized()) { $data .= "position: " . Helpers::bytes($downloader->position) . "; "; //$data .= "length: ".Helpers::bytes($downloader->length)."; "; $data .= "http-range: " . Helpers::bytes($downloader->start) . "-" . Helpers::bytes($downloader->end) . "; "; $data .= "progress (con: " . round($file->transferredBytes / $downloader->end * 100) . "% X "; $data .= "file: " . round($downloader->position / $file->sourceFileSize * 100) . "%)"; } $log[] = $data; $cache[$tid] = $log; }
/** * @return Nette\Templates\ITemplate */ protected function createTemplate() { $template = new Nette\Templates\FileTemplate(); $presenter = $this->getPresenter(FALSE); $template->onPrepareFilters[] = callback($this, 'templatePrepareFilters'); // default parameters $template->control = $this; $template->presenter = $presenter; $template->user = Nette\Environment::getUser(); $template->baseUri = Nette\Environment::getVariable('baseUri', NULL); $template->basePath = rtrim($template->baseUri, '/'); // flash message if ($presenter !== NULL && $presenter->hasFlashSession()) { $id = $this->getParamId('flash'); $template->flashes = $presenter->getFlashSession()->{$id}; } if (!isset($template->flashes) || !is_array($template->flashes)) { $template->flashes = array(); } // default helpers $template->registerHelper('escape', 'Nette\\Templates\\TemplateHelpers::escapeHtml'); $template->registerHelper('escapeUrl', 'rawurlencode'); $template->registerHelper('stripTags', 'strip_tags'); $template->registerHelper('nl2br', 'nl2br'); $template->registerHelper('substr', 'iconv_substr'); $template->registerHelper('repeat', 'str_repeat'); $template->registerHelper('replaceRE', 'Nette\\String::replace'); $template->registerHelper('implode', 'implode'); $template->registerHelper('number', 'number_format'); $template->registerHelperLoader('Nette\\Templates\\TemplateHelpers::loader'); return $template; }
public function getConfig() { if (!$this->config) { $this->config = Environment::getConfig(); } return $this->config; }
public function handleUpload() { $files = \Nette\Environment::getHttpRequest()->getFile("user_file"); foreach ($files as $file) { call_user_func($this->handler, $file); } }
/** * @return \Nette\DI\Container */ protected function getContext() { static $context; if (!$context) { $context = \Nette\Environment::getContext(); } return $context; }
/** * @internal * @return string */ protected function getStorageDir() { if ($this instanceof FileEntity) { return \Nette\Environment::getContext()->expand(FileService::STORAGE_DIR); } else { return \Nette\Environment::getContext()->expand(ImageService::STORAGE_DIR); } }
private function validateEntity($entity) { $errors = Environment::getService("validator")->validate($entity); if (count($errors) > 0) { foreach ($errors as $violation) { throw new \Neuron\Model\ValidationException($violation->getMessage(), $violation->getPropertyPath()); } } }
/** * @return Template */ protected function createTemplate($file = null) { $template = new Template($file); $template->baseUrl = \Nette\Environment::getHttpRequest()->url->baseUrl; $template->basePath = rtrim($template->baseUrl, '/'); $template->interface = $this; $template->registerHelperLoader('Nette\\Templating\\Helpers::loader'); return $template; }
/** * Constructor * * @note Maybe get User by DI */ public function __construct() { if (class_exists('\\Nette\\Environment')) { $this->userId = \Nette\Environment::getUser()->id; $this->avaibleTables = \Nette\Environment::getConfig('store'); } else { $this->userId = 0; $this->avaibleTables = []; } }
protected function createTemplate($class = NULL) { $template = parent::createTemplate($class); $template->registerHelperLoader('Helpers::loader'); $this->translator = \Nette\Environment::getContext()->translator; $template->setTranslator($this->translator); $template->registerHelper('convert', callback(\Nette\Environment::getContext()->currencyHelper, 'convert')); $template->currentLang = $this->translator->getLangTo(); return $template; }
public function loginFormSubmitted($form) { try { $user = Environment::getUser(); $user->login($form['username']->getValue(), $form['password']->getValue()); $this->getApplication()->restoreRequest($this->backlink); $this->redirect('Dashboard:'); } catch (AuthenticationException $e) { $form->addError($e->getMessage()); } }
public function getFilters() { $stored = \Nette\Environment::getSession($this->getParent()->getName()); $res = null; // dump($stored->filter); // foreach ($stored->filter as $key => $value) { // dump($key); // if($key != 'like' and $key !='boolean') // $res[] = '['.eregi_replace('__','.',$key).'] LIKE "%'.$value.'%"'; // } return $res; }
public function formatLayoutTemplateFiles($presenter, $layout) { $appDir = Environment::getVariable('appDir'); $path = '/' . str_replace(':', 'Module/', $presenter); $pathP = substr_replace($path, '/templates', strrpos($path, '/'), 0); $list = array("{$appDir}{$pathP}/@{$layout}.phtml", "{$appDir}{$pathP}.@{$layout}.phtml", NEURON_DIR . "{$pathP}/@{$layout}.phtml", NEURON_DIR . "{$pathP}.@{$layout}.phtml"); while (($path = substr($path, 0, strrpos($path, '/'))) !== FALSE) { $list[] = "{$appDir}{$path}/templates/@{$layout}.phtml"; $list[] = NEURON_DIR . "{$path}/templates/@{$layout}.phtml"; } return $list; }
public function getPanel() { if (count($this->queries) == 0) { return NULL; } $platform = get_class(\Nette\Environment::getService('Doctrine\\ORM\\EntityManager')->getConnection()->getDatabasePlatform()); $platform = substr($platform, strrpos($platform, "\\") + 1, strrpos($platform, "Platform") - (strrpos($platform, "\\") + 1)); $queries = $this->queries; $totalTime = round($this->totalTime, 3); $i = 0; ob_start(); require_once __DIR__ . "/doctrine2.panel.phtml"; return ob_get_clean(); }
public function __construct(\Nette\IComponentContainer $parent = null, $name = null) { parent::__construct($parent, $name); $this->setJoinFiles(Environment::isProduction()); $this->setTempUri(Environment::getVariable("baseUri") . "data/webtemp"); $this->setTempPath(WWW_DIR . "/data/webtemp"); $this->setSourcePath(WWW_DIR . "/js"); $presenter = Environment::getApplication()->getPresenter(); $this->filters[] = new VariablesFilter(array("baseUri" => Environment::getVariable("baseUri"), "texylaPreviewPath" => $presenter->link(":Texyla:preview"), "texylaFilesPath" => $presenter->link(":Texyla:listFiles"), "texylaFilesUploadPath" => $presenter->link(":Texyla:upload"))); if (Environment::isProduction()) { $this->filters[] = "JSMin::minify"; } $this->init(); }
/** * Přesměruje zpět na RequestButton, když je z něj požadavek. * Používá ho RequestButtonReceiver a tuto funkcy lze zavolat i třeba v signálu. * * @param AppForm|PresenterComponent|NULL Null znamená vzít presenter z prostředí, u AppForm se kontroluje jestli nebyl stisknut další RequestButton. * @throw AbortException */ public static function redirectBack($form = NULL) { if ($form === NULL) { $presenter = \Nette\Environment::getApplication()->getPresenter(); } else { if ($form instanceof PresenterComponent or $form instanceof AppForm) { $presenter = $form->getPresenter(); } } $backlinkId = $presenter->getParam(RequestButton::BACKLINK_KEY); if ($backlinkId and ($form === NULL or !$form->isSubmitted() instanceof RequestButton) and RequestButtonStorage::is($backlinkId)) { $presenter->redirect(RequestButtonStorage::getDestination($backlinkId), array(RequestButton::RECEIVED_KEY => $backlinkId, 'do' => NULL) + RequestButtonStorage::getDestinationArgs($backlinkId)); } }
public static function createHelperLoader() { $loader = new \Neuron\Helper\TemplateHelperLoader(); $loader->setHelper('texy', 'Neuron\\Texy\\TemplateHelper::process'); $loader->setHelper('safetexy', 'Neuron\\Texy\\TemplateHelper::safeProcess'); $loader->setHelper('thumbnail', array(Environment::getService('ThumbnailHelper'), 'createThumbnail')); $loader->setHelper('gravatar', 'Neuron\\Helper\\Gravatar::getImageTag'); $loader->setHelper('imagehtml', 'Neuron\\Helper\\ImageHtml::getHtml'); $loader->setHelper('webpath', 'Neuron\\Helper\\WebPath::getSrc'); $loader->setHelper('imagepath', function ($image) { return Environment::getService('PhotoService')->getImagePath($image); }); return $loader; }
public function __construct(\Nette\IComponentContainer $parent = null, $name = null) { parent::__construct($parent, $name); $this->setSourcePath(WWW_DIR . "/css"); $this->setTempUri(Environment::getVariable("baseUri") . "data/webtemp"); $this->setTempPath(WWW_DIR . "/data/webtemp"); $this->setJoinFiles(Environment::isProduction()); $this->fileFilters[] = new Webloader\LessFilter(); if (Environment::isProduction()) { $this->filters[] = function ($code) { return cssmin::minify($code, "remove-last-semicolon"); }; } $this->init(); }
/** * Get table config * @return Config */ public function getConfig() { if (empty($this->config)) { $cacheKey = get_class($this) . "-" . $this->table . "-" . $this->rowClass; $cache = Environment::getCache("Ormion"); if (isset($cache[$cacheKey])) { $this->config = $cache[$cacheKey]; } else { $tableInfo = $this->getDb()->getDatabaseInfo()->getTable($this->table); $this->config = Config::fromTableInfo($tableInfo); $cache[$cacheKey] = $this->config; } } return $this->config; }
public function onFlush(Event\OnFlushEventArgs $args) { $em = $args->getEntityManager(); $uow = $em->getUnitOfWork(); $tags = array(); foreach ($uow->getScheduledEntityDeletions() as $entity) { $tags[] = get_class($entity); $tags[] = $entity->getCacheKey(); } foreach ($uow->getScheduledEntityUpdates() as $entity) { $tags[] = get_class($entity); $tags[] = $entity->getCacheKey(); } Environment::getCache()->clean(array(Cache::TAGS => array_unique($tags))); }
public function processArguments($args, IContext $context) { return array_map(function ($arg) use($context) { if (!is_string($arg)) { return $arg; } elseif (String::startsWith($arg, "%")) { return $context->getService(substr($arg, 1)); } elseif (String::startsWith($arg, "\$\$")) { return Environment::getConfig(substr($arg, 2)); } elseif (String::startsWith($arg, "\$")) { return Environment::getVariable(substr($arg, 1)); } else { return $arg; } }, $args); }
/** * Gets upload directory path * @return string */ function getUploadedFilesTemporaryPath() { if (!Queues::$uploadsTempDir) { Queues::$uploadsTempDir = Environment::expand("%tempDir%" . DIRECTORY_SEPARATOR . "uploads-MFU"); } if (!file_exists(Queues::$uploadsTempDir)) { mkdir(Queues::$uploadsTempDir, 0777, true); } if (!is_writable(Queues::$uploadsTempDir)) { Queues::$uploadsTempDir = Environment::expand("%tempDir%"); } if (!is_writable(Queues::$uploadsTempDir)) { throw new InvalidStateException("Directory for temp files is not writable!"); } return Queues::$uploadsTempDir; }
/** * Handles uploaded files * forwards it to model */ public function handleUploads() { if (!isset($_POST["token"])) { return; } /* @var $token string */ $token = $_POST["token"]; /* @var $file \Nette\Http\FileUpload */ foreach (Environment::getHttpRequest()->getFiles() as $file) { self::processFile($token, $file); } // Response to client echo "1"; // End the script exit; }