Пример #1
0
function wpr_ama_handler($atts, $content = null)
{
    global $wpdb, $wpr_table_templates;
    $template = $wpdb->get_var("SELECT content FROM " . $wpr_table_templates . " WHERE type = 'amazon'");
    $imagepath = WP_PLUGIN_URL . '/' . str_replace(basename(__FILE__), "", plugin_basename(__FILE__));
    $imagepath = str_replace("/modules/", "/images/", $imagepath);
    $options = unserialize(get_option("wpr_options"));
    $public_key = $options['wpr_aa_apikey'];
    $private_key = $options['wpr_aa_secretkey'];
    $locale = $options['wpr_aa_site'];
    $affid = $options['wpr_aa_affkey'];
    if ($locale == "us") {
        $locale = "com";
    }
    if ($locale == "uk") {
        $locale = "co.uk";
    }
    $pxml = wpr_aws_request($locale, array("Operation" => "ItemLookup", "ItemId" => $atts["asin"], "IncludeReviewsSummary" => "False", "AssociateTag" => $affid, "TruncateReviewsAt" => "5000", "ResponseGroup" => "Large"), $public_key, $private_key);
    //echo "<pre>";print_r($pxml);echo "</pre>";
    if ($pxml === False) {
        return false;
    } else {
        if ($pxml->Items->Item->CustomerReviews->IFrameURL) {
            foreach ($pxml->Items->Item as $item) {
                $desc = "";
                if (isset($item->EditorialReviews->EditorialReview)) {
                    foreach ($item->EditorialReviews->EditorialReview as $descs) {
                        $desc .= $descs->Content;
                    }
                }
                $elength = $options['wpr_aa_excerptlength'];
                if ($elength != 'full') {
                    $desc = strip_tags($desc, '<br>');
                    $desc = substr($desc, 0, $elength);
                }
                $features = "";
                if (isset($item->ItemAttributes->Feature)) {
                    $features = "<ul>";
                    foreach ($item->ItemAttributes->Feature as $feature) {
                        $posx = strpos($feature, "href=");
                        if ($posx === false) {
                            $features .= "<li>" . $feature . "</li>";
                        }
                    }
                    $features .= "</ul>";
                }
                $timg = $item->MediumImage->URL;
                if ($timg == "") {
                    $timg = $item->SmallImage->URL;
                }
                $thumbnail = '<a href="' . $item->DetailPageURL . '" rel="nofollow"><img style="float:left;margin: 0 20px 10px 0;" src="' . $timg . '" /></a>';
                $link = '<a href="' . $item->DetailPageURL . '" rel="nofollow">' . $item->ItemAttributes->Title . '</a>';
                $product_review = $item->CustomerReviews->IFrameURL;
                $reviewsiframe = '<iframe style="margin-top: 10px;" src="' . $product_review . '" width="100%" height="450px"><p>Your browser does not support iframes.</p></iframe>';
                $revcontent = file_get_contents($product_review);
                if (preg_match('~<body[^>]*>(.*?)</body>~si', $revcontent, $body)) {
                    $reviewsnoiframe = str_replace('class="crVotingButtons">', "", $body[1]);
                } else {
                    $reviewsnoiframe = "";
                }
                $price = str_replace("\$", "\$ ", $item->OfferSummary->LowestNewPrice->FormattedPrice);
                $listprice = str_replace("\$", "\$ ", $item->ItemAttributes->ListPrice->FormattedPrice);
                if ($price == "Too low to display" || $price == "Price too low to display") {
                    $price = $listprice;
                }
                $acontent = $template;
                preg_match('#\\[has_reviews\\](.*)\\[/has_reviews\\]#smiU', $template, $check);
                if ($check[0] != false) {
                    if (empty($item->CustomerReviews->TotalReviews)) {
                        $acontent = str_replace($check[0], "", $acontent);
                    }
                }
                $acontent = str_replace(array("[has_reviews]", "[/has_reviews]"), "", $acontent);
                preg_match('#\\[has_listprice\\](.*)\\[/has_listprice\\]#smiU', $template, $matches);
                //print_r($matches);
                if ($matches[0] != false) {
                    if (empty($listprice)) {
                        $acontent = str_replace($matches[0], "", $acontent);
                    }
                }
                $acontent = str_replace(array("[has_listprice]", "[/has_listprice]"), "", $acontent);
                $asin = $item->ASIN;
                $acontent = wpr_random_tags($acontent);
                $acontent = str_replace("{title}", $item->ItemAttributes->Title, $acontent);
                $acontent = str_replace("{description}", $desc, $acontent);
                $acontent = str_replace("{features}", $features, $acontent);
                $acontent = str_replace("{thumbnail}", $thumbnail, $acontent);
                $acontent = str_replace("{smallimage}", $item->SmallImage->URL, $acontent);
                $acontent = str_replace("{mediumimage}", $item->MediumImage->URL, $acontent);
                $acontent = str_replace("{largeimage}", $item->LargeImage->URL, $acontent);
                $acontent = str_replace("{buynow}", '<a href="' . $item->DetailPageURL . '" rel="nofollow"><img src="' . $imagepath . 'buynow-small.gif" /></a>', $acontent);
                $acontent = str_replace("{buynow-big}", '<a href="' . $item->DetailPageURL . '" rel="nofollow"><img src="' . $imagepath . 'buynow-big.gif" /></a>', $acontent);
                $acontent = str_replace("{buynow-ger}", '<a href="' . $item->DetailPageURL . '" rel="nofollow"><img src="' . $imagepath . 'buynow-ger.gif" /></a>', $acontent);
                $acontent = str_replace("{price}", $price, $acontent);
                $acontent = str_replace("{listprice}", $listprice, $acontent);
                $savings = str_replace("\$ ", "", $listprice) - str_replace("\$ ", "", $price);
                $acontent = str_replace("{savings}", $savings, $acontent);
                $acontent = str_replace("{url}", $item->DetailPageURL, $acontent);
                $acontent = str_replace("{avgrating}", $item->CustomerReviews->AverageRating, $acontent);
                $acontent = str_replace("{reviewsnum}", $item->CustomerReviews->TotalReviews, $acontent);
                $noqkeyword = str_replace('"', '', $keywords);
                $acontent = str_replace("{keyword}", $noqkeyword, $acontent);
                $acontent = str_replace("{Keyword}", ucwords($noqkeyword), $acontent);
                $acontent = str_replace("{link}", $link, $acontent);
                $acontent = str_replace("{asin}", $asin, $acontent);
                $acontent = str_replace("{price-updating}", $price, $acontent);
                // rating
                if (strpos($acontent, "{rating}") != false) {
                    $image = wpr_star_rating($item->CustomerReviews->AverageRating);
                    $acontent = str_replace("{rating}", $image, $acontent);
                }
                // reviews
                $acontent = str_replace("{reviews-url}", $product_review, $acontent);
                $acontent = str_replace("{reviews-iframe}", $reviewsiframe, $acontent);
                $acontent = str_replace("{reviews-noiframe}", $reviewsnoiframe, $acontent);
                preg_match('#\\{reviews(.*)\\}#iU', $acontent, $rmatches);
                if ($rmatches[0] == false) {
                } else {
                    $acontent = str_replace($rmatches[0], $reviewsiframe, $acontent);
                }
            }
            return $acontent;
        } else {
            return $content;
        }
    }
}
Пример #2
0
function wpr_ama_reviews($atts, $content = null) {

	$options = unserialize(get_option("wpr_options"));	
	$public_key = $options['wpr_aa_apikey'];
	$private_key = $options['wpr_aa_secretkey'];
	$locale = $options['wpr_aa_site'];		
	$affid = $options['wpr_aa_affkey'];	
	if($locale == "us") {$locale = "com";}
	if($locale == "uk") {$locale = "co.uk";}	
	$pxml = wpr_aws_request($locale, array(
	"Operation"=>"ItemLookup",
	"ItemId"=>$atts["asin"],
	"IncludeReviewsSummary"=>"False",
	"AssociateTag"=>$affid,
	"TruncateReviewsAt"=>"5000",
	"ResponseGroup"=>"Reviews"
	), $public_key, $private_key);
	//echo "<pre>";print_r($pxml);echo "</pre>";
	if ($pxml === False) {
		return false;
	} else {
		if($pxml->Items->Item->CustomerReviews->IFrameURL) {
		
			$product_review = $pxml->Items->Item->CustomerReviews->IFrameURL;
			$reviewsiframe = '<iframe style="margin-top: 10px;" src="'.$product_review.'" width="100%" height="450px"><p>Your browser does not support iframes.</p></iframe>';		
	
			return $reviewsiframe;
		} else {
			return $content;	
		}
	}
}
Пример #3
0
function wpr_aws_getnodename($nodeid)
{
    $options = unserialize(get_option("wpr_options"));
    $public_key = $options['wpr_aa_apikey'];
    $private_key = $options['wpr_aa_secretkey'];
    $locale = $options['wpr_aa_site'];
    if ($locale == "us") {
        $locale = "com";
    }
    if ($locale == "uk") {
        $locale = "co.uk";
    }
    $pxml = wpr_aws_request($locale, array("Operation" => "BrowseNodeLookup", "BrowseNodeId" => $nodeid, "ResponseGroup" => "BrowseNodeInfo"), $public_key, $private_key);
    if ($pxml === False) {
        return false;
    } else {
        if ($pxml->BrowseNodes->BrowseNode->Name) {
            return $pxml->BrowseNodes->BrowseNode->Name;
        } else {
            return false;
        }
    }
}