Beispiel #1
0
 public function import($feed)
 {
     // fetch
     $xml = $this->_fetch($feed->url);
     // parse
     $xml = new SimpleXMLElement($xml);
     $stubs = array();
     foreach ($xml->xpath('/deals/deal') as $deal) {
         $stub = new Yadda_Feed_Stub();
         $res = $deal->xpath('ID');
         $stub->setGuid('cotd/' . intval($res[0]));
         $res = $deal->xpath('title');
         $stub->setTitle($this->_sanitize((string) $res[0]));
         $res = $deal->xpath('url');
         $stub->setLink($this->_sanitize((string) $res[0]));
         $res = $deal->xpath('description');
         $stub->setDescription($this->_sanitize((string) $res[0]));
         $res = $deal->xpath('image');
         $stub->addImage($this->_sanitize((string) $res[0]));
         $res = $deal->xpath('value');
         $stub->setValue((double) $res[0]);
         $res = $deal->xpath('price');
         $stub->setPrice($res[0]);
         $stub->setDiscount(($stub->getValue() - $stub->getPrice()) / $stub->getValue() * 100);
         $stubs[] = $stub;
     }
     return $stubs;
 }
Beispiel #2
0
 public function import($feed)
 {
     $stubs = array();
     // fetch
     $html = $this->_fetch($feed->url);
     // parse
     $matches = array();
     preg_match_all('#<div class="side1">.*<img src="(/img/medium_big_thumb[^"]+)".*<h3>Description</h3>(.*)</div>.*</div>.*<div class="side2">.*([0-9]+)" title="Buy".*<p class="price"><span>R<span class="c cr"[^>]+>([0-9\\.]+)</span></span></p>.*</div>#sU', $html, $matches);
     for ($i = 0; $i < sizeof($matches[0]); $i++) {
         $stub = new Yadda_Feed_Stub();
         // link
         $stub->setLink($feed->url);
         // guid
         $id = (int) $matches[3][$i];
         $stub->setGuid('justhenga/' . $id);
         // description
         $stub->setDescription($this->_sanitize($matches[2][$i]));
         // price
         $stub->setPrice((double) $matches[4][$i]);
         // title
         $stub->setTitle(substr($stub->getDescription(), 0, 50) . '... (R' . sprintf('%.2f', $stub->getPrice()) . ')');
         // image
         $stub->addImage('http://www.justhenga.com' . $this->_sanitize($matches[1][$i]));
         $stubs[] = $stub;
     }
     return $stubs;
 }
Beispiel #3
0
 public function import($feed)
 {
     $stub = new Yadda_Feed_Stub();
     // fetch
     $html = $this->_fetch($feed->url);
     // link
     $stub->setLink('http://www.onedayonly.co.za/');
     // guid
     $guid = $this->_match('#<input type="hidden" name="product_id" value="([^"]+)" />#sU', $html);
     if ($guid !== null) {
         $stub->setGuid('onedayonly/' . $guid);
     }
     // title
     $title = $this->_match('#<td.*class="product_name".*>([^<]+)</td>#sU', $html);
     if ($title !== null) {
         $stub->setTitle($this->_sanitize($title));
     }
     // description
     $description = $this->_match('#<div class="product_s_desc">(.*)</td>#sU', $html);
     if ($description !== null) {
         $stub->setDescription($this->_sanitize($description));
     }
     // price
     $price = $this->_match('#<span class="productPrice">([^<]+)</span>#sU', $html);
     if ($price !== null) {
         $stub->setPrice((double) str_replace('R', '', trim($price)));
     }
     // value
     $value = $this->_match('#Retail price: <s>R([\\d\\.]+)</s>#sU', $html);
     if ($value !== null) {
         $stub->setValue((double) $value);
     }
     // discount
     if ($stub->getValue() !== null && $stub->getPrice() !== null && $stub->getValue() > 0) {
         $stub->setDiscount(($stub->getValue() - $stub->getPrice()) / $stub->getValue() * 100);
     }
     // image
     $image = $this->_match('#<a.*rel="lightbox"><img src="([^"]+)" class="browseProductImage"#sU', $html);
     if ($image !== null) {
         $stub->addImage($this->_sanitize($image));
     }
     return array($stub);
 }
Beispiel #4
0
 public function import($feed)
 {
     $stub = new Yadda_Feed_Stub();
     // fetch
     $html = $this->_fetch($feed->url);
     // link + guid
     $link = $this->_match('#<meta name="og:url" content="([^"]+)" />#sU', $html);
     if ($link !== null) {
         $stub->setLink($this->_sanitize($link));
         $stub->setGuid($this->_sanitize($link));
     }
     // title
     $title = $this->_match('#<h1>([^<]+)</h1>#sU', $html);
     if ($title !== null) {
         $stub->setTitle($this->_sanitize($title));
     }
     // description
     $description = $this->_match('#<div class="product-details".*>(.*)</div>#sU', $html);
     if ($description !== null) {
         $stub->setDescription($this->_sanitize($description));
     }
     // price
     $price = $this->_match('#<div class="price">([^<]+)</div>#sU', $html);
     if ($price !== null) {
         $stub->setPrice((double) $price);
     }
     // value
     $value = $this->_match('#<span class="rrp">R.*([\\d\\.]+)</span>#sU', $html);
     if ($value !== null) {
         $stub->setValue((double) $value);
     }
     // discount
     if ($stub->getPrice() !== null && $stub->getValue() !== null && $stub->getValue() > 0) {
         $stub->setDiscount(($stub->getValue() - $stub->getPrice()) / $stub->getValue() * 100);
     }
     // image
     $image = $this->_match('#<img id="MainPic".*src="([^"]+)"#sU', $html);
     if ($image !== null) {
         $stub->addImage('http://www.24hoursonly.co.za/' . $image);
     }
     return array($stub);
 }