1: <?php
 2:  3:  4:  5:  6:  7:  8:  9: 
10: namespace FastFeed\Processor;
11: 
12: use FastFeed\Item;
13: use FastFeed\Url\Url;
14: 
15: 16: 17: 
18: class PathProcessor implements ProcessorInterface
19: {
20:     21: 22: 23: 24: 25: 26: 
27:     public function process(array $items)
28:     {
29:         foreach ($items as $key => $item) {
30:             $items[$key] = $this->fixPaths($item);
31:         }
32: 
33:         return $items;
34:     }
35: 
36:     37: 38: 39: 40: 
41:     protected function fixPaths(Item $item)
42:     {
43:         $url = new Url($item->getSource());
44:         $item->setIntro($this->getFixedText($item->getIntro(), $url->getFullHost()));
45:         $item->setContent($this->getFixedText($item->getContent(), $url->getFullHost()));
46: 
47:         return $item;
48:     }
49: 
50:     51: 52: 53: 54: 55: 
56:     protected function getFixedText($text, $domain)
57:     {
58:         $text = str_ireplace('href="/', 'href="' . $domain . '/', $text);
59:         $text = str_ireplace('href=\'/', 'href=\'' . $domain . '/', $text);
60:         $text = str_ireplace('src="/', 'src="' . $domain . '/', $text);
61:         $text = str_ireplace('src=\'/', 'src=\'' . $domain . '/', $text);
62: 
63:         return $text;
64:     }
65: }
66: