Beispiel #1
0
 public function addAjaxActionAuth(Param\AjaxString $title, Param\AjaxSafeHTML $text, Param\AjaxString $tags = null)
 {
     $userId = Difra\Auth::getInstance()->getEmail();
     if ($group = Blogs\Group::current()) {
         if (!$group->hasUser($userId)) {
             \Difra\Libs\Cookies::getInstance()->notify(\Difra\Locales::getInstance()->getXPath('blogs/notifies/add_post_denied'), true);
             $this->view->redirect('/');
         }
         $blog = Blogs\Blog::touchByGroup($group->getId());
     } else {
         $blog = Blogs\Blog::touchByUser($userId);
     }
     if ($post = $blog->addPost($userId, $title->val(), $text->val())) {
         $post = $blog->getPost($post->getId());
         if (class_exists('Difra\\Plugins\\Tags')) {
             $tagsArray = Difra\Plugins\Tags::getInstance()->tagsFromString($tags);
             Difra\Plugins\Tags::getInstance()->update('posts', $post->getId(), $tagsArray);
         }
         $this->ajax->redirect($post->getUrl());
     } else {
         $this->ajax->error(\Difra\Locales::getInstance()->getXPath('blogs/notifies/add_post_failed'));
     }
 }