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); } } }