function amazonShortcode($atts, $content)
{
    // extract attributes
    extract(shortcode_atts(array('num' => ''), $atts));
    // We get $num variable
    if (empty($num)) {
        $num = 5;
    }
    // define HTML prefix and suffix for displayed App Store Box
    $preBox = '<hr style="border: 0; height: 0; border-top: 1px solid rgba(0, 0, 0, 0.1); border-bottom: 1px solid rgba(255, 255, 255, 0.3);">';
    $sufBox = '<hr style="border: 0; height: 0; border-top: 1px solid rgba(0, 0, 0, 0.1); border-bottom: 1px solid rgba(255, 255, 255, 0.3);">';
    // Require the class file
    // From https://github.com/chopin2256/Amazon
    require_once 'Amazon.php';
    //Run Amazon
    $amazon = new Amazon();
    //Instantiate Amazon object
    $kw = $content;
    //Set keyword
    $cnt = $num;
    //Set amazon max results, up to 10
    //Set config options
    $amazon->config()->API_KEY(get_option('amazon_shortc_apikey'))->SECRET_KEY(get_option('amazon_shortc_secretkey'))->associate_tag(get_option('amazon_shortc_associatetag'))->locale(get_option('amazon_shortc_locale'))->maxResults($cnt);
    //Search for keyword
    $amazon->search($kw);
    //Loop through array in for loop to save your Amazon results
    for ($i = 0; $i < $cnt; $i++) {
        $result .= amazonLayout($i, $amazon) . $sufBox;
    }
    //Clear amazon object
    $amazon->clear();
    //Set and return results, in this case, 5 product titles
    return $preBox . $result;
}
Esempio n. 2
0
 public static function getInstance()
 {
     if (self::$_instance == null) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 function amazon($ids, $tag)
 {
     $isbns = $lookupIsbns = array();
     foreach (explode(',', $ids) as $id) {
         preg_match("/\\{(.+?)\\:(.+?)\\}/", $id, $matches);
         if ($matches[1] == 'A') {
             $isbns[] = $matches[2];
         } else {
             if ($matches[1] == 'MP') {
                 $lookupIsbns[] = $matches[2];
             } else {
                 error_log("amazon cart called with bad input: {$ids}");
             }
         }
     }
     // find current, lowest-priced offers for the marketplace isbns
     $offersArray = Amazon::getMarketplaceOffers($lookupIsbns);
     $offerIds = array();
     foreach ($offersArray as $offers) {
         foreach ($offers->Items->Item as $item) {
             // sometimes Amazon gives us different isbns than the ones we asked for
             if (in_array((string) $item->ItemAttributes->EAN, $lookupIsbns)) {
                 $offerIds[] = (string) $item->Offers->Offer[0]->OfferListing->OfferListingId;
             }
         }
     }
     $GLOBALS['tag'] = $tag;
     global $app;
     $app->redirect(Amazon::getCartUrl($isbns, $offerIds), 301);
 }
Esempio n. 4
0
 private static function init()
 {
     if (self::$s3) {
         return true;
     }
     self::$s3 = new AmazonS3(array('key' => self::$access_key, 'secret' => self::$secret_key));
 }
 public static function getUrl(array $prices)
 {
     global $tag, $marketplaceSingleCart;
     if (!$marketplaceSingleCart && count($prices) == 1) {
         return "http://www.amazon.com/gp/offer-listing/" . Isbn::to10(current($prices)->bookId) . "/condition=all&tag={$tag}";
     } else {
         return Amazon::getUrl($prices);
     }
 }
Esempio n. 6
0
function amazonLayout($i, Amazon $amazon)
{
    //Get your amazon attributes here
    $image = $amazon->get()->image("LargeImage");
    $priceLowNew = $amazon->get()->price("lowestNew");
    $priceUsed = $amazon->get()->price("lowestUsed");
    $offersNew = $amazon->get()->numOffers("TotalNew");
    $offersUsed = $amazon->get()->numOffers("TotalUsed");
    $url = $amazon->get()->url();
    $title = $amazon->get()->title();
    $desc = $amazon->get()->description();
    //Your custom code and formatting here
    $newTitle = "<div>{$title[$i]}</div>";
    $newUrl = "<div>{$url[$i]}</div>";
    //..etc
    return $newTitle;
}
 public function postSearch()
 {
     $params = Input::all();
     // 楽天商品の検索
     $rakuten_gestion = Rakuten::getInstance();
     $rakuten_items = $rakuten_gestion->searchItemByKeyword($params['itemKeyword']);
     // Amazon商品の検索
     $amazon_gestion = Amazon::getInstance();
     $amazon_items = $amazon_gestion->searchItemByKeyword($params['itemKeyword']);
     $results = array_merge($rakuten_items, $amazon_items);
     header('Content-Type: application/json');
     echo json_encode($results);
     exit;
 }
Esempio n. 8
0
<?php

// PHPのバージョンが新しくて、エラーがたくさん出る場合コメントアウトする
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
require_once 'amazon.php';
$obj = new Amazon();
// アクセスキー、シークレットキー、セラーID、マーケットプレイスIDをセットする
$obj->setAccessKeyId("");
$obj->setSecretAccessKey("");
$obj->setSellerId('');
$obj->setMarketplaceId('');
//使用したいオペレーションをコメントアウトする
//$hoge = $obj->getServiceStatus();
//$hoge = $obj->getMatchingProduct('');
//$hoge = $obj->getCompetitivePricingForASIN('');
//$hoge = $obj->getLowestOfferListingsForASIN('Used', '');
//$hoge = $obj->getProductCategoriesForASIN('');
echo "<pre>";
var_dump($hoge);
echo "</pre>";
Esempio n. 9
0
include __DIR__ . '/config.php';
require __DIR__ . '/simplepie/simplepie.inc';
$feed = new SimplePie();
$feed->set_feed_url("http://ws.audioscrobbler.com/1.0/user/bbc6music/recenttracks.rss");
$feed->set_cache_duration(59);
# 1 minute
$feed->init();
$feed->handle_content_type();
$songs = $feed->get_items();
$song = $songs[0]->get_title();
$query = preg_replace('/\\W/', ' ', $song);
$mp3s = array();
if ($conf['amazon']['key'] && $conf['amazon']['secret']) {
    require __DIR__ . '/amazon.php';
    $amazon = new Amazon();
    $amazon->key = $conf['amazon']['key'];
    $amazon->secret = $conf['amazon']['secret'];
    $amazon->tag = $conf['amazon']['tag'];
    $mp3s = $amazon->lookup($query);
}
if (empty($mp3s)) {
    $mp3s = array(array('info' => 'http://www.amazon.com/s/?url=search-alias%3Ddigital-music&field-keywords=' . urlencode($query)));
}
$feed->set_feed_url("http://twitter.com/statuses/user_timeline/15734589.rss");
$feed->set_cache_duration(59);
# 1 minute
$feed->init();
$feed->handle_content_type();
$shows = $feed->get_items();
# title is of the form "on_6music: Liz Kershaw http://bbc.co.uk/6music/" so always chomp first 12 and last 24
Esempio n. 10
0
 public function main()
 {
     parent::main();
     $client = $this->getAwsClient()->createS3();
     $client->getObject(array('Bucket' => $this->getBucket(), 'Key' => $this->getObject(), 'SaveAs' => is_dir($this->getTarget()) ? $this->getTarget() . $this->getObject() : $this->getTarget()));
 }
Esempio n. 11
0
<?php

require_once dirname(__FILE__) . '/../inc/init.php';
require_once BASE . 'inc/HTTPClient.php';
require_once BASE . 'inc/Amazon.php';
$AMZ = new Amazon($CONF['public_key'], $CONF['private_key']);
$stmt_srch = $PDO->prepare("SELECT *\n       FROM search\n      WHERE added > datetime('NOW','-90 days')\n        AND lastget > datetime('NOW','-5 days')");
$stmt_ins = $PDO->prepare('INSERT OR IGNORE INTO search_results
            (sid, asin, title, price, url, image, more)
     VALUES (?,?,?,?,?,?,?)');
$stmt_srch->execute();
while ($row = $stmt_srch->fetch(PDO::FETCH_ASSOC)) {
    printf("%5s %s\n", $row['region'], $row['query']);
    $AMZ->setRegion($row['region']);
    $items = $AMZ->search($row['query']);
    foreach ($items as $item) {
        $num = $item->OfferSummary->TotalNew + $item->OfferSummary->TotalUsed + $item->OfferSummary->TotalCollectible + $item->OfferSummary->TotalRefurbished;
        if (!$num) {
            continue;
        }
        // skip non available products
        if ($item->OfferSummary->LowestNewPrice->FormattedPrice) {
            $price = $item->OfferSummary->LowestNewPrice->FormattedPrice . ' (new)';
        } else {
            $price = $item->OfferSummary->LowestUsedPrice->FormattedPrice . ' (used)';
        }
        $stmt_ins->execute(array($row['sid'], $item->ASIN, $item->ItemAttributes->Title, $price, $item->DetailPageURL, $item->MediumImage->URL, $item->EditorialReviews->EditorialReview->Content));
    }
}
Esempio n. 12
0
 public function main()
 {
     parent::main();
     $client = $this->getAwsClient()->createElasticBeanstalk();
     $client->createApplicationVersion(array("ApplicationName" => $this->getApplication(), "VersionLabel" => $this->getVersion(), "Description" => "Deploy app {$this->getApplication} at version {$this->getVersion()} on date " . date('Ymd H:i:s'), "SourceBundle" => array("S3Bucket" => $this->getBucket(), "S3Key" => $this->getObject()), "AutoCreateApplication" => false));
 }
 /**
  * todo: this should be changed to use Amazon::getMultiAmazonData so only
  * one call is made if there are multiple isbns.  however, that makes it
  * difficult to keep isbn10/isbn13 distinction.
  */
 public function book($isbn)
 {
     global $app;
     $isbns = explode("-", $isbn);
     $ret = array();
     foreach ($isbns as $isbn) {
         if (Isbn::validate($isbn) && ($data = Amazon::getAmazonData($isbn))) {
             // Occasionally Amazon returns data for the book we want, but
             // with a different ISBN.  This preserves the original ISBN.
             if ($data['isbn'] != Isbn::to13($isbn)) {
                 $itemId = $data['isbn'];
             } else {
                 $itemId = $isbn;
             }
             $ret[] = array('itemId' => $itemId, 'slug' => $itemId, 'data' => $data);
         } else {
             $ret[] = array('itemId' => $isbn, 'slug' => $isbn, 'error' => true);
         }
     }
     echo json_encode($ret);
     $app->stop();
     Results::fetchPrices($isbns);
 }
Esempio n. 14
0
 public function main()
 {
     parent::main();
     $client = $this->getAwsClient()->createS3();
     $client->putObject(array('Bucket' => $this->getBucket(), 'Key' => $this->getObject(), 'SourceFile' => $this->getSource()));
 }
Esempio n. 15
0
 public static function get_link($movieId)
 {
     $link = self::find_by_id($movieId);
     $exists = $link ? true : false;
     if ($link && days_from_now($link->timestamp) < LINK_UPDATE_DAYS) {
         // good
     } else {
         $exists = $link ? true : false;
         $movie = Movie::find_by_id($movieId);
         $link = new Amazon();
         $link->id = $movieId;
         $link->timestamp = gen_timestamp();
         require_once LIB_PATH . DS . "amazon_api_class.php";
         $runtime = $movie->runtime;
         $title = preg_replace('/[^a-z0-9]+/i', ' ', $movie->title);
         $obj = new AmazonProductAPI();
         try {
             $result = $obj->searchProducts($title, AmazonProductAPI::VIDEO, "TITLE");
         } catch (Exception $e) {
             echo $e->getMessage();
         }
         $cast = Actor::list_of_names($movie->id);
         foreach ($result->Items->Item as $k) {
             if ($k->ItemAttributes->Binding == 'Amazon Instant Video') {
                 if (abs($k->ItemAttributes->RunningTime - $runtime) < 5 && strpos($cast, (string) $k->ItemAttributes->Actor) !== false || abs($k->ItemAttributes->RunningTime - $runtime) < 5 && levenshtein($title, (string) $k->ItemAttributes->Title) <= 3) {
                     $link->link = $k->DetailPageURL;
                     $link->asin = $k->ASIN;
                     break;
                 }
             }
         }
         if (strlen($link->link) > 0) {
             $html = file_get_contents($link->link);
             if (!strpos($html, 'movie is currently unavailable') && strlen($html) > 20) {
                 $html = substr($html, strpos($html, '<ul class="button-list">'), 2000);
                 $matches = array();
                 $rent = "";
                 $buy = "";
                 preg_match_all("/Rent SD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $rent .= substr($matches[0][0], 8);
                 }
                 preg_match_all("/Rent HD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $rent .= "|" . substr($matches[0][0], 8);
                 }
                 preg_match_all("/Buy SD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $buy .= substr($matches[0][0], 7);
                 }
                 preg_match_all("/Buy HD [\$][1-9]+[.][1-9][1-9]/", $html, $matches);
                 if (sizeof($matches[0]) > 0) {
                     $buy .= "|" . substr($matches[0][0], 7);
                 }
                 $link->rent = $rent;
                 $link->buy = $buy;
             }
         }
         if ($exists) {
             $link->update();
         } else {
             $link->create();
         }
     }
     return $link;
 }
Esempio n. 16
0
     // fetch from amazon
     $fetch_url = ImgStore::getUrl($image['image_id'], $image['size_id'], 0);
     $real_private_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id'], $private = true);
     log_('fetching ' . $fetch_url . ' to ' . $real_private_path);
     file_put_contents($real_private_path, file_get_contents($fetch_url));
     log_($image['bytes'] . '=db size,' . filesize($real_private_path) . '=real size copied');
     if (filesize($real_private_path)) {
         $amazon_dest = str_replace(ImgStore::$server_urls[ImgStore::SERVER_AMAZONS3], '', $fetch_url);
         $res = Amazon::delete($amazon_dest);
         log_('deleted ' . $amazon_dest . ' from amazon with code:' . $res);
         Database::query('UPDATE `images` SET `server_id`=' . ImgStore::SERVER_PRIVATE . ', `private_real`=1 WHERE `id`=' . $image['id']);
     }
 } else {
     // get from local file, delete amazon copy
     $amazon_dest = str_replace(ImgStore::$server_urls[ImgStore::SERVER_AMAZONS3], '', ImgStore::getUrl($image['image_id'], $image['size_id'], 0));
     $res = Amazon::delete($amazon_dest);
     log_('deleted ' . $amazon_dest . ' from amazon with code:' . $res);
     //
     $real_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id']);
     log_($image['id'] . ' at original server in ' . $real_path . ' ' . filesize($real_path) . ' bytes');
     // change location to private folder
     $real_private_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id'], $private = true);
     log_('will be moved to ' . $real_private_path);
     if (copy($real_path, $real_private_path)) {
         log_('succesfully copied');
         Database::query('UPDATE `images` SET `server_id`=' . ImgStore::SERVER_PRIVATE . ', `private_real`=1 WHERE `id`=' . $image['id']);
         unlink($real_path);
     } else {
         log_('cant copy');
     }
 }
Esempio n. 17
0
 /**
  * Prepend constant before string
  *
  * @return void
  */
 public function prepend()
 {
     $this->string = str_replace('{region}', $this->amazon->domain(), self::PREPEND) . $this->string;
 }
Esempio n. 18
0
             log_('LIMIT REACHED[BYTES]:' . $limit['uploaded_bytes'] . ' FROM ' . $day_limit_bytes);
             exit(0);
         } else {
             log_('LIMIT [BYTES]:' . $limit['uploaded_bytes'] . ' FROM ' . $day_limit_bytes);
         }
         if ($limit['uploaded_count'] > $day_limit_count) {
             log_('LIMIT REACHED[COUNT]:' . $limit['uploaded_count'] . ' FROM ' . $day_limit_count);
             exit(0);
         } else {
             log_('LIMIT [COUNT]:' . $limit['uploaded_count'] . ' FROM ' . $day_limit_count);
         }
         $real_path = ImgStore::getFileLocalPath($image['image_id'], $image['size_id']);
         log_($real_path . ' ' . floor($image['bytes'] / 1024 / 1024 * 1000) / 1000 . 'Mb');
         $target_path = str_replace(ImgStore::$server_urls[ImgStore::SERVER_ORIG], '', ImgStore::getUrl($image['image_id'], $image['size_id'], 0));
         log_('saving to ' . $target_path);
         $result = Amazon::store($real_path, $target_path);
         if ($result) {
             $limit['uploaded_count']++;
             $limit['uploaded_bytes'] += $image['bytes'];
             log_('Stored at amazon at ' . ImgStore::$server_urls[ImgStore::SERVER_AMAZONS3] . $target_path);
             Database::query('UPDATE `images` SET 
                 `server_id`=' . ImgStore::SERVER_AMAZONS3 . ',
                 `amazon_stored_time`=' . time() . ' WHERE `id`=' . $image['id']);
         } else {
             log_('Cant store file to amazon');
             Database::query('UPDATE `images` SET `amazon_stored_time`=' . time() . ' WHERE `id`=' . $image['id']);
         }
         Database::query('REPLACE INTO `amazon_limit` SET `day`=' . $day . ', `uploaded_bytes`=' . $limit['uploaded_bytes'] . ',`uploaded_count`=' . $limit['uploaded_count']);
     }
     log_('+');
 }
Esempio n. 19
0
<button type="submit" id="btn" class="button">Search</button>
</fieldset>
</form>
<p id="message" style="display:none"><img src="./meta/img/loading.gif" id="loading" /> Time to make the donuts...</p>
<script>
window.onload = function() {
var submit = document.getElementById('btn');
	submit.onclick = function() {
		var msg = document.getElementById("message");
		msg.style.display = 'block';
	}
}
</script>

<?php 
    $Amazon = new Amazon();
    $parameters = array("region" => "com", "AssociateTag" => "jasonclarkinf-20", "Operation" => "ItemSearch", "SearchIndex" => "Books", "ResponseGroup" => "Images,ItemAttributes,EditorialReview,Reviews,Similarities", "Keywords" => "{$q}");
    // this is what we are looking for, you could use the book's title instead
    $queryUrl = $Amazon->getSignedUrl($parameters);
    $request = simplexml_load_file($queryUrl) or die('API response not loading');
    if ($request->Items->TotalResults > 0) {
        // we have at least one response
        //set Amazon xml values as specifc variables to be printed out below
        $image = $request->Items->Item->SmallImage->URL;
        if (empty($image)) {
            $image = './meta/img/thumbnail-default.gif';
        }
        $title = $request->Items->Item->ItemAttributes->Title;
        $author = $request->Items->Item->ItemAttributes->Author;
        //simple logic check for author and director values
        if (strlen($author) > 2) {
Esempio n. 20
0
 public static function updateBook($isbn, $itemNode)
 {
     $book = BookQuery::create()->filterByIsbn($isbn)->findOneOrCreate();
     if ($data = Amazon::parseItemNode($itemNode)) {
         $book->setTitle($data['title'])->setAuthor($data['author'])->setPublisher($data['publisher'])->setEdition($data['edition'])->setPubdate($data['date'])->setIsPaperback($data['isPaperback'])->setImageUrl($data['image_url']);
     }
     $book->save();
 }