/** * @secured */ public function handleRegenerate($tagId) { try { $tag = $this->tags->findOneBy(['id' => $tagId]); $tag->color = substr(md5(rand()), 0, 6); //Short and sweet $this->tags->save($tag); $this->flashMessage('Tag byl úspěšně regenerován.', 'success'); } catch (\Exception $exc) { $this->flashMessage($exc->getMessage(), 'danger'); } $this->redirect('this'); }
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; } }
public function postFormSucceeded(UI\Form $form, Nette\Utils\ArrayHash $vals) { try { if (!$this->post) { $this->post = new Post(); $this->post->date = new \DateTime(); } $this->post->publish_date = $vals->publish_date ? new \DateTime($vals->publish_date) : new \DateTime('now'); $this->post->title = $vals->title; $this->post->slug = $vals->slug; $this->post->body = $vals->editor; $this->post->disable_comments = $vals->disable_comments; $this->post->draft = FALSE; foreach (array_unique(preg_split('/\\s*,\\s*/', $vals->tags)) as $tagName) { $tag = $this->tags->findOneBy(['name' => $tagName]); if (!$tag) { $tag = new Entity\Tag(); $tag->name = $tagName; $tag->color = substr(md5(rand()), 0, 6); //Short and sweet } if (!empty($tagName)) { $this->post->addTag($tag); } } $this->posts->save($this->post); $this->presenter->flashMessage('Příspěvek byl úspěšně uložen a publikován.', 'success'); $this->onSave(); } catch (\Doctrine\DBAL\Exception\UniqueConstraintViolationException $exc) { $this->presenter->flashMessage('Tento URL slug je již v databázi uložen, zvolte prosím jiný.', 'danger'); } catch (\Nette\Security\AuthenticationException $exc) { $this->presenter->flashMessage('Myslím to vážně, editovat opravdu **ne**můžete!', 'danger'); $this->redirect('this'); return; } }