Example #1
0
 public function savepostAction()
 {
     if (isset($_POST['user']) && $_POST['user'] != '' && isset($_POST['postText']) && $_POST['postText'] != '' && isset($_POST['postTitle']) && $_POST['postTitle'] != '') {
         $userId = intval($_POST['user']);
         $blog = Blogs\Blog::touchByGroup(1);
         $blog->addPost($userId, $_POST['postTitle'], $_POST['postText']);
     }
     $this->view->redirect('/adm/blogs/');
 }
Example #2
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'));
     }
 }
Example #3
0
 public function getBlog()
 {
     return Blog::getById($this->blog);
 }
Example #4
0
 public function indexAction(Param\AnyString $nickname = null, Param\NamedInt $page = null)
 {
     $page = $page ? $page->val() : 1;
     if ($nickname) {
         // получаем $userId по никнейму
         $nickname = rawurldecode($nickname);
         if (!($userId = Difra\Additionals::getAdditionalId('users', 'nickname', $nickname))) {
             $this->view->httpError(404);
             return;
         }
         /** @var \DOMElement $userNode */
         $userNode = $this->root->appendChild($this->xml->createElement('user'));
         $userNode->setAttribute('id', $userId);
         \Difra\Additionals::getAdditionalsXml('users', $userId, $userNode);
         // /user/имя
         if (empty($this->action->parameters)) {
             $auth = \Difra\Auth::getInstance();
             $canModify = ($auth->isAuthorized() and $userId == $auth->getEmail());
             // виджет данных юзера
             /** @var \DOMElement $blogsViewNode */
             $blogsViewNode = $this->root->appendChild($this->xml->createElement('userInfoWidget'));
             $blogsViewNode->setAttribute('left', 1);
             $blogsViewNode = $this->root->appendChild($this->xml->createElement('blogsView'));
             $blogsViewNode->setAttribute('left', 1);
             $blogsViewNode->setAttribute('link', '/blogs/' . rawurlencode($nickname));
             $blogsViewNode->setAttribute('canModify', $canModify ? '1' : '0');
             $blogId = Blogs::getInstance()->getUserBlogXML($blogsViewNode, $userId, $page);
             if ($auth->isAuthorized()) {
                 if ($canModify) {
                     /** @var \DOMElement $blogsControlNode */
                     $blogsControlNode = $this->root->appendChild($this->xml->createElement('blogsControl'));
                     $blogsControlNode->setAttribute('right', 1);
                     $blogsControlNode->setAttribute('addPrefix', 1);
                 }
             }
             // виджет "я в группах"
             /** @var \DOMElement $myGroupsNode */
             $myGroupsNode = $this->root->appendChild($this->xml->createElement('myGroupsWidget'));
             $myGroupsNode->setAttribute('right', 1);
             \Difra\Plugins\Blogs\Group::getUsersGroups($userId, $myGroupsNode);
             // виджет избранных блогов
             /** @var \DOMElement $friendsNode */
             $friendsNode = $this->root->appendChild($this->xml->createElement('friendsWidget'));
             $friendsNode->setAttribute('right', 1);
             \Difra\Plugins\Blogs\Blog::getFriendsPreviewXML($auth->getEmail(), $friendsNode);
             if ($userId != $auth->getEmail()) {
                 $friendsNode->setAttribute('user', $auth->getEmail());
                 $friendsNode->setAttribute('canAdd', $blogId);
             }
             // /user/имя/15/заголовок
         } elseif (sizeof($this->action->parameters) == 2) {
             $postId = $this->action->parameters[0];
             if (!ctype_digit($postId)) {
                 $this->view->httpError(404);
                 return;
             }
             $postLink = rawurldecode($this->action->parameters[1]);
             if (!($post = Blogs::getInstance()->getPost($userId, $postId))) {
                 $this->view->httpError(404);
                 return;
             }
             if ($postLink != $post->getLink()) {
                 $this->view->redirect("/blogs/{$nickname}/{$postId}/" . $post->getLink());
                 return;
             }
             $this->action->parameters = [];
             // виджет "я в группах"
             $myGroupsNode = $this->root->appendChild($this->xml->createElement('myGroupsWidget'));
             $myGroupsNode->setAttribute('right', 1);
             \Difra\Plugins\Blogs\Group::getUsersGroups($userId, $myGroupsNode);
             // виджет данных юзера
             $blogsViewNode = $this->root->appendChild($this->xml->createElement('userInfoWidget'));
             $blogsViewNode->setAttribute('left', 1);
             /** @var \DOMElement $blogsSingle */
             $blogsSingle = $this->root->appendChild($this->xml->createElement('blogsSingle'));
             $blogsSingle->setAttribute('left', 1);
             $post->getXML($blogsSingle, true);
             /** @var \DOMElement $comments */
             $comments = $this->root->appendChild($this->xml->createElement('comments'));
             $comments->setAttribute('left', 1);
             \Difra\Plugins\Comments::getInstance()->getCommentsXML($comments, 'blogs', $postId, $page);
             // виджет избранных блогов
             $friendsNode = $this->root->appendChild($this->xml->createElement('friendsWidget'));
             $friendsNode->setAttribute('right', 1);
             $auth = \Difra\Auth::getInstance();
             \Difra\Plugins\Blogs\Blog::getFriendsPreviewXML($auth->getEmail(), $friendsNode);
             if ($userId != $auth->getEmail()) {
                 $friendsNode->setAttribute('user', $auth->getEmail());
                 $friendsNode->setAttribute('canAdd', $post->getBlogId());
             }
             // статистика для поста
             Blogs::getInstance()->savePostStat($postId, null, $userId);
         } else {
             $this->view->httpError(404);
         }
     } else {
         $blogsViewNode = $this->root->appendChild($this->xml->createElement('blogsAllView'));
         $blogsViewNode->setAttribute('left', 1);
         $blogsViewNode->setAttribute('link', '/blogs');
         Difra\Plugins\Blogs::getInstance()->getAllPostsXML($blogsViewNode, $page);
         if (Difra\Auth::getInstance()->isAuthorized()) {
             /** @var \DOMElement $mypageWidget */
             $mypageWidget = $this->root->appendChild($this->xml->createElement('myPageWidget'));
             $mypageWidget->setAttribute('right', 1);
         }
         /** @var \DOMElement $controlNode */
         $controlNode = $this->root->appendChild($this->xml->createElement('artistControl'));
         $controlNode->setAttribute('right', 1);
         // TODO: вынести работу с тэгами в отдельный диспатчер
         $Tags = Difra\Plugins\Tags::getInstance();
         if ($Tags->getCloudXml('posts', $this->root)) {
             $controlNode = $this->root->appendChild($this->xml->createElement('postsTags'));
             $controlNode->setAttribute('right', 1);
         }
     }
 }