Plugin Directory

Changeset 752566


Ignore:
Timestamp:
08/06/2013 09:57:53 PM (13 years ago)
Author:
altmannmarcelo
Message:

price fix

File:
1 edited

Legend:

Unmodified
Added
Removed
  • amazon-wishlist-pro/trunk/Amazon-wishlist-pro.php

    r723007 r752566  
    2727        {
    2828            unlink($cache_file);
    29             update_option('Amazon-wishlist-pro-invalidate-cache', '0');
    3029        }
    3130    }
     
    3736            $update = 1;
    3837    }
    39     echo $wishListHTML;
    4038    $wishListHTML = @file_get_html($wishListURL);
     39    if($update == 1)
     40        file_put_contents($cache_file, $wishListHTML, LOCK_EX);
     41    $wishListHTML = $wishListHTML->find('div[id=item-page-wrapper]', 0);
     42   
    4143    if(!$wishListHTML)
    4244        return 'Invalid ListID ' . $listID .' for amazon.' . $website;
    4345
    44     if($update == 1)
    45         file_put_contents($cache_file, $wishListHTML, LOCK_EX);
    4646
    4747    $template = get_option('Amazon-wishlist-pro-layout');
    4848
    4949    $output = '';
     50    $a = 0;
    5051    foreach($wishListHTML->find('.itemWrapper') as $element)
    5152    {
     
    5859            $output .= '</li>';
    5960
    60 
     61    $a++;
    6162    }
    6263    if(trim($output) != '')
     
    6566            $output = '<ul>' . $output . '</ul>';
    6667    }
     68
     69    if($invalidateCache == 1)
     70            update_option('Amazon-wishlist-pro-invalidate-cache', '0');
     71   
    6772    return $output;
    6873
     
    7176function getItemInfo($node)
    7277{
    73     $price = utf8_encode($node->find('span.wlPriceBold',0)->plaintext);
    7478    $image = $node->find('img',0)->src;
    7579    $buyLink = $node->find('.wlBuyButton a',0)->href;
    7680    $title = utf8_encode(trim($node->find('span.productTitle',0)->plaintext));
    7781    $productLink = $node->find('span.productTitle strong a',0)->href;
     82    $price = utf8_encode($node->find('span.wlPriceBold',0)->plaintext);
     83    if(trim($price) == '')
     84    {
     85        $link = $productLink;
     86        $useCache = get_option('Amazon-wishlist-pro-use-cache');
     87        $invalidateCache = get_option('Amazon-wishlist-pro-invalidate-cache');
     88        $cache_file_prod = __DIR__.'/' . md5($productLink) .'.cache';
     89        if($invalidateCache == 1)
     90        {
     91            if (file_exists($cache_file_prod))
     92            {
     93                unlink($cache_file_prod);
     94            }
     95        }
     96        if($useCache == 1)
     97        {
     98            if (file_exists($cache_file_prod) && (filemtime($cache_file_prod) > (time() - 60 * 24 )))
     99                $link = $cache_file_prod;
     100            else
     101                $update = 1;
     102        }
     103        $productHTML = @file_get_html($link);
     104        if($update == 1)
     105            file_put_contents($cache_file_prod, $productHTML, LOCK_EX);
     106       
     107        $price = utf8_encode($productHTML->find('.priceLarge',0)->plaintext);   
     108    }
    78109    $info = array(
    79110        '@price@' => $price,
Note: See TracChangeset for help on using the changeset viewer.