public function __construct() { parent::__construct(); // output $this->setOutputMode(self::HTML4_TRANSITIONAL); $this->htmlOutputModule->removeOptional = FALSE; $this->htmlOutputModule->lineWrap = false; $this->headingModule->balancing = TexyHeadingModule::FIXED; $this->allowed['phrase/sup'] = true; $this->allowed['phrase/sub'] = true; $this->allowed['phrase/del'] = true; // images $this->imageModule->fileRoot = WWW_DIR . "/data/files"; $this->imageModule->root = Environment::getVariable("baseUri") . "data/files"; // align classes // $this->alignClasses['left'] = 'left'; // $this->alignClasses['right'] = 'right'; // $this->alignClasses['center'] = 'center'; // justify, top, bottom, middle $this->imageModule->leftClass = "left"; $this->imageModule->rightClass = "right"; $this->figureModule->class = "box"; $this->figureModule->leftClass = "box left"; $this->figureModule->rightClass = "box right"; $this->figureModule->widthDelta = 0; // handlers $this->addHandler('afterTable', array($this, 'afterTable')); $this->addHandler('image', array($this, 'youtubeHandler')); $this->addHandler('image', array($this, 'flashHandler')); $this->addHandler("phrase", array($this, "netteLink")); }
/** * @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; }
/** * Startup */ public function startup() { parent::startup(); $texy = Environment::getService("Texy"); $this->baseFolderPath = $texy->imageModule->fileRoot; $this->baseFolderUri = $texy->imageModule->root; $this->tempDir = WWW_DIR . "/webtemp"; $this->tempUri = Environment::getVariable("baseUri") . "/webtemp"; }
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 __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(); }
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(); }
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); }
/** * Make relative url absolute * @param string image url * @param string single or double quote * @param string absolute css file path * @param string source path * @return string */ public static function absolutizeUrl($url, $quote, $cssFile, $sourcePath) { // is already absolute if (preg_match("/^([a-z]+:\\/)?\\//", $url)) { return $url; } $docroot = realpath(WWW_DIR); $basePath = rtrim(Environment::getVariable("baseUri"), '/'); // inside document root if (String::startsWith($cssFile, $docroot)) { $path = $basePath . substr(dirname($cssFile), strlen($docroot)) . DIRECTORY_SEPARATOR . $url; // outside document root } else { $path = $basePath . substr($sourcePath, strlen($docroot)) . DIRECTORY_SEPARATOR . $url; } //$path = self::cannonicalizePath($path); $path = strtr($path, "\\", "/"); return $quote === '"' ? addslashes($path) : $path; }
public function setUrl($url) { $uriScript = new UriScript($url); $uriScript->setScriptPath(Environment::getHttpRequest()->getUri()->getScriptPath()); $httpRequest = new HttpRequest($uriScript); $presenterRequest = Environment::getApplication()->getRouter()->match($httpRequest); if ($presenterRequest === null || !String::startsWith($url, Environment::getVariable("baseUri"))) { $this->url = $url ?: null; $this->destination = null; $this->params = array(); } else { $presenter = $presenterRequest->getPresenterName(); $params = $presenterRequest->getParams(); $action = isset($params["action"]) ? $params["action"] : "default"; $module = isset($params["module"]) ? $params["module"] . ":" : ""; unset($params["action"]); $this->destination = "{$module}{$presenter}:{$action}"; $this->params = $params; $this->url = null; } }
public function match(IHttpRequest $httpRequest) { $path = substr($httpRequest->getUri()->getAbsoluteUri(), strlen(Environment::getVariable("baseUri"))); foreach ($this->getData() as $id => $url) { if ($this->prefix . $url == $path || $this->prefix . $url . "/" == $path) { $params = $httpRequest->getQuery(); $params["id"] = $id; $params["action"] = $this->action; return new PresenterRequest( $this->presenter, $httpRequest->getMethod(), $params, $httpRequest->getPost(), $httpRequest->getFiles(), array('secured' => $httpRequest->isSecured()) ); } } return null; }
use Nette\Web\Html; // Load libraries require LIBS_DIR . '/Nette/loader.php'; require APP_DIR . '/routers/StaticRouter.php'; require APP_DIR . '/classes/TemplateLocator.php'; require APP_DIR . '/classes/PresenterLoader.php'; // Enable and setup Nette\Debug Debug::enable(); Debug::$strictMode = !Debug::$productionMode; // Configure environment date_default_timezone_set('Europe/Prague'); Html::$xhtml = FALSE; Env::getContext()->addService('TemplateLocator', 'StaticWeb\TemplateLocator'); Env::getContext()->addService('Nette\\Application\\IPresenterLoader', function () { return new PresenterLoader(Env::getVariable('appDir')); }); // Configure application $application = Env::getApplication(); $application->errorPresenter = 'Error'; $application->catchExceptions = Debug::$productionMode; $application->setRouter(new StaticRouter('StaticPage', 'homepage', 'default')); // Run the application! $application->run();
/** * Formats view template file names. * @param string * @param string * @return array */ public function formatTemplateFiles($presenter, $view) { $appDir = Environment::getVariable('appDir'); $path = '/' . str_replace(':', 'Module/', $presenter); $pathP = substr_replace($path, '/templates', strrpos($path, '/'), 0); $path = substr_replace($path, '/templates', strrpos($path, '/')); return array("{$appDir}{$pathP}/{$view}.phtml", "{$appDir}{$pathP}.{$view}.phtml", "{$appDir}{$path}/@global.{$view}.phtml"); }
/** * @return Nette\Loaders\RobotLoader */ public static function createRobotLoader($options) { $loader = new Nette\Loaders\RobotLoader(); $loader->autoRebuild = isset($options['autoRebuild']) ? $options['autoRebuild'] : !Environment::isProduction(); $loader->setCacheStorage(Environment::getService('Nette\\Caching\\ICacheStorage')); if (isset($options['directory'])) { $loader->addDirectory($options['directory']); } else { foreach (array('appDir', 'libsDir') as $var) { if ($dir = Environment::getVariable($var, NULL)) { $loader->addDirectory($dir); } } } $loader->register(); return $loader; }
/** * @return Nette\Caching\ICacheStorage */ public static function getCacheStorage() { if (self::$cacheStorage === NULL) { $dir = Environment::getVariable('tempDir') . '/cache'; umask(00); @mkdir($dir, 0755); // @ - directory may exists self::$cacheStorage = new TemplateCacheStorage($dir); } return self::$cacheStorage; }
/** * Creates and returns configured template. * * @author Jan Tvrdík, David Grudl * @param string template file path * @return Nette\Templates\FileTemplate */ protected function createTemplate($path = NULL) { $template = new Nette\Templates\FileTemplate($path); // default parameters $template->baseUri = rtrim(Env::getVariable('baseUri', NULL), '/'); $template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUri); $template->presenter = $this; $template->page = $this->page; $template->lang = $this->lang; // default filters $template->onPrepareFilters[] = function($template) { require_once APP_DIR . '/classes/ConfiguredTexy.php'; require_once APP_DIR . '/classes/TexyElementsFilter.php'; require_once APP_DIR . '/classes/LatteMacros.php'; $texyElementsFilter = new TexyElementsFilter(); $texyElementsFilter->texy = new ConfiguredTexy(); $texyElementsFilter->autoChangeSyntax = TRUE; $latteHandler = new LatteMacros(); $latteHandler->macros['@href'] = ' href="<?php echo %:escape%(%:macroPageLink%) ?>"'; $latteFilter = new Nette\Templates\LatteFilter(); $latteFilter->setHandler($latteHandler); $template->registerFilter($texyElementsFilter); $template->registerFilter($latteFilter); }; // 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; }
/** * @return Nette\Caching\ICacheStorage */ public static function getCacheStorage() { if (self::$cacheStorage === NULL) { self::$cacheStorage = new TemplateCacheStorage(Environment::getVariable('tempDir')); } return self::$cacheStorage; }
/** * @return Nette\Loaders\RobotLoader */ public static function createRobotLoader($options) { $loader = new Nette\Loaders\RobotLoader(); $loader->autoRebuild = !Environment::isProduction(); //$loader->setCache(Environment::getCache('Nette.RobotLoader')); $dirs = isset($options['directory']) ? $options['directory'] : array(Environment::getVariable('appDir'), Environment::getVariable('libsDir')); $loader->addDirectory($dirs); $loader->register(); return $loader; }
// this allows load Nette Framework classes automatically so that // you don't have to litter your code with 'require' statements require_once LIBS_DIR . '/Nette/loader.php'; // Step 2: Configure environment // 2a) enable Nette\Debug for better exception and error visualisation Debug::$strictMode = true; Debug::enable(); // 2b) load configuration from config.ini file Environment::loadConfig(); // 2c) check if directory /app/temp is writable if (@file_put_contents(Environment::expand('%tempDir%/_check'), '') === FALSE) { throw new Exception("Make directory '" . Environment::getVariable('tempDir') . "' writable!"); } // 2d) setup sessions //$session = Environment::getSession(); //$session->start(); // Step 3: Setup application router $application = Environment::getApplication(); $router = $application->getRouter(); $router[] = new SimpleRouter(array("presenter" => "AutoUse")); // Step 5: Run the application! $application->run();
/** * @return IPresenterLoader */ public static function createPresenterLoader() { return new PresenterLoader(Environment::getVariable('appDir')); }
public function getSrc() { $src = rtrim(Environment::getVariable('baseUri'), '/') . substr($this->path, strlen(WWW_DIR)); $src = strtr($src, "\\", "/"); return $src; }
public static function getSrc($path) { $src = rtrim(\Nette\Environment::getVariable('baseUri'), '/') . substr($path, strlen(WWW_DIR)); $src = strtr($src, "\\", "/"); return $src; }
/** * Formats view template file names. * @param string * @param string * @return array */ public function formatTemplateFiles($presenter, $view) { $appDir = Environment::getVariable('appDir'); $path = '/' . str_replace(':', 'Module/', $presenter); $pathP = substr_replace($path, '/templates', strrpos($path, '/'), 0); $path = substr_replace($path, '/templates', strrpos($path, '/')); return array( "$appDir$pathP/$view.latte", "$appDir$pathP.$view.latte", "$appDir$pathP/$view.phtml", "$appDir$pathP.$view.phtml", "$appDir$path/@global.$view.phtml", // deprecated ); }
/** * @return Nette\Caching\ICacheStorage */ public function getCacheStorage() { if ($this->cacheStorage === NULL) { $dir = Environment::getVariable('tempDir') . '/cache'; umask(00); @mkdir($dir, 0777); // @ - directory may exists $this->cacheStorage = new TemplateCacheStorage($dir); } return $this->cacheStorage; }
/** * Returns expanded variable. * @param string * @return string * @throws \InvalidStateException */ public static function expand($var) { static $livelock; if (is_string($var) && strpos($var, '%') !== FALSE) { return @preg_replace_callback( '#%([a-z0-9_-]*)%#i', function ($m) use (& $livelock) { list(, $var) = $m; if ($var === '') return '%'; if (isset($livelock[$var])) { throw new \InvalidStateException("Circular reference detected for variables: " . implode(', ', array_keys($livelock)) . "."); } try { $livelock[$var] = TRUE; $val = Environment::getVariable($var); unset($livelock[$var]); } catch (\Exception $e) { $livelock = array(); throw $e; } if (!is_scalar($val)) { throw new \InvalidStateException("Environment variable '$var' is not scalar."); } return $val; }, $var ); // intentionally @ due PHP bug #39257 } return $var; }
Debug::$strictMode = !Debug::$productionMode; // Configure environment date_default_timezone_set('Europe/Prague'); Html::$xhtml = FALSE; // Configure application $application = Env::getApplication(); $application->errorPresenter = 'Error'; $application->catchExceptions = Debug::$productionMode; // Configure application context $context = $application->getContext(); $context->addService('StaticWeb\\TemplateLocator', 'StaticWeb\\TemplateLocator'); $context->addService('StaticWeb\\PageManager', function() use ($context) { $manager = new PageManager(); $manager->setContext($context); return $manager; }); $context->addService('Nette\\Application\\IPresenterFactory', function() use ($context) { return new PresenterFactory(Env::getVariable('appDir'), $context); }); $context->addService('Nette\\Application\\IRouter', function() use ($context) { $router = new StaticRouter('StaticPage', 'homepage', 'default', 'en'); $router->setContext($context); return $router; }); // Run the application! $application->run();