public function collectNews($page = 1, $limit = 20, &$errors) { $objects = array(); $categories = $this->em->getRepository('SymbbCoreNewsBundle:Category')->findAll(); /** * @var $categories Category[] */ foreach ($categories as $category) { $sources = $category->getSources(); foreach ($sources as $source) { $date = new \DateTime(); if ($source->getLastCall()) { $date->setTimestamp($source->getLastCall()); } else { $date->modify("- 2 weeks"); } $source->setLastCall(new \DateTime()); if ($source instanceof Category\Source\Email) { // $connection is instance of \Ddeboer\Imap\Connection try { $connection = $this->getEmailConnection($source); $category = $source->getCategory(); $mailboxes = $connection->getMailboxes(); foreach ($mailboxes as $mailbox) { if (strpos($mailbox->getName(), "INBOX") === 0) { $search = new SearchExpression(); $search->addCondition(new After($date)); $search->addCondition(new Undeleted()); $messages = $mailbox->getMessages($search); foreach ($messages as $message) { // imap filter will only check the day not the time... if ($message->getDate() <= $date) { continue; } $text = $message->getBodyHtml(); if (empty($text)) { $text = $message->getBodyText(); } $text = Utils::purifyHtml($text); $objects[] = array('email_id' => $message->getId(), 'title' => $message->getSubject(), 'text' => $text, 'realSource' => $message->getFrom(), 'date' => $message->getDate(), 'type' => "email", 'category' => $category, 'source' => $source); } } } } catch (\Exception $exp) { $errors[] = array('title' => "error while connection to email server", "text" => $exp->getMessage(), "date" => new \DateTime()); } } else { if ($source instanceof Category\Source\Feed) { $reader = $this->feedReader; $feed = $reader->getFeedContent($source->getUrl(), $date); $items = $feed->getItems(); foreach ($items as $item) { $objects[] = array('feed_id' => null, 'title' => (string) $item->getTitle(), 'text' => (string) $item->getDescription(), 'date' => $item->getUpdated(), 'realSource' => (string) $item->getLink(), 'type' => "feed", 'category' => $category, 'source' => $source); } } } $this->em->persist($source); } } foreach ($objects as $object) { $entry = new Category\Entry(); $entry->setCategory($object["category"]); $entry->setSource($object["source"]); $entry->setType($object["type"]); $entry->setTitle($object["title"]); $entry->setText($object["text"]); $entry->setDate($object["date"]); $this->em->persist($entry); } $this->em->flush(); $qb = $this->em->getRepository('SymbbCoreNewsBundle:Category\\Entry')->createQueryBuilder('e'); $qb->select("e"); $qb->where("e.topic IS NULL"); $qb->addOrderBy("e.date", "desc"); $query = $qb->getQuery(); $objects = $this->createPagination($query, $page, $limit); return $objects; }
/** * @param Post $post * @return bool */ public function save(Post $post) { $new = false; if ($post->getId() <= 0) { $new = true; } $text = Utils::purifyHtml($post->getText()); $post->setText($text); $this->em->persist($post); $this->em->flush(); if ($new) { $this->markAsNew($post); } // if it is a new answer of an existing topic if ($post->getTopic()->getId() > 0 && $new) { // get all notify flags for this topic $flags = $this->topicFlagHandler->findFlagsByObjectAndFlag($post->getTopic(), AbstractFlagHandler::FLAG_NOTIFY); foreach ($flags as $flag) { // if the notify user is not the author of the new post if ($flag->getUser()->getId() !== $post->getAuthor()->getId()) { // send a notify $this->notifyHandler->sendTopicNotifications($post->getTopic(), $flag->getUser()); } } } return true; }
public function removeHtml($html) { return Utils::removeHtml($html); }