Example #1
0
 public function testFromString()
 {
     $string = (string) rand();
     $safe = SafeString::fromString($string);
     $this->assertInstanceOf('Athens\\Core\\Etc\\SafeString', $safe);
     $this->assertEquals($string, (string) $safe);
 }
Example #2
0
 /**
  * @param string                     $id
  * @param FilterStatementInterface[] $classes
  * @param string[]                   $data
  * @param FilterInterface|null       $nextFilter
  */
 public function __construct($id, array $classes, array $data, FilterInterface $nextFilter = null)
 {
     $statements = [];
     for ($i = 0; $i <= 5; $i++) {
         $fieldname = FilterControls::getControl($id, "fieldname{$i}");
         $operation = FilterControls::getControl($id, "operation{$i}");
         $value = FilterControls::getControl($id, "value{$i}");
         if ($fieldname !== "" && $operation !== "" && $value !== "") {
             $statements[] = new ExcludingFilterStatement($fieldname, $operation, $value, null);
         }
     }
     $feedbackStatements = [];
     foreach ($statements as $statement) {
         $fieldname = $statement->getFieldName();
         $value = $statement->getCriterion();
         $operation = $statement->getCondition();
         $feedbackStatement = $fieldname . " " . $operation . " " . $value;
         $feedbackStatements[] = preg_replace('/[^a-zA-Z0-9 -.]/', '', $feedbackStatement);
     }
     if ($feedbackStatements !== []) {
         $feedbackStatements[] = '
         <a href="#" class="search-clear" onclick="athens.search.clearSearch(\'' . trim($id) . '\'); return false;">
             Clear
         </a>';
     }
     $this->feedback = SafeString::fromString(implode(', ', $feedbackStatements));
     parent::__construct($id, $classes, $data, $statements, $nextFilter);
 }
 /**
  * @param string $content
  * @param string $name
  * @return WritableBearerBuilder
  */
 public function addContent($content, $name = null)
 {
     if ($content instanceof SafeString === false) {
         $content = htmlentities($content);
     }
     $content = SafeString::fromString(nl2br($content));
     return $this->addLiteralContent($content, $name);
 }
Example #4
0
 /**
  * @param string $message
  * @return EmailBuilder
  */
 public function setMessage($message)
 {
     if ($message instanceof SafeString === false) {
         $message = htmlentities($message);
     }
     $message = SafeString::fromString(nl2br($message));
     return $this->setLiteralMessage($message);
 }
Example #5
0
 public function testSaferawFilter()
 {
     $writer = new MockHTMLWriter();
     $env = $writer->getEnvironment();
     $template = "{{ var|saferaw|raw }}";
     $unsafeVar = '<a href="http://example.com">a link</a>';
     $safeVar = SafeString::fromString($unsafeVar);
     // Render the unsafe string
     $result = $env->createTemplate($template)->render(["var" => $unsafeVar]);
     $this->assertEquals(htmlentities($unsafeVar), $result);
     // Render the safe string
     $result = $env->createTemplate($template)->render(["var" => $safeVar]);
     $this->assertEquals((string) $safeVar, $result);
 }