示例#1
0
文件: Cotd.php 项目: neilgarb/yadda
 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;
 }
示例#2
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);
 }
示例#3
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);
 }