1: <?php
2: /**
3: * This file is part of the FastFeed package.
4: *
5: * (c) Daniel González <daniel@desarrolla2.com>
6: *
7: * For the full copyright and license information, please view the LICENSE
8: * file that was distributed with this source code.
9: */
10: namespace FastFeed\Processor;
11:
12: use DOMDocument;
13: use FastFeed\Item;
14:
15: /**
16: * ImageProcessor
17: */
18: class ImageProcessor extends ImagesProcessor
19: {
20: /**
21: * @var bool
22: */
23: protected $overrideImage = false;
24:
25: /**
26: * @param boolean $overrideImage
27: */
28: public function setOverrideImage($overrideImage)
29: {
30: $this->overrideImage = (bool)$overrideImage;
31: }
32:
33: /**
34: * Execute processor
35: *
36: * @param array $items
37: *
38: * @return array
39: */
40: public function process(array $items)
41: {
42: foreach ($items as $key => $item) {
43: $items[$key] = $this->setImage($item);
44: }
45:
46: return $items;
47: }
48:
49: /**
50: * @param Item $item
51: *
52: * @return Item
53: */
54: protected function setImage(Item $item)
55: {
56: if ($item->hasImage() && !$this->overrideImage) {
57: return $item;
58: }
59:
60: $this->setImageFromContent($item);
61:
62: return $item;
63: }
64:
65: /**
66: * @param Item $item
67: *
68: * @return bool|string
69: */
70: protected function setImageFromContent(Item $item)
71: {
72: $images = $this->getImages($item->getContent());
73:
74: foreach ($images as $image) {
75: if ($this->isOnIgnoredPatterns($image)) {
76: continue;
77: }
78: $item->setImage($image);
79:
80: return;
81: }
82: }
83: }
84: