Exemple #1
0
 /**
  * Отправляет уведомления о новых комментариях в сообществе.
  * 
  * @param   string|array   $message_ids  идентификаторы комментариев.
  * @param   resource       $connect      соединение к БД (необходимо в PgQ) или NULL -- создать новое.
  * @return  integer                      количество отправленных уведомлений.
  */
 function CommuneDeleteComment($message_ids, $connect = NULL)
 {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/classes/commune.php';
     require_once $_SERVER['DOCUMENT_ROOT'] . "/classes/messages.php";
     $commune = new commune();
     if (!($comments = $commune->GetComments4Sending($message_ids, $connect))) {
         $subscr = $commune->getThemeSubscribers(implode(',', $message_ids));
         $this->CommuneDeleteTopic($subscr, is_array($message_ids) ? $message_ids[0] : $message_ids);
         return NULL;
     }
     $top_ids = array();
     foreach ($comments as $cm) {
         $top_ids[] = $cm['top_id'];
     }
     $subscribers = array();
     if (count($top_ids)) {
         $top_ids = array_unique($top_ids);
         $subscr = $commune->getThemeSubscribers(implode(',', $top_ids));
         foreach ($subscr as $row) {
             $subscribers[$row['message_id']][] = $row;
         }
     }
     foreach ($comments as $comment) {
         $this->subject = 'Комментарий в сообществе «' . $comment['commune_name'] . '» удален';
         $skip_users = array();
         $skip_users[] = $comment['user_id'];
         $userlink = $GLOBALS["host"] . "/users/" . $comment['login'];
         if ($comment['commune_id'] == commune::COMMUNE_BLOGS_ID && $comment['p_user_id'] != $comment['user_id']) {
             $admin_user = "******";
         } else {
             $admin_user = "******";
         }
         $body_start = "\n{$admin_user} удалил(а) <a href=\"{$GLOBALS['host']}/commune/?id={$comment['commune_id']}&site=Topic&post={$comment['top_id']}.{$comment['id']}{$this->_addUrlParams('b', '&')}#c_{$comment['id']}\">комментарий</a> к вашему сообщению/комментарию в сообществе «<a href=\"{$GLOBALS['host']}/commune/?id={$comment['commune_id']}{$this->_addUrlParams('b', '&')}\" target=\"_blank\">{$comment['commune_name']}</a>».\n<br/><br/>\n--------\n";
         $body_subscr = "{$admin_user} удалил(а) <a href=\"{$GLOBALS['host']}/commune/?id={$comment['commune_id']}&site=Topic&post={$comment['top_id']}.{$comment['id']}{$this->_addUrlParams('b', '&')}#c_{$comment['id']}\">комментарий</a> к сообщению/комментарию.\n<br/><br/>\n--------\n";
         $body = "<br/>" . reformat2($comment['title'], 100) . "\n<br/>" . reformat2($comment['msgtext'], 100, 0, 1) . "\n<br/><br/>\n--------\n";
         $p_body = "<br/>" . reformat2($comment['title'], 100) . "\n<br/>" . str_replace(array("\r", "\n", "<br>", "<br/>"), array("__NEWLINE__", "__NEWLINE__", "__NEWLINE__", "__NEWLINE__"), $comment['msgtext']) . "\n--------";
         $p_body = str_replace("__NEWLINE__", "<br/>", $p_body);
         $p_body = str_replace("<br/>", "\n", "\n--------\n" . $p_body);
         if ($comment['p_user_id'] != $comment['user_id'] && $comment['p_email'] && substr($comment['p_subscr'], 5, 1) == '1' && $comment['p_banned'] == '0') {
             // отправляем родителю.
             $this->recipient = $comment['p_uname'] . " " . $comment['p_usurname'] . " [" . $comment['p_login'] . "] <" . $comment['p_email'] . ">";
             $this->message = $this->GetHtml($comment['p_uname'], $body_start . $body, array('header' => 'default', 'footer' => 'default'), array('login' => $comment['p_login']));
             $this->SmtpMail('text/html');
             $skip_users[] = $comment['p_user_id'];
         }
         if ($comment['t_user_id'] != $comment['user_id'] && $comment['t_user_id'] != $comment['p_user_id'] && $comment['t_email'] && substr($comment['t_subscr'], 5, 1) == '1' && $comment['t_banned'] == '0') {
             // отправляем автору топика.
             $this->recipient = $comment['t_uname'] . " " . $comment['t_usurname'] . " [" . $comment['t_login'] . "] <" . $comment['t_email'] . ">";
             $this->message = $this->GetHtml($comment['t_uname'], $body_start . $body, array('header' => 'default', 'footer' => 'default'), array('login' => $comment['t_login']));
             $this->SmtpMail('text/html');
             $skip_users[] = $comment['t_user_id'];
         }
         if (isset($subscribers[$comment['top_id']])) {
             // отправка всем подписчикам топика
             foreach ($subscribers[$comment['top_id']] as $user) {
                 // кроме родителя и автора
                 if (in_array($user['user_id'], $skip_users)) {
                     continue;
                 }
                 $link_commune = "<a href='{$GLOBALS['host']}/commune/?id={$comment['commune_id']}' target='_blank'>{$comment['commune_name']}</a>";
                 $this->recipient = $user['uname'] . " " . $user['usurname'] . " [" . $user['login'] . "] <" . $user['email'] . ">";
                 $this->message = $this->GetHtml($user['uname'], $body_subscr . $body, array('header' => 'subscribe', 'footer' => 'subscribe'), array('type' => 0, 'title' => $link_commune, 'login' => $user['login']));
                 $this->SmtpMail('text/html');
             }
         }
     }
     return $this->sended;
 }