Пример #1
0
 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;
     }
 }
Пример #2
0
 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;
     }
 }