/**
  * @param Item $item
  * @param array $body
  *
  * @return Item
  */
 public function setImages(Item $item, $body)
 {
     $images = $this->browser->get(str_replace('#ID#', $body['id'], self::FILL_IMAGES_URL));
     foreach ($images as $image) {
         if ($path = parse_url($image['original'], PHP_URL_PATH)) {
             $image = new Image();
             $image->setSource(self::NAME . '/' . $body['id'] . '/' . pathinfo($path, PATHINFO_BASENAME));
             if ($this->uploadImage($this->browser->getHost() . $image['original'], $image)) {
                 $item->addImage($image);
             }
         }
     }
     return $item;
 }
 /**
  * Get item frames
  *
  * @param integer $id
  * @param string $type
  *
  * @return array
  */
 public function getFrames($id, $type)
 {
     $dom = $this->browser->getDom('/' . $type . '/' . $type . '_photos.php?id=' . $id);
     if (!$dom) {
         return [];
     }
     $images = (new \DOMXPath($dom))->query('//table//table//table//img');
     $frames = [];
     foreach ($images as $image) {
         $src = $this->getAttrAsArray($image)['src'];
         $entity = new Image();
         if ($type == self::ITEM_TYPE_ANIMATION) {
             $src = str_replace('optimize_b', 'optimize_d', $src);
             if (strpos($src, 'http://') === false) {
                 $src = $this->browser->getHost() . '/' . $type . '/' . $src;
             }
             if (preg_match('/\\-(?<image>\\d+)\\-optimize_d(?<ext>\\.jpe?g|png|gif)/', $src, $mat)) {
                 $entity->setSource(self::NAME . '/' . $id . '/' . $mat['image'] . $mat['ext']);
                 if ($this->uploadImage($src, $entity)) {
                     $frames[] = $entity;
                 }
             }
         } elseif (preg_match('/_(?<round>\\d+)\\/.+\\/(?<id>\\d+)-(?<image>\\d+)-.+(?<ext>\\.jpe?g|png|gif)/', $src, $mat)) {
             $src = $this->browser->getHost() . '/' . $type . '/img/' . $mat['round'] . '/' . $mat['id'] . '/' . $mat['image'] . $mat['ext'];
             $entity->setSource(self::NAME . '/' . $id . '/' . $mat['image'] . $mat['ext']);
             if ($this->uploadImage($src, $entity)) {
                 $frames[] = $entity;
             }
         }
     }
     return $frames;
 }
Exemple #3
0
 /**
  * @param Image $image
  *
  * @return Item
  */
 public function addImage(Image $image)
 {
     $images = array_map('strval', $this->images->toArray());
     if (!in_array($image->getSource(), $images)) {
         $this->images->add($image);
         $image->setItem($this);
     }
     return $this;
 }