예제 #1
0
 /**
  * Send email notifications from the message.
  *
  * @param null|string $url
  *
  * @return bool|null
  */
 public function sendNotification($url = null)
 {
     $config = KunenaFactory::getConfig();
     if (!$config->get('send_emails')) {
         return null;
     }
     if ($this->hold > 1) {
         return null;
     } elseif ($this->hold == 1) {
         $mailsubs = 0;
         $mailmods = $config->mailmod >= 0;
         $mailadmins = $config->mailadmin >= 0;
     } else {
         $mailsubs = (bool) $config->allowsubscriptions;
         $mailmods = $config->mailmod >= 1;
         $mailadmins = $config->mailadmin >= 1;
     }
     $once = false;
     if ($mailsubs) {
         if (!$this->parent) {
             // New topic: Send email only to category subscribers
             $mailsubs = $config->category_subscriptions != 'disabled' ? KunenaAccess::CATEGORY_SUBSCRIPTION : 0;
             $once = $config->category_subscriptions == 'topic';
         } elseif ($config->category_subscriptions != 'post') {
             // Existing topic: Send email only to topic subscribers
             $mailsubs = $config->topic_subscriptions != 'disabled' ? KunenaAccess::TOPIC_SUBSCRIPTION : 0;
             $once = $config->topic_subscriptions == 'first';
         } else {
             // Existing topic: Send email to both category and topic subscribers
             $mailsubs = $config->topic_subscriptions == 'disabled' ? KunenaAccess::CATEGORY_SUBSCRIPTION : KunenaAccess::CATEGORY_SUBSCRIPTION | KunenaAccess::TOPIC_SUBSCRIPTION;
             // FIXME: category subscription can override topic
             $once = $config->topic_subscriptions == 'first';
         }
     }
     if (!$url) {
         $url = JUri::getInstance()->toString(array('scheme', 'host', 'port')) . $this->getPermaUrl();
     }
     // Get all subscribers, moderators and admins who should get the email.
     $emailToList = KunenaAccess::getInstance()->getSubscribers($this->catid, $this->thread, $mailsubs, $mailmods, $mailadmins, KunenaUserHelper::getMyself()->userid);
     if ($emailToList) {
         if (!$config->getEmail()) {
             KunenaError::warning(JText::_('COM_KUNENA_EMAIL_DISABLED'));
             return false;
         } elseif (!JMailHelper::isEmailAddress($config->getEmail())) {
             KunenaError::warning(JText::_('COM_KUNENA_EMAIL_INVALID'));
             return false;
         }
         $topic = $this->getTopic();
         // Make a list from all receivers; split the receivers into two distinct groups.
         $sentusers = array();
         $receivers = array(0 => array(), 1 => array());
         foreach ($emailToList as $emailTo) {
             if (!$emailTo->email || !JMailHelper::isEmailAddress($emailTo->email)) {
                 continue;
             }
             $receivers[$emailTo->subscription][] = $emailTo->email;
             $sentusers[] = $emailTo->id;
         }
         $mailsender = JMailHelper::cleanAddress($config->board_title);
         $mailsubject = JMailHelper::cleanSubject($config->board_title . ' ' . $topic->subject . " (" . $this->getCategory()->name . ")");
         $subject = $this->subject ? $this->subject : $topic->subject;
         // Create email.
         $mail = JFactory::getMailer();
         $mail->setSubject($mailsubject);
         $mail->setSender(array($config->getEmail(), $mailsender));
         // Send email to all subscribers.
         if (!empty($receivers[1])) {
             $this->attachEmailBody($mail, 1, $subject, $url, $once);
             KunenaEmail::send($mail, $receivers[1]);
         }
         // Send email to all moderators.
         if (!empty($receivers[0])) {
             $this->attachEmailBody($mail, 0, $subject, $url, $once);
             KunenaEmail::send($mail, $receivers[0]);
         }
         // Update subscriptions.
         if ($once && $sentusers) {
             $sentusers = implode(',', $sentusers);
             $db = JFactory::getDbo();
             $query = $db->getQuery(true)->update('#__kunena_user_topics')->set('subscribed=2')->where("topic_id={$this->thread}")->where("user_id IN ({$sentusers})")->where('subscribed=1');
             $db->setQuery($query);
             $db->execute();
             KunenaError::checkDatabaseError();
         }
     }
     return true;
 }
예제 #2
0
 function report()
 {
     if (!JSession::checkToken('post')) {
         $this->app->enqueueMessage(JText::_('COM_KUNENA_ERROR_TOKEN'), 'error');
         $this->setRedirectBack();
         return;
     }
     if (!$this->me->exists() || $this->config->reportmsg == 0) {
         // Deny access if report feature has been disabled or user is guest
         $this->app->enqueueMessage(JText::_('COM_KUNENA_NO_ACCESS'), 'notice');
         $this->setRedirectBack();
         return;
     }
     if (!$this->config->get('send_emails')) {
         // Emails have been disabled
         $this->app->enqueueMessage(JText::_('COM_KUNENA_EMAIL_DISABLED'), 'notice');
         $this->setRedirectBack();
         return;
     }
     if (!$this->config->getEmail() || !JMailHelper::isEmailAddress($this->config->getEmail())) {
         // Error: email address is invalid
         $this->app->enqueueMessage(JText::_('COM_KUNENA_EMAIL_INVALID'), 'error');
         $this->setRedirectBack();
         return;
     }
     // Get target object for the report
     if ($this->mesid) {
         $message = $target = KunenaForumMessageHelper::get($this->mesid);
         $topic = $target->getTopic();
     } else {
         $topic = $target = KunenaForumTopicHelper::get($this->id);
         $message = KunenaForumMessageHelper::get($topic->first_post_id);
     }
     $messagetext = $message->message;
     $baduser = KunenaFactory::getUser($message->userid);
     if (!$target->authorise('read')) {
         // Deny access if user cannot read target
         $this->app->enqueueMessage($target->getError(), 'notice');
         $this->setRedirectBack();
         return;
     }
     $reason = JRequest::getString('reason');
     $text = JRequest::getString('text');
     $template = KunenaTemplate::getInstance();
     if (method_exists($template, 'reportMessage')) {
         $template->reportMessage($message, $reason, $text);
     }
     // Load language file from the template.
     KunenaFactory::getTemplate()->loadLanguage();
     if (empty($reason) && empty($text)) {
         // Do nothing: empty subject or reason is empty
         $this->app->enqueueMessage(JText::_('COM_KUNENA_REPORT_FORG0T_SUB_MES'));
         $this->setRedirectBack();
         return;
     } else {
         $acl = KunenaAccess::getInstance();
         $emailToList = $acl->getSubscribers($topic->category_id, $topic->id, false, true, false);
         if (!empty($emailToList)) {
             $mailsender = JMailHelper::cleanAddress($this->config->board_title . ' ' . JText::_('COM_KUNENA_FORUM') . ': ' . $this->me->getName());
             $mailsubject = "[" . $this->config->board_title . " " . JText::_('COM_KUNENA_FORUM') . "] " . JText::_('COM_KUNENA_REPORT_MSG') . ": ";
             if ($reason) {
                 $mailsubject .= $reason;
             } else {
                 $mailsubject .= $topic->subject;
             }
             jimport('joomla.environment.uri');
             $msglink = JUri::getInstance()->toString(array('scheme', 'host', 'port')) . $target->getPermaUrl(null, false);
             $mail = JFactory::getMailer();
             $mail->setSender(array($this->me->username, $this->me->email));
             $mail->setSubject($mailsubject);
             // Render the email.
             $layout = KunenaLayout::factory('Email/Report')->debug(false)->set('mail', $mail)->set('message', $message)->set('me', $this->me)->set('title', $reason)->set('content', $text)->set('messageLink', $msglink);
             try {
                 $body = trim($layout->render());
                 $mail->setBody($body);
             } catch (Exception $e) {
                 // TODO: Deprecated in K4.0, remove in K5.0
                 $mailmessage = "" . JText::_('COM_KUNENA_REPORT_RSENDER') . " {$this->me->username} ({$this->me->name})";
                 $mailmessage .= "\n";
                 $mailmessage .= "" . JText::_('COM_KUNENA_REPORT_RREASON') . " " . $reason;
                 $mailmessage .= "\n";
                 $mailmessage .= "" . JText::_('COM_KUNENA_REPORT_RMESSAGE') . " " . $text;
                 $mailmessage .= "\n\n";
                 $mailmessage .= "" . JText::_('COM_KUNENA_REPORT_POST_POSTER') . " {$baduser->username} ({$baduser->name})";
                 $mailmessage .= "\n";
                 $mailmessage .= "" . JText::_('COM_KUNENA_REPORT_POST_SUBJECT') . ": " . $topic->subject;
                 $mailmessage .= "\n";
                 $mailmessage .= "" . JText::_('COM_KUNENA_REPORT_POST_MESSAGE') . "\n-----\n" . KunenaHtmlParser::stripBBCode($messagetext, 0, false);
                 $mailmessage .= "\n-----\n\n";
                 $mailmessage .= "" . JText::_('COM_KUNENA_REPORT_POST_LINK') . " " . $msglink;
                 $mailmessage = JMailHelper::cleanBody(strtr($mailmessage, array(' ' => '')));
                 $mail->setBody($mailmessage);
             }
             $receivers = array();
             foreach ($emailToList as $emailTo) {
                 if (!$emailTo->email || !JMailHelper::isEmailAddress($emailTo->email)) {
                     continue;
                 }
                 $receivers[] = $emailTo->email;
             }
             KunenaEmail::send($mail, $receivers);
             $this->app->enqueueMessage(JText::_('COM_KUNENA_REPORT_SUCCESS'));
         } else {
             $this->app->enqueueMessage(JText::_('COM_KUNENA_REPORT_NOT_SEND'));
         }
     }
     $this->setRedirect($target->getUrl($this->return, false));
 }