Beispiel #1
0
 public function addAjaxActionAuth(\Difra\Param\AjaxString $module, \Difra\Param\AjaxInt $moduleId, \Difra\Param\AjaxInt $replyId, \Difra\Param\AjaxString $text)
 {
     $commentArray = ['module' => $module->val(), 'moduleId' => intval($moduleId->val()), 'replyId' => intval($replyId->val()), 'text' => $text->val()];
     Comments::getInstance()->add($commentArray);
     //$this->ajax->notify( $moduleId->val() );
     $this->ajax->refresh();
 }
Beispiel #2
0
 public function lastAction()
 {
     $commentsRootNode = $this->root->appendChild($this->xml->createElement('last-comments'));
     $commentsNode = $commentsRootNode->appendChild($this->xml->createElement('comments'));
     \Difra\Plugins\Comments::getInstance()->getAllCommentsXML($commentsNode);
 }
Beispiel #3
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);
         }
     }
 }