Beispiel #1
0
 /**
  * Test folder
  */
 public function testDestination()
 {
     $this->assertEquals('Text', Mime::getDestinationFolder('test.xhtml'));
     $this->assertEquals('Text', Mime::getDestinationFolder('test.html'));
     $this->assertEquals('CSS', Mime::getDestinationFolder('style.css'));
     //		$this->assertEquals('Media', Mime::getDestinationFolder('test.html'));
     //		$this->assertEquals('Speech', Mime::getDestinationFolder('test.html'));
     //		$this->assertEquals('JS', Mime::getDestinationFolder('test.html'));
     //		$this->assertEquals('Misc', Mime::getDestinationFolder('test.html'));
 }
Beispiel #2
0
 /**
  * Extract remote assets and save it
  *
  * @param \DomDocument $dom
  *
  * @return array
  */
 public function pullRemoteAssets(\DomDocument &$dom)
 {
     $paths = [];
     foreach (['img' => 'src', 'script' => 'src', 'link' => 'href'] as $tag => $attr) {
         foreach ($dom->getElementsByTagName($tag) as $elem) {
             $url = $elem->getAttribute($attr);
             if (!preg_match('/^(https?:)?\\/\\//', $url)) {
                 continue;
             }
             // Get remote resource
             if (!($resource = $this->getRemote($url))) {
                 continue;
             }
             // Let's detect file mime
             list($basename) = explode('?', basename($url));
             $dir = Mime::getDestinationFolder($basename);
             if ('Misc' === $dir) {
                 // Oh, it might not have extension...
                 if ($resource['info']) {
                     list($mime, $type) = explode('/', $resource['info']['content_type']);
                     list($ext) = explode(';', $type);
                     $new_dir = Mime::getDestinationFolder("hoge.{$ext}");
                     if ($new_dir != $dir) {
                         $dir = $new_dir;
                         $basename = "{$basename}.{$ext}";
                     }
                 }
             }
             // O.K.
             $new_path = $dir . '/' . $basename;
             $elem->setAttribute($attr, '../' . $new_path);
             if ($this->distributor->write($resource['body'], 'OEBPS/' . $new_path)) {
                 $paths[] = $new_path;
             }
         }
     }
     return $paths;
 }