Esempio n. 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'));
 }
Esempio n. 2
0
 /**
  * Add item to
  *
  * @param string $relative_path
  * @param string $id If empty, path will convert to id
  * @param array $properties Default empty. If set, properties will be set.
  * @return string
  */
 public function addItem($relative_path, $id = '', array $properties = [])
 {
     $id = $id ?: $this->pathToId($relative_path);
     // Avoid duplication
     foreach ($this->dom->manifest->item as $item) {
         /** @var \SimpleXMLElement $item */
         $attr = $item->attributes();
         if (isset($attr['id']) && $id == $attr['id']) {
             return $id;
         }
     }
     // This is unique.
     $item = $this->dom->manifest->addChild('item');
     $item['id'] = $id;
     $item['href'] = $relative_path;
     $item['media-type'] = Mime::getTypeFromPath($relative_path);
     if ($properties) {
         $item['properties'] = implode(' ', $properties);
     }
     return $id;
 }
Esempio n. 3
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;
 }