Exemple #1
0
 function test_unprefixResourceUrls()
 {
     $html = '<html><head></head><body>' . '<div>' . '<a id="a1" href="p/a1">a1</a>' . '</div>' . '<div class="sc-content-1">' . '<a id="a2" href="p/a2">a2</a>' . '</div>' . '<div class="sc-content">' . '<a id="a3" href="p/files/a3-sc123456789abcd.doc">a3</a>' . '<img id="img1" src="p/images/img1-sc123456789abcd-00.jpg" srcset="draft/images/img1-sc123456789abcd-00.jpg 1, p/img2.jpg 2"/>' . '</div>' . '<div class="sc-content sc-content-2">' . '<a id="a4" href="javascript:p/files/a4-sc123456789abcd.doc">a4</a>' . '<a id="a5" href="#p/images/a5-sc123456789abcd.doc">a5</a>' . '<a id="a6" href="https://p/files/a6-sc123456789abcd.doc">a6</a>' . '</div>' . '</body></html>';
     $page = new Page($html);
     $page->unprefixResourceUrls('p/');
     $doc = phpQuery::newDocument((string) $page);
     $this->assertEquals('p/a1', phpQuery::pq('#a1', $doc)->elements[0]->getAttribute('href'));
     $this->assertEquals('p/a2', phpQuery::pq('#a2', $doc)->elements[0]->getAttribute('href'));
     $this->assertEquals('files/a3-sc123456789abcd.doc', phpQuery::pq('#a3', $doc)->elements[0]->getAttribute('href'));
     $this->assertEquals('javascript:p/files/a4-sc123456789abcd.doc', phpQuery::pq('#a4', $doc)->elements[0]->getAttribute('href'));
     $this->assertEquals('#p/images/a5-sc123456789abcd.doc', phpQuery::pq('#a5', $doc)->elements[0]->getAttribute('href'));
     $this->assertEquals('https://p/files/a6-sc123456789abcd.doc', phpQuery::pq('#a6', $doc)->elements[0]->getAttribute('href'));
     $this->assertEquals('images/img1-sc123456789abcd-00.jpg', phpQuery::pq('#img1', $doc)->elements[0]->getAttribute('src'));
     $this->assertEquals('draft/images/img1-sc123456789abcd-00.jpg 1, p/img2.jpg 2', phpQuery::pq('#img1', $doc)->elements[0]->getAttribute('srcset'));
 }
Exemple #2
0
 protected function cleanupPublic()
 {
     $pagePaths = $this->listScPagesPaths();
     foreach ($pagePaths as $pagePath) {
         $page = new Page($this->fs->read($pagePath));
         $page->removePageId();
         $page->cleanupContainerNames();
         $page->removeMetadata();
         $page->unprefixResourceUrls($this->draftBaseUrl());
         $this->fs->update($pagePath, (string) $page);
     }
 }