コード例 #1
0
 public function testAttributeEscaping()
 {
     $value = new SS_HTML4Value();
     $value->setContent('<a href="[]"></a>');
     $this->assertEquals('<a href="[]"></a>', $value->getContent(), "'[' character isn't escaped");
     $value->setContent('<a href="&quot;"></a>');
     $this->assertEquals('<a href="&quot;"></a>', $value->getContent(), "'\"' character is escaped");
 }
コード例 #2
0
    public function tidy($content, $stripWord = false)
    {

        // Try to use the extension first
        if (extension_loaded('tidy')) {
            $tidy = tidy_parse_string($content, array(
                'clean' => true,
                'output-xhtml' => true,
                'show-body-only' => true,
                'quote-nbsp'    => true,
                'wrap' => 0,
                'input-encoding' => 'utf8',
                'output-encoding' => 'utf8',
                'new-blocklevel-tags' => 'article aside audio details figcaption figure footer header hgroup nav section source summary temp track video',
                'new-empty-tags' => 'command embed keygen source track wbr',
                'new-inline-tags' => 'audio canvas command datalist embed keygen mark meter output progress time video wbr',
                'bare'                => $stripWord,
                'word-2000' => $stripWord
            ));

            $tidy->cleanRepair();
            return $this->rewriteShortcodes('' . $tidy);
        }

        // No PHP extension available, attempt to use CLI tidy.
        $retval = null;
        $output = null;
        @exec('tidy --version', $output, $retval);
        if ($retval === 0) {
            $tidy = '';
            $input = escapeshellarg($content);
            // Doesn't work on Windows, sorry, stick to the extension.
            $tidy = @`echo $input | tidy -q --show-body-only yes --input-encoding utf8 --output-encoding utf8 --wrap 0 --clean yes --output-xhtml yes`;
            return $this->rewriteShortcodes($tidy);
        }

        // Fall back to default
        $doc = new SS_HTML4Value($content);
        return $doc->getContent();
    }
 /**
  * Fixes URLs in images, link and a tags to refer to correct things relevant to the base tag.
  *
  * @param string $contentFile
  * 				The name of the file to fix links within
  */
 protected function fixLinks($content)
 {
     $value = SS_HTML4Value::create($content);
     $base = $value->getElementsByTagName('base');
     if ($base && $base->item(0)) {
         $base = $base->item(0)->getAttribute('href');
         $check = array('a' => 'href', 'link' => 'href', 'img' => 'src');
         foreach ($check as $tag => $attr) {
             if ($items = $value->getElementsByTagName($tag)) {
                 foreach ($items as $item) {
                     $href = $item->getAttribute($attr);
                     if ($href && $href[0] != '/' && strpos($href, '://') === false) {
                         $item->setAttribute($attr, $base . $href);
                     }
                 }
             }
         }
     }
     return $value->getContent();
 }