Example #1
0
 /**
  * Создаёт новую группу.
  * Массив $data может содержать следующие ключи:
  * owner        id владельца (обязательно)
  * name                название группы
  * domain        имя поддомена группы
  * Поддерживается Additionals
  * @param array $data
  * @throws \Difra\Exception
  * @return Group
  */
 public static function create($data)
 {
     $db = Difra\MySQL::getInstance();
     $instance = new self();
     $query = 'INSERT INTO `groups`';
     if (!empty($data['name']) or !trim($data['name'])) {
         $instance->name = $db->escape(trim($data['name']));
     }
     $query .= " SET `name`='{$instance->name}'";
     if (!empty($data['domain']) or !trim($data['domain'])) {
         $instance->domain = $db->escape(trim($data['domain']));
     }
     $query .= ",`domain`='{$instance->domain}'";
     if (empty($data['owner']) or !$data['owner'] or !ctype_digit($data['owner']) or !intval($data['owner'])) {
         throw new Difra\Exception("Group::create() expects valid owner id");
     }
     $instance->owner = $db->escape($data['owner']);
     $query .= ",`owner`='{$instance->owner}'";
     if (true !== ($res = Difra\Additionals::checkAdditionals('groups', $data))) {
         return $res;
     }
     $db->query($query);
     if (!($instance->id = $db->getLastId())) {
         throw new \Difra\Exception("Group::create() failed to create a new group");
     }
     Difra\Additionals::saveAdditionals('groups', $instance->id, $data);
     return $instance;
 }
Example #2
0
 public function deletenotifyAjaxActionAuth(Param\AjaxString $id = null)
 {
     $id = $id ? $id->val() : null;
     if (!($post = Blogs\Post::getById($id))) {
         $this->ajax->display(Difra\Locales::getInstance()->getXPath('blogs/notifies/post_not_found'));
         die;
     }
     $Auth = \Difra\Auth::getInstance();
     if ($post->getUser() != $Auth->getEmail() && !$Auth->isModerator()) {
         $group = $post->getBlog()->getGroup();
         if (!$group or $group->getOwner() != \Difra\Auth::getInstance()->getEmail()) {
             $this->ajax->display(Difra\Locales::getInstance()->getXPath('blogs/notifies/edit_post_denied'));
             die;
         }
     }
     $nickname = \Difra\Additionals::getAdditionalValue('users', $post->getUser(), 'nickname');
     $this->ajax->display(Difra\Locales::getInstance()->getXPath('blogs/notifies/delete_post') . '<br/><br/><div href="#" onclick="blogs.delete( ' . intval($id) . ', \'' . $nickname . '\' );" class="button">Да</div>' . '<a href="#" style="display: inline-block; margin-left:15px;" class="button" onclick="ajaxer.close(this)">Нет</a>');
 }
Example #3
0
 private function sendMail()
 {
     $db = \Difra\MySQL::getInstance();
     // определяем кто владелец родительского элемента
     switch ($this->module) {
         case 'albums':
             $query = "SELECT a.`name` AS `title`, a.`link`, a.`group_id`, g.`domain`, g.`owner`\n\t\t\t\t\t\tFROM `albums` a\n\t\t\t\t\t\tLEFT JOIN `groups` AS `g` ON g.`id`=a.`group_id`\n\t\t\t\t\t\tWHERE a.`id`='" . $this->moduleId . "'";
             break;
         case 'catalog':
             // TODO: замутить отправку письма если это ответ на коммент юзера
             // XXX: есть ведь уже? //nap
             return;
         case 'blogs':
         default:
             $query = "SELECT b.`user`, g.`owner`, bp.`title`, g.`domain`, bp.`link`\n\t\t\t\t\tFROM `blogs_posts` bp\n\t\t\t\t\tLEFT JOIN `blogs` AS `b` ON b.`id`=bp.`blog`\n\t\t\t\t\tLEFT JOIN `groups` AS `g` ON g.`id`=b.`group`\n\t\t\t\t\tWHERE bp.`id`='" . $this->moduleId . "'";
             break;
     }
     $res = $db->fetchRow($query);
     if (empty($res)) {
         return;
     }
     if (isset($res['user']) && $res['user'] != '') {
         $elementOwner = $res['user'];
     } else {
         $elementOwner = $res['owner'];
     }
     // смотрим можно ли юзеру отправить email
     $userAdditionals = \Difra\Additionals::getAdditionals('users', $elementOwner);
     if (!isset($userAdditionals['unsubscribe']) || $userAdditionals['unsubscribe'] == 0) {
         // отправляем письмо владельцу родительского элемента
         $query = "SELECT `email`, `activation` FROM `users` WHERE `id`='" . intval($elementOwner) . "' AND `banned`=0 AND `active`=1";
         $replyText = [];
         if ($this->replyId) {
             // это ответ на чужой коммент.
             // забираем данные об ответе
             $query = "SELECT c.`text`, c.`user` FROM `" . $this->module . "_comments` c WHERE c.`id`='" . $this->replyId . "'";
             $replyText = $db->fetchRow($query);
             $query = "SELECT `email`, `activation` FROM `users` WHERE `id`='" . intval($replyText['user']) . "' AND `banned`=0 AND `active`=1";
         }
         $userData = $db->fetchRow($query);
         if (!empty($userData)) {
             // получаем никнейм отправителя:
             $replyUser = \Difra\Additionals::getAdditionalValue('users', $this->user, 'nickname');
             // ссылка на родительский элемент
             $elementLink = '';
             if ($this->module == 'albums') {
                 // если альбом
                 $elementLink = 'http://' . $res['domain'] . '.' . \Difra\Site::getInstance()->getMainhost() . '/album/' . rawurlencode($res['link']) . '/';
             } elseif ($this->module == 'blogs') {
                 if (isset($res['domain']) && $res['domain'] != '') {
                     // если пост в блоге группы
                     $elementLink = 'http://' . $res['domain'] . '.' . \Difra\Site::getInstance()->getMainhost() . '/' . $this->moduleId . '/' . rawurlencode($res['link']) . '/';
                 } else {
                     // если пост в личном блоге юзера
                     $ownerNickname = \Difra\Additionals::getAdditionalValue('users', $elementOwner, 'nickname');
                     $elementLink = 'http://' . \Difra\Site::getInstance()->getMainhost() . '/blogs/' . $ownerNickname . '/' . $this->moduleId . '/' . rawurlencode($res['link']) . '/';
                 }
             }
             $unsubscribeLink = 'http://' . \Difra\Site::getInstance()->getMainhost() . '/unsubscribe/' . $userData['activation'] . '/';
             $sendData = ['unsubscribe' => $unsubscribeLink, 'message' => $this->text, 'module' => $this->module, 'link' => $elementLink, 'reply_nickname' => $replyUser, 'mainHost' => \Difra\Site::getInstance()->getMainhost(), 'title' => $res['title']];
             if ($this->replyId) {
                 $sendData['replay'] = 1;
                 $sendData['original'] = $replyText['text'];
             }
             \Difra\Mailer::getInstance()->CreateMail($userData['email'], 'mail_newcomment', $sendData);
         }
     }
 }
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);
         }
     }
 }