示例#1
0
 function process()
 {
     $view = new EasyDiscussView();
     $date = DiscussHelper::getDate();
     $now = $date->toMySQL();
     $modelSubscribe = $view->getModel('Subscribe');
     $subscribers = $modelSubscribe->getSiteSubscribers($this->interval, $now);
     $total = count($subscribers);
     if (empty($total)) {
         return false;
     }
     foreach ($subscribers as $subscriber) {
         $notify = DiscussHelper::getNotification();
         $data = array();
         $rows = $modelSubscribe->getCreatedPostByInterval($subscriber->sent_out, $now);
         $posts = array();
         if ($rows) {
             foreach ($rows as $row) {
                 $row['categorylink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=categorie&layout=listings&category_id=' . $row['category_id'], false, true);
                 $row['link'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $row['id'], false, true);
                 $row['userlink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=profile&id=' . $row['user_id'], false, true);
                 $category = DiscussHelper::getTable('Category');
                 $creator = DiscussHelper::getTable('Profile');
                 $category->load($row['category_id']);
                 $creator->load($row['user_id']);
                 $row['category'] = $category->getTitle();
                 $row['avatar'] = $creator->getAvatar();
                 $row['name'] = $creator->getName();
                 $row['date'] = DiscussDateHelper::toFormat($row['created'], '%b %e, %Y');
                 $row['message'] = DiscussHelper::parseContent($row['content']);
                 $posts[] = $row;
             }
         }
         $data['post'] = $posts;
         $data['total'] = count($data['post']);
         $data['unsubscribeLink'] = DiscussHelper::getUnsubscribeLink($subscriber, true, true);
         $subject = $date->toMySQL();
         switch (strtoupper($this->interval)) {
             case 'DAILY':
                 $subject = $date->toFormat('%F');
                 $data['interval'] = JText::_('today');
                 break;
             case 'WEEKLY':
                 $subject = $date->toFormat('%V');
                 $data['interval'] = JText::_('this week');
                 break;
             case 'MONTHLY':
                 $subject = $date->toFormat('%B');
                 $data['interval'] = JText::_('this month');
                 break;
         }
         if (!empty($data['post'])) {
             $notify->addQueue($subscriber->email, JText::sprintf('COM_EASYDISCUSS_YOUR_' . $this->interval . '_SUBSCRIPTION', $subject), '', 'email.subscription.site.interval.php', $data);
         }
         $subscribe = DiscussHelper::getTable('Subscribe');
         $subscribe->load($subscriber->id);
         $subscribe->sent_out = $now;
         $subscribe->store();
     }
 }
示例#2
0
 /**
  * $post - post jtable object
  * $parent - post's parent id.
  * $isNew - indicate this is a new post or not.
  */
 public static function sendNotification($post, $parent = 0, $isNew, $postOwner, $prevPostStatus)
 {
     JFactory::getLanguage()->load('com_easydiscuss', JPATH_ROOT);
     $config = DiscussHelper::getConfig();
     $notify = DiscussHelper::getNotification();
     $emailPostTitle = $post->title;
     $modelSubscribe = self::getModel('Subscribe');
     //get all admin emails
     $adminEmails = array();
     $ownerEmails = array();
     $newPostOwnerEmails = array();
     $postSubscriberEmails = array();
     $participantEmails = array();
     $catSubscriberEmails = array();
     if (empty($parent)) {
         // only new post we notify admin.
         if ($config->get('notify_admin')) {
             $admins = $notify->getAdminEmails();
             if (!empty($admins)) {
                 foreach ($admins as $admin) {
                     $adminEmails[] = $admin->email;
                 }
             }
         }
         // notify post owner too when moderate is on
         if (!empty($postOwner)) {
             $postUser = JFactory::getUser($postOwner);
             $newPostOwnerEmails[] = $postUser->email;
         } else {
             $newPostOwnerEmails[] = $post->poster_email;
         }
     } else {
         // if this is a new reply, notify post owner.
         $parentTable = DiscussHelper::getTable('Post');
         $parentTable->load($parent);
         $emailPostTitle = $parentTable->title;
         $oriPostAuthor = $parentTable->user_id;
         if (!$parentTable->user_id) {
             $ownerEmails[] = $parentTable->poster_email;
         } else {
             $oriPostUser = JFactory::getUser($oriPostAuthor);
             $ownerEmails[] = $oriPostUser->email;
         }
     }
     $emailSubject = empty($parent) ? JText::sprintf('COM_EASYDISCUSS_NEW_POST_ADDED', $post->id, $emailPostTitle) : JText::sprintf('COM_EASYDISCUSS_NEW_REPLY_ADDED', $parent, $emailPostTitle);
     $emailTemplate = empty($parent) ? 'email.subscription.site.new.php' : 'email.post.reply.new.php';
     //get all site's subscribers email that want to receive notification immediately
     $subscriberEmails = array();
     $subscribers = array();
     // @rule: Specify the default name and avatar
     $authorName = $post->poster_name;
     $authorAvatar = DISCUSS_JURIROOT . '/media/com_easydiscuss/images/default.png';
     // @rule: Only process author items that belongs to a valid user.
     if (!empty($postOwner)) {
         $profile = DiscussHelper::getTable('Profile');
         $profile->load($postOwner);
         $authorName = $profile->getName();
         $authorAvatar = $profile->getAvatar();
     }
     if ($config->get('main_sitesubscription') && ($isNew || $prevPostStatus == DISCUSS_ID_PENDING)) {
         //$modelSubscribe		= self::getModel( 'Subscribe' );
         $subscribers = $modelSubscribe->getSiteSubscribers('instant', '', $post->category_id);
         $postSubscribers = $modelSubscribe->getPostSubscribers($post->parent_id);
         // This was added because the user allow site wide notification (as in all subscribers should get notified) but category subscribers did not get it.
         $catSubscribers = $modelSubscribe->getCategorySubscribers($post->id);
         if (!empty($subscribers)) {
             foreach ($subscribers as $subscriber) {
                 $subscriberEmails[] = $subscriber->email;
             }
         }
         if (!empty($postSubscribers)) {
             foreach ($postSubscribers as $postSubscriber) {
                 $postSubscriberEmails[] = $postSubscriber->email;
             }
         }
         if (!empty($catSubscribers)) {
             foreach ($catSubscribers as $catSubscriber) {
                 $catSubscriberEmails[] = $catSubscriber->email;
             }
         }
     }
     // Notify Participants if this is a reply
     if (!empty($parent) && $config->get('notify_participants') && ($isNew || $prevPostStatus == DISCUSS_ID_PENDING)) {
         $participantEmails = DiscussHelper::getHelper('Mailer')->_getParticipants($post->parent_id);
         $participantEmails = array_unique($participantEmails);
         // merge into owneremails. dirty hacks.
         if (count($participantEmails) > 0) {
             $newPostOwnerEmails = array_merge($newPostOwnerEmails, $participantEmails);
         }
     }
     if (!empty($adminEmails) || !empty($subscriberEmails) || !empty($newPostOwnerEmails) || !empty($postSubscriberEmails) || $config->get('notify_all')) {
         $emails = array_unique(array_merge($adminEmails, $subscriberEmails, $newPostOwnerEmails, $postSubscriberEmails, $catSubscriberEmails));
         // prepare email content and information.
         $emailData = array();
         $emailData['postTitle'] = $emailPostTitle;
         $emailData['postAuthor'] = $authorName;
         $emailData['postAuthorAvatar'] = $authorAvatar;
         $emailData['replyAuthor'] = $authorName;
         $emailData['replyAuthorAvatar'] = $authorAvatar;
         $emailData['comment'] = $post->content;
         $emailData['postContent'] = $post->trimEmail($post->content);
         $emailData['replyContent'] = $post->trimEmail($post->content);
         $attachments = $post->getAttachments();
         $emailData['attachments'] = $attachments;
         // get the correct post id in url, the parent post id should take precedence
         $postId = empty($parent) ? $post->id : $parentTable->id;
         $emailData['postLink'] = DiscussRouter::getRoutedURL('index.php?option=com_easydiscuss&view=post&id=' . $postId, false, true);
         if ($config->get('notify_all') && $post->published == DISCUSS_ID_PUBLISHED) {
             $emailData['emailTemplate'] = 'email.subscription.site.new.php';
             $emailData['emailSubject'] = JText::sprintf('COM_EASYDISCUSS_NEW_QUESTION_ASKED', $post->id, $post->title);
             DiscussHelper::getHelper('Mailer')->notifyAllMembers($emailData, $newPostOwnerEmails);
         } else {
             //insert into mailqueue
             foreach ($emails as $email) {
                 if (in_array($email, $subscriberEmails) || in_array($email, $postSubscriberEmails) || in_array($email, $newPostOwnerEmails)) {
                     $doContinue = false;
                     // these are subscribers
                     if (!empty($subscribers)) {
                         foreach ($subscribers as $key => $value) {
                             if ($value->email == $email) {
                                 $emailData['unsubscribeLink'] = DiscussHelper::getUnsubscribeLink($subscribers[$key], true, true);
                                 $notify->addQueue($email, $emailSubject, '', $emailTemplate, $emailData);
                                 $doContinue = true;
                                 break;
                             }
                         }
                     }
                     if ($doContinue) {
                         continue;
                     }
                     if (!empty($postSubscribers)) {
                         foreach ($postSubscribers as $key => $value) {
                             if ($value->email == $email) {
                                 $emailData['unsubscribeLink'] = DiscussHelper::getUnsubscribeLink($postSubscribers[$key], true, true);
                                 $notify->addQueue($email, $emailSubject, '', $emailTemplate, $emailData);
                                 $doContinue = true;
                                 break;
                             }
                         }
                     }
                     if ($doContinue) {
                         continue;
                     }
                     if (!empty($newPostOwnerEmails)) {
                         $emailSubject = JText::sprintf('COM_EASYDISCUSS_NEW_POST_ADDED', $emailPostTitle, $post->id);
                         foreach ($newPostOwnerEmails as $ownerEmail) {
                             //$emailData['unsubscribeLink']	= DiscussHelper::getUnsubscribeLink( $ownerEmail, true, true);
                             $notify->addQueue($email, $emailSubject, '', $emailTemplate, $emailData);
                             $doContinue = true;
                             break;
                         }
                     }
                 } else {
                     // non-subscribers will not get the unsubscribe link
                     $notify->addQueue($email, $emailSubject, '', $emailTemplate, $emailData);
                 }
             }
         }
     }
 }