private function fixComment($text) { $escaped = \Latte\Runtime\Filters::escapeHtml($text, ENT_COMPAT); $esmiled = $this->smileReplace($escaped); $reg = '#(http://|ftp://|(www\\.))([\\w\\-]*\\.[\\w\\-\\.]*([/?][^\\s]*)?)#'; return preg_replace_callback($reg, 'self::createLink', $esmiled); }
/** * New node is found. Returns FALSE to reject. * * @param MacroNode $node * @return bool * @throws Latte\CompileException */ public function nodeOpened(MacroNode $node) { if ($node->prefix) { return false; } if ($node->modifiers) { throw new Latte\CompileException("Modifiers are not allowed in {{$node->name}}."); } $file = $node->tokenizer->fetchWord(); if ($file === false) { throw new Latte\CompileException("Missing file name in {{$node->name}}."); } elseif ($node->tokenizer->fetchWord()) { throw new Latte\CompileException("Multiple arguments are not supported in {{$node->name}}."); } $node->isEmpty = true; $node->modifiers = '|safeurl|escape'; // auto-escape $writer = Latte\PhpWriter::using($node, $this->compiler); if ($this->debugMode) { $node->openingCode = $writer->write('<?php echo %modify(%1.word . \'?\' . Nepada\\BustCache\\Helpers::timestamp(%0.var . %1.word)) ?>', $this->wwwDir, $file); } elseif (preg_match('#^(["\']?)[^$\'"]*\\1$#', $file)) { // Static path $file = trim($file, '"\''); $url = $file . '?' . Helpers::hash($this->wwwDir . $file); $url = Latte\Runtime\Filters::safeUrl($url); $node->openingCode = $writer->write('<?php echo %escape(%var) ?>', $url); } else { $node->openingCode = $writer->write('<?php echo %modify(%1.word . \'?\' . Nepada\\BustCache\\Helpers::hash(%0.var . %1.word)) ?>', $this->wwwDir, $file); } }
public function getPanel() { $buff = '<h1>AssetsLoader</h1>' . '<div class="nette-inner">' . '<table>' . '<thead><tr><th>Source</th><th>Generated file</th><th>Memory usage</th></tr></thead>'; $i = 0; foreach ($this->files as $source => $generated) { $buff .= '<tr><th' . ($i % 2 ? 'class="nette-alt"' : '') . '>' . $source . '</th><td>' . $this->link($generated['id'], $generated['type'], $generated['lastModified']) . '</td><td>' . Runtime\Filters::bytes($generated['memory']) . '</td></tr>'; } return $buff . '</table></div>'; }
/** * @param string $defaultGenre * @return Form */ public function create(string $defaultGenre = null) { $form = $this->factory->create(); $maxSize = SizeParser::parse_size(ini_get("upload_max_filesize")); $form->addUpload('song', 'Nová skladba: ', true)->addRule(Form::MAX_FILE_SIZE, 'Nemůžete nahrát vetší soubor než ' . Filters::bytes($maxSize) . '(nastaveno v php.ini)', $maxSize)->getControlPrototype()->addAttributes(['class' => 'file', 'tabindex' => 1, 'accesskey' => 'i']); $genres = $this->genresManager->getAllGenreIdsAndNames(); $form->addSelect('genre', 'Žánr: ', $genres)->setPrompt('-')->setDefaultValue($defaultGenre)->getControlPrototype()->addAttributes(['tabindex' => 2, 'accesskey' => 'g']); $form->addSubmit('send', 'Nahrát skladbu')->getControlPrototype()->addAttributes(['tabindex' => 3, 'accesskey' => 's']); $form->onValidate[] = $this->validateSongsMetadata; return $form; }
/** * @param mixed $value * @return mixed */ protected function formatValue($value) { if ($value === NULL || is_bool($value)) { return $this->applyReplacement($value); } elseif (is_scalar($value)) { $value = \Latte\Runtime\Filters::escapeHtml($value); $replaced = $this->applyReplacement($value); if ($value !== $replaced && is_scalar($replaced)) { return $replaced; } } return $value instanceof \DateTime ? $value->format($this->dateFormat) : date($this->dateFormat, is_numeric($value) ? $value : strtotime($value)); //@todo notice for "01.01.1970" }
public function actionDeleteFinal($id) { $f = $this->folder->find($id); if (!$f) { $this->error('Složka s tímto ID neexistuje.'); } $fm = $this->sm->getFolder($f->name); $fc = $fm["sc"]; $maxSpace = 2 * 1024 * 1024; if ($fc->space_used > $maxSpace) { $this->flashMessage('Chyba, složka není prázdná. Obsahuje ' . \Latte\Runtime\Filters::bytes($fc->space_used) . ' dat.', 'danger'); $this->redirect('Slozky:delete', $id); } $sharescount = $f->related('share.folder_id')->count(); if ($sharescount != 0) { $this->flashMessage('Chyba, složka má stále zaplá některá sdílení. Deaktivujte je před smazáním, prosím.', 'danger'); $this->redirect('Slozky:delete', $id); } $state = $this->sm->deleteUserFolder($id); if ($state == FALSE) { $this->flashMessage('Omlouváme se, složku se nepodařilo smazat kvůli chybě v systému. Prosím kontaktujte podporu.', 'danger'); $this->redirect('Slozky:'); } $this->flashMessage('Složka byla úspěšně smazána.', 'success'); $this->redirect('Slozky:'); }
/** * Returns panel tab. * @return string */ public function getTab() { $this->compute(); return '<span title="WebLoader">' . '<svg viewBox="0 -50 600 600" style="vertical-align: bottom; width:1.23em; height:1.55em"><polygon fill="#1565C0" points="75.089,23.98 58.245,108.778 403.138,108.778 392.289,163.309 47.111,163.309 30.549,248.104 375.445,248.104 356.027,344.887 217.273,390.856 96.789,344.887 105.069,302.921 20.272,302.921 0,404.559 199.286,480.791 428.831,404.559 504.771,23.98"/></svg>' . Filters::bytes($this->size['combined']) . '</span>'; }
/** * Returns links for types. * * @param string $annotation * @param ElementReflectionInterface $reflectionElement * @return string */ public function typeLinks($annotation, ElementReflectionInterface $reflectionElement) { $links = []; // typehints can not contains spaces // valid typehint is: // [TYPE[|TYPE[|...]][SPACE[METHOD|PARAM][DESCRIPTION]] $parts = explode(' ', $annotation); foreach (explode('|', $parts[0]) as $type) { $type = $this->getTypeName($type, false); $links[] = $this->resolveLink($type, $reflectionElement) ?: LatteFilters::escapeHtml(ltrim($type, '\\')); } return implode('|', $links); }
/** * @param mixed $value * @return mixed */ protected function formatValue($value) { $value = is_string($value) ? \Latte\Runtime\Filters::escapeHtml($value) : $value; return $this->applyReplacement($value); }
/** * Returns panel tab. * @return string */ public function getTab() { $this->compute(); return '<span title="WebLoader">' . '<img src="data:image/png;base64,' . base64_encode(file_get_contents(__DIR__ . '/icon.png')) . '" /> ' . Filters::bytes($this->size['combined']) . '</span>'; }
/** * @param string $url * @param Html|string $text * @param bool $escape * @param array $classes * @return string */ public function build($url, $text, $escape = TRUE, array $classes = []) { return Html::el('a')->href($url)->setHtml($escape ? Filters::escapeHtml($text) : $text)->addAttributes(['class' => $classes])->render(); }
/** * @param mixed $column * @param array $conditions * @param int $limit * @return array * @throws Exception */ public function suggest($column, array $conditions, $limit) { $qb = clone $this->qb; $qb->setMaxResults($limit); if (is_string($column)) { $mapping = isset($this->filterMapping[$column]) ? $this->filterMapping[$column] : current($qb->getRootAliases()) . '.' . $column; $qb->select($mapping)->distinct()->orderBy($mapping); } foreach ($conditions as $condition) { $this->makeWhere($condition, $qb); } $items = []; $data = $qb->getQuery()->getScalarResult(); foreach ($data as $row) { if (is_string($column)) { $value = (string) current($row); } elseif (is_callable($column)) { $value = (string) $column($row); } else { $type = gettype($column); throw new Exception("Column of suggestion must be string or callback, {$type} given."); } $items[$value] = \Latte\Runtime\Filters::escapeHtml($value); } is_callable($column) && sort($items); return array_values($items); }
/** @internal */ protected function checkExtraArgs(MacroNode $node) { if ($node->tokenizer->isNext()) { $args = Latte\Runtime\Filters::truncate($node->tokenizer->joinAll(), 20); trigger_error("Unexpected arguments '{$args}' in " . $node->getNotation()); } }
/** * @param mixed $column * @param array $conditions * @param int $limit * @return array * @throws Exception */ public function suggest($column, array $conditions, $limit) { $fluent = clone $this->fluent; if (is_string($column)) { $fluent->removeClause('SELECT')->select("DISTINCT %n", $column)->orderBy("%n", $column, 'ASC'); } foreach ($conditions as $condition) { $this->makeWhere($condition, $fluent); } $items = []; $data = $fluent->fetchAll(0, $limit); foreach ($data as $row) { if (is_string($column)) { $value = (string) $row[$column]; } elseif (is_callable($column)) { $value = (string) $column($row); } else { $type = gettype($column); throw new Exception("Column of suggestion must be string or callback, {$type} given."); } $items[$value] = \Latte\Runtime\Filters::escapeHtml($value); } is_callable($column) && sort($items); return array_values($items); }
/** * @param mixed $column * @param array $conditions * @param int $limit * @return array * @throws Exception */ public function suggest($column, array $conditions, $limit) { $selection = clone $this->selection; is_string($column) && $selection->select("DISTINCT {$column}")->order($column); $selection->limit($limit); foreach ($conditions as $condition) { $this->makeWhere($condition, $selection); } $items = []; foreach ($selection as $row) { if (is_string($column)) { $value = (string) $row[$column]; } elseif (is_callable($column)) { $value = (string) $column($row); } else { $type = gettype($column); throw new Exception("Column of suggestion must be string or callback, {$type} given."); } $items[$value] = \Latte\Runtime\Filters::escapeHtml($value); } is_callable($column) && sort($items); return array_values($items); }
/** * @param mixed $column * @param array $conditions * @param int $limit * @return array * @throws Exception */ public function suggest($column, array $conditions, $limit) { $data = $this->data; foreach ($conditions as $condition) { $data = $this->makeWhere($condition, $data); } array_slice($data, 1, $limit); $items = []; foreach ($data as $row) { if (is_string($column)) { $value = (string) $row[$column]; } elseif (is_callable($column)) { $value = (string) $column($row); } else { $type = gettype($column); throw new Exception("Column of suggestion must be string or callback, {$type} given."); } $items[$value] = \Latte\Runtime\Filters::escapeHtml($value); } sort($items); return array_values($items); }
/** * Renders block. * @param string * @param array * @param string|\Closure content-type name or modifier closure * @return void * @internal */ protected function renderBlock($name, array $params, $mod = NULL) { if (empty($this->blockQueue[$name])) { $hint = isset($this->blockQueue) && ($t = Latte\Helpers::getSuggestion(array_keys($this->blockQueue), $name)) ? ", did you mean '{$t}'?" : '.'; throw new \RuntimeException("Cannot include undefined block '{$name}'{$hint}"); } $block = reset($this->blockQueue[$name]); if ($mod && $mod !== ($blockType = $this->blockTypes[$name])) { if ($filter = is_string($mod) ? Filters::getConvertor($blockType, $mod) : $mod) { echo $filter($this->capture(function () use($block, $params) { $block($params); }), $blockType); return; } trigger_error("Including block {$name} with content type " . strtoupper($blockType) . ' into incompatible type ' . strtoupper($mod) . '.', E_USER_WARNING); } $block($params); }
/** * Returns links for types. * * @param string $annotation * @param ElementReflectionInterface $reflectionElement * @return string */ public function typeLinks($annotation, ElementReflectionInterface $reflectionElement) { $links = []; list($types) = Strings::split($annotation); if (!empty($types) && $types[0] === '$') { $types = null; } foreach (explode('|', $types) as $type) { $type = $this->getTypeName($type, false); $links[] = $this->resolveLink($type, $reflectionElement) ?: LatteFilters::escapeHtml(ltrim($type, '\\')); } return implode('|', $links); }