Beispiel #1
0
 public function processCommentMailbox()
 {
     /*
      * Check enabled
      */
     $config = EasyBlogHelper::getConfig();
     $debug = JRequest::getBool('debug', false);
     if (!$config->get('main_comment_email')) {
         return;
     }
     $interval = (int) $config->get('main_remotepublishing_mailbox_run_interval');
     $nextrun = (int) $config->get('main_remotepublishing_mailbox_next_run');
     $nextrun = EasyBlogHelper::getDate($nextrun)->toUnix();
     $timenow = EasyBlogHelper::getDate()->toUnix();
     if ($nextrun !== 0 && $timenow < $nextrun) {
         if (!$debug) {
             echo 'time now: ' . EasyBlogHelper::getDate($timenow)->toMySQL() . "<br />\n";
             echo 'next email run: ' . EasyBlogHelper::getDate($nextrun)->toMySQL() . "<br />\n";
             return;
         }
     }
     $txOffset = EasyBlogDateHelper::getOffSet();
     $newnextrun = EasyBlogHelper::getDate('+ ' . $interval . ' minutes', $txOffset)->toUnix();
     // use $configTable to avoid variable name conflict
     $configTable = EasyBlogHelper::getTable('configs');
     $configTable->load('config');
     $parameters = new JParameter($configTable->params);
     $parameters->set('main_remotepublishing_mailbox_next_run', $newnextrun);
     $configTable->params = $parameters->toString('ini');
     $configTable->store();
     /*
      * Connect to mailbox
      */
     require_once JPATH_ROOT . DS . 'components' . DS . 'com_easyblog' . DS . 'classes' . DS . 'mailbox.php';
     $mailbox = new EasyblogMailbox();
     if (!$mailbox->connect()) {
         $mailbox->disconnect();
         echo 'Comment Mailbox: Could not connect to mailbox.';
         return false;
     }
     $total = 0;
     /*
      * Get data from mailbox
      */
     $total_mails = $mailbox->getMessageCount();
     if ($total_mails < 1) {
         // No mails in mailbox
         $mailbox->disconnect();
         echo 'Comment Mailbox: No emails found.';
         return false;
     }
     // Let's get the correct mails
     $messages = $mailbox->searchMessages('UNSEEN');
     if ($messages) {
         $prefix = '/\\[\\#(.*)\\]/is';
         $filter = JFilterInput::getInstance();
         $db = EasyBlogHelper::db();
         foreach ($messages as $messageSequence) {
             $info = $mailbox->getMessageInfo($messageSequence);
             $from = $info->fromemail;
             $senderName = $info->from[0]->personal;
             $subject = $filter->clean($info->subject);
             // @rule: Detect if this is actually a reply.
             preg_match('/\\[\\#(.*)\\]/is', $subject, $matches);
             // If the title doesn't match the comment specific title, just continue the block.
             if (empty($matches)) {
                 continue;
             }
             $query = 'SELECT ' . $db->nameQuote('id') . ' FROM ' . $db->nameQuote('#__users') . ' ' . 'WHERE ' . $db->nameQuote('email') . '=' . $db->Quote($from);
             $db->setQuery($query);
             $userId = $db->loadResult();
             $commentId = $matches[1];
             $refComment = EasyBlogHelper::getTable('Comment');
             $refComment->load($commentId);
             // Get the message contents.
             $message = new EasyblogMailboxMessage($mailbox->stream, $messageSequence);
             $message->getMessage();
             $content = $message->getPlain();
             // If guest commenting is not allowed, and user's email does not exist in system, pass this.
             if (!$config->get('main_allowguestcomment') && !$userId) {
                 continue;
             }
             // Apply akismet filtering
             if ($config->get('comment_akismet')) {
                 $data = array('author' => $senderName, 'email' => $from, 'website' => JURI::root(), 'body' => $content, 'permalink' => EasyBlogRouter::_('index.php?option=com_easyblog&view=entry&id=' . $refComment->post_id));
                 if (EasyBlogHelper::getHelper('Akismet')->isSpam($data)) {
                     continue;
                 }
             }
             $model = EasyBlogHelper::getModel('Comment');
             $comment = EasyBlogHelper::getTable('Comment');
             $comment->name = $senderName;
             $comment->email = $from;
             $comment->comment = $content;
             $comment->post_id = $refComment->post_id;
             $date = EasyBlogHelper::getDate();
             $comment->created = $date->toMySQL();
             $comment->modified = $date->toMySQL();
             $comment->published = 1;
             if ($userId) {
                 $comment->created_by = $userId;
             }
             $comment->sent = 0;
             $isModerated = false;
             // Update publish status if the comment requires moderation
             if ($config->get('comment_moderatecomment') == 1 || !$userId && $config->get('comment_moderateguestcomment') == 1) {
                 $comment->set('published', EBLOG_COMMENT_STATUS_MODERATED);
                 $isModerated = true;
             }
             $blog = EasyBlogHelper::getTable('Blog');
             $blog->load($comment->post_id);
             // If moderation for author is disabled, ensure that the comment is published.
             // If the author is the owner of the blog, it should never be moderated.
             if (!$config->get('comment_moderateauthorcomment') && $blog->created_by == $userId) {
                 $comment->set('published', 1);
                 $isModerated = false;
             }
             if (!$comment->store()) {
                 echo 'Error storing comment: ' . $comment->getError();
                 return;
             }
             echo '* Added comment for post <strong>' . $blog->title . '</strong><br />';
             // @rule: Process notifications
             $comment->processEmails($isModerated, $blog);
             // Update the sent flag
             $comment->updateSent();
             $total++;
         }
     }
     /*
      * Disconnect from mailbox
      */
     $mailbox->disconnect();
     /*
      * Generate report
      */
     echo JText::sprintf('Comment Mailbox: %1s comments fetched from mailbox: ' . $config->get('main_remotepublishing_mailbox_remotesystemname') . '.', $total);
 }
Beispiel #2
0
 /**
  * Extract parts of a message
  *
  * @since	4.0
  * @access	public
  * @param	string
  * @return
  */
 private function extractPart($part, $data)
 {
     switch ($part->encoding) {
         case '3':
             // base 64
             $data = base64_decode($data);
             break;
         case '4':
             // quoted-printable
             $data = quoted_printable_decode($data);
             break;
         case '5':
             // other
         // other
         case '0':
             // 7bit
         // 7bit
         case '1':
             // 8 bit
         // 8 bit
         case '2':
             // binary
         // binary
         default:
             break;
     }
     // Get the params
     $params = EasyBlogMailboxMessage::getformatedParams($part);
     $encoding = 'UTF-8';
     if (isset($params['charset'])) {
         $encoding = $params['charset'];
     }
     $type = $part->type;
     $subtype = strtolower($part->subtype);
     // Get the part id
     $id = isset($part->id) ? $part->id : '';
     // Plain text messages
     if ($type == 0 && $subtype == 'plain') {
         $this->plain_data .= EasyblogMailboxMessage::stringToUTF8($encoding, trim($data));
     }
     // Html messages
     if ($type == 0 && $subtype == 'html') {
         $this->html_data .= EasyblogMailboxMessage::stringToUTF8($encoding, trim($data));
     }
     // What type is this?
     if ($type == 2) {
         $this->plain_data .= EasyblogMailboxMessage::stringToUTF8($encoding, trim($data));
     }
     // PDF files
     if ($type == 3 && $subtype == 'pdf') {
         $file = array();
         $file['mime'] = $subtype;
         $file['data'] = $data;
         $file['name'] = isset($params['name']) ? $params['name'] : $params['filename'];
         $file['id'] = $id;
         $file['size'] = $part->bytes;
         $this->attachment[] = $file;
     }
     // Image parts
     if ($type == 5) {
         $image = array();
         $image['mime'] = $subtype;
         // GIF
         $image['data'] = $data;
         // binary
         $image['name'] = isset($params['name']) ? $params['name'] : $params['filename'];
         // 35D.gif
         $image['id'] = $id;
         // <*****@*****.**>
         $image['size'] = $part->bytes;
         $this->attachment[] = $image;
     }
     return;
 }