public function startQuery($sql, array $params = null, array $types = null) { $highlighted = Panel::highlightQuery(Panel::formatQuery($sql, (array) $params, (array) $types)); $formatted = html_entity_decode(strip_tags($highlighted)); $formatted = preg_replace('#^[\\t ]+#m', '', Nette\Utils\Strings::normalize($formatted)); $message = '-- process ' . getmypid() . '; ' . Debugger::$source . "\n" . $formatted . "\n\n"; file_put_contents($this->file, $message, FILE_APPEND); }
/** * factory to grid component * @param string $name * @return \Ublaboo\DataGrid\DataGrid */ public function createComponentGrid($name) { $datasource = $this->model->getQuery()->study()->setDestination($this->remoteAet)->setRequestedFields($this->tableRows); if ($this->isExternist) { $datasource->addCondition("ReferringPhysicianName", $this->externistKey); } //create grid and set data source $grid = new \Ublaboo\DataGrid\DataGrid($this, $name); // setting datasource $grid->setPrimaryKey('StudyInstanceUID'); $grid->setDataSource($datasource); // setting outer filter rendering $grid->setOuterFilterRendering(TRUE); // set columns hidable $grid->setColumnsHideable(); //add collumn Patient ID which is sortable and may be filtered $grid->addColumnText('PatientID', _("PatientID"))->setSortable()->setFilterText(); //add collumn Patient Name which is sortable and may be filtered $grid->addColumnText('PatientName', _("Patient name"))->setSortable()->setFilterText(); //add collumn Study description Name which is sortable and may be filtered $grid->addColumnText('StudyDescription', _("Study description"))->setRenderer(function ($item) { return $this->model->query->encodeDicomName($item["StudyDescription"]); })->setSortable()->setFilterText(); //add collumn Patient Name which is sortable and may be filtered $grid->addColumnText('PatientSex', _("Patient sex"))->setSortable()->setRenderer(function ($item) { $sexItems = $this->model->query->getConfig()["patientSexItems"]; return $sexItems[\Nette\Utils\Strings::normalize($item["PatientSex"])]; })->setFilterSelect($this->model->query->getConfig()["patientSexItems"]); //add collumn Study modality which is sortable and may be filtered $grid->addColumnText('Modality', _("Study modality"))->setSortable()->setFilterText(); //add collumn Study date which is sortable and may be filtered $grid->addColumnDateTime('StudyDate', _("Study date"))->setFormat('Y-m-d')->setSortable()->setFilterDateRange(); $grid->addColumnDateTime('StudyTime', _("Study time"))->setSortable()->setRenderer(function ($item) { return $this->model->query->encodeTime($item["StudyTime"]); }); if ($this->isLocal) { // add action show $grid->addAction(':Data:Viewer:default', _('Open'))->setClass('btn btn-xs btn-default')->setIcon('folder-open-o'); // add action send # $grid->addAction('sendStudyForm!', _('Send'))->setIcon('upload')->setClass('btn btn-xs btn-default ajax modalOpen')->setDataAttribute("toggle", "modal")->setDataAttribute("target", "#sendFormModal"); // add action export $grid->addAction('export!', _('Export'))->setIcon('share-square-o')->setDataAttribute("toggle", "modal")->setDataAttribute("target", "#exportModal"); // add action delete if ($this->user->isAllowed("data", "delete")) { $grid->addAction('deleteStudy!', _('Delete'))->setIcon('trash-o')->setClass('btn btn-xs btn-default')->setConfirm(_('Do you really want to delete this study?')); } } else { // add action show $grid->addAction('open!', _('Open'))->setIcon('folder-open-o'); // add action retrieve # $grid->addAction('retrieve!', _('Retrieve'))->setDataAttribute("toggle", "modal")->setDataAttribute("target", "#retrieveModal")->setIcon('download'); } // setting pagination $grid->setItemsPerPageList([20, 50, 100, 500]); // return grid return $grid; }
/** * @param string $config * @return TokenIterator tokens * @throws ConfigException */ public function lex($config) { $normalized = Strings::normalize($config); // remove meaningless leading spacing to simplify T_KEYWORD $simplified = Strings::replace($normalized, '~^\\s+~m', ''); try { $tokens = $this->getTokenizer()->tokenize($simplified); return new TokenIterator($tokens); } catch (TokenizerException $e) { throw ConfigException::createFromLexerException($e); } }
public static function diff($original, $replacement) { $original = \Nette\Utils\Strings::normalize($original); $replacement = \Nette\Utils\Strings::normalize($replacement); if ($original == $replacement) { //no change return Html::el('span', ['style' => 'color:blue;'])->setHtml($original); } elseif ($original == '') { //no original text return Html::el('span', ['style' => 'color:green;'])->setHtml($replacement); } elseif ($replacement == '') { //no replacement text return Html::el('span', ['style' => 'color:red;'])->setHtml($original); } else { //text is different return HTML::el('span')->add(Html::el('span', ['style' => 'color:red;'])->setHtml($original))->add(Html::el('br'))->add(Html::el('span', ['style' => 'color:green;'])->setHtml($replacement)); } }
protected function fetchSubtitles($youtubeId, $cached) { $url = "https://report.khanovaskola.cz/api/1/subtitles/{$youtubeId}/cs" . ($cached ? '?cached=1' : ''); $res = @file_get_contents($url); // was failing randomly if (!$res) { return NULL; } if ($cached) { $headers = $http_response_header; if (strpos($headers[0], 'HTTP/1.1 304') !== FALSE) { return $cached; } } $data = json_decode($res); if ($data->found) { return Strings::normalize(Strings::fixEncoding($data->subtitles)); } return NULL; }
public function renderDefault($search) { //FIXME tagy ::: 'publish_date <=' => new \DateTime() $string = Strings::lower(Strings::normalize($search)); $string = Strings::replace($string, '/[^\\d\\w]/u', ' '); $words = Strings::split(Strings::trim($string), '/\\s+/u'); $words = array_unique(array_filter($words, function ($word) { return Strings::length($word) > 1; })); $words = array_map(function ($word) { return Strings::toAscii($word); }, $words); $string = implode(' ', $words); $this->template->tag = $this->tags->findOneBy(['name' => $string]); $result = $this->posts->fulltextSearch($string); if (count($result) == 0) { $this->template->search = $search; $this->template->error = 'Nic nebylo nalezeno'; } else { $this->template->search = $search; $this->template->result = $result; } }
/** * @param CurlWrapper $curl * @return string */ public static function convertEncoding(CurlWrapper $curl) { if (Strings::checkEncoding($response = $curl->response)) { return Strings::normalize($response); } if ($charset = static::charsetFromContentType($curl->info['content_type'])) { $response = @iconv($charset, 'UTF-8', $response); } else { if ($contentType = Strings::match($response, '~<(?P<el>meta[^>]+Content-Type[^>]+)>~i')) { foreach (Nette\Utils\Html::el($contentType['el'])->attrs as $attr => $value) { if (strtolower($attr) !== 'content') { continue; } if ($charset = static::charsetFromContentType($value)) { $response = @iconv($charset, 'UTF-8', $response); $response = static::fixContentTypeMeta($response); break; } } } } return Strings::normalize($response); }
/** * @return string PHP code */ public function __toString() { $consts = array(); foreach ($this->consts as $name => $value) { $consts[] = "const {$name} = " . Helpers::dump($value) . ";\n"; } $properties = array(); foreach ($this->properties as $property) { $doc = str_replace("\n", "\n * ", implode("\n", (array) $property->getDocuments())); $properties[] = ($property->getDocuments() ? strpos($doc, "\n") === FALSE ? "/** {$doc} */\n" : "/**\n * {$doc}\n */\n" : '') . $property->getVisibility() . ($property->isStatic() ? ' static' : '') . ' $' . $property->getName() . ($property->value === NULL ? '' : ' = ' . Helpers::dump($property->value)) . ";\n"; } $extends = $implements = $traits = array(); if ($this->namespace) { foreach ((array) $this->extends as $name) { $extends[] = $this->namespace->unresolveName($name); } foreach ((array) $this->implements as $name) { $implements[] = $this->namespace->unresolveName($name); } foreach ((array) $this->traits as $name) { $traits[] = $this->namespace->unresolveName($name); } } else { $extends = (array) $this->extends; $implements = (array) $this->implements; $traits = (array) $this->traits; } foreach ($this->methods as $method) { $method->setNamespace($this->namespace); } return Strings::normalize(($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '') . ($this->abstract ? 'abstract ' : '') . ($this->final ? 'final ' : '') . $this->type . ' ' . $this->name . ' ' . ($this->extends ? 'extends ' . implode(', ', $extends) . ' ' : '') . ($this->implements ? 'implements ' . implode(', ', $implements) . ' ' : '') . "\n{\n\n" . Strings::indent(($this->traits ? 'use ' . implode(', ', $traits) . ";\n\n" : '') . ($this->consts ? implode('', $consts) . "\n\n" : '') . ($this->properties ? implode("\n", $properties) . "\n\n" : '') . implode("\n\n\n", $this->methods), 1) . "\n\n}") . "\n"; }
public function addAdmin($name) { $this->fbAdmins[] = Nette\Utils\Strings::normalize($name); return $this; //fluent interface }
/** * @return string PHP code */ public function __toString() : string { foreach ($this->namespaces as $namespace) { $namespace->setBracketedSyntax(isset($this->namespaces[NULL])); } return Strings::normalize("<?php\n" . ($this->comment ? "\n" . str_replace("\n", "\n * ", "/**\n" . $this->comment) . "\n */\n\n" : '') . implode("\n\n", $this->namespaces)) . "\n"; }
/** * Validate. */ public function validate() { if (!ob_get_level()) { return; } $this->html = Strings::normalize(ob_get_contents()); ob_end_flush(); libxml_use_internal_errors(true); $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->resolveExternals = FALSE; $dom->validateOnParse = TRUE; $dom->preserveWhiteSpace = FALSE; $dom->strictErrorChecking = TRUE; $dom->recover = TRUE; set_error_handler(function ($severity, $message) { restore_error_handler(); }); @$dom->loadHTML($this->html); restore_error_handler(); $this->errors = array_filter(libxml_get_errors(), function (\LibXMLError $error) { return !in_array((int) $error->code, ValidatorPanel::$ignoreErrors, TRUE); }); libxml_clear_errors(); }
private function processFunction(array $definition, Node $node) { $message = array(Context::LINE => $node->getLine()); foreach ($definition as $position => $type) { if (!isset($node->args[$position - 1])) { return; } $arg = $node->args[$position - 1]->value; if ($arg instanceof String_) { $message[$type] = $arg->value; } elseif ($arg instanceof Array_) { foreach ($arg->items as $item) { if ($item->value instanceof String_) { $message[$type][] = $item->value->value; } } } else { return; } } if (is_array($message[Context::SINGULAR])) { foreach ($message[Context::SINGULAR] as $value) { $tmp = $message; $tmp[Context::SINGULAR] = Strings::normalize($value); $this->data[] = $tmp; } } else { $message[Context::SINGULAR] = Strings::normalize($message[Context::SINGULAR]); $this->data[] = $message; } }
/** * DataGrit form * @param Form $form * @return Form */ public function createComponentForm() { $form = new Form(); //create filter form elements foreach ($this->th as $key => $value) { if ($value->filter) { switch ($value->filter) { case 'text': $form->addText($key)->getControlPrototype()->class('filter-' . $value->filter); break; case 'date': $form->addText($key)->setHtmlId($this->name . '-' . $key . '-date-filter')->getControlPrototype()->class('filter-' . $value->filter); break; case 'int': $form->addText($key)->getControlPrototype()->class('filter-' . $value->filter); break; case 'select': $form->addSelect($key, NULL, $value->select)->getControlPrototype()->class('filter-' . $value->filter); break; case 'bool': $form->addSelect($key, '', array('yes' => 'Áno', 'no' => 'Nie'))->setPrompt('')->getControlPrototype()->class('filter-' . $value->filter); break; } } } $form->addSubmit('filter', 'Filtrovať')->getControlPrototype()->class('grid-submit-filter'); $self = $this; $th = $this->th; $form->onSuccess[] = function ($form) use($self, $th) { $set_values = array(); foreach ($form->values as $key => $value) { $value = Strings::normalize($value); if (!empty($value)) { $set_values[$key] = array('value' => $th[$key]->filter == 'bool' ? $self->stringToBool($value) : $value, 'kind' => $th[$key]->filter); } } $self->filter = $set_values; $self->page = '1'; $self->finalize(); }; return $form; }
/** * @return string PHP code */ public function __toString() { $consts = array(); foreach ($this->consts as $name => $value) { $consts[] = "const {$name} = " . Helpers::dump($value) . ";\n"; } $properties = array(); foreach ($this->properties as $property) { $doc = str_replace("\n", "\n * ", implode("\n", $property->getDocuments())); $properties[] = ($property->getDocuments() ? strpos($doc, "\n") === FALSE ? "/** {$doc} */\n" : "/**\n * {$doc}\n */\n" : '') . $property->getVisibility() . ($property->isStatic() ? ' static' : '') . ' $' . $property->getName() . ($property->value === NULL ? '' : ' = ' . Helpers::dump($property->value)) . ";\n"; } $namespace = $this->namespace; $mapper = function (array $arr) use($namespace) { return $namespace ? array_map(array($namespace, 'unresolveName'), $arr) : $arr; }; return Strings::normalize(($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", $this->documents)) . "\n */\n" : '') . ($this->abstract ? 'abstract ' : '') . ($this->final ? 'final ' : '') . $this->type . ' ' . $this->name . ' ' . ($this->extends ? 'extends ' . implode(', ', $mapper((array) $this->extends)) . ' ' : '') . ($this->implements ? 'implements ' . implode(', ', $mapper($this->implements)) . ' ' : '') . "\n{\n" . Strings::indent(($this->traits ? 'use ' . implode(";\nuse ", $mapper($this->traits)) . ";\n\n" : '') . ($this->consts ? implode('', $consts) . "\n" : '') . ($this->properties ? implode("\n", $properties) . "\n" : '') . ($this->methods ? "\n" . implode("\n\n\n", $this->methods) . "\n\n" : ''), 1) . '}') . "\n"; }
/** * @param string $specialClass * @return \Illagrenan\Navigation\NavigationNode */ public function addSpecialClass($specialClass) { if (Validators::isUnicode($specialClass) === FALSE) { throw new Exceptions\InvalidSpecialClassException("Given \"" . $specialClass . "\" is not valid special class."); } $specialClass = Strings::trim($specialClass); $specialClass = Strings::normalize($specialClass); $specialClass = Strings::toAscii($specialClass); $this->specialClass[] = $specialClass; return $this; }
/** * @param string|array $columns * @throws InvalidStateException * @return ResultSet */ public function applySorting($columns) { $this->updating(); $sorting = []; foreach (is_array($columns) ? $columns : func_get_args() as $name => $column) { if (!is_numeric($name)) { $column = $name . ' ' . $column; } if (!preg_match('~\\s+(DESC|ASC)\\s*\\z~i', $column = trim($column))) { $column .= ' ASC'; } $sorting[] = $column; } if ($sorting) { $dql = Strings::normalize($this->query->getDQL()); if (!preg_match('~^(.+)\\s+(ORDER BY\\s+((?!FROM|WHERE|ORDER\\s+BY|GROUP\\sBY|JOIN).)*)\\z~si', $dql, $m)) { $dql .= ' ORDER BY '; } else { $dql .= ', '; } $this->query->setDQL($dql . implode(', ', $sorting)); } $this->iterator = NULL; return $this; }
public static function parse($phrase) { $normalized = Strings::lower(Strings::normalize(Strings::toAscii($phrase))); $words = preg_split('~\\s+~', $normalized, -1, PREG_SPLIT_NO_EMPTY); $number = 0; $buffer = 0; while ($word = array_shift($words)) { $compound = static::parseCompoundWord($word); if ($compound) { $buffer += $compound; continue; } switch ($word) { case 'a': // ignore // ignore case 'nula': // keep $number 0 break; case 'jedno': case 'jedna': case 'jeden': $buffer += 1; break; case 'dva': case 'dve': $buffer += 2; break; case 'tri': $buffer += 3; break; case 'ctyri': $buffer += 4; break; case 'pet': $buffer += 5; break; case 'sest': $buffer += 6; break; case 'sedm': case 'sedum': $buffer += 7; break; case 'osm': case 'osum': $buffer += 8; break; case 'devet': $buffer += 9; break; case 'deset': $buffer += 10; break; case 'jedenact': $buffer += 11; break; case 'dvanact': $buffer += 12; break; case 'trinact': $buffer += 13; break; case 'ctrnact': $buffer += 14; break; case 'patnact': $buffer += 15; break; case 'sestnact': $buffer += 16; break; case 'sedmnact': case 'sedumnact': $buffer += 17; break; case 'osmnact': case 'osumnact': $buffer += 18; break; case 'devatenact': $buffer += 19; break; case 'dvacet': $buffer += 20; break; case 'tricet': $buffer += 30; break; case 'ctyricet': $buffer += 40; break; case 'padesat': $buffer += 50; break; case 'sedesat': $buffer += 60; break; case 'sedmdesat': case 'sedumdesat': $buffer += 70; break; case 'osmdesat': case 'osumdesat': $buffer += 80; break; case 'devadesat': $buffer += 90; break; case 'sto': if ($buffer === 1) { // jedno sto $buffer = 100; break; } else { $buffer += 100; break; } case 'ste': case 'sta': case 'set': if ($buffer >= 11 && $buffer <= 19) { // devatenact set $number += $buffer * 100; $buffer = 0; } else { $buffer *= 100; } break; case 'tisic': case 'tisice': case 'tisicu': $number += ($buffer ?: 1) * 1000.0; $buffer = 0; break; case 'milion': case 'miliony': case 'milionu': $number += ($buffer ?: 1) * 1000000.0; $buffer = 0; break; default: throw new InvalidArgumentException("Failed to parse '{$word}'"); } } return (int) $number + $buffer; var_dump($number, $buffer); }
private function processViews() { $tables = $this->db->getConnection()->getSupplementalDriver()->getTables(); foreach ($tables as $table) { if ($table['view'] == TRUE) { $viewName = $table['name']; // Fetch SHOW CREATE VIEW string $row = $this->db->query("SHOW CREATE VIEW `{$viewName}`")->fetch(); $createView = $row["Create View"]; // Remove Auto increment value $createView = Strings::replace($createView, '#SQL SECURITY DEFINER\\s?#i'); $createView = Strings::replace($createView, '#ALGORITHM=UNDEFINED\\s?#i'); $createView = Strings::replace($createView, '/DEFINER=`.+?`\\@`.+?`\\s?/'); // Add ; $createView .= ";"; $dropTable = "DROP VIEW IF EXISTS `{$viewName}`;\n"; $data = Data::header() . $dropTable . $createView . "\n" . Data::footer(); $dump = new Dump($viewName, Dump::TYPE_VIEW, $this->dumpDir); $dump->saveIfChanged($data, function ($fromFile) use($createView) { $createViewFromFile = Strings::match($fromFile, "/CREATE.*;/s")[0]; return Strings::normalize($createViewFromFile) == Strings::normalize($createView); }); } } }
/** @return string PHP code */ public function __toString() { $consts = array(); foreach ($this->consts as $name => $value) { $consts[] = "const {$name} = " . Helpers::dump($value) . ";\n"; } $properties = array(); foreach ($this->properties as $property) { $properties[] = ($property->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $property->documents)) . "\n */\n" : '') . $property->visibility . ($property->static ? ' static' : '') . ' $' . $property->name . ($property->value === null ? '' : ' = ' . Helpers::dump($property->value)) . ";\n"; } return Nette\Utils\Strings::normalize(($this->documents ? str_replace("\n", "\n * ", "/**\n" . implode("\n", (array) $this->documents)) . "\n */\n" : '') . ($this->abstract ? 'abstract ' : '') . ($this->final ? 'final ' : '') . $this->type . ' ' . $this->name . ' ' . ($this->extends ? 'extends ' . implode(', ', (array) $this->extends) . ' ' : '') . ($this->implements ? 'implements ' . implode(', ', (array) $this->implements) . ' ' : '') . "\n{\n\n" . Nette\Utils\Strings::indent(($this->traits ? "use " . implode(', ', (array) $this->traits) . ";\n\n" : '') . ($this->consts ? implode('', $consts) . "\n\n" : '') . ($this->properties ? implode("\n", $properties) . "\n\n" : '') . implode("\n\n\n", $this->methods), 1) . "\n\n}") . "\n"; }
/** * Remove big letters, diacritics, translate numbers and y = i * @param string $answer * @return string */ private function cutAnswer($answer) { return $this->translateNumber($this->normalizeY(Strings::toAscii(Strings::lower(Strings::trim(Strings::normalize($answer)))))); }