Example #1
0
 public function testExecuteAction()
 {
     $options = ['html' => '$.html', 'attribute' => '$.attribute'];
     $fakeContext = ['fake', 'things', 'are', 'here'];
     $this->contextAccessor->expects($this->once())->method('getValue')->with($this->equalTo($fakeContext), $this->equalTo('$.html'))->will($this->returnValue($html = '<html></html>'));
     $this->contextAccessor->expects($this->once())->method('setValue')->with($this->equalTo($fakeContext), $this->equalTo('$.attribute'), $this->equalTo($stripped = 'stripped'));
     $this->helper->expects($this->once())->method('purify')->with($this->equalTo($html))->will($this->returnValue($purified = 'purified'));
     $this->helper->expects($this->once())->method('stripTags')->with($this->equalTo($purified))->will($this->returnValue($stripped));
     $this->action->initialize($options);
     $this->action->execute($fakeContext);
 }
 /**
  * @param object                        $entity
  * @param ActivityListProviderInterface $provider
  * @param string                        $verb
  * @param ActivityList|null             $list
  *
  * @return ActivityList
  */
 protected function getActivityListEntityForEntity($entity, ActivityListProviderInterface $provider, $verb = ActivityList::VERB_CREATE, $list = null)
 {
     if ($provider->isApplicable($entity)) {
         if (!$list) {
             $list = new ActivityList();
         }
         $list->setSubject($provider->getSubject($entity));
         $list->setDescription($this->htmlTagHelper->stripTags($this->htmlTagHelper->purify($provider->getDescription($entity))));
         $this->setDate($entity, $provider, $list);
         if ($this->hasGrouping($provider)) {
             $list->setHead($provider->isHead($entity));
         }
         $list->setVerb($verb);
         if ($verb === ActivityList::VERB_UPDATE) {
             $activityListTargets = $list->getActivityListTargetEntities();
             foreach ($activityListTargets as $target) {
                 $list->removeActivityListTarget($target);
             }
         } else {
             $className = $this->doctrineHelper->getEntityClass($entity);
             $list->setRelatedActivityClass($className);
             $list->setRelatedActivityId($this->doctrineHelper->getSingleEntityIdentifier($entity));
             $list->setOrganization($provider->getOrganization($entity));
         }
         $targets = $provider->getTargetEntities($entity);
         foreach ($targets as $target) {
             if ($list->supportActivityListTarget($this->doctrineHelper->getEntityClass($target))) {
                 $list->addActivityListTarget($target);
             }
         }
         return $list;
     }
     return null;
 }
 /**
  * @param User $user
  * @param $maxEmailsDisplay
  *
  * @return array
  */
 public function getEmails(User $user, Organization $organization, $maxEmailsDisplay)
 {
     $emails = $this->em->getRepository('OroEmailBundle:Email')->getNewEmails($user, $organization, $maxEmailsDisplay);
     $emailsData = [];
     /** @var $email Email */
     foreach ($emails as $element) {
         $isSeen = $element['seen'];
         $email = $element[0];
         $bodyContent = '';
         try {
             $this->emailCacheManager->ensureEmailBodyCached($email);
             $bodyContent = $this->htmlTagHelper->shorten($this->htmlTagHelper->stripTags($this->htmlTagHelper->purify($email->getEmailBody()->getBodyContent())));
         } catch (LoadEmailBodyException $e) {
             // no content
         }
         $emailsData[] = ['route' => $this->router->generate('oro_email_email_reply', ['id' => $email->getId()]), 'id' => $email->getId(), 'seen' => $isSeen, 'subject' => $email->getSubject(), 'bodyContent' => $bodyContent, 'fromName' => $email->getFromName(), 'linkFromName' => $this->getFromNameLink($email)];
     }
     return $emailsData;
 }
Example #4
0
    public function testHtmlPurify()
    {
        $testString = <<<STR
<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="MSHTML 10.00.9200.17228">
<style id="owaParaStyle">P {
\tMARGIN-BOTTOM: 0px; MARGIN-TOP: 0px
}
</style>
</head>
<body fPStyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">no subject</div>
</body>
</html>

STR;
        $this->assertEquals('<div style="font-family:Tahoma;color:#000000;font-size:10pt;">no subject</div>', trim($this->helper->purify($testString)));
    }
 /**
  * {@inheritdoc}
  */
 public function getDescription($entity)
 {
     /** @var $entity Email */
     if ($entity->getEmailBody()) {
         $body = $entity->getEmailBody()->getBodyContent();
         $content = $this->htmlTagHelper->purify($body);
         $content = $this->htmlTagHelper->stripTags($content);
         $content = $this->htmlTagHelper->shorten($content);
         return $content;
     }
     return null;
 }
Example #6
0
 /**
  * Filter is intended to purify script, style etc tags and content of them
  *
  * @param string $string
  * @return string
  */
 public function htmlPurify($string)
 {
     return $this->htmlTagHelper->purify($string);
 }
Example #7
0
 /**
  * {@inheritdoc}
  */
 protected function executeAction($context)
 {
     $result = $this->htmlTagHelper->purify($this->contextAccessor->getValue($context, $this->html));
     $result = $this->htmlTagHelper->stripTags($result);
     $this->contextAccessor->setValue($context, $this->attribute, $result);
 }