public function actionDefault($exception) { $application = Environment::getApplication(); $application->catchExceptions = FALSE; if ($this->isAjax()) { $this->payload->error = (string)$exception; $this->sendPayload(); } else { $this->template->robots = 'noindex,noarchive'; if ($exception instanceof /*Nette\Application\*/BadRequestException) { Environment::getHttpResponse()->setCode($exception->getCode()); switch($exception->getCode()) { case 403: $this->template->title = _('403 Permission denied'); break; default: Environment::getHttpResponse()->setCode(404); $this->template->title = _('404 Not Found'); break; } } else { Environment::getHttpResponse()->setCode(500); $this->template->title = _("Don't recognize error"); Debug::processException($exception); } } }
private function gatherActions() { $service = Environment::getService('Nette\\Loaders\\RobotLoader'); $class_list = $service->list; $actions = array(); foreach ($class_list as $class => $file) { //zachtime annotation exception lebo nette si generuje nejake annotation claasy do robotloodera try { $r = new ReflectionClass($class); if ($r->isSubclassOf('Admin_SecurePresenter') && $r->getName() != 'BaseModulePresenter') { $methods = $r->getMethods(ReflectionMethod::IS_PUBLIC); foreach ($methods as $method) { if (String::lower($method->class) == $class) { if (strpos($method->getName(), 'action') !== false || strpos($method->getName(), 'handle') !== false) { $actions[$class][] = $method->getName(); } } } } } catch (ReflectionException $e) { } } $actions = array_merge($actions, Environment::getApplication()->getModulesPermissions()); $model = new UsersModuleModel(); $model->saveActions($actions); return $actions; }
public function __construct() { parent::__construct(); $this->lang = Environment::getApplication()->getPresenter()->lang; $this->addText('email', 'email')->addRule(Form::FILLED, 'Please, fill in the email')->addRule(Form::EMAIL, 'E-mail is not valid'); $this->addSubmit('submit', 'subscribe the newsletter'); $this->onSuccess[] = callback($this, 'submitted'); $this->setTranslator(new TranslationsModel($this->lang)); }
public function __construct(IComponentContainer $parent = null, $name = null) { parent::__construct($parent, $name); $script = new LiveClientScript($this); $this->setTranslator(new Translator(Environment::getApplication()->getPresenter()->lang)); $this->getRenderer()->setClientScript($script); $renderer = $this->getRenderer(); $renderer->wrappers['label']['suffix'] = ':'; }
public function __construct(IComponentContainer $parent = null, $name = null) { parent::__construct($parent, $name); $this->addProtection(); $script = new LiveClientScript($this); $this->setTranslator(new Translator(Environment::getApplication()->getPresenter()->lang)); $this->getRenderer()->setClientScript($script); $this->getElementPrototype()->class = 'ajax'; }
/** * Dispatch an HTTP request to a routing debugger. Please don't call directly. */ public static function run() { if (!self::$enabled || Environment::getMode('production')) { return; } self::$enabled = FALSE; $debugger = new self(Environment::getApplication()->getRouter(), Environment::getHttpRequest()); $debugger->paint(); }
public function createComponentMenu($name) { $menu = new AdminNavigationBuilder($this, $name); $menu->setTranslator($this->translator); $menu->add('Dashboard', ':Admin:Dashboard:'); $menu->add('Pages', ':Admin:Pages:'); $menu->add('Categories', ':Admin:Categories:'); $menu->add('Menus', ':Admin:Menus:'); $menu->add('Themes', ':Admin:Themes:'); $module_items = Environment::getApplication()->getAdminNodes(); $menu = $this->compileMenuItems($menu, $module_items); $menu->add('Modules', ':Admin:Modules:'); $menu->add('Settings', ':Admin:Options:'); $menu->template->presenter = $this; return $menu; }
public function startup() { //$this->oldLayoutMode = false; //$this->oldModuleMode = false; parent::startup(); $application = Environment::getApplication(); if (!isset($this->lang)) { $this->lang = $this->getHttpRequest()->detectLanguage(array('en', 'sk')); $this->canonicalize(); } $this->translator = new Translator($this->lang); $this->template->setTranslator($this->translator); $modul = explode(':', $this->getName()); $this->module = $modul[0]; $this->template->module = $this->module; }
public function __construct(IEditableTranslator $translator, $layout = NULL, $height = NULL) { $this->translator = $translator; if ($height !== NULL) { if (!is_numeric($height)) { throw new InvalidArgumentException('Panel height has to be a numeric value.'); } $this->height = $height; } if ($layout !== NULL) { $this->layout = $layout; if ($height === NULL) { $this->height = 500; } } Environment::getApplication()->onRequest[] = callback($this, 'processRequest'); }
/** * znova spracovava retazec s latte syntaxou s vyuzitim StringTemplate * * @param string $s * @return string */ public static function latte($s) { // kedze HTML Purifier aj CKEditor escape-uju entity, tak by mi nefungovali nette linky -> robim replace $search = array('->', '=>'); $replace = array('->', '=>'); $s = str_replace($search, $replace, $s); $tpl = new StringTemplate(); $tpl->presenter = Environment::getApplication()->getPresenter(); // nutné např. pro rozchození linků $tpl->registerFilter(new LatteFilter()); $tpl->content = $s; // obsah šablony (řetězec) $tpl->control = $tpl->presenter; // vrátíme vygenerovanou šablonu return $tpl->__toString(); // nebo ji vypíšeme na výstup // $tpl->render(); }
/** * posle [chybovu] hlasku userovi nezavisle ci je ajax alebo nie * * @param string $msg hlaska * @param string $type pridava sa ako class k $flashes */ public static function sendMsg(&$_this, $msg, $type = self::FLASH_MESSAGE_ERROR, $destination = 'this', $plink = false, $backlink = null) { $presenter = $_this->getPresenter(); if ($presenter->isAjax()) { $presenter->payload->actions = array($type => $_this->translate($msg)); $presenter->sendPayload(); } else { $presenter->flashMessage($msg, $type); // ak mame ulozeny kluc, kam sa mame vratit, ideme tam if ($backlink) { Environment::getApplication()->restoreRequest($backlink); } elseif ($plink) { $presenter->redirect($destination); } else { $_this->redirect($destination); } } }
/** * Add navigation node as a child * @staticvar int $counter * @param string $label * @param string $url * @param string $netteLink added - aby sa dalo testovat ifCurrent na cely presenter * @return NavigationNode */ public function add($label, $url, $netteLink = null) { $navigationNode = new self(); $navigationNode->label = $label; $navigationNode->url = $url; static $counter; $this->addComponent($navigationNode, ++$counter); /*added*/ $uri = Environment::getHttpRequest()->getOriginalUri()->getPath(); if ($netteLink) { $presenter = Environment::getApplication()->getPresenter(); try { $presenter->link($netteLink); } catch (InvalidLinkException $e) { } $navigationNode->isCurrent = $presenter->getLastCreatedRequestFlag("current"); } else { $navigationNode->isCurrent = $url == $uri; } /*added end*/ return $navigationNode; }
/** * @param Form $form */ public function onLoginSubmitted(Form $form) { try { $values = $form->getValues(); $username = $values['user']; if ($username == '__guest') { $this->user->logout(TRUE); } else { $password = $this->credentials[$username]; Environment::getUser()->login($username, $password); } $this->redirect('this'); } catch (AuthenticationException $e) { Environment::getApplication()->presenter->flashMessage($e->getMessage(), 'error'); $this->redirect('this'); } }
/** * Iterates through all presenters and returns their actions with backlinks and arguments * @return array */ private function generate() { $links = array(); $depends = array(); $iterator = new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(APP_DIR)), '/Presenter\\.(php|PHP)$/m', RecursiveRegexIterator::GET_MATCH); foreach ($iterator as $path => $match) { $fileinfo = pathinfo($path); $reflection = new ReflectionClass($this->getClassNameFromPath($path)); if ($reflection->isInstantiable()) { $depends[] = $path; $modules = $this->getModulesFromName($reflection->name); $link = ''; if ($modules !== FALSE) { $link .= implode(':', $modules); } $link .= ':'; preg_match('/(?:[A-z0-9]+?_)*([A-z0-9]+)Presenter/m', $reflection->getName(), $match); $presenter = $match[1]; $link .= $presenter; $persistent = array(); foreach ($reflection->getProperties() as $property) { foreach (AnnotationsParser::getAll($property) as $annotation => $value) { if ($annotation == 'persistent') { $persistent[] = $property; } } } $actions = array(); foreach ($reflection->getMethods() as $action) { if (preg_match('/^(action|render)(.*)$/m', $action->getName(), $name) && !in_array($name[2], $actions)) { $action_name = lcfirst($name[2]); $pattern = '/Method \\[.*? ' . $action . ' \\].*? (?:Parameters .*? \\{.*?Parameter #\\d+ \\[(.*?)\\].*?\\})? }/ms'; $set_required = FALSE; $set_optional = FALSE; foreach ($action->getParameters() as $arg) { if (!$arg->isOptional()) { $actions[$action_name]['arguments']['required'][$arg->getName()] = NULL; $set_required = TRUE; } else { $actions[$action_name]['arguments']['optional'][$arg->getName()] = $arg->getDefaultValue(); $set_optional = TRUE; } } if (!$set_required) { $actions[$action_name]['arguments']['required'] = array(); } if (!$set_optional) { $actions[$action_name]['arguments']['optional'] = array(); } $actions[$action_name]['arguments']['persistent'] = $persistent; } } if (count($actions) == 0) { $actions['Default']['arguments']['required'] = array(); $actions['Default']['arguments']['optional'] = array(); $actions['Default']['arguments']['persistent'] = array(); } foreach ($actions as $action => $info) { $label = ':' . $link . ':' . $action; if (Environment::getApplication()->getPresenter() instanceof Presenter) { $links[$label]['link'] = Environment::getApplication()->getPresenter()->link($label); } else { $links[$label]['link'] = 'false'; } $links[$label]['action'] = $action; $links[$label]['presenter'] = $presenter; $links[$label]['modules'] = $modules; $links[$label]['arguments'] = $info['arguments']; } } } return array('tree' => $this->categorize($links), 'depends' => $depends); }
/** * chyby vo formulari zobrazi ako flash a chyby zmaze * * @param AppForm $form */ public static function errorsAsFlashMessages(MyAppForm $form) { $errors = $form->getErrors(); foreach ($errors as $error) { Environment::getApplication()->getPresenter()->flashMessage($error, 'error'); } $form->cleanErrors(); }
<h1>Nette\Environment services test</h1> <pre> <?php require_once '../../Nette/loader.php'; /*use Nette\Debug;*/ /*use Nette\Environment;*/ echo "Environment::getHttpResponse\n"; $obj = Environment::getHttpResponse(); Debug::dump($obj->class); echo "Environment::getApplication\n"; $obj = Environment::getApplication(); Debug::dump($obj->class); echo "Environment::getCache(...)\n"; Environment::setVariable('tempDir', __FILE__); $obj = Environment::getCache('my'); Debug::dump($obj->class); /* in PHP 5.3 echo "Environment::getXyz(...)\n"; Environment::setServiceAlias('Nette\Web\IUser', 'xyz'); $obj = Environment::getXyz(); Debug::dump($obj->class); */
public function getControlHtml($opts = null) { $preview = $this->previewLink("480x330"); //$link = $this->downloadLink(); $link = Environment::getHttpRequest()->getUrl()->getBasePath() . "data/files/{$this->id}.orig.{$this->suffix}"; // custom templating $template = Environment::getContext()->params["themeDir"] . '/control-video.latte'; if (file_exists($template)) { $tpl = Environment::getApplication()->presenter->createTemplate(); $tpl->setFile($template); $tpl->file = $this; $tpl->preview = $preview; $tpl->link = $link; $tpl->basePath = Environment::getHttpRequest()->getUrl()->getBasePath(); return (string) $tpl; } return "\n<video src='{$link}' width='480' height='330' poster='{$preview}' preload='none'>\n" . "Pokud vidíte tento text, váš prohlížeč zřejmě neumí přehrávat video.\n" . "<br>Video můžete alespoň <a href='{$link}'>stáhnout</a> a zkusit ho přehrát mimo prohlížeč.\n" . "</video>\n"; //TODO proč nefunguje downloadLink?? //TODO dát to do šablony //TODO do disable textu přidat preview }
/** * @return Application */ protected function getApplication() { return Environment::getApplication(); }
protected function storeRequest() { $session = $this->getSession('backlink'); $session['backlink'] = Environment::getApplication()->storeRequest(); }
public function link($absolute = false) { $redirect = $this->getRedirectLink(); if ($redirect) { return $redirect; } $presenter = Environment::getApplication()->getPresenter(); $target = ($absolute ? '//' : '') . ':Front:Pages:'; return $presenter->link($target, array($this->id, 'lang' => $this->lang)); }
public function renderRss($channels = null) { if ($channels !== null) { $this->rssChannels = array(); foreach ($channels as $title => $link) { $this->addRssChannel($title, $link); } } foreach ($this->rssChannels as $channel) { echo Html::el('link')->rel('alternate')->type('application/rss+xml')->title($channel['title'])->href(Environment::getApplication()->getPresenter()->link($channel['link'])) . "\n"; } }
<?php /** * Nette TreeView example bootstrap file. * * @copyright Copyright (c) 2010 Roman Novák * @package nette-treeview */ // Step 1: Load Nette Framework // this allows load Nette Framework classes automatically so that // you don't have to litter your code with 'require' statements require LIBS_DIR . '/Nette/loader.php'; // Step 2: Configure environment // 2a) enable Nette\Debug for better exception and error visualisation Debug::enable(false); Debug::enableProfiler(); // 2b) load configuration from config.ini file Environment::loadConfig(); Environment::getSession()->start(); dibi::connect(Environment::getConfig('database')); // Step 3: Configure application // 3a) get and setup a front controller $application = Environment::getApplication(); //$application->errorPresenter = 'Error'; $application->catchExceptions = false; // Step 4: Setup application router $router = $application->getRouter(); $router[] = new Route('index.php', array('presenter' => 'Homepage', 'action' => 'default'), Route::ONE_WAY); $router[] = new Route('<presenter>/<action>/<id>', array('presenter' => 'Homepage', 'action' => 'default', 'id' => NULL)); // Step 5: Run the application! $application->run();
/** * @return Application */ public function getApplication() { return Environment::getApplication(); }
public function handleChangeStatus($module_name, $new_status) { ModuleManager::changeStatus($module_name, $new_status); $this['page']->refresh('modules'); if ($new_status == 'enabled') { Environment::getApplication()->installModules(); $this->invalidateControl('menu'); } else { $this->redirect('this'); } }