public function onUpload(Form $form) { /** @var UploadControl[] $form */ /** @var FileUpload $json */ /** @var FileUpload $audio */ $json = $form['json']->getValue(); $audio = $form['audio']->getValue(); $data = Json::decode($json->getContents(), Json::FORCE_ARRAY); $blackboard = new Rme\Blackboard(); $this->orm->contents->attach($blackboard); $blackboard->title = 'Nová nahrávka'; $blackboard->description = ' '; $blackboard->hidden = TRUE; $blackboard->duration = $data['duration']; $blackboard->preview = 'https://placehold.it/480x320&text=...'; $blackboard->author = $this->userEntity; $this->orm->flush(); $base = $this->paths->getBlackboards() . "/{$blackboard->id}"; $json->move("{$base}.json"); $audio->move("{$base}.wav"); $producer = $this->queue->getProducer('blackboardPreview'); $producer->publish(serialize(['blackboard' => new EntityPointer($blackboard)])); $link = $this->link('BlackboardEditor:default', ['blackboardId' => $blackboard->id]); $this->sendJson(['redirect' => $link]); }
public function invoke(Paths $paths) { $tmp = $paths->getTemp(); exec('sudo rm -rf ' . escapeshellarg("{$tmp}/cache/_*")); $this->out->writeln('<info>Cache cleared</info>'); // TODO clear opcache }
public function invoke(ElasticSearch $elastic, Paths $paths) { $raw = file_get_contents($paths->getApp() . '/config/synonyms.esn'); $output = []; foreach (explode("\n", $raw) as $line) { $line = preg_replace('~\\s*#.*$~m', '', $line); // remove comments if (!$line) { continue; } $parts = preg_split('~\\s*(=>|,)\\s*~', $line, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); foreach ($parts as &$part) { if ($part === '=>' || $part === ',') { continue; } $words = []; foreach ($elastic->analyze('synonyms_compiler', $part)['tokens'] as $token) { $words[] = $token['token']; } $part = implode(' ', $words); } $output[] = '- "' . implode(' ', $parts) . '"'; } $content = "# Do not edit this file directly! Instead,\n"; $content .= "# edit synonyms.esn and run elasticsearch:build-synonyms command.\n\n"; $content .= str_replace(' ,', ',', implode("\n", $output)) . "\n"; file_put_contents($paths->getApp() . '/config/synonyms.compiled.neon', $content); $this->out->writeln('<info>Synonyms compiled</info>'); }
/** * @return string dir path */ protected function getTempDir() { $dir = $this->paths->getBackup() . '/.temp'; if (!file_exists($dir)) { mkdir($dir); } return $dir; }
public function invoke(array $args) { /** @var Blackboard $bb */ $bb = $args['blackboard']; $file = $this->paths->getPreviews() . "/{$bb->id}.png"; $this->generator->generate($bb, $file); $bb->preview = "/data/preview/{$bb->id}.png"; $this->orm->flush(); }
public function renderBlueprints($page = NULL) { $this->template->setFile($this->paths->getTemplate('Search', 'results')); $this->template->query = $query = 'Všechna cvičení'; $this->template->filter = NULL; $this['searchResultsForm-form-query']->setDefaultValue($query); list($limit, $offset) = $this->getLinearLimitOffset($page ?: 1); $results = $this->orm->contents->findAllBlueprints()->applyLimit($limit, $offset); $this->template->search = (object) ['results' => $results, 'aggregations' => [['key' => 'blueprint', 'doc_count' => $results->count()]], 'total' => $results->count()]; $this->payload->results = $results->count(); $this->redrawControl('results'); }
public function invoke(RepositoryContainer $orm, Paths $paths, BlackboardPreview $generator) { $blackboards = $orm->contents->findAllBlackboards(); foreach ($blackboards as $bb) { $file = $paths->getPreviews() . "/{$bb->id}.png"; if (!file_exists($file)) { $generator->generate($bb, $file); $bb->preview = "/data/preview/{$bb->id}.png"; $this->out->writeln("<info>Preview saved to {$file}</info>"); } } $orm->flush(); }
public function invoke(array $args) { /** @var Video $video */ $video = $args['video']; $seconds = []; $norm = $video->views->count(); foreach ($video->views as $view) { $time = 0; foreach ($view->events as $event) { for (; $time < $event->timeAt; ++$time) { @$seconds['watched'][$time]++; // zero if unset } if ($event instanceof VideoEvents\Seek) { if ($event->timeTo > $time) { // skip forward for (; $time < $event->timeTo; ++$time) { @($seconds['watched'][$time] -= $norm / 100); // penalize these seconds } } else { // jump back, will iterate over same time again on next event $time = (int) $event->timeTo; } } else { if ($event instanceof VideoEvents\Pause) { @($seconds['pause'][$time] += max(2, $event->duration)); // zero if unset } } } for (; $time < $view->furthest; ++$time) { @$seconds['watched'][$time]++; // zero if unset } } $canvas = imagecreatetruecolor($video->duration, 2); $maxWatch = max($seconds['watched']); $maxPause = max($seconds['pause']); for ($s = 0; $s < $video->duration; ++$s) { $watched = isset($seconds['watched'][$s]) ? max($seconds['watched'][$s], 0) / $maxWatch : 0; $color = imagecolorallocate($canvas, (1 - $watched) * 255, (1 - $watched) * 255, 255); imagesetpixel($canvas, $s, 0, $color); $pause = isset($seconds['pause'][$s]) ? max($seconds['pause'][$s], 0) / $maxPause : 0; $color = imagecolorallocate($canvas, 255, (1 - $pause) * 255, (1 - $pause) * 255); imagesetpixel($canvas, $s, 1, $color); } $dir = $this->paths->getVideoCharts(); @mkdir($dir); imagepng($canvas, "{$dir}/{$video->id}.png", 9); }
public function generate(Blackboard $bb, $outfile) { $raw = file_get_contents($this->paths->getBlackboards() . "/{$bb->id}.json"); $data = Json::decode($raw, Json::FORCE_ARRAY); $min = ['width' => PHP_INT_MAX, 'height' => PHP_INT_MAX]; $max = ['width' => 0, 'height' => 0]; foreach ($data['data'] as $row) { if ($row['type'] !== 'beginStroke' && $row['type'] !== 'strokeTo') { continue; } $min['width'] = min($min['width'], $row['loc']['x']); $min['height'] = min($min['height'], $row['loc']['y']); $max['width'] = max($max['width'], $row['loc']['x']); $max['height'] = max($max['height'], $row['loc']['y']); } $margin = 20; $min['width'] -= $margin; $min['height'] -= $margin; $max['width'] += $margin; $max['height'] += $margin; $ratio = 2; $canvas = imagecreatetruecolor(($max['width'] - $min['width']) * $ratio, ($max['height'] - $min['height']) * $ratio); if (function_exists('imageantialias')) { // this function is not in php5-gd and requires recompiling php imageantialias($canvas, TRUE); } $last = NULL; foreach ($data['data'] as $row) { if ($row['type'] === 'beginStroke') { $last = $row['loc']; } else { if ($row['type'] === 'strokeTo') { $c = $row['color']; $color = imagecolorallocate($canvas, $c['r'], $c['g'], $c['b']); $this->imagelinethick($canvas, ($last['x'] - $min['width']) * $ratio, ($last['y'] - $min['height']) * $ratio, ($row['loc']['x'] - $min['width']) * $ratio, ($row['loc']['y'] - $min['height']) * $ratio, $color, 3); $last = $row['loc']; } else { if ($row['type'] === 'erase') { $color = imagecolorallocate($canvas, 0, 0, 0); $radius = 11 * $ratio; $x = ($row['loc']['x'] - $min['width']) * $ratio; $y = ($row['loc']['y'] - $min['height']) * $ratio; imagefilledarc($canvas, $x, $y, $radius, $radius, 0, 360, $color, IMG_ARC_PIE); } } } } imagepng($canvas, $outfile, 9); }
private function setScripts() { $current = preg_replace_callback('~\\B[A-Z]~', function ($m) { return '-' . strToLower($m[0]); }, $this->getAction(TRUE)); $partials = explode(':', 'app' . strToLower($current)); $scripts = []; $last = TRUE; for ($i = count($partials); $i > 0; $i--) { $script = []; for ($p = 0; $p < $i; $p++) { $script[] = $partials[$p]; } if (!$last) { $script[] = '_all'; } $scripts[] = implode('/', $script); $last = FALSE; } $jsDir = $this->paths->getJs(); $existingScripts = []; foreach (array_reverse($scripts) as $script) { if (file_exists("{$jsDir}/{$script}.js")) { $existingScripts[] = $script; } } $this->template->scripts = Nette\Utils\Json::encode($existingScripts); }