Пример #1
0
 public function indexAction(\Difra\Param\AnyString $link = null)
 {
     if (!is_null($link)) {
         // страница анонса события
         $this->eventRoot = $this->root->appendChild($this->xml->createElement('announcements-event-view'));
         $this->eventRoot->setAttribute('view', true);
         $this->_showEvent(rawurldecode($link->val()));
     } else {
         if (\Difra\Plugger::isEnabled('Blogs')) {
             $Group = \Difra\Plugins\Blogs\Group::current();
             if ($Group) {
                 // страница анонсов группы
                 $this->eventRoot = $this->root->appendChild($this->xml->createElement('groupEvents'));
                 $groupId = $Group->getId();
                 $this->_showGroupEvents($groupId);
             } else {
                 throw new \Difra\View\HttpError(404);
                 return;
             }
         } else {
             // общая страница анонсов
             $this->eventRoot = $this->root->appendChild($this->xml->createElement('allEvents'));
             $this->_showByPriority();
         }
     }
 }
Пример #2
0
 /**
  * Создаёт пост (или несколько) из результатов выборки из базы
  * @static
  * @param array $data
  * @return array|null
  */
 public static function makeList($data)
 {
     // нет данных
     if (empty($data) or !is_array($data)) {
         return null;
     }
     // в $data один пост
     if (isset($data['id'])) {
         $data = [$data];
     }
     $groups = [];
     $Auth = Auth::getInstance();
     if ($userId = $Auth->getEmail()) {
         $groups = Group::getOwnedGroupsIds($userId);
     }
     $posts = [];
     foreach ($data as $row) {
         $post = new self();
         foreach ($row as $k => $v) {
             if (property_exists($post, $k)) {
                 $post->{$k} = $v;
             }
         }
         if ($userId and $post->getUser() == $userId || $Auth->isModerator()) {
             $post->canModify = true;
         } elseif ($userId and $post->groupId and in_array($post->groupId, $groups)) {
             $post->canModify = true;
         } else {
             $post->canModify = false;
         }
         $posts[] = $post;
     }
     return $posts;
 }
Пример #3
0
 public function editAction(\Difra\Param\AnyInt $id)
 {
     $editNode = $this->root->appendChild($this->xml->createElement('announcementsEdit'));
     \Difra\Plugins\Announcements::getInstance()->getByIdXML($id->val(), $editNode);
     if (\Difra\Plugger::getInstance()->isEnabled('blogs')) {
         \Difra\Plugins\Blogs\Group::getNewGroupsXml($editNode, 0, false);
     }
 }
Пример #4
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'));
     }
 }
Пример #5
0
 public function editAction(\Difra\Param\AnyInt $id)
 {
     $editNode = $this->root->appendChild($this->xml->createElement('announcementsEdit'));
     \Difra\Plugins\Announcements::getInstance()->getByIdXML($id->val(), $editNode);
     $additionalsFieldsNode = $editNode->appendChild($this->xml->createElement('additionalsFields'));
     $categoryNode = $editNode->appendChild($this->xml->createElement('announceCateroty'));
     \Difra\Plugins\Announcements\Additionals::getListXML($additionalsFieldsNode);
     \Difra\Plugins\Announcements\Category::getList($categoryNode);
     $locationsNode = $editNode->appendChild($this->xml->createElement('locations'));
     \Difra\Plugins\Announcements::getInstance()->getLocationsXML($locationsNode);
     if (\Difra\Plugger::isEnabled('blogs')) {
         \Difra\Plugins\Blogs\Group::getNewGroupsXml($editNode, 0, false);
     }
 }
Пример #6
0
 public static function checkDeleteRights($id, $module)
 {
     $db = \Difra\MySQL::getInstance();
     $parentOwner = false;
     switch ($module) {
         case 'blogs':
             $query = "SELECT bl.`user`, bl.`group`\n\t\t\t\t\t\tFROM `blogs_posts` bp\n\t\t\t\t\t\tRIGHT JOIN `blogs` AS `bl` ON bl.`id`=bp.`blog`\n\t\t\t\t\t\tWHERE bp.`id`='" . intval($id) . "'";
             break;
         case 'albums':
             $query = "SELECT al.`group_id` as `group`\n\t\t\t\t\t\tFROM `albums` al\n\t\t\t\t\t\tWHERE al.`id` = '" . intval($id) . "'";
             break;
         default:
             $query = false;
     }
     if ($query) {
         $parentOwner = $db->fetchRow($query);
     }
     $groups = [];
     $Auth = \Difra\Auth::getInstance();
     $userId = $Auth->getEmail();
     if ($userId && \Difra\Plugger::getInstance()->isEnabled('blogs')) {
         $groups = \Difra\Plugins\Blogs\Group::getOwnedGroupsIds($userId);
     }
     $commentData = $db->fetchRow("SELECT `user` FROM `{$module}_comments` WHERE `id`='" . intval($id) . "'");
     if ($userId && ($userId == $commentData['user'] || $Auth->isModerator())) {
         return true;
     } elseif ($userId && $parentOwner && in_array($parentOwner['group'], $groups)) {
         return true;
     } elseif ($userId && $parentOwner && isset($parentOwner['user']) && $parentOwner['user'] == $userId) {
         return true;
     }
     return false;
 }
Пример #7
0
 public function getGroup()
 {
     return Group::getById($this->group);
 }
Пример #8
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);
         }
     }
 }